diff --git a/flytekit/remote/remote.py b/flytekit/remote/remote.py index 31b69cee1a..319b67d0d5 100644 --- a/flytekit/remote/remote.py +++ b/flytekit/remote/remote.py @@ -2399,12 +2399,15 @@ def generate_console_url( if not isinstance(entity, (FlyteWorkflow, FlyteTask, FlyteLaunchPlan)): raise ValueError(f"Only remote entities can be looked at in the console, got type {type(entity)}") + return self.generate_url_from_id(id=entity.id) + + def generate_url_from_id(self, id: Identifier): rt = "workflow" - if entity.id.resource_type == ResourceType.TASK: + if id.resource_type == ResourceType.TASK: rt = "task" - elif entity.id.resource_type == ResourceType.LAUNCH_PLAN: + elif id.resource_type == ResourceType.LAUNCH_PLAN: rt = "launch_plan" - return f"{self.generate_console_http_domain()}/console/projects/{entity.id.project}/domains/{entity.id.domain}/{rt}/{entity.name}/version/{entity.id.version}" # noqa + return f"{self.generate_console_http_domain()}/console/projects/{id.project}/domains/{id.domain}/{rt}/{id.name}/version/{id.version}" def launch_backfill( self, diff --git a/flytekit/tools/repo.py b/flytekit/tools/repo.py index 2d10355f2b..502d376925 100644 --- a/flytekit/tools/repo.py +++ b/flytekit/tools/repo.py @@ -21,6 +21,8 @@ from flytekit.tools.serialize_helpers import get_registrable_entities, persist_registrable_entities from flytekit.tools.translator import FlyteControlPlaneEntity, Options +REGISTRATION = "Registration" + class NoSerializableEntitiesError(Exception): pass @@ -51,6 +53,7 @@ def serialize_get_control_plane_entities( settings: SerializationSettings, local_source_root: typing.Optional[str] = None, options: typing.Optional[Options] = None, + is_registration: bool = False, ) -> typing.List[FlyteControlPlaneEntity]: """ See :py:class:`flytekit.models.core.identifier.ResourceType` to match the trailing index in the file name with the @@ -59,12 +62,16 @@ def serialize_get_control_plane_entities( :param settings: SerializationSettings to be used :param pkgs: Dot-delimited Python packages/subpackages to look into for serialization. :param local_source_root: Where to start looking for the code. + :param is_registration: Whether this is happening for registration. """ settings.source_root = local_source_root ctx_builder = FlyteContextManager.current_context().with_serialization_settings(settings) with FlyteContextManager.with_context(ctx_builder) as ctx: registrable_entities = get_registrable_entities(ctx, options=options) - click.secho(f"Successfully serialized {len(registrable_entities)} flyte objects", fg="green") + click.secho( + f"Successfully serialized{' and registered' if is_registration else ''} {len(registrable_entities)} flyte objects", + fg="green", + ) return registrable_entities @@ -199,7 +206,7 @@ def list_packages_and_modules( return pkgs_and_modules -def secho(i: Identifier, state: str = "success", reason: str = None, op: str = "Registration"): +def secho(i: Identifier, state: str = "success", reason: str = None, op: str = REGISTRATION, console_url: str = None): state_ind = "[ ]" fg = "white" nl = False @@ -207,17 +214,28 @@ def secho(i: Identifier, state: str = "success", reason: str = None, op: str = " state_ind = "\r[✔]" fg = "green" nl = True - reason = f"successful with version {i.version}" if not reason else reason + if not reason: + url_string = click.style(console_url, fg="cyan") + reason = f": {url_string}" if console_url else f" at version: {i.version}" elif state == "failed": state_ind = "\r[x]" fg = "red" nl = True reason = "skipped!" - click.secho( - click.style(f"{state_ind}", fg=fg) + f" {op} {i.name} type {i.resource_type_name()} {reason}", - dim=True, - nl=nl, - ) + if op == REGISTRATION: + name_words = i.resource_type_name().replace("_", " ").split() + name = " ".join(word.capitalize() for word in name_words) + click.secho( + click.style(f"{state_ind}", fg=fg) + f" {name} {i.name}{reason}", + dim=True, + nl=nl, + ) + else: + click.secho( + click.style(f"{state_ind}", fg=fg) + f" {op} {i.name} type {i.resource_type_name()} {reason}", + dim=True, + nl=nl, + ) def register( @@ -295,7 +313,9 @@ def register( serialization_settings.version = version click.secho(f"Computed version is {version}", fg="yellow") - registrable_entities = serialize_get_control_plane_entities(serialization_settings, str(detected_root), options) + registrable_entities = serialize_get_control_plane_entities( + serialization_settings, str(detected_root), options, is_registration=True + ) FlyteContextManager.pop_context() if len(registrable_entities) == 0: @@ -315,7 +335,9 @@ def _raw_register(cp_entity: FlyteControlPlaneEntity): i = remote.raw_register( cp_entity, serialization_settings, version=version, create_default_launchplan=False ) - secho(i, state="success") + console_url = remote.generate_url_from_id(id=i) + + secho(i, state="success", console_url=console_url) if is_lp and activate_launchplans: secho(og_id, "", op="Activation") remote.activate_launchplan(i) @@ -344,5 +366,3 @@ async def _register(entities: typing.List[task.TaskSpec]): cp_other_entities = list(filter(lambda x: not isinstance(x, task.TaskSpec), registrable_entities)) for entity in cp_other_entities: _raw_register(entity) - - click.secho(f"Successfully registered {len(registrable_entities)} entities", fg="green")