mirror of
https://github.com/Stone-Red-Code/dvc.git
synced 2026-11-10 15:28:34 +01:00
bump ruff to v0.0.247 (#9050)
* bump ruff to v0.0.247 * ruff: enable pep8-naming check rename some camelCased APIs, especially in logger rename G variables to graph ignore some variable namings and help messages in dvc.commands
This commit is contained in:
@@ -43,7 +43,7 @@ repos:
|
||||
hooks:
|
||||
- id: isort
|
||||
- repo: https://github.com/charliermarsh/ruff-pre-commit
|
||||
rev: 'v0.0.238'
|
||||
rev: 'v0.0.247'
|
||||
hooks:
|
||||
- id: ruff
|
||||
- repo: https://github.com/codespell-project/codespell
|
||||
|
||||
+3
-3
@@ -146,7 +146,7 @@ def _log_exceptions(exc: Exception) -> Optional[int]:
|
||||
return None
|
||||
|
||||
|
||||
def main(argv=None): # noqa: C901
|
||||
def main(argv=None): # noqa: C901, PLR0912, PLR0915
|
||||
"""Main entry point for dvc CLI.
|
||||
|
||||
Args:
|
||||
@@ -172,7 +172,7 @@ def main(argv=None): # noqa: C901
|
||||
|
||||
args = None
|
||||
|
||||
outerLogLevel = logger.level
|
||||
outer_log_level = logger.level
|
||||
try:
|
||||
args = parse_args(argv)
|
||||
|
||||
@@ -243,7 +243,7 @@ def main(argv=None): # noqa: C901
|
||||
|
||||
return ret
|
||||
finally:
|
||||
logger.setLevel(outerLogLevel)
|
||||
logger.setLevel(outer_log_level)
|
||||
|
||||
from dvc.external_repo import clean_repos
|
||||
|
||||
|
||||
+23
-24
@@ -9,11 +9,11 @@ if TYPE_CHECKING:
|
||||
from networkx import DiGraph
|
||||
|
||||
|
||||
def _show_ascii(G: "DiGraph"):
|
||||
def _show_ascii(graph: "DiGraph"):
|
||||
from dvc.dagascii import draw
|
||||
from dvc.repo.graph import get_pipelines
|
||||
|
||||
pipelines = get_pipelines(G)
|
||||
pipelines = get_pipelines(graph)
|
||||
|
||||
ret = []
|
||||
for pipeline in pipelines:
|
||||
@@ -31,7 +31,7 @@ def _quote_label(node):
|
||||
return label
|
||||
|
||||
|
||||
def _show_dot(G: "DiGraph"):
|
||||
def _show_dot(graph: "DiGraph"):
|
||||
import io
|
||||
|
||||
import networkx as nx
|
||||
@@ -39,15 +39,15 @@ def _show_dot(G: "DiGraph"):
|
||||
|
||||
dot_file = io.StringIO()
|
||||
|
||||
nx.relabel_nodes(G, _quote_label, copy=False)
|
||||
write_dot(G.reverse(), dot_file)
|
||||
nx.relabel_nodes(graph, _quote_label, copy=False)
|
||||
write_dot(graph.reverse(), dot_file)
|
||||
return dot_file.getvalue()
|
||||
|
||||
|
||||
def _show_mermaid(G, markdown: bool = False):
|
||||
def _show_mermaid(graph, markdown: bool = False):
|
||||
from dvc.repo.graph import get_pipelines
|
||||
|
||||
pipelines = get_pipelines(G)
|
||||
pipelines = get_pipelines(graph)
|
||||
|
||||
graph = "flowchart TD"
|
||||
|
||||
@@ -100,43 +100,42 @@ def _transform(index, outs):
|
||||
def _relabel(node) -> str:
|
||||
return node.addressing if isinstance(node, Stage) else str(node)
|
||||
|
||||
G = index.outs_graph if outs else index.graph
|
||||
return nx.relabel_nodes(G, _relabel, copy=True)
|
||||
graph = index.outs_graph if outs else index.graph
|
||||
return nx.relabel_nodes(graph, _relabel, copy=True)
|
||||
|
||||
|
||||
def _filter(G, targets, full):
|
||||
def _filter(graph, targets, full):
|
||||
import networkx as nx
|
||||
|
||||
if not targets:
|
||||
return G
|
||||
return graph
|
||||
|
||||
H = G.copy()
|
||||
new_graph = graph.copy()
|
||||
if not full:
|
||||
descendants = set()
|
||||
for target in targets:
|
||||
descendants.update(nx.descendants(G, target))
|
||||
descendants.update(nx.descendants(graph, target))
|
||||
descendants.add(target)
|
||||
H.remove_nodes_from(set(G.nodes()) - descendants)
|
||||
new_graph.remove_nodes_from(set(graph.nodes()) - descendants)
|
||||
|
||||
undirected = H.to_undirected()
|
||||
undirected = new_graph.to_undirected()
|
||||
connected = set()
|
||||
for target in targets:
|
||||
connected.update(nx.node_connected_component(undirected, target))
|
||||
|
||||
H.remove_nodes_from(set(H.nodes()) - connected)
|
||||
|
||||
return H
|
||||
new_graph.remove_nodes_from(set(new_graph.nodes()) - connected)
|
||||
return new_graph
|
||||
|
||||
|
||||
def _build(repo, target=None, full=False, outs=False):
|
||||
targets = _collect_targets(repo, target, outs)
|
||||
G = _transform(repo.index, outs)
|
||||
return _filter(G, targets, full)
|
||||
graph = _transform(repo.index, outs)
|
||||
return _filter(graph, targets, full)
|
||||
|
||||
|
||||
class CmdDAG(CmdBase):
|
||||
def run(self):
|
||||
G = _build(
|
||||
graph = _build(
|
||||
self.repo,
|
||||
target=self.args.target,
|
||||
full=self.args.full,
|
||||
@@ -144,12 +143,12 @@ class CmdDAG(CmdBase):
|
||||
)
|
||||
|
||||
if self.args.dot:
|
||||
ui.write(_show_dot(G))
|
||||
ui.write(_show_dot(graph))
|
||||
elif self.args.mermaid or self.args.markdown:
|
||||
ui.write(_show_mermaid(G, self.args.markdown))
|
||||
ui.write(_show_mermaid(graph, self.args.markdown))
|
||||
else:
|
||||
with ui.pager():
|
||||
ui.write(_show_ascii(G))
|
||||
ui.write(_show_ascii(graph))
|
||||
|
||||
return 0
|
||||
|
||||
|
||||
@@ -62,7 +62,7 @@ experiment_types = {
|
||||
}
|
||||
|
||||
|
||||
def _collect_rows( # noqa: C901
|
||||
def _collect_rows( # noqa: C901, PLR0912, PLR0913, PLR0915
|
||||
base_rev,
|
||||
experiments,
|
||||
all_headers,
|
||||
@@ -244,7 +244,7 @@ def _extend_row(row, names, headers, items, precision, fill_value=FILL_VALUE):
|
||||
row[f"{fname}:{name}"] = value
|
||||
|
||||
|
||||
def experiments_table(
|
||||
def experiments_table( # noqa: PLR0913
|
||||
all_experiments,
|
||||
headers,
|
||||
metric_headers,
|
||||
@@ -308,7 +308,7 @@ def baseline_styler(typ):
|
||||
return {"style": "bold"} if typ == "baseline" else {}
|
||||
|
||||
|
||||
def show_experiments( # noqa: C901
|
||||
def show_experiments( # noqa: C901, PLR0912
|
||||
all_experiments,
|
||||
keep=None,
|
||||
drop=None,
|
||||
|
||||
@@ -302,7 +302,7 @@ class CmdMachineSsh(CmdBase):
|
||||
return 0
|
||||
|
||||
|
||||
def add_parser(subparsers, parent_parser):
|
||||
def add_parser(subparsers, parent_parser): # noqa: PLR0915
|
||||
from dvc.commands.config import parent_config_parser
|
||||
|
||||
machine_HELP = "Set up and manage cloud machines."
|
||||
|
||||
@@ -91,7 +91,7 @@ class CmdPlots(CmdBase):
|
||||
html_template_path = os.path.join(self.repo.dvc_dir, html_template_path)
|
||||
return html_template_path # noqa: RET504
|
||||
|
||||
def run(self) -> int: # noqa: C901
|
||||
def run(self) -> int: # noqa: C901, PLR0911, PLR0912
|
||||
from pathlib import Path
|
||||
|
||||
from dvc.render.match import match_defs_renderers
|
||||
|
||||
+2
-2
@@ -209,7 +209,7 @@ class TabularData(MutableSequence[Sequence["CellT"]]):
|
||||
keys = self.keys() if cols is None else set(cols)
|
||||
return [{k: self._columns[k][i] for k in keys} for i in range(len(self))]
|
||||
|
||||
def dropna( # noqa: C901
|
||||
def dropna( # noqa: C901, PLR0912
|
||||
self,
|
||||
axis: str = "rows",
|
||||
how="any",
|
||||
@@ -371,7 +371,7 @@ def diff_table(
|
||||
return td
|
||||
|
||||
|
||||
def show_diff(
|
||||
def show_diff( # noqa: PLR0913
|
||||
diff,
|
||||
title: str,
|
||||
old: bool = True,
|
||||
|
||||
@@ -30,7 +30,7 @@ def supported_cache_type(types):
|
||||
return types
|
||||
|
||||
|
||||
def Choices(*choices):
|
||||
def Choices(*choices): # noqa: N802
|
||||
"""Checks that value belongs to the specified set of values
|
||||
|
||||
Args:
|
||||
@@ -40,7 +40,7 @@ def Choices(*choices):
|
||||
return Any(*choices, msg="expected one of {}".format(", ".join(choices)))
|
||||
|
||||
|
||||
def ByUrl(mapping):
|
||||
def ByUrl(mapping): # noqa: N802
|
||||
schemas = walk_values(Schema, mapping)
|
||||
|
||||
def validate(data):
|
||||
|
||||
+3
-3
@@ -80,7 +80,7 @@ class AsciiCanvas:
|
||||
|
||||
self.canvas[y][x] = char
|
||||
|
||||
def line(self, x0, y0, x1, y1, char): # noqa: C901
|
||||
def line(self, x0, y0, x1, y1, char): # noqa: C901, PLR0912
|
||||
"""Create a line on ASCII canvas.
|
||||
|
||||
Args:
|
||||
@@ -213,8 +213,8 @@ def draw(vertices, edges):
|
||||
# pylint: disable=too-many-locals
|
||||
# NOTE: coordinates might me negative, so we need to shift
|
||||
# everything to the positive plane before we actually draw it.
|
||||
Xs = [] # pylint: disable=invalid-name
|
||||
Ys = [] # pylint: disable=invalid-name
|
||||
Xs = [] # noqa: N806, pylint: disable=invalid-name
|
||||
Ys = [] # noqa: N806, pylint: disable=invalid-name
|
||||
|
||||
sug = _build_sugiyama_layout(vertices, edges)
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ class RepoDependency(Dependency):
|
||||
self._check_circular_import(odb, obj_ids)
|
||||
used_obj_ids[odb].update(obj_ids)
|
||||
except (NoRemoteError, NoOutputOrStageError):
|
||||
pass # noqa: S110
|
||||
pass
|
||||
|
||||
try:
|
||||
object_store, meta, obj = build(
|
||||
|
||||
+2
-2
@@ -187,7 +187,7 @@ class FileMixin:
|
||||
|
||||
class SingleStageFile(FileMixin):
|
||||
from dvc.schema import COMPILED_SINGLE_STAGE_SCHEMA as SCHEMA
|
||||
from dvc.stage.loader import SingleStageLoader as LOADER
|
||||
from dvc.stage.loader import SingleStageLoader as LOADER # noqa: N814
|
||||
|
||||
metrics: List[str] = []
|
||||
plots: Any = {}
|
||||
@@ -231,7 +231,7 @@ class ProjectFile(FileMixin):
|
||||
"""Abstraction for pipelines file, .yaml + .lock combined."""
|
||||
|
||||
from dvc.schema import COMPILED_MULTI_STAGE_SCHEMA as SCHEMA
|
||||
from dvc.stage.loader import StageLoader as LOADER
|
||||
from dvc.stage.loader import StageLoader as LOADER # noqa: N814
|
||||
|
||||
@property
|
||||
def _lockfile(self):
|
||||
|
||||
@@ -189,7 +189,7 @@ def _cached_clone(url, rev, for_write=False):
|
||||
|
||||
|
||||
@wrap_with(threading.Lock())
|
||||
def _clone_default_branch(url, rev, for_write=False): # noqa: C901
|
||||
def _clone_default_branch(url, rev, for_write=False): # noqa: C901, PLR0912
|
||||
"""Get or create a clean clone of the url.
|
||||
|
||||
The cloned is reactualized with git pull unless rev is a known sha.
|
||||
|
||||
+1
-1
@@ -6,7 +6,6 @@ from dvc.config import ConfigError as RepoConfigError
|
||||
from dvc.config_schema import SCHEMA, Invalid
|
||||
|
||||
# pylint: disable=unused-import
|
||||
from dvc_objects.fs import utils # noqa: F401
|
||||
from dvc_objects.fs import ( # noqa: F401
|
||||
LocalFileSystem,
|
||||
MemoryFileSystem,
|
||||
@@ -17,6 +16,7 @@ from dvc_objects.fs import ( # noqa: F401
|
||||
localfs,
|
||||
registry,
|
||||
system,
|
||||
utils,
|
||||
)
|
||||
from dvc_objects.fs.base import AnyFSPath, FileSystem # noqa: F401
|
||||
from dvc_objects.fs.errors import ( # noqa: F401
|
||||
|
||||
+4
-2
@@ -289,7 +289,7 @@ class _DVCFileSystem(AbstractFileSystem): # pylint:disable=abstract-method
|
||||
):
|
||||
fs_infos[fs.path.name(info["name"])] = info
|
||||
except (FileNotFoundError, NotADirectoryError):
|
||||
pass # noqa: S110
|
||||
pass
|
||||
|
||||
dvcfiles = kwargs.get("dvcfiles", False)
|
||||
|
||||
@@ -316,7 +316,9 @@ class _DVCFileSystem(AbstractFileSystem): # pylint:disable=abstract-method
|
||||
ignore_subrepos = kwargs.get("ignore_subrepos", True)
|
||||
return self._info(key, path, ignore_subrepos=ignore_subrepos)
|
||||
|
||||
def _info(self, key, path, ignore_subrepos=True, check_ignored=True): # noqa: C901
|
||||
def _info( # noqa: C901, PLR0912
|
||||
self, key, path, ignore_subrepos=True, check_ignored=True
|
||||
):
|
||||
repo, dvc_fs, subkey = self._get_subrepo_info(key)
|
||||
|
||||
dvc_info = None
|
||||
|
||||
+24
-24
@@ -10,46 +10,46 @@ import colorama
|
||||
from dvc.progress import Tqdm
|
||||
|
||||
|
||||
def addLoggingLevel(levelName, levelNum, methodName=None):
|
||||
def add_logging_level(level_name, level_num, method_name=None):
|
||||
"""
|
||||
Adds a new logging level to the `logging` module and the
|
||||
currently configured logging class.
|
||||
|
||||
Uses the existing numeric levelNum if already defined.
|
||||
Uses the existing numeric level_num if already defined.
|
||||
|
||||
Based on https://stackoverflow.com/questions/2183233
|
||||
"""
|
||||
if methodName is None:
|
||||
methodName = levelName.lower()
|
||||
if method_name is None:
|
||||
method_name = level_name.lower()
|
||||
|
||||
# If the level name is already defined as a top-level `logging`
|
||||
# constant, then adopt the existing numeric level.
|
||||
if hasattr(logging, levelName):
|
||||
existingLevelNum = getattr(logging, levelName)
|
||||
assert isinstance(existingLevelNum, int)
|
||||
levelNum = existingLevelNum
|
||||
if hasattr(logging, level_name):
|
||||
existing_level_num = getattr(logging, level_name)
|
||||
assert isinstance(existing_level_num, int)
|
||||
level_num = existing_level_num
|
||||
|
||||
def logForLevel(self, message, *args, **kwargs):
|
||||
if self.isEnabledFor(levelNum):
|
||||
def log_for_level(self, message, *args, **kwargs):
|
||||
if self.isEnabledFor(level_num):
|
||||
# pylint: disable=protected-access
|
||||
self._log(levelNum, message, args, **kwargs)
|
||||
self._log(level_num, message, args, **kwargs)
|
||||
|
||||
def logToRoot(message, *args, **kwargs):
|
||||
logging.log(levelNum, message, *args, **kwargs)
|
||||
def log_to_root(message, *args, **kwargs):
|
||||
logging.log(level_num, message, *args, **kwargs)
|
||||
|
||||
# getLevelName resolves the numeric log level if already defined,
|
||||
# otherwise returns a string
|
||||
if not isinstance(logging.getLevelName(levelName), int):
|
||||
logging.addLevelName(levelNum, levelName)
|
||||
if not isinstance(logging.getLevelName(level_name), int):
|
||||
logging.addLevelName(level_num, level_name)
|
||||
|
||||
if not hasattr(logging, levelName):
|
||||
setattr(logging, levelName, levelNum)
|
||||
if not hasattr(logging, level_name):
|
||||
setattr(logging, level_name, level_num)
|
||||
|
||||
if not hasattr(logging.getLoggerClass(), methodName):
|
||||
setattr(logging.getLoggerClass(), methodName, logForLevel)
|
||||
if not hasattr(logging.getLoggerClass(), method_name):
|
||||
setattr(logging.getLoggerClass(), method_name, log_for_level)
|
||||
|
||||
if not hasattr(logging, methodName):
|
||||
setattr(logging, methodName, logToRoot)
|
||||
if not hasattr(logging, method_name):
|
||||
setattr(logging, method_name, log_to_root)
|
||||
|
||||
|
||||
class LoggingException(Exception):
|
||||
@@ -129,7 +129,7 @@ class ColorFormatter(logging.Formatter):
|
||||
|
||||
|
||||
class LoggerHandler(logging.StreamHandler):
|
||||
def handleError(self, record):
|
||||
def handleError(self, record): # noqa: N802
|
||||
super().handleError(record)
|
||||
raise LoggingException(record)
|
||||
|
||||
@@ -147,7 +147,7 @@ class LoggerHandler(logging.StreamHandler):
|
||||
if not _is_verbose():
|
||||
return
|
||||
except Exception: # noqa, pylint: disable=broad-except
|
||||
pass # noqa: S110
|
||||
pass
|
||||
|
||||
msg = self.format(record)
|
||||
Tqdm.write(msg, file=self.stream, end=getattr(self, "terminator", "\n"))
|
||||
@@ -190,7 +190,7 @@ def setup(level: int = logging.INFO, log_colors: bool = True) -> None:
|
||||
console_debug.setFormatter(formatter)
|
||||
console_debug.addFilter(exclude_filter(logging.INFO))
|
||||
|
||||
addLoggingLevel("TRACE", logging.DEBUG - 5)
|
||||
add_logging_level("TRACE", logging.DEBUG - 5)
|
||||
|
||||
console_trace = LoggerHandler(sys.stdout)
|
||||
console_trace.setLevel(logging.TRACE) # type: ignore[attr-defined]
|
||||
|
||||
+3
-3
@@ -312,7 +312,7 @@ class Output:
|
||||
IsStageFileError: Type[DvcException] = OutputIsStageFileError
|
||||
IsIgnoredError: Type[DvcException] = OutputIsIgnoredError
|
||||
|
||||
def __init__(
|
||||
def __init__( # noqa: PLR0913
|
||||
self,
|
||||
stage,
|
||||
path,
|
||||
@@ -768,7 +768,7 @@ class Output:
|
||||
)
|
||||
return checkout_obj
|
||||
|
||||
def dumpd(self, **kwargs): # noqa: C901
|
||||
def dumpd(self, **kwargs): # noqa: C901, PLR0912
|
||||
ret: Dict[str, Any] = {}
|
||||
with_files = (
|
||||
(not self.IS_DEPENDENCY or self.stage.is_import)
|
||||
@@ -1059,7 +1059,7 @@ class Output:
|
||||
return obj.filter(prefix)
|
||||
return cast(Tree, obj)
|
||||
|
||||
def get_used_objs( # noqa: C901
|
||||
def get_used_objs( # noqa: C901, PLR0911
|
||||
self, **kwargs
|
||||
) -> Dict[Optional["ObjectDB"], Set["HashInfo"]]:
|
||||
"""Return filtered set of used object IDs for this out."""
|
||||
|
||||
@@ -155,7 +155,7 @@ class Value(Node):
|
||||
PRIMITIVES = (int, float, str, bytes, bool)
|
||||
|
||||
|
||||
class Container(Node, ABC): # noqa: B024
|
||||
class Container(Node, ABC):
|
||||
meta: Meta
|
||||
data: Union[list, dict]
|
||||
_key_transform = staticmethod(identity)
|
||||
|
||||
@@ -19,7 +19,7 @@ class VersionEnum(str, enum.Enum):
|
||||
return [v.value for v in cls]
|
||||
|
||||
|
||||
class LOCKFILE_VERSION(VersionEnum):
|
||||
class LOCKFILE_VERSION(VersionEnum): # noqa: N801
|
||||
V1 = "1.0"
|
||||
V2 = "2.0"
|
||||
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ class Tqdm(tqdm):
|
||||
"miniters": 1,
|
||||
}
|
||||
|
||||
def __init__(
|
||||
def __init__( # noqa: PLR0913
|
||||
self,
|
||||
iterable=None,
|
||||
disable=None,
|
||||
|
||||
@@ -193,7 +193,7 @@ class VegaConverter(Converter):
|
||||
return first(fields)
|
||||
return "x"
|
||||
|
||||
def flat_datapoints(self, revision): # noqa: C901
|
||||
def flat_datapoints(self, revision): # noqa: C901, PLR0912
|
||||
file2datapoints, properties = self.convert()
|
||||
|
||||
props_update = {}
|
||||
|
||||
@@ -149,7 +149,7 @@ class Repo:
|
||||
self.fs.makedirs(db_dir, exist_ok=True)
|
||||
return db_dir
|
||||
|
||||
def __init__(
|
||||
def __init__( # noqa: PLR0915
|
||||
self,
|
||||
root_dir: Optional[str] = None,
|
||||
fs: Optional["FileSystem"] = None,
|
||||
@@ -453,7 +453,7 @@ class Repo:
|
||||
|
||||
return brancher(self, *args, **kwargs)
|
||||
|
||||
def used_objs(
|
||||
def used_objs( # noqa: PLR0913
|
||||
self,
|
||||
targets=None,
|
||||
all_branches=False,
|
||||
|
||||
+1
-1
@@ -148,7 +148,7 @@ VALIDATORS = (
|
||||
@validate(*VALIDATORS)
|
||||
@locked
|
||||
@scm_context
|
||||
def add( # noqa: C901
|
||||
def add(
|
||||
repo: "Repo",
|
||||
targets: "TargetType",
|
||||
recursive: bool = False,
|
||||
|
||||
@@ -407,7 +407,7 @@ class Experiments:
|
||||
try:
|
||||
name = ExpRefInfo.from_ref(ref).name
|
||||
except InvalidExpRefError:
|
||||
pass # noqa: S110
|
||||
pass
|
||||
if not name:
|
||||
if rev in self.stash_revs:
|
||||
name = self.stash_revs[rev].name
|
||||
|
||||
@@ -49,7 +49,7 @@ def apply(repo: "Repo", rev: str, force: bool = True, **kwargs): # noqa: C901
|
||||
exp_rev = repo.scm.get_ref(str(exp_ref_info))
|
||||
elif queue_entry:
|
||||
if queue_entry.baseline_rev != baseline_sha:
|
||||
raise InvalidExpRevError(rev)
|
||||
raise InvalidExpRevError(rev) # noqa: B904
|
||||
exp_rev = queue_entry.stash_rev
|
||||
is_stash = True
|
||||
else:
|
||||
|
||||
@@ -21,9 +21,9 @@ from dvc.exceptions import DvcException
|
||||
from dvc.stage import PipelineStage
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from dvc.dependency import Dependency
|
||||
from dvc.dvcfile import ProjectFile, SingleStageFile
|
||||
from dvc.repo import Repo
|
||||
from dvc.dependency import Dependency
|
||||
|
||||
from dvc.ui import ui
|
||||
|
||||
|
||||
@@ -295,7 +295,7 @@ class BaseStashQueue(ABC):
|
||||
output.
|
||||
"""
|
||||
|
||||
def _stash_exp( # noqa: C901
|
||||
def _stash_exp( # noqa: PLR0915, C901
|
||||
self,
|
||||
*args,
|
||||
params: Optional[Dict[str, List[str]]] = None,
|
||||
|
||||
@@ -9,7 +9,7 @@ if TYPE_CHECKING:
|
||||
from dvc.repo.experiments.stash import ExpStashEntry
|
||||
|
||||
|
||||
def remove_tasks( # noqa: C901
|
||||
def remove_tasks( # noqa: C901, PLR0912
|
||||
celery_queue: "LocalCeleryQueue",
|
||||
queue_entries: Iterable["QueueEntry"],
|
||||
):
|
||||
|
||||
@@ -383,7 +383,7 @@ def move_properties_to_head(result: Dict[str, Dict[str, Dict[str, Any]]]):
|
||||
checkpoint = True
|
||||
|
||||
|
||||
def show(
|
||||
def show( # noqa: PLR0913
|
||||
repo: "Repo",
|
||||
all_branches=False,
|
||||
all_tags=False,
|
||||
|
||||
File diff suppressed because one or more lines are too long
+1
-1
@@ -19,7 +19,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@locked
|
||||
def fetch( # noqa: C901
|
||||
def fetch( # noqa: C901, PLR0913
|
||||
self,
|
||||
targets=None,
|
||||
jobs=None,
|
||||
|
||||
+1
-1
@@ -23,7 +23,7 @@ def _validate_args(**kwargs):
|
||||
|
||||
|
||||
@locked
|
||||
def gc(
|
||||
def gc( # noqa: PLR0913
|
||||
self: "Repo",
|
||||
all_branches: bool = False,
|
||||
cloud: bool = False,
|
||||
|
||||
+11
-11
@@ -33,10 +33,10 @@ def get_pipeline(pipelines, node):
|
||||
return found[0]
|
||||
|
||||
|
||||
def get_pipelines(G: "DiGraph"):
|
||||
def get_pipelines(graph: "DiGraph"):
|
||||
import networkx as nx
|
||||
|
||||
return [G.subgraph(c).copy() for c in nx.weakly_connected_components(G)]
|
||||
return [graph.subgraph(c).copy() for c in nx.weakly_connected_components(graph)]
|
||||
|
||||
|
||||
def collect_pipeline(stage: "Stage", graph: "DiGraph") -> Iterator["Stage"]:
|
||||
@@ -97,7 +97,7 @@ def build_graph(stages, outs_trie=None):
|
||||
|
||||
from .trie import build_outs_trie
|
||||
|
||||
G = nx.DiGraph()
|
||||
graph = nx.DiGraph()
|
||||
|
||||
# Use trie to efficiently find overlapping outs and deps
|
||||
outs_trie = outs_trie or build_outs_trie(stages)
|
||||
@@ -108,7 +108,7 @@ def build_graph(stages, outs_trie=None):
|
||||
raise StagePathAsOutputError(stage, str(out))
|
||||
|
||||
# Building graph
|
||||
G.add_nodes_from(stages)
|
||||
graph.add_nodes_from(stages)
|
||||
for stage in stages:
|
||||
for dep in stage.deps:
|
||||
if dep.fs_path is None:
|
||||
@@ -119,10 +119,10 @@ def build_graph(stages, outs_trie=None):
|
||||
if outs_trie.has_subtrie(dep_key):
|
||||
overlapping.extend(outs_trie.values(prefix=dep_key))
|
||||
|
||||
G.add_edges_from((stage, out.stage) for out in overlapping)
|
||||
check_acyclic(G)
|
||||
graph.add_edges_from((stage, out.stage) for out in overlapping)
|
||||
check_acyclic(graph)
|
||||
|
||||
return G
|
||||
return graph
|
||||
|
||||
|
||||
# NOTE: using stage graph instead of just list of stages to make sure that it
|
||||
@@ -131,9 +131,9 @@ def build_graph(stages, outs_trie=None):
|
||||
def build_outs_graph(graph, outs_trie):
|
||||
import networkx as nx
|
||||
|
||||
G = nx.DiGraph()
|
||||
outs_graph = nx.DiGraph()
|
||||
|
||||
G.add_nodes_from(outs_trie.values())
|
||||
outs_graph.add_nodes_from(outs_trie.values())
|
||||
for stage in graph.nodes():
|
||||
for dep in stage.deps:
|
||||
if dep.fs_path is None:
|
||||
@@ -145,5 +145,5 @@ def build_outs_graph(graph, outs_trie):
|
||||
overlapping.extend(outs_trie.values(prefix=dep_key))
|
||||
|
||||
for from_out in stage.outs:
|
||||
G.add_edges_from((from_out, out) for out in overlapping)
|
||||
return G
|
||||
outs_graph.add_edges_from((from_out, out) for out in overlapping)
|
||||
return outs_graph
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ from . import locked
|
||||
|
||||
@locked
|
||||
@scm_context
|
||||
def imp_url( # noqa: C901
|
||||
def imp_url( # noqa: C901, PLR0913
|
||||
self: "Repo",
|
||||
url,
|
||||
out=None,
|
||||
|
||||
@@ -143,7 +143,7 @@ def show(
|
||||
except (SCMError, NoSCMError):
|
||||
# SCMError - detached head
|
||||
# NoSCMError - no repo case
|
||||
pass # noqa: S110
|
||||
pass
|
||||
else:
|
||||
if res.get("workspace") == res.get(active_branch):
|
||||
res.pop("workspace", None)
|
||||
|
||||
+3
-3
@@ -32,11 +32,11 @@ def move(self, from_path, to_path):
|
||||
It only works with outputs generated by `add` or `import`,
|
||||
also known as data sources.
|
||||
"""
|
||||
import dvc.output as Output
|
||||
from dvc import output
|
||||
from dvc.dvcfile import DVC_FILE_SUFFIX
|
||||
from dvc.stage import Stage
|
||||
|
||||
from_out = Output.loads_from(Stage(self), [from_path])[0]
|
||||
from_out = output.loads_from(Stage(self), [from_path])[0]
|
||||
assert from_out.protocol == "local"
|
||||
|
||||
to_path = _expand_target_path(from_path, to_path)
|
||||
@@ -71,7 +71,7 @@ def move(self, from_path, to_path):
|
||||
else:
|
||||
to_path = os.path.relpath(to_path, stage.wdir)
|
||||
|
||||
to_out = Output.loads_from(stage, [to_path], out.use_cache, out.metric)[0]
|
||||
to_out = output.loads_from(stage, [to_path], out.use_cache, out.metric)[0]
|
||||
|
||||
out.move(to_out)
|
||||
stage.save()
|
||||
|
||||
@@ -153,7 +153,7 @@ def show(
|
||||
except (SCMError, NoSCMError):
|
||||
# SCMError - detached head
|
||||
# NoSCMError - no repo case
|
||||
pass # noqa: S110
|
||||
pass
|
||||
else:
|
||||
if res.get("workspace") == res.get(active_branch):
|
||||
res.pop("workspace", None)
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@locked
|
||||
def pull(
|
||||
def pull( # noqa: PLR0913
|
||||
self,
|
||||
targets=None,
|
||||
jobs=None,
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ if TYPE_CHECKING:
|
||||
|
||||
|
||||
@locked
|
||||
def push( # noqa: C901
|
||||
def push( # noqa: C901, PLR0913
|
||||
self,
|
||||
targets=None,
|
||||
jobs=None,
|
||||
|
||||
@@ -129,7 +129,7 @@ def reproduce( # noqa: C901
|
||||
|
||||
|
||||
def _reproduce_stages( # noqa: C901
|
||||
G, stages, downstream=False, single_item=False, on_unchanged=None, **kwargs
|
||||
graph, stages, downstream=False, single_item=False, on_unchanged=None, **kwargs
|
||||
):
|
||||
r"""Derive the evaluation of the given node for the given graph.
|
||||
|
||||
@@ -166,7 +166,7 @@ def _reproduce_stages( # noqa: C901
|
||||
|
||||
The derived evaluation of _downstream_ B would be: [B, D, E]
|
||||
"""
|
||||
steps = _get_steps(G, stages, downstream, single_item)
|
||||
steps = _get_steps(graph, stages, downstream, single_item)
|
||||
|
||||
force_downstream = kwargs.pop("force_downstream", False)
|
||||
result = []
|
||||
@@ -222,16 +222,16 @@ def _reproduce_stages( # noqa: C901
|
||||
return result
|
||||
|
||||
|
||||
def _get_steps(G, stages, downstream, single_item):
|
||||
def _get_steps(graph, stages, downstream, single_item):
|
||||
import networkx as nx
|
||||
|
||||
active = G.copy()
|
||||
active = graph.copy()
|
||||
if not single_item:
|
||||
# NOTE: frozen stages don't matter for single_item
|
||||
for stage in G:
|
||||
for stage in graph:
|
||||
if stage.frozen:
|
||||
# NOTE: disconnect frozen stage from its dependencies
|
||||
active.remove_edges_from(G.out_edges(stage))
|
||||
active.remove_edges_from(graph.out_edges(stage))
|
||||
|
||||
all_pipelines: List["Stage"] = []
|
||||
for stage in stages:
|
||||
|
||||
+1
-1
@@ -74,7 +74,7 @@ def _infos_to_str(infos):
|
||||
)
|
||||
|
||||
|
||||
def _check_blockers(tmp_dir, lock, info, *, mode, waiters): # noqa: C901
|
||||
def _check_blockers(tmp_dir, lock, info, *, mode, waiters): # noqa: C901, PLR0912
|
||||
from .lock import LockError
|
||||
|
||||
non_existing_pid = set()
|
||||
|
||||
+1
-1
@@ -227,7 +227,7 @@ def _get_n_commits(scm: "Git", revs: List[str], num: int) -> List[str]:
|
||||
return results
|
||||
|
||||
|
||||
def iter_revs( # noqa: C901
|
||||
def iter_revs(
|
||||
scm: "Git",
|
||||
revs: Optional[List[str]] = None,
|
||||
num: int = 1,
|
||||
|
||||
@@ -140,7 +140,7 @@ class Stage(params.StageParams):
|
||||
# pylint:disable=no-value-for-parameter
|
||||
# rwlocked() confuses pylint
|
||||
|
||||
def __init__(
|
||||
def __init__( # noqa: PLR0913
|
||||
self,
|
||||
repo,
|
||||
path=None,
|
||||
|
||||
@@ -29,7 +29,7 @@ class MonitorTask:
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
def SIGNAL_FILE(self) -> str:
|
||||
def SIGNAL_FILE(self) -> str: # noqa: N802
|
||||
raise NotImplementedError
|
||||
|
||||
@property
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ class Console:
|
||||
styled=styled,
|
||||
)
|
||||
|
||||
def write_json(
|
||||
def write_json( # noqa: PLR0913
|
||||
self,
|
||||
data: Any,
|
||||
indent: Optional[int] = None,
|
||||
|
||||
@@ -14,8 +14,8 @@ def apply_diff(src, dest): # noqa: C901
|
||||
|
||||
Used in Stage load/dump cycle to preserve comments and custom formatting.
|
||||
"""
|
||||
Seq = (list, tuple)
|
||||
Container = (Mapping, list, tuple)
|
||||
Seq = (list, tuple) # noqa: N806
|
||||
Container = (Mapping, list, tuple) # noqa: N806
|
||||
|
||||
def is_same_type(a, b):
|
||||
return any(
|
||||
|
||||
@@ -111,7 +111,7 @@ def _ast_tree_to_dict(tree, only_self_params=False, lineno=False):
|
||||
return result
|
||||
|
||||
|
||||
def _ast_assign_to_dict(assign, only_self_params=False, lineno=False):
|
||||
def _ast_assign_to_dict(assign, only_self_params=False, lineno=False): # noqa: PLR0912
|
||||
result = {}
|
||||
|
||||
if isinstance(assign, ast.AnnAssign):
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
# pylint: disable=unused-import
|
||||
try:
|
||||
from ._dvc_version import version as __version__
|
||||
from ._dvc_version import version_tuple # noqa: F401
|
||||
from ._dvc_version import version_tuple
|
||||
except ImportError:
|
||||
__version__ = "UNKNOWN"
|
||||
version_tuple = (0, 0, __version__) # type: ignore[assignment]
|
||||
|
||||
+15
-5
@@ -159,10 +159,10 @@ line_length = 88
|
||||
[tool.ruff]
|
||||
target-version = "py38"
|
||||
show-source = true
|
||||
ignore = ["S101", "PT004", "PT007", "PT019", "SIM105", "SIM108", "SIM110", "SIM111", "SIM117", "TRY003", "TRY200", "TRY300", "TRY301", "PLR0913", "PLR2004", "RUF005"]
|
||||
select = ["F", "E", "W", "C90", "UP", "YTT", "S", "BLE", "B", "A", "C4", "T10", "ISC", "ICN", "G", "INP", "PIE", "T20", "PT", "Q", "RET501", "RET504", "SIM", "TID", "TCH", "ARG", "PGH", "PLC", "PLE", "PLR", "PLW", "TRY", "RUF"]
|
||||
ignore = ["N818", "S101", "PT004", "PT007", "PT019", "SIM105", "SIM108", "SIM110", "SIM111", "SIM117", "TRY003", "TRY200", "TRY300", "TRY301", "PLR2004", "RUF005"]
|
||||
select = ["F", "E", "W", "C90", "N", "UP", "YTT", "S", "BLE", "B", "A", "C4", "T10", "ISC", "ICN", "G", "INP", "PIE", "T20", "PT", "Q", "RET501", "RET504", "SIM", "TID", "TCH", "ARG", "PGH", "PLC", "PLE", "PLR", "PLW", "TRY", "RUF"]
|
||||
# external flake8 codes that should be preserved
|
||||
external = ["B301", "B024", "C901", "E302", "F401", "W601"]
|
||||
external = ["B301", "C901", "E302", "W601"]
|
||||
|
||||
[tool.ruff.flake8-pytest-style]
|
||||
fixture-parentheses = false
|
||||
@@ -181,9 +181,19 @@ strict = true
|
||||
[tool.ruff.flake8-unused-arguments]
|
||||
ignore-variadic-names = true
|
||||
|
||||
[tool.ruff.isort]
|
||||
known-first-party = ["dvc", "dvc_data", "dvc_objects", "dvc_render", "dvc_task", "tests"]
|
||||
|
||||
[tool.ruff.pep8-naming]
|
||||
ignore-names = ["M", "SCM"]
|
||||
|
||||
[tool.ruff.per-file-ignores]
|
||||
"dvc/testing/*.py" = ["ARG002"]
|
||||
"scripts/**/*.py" = ["T201", "INP001", "TRY002"]
|
||||
"dvc/testing/**" = ["ARG002"]
|
||||
"scripts/**" = ["T201", "INP001", "TRY002"]
|
||||
"dvc/commands/**" = ["N806"]
|
||||
|
||||
[tool.ruff.pylint]
|
||||
max-args = 10
|
||||
|
||||
[tool.pytest.ini_options]
|
||||
log_level = "debug"
|
||||
|
||||
@@ -100,7 +100,7 @@ def test_init_cache(tmp_dir, dvc, scm, cloud):
|
||||
@pytest.mark.needs_internet
|
||||
@pytest.mark.parametrize("cloud", [pytest.lazy_fixture("git_ssh")])
|
||||
def test_reproduce(tmp_dir, scm, dvc, cloud, exp_stage, mocker):
|
||||
from sshfs import SSHFileSystem as _sshfs
|
||||
from sshfs import SSHFileSystem as _sshfs # noqa: N813
|
||||
|
||||
rev = scm.get_rev()
|
||||
root_url = cloud / SSHExecutor.gen_dirname()
|
||||
|
||||
@@ -15,7 +15,7 @@ from dvc_data.hashfile.db import HashFileDB
|
||||
from dvc_data.hashfile.db.local import LocalHashFileDB
|
||||
|
||||
|
||||
def test_cloud_cli(tmp_dir, dvc, remote, mocker):
|
||||
def test_cloud_cli(tmp_dir, dvc, remote, mocker): # noqa: PLR0915
|
||||
jobs = 2
|
||||
args = ["-v", "-j", str(jobs)]
|
||||
|
||||
|
||||
@@ -158,9 +158,9 @@ def test_refs(tmp_dir, scm, dvc):
|
||||
tmp_dir.dvc_gen("file", "second", commit="second version")
|
||||
tmp_dir.dvc_gen("file", "third", commit="third version")
|
||||
|
||||
HEAD_2 = digest("first")
|
||||
HEAD_1 = digest("second")
|
||||
HEAD = digest("third")
|
||||
HEAD_2 = digest("first") # noqa: N806
|
||||
HEAD_1 = digest("second") # noqa: N806
|
||||
HEAD = digest("third") # noqa: N806
|
||||
|
||||
assert dvc.diff("HEAD~1") == {
|
||||
"added": [],
|
||||
|
||||
@@ -97,11 +97,6 @@ def _remove_blanks(text: str):
|
||||
return " ".join(text.replace("\t", "").replace("\n", "").split())
|
||||
|
||||
|
||||
class hashabledict(dict):
|
||||
def __hash__(self):
|
||||
return hash(tuple(sorted(self.items())))
|
||||
|
||||
|
||||
def verify_vega(
|
||||
versions,
|
||||
html_result,
|
||||
|
||||
@@ -60,35 +60,35 @@ def test_build(repo):
|
||||
|
||||
|
||||
def test_build_target(repo):
|
||||
G = _build(repo, target="3")
|
||||
assert set(G.nodes()) == {"3", "b.dvc", "a.dvc"}
|
||||
assert set(G.edges()) == {("3", "a.dvc"), ("3", "b.dvc")}
|
||||
graph = _build(repo, target="3")
|
||||
assert set(graph.nodes()) == {"3", "b.dvc", "a.dvc"}
|
||||
assert set(graph.edges()) == {("3", "a.dvc"), ("3", "b.dvc")}
|
||||
|
||||
|
||||
def test_build_target_with_outs(repo):
|
||||
G = _build(repo, target="3", outs=True)
|
||||
assert set(G.nodes()) == {"a", "b", "h", "i"}
|
||||
assert set(G.edges()) == {("i", "a"), ("i", "b"), ("h", "a"), ("h", "b")}
|
||||
graph = _build(repo, target="3", outs=True)
|
||||
assert set(graph.nodes()) == {"a", "b", "h", "i"}
|
||||
assert set(graph.edges()) == {("i", "a"), ("i", "b"), ("h", "a"), ("h", "b")}
|
||||
|
||||
|
||||
def test_build_granular_target_with_outs(repo):
|
||||
G = _build(repo, target="h", outs=True)
|
||||
assert set(G.nodes()) == {"a", "b", "h"}
|
||||
assert set(G.edges()) == {("h", "a"), ("h", "b")}
|
||||
graph = _build(repo, target="h", outs=True)
|
||||
assert set(graph.nodes()) == {"a", "b", "h"}
|
||||
assert set(graph.edges()) == {("h", "a"), ("h", "b")}
|
||||
|
||||
|
||||
def test_build_full(repo):
|
||||
G = _build(repo, target="3", full=True)
|
||||
assert nx.is_isomorphic(G, repo.index.graph)
|
||||
graph = _build(repo, target="3", full=True)
|
||||
assert nx.is_isomorphic(graph, repo.index.graph)
|
||||
|
||||
|
||||
# NOTE: granular or not, full outs DAG should be the same
|
||||
@pytest.mark.parametrize("granular", [True, False])
|
||||
def test_build_full_outs(repo, granular):
|
||||
target = "h" if granular else "3"
|
||||
G = _build(repo, target=target, outs=True, full=True)
|
||||
assert set(G.nodes()) == {"j", "i", "d", "b", "g", "f", "e", "a", "h"}
|
||||
assert set(G.edges()) == {
|
||||
graph = _build(repo, target=target, outs=True, full=True)
|
||||
assert set(graph.nodes()) == {"j", "i", "d", "b", "g", "f", "e", "a", "h"}
|
||||
assert set(graph.edges()) == {
|
||||
("d", "a"),
|
||||
("e", "a"),
|
||||
("f", "b"),
|
||||
|
||||
@@ -171,7 +171,7 @@ def test_plots_diff_open(tmp_dir, dvc, mocker, capsys, plots_data, auto_open):
|
||||
assert index_path.as_uri() in out
|
||||
|
||||
|
||||
def test_plots_diff_open_WSL(tmp_dir, dvc, mocker, plots_data):
|
||||
def test_plots_diff_open_wsl(tmp_dir, dvc, mocker, plots_data):
|
||||
mocked_open = mocker.patch("webbrowser.open", return_value=True)
|
||||
mocked_uname_result = mocker.MagicMock()
|
||||
mocked_uname_result.release = "microsoft"
|
||||
|
||||
@@ -242,11 +242,11 @@ def test_add_existing_level(caplog, dt):
|
||||
# eg:
|
||||
# https://github.com/bokeh/bokeh/blob/04bb30fef2e72e64baaa8b2f330806d5bfdd3b11/
|
||||
# bokeh/util/logconfig.py#L79-L85
|
||||
TRACE2 = 4
|
||||
TRACE2 = 4 # noqa: N806
|
||||
logging.addLevelName(TRACE2, "TRACE2")
|
||||
logging.TRACE2 = TRACE2
|
||||
|
||||
dvc.logger.addLoggingLevel("TRACE2", 2)
|
||||
dvc.logger.add_logging_level("TRACE2", 2)
|
||||
|
||||
# DVC sets all expected entrypoints, but doesn't override the level
|
||||
assert logging.TRACE2 == 4
|
||||
|
||||
Reference in New Issue
Block a user