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

Try MP_API_KEY in Github Actions #332

Merged
merged 5 commits into from
Nov 21, 2024
Merged

Try MP_API_KEY in Github Actions #332

merged 5 commits into from
Nov 21, 2024

Conversation

AntObi
Copy link
Collaborator

@AntObi AntObi commented Nov 21, 2024

Test MP API KEY in the workflow

Description

To ensure that any future updates to SMACT don't break workflows dependent on the Materials Project API, I have added an API Key as a secret

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

Test Configuration:

  • Python version: 3.10
  • Operating System: macOS

Reviewers

N/A

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • Any dependent changes have been merged and published in downstream modules
  • I have checked my code and corrected any misspellings

Summary by CodeRabbit

  • Chores
    • Added a new environment variable MP_API_KEY for secure access to sensitive information during test execution in the CI workflow.
  • New Features
    • Expanded optional dependencies for crystal_space to include kaleido and pydantic<2.10.0, enhancing functionality and data validation support.
    • Updated linting configuration to allow more flexibility in documentation string requirements for test files.
  • Tests
    • Integrated pytest for improved test execution, including conditional skipping of tests based on the operating system and API key presence.

@AntObi AntObi added the github_actions Pull requests that update GitHub Actions code label Nov 21, 2024
Copy link
Contributor

coderabbitai bot commented Nov 21, 2024

Walkthrough

The changes involve updates to the Continuous Integration (CI) workflow configuration in the .github/workflows/ci.yml file and modifications to the pyproject.toml file. An environment variable, MP_API_KEY, has been added to the test job in the CI configuration, sourced from the repository's secrets. Additionally, the pyproject.toml file has been updated to include new optional dependencies for crystal_space and modified linting rules for test files. Changes were also made to the test utilities to enhance compatibility with the pytest framework.

Changes

