[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](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 (सौगात) <[email protected]>
This commit is contained in:
pre-commit-ci[bot]
2024-03-26 06:37:53 +00:00
committed by GitHub
co-authored by Saugat Pachhai
parent 519c47f5fc
commit 3375a7c39f
23 changed files with 50 additions and 65 deletions
+1 -1
View File
@@ -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]
+1 -1
View File
@@ -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
+3 -3
View File
@@ -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):
+1 -5
View File
@@ -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:
+2 -2
View File
@@ -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)
+1 -1
View File
@@ -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,
+1 -1
View File
@@ -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"
+3 -7
View File
@@ -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,
+2 -4
View File
@@ -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):
+2 -6
View File
@@ -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,
+3 -1
View File
@@ -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:
+1 -3
View File
@@ -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:
+2 -2
View File
@@ -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
+3 -3
View File
@@ -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()
+1 -1
View File
@@ -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")
+4 -4
View File
@@ -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",
+2 -2
View File
@@ -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",
},
]
@@ -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
},
]
+1 -1
View File
@@ -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(
+4 -4
View File
@@ -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,
)
+2 -1
View File
@@ -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"
+1 -1
View File
@@ -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
+1 -3
View File
@@ -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,