Skip to content

Commit

Permalink
feat: allow passing arguments to utils.is_loading_pipeline()
Browse files Browse the repository at this point in the history
  • Loading branch information
pwwang committed Feb 22, 2024
1 parent 705c72c commit 98b786a
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pipen/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -734,7 +734,7 @@ async def load_pipeline(
return pipeline


def is_loading_pipeline(*flags: str) -> bool:
def is_loading_pipeline(*flags: str, args: Sequence[str] | None = None) -> bool:
"""Check if we are loading the pipeline. Works only when
`argv0` is "@pipen" while loading the pipeline.
Expand All @@ -745,13 +745,20 @@ def is_loading_pipeline(*flags: str) -> bool:
Args:
*flags: Additional flags to check in sys.argv (e.g. "-h", "--help")
to determine if we are loading the pipeline
args: The arguments to check. sys.argv is used by default.
Note that the first argument should be included in the check.
You could typically pass `[sys.argv[0], *your_args]` to this if you want
to check if `sys.argv[0]` is "@pipen" or `your_args` contains some flags.
Returns:
True if we are loading the pipeline (argv[0] == "@pipen"),
otherwise False
"""
if sys.argv[0] == LOADING_ARGV0:
if args is None:
args = sys.argv

if len(args) > 0 and args[0] == LOADING_ARGV0:
return True

if flags:
return any(flag in sys.argv for flag in flags)
return any(flag in args for flag in flags)

0 comments on commit 98b786a

Please sign in to comment.