Skip to content
This repository has been archived by the owner on Jul 19, 2024. It is now read-only.

Commit

Permalink
Beautified pyflyte run even for every task and workflow (flyteorg#1783)
Browse files Browse the repository at this point in the history
* Beautified pyflyte run even for every task and workflow

- identify a task or a workflow
- task or workflow help menus show types and use rich to beautify

Signed-off-by: Ketan Umare <[email protected]>

* one more improvement

Signed-off-by: Ketan Umare <[email protected]>

---------

Signed-off-by: Ketan Umare <[email protected]>
Signed-off-by: Future Outlier <[email protected]>
  • Loading branch information
kumare3 authored and Future Outlier committed Oct 3, 2023
1 parent 63e2d0a commit ea697a1
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions flytekit/clis/sdk_in_container/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,9 +747,11 @@ def __init__(self, filename: str, *args, **kwargs):
else:
self._filename = pathlib.Path(filename).resolve()
self._should_delete = False
self._entities = None

def list_commands(self, ctx):
entities = get_entities_in_file(self._filename, self._should_delete)
self._entities = entities
return entities.all()

def get_command(self, ctx, exe_entity):
Expand All @@ -762,7 +764,9 @@ def get_command(self, ctx, exe_entity):
function.
:return:
"""

is_workflow = False
if self._entities:
is_workflow = exe_entity in self._entities.workflows
rel_path = os.path.relpath(self._filename)
if rel_path.startswith(".."):
raise ValueError(
Expand Down Expand Up @@ -799,11 +803,16 @@ def get_command(self, ctx, exe_entity):
params.append(
to_click_option(ctx, flyte_ctx, input_name, literal_var, python_type, default_val, get_upload_url_fn)
)
cmd = click.Command(

entity_type = "Workflow" if is_workflow else "Task"
h = f"{click.style(entity_type, bold=True)} ({module}.{exe_entity})"
if entity.__doc__:
h = h + click.style(f"{entity.__doc__}", dim=True)
cmd = click.RichCommand(
name=exe_entity,
params=params,
callback=run_command(ctx, entity),
help=f"Run {module}.{exe_entity} in script mode",
help=h,
)
return cmd

Expand All @@ -823,7 +832,7 @@ def list_commands(self, ctx):
def get_command(self, ctx, filename):
if ctx.obj:
ctx.obj[RUN_LEVEL_PARAMS_KEY] = ctx.params
return WorkflowCommand(filename, name=filename, help="Run a [workflow|task] in a file using script mode")
return WorkflowCommand(filename, name=filename, help=f"Run a [workflow|task] from {filename}")


_run_help = """
Expand Down

0 comments on commit ea697a1

Please sign in to comment.