Skip to content

Commit

Permalink
feat: add auto install dep hook to py script components main closure
Browse files Browse the repository at this point in the history
  • Loading branch information
z3z1ma committed Apr 8, 2024
1 parent f414d8c commit cf9400c
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cdf/core/specification/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,11 @@ def install_requirements(self) -> None:
class PythonScript(WorkspaceComponent, InstallableRequirements):
"""A python script component."""

auto_install: bool = pydantic.Field(
False,
description="Whether to automatically install the requirements for the script. Useful for leaner Docker images which defer certain component dep installs to runtime.",
)

_lock: Lock = pydantic.PrivateAttr(default_factory=Lock)
"""A lock for ensuring thread safety."""

Expand Down Expand Up @@ -327,6 +332,8 @@ def _run() -> t.Any:
run_name = ".".join(parts)
try:
with self._lock:
if self.auto_install:
self.install_requirements()
return runpy.run_path(
str(self.path),
run_name=run_name,
Expand Down

0 comments on commit cf9400c

Please sign in to comment.