Skip to content

Conversation

@Borda
Copy link
Member

@Borda Borda commented Jan 7, 2026

This pull request refactors the command-line interface (CLI) handling in both inference_example.py and ultralytics_example.py for the traffic analysis examples. The main improvement is replacing the previous argparse-based CLI with a more flexible approach that prefers jsonargparse if available, while providing a fallback to positional arguments for environments where jsonargparse is not installed. Additionally, the main execution logic is moved into a dedicated main function in each script, improving modularity and readability.

CLI refactoring and flexibility:

  • Replaced the argparse-based CLI with logic that first attempts to use jsonargparse for argument parsing, falling back to simple positional arguments if jsonargparse is unavailable. This makes the scripts more robust and user-friendly in different environments. [1] [2]
  • Moved the script logic into a dedicated main function in both inference_example.py and ultralytics_example.py, improving code organization and enabling easier reuse and testing. [1] [2]

Imports and dependencies:

  • Updated imports to remove argparse and add sys, reflecting the new CLI handling approach. [1] [2]

Part of #2090

Copilot AI review requested due to automatic review settings January 7, 2026 20:58
@Borda Borda requested a review from SkalskiP as a code owner January 7, 2026 20:58
Copy link
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

This pull request refactors the CLI argument handling in traffic analysis examples by replacing argparse with a flexible approach that uses jsonargparse when available and falls back to positional arguments otherwise. The main execution logic is extracted into dedicated main() functions for improved modularity.

Key changes:

  • Replaced argparse with conditional jsonargparse usage, falling back to positional arguments when unavailable
  • Extracted script logic into main() functions with proper type hints and docstrings
  • Updated imports to use sys instead of argparse

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.

File Description
examples/traffic_analysis/ultralytics_example.py Refactored CLI to use jsonargparse with positional fallback; extracted main() function for YOLO-based traffic analysis
examples/traffic_analysis/inference_example.py Refactored CLI to use jsonargparse with positional fallback; extracted main() function for Inference-based traffic analysis

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

def main(
source_weights_path: str,
source_video_path: str,
target_video_path: str,
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The target_video_path parameter should be optional with a default value of None to maintain backward compatibility with the previous argparse implementation. The original argparse version had default=None for this parameter. Without making it optional, this is a breaking API change.

Copilot uses AI. Check for mistakes.
api_key = args.roboflow_api_key
def main(
source_video_path: str,
target_video_path: str,
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The target_video_path parameter should be optional with a default value of None to maintain backward compatibility with the previous argparse implementation. The original argparse version had default=None for this parameter. Without making it optional, this is a breaking API change.

Copilot uses AI. Check for mistakes.
Args:
source_video_path: Path to the source video file
target_video_path: Path to the target video file (output)
roboflow_api_key: Roboflow API key
Copy link

Copilot AI Jan 7, 2026

Choose a reason for hiding this comment

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

The documentation incorrectly describes roboflow_api_key as "Roboflow API key" without noting that it can be None and will fall back to the environment variable ROBOFLOW_API_KEY. The function logic on lines 202-209 shows that roboflow_api_key can be None and will use os.environ.get("ROBOFLOW_API_KEY", api_key) as a fallback. The documentation should clarify that this parameter is optional when the environment variable is set.

Copilot uses AI. Check for mistakes.
@codecov
Copy link

codecov bot commented Jan 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 52%. Comparing base (8df7aea) to head (3646830).
⚠️ Report is 6 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff           @@
##           develop   #2059   +/-   ##
=======================================
  Coverage       52%     52%           
=======================================
  Files           61      61           
  Lines         7077    7076    -1     
=======================================
  Hits          3657    3657           
+ Misses        3420    3419    -1     
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Borda Borda changed the title refactor(traffic_analysis): improve CLI argument handling example(traffic_analysis): improve CLI argument handling Jan 12, 2026
@Borda Borda changed the title example(traffic_analysis): improve CLI argument handling examples/traffic_analysis: improve CLI argument handling Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants