Skip to content

ruff related fixes #181

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

Closed
wants to merge 2 commits into from
Closed

ruff related fixes #181

wants to merge 2 commits into from

Conversation

jan-janssen
Copy link
Member

@jan-janssen jan-janssen commented May 14, 2024

Summary by CodeRabbit

  • New Features

    • Enhanced module usability by explicitly listing all public entities in relevant modules.
  • Bug Fixes

    • Improved exception handling in the generate function.
    • Adjusted formatting and tolerance values in test cases to ensure accuracy.
  • Refactor

    • Simplified variable assignments and dictionary formatting for clarity and maintainability.
  • Style

    • Streamlined imports and removed unnecessary line breaks for better code readability.
  • Tests

    • Updated test cases to improve formatting and assertion logic for accurate testing.

Copy link

coderabbitai bot commented May 14, 2024

Warning

Rate Limit Exceeded

@jan-janssen has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 6 minutes and 39 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 Files that changed from the base of the PR and between 336a509 and 4d0eb42.

Walkthrough

This update primarily focuses on refining and organizing the structuretoolkit package by enhancing the accessibility and clarity of its public entities. Key changes include updating __all__ lists for explicit exports, simplifying code for readability, and minor adjustments to test cases for improved formatting and accuracy. These enhancements ensure a more streamlined and user-friendly experience for developers interacting with the module.

Changes

File Path Change Summary
.ci_support/release.py, setup.py No functional changes; minor formatting adjustments.
structuretoolkit/__init__.py, structuretoolkit/analyse/__init__.py, structuretoolkit/build/__init__.py, structuretoolkit/common/__init__.py Updated __all__ lists to include various functions and constants for better module accessibility.
structuretoolkit/build/aimsgb.py, structuretoolkit/build/compound.py, structuretoolkit/build/random.py, structuretoolkit/build/sqs.py, structuretoolkit/build/surface.py Simplified code formatting and improved readability without altering core functionality.
structuretoolkit/common/helper.py Removed import of atomic_numbers from ase.data.
tests/test_dscribe.py, tests/test_pymatgen.py, tests/test_pyxtal.py, tests/test_symmetry.py, tests/test_visualize.py Adjusted test cases for better formatting, readability, and accuracy.

🐇
In the toolkit's heart, where structures align,
Functions and constants now clearly define.
With imports refined and exports so clear,
Developers rejoice, there's less to fear.
Tests now run smoother, with formatting bright,
Code's more readable, a pure delight.
Cheers to the changes, all tidy and neat,
The toolkit evolves, a programmer’s treat.
🐇


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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

@jan-janssen jan-janssen marked this pull request as draft May 14, 2024 20:32
@jan-janssen
Copy link
Member Author

structuretoolkit/analyse/neighbors.py:387:16: E712 Avoid equality comparisons to `False`; use `if not self._ref_structure.pbc:` for false checks
structuretoolkit/analyse/neighbors.py:474:9: E741 Ambiguous variable name: `l`
structuretoolkit/analyse/neighbors.py:520:15: E741 Ambiguous variable name: `l`
structuretoolkit/analyse/neighbors.py:559:33: E741 Ambiguous variable name: `l`
structuretoolkit/analyse/snap.py:409:5: E722 Do not use bare `except`
structuretoolkit/analyse/snap.py:547:5: F841 Local variable `lmp_bsum` is assigned to but never used
structuretoolkit/analyse/snap.py:618:5: E722 Do not use bare `except`
structuretoolkit/analyse/spatial.py:318:41: E741 Ambiguous variable name: `l`
structuretoolkit/build/random.py:11:5: E731 Do not assign a `lambda` expression, use a `def`
Found 9 errors.

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

Out of diff range and nitpick comments (4)
tests/test_dscribe.py (1)

Line range hint 11-11: Remove unused import dscribe.

- import dscribe
tests/test_pyxtal.py (1)

Line range hint 7-7: Remove unused import pyxtal.

- import pyxtal
tests/test_symmetry.py (2)

Line range hint 12-12: Remove unused import pyscal.

- import pyscal

Line range hint 20-20: Remove unused import spglib.

