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

Add ruff formatter #205

Merged
merged 3 commits into from
May 14, 2024
Merged

Add ruff formatter #205

merged 3 commits into from
May 14, 2024

Conversation

jan-janssen
Copy link
Member

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

Summary by CodeRabbit

  • New Features

    • Introduced pre-commit hooks for linting and formatting.
  • Bug Fixes

    • Improved handling of dependencies and versions in setup scripts.
    • Corrected string manipulation in various functions for better reliability.
  • Style

    • Updated string quotations and formatting across multiple files for consistency and readability.
  • Tests

    • Reformatted test methods and assertions for clarity and consistency.

Copy link

coderabbitai bot commented May 14, 2024

Walkthrough

The recent updates enhance the robustness and readability of the pylammpsmpi package. Key improvements include better string manipulation for dependency handling in the release.py script, consistent quotation marks in various configuration and source files, and refined test case structures. Additionally, a pre-commit configuration has been introduced for code linting and formatting, ensuring code quality and consistency.

Changes

File(s) Change Summary
.ci_support/release.py Enhanced string manipulation for dependencies and versions, updated file I/O operations for consistency.
.pre-commit-config.yaml Introduced pre-commit hooks for linting and formatting using ruff and ruff-format.
docs/source/conf.py Standardized string quotations and improved consistency in configuration settings.
pylammpsmpi/__init__.py Added LammpsLibrary and LammpsASELibrary to __all__, adjusted version assignment.
pylammpsmpi/mpi/lmpmpi.py Improved readability by changing condition checks to a more Pythonic style.
pylammpsmpi/wrapper/concurrent.py Removed the unused lenids variable from gather_atoms and scatter_atoms functions.
setup.py Standardized string quotations for consistency.
tests/test_ase_interface.py, tests/test_base.py, tests/test_concurrent.py, tests/test_pylammpsmpi_local.py Updated string quotations, restructured assertions, and improved code formatting for better readability and consistency.

🐇
In the land of code, where rabbits run,
We've polished scripts and made them fun.
Dependencies now, so robust and clear,
With linting and tests, no bugs to fear.
Our project shines, like morning dew,
Thanks to these tweaks, from me to you.
🐇


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 reopened this May 14, 2024
@jan-janssen jan-janssen marked this pull request as draft May 14, 2024 18:43
@jan-janssen jan-janssen marked this pull request as ready for review May 14, 2024 19:10
@jan-janssen jan-janssen merged commit 945a37a into main May 14, 2024
17 of 18 checks passed
@jan-janssen jan-janssen deleted the ruff branch May 14, 2024 19:11
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: 5

Review Details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits Files that changed from the base of the PR and between 1c0235a and 2968221.
Files selected for processing (11)
  • .ci_support/release.py (3 hunks)
  • .pre-commit-config.yaml (1 hunks)
  • docs/source/conf.py (1 hunks)
  • pylammpsmpi/init.py (1 hunks)
  • pylammpsmpi/mpi/lmpmpi.py (3 hunks)
  • pylammpsmpi/wrapper/concurrent.py (2 hunks)
  • setup.py (1 hunks)
  • tests/test_ase_interface.py (8 hunks)
  • tests/test_base.py (3 hunks)
  • tests/test_concurrent.py (3 hunks)
  • tests/test_pylammpsmpi_local.py (4 hunks)
Files skipped from review due to trivial changes (6)
  • .pre-commit-config.yaml
  • pylammpsmpi/mpi/lmpmpi.py
  • pylammpsmpi/wrapper/concurrent.py
  • setup.py
  • tests/test_ase_interface.py
  • tests/test_pylammpsmpi_local.py
Additional Context Used
Ruff (5)
.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

docs/source/conf.py (1)

32-32: Module level import not at top of file

Additional comments not posted (10)
pylammpsmpi/__init__.py (1)

11-15: The try-except block for importing LammpsASELibrary is correctly implemented to handle the optional dependency on ase.

docs/source/conf.py (1)

9-9: Standardizing string quotations to double quotes improves consistency.

Also applies to: 16-16, 18-18, 25-25, 26-26

.ci_support/release.py (1)

55-69: The main block for handling dependencies and versions is appropriately updated to improve robustness.

tests/test_concurrent.py (4)

17-17: Adding a comma at the end of the cmdargs list improves consistency.


97-99: Reformatting the assertion in test_version improves readability.


104-107: Adding a comma at the end of the list in test_extract_global improves consistency.


118-120: Reformatting the assertion in test_properties improves readability.

