mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-01 23:08:43 +01:00
use ruff formatter (#10081)
Replaces black with ruff-formatter, and isort with ruff.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
[flake8]
|
[flake8]
|
||||||
max_line_length = 88
|
max_line_length = 88
|
||||||
extend-ignore=
|
extend-ignore=
|
||||||
|
E501
|
||||||
# Whitespace before ':'
|
# Whitespace before ':'
|
||||||
E203
|
E203
|
||||||
# Line break occurred before a binary operator
|
# Line break occurred before a binary operator
|
||||||
|
|||||||
+2
-11
@@ -17,25 +17,16 @@ repos:
|
|||||||
args: ['--assume-in-merge']
|
args: ['--assume-in-merge']
|
||||||
- id: check-toml
|
- id: check-toml
|
||||||
- id: check-yaml
|
- id: check-yaml
|
||||||
- id: debug-statements
|
|
||||||
exclude: "dvc/_debug.py"
|
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
- id: mixed-line-ending
|
- id: mixed-line-ending
|
||||||
- id: sort-simple-yaml
|
- id: sort-simple-yaml
|
||||||
- id: trailing-whitespace
|
- 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
|
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||||
rev: 'v0.0.291'
|
rev: 'v0.1.5'
|
||||||
hooks:
|
hooks:
|
||||||
- id: ruff
|
- id: ruff
|
||||||
args: [--fix, --exit-non-zero-on-fix]
|
args: [--fix, --exit-non-zero-on-fix]
|
||||||
|
- id: ruff-format
|
||||||
- repo: https://github.com/codespell-project/codespell
|
- repo: https://github.com/codespell-project/codespell
|
||||||
rev: v2.2.5
|
rev: v2.2.5
|
||||||
hooks:
|
hooks:
|
||||||
|
|||||||
@@ -106,9 +106,7 @@ class CmdDataStatus(CmdBase):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
def run(self) -> int:
|
def run(self) -> int:
|
||||||
with log_durations(
|
with log_durations(logger.trace, "in data_status"): # type: ignore[attr-defined]
|
||||||
logger.trace, "in data_status" # type: ignore[attr-defined]
|
|
||||||
):
|
|
||||||
status = self.repo.data_status(
|
status = self.repo.data_status(
|
||||||
granular=self.args.granular,
|
granular=self.args.granular,
|
||||||
untracked_files=self.args.untracked_files,
|
untracked_files=self.args.untracked_files,
|
||||||
|
|||||||
@@ -36,9 +36,7 @@ def apply(repo: "Repo", rev: str, **kwargs): # noqa: C901
|
|||||||
(
|
(
|
||||||
exp_ref_info,
|
exp_ref_info,
|
||||||
queue_entry,
|
queue_entry,
|
||||||
) = exps.celery_queue.get_ref_and_entry_by_names(
|
) = exps.celery_queue.get_ref_and_entry_by_names(rev)[rev]
|
||||||
rev
|
|
||||||
)[rev]
|
|
||||||
if exp_ref_info:
|
if exp_ref_info:
|
||||||
exp_rev = repo.scm.get_ref(str(exp_ref_info))
|
exp_rev = repo.scm.get_ref(str(exp_ref_info))
|
||||||
elif queue_entry:
|
elif queue_entry:
|
||||||
|
|||||||
@@ -148,7 +148,10 @@ class TempDirExecutor(BaseLocalExecutor):
|
|||||||
conf_obj.write(fobj)
|
conf_obj.write(fobj)
|
||||||
|
|
||||||
def init_cache(
|
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."""
|
"""Initialize DVC cache."""
|
||||||
self._update_config({"cache": {"dir": repo.cache.local_cache_dir}})
|
self._update_config({"cache": {"dir": repo.cache.local_cache_dir}})
|
||||||
|
|||||||
@@ -237,7 +237,9 @@ def docker_services(
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
subprocess.check_output( # nosec B607, B602,
|
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:
|
except subprocess.CalledProcessError as err:
|
||||||
out = (err.output or b"").decode("utf-8")
|
out = (err.output or b"").decode("utf-8")
|
||||||
@@ -246,7 +248,9 @@ def docker_services(
|
|||||||
try:
|
try:
|
||||||
cmd = "docker-compose version"
|
cmd = "docker-compose version"
|
||||||
subprocess.check_output(
|
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:
|
except subprocess.CalledProcessError as err:
|
||||||
out = (err.output or b"").decode("utf-8")
|
out = (err.output or b"").decode("utf-8")
|
||||||
|
|||||||
@@ -9,9 +9,7 @@ if os.path.isfile(sys.argv[1]):
|
|||||||
shutil.copyfile(sys.argv[1], sys.argv[2])
|
shutil.copyfile(sys.argv[1], sys.argv[2])
|
||||||
else:
|
else:
|
||||||
shutil.copytree(sys.argv[1], sys.argv[2])
|
shutil.copytree(sys.argv[1], sys.argv[2])
|
||||||
""".replace(
|
""".replace("\r\n", "\n")
|
||||||
"\r\n", "\n"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def _add_script(tmp_dir, path, contents=""):
|
def _add_script(tmp_dir, path, contents=""):
|
||||||
|
|||||||
+1
-3
@@ -57,9 +57,7 @@ class Table(RichTable):
|
|||||||
If table is still too wide after collapsing, rich's automatic overflow
|
If table is still too wide after collapsing, rich's automatic overflow
|
||||||
handling will be used.
|
handling will be used.
|
||||||
"""
|
"""
|
||||||
collapsible = [
|
collapsible = [column.collapse for column in self.columns] # type: ignore[attr-defined]
|
||||||
column.collapse for column in self.columns # type: ignore[attr-defined]
|
|
||||||
]
|
|
||||||
total_width = sum(widths)
|
total_width = sum(widths)
|
||||||
excess_width = total_width - max_width
|
excess_width = total_width - max_width
|
||||||
if any(collapsible):
|
if any(collapsible):
|
||||||
|
|||||||
+2
-6
@@ -143,10 +143,6 @@ namespaces = false
|
|||||||
[tool.setuptools_scm]
|
[tool.setuptools_scm]
|
||||||
write_to = "dvc/_dvc_version.py"
|
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]
|
[tool.pytest.ini_options]
|
||||||
addopts = "-ra --cov-config pyproject.toml --dist worksteal"
|
addopts = "-ra --cov-config pyproject.toml --dist worksteal"
|
||||||
filterwarnings = [
|
filterwarnings = [
|
||||||
@@ -251,11 +247,11 @@ ignore-words-list = "ba,datas,fo,uptodate,cachable,falsy"
|
|||||||
# external flake8 codes that should be preserved
|
# external flake8 codes that should be preserved
|
||||||
external = ["B301", "C901", "E302", "W601"]
|
external = ["B301", "C901", "E302", "W601"]
|
||||||
ignore = [
|
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"
|
"SIM117", "TRY003", "TRY200", "TRY300", "PLR2004", "PLW2901", "RUF012"
|
||||||
]
|
]
|
||||||
select = [
|
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",
|
"EXE", "ISC", "ICN", "G", "INP", "PIE", "T20", "PYI", "PT", "Q", "RSE", "RET",
|
||||||
"SLOT", "SIM", "TID", "TCH", "ARG", "PGH", "PLC", "PLE", "PLR", "PLW", "TRY",
|
"SLOT", "SIM", "TID", "TCH", "ARG", "PGH", "PLC", "PLE", "PLR", "PLW", "TRY",
|
||||||
"FLY", "PERF101", "RUF",
|
"FLY", "PERF101", "RUF",
|
||||||
|
|||||||
@@ -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). "
|
"{} is not tracked by any supported SCM tool (e.g. Git). "
|
||||||
"Use `--no-scm` if you don't want to use any SCM or "
|
"Use `--no-scm` if you don't want to use any SCM or "
|
||||||
"`--subdir` if initializing inside a subdirectory of a parent SCM "
|
"`--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
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,9 +33,7 @@ MAPPING_VALUES_NOT_ALLOWED_OUTPUT = """\
|
|||||||
'./dvc.yaml' is invalid.
|
'./dvc.yaml' is invalid.
|
||||||
|
|
||||||
Mapping values are not allowed {}, in line 3, column 8
|
Mapping values are not allowed {}, in line 3, column 8
|
||||||
3 │ cmd: python script.py""".format(
|
3 │ cmd: python script.py""".format("in this context" if ruamel_clib else "here")
|
||||||
"in this context" if ruamel_clib else "here"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
NO_HYPHEN_INDICATOR_IN_BLOCK = """\
|
NO_HYPHEN_INDICATOR_IN_BLOCK = """\
|
||||||
|
|||||||
+2
-6
@@ -14,9 +14,7 @@ from pathlib import Path
|
|||||||
|
|
||||||
with Path(sys.argv[1]).open("a+", encoding="utf-8") as f:
|
with Path(sys.argv[1]).open("a+", encoding="utf-8") as f:
|
||||||
f.write("foo")
|
f.write("foo")
|
||||||
""".replace(
|
""".replace("\r\n", "\n"),
|
||||||
"\r\n", "\n"
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -34,7 +32,5 @@ import sys
|
|||||||
for file in sys.argv[1:]:
|
for file in sys.argv[1:]:
|
||||||
with open(file) as f, open(file +"-1","w+") as w:
|
with open(file) as f, open(file +"-1","w+") as w:
|
||||||
w.write(f.readline())
|
w.write(f.readline())
|
||||||
""".replace(
|
""".replace("\r\n", "\n"),
|
||||||
"\r\n", "\n"
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user