update ruff to 0.6 (#10526)

This commit is contained in:
skshetry
2024-08-15 20:02:09 +05:45
committed by GitHub
parent d494126cc5
commit 38ee0a01f7
17 changed files with 28 additions and 26 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ repos:
- id: sort-simple-yaml - id: sort-simple-yaml
- id: trailing-whitespace - id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit - repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.5.7' rev: 'v0.6.0'
hooks: hooks:
- id: ruff - id: ruff
args: [--fix, --exit-non-zero-on-fix] args: [--fix, --exit-non-zero-on-fix]
+1 -1
View File
@@ -17,7 +17,7 @@ def _show_ascii(graph: "DiGraph"):
ret = [] ret = []
for pipeline in pipelines: for pipeline in pipelines:
ret.append(draw(pipeline.nodes, pipeline.edges)) ret.append(draw(pipeline.nodes, pipeline.edges)) # noqa: PERF401
return "\n".join(ret) return "\n".join(ret)
+1 -1
View File
@@ -123,7 +123,7 @@ def _get_supported_remotes():
if not fs_cls.get_missing_deps(): if not fs_cls.get_missing_deps():
dependencies = [] dependencies = []
for requirement in fs_cls.REQUIRES: for requirement in fs_cls.REQUIRES:
dependencies.append( dependencies.append( # noqa: PERF401
f"{requirement} = {importlib_metadata.version(requirement)}" f"{requirement} = {importlib_metadata.version(requirement)}"
) )
+1 -1
View File
@@ -23,7 +23,7 @@ def _lists(blob: Union[dict, list]) -> Iterable[list]:
if isinstance(blob, list): if isinstance(blob, list):
yield blob yield blob
else: else:
for _, value in blob.items(): for value in blob.values():
if isinstance(value, dict): if isinstance(value, dict):
yield from _lists(value) yield from _lists(value)
elif isinstance(value, list): elif isinstance(value, list):
+1 -1
View File
@@ -249,7 +249,7 @@ class Experiments:
exec_results = queue.reproduce(copy_paths=copy_paths, message=message) exec_results = queue.reproduce(copy_paths=copy_paths, message=message)
results: dict[str, str] = {} results: dict[str, str] = {}
for _, exp_result in exec_results.items(): for exp_result in exec_results.values():
results.update(exp_result) results.update(exp_result)
return results return results
+1 -1
View File
@@ -288,7 +288,7 @@ class BaseExecutor(ABC):
stages = [] stages = []
if targets: if targets:
for target in targets: for target in targets:
stages.append( stages.append( # noqa: PERF401
dvc.commit( dvc.commit(
target, recursive=recursive, force=True, relink=False target, recursive=recursive, force=True, relink=False
) )
+1 -1
View File
@@ -55,7 +55,7 @@ def pull( # noqa: C901
rev_dict = iter_revs(repo.scm, rev, num) rev_dict = iter_revs(repo.scm, rev, num)
rev_set = set(rev_dict.keys()) rev_set = set(rev_dict.keys())
ref_info_dict = exp_refs_by_baseline(repo.scm, rev_set, git_remote) ref_info_dict = exp_refs_by_baseline(repo.scm, rev_set, git_remote)
for _, ref_info_list in ref_info_dict.items(): for ref_info_list in ref_info_dict.values():
exp_ref_set.update(ref_info_list) exp_ref_set.update(ref_info_list)
pull_result = _pull(repo, git_remote, exp_ref_set, force) pull_result = _pull(repo, git_remote, exp_ref_set, force)
+1 -1
View File
@@ -78,7 +78,7 @@ def exp_refs_from_rev(scm: "Git", rev: list[str], num: int = 1) -> set["ExpRefIn
rev_dict = iter_revs(scm, rev, num) rev_dict = iter_revs(scm, rev, num)
rev_set = set(rev_dict.keys()) rev_set = set(rev_dict.keys())
ref_info_dict = exp_refs_by_baseline(scm, rev_set) ref_info_dict = exp_refs_by_baseline(scm, rev_set)
for _, ref_info_list in ref_info_dict.items(): for ref_info_list in ref_info_dict.values():
exp_ref_set.update(ref_info_list) exp_ref_set.update(ref_info_list)
return exp_ref_set return exp_ref_set
+1 -1
View File
@@ -323,7 +323,7 @@ class LocalCeleryQueue(BaseStashQueue):
def _get_running_task_ids(self) -> set[str]: def _get_running_task_ids(self) -> set[str]:
running_task_ids: set[str] = set() running_task_ids: set[str] = set()
active_workers = self.worker_status() active_workers = self.worker_status()
for _, tasks in active_workers.items(): for tasks in active_workers.values():
task = first(tasks) task = first(tasks)
if task: if task:
running_task_ids.add(task["id"]) running_task_ids.add(task["id"])
+1 -1
View File
@@ -25,7 +25,7 @@ def get_remote_executor_refs(scm: "Git", remote_url: str) -> list[str]:
refs = [] refs = []
for ref in iter_remote_refs(scm, remote_url, base=EXPS_NAMESPACE): for ref in iter_remote_refs(scm, remote_url, base=EXPS_NAMESPACE):
if not ref.startswith(EXEC_NAMESPACE) and ref != EXPS_STASH: if not ref.startswith(EXEC_NAMESPACE) and ref != EXPS_STASH:
refs.append(ref) refs.append(ref) # noqa: PERF401
return refs return refs
+1 -1
View File
@@ -98,7 +98,7 @@ def _resolve_exp_by_baseline(
rev_dict = iter_revs(repo.scm, rev, num) rev_dict = iter_revs(repo.scm, rev, num)
rev_set = set(rev_dict.keys()) rev_set = set(rev_dict.keys())
ref_info_dict = exp_refs_by_baseline(repo.scm, rev_set, git_remote) ref_info_dict = exp_refs_by_baseline(repo.scm, rev_set, git_remote)
for _, ref_info_list in ref_info_dict.items(): for ref_info_list in ref_info_dict.values():
for ref_info in ref_info_list: for ref_info in ref_info_list:
commit_ref_dict[ref_info.name] = ref_info commit_ref_dict[ref_info.name] = ref_info
return commit_ref_dict return commit_ref_dict
+2 -2
View File
@@ -302,9 +302,9 @@ def _get_stage_files(stage: "Stage") -> list[str]:
and dep.is_in_repo and dep.is_in_repo
and not stage.repo.dvcfs.isdvc(stage.repo.dvcfs.from_os_path(str(dep))) and not stage.repo.dvcfs.isdvc(stage.repo.dvcfs.from_os_path(str(dep)))
): ):
ret.append(relpath(dep.fs_path)) ret.append(relpath(dep.fs_path)) # noqa: PERF401
for out in stage.outs: for out in stage.outs:
if not out.use_scm_ignore and out.is_in_repo: if not out.use_scm_ignore and out.is_in_repo:
ret.append(relpath(out.fs_path)) ret.append(relpath(out.fs_path)) # noqa: PERF401
return ret return ret
+1 -1
View File
@@ -32,7 +32,7 @@ class PathInfo(pathlib.PurePath, _BasePath):
def __new__(cls, *args): def __new__(cls, *args):
if cls is PathInfo: if cls is PathInfo:
cls = WindowsPathInfo if os.name == "nt" else PosixPathInfo cls = WindowsPathInfo if os.name == "nt" else PosixPathInfo # noqa: PLW0642
return cls._from_parts(args) # type: ignore[attr-defined] return cls._from_parts(args) # type: ignore[attr-defined]
+1 -1
View File
@@ -71,7 +71,7 @@ class TmpDir(pathlib.Path):
def __new__(cls, *args, **kwargs): def __new__(cls, *args, **kwargs):
if cls is TmpDir: if cls is TmpDir:
cls = WindowsTmpDir if os.name == "nt" else PosixTmpDir cls = WindowsTmpDir if os.name == "nt" else PosixTmpDir # noqa: PLW0642
# init parameter and `_init` method has been removed in Python 3.10. # init parameter and `_init` method has been removed in Python 3.10.
kw = {"init": False} if sys.version_info < (3, 10) else {} kw = {"init": False} if sys.version_info < (3, 10) else {}
+1 -1
View File
@@ -243,7 +243,7 @@ def env2bool(var, undefined=False):
var = os.getenv(var, None) var = os.getenv(var, None)
if var is None: if var is None:
return undefined return undefined
return bool(re.search("1|y|yes|true", var, flags=re.I)) return bool(re.search("1|y|yes|true", var, flags=re.IGNORECASE))
def resolve_output(inp: str, out: Optional[str], force=False) -> str: def resolve_output(inp: str, out: Optional[str], force=False) -> str:
+5 -7
View File
@@ -264,21 +264,19 @@ show-fixes = true
[tool.ruff.lint] [tool.ruff.lint]
ignore = [ ignore = [
"N818", "S101", "ISC001", "PT004", "PT007", "RET502", "RET503", "SIM105", "SIM108", "SIM117", "N818", "S101", "ISC001", "PT007", "RET502", "RET503", "SIM105", "SIM108", "SIM117",
"TRY003", "TRY300", "PLR2004", "PLW2901", "LOG007", "TRY003", "TRY300", "PERF203", "PLR2004", "PLW2901", "LOG007",
] ]
select = [ select = [
"F", "E", "W", "C90", "I", "N", "UP", "YTT", "ASYNC", "S", "BLE", "B", "A", "C4", "DTZ", "T10", "F", "E", "W", "C90", "I", "N", "UP", "YTT", "ASYNC", "S", "BLE", "B", "A", "C4", "DTZ", "T10",
"EXE", "ISC", "ICN", "G", "INP", "PIE", "T20", "PYI", "PT", "Q", "RSE", "RET", "EXE", "ISC", "ICN", "LOG", "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", "LOG", "RUF", "RUF022", "RUF023", "RUF024", "RUF025", "RUF026", "RUF027" "FLY", "PERF", "FURB", "RUF", "RUF022", "RUF023", "RUF024", "RUF026", "RUF027", "RUF029", "RUF030",
] ]
preview = true preview = true
explicit-preview-rules = true explicit-preview-rules = true
[tool.ruff.lint.flake8-pytest-style] [tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false
parametrize-names-type = "csv" parametrize-names-type = "csv"
raises-extend-require-match-for = ["dvc.exceptions.DvcException", "dvc.scm.SCMError", "scmrepo.exceptions.SCMError"] raises-extend-require-match-for = ["dvc.exceptions.DvcException", "dvc.scm.SCMError", "scmrepo.exceptions.SCMError"]
@@ -305,4 +303,4 @@ max-args = 10
"dvc/commands/**" = ["N806"] "dvc/commands/**" = ["N806"]
"dvc/testing/**" = ["ARG002"] "dvc/testing/**" = ["ARG002"]
"dvc/testing/benchmarks/**" = ["ARG001"] "dvc/testing/benchmarks/**" = ["ARG001"]
"tests/**" = ["S", "ARG001", "ARG002", "TRY002", "TRY301"] "tests/**" = ["S", "ARG001", "ARG002", "TRY002", "TRY301", "PERF"]
+7 -3
View File
@@ -109,11 +109,13 @@ def test_analytics(tmp_path, server):
text=True, text=True,
) )
match = re.search(r".*Saving analytics report to (.*)", output, flags=re.M) match = re.search(r".*Saving analytics report to (.*)", output, flags=re.MULTILINE)
assert match, "no match for the report file" assert match, "no match for the report file"
report_file = match.group(1).strip() report_file = match.group(1).strip()
match = re.search(r".*Spawned .*analytics.* with pid (.*)", output, flags=re.M) match = re.search(
r".*Spawned .*analytics.* with pid (.*)", output, flags=re.MULTILINE
)
assert match, "no match for the pid" assert match, "no match for the pid"
pid = int(match.group(1).strip()) pid = int(match.group(1).strip())
@@ -148,7 +150,9 @@ def test_updater(tmp_dir, dvc, server):
text=True, text=True,
) )
match = re.search(r".*Spawned .*updater.* with pid (.*)", output, flags=re.M) match = re.search(
r".*Spawned .*updater.* with pid (.*)", output, flags=re.MULTILINE
)
assert match, "no match for the pid" assert match, "no match for the pid"
pid = int(match.group(1).strip()) pid = int(match.group(1).strip())