-
Notifications
You must be signed in to change notification settings - Fork 1
Enhance README with installation instructions and refactor aim query … #4
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
Changes from all commits
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,3 +1,3 @@ | ||
| __all__ = ["__version__"] | ||
|
|
||
| __version__ = "0.1.0" | ||
| __version__ = "0.2.0" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,10 +5,6 @@ | |
| from pathlib import Path | ||
| from typing import Any | ||
|
|
||
| from aim import Repo | ||
| from aim.sdk.types import QueryReportMode | ||
|
|
||
|
|
||
| SUPPORTED_TARGETS = {"metrics", "images"} | ||
|
|
||
|
|
||
|
|
@@ -35,6 +31,18 @@ class QueryCommandResult: | |
| error_message: str | None = None | ||
|
|
||
|
|
||
| def load_aim_query_support(): | ||
|
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. |
||
| try: | ||
| from aim import Repo | ||
| from aim.sdk.types import QueryReportMode | ||
| except ModuleNotFoundError as error: | ||
| raise RuntimeError( | ||
| "`aimx query` requires the Python `aim` package in the current environment." | ||
| ) from error | ||
|
|
||
| return Repo, QueryReportMode | ||
|
|
||
|
|
||
| def normalize_repo_path(path: Path) -> Path: | ||
| if not path.exists(): | ||
| raise ValueError(f"Repository path does not exist: {path}") | ||
|
|
@@ -108,6 +116,7 @@ def run_query_command(args: list[str]) -> QueryCommandResult: | |
|
|
||
|
|
||
| def collect_query_rows(invocation: QueryInvocation, repo_path: Path) -> list[dict[str, Any]]: | ||
| Repo, QueryReportMode = load_aim_query_support() | ||
| repo = Repo(str(repo_path)) | ||
|
|
||
| if invocation.target == "metrics": | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,42 @@ | ||||||
| from __future__ import annotations | ||||||
|
|
||||||
| import importlib | ||||||
| import sys | ||||||
|
|
||||||
|
|
||||||
| def _reload_main_without_python_aim(monkeypatch): | ||||||
| monkeypatch.setitem(sys.modules, "aim", None) | ||||||
| monkeypatch.delitem(sys.modules, "aim.sdk", raising=False) | ||||||
| monkeypatch.delitem(sys.modules, "aim.sdk.types", raising=False) | ||||||
| sys.modules.pop("aimx.__main__", None) | ||||||
| sys.modules.pop("aimx.cli", None) | ||||||
| sys.modules.pop("aimx.commands.query", None) | ||||||
| return importlib.import_module("aimx.__main__").main | ||||||
|
|
||||||
|
|
||||||
| def test_owned_commands_still_work_when_python_aim_package_is_missing( | ||||||
| capsys, monkeypatch | ||||||
| ) -> None: | ||||||
| monkeypatch.setenv("PATH", "") | ||||||
|
|
||||||
| main = _reload_main_without_python_aim(monkeypatch) | ||||||
| exit_code = main(["version"]) | ||||||
|
|
||||||
| captured = capsys.readouterr() | ||||||
| assert exit_code == 0 | ||||||
| assert "aimx 0.1.0" in captured.out | ||||||
|
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. The version string in this assertion is outdated. Since the project version was bumped to
Suggested change
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.
This test hard-codes Useful? React with 👍 / 👎. |
||||||
|
|
||||||
|
|
||||||
| def test_query_reports_actionable_error_when_python_aim_package_is_missing( | ||||||
| capsys, monkeypatch, tmp_path | ||||||
| ) -> None: | ||||||
| monkeypatch.setenv("PATH", "") | ||||||
|
|
||||||
| main = _reload_main_without_python_aim(monkeypatch) | ||||||
| exit_code = main( | ||||||
| ["query", "metrics", "metric.name == 'loss'", "--repo", str(tmp_path)] | ||||||
| ) | ||||||
|
|
||||||
| captured = capsys.readouterr() | ||||||
| assert exit_code == 2 | ||||||
| assert "requires the Python `aim` package" in captured.err | ||||||
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.
For a CLI tool like
aimx,uv tool installis generally the recommended way to install it for global use, rather thanuv addwhich is intended for project dependencies. Consider updating the recommendation to reflect this best practice.