tests/test_base.py (3)

21-21: Comma added for better readability.


34-34: Comma added for better readability.


117-117: Comma added for better readability.

@@ -4,10 +4,14 @@
from pylammpsmpi.wrapper.concurrent import LammpsConcurrent
from pylammpsmpi.wrapper.base import LammpsBase


__all__ = [LammpsLibrary, LammpsConcurrent, LammpsBase]
Copy link

Choose a reason for hiding this comment

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

Ensure LammpsASELibrary is only added to __all__ when ase is installed.

- __all__ = [LammpsLibrary, LammpsConcurrent, LammpsBase]
+ __all__ = [LammpsLibrary, LammpsConcurrent, LammpsBase, "LammpsASELibrary"]

The __all__ list should include "LammpsASELibrary" as a string to avoid potential issues when ase is not installed.


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
__all__ = [LammpsLibrary, LammpsConcurrent, LammpsBase]
__all__ = [LammpsLibrary, LammpsConcurrent, LammpsBase, "LammpsASELibrary"]

Comment on lines +33 to +34
main(["-e", "-o", "apidoc", "../../pylammpsmpi/", "--force"])
Copy link

Choose a reason for hiding this comment

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

Move the import statement for main to the top of the file to follow best practices for module-level imports.

- from sphinx.ext.apidoc import main
- main(["-e", "-o", "apidoc", "../../pylammpsmpi/", "--force"])
+ from sphinx.ext.apidoc import main

# -- Generate API documentation ----------------------------------------------
# https://www.sphinx-doc.org/en/master/man/sphinx-apidoc.html

main(["-e", "-o", "apidoc", "../../pylammpsmpi/", "--force"])

Module-level imports should be at the top of the file.


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
main(["-e", "-o", "apidoc", "../../pylammpsmpi/", "--force"])
from sphinx.ext.apidoc import main
# -- Generate API documentation ----------------------------------------------
# https://www.sphinx-doc.org/en/master/man/sphinx-apidoc.html
main(["-e", "-o", "apidoc", "../../pylammpsmpi/", "--force"])

@@ -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 to improve code readability.

- for l in setup_content:
-     if "==" in l:
-         lst = (
-             l.split("[")[-1]
-             .split("]")[0]
-             .replace(" ", "")
-             .replace('"', "")
-             .replace("'", "")
-             .split(",")
-         )
-         for dep in lst:
-             if dep != "\n":
-                 version_lst.append(dep.split("==")[1])
-                 depend_lst.append(dep.split("==")[0])
+ for line in setup_content:
+     if "==" in line:
+         lst = (
+             line.split("[")[-1]
+             .split("]")[0]
+             .replace(" ", "")
+             .replace('"', "")
+             .replace("'", "")
+             .split(",")
+         )
+         for dep in lst:
+             if dep != "\n":
+                 version_lst.append(dep.split("==")[1])
+                 depend_lst.append(dep.split("==")[0])

The variable name l is ambiguous and should be renamed to line for better readability.

Also applies to: 26-26, 46-46, 49-49


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:
if 'dependencies:' in l:
if "dependencies:" in l:
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 to improve code readability.

- for l in env_content:
-     if "dependencies:" in l:
-         read_flag = True
-     elif read_flag:
-         lst = l.replace("-", "").replace(" ", "").replace("\n", "").split("=")
-         if len(lst) == 2:
-             depend_lst.append(lst[0])
-             version_lst.append(lst[1])
+ for line in env_content:
+     if "dependencies:" in line:
+         read_flag = True
+     elif read_flag:
+         lst = line.replace("-", "").replace(" ", "").replace("\n", "").split("=")
+         if len(lst) == 2:
+             depend_lst.append(lst[0])
+             version_lst.append(lst[1])

The variable name l is ambiguous and should be renamed to line for better readability.


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
if "dependencies:" in l:
if "dependencies:" in line:

@@ -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 to improve code readability.

- for l in setup_content:
-     for k, v in pattern_dict.items():
-         if v in l:
-             l = l.replace(v, version_combo_dict[k])
-     setup_content_new += l
+ for line in setup_content:
+     for k, v in pattern_dict.items():
+         if v in line:
+             line = line.replace(v, version_combo_dict[k])
+     setup_content_new += line

The variable name l is ambiguous and should be renamed to line for better readability.

Also applies to: 49-49


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:
for k, v in pattern_dict.items():
if v in line:
line = line.replace(v, version_combo_dict[k])
setup_content_new += line

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