- import spglib
Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 696fd52 and 336a509.
Files selected for processing (18)
  • .ci_support/release.py (3 hunks)
  • setup.py (1 hunks)
  • structuretoolkit/init.py (1 hunks)
  • structuretoolkit/analyse/init.py (1 hunks)
  • structuretoolkit/build/init.py (1 hunks)
  • structuretoolkit/build/aimsgb.py (1 hunks)
  • structuretoolkit/build/compound.py (1 hunks)
  • structuretoolkit/build/random.py (2 hunks)
  • structuretoolkit/build/sqs.py (2 hunks)
  • structuretoolkit/build/surface.py (3 hunks)
  • structuretoolkit/common/init.py (1 hunks)
  • structuretoolkit/common/helper.py (1 hunks)
  • tests/test_dscribe.py (1 hunks)
  • tests/test_pymatgen.py (7 hunks)
  • tests/test_pyxtal.py (1 hunks)
  • tests/test_snap.py (7 hunks)
  • tests/test_symmetry.py (2 hunks)
  • tests/test_visualize.py (1 hunks)
Files not summarized due to errors (1)
  • tests/test_snap.py: Error: Message exceeds token limit
Files skipped from review due to trivial changes (6)
  • setup.py
  • structuretoolkit/build/init.py
  • structuretoolkit/build/aimsgb.py
  • structuretoolkit/build/surface.py
  • structuretoolkit/common/init.py
  • structuretoolkit/common/helper.py
Additional Context Used
Ruff (9)
.ci_support/release.py (4)

3-3: Ambiguous variable name: l


25-25: Ambiguous variable name: l


46-46: Ambiguous variable name: l


49-49: Ambiguous variable name: l

structuretoolkit/build/random.py (1)

11-11: Do not assign a lambda expression, use a def

tests/test_dscribe.py (1)

11-11: dscribe imported but unused; consider using importlib.util.find_spec to test for availability

tests/test_pyxtal.py (1)

7-7: pyxtal imported but unused; consider using importlib.util.find_spec to test for availability

tests/test_symmetry.py (2)

12-12: pyscal imported but unused; consider using importlib.util.find_spec to test for availability


20-20: spglib imported but unused; consider using importlib.util.find_spec to test for availability

Additional comments not posted (21)
tests/test_dscribe.py (1)

28-28: LGTM! The updated tolerance value in the assertion improves precision.

tests/test_visualize.py (1)

27-27: LGTM! The changes improve the readability and clarity of the assertion statement.

tests/test_pyxtal.py (1)

31-37: LGTM! The changes improve the readability and clarity of the with statement.

structuretoolkit/__init__.py (1)

80-135: LGTM! The expanded __all__ list improves the module's usability by explicitly exporting more entities.

structuretoolkit/build/sqs.py (2)

123-123: Ensure that the sqs_optimize import is necessary and used correctly.

Verification successful

