From 4ee8f554a5cf6b96744069244ec1ed803e58345c Mon Sep 17 00:00:00 2001 From: skshetry <18718008+skshetry@users.noreply.github.com> Date: Thu, 9 Nov 2023 20:58:58 +0545 Subject: [PATCH] use ruff formatter (#10081) Replaces black with ruff-formatter, and isort with ruff. --- .flake8 | 1 + .pre-commit-config.yaml | 13 ++----------- dvc/commands/data.py | 4 +--- dvc/repo/experiments/apply.py | 4 +--- dvc/repo/experiments/executor/local.py | 5 ++++- dvc/testing/fixtures.py | 8 ++++++-- dvc/testing/scripts.py | 4 +--- dvc/utils/table.py | 4 +--- pyproject.toml | 8 ++------ tests/func/test_init.py | 3 ++- tests/func/utils/test_strict_yaml.py | 4 +--- tests/scripts.py | 8 ++------ 12 files changed, 24 insertions(+), 42 deletions(-) diff --git a/.flake8 b/.flake8 index 736ce6620d..edf22d70b4 100644 --- a/.flake8 +++ b/.flake8 @@ -1,6 +1,7 @@ [flake8] max_line_length = 88 extend-ignore= + E501 # Whitespace before ':' E203 # Line break occurred before a binary operator diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7c7e33868b..99d9789e02 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -17,25 +17,16 @@ repos: args: ['--assume-in-merge'] - id: check-toml - id: check-yaml - - id: debug-statements - exclude: "dvc/_debug.py" - id: end-of-file-fixer - id: mixed-line-ending - id: sort-simple-yaml - id: trailing-whitespace - - repo: https://github.com/psf/black - rev: 23.9.1 - hooks: - - id: black - - repo: https://github.com/PyCQA/isort - rev: 5.12.0 - hooks: - - id: isort - repo: https://github.com/astral-sh/ruff-pre-commit - rev: 'v0.0.291' + rev: 'v0.1.5' hooks: - id: ruff args: [--fix, --exit-non-zero-on-fix] + - id: ruff-format - repo: https://github.com/codespell-project/codespell rev: v2.2.5 hooks: diff --git a/dvc/commands/data.py b/dvc/commands/data.py index eb1da14d20..5b235e0f43 100644 --- a/dvc/commands/data.py +++ b/dvc/commands/data.py @@ -106,9 +106,7 @@ def _show_status(cls, status: "DataStatus") -> int: # noqa: C901 return 0 def run(self) -> int: - with log_durations( - logger.trace, "in data_status" # type: ignore[attr-defined] - ): + with log_durations(logger.trace, "in data_status"): # type: ignore[attr-defined] status = self.repo.data_status( granular=self.args.granular, untracked_files=self.args.untracked_files, diff --git a/dvc/repo/experiments/apply.py b/dvc/repo/experiments/apply.py index 8e59afc387..102f2c6c4e 100644 --- a/dvc/repo/experiments/apply.py +++ b/dvc/repo/experiments/apply.py @@ -36,9 +36,7 @@ def apply(repo: "Repo", rev: str, **kwargs): # noqa: C901 ( exp_ref_info, queue_entry, - ) = exps.celery_queue.get_ref_and_entry_by_names( - rev - )[rev] + ) = exps.celery_queue.get_ref_and_entry_by_names(rev)[rev] if exp_ref_info: exp_rev = repo.scm.get_ref(str(exp_ref_info)) elif queue_entry: diff --git a/dvc/repo/experiments/executor/local.py b/dvc/repo/experiments/executor/local.py index a1af685bf2..693141d877 100644 --- a/dvc/repo/experiments/executor/local.py +++ b/dvc/repo/experiments/executor/local.py @@ -148,7 +148,10 @@ def _update_config(self, update): conf_obj.write(fobj) def init_cache( - self, repo: "Repo", rev: str, run_cache: bool = True # noqa: ARG002 + self, + repo: "Repo", + rev: str, # noqa: ARG002 + run_cache: bool = True, # noqa: ARG002 ): """Initialize DVC cache.""" self._update_config({"cache": {"dir": repo.cache.local_cache_dir}}) diff --git a/dvc/testing/fixtures.py b/dvc/testing/fixtures.py index 553a3ed3ac..b5b20d7020 100644 --- a/dvc/testing/fixtures.py +++ b/dvc/testing/fixtures.py @@ -237,7 +237,9 @@ def docker_services( try: subprocess.check_output( # nosec B607, B602, - "docker ps", stderr=subprocess.STDOUT, shell=True # noqa: S602, S607 + "docker ps", # noqa: S607 + stderr=subprocess.STDOUT, + shell=True, # noqa: S602 ) except subprocess.CalledProcessError as err: out = (err.output or b"").decode("utf-8") @@ -246,7 +248,9 @@ def docker_services( try: cmd = "docker-compose version" subprocess.check_output( - cmd, stderr=subprocess.STDOUT, shell=True # nosec B602 # noqa: S602 + cmd, + stderr=subprocess.STDOUT, + shell=True, # nosec B602 # noqa: S602 ) except subprocess.CalledProcessError as err: out = (err.output or b"").decode("utf-8") diff --git a/dvc/testing/scripts.py b/dvc/testing/scripts.py index 072ecd5af5..9c907a1828 100644 --- a/dvc/testing/scripts.py +++ b/dvc/testing/scripts.py @@ -9,9 +9,7 @@ shutil.copyfile(sys.argv[1], sys.argv[2]) else: shutil.copytree(sys.argv[1], sys.argv[2]) -""".replace( - "\r\n", "\n" -) +""".replace("\r\n", "\n") def _add_script(tmp_dir, path, contents=""): diff --git a/dvc/utils/table.py b/dvc/utils/table.py index 3330eef643..3ab4a80d9d 100644 --- a/dvc/utils/table.py +++ b/dvc/utils/table.py @@ -57,9 +57,7 @@ def _collapse_widths( # type: ignore[override] If table is still too wide after collapsing, rich's automatic overflow handling will be used. """ - collapsible = [ - column.collapse for column in self.columns # type: ignore[attr-defined] - ] + collapsible = [column.collapse for column in self.columns] # type: ignore[attr-defined] total_width = sum(widths) excess_width = total_width - max_width if any(collapsible): diff --git a/pyproject.toml b/pyproject.toml index 4d763c7ba8..a3f700f623 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -143,10 +143,6 @@ namespaces = false [tool.setuptools_scm] write_to = "dvc/_dvc_version.py" -[tool.isort] -known_first_party = ["dvc", "dvc_data", "dvc_objects", "dvc_render", "dvc_task", "tests"] -profile = "black" - [tool.pytest.ini_options] addopts = "-ra --cov-config pyproject.toml --dist worksteal" filterwarnings = [ @@ -251,11 +247,11 @@ ignore-words-list = "ba,datas,fo,uptodate,cachable,falsy" # external flake8 codes that should be preserved external = ["B301", "C901", "E302", "W601"] ignore = [ - "N818", "S101", "PT004", "PT007", "RET501", "RET502", "RET503", "SIM105", "SIM108", + "N818", "S101", "ISC001", "PT004", "PT007", "RET501", "RET502", "RET503", "SIM105", "SIM108", "SIM117", "TRY003", "TRY200", "TRY300", "PLR2004", "PLW2901", "RUF012" ] select = [ - "F", "E", "W", "C90", "N", "UP", "YTT", "ASYNC", "S", "BLE", "B", "A", "C4", "T10", + "F", "E", "W", "C90", "I", "N", "UP", "YTT", "ASYNC", "S", "BLE", "B", "A", "C4", "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", "RUF", diff --git a/tests/func/test_init.py b/tests/func/test_init.py index 5e79a9a47d..7d42f9cd45 100644 --- a/tests/func/test_init.py +++ b/tests/func/test_init.py @@ -93,7 +93,8 @@ def test_subdir_init_no_option(tmp_dir, scm, monkeypatch, caplog): "{} is not tracked by any supported SCM tool (e.g. Git). " "Use `--no-scm` if you don't want to use any SCM or " "`--subdir` if initializing inside a subdirectory of a parent SCM " - "repository.".format(os.fspath(tmp_dir / "subdir")) in caplog.text + "repository.".format(os.fspath(tmp_dir / "subdir")) + in caplog.text ) diff --git a/tests/func/utils/test_strict_yaml.py b/tests/func/utils/test_strict_yaml.py index b32b35557f..74aacec6d6 100644 --- a/tests/func/utils/test_strict_yaml.py +++ b/tests/func/utils/test_strict_yaml.py @@ -33,9 +33,7 @@ './dvc.yaml' is invalid. Mapping values are not allowed {}, in line 3, column 8 - 3 │ cmd: python script.py""".format( - "in this context" if ruamel_clib else "here" -) + 3 │ cmd: python script.py""".format("in this context" if ruamel_clib else "here") NO_HYPHEN_INDICATOR_IN_BLOCK = """\ diff --git a/tests/scripts.py b/tests/scripts.py index 5b2887f8fc..8bcf79a625 100644 --- a/tests/scripts.py +++ b/tests/scripts.py @@ -14,9 +14,7 @@ def append_foo_script(tmp_dir): with Path(sys.argv[1]).open("a+", encoding="utf-8") as f: f.write("foo") -""".replace( - "\r\n", "\n" - ), +""".replace("\r\n", "\n"), ) @@ -34,7 +32,5 @@ def head_script(tmp_dir): for file in sys.argv[1:]: with open(file) as f, open(file +"-1","w+") as w: w.write(f.readline()) -""".replace( - "\r\n", "\n" - ), +""".replace("\r\n", "\n"), )