diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 28e6fb296..0a5127d8f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -22,7 +22,7 @@ repos: - id: sort-simple-yaml - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.5.7' + rev: 'v0.6.0' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/dvc/commands/dag.py b/dvc/commands/dag.py index 46b44d0d6..221e83c63 100644 --- a/dvc/commands/dag.py +++ b/dvc/commands/dag.py @@ -17,7 +17,7 @@ def _show_ascii(graph: "DiGraph"): ret = [] for pipeline in pipelines: - ret.append(draw(pipeline.nodes, pipeline.edges)) + ret.append(draw(pipeline.nodes, pipeline.edges)) # noqa: PERF401 return "\n".join(ret) diff --git a/dvc/info.py b/dvc/info.py index fedf4a99e..6e225187a 100644 --- a/dvc/info.py +++ b/dvc/info.py @@ -123,7 +123,7 @@ def _get_supported_remotes(): if not fs_cls.get_missing_deps(): dependencies = [] for requirement in fs_cls.REQUIRES: - dependencies.append( + dependencies.append( # noqa: PERF401 f"{requirement} = {importlib_metadata.version(requirement)}" ) diff --git a/dvc/render/converter/vega.py b/dvc/render/converter/vega.py index 48f5843c0..6a60e8716 100644 --- a/dvc/render/converter/vega.py +++ b/dvc/render/converter/vega.py @@ -23,7 +23,7 @@ def _lists(blob: Union[dict, list]) -> Iterable[list]: if isinstance(blob, list): yield blob else: - for _, value in blob.items(): + for value in blob.values(): if isinstance(value, dict): yield from _lists(value) elif isinstance(value, list): diff --git a/dvc/repo/experiments/__init__.py b/dvc/repo/experiments/__init__.py index 9a374f50a..0cc8719c9 100644 --- a/dvc/repo/experiments/__init__.py +++ b/dvc/repo/experiments/__init__.py @@ -249,7 +249,7 @@ class Experiments: exec_results = queue.reproduce(copy_paths=copy_paths, message=message) results: dict[str, str] = {} - for _, exp_result in exec_results.items(): + for exp_result in exec_results.values(): results.update(exp_result) return results diff --git a/dvc/repo/experiments/executor/base.py b/dvc/repo/experiments/executor/base.py index fe30b935c..3ff373242 100644 --- a/dvc/repo/experiments/executor/base.py +++ b/dvc/repo/experiments/executor/base.py @@ -288,7 +288,7 @@ class BaseExecutor(ABC): stages = [] if targets: for target in targets: - stages.append( + stages.append( # noqa: PERF401 dvc.commit( target, recursive=recursive, force=True, relink=False ) diff --git a/dvc/repo/experiments/pull.py b/dvc/repo/experiments/pull.py index 41066e512..a1c7c63fb 100644 --- a/dvc/repo/experiments/pull.py +++ b/dvc/repo/experiments/pull.py @@ -55,7 +55,7 @@ def pull( # noqa: C901 rev_dict = iter_revs(repo.scm, rev, num) rev_set = set(rev_dict.keys()) ref_info_dict = exp_refs_by_baseline(repo.scm, rev_set, git_remote) - for _, ref_info_list in ref_info_dict.items(): + for ref_info_list in ref_info_dict.values(): exp_ref_set.update(ref_info_list) pull_result = _pull(repo, git_remote, exp_ref_set, force) diff --git a/dvc/repo/experiments/push.py b/dvc/repo/experiments/push.py index 0496e39ff..83614381a 100644 --- a/dvc/repo/experiments/push.py +++ b/dvc/repo/experiments/push.py @@ -78,7 +78,7 @@ def exp_refs_from_rev(scm: "Git", rev: list[str], num: int = 1) -> set["ExpRefIn rev_dict = iter_revs(scm, rev, num) rev_set = set(rev_dict.keys()) ref_info_dict = exp_refs_by_baseline(scm, rev_set) - for _, ref_info_list in ref_info_dict.items(): + for ref_info_list in ref_info_dict.values(): exp_ref_set.update(ref_info_list) return exp_ref_set diff --git a/dvc/repo/experiments/queue/celery.py b/dvc/repo/experiments/queue/celery.py index d55163afa..fa7dbff1c 100644 --- a/dvc/repo/experiments/queue/celery.py +++ b/dvc/repo/experiments/queue/celery.py @@ -323,7 +323,7 @@ class LocalCeleryQueue(BaseStashQueue): def _get_running_task_ids(self) -> set[str]: running_task_ids: set[str] = set() active_workers = self.worker_status() - for _, tasks in active_workers.items(): + for tasks in active_workers.values(): task = first(tasks) if task: running_task_ids.add(task["id"]) diff --git a/dvc/repo/experiments/queue/utils.py b/dvc/repo/experiments/queue/utils.py index f1867c837..5dcd5c290 100644 --- a/dvc/repo/experiments/queue/utils.py +++ b/dvc/repo/experiments/queue/utils.py @@ -25,7 +25,7 @@ def get_remote_executor_refs(scm: "Git", remote_url: str) -> list[str]: refs = [] for ref in iter_remote_refs(scm, remote_url, base=EXPS_NAMESPACE): if not ref.startswith(EXEC_NAMESPACE) and ref != EXPS_STASH: - refs.append(ref) + refs.append(ref) # noqa: PERF401 return refs diff --git a/dvc/repo/experiments/remove.py b/dvc/repo/experiments/remove.py index 894ecb1e5..bcc2511cf 100644 --- a/dvc/repo/experiments/remove.py +++ b/dvc/repo/experiments/remove.py @@ -98,7 +98,7 @@ def _resolve_exp_by_baseline( rev_dict = iter_revs(repo.scm, rev, num) rev_set = set(rev_dict.keys()) ref_info_dict = exp_refs_by_baseline(repo.scm, rev_set, git_remote) - for _, ref_info_list in ref_info_dict.items(): + for ref_info_list in ref_info_dict.values(): for ref_info in ref_info_list: commit_ref_dict[ref_info.name] = ref_info return commit_ref_dict diff --git a/dvc/stage/utils.py b/dvc/stage/utils.py index 1575db6d7..9e335cf3e 100644 --- a/dvc/stage/utils.py +++ b/dvc/stage/utils.py @@ -302,9 +302,9 @@ def _get_stage_files(stage: "Stage") -> list[str]: and dep.is_in_repo and not stage.repo.dvcfs.isdvc(stage.repo.dvcfs.from_os_path(str(dep))) ): - ret.append(relpath(dep.fs_path)) + ret.append(relpath(dep.fs_path)) # noqa: PERF401 for out in stage.outs: if not out.use_scm_ignore and out.is_in_repo: - ret.append(relpath(out.fs_path)) + ret.append(relpath(out.fs_path)) # noqa: PERF401 return ret diff --git a/dvc/testing/path_info.py b/dvc/testing/path_info.py index b7fe23b60..ff0ab4dd8 100644 --- a/dvc/testing/path_info.py +++ b/dvc/testing/path_info.py @@ -32,7 +32,7 @@ class PathInfo(pathlib.PurePath, _BasePath): def __new__(cls, *args): if cls is PathInfo: - cls = WindowsPathInfo if os.name == "nt" else PosixPathInfo + cls = WindowsPathInfo if os.name == "nt" else PosixPathInfo # noqa: PLW0642 return cls._from_parts(args) # type: ignore[attr-defined] diff --git a/dvc/testing/tmp_dir.py b/dvc/testing/tmp_dir.py index 57272adb4..33378d0eb 100644 --- a/dvc/testing/tmp_dir.py +++ b/dvc/testing/tmp_dir.py @@ -71,7 +71,7 @@ class TmpDir(pathlib.Path): def __new__(cls, *args, **kwargs): if cls is TmpDir: - cls = WindowsTmpDir if os.name == "nt" else PosixTmpDir + cls = WindowsTmpDir if os.name == "nt" else PosixTmpDir # noqa: PLW0642 # init parameter and `_init` method has been removed in Python 3.10. kw = {"init": False} if sys.version_info < (3, 10) else {} diff --git a/dvc/utils/__init__.py b/dvc/utils/__init__.py index a43d11ac7..850efe3b9 100644 --- a/dvc/utils/__init__.py +++ b/dvc/utils/__init__.py @@ -243,7 +243,7 @@ def env2bool(var, undefined=False): var = os.getenv(var, None) if var is None: return undefined - return bool(re.search("1|y|yes|true", var, flags=re.I)) + return bool(re.search("1|y|yes|true", var, flags=re.IGNORECASE)) def resolve_output(inp: str, out: Optional[str], force=False) -> str: diff --git a/pyproject.toml b/pyproject.toml index cc916be87..20f053ddd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -264,21 +264,19 @@ show-fixes = true [tool.ruff.lint] ignore = [ - "N818", "S101", "ISC001", "PT004", "PT007", "RET502", "RET503", "SIM105", "SIM108", "SIM117", - "TRY003", "TRY300", "PLR2004", "PLW2901", "LOG007", + "N818", "S101", "ISC001", "PT007", "RET502", "RET503", "SIM105", "SIM108", "SIM117", + "TRY003", "TRY300", "PERF203", "PLR2004", "PLW2901", "LOG007", ] select = [ "F", "E", "W", "C90", "I", "N", "UP", "YTT", "ASYNC", "S", "BLE", "B", "A", "C4", "DTZ", "T10", - "EXE", "ISC", "ICN", "G", "INP", "PIE", "T20", "PYI", "PT", "Q", "RSE", "RET", + "EXE", "ISC", "ICN", "LOG", "G", "INP", "PIE", "T20", "PYI", "PT", "Q", "RSE", "RET", "SLOT", "SIM", "TID", "TCH", "ARG", "PGH", "PLC", "PLE", "PLR", "PLW", "TRY", - "FLY", "PERF101", "LOG", "RUF", "RUF022", "RUF023", "RUF024", "RUF025", "RUF026", "RUF027" + "FLY", "PERF", "FURB", "RUF", "RUF022", "RUF023", "RUF024", "RUF026", "RUF027", "RUF029", "RUF030", ] preview = true explicit-preview-rules = true [tool.ruff.lint.flake8-pytest-style] -fixture-parentheses = false -mark-parentheses = false parametrize-names-type = "csv" raises-extend-require-match-for = ["dvc.exceptions.DvcException", "dvc.scm.SCMError", "scmrepo.exceptions.SCMError"] @@ -305,4 +303,4 @@ max-args = 10 "dvc/commands/**" = ["N806"] "dvc/testing/**" = ["ARG002"] "dvc/testing/benchmarks/**" = ["ARG001"] -"tests/**" = ["S", "ARG001", "ARG002", "TRY002", "TRY301"] +"tests/**" = ["S", "ARG001", "ARG002", "TRY002", "TRY301", "PERF"] diff --git a/tests/func/test_daemon.py b/tests/func/test_daemon.py index bef6fcec7..070ea31b9 100644 --- a/tests/func/test_daemon.py +++ b/tests/func/test_daemon.py @@ -109,11 +109,13 @@ def test_analytics(tmp_path, server): text=True, ) - match = re.search(r".*Saving analytics report to (.*)", output, flags=re.M) + match = re.search(r".*Saving analytics report to (.*)", output, flags=re.MULTILINE) assert match, "no match for the report file" report_file = match.group(1).strip() - match = re.search(r".*Spawned .*analytics.* with pid (.*)", output, flags=re.M) + match = re.search( + r".*Spawned .*analytics.* with pid (.*)", output, flags=re.MULTILINE + ) assert match, "no match for the pid" pid = int(match.group(1).strip()) @@ -148,7 +150,9 @@ def test_updater(tmp_dir, dvc, server): text=True, ) - match = re.search(r".*Spawned .*updater.* with pid (.*)", output, flags=re.M) + match = re.search( + r".*Spawned .*updater.* with pid (.*)", output, flags=re.MULTILINE + ) assert match, "no match for the pid" pid = int(match.group(1).strip())