Skip to content

fix: move clang tools dependencies to optional #92

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 16, 2025

Conversation

shenxianpeng
Copy link
Collaborator

@shenxianpeng shenxianpeng commented Jul 16, 2025

Summary by CodeRabbit

  • New Features

    • Improved support for retrieving tool versions from an optional dependencies section, enhancing configuration flexibility.
  • Bug Fixes

    • Updated logic to ensure tool versions are correctly detected from the new optional dependencies group.
    • Added fallback to hardcoded tool versions to guarantee version availability during installation.
  • Tests

    • Adjusted and expanded tests to validate the updated version lookup behavior, including fallback scenarios.
  • Chores

    • Updated dependency configuration to move tool dependencies into an optional group for better project organization.

@shenxianpeng shenxianpeng added the bug Something isn't working label Jul 16, 2025
Copy link

coderabbitai bot commented Jul 16, 2025

Warning

Rate limit exceeded

@shenxianpeng has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 20 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between fb84f57 and b8eb49e.

📒 Files selected for processing (3)
  • cpp_linter_hooks/util.py (2 hunks)
  • pyproject.toml (2 hunks)
  • tests/test_util.py (3 hunks)
## Walkthrough

The changes update how dependency versions for tools are retrieved. The lookup now prioritizes the `tools` group under `project.optional-dependencies` in `pyproject.toml` instead of the main dependencies list. Tests and configuration are adjusted accordingly.

## Changes

| File(s)                 | Change Summary                                                                                              |
|-------------------------|-------------------------------------------------------------------------------------------------------------|
| cpp_linter_hooks/util.py | Modified `get_version_from_dependency` to look for tool versions in `optional-dependencies.tools` before falling back to `dependencies`. Added fallback to hardcoded versions if resolved version is None in `_resolve_install`. |
| pyproject.toml           | Moved `clang-format` and `clang-tidy` from main dependencies to `optional-dependencies.tools`; added clarifying comment restricting this group to clang tools only. |
| tests/test_util.py       | Updated tests to reflect new `optional-dependencies.tools` structure and added a test verifying fallback to hardcoded versions when default constants are None. |

## Sequence Diagram(s)

```mermaid
sequenceDiagram
    participant Test
    participant Util
    participant PyprojectToml

    Test->>Util: get_version_from_dependency(tool)
    Util->>PyprojectToml: Read pyproject.toml
    alt tool version in optional-dependencies.tools
        Util->>PyprojectToml: Look up tool in optional-dependencies.tools
        alt tool found
            Util-->>Test: Return version
        else tool not found
            Util->>PyprojectToml: Look up tool in dependencies
            alt tool found
                Util-->>Test: Return version
            else
                Util-->>Test: Return None
            end
        end
    else
        Util->>PyprojectToml: Look up tool in dependencies
        alt tool found
            Util-->>Test: Return version
        else
            Util-->>Test: Return None
        end
    end

Possibly related PRs

Suggested labels

enhancement


<!-- walkthrough_end -->
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEejqANiS4AzeAA8uzfFMYXMRSAXwXkS7sgE/Nzi+BhoFgYActjMApRcAJwATAYAqogJkIiwZPbwmNxkREb6xuBQZPT4NjgExGTKNPRMrOxcvPzCouJSMvJMSlSq6lo6ZSZQcKiomHWEpORUzQptGJyQVADu2bHMaBTycgpDKmqa2rpghuWmBgzc3AD6FvDrlE+w+PgA1ogA9Hh4BYNNxZBwDAAiaEGADEsMgAEEAJINJbUOi7VgHeQ1RiwDzSMy5SA2bAYMTwMKQAAGpFwTykFEQVIwTxsFBYT38VTIDFkNMgWzQyGw3FoGPoQTszNw6FwNGYIU2JFwFHgJAkb08uBJ3gskCZLOpHJYXhJNN4+BEYg0+BCrIiYB5GCUF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YwriGEk0p9QUUOwOq1GAugTwYrlL07cKAxkAAciQBCJF0gIGwBkBAABZEgkGSJ5hzJA0AAGZkj2b0sZRIBkACsyRkgGVoAANkSD52gnmvM2ck8ZEgCW3PGTQB5gyaBjIMFoAIILQW8ueai8ZZIAgkueZsJ5+LUX/MGSC01qL9AJgVFJAIezDXqvFcSNmTzDAbC6WSFFpznmgsCAMjYRIxlCtuYEAwBgQWEvJGMrQRINmDAGZYDyhkl9ECmY1FLWgTwqh6aAA -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=cpp-linter/cpp-linter-hooks&utm_content=92):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `Open a follow-up GitHub issue for this discussion.`
- Files and specific lines of code (under the "Files changed" tab): Tag `@coderabbitai` in a new review comment at the desired location with your query. Examples:
  - `@coderabbitai explain this code block.`
  -	`@coderabbitai modularize this function.`
- PR comments: Tag `@coderabbitai` in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
  - `@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.`
  - `@coderabbitai read src/utils.ts and explain its main purpose.`
  - `@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.`
  - `@coderabbitai help me debug CodeRabbit configuration file.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

### CodeRabbit Commands (Invoked using PR comments)

- `@coderabbitai pause` to pause the reviews on a PR.
- `@coderabbitai resume` to resume the paused reviews.
- `@coderabbitai review` to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
- `@coderabbitai full review` to do a full review from scratch and review all the files again.
- `@coderabbitai summary` to regenerate the summary of the PR.
- `@coderabbitai generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this PR.
- `@coderabbitai resolve` resolve all the CodeRabbit review comments.
- `@coderabbitai configuration` to show the current CodeRabbit configuration for the repository.
- `@coderabbitai help` to get help.

### Other keywords and placeholders

- Add `@coderabbitai ignore` anywhere in the PR description to prevent this PR from being reviewed.
- Add `@coderabbitai summary` to generate the high-level summary at a specific location in the PR description.
- Add `@coderabbitai` anywhere in the PR title to generate the title automatically.

### CodeRabbit Configuration File (`.coderabbit.yaml`)

- You can programmatically configure CodeRabbit by adding a `.coderabbit.yaml` file to the root of your repository.
- Please see the [configuration documentation](https://docs.coderabbit.ai/guides/configure-coderabbit) for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: `# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json`

### Documentation and Community

- Visit our [Documentation](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

@shenxianpeng shenxianpeng changed the title fix: Update pyproject.toml to move deps to optional fix: move clang tools deps to optional Jul 16, 2025
Copy link

codecov bot commented Jul 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 94.48%. Comparing base (73af16b) to head (b8eb49e).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #92      +/-   ##
==========================================
- Coverage   95.65%   94.48%   -1.17%     
==========================================
  Files           3        3              
  Lines         138      145       +7     
==========================================
+ Hits          132      137       +5     
- Misses          6        8       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 73af16b and 789b90b.

📒 Files selected for processing (3)
  • cpp_linter_hooks/util.py (1 hunks)
  • pyproject.toml (1 hunks)
  • tests/test_util.py (3 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
tests/test_util.py (1)
cpp_linter_hooks/util.py (1)
  • get_version_from_dependency (16-30)
🔇 Additional comments (3)
pyproject.toml (1)

47-53: LGTM! Good architectural improvement.

Moving clang tools to optional dependencies is a sound design decision. This allows users to install the core package without the heavyweight clang tools, and the clear comment provides good guidance for maintainers about what belongs in this section.

tests/test_util.py (2)

104-112: LGTM! Test structure updated correctly.

The test data structure properly reflects the new optional-dependencies.tools format.


137-139: LGTM! Missing dependency test updated appropriately.

The test correctly validates the behavior when no matching dependency is found in the tools section.

Comment on lines 162 to 184
@pytest.mark.benchmark
def test_get_version_from_dependency_fallback_to_dependencies():
"""Test get_version_from_dependency falls back to project.dependencies."""
mock_toml_content = {
"project": {
"dependencies": [
"clang-format==20.1.7",
"clang-tidy==20.1.0",
"other-package==1.0.0",
]
}
}

with (
patch("pathlib.Path.exists", return_value=True),
patch("cpp_linter_hooks.util.tomllib.load", return_value=mock_toml_content),
):
result = get_version_from_dependency("clang-format")
assert result == "20.1.7"

result = get_version_from_dependency("clang-tidy")
assert result == "20.1.0"

Copy link

Choose a reason for hiding this comment

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

💡 Verification agent

🧩 Analysis chain

Test expects fallback behavior that's missing in implementation.

This test validates fallback to the old dependencies structure, but the current implementation in cpp_linter_hooks/util.py doesn't include this fallback logic. The test will fail because the function only checks optional-dependencies.tools and returns None if not found there.

This test confirms that fallback functionality should exist but is missing from the implementation. Run this test to verify it fails:


🏁 Script executed:

#!/bin/bash
# Description: Run the specific fallback test to verify it fails due to missing implementation

python -m pytest tests/test_util.py::test_get_version_from_dependency_fallback_to_dependencies -v

Length of output: 9788


🏁 Script executed:

#!/bin/bash
rg -n "def get_version_from_dependency" -A 20 -B 5 cpp_linter_hooks/util.py

Length of output: 1002


Implement fallback to project.dependencies in get_version_from_dependency
The test test_get_version_from_dependency_fallback_to_dependencies fails because the function only looks under project.optional-dependencies.tools and never falls back to project.dependencies. You’ll need to update cpp_linter_hooks/util.py to try the old dependencies list before returning None.

Locations to update:
• cpp_linter_hooks/util.py, inside get_version_from_dependency (around lines 23–30)

Suggested patch:

     # First try project.optional-dependencies.tools
     optional_deps = data.get("project", {}).get("optional-dependencies", {})
     tools_deps = optional_deps.get("tools", [])
     for dep in tools_deps:
         if dep.startswith(f"{tool}=="):
             return dep.split("==")[1]

+    # Fallback to project.dependencies
+    project_deps = data.get("project", {}).get("dependencies", [])
+    for dep in project_deps:
+        if dep.startswith(f"{tool}=="):
+            return dep.split("==")[1]
+
     return None

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In cpp_linter_hooks/util.py around lines 23 to 30, the function
get_version_from_dependency currently only checks
project.optional-dependencies.tools for the package version and does not fall
back to project.dependencies. Update the function to first attempt to find the
version in project.optional-dependencies.tools, and if not found, then search in
project.dependencies before returning None. This ensures the fallback behavior
tested in tests/test_util.py lines 162 to 184 works correctly.

Copy link

codspeed-hq bot commented Jul 16, 2025

CodSpeed Performance Report

Merging #92 will degrade performances by 10.35%

Comparing shenxianpeng-patch-1 (b8eb49e) with main (73af16b)

🎉 Hooray! pytest-codspeed just leveled up to 4.0.0!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

❌ 1 regressions
✅ 67 untouched benchmarks
🆕 1 new benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
test_run_clang_tidy_invalid[args4-1] 757.9 µs 845.3 µs -10.35%
🆕 test_resolve_install_with_none_default_version N/A 1 ms N/A

Copy link

@shenxianpeng shenxianpeng merged commit d3169df into main Jul 16, 2025
15 of 17 checks passed
@shenxianpeng shenxianpeng deleted the shenxianpeng-patch-1 branch July 16, 2025 18:52
@shenxianpeng shenxianpeng changed the title fix: move clang tools deps to optional fix: move clang tools dependencies to optional Jul 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant