Skip to content

Commit

Permalink
ruff: ignore complex functions and remove dvc.utils.fs.makedirs (iter…
Browse files Browse the repository at this point in the history
…ative#8795)

We may want to prevent any new functions from getting complex.
  • Loading branch information
skshetry authored Jan 11, 2023
1 parent 175c578 commit 90a2717
Show file tree
Hide file tree
Showing 46 changed files with 61 additions and 128 deletions.
2 changes: 1 addition & 1 deletion .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ ignore=
P1, # unindexed parameters in the str.format, see:
# https://pypi.org/project/flake8-string-format/
max_line_length = 79
max-complexity = 15
max-complexity = 10
select = B,C,E,F,W,T4,B902,T,P
show_source = true
count = true
2 changes: 1 addition & 1 deletion dvc/commands/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def _process_status(status: "DataStatus"):
yield stage, items

@classmethod
def _show_status(cls, status: "DataStatus") -> int:
def _show_status(cls, status: "DataStatus") -> int: # noqa: C901
git_info = status.pop("git") # type: ignore[misc]
result = dict(cls._process_status(status))
if not result:
Expand Down
4 changes: 2 additions & 2 deletions dvc/commands/experiments/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _collect_names(all_experiments, **kwargs):
}


def _collect_rows(
def _collect_rows( # noqa: C901
base_rev,
experiments,
all_headers,
Expand Down Expand Up @@ -314,7 +314,7 @@ def baseline_styler(typ):
return {"style": "bold"} if typ == "baseline" else {}


def show_experiments(
def show_experiments( # noqa: C901
all_experiments,
keep=None,
drop=None,
Expand Down
2 changes: 1 addition & 1 deletion dvc/commands/gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class CmdGC(CmdBase):
def run(self):
def run(self): # noqa: C901
from dvc.repo.gc import _validate_args

_validate_args(
Expand Down
2 changes: 1 addition & 1 deletion dvc/commands/plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def _html_template_path(self):
)
return html_template_path

def run(self):
def run(self): # noqa: C901
from pathlib import Path

from dvc.render.match import match_defs_renderers
Expand Down
4 changes: 2 additions & 2 deletions dvc/compare.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ def as_dict(
{k: self._columns[k][i] for k in keys} for i in range(len(self))
]

def dropna(
def dropna( # noqa: C901
self,
axis: str = "rows",
how="any",
Expand Down Expand Up @@ -267,7 +267,7 @@ def dropna(
else:
self.drop(*to_drop)

def drop_duplicates(
def drop_duplicates( # noqa: C901
self,
axis: str = "rows",
subset: Optional[Iterable[str]] = None,
Expand Down
2 changes: 1 addition & 1 deletion dvc/dagascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def point(self, x, y, char):

self.canvas[y][x] = char

def line(self, x0, y0, x1, y1, char):
def line(self, x0, y0, x1, y1, char): # noqa: C901
"""Create a line on ASCII canvas.
Args:
Expand Down
2 changes: 1 addition & 1 deletion dvc/external_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ def _cached_clone(url, rev, for_write=False):


@wrap_with(threading.Lock())
def _clone_default_branch(url, rev, for_write=False):
def _clone_default_branch(url, rev, for_write=False): # noqa: C901
"""Get or create a clean clone of the url.
The cloned is reactualized with git pull unless rev is a known sha.
Expand Down
4 changes: 3 additions & 1 deletion dvc/fs/dvc.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,9 @@ def info(self, path, **kwargs):
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):
def _info( # noqa: C901
self, key, path, ignore_subrepos=True, check_ignored=True
):
repo, dvc_fs, subkey = self._get_subrepo_info(key)

dvc_info = None
Expand Down
5 changes: 2 additions & 3 deletions dvc/machine/backend/terraform.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
from dvc_ssh import DEFAULT_PORT, SSHFileSystem

from dvc.exceptions import DvcException
from dvc.utils.fs import makedirs

from .base import BaseMachineBackend

Expand All @@ -30,7 +29,7 @@ def _sshfs(resource: dict):
class TerraformBackend(BaseMachineBackend):
def __init__(self, tmp_dir: "StrPath", **kwargs):
super().__init__(tmp_dir, **kwargs)
makedirs(tmp_dir, exist_ok=True)
os.makedirs(tmp_dir, exist_ok=True)

@contextmanager
def make_tpi(self, name: str):
Expand All @@ -39,7 +38,7 @@ def make_tpi(self, name: str):

try:
working_dir = os.path.join(self.tmp_dir, name)
makedirs(working_dir, exist_ok=True)
os.makedirs(working_dir, exist_ok=True)
yield TPIBackend(working_dir=working_dir)
except TPIError as exc:
raise DvcException("TPI operation failed") from exc
Expand Down
4 changes: 2 additions & 2 deletions dvc/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ def _commit_granular_dir(self, filter_info):
)
return checkout_obj

def dumpd(self, **kwargs):
def dumpd(self, **kwargs): # noqa: C901
meta = self.meta.to_dict()
meta.pop("isdir", None)
ret = {**self.hash_info.to_dict(), **meta}
Expand Down Expand Up @@ -1034,7 +1034,7 @@ def _collect_used_dir_cache(
return obj.filter(prefix)
return obj

def get_used_objs(
def get_used_objs( # noqa: C901
self, **kwargs
) -> Dict[Optional["ObjectDB"], Set["HashInfo"]]:
"""Return filtered set of used object IDs for this out."""
Expand Down
2 changes: 1 addition & 1 deletion dvc/parsing/interpolate.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def _(obj: bool):


@to_str.register(dict)
def _(obj: dict):
def _(obj: dict): # noqa: C901
from dvc.config import Config

config = Config().get("parsing", {})
Expand Down
4 changes: 1 addition & 3 deletions dvc/proc/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@
from funcy import cached_property
from shortuuid import uuid

from dvc.utils.fs import makedirs

from .exceptions import TimeoutExpired

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -103,7 +101,7 @@ def info(self) -> "ProcessInfo":

def _make_wdir(self):
if self.wdir:
makedirs(self.wdir, exist_ok=True)
os.makedirs(self.wdir, exist_ok=True)

def _dump(self):
self._make_wdir()
Expand Down
2 changes: 1 addition & 1 deletion dvc/render/converter/vega.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def infer_x_label(properties):
return first(fields)
return "x"

def flat_datapoints(self, revision):
def flat_datapoints(self, revision): # noqa: C901

file2datapoints, properties = self.convert()

Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def _paths_checksums(repo, targets):
return dict(_output_paths(repo, targets))


def _output_paths(repo, targets):
def _output_paths(repo, targets): # noqa: C901
from dvc.fs import LocalFileSystem
from dvc_data.hashfile.build import build

Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/experiments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def _workspace_resume_rev(self) -> Optional[str]:
return last_applied
return None

def reproduce_celery(
def reproduce_celery( # noqa: C901
self, entries: Optional[Iterable[QueueEntry]] = None, **kwargs
) -> Dict[str, str]:
results: Dict[str, str] = {}
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/experiments/apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

@locked
@scm_context
def apply(repo: "Repo", rev: str, force: bool = True, **kwargs):
def apply(repo: "Repo", rev: str, force: bool = True, **kwargs): # noqa: C901
from scmrepo.exceptions import SCMError as _SCMError

from dvc.repo.checkout import checkout as dvc_checkout
Expand Down
8 changes: 3 additions & 5 deletions dvc/repo/experiments/executor/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ def result(self) -> Optional["ExecutorResult"]:
)

def dump_json(self, filename: str):
from dvc.utils.fs import makedirs
from dvc.utils.serialize import modify_json

makedirs(os.path.dirname(filename), exist_ok=True)
os.makedirs(os.path.dirname(filename), exist_ok=True)
with modify_json(filename) as d:
d.update(self.asdict())

Expand Down Expand Up @@ -288,10 +287,9 @@ def pack_repro_args(path, *args, fs=None, extra=None, **kwargs):
open_func = fs.open
fs.makedirs(dpath)
else:
from dvc.utils.fs import makedirs

open_func = open
makedirs(dpath, exist_ok=True)
os.makedirs(dpath, exist_ok=True)

data = {"args": args, "kwargs": kwargs}
if extra is not None:
Expand Down Expand Up @@ -549,7 +547,7 @@ def _repro_commit(

@classmethod
@contextmanager
def _repro_dvc(
def _repro_dvc( # noqa: C901
cls,
info: "ExecutorInfo",
infofile: str = None,
Expand Down
4 changes: 2 additions & 2 deletions dvc/repo/experiments/executor/local.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)
from dvc.repo.experiments.utils import EXEC_TMP_DIR, get_exp_rwlock
from dvc.scm import SCM, GitMergeError
from dvc.utils.fs import makedirs, remove
from dvc.utils.fs import remove

from .base import BaseExecutor, TaskStatus

Expand Down Expand Up @@ -166,7 +166,7 @@ def from_stash_entry(
**kwargs,
):
parent_dir: str = wdir or os.path.join(repo.tmp_dir, EXEC_TMP_DIR)
makedirs(parent_dir, exist_ok=True)
os.makedirs(parent_dir, exist_ok=True)
tmp_dir = mkdtemp(dir=parent_dir)
try:
executor = cls._from_stash_entry(repo, entry, tmp_dir, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/experiments/pull.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@locked
@scm_context
def pull(
def pull( # noqa: C901
repo,
git_remote: str,
exp_names: Union[Iterable[str], str],
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/experiments/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

@locked
@scm_context
def push(
def push( # noqa: C901
repo,
git_remote: str,
exp_names: Union[Iterable[str], str],
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/experiments/queue/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from dvc.repo.experiments.stash import ExpStashEntry


def remove_tasks(
def remove_tasks( # noqa: C901
celery_queue: "LocalCeleryQueue",
queue_entries: Iterable["QueueEntry"],
):
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/experiments/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

@locked
@scm_context
def remove(
def remove( # noqa: C901
repo: "Repo",
exp_names: Union[None, str, List[str]] = None,
rev: Optional[str] = None,
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/experiments/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


@locked
def run(
def run( # noqa: C901
repo,
targets: Optional[Iterable[str]] = None,
params: Optional[Iterable[str]] = None,
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/experiments/show.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ def get_branch_names(
return names


def update_names(
def update_names( # noqa: C901
repo: "Repo",
branch_names: Dict[str, Optional[str]],
result: Dict[str, Dict[str, Any]],
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@


@locked
def fetch(
def fetch( # noqa: C901
self,
targets=None,
jobs=None,
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/imp_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@locked
@scm_context
def imp_url(
def imp_url( # noqa: C901
self,
url,
out=None,
Expand Down
4 changes: 2 additions & 2 deletions dvc/repo/imports.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import os
from tempfile import TemporaryDirectory
from typing import TYPE_CHECKING, List, Set, Tuple, Union

Expand Down Expand Up @@ -94,7 +95,6 @@ def save_imports(
Objects which were downloaded from source location.
"""
from dvc.stage.exceptions import DataSourceChanged
from dvc.utils.fs import makedirs
from dvc_data.index import checkout, md5, save
from dvc_objects.fs.callbacks import Callback

Expand All @@ -110,7 +110,7 @@ def save_imports(
if len(data_view):
cache = repo.odb.local
if not cache.fs.exists(cache.path):
makedirs(cache.path)
os.makedirs(cache.path)
with TemporaryDirectory(dir=cache.path) as tmpdir:
with Callback.as_tqdm_callback(
desc="Downloading imports from source",
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/push.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


@locked
def push(
def push( # noqa: C901
self,
targets=None,
jobs=None,
Expand Down
4 changes: 2 additions & 2 deletions dvc/repo/reproduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def _track_stage(stage: "Stage") -> None:

@locked
@scm_context
def reproduce(
def reproduce( # noqa: C901
self: "Repo",
targets=None,
recursive=False,
Expand Down Expand Up @@ -138,7 +138,7 @@ def reproduce(
return _reproduce_stages(self.index.graph, list(stages), **kwargs)


def _reproduce_stages(
def _reproduce_stages( # noqa: C901
G, stages, downstream=False, single_item=False, on_unchanged=None, **kwargs
):
r"""Derive the evaluation of the given node for the given graph.
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ def _load_file(self, path):
stages_ = [stages[key] for key in keys]
return stages_, dvcfile

def _collect_all_from_repo(
def _collect_all_from_repo( # noqa: C901
self, onerror: Callable[[str, Exception], None] = None
):
"""Collects all of the stages present in the DVC repo.
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


@locked
def update(
def update( # noqa: C901
self,
targets=None,
rev=None,
Expand Down
Loading

0 comments on commit 90a2717

Please sign in to comment.