refactor(cli): rename scripts→cli, add jsonargparse with --config YAML support#413
Draft
Borda wants to merge 2 commits into
Draft
refactor(cli): rename scripts→cli, add jsonargparse with --config YAML support#413Borda wants to merge 2 commits into
jsonargparse with --config YAML support#413Borda wants to merge 2 commits into
Conversation
- Rename `trackers/scripts/` → `trackers/cli/` and update `pyproject.toml` entry point to `trackers.cli.__main__:main` - Replace `argparse.ArgumentParser` with `jsonargparse.ArgumentParser` in `__main__.py`; all subcommand parsers now use `jsonargparse.DefaultHelpFormatter` - Add `--config` argument with `action="config"` — any subcommand run can now be specified as a YAML file (e.g. `trackers track --config run.yaml`) - Update handler type annotations from `argparse.Namespace` to `jsonargparse.Namespace`; `_add_tracker_params` / `add_*_subparser` use `Any` to accept both argparse and jsonargparse subparser objects - Add `jsonargparse>=4.48.0` to core dependencies; only transitive dep is PyYAML (depth 1, zero own deps) - Migrate all tests from `tests/scripts/` → `tests/cli/`; update patch paths (`trackers.scripts.*` → `trackers.cli.*`) --- Co-authored-by: Claude Code <noreply@anthropic.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors the trackers command-line interface by moving it from trackers/scripts into a dedicated trackers/cli package and switching the parsing backend from argparse to jsonargparse, with the goal of enabling config-file driven runs.
Changes:
- Migrated CLI modules from
trackers/scripts/totrackers/cli/and updated the console entry point. - Replaced
argparseusage withjsonargparseacross CLI commands and introduced a--configoption. - Updated CLI tests to import/patch the new
trackers.cli.*module paths.
Reviewed changes
Copilot reviewed 11 out of 14 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| uv.lock | Adds resolved dependency entries for jsonargparse and updates the locked dependency set. |
| pyproject.toml | Adds jsonargparse to core deps and updates console script entry point to trackers.cli.__main__:main. |
| src/trackers/cli/init.py | Introduces the new CLI package. |
| src/trackers/cli/main.py | New CLI entry point using jsonargparse, adds --config, registers subcommands. |
| src/trackers/cli/track.py | Migrates track subcommand to jsonargparse and adjusts dynamic tracker-param registration. |
| src/trackers/cli/eval.py | Migrates eval subcommand to jsonargparse. |
| src/trackers/cli/tune.py | Migrates tune subcommand to jsonargparse. |
| src/trackers/cli/download.py | Migrates download subcommand to jsonargparse. |
| src/trackers/cli/progress.py | Adds progress/source-classification utilities under the new CLI package. |
| tests/cli/init.py | Adds the tests/cli package marker. |
| tests/cli/test_track.py | Updates imports to trackers.cli.track. |
| tests/cli/test_eval.py | (Not shown in diff excerpt) If present in PR, validates eval CLI behavior against new module path. |
| tests/cli/test_tune.py | Updates imports/patch paths to trackers.cli.tune. |
| tests/cli/test_download.py | Updates imports/patch paths to trackers.cli.download. |
| tests/cli/test_progress.py | Updates imports/patch paths to trackers.cli.progress. |
Comments suppressed due to low confidence (3)
src/trackers/cli/track.py:262
_add_tracker_paramsnow wrapsgroup.add_argument(...)insuppress(Exception), which will silently hide any error (e.g. invalidtype, bad kwargs, API changes) and can result in tracker parameters not being exposed on the CLI with no signal. This previously only ignored duplicate-argument errors. Please narrow the suppression to the specific expected exception raised for duplicate options (and consider logging/debug output when a param is skipped).
src/trackers/cli/main.py:39--configis added only to the top-level parser. With subcommands, options defined on the parent parser are typically only accepted before the subcommand (e.g.trackers --config run.yaml track ...), while the PR description claimstrackers track --config run.yamlshould work. If the intent is to allow--configafter the subcommand, it likely needs to be registered on each subparser (or provided viaparents=[...]when creating subparsers) / otherwise document the supported ordering explicitly.
src/trackers/cli/main.py:39- The new config-file feature (
--config,action="config") is a key behavior change but there are no CLI tests covering parsing/precedence from a YAML/JSON config (e.g. verifying config values are applied and CLI args override config). Adding a focused test would help prevent regressions injsonargparseintegration and confirm the documented invocation works.
| @@ -41,14 +41,15 @@ dependencies = [ | |||
| "opencv-python>=4.8.0", | |||
| "rich>=13.0.0", | |||
| "requests>=2.28.0", | |||
- replace add_subparsers boilerplate with CLI({"track": ..., "eval": ..., "tune": ..., "download": ...}) on typed entry points; subcommands and --config YAML are derived automatically from function signatures
- track.py: collapse 735→547 lines by dropping argparse plumbing; group dynamic per-tracker overrides under a TrackerParams dataclass (--tracker_params.<name>=...) so jsonargparse renders one nested help group
- __main__.py: 76→40 lines; main() now warns, dispatches via CLI, and returns the entry-point exit code
- download.py: positional `dataset` becomes `--dataset` (jsonargparse has no positionals); `--list` renamed to `--list_available`
- update tests/cli/test_download.py and test_tune.py to call the new typed functions directly and exercise the CLI via jsonargparse.CLI(...args=[...]) instead of constructing argparse subparsers
- 498 non-integration tests pass; all five `--help` screens render
---
Co-authored-by: Claude Code <noreply@anthropic.com>
jsonargparse with --config YAML support
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request migrates the CLI implementation from
argparsetojsonargparse, restructures the CLI code into a newtrackers/clipackage, and updates all related imports and tests accordingly. The changes improve configuration flexibility (including config file support), streamline argument parsing, and modernize the CLI codebase.Migration to
jsonargparseand CLI Refactor:Switched from
argparsetojsonargparsein all CLI modules, enabling advanced features such as config file parsing and improved help formatting. All CLI entrypoints and subcommands now usejsonargparse.ArgumentParserand related types. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16]Added support for loading CLI arguments from YAML/JSON config files via a new
--configoption.Codebase Restructuring:
Moved all CLI-related modules from
trackers/scripts/to a newtrackers/cli/package and updated all internal and test imports to reflect the new structure. [1] [2] [3] [4] [5] [6]Updated the main entry point in
pyproject.tomlto point totrackers.cli.__main__:maininstead of the old scripts location.Test Suite Updates:
trackers.clipackage path. [1] [2] [3] [4] [5] [6] [7] [8] [9]Dependency Updates:
jsonargparse>=4.48.0as a required dependency to support the new CLI implementation.Other:
tests/cli/__init__.py.trackers/scripts/→trackers/cli/and updatepyproject.tomlentry point totrackers.cli.__main__:mainargparse.ArgumentParserwithjsonargparse.ArgumentParserin__main__.py; all subcommand parsers now usejsonargparse.DefaultHelpFormatter--configargument withaction="config"— any subcommand run can now be specified as a YAML file (e.g.trackers track --config run.yaml)argparse.Namespacetojsonargparse.Namespace;_add_tracker_params/add_*_subparseruseAnyto accept both argparse and jsonargparse subparser objectsjsonargparse>=4.48.0to core dependencies; only transitive dep is PyYAML (depth 1, zero own deps)tests/scripts/→tests/cli/; update patch paths (trackers.scripts.*→trackers.cli.*)resolves #406