Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#10372)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.3.3 → v0.3.4](astral-sh/ruff-pre-commit@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 (सौगात) <[email protected]>
  • Loading branch information
pre-commit-ci[bot] and skshetry authored Mar 26, 2024
1 parent 519c47f commit 3375a7c
Show file tree
Hide file tree
Showing 23 changed files with 50 additions and 65 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion dvc/_debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 3 additions & 3 deletions dvc/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 1 addition & 5 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,11 +551,7 @@ def eq(one, two):

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:
Expand Down
4 changes: 2 additions & 2 deletions dvc/repo/experiments/collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -338,6 +338,6 @@ def _head_timestamp(exp_range: "ExpRange") -> tuple[datetime, str]:
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)
2 changes: 1 addition & 1 deletion dvc/repo/experiments/queue/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ def status(self) -> list[dict[str, Any]]:

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,
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/experiments/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 3 additions & 7 deletions dvc/repo/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def _onerror(entry, exc):
return _onerror


def _collect_indexes( # noqa: PLR0913, C901
def _collect_indexes( # noqa: PLR0913
repo,
targets=None,
remote=None,
Expand All @@ -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,
Expand Down
6 changes: 2 additions & 4 deletions dvc/repo/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 2 additions & 6 deletions dvc/repo/worktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion dvc/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions dvc/stage/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions tests/func/experiments/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/command/test_dataset.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone

import pytest

Expand All @@ -15,7 +15,7 @@
),
(
{"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",
),
(
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/command/test_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
]
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/repo/experiments/queue/test_celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -230,24 +230,24 @@ def resolve_commit(rev):
"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
},
]
2 changes: 1 addition & 1 deletion tests/unit/repo/experiments/test_collect.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
8 changes: 4 additions & 4 deletions tests/unit/scm/test_scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,30 +68,30 @@ def _resolve_commit(rev):
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"],
committer_name="dummy",
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"],
committer_name="dummy",
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,
)

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
@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"

Expand Down
2 changes: 1 addition & 1 deletion tests/unit/ui/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions tests/unit/utils/test_fs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3375a7c

Please sign in to comment.