Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the value in the label optional #2465

Merged
merged 1 commit into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions flytekit/clis/sdk_in_container/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
from flytekit.core.type_engine import TypeEngine
from flytekit.core.workflow import PythonFunctionWorkflow, WorkflowBase
from flytekit.exceptions.system import FlyteSystemException
from flytekit.interaction.click_types import FlyteLiteralConverter, key_value_callback
from flytekit.interaction.click_types import FlyteLiteralConverter, key_value_callback, labels_callback
from flytekit.interaction.string_literals import literal_string_repr
from flytekit.loggers import logger
from flytekit.models import security
Expand Down Expand Up @@ -174,7 +174,7 @@ class RunLevelParams(PyFlyteParams):
multiple=True,
type=str,
show_default=True,
callback=key_value_callback,
callback=labels_callback,
help="Labels to be attached to the execution of the format `label_key=label_value`.",
)
)
Expand Down
16 changes: 16 additions & 0 deletions flytekit/interaction/click_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ def key_value_callback(_: typing.Any, param: str, values: typing.List[str]) -> t
return result


def labels_callback(_: typing.Any, param: str, values: typing.List[str]) -> typing.Optional[typing.Dict[str, str]]:
"""
Callback for click to parse labels.
"""
if not values:
return None
result = {}
for v in values:
if "=" not in v:
result[v.strip()] = ""
else:
k, v = v.split("=", 1)
result[k.strip()] = v.strip()
return result


class DirParamType(click.ParamType):
name = "directory path"

Expand Down
10 changes: 10 additions & 0 deletions tests/flytekit/unit/cli/pyflyte/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,16 @@ def test_pyflyte_run_wf(remote, remote_flag, workflow_file):
assert result.exit_code == 0


def test_pyflyte_run_with_labels():
workflow_file = pathlib.Path(__file__).parent / "workflow.py"
with mock.patch("flytekit.configuration.plugin.FlyteRemote"):
runner = CliRunner()
result = runner.invoke(
pyflyte.main, ["run", "--remote", str(workflow_file), "my_wf", "--help"], catch_exceptions=False
)
assert result.exit_code == 0


def test_imperative_wf():
runner = CliRunner()
result = runner.invoke(
Expand Down
Loading