3434
3535if TYPE_CHECKING :
3636 from zenml .artifact_stores import BaseArtifactStore
37+ from zenml .config import DockerSettings
3738 from zenml .models import CodeReferenceResponse , PipelineSnapshotResponse
3839
3940logger = get_logger (__name__ )
@@ -64,6 +65,7 @@ def __init__(self, arguments: List[str]):
6465 arguments: Command line arguments to configure this object.
6566 """
6667 self .entrypoint_args = self ._parse_arguments (arguments )
68+ self ._snapshot : Optional ["PipelineSnapshotResponse" ] = None
6769
6870 @classmethod
6971 def get_entrypoint_command (cls ) -> List [str ]:
@@ -189,7 +191,48 @@ def error(self, message: str) -> NoReturn:
189191 result , _ = parser .parse_known_args (arguments )
190192 return vars (result )
191193
192- def load_snapshot (self ) -> "PipelineSnapshotResponse" :
194+ @property
195+ def snapshot (self ) -> "PipelineSnapshotResponse" :
196+ """The snapshot configured for this entrypoint configuration.
197+
198+ Returns:
199+ The snapshot.
200+ """
201+ if self ._snapshot is None :
202+ self ._snapshot = self ._load_snapshot ()
203+ return self ._snapshot
204+
205+ @property
206+ def docker_settings (self ) -> "DockerSettings" :
207+ """The Docker settings configured for this entrypoint configuration.
208+
209+ Returns:
210+ The Docker settings.
211+ """
212+ return self .snapshot .pipeline_configuration .docker_settings
213+
214+ @property
215+ def should_download_code (self ) -> bool :
216+ """Whether code should be downloaded.
217+
218+ Returns:
219+ Whether code should be downloaded.
220+ """
221+ if (
222+ self .snapshot .code_reference
223+ and self .docker_settings .allow_download_from_code_repository
224+ ):
225+ return True
226+
227+ if (
228+ self .snapshot .code_path
229+ and self .docker_settings .allow_download_from_artifact_store
230+ ):
231+ return True
232+
233+ return False
234+
235+ def _load_snapshot (self ) -> "PipelineSnapshotResponse" :
193236 """Loads the snapshot.
194237
195238 Returns:
@@ -198,34 +241,19 @@ def load_snapshot(self) -> "PipelineSnapshotResponse":
198241 snapshot_id = UUID (self .entrypoint_args [SNAPSHOT_ID_OPTION ])
199242 return Client ().zen_store .get_snapshot (snapshot_id = snapshot_id )
200243
201- def download_code_if_necessary (
202- self ,
203- snapshot : "PipelineSnapshotResponse" ,
204- step_name : Optional [str ] = None ,
205- ) -> None :
244+ def download_code_if_necessary (self ) -> None :
206245 """Downloads user code if necessary.
207246
208- Args:
209- snapshot: The snapshot for which to download the code.
210- step_name: Name of the step to be run. This will be used to
211- determine whether code download is necessary. If not given,
212- the DockerSettings of the pipeline will be used to make that
213- decision instead.
214-
215247 Raises:
216248 CustomFlavorImportError: If the artifact store flavor can't be
217249 imported.
218250 RuntimeError: If the current environment requires code download
219251 but the snapshot does not have a reference to any code.
220252 """
221- should_download_code = self ._should_download_code (
222- snapshot = snapshot , step_name = step_name
223- )
224-
225- if not should_download_code :
253+ if not self .should_download_code :
226254 return
227255
228- if code_path := snapshot .code_path :
256+ if code_path := self . snapshot .code_path :
229257 # Load the artifact store not from the active stack but separately.
230258 # This is required in case the stack has custom flavor components
231259 # (other than the artifact store) for which the flavor
@@ -247,7 +275,7 @@ def download_code_if_necessary(
247275 code_utils .download_code_from_artifact_store (
248276 code_path = code_path , artifact_store = artifact_store
249277 )
250- elif code_reference := snapshot .code_reference :
278+ elif code_reference := self . snapshot .code_reference :
251279 # TODO: This might fail if the code repository had unpushed changes
252280 # at the time the pipeline run was started.
253281 self .download_code_from_code_repository (
@@ -294,43 +322,6 @@ def download_code_from_code_repository(
294322 sys .path .insert (0 , download_dir )
295323 os .chdir (download_dir )
296324
297- def _should_download_code (
298- self ,
299- snapshot : "PipelineSnapshotResponse" ,
300- step_name : Optional [str ] = None ,
301- ) -> bool :
302- """Checks whether code should be downloaded.
303-
304- Args:
305- snapshot: The snapshot to check.
306- step_name: Name of the step to be run. This will be used to
307- determine whether code download is necessary. If not given,
308- the DockerSettings of the pipeline will be used to make that
309- decision instead.
310-
311- Returns:
312- Whether code should be downloaded.
313- """
314- docker_settings = (
315- snapshot .step_configurations [step_name ].config .docker_settings
316- if step_name
317- else snapshot .pipeline_configuration .docker_settings
318- )
319-
320- if (
321- snapshot .code_reference
322- and docker_settings .allow_download_from_code_repository
323- ):
324- return True
325-
326- if (
327- snapshot .code_path
328- and docker_settings .allow_download_from_artifact_store
329- ):
330- return True
331-
332- return False
333-
334325 def _load_active_artifact_store (self ) -> "BaseArtifactStore" :
335326 """Load the active artifact store.
336327
0 commit comments