Skip to content

Feat/cli timeout flag#32

Open
John-1-1-1 wants to merge 5 commits into
pipe1os:mainfrom
John-1-1-1:feat/cli-timeout-flag
Open

Feat/cli timeout flag#32
John-1-1-1 wants to merge 5 commits into
pipe1os:mainfrom
John-1-1-1:feat/cli-timeout-flag

Conversation

@John-1-1-1

@John-1-1-1 John-1-1-1 commented Jun 18, 2026

Copy link
Copy Markdown
  • Added --timeout argument.
  • Passed this argument down through analyze_model to fetch_huggingface_repo.
  • Replaced the hardcoded 10 with the user-provided timeout value.
  • Added test cases to verify the configurable timeout logic.

Summary by CodeRabbit

  • New Features

    • Added --timeout CLI argument to configure the network request timeout for Hugging Face Hub operations (defaults to 10.0 seconds).
  • Documentation

    • Updated the command reference to include the new --timeout option and example values.
  • Tests

    • Added tests to verify --timeout is accepted by the CLI and correctly applied to Hugging Face fetch calls.

@coderabbitai

coderabbitai Bot commented Jun 18, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b451df73-b014-419b-9cd0-d603bf02f039

📥 Commits

Reviewing files that changed from the base of the PR and between 28a86d2 and 6eedf4a.

📒 Files selected for processing (9)
  • .idea/.gitignore
  • .idea/inspectionProfiles/profiles_settings.xml
  • .idea/misc.xml
  • .idea/modelinfo-cli.iml
  • .idea/modules.xml
  • .idea/vcs.xml
  • src/modelinfo/cli.py
  • src/modelinfo/parsers/huggingface.py
  • tests/test_hf_timeout_configurable.py
✅ Files skipped from review due to trivial changes (6)
  • .idea/.gitignore
  • .idea/inspectionProfiles/profiles_settings.xml
  • .idea/misc.xml
  • .idea/vcs.xml
  • .idea/modules.xml
  • .idea/modelinfo-cli.iml

Walkthrough

Adds a --timeout CLI argument (default 10.0 seconds) to configure Hugging Face Hub network request timeouts. The value flows from parse_args through analyze_model into fetch_huggingface_repo, which propagates it to _make_request and _fetch_safetensors_header, replacing all previously hardcoded timeouts across every urlopen call site. Also includes JetBrains IDE configuration files.

Changes

Configurable HF network timeout

Layer / File(s) Summary
HF parser: timeout propagation through all network calls
src/modelinfo/parsers/huggingface.py
_make_request, _fetch_safetensors_header, and fetch_huggingface_repo each gain a timeout: float = 10.0 parameter forwarded to every urlopen call, including the 416-fallback, sharded header fetches, and the single-file HEAD/body path.
CLI --timeout argument wired into analyze_model
src/modelinfo/cli.py
parse_args gains --timeout (default 10.0) with _positive_float validation; analyze_model signature is extended with timeout and passes it to fetch_huggingface_repo; both the multi-file loop and single-file path forward args.timeout.
Tests and README docs
tests/test_hf_timeout_configurable.py, README.md
Two pytest tests verify the CLI accepts --timeout without SystemExit and that fetch_huggingface_repo forwards the timeout to urlopen. README command-reference table documents the new flag.

IDE configuration setup

Layer / File(s) Summary
JetBrains IDE project configuration
.idea/.gitignore, .idea/inspectionProfiles/profiles_settings.xml, .idea/misc.xml, .idea/modelinfo-cli.iml, .idea/modules.xml, .idea/vcs.xml
IDE project files configure the Python module, SDK version (3.14), inspection profiles, Git VCS mappings, and workspace artifact ignores.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Possibly related issues

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is incomplete and does not follow the provided template structure. It lacks required sections such as Summary, Motivation & Context, Type of Change, How Has This Been Tested, and Checklist. Expand the description to follow the template: add a brief summary section, explain motivation/context, check the appropriate type of change (likely New feature), document testing approach with test type checkboxes, and complete the pre-merge checklist.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Feat/cli timeout flag' is related to the main change of adding a configurable --timeout CLI argument to replace hardcoded timeout values.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/test_hf_timeout_configurable.py (2)

7-17: ⚡ Quick win

Assert that CLI actually forwards --timeout into the fetch call.

This test currently proves parsing/execution succeeds, but it does not verify the main→analyze→fetch timeout handoff.

Suggested patch
         try:
             result = main(["--timeout", "20.0", "gpt2"])
             assert result == 0
