dagstermill 0.19.1__py3-none-any.whl → 0.19.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of dagstermill might be problematic. Click here for more details.

dagstermill/__init__.py CHANGED
@@ -4,7 +4,10 @@ from .asset_factory import define_dagstermill_asset as define_dagstermill_asset
4
4
  from .context import DagstermillExecutionContext as DagstermillExecutionContext
5
5
  from .errors import DagstermillError as DagstermillError
6
6
  from .factory import define_dagstermill_op as define_dagstermill_op
7
- from .io_managers import local_output_notebook_io_manager as local_output_notebook_io_manager
7
+ from .io_managers import (
8
+ ConfigurableLocalOutputNotebookIOManager as ConfigurableLocalOutputNotebookIOManager,
9
+ local_output_notebook_io_manager as local_output_notebook_io_manager,
10
+ )
8
11
  from .manager import MANAGER_FOR_NOTEBOOK_INSTANCE as _MANAGER_FOR_NOTEBOOK_INSTANCE
9
12
  from .version import __version__ as __version__
10
13
 
@@ -16,7 +19,7 @@ yield_result = _MANAGER_FOR_NOTEBOOK_INSTANCE.yield_result
16
19
 
17
20
  yield_event = _MANAGER_FOR_NOTEBOOK_INSTANCE.yield_event
18
21
 
19
- _reconstitute_pipeline_context = _MANAGER_FOR_NOTEBOOK_INSTANCE.reconstitute_pipeline_context
22
+ _reconstitute_job_context = _MANAGER_FOR_NOTEBOOK_INSTANCE.reconstitute_job_context
20
23
 
21
24
  _teardown = _MANAGER_FOR_NOTEBOOK_INSTANCE.teardown_resources
22
25
 
@@ -1,6 +1,6 @@
1
1
  import pickle
2
2
  import tempfile
3
- from typing import Any, Callable, Iterable, Mapping, Optional, Set, Union
3
+ from typing import Any, Callable, Iterable, Mapping, Optional, Set, Type, Union, cast
4
4
 
5
5
  import dagster._check as check
