-
Notifications
You must be signed in to change notification settings - Fork 175
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: ignore UP031 #1683
Fix: ignore UP031 #1683
Conversation
for more information, see https://pre-commit.ci
Warning Rate limit exceeded@wanghan-iapcm has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 21 minutes and 8 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the 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. 📝 Walkthrough📝 Walkthrough📝 WalkthroughWalkthroughThe pull request includes updates primarily focused on enhancing code quality and compliance with linting standards across multiple files in the Changes
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## devel #1683 +/- ##
=======================================
Coverage 49.51% 49.51%
=======================================
Files 83 83
Lines 14863 14863
=======================================
Hits 7359 7359
Misses 7504 7504 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this 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
🧹 Outside diff range and nitpick comments (5)
dpgen/auto_test/Interstitial.py (1)
225-225
: Refactor string formatting to use f-stringsThe code currently uses the
%
operator for string formatting, which can be replaced with f-strings for improved readability and performance.Apply the following changes:
- output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031 + output_task = os.path.join(path_to_work, f"task.{ii:06d}") # noqa: UP031 - output_task1 = os.path.join(path_to_work, "task.%06d" % (len(dss))) # noqa: UP031 + output_task1 = os.path.join(path_to_work, f"task.{len(dss):06d}") # noqa: UP031 - "task.%06d" % (len(dss) + 1), # noqa: UP031 + f"task.{len(dss) + 1:06d}", # noqa: UP031 - "task.%06d" % (len(dss) + 2), # noqa: UP031 + f"task.{len(dss) + 2:06d}", # noqa: UP031 - "task.%06d" % (len(dss) + 3), # noqa: UP031 + f"task.{len(dss) + 3:06d}", # noqa: UP031 - "task.%06d" % (len(dss) + 4), # noqa: UP031 + f"task.{len(dss) + 4:06d}", # noqa: UP031 - "task.%06d" % (len(dss) + 5), # noqa: UP031 + f"task.{len(dss) + 5:06d}", # noqa: UP031Also applies to: 265-265, 286-287, 309-310, 351-352, 386-387, 421-422
dpgen/__init__.py (1)
51-51
: Refactor print statements to use f-stringsUsing f-strings enhances readability and consistency in Python 3.
Apply the following changes:
- print("%10s %10s %s" % (modui, mm.__version__, mm.__path__[0])) # noqa: UP031 + print(f"{modui:10s} {mm.__version__:10s} {mm.__path__[0]}") # noqa: UP031 - print("%10s %10s Not Found" % (modui, "")) # noqa: UP031 + print(f"{modui:10s} {'':10s} Not Found") # noqa: UP031 - print("%10s %10s unknown version or path" % (modui, "")) # noqa: UP031 + print(f"{modui:10s} {'':10s} unknown version or path") # noqa: UP031Also applies to: 53-53, 55-55
dpgen/auto_test/Vacancy.py (1)
190-190
: Refactor string formatting to use f-stringsConsider using f-strings for better readability and modern Python practices.
Apply the following change:
- output_task = os.path.join(path_to_work, "task.%06d" % ii) # noqa: UP031 + output_task = os.path.join(path_to_work, f"task.{ii:06d}") # noqa: UP031dpgen/auto_test/EOS.py (1)
201-201
: Refactor string formatting to use f-stringsUpdating to f-strings improves code readability and aligns with Python 3 standards.
Apply the following change:
- output_task = os.path.join(path_to_work, "task.%06d" % task_num) # noqa: UP031 + output_task = os.path.join(path_to_work, f"task.{task_num:06d}") # noqa: UP031dpgen/auto_test/Gamma.py (1)
Line range hint
1-483
: Consider additional code quality improvementsWhile addressing the string formatting issues, consider these improvements for better maintainability:
Error Handling:
- Add error handling for file operations (e.g., around line 226)
- Consider using
pathlib.Path
for more robust path handlingMethod Organization:
- Consider splitting
make_confs
into smaller, more focused methods- Move file I/O operations into separate utility methods
Naming Conventions:
- Rename private methods to use single underscore prefix consistently (e.g.,
_gen_slab_ase
instead of__gen_slab_ase
)Documentation:
- Add docstrings to methods explaining parameters and return values
- Document the expected format of input files and configuration
Would you like me to provide specific examples for any of these improvements?
🧰 Tools
🪛 Ruff (0.8.0)
476-476: Use format specifiers instead of percent format
(UP031)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (49)
.pre-commit-config.yaml
(1 hunks)dpgen/__init__.py
(1 hunks)dpgen/auto_test/EOS.py
(1 hunks)dpgen/auto_test/Elastic.py
(1 hunks)dpgen/auto_test/Gamma.py
(3 hunks)dpgen/auto_test/Interstitial.py
(9 hunks)dpgen/auto_test/Surface.py
(3 hunks)dpgen/auto_test/VASP.py
(2 hunks)dpgen/auto_test/Vacancy.py
(1 hunks)dpgen/auto_test/common_prop.py
(2 hunks)dpgen/auto_test/lib/abacus.py
(1 hunks)dpgen/auto_test/lib/lammps.py
(8 hunks)dpgen/auto_test/lib/lmp.py
(3 hunks)dpgen/auto_test/lib/mfp_eosfit.py
(14 hunks)dpgen/auto_test/lib/pwscf.py
(3 hunks)dpgen/auto_test/lib/siesta.py
(4 hunks)dpgen/auto_test/lib/utils.py
(1 hunks)dpgen/auto_test/lib/vasp.py
(5 hunks)dpgen/auto_test/refine.py
(2 hunks)dpgen/auto_test/reproduce.py
(1 hunks)dpgen/collect/collect.py
(2 hunks)dpgen/data/gen.py
(12 hunks)dpgen/data/reaction.py
(1 hunks)dpgen/data/surf.py
(5 hunks)dpgen/data/tools/bcc.py
(1 hunks)dpgen/data/tools/cessp2force_lin.py
(2 hunks)dpgen/data/tools/create_random_disturb.py
(3 hunks)dpgen/data/tools/diamond.py
(1 hunks)dpgen/data/tools/fcc.py
(1 hunks)dpgen/data/tools/hcp.py
(1 hunks)dpgen/data/tools/io_lammps.py
(3 hunks)dpgen/data/tools/sc.py
(1 hunks)dpgen/generator/lib/abacus_scf.py
(6 hunks)dpgen/generator/lib/calypso_check_outcar.py
(1 hunks)dpgen/generator/lib/calypso_run_model_devi.py
(2 hunks)dpgen/generator/lib/calypso_run_opt.py
(1 hunks)dpgen/generator/lib/gaussian.py
(2 hunks)dpgen/generator/lib/lammps.py
(5 hunks)dpgen/generator/lib/make_calypso.py
(6 hunks)dpgen/generator/lib/pwmat.py
(1 hunks)dpgen/generator/lib/pwscf.py
(3 hunks)dpgen/generator/lib/run_calypso.py
(8 hunks)dpgen/generator/lib/siesta.py
(4 hunks)dpgen/generator/lib/utils.py
(2 hunks)dpgen/generator/run.py
(26 hunks)dpgen/simplify/simplify.py
(4 hunks)dpgen/tools/collect_data.py
(2 hunks)dpgen/tools/relabel.py
(4 hunks)dpgen/tools/stat_sys.py
(2 hunks)
✅ Files skipped from review due to trivial changes (43)
- dpgen/data/tools/sc.py
- dpgen/auto_test/lib/pwscf.py
- dpgen/data/tools/fcc.py
- dpgen/generator/lib/pwscf.py
- dpgen/auto_test/lib/abacus.py
- dpgen/data/tools/diamond.py
- dpgen/data/tools/bcc.py
- dpgen/generator/lib/calypso_check_outcar.py
- dpgen/data/surf.py
- dpgen/data/tools/hcp.py
- dpgen/auto_test/lib/siesta.py
- dpgen/generator/lib/abacus_scf.py
- dpgen/generator/lib/calypso_run_opt.py
- dpgen/auto_test/refine.py
- dpgen/data/tools/io_lammps.py
- dpgen/generator/lib/run_calypso.py
- dpgen/auto_test/lib/utils.py
- dpgen/data/tools/create_random_disturb.py
- dpgen/collect/collect.py
- dpgen/generator/lib/make_calypso.py
- dpgen/auto_test/VASP.py
- dpgen/auto_test/lib/lammps.py
- dpgen/generator/lib/utils.py
- dpgen/tools/stat_sys.py
- dpgen/data/tools/cessp2force_lin.py
- dpgen/tools/relabel.py
- dpgen/auto_test/common_prop.py
- dpgen/simplify/simplify.py
- dpgen/generator/lib/siesta.py
- dpgen/auto_test/reproduce.py
- dpgen/generator/lib/lammps.py
- dpgen/generator/lib/calypso_run_model_devi.py
- dpgen/auto_test/Elastic.py
- dpgen/data/gen.py
- dpgen/auto_test/lib/mfp_eosfit.py
- dpgen/generator/lib/gaussian.py
- dpgen/auto_test/Surface.py
- dpgen/auto_test/lib/vasp.py
- dpgen/data/reaction.py
- dpgen/tools/collect_data.py
- dpgen/generator/lib/pwmat.py
- dpgen/generator/run.py
- dpgen/auto_test/lib/lmp.py
🧰 Additional context used
🪛 Ruff (0.8.0)
dpgen/auto_test/Gamma.py
476-476: Use format specifiers instead of percent format
(UP031)
🔇 Additional comments (1)
.pre-commit-config.yaml (1)
31-31
: Update pre-commit hooks to latest versions and verify compatibility
The ruff-pre-commit
hook has been updated from v0.7.4
to v0.8.1
. Ensure that this version is compatible with your codebase and that any new features or changes are accounted for.
Run the following script to check for available updates and review the changelog:
✅ Verification successful
Update to ruff-pre-commit v0.8.1 is compatible with the codebase
The codebase's ruff configuration in pyproject.toml shows standard linting rules and the project is using common Python code style conventions. The update from v0.7.4 to v0.8.1 of ruff-pre-commit is safe as:
- The latest version is v0.8.1, confirming this is up-to-date
- The project's ruff configuration uses stable rule sets (isort, errors, pyflakes, pydocstyle, pyupgrade)
- No custom or deprecated rules are used that might be affected by the version update
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for the latest version of ruff-pre-commit and review the changelog.
# Fetch the latest release version
curl -s https://api.github.com/repos/astral-sh/ruff-pre-commit/releases/latest | jq '.tag_name'
# Review the changelog
echo "Please review the changelog at: https://github.com/astral-sh/ruff-pre-commit/releases/tag/v0.8.1"
Length of output: 307
Script:
#!/bin/bash
# Check for Python files and their ruff configuration
fd -e py -x echo "Python file: {}"
fd "ruff.toml|pyproject.toml" -x cat {}
Length of output: 11006
There was a problem hiding this 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 (6)
doc/conf.py (1)
22-22
: LGTM! The linter suppression is appropriate here.The addition of
# noqa: UP031
to suppress the warning about using f-strings instead of %-formatting is reasonable in this context. While f-strings are generally preferred in Python code, the current %-formatting approach is acceptable in configuration files, especially for simple year substitutions in copyright notices.If you'd like to use f-strings instead, here's an alternative:
-copyright = "2020-%d, DeepModeling" % date.today().year # noqa: UP031 +copyright = f"2020-{date.today().year}, DeepModeling"tests/generator/test_make_train.py (1)
52-52
: LGTM! The noqa suppressions for string formatting are appropriate.The use of %-formatting for fixed-width numbers in file paths is a valid pattern here since:
- It ensures consistent file/directory naming
- Maintains proper sorting of files
- Makes the width requirements explicit
While f-strings could be used (e.g.,
f"iter.{iter_idx:06d}"
), the current approach is consistent and clear.For future improvement, consider creating helper functions to centralize the path formatting:
def get_iter_path(iter_idx: int) -> str: """Get the iteration directory path with proper formatting.""" return f"iter.{iter_idx:06d}" def get_task_path(sys_idx: int, task_idx: int) -> str: """Get the task directory path with proper formatting.""" return f"task.{sys_idx:03d}.{task_idx:06d}"Also applies to: 83-83, 207-209, 212-212, 226-227, 419-419, 489-489, 548-552, 603-607
tests/generator/test_make_fp.py (2)
266-268
: LGTM! The changes are consistent with test_make_train.py.The noqa suppressions for string formatting follow the same pattern as in test_make_train.py, maintaining consistency across the test files. The use of %-formatting for fixed-width numbers in file paths is appropriate here for the same reasons.
Consider applying the same helper function suggestion as mentioned for test_make_train.py to maintain consistency across both files.
Also applies to: 307-309, 352-354, 383-385, 852-854, 1367-1367, 1381-1385
🧰 Tools
🪛 Ruff (0.8.0)
266-266: Use format specifiers instead of percent format
(UP031)
239-240
: Add missing noqa comment for consistency.This instance of %-formatting should also have a noqa comment for consistency with other changes:
- "%d %d %f %f %f\n" + "%d %d %f %f %f\n" # noqa: UP031 % (ii + 1, atype[ii] + 1, coord[ii][0], coord[ii][1], coord[ii][2])tests/generator/test_make_md.py (2)
Line range hint
701-718
: Use consistent path construction in test casesMultiple instances of string formatting for path construction could be replaced with f-strings or
os.path.join()
for better readability and maintainability.- os.path.join( - "iter.%06d" % 0, - "01.model_devi", - "task.000.000000", - "rc.rst7", # noqa: UP031 - ), + os.path.join( + f"iter.{0:06d}", + "01.model_devi", + "task.000.000000", + "rc.rst7", + ),🧰 Tools
🪛 Ruff (0.8.0)
701-701: Use format specifiers instead of percent format
(UP031)
40-40
: Consider updating to f-strings for better readabilityMultiple instances of %-formatting are used throughout the code. While they are marked with
# noqa: UP031
, consider updating to f-strings for better readability and maintainability.Examples:
- train_dir = os.path.join("iter.%06d" % idx, "00.train") # noqa: UP031 + train_dir = os.path.join(f"iter.{idx:06d}", "00.train") - md_dir = os.path.join("iter.%06d" % iter_idx, "01.model_devi") # noqa: UP031 + md_dir = os.path.join(f"iter.{iter_idx:06d}", "01.model_devi")Also applies to: 701-701, 715-715, 724-724
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (8)
doc/conf.py
(1 hunks)dpgen/auto_test/Gamma.py
(3 hunks)tests/auto_test/data.vasp.kp.gf/make_kp_test.py
(1 hunks)tests/generator/comp_sys.py
(7 hunks)tests/generator/gromacs/model_devi_case/model_devi.py
(1 hunks)tests/generator/test_make_fp.py
(26 hunks)tests/generator/test_make_md.py
(9 hunks)tests/generator/test_make_train.py
(10 hunks)
✅ Files skipped from review due to trivial changes (3)
- tests/generator/gromacs/model_devi_case/model_devi.py
- tests/auto_test/data.vasp.kp.gf/make_kp_test.py
- tests/generator/comp_sys.py
🚧 Files skipped from review as they are similar to previous changes (1)
- dpgen/auto_test/Gamma.py
🧰 Additional context used
🪛 Ruff (0.8.0)
tests/generator/test_make_train.py
207-207: Use format specifiers instead of percent format
(UP031)
550-550: Use format specifiers instead of percent format
(UP031)
605-605: Use format specifiers instead of percent format
(UP031)
tests/generator/test_make_fp.py
266-266: Use format specifiers instead of percent format
(UP031)
307-307: Use format specifiers instead of percent format
(UP031)
353-353: Use format specifiers instead of percent format
(UP031)
384-384: Use format specifiers instead of percent format
(UP031)
852-852: Use format specifiers instead of percent format
(UP031)
1384-1384: Use format specifiers instead of percent format
(UP031)
tests/generator/test_make_md.py
50-50: Use format specifiers instead of percent format
(UP031)
701-701: Use format specifiers instead of percent format
(UP031)
715-715: Use format specifiers instead of percent format
(UP031)
Summary by CodeRabbit
Overall, the changes focus on improving code quality and maintainability without altering the core functionality of the application.