From a33ce344457717afbc488826d2737016aef04009 Mon Sep 17 00:00:00 2001 From: Janosh Riebesell Date: Thu, 3 Aug 2023 09:30:54 -0700 Subject: [PATCH] fix ruff PERF401 errors --- .pre-commit-config.yaml | 4 ++-- custodian/vasp/jobs.py | 13 +++++-------- pyproject.toml | 5 ++--- tasks.py | 13 ++++--------- 4 files changed, 13 insertions(+), 22 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 71f67698..ff91e7e8 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,4 +1,4 @@ -exclude: ^(docs|.*test_files|tests) +exclude: ^(docs|test_files|tests) ci: autoupdate_schedule: monthly @@ -8,7 +8,7 @@ ci: repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.281 + rev: v0.0.282 hooks: - id: ruff args: [--fix, --ignore, D] diff --git a/custodian/vasp/jobs.py b/custodian/vasp/jobs.py index 201f26d5..5b23a84c 100644 --- a/custodian/vasp/jobs.py +++ b/custodian/vasp/jobs.py @@ -778,14 +778,11 @@ def __init__( self.gamma_vasp_cmd = tuple(gamma_vasp_cmd) if gamma_vasp_cmd else None self.auto_continue = auto_continue self.settings_override = settings_override - self.neb_dirs = [] # 00, 01, etc. - self.neb_sub = [] # 01, 02, etc. - - for path in os.listdir("."): - if os.path.isdir(path) and path.isdigit(): - self.neb_dirs.append(path) - self.neb_dirs = sorted(self.neb_dirs) - self.neb_sub = self.neb_dirs[1:-1] + + self.neb_dirs = sorted( # 00, 01, etc. + path for path in os.listdir(".") if os.path.isdir(path) and path.isdigit() + ) + self.neb_sub = self.neb_dirs[1:-1] # 01, 02, etc. def setup(self): """ diff --git a/pyproject.toml b/pyproject.toml index 94c71935..ae5c7a8f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,7 +46,6 @@ ignore = [ "PD011", # pandas-use-of-dot-values "PD901", # pandas-df-variable-name "PERF203", # try-except-in-loop - "PERF401", # manual-list-comprehension (TODO fix these or wait for autofix) "PLR", # pylint refactor "PLW2901", # Outer for loop variable overwritten by inner assignment target "PT013", # pytest-incorrect-pytest-import @@ -82,12 +81,12 @@ exclude_lines = [ "@deprecated", "def __repr__", "if 0:", + "if TYPE_CHECKING:", "if __name__ == .__main__.:", "if self.debug:", "if settings.DEBUG", + "input", "pragma: no cover", "raise AssertionError", "raise NotImplementedError", - "input", - "if TYPE_CHECKING:" ] diff --git a/tasks.py b/tasks.py index 18d79d95..a49f8d43 100755 --- a/tasks.py +++ b/tasks.py @@ -75,20 +75,15 @@ def test(ctx): @task def set_ver(ctx): - lines = [] with open("custodian/__init__.py") as file: - for line in file: - if "__version__" in line: - lines.append(f'__version__ = "{NEW_VER}"') - else: - lines.append(line.rstrip()) + lines = [f'__version__ = "{NEW_VER}"' if "__version__" in line else line.rstrip() for line in file] + with open("custodian/__init__.py", "w") as file: file.write("\n".join(lines) + "\n") - lines = [] with open("setup.py") as file: - for line in file: - lines.append(re.sub(r"version=([^,]+),", f'version="{NEW_VER}",', line.rstrip())) + lines = [re.sub(r"version=([^,]+),", f'version="{NEW_VER}",', line.rstrip()) for line in file] + with open("setup.py", "w") as file: file.write("\n".join(lines) + "\n")