The sqs_optimize function is indeed used in the structuretoolkit/build/sqs.py file. The import statement and its usage in the sqs_structures function appear to be correct.

  • structuretoolkit/build/sqs.py: from sqsgenerator import sqs_optimize
  • structuretoolkit/build/sqs.py: results, timings = sqs_optimize(

The changes related to the import and usage of sqs_optimize are valid.

Scripts Executed

The following scripts were executed for the analysis:


Script:

#!/bin/bash
# Description: Verify the usage of `sqs_optimize` in the codebase.

# Test: Search for the function usage. Expect: Only occurances of the new import.
rg --type python $'sqs_optimize'

Length of output: 62



Script:

#!/bin/bash
# Description: Verify the usage of `sqs_optimize` in the codebase.

# Test: Search for the function usage. Expect: Only occurrences of the new import.
rg 'sqs_optimize' --glob '*.py'

Length of output: 170


159-159: Ensure that the additional statistics returned are correctly handled in the calling code.

structuretoolkit/build/compound.py (1)

31-38: The formatting changes improve readability. Ensure consistency across the codebase.

structuretoolkit/analyse/__init__.py (1)

33-58: The __all__ list expansion improves module usability. Ensure all listed entities are correctly defined and imported.

tests/test_pymatgen.py (6)

60-62: The formatting changes improve readability. Ensure consistency across the codebase.


87-90: The formatting changes improve readability. Ensure consistency across the codebase.


129-129: The formatting changes improve readability. Ensure consistency across the codebase.


138-138: The formatting changes improve readability. Ensure consistency across the codebase.


151-151: The formatting changes improve readability. Ensure consistency across the codebase.


195-195: The formatting changes improve readability. Ensure consistency across the codebase.

tests/test_symmetry.py (2)

158-158: Consistent string formatting.


177-177: Consistent string formatting.

tests/test_snap.py (5)

9-9: Necessary import for the new test case.


22-54: LGTM! The array definition is clear and necessary for the test cases.


57-554: LGTM! The array definition is clear and necessary for the test cases.


574-575: Necessary attributes for the SNAP descriptor calculations.


608-608: LGTM! The new test case is well-defined and necessary for validating the _get_lammps_compatible_cell function.

@@ -1,12 +1,19 @@
def get_setup_version_and_pattern(setup_content):
depend_lst, version_lst = [], []
for l in setup_content:
Copy link

Choose a reason for hiding this comment

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

Rename the variable l to a more descriptive name for clarity.

- for l in setup_content:
+ for line in setup_content:

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.

Suggested change
for l in setup_content:
for line in setup_content:

@@ -16,14 +23,14 @@
read_flag = False
depend_lst, version_lst = [], []
for l in env_content:
Copy link

Choose a reason for hiding this comment

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

Rename the variable l to a more descriptive name for clarity.

- for l in env_content:
+ for line in env_content:

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.

Suggested change
for l in env_content:
for line in env_content:

@@ -35,27 +42,29 @@
version_combo_dict[dep] = dep + "==" + ver

setup_content_new = ""
pattern_dict = {d:d + "==" + v for d, v in version_high_dict.items()}
pattern_dict = {d: d + "==" + v for d, v in version_high_dict.items()}
for l in setup_content:
Copy link

Choose a reason for hiding this comment

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

Rename the variable l to a more descriptive name for clarity.

- for l in setup_content:
+ for line in setup_content:

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.

Suggested change
for l in setup_content:
for line in setup_content:

@@ -35,27 +42,29 @@
version_combo_dict[dep] = dep + "==" + ver

setup_content_new = ""
pattern_dict = {d:d + "==" + v for d, v in version_high_dict.items()}
pattern_dict = {d: d + "==" + v for d, v in version_high_dict.items()}
for l in setup_content:
for k, v in pattern_dict.items():
if v in l:
l = l.replace(v, version_combo_dict[k])
Copy link

Choose a reason for hiding this comment

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

Rename the variable l to a more descriptive name for clarity.

- for l in setup_content:
+ for line in setup_content:

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.

Suggested change
l = l.replace(v, version_combo_dict[k])
line = line.replace(v, version_combo_dict[k])

@@ -69,7 +69,7 @@ def generate(group):
s.from_random(
dim=dim, group=group, species=species, numIons=num_ions, **kwargs
)
except Comp_CompatibilityError as e:
except Comp_CompatibilityError:
Copy link

Choose a reason for hiding this comment

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

Avoid using lambda for defining functions.

- tqdm = lambda x: x
+ def tqdm(x):
+     return x

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.

Suggested change
except Comp_CompatibilityError:
except Comp_CompatibilityError:
def tqdm(x):
return x

"symmetry": g,
"repeat": i
})
structures.append({"atoms": s, "symmetry": g, "repeat": i})
Copy link

Choose a reason for hiding this comment

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

Consider breaking down the warning message for better readability.

- warnings.warn(f'Groups [{", ".join(map(str,failed_groups))}] could not be generated with stoichiometry {stoich}!')
+ warnings.warn(
+     f'Groups [{", ".join(map(str, failed_groups))}] could not be generated with stoichiometry {stoich}!'
+ )

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.

Suggested change
structures.append({"atoms": s, "symmetry": g, "repeat": i})
structures.append({"atoms": s, "symmetry": g, "repeat": i})
warnings.warn(
f'Groups [{", ".join(map(str, failed_groups))}] could not be generated with stoichiometry {stoich}!'
)

@jan-janssen jan-janssen deleted the ruff_pre branch July 18, 2024 05:23
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