Skip to content

Commit

Permalink
package: dynamically determine condition module __all__
Browse files Browse the repository at this point in the history
include all Condition subclasses and anything in _additional__all__
attribute
  • Loading branch information
kmantel committed Dec 14, 2023
1 parent 4046fd1 commit 9db52f8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
24 changes: 20 additions & 4 deletions src/graph_scheduler/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
Documentation: https://kmantel.github.io/graph-scheduler/
"""

import inspect
import pint

_unit_registry = pint.get_application_registry()
Expand All @@ -22,10 +23,24 @@
from . import time # noqa: E402
from . import utilities # noqa: E402

from .condition import * # noqa: E402
from .scheduler import * # noqa: E402
from .time import * # noqa: E402
from .utilities import * # noqa: E402

condition.__all__ = []
for k, v in condition.__dict__.items():
if (
(
k[0] != '_'
and inspect.isclass(v)
and issubclass(v, condition.Condition)
)
or k in condition._additional__all__
):
condition.__all__.append(k)


from .condition import * # noqa: E402, F401, F403
from .scheduler import * # noqa: E402, F401, F403
from .time import * # noqa: E402, F401, F403
from .utilities import * # noqa: E402, F401, F403

__all__ = list(condition.__all__)
__all__.extend(scheduler.__all__)
Expand All @@ -38,4 +53,5 @@
from . import _version # noqa: E402
__version__ = _version.get_versions()['version']

del inspect
del pint
10 changes: 2 additions & 8 deletions src/graph_scheduler/condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,14 +298,8 @@ def converge(node, thresh):
from graph_scheduler.time import TimeScale
from graph_scheduler.utilities import call_with_pruned_args

__all__ = [
'AfterCall', 'AfterNCalls', 'AfterNCallsCombined', 'AfterNPasses', 'AfterNConsiderationSetExecutions', 'AfterNEnvironmentStateUpdates', 'AfterPass',
'AtEnvironmentSequence', 'AfterEnvironmentSequence', 'AfterNEnvironmentSequences', 'AfterConsiderationSetExecution', 'AfterEnvironmentStateUpdate', 'All', 'AllHaveRun', 'Always', 'And', 'Any',
'AtNCalls','AtPass', 'AtEnvironmentSequenceStart', 'AtEnvironmentSequenceNStart', 'AtConsiderationSetExecution', 'AtEnvironmentStateUpdate',
'AtEnvironmentStateUpdateStart', 'AtEnvironmentStateUpdateNStart', 'BeforeNCalls', 'BeforePass', 'BeforeConsiderationSetExecution', 'BeforeEnvironmentStateUpdate',
'Condition','ConditionError', 'ConditionSet', 'EveryNCalls', 'EveryNPasses',
'JustRan', 'Never', 'Not', 'NWhen', 'Or', 'WhenFinished', 'WhenFinishedAll', 'WhenFinishedAny', 'While', 'WhileNot', 'TimeInterval', 'TimeTermination', 'Threshold'
]

_additional__all__ = ['ConditionError', 'ConditionSet']

logger = logging.getLogger(__name__)

Expand Down

0 comments on commit 9db52f8

Please sign in to comment.