+            mock_fetch.assert_called_once()
+            assert mock_fetch.call_args.kwargs.get("timeout") == 20.0
         except SystemExit as e:
             pytest.fail(f"CLI failed with SystemExit: {e}. --timeout argument is likely not implemented.")
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_hf_timeout_configurable.py` around lines 7 - 17, The
test_cli_timeout_argument function currently only verifies that the CLI
execution succeeds, but does not actually verify that the --timeout argument
value (20.0) is forwarded to the mocked fetch_huggingface_repo function. After
the main() call completes successfully, add an assertion on mock_fetch to verify
it was called with the timeout parameter set to 20.0. This ensures the timeout
value flows through the entire call chain from CLI parsing through to the actual
fetch function call.

44-45: ⚡ Quick win

Validate timeout on every mocked urlopen invocation, not just the final one.

Using mock_urlopen.call_args checks only the last call, so partial propagation bugs can slip through.

Suggested patch
-        args, kwargs = mock_urlopen.call_args
-        assert kwargs.get('timeout') == 20.0, f"Expected timeout=20.0, but got {kwargs.get('timeout')}"
+        assert mock_urlopen.call_count >= 1
+        for _, kwargs in mock_urlopen.call_args_list:
+            assert kwargs.get("timeout") == 20.0
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/test_hf_timeout_configurable.py` around lines 44 - 45, The current
assertion using mock_urlopen.call_args only validates the timeout on the last
invocation of urlopen. To ensure the timeout is correctly propagated across all
urlopen calls, replace the call_args check with an iteration through
mock_urlopen.call_args_list and assert that every call in the list contains the
correct timeout value of 20.0. This prevents partial propagation bugs where some
calls might have incorrect timeout values while others do not.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/modelinfo/cli.py`:
- Around line 110-115: The --timeout argument currently accepts invalid values
like 0, negative numbers, and non-finite floats due to using type=float without
validation. Create a custom validation function that checks if the input is a
positive finite number and raises an appropriate ArgumentTypeError for invalid
values, then replace the type=float parameter in the parser.add_argument call
for --timeout with this custom validation function to ensure invalid timeout
values are rejected at parse time with a clear error message.

---

Nitpick comments:
In `@tests/test_hf_timeout_configurable.py`:
- Around line 7-17: The test_cli_timeout_argument function currently only
verifies that the CLI execution succeeds, but does not actually verify that the
--timeout argument value (20.0) is forwarded to the mocked
fetch_huggingface_repo function. After the main() call completes successfully,
add an assertion on mock_fetch to verify it was called with the timeout
parameter set to 20.0. This ensures the timeout value flows through the entire
call chain from CLI parsing through to the actual fetch function call.
- Around line 44-45: The current assertion using mock_urlopen.call_args only
validates the timeout on the last invocation of urlopen. To ensure the timeout
is correctly propagated across all urlopen calls, replace the call_args check
with an iteration through mock_urlopen.call_args_list and assert that every call
in the list contains the correct timeout value of 20.0. This prevents partial
propagation bugs where some calls might have incorrect timeout values while
others do not.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3440ae91-6099-4962-92d4-5a531bd2e78a

📥 Commits

Reviewing files that changed from the base of the PR and between 99a7a5f and 28a86d2.

📒 Files selected for processing (4)
  • README.md
  • src/modelinfo/cli.py
  • src/modelinfo/parsers/huggingface.py
  • tests/test_hf_timeout_configurable.py

Comment thread src/modelinfo/cli.py

@pipe1os pipe1os left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you for your contribution!

please address the CodeRabbit review points and formatting issues before we merge:

  1. add custom validation to the --timeout argument to reject invalid values like 0, negative numbers, or non-finite floats.
  2. update the unit tests in test_hf_timeout_configurable.py to verify:
    • the --timeout argument successfully reaches mock_fetch in the CLI test.
    • the timeout parameter propagates to all urlopen calls by checking mock_urlopen.call_args_list.
  3. format the codebase by running uv run ruff format . to pass the linter checks.
  4. resolve the merge conflicts in huggingface.py.

@pipe1os pipe1os linked an issue Jun 19, 2026 that may be closed by this pull request

@pipe1os pipe1os left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thank you for the updates!

just two small things left to fix to pass the ci:

  1. In tests/test_parsers.py, please move the from modelinfo.parsers.huggingface import _get_hf_endpoint import from line 52 up to the top of the file (around line 4).
  2. please run uv run ruff format . locally and push the resulting changes to fix the remaining formatting failures.

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.

[Feature]: Expose a --timeout flag for remote Hub fetching

2 participants