Skip to content
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

fix pip check for optional dependencies #405

Merged
merged 7 commits into from
Feb 14, 2025
Merged

Conversation

jan-janssen
Copy link
Member

@jan-janssen jan-janssen commented Feb 14, 2025

Summary by CodeRabbit

  • New Features
    • Introduced an automated tool that extracts and updates optional dependencies to ensure consistent configuration management.
    • Added support for pytorch as a new dependency in the environment configuration.
  • Chores
    • Refined the environment setup process by merging multiple configuration sources.
    • Made minor adjustments to dependency listings to streamline the build process.

Copy link

coderabbitai bot commented Feb 14, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces a new Python script within the CI support folder that processes the pyproject.toml file by consolidating optional dependencies and updating the dependencies list. Additionally, a minor formatting update was made in the QE environment configuration file. The GitHub Actions workflow has been modified to merge multiple environment files, update dependency installation commands, and execute the new check script as part of the pip check job.

Changes

File(s) Change Summary
.ci_support/check.py Added a new standalone script that reads pyproject.toml, extracts optional dependencies, updates the dependencies field with unique entries, and writes the changes back.
.ci_support/environment-qe.yml Modified the dependency entry for pwtools by removing an extraneous newline character.
.github/workflows/pipeline.yml Updated the pip_check job: combined multiple environment files into a new environment.yml, changed the environment file reference for Mambaforge setup, updated pip install commands, and added a step to run the new check script.
.ci_support/environment-mace.yml Added a new dependency pytorch =2.5.1 to the list of dependencies.

Sequence Diagram(s)

sequenceDiagram
    participant Runner as GitHub Action Runner
    participant Conda as "Conda Config Step"
    participant Mamba as "Setup Mambaforge"
    participant Pip as "Pip Check Step"
    participant Check as "check.py Script"

    Runner->>Conda: Copy & append multiple environment files\n→ create environment.yml
    Conda-->>Runner: environment.yml ready
    Runner->>Mamba: Setup environment using environment.yml
    Mamba-->>Runner: Environment configured
    Runner->>Pip: Execute pip install with additional dependencies
    Pip->>Check: Run `python .ci_support/check.py`
    Check-->>Pip: Process and update pyproject.toml
    Pip->>Runner: Display updated pyproject.toml contents
Loading

Possibly related PRs

  • fix pip check for optional dependencies #405: The changes in the main PR are directly related to those in the retrieved PR as both modify the same script .ci_support/check.py to process the pyproject.toml file for optional dependencies.

Poem

I'm a bunny in the code, hopping through the change,
New scripts and workflows, all arranged in a range.
I nibble on the dependencies and munch on YAML treats,
My code garden blossoms with fresh, delightful feats.
With a twitch of my nose and a skip in my step, code magic repeats!
🐇✨


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 49bb62e and 8485643.

📒 Files selected for processing (3)
  • .ci_support/check.py (1 hunks)
  • .ci_support/environment-mace.yml (1 hunks)
  • .github/workflows/pipeline.yml (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 for this PR. (Beta)
  • @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 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 for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

codecov bot commented Feb 14, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.07%. Comparing base (39a63ac) to head (8485643).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #405   +/-   ##
=======================================
  Coverage   81.07%   81.07%           
=======================================
  Files          39       39           
  Lines        2309     2309           
=======================================
  Hits         1872     1872           
  Misses        437      437           

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

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: 4

🧹 Nitpick comments (1)
.ci_support/check.py (1)

13-13: Consider using set operations for better efficiency.

The current implementation first converts the list to a set and then back to a list. Using set operations directly would be more efficient.

Apply this diff to use set operations:

-    data["project"]["dependencies"] += list(set(lst))
+    existing_deps = set(data["project"]["dependencies"])
+    optional_deps = set(lst)
+    data["project"]["dependencies"] = list(existing_deps | optional_deps)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 39a63ac and 49bb62e.

📒 Files selected for processing (3)
  • .ci_support/check.py (1 hunks)
  • .ci_support/environment-qe.yml (1 hunks)
  • .github/workflows/pipeline.yml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • .ci_support/environment-qe.yml
🧰 Additional context used
🪛 Ruff (0.8.2)
.ci_support/check.py

5-5: Unnecessary open mode parameters

Remove open mode parameters

(UP015)

Comment on lines +5 to +6
with open("pyproject.toml", "r") as f:
data = tomlkit.load(f)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add error handling for file operations and TOML parsing.

The script should handle potential file operation errors and TOML parsing exceptions to prevent crashes and data loss.

Apply this diff to add error handling:

-    with open("pyproject.toml", "r") as f:
-        data = tomlkit.load(f)
+    try:
+        with open("pyproject.toml") 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)

-    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 pyproject.toml: {e}")
+        sys.exit(1)

Don't forget to add the required import:

import sys

Also applies to: 15-16

🧰 Tools
🪛 Ruff (0.8.2)

5-5: Unnecessary open mode parameters

Remove open mode parameters

(UP015)

Comment on lines 8 to 13
lst = []
for sub_lst in data["project"]["optional-dependencies"].values():
for el in sub_lst:
lst.append(el)

data["project"]["dependencies"] += list(set(lst))
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Add validation for TOML structure and required fields.

The script assumes the presence of required fields in the TOML file without validation. This could lead to KeyError exceptions if the fields are missing.

Apply this diff to add validation:

