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

ruff 0.4.3 auto-fixes #3808

Merged
merged 2 commits into from
May 4, 2024
Merged

ruff 0.4.3 auto-fixes #3808

merged 2 commits into from
May 4, 2024

Conversation

janosh
Copy link
Member

@janosh janosh commented May 4, 2024

simplified code plus some minor logging fixes

@janosh janosh added the linting Linting and quality assurance label May 4, 2024
Copy link

coderabbitai bot commented May 4, 2024

Walkthrough

This update involves a series of refinements across various Python files, focusing on simplifying and streamlining code. Key changes include updating logger initializations, refining method implementations for clarity and efficiency, and enhancing string operations. The modifications also include updates to version numbers in configuration files, demonstrating a maintenance effort to keep dependencies current.

Changes

File Path Change Summary
.pre-commit-config.yaml Updated versions for pre-commit hooks.
pymatgen/.../eos.py, pymatgen/io/abinit/inputs.py Changed logger initialization from __file__ to __name__.
pymatgen/analysis/transition_state.py Simplified search sequence setup for OUTCAR files.
pymatgen/core/sites.py, pymatgen/io/aims/inputs.py Streamlined comparison methods in classes.
pymatgen/electronic_structure/plotter.py Simplified assignment of None using the or operator.
pymatgen/io/... (multiple files) Updated string handling, comparison logic, and method signatures.
pymatgen/util/testing/aims.py, tests/analysis/test_molecule_matcher.py Improved file reading operations.

This table groups files with similar types of changes together to provide a concise overview of the updates made in this patch.


Recent Review Details

Configuration used: .coderabbit.yaml
Review profile: CHILL

Commits Files that changed from the base of the PR and between 8f011ff and d1040a7.
Files selected for processing (3)
  • pymatgen/util/provenance.py (1 hunks)
  • pymatgen/vis/structure_vtk.py (2 hunks)
  • tests/analysis/test_interface_reactions.py (2 hunks)
Files skipped from review due to trivial changes (1)
  • pymatgen/util/provenance.py
Additional comments not posted (2)
tests/analysis/test_interface_reactions.py (1)

7-7: The addition of MplFigure import is appropriate for the type checking in the test_plot method.

pymatgen/vis/structure_vtk.py (1)

883-883: The addition of DEFAULT_ANIMATED_MOVIE_OPTIONS enhances the flexibility of the MultiStructuresVis class by allowing customizable animated movie settings.


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.

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

Out of diff range and nitpick comments (1)
pymatgen/io/pwmat/inputs.py (1)

Line range hint 331-347: Potential issue with loop structure in get_virial method.

-        for tmp_idx in [aim_idx + 1, aim_idx + 2, aim_idx + 3]:
-            # tmp_strs_lst =
-            # ['0.8759519000E+01', '0.0000000000E+00', '0.0000000000E+00',
-            # 'stress', '(eV):', '0.115558E+02', '0.488108E+01', '0.238778E+01']
-            tmp_strs_lst = self.strs_lst[tmp_idx].split()
-            tmp_aim_row_lst = ListLocator.locate_all_lines(strs_lst=tmp_strs_lst, content="STRESS")
-            if len(tmp_aim_row_lst) == 0:
-                return None
+        tmp_strs_lst = [self.strs_lst[tmp_idx].split() for tmp_idx in [aim_idx + 1, aim_idx + 2, aim_idx + 3]]
+        if not any("STRESS" in sublist for sublist in tmp_strs_lst):
+            return None

This change ensures that the method exits early if "STRESS" is not found in any of the relevant lines, rather than checking each line individually without any effect.

Comment on lines +442 to +453
lines += (f"\t{self.structure.num_sites} atoms\n", "Lattice vector\n")
for idx in range(3):
lines.append(f"{lattice.matrix[idx][0]:>15f}{lattice.matrix[idx][1]:>15f}{lattice.matrix[idx][2]:>15f}\n")
lines.append("Position, move_x, move_y, move_z\n")
for ii in range(self.structure.num_sites):
lines.append(f"{int(self.structure.species[ii].Z):>4d}")
lines.append(f"{self.structure.frac_coords[ii][0]:>15f}")
lines.append(f"{self.structure.frac_coords[ii][1]:>15f}")
lines.append(f"{self.structure.frac_coords[ii][2]:>15f}")
lines.append(" 1 1 1\n")
for site_idx in range(len(self.structure)):
lines += (
f"{int(self.structure.species[site_idx].Z):>4d}",
f"{self.structure.frac_coords[site_idx][0]:>15f}",
f"{self.structure.frac_coords[site_idx][1]:>15f}",
f"{self.structure.frac_coords[site_idx][2]:>15f}",
" 1 1 1\n",
)
Copy link

