diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 2dbba16a6..cc26637d1 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.2.2' + rev: 'v0.3.2' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/dvc/__init__.py b/dvc/__init__.py index f07a37dab..a0e4f420f 100644 --- a/dvc/__init__.py +++ b/dvc/__init__.py @@ -3,6 +3,7 @@ DVC ---- Make your data science projects reproducible and shareable. """ + import dvc.logger from dvc.build import PKG # noqa: F401 from dvc.version import __version__, version_tuple # noqa: F401 diff --git a/dvc/__main__.py b/dvc/__main__.py index df6e3a3ee..8ac8c4cc7 100644 --- a/dvc/__main__.py +++ b/dvc/__main__.py @@ -1,4 +1,5 @@ """Main entry point for DVC command line tool.""" + import sys from dvc.cli import main diff --git a/dvc/cli/parser.py b/dvc/cli/parser.py index 95ca31ce6..3dcec156a 100644 --- a/dvc/cli/parser.py +++ b/dvc/cli/parser.py @@ -1,4 +1,5 @@ """Main parser for the dvc cli.""" + import argparse import os from functools import lru_cache diff --git a/dvc/compare.py b/dvc/compare.py index 26c91e28d..86abef09f 100644 --- a/dvc/compare.py +++ b/dvc/compare.py @@ -88,12 +88,10 @@ class TabularData(MutableSequence[Sequence["CellT"]]): return list(it) @overload - def __setitem__(self, item: int, value: Sequence["CellT"]) -> None: - ... + def __setitem__(self, item: int, value: Sequence["CellT"]) -> None: ... @overload - def __setitem__(self, item: slice, value: Iterable[Sequence["CellT"]]) -> None: - ... + def __setitem__(self, item: slice, value: Iterable[Sequence["CellT"]]) -> None: ... def __setitem__(self, item, value) -> None: it = value diff --git a/dvc/config.py b/dvc/config.py index 3522404ea..89d9fb489 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -1,4 +1,5 @@ """DVC config objects.""" + import os import re from contextlib import contextmanager diff --git a/dvc/dependency/db.py b/dvc/dependency/db.py index 6cdbd169e..95095cbb4 100644 --- a/dvc/dependency/db.py +++ b/dvc/dependency/db.py @@ -22,9 +22,12 @@ def download_progress(to: "Output") -> Iterator[Callable[[int], Any]]: from dvc.ui import ui from dvc.ui._rich_progress import DbDownloadProgress - with log_durations(logger.debug, f"Saving to {to}"), DbDownloadProgress( - console=ui.error_console, - ) as progress: + with ( + log_durations(logger.debug, f"Saving to {to}"), + DbDownloadProgress( + console=ui.error_console, + ) as progress, + ): task = progress.add_task("Saving", total=None, output=to) yield lambda n: progress.advance(task, advance=n) progress.update(task, description="Saved", total=0) diff --git a/dvc/dvcfile.py b/dvc/dvcfile.py index 134378f3b..dde1aac8a 100644 --- a/dvc/dvcfile.py +++ b/dvc/dvcfile.py @@ -68,10 +68,9 @@ def is_git_ignored(repo, path): def check_dvcfile_path(repo, path): if not is_valid_filename(path): raise StageFileBadNameError( - "bad DVC file name '{}'. DVC files should be named " - "'{}' or have a '.dvc' suffix (e.g. '{}.dvc').".format( - relpath(path), PROJECT_FILE, os.path.basename(path) - ) + f"bad DVC file name '{relpath(path)}'. DVC files should be named " + f"'{PROJECT_FILE}' or have a '.dvc' suffix " + f"(e.g. '{os.path.basename(path)}.dvc')." ) if is_git_ignored(repo, path): diff --git a/dvc/exceptions.py b/dvc/exceptions.py index bf1f418e8..01cdeeac4 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -1,4 +1,5 @@ """Exceptions raised by the dvc.""" + import errno from typing import TYPE_CHECKING, Optional @@ -270,9 +271,8 @@ class NoOutputInExternalRepoError(DvcException): from dvc.utils import relpath super().__init__( - "Output '{}' not found in target repository '{}'".format( - relpath(path, external_repo_path), external_repo_url - ) + f"Output {relpath(path, external_repo_path)!r} " + f"not found in target repository '{external_repo_url}'" ) diff --git a/dvc/progress.py b/dvc/progress.py index 4ed6750b3..00cb09e39 100644 --- a/dvc/progress.py +++ b/dvc/progress.py @@ -1,4 +1,5 @@ """Manages progress bars for DVC repo.""" + import logging import sys from threading import RLock diff --git a/dvc/repo/experiments/executor/local.py b/dvc/repo/experiments/executor/local.py index a8c19473a..ac442af70 100644 --- a/dvc/repo/experiments/executor/local.py +++ b/dvc/repo/experiments/executor/local.py @@ -96,9 +96,10 @@ class TempDirExecutor(BaseLocalExecutor): temp_merge: stash_rev, temp_baseline: entry.baseline_rev, } - with get_exp_rwlock( - repo, writes=[temp_head, temp_merge, temp_baseline] - ), self.set_temp_refs(scm, temp_ref_dict): + with ( + get_exp_rwlock(repo, writes=[temp_head, temp_merge, temp_baseline]), + self.set_temp_refs(scm, temp_ref_dict), + ): # Executor will be initialized with an empty git repo that # we populate by pushing: # EXEC_HEAD - the base commit for this experiment diff --git a/dvc/repo/experiments/queue/celery.py b/dvc/repo/experiments/queue/celery.py index 2c5e86188..3370b7cff 100644 --- a/dvc/repo/experiments/queue/celery.py +++ b/dvc/repo/experiments/queue/celery.py @@ -474,10 +474,10 @@ class LocalCeleryQueue(BaseStashQueue): self.scm, exp_names, git_remote ) if not git_remote: - queue_entry_match: dict[ - str, Optional["QueueEntry"] - ] = self.match_queue_entry_by_name( - exp_names, self.iter_queued(), self.iter_done() + queue_entry_match: dict[str, Optional["QueueEntry"]] = ( + self.match_queue_entry_by_name( + exp_names, self.iter_queued(), self.iter_done() + ) ) for exp_name in exp_names: diff --git a/dvc/repo/experiments/remove.py b/dvc/repo/experiments/remove.py index 2fc7373ec..af1297c68 100644 --- a/dvc/repo/experiments/remove.py +++ b/dvc/repo/experiments/remove.py @@ -44,9 +44,9 @@ def remove( # noqa: C901, PLR0912 exp_ref_list: list["ExpRefInfo"] = [] queue_entry_list: list["QueueEntry"] = [] if exp_names: - results: dict[ - str, "ExpRefAndQueueEntry" - ] = celery_queue.get_ref_and_entry_by_names(exp_names, git_remote) + results: dict[str, "ExpRefAndQueueEntry"] = ( + celery_queue.get_ref_and_entry_by_names(exp_names, git_remote) + ) remained: list[str] = [] for name, result in results.items(): if not result.exp_ref_info and not result.queue_entry: diff --git a/dvc/repo/trie.py b/dvc/repo/trie.py index de5ed0885..660240fe7 100644 --- a/dvc/repo/trie.py +++ b/dvc/repo/trie.py @@ -25,15 +25,11 @@ def build_outs_trie(stages): overlapping = out if parent and overlapping: msg = ( - "The output paths:\n'{}'('{}')\n'{}'('{}')\n" + f"The output paths:\n'{parent!s}'('{parent.stage.addressing}')\n" + f"'{overlapping!s}'('{overlapping.stage.addressing}')\n" "overlap and are thus in the same tracked directory.\n" "To keep reproducibility, outputs should be in separate " "tracked directories or tracked individually." - ).format( - str(parent), - parent.stage.addressing, - str(overlapping), - overlapping.stage.addressing, ) raise OverlappingOutputPathsError(parent, overlapping, msg) diff --git a/dvc/scm.py b/dvc/scm.py index 763f7718f..4314ea1a7 100644 --- a/dvc/scm.py +++ b/dvc/scm.py @@ -1,4 +1,5 @@ """Manages source control systems (e.g. Git).""" + import os from collections.abc import Iterator, Mapping from contextlib import contextmanager @@ -70,8 +71,7 @@ def SCM( *, search_parent_directories: bool = ..., no_scm: Literal[False] = ..., -) -> "Git": - ... +) -> "Git": ... @overload @@ -80,8 +80,7 @@ def SCM( *, search_parent_directories: bool = ..., no_scm: Literal[True], -) -> "NoSCM": - ... +) -> "NoSCM": ... @overload @@ -90,8 +89,7 @@ def SCM( *, search_parent_directories: bool = ..., no_scm: bool = ..., -) -> Union["Git", "NoSCM"]: - ... +) -> Union["Git", "NoSCM"]: ... def SCM(root_dir, *, search_parent_directories=True, no_scm=False): diff --git a/dvc/testing/benchmarks/cli/stories/test_modify_data.py b/dvc/testing/benchmarks/cli/stories/test_modify_data.py index 65a600b41..8c0e08de7 100644 --- a/dvc/testing/benchmarks/cli/stories/test_modify_data.py +++ b/dvc/testing/benchmarks/cli/stories/test_modify_data.py @@ -1,6 +1,7 @@ """ Tests for modifications to an existing dataset. """ + import glob import os import random diff --git a/dvc/utils/collections.py b/dvc/utils/collections.py index d8c38c317..05598d9d7 100644 --- a/dvc/utils/collections.py +++ b/dvc/utils/collections.py @@ -39,9 +39,7 @@ def apply_diff(src, dest): # noqa: C901 dest[i] = value else: raise AssertionError( # noqa: TRY004 - "Can't apply diff from {} to {}".format( - src.__class__.__name__, dest.__class__.__name__ - ) + f"Can't apply diff from {type(src).__name__} to {type(dest).__name__}" ) diff --git a/dvc/utils/serialize/_common.py b/dvc/utils/serialize/_common.py index 46bc6907f..fde893343 100644 --- a/dvc/utils/serialize/_common.py +++ b/dvc/utils/serialize/_common.py @@ -1,4 +1,5 @@ """Common utilities for serialize.""" + import os from contextlib import AbstractContextManager, contextmanager from typing import TYPE_CHECKING, Any, Callable, Optional, Protocol, TextIO, Union @@ -15,25 +16,21 @@ if TYPE_CHECKING: class DumperFn(Protocol): def __call__( self, path: "StrPath", data: Any, fs: Optional["FileSystem"] = None - ) -> Any: - ... + ) -> Any: ... class DumpersFn(Protocol): - def __call__(self, data: Any, stream: TextIO) -> Any: - ... + def __call__(self, data: Any, stream: TextIO) -> Any: ... class ModifierFn(Protocol): def __call__( self, path: "StrPath", fs: Optional["FileSystem"] = None - ) -> AbstractContextManager[dict]: - ... + ) -> AbstractContextManager[dict]: ... class LoaderFn(Protocol): - def __call__(self, path: "StrPath", fs: Optional["FileSystem"] = None) -> Any: - ... + def __call__(self, path: "StrPath", fs: Optional["FileSystem"] = None) -> Any: ... ReadType = Union[bytes, None, str] diff --git a/dvc/utils/strictyaml.py b/dvc/utils/strictyaml.py index 7d6a11ce6..50926c65c 100644 --- a/dvc/utils/strictyaml.py +++ b/dvc/utils/strictyaml.py @@ -6,6 +6,7 @@ Used for parsing dvc.yaml, dvc.lock and .dvc files. Not to be confused with strictyaml, a python library with similar motivations. """ + import re import typing from contextlib import suppress diff --git a/tests/dir_helpers.py b/tests/dir_helpers.py index 3a473de7e..ac6e92d91 100644 --- a/tests/dir_helpers.py +++ b/tests/dir_helpers.py @@ -43,7 +43,6 @@ from global repo template to creating everything inplace, which: - does not create unnecessary files """ - import os import pytest diff --git a/tests/func/experiments/test_show.py b/tests/func/experiments/test_show.py index 5b7b1648c..496f09935 100644 --- a/tests/func/experiments/test_show.py +++ b/tests/func/experiments/test_show.py @@ -453,15 +453,11 @@ def test_show_csv(tmp_dir, scm, dvc, exp_stage, capsys): in cap.out ) assert ( - "{},{},branch_base,{},,2,2,{}".format( - ref_info1.name, rev1[:7], _get_rev_isotimestamp(rev1), data_hash - ) + f"{ref_info1.name},{rev1[:7]},branch_base,{_get_rev_isotimestamp(rev1)},,2,2,{data_hash}" in cap.out ) assert ( - "{},{},branch_commit,{},,3,3,{}".format( - ref_info2.name, rev2[:7], _get_rev_isotimestamp(rev2), data_hash - ) + f"{ref_info2.name},{rev2[:7]},branch_commit,{_get_rev_isotimestamp(rev2)},,3,3,{data_hash}" in cap.out ) diff --git a/tests/func/parsing/test_errors.py b/tests/func/parsing/test_errors.py index a733e4696..a1f621630 100644 --- a/tests/func/parsing/test_errors.py +++ b/tests/func/parsing/test_errors.py @@ -1,6 +1,5 @@ """Negative tests for the parametrization.""" - import logging import re diff --git a/tests/func/parsing/test_foreach.py b/tests/func/parsing/test_foreach.py index eeda0e6f7..105f53f7a 100644 --- a/tests/func/parsing/test_foreach.py +++ b/tests/func/parsing/test_foreach.py @@ -1,4 +1,5 @@ """Testing happy paths for the foreach.""" + import os import pytest