6
6
  from dagster import (
@@ -15,6 +15,8 @@ from dagster import (
15
15
  RetryRequested,
16
16
  asset,
17
17
  )
18
+ from dagster._config.pythonic_config import Config, infer_schema_from_config_class
19
+ from dagster._config.pythonic_config.utils import safe_is_subclass
18
20
  from dagster._core.definitions.events import CoercibleToAssetKeyPrefix
19
21
  from dagster._core.definitions.utils import validate_tags
20
22
  from dagster._core.execution.context.compute import OpExecutionContext
@@ -185,6 +187,9 @@ def define_dagstermill_asset(
185
187
 
186
188
  default_tags = {"notebook_path": _clean_path_for_windows(notebook_path), "kind": "ipynb"}
187
189
 
190
+ if safe_is_subclass(config_schema, Config):
191
+ config_schema = infer_schema_from_config_class(cast(Type[Config], config_schema))
192
+
188
193
  return asset(
189
194
  name=name,
190
195
  key_prefix=key_prefix,
dagstermill/context.py CHANGED
@@ -12,7 +12,6 @@ from dagster._core.execution.context.compute import AbstractComputeExecutionCont
12
12
  from dagster._core.execution.context.system import PlanExecutionContext, StepExecutionContext
13
13
  from dagster._core.log_manager import DagsterLogManager
14
14
  from dagster._core.system_config.objects import ResolvedRunConfig
15
- from dagster._legacy import PipelineDefinition
16
15
  from dagster._utils.backcompat import deprecation_warning
17
16
 
18
17
 
@@ -24,17 +23,15 @@ class DagstermillExecutionContext(AbstractComputeExecutionContext):
24
23
 
25
24
  def __init__(
26
25
  self,
27
- pipeline_context: PlanExecutionContext,
28
- pipeline_def: PipelineDefinition,
26
+ job_context: PlanExecutionContext,
27
+ job_def: JobDefinition,
29
28
  resource_keys_to_init: AbstractSet[str],
30
29
  op_name: str,
31
30
  node_handle: NodeHandle,
32
31
  op_config: Any = None,
33
32
  ):
34
- self._pipeline_context = check.inst_param(
35
- pipeline_context, "pipeline_context", PlanExecutionContext
36
- )
37
- self._pipeline_def = check.inst_param(pipeline_def, "pipeline_def", PipelineDefinition)
33
+ self._job_context = check.inst_param(job_context, "job_context", PlanExecutionContext)
34
+ self._job_def = check.inst_param(job_def, "job_def", JobDefinition)
38
35
  self._resource_keys_to_init = check.set_param(
39
36
  resource_keys_to_init, "resource_keys_to_init", of_type=str
40
37
  )
@@ -52,7 +49,7 @@ class DagstermillExecutionContext(AbstractComputeExecutionContext):
52
49
  bool
53
50
  """
54
51
  check.str_param(key, "key")
55
- return self._pipeline_context.has_tag(key)
52
+ return self._job_context.has_tag(key)
56
53
 
57
54
  def get_tag(self, key: str) -> Optional[str]:
58
55
  """Get a logging tag defined on the context.
@@ -64,44 +61,35 @@ class DagstermillExecutionContext(AbstractComputeExecutionContext):
64
61
  str
65
62
  """
66
63
  check.str_param(key, "key")
67
- return self._pipeline_context.get_tag(key)
64
+ return self._job_context.get_tag(key)
68
65
 
69
66
  @public
70
67
  @property
71
68
  def run_id(self) -> str:
72
69
  """str: The run_id for the context."""
73
- return self._pipeline_context.run_id
70
+ return self._job_context.run_id
74
71
 
75
72
  @public
76
73
  @property
77
74
  def run_config(self) -> Mapping[str, Any]:
78
75
  """dict: The run_config for the context."""
79
- return self._pipeline_context.run_config
76
+ return self._job_context.run_config
80
77
 
81
78
  @property
82
79
  def resolved_run_config(self) -> ResolvedRunConfig:
83
80
  """:class:`dagster.ResolvedRunConfig`: The resolved_run_config for the context."""
84
- return self._pipeline_context.resolved_run_config
81
+ return self._job_context.resolved_run_config
85
82
 
86
83
  @public
87
84
  @property
88
85
  def logging_tags(self) -> Mapping[str, str]:
89
86
  """dict: The logging tags for the context."""
90
- return self._pipeline_context.logging_tags
87
+ return self._job_context.logging_tags
91
88
 
92
89
  @public
93
90
  @property
94
91
  def job_name(self) -> str:
95
- return self._pipeline_context.job_name
96
-
97
- @property
98
- def pipeline_name(self) -> str:
99
- deprecation_warning(
100
- "DagstermillExecutionContext.pipeline_name",
101
- "0.17.0",
102
- "use the 'job_name' property instead.",
103
- )
104
- return self.job_name
92
+ return self._job_context.job_name
105
93
 
106
94
  @public
107
95
  @property
@@ -110,34 +98,14 @@ class DagstermillExecutionContext(AbstractComputeExecutionContext):
110
98
 
111
99
  This will be a dagstermill-specific shim.
112
100
  """
113
- return cast(
114
- JobDefinition,
115
- check.inst(
116
- self._pipeline_def,
117
- JobDefinition,
118
- "Accessing job_def inside a legacy pipeline. Use pipeline_def instead.",
119
- ),
120
- )
121
-
122
- @property
123
- def pipeline_def(self) -> PipelineDefinition:
124
- """:class:`dagster.PipelineDefinition`: The pipeline definition for the context.
125
-
126
- This will be a dagstermill-specific shim.
127
- """
128
- deprecation_warning(
129
- "DagstermillExecutionContext.pipeline_def",
130
- "0.17.0",
131
- "use the 'job_def' property instead.",
132
- )
133
- return self._pipeline_def
101
+ return self._job_def
134
102
 
135
103
  @property
136
104
  def resources(self) -> Any:
137
105
  """collections.namedtuple: A dynamically-created type whose properties allow access to
138
106
  resources.
139
107
  """
140
- return self._pipeline_context.scoped_resources_builder.build(
108
+ return self._job_context.scoped_resources_builder.build(
141
109
  required_resource_keys=self._resource_keys_to_init,
142
110
  )
143
111
 
@@ -145,16 +113,7 @@ class DagstermillExecutionContext(AbstractComputeExecutionContext):
145
113
  @property
146
114
  def run(self) -> DagsterRun:
147
115
  """:class:`dagster.DagsterRun`: The job run for the context."""
148
- return cast(DagsterRun, self._pipeline_context.dagster_run)
149
-
150
- @property
151
- def pipeline_run(self) -> DagsterRun:
152
- deprecation_warning(
153
- "DagstermillExecutionContext.pipeline_run",
154
- "0.17.0",
155
- "use the 'run' property instead.",
156
- )
157
- return self.run
116
+ return cast(DagsterRun, self._job_context.dagster_run)
158
117
 
159
118
  @property
160
119
  def log(self) -> DagsterLogManager:
@@ -162,7 +121,7 @@ class DagstermillExecutionContext(AbstractComputeExecutionContext):
162
121
 
163
122
  Call, e.g., ``log.info()`` to log messages through the Dagster machinery.
164
123
  """
165
- return self._pipeline_context.log
124
+ return self._job_context.log
166
125
 
167
126
  @public
168
127
  @property
@@ -172,7 +131,7 @@ class DagstermillExecutionContext(AbstractComputeExecutionContext):
172
131
  In interactive contexts, this may be a dagstermill-specific shim, depending whether an
173
132
  op definition was passed to ``dagstermill.get_context``.
174
133
  """
175
- return cast(OpDefinition, self._pipeline_def.node_def_named(self.op_name))
134
+ return cast(OpDefinition, self._job_def.node_def_named(self.op_name))
176
135
 
177
136
  @property
178
137
  def node(self) -> Node:
@@ -186,7 +145,7 @@ class DagstermillExecutionContext(AbstractComputeExecutionContext):
186
145
  "0.17.0",
187
146
  "use the 'op_def' property instead.",
188
147
  )
189
- return self.pipeline_def.get_node(self.node_handle)
148
+ return self.job_def.get_node(self.node_handle)
190
149
 
191
150
  @public
192
151
  @property
@@ -204,8 +163,8 @@ class DagstermillExecutionContext(AbstractComputeExecutionContext):
204
163
  class DagstermillRuntimeExecutionContext(DagstermillExecutionContext):
205
164
  def __init__(
206
165
  self,
207
- pipeline_context: PlanExecutionContext,
208
- pipeline_def: PipelineDefinition,
166
+ job_context: PlanExecutionContext,
167
+ job_def: JobDefinition,
209
168
  resource_keys_to_init: AbstractSet[str],
210
169
  op_name: str,
211
170
  step_context: StepExecutionContext,
@@ -214,8 +173,8 @@ class DagstermillRuntimeExecutionContext(DagstermillExecutionContext):
214
173
  ):
215
174
  self._step_context = check.inst_param(step_context, "step_context", StepExecutionContext)
216
175
  super().__init__(
217
- pipeline_context,
218
- pipeline_def,
176
+ job_context,
177
+ job_def,
219
178
  resource_keys_to_init,
220
179
  op_name,
221
180
  node_handle,
@@ -7,7 +7,6 @@ from dagster import (
7
7
  AssetSelection,
8
8
  Field,
9
9
  In,
10
- Int,
11
10
  List,
12
11
  Out,
13
12
  ResourceDefinition,
@@ -23,11 +22,15 @@ from dagster import (
23
22
  resource,
24
23
  with_resources,
25
24
  )
25
+ from dagster._config.pythonic_config import Config
26
26
  from dagster._core.definitions.utils import DEFAULT_OUTPUT
27
27
  from dagster._utils import PICKLE_PROTOCOL, file_relative_path
28
28
 
29
29
  import dagstermill
30
- from dagstermill.io_managers import local_output_notebook_io_manager
30
+ from dagstermill.io_managers import (
31
+ ConfigurableLocalOutputNotebookIOManager,
32
+ local_output_notebook_io_manager,
33
+ )
31
34
 
32
35
  try:
33
36
  from dagster_pandas import DataFrame
@@ -90,6 +93,16 @@ def hello_world_job():
90
93
  hello_world()
91
94
 
92
95
 
96
+ @job(
97
+ resource_defs={
98
+ "output_notebook_io_manager": ConfigurableLocalOutputNotebookIOManager.configure_at_launch(),
99
+ "io_manager": fs_io_manager,
100
+ }
101
+ )
102
+ def hello_world_job_struct_resource() -> None:
103
+ hello_world()
104
+
105
+
93
106
  def build_hello_world_job():
94
107
  @job(
95
108
  resource_defs={
@@ -136,6 +149,31 @@ def hello_world_config_job():
136
149
  goodbye_config()
137
150
 
138
151
 
152
+ class HelloWorldConfig(Config):
153
+ greeting: str = "hello"
154
+
155
+
156
+ hello_world_config_struct = test_nb_op("hello_world_config_struct", config_schema=HelloWorldConfig)
157
+
158
+
159
+ class GoodbyeConfig(Config):
160
+ farewell: str = "goodbye"
161
+
162
+
163
+ goodbye_config_struct = test_nb_op(
164
+ name="goodbye_config_struct",
165
+ path=nb_test_path("print_dagstermill_context_op_config"),
166
+ output_notebook_name="notebook",
167
+ config_schema=GoodbyeConfig,
168
+ )
169
+
170
+
171
+ @job(resource_defs=common_resource_defs)
172
+ def hello_world_config_job_struct() -> None:
173
+ hello_world_config_struct()
174
+ goodbye_config_struct()
175
+
176
+
139
177
  @job(resource_defs=common_resource_defs)
140
178
  def alias_config_job():
141
179
  hello_world_config.alias("aliased_greeting")()
@@ -239,9 +277,9 @@ def double_add_job():
239
277
  add_two_numbers.alias("add_two_numbers_2")(return_three(), return_four())
240
278
 
241
279
 
242
- @op(config_schema=Int)
243
- def load_constant(context):
244
- return context.op_config
280
+ @op
281
+ def load_constant(config: int) -> int:
282
+ return config
245
283
 
246
284
 
247
285
  @job(resource_defs=common_resource_defs)
@@ -536,8 +574,8 @@ yield_event_asset = dagstermill.define_dagstermill_asset(
536
574
  )
537
575
 
538
576
 
539
- # this is hacky. We need a ReconstructablePipeline to run dagstermill, and
540
- # ReconstructablePipeline.for_module() find the jobs defined in this file. So we need to resolve all
577
+ # this is hacky. We need a ReconstructableJob to run dagstermill, and
578
+ # ReconstructableJob.for_module() find the jobs defined in this file. So we need to resolve all
541
579
  # of the asset jobs outside of the repository function.
542
580
  assets = with_resources(
543
581
  [
@@ -585,6 +623,7 @@ def notebook_repo():
585
623
  bad_kernel_job,
586
624
  error_job,
587
625
  hello_world_job,
626
+ hello_world_job_struct_resource,
588
627
  hello_world_with_custom_tags_and_description_job,
589
628
  hello_world_config_job,
590
629
  hello_world_explicit_yield_job,
dagstermill/factory.py CHANGED
@@ -4,7 +4,7 @@ import pickle
4
4
  import sys
5
5
  import tempfile
6
6
  import uuid
7
- from typing import Any, Callable, Iterable, Mapping, Optional, Sequence, Set, Union, cast
7
+ from typing import Any, Callable, Iterable, Mapping, Optional, Sequence, Set, Type, Union, cast
8
8
 
9
9
  import nbformat
10
10
  import papermill
@@ -16,9 +16,11 @@ from dagster import (
16
16
  _check as check,
17
17
  _seven,
18
18
  )
19
+ from dagster._config.pythonic_config import Config, infer_schema_from_config_class
20
+ from dagster._config.pythonic_config.utils import safe_is_subclass
19
21
  from dagster._core.definitions.events import AssetMaterialization, Failure, RetryRequested
20
22
  from dagster._core.definitions.metadata import MetadataValue
21
- from dagster._core.definitions.reconstruct import ReconstructablePipeline
23
+ from dagster._core.definitions.reconstruct import ReconstructableJob
22
24
  from dagster._core.definitions.utils import validate_tags
23
25
  from dagster._core.execution.context.compute import OpExecutionContext
24
26
  from dagster._core.execution.context.input import build_input_context
@@ -121,7 +123,7 @@ def get_papermill_parameters(
121
123
  marshal_dir = os.path.normpath(os.path.join(temp_dir, "dagstermill", str(run_id), "marshal"))
122
124
  mkdir_p(marshal_dir)
123
125
 
124
- if not isinstance(step_context.pipeline, ReconstructablePipeline):
126
+ if not isinstance(step_context.job, ReconstructableJob):
125
127
  if compute_descriptor == "asset":
126
128
  raise DagstermillError(
127
129
  "Can't execute a dagstermill asset that is not reconstructable. "
@@ -133,7 +135,7 @@ def get_papermill_parameters(
133
135
  "Use the reconstructable() function if executing from python"
134
136
  )
135
137
 
136
- dm_executable_dict = step_context.pipeline.to_dict()
138
+ dm_executable_dict = step_context.job.to_dict()
137
139
 
138
140
  dm_context_dict = {
139
141
  "output_log_path": output_log_path,
@@ -430,6 +432,9 @@ def define_dagstermill_op(
430
432
  )
431
433
  default_tags = {"notebook_path": _clean_path_for_windows(notebook_path), "kind": "ipynb"}
432
434
 
435
+ if safe_is_subclass(config_schema, Config):
436
+ config_schema = infer_schema_from_config_class(cast(Type[Config], config_schema))
437
+
433
438
  return OpDefinition(
434
439
  name=name,
435
440
  compute_fn=_make_dagstermill_compute_fn(
@@ -1,15 +1,21 @@
1
1
  import os
2
2
  from pathlib import Path
3
- from typing import Any, Optional, Sequence
3
+ from typing import Any, List, Optional, Sequence
4
4
 
5
5
  import dagster._check as check
6
- from dagster import AssetKey, AssetMaterialization
7
- from dagster._config import Field
6
+ from dagster import (
7
+ AssetKey,
8
+ AssetMaterialization,
9
+ ConfigurableIOManagerFactory,
10
+ InitResourceContext,
11
+ IOManager,
12
+ )
8
13
  from dagster._core.definitions.metadata import MetadataValue
9
14
  from dagster._core.execution.context.input import InputContext
10
15
  from dagster._core.execution.context.output import OutputContext
11
- from dagster._core.storage.io_manager import IOManager, io_manager
16
+ from dagster._core.storage.io_manager import io_manager
12
17
  from dagster._utils import mkdir_p
18
+ from pydantic import Field
13
19
 
14
20
  from dagstermill.factory import _clean_path_for_windows
15
21
 
@@ -26,8 +32,6 @@ class OutputNotebookIOManager(IOManager):
26
32
 
27
33
 
28
34
  class LocalOutputNotebookIOManager(OutputNotebookIOManager):
29
- """Built-in IO Manager for handling output notebook."""
30
-
31
35
  def __init__(self, base_dir: str, asset_key_prefix: Optional[Sequence[str]] = None):
32
36
  super(LocalOutputNotebookIOManager, self).__init__(asset_key_prefix=asset_key_prefix)
33
37
  self.base_dir = base_dir
@@ -70,7 +74,7 @@ class LocalOutputNotebookIOManager(OutputNotebookIOManager):
70
74
  )
71
75
  )
72
76
 
73
- def load_input(self, context) -> bytes:
77
+ def load_input(self, context: InputContext) -> bytes:
74
78
  check.inst_param(context, "context", InputContext)
75
79
  # pass output notebook to downstream ops as File Object
76
80
  output_context = check.not_none(context.upstream_output)
@@ -78,17 +82,32 @@ class LocalOutputNotebookIOManager(OutputNotebookIOManager):
78
82
  return file_obj.read()
79
83
 
80
84
 
81
- @io_manager(
82
- config_schema={
83
- "asset_key_prefix": Field(str, is_required=False),
84
- "base_dir": Field(str, is_required=False),
85
- },
86
- )
87
- def local_output_notebook_io_manager(init_context):
88
- """Built-in IO Manager that handles output notebooks."""
89
- return LocalOutputNotebookIOManager(
90
- base_dir=init_context.resource_config.get(
91
- "base_dir", init_context.instance.storage_directory()
85
+ class ConfigurableLocalOutputNotebookIOManager(ConfigurableIOManagerFactory):
86
+ """Built-in IO Manager for handling output notebook."""
87
+
88
+ base_dir: Optional[str] = Field(
89
+ default=None,
90
+ description=(
91
+ "Base directory to use for output notebooks. Defaults to the Dagster instance storage"
92
+ " directory if not provided."
92
93
  ),
93
- asset_key_prefix=init_context.resource_config.get("asset_key_prefix", []),
94
94
  )
95
+ asset_key_prefix: List[str] = Field(
96
+ default=[],
97
+ description=(
98
+ "Asset key prefix to apply to assets materialized for output notebooks. Defaults to no"
99
+ " prefix."
100
+ ),
101
+ )
102
+
103
+ def create_io_manager(self, context: InitResourceContext) -> "LocalOutputNotebookIOManager":
104
+ return LocalOutputNotebookIOManager(
105
+ base_dir=self.base_dir or check.not_none(context.instance).storage_directory(),
106
+ asset_key_prefix=self.asset_key_prefix,
107
+ )
108
+
109
+
110
+ @io_manager(config_schema=ConfigurableLocalOutputNotebookIOManager.to_config_schema())
111
+ def local_output_notebook_io_manager(init_context) -> LocalOutputNotebookIOManager:
112
+ """Built-in IO Manager that handles output notebooks."""
113
+ return ConfigurableLocalOutputNotebookIOManager.from_resource_context(init_context)
dagstermill/manager.py CHANGED
@@ -16,14 +16,15 @@ from dagster import (
16
16
  )
17
17
  from dagster._core.definitions.dependency import NodeHandle
18
18
  from dagster._core.definitions.events import RetryRequested
19
+ from dagster._core.definitions.graph_definition import GraphDefinition
20
+ from dagster._core.definitions.job_base import InMemoryJob
21
+ from dagster._core.definitions.job_definition import JobDefinition
19
22
  from dagster._core.definitions.node_definition import NodeDefinition
20
23
  from dagster._core.definitions.op_definition import OpDefinition
21
- from dagster._core.definitions.pipeline_base import InMemoryPipeline
22
- from dagster._core.definitions.reconstruct import ReconstructablePipeline
24
+ from dagster._core.definitions.reconstruct import ReconstructableJob
23
25
  from dagster._core.definitions.resource_definition import ScopedResourcesBuilder
24
- from dagster._core.errors import DagsterInvariantViolationError
25
26
  from dagster._core.events import DagsterEvent
26
- from dagster._core.execution.api import scoped_pipeline_context
27
+ from dagster._core.execution.api import scoped_job_context
27
28
  from dagster._core.execution.plan.outputs import StepOutputHandle
28
29
  from dagster._core.execution.plan.plan import ExecutionPlan
29
30
  from dagster._core.execution.plan.step import ExecutionStep
@@ -34,14 +35,12 @@ from dagster._core.execution.resources_init import (
34
35
  from dagster._core.instance import DagsterInstance
35
36
  from dagster._core.instance.ref import InstanceRef
36
37
  from dagster._core.log_manager import DagsterLogManager
37
- from dagster._core.storage.pipeline_run import DagsterRun, DagsterRunStatus
38
+ from dagster._core.storage.dagster_run import DagsterRun, DagsterRunStatus
38
39
  from dagster._core.system_config.objects import ResolvedRunConfig, ResourceConfig
39
40
  from dagster._core.utils import make_new_run_id
40
- from dagster._legacy import ModeDefinition, PipelineDefinition
41
41
  from dagster._loggers import colored_console_logger
42
42
  from dagster._serdes import unpack_value
43
43
  from dagster._utils import EventGenerationManager
44
- from dagster._utils.backcompat import deprecation_warning
45
44
 
46
45
  from .context import DagstermillExecutionContext, DagstermillRuntimeExecutionContext
47
46
  from .errors import DagstermillError
@@ -68,9 +67,9 @@ class DagstermillResourceEventGenerationManager(EventGenerationManager):
68
67
 
69
68
  class Manager:
70
69
  def __init__(self):
71
- self.pipeline = None
70
+ self.job = None
72
71
  self.op_def: Optional[NodeDefinition] = None
73
- self.in_pipeline: bool = False
72
+ self.in_job: bool = False
74
73
  self.marshal_dir: Optional[str] = None
75
74
  self.context = None
76
75
  self.resource_manager = None
@@ -105,10 +104,10 @@ class Manager:
105
104
  )
106
105
  return self.resource_manager
107
106
 
108
- def reconstitute_pipeline_context(
107
+ def reconstitute_job_context(
109
108
  self,
110
109
  executable_dict: Mapping[str, Any],
111
- pipeline_run_dict: Mapping[str, Any],
110
+ job_run_dict: Mapping[str, Any],
112
111
  node_handle_kwargs: Mapping[str, Any],
113
112
  instance_ref_dict: Mapping[str, Any],
114
113
  step_key: str,
@@ -118,26 +117,26 @@ class Manager:
118
117
  ):
119
118
  """Reconstitutes a context for dagstermill-managed execution.
120
119
 
121
- You'll see this function called to reconstruct a pipeline context within the ``injected
120
+ You'll see this function called to reconstruct a job context within the ``injected
122
121
  parameters`` cell of a dagstermill output notebook. Users should not call this function
123
122
  interactively except when debugging output notebooks.
124
123
 
125
124
  Use :func:`dagstermill.get_context` in the ``parameters`` cell of your notebook to define a
126
125
  context for interactive exploration and development. This call will be replaced by one to
127
- :func:`dagstermill.reconstitute_pipeline_context` when the notebook is executed by
126
+ :func:`dagstermill.reconstitute_job_context` when the notebook is executed by
128
127
  dagstermill.
129
128
  """
130
129
  check.opt_str_param(output_log_path, "output_log_path")
131
130
  check.opt_str_param(marshal_dir, "marshal_dir")
132
131
  run_config = check.opt_mapping_param(run_config, "run_config", key_type=str)
133
- check.mapping_param(pipeline_run_dict, "pipeline_run_dict")
132
+ check.mapping_param(job_run_dict, "job_run_dict")
134
133
  check.mapping_param(executable_dict, "executable_dict")
135
134
  check.mapping_param(node_handle_kwargs, "node_handle_kwargs")
136
135
  check.mapping_param(instance_ref_dict, "instance_ref_dict")
137
136
  check.str_param(step_key, "step_key")
138
137
 
139
- pipeline = ReconstructablePipeline.from_dict(executable_dict)
140
- pipeline_def = pipeline.get_definition()
138
+ job = ReconstructableJob.from_dict(executable_dict)
139
+ job_def = job.get_definition()
141
140
 
142
141
  try:
143
142
  instance_ref = unpack_value(instance_ref_dict, InstanceRef)
@@ -147,51 +146,49 @@ class Manager:
147
146
  "Error when attempting to resolve DagsterInstance from serialized InstanceRef"
148
147
  ) from err
149
148
 
150
- dagster_run = unpack_value(pipeline_run_dict, DagsterRun)
149
+ dagster_run = unpack_value(job_run_dict, DagsterRun)
151
150
 
152
151
  node_handle = NodeHandle.from_dict(node_handle_kwargs)
153
- op = pipeline_def.get_node(node_handle)
152
+ op = job_def.get_node(node_handle)
154
153
  op_def = op.definition
155
154
 
156
155
  self.marshal_dir = marshal_dir
157
- self.in_pipeline = True
156
+ self.in_job = True
158
157
  self.op_def = op_def
159
- self.pipeline = pipeline
158
+ self.job = job
160
159
 
161
- resolved_run_config = ResolvedRunConfig.build(
162
- pipeline_def, run_config, mode=dagster_run.mode
163
- )
160
+ resolved_run_config = ResolvedRunConfig.build(job_def, run_config)
164
161
 
165
162
  execution_plan = ExecutionPlan.build(
166
- self.pipeline,
163
+ self.job,
167
164
  resolved_run_config,
168
165
  step_keys_to_execute=dagster_run.step_keys_to_execute,
169
166
  )
170
167
 
171
- with scoped_pipeline_context(
168
+ with scoped_job_context(
172
169
  execution_plan,
173
- pipeline,
170
+ job,
174
171
  run_config,
175
172
  dagster_run,
176
173
  instance,
177
174
  scoped_resources_builder_cm=self._setup_resources,
178
175
  # Set this flag even though we're not in test for clearer error reporting
179
176
  raise_on_error=True,
180
- ) as pipeline_context:
177
+ ) as job_context:
181
178
  self.context = DagstermillRuntimeExecutionContext(
182
- pipeline_context=pipeline_context,
183
- pipeline_def=pipeline_def,
179
+ job_context=job_context,
180
+ job_def=job_def,
184
181
  op_config=run_config.get("ops", {}).get(op.name, {}).get("config"),
185
182
  resource_keys_to_init=get_required_resource_keys_to_init(
186
183
  execution_plan,
187
- pipeline_def,
184
+ job_def,
188
185
  resolved_run_config,
189
186
  ),
190
187
  op_name=op.name,
191
188
  node_handle=node_handle,
192
189
  step_context=cast(
193
190
  StepExecutionContext,
194
- pipeline_context.for_step(
191
+ job_context.for_step(
195
192
  cast(ExecutionStep, execution_plan.get_step_by_key(step_key))
196
193
  ),
197
194
  ),
@@ -204,7 +201,6 @@ class Manager:
204
201
  op_config: Any = None,
205
202
  resource_defs: Optional[Mapping[str, ResourceDefinition]] = None,
206
203
  logger_defs: Optional[Mapping[str, LoggerDefinition]] = None,
207
- mode_def: Optional[ModeDefinition] = None,
208
204
  run_config: Optional[dict] = None,
209
205
  ) -> DagstermillExecutionContext:
210
206
  """Get a dagstermill execution context for interactive exploration and development.
@@ -220,31 +216,8 @@ class Manager:
220
216
  Returns:
221
217
  :py:class:`~dagstermill.DagstermillExecutionContext`
222
218
  """
223
- check.opt_inst_param(mode_def, "mode_def", ModeDefinition)
224
219
  run_config = check.opt_dict_param(run_config, "run_config", key_type=str)
225
220
 
226
- if resource_defs and mode_def:
227
- raise DagsterInvariantViolationError(
228
- "Attempted to provide both resource_defs and mode_def arguments to"
229
- " `dagstermill.get_context`. Please provide one or the other."
230
- )
231
-
232
- if logger_defs and mode_def:
233
- raise DagsterInvariantViolationError(
234
- "Attempted to provide both logger_defs and mode_def arguments to"
235
- " `dagstermill.get_context`. Please provide one or the other."
236
- )
237
-
238
- if mode_def:
239
- deprecation_warning(
240
- "mode_def argument to dagstermill.get_context",
241
- "0.17.0",
242
- (
243
- "Use the resource_defs argument to provide resources, and the logger_defs"
244
- " argument to provide loggers."
245
- ),
246
- )
247
-
248
221
  # If we are running non-interactively, and there is already a context reconstituted, return
249
222
  # that context rather than overwriting it.
250
223
  if self.context is not None and isinstance(
@@ -252,64 +225,63 @@ class Manager:
252
225
  ):
253
226
  return self.context
254
227
 
255
- if not mode_def:
256
- if not logger_defs:
257
- logger_defs = {"dagstermill": colored_console_logger}
258
- run_config["loggers"] = {"dagstermill": {}}
259
- logger_defs = check.opt_mapping_param(logger_defs, "logger_defs")
260
- resource_defs = check.opt_mapping_param(resource_defs, "resource_defs")
261
- mode_def = ModeDefinition(logger_defs=logger_defs, resource_defs=resource_defs)
228
+ if not logger_defs:
229
+ logger_defs = {"dagstermill": colored_console_logger}
230
+ run_config["loggers"] = {"dagstermill": {}}
231
+ logger_defs = check.opt_mapping_param(logger_defs, "logger_defs")
232
+ resource_defs = check.opt_mapping_param(resource_defs, "resource_defs")
262
233
 
263
234
  op_def = OpDefinition(
264
235
  name="this_op",
265
236
  compute_fn=lambda *args, **kwargs: None,
266
237
  description="Ephemeral op constructed by dagstermill.get_context()",
267
- required_resource_keys=mode_def.resource_key_set,
238
+ required_resource_keys=set(resource_defs.keys()),
268
239
  )
269
240
 
270
- pipeline_def = PipelineDefinition(
271
- [op_def], mode_defs=[mode_def], name="ephemeral_dagstermill_pipeline"
241
+ job_def = JobDefinition(
242
+ graph_def=GraphDefinition(name="ephemeral_dagstermill_pipeline", node_defs=[op_def]),
243
+ logger_defs=logger_defs,
244
+ resource_defs=resource_defs,
272
245
  )
273
246
 
274
247
  run_id = make_new_run_id()
275
248
 
276
- # construct stubbed PipelineRun for notebook exploration...
277
- # The actual pipeline run during pipeline execution will be serialized and reconstituted
278
- # in the `reconstitute_pipeline_context` call
279
- pipeline_run = DagsterRun(
280
- pipeline_name=pipeline_def.name,
249
+ # construct stubbed DagsterRun for notebook exploration...
250
+ # The actual dagster run during job execution will be serialized and reconstituted
251
+ # in the `reconstitute_job_context` call
252
+ dagster_run = DagsterRun(
253
+ job_name=job_def.name,
281
254
  run_id=run_id,
282
255
  run_config=run_config,
283
- mode=mode_def.name,
284
256
  step_keys_to_execute=None,
285
257
  status=DagsterRunStatus.NOT_STARTED,
286
258
  tags=None,
287
259
  )
288
260
 
289
- self.in_pipeline = False
261
+ self.in_job = False
290
262
  self.op_def = op_def
291
- self.pipeline = pipeline_def
263
+ self.job = job_def
292
264
 
293
- resolved_run_config = ResolvedRunConfig.build(pipeline_def, run_config, mode=mode_def.name)
265
+ resolved_run_config = ResolvedRunConfig.build(job_def, run_config)
294
266
 
295
- pipeline = InMemoryPipeline(pipeline_def)
296
- execution_plan = ExecutionPlan.build(pipeline, resolved_run_config)
267
+ job = InMemoryJob(job_def)
268
+ execution_plan = ExecutionPlan.build(job, resolved_run_config)
297
269
 
298
- with scoped_pipeline_context(
270
+ with scoped_job_context(
299
271
  execution_plan,
300
- pipeline,
272
+ job,
301
273
  run_config,
302
- pipeline_run,
274
+ dagster_run,
303
275
  DagsterInstance.ephemeral(),
304
276
  scoped_resources_builder_cm=self._setup_resources,
305
- ) as pipeline_context:
277
+ ) as job_context:
306
278
  self.context = DagstermillExecutionContext(
307
- pipeline_context=pipeline_context,
308
- pipeline_def=pipeline_def,
279
+ job_context=job_context,
280
+ job_def=job_def,
309
281
  op_config=op_config,
310
282
  resource_keys_to_init=get_required_resource_keys_to_init(
311
283
  execution_plan,
312
- pipeline_def,
284
+ job_def,
313
285
  resolved_run_config,
314
286
  ),
315
287
  op_name=op_def.name,
@@ -327,7 +299,7 @@ class Manager:
327
299
  value (Any): The value to yield.
328
300
  output_name (Optional[str]): The name of the result to yield (default: ``'result'``).
329
301
  """
330
- if not self.in_pipeline:
302
+ if not self.in_job:
331
303
  return value
332
304
 
333
305
  # deferred import for perf
@@ -384,7 +356,7 @@ class Manager:
384
356
  f" type, one of {valid_types}."
385
357
  )
386
358
 
387
- if not self.in_pipeline:
359
+ if not self.in_job:
388
360
  return dagster_event
389
361
 
390
362
  # deferred import for perf
dagstermill/translator.py CHANGED
@@ -18,11 +18,11 @@ INJECTED_BOILERPLATE = """
18
18
  # Injected parameters
19
19
  from dagster import seven as __dm_seven
20
20
  import dagstermill as __dm_dagstermill
21
- context = __dm_dagstermill._reconstitute_pipeline_context(
21
+ context = __dm_dagstermill._reconstitute_job_context(
22
22
  **{{
23
23
  key: __dm_seven.json.loads(value)
24
24
  for key, value
25
- in {pipeline_context_args}.items()
25
+ in {job_context_args}.items()
26
26
  }}
27
27
  )
28
28
  """
@@ -41,19 +41,19 @@ class DagsterTranslator(papermill.translators.PythonTranslator):
41
41
  assert "__dm_input_names" in parameters
42
42
 
43
43
  context_args = parameters["__dm_context"]
44
- pipeline_context_args = dict(
44
+ job_context_args = dict(
45
45
  executable_dict=parameters["__dm_executable_dict"],
46
- pipeline_run_dict=parameters["__dm_pipeline_run_dict"],
46
+ job_run_dict=parameters["__dm_pipeline_run_dict"],
47
47
  node_handle_kwargs=parameters["__dm_node_handle_kwargs"],
48
48
  instance_ref_dict=parameters["__dm_instance_ref_dict"],
49
49
  step_key=parameters["__dm_step_key"],
50
50
  **context_args,
51
51
  )
52
52
 
53
- for key in pipeline_context_args:
54
- pipeline_context_args[key] = _seven.json.dumps(pipeline_context_args[key])
53
+ for key in job_context_args:
54
+ job_context_args[key] = _seven.json.dumps(job_context_args[key])
55
55
 
56
- content = INJECTED_BOILERPLATE.format(pipeline_context_args=pipeline_context_args)
56
+ content = INJECTED_BOILERPLATE.format(job_context_args=job_context_args)
57
57
 
58
58
  for input_name in parameters["__dm_input_names"]:
59
59
  dm_load_input_call = f"__dm_dagstermill._load_input_parameter('{input_name}')"
dagstermill/version.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.19.1"
1
+ __version__ = "0.19.3"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dagstermill
3
- Version: 0.19.1
3
+ Version: 0.19.3
4
4
  Summary: run notebooks using the Dagster tools
5
5
  Author: Elementl
6
6
  Author-email: hello@elementl.com
@@ -13,7 +13,7 @@ Classifier: Programming Language :: Python :: 3.11
13
13
  Classifier: License :: OSI Approved :: Apache Software License
14
14
  Classifier: Operating System :: OS Independent
15
15
  License-File: LICENSE
16
- Requires-Dist: dagster (==1.3.1)
16
+ Requires-Dist: dagster (==1.3.3)
17
17
  Requires-Dist: ipykernel (!=5.4.0,!=5.4.1,>=4.9.0)
18
18
  Requires-Dist: ipython-genutils (>=0.2.0)
19
19
  Requires-Dist: packaging (>=20.9)
@@ -0,0 +1,22 @@
1
+ dagstermill/__init__.py,sha256=WZRYSjL1yAM1w5cqmC1t2T7hvuW-RGGY5tV9vZGHZwU,1133
2
+ dagstermill/__main__.py,sha256=bYt9eEaoRQWdejEHFD8REx9jxVEdZptECFsV7F49Ink,30
3
+ dagstermill/asset_factory.py,sha256=Qz2vcCjGLUE0IyUn9ceGSTV9f_eTojWhm89jMjxYg8U,9134
4
+ dagstermill/cli.py,sha256=NluBLUhAcf47DaQ7o1W9IhF9Ps8HCUc6v5xMYqO_BBk,4569
5
+ dagstermill/compat.py,sha256=GCfUaGC3eIEhlZP_VFtua8hFKNtwXocOAfYxuKZ5X3I,526
6
+ dagstermill/context.py,sha256=uyyfwMxxuataxLlwBS3SV1AtC5Y8_-TwC45GQ17oxok,5965
7
+ dagstermill/engine.py,sha256=4CZW-eni4TnG8C8VhPkZZgj6djItdOUKhHPzvaVhaYo,5843
8
+ dagstermill/errors.py,sha256=WOmpAGp-J1XhyGK_LT3ZZKsBwF5dvrWbqSaSldtoh6Y,141
9
+ dagstermill/factory.py,sha256=Hl-X6AiQ3RXRF7piW5atWxq7AwM2zD3MUmIz5EohTiE,18747
10
+ dagstermill/io_managers.py,sha256=kk36zAvxnnDot6he9CBTm8-VTDsbx9v1MUY6BaZeeKQ,4258
11
+ dagstermill/manager.py,sha256=_XrERGVBDfgKEOT7GeOqRm4kdSYkFe3by6pPTVarNr4,15497
12
+ dagstermill/serialize.py,sha256=eXW3c26CiILT_uebyFcAKBnsiNxnjyGT_ch3PfGyjek,188
13
+ dagstermill/translator.py,sha256=h1VPAOWtdjLKzFjRmyN9hO_R6qJuAETNkJydfdgwWGM,2170
14
+ dagstermill/version.py,sha256=LpBqSbK1KuDbSUey7PHJzdDwxD-diUSlq4z4kUt_6cU,23
15
+ dagstermill/examples/__init__.py,sha256=kzan-9zFjxaJ8o9bqUso44gcGiOmJrlq4JYO-yIBQao,55
16
+ dagstermill/examples/repository.py,sha256=OY0x-4nJRBKxOsS1hrFFhx9cRX0NQ0YdYvXgg5n9Dco,15725
17
+ dagstermill-0.19.3.dist-info/LICENSE,sha256=-gtoVIAZYUHYmNHISZg982FI4Oh19mV1nxgTVW8eCB8,11344
18
+ dagstermill-0.19.3.dist-info/METADATA,sha256=uS9-dMCqtniDBVR8BbcwMCTImZQP_1ST1M7rD3z-F54,1017
19
+ dagstermill-0.19.3.dist-info/WHEEL,sha256=p46_5Uhzqz6AzeSosiOnxK-zmFja1i22CrQCjmYe8ec,92
20
+ dagstermill-0.19.3.dist-info/entry_points.txt,sha256=885a7vvhABYWEj7W28elkzSmIcKO3REkdd5h4Z4DEJs,53
21
+ dagstermill-0.19.3.dist-info/top_level.txt,sha256=YDelJKdA5YIIrjsObdd8U4E9YhuXJLRe9NKfUzud9Uc,12
22
+ dagstermill-0.19.3.dist-info/RECORD,,
@@ -1,22 +0,0 @@
1
- dagstermill/__init__.py,sha256=3xNVyJruilLSc6JYrf0W5v5KF_tzUCDQBpYf1nel378,1044
2
- dagstermill/__main__.py,sha256=bYt9eEaoRQWdejEHFD8REx9jxVEdZptECFsV7F49Ink,30
3
- dagstermill/asset_factory.py,sha256=4cVAD1DybnMiRi-O6VgRvgP7JYcJnJo-Gs7zmA8JyH8,8833
4
- dagstermill/cli.py,sha256=NluBLUhAcf47DaQ7o1W9IhF9Ps8HCUc6v5xMYqO_BBk,4569
5
- dagstermill/compat.py,sha256=GCfUaGC3eIEhlZP_VFtua8hFKNtwXocOAfYxuKZ5X3I,526
6
- dagstermill/context.py,sha256=By48t6GoPkK2_bVoBCjfhoCR2WVtqSRGYazCoqLdgn8,7307
7
- dagstermill/engine.py,sha256=4CZW-eni4TnG8C8VhPkZZgj6djItdOUKhHPzvaVhaYo,5843
8
- dagstermill/errors.py,sha256=WOmpAGp-J1XhyGK_LT3ZZKsBwF5dvrWbqSaSldtoh6Y,141
9
- dagstermill/factory.py,sha256=tF5bE097lkPINa9OqHEAA92JPiOQULWKM4UVsA2_JKA,18472
10
- dagstermill/io_managers.py,sha256=OGUjSH--pN8qsTDBgGPLWdeamXwEZOjfNX9rQfNsQEs,3533
11
- dagstermill/manager.py,sha256=A7lN22c_Yx8HQOFqobL4BbdaXn2EqpiIaCGMHEhnGZE,16960
12
- dagstermill/serialize.py,sha256=eXW3c26CiILT_uebyFcAKBnsiNxnjyGT_ch3PfGyjek,188
13
- dagstermill/translator.py,sha256=LpnD_4-4SgRAsHPh7REywkiXRr_yvoszcECk_d_JuUQ,2215
14
- dagstermill/version.py,sha256=ACwqBctK6p_9Oj2rXWiSmVOPJURrCCh7l_Ak1Mk2h-o,23
15
- dagstermill/examples/__init__.py,sha256=kzan-9zFjxaJ8o9bqUso44gcGiOmJrlq4JYO-yIBQao,55
16
- dagstermill/examples/repository.py,sha256=V88N5HjmFSLOWU_jN70hvrYfoMAhVZAS36z17za4Ugk,14797
17
- dagstermill-0.19.1.dist-info/LICENSE,sha256=-gtoVIAZYUHYmNHISZg982FI4Oh19mV1nxgTVW8eCB8,11344
18
- dagstermill-0.19.1.dist-info/METADATA,sha256=U22NWvMuNmhkK0A4J1EvGYcZ5A4TYWWgbMkZNsMZeqI,1017
19
- dagstermill-0.19.1.dist-info/WHEEL,sha256=p46_5Uhzqz6AzeSosiOnxK-zmFja1i22CrQCjmYe8ec,92
20
- dagstermill-0.19.1.dist-info/entry_points.txt,sha256=885a7vvhABYWEj7W28elkzSmIcKO3REkdd5h4Z4DEJs,53
21
- dagstermill-0.19.1.dist-info/top_level.txt,sha256=YDelJKdA5YIIrjsObdd8U4E9YhuXJLRe9NKfUzud9Uc,12
22
- dagstermill-0.19.1.dist-info/RECORD,,