-    lst = []
-    for sub_lst in data["project"]["optional-dependencies"].values():
-        for el in sub_lst:
-            lst.append(el)
+    lst = []
+    if "project" not in data:
+        print("Error: Missing 'project' section in pyproject.toml")
+        sys.exit(1)
+    if "optional-dependencies" not in data["project"]:
+        print("Error: Missing 'optional-dependencies' in project section")
+        sys.exit(1)
+    if "dependencies" not in data["project"]:
+        print("Error: Missing 'dependencies' in project section")
+        sys.exit(1)
+    
+    for sub_lst in data["project"]["optional-dependencies"].values():
+        for el in sub_lst:
+            lst.append(el)
📝 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.

Suggested change
lst = []
for sub_lst in data["project"]["optional-dependencies"].values():
for el in sub_lst:
lst.append(el)
data["project"]["dependencies"] += list(set(lst))
lst = []
if "project" not in data:
print("Error: Missing 'project' section in pyproject.toml")
sys.exit(1)
if "optional-dependencies" not in data["project"]:
print("Error: Missing 'optional-dependencies' in project section")
sys.exit(1)
if "dependencies" not in data["project"]:
print("Error: Missing 'dependencies' in project section")
sys.exit(1)
for sub_lst in data["project"]["optional-dependencies"].values():
for el in sub_lst:
lst.append(el)
data["project"]["dependencies"] += list(set(lst))

Comment on lines 137 to 142
run: |
cp .ci_support/environment.yml environment.yml
tail --lines=+4 .ci_support/environment-lammps.yml >> environment.yml
tail --lines=+4 .ci_support/environment-qe.yml >> environment.yml
tail --lines=+4 .ci_support/environment-gpaw.yml >> environment.yml
echo -e "channels:\n - conda-forge\n" > .condarc
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation for environment file existence.

The script assumes the existence of environment files without validation. This could lead to pipeline failures if files are missing.

Apply this diff to add validation:

       run: |
-        cp .ci_support/environment.yml environment.yml
-        tail --lines=+4 .ci_support/environment-lammps.yml >> environment.yml
-        tail --lines=+4 .ci_support/environment-qe.yml >> environment.yml
-        tail --lines=+4 .ci_support/environment-gpaw.yml >> environment.yml
-        echo -e "channels:\n  - conda-forge\n" > .condarc
+        for file in \
+          ".ci_support/environment.yml" \
+          ".ci_support/environment-lammps.yml" \
+          ".ci_support/environment-qe.yml" \
+          ".ci_support/environment-gpaw.yml"; do
+          if [ ! -f "$file" ]; then
+            echo "Error: $file not found"
+            exit 1
+          fi
+        done
+        
+        cp .ci_support/environment.yml environment.yml
+        for file in \
+          ".ci_support/environment-lammps.yml" \
+          ".ci_support/environment-qe.yml" \
+          ".ci_support/environment-gpaw.yml"; do
+          tail --lines=+4 "$file" >> environment.yml || {
+            echo "Error: Failed to append $file"
+            exit 1
+          }
+        done
+        
+        echo -e "channels:\n  - conda-forge\n" > .condarc
📝 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.

Suggested change
run: |
cp .ci_support/environment.yml environment.yml
tail --lines=+4 .ci_support/environment-lammps.yml >> environment.yml
tail --lines=+4 .ci_support/environment-qe.yml >> environment.yml
tail --lines=+4 .ci_support/environment-gpaw.yml >> environment.yml
echo -e "channels:\n - conda-forge\n" > .condarc
run: |
for file in \
".ci_support/environment.yml" \
".ci_support/environment-lammps.yml" \
".ci_support/environment-qe.yml" \
".ci_support/environment-gpaw.yml"; do
if [ ! -f "$file" ]; then
echo "Error: $file not found"
exit 1
fi
done
cp .ci_support/environment.yml environment.yml
for file in \
".ci_support/environment-lammps.yml" \
".ci_support/environment-qe.yml" \
".ci_support/environment-gpaw.yml"; do
tail --lines=+4 "$file" >> environment.yml || {
echo "Error: Failed to append $file"
exit 1
}
done
echo -e "channels:\n - conda-forge\n" > .condarc

Comment on lines +153 to +155
pip install versioneer[toml]==0.29 tomlkit
python .ci_support/check.py
cat pyproject.toml
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add error handling for script execution.

The script execution should be validated to ensure it completes successfully.

Apply this diff to add error handling:

-        pip install versioneer[toml]==0.29 tomlkit
-        python .ci_support/check.py
-        cat pyproject.toml
+        pip install versioneer[toml]==0.29 tomlkit || {
+          echo "Error: Failed to install dependencies"
+          exit 1
+        }
+        
+        if [ ! -f ".ci_support/check.py" ]; then
+          echo "Error: check.py not found"
+          exit 1
+        fi
+        
+        python .ci_support/check.py || {
+          echo "Error: Failed to process dependencies"
+          exit 1
+        }
+        
+        if [ ! -f "pyproject.toml" ]; then
+          echo "Error: pyproject.toml not found after processing"
+          exit 1
+        fi
+        cat pyproject.toml
📝 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.

Suggested change
pip install versioneer[toml]==0.29 tomlkit
python .ci_support/check.py
cat pyproject.toml
pip install versioneer[toml]==0.29 tomlkit || {
echo "Error: Failed to install dependencies"
exit 1
}
if [ ! -f ".ci_support/check.py" ]; then
echo "Error: check.py not found"
exit 1
fi
python .ci_support/check.py || {
echo "Error: Failed to process dependencies"
exit 1
}
if [ ! -f "pyproject.toml" ]; then
echo "Error: pyproject.toml not found after processing"
exit 1
fi
cat pyproject.toml

@jan-janssen jan-janssen merged commit 091eb1b into main Feb 14, 2025
25 checks passed
@jan-janssen jan-janssen deleted the pip_check_extended branch February 14, 2025 09:57
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.

1 participant