Skip to content

refactor(cli): Rename scripts→cli, integrate defopt#416

Closed
Borda wants to merge 9 commits into
developfrom
cli/defopt
Closed

refactor(cli): Rename scripts→cli, integrate defopt#416
Borda wants to merge 9 commits into
developfrom
cli/defopt

Conversation

@Borda
Copy link
Copy Markdown
Member

@Borda Borda commented May 14, 2026

This pull request introduces a major refactor of the command-line interface (CLI) for the trackers project. The CLI implementation has been moved from the trackers.scripts package, which used argparse, to a new, modular trackers.cli package that leverages the defopt library for command parsing. This change modernizes the codebase, simplifies CLI command definitions, and improves maintainability. Backward compatibility is preserved via shims in the old locations. Additionally, several new CLI modules are introduced, each encapsulating a specific command.

Key changes include:

CLI Refactor and Modernization:

  • Migrated the CLI entry point from trackers.scripts.__main__ to trackers.cli.__main__, now using defopt for argument parsing instead of argparse. The main script now dispatches to subcommands (track, eval, tune, download) as standalone Python functions, improving modularity and testability. [1] [2] [3]
  • Updated the pyproject.toml to add defopt as a required dependency and to point the trackers script entry to the new CLI location.

New CLI Command Modules:

  • Added src/trackers/cli/download.py: Implements the download command for datasets, replacing the previous argparse-based logic with a direct function interface.
  • Added src/trackers/cli/eval.py: Implements the eval command for evaluating tracker predictions, supporting both single-sequence and benchmark modes.
  • Added src/trackers/cli/tune.py: Implements the tune command for hyperparameter optimization using Optuna.
  • Added src/trackers/cli/progress.py: Provides a progress display utility for tracking frame processing, with live updates and error handling.

Backward Compatibility:

  • Introduced shim modules in trackers.scripts (e.g., __main__.py, download.py) that import and expose the new CLI functionality, ensuring existing scripts and user workflows do not break. [1] [2]

Other:

  • Added copyright and license headers to new CLI files for consistency.

These changes collectively modernize the CLI, improve code organization, and set the stage for future extensibility.


  • New trackers/cli/ package: defopt-based entry point, --tracker-params key=val replaces per-param --tracker.<param> flags, typed function signatures on all four subcommands
  • trackers/scripts/ converted to thin backward-compat re-export shims
  • Tests moved from tests/scripts/ to tests/cli/; 75 tests ported/rewritten for defopt API; tests/scripts stubs removed
  • Add defopt>=7.0.0 to dependencies (pulls docutils + sphinxcontrib-napoleon + pockets)
  • Console-scripts entry updated to trackers.cli.__main__:main

resolves #406

- New `trackers/cli/` package: defopt-based entry point, `--tracker-params key=val` replaces per-param `--tracker.<param>` flags, typed function signatures on all four subcommands
- `trackers/scripts/` converted to thin backward-compat re-export shims
- Tests moved from `tests/scripts/` to `tests/cli/`; 75 tests ported/rewritten for defopt API; tests/scripts stubs removed
- Add `defopt>=7.0.0` to dependencies (pulls docutils + sphinxcontrib-napoleon + pockets)
- Console-scripts entry updated to `trackers.cli.__main__:main`

---
Co-authored-by: Claude Code <noreply@anthropic.com>
@socket-security
Copy link
Copy Markdown

socket-security Bot commented May 14, 2026

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

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedmypy@​2.1.076100100100100
Addeddefopt@​7.0.0100100100100100

View full report

@Borda Borda changed the title refactor(cli): Rename scripts→cli, integrate defopt refactor(cli): Rename scripts→cli, integrate defopt May 15, 2026
@Borda Borda added the enhancement New feature or request label May 15, 2026
Borda and others added 8 commits May 20, 2026 22:36
- Patch defopt._create_parser to rewrite --group-field flags to --group.field
  for groups: detection, filters, out, show
- Rename track() params to carry group prefix (detection_model,
  filters_classes, out_mot_results, show_display, etc.)
- Update all docs to use dotted flag syntax

---
Co-authored-by: Claude Code <noreply@anthropic.com>
Extend _rewrite_dotted to match --no-<group>-<rest> and rewrite to
--<group>.no-<rest> (e.g. --no-show-ids → --show.no-ids). Also update
action.negative_option_strings so _BooleanOptionalAction True/False
detection stays correct after the rename.

---
Co-authored-by: Claude Code <noreply@anthropic.com>
- Replace --tracker.param_name style with --tracker-params key=value
  in code blocks and prose
- Remove four non-existent --tracker.* rows from CLI Reference table;
  add single --tracker-params row with key=value description
- Add missing --detections row to CLI Reference table (challenger catch)

---
Co-authored-by: Claude Code <noreply@anthropic.com>
Replace --tracker-params key=value bag with 15 typed individual flags
(--tracker.lost-track-buffer, --tracker.track-activation-threshold,
etc.) by adding "tracker" to _GROUPS and removing _parse_tracker_params.
None-filtering kwargs builder passes only user-supplied values to
_init_tracker so each tracker's own defaults stay authoritative.

- Add tracker to _GROUPS in __main__.py
- Replace tracker_params param with 15 tracker_* typed params in track()
- Remove _parse_tracker_params() helper
- Update docs/learn/track.md CLI examples and reference table

---
Co-authored-by: Claude Code <noreply@anthropic.com>
- Guard `class_id is not None` before `np.isin` in _run_frameless and _run_with_source (AttributeError on empty detections)
- Add `# type: ignore` suppressions for tracked-slice and label_annotator return types
- Add `mypy>=2.1.0` to dev deps; add `defopt` and `inference_models` to mypy ignore_missing_imports

---
Co-authored-by: Claude Code <noreply@anthropic.com>
Resolve two conflicts:
- scripts/tune.py: keep shim (HEAD wins over develop argparse impl)
- tests/scripts/test_tune.py: keep deleted (argparse API removed)

New from develop: defopt dep bump, tuner seeding/fixed-params/#427,
ByteTrack confidence fix (#415), CMC as external module (#414), doc fixes.

---
Co-authored-by: Claude Code <noreply@anthropic.com>
- Add fixed_params, images_dir, enqueue_defaults, seed to tune() signature
- Forward all four to Tuner() constructor call
- Register parsers={dict: json.loads} in defopt.run() so --fixed-params
  accepts a JSON string from the CLI (e.g. '{"enable_cmc": false}')
- Add 4 tests covering param passthrough to Tuner (11 total, all green)

---
Co-authored-by: Claude Code <noreply@anthropic.com>
- Pin defopt to >=7.0.0,<8 to protect monkey-patch against breaking upgrades
- Change detection_model default to None sentinel so explicit --detection.model
  always conflicts with --detections (was silently bypassed when model == DEFAULT_MODEL)
- Add TestTrackerParamSync: asserts every primitive-typed tracker registry param
  appears as tracker_<name> in track(); catches future tracker additions that
  forget to update the signature

---
Co-authored-by: Claude Code <noreply@anthropic.com>
@Borda
Copy link
Copy Markdown
Member Author

Borda commented May 21, 2026

Due to the required arg grouping, it has a similar complexity to the original argparse

@Borda Borda closed this May 21, 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

1 participant