Choose a reason for hiding this comment

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

Improve consistency in string formatting in AtomConfig class.

-        lines += (f"\t{self.structure.num_sites} atoms\n", "Lattice vector\n")
+        lines.append(f"\t{self.structure.num_sites} atoms\nLattice vector\n")
-            lines += (
-                f"{int(self.structure.species[site_idx].Z):>4d}",
-                f"{self.structure.frac_coords[site_idx][0]:>15f}",
-                f"{self.structure.frac_coords[site_idx][1]:>15f}",
-                f"{self.structure.frac_coords[site_idx][2]:>15f}",
-                "   1   1   1\n",
-            )
+            lines.append(
+                f"{int(self.structure.species[site_idx].Z):>4d}"
+                f"{self.structure.frac_coords[site_idx][0]:>15f}"
+                f"{self.structure.frac_coords[site_idx][1]:>15f}"
+                f"{self.structure.frac_coords[site_idx][2]:>15f}"
+                "   1   1   1\n"
+            )

This change improves the consistency of how lines are added to the list, using append instead of += for single lines and ensuring that all parts of the formatted string are concatenated directly.


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
lines += (f"\t{self.structure.num_sites} atoms\n", "Lattice vector\n")
for idx in range(3):
lines.append(f"{lattice.matrix[idx][0]:>15f}{lattice.matrix[idx][1]:>15f}{lattice.matrix[idx][2]:>15f}\n")
lines.append("Position, move_x, move_y, move_z\n")
for ii in range(self.structure.num_sites):
lines.append(f"{int(self.structure.species[ii].Z):>4d}")
lines.append(f"{self.structure.frac_coords[ii][0]:>15f}")
lines.append(f"{self.structure.frac_coords[ii][1]:>15f}")
lines.append(f"{self.structure.frac_coords[ii][2]:>15f}")
lines.append(" 1 1 1\n")
for site_idx in range(len(self.structure)):
lines += (
f"{int(self.structure.species[site_idx].Z):>4d}",
f"{self.structure.frac_coords[site_idx][0]:>15f}",
f"{self.structure.frac_coords[site_idx][1]:>15f}",
f"{self.structure.frac_coords[site_idx][2]:>15f}",
" 1 1 1\n",
)
lines.append(f"\t{self.structure.num_sites} atoms\nLattice vector\n")
for idx in range(3):
lines.append(f"{lattice.matrix[idx][0]:>15f}{lattice.matrix[idx][1]:>15f}{lattice.matrix[idx][2]:>15f}\n")
lines.append("Position, move_x, move_y, move_z\n")
for site_idx in range(len(self.structure)):
lines.append(
f"{int(self.structure.species[site_idx].Z):>4d}"
f"{self.structure.frac_coords[site_idx][0]:>15f}"
f"{self.structure.frac_coords[site_idx][1]:>15f}"
f"{self.structure.frac_coords[site_idx][2]:>15f}"
" 1 1 1\n"
)

@janosh janosh enabled auto-merge (squash) May 4, 2024 11:14
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: 1

Out of diff range and nitpick comments (1)
pymatgen/vis/structure_vtk.py (1)

883-883: Consider documenting the DEFAULT_ANIMATED_MOVIE_OPTIONS class variable.

Adding a docstring or comment explaining the purpose and usage of DEFAULT_ANIMATED_MOVIE_OPTIONS would enhance code readability and maintainability.

@@ -392,7 +392,7 @@ def test_labels(self):
def test_plot(self):
for ir in self.irs:
fig = ir.plot(backend="matplotlib")
assert fig, isinstance(fig, mpl_figure)
assert fig, isinstance(fig, MplFigure)
Copy link

Choose a reason for hiding this comment

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

Fix the syntax error in the assertion.

- assert fig, isinstance(fig, MplFigure)
+ assert isinstance(fig, MplFigure)

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
assert fig, isinstance(fig, MplFigure)
assert isinstance(fig, MplFigure)

@janosh janosh merged commit a16ac39 into master May 4, 2024
22 checks passed
@janosh janosh deleted the ruff-fixes branch May 4, 2024 11:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
linting Linting and quality assurance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant