-
Notifications
You must be signed in to change notification settings - Fork 3
fix pip check for optional dependencies #579
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #579 +/- ##
=======================================
Coverage 95.89% 95.89%
=======================================
Files 26 26
Lines 1193 1193
=======================================
Hits 1144 1144
Misses 49 49 ☔ View full report in Codecov by Sentry. |
WalkthroughThis update introduces a new script that processes the Changes
Sequence Diagram(s)sequenceDiagram
participant W as GitHub Workflow
participant S as check.py Script
participant P as pyproject.toml
W->>S: Execute check.py
S->>P: Read pyproject.toml
S->>S: Process optional dependencies & remove duplicates
S->>P: Write updated dependencies
W->>W: Run cat pyproject.toml to display changes
Poem
✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Nitpick comments (1)
.ci_support/check.py (1)
8-11: Improve memory efficiency and readability.The list operations can be optimized using list comprehension and the code can be made more readable.
Apply this diff to improve the code:
- lst = [] - for sub_lst in data["project"]["optional-dependencies"].values(): - for el in sub_lst: - lst.append(el) + try: + lst = [ + dep + for deps in data["project"]["optional-dependencies"].values() + for dep in deps + ] + except KeyError: + print("Error: Missing required TOML keys") + sys.exit(1)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.ci_support/check.py(1 hunks).github/workflows/pipeline.yml(1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
.ci_support/check.py
5-5: Unnecessary open mode parameters
Remove open mode parameters
(UP015)
| with open("pyproject.toml", "r") as f: | ||
| data = tomlkit.load(f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for file operations.
The script should handle potential file operation errors and missing TOML keys gracefully.
Apply this diff to add error handling:
- with open("pyproject.toml", "r") as f:
- data = tomlkit.load(f)
+ try:
+ with open("pyproject.toml", "r") as f:
+ data = tomlkit.load(f)
+ except FileNotFoundError:
+ print("Error: pyproject.toml not found")
+ sys.exit(1)
+ except tomlkit.exceptions.TOMLKitError as e:
+ print(f"Error parsing pyproject.toml: {e}")
+ sys.exit(1)Don't forget to add the required import:
import sys🧰 Tools
🪛 Ruff (0.8.2)
5-5: Unnecessary open mode parameters
Remove open mode parameters
(UP015)
| with open("pyproject.toml", "w") as f: | ||
| f.writelines(tomlkit.dumps(data)) No newline at end of file |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add error handling for file write operations.
The script should handle potential file write errors gracefully.
Apply this diff to add error handling:
- with open("pyproject.toml", "w") as f:
- f.writelines(tomlkit.dumps(data))
+ try:
+ with open("pyproject.toml", "w") as f:
+ f.writelines(tomlkit.dumps(data))
+ except IOError as e:
+ print(f"Error writing to pyproject.toml: {e}")
+ sys.exit(1)📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| with open("pyproject.toml", "w") as f: | |
| f.writelines(tomlkit.dumps(data)) | |
| try: | |
| with open("pyproject.toml", "w") as f: | |
| f.writelines(tomlkit.dumps(data)) | |
| except IOError as e: | |
| print(f"Error writing to pyproject.toml: {e}") | |
| sys.exit(1) |
| for el in sub_lst: | ||
| lst.append(el) | ||
|
|
||
| data["project"]["dependencies"] += list(set(lst)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
Validate dependency format before adding.
The script should validate the dependency format before adding it to the main dependencies list.
Run this script to check the dependency format in the codebase:
🏁 Script executed:
#!/bin/bash
# Description: Check dependency format in pyproject.toml
# Expected format: package[extras]>=version or package[extras]==version
rg -A 5 'dependencies\s*=\s*\[' pyproject.tomlLength of output: 137
Action Required: Enforce Dependency Format Validation
Currently, in .ci_support/check.py at line 13, dependencies are appended using:
data["project"]["dependencies"] += list(set(lst))without any validation. Although the dependency format in pyproject.toml (e.g., "cloudpickle==3.1.1", "pyzmq==26.2.1") adheres to the expected pattern (package[extras]>=version or package[extras]==version), the script must programmatically verify that all dependencies meet this criterion before adding them to the main list.
- Suggestion: Introduce a validation step—ideally by matching each dependency string against a regular expression—that confirms its format matches the expected pattern. This will prevent potential formatting issues arising from incorrect dependency strings in the future.
| pip install versioneer[toml]==0.29 tomlkit | ||
| python .ci_support/check.py | ||
| cat pyproject.toml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Pin tomlkit version and add error handling.
The script execution should be resilient to failures, and dependencies should have fixed versions for reproducibility.
Apply this diff to improve the code:
- pip install versioneer[toml]==0.29 tomlkit
- python .ci_support/check.py
- cat pyproject.toml
+ pip install versioneer[toml]==0.29 tomlkit==0.12.3
+ if ! python .ci_support/check.py; then
+ echo "Error: Failed to process dependencies"
+ exit 1
+ fi
+ if ! cat pyproject.toml; then
+ echo "Error: Failed to display pyproject.toml"
+ exit 1
+ fi📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| pip install versioneer[toml]==0.29 tomlkit | |
| python .ci_support/check.py | |
| cat pyproject.toml | |
| pip install versioneer[toml]==0.29 tomlkit==0.12.3 | |
| if ! python .ci_support/check.py; then | |
| echo "Error: Failed to process dependencies" | |
| exit 1 | |
| fi | |
| if ! cat pyproject.toml; then | |
| echo "Error: Failed to display pyproject.toml" | |
| exit 1 | |
| fi |
Summary by CodeRabbit