diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index f474e8ea7..e88729ebe 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -23,7 +23,7 @@ repos: - id: sort-simple-yaml - id: trailing-whitespace - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.9.9' + rev: 'v0.11.4' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] diff --git a/dvc/api/show.py b/dvc/api/show.py index 7b91123d1..563789920 100644 --- a/dvc/api/show.py +++ b/dvc/api/show.py @@ -27,8 +27,7 @@ def _postprocess(results): } processed[rev] = processed[rev] | to_merge - if "workspace" in processed: - del processed["workspace"] + processed.pop("workspace", None) return processed diff --git a/dvc/dagascii.py b/dvc/dagascii.py index 2b5a96f92..f8623ffe5 100644 --- a/dvc/dagascii.py +++ b/dvc/dagascii.py @@ -104,21 +104,21 @@ class AsciiCanvas: if dx == 0: y = y0 else: - y = y0 + int(round((x - x0) * dy / float(dx))) + y = y0 + round((x - x0) * dy / float(dx)) self.point(x, y, char) elif y0 < y1: for y in range(y0, y1 + 1): if dy == 0: x = x0 else: - x = x0 + int(round((y - y0) * dx / float(dy))) + x = x0 + round((y - y0) * dx / float(dy)) self.point(x, y, char) else: for y in range(y1, y0 + 1): if dy == 0: x = x0 else: - x = x1 + int(round((y - y1) * dx / float(dy))) + x = x1 + round((y - y1) * dx / float(dy)) self.point(x, y, char) def text(self, x, y, text): @@ -258,8 +258,8 @@ def draw(vertices, edges): maxx = max(Xs) maxy = max(Ys) - canvas_cols = int(math.ceil(math.ceil(maxx) - math.floor(minx))) + 1 - canvas_lines = int(round(maxy - miny)) + canvas_cols = math.ceil(math.ceil(maxx) - math.floor(minx)) + 1 + canvas_lines = round(maxy - miny) canvas = AsciiCanvas(canvas_cols, canvas_lines) @@ -270,10 +270,10 @@ def draw(vertices, edges): start = edge.view._pts[index - 1] end = edge.view._pts[index] - start_x = int(round(start[0] - minx)) - start_y = int(round(start[1] - miny)) - end_x = int(round(end[0] - minx)) - end_y = int(round(end[1] - miny)) + start_x = round(start[0] - minx) + start_y = round(start[1] - miny) + end_x = round(end[0] - minx) + end_y = round(end[1] - miny) assert start_x >= 0 assert start_y >= 0 @@ -288,12 +288,12 @@ def draw(vertices, edges): y = vertex.view.xy[1] canvas.box( - int(round(x - minx)), - int(round(y - miny)), + round(x - minx), + round(y - miny), vertex.view.w, vertex.view.h, ) - canvas.text(int(round(x - minx)) + 1, int(round(y - miny)) + 1, vertex.data) + canvas.text(round(x - minx) + 1, round(y - miny) + 1, vertex.data) return canvas.draw() diff --git a/dvc/logger.py b/dvc/logger.py index 274555d11..9175c7ec6 100644 --- a/dvc/logger.py +++ b/dvc/logger.py @@ -36,7 +36,7 @@ def add_logging_level(level_name, level_num, method_name=None): self._log(level_num, message, args, **kwargs) def log_to_root(message, *args, **kwargs): - logging.log(level_num, message, *args, **kwargs) + logging.log(level_num, message, *args, **kwargs) # noqa: LOG015 # getLevelName resolves the numeric log level if already defined, # otherwise returns a string diff --git a/dvc/parsing/context.py b/dvc/parsing/context.py index af8d1b3fd..c13bb74cf 100644 --- a/dvc/parsing/context.py +++ b/dvc/parsing/context.py @@ -105,7 +105,7 @@ class Meta: @staticmethod def update_path(meta: "Meta", path: Union[str, int]): - dpaths = meta.dpaths[:] + [str(path)] + dpaths = [*meta.dpaths, str(path)] return replace(meta, dpaths=dpaths) def __str__(self): diff --git a/dvc/repo/experiments/queue/base.py b/dvc/repo/experiments/queue/base.py index 527673cd1..79a7d8e70 100644 --- a/dvc/repo/experiments/queue/base.py +++ b/dvc/repo/experiments/queue/base.py @@ -372,7 +372,7 @@ class BaseStashQueue(ABC): ) def _stash_commit_deps(self, *args, **kwargs): - if len(args): + if args: targets = args[0] else: targets = kwargs.get("targets") diff --git a/tests/func/experiments/test_remove.py b/tests/func/experiments/test_remove.py index 8dd2b6549..a172eccfd 100644 --- a/tests/func/experiments/test_remove.py +++ b/tests/func/experiments/test_remove.py @@ -18,7 +18,7 @@ def test_remove_experiments_by_ref(tmp_dir, scm, dvc, exp_stage, caplog): ref_name_list.append(str(ref_info)) with pytest.raises(InvalidArgumentError): - dvc.experiments.remove(ref_name_list[:2] + ["non-exist"]) + dvc.experiments.remove([*ref_name_list[:2], "non-exist"]) assert scm.get_ref(ref_name_list[0]) is not None assert scm.get_ref(ref_name_list[1]) is not None assert scm.get_ref(ref_name_list[2]) is not None diff --git a/tests/func/repro/test_repro.py b/tests/func/repro/test_repro.py index a1ea308d2..aabda54b1 100644 --- a/tests/func/repro/test_repro.py +++ b/tests/func/repro/test_repro.py @@ -759,7 +759,7 @@ def test_repro_dry(tmp_dir, dvc, copy_script): stages = dvc.reproduce(stage.addressing, dry=True) - assert len(stages), 2 + assert len(stages) == 2 assert not filecmp.cmp("file1", "bar", shallow=False) ret = main(["repro", "--dry", stage.addressing]) diff --git a/tests/func/test_state.py b/tests/func/test_state.py index 65c5ee262..3853addf1 100644 --- a/tests/func/test_state.py +++ b/tests/func/test_state.py @@ -65,7 +65,7 @@ def test_get_unused_links(tmp_dir, dvc): assert set(dvc.state.get_unused_links(links, dvc.fs)) == set() assert set( dvc.state.get_unused_links( - (links[:1] + [os.path.join(dvc.root_dir, "not-existing-file")]), + ([*links[:1], os.path.join(dvc.root_dir, "not-existing-file")]), dvc.fs, ) ) == {"bar"} diff --git a/tests/unit/output/test_load.py b/tests/unit/output/test_load.py index e69cc2d8f..bdf9c466f 100644 --- a/tests/unit/output/test_load.py +++ b/tests/unit/output/test_load.py @@ -99,7 +99,7 @@ def test_load_from_pipeline_error_on_typ(dvc, typ): output.load_from_pipeline(Stage(dvc), ["file1"], typ) -@pytest.mark.parametrize("key", [3, "list".split()]) +@pytest.mark.parametrize("key", [3, ["list"]]) def test_load_from_pipeline_illegal_type(dvc, key): stage = Stage(dvc) with pytest.raises(ValueError, match=f"'{type(key).__name__}' not supported."): diff --git a/tests/unit/test_context.py b/tests/unit/test_context.py index bc10628d5..6eeced5ee 100644 --- a/tests/unit/test_context.py +++ b/tests/unit/test_context.py @@ -60,7 +60,7 @@ def test_context_list(): _ = context["lst"][3] context["lst"].insert(0, "baz") - assert context["lst"] == CtxList(["baz"] + lst[:2]) + assert context["lst"] == CtxList(["baz", *lst[:2]]) def test_context_setitem_getitem():