Skip to content

refactor(cli): rename scripts→cli, add jsonargparse with --config YAML support#413

Draft
Borda wants to merge 2 commits into
developfrom
cli/jsonargparse
Draft

refactor(cli): rename scripts→cli, add jsonargparse with --config YAML support#413
Borda wants to merge 2 commits into
developfrom
cli/jsonargparse

Conversation

@Borda
Copy link
Copy Markdown
Member

@Borda Borda commented May 12, 2026

This pull request migrates the CLI implementation from argparse to jsonargparse, restructures the CLI code into a new trackers/cli package, 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 jsonargparse and CLI Refactor:

  • Switched from argparse to jsonargparse in all CLI modules, enabling advanced features such as config file parsing and improved help formatting. All CLI entrypoints and subcommands now use jsonargparse.ArgumentParser and 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 --config option.

Codebase Restructuring:

  • Moved all CLI-related modules from trackers/scripts/ to a new trackers/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.toml to point to trackers.cli.__main__:main instead of the old scripts location.

Test Suite Updates:

  • Renamed and updated all CLI-related test files and mocks to use the new trackers.cli package path. [1] [2] [3] [4] [5] [6] [7] [8] [9]

Dependency Updates:

  • Added jsonargparse>=4.48.0 as a required dependency to support the new CLI implementation.

Other:

  • Added a license header to tests/cli/__init__.py.

  • 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.*)

resolves #406

- 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>
Copilot AI review requested due to automatic review settings May 12, 2026 13:16
@Borda Borda requested a review from SkalskiP as a code owner May 12, 2026 13:16
@socket-security
Copy link
Copy Markdown

socket-security Bot commented May 12, 2026

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedjsonargparse@​4.48.097100100100100

View full report

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/ to trackers/cli/ and updated the console entry point.
  • Replaced argparse usage with jsonargparse across CLI commands and introduced a --config option.
  • 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_params now wraps group.add_argument(...) in suppress(Exception), which will silently hide any error (e.g. invalid type, 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
  • --config is 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 claims trackers track --config run.yaml should work. If the intent is to allow --config after the subcommand, it likely needs to be registered on each subparser (or provided via parents=[...] 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 in jsonargparse integration and confirm the documented invocation works.

Comment thread pyproject.toml
@@ -41,14 +41,15 @@ dependencies = [
"opencv-python>=4.8.0",
"rich>=13.0.0",
"requests>=2.28.0",
@Borda Borda marked this pull request as draft May 12, 2026 13:55
- 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>
@Borda Borda changed the title rename scripts→cli, add jsonargparse with --config YAML support refactor(cli): rename scripts→cli, add jsonargparse with --config YAML support May 12, 2026
@Borda Borda changed the title refactor(cli): rename scripts→cli, add jsonargparse with --config YAML support refactor(cli): rename scripts→cli, add jsonargparse with --config YAML support May 15, 2026
@Borda Borda added the enhancement New feature or request label May 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor trackers/scriptstrackers/cli and evaluate CLI framework

3 participants