diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 4d6bb971d..c7d39eebf 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -43,10 +43,9 @@ repos: hooks: - id: isort - repo: https://github.com/charliermarsh/ruff-pre-commit - rev: 'v0.0.223' + rev: 'v0.0.235' hooks: - id: ruff - args: ["--force-exclude"] - repo: https://github.com/codespell-project/codespell rev: v2.2.2 hooks: diff --git a/dvc/daemon.py b/dvc/daemon.py index ff4a35224..1311bb9dc 100644 --- a/dvc/daemon.py +++ b/dvc/daemon.py @@ -105,7 +105,7 @@ def daemon(args): Args: args (list): list of arguments to append to `dvc daemon` command. """ - daemonize(["daemon", "-q"] + args) + daemonize(["daemon", "-q", *args]) def daemonize(cmd: List[str]): diff --git a/dvc/dependency/__init__.py b/dvc/dependency/__init__.py index 965e75168..a1bd0eaa4 100644 --- a/dvc/dependency/__init__.py +++ b/dvc/dependency/__init__.py @@ -74,7 +74,7 @@ def _merge_params(s_list): if not isinstance(key, dict): msg = "Only list of str/dict is supported. Got: " msg += f"'{type(key).__name__}'." - raise ValueError(msg) + raise ValueError(msg) # noqa: TRY004 for k, params in key.items(): if k in wholly_tracked: @@ -83,7 +83,7 @@ def _merge_params(s_list): if not isinstance(params, list): msg = "Expected list of params for custom params file " msg += f"'{k}', got '{type(params).__name__}'." - raise ValueError(msg) + raise ValueError(msg) # noqa: TRY004 d[k].extend(params) return d diff --git a/dvc/output.py b/dvc/output.py index de75c4c0d..4138499da 100644 --- a/dvc/output.py +++ b/dvc/output.py @@ -150,11 +150,13 @@ def _merge_data(s_list): d[key].update({}) continue if not isinstance(key, dict): - raise ValueError(f"'{type(key).__name__}' not supported.") + raise ValueError( # noqa: TRY004 + f"'{type(key).__name__}' not supported." + ) for k, flags in key.items(): if not isinstance(flags, dict): - raise ValueError( + raise ValueError( # noqa: TRY004 f"Expected dict for '{k}', got: '{type(flags).__name__}'" ) d[k].update(flags) diff --git a/dvc/parsing/context.py b/dvc/parsing/context.py index f2c02fe81..92387c041 100644 --- a/dvc/parsing/context.py +++ b/dvc/parsing/context.py @@ -228,7 +228,7 @@ class Container(Node, ABC): # noqa: B024 rem = rems[0] if not isinstance(d, Container): - raise ValueError( + raise ValueError( # noqa: TRY004 f"{index} is a primitive value, cannot get '{rem}'" ) return d.select(rem) diff --git a/dvc/repo/experiments/queue/celery.py b/dvc/repo/experiments/queue/celery.py index 8d2cef4c9..ba668e786 100644 --- a/dvc/repo/experiments/queue/celery.py +++ b/dvc/repo/experiments/queue/celery.py @@ -146,7 +146,7 @@ class LocalCeleryQueue(BaseStashQueue): if os.name == "nt": daemonize(cmd) else: - ManagedProcess.spawn(["dvc"] + cmd, wdir=self.wdir, name=name) + ManagedProcess.spawn(["dvc", *cmd], wdir=self.wdir, name=name) def start_workers(self, count: int) -> int: """start some workers to process the queued tasks. diff --git a/dvc/repo/gc.py b/dvc/repo/gc.py index e98203975..845f178bd 100644 --- a/dvc/repo/gc.py +++ b/dvc/repo/gc.py @@ -72,7 +72,7 @@ def gc( for repo in all_repos: stack.enter_context(repo.lock) - for repo in all_repos + [self]: + for repo in [*all_repos, self]: for obj_ids in repo.used_objs( all_branches=all_branches, with_deps=with_deps, diff --git a/dvc/stage/run.py b/dvc/stage/run.py index b87f31303..4f4e0ebf0 100644 --- a/dvc/stage/run.py +++ b/dvc/stage/run.py @@ -22,7 +22,7 @@ def _make_cmd(executable, cmd): return cmd opts = {"zsh": ["--no-rcs"], "bash": ["--noprofile", "--norc"]} name = os.path.basename(executable).lower() - return [executable] + opts.get(name, []) + ["-c", cmd] + return [executable, *opts.get(name, []), "-c", cmd] def warn_if_fish(executable): diff --git a/dvc/utils/collections.py b/dvc/utils/collections.py index 23350813f..805353d02 100644 --- a/dvc/utils/collections.py +++ b/dvc/utils/collections.py @@ -53,7 +53,7 @@ def apply_diff(src, dest): # noqa: C901 elif value != dest[i]: dest[i] = value else: - raise AssertionError( + raise AssertionError( # noqa: TRY004 "Can't apply diff from {} to {}".format( src.__class__.__name__, dest.__class__.__name__ ) diff --git a/dvc/utils/strictyaml.py b/dvc/utils/strictyaml.py index 5e55ef9ee..d3676413c 100644 --- a/dvc/utils/strictyaml.py +++ b/dvc/utils/strictyaml.py @@ -93,7 +93,7 @@ class YAMLSyntaxError(PrettyDvcException, YAMLFileCorruptedError): exc = self.exc.__cause__ if not isinstance(exc, MarkedYAMLError): - raise ValueError("nothing to pretty-print here. :)") + raise ValueError("nothing to pretty-print here.") # noqa: TRY004 source = self.yaml_text.splitlines() diff --git a/pyproject.toml b/pyproject.toml index ce6f5e59b..07ef14ad0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -161,13 +161,13 @@ line_length = 79 line-length = 79 target-version = "py38" show-source = true -ignore = ["S101", "SIM105", "SIM108", "SIM110", "SIM111", "SIM117", "A003", "ARG002", "PLR2004"] -select = ["F", "E", "W", "C90", "UP", "YTT", "S", "BLE", "B", "A", "C4", "T10", "ISC", "ICN", "T20", "PT003", "PT008", "PT009", "PT010", "PT015", "PT016", "PT017", "PT020", "PT021", "PT024", "PT025", "PT026", "Q", "RET501", "RET504", "SIM", "ARG", "TID", "PGH", "PLC", "PLE", "PLR", "PLW", "PIE", "RUF"] +ignore = ["S101", "SIM105", "SIM108", "SIM110", "SIM111", "SIM117", "A003", "ARG002", "PLR2004", "RUF005"] +select = ["F", "E", "W", "C90", "UP", "YTT", "S", "BLE", "B", "A", "C4", "T10", "ISC", "ICN", "T20", "PT003", "PT008", "PT009", "PT010", "PT015", "PT016", "PT017", "PT020", "PT021", "PT024", "PT025", "PT026", "Q", "RET501", "RET504", "SIM", "ARG", "TID", "PGH", "PLC", "PLE", "PLR", "PLW", "PIE", "INP", "TRY004", "TRY201", "RUF"] # external flake8 codes that should be preserved external = ["B301", "B024", "C901", "E302", "F401", "W601"] [tool.ruff.per-file-ignores] -"scripts/**/*.py" = ["T201"] +"scripts/**/*.py" = ["T201", "INP001"] [tool.ruff.flake8-pytest-style] fixture-parentheses = false diff --git a/tests/func/api/__init__.py b/tests/func/api/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/func/test_check_ignore.py b/tests/func/test_check_ignore.py index 6e377af49..80e21494a 100644 --- a/tests/func/test_check_ignore.py +++ b/tests/func/test_check_ignore.py @@ -65,7 +65,7 @@ def test_check_ignore_non_matching(tmp_dir, dvc, non_matching, caplog, capsys): ], ) def test_check_ignore_error_args_cases(tmp_dir, dvc, args, caplog): - assert main(["check-ignore"] + args) == 255 + assert main(["check-ignore", *args]) == 255 assert "Having any troubles?" not in caplog.text diff --git a/tests/func/test_config.py b/tests/func/test_config.py index 9bc437895..e2a48208f 100644 --- a/tests/func/test_config.py +++ b/tests/func/test_config.py @@ -129,7 +129,7 @@ def test_config_get(tmp_dir, dvc, capsys, caplog, args, ret, msg): ) ) - assert main(["config"] + args) == ret + assert main(["config", *args]) == ret text = caplog.text if ret else capsys.readouterr()[0] assert msg in text @@ -143,7 +143,7 @@ def test_config_get(tmp_dir, dvc, capsys, caplog, args, ret, msg): ], ) def test_config_get_in_non_dvc_repo(tmp_dir, caplog, args, ret): - assert main(["config"] + args) == ret + assert main(["config", *args]) == ret if ret != 0: out = caplog.text assert "Not inside a DVC repo" in out @@ -199,7 +199,7 @@ def test_config_list(tmp_dir, dvc, capsys): ], ) def test_config_list_in_non_dvc_repo(tmp_dir, caplog, args, ret): - assert main(["config"] + args) == ret + assert main(["config", *args]) == ret if ret != 0: out = caplog.text assert "Not inside a DVC repo" in out @@ -210,7 +210,7 @@ def test_config_list_in_non_dvc_repo(tmp_dir, caplog, args, ret): ) def test_list_bad_args(tmp_dir, dvc, caplog, args): caplog.clear() - assert main(["config", "--list"] + args) == 1 + assert main(["config", "--list", *args]) == 1 assert ( "-l/--list can't be used together with any of these options: " "-u/--unset, name, value" diff --git a/tests/func/test_data_cloud.py b/tests/func/test_data_cloud.py index dc1871d7f..5f3aca21f 100644 --- a/tests/func/test_data_cloud.py +++ b/tests/func/test_data_cloud.py @@ -39,7 +39,7 @@ def test_cloud_cli(tmp_dir, dvc, remote, mocker): # FIXME check status output oids_exist = mocker.spy(LocalHashFileDB, "oids_exist") - assert main(["push"] + args) == 0 + assert main(["push", *args]) == 0 assert os.path.exists(cache) assert os.path.isfile(cache) assert os.path.isfile(cache_dir) @@ -52,7 +52,7 @@ def test_cloud_cli(tmp_dir, dvc, remote, mocker): dvc.odb.local.clear() oids_exist.reset_mock() - assert main(["fetch"] + args) == 0 + assert main(["fetch", *args]) == 0 assert os.path.exists(cache) assert os.path.isfile(cache) assert os.path.isfile(cache_dir) @@ -64,7 +64,7 @@ def test_cloud_cli(tmp_dir, dvc, remote, mocker): oids_exist.reset_mock() - assert main(["pull"] + args) == 0 + assert main(["pull", *args]) == 0 assert os.path.exists(cache) assert os.path.isfile(cache) assert os.path.isfile(cache_dir) @@ -88,14 +88,14 @@ def test_cloud_cli(tmp_dir, dvc, remote, mocker): _list_oids_traverse = mocker.spy(HashFileDB, "_list_oids_traverse") # NOTE: check if remote gc works correctly on directories - assert main(["gc", "-cw", "-f"] + args) == 0 + assert main(["gc", "-cw", "-f", *args]) == 0 assert _list_oids_traverse.called assert all( _kwargs["jobs"] == 2 for (_args, _kwargs) in oids_exist.call_args_list ) shutil.move(dvc.odb.local.path, dvc.odb.local.path + ".back") - assert main(["fetch"] + args) == 0 + assert main(["fetch", *args]) == 0 assert oids_exist.called assert all( @@ -104,7 +104,7 @@ def test_cloud_cli(tmp_dir, dvc, remote, mocker): ) oids_exist.reset_mock() - assert main(["pull", "-f"] + args) == 0 + assert main(["pull", "-f", *args]) == 0 assert os.path.exists(cache) assert os.path.isfile(cache) assert os.path.isfile(cache_dir) diff --git a/tests/func/test_ls.py b/tests/func/test_ls.py index 4d709d57d..59885e9cd 100644 --- a/tests/func/test_ls.py +++ b/tests/func/test_ls.py @@ -42,13 +42,11 @@ def create_dvc_pipeline(tmp_dir, dvc): tmp_dir.scm_gen({"script.py": script}, commit="init") tmp_dir.dvc_gen({"dep": "content"}, commit="init dvc") dvc.run( - **{ - "cmd": "python script.py {}".format(os.path.join("out", "file")), - "outs": [os.path.join("out", "file")], - "deps": ["dep"], - "fname": "out.dvc", - "single_stage": True, - } + cmd="python script.py {}".format(os.path.join("out", "file")), + outs=[os.path.join("out", "file")], + deps=["dep"], + fname="out.dvc", + single_stage=True, ) tmp_dir.scm_add(["out.dvc"], commit="run") shutil.rmtree("out") diff --git a/tests/ruff.toml b/tests/ruff.toml index 576a93f61..d7cbe2ee6 100644 --- a/tests/ruff.toml +++ b/tests/ruff.toml @@ -1,2 +1,3 @@ extend = "../pyproject.toml" +extend-select = ["RUF005"] extend-ignore = ["S", "RUF001", "ARG001", "ARG002"] diff --git a/tests/unit/command/test_machine.py b/tests/unit/command/test_machine.py index 6db8fb258..cdb37cfdb 100644 --- a/tests/unit/command/test_machine.py +++ b/tests/unit/command/test_machine.py @@ -118,7 +118,7 @@ def test_list(tmp_dir, mocker, show_origin): from dvc.ui import ui tmp_dir.gen(DATA) - cli_args = parse_args(["machine", "list"] + show_origin + ["foo"]) + cli_args = parse_args(["machine", "list", *show_origin, "foo"]) assert cli_args.func == CmdMachineList cmd = cli_args.func(cli_args) if show_origin: diff --git a/tests/unit/fs/test_dvc.py b/tests/unit/fs/test_dvc.py index 7210076b6..b523b477b 100644 --- a/tests/unit/fs/test_dvc.py +++ b/tests/unit/fs/test_dvc.py @@ -629,7 +629,7 @@ def test_walk_nested_subrepos(tmp_dir, dvc, scm, traverse_subrepos): extras = {".gitignore"} # these files are always there expected = {} - for repo_dir in subrepos + [tmp_dir]: + for repo_dir in [*subrepos, tmp_dir]: base = os.path.basename(repo_dir) scm_files = fs_structure(base) dvc_files = dvc_structure(base) diff --git a/tests/unit/scm/__init__.py b/tests/unit/scm/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/unit/stage/test_serialize_pipeline_file.py b/tests/unit/stage/test_serialize_pipeline_file.py index 075d65a2e..3c57560ec 100644 --- a/tests/unit/stage/test_serialize_pipeline_file.py +++ b/tests/unit/stage/test_serialize_pipeline_file.py @@ -209,7 +209,7 @@ def test_order_deps_outs(dvc, typ): stage = create_stage(PipelineStage, dvc, **kwargs, **extra) assert typ not in to_pipeline_file(stage)["something"] - assert ( - list(to_pipeline_file(stage)["something"].keys()) - == ["cmd"] + all_types - ) + assert list(to_pipeline_file(stage)["something"].keys()) == [ + "cmd", + *all_types, + ] diff --git a/tests/unit/test_external_repo.py b/tests/unit/test_external_repo.py index 81d0b3e5f..a78e907fb 100644 --- a/tests/unit/test_external_repo.py +++ b/tests/unit/test_external_repo.py @@ -20,7 +20,7 @@ def test_hook_is_called(tmp_dir, erepo_dir, mocker): for repo in subrepos: make_subrepo(repo, erepo_dir.scm) - for repo in subrepos + [erepo_dir]: + for repo in [*subrepos, erepo_dir]: with repo.chdir(): repo.scm_gen("foo", "foo", commit=f"git add {repo}/foo") repo.dvc_gen("bar", "bar", commit=f"dvc add {repo}/bar")