Skip to content

Commit

Permalink
update ruff to 0.1.15 (iterative#10263)
Browse files Browse the repository at this point in the history
update ruff
  • Loading branch information
skshetry authored Jan 30, 2024
1 parent 196c1c7 commit 4eb0738
Show file tree
Hide file tree
Showing 26 changed files with 85 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repos:
- id: sort-simple-yaml
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: 'v0.1.14'
rev: 'v0.1.15'
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
4 changes: 2 additions & 2 deletions dvc/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
from .show import metrics_show, params_show

__all__ = [
"DVCFileSystem",
"all_branches",
"all_commits",
"all_tags",
"artifacts_show",
"exp_save",
"exp_show",
"get_url",
"metrics_show",
"open",
"params_show",
"metrics_show",
"read",
"DVCFileSystem",
]
8 changes: 4 additions & 4 deletions dvc/commands/data.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, ClassVar, Dict, Tuple

from funcy import chunks, compact, log_durations

Expand All @@ -17,22 +17,22 @@


class CmdDataStatus(CmdBase):
COLORS = {
COLORS: ClassVar[Dict[str, str]] = {
"not_in_remote": "red",
"not_in_cache": "red",
"committed": "green",
"uncommitted": "yellow",
"untracked": "cyan",
}
LABELS = {
LABELS: ClassVar[Dict[str, str]] = {
"not_in_remote": "Not in remote",
"not_in_cache": "Not in cache",
"committed": "DVC committed changes",
"uncommitted": "DVC uncommitted changes",
"untracked": "Untracked files",
"unchanged": "DVC unchanged files",
}
HINTS = {
HINTS: ClassVar[Dict[str, Tuple[str, ...]]] = {
"not_in_remote": ('use "dvc push <file>..." to upload files',),
"not_in_cache": ('use "dvc fetch <file>..." to download files',),
"committed": ("git commit the corresponding dvc files to update the repo",),
Expand Down
5 changes: 3 additions & 2 deletions dvc/dependency/db.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from contextlib import contextmanager
from typing import TYPE_CHECKING, Any, Callable, Dict, Iterator, Optional
from typing import TYPE_CHECKING, Any, Callable, ClassVar, Dict, Iterator, Optional

from funcy import compact, log_durations

Expand Down Expand Up @@ -46,7 +46,7 @@ class DbDependency(AbstractDependency):
PARAM_QUERY = "query"
PARAM_TABLE = "table"
PARAM_FILE_FORMAT = "file_format"
DB_SCHEMA = {
DB_SCHEMA: ClassVar[Dict] = {
PARAM_DB: {
PARAM_QUERY: str,
PARAM_CONNECTION: str,
Expand Down Expand Up @@ -110,6 +110,7 @@ def download(
raise DvcException(f"connection {self.connection} not found in config")

file_format = file_format or self.db_info.get(self.PARAM_FILE_FORMAT, "csv")
assert file_format
with client(config) as db:
msg = "Testing connection"
with log_durations(logger.debug, msg), ui.status(msg) as status:
Expand Down
4 changes: 2 additions & 2 deletions dvc/dependency/repo.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from copy import deepcopy
from typing import TYPE_CHECKING, Any, Dict, Optional, Union
from typing import TYPE_CHECKING, Any, ClassVar, Dict, Optional, Union

import voluptuous as vol

Expand All @@ -20,7 +20,7 @@ class RepoDependency(Dependency):
PARAM_CONFIG = "config"
PARAM_REMOTE = "remote"

REPO_SCHEMA = {
REPO_SCHEMA: ClassVar[Dict] = {
PARAM_REPO: {
vol.Required(PARAM_URL): str,
PARAM_REV: str,
Expand Down
9 changes: 5 additions & 4 deletions dvc/dvcfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Dict,
List,
Optional,
Expand Down Expand Up @@ -181,10 +182,10 @@ class SingleStageFile(FileMixin):
from dvc.schema import COMPILED_SINGLE_STAGE_SCHEMA as SCHEMA
from dvc.stage.loader import SingleStageLoader as LOADER # noqa: N814

metrics: List[str] = []
plots: Any = {}
params: List[str] = []
artifacts: Dict[str, Optional[Dict[str, Any]]] = {}
metrics: ClassVar[List[str]] = []
plots: ClassVar[Any] = {}
params: ClassVar[List[str]] = []
artifacts: ClassVar[Dict[str, Optional[Dict[str, Any]]]] = {}

@property
def stage(self) -> "Stage":
Expand Down
3 changes: 2 additions & 1 deletion dvc/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import logging.handlers
import os
import sys
from typing import ClassVar, Dict

import colorama

Expand Down Expand Up @@ -78,7 +79,7 @@ class ColorFormatter(logging.Formatter):
"""

reset = colorama.Fore.RESET
color_codes = {
color_codes: ClassVar[Dict[str, str]] = {
"TRACE": colorama.Fore.GREEN,
"DEBUG": colorama.Fore.BLUE,
"WARNING": colorama.Fore.YELLOW,
Expand Down
2 changes: 1 addition & 1 deletion dvc/parsing/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def _track_data(self, node):
continue
params_file = self._tracked_data[source]
keys = [keys] if isinstance(keys, str) else keys
params_file.update({key: node.value for key in keys})
params_file.update(dict.fromkeys(keys, node.value))

def select(self, key: str, unwrap: bool = False):
"""Select the item using key, similar to `__getitem__`
Expand Down
4 changes: 2 additions & 2 deletions dvc/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
import sys
from threading import RLock
from typing import TYPE_CHECKING
from typing import TYPE_CHECKING, Any, ClassVar, Dict

from tqdm import tqdm

Expand Down Expand Up @@ -33,7 +33,7 @@ class Tqdm(tqdm):
" [{elapsed}<{remaining}, {rate_fmt:>11}]"
)
BAR_FMT_NOTOTAL = "{desc}{bar:b}|{postfix[info]}{n_fmt} [{elapsed}, {rate_fmt:>11}]"
BYTES_DEFAULTS = {
BYTES_DEFAULTS: ClassVar[Dict[str, Any]] = {
"unit": "B",
"unit_scale": True,
"unit_divisor": 1024,
Expand Down
4 changes: 2 additions & 2 deletions dvc/render/converter/vega.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def _verify_field(file2datapoints: Dict[str, List], filename: str, field: str):


def _get_xs(properties: Dict, file2datapoints: Dict[str, List[Dict]]):
x = properties.get("x", None)
x = properties.get("x")
if x is not None and isinstance(x, dict):
for filename, field in _file_field(x):
_verify_field(file2datapoints, filename, field)
Expand Down Expand Up @@ -255,7 +255,7 @@ def flat_datapoints(self, revision): # noqa: C901, PLR0912
x_file, x_field = xs[i]
datapoints = [{**d} for d in file2datapoints.get(y_file, [])]

if props_update.get("y", None) == "dvc_inferred_y_value":
if props_update.get("y") == "dvc_inferred_y_value":
_update_from_field(
datapoints,
field="dvc_inferred_y_value",
Expand Down
4 changes: 2 additions & 2 deletions dvc/repo/experiments/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def _build_rows(
**kwargs,
) -> Iterator[Tuple["CellT", ...]]:
for baseline in baseline_states:
row: Dict[str, "CellT"] = {k: fill_value for k in all_headers}
row: Dict[str, "CellT"] = dict.fromkeys(all_headers, fill_value)
row["Experiment"] = ""
if baseline.name:
row["rev"] = baseline.name
Expand Down Expand Up @@ -245,7 +245,7 @@ def _exp_range_rows(
logger.debug("Returning tip commit for legacy checkpoint exp")
exp = first(exp_range.revs)
if exp:
row: Dict[str, "CellT"] = {k: fill_value for k in all_headers}
row: Dict[str, "CellT"] = dict.fromkeys(all_headers, fill_value)
row["Experiment"] = exp.name or ""
row["rev"] = exp.rev[:7] if Git.is_sha(exp.rev) else exp.rev
row["typ"] = "branch_base" if is_base else "branch_commit"
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/params/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def _collect_params(
path = fs.from_os_path(param)
# make paths absolute for DVCFileSystem
repo_path = f"{fs.root_marker}{path}"
ret.update({file: _params for file in expand_paths(fs, [repo_path])})
ret.update(dict.fromkeys(expand_paths(fs, [repo_path]), _params))
return ret


Expand Down
6 changes: 3 additions & 3 deletions dvc/repo/reproduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _reproduce(
to_skip: Dict["Stage", "Stage"] = {}
ret: Optional["Stage"] = None

force_state = {node: force for node in stages}
force_state = dict.fromkeys(stages, force)

for stage in stages:
if stage in to_skip:
Expand All @@ -203,11 +203,11 @@ def _reproduce(
_raise_error(exc, stage)

dependents = handle_error(graph, on_error, exc, stage)
to_skip.update({node: stage for node in dependents})
to_skip.update(dict.fromkeys(dependents, stage))
continue

if force_downstream and (ret or force_stage):
force_state.update({node: True for node in downstream})
force_state.update(dict.fromkeys(downstream, True))

if ret:
result.append(ret)
Expand Down
24 changes: 12 additions & 12 deletions dvc/testing/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,29 @@
from .scripts import copy_script

__all__ = [
"make_tmp_dir",
"tmp_dir",
"scm",
"cloud",
"copy_script",
"docker_compose_project_name",
"docker_services",
"dvc",
"local_cloud",
"local_remote",
"local_workspace",
"make_cloud",
"make_cloud_version_aware",
"make_local",
"cloud",
"local_cloud",
"make_remote",
"make_remote_version_aware",
"make_remote_worktree",
"make_tmp_dir",
"make_workspace",
"remote",
"remote_version_aware",
"remote_worktree",
"local_remote",
"workspace",
"make_workspace",
"local_workspace",
"docker_compose_project_name",
"docker_services",
"copy_script",
"run_copy",
"scm",
"tmp_dir",
"workspace",
]

CACHE: Dict[Tuple[bool, bool, bool], str] = {}
Expand Down
9 changes: 7 additions & 2 deletions dvc/testing/path_info.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import pathlib
import posixpath
from typing import Callable
from typing import Callable, ClassVar, Dict
from urllib.parse import urlparse

from dvc.utils import relpath
Expand Down Expand Up @@ -120,7 +120,12 @@ def __repr__(self):


class URLInfo(_BasePath):
DEFAULT_PORTS = {"http": 80, "https": 443, "ssh": 22, "hdfs": 0}
DEFAULT_PORTS: ClassVar[Dict[str, int]] = {
"http": 80,
"https": 443,
"ssh": 22,
"hdfs": 0,
}

def __init__(self, url):
p = urlparse(url)
Expand Down
34 changes: 19 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ show_error_codes = true
show_error_context = true
show_traceback = true
strict_equality = true
strict_concatenate = true
extra_checks = true
warn_no_return = true
warn_redundant_casts = true
warn_unreachable = true
Expand Down Expand Up @@ -243,46 +243,50 @@ module = [
ignore-words-list = "ba,datas,fo,uptodate,cachable,falsy"

[tool.ruff]
show-source = true
show-fixes = true

[tool.ruff.lint]
ignore = [
"N818", "S101", "ISC001", "PT004", "PT007", "RET501", "RET502", "RET503", "SIM105", "SIM108",
"SIM117", "TRY003", "TRY200", "TRY300", "PLR2004", "PLW2901", "RUF012"
"SIM117", "TRY003", "TRY200", "TRY300", "PLR2004", "PLW2901",
]
select = [
"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",
"FLY", "PERF101", "RUF", "RUF018", "RUF019", "RUF022", "RUF023", "RUF025",
]
show-source = true
show-fixes = true
preview = true
explicit-preview-rules = true

[tool.ruff.flake8-pytest-style]
[tool.ruff.lint.flake8-pytest-style]
fixture-parentheses = false
mark-parentheses = false
parametrize-names-type = "csv"
raises-extend-require-match-for = ["dvc.exceptions.DvcException", "dvc.scm.SCMError", "scmrepo.exceptions.SCMError"]

[tool.ruff.flake8-tidy-imports]
[tool.ruff.flake8-tidy-imports.banned-api]
[tool.ruff.lint.flake8-tidy-imports]
[tool.ruff.lint.flake8-tidy-imports.banned-api]
"funcy.cached_property" = {msg = "use `from dvc.utils.objects import cached_property` instead."}

[tool.ruff.flake8-type-checking]
[tool.ruff.lint.flake8-type-checking]
strict = true

[tool.ruff.flake8-unused-arguments]
[tool.ruff.lint.flake8-unused-arguments]
ignore-variadic-names = true

[tool.ruff.isort]
[tool.ruff.lint.isort]
known-first-party = ["dvc", "dvc_data", "dvc_objects", "dvc_render", "dvc_task", "tests"]

[tool.ruff.pep8-naming]
[tool.ruff.lint.pep8-naming]
extend-ignore-names = ["M", "SCM"]

[tool.ruff.lint.pylint]
max-args = 10

[tool.ruff.per-file-ignores]
"dvc/commands/**" = ["N806"]
"dvc/testing/**" = ["ARG002"]
"dvc/testing/benchmarks/**" = ["ARG001"]
"tests/**" = ["S", "ARG001", "ARG002", "TRY002", "TRY301"]

[tool.ruff.pylint]
max-args = 10
4 changes: 2 additions & 2 deletions tests/dir_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@
import pytest

__all__ = [
"run_head",
"erepo_dir",
"git_dir",
"git_upstream",
"git_downstream",
"git_upstream",
"run_head",
]


Expand Down
2 changes: 1 addition & 1 deletion tests/func/repro/test_repro.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ def test_repro_allow_missing(tmp_dir, dvc):
tmp_dir.gen("fixed", "fixed")
dvc.stage.add(name="create-foo", cmd="echo foo > foo", deps=["fixed"], outs=["foo"])
dvc.stage.add(name="copy-foo", cmd="cp foo bar", deps=["foo"], outs=["bar"])
(create_foo, copy_foo) = dvc.reproduce()
(create_foo, _) = dvc.reproduce()

remove("foo")
remove(create_foo.outs[0].cache_path)
Expand Down
Loading

0 comments on commit 4eb0738

Please sign in to comment.