Skip to content

Commit

Permalink
πŸ”– 0.12.4 (#186)
Browse files Browse the repository at this point in the history
* Modify sys.argv before the module is loaded in `utils.load_pipeline()`

* Fix linting

* πŸ”– 0.12.4
  • Loading branch information
pwwang authored Oct 20, 2023
1 parent eace135 commit be7eace
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 29 deletions.
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## 0.12.4

- Modify sys.argv before the module is loaded in `utils.load_pipeline()`

## 0.12.3

- Change cli_args to argv0 and argv1p for utils.load_pipeline
Expand Down
61 changes: 34 additions & 27 deletions pipen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,40 +665,43 @@ async def load_pipeline(
from .proc import Proc
from .procgroup import ProcGroup

if isinstance(obj, str):
obj = _get_obj_from_spec(obj)
if (
not isinstance(obj, type)
or not issubclass(obj, (Pipen, Proc, ProcGroup))
):
raise TypeError(
f"Expected a Pipen, Proc or ProcGroup class, got {type(obj)}"
)

pipeline = obj
if isinstance(obj, type) and issubclass(obj, Proc):
kwargs.setdefault("name", f"{obj.name}Pipeline")
pipeline = Pipen(**kwargs).set_starts(obj)

if isinstance(obj, type) and issubclass(obj, ProcGroup):
pipeline = obj().as_pipen(**kwargs)

if isinstance(obj, type) and issubclass(obj, Pipen):
# Avoid "pipeline" to be used as pipeline name by varname
(pipeline, ) = (obj(**kwargs), )

if not isinstance(pipeline, Pipen):
raise TypeError(
f"Expected a Pipen, Proc or ProcGroup class, got {type(pipeline)}"
)

old_argv = sys.argv
if argv0 is None:
argv0 = LOADING_ARGV0
if argv1p is None:
argv1p = sys.argv[1:]
sys.argv = [argv0] + list(argv1p)

try:
if isinstance(obj, str):
obj = _get_obj_from_spec(obj)
if (
not isinstance(obj, type)
or not issubclass(obj, (Pipen, Proc, ProcGroup))
):
raise TypeError(
"Expected a Pipen, Proc or ProcGroup class, "
f"got {type(obj)}"
)

pipeline = obj
if isinstance(obj, type) and issubclass(obj, Proc):
kwargs.setdefault("name", f"{obj.name}Pipeline")
pipeline = Pipen(**kwargs).set_starts(obj)

if isinstance(obj, type) and issubclass(obj, ProcGroup):
pipeline = obj().as_pipen(**kwargs)

if isinstance(obj, type) and issubclass(obj, Pipen):
# Avoid "pipeline" to be used as pipeline name by varname
(pipeline, ) = (obj(**kwargs), )

if not isinstance(pipeline, Pipen):
raise TypeError(
"Expected a Pipen, Proc or ProcGroup class, "
f"got {type(pipeline)}"
)

# Initialize the pipeline so that the arguments definied by
# other plugins (i.e. pipen-args) to take in place.
pipeline.workdir = Path(pipeline.config.workdir).joinpath(
Expand All @@ -717,6 +720,10 @@ def is_loading_pipeline() -> bool:
"""Check if we are loading the pipeline. Works only when
`argv0` is "@pipen" while loading the pipeline.
Note if you are using this function at compile time, make
sure you load your pipeline using the string form (`part1:part2`)
See more with `load_pipline()`.
Returns:
True if we are loading the pipeline (argv[0] == "@pipen"),
otherwise False
Expand Down
2 changes: 1 addition & 1 deletion pipen/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Provide version of pipen"""

__version__ = "0.12.3"
__version__ = "0.12.4"
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "poetry.masonry.api"

[tool.poetry]
name = "pipen"
version = "0.12.3"
version = "0.12.4"
description = "A pipeline framework for python"
authors = [ "pwwang <[email protected]>",]
license = "MIT"
Expand Down

0 comments on commit be7eace

Please sign in to comment.