File Change Summary
.github/workflows/ci.yml Added MP_API_KEY environment variable to the test job, sourced from repository secrets.
pyproject.toml Updated crystal_space optional dependencies to include kaleido and pydantic<2.10.0; modified linting rules to ignore D for smact/tests/*.
smact/tests/test_utils.py Added imports for sys and pytest; updated test method to use pytest.mark.skipif instead of unittest.skipUnless.

Poem

In the garden of code, a secret we keep,
MP_API_KEY now helps tests leap!
With whispers of safety, our workflows align,
In the world of CI, all will be fine.
Hopping through changes, we celebrate cheer,
For secure little secrets, we hold so dear! 🐇✨

Warning

Rate limit exceeded

@AntObi has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 13 minutes and 17 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 8384696 and e9edfb6.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 8384696 and e9edfb6.

📒 Files selected for processing (1)
  • smact/tests/test_utils.py (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • smact/tests/test_utils.py

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 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 or @coderabbitai title 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
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (1)
.github/workflows/ci.yml (1)

37-38: Consider documenting the required secrets

It would be helpful to document the required secrets in the repository's README or contributing guidelines to help other contributors set up their development environment correctly.

Consider adding a section like this to your README:

+ ## Required Secrets for CI
+ 
+ The following secrets need to be configured in your repository settings:
+ 
+ - `MP_API_KEY`: Materials Project API key for accessing their database
+ - `CODECOV_TOKEN`: Token for uploading coverage reports
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1bac2b1 and 00769c7.

📒 Files selected for processing (1)
  • .github/workflows/ci.yml (1 hunks)
🔇 Additional comments (1)
.github/workflows/ci.yml (1)

37-38: The environment variable configuration looks good!

The MP_API_KEY is correctly configured using GitHub's secure secrets mechanism, which is the recommended approach for handling sensitive credentials in CI workflows.

Let's verify if the Materials Project API integration is complete:

✅ Verification successful

The Materials Project API integration is properly implemented

The codebase shows a complete and well-structured integration of the MP_API_KEY:

  • The key is correctly used in the download utility (download_compounds_with_mp_api.py) with proper error handling
  • Test files appropriately check for the API key's presence using both environment variables and PyMatGen settings
  • The implementation includes graceful fallbacks (checking both MP_API_KEY and PMG_MAPI_KEY)
  • Tests are properly configured to skip when the API key is not available
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for Materials Project API usage in the codebase
# Expected: Find code that utilises the MP_API_KEY environment variable

# Search for Materials Project API imports and usage
rg -l "materials project|pymatgen" 

# Search for environment variable usage
rg "MP_API_KEY|os\.environ\.get\(['\"]MP_API_KEY" 

# Search for test files that might require the API key
fd -e py test_ -x rg -l "materials project|pymatgen|MP_API_KEY" {}

Length of output: 1980


Script:

#!/bin/bash
# Let's check the content of the files that use MP_API_KEY to understand the integration
cat smact/utils/crystal_space/download_compounds_with_mp_api.py

Length of output: 3571


Script:

#!/bin/bash
# Check if there are any configuration files that might handle the API key
rg -l "config|settings|api.*key" --type yaml --type ini --type toml

Length of output: 97


Script:

#!/bin/bash
# Check the test files to understand how the API key is used in tests
cat smact/tests/test_utils.py

Length of output: 7609

Copy link

codecov bot commented Nov 21, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.42%. Comparing base (edc6a50) to head (e9edfb6).
Report is 140 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #332      +/-   ##
==========================================
+ Coverage   73.74%   76.42%   +2.68%     
==========================================
  Files          31       31              
  Lines        2544     2545       +1     
==========================================
+ Hits         1876     1945      +69     
+ Misses        668      600      -68     

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

Copy link
Contributor

@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: 0

🧹 Outside diff range and nitpick comments (1)
pyproject.toml (1)

82-83: Consider documenting the rationale for kaleido dependency

The addition of kaleido as a dependency should be documented to explain its purpose within the crystal_space feature set. This helps future maintainers understand the dependency's role.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 00769c7 and d68b9d4.

📒 Files selected for processing (1)
  • pyproject.toml (1 hunks)
🔇 Additional comments (1)
pyproject.toml (1)

82-83: Verify pydantic version constraint compatibility

The addition of pydantic<2.10.0 as a dependency warrants verification of compatibility with other packages. The strict version constraint might cause conflicts with other dependencies that require newer versions of pydantic.

✅ Verification successful

Pydantic version constraint is appropriate

The pydantic dependency is used minimally in the codebase, specifically in utilities.py for handling MP API responses. The version constraint pydantic<2.10.0 is appropriate because:

  • The only usage is for type hints and data conversion of the MP API response
  • No direct pydantic models or complex features are implemented
  • The constraint helps maintain compatibility with the MP API client
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for potential dependency conflicts with pydantic

# Check if any other dependencies require pydantic
rg -l "pydantic" | grep -v "pyproject.toml"

# Check if mp-api has specific pydantic requirements
curl -s https://pypi.org/pypi/mp-api/json | jq '.info.requires_dist[]' | grep -i "pydantic"

Length of output: 173


Script:

#!/bin/bash
# Check the content of the file that uses pydantic
cat smact/structure_prediction/utilities.py

# Check if there are any other files importing pydantic
rg "from pydantic" -A 2

# Check if there are any other files using pydantic classes or models
rg "class.*\(.*pydantic" -A 2

Length of output: 2892

Copy link
Contributor

@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: 1

🧹 Outside diff range and nitpick comments (2)
smact/tests/test_utils.py (2)

5-5: Consider migrating fully to pytest

The test file currently mixes unittest and pytest frameworks. While this works, it's generally better to stick to one testing framework for consistency and maintainability. Consider migrating the entire test suite to pytest, which offers more features and better readability.

Also applies to: 9-9


Line range hint 121-134: Use pytest's tmp_path fixture

Instead of manually managing temporary directories, consider using pytest's tmp_path fixture. This ensures proper cleanup and provides a unique temporary directory for each test run.

Here's how you could refactor it:

-    def test_download_compounds_with_mp_api(self):
-        save_mp_dir = "data/binary/mp_data"
+    def test_download_compounds_with_mp_api(self, tmp_path):
+        save_mp_dir = tmp_path / "binary" / "mp_data"
         download_compounds_with_mp_api.download_mp_data(
             mp_api_key=os.environ.get("MP_API_KEY"),
             num_elements=2,
             max_stoich=1,
             save_dir=save_mp_dir,
         )
 
         # Check if the data was downloaded
         self.assertTrue(os.path.exists(save_mp_dir))
         self.assertTrue(len(os.listdir(save_mp_dir)) > 0)
-
-        # Clean up
-        shutil.rmtree(save_mp_dir)
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between d68b9d4 and 8384696.

📒 Files selected for processing (1)
  • smact/tests/test_utils.py (2 hunks)
🔇 Additional comments (1)
smact/tests/test_utils.py (1)

116-116: Verify environment variable usage

The code accepts both MP_API_KEY and PMG_MAPI_KEY, but the test only uses MP_API_KEY. Let's verify the environment variable setup and usage.

Also applies to: 122-122

✅ Verification successful

Environment variable setup is correctly implemented

The environment variable usage is consistent across the codebase:

  • The main functionality in download_compounds_with_mp_api.py requires MP_API_KEY
  • The test file appropriately handles both MP_API_KEY and legacy PMG_MAPI_KEY for backwards compatibility
  • GitHub Actions workflow correctly sets up MP_API_KEY as a secret in the test job
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check environment variable usage and GitHub Actions setup

# Check for environment variable usage in the codebase
echo "Checking for MP_API_KEY usage:"
rg -l "MP_API_KEY"

echo -e "\nChecking for PMG_MAPI_KEY usage:"
rg -l "PMG_MAPI_KEY"

echo -e "\nChecking GitHub Actions workflow for MP_API_KEY:"
fd -t f "*.yml" .github/workflows/ --exec cat {} \; | grep -A 5 -B 5 "MP_API_KEY"

Length of output: 786


Script:

#!/bin/bash
# Let's examine the actual usage of these environment variables in the files

echo "Checking MP_API_KEY usage context in download_compounds_with_mp_api.py:"
rg -C 5 "MP_API_KEY" smact/utils/crystal_space/download_compounds_with_mp_api.py

echo -e "\nChecking both environment variables usage in test_utils.py:"
rg -C 5 "MP_API_KEY|PMG_MAPI_KEY" smact/tests/test_utils.py

echo -e "\nChecking GitHub Actions workflows with correct glob pattern:"
find .github/workflows -type f -name "*.yml" -exec cat {} \;

Length of output: 10055

AntObi and others added 2 commits November 21, 2024 15:23
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
@AntObi AntObi added the bug label Nov 21, 2024
@AntObi AntObi merged commit ce807e1 into master Nov 21, 2024
13 checks passed
@AntObi AntObi deleted the fix_tests branch November 21, 2024 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug github_actions Pull requests that update GitHub Actions code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant