Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.12.12'
rev: 'v0.13.0'
hooks:
- id: ruff-check
args: [--fix, --exit-non-zero-on-fix]
Expand Down
1 change: 1 addition & 0 deletions dvc/api/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,4 @@ def get(name: str) -> Union[DatachainDataset, DVCDataset, URLDataset]:
for file in dataset.lock.files
]
return URLDataset(type="url", files=files, path=versioned_path)
raise AssertionError("unreachable")
2 changes: 1 addition & 1 deletion dvc/commands/check_ignore.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def __init__(self, args):

def _show_results(self, result: "CheckIgnoreResult"):
if not result.match and not self.args.details:
return
return None

if self.args.details:
pattern_infos = result.pattern_infos
Expand Down
3 changes: 2 additions & 1 deletion dvc/commands/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def display(self, name: str, dataset: "Dataset", new: "Dataset"):
return CmdDatasetAdd.display(name, new, action)
if dataset == new:
ui.write("[yellow]Nothing to update[/]", styled=True)
return
return None

assert new.lock

Expand Down Expand Up @@ -112,6 +112,7 @@ def display(self, name: str, dataset: "Dataset", new: "Dataset"):
assert new.type == "url"
stats = diff_files(dataset.lock.files, new.lock.files)
log_changes(stats)
return None

def run(self):
from difflib import get_close_matches
Expand Down
1 change: 1 addition & 0 deletions dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ def get_dir(cls, level):
return global_config_dir()
if level == "system":
return system_config_dir()
return None

@cached_property
def files(self) -> dict[str, str]:
Expand Down
2 changes: 1 addition & 1 deletion dvc/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def test_connection(self, onerror: Optional[Callable[[], Any]] = None) -> None:
except Exception as exc:
if callable(onerror):
onerror()
logger.exception(
logger.exception( # noqa: LOG007
"Could not connect to the database. "
"Check your database credentials and try again.",
exc_info=False,
Expand Down
2 changes: 1 addition & 1 deletion dvc/dvcfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def dump(self, stage, **kwargs) -> None:

def dump_stages(self, stages, **kwargs) -> None:
if not stages:
return
return None

assert len(stages) == 1, "SingleStageFile can only dump one stage."
return self.dump(stages[0], **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion dvc/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from dvc.stage import Stage


class DvcException(Exception):
class DvcException(Exception): # noqa: N818
"""Base class for all dvc exceptions."""

def __init__(self, msg, *args):
Expand Down
2 changes: 1 addition & 1 deletion dvc/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def log_to_root(message, *args, **kwargs):
setattr(logging, method_name, log_to_root)


class LoggingException(Exception):
class LoggingException(Exception): # noqa: N818
def __init__(self, record):
msg = f"failed to log {record!s}"
super().__init__(msg)
Expand Down
5 changes: 3 additions & 2 deletions dvc/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -1473,12 +1473,13 @@ def merge_version_meta(
):
"""Merge version meta for files which are unchanged from other."""
if not self.hash_info:
return
return None
if self.hash_info.isdir:
return self._merge_dir_version_meta(old_hi, old_obj)
if self.hash_info != old_hi:
return
return None
self.meta = old_meta
return None

def _merge_dir_version_meta(
self, old_hi: "HashInfo", old_obj: Optional[Union["HashFile", "Tree"]]
Expand Down
6 changes: 3 additions & 3 deletions dvc/parsing/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ParamsLoadError(ContextError):
pass


class KeyNotInContext(ContextError, KeyError):
class KeyNotInContext(ContextError, KeyError): # noqa: N818
def __init__(self, key: str) -> None:
self.key: str = key
super().__init__(f"Could not find '{key}'")
Expand All @@ -75,7 +75,7 @@ def __str__(self):
return self.msg


class VarsAlreadyLoaded(ContextError):
class VarsAlreadyLoaded(ContextError): # noqa: N818
pass


Expand Down Expand Up @@ -272,7 +272,7 @@ def __setitem__(self, key, value):
if not isinstance(key, str):
# limitation for the interpolation
# ignore other kinds of keys
return
return None
return super().__setitem__(key, value)

def merge_update(self, other, overwrite=False):
Expand Down
1 change: 1 addition & 0 deletions dvc/parsing/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ def validate_value(value, key):
if isinstance(value, dict) and key == "cmd":
return True
raise ParseError(f"Cannot interpolate data of type '{type(value).__name__}'")
return None


def str_interpolate(
Expand Down
2 changes: 1 addition & 1 deletion dvc/render/converter/vega.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ def infer_y_label(properties):
if isinstance(y, list):
return "y"
if not isinstance(y, dict):
return
return None

fields = {field for _, field in _file_field(y)}
if len(fields) == 1:
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/experiments/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def __init__(self, rev, ref_infos):
self.ref_infos = ref_infos


class AmbiguousExpRefInfo(InvalidArgumentError):
class AmbiguousExpRefInfo(InvalidArgumentError): # noqa: N818
def __init__(self, exp_name: str, exp_ref_list: Iterable["ExpRefInfo"]):
msg = [
(
Expand Down
1 change: 1 addition & 0 deletions dvc/repo/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def _make_index_onerror(onerror, rev):
def _onerror(entry, exc):
if onerror:
return onerror(rev, entry, exc)
return None

return _onerror

Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def install(self: "Repo", use_pre_commit_tool: bool = False) -> None:

scm = self.scm
if not isinstance(scm, Git):
return
return None

driver = "dvc git-hook merge-driver --ancestor %O --our %A --their %B "
scm.install_merge_driver("dvc", "DVC merge driver", driver)
Expand Down
4 changes: 3 additions & 1 deletion dvc/repo/scm_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def add(self, paths: Union[str, Iterable[str]]) -> None:
def track_changed_files(self) -> None:
"""Stage files that have changed."""
if not self.files_to_track:
return
return None
logger.debug("Staging files: %s", self.files_to_track)
return self.add(self.files_to_track)

Expand All @@ -76,6 +76,7 @@ def ignore(self, path: str) -> None:
logger.debug("Added '%s' to gitignore file.", path)
self.track_file(relpath(gitignore_file))
return self.ignored_paths.append(path)
return None

def ignore_remove(self, path: str) -> None:
from scmrepo.exceptions import FileNotInRepoError
Expand All @@ -90,6 +91,7 @@ def ignore_remove(self, path: str) -> None:

if gitignore_file:
return self.track_file(relpath(gitignore_file))
return None

@contextmanager
def __call__(
Expand Down
2 changes: 1 addition & 1 deletion dvc/scm.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def __init__(self):
super().__init__(msg)


class InvalidRemoteSCMRepo(SCMError):
class InvalidRemoteSCMRepo(SCMError): # noqa: N818
pass


Expand Down
2 changes: 1 addition & 1 deletion dvc/stage/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ def restore_fields(stage: "Stage") -> None:

old_outs = {out.def_path: out for out in old.outs}
for out in stage.outs:
old_out = old_outs.get(out.def_path, None)
old_out = old_outs.get(out.def_path)
if old_out is not None:
out.restore_fields(old_out)

Expand Down
2 changes: 1 addition & 1 deletion dvc/stage/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def __init__(self, path: str):
super().__init__(f"data source changed: {path}")


class StageNotFound(DvcException, KeyError):
class StageNotFound(DvcException, KeyError): # noqa: N818
def __init__(self, file, name):
self.file = file.relpath
self.name = name
Expand Down
6 changes: 3 additions & 3 deletions dvc/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ def write(
sep = " " if sep is None else sep
end = "\n" if end is None else end
if not self._enabled and not force:
return
return None

file = file or (sys.stderr if stderr else sys.stdout)
with Tqdm.external_write_mode(file=file):
Expand Down Expand Up @@ -305,7 +305,7 @@ def table(
from dvc.ui import table as t

if not data and not markdown:
return
return None

if not markdown and rich_table:
if force or self._enabled:
Expand All @@ -319,7 +319,7 @@ def table(
borders=borders,
)

return
return None

return t.plain_table(
self,
Expand Down
2 changes: 1 addition & 1 deletion dvc/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def _notify(self, latest: str, pkg: Optional[str] = PKG) -> None:
from dvc.ui import ui

if not ui.isatty():
return
return None

message = self._get_message(latest, pkg=pkg)
return ui.error_write(message, styled=True)
Expand Down
14 changes: 11 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,16 @@ show-fixes = true

[tool.ruff.lint]
ignore = [
"N818", "S101", "A005", "PT007", "RET502", "RET503", "SIM105", "SIM108", "SIM117",
"TRY003", "TRY300", "PERF203", "PLC0415", "PLR2004", "PLW2901", "LOG007",
"PERF203", # try-except-in-loop
"PLC0415", # import-outside-top-level
"PLR2004", # magic-value-comparison
"PLW2901", # redefined-loop-name
"S101", # assert
"SIM105", # suppressible-exception
"SIM108", # if-else-block-instead-of-if-exp
"SIM117", # multiple-with-statements
"TRY003", # raise-vanilla-args
"TRY300", # try-consider-else
]
select = [
"F", "E", "W", "C90", "I", "N", "UP", "YTT", "ASYNC", "S", "BLE", "B", "A", "C4", "DTZ", "T10",
Expand Down Expand Up @@ -304,4 +312,4 @@ max-args = 10
"dvc/commands/**" = ["N806"]
"dvc/testing/**" = ["ARG002"]
"dvc/testing/benchmarks/**" = ["ARG001"]
"tests/**" = ["S", "ARG001", "ARG002", "TRY002", "TRY301", "PERF"]
"tests/**" = ["S", "ARG001", "ARG002", "TRY002", "TRY301", "PERF", "PLR2004"]
4 changes: 3 additions & 1 deletion tests/func/api/test_experiments.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

import pytest

from dvc import api
Expand All @@ -13,7 +15,7 @@ def test_exp_save(tmp_dir, dvc, scm):
api.exp_save("foo")
with pytest.raises(
ExperimentExistsError,
match="Experiment conflicts with existing experiment 'foo'.",
match=re.escape("Experiment conflicts with existing experiment 'foo'."),
):
api.exp_save("foo")
api.exp_save("foo", force=True)
Expand Down
24 changes: 12 additions & 12 deletions tests/func/experiments/test_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ def test_remove_multi_rev(tmp_dir, scm, dvc, exp_stage):
@pytest.mark.parametrize(
"keep, expected_removed",
[
[["exp1"], ["exp2", "exp3"]],
[["exp1", "exp2"], ["exp3"]],
[["exp1", "exp2", "exp3"], []],
[[], []], # remove does nothing if no experiments are specified
(["exp1"], ["exp2", "exp3"]),
(["exp1", "exp2"], ["exp3"]),
(["exp1", "exp2", "exp3"], []),
([], []), # remove does nothing if no experiments are specified
],
)
def test_keep_selected_by_name(tmp_dir, scm, dvc, exp_stage, keep, expected_removed):
Expand Down Expand Up @@ -239,14 +239,14 @@ def test_keep_selected_by_nonexistent_name(tmp_dir, scm, dvc, exp_stage):
@pytest.mark.parametrize(
"num_exps, rev, num, expected_removed",
[
[2, "exp1", 1, ["exp2"]],
[3, "exp3", 1, ["exp1", "exp2"]],
[3, "exp3", 2, ["exp1"]],
[3, "exp3", 3, []],
[3, "exp2", 2, ["exp3"]],
[4, "exp2", 2, ["exp3", "exp4"]],
[4, "exp4", 2, ["exp1", "exp2"]],
[1, None, 1, []], # remove does nothing if no experiments are specified
(2, "exp1", 1, ["exp2"]),
(3, "exp3", 1, ["exp1", "exp2"]),
(3, "exp3", 2, ["exp1"]),
(3, "exp3", 3, []),
(3, "exp2", 2, ["exp3"]),
(4, "exp2", 2, ["exp3", "exp4"]),
(4, "exp4", 2, ["exp1", "exp2"]),
(1, None, 1, []), # remove does nothing if no experiments are specified
],
)
def test_keep_selected_by_rev(
Expand Down
6 changes: 3 additions & 3 deletions tests/func/experiments/test_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def test_exp_save_unchanged(tmp_dir, dvc, scm):
dvc.experiments.save()


@pytest.mark.parametrize("name", (None, "test"))
@pytest.mark.parametrize("name", [None, "test"])
def test_exp_save(tmp_dir, dvc, scm, name):
setup_stage(tmp_dir, dvc, scm)
baseline = scm.get_rev()
Expand Down Expand Up @@ -47,13 +47,13 @@ def test_exp_save_overwrite_experiment(tmp_dir, dvc, scm):

@pytest.mark.parametrize(
"name",
(
[
"invalid/name",
"invalid..name",
"invalid~name",
"invalid?name",
"invalidname.",
),
],
)
def test_exp_save_invalid_name(tmp_dir, dvc, scm, name):
setup_stage(tmp_dir, dvc, scm)
Expand Down
4 changes: 2 additions & 2 deletions tests/func/experiments/test_set_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
@pytest.mark.parametrize(
"changes, expected",
[
[["foo=baz"], "foo: baz\ngoo:\n bag: 3.0\nlorem: false"],
[["params.yaml:foo=baz"], "foo: baz\ngoo:\n bag: 3.0\nlorem: false"],
(["foo=baz"], "foo: baz\ngoo:\n bag: 3.0\nlorem: false"),
(["params.yaml:foo=baz"], "foo: baz\ngoo:\n bag: 3.0\nlorem: false"),
],
)
def test_modify_params(params_repo, dvc, changes, expected):
Expand Down
4 changes: 2 additions & 2 deletions tests/func/metrics/test_show.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,14 @@ def test_metrics_show_overlap(tmp_dir, dvc, run_copy_metrics, clear_before_run):

@pytest.mark.parametrize(
"file,error_path,err_type",
(
[
(PROJECT_FILE, ["workspace", "error", "type"], "YAMLSyntaxError"),
(
"metrics.yaml",
["workspace", "data", "metrics.yaml", "error", "type"],
"YAMLFileCorruptedError",
),
),
],
)
def test_log_errors(
tmp_dir, scm, dvc, capsys, run_copy_metrics, file, error_path, err_type
Expand Down
Loading
Loading