Skip to content

Commit 3375a7c

Browse files
[pre-commit.ci] pre-commit autoupdate (#10372)
* [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]>
1 parent 519c47f commit 3375a7c

23 files changed

+50
-65
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ repos:
2222
- id: sort-simple-yaml
2323
- id: trailing-whitespace
2424
- repo: https://github.com/astral-sh/ruff-pre-commit
25-
rev: 'v0.3.3'
25+
rev: 'v0.3.4'
2626
hooks:
2727
- id: ruff
2828
args: [--fix, --exit-non-zero-on-fix]

dvc/_debug.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _get_path_func(tool: str, ext: str):
162162
fmt = f"{tool}.dvc-{{now:%Y%m%d}}_{{now:%H%M%S}}.{ext}"
163163

164164
def func(now: Optional["datetime"] = None) -> str:
165-
return fmt.format(now=now or datetime.now())
165+
return fmt.format(now=now or datetime.now()) # noqa: DTZ005
166166

167167
return func
168168

dvc/exceptions.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,11 @@ class MoveNotDataSourceError(DvcException):
133133
def __init__(self, path):
134134
msg = (
135135
"move is not permitted for stages that are not data sources. "
136-
"You need to either move '{path}' to a new location and edit "
137-
"it by hand, or remove '{path}' and create a new one at the "
136+
f"You need to either move {path!r} to a new location and edit "
137+
f"it by hand, or remove {path!r} and create a new one at the "
138138
"desired location."
139139
)
140-
super().__init__(msg.format(path=path))
140+
super().__init__(msg)
141141

142142

143143
class NotDvcRepoError(DvcException):

dvc/repo/__init__.py

+1-5
Original file line numberDiff line numberDiff line change
@@ -551,11 +551,7 @@ def eq(one, two):
551551

552552
if out.protocol == "local" and match(fs_path, out.fs_path):
553553
return True
554-
555-
if recursive and out.fs.isin(out.fs_path, fs_path):
556-
return True
557-
558-
return False
554+
return recursive and out.fs.isin(out.fs_path, fs_path)
559555

560556
matched = list(filter(func, outs))
561557
if not matched:

dvc/repo/experiments/collect.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ def _collect_rev(
7878
timestamp: Optional[datetime] = None
7979
else:
8080
commit = repo.scm.resolve_commit(rev)
81-
timestamp = datetime.fromtimestamp(commit.commit_time)
81+
timestamp = datetime.fromtimestamp(commit.commit_time) # noqa: DTZ006
8282

8383
return SerializableExp.from_repo(
8484
repo,
@@ -338,6 +338,6 @@ def _head_timestamp(exp_range: "ExpRange") -> tuple[datetime, str]:
338338
if head_exp and head_exp.data and head_exp.data.timestamp:
339339
return head_exp.data.timestamp, head_exp.rev
340340

341-
return datetime.fromtimestamp(0), ""
341+
return datetime.fromtimestamp(0), "" # noqa: DTZ006
342342

343343
return sorted(exp_ranges, key=_head_timestamp, reverse=True)

dvc/repo/experiments/queue/base.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ def status(self) -> list[dict[str, Any]]:
180180

181181
def _get_timestamp(rev: str) -> datetime:
182182
commit = self.scm.resolve_commit(rev)
183-
return datetime.fromtimestamp(commit.commit_time)
183+
return datetime.fromtimestamp(commit.commit_time) # noqa: DTZ006
184184

185185
def _format_entry(
186186
entry: QueueEntry,

dvc/repo/experiments/show.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ def format_time(
306306
return fill_value
307307
if iso:
308308
return timestamp.isoformat()
309-
if timestamp.date() == date.today():
309+
if timestamp.date() == date.today(): # noqa: DTZ011
310310
fmt = "%I:%M %p"
311311
else:
312312
fmt = "%b %d, %Y"

dvc/repo/fetch.py

+3-7
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def _onerror(entry, exc):
2222
return _onerror
2323

2424

25-
def _collect_indexes( # noqa: PLR0913, C901
25+
def _collect_indexes( # noqa: PLR0913
2626
repo,
2727
targets=None,
2828
remote=None,
@@ -49,16 +49,12 @@ def _collect_indexes( # noqa: PLR0913, C901
4949
config["core"] = core
5050

5151
def stage_filter(stage: "Stage") -> bool:
52-
if push and stage.is_repo_import:
53-
return False
54-
return True
52+
return not (push and stage.is_repo_import)
5553

5654
def outs_filter(out: "Output") -> bool:
5755
if push and not out.can_push:
5856
return False
59-
if remote and out.remote and remote != out.remote:
60-
return False
61-
return True
57+
return not (remote and out.remote and remote != out.remote)
6258

6359
for rev in repo.brancher(
6460
revs=revs,

dvc/repo/plots/__init__.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -369,11 +369,9 @@ def _matches(targets, config_file, plot_id):
369369
return True
370370

371371
full_id = get_plot_id(plot_id, config_file)
372-
if any(
372+
return any(
373373
(re.match(target, plot_id) or re.match(target, full_id)) for target in targets
374-
):
375-
return True
376-
return False
374+
)
377375

378376

379377
def _normpath(path):

dvc/repo/worktree.py

+2-6
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,10 @@ def worktree_view(
7676
"""
7777

7878
def stage_filter(stage: "Stage") -> bool:
79-
if push and stage.is_repo_import:
80-
return False
81-
return True
79+
return not (push and stage.is_repo_import)
8280

8381
def outs_filter(out: "Output") -> bool:
84-
if not out.is_in_repo or not out.use_cache or (push and not out.can_push):
85-
return False
86-
return True
82+
return out.is_in_repo and out.use_cache and (not push or out.can_push)
8783

8884
return index.targets_view(
8985
targets,

dvc/scm.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,9 @@ def iter_revs(
239239
if commit_date:
240240
from datetime import datetime
241241

242-
commit_datestamp = datetime.strptime(commit_date, "%Y-%m-%d").timestamp()
242+
commit_datestamp = (
243+
datetime.strptime(commit_date, "%Y-%m-%d").timestamp() # noqa: DTZ007
244+
)
243245

244246
def _time_filter(rev):
245247
try:

dvc/stage/utils.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ def check_no_externals(stage):
9292
from dvc.utils import format_link
9393

9494
def _is_cached_external(out):
95-
if out.is_in_repo or not out.use_cache:
96-
return False
97-
return True
95+
return not out.is_in_repo and out.use_cache
9896

9997
outs = [str(out) for out in stage.outs if _is_cached_external(out)]
10098
if not outs:

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ ignore = [
267267
"TRY003", "TRY300", "PLR2004", "PLW2901", "LOG007",
268268
]
269269
select = [
270-
"F", "E", "W", "C90", "I", "N", "UP", "YTT", "ASYNC", "S", "BLE", "B", "A", "C4", "T10",
270+
"F", "E", "W", "C90", "I", "N", "UP", "YTT", "ASYNC", "S", "BLE", "B", "A", "C4", "DTZ", "T10",
271271
"EXE", "ISC", "ICN", "G", "INP", "PIE", "T20", "PYI", "PT", "Q", "RSE", "RET",
272272
"SLOT", "SIM", "TID", "TCH", "ARG", "PGH", "PLC", "PLE", "PLR", "PLW", "TRY",
273-
"FLY", "PERF101", "LOG", "RUF", "RUF022", "RUF023", "RUF024", "RUF025", "RUF026",
273+
"FLY", "PERF101", "LOG", "RUF", "RUF022", "RUF023", "RUF024", "RUF025", "RUF026", "RUF027"
274274
]
275275
preview = true
276276
explicit-preview-rules = true

tests/func/experiments/test_show.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def test_show_simple(tmp_dir, scm, dvc, exp_stage):
101101
@pytest.mark.parametrize("workspace", [True, False])
102102
def test_show_experiment(tmp_dir, scm, dvc, exp_stage, workspace):
103103
baseline_rev = scm.get_rev()
104-
timestamp = datetime.fromtimestamp(
104+
timestamp = datetime.fromtimestamp( # noqa: DTZ006
105105
scm.gitpython.repo.rev_parse(baseline_rev).committed_date
106106
)
107107

@@ -423,7 +423,7 @@ def test_show_csv(tmp_dir, scm, dvc, exp_stage, capsys):
423423
baseline_rev = scm.get_rev()
424424

425425
def _get_rev_isotimestamp(rev):
426-
return datetime.fromtimestamp(
426+
return datetime.fromtimestamp( # noqa: DTZ006
427427
scm.gitpython.repo.rev_parse(rev).committed_date
428428
).isoformat()
429429

@@ -652,7 +652,7 @@ def test_metrics_renaming(tmp_dir, dvc, scm, capsys, copy_script):
652652
cap = capsys.readouterr()
653653

654654
def _get_rev_isotimestamp(rev):
655-
return datetime.fromtimestamp(
655+
return datetime.fromtimestamp( # noqa: DTZ006
656656
scm.gitpython.repo.rev_parse(rev).committed_date
657657
).isoformat()
658658

tests/func/test_gc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ def test_gc_rev_num(tmp_dir, scm, dvc):
297297
def test_date(tmp_dir, scm, dvc):
298298
tmp_dir.dvc_gen("testfile", "content", commit="add testfile")
299299

300-
now = datetime.datetime.now()
300+
now = datetime.datetime.now(tz=datetime.timezone.utc)
301301
datestamp = (now.date() + datetime.timedelta(days=1)).isoformat()
302302

303303
tmp_dir.dvc_gen("testfile", "modified", commit="modified")

tests/unit/command/test_dataset.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from datetime import datetime
1+
from datetime import datetime, timezone
22

33
import pytest
44

@@ -15,7 +15,7 @@
1515
),
1616
(
1717
{"name": "mydataset", "url": "dvcx://dataset", "type": "dvcx"},
18-
{"rev_lock": "0" * 40, "version": 1, "created_at": datetime.now()},
18+
{"version": 1, "created_at": datetime.now(tz=timezone.utc)},
1919
"Adding mydataset (dvcx://dataset @ v1)\n",
2020
),
2121
(
@@ -65,7 +65,7 @@ def test_add_already_exists(dvc, caplog, mocker):
6565
),
6666
(
6767
{"name": "mydataset", "url": "dvcx://dataset", "type": "dvcx"},
68-
{"rev_lock": "0" * 40, "version": 1, "created_at": datetime.now()},
68+
{"version": 1, "created_at": datetime.now(tz=timezone.utc)},
6969
{"version": 2},
7070
{
7171
"missing": "Updating mydataset (dvcx://dataset @ v2)\n",
@@ -75,7 +75,7 @@ def test_add_already_exists(dvc, caplog, mocker):
7575
),
7676
(
7777
{"name": "mydataset", "url": "dvcx://dataset", "type": "dvcx"},
78-
{"rev_lock": "0" * 40, "version": 2, "created_at": datetime.now()},
78+
{"version": 2, "created_at": datetime.now(tz=timezone.utc)},
7979
{"version": 1},
8080
{
8181
"missing": "Updating mydataset (dvcx://dataset @ v1)\n",

tests/unit/command/test_queue.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ def test_experiments_status(dvc, scm, mocker, capsys):
166166
{
167167
"rev": "c61a525a4ff39007301b4516fb6e54b323a0587b",
168168
"name": "I40",
169-
"timestamp": datetime(2022, 6, 9, 20, 49, 48),
169+
"timestamp": datetime(2022, 6, 9, 20, 49, 48), # noqa: DTZ001
170170
"status": "Queued",
171171
},
172172
{
173173
"rev": "8da9c339da30636261a3491a90aafdb760a4168f",
174174
"name": "I60",
175-
"timestamp": datetime(2022, 6, 9, 20, 49, 43),
175+
"timestamp": datetime(2022, 6, 9, 20, 49, 43), # noqa: DTZ001
176176
"status": "Running",
177177
},
178178
]

tests/unit/repo/experiments/queue/test_celery.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -189,13 +189,13 @@ def test_queue_status(test_queue, scm, mocker):
189189

190190
def resolve_commit(rev):
191191
if rev == "active":
192-
commit_time = datetime(2022, 8, 7).timestamp()
192+
commit_time = datetime(2022, 8, 7).timestamp() # noqa: DTZ001
193193
elif rev == "queued":
194-
commit_time = datetime(2022, 8, 6).timestamp()
194+
commit_time = datetime(2022, 8, 6).timestamp() # noqa: DTZ001
195195
elif rev == "failed":
196-
commit_time = datetime(2022, 8, 5).timestamp()
196+
commit_time = datetime(2022, 8, 5).timestamp() # noqa: DTZ001
197197
elif rev == "success":
198-
commit_time = datetime(2022, 8, 4).timestamp()
198+
commit_time = datetime(2022, 8, 4).timestamp() # noqa: DTZ001
199199
return mocker.Mock(commit_time=commit_time)
200200

201201
mocker.patch.object(
@@ -230,24 +230,24 @@ def resolve_commit(rev):
230230
"name": "foo",
231231
"rev": "active",
232232
"status": "Running",
233-
"timestamp": datetime(2022, 8, 7, 0, 0, 0),
233+
"timestamp": datetime(2022, 8, 7, 0, 0, 0), # noqa: DTZ001
234234
},
235235
{
236236
"name": None,
237237
"rev": "queued",
238238
"status": "Queued",
239-
"timestamp": datetime(2022, 8, 6, 0, 0, 0),
239+
"timestamp": datetime(2022, 8, 6, 0, 0, 0), # noqa: DTZ001
240240
},
241241
{
242242
"name": "bar",
243243
"rev": "failed",
244244
"status": "Failed",
245-
"timestamp": datetime(2022, 8, 5, 0, 0, 0),
245+
"timestamp": datetime(2022, 8, 5, 0, 0, 0), # noqa: DTZ001
246246
},
247247
{
248248
"name": "foobar",
249249
"rev": "success",
250250
"status": "Success",
251-
"timestamp": datetime(2022, 8, 4, 0, 0, 0),
251+
"timestamp": datetime(2022, 8, 4, 0, 0, 0), # noqa: DTZ001
252252
},
253253
]

tests/unit/repo/experiments/test_collect.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_collect_stable_sorting(dvc, scm, mocker):
2222
]
2323

2424
def collect_queued_patched(_, baseline_revs) -> dict[str, list["ExpRange"]]:
25-
single_timestamp = datetime.datetime(2023, 6, 20, 0, 0, 0)
25+
single_timestamp = datetime.datetime(2023, 6, 20, 0, 0, 0) # noqa: DTZ001
2626

2727
exp_ranges = [
2828
ExpRange(

tests/unit/scm/test_scm.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,30 @@ def _resolve_commit(rev):
6868
if rev == rev_root:
6969
return GitCommit(
7070
"dummy",
71-
commit_time=datetime(2022, 6, 28).timestamp(),
71+
commit_time=datetime(2022, 6, 28).timestamp(), # noqa: DTZ001
7272
commit_time_offset=0,
7373
message="dummy",
7474
parents=["dummy"],
7575
committer_name="dummy",
7676
committer_email="dummy",
7777
author_name="dummy",
7878
author_email="dummy",
79-
author_time=datetime(2022, 6, 28).timestamp(),
79+
author_time=datetime(2022, 6, 28).timestamp(), # noqa: DTZ001
8080
author_time_offset=0,
8181
)
8282
if rev == rev_old:
8383
raise SCMError
8484
return GitCommit(
8585
"dummy",
86-
commit_time=datetime(2022, 6, 30).timestamp(),
86+
commit_time=datetime(2022, 6, 30).timestamp(), # noqa: DTZ001
8787
commit_time_offset=0,
8888
message="dummy",
8989
parents=["dummy"],
9090
committer_name="dummy",
9191
committer_email="dummy",
9292
author_name="dummy",
9393
author_email="dummy",
94-
author_time=datetime(2022, 6, 28).timestamp(),
94+
author_time=datetime(2022, 6, 28).timestamp(), # noqa: DTZ001
9595
author_time_offset=0,
9696
)
9797

tests/unit/test_logger.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
@pytest.fixture
2424
def dt(mocker):
2525
mocker.patch(
26-
"time.time", return_value=time.mktime(datetime(2020, 2, 2).timetuple())
26+
"time.time",
27+
return_value=time.mktime(datetime(2020, 2, 2).timetuple()), # noqa: DTZ001
2728
)
2829
return "2020-02-02 00:00:00,000"
2930

tests/unit/ui/test_console.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def test_write_json(capsys, mocker, isatty, expected_output):
4747

4848
console = Console(enable=True)
4949
mocker.patch.object(console, "isatty", return_value=isatty)
50-
message = {"hello": "world", "date": datetime.datetime(1970, 1, 1)}
50+
message = {"hello": "world", "date": datetime.datetime(1970, 1, 1)} # noqa: DTZ001
5151
console.write_json(message, default=str)
5252
captured = capsys.readouterr()
5353
assert captured.out == expected_output

tests/unit/utils/test_fs.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@ def test_should_return_false_when_base_path_is_symlink(mocker):
4343
target_path = os.path.join(base_path, "bar")
4444

4545
def base_path_is_symlink(path):
46-
if path == base_path:
47-
return True
48-
return False
46+
return path == base_path
4947

5048
mocker.patch.object(
5149
system,

0 commit comments

Comments
 (0)