-
Notifications
You must be signed in to change notification settings - Fork 4
[caliper] Progress with the parser and plotter #57
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: main
Are you sure you want to change the base?
Changes from all commits
7a3f61e
7a0dbe9
d40b69a
9351e03
9c65fe3
376bcbb
4e2e5d1
c745d7f
9ff0975
427a3a5
5b56f98
2f2af26
e449b9d
676bb5f
da0cfaf
ed039a3
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 | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -60,7 +60,7 @@ def _require_artifacts_dir(ctx: click.Context) -> Path: | |||||||||||||||||||||||||||||
| _exit_with_help( | ||||||||||||||||||||||||||||||
| ctx, | ||||||||||||||||||||||||||||||
| "This command requires the test artifact tree root: " | ||||||||||||||||||||||||||||||
| "`--artifacts-dir DIR` or `--base-dir DIR` " | ||||||||||||||||||||||||||||||
| "`--artifacts-dir DIR` " | ||||||||||||||||||||||||||||||
| "(before or after the subcommand).", | ||||||||||||||||||||||||||||||
| code=1, | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
|
|
@@ -89,7 +89,6 @@ def _workspace_cli_options(cmd: Any) -> Any: | |||||||||||||||||||||||||||||
| opts = ( | ||||||||||||||||||||||||||||||
| click.option( | ||||||||||||||||||||||||||||||
| "--artifacts-dir", | ||||||||||||||||||||||||||||||
| "--base-dir", | ||||||||||||||||||||||||||||||
| "artifacts_dir", | ||||||||||||||||||||||||||||||
| type=click.Path(path_type=Path, exists=True), | ||||||||||||||||||||||||||||||
| default=None, | ||||||||||||||||||||||||||||||
|
|
@@ -105,12 +104,11 @@ def _workspace_cli_options(cmd: Any) -> Any: | |||||||||||||||||||||||||||||
| help=_POSTPROCESS_CONFIG_HELP + " Overrides the global option when set here.", | ||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||
| click.option( | ||||||||||||||||||||||||||||||
| "--plugin-module", | ||||||||||||||||||||||||||||||
| "--plugin", | ||||||||||||||||||||||||||||||
| "plugin_module_override", | ||||||||||||||||||||||||||||||
| metavar="MODULE", | ||||||||||||||||||||||||||||||
| default=None, | ||||||||||||||||||||||||||||||
| help="Plugin import path; same as global --plugin-module / --plugin.", | ||||||||||||||||||||||||||||||
| help="Plugin import path; same as global --plugin.", | ||||||||||||||||||||||||||||||
| ), | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| for opt in reversed(opts): | ||||||||||||||||||||||||||||||
|
|
@@ -141,7 +139,6 @@ def _plugin_tuple(ctx: click.Context) -> tuple[str, Any]: | |||||||||||||||||||||||||||||
| @click.group(context_settings={"help_option_names": ["-h", "--help"]}) | ||||||||||||||||||||||||||||||
| @click.option( | ||||||||||||||||||||||||||||||
| "--artifacts-dir", | ||||||||||||||||||||||||||||||
| "--base-dir", | ||||||||||||||||||||||||||||||
| "artifacts_dir", | ||||||||||||||||||||||||||||||
| type=click.Path(path_type=Path, exists=True), | ||||||||||||||||||||||||||||||
| default=None, | ||||||||||||||||||||||||||||||
|
|
@@ -154,7 +151,6 @@ def _plugin_tuple(ctx: click.Context) -> tuple[str, Any]: | |||||||||||||||||||||||||||||
| help=_POSTPROCESS_CONFIG_HELP, | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| @click.option( | ||||||||||||||||||||||||||||||
| "--plugin-module", | ||||||||||||||||||||||||||||||
| "--plugin", | ||||||||||||||||||||||||||||||
| "plugin_module", | ||||||||||||||||||||||||||||||
| metavar="MODULE", | ||||||||||||||||||||||||||||||
|
|
@@ -360,7 +356,7 @@ def kpi_analyze( | |||||||||||||||||||||||||||||
| @main.group("artifacts") | ||||||||||||||||||||||||||||||
| @click.pass_context | ||||||||||||||||||||||||||||||
| def artifacts_group(ctx: click.Context) -> None: | ||||||||||||||||||||||||||||||
| """File artifact export.""" | ||||||||||||||||||||||||||||||
| """File artifact export and import.""" | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @artifacts_group.command("export") | ||||||||||||||||||||||||||||||
|
|
@@ -521,14 +517,87 @@ def ai_eval_export( | |||||||||||||||||||||||||||||
| plugin=plugin, | ||||||||||||||||||||||||||||||
| output=output, | ||||||||||||||||||||||||||||||
| use_cache=True, | ||||||||||||||||||||||||||||||
| cache_path=None, | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| except Exception as e: # noqa: BLE001 | ||||||||||||||||||||||||||||||
| click.echo(f"ai-eval-export failed: {e}", err=True) | ||||||||||||||||||||||||||||||
| sys.exit(2) | ||||||||||||||||||||||||||||||
| click.echo(f"Wrote {output}") | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| @artifacts_group.command("import") | ||||||||||||||||||||||||||||||
| @click.option("--from-mlflow", "mlflow_run_id", help="MLflow run ID to download artifacts from.") | ||||||||||||||||||||||||||||||
| @click.option( | ||||||||||||||||||||||||||||||
| "--output-dir", | ||||||||||||||||||||||||||||||
| type=click.Path(path_type=Path), | ||||||||||||||||||||||||||||||
| required=True, | ||||||||||||||||||||||||||||||
| help="Local directory to download artifacts to.", | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| @click.option( | ||||||||||||||||||||||||||||||
| "--mlflow-tracking-uri", | ||||||||||||||||||||||||||||||
| envvar="MLFLOW_TRACKING_URI", | ||||||||||||||||||||||||||||||
| help="MLflow tracking server URI (can be set via MLFLOW_TRACKING_URI).", | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| @click.option( | ||||||||||||||||||||||||||||||
| "--artifact-path", | ||||||||||||||||||||||||||||||
| default="", | ||||||||||||||||||||||||||||||
| help="Specific artifact path to download (default: download all artifacts).", | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| @click.pass_context | ||||||||||||||||||||||||||||||
| def import_command( | ||||||||||||||||||||||||||||||
| ctx: click.Context, | ||||||||||||||||||||||||||||||
| mlflow_run_id: str | None, | ||||||||||||||||||||||||||||||
| output_dir: Path, | ||||||||||||||||||||||||||||||
| mlflow_tracking_uri: str | None, | ||||||||||||||||||||||||||||||
| artifact_path: str, | ||||||||||||||||||||||||||||||
| ) -> None: | ||||||||||||||||||||||||||||||
| """Download artifact files from MLflow.""" | ||||||||||||||||||||||||||||||
| if mlflow_run_id: | ||||||||||||||||||||||||||||||
| if not mlflow_tracking_uri: | ||||||||||||||||||||||||||||||
| click.echo( | ||||||||||||||||||||||||||||||
| "Error: MLflow tracking URI required. Set --mlflow-tracking-uri or MLFLOW_TRACKING_URI.", | ||||||||||||||||||||||||||||||
| err=True, | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
| sys.exit(1) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||
| import mlflow | ||||||||||||||||||||||||||||||
| from mlflow.tracking import MlflowClient | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Set tracking URI | ||||||||||||||||||||||||||||||
| mlflow.set_tracking_uri(mlflow_tracking_uri) | ||||||||||||||||||||||||||||||
| client = MlflowClient() | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Download artifacts | ||||||||||||||||||||||||||||||
| output_dir.mkdir(parents=True, exist_ok=True) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Download artifacts to the output directory | ||||||||||||||||||||||||||||||
| downloaded_path = client.download_artifacts( | ||||||||||||||||||||||||||||||
| run_id=mlflow_run_id, path=artifact_path, dst_path=str(output_dir) | ||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| # Count downloaded files | ||||||||||||||||||||||||||||||
| if Path(downloaded_path).is_file(): | ||||||||||||||||||||||||||||||
| downloaded_files = [Path(downloaded_path)] | ||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||
| downloaded_files = list(Path(downloaded_path).rglob("*")) | ||||||||||||||||||||||||||||||
| downloaded_files = [f for f in downloaded_files if f.is_file()] | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| click.echo(f"Downloaded {len(downloaded_files)} files to {output_dir}") | ||||||||||||||||||||||||||||||
| if downloaded_files: | ||||||||||||||||||||||||||||||
| click.echo("Downloaded files:") | ||||||||||||||||||||||||||||||
| for file in downloaded_files[:10]: # Show first 10 | ||||||||||||||||||||||||||||||
| click.echo(f" {file.relative_to(output_dir)}") | ||||||||||||||||||||||||||||||
| if len(downloaded_files) > 10: | ||||||||||||||||||||||||||||||
| click.echo(f" ... and {len(downloaded_files) - 10} more") | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| except Exception as e: # noqa: BLE001 | ||||||||||||||||||||||||||||||
| click.echo(f"artifacts import failed: {e}", err=True) | ||||||||||||||||||||||||||||||
| sys.exit(2) | ||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||
| click.echo("Error: Specify source backend: --from-mlflow RUN_ID", err=True) | ||||||||||||||||||||||||||||||
| sys.exit(1) | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| def run_cli() -> None: | ||||||||||||||||||||||||||||||
| """Invoke CLI; on missing required options, print subcommand help.""" | ||||||||||||||||||||||||||||||
| try: | ||||||||||||||||||||||||||||||
|
|
@@ -537,14 +606,13 @@ def run_cli() -> None: | |||||||||||||||||||||||||||||
| rv = main.main(standalone_mode=False, prog_name="caliper") | ||||||||||||||||||||||||||||||
| if isinstance(rv, int) and rv != 0: | ||||||||||||||||||||||||||||||
| sys.exit(rv) | ||||||||||||||||||||||||||||||
| except click.MissingParameter as exc: | ||||||||||||||||||||||||||||||
| msg = exc.format_message() | ||||||||||||||||||||||||||||||
| sub = getattr(exc, "ctx", None) | ||||||||||||||||||||||||||||||
| click.echo(f"Error: {msg}\n", err=True) | ||||||||||||||||||||||||||||||
| if sub is not None: | ||||||||||||||||||||||||||||||
| click.echo(sub.get_help(), err=True) | ||||||||||||||||||||||||||||||
| ec = getattr(exc, "exit_code", 2) | ||||||||||||||||||||||||||||||
| sys.exit(2 if ec is None else int(ec)) | ||||||||||||||||||||||||||||||
| except click.ClickException as exc: | ||||||||||||||||||||||||||||||
| # Handle click exceptions including NoArgsIsHelpError and MissingParameter | ||||||||||||||||||||||||||||||
| if hasattr(exc, "ctx") and exc.ctx: | ||||||||||||||||||||||||||||||
| click.echo(exc.ctx.get_help(), err=True) | ||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||
| exc.show(sys.stderr) | ||||||||||||||||||||||||||||||
| sys.exit(2) | ||||||||||||||||||||||||||||||
|
Comment on lines
+609
to
+615
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🌐 Web query:
💡 Result: In Click 8.1.0, click.Context.get_help does NOT include the original exception text for MissingParameter or NoSuchOption. In other words, exc.show(...) is required if you want the exception’s message (e.g., the “Missing parameter …” or “No such option …” text) to be preserved and displayed. Reasoning grounded in the code: - Context.get_help just returns the formatted help page generated from the command (it calls command.get_help/format_help) and has no access to any active exception or its message. [1] - ClickException.show is the method responsible for rendering the exception message to stderr/file (including adding the “Try '… --help' for help” hint and then echoing “Error: {message}”). [2] - MissingParameter and NoSuchOption both implement their own message formatting via ClickException.format_message / str logic (so the message lives on the exception object, not on the help text). [2] So: if you call ctx.get_help (or command.get_help(ctx)) in an exception handler without also showing the exception, you will get only usage/help text, not the original exception message; to include it you must call exc.show(...). Citations:
Preserve error messages when showing help for Click exceptions. When Proposed fix except click.ClickException as exc:
- # Handle click exceptions including NoArgsIsHelpError and MissingParameter
- if hasattr(exc, "ctx") and exc.ctx:
- click.echo(exc.ctx.get_help(), err=True)
- else:
- exc.show(sys.stderr)
+ # Preserve Click's error text, then add command help when available.
+ exc.show(sys.stderr)
+ if getattr(exc, "ctx", None):
+ click.echo("", err=True)
+ click.echo(exc.ctx.get_help(), err=True)
sys.exit(2)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| except SystemExit: | ||||||||||||||||||||||||||||||
| raise | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.