Skip to content

Commit

Permalink
Allow users to just have one --pkgs switch, but have commas in there …
Browse files Browse the repository at this point in the history
…indicating separate packages (#999)

Signed-off-by: Yee Hing Tong <[email protected]>
  • Loading branch information
wild-endeavor authored and eapolinario committed Jun 17, 2022
1 parent 58aca28 commit a961336
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
12 changes: 10 additions & 2 deletions flytekit/clis/sdk_in_container/pyflyte.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,22 @@
from flytekit.clis.sdk_in_container.run import run
from flytekit.clis.sdk_in_container.serialize import serialize
from flytekit.configuration.internal import LocalSDK
from flytekit.loggers import cli_logger


def validate_package(ctx, param, values):
pkgs = []
for val in values:
if "/" in val or "-" in val or "\\" in val:
raise click.BadParameter(
f"Illegal package value {val} for parameter: {param}. Expected for the form [a.b.c]"
)
return values
elif "," in val:
pkgs.extend(val.split(","))
else:
pkgs.append(val)
cli_logger.debug(f"Using packages: {pkgs}")
return pkgs


@click.group("pyflyte", invoke_without_command=True)
Expand All @@ -26,7 +33,8 @@ def validate_package(ctx, param, values):
required=False,
multiple=True,
callback=validate_package,
help="Dot separated python packages to operate on. Multiple may be specified Please note that this "
help="Dot-delineated python packages to operate on. Multiple may be specified (can use commas, or specify the "
"switch multiple times. Please note that this "
"option will override the option specified in the configuration file, or environment variable",
)
@click.option(
Expand Down
5 changes: 5 additions & 0 deletions tests/flytekit/unit/cli/pyflyte/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,8 @@ def test_package():
)
assert result.exit_code == 1
assert result.output is not None


def test_pkgs():
pp = pyflyte.validate_package(None, None, ["a.b", "a.c,b.a", "cc.a"])
assert pp == ["a.b", "a.c", "b.a", "cc.a"]

0 comments on commit a961336

Please sign in to comment.