Skip to content

Commit

Permalink
give the configuration enums default values
Browse files Browse the repository at this point in the history
  • Loading branch information
smacke committed Nov 30, 2023
1 parent d91e2ea commit 89ef415
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 39 deletions.
34 changes: 20 additions & 14 deletions core/ipyflow/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,43 @@
from ipyflow.slicing.context import SlicingContext, iter_slicing_contexts


class ExecutionMode(Enum):
class EnumWithDefault(Enum):
@classmethod
def _missing_(cls, value):
return cls(cls.__default__) # type: ignore


class ExecutionMode(EnumWithDefault):
NORMAL = "normal"
REACTIVE = "reactive"
REACTIVE = __default__ = "reactive" # type: ignore


class ExecutionSchedule(Enum):
class ExecutionSchedule(EnumWithDefault):
LIVENESS_BASED = "liveness_based"
DAG_BASED = "dag_based"
HYBRID_DAG_LIVENESS_BASED = "hybrid_dag_liveness_based"
HYBRID_DAG_LIVENESS_BASED = __default__ = "hybrid_dag_liveness_based" # type: ignore


class FlowDirection(Enum):
class FlowDirection(EnumWithDefault):
ANY_ORDER = "any_order"
IN_ORDER = "in_order"
IN_ORDER = __default__ = "in_order" # type: ignore


class Highlights(Enum):
class Highlights(EnumWithDefault):
ALL = "all"
NONE = "none"
EXECUTED = "executed"
EXECUTED = __default__ = "executed" # type: ignore
REACTIVE = "reactive"


class ReactivityMode(Enum):
BATCH = "batch"
class ReactivityMode(EnumWithDefault):
BATCH = __default__ = "batch" # type: ignore
INCREMENTAL = "incremental"


# TODO: figure out how to represent different versions of
# same interface (e.g. jupyterlab 4.0, notebook v7, etc)
class Interface(Enum):
class Interface(EnumWithDefault):
BENTO = "bento" # ~TODO
COLAB = "colab" # TODO
DATABRICKS = "databricks" # TODO
Expand All @@ -48,11 +54,11 @@ class Interface(Enum):
JUPYTERLAB = "jupyterlab"
NOTEABLE = "noteable" # TODO
VSCODE = "vscode" # TODO
UNKNOWN = "unknown"
UNKNOWN = __default__ = "unknown" # type: ignore


class ColorScheme(Enum):
NORMAL = "normal"
class ColorScheme(EnumWithDefault):
NORMAL = __default__ = "normal" # type: ignore
CLASSIC = "classic"


Expand Down
37 changes: 12 additions & 25 deletions core/ipyflow/flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,39 +101,31 @@ def __init__(self, **kwargs) -> None:
exec_mode=ExecutionMode(
kwargs.pop(
"exec_mode",
ExecutionMode(getattr(config, "exec_mode", ExecutionMode.NORMAL)),
getattr(config, "exec_mode", ExecutionMode.NORMAL),
)
),
exec_schedule=ExecutionSchedule(
kwargs.pop(
"exec_schedule",
ExecutionSchedule(
getattr(
config, "exec_schedule", ExecutionSchedule.LIVENESS_BASED
)
),
getattr(config, "exec_schedule", ExecutionSchedule.LIVENESS_BASED),
)
),
flow_order=FlowDirection(
kwargs.pop(
"flow_direction",
FlowDirection(
getattr(config, "flow_direction", FlowDirection.IN_ORDER)
),
getattr(config, "flow_direction", FlowDirection.IN_ORDER),
)
),
reactivity_mode=ReactivityMode(
kwargs.pop(
"reactivity_mode",
ReactivityMode(
getattr(config, "reactivity_mode", ReactivityMode.BATCH)
),
getattr(config, "reactivity_mode", ReactivityMode.BATCH),
)
),
color_scheme=ColorScheme(
kwargs.pop(
"color_scheme",
ColorScheme(getattr(config, "color_scheme", ColorScheme.NORMAL)),
getattr(config, "color_scheme", ColorScheme.NORMAL),
)
),
warn_out_of_order_usages=kwargs.pop(
Expand Down Expand Up @@ -278,10 +270,7 @@ def initialize(
**kwargs,
) -> None:
config = shell().config.ipyflow
try:
iface = Interface(interface)
except ValueError:
iface = Interface.UNKNOWN
iface = Interface(interface)
if self.mut_settings.interface == iface:
return
self.mut_settings.interface = iface
Expand All @@ -302,40 +291,38 @@ def initialize(
getattr(
config,
"exec_mode",
kwargs.get("exec_mode", ExecutionMode.NORMAL),
kwargs.get("exec_mode"),
)
)
self.mut_settings.exec_schedule = ExecutionSchedule(
getattr(
config,
"exec_schedule",
kwargs.get(
"exec_schedule", ExecutionSchedule.HYBRID_DAG_LIVENESS_BASED
),
kwargs.get("exec_schedule"),
)
)
self.mut_settings.flow_order = FlowDirection(
getattr(
config,
"flow_direction",
kwargs.get("flow_direction", FlowDirection.IN_ORDER),
kwargs.get("flow_direction"),
)
)
self.mut_settings.highlights = Highlights(
getattr(config, "highlights", kwargs.get("highlights", Highlights.EXECUTED))
getattr(config, "highlights", kwargs.get("highlights"))
)
self.mut_settings.reactivity_mode = ReactivityMode(
getattr(
config,
"reactivity_mode",
kwargs.get("reactivity_mode", ReactivityMode.BATCH),
kwargs.get("reactivity_mode"),
)
)
self.mut_settings.color_scheme = ColorScheme(
getattr(
config,
"color_scheme",
kwargs.get("color_scheme", ColorScheme.NORMAL),
kwargs.get("color_scheme"),
)
)
self.mut_settings.max_external_call_depth_for_tracing = getattr(
Expand Down

0 comments on commit 89ef415

Please sign in to comment.