Skip to content

Commit

Permalink
use ruff formatter (#10081)
Browse files Browse the repository at this point in the history
Replaces black with ruff-formatter, and isort with ruff.
  • Loading branch information
skshetry authored Nov 9, 2023
1 parent 06565e1 commit 4ee8f55
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 42 deletions.
1 change: 1 addition & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[flake8]
max_line_length = 88
extend-ignore=
E501
# Whitespace before ':'
E203
# Line break occurred before a binary operator
Expand Down
13 changes: 2 additions & 11 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 1 addition & 3 deletions dvc/commands/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions dvc/repo/experiments/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion dvc/repo/experiments/executor/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}})
Expand Down
8 changes: 6 additions & 2 deletions dvc/testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
4 changes: 1 addition & 3 deletions dvc/testing/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=""):
Expand Down
4 changes: 1 addition & 3 deletions dvc/utils/table.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
8 changes: 2 additions & 6 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion tests/func/test_init.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)


Expand Down
4 changes: 1 addition & 3 deletions tests/func/utils/test_strict_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """\
Expand Down
8 changes: 2 additions & 6 deletions tests/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
)


Expand All @@ -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"),
)

0 comments on commit 4ee8f55

Please sign in to comment.