From 3375a7c39fdc64df1442aedae334fb7e693cbe7d Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 26 Mar 2024 06:37:53 +0000 Subject: [PATCH] [pre-commit.ci] pre-commit autoupdate (#10372) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.3.3 → v0.3.4](https://github.com/astral-sh/ruff-pre-commit/compare/v0.3.3...v0.3.4) * fixes --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Saugat Pachhai (सौगात) --- .pre-commit-config.yaml | 2 +- dvc/_debug.py | 2 +- dvc/exceptions.py | 6 +++--- dvc/repo/__init__.py | 6 +----- dvc/repo/experiments/collect.py | 4 ++-- dvc/repo/experiments/queue/base.py | 2 +- dvc/repo/experiments/show.py | 2 +- dvc/repo/fetch.py | 10 +++------- dvc/repo/plots/__init__.py | 6 ++---- dvc/repo/worktree.py | 8 ++------ dvc/scm.py | 4 +++- dvc/stage/utils.py | 4 +--- pyproject.toml | 4 ++-- tests/func/experiments/test_show.py | 6 +++--- tests/func/test_gc.py | 2 +- tests/unit/command/test_dataset.py | 8 ++++---- tests/unit/command/test_queue.py | 4 ++-- tests/unit/repo/experiments/queue/test_celery.py | 16 ++++++++-------- tests/unit/repo/experiments/test_collect.py | 2 +- tests/unit/scm/test_scm.py | 8 ++++---- tests/unit/test_logger.py | 3 ++- tests/unit/ui/test_console.py | 2 +- tests/unit/utils/test_fs.py | 4 +--- 23 files changed, 50 insertions(+), 65 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5e852dd4b..76865f83e 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.3.3' + rev: 'v0.3.4' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/dvc/_debug.py b/dvc/_debug.py index ae311ffcf..75b9a0022 100644 --- a/dvc/_debug.py +++ b/dvc/_debug.py @@ -162,7 +162,7 @@ def _get_path_func(tool: str, ext: str): fmt = f"{tool}.dvc-{{now:%Y%m%d}}_{{now:%H%M%S}}.{ext}" def func(now: Optional["datetime"] = None) -> str: - return fmt.format(now=now or datetime.now()) + return fmt.format(now=now or datetime.now()) # noqa: DTZ005 return func diff --git a/dvc/exceptions.py b/dvc/exceptions.py index 01cdeeac4..f72b0dd62 100644 --- a/dvc/exceptions.py +++ b/dvc/exceptions.py @@ -133,11 +133,11 @@ class MoveNotDataSourceError(DvcException): def __init__(self, path): msg = ( "move is not permitted for stages that are not data sources. " - "You need to either move '{path}' to a new location and edit " - "it by hand, or remove '{path}' and create a new one at the " + f"You need to either move {path!r} to a new location and edit " + f"it by hand, or remove {path!r} and create a new one at the " "desired location." ) - super().__init__(msg.format(path=path)) + super().__init__(msg) class NotDvcRepoError(DvcException): diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py index 7ca79a74d..8d67614e0 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -551,11 +551,7 @@ class Repo: if out.protocol == "local" and match(fs_path, out.fs_path): return True - - if recursive and out.fs.isin(out.fs_path, fs_path): - return True - - return False + return recursive and out.fs.isin(out.fs_path, fs_path) matched = list(filter(func, outs)) if not matched: diff --git a/dvc/repo/experiments/collect.py b/dvc/repo/experiments/collect.py index ed96b9804..428630ed0 100644 --- a/dvc/repo/experiments/collect.py +++ b/dvc/repo/experiments/collect.py @@ -78,7 +78,7 @@ def _collect_rev( timestamp: Optional[datetime] = None else: commit = repo.scm.resolve_commit(rev) - timestamp = datetime.fromtimestamp(commit.commit_time) + timestamp = datetime.fromtimestamp(commit.commit_time) # noqa: DTZ006 return SerializableExp.from_repo( repo, @@ -338,6 +338,6 @@ def _sorted_ranges(exp_ranges: Iterable["ExpRange"]) -> list["ExpRange"]: if head_exp and head_exp.data and head_exp.data.timestamp: return head_exp.data.timestamp, head_exp.rev - return datetime.fromtimestamp(0), "" + return datetime.fromtimestamp(0), "" # noqa: DTZ006 return sorted(exp_ranges, key=_head_timestamp, reverse=True) diff --git a/dvc/repo/experiments/queue/base.py b/dvc/repo/experiments/queue/base.py index d0f969290..ab686fbb2 100644 --- a/dvc/repo/experiments/queue/base.py +++ b/dvc/repo/experiments/queue/base.py @@ -180,7 +180,7 @@ class BaseStashQueue(ABC): def _get_timestamp(rev: str) -> datetime: commit = self.scm.resolve_commit(rev) - return datetime.fromtimestamp(commit.commit_time) + return datetime.fromtimestamp(commit.commit_time) # noqa: DTZ006 def _format_entry( entry: QueueEntry, diff --git a/dvc/repo/experiments/show.py b/dvc/repo/experiments/show.py index 16ab9b38f..fe5aae8bc 100644 --- a/dvc/repo/experiments/show.py +++ b/dvc/repo/experiments/show.py @@ -306,7 +306,7 @@ def format_time( return fill_value if iso: return timestamp.isoformat() - if timestamp.date() == date.today(): + if timestamp.date() == date.today(): # noqa: DTZ011 fmt = "%I:%M %p" else: fmt = "%b %d, %Y" diff --git a/dvc/repo/fetch.py b/dvc/repo/fetch.py index 1bf95a074..05f92921d 100644 --- a/dvc/repo/fetch.py +++ b/dvc/repo/fetch.py @@ -22,7 +22,7 @@ def _make_index_onerror(onerror, rev): return _onerror -def _collect_indexes( # noqa: PLR0913, C901 +def _collect_indexes( # noqa: PLR0913 repo, targets=None, remote=None, @@ -49,16 +49,12 @@ def _collect_indexes( # noqa: PLR0913, C901 config["core"] = core def stage_filter(stage: "Stage") -> bool: - if push and stage.is_repo_import: - return False - return True + return not (push and stage.is_repo_import) def outs_filter(out: "Output") -> bool: if push and not out.can_push: return False - if remote and out.remote and remote != out.remote: - return False - return True + return not (remote and out.remote and remote != out.remote) for rev in repo.brancher( revs=revs, diff --git a/dvc/repo/plots/__init__.py b/dvc/repo/plots/__init__.py index 7fcae7fd1..9412abbe3 100644 --- a/dvc/repo/plots/__init__.py +++ b/dvc/repo/plots/__init__.py @@ -369,11 +369,9 @@ def _matches(targets, config_file, plot_id): return True full_id = get_plot_id(plot_id, config_file) - if any( + return any( (re.match(target, plot_id) or re.match(target, full_id)) for target in targets - ): - return True - return False + ) def _normpath(path): diff --git a/dvc/repo/worktree.py b/dvc/repo/worktree.py index dbcbd28e6..cfb62e6e2 100644 --- a/dvc/repo/worktree.py +++ b/dvc/repo/worktree.py @@ -76,14 +76,10 @@ def worktree_view( """ def stage_filter(stage: "Stage") -> bool: - if push and stage.is_repo_import: - return False - return True + return not (push and stage.is_repo_import) def outs_filter(out: "Output") -> bool: - if not out.is_in_repo or not out.use_cache or (push and not out.can_push): - return False - return True + return out.is_in_repo and out.use_cache and (not push or out.can_push) return index.targets_view( targets, diff --git a/dvc/scm.py b/dvc/scm.py index 4314ea1a7..1e6de3e72 100644 --- a/dvc/scm.py +++ b/dvc/scm.py @@ -239,7 +239,9 @@ def iter_revs( if commit_date: from datetime import datetime - commit_datestamp = datetime.strptime(commit_date, "%Y-%m-%d").timestamp() + commit_datestamp = ( + datetime.strptime(commit_date, "%Y-%m-%d").timestamp() # noqa: DTZ007 + ) def _time_filter(rev): try: diff --git a/dvc/stage/utils.py b/dvc/stage/utils.py index 70b2d249a..1575db6d7 100644 --- a/dvc/stage/utils.py +++ b/dvc/stage/utils.py @@ -92,9 +92,7 @@ def check_no_externals(stage): from dvc.utils import format_link def _is_cached_external(out): - if out.is_in_repo or not out.use_cache: - return False - return True + return not out.is_in_repo and out.use_cache outs = [str(out) for out in stage.outs if _is_cached_external(out)] if not outs: diff --git a/pyproject.toml b/pyproject.toml index c8525cad7..f0a36ff97 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -267,10 +267,10 @@ ignore = [ "TRY003", "TRY300", "PLR2004", "PLW2901", "LOG007", ] select = [ - "F", "E", "W", "C90", "I", "N", "UP", "YTT", "ASYNC", "S", "BLE", "B", "A", "C4", "T10", + "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", "SLOT", "SIM", "TID", "TCH", "ARG", "PGH", "PLC", "PLE", "PLR", "PLW", "TRY", - "FLY", "PERF101", "LOG", "RUF", "RUF022", "RUF023", "RUF024", "RUF025", "RUF026", + "FLY", "PERF101", "LOG", "RUF", "RUF022", "RUF023", "RUF024", "RUF025", "RUF026", "RUF027" ] preview = true explicit-preview-rules = true diff --git a/tests/func/experiments/test_show.py b/tests/func/experiments/test_show.py index 496f09935..54ef4ba6d 100644 --- a/tests/func/experiments/test_show.py +++ b/tests/func/experiments/test_show.py @@ -101,7 +101,7 @@ def test_show_simple(tmp_dir, scm, dvc, exp_stage): @pytest.mark.parametrize("workspace", [True, False]) def test_show_experiment(tmp_dir, scm, dvc, exp_stage, workspace): baseline_rev = scm.get_rev() - timestamp = datetime.fromtimestamp( + timestamp = datetime.fromtimestamp( # noqa: DTZ006 scm.gitpython.repo.rev_parse(baseline_rev).committed_date ) @@ -423,7 +423,7 @@ def test_show_csv(tmp_dir, scm, dvc, exp_stage, capsys): baseline_rev = scm.get_rev() def _get_rev_isotimestamp(rev): - return datetime.fromtimestamp( + return datetime.fromtimestamp( # noqa: DTZ006 scm.gitpython.repo.rev_parse(rev).committed_date ).isoformat() @@ -652,7 +652,7 @@ def test_metrics_renaming(tmp_dir, dvc, scm, capsys, copy_script): cap = capsys.readouterr() def _get_rev_isotimestamp(rev): - return datetime.fromtimestamp( + return datetime.fromtimestamp( # noqa: DTZ006 scm.gitpython.repo.rev_parse(rev).committed_date ).isoformat() diff --git a/tests/func/test_gc.py b/tests/func/test_gc.py index 5df851e8a..b4f6af2cc 100644 --- a/tests/func/test_gc.py +++ b/tests/func/test_gc.py @@ -297,7 +297,7 @@ def test_gc_rev_num(tmp_dir, scm, dvc): def test_date(tmp_dir, scm, dvc): tmp_dir.dvc_gen("testfile", "content", commit="add testfile") - now = datetime.datetime.now() + now = datetime.datetime.now(tz=datetime.timezone.utc) datestamp = (now.date() + datetime.timedelta(days=1)).isoformat() tmp_dir.dvc_gen("testfile", "modified", commit="modified") diff --git a/tests/unit/command/test_dataset.py b/tests/unit/command/test_dataset.py index 15ac37b32..e32678c52 100644 --- a/tests/unit/command/test_dataset.py +++ b/tests/unit/command/test_dataset.py @@ -1,4 +1,4 @@ -from datetime import datetime +from datetime import datetime, timezone import pytest @@ -15,7 +15,7 @@ from dvc.cli import main ), ( {"name": "mydataset", "url": "dvcx://dataset", "type": "dvcx"}, - {"rev_lock": "0" * 40, "version": 1, "created_at": datetime.now()}, + {"version": 1, "created_at": datetime.now(tz=timezone.utc)}, "Adding mydataset (dvcx://dataset @ v1)\n", ), ( @@ -65,7 +65,7 @@ def test_add_already_exists(dvc, caplog, mocker): ), ( {"name": "mydataset", "url": "dvcx://dataset", "type": "dvcx"}, - {"rev_lock": "0" * 40, "version": 1, "created_at": datetime.now()}, + {"version": 1, "created_at": datetime.now(tz=timezone.utc)}, {"version": 2}, { "missing": "Updating mydataset (dvcx://dataset @ v2)\n", @@ -75,7 +75,7 @@ def test_add_already_exists(dvc, caplog, mocker): ), ( {"name": "mydataset", "url": "dvcx://dataset", "type": "dvcx"}, - {"rev_lock": "0" * 40, "version": 2, "created_at": datetime.now()}, + {"version": 2, "created_at": datetime.now(tz=timezone.utc)}, {"version": 1}, { "missing": "Updating mydataset (dvcx://dataset @ v1)\n", diff --git a/tests/unit/command/test_queue.py b/tests/unit/command/test_queue.py index c688bc146..19618eb3c 100644 --- a/tests/unit/command/test_queue.py +++ b/tests/unit/command/test_queue.py @@ -166,13 +166,13 @@ def test_experiments_status(dvc, scm, mocker, capsys): { "rev": "c61a525a4ff39007301b4516fb6e54b323a0587b", "name": "I40", - "timestamp": datetime(2022, 6, 9, 20, 49, 48), + "timestamp": datetime(2022, 6, 9, 20, 49, 48), # noqa: DTZ001 "status": "Queued", }, { "rev": "8da9c339da30636261a3491a90aafdb760a4168f", "name": "I60", - "timestamp": datetime(2022, 6, 9, 20, 49, 43), + "timestamp": datetime(2022, 6, 9, 20, 49, 43), # noqa: DTZ001 "status": "Running", }, ] diff --git a/tests/unit/repo/experiments/queue/test_celery.py b/tests/unit/repo/experiments/queue/test_celery.py index 4fd3bad7c..95cff373d 100644 --- a/tests/unit/repo/experiments/queue/test_celery.py +++ b/tests/unit/repo/experiments/queue/test_celery.py @@ -189,13 +189,13 @@ def test_queue_status(test_queue, scm, mocker): def resolve_commit(rev): if rev == "active": - commit_time = datetime(2022, 8, 7).timestamp() + commit_time = datetime(2022, 8, 7).timestamp() # noqa: DTZ001 elif rev == "queued": - commit_time = datetime(2022, 8, 6).timestamp() + commit_time = datetime(2022, 8, 6).timestamp() # noqa: DTZ001 elif rev == "failed": - commit_time = datetime(2022, 8, 5).timestamp() + commit_time = datetime(2022, 8, 5).timestamp() # noqa: DTZ001 elif rev == "success": - commit_time = datetime(2022, 8, 4).timestamp() + commit_time = datetime(2022, 8, 4).timestamp() # noqa: DTZ001 return mocker.Mock(commit_time=commit_time) mocker.patch.object( @@ -230,24 +230,24 @@ def test_queue_status(test_queue, scm, mocker): "name": "foo", "rev": "active", "status": "Running", - "timestamp": datetime(2022, 8, 7, 0, 0, 0), + "timestamp": datetime(2022, 8, 7, 0, 0, 0), # noqa: DTZ001 }, { "name": None, "rev": "queued", "status": "Queued", - "timestamp": datetime(2022, 8, 6, 0, 0, 0), + "timestamp": datetime(2022, 8, 6, 0, 0, 0), # noqa: DTZ001 }, { "name": "bar", "rev": "failed", "status": "Failed", - "timestamp": datetime(2022, 8, 5, 0, 0, 0), + "timestamp": datetime(2022, 8, 5, 0, 0, 0), # noqa: DTZ001 }, { "name": "foobar", "rev": "success", "status": "Success", - "timestamp": datetime(2022, 8, 4, 0, 0, 0), + "timestamp": datetime(2022, 8, 4, 0, 0, 0), # noqa: DTZ001 }, ] diff --git a/tests/unit/repo/experiments/test_collect.py b/tests/unit/repo/experiments/test_collect.py index f0406812c..052711fa2 100644 --- a/tests/unit/repo/experiments/test_collect.py +++ b/tests/unit/repo/experiments/test_collect.py @@ -22,7 +22,7 @@ def test_collect_stable_sorting(dvc, scm, mocker): ] def collect_queued_patched(_, baseline_revs) -> dict[str, list["ExpRange"]]: - single_timestamp = datetime.datetime(2023, 6, 20, 0, 0, 0) + single_timestamp = datetime.datetime(2023, 6, 20, 0, 0, 0) # noqa: DTZ001 exp_ranges = [ ExpRange( diff --git a/tests/unit/scm/test_scm.py b/tests/unit/scm/test_scm.py index c06f1fa88..bedc0aa0d 100644 --- a/tests/unit/scm/test_scm.py +++ b/tests/unit/scm/test_scm.py @@ -68,7 +68,7 @@ def test_iter_revs(tmp_dir, scm, mocker): if rev == rev_root: return GitCommit( "dummy", - commit_time=datetime(2022, 6, 28).timestamp(), + commit_time=datetime(2022, 6, 28).timestamp(), # noqa: DTZ001 commit_time_offset=0, message="dummy", parents=["dummy"], @@ -76,14 +76,14 @@ def test_iter_revs(tmp_dir, scm, mocker): committer_email="dummy", author_name="dummy", author_email="dummy", - author_time=datetime(2022, 6, 28).timestamp(), + author_time=datetime(2022, 6, 28).timestamp(), # noqa: DTZ001 author_time_offset=0, ) if rev == rev_old: raise SCMError return GitCommit( "dummy", - commit_time=datetime(2022, 6, 30).timestamp(), + commit_time=datetime(2022, 6, 30).timestamp(), # noqa: DTZ001 commit_time_offset=0, message="dummy", parents=["dummy"], @@ -91,7 +91,7 @@ def test_iter_revs(tmp_dir, scm, mocker): committer_email="dummy", author_name="dummy", author_email="dummy", - author_time=datetime(2022, 6, 28).timestamp(), + author_time=datetime(2022, 6, 28).timestamp(), # noqa: DTZ001 author_time_offset=0, ) diff --git a/tests/unit/test_logger.py b/tests/unit/test_logger.py index 1673c6fcf..a812a1c5d 100644 --- a/tests/unit/test_logger.py +++ b/tests/unit/test_logger.py @@ -23,7 +23,8 @@ colors = { @pytest.fixture def dt(mocker): mocker.patch( - "time.time", return_value=time.mktime(datetime(2020, 2, 2).timetuple()) + "time.time", + return_value=time.mktime(datetime(2020, 2, 2).timetuple()), # noqa: DTZ001 ) return "2020-02-02 00:00:00,000" diff --git a/tests/unit/ui/test_console.py b/tests/unit/ui/test_console.py index eebdf5859..f2a0ebc82 100644 --- a/tests/unit/ui/test_console.py +++ b/tests/unit/ui/test_console.py @@ -47,7 +47,7 @@ def test_write_json(capsys, mocker, isatty, expected_output): console = Console(enable=True) mocker.patch.object(console, "isatty", return_value=isatty) - message = {"hello": "world", "date": datetime.datetime(1970, 1, 1)} + message = {"hello": "world", "date": datetime.datetime(1970, 1, 1)} # noqa: DTZ001 console.write_json(message, default=str) captured = capsys.readouterr() assert captured.out == expected_output diff --git a/tests/unit/utils/test_fs.py b/tests/unit/utils/test_fs.py index 032d86836..507e52c7f 100644 --- a/tests/unit/utils/test_fs.py +++ b/tests/unit/utils/test_fs.py @@ -43,9 +43,7 @@ def test_should_return_false_when_base_path_is_symlink(mocker): target_path = os.path.join(base_path, "bar") def base_path_is_symlink(path): - if path == base_path: - return True - return False + return path == base_path mocker.patch.object( system,