-
Notifications
You must be signed in to change notification settings - Fork 550
Feature/Improved CLI lists with enhanced tables and new formats #3866
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
base: develop
Are you sure you want to change the base?
Changes from 17 commits
f5d863b
78af737
4ecfdfc
6403d92
4514cfc
8f361b6
cd2b987
6604636
cea4272
ebebd80
038940d
7bed4be
bf13b44
fbeef0c
15d2247
783304d
a0b63dd
a36632a
ff9acec
6fb4e3c
79e75a7
4eea33f
8fa6b5a
c383943
783f8eb
81045c5
277e774
932d61d
6ef6bc7
39a7c43
06e2ad5
494df98
ffe3bf1
1ea0f32
0341fd5
44a7b1c
99399c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| [tool.poetry] | ||
| name = "zenml" | ||
| version = "0.84.2" | ||
| packages = [{ include = "zenml", from = "src" }] | ||
| packages = [{ include = "zenml", from = "src" }, { include = "zenml_cli", from = "src" }] | ||
| description = "ZenML: Write production-ready ML code." | ||
| authors = ["ZenML GmbH <[email protected]>"] | ||
| readme = "README.md" | ||
|
|
@@ -38,7 +38,7 @@ exclude = [ | |
| include = ["src/zenml", "*.txt", "*.sh", "*.md"] | ||
|
|
||
| [tool.poetry.scripts] | ||
| zenml = "zenml.cli.cli:cli" | ||
| zenml = "zenml_cli:cli" | ||
|
|
||
| [tool.poetry.dependencies] | ||
| alembic = { version = ">=1.8.1,<=1.15.2" } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,7 +19,13 @@ | |
|
|
||
| from zenml.cli import utils as cli_utils | ||
| from zenml.cli.cli import TagGroup, cli | ||
| from zenml.cli.utils import ( | ||
| enhanced_list_options, | ||
| format_date_for_table, | ||
| prepare_list_data, | ||
| ) | ||
| from zenml.client import Client | ||
| from zenml.console import console | ||
| from zenml.enums import CliCategories | ||
| from zenml.logger import get_logger | ||
| from zenml.models import ArtifactFilter, ArtifactVersionFilter | ||
|
|
@@ -35,25 +41,39 @@ def artifact() -> None: | |
| """Commands for interacting with artifacts.""" | ||
|
|
||
|
|
||
| @cli_utils.list_options(ArtifactFilter) | ||
| @enhanced_list_options(ArtifactFilter) | ||
| @artifact.command("list", help="List all artifacts.") | ||
| def list_artifacts(**kwargs: Any) -> None: | ||
| """List all artifacts. | ||
|
|
||
| Args: | ||
| **kwargs: Keyword arguments to filter artifacts by. | ||
| """ | ||
| artifacts = Client().list_artifacts(**kwargs) | ||
| # Extract table options from kwargs | ||
| table_kwargs = cli_utils.extract_table_options(kwargs) | ||
|
|
||
| with console.status("Listing artifacts..."): | ||
| artifacts = Client().list_artifacts(**kwargs) | ||
|
|
||
| if not artifacts: | ||
| cli_utils.declare("No artifacts found.") | ||
|
||
| return | ||
|
|
||
| to_print = [] | ||
| for artifact in artifacts: | ||
| to_print.append(_artifact_to_print(artifact)) | ||
| # Prepare data based on output format | ||
| output_format = ( | ||
| table_kwargs.get("output") or cli_utils.get_default_output_format() | ||
| ) | ||
| artifact_data = [] | ||
|
|
||
| # Use centralized data preparation | ||
| artifact_data = prepare_list_data( | ||
| artifacts.items, output_format, _artifact_to_print | ||
| ) | ||
|
|
||
| cli_utils.print_table(to_print) | ||
| # Handle table output with enhanced system and pagination | ||
|
||
| cli_utils.handle_table_output( | ||
| artifact_data, page=artifacts, **table_kwargs | ||
| ) | ||
|
|
||
|
|
||
| @artifact.command("update", help="Update an artifact.") | ||
|
|
@@ -115,25 +135,39 @@ def version() -> None: | |
| """Commands for interacting with artifact versions.""" | ||
|
|
||
|
|
||
| @cli_utils.list_options(ArtifactVersionFilter) | ||
| @enhanced_list_options(ArtifactVersionFilter) | ||
| @version.command("list", help="List all artifact versions.") | ||
| def list_artifact_versions(**kwargs: Any) -> None: | ||
| """List all artifact versions. | ||
|
|
||
| Args: | ||
| **kwargs: Keyword arguments to filter artifact versions by. | ||
| """ | ||
| artifact_versions = Client().list_artifact_versions(**kwargs) | ||
| # Extract table options from kwargs | ||
| table_kwargs = cli_utils.extract_table_options(kwargs) | ||
|
|
||
| with console.status("Listing artifact versions..."): | ||
| artifact_versions = Client().list_artifact_versions(**kwargs) | ||
|
|
||
| if not artifact_versions: | ||
| cli_utils.declare("No artifact versions found.") | ||
| return | ||
|
|
||
| to_print = [] | ||
| for artifact_version in artifact_versions: | ||
| to_print.append(_artifact_version_to_print(artifact_version)) | ||
| # Prepare data based on output format | ||
| output_format = ( | ||
| table_kwargs.get("output") or cli_utils.get_default_output_format() | ||
| ) | ||
| artifact_version_data = [] | ||
|
|
||
| cli_utils.print_table(to_print) | ||
| # Use centralized data preparation | ||
| artifact_version_data = prepare_list_data( | ||
| artifact_versions.items, output_format, _artifact_version_to_print | ||
| ) | ||
|
|
||
| # Handle table output with enhanced system and pagination | ||
| cli_utils.handle_table_output( | ||
| artifact_version_data, page=artifact_versions, **table_kwargs | ||
| ) | ||
|
|
||
|
|
||
| @version.command("update", help="Update an artifact version.") | ||
|
|
@@ -296,26 +330,71 @@ def prune_artifacts( | |
| cli_utils.declare("All unused artifacts and artifact versions deleted.") | ||
|
|
||
|
|
||
| def _artifact_to_print(artifact: ArtifactResponse) -> Dict[str, Any]: | ||
| """Convert an artifact response to a dictionary suitable for table display. | ||
|
|
||
| For table output, keep it compact with essential artifact information. | ||
| Full details are available in JSON/YAML output formats. | ||
|
|
||
| Args: | ||
| artifact: Artifact response object | ||
|
|
||
| Returns: | ||
| Dictionary containing formatted artifact data for table display | ||
| """ | ||
| return { | ||
| "name": artifact.name, | ||
| "tags": [t.name for t in artifact.tags] if artifact.tags else [], | ||
| "created": format_date_for_table(artifact.created), | ||
| } | ||
|
|
||
|
|
||
| def _artifact_to_print_full(artifact: ArtifactResponse) -> Dict[str, Any]: | ||
| """Convert artifact response to complete dictionary for JSON/YAML. | ||
|
|
||
| Args: | ||
| artifact: Artifact response object | ||
|
|
||
| Returns: | ||
| Complete dictionary containing all artifact data | ||
| """ | ||
| return artifact.model_dump(mode="json") | ||
|
|
||
|
|
||
| def _artifact_version_to_print( | ||
| artifact_version: ArtifactVersionResponse, | ||
| ) -> Dict[str, Any]: | ||
| """Convert artifact version response to dictionary for table display. | ||
|
|
||
| For table output, keep it compact with essential version information. | ||
| Full details are available in JSON/YAML output formats. | ||
|
|
||
| Args: | ||
| artifact_version: Artifact version response object | ||
|
|
||
| Returns: | ||
| Dictionary containing formatted artifact version data for table display | ||
| """ | ||
| return { | ||
| "id": artifact_version.id, | ||
| "name": artifact_version.artifact.name, | ||
| "version": artifact_version.version, | ||
| "uri": artifact_version.uri, | ||
| "type": artifact_version.type, | ||
| "materializer": artifact_version.materializer, | ||
| "data_type": artifact_version.data_type, | ||
| "tags": [t.name for t in artifact_version.tags], | ||
| "tags": [t.name for t in artifact_version.tags] | ||
| if artifact_version.tags | ||
| else [], | ||
| "created": format_date_for_table(artifact_version.created), | ||
| } | ||
|
|
||
|
|
||
| def _artifact_to_print( | ||
| artifact_version: ArtifactResponse, | ||
| def _artifact_version_to_print_full( | ||
| artifact_version: ArtifactVersionResponse, | ||
| ) -> Dict[str, Any]: | ||
| return { | ||
| "id": artifact_version.id, | ||
| "name": artifact_version.name, | ||
| "tags": [t.name for t in artifact_version.tags], | ||
| } | ||
| """Convert artifact version response to complete dictionary for JSON/YAML. | ||
|
|
||
| Args: | ||
| artifact_version: Artifact version response object | ||
|
|
||
| Returns: | ||
| Complete dictionary containing all artifact version data | ||
| """ | ||
| return artifact_version.model_dump(mode="json") | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh really