Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restyle upgrade to isort5 #4400

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@ repos:
language_version: python3
repo: https://github.com/ambv/black
rev: 19.10b0
- repo: https://github.com/asottile/seed-isort-config
rev: v2.1.1
hooks:
- id: seed-isort-config
- hooks:
- id: isort
language_version: python3
repo: https://github.com/timothycrosley/isort
rev: 4.3.21
rev: 5.4.2
- hooks:
- id: flake8
language_version: python3
Expand All @@ -22,7 +18,7 @@ repos:
- flake8-debugger
- flake8-string-format
repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
rev: 3.8.3
- repo: local
hooks:
- id: pylint
Expand Down
3 changes: 2 additions & 1 deletion dvc/command/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ class CmdDaemonBase(CmdBaseNoRepo):
class CmdDaemonUpdater(CmdDaemonBase):
def run(self):
import os
from dvc.repo import Repo

from dvc.config import Config
from dvc.repo import Repo
from dvc.updater import Updater

root_dir = Repo.find_root()
Expand Down
4 changes: 3 additions & 1 deletion dvc/command/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@


def _show_ascii(G):
from dvc.repo.graph import get_pipelines
from dvc.dagascii import draw
from dvc.repo.graph import get_pipelines

pipelines = get_pipelines(G)

Expand All @@ -22,6 +22,7 @@ def _show_ascii(G):

def _show_dot(G):
import io

from networkx.drawing.nx_pydot import write_dot

dot_file = io.StringIO()
Expand All @@ -31,6 +32,7 @@ def _show_dot(G):

def _build(G, target=None, full=False):
import networkx as nx

from dvc.repo.graph import get_pipeline, get_pipelines

if target:
Expand Down
2 changes: 2 additions & 0 deletions dvc/command/experiments.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ def _parse_list(param_list):

def _show_experiments(all_experiments, console, precision=None, **kwargs):
from rich.table import Table

from dvc.scm.git import Git

include_metrics = _parse_list(kwargs.get("include_metrics", []))
Expand Down Expand Up @@ -193,6 +194,7 @@ def _show_experiments(all_experiments, console, precision=None, **kwargs):
class CmdExperimentsShow(CmdBase):
def run(self):
from rich.console import Console

from dvc.utils.pager import pager

if not self.repo.experiments:
Expand Down
2 changes: 1 addition & 1 deletion dvc/command/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

class CmdInit(CmdBaseNoRepo):
def run(self):
from dvc.repo import Repo
from dvc.exceptions import InitError
from dvc.repo import Repo

try:
self.repo = Repo.init(
Expand Down
1 change: 1 addition & 0 deletions dvc/command/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ def show_metrics(
metrics, all_branches=False, all_tags=False, all_commits=False
):
from flatten_json import flatten

from dvc.utils.diff import format_dict

# When `metrics` contains a `None` key, it means that some files
Expand Down
18 changes: 4 additions & 14 deletions dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,12 @@
from urllib.parse import urlparse

import configobj
from funcy import cached_property, compact, re_find, walk_values
from voluptuous import (
ALLOW_EXTRA,
All,
Any,
Coerce,
Invalid,
Lower,
Optional,
Range,
Schema,
)

from dvc.exceptions import DvcException, NotDvcRepoError
from dvc.path_info import PathInfo
from dvc.utils import relpath
from funcy import cached_property, compact, re_find, walk_values
from voluptuous import (ALLOW_EXTRA, All, Any, Coerce, Invalid, Lower,
Optional, Range, Schema)

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -271,7 +261,7 @@ def __init__(

@classmethod
def get_dir(cls, level):
from appdirs import user_config_dir, site_config_dir
from appdirs import site_config_dir, user_config_dir

assert level in ("global", "system")

Expand Down
2 changes: 1 addition & 1 deletion dvc/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def _popen(cmd, **kwargs):


def _spawn_windows(cmd, env):
from subprocess import STARTUPINFO, STARTF_USESHOWWINDOW
from subprocess import STARTF_USESHOWWINDOW, STARTUPINFO

creationflags = CREATE_NEW_PROCESS_GROUP | DETACHED_PROCESS

Expand Down
55 changes: 26 additions & 29 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@
from contextlib import contextmanager
from functools import wraps

from funcy import cached_property, cat, first

from dvc.config import Config
from dvc.dvcfile import PIPELINE_FILE, Dvcfile, is_valid_filename
from dvc.exceptions import FileMissingError
from dvc.exceptions import IsADirectoryError as DvcIsADirectoryError
from dvc.exceptions import (
NoOutputOrStageError,
NotDvcRepoError,
OutputNotFoundError,
)
from dvc.exceptions import (NoOutputOrStageError, NotDvcRepoError,
OutputNotFoundError)
from dvc.path_info import PathInfo
from dvc.repo.tree import RepoTree
from dvc.utils.fs import path_isin
from funcy import cached_property, cat, first

from ..stage.exceptions import StageFileDoesNotExistError, StageNotFound
from ..utils import parse_target
Expand All @@ -42,43 +38,43 @@ def wrapper(repo, *args, **kwargs):
class Repo:
DVC_DIR = ".dvc"

from dvc.repo.destroy import destroy
from dvc.repo.install import install
from dvc.repo.add import add
from dvc.repo.remove import remove
from dvc.repo.ls import ls
from dvc.repo.freeze import freeze, unfreeze
from dvc.repo.move import move
from dvc.repo.run import run
from dvc.repo.imp import imp
from dvc.repo.imp_url import imp_url
from dvc.repo.reproduce import reproduce
from dvc.repo.brancher import brancher
from dvc.repo.checkout import _checkout
from dvc.repo.push import push
from dvc.repo.fetch import _fetch
from dvc.repo.pull import pull
from dvc.repo.status import status
from dvc.repo.gc import gc
from dvc.repo.commit import commit
from dvc.repo.destroy import destroy
from dvc.repo.diff import diff
from dvc.repo.brancher import brancher
from dvc.repo.fetch import _fetch
from dvc.repo.freeze import freeze, unfreeze
from dvc.repo.gc import gc
from dvc.repo.get import get
from dvc.repo.get_url import get_url
from dvc.repo.imp import imp
from dvc.repo.imp_url import imp_url
from dvc.repo.install import install
from dvc.repo.ls import ls
from dvc.repo.move import move
from dvc.repo.pull import pull
from dvc.repo.push import push
from dvc.repo.remove import remove
from dvc.repo.reproduce import reproduce
from dvc.repo.run import run
from dvc.repo.status import status
from dvc.repo.update import update

def __init__(self, root_dir=None, scm=None, rev=None):
from dvc.state import State, StateNoop
from dvc.lock import make_lock
from dvc.scm import SCM
from dvc.cache import Cache
from dvc.data_cloud import DataCloud
from dvc.lock import make_lock
from dvc.repo.experiments import Experiments
from dvc.repo.metrics import Metrics
from dvc.repo.plots import Plots
from dvc.repo.params import Params
from dvc.repo.plots import Plots
from dvc.scm import SCM
from dvc.stage.cache import StageCache
from dvc.state import State, StateNoop
from dvc.tree.local import LocalTree
from dvc.utils.fs import makedirs
from dvc.stage.cache import StageCache

if scm:
tree = scm.get_tree(rev)
Expand Down Expand Up @@ -441,10 +437,11 @@ def _collect_graph(self, stages):
"""
import networkx as nx
from pygtrie import Trie

from dvc.exceptions import (
OutputDuplicationError,
StagePathAsOutputError,
OverlappingOutputPathsError,
StagePathAsOutputError,
)

G = nx.DiGraph()
Expand Down
4 changes: 2 additions & 2 deletions dvc/repo/experiments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@
from contextlib import contextmanager
from typing import Iterable, Optional

from funcy import cached_property

from dvc.exceptions import DvcException
from dvc.path_info import PathInfo
from dvc.repo.experiments.executor import ExperimentExecutor, LocalExecutor
from dvc.scm.git import Git
from dvc.stage.serialize import to_lockfile
from dvc.utils import dict_sha256, env2bool, relpath
from dvc.utils.fs import copyfile, remove
from funcy import cached_property

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -404,6 +403,7 @@ def _collect_output(self, rev: str, executor: ExperimentExecutor):
def checkout_exp(self, rev):
"""Checkout an experiment to the user's workspace."""
from git.exc import GitCommandError

from dvc.repo.checkout import _checkout as dvc_checkout

self._check_baseline(rev)
Expand Down
1 change: 1 addition & 0 deletions dvc/repo/gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ def gc(
)

from contextlib import ExitStack

from dvc.repo import Repo

if not repos:
Expand Down
3 changes: 1 addition & 2 deletions dvc/repo/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import os

import shortuuid

from dvc.exceptions import DvcException
from dvc.utils import resolve_output
from dvc.utils.fs import remove
Expand All @@ -20,8 +19,8 @@ def __init__(self):

@staticmethod
def get(url, path, out=None, rev=None):
from dvc.external_repo import external_repo
from dvc.dvcfile import is_valid_filename
from dvc.external_repo import external_repo

out = resolve_output(path, out)

Expand Down
1 change: 1 addition & 0 deletions dvc/repo/graph.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
def check_acyclic(graph):
import networkx as nx

from dvc.exceptions import CyclicGraphError

try:
Expand Down
1 change: 1 addition & 0 deletions dvc/repo/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def move(self, from_path, to_path):
"""
import dvc.output as Output
from dvc.stage import Stage

from ..dvcfile import DVC_FILE_SUFFIX, Dvcfile

from_out = Output.loads_from(Stage(self), [from_path])[0]
Expand Down
5 changes: 2 additions & 3 deletions dvc/repo/plots/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import logging

from funcy import first, project

from dvc.exceptions import DvcException, NoPlotsError, OutputNotFoundError
from dvc.repo.tree import RepoTree
from dvc.schema import PLOT_PROPS
from dvc.utils import relpath
from funcy import first, project

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -210,7 +209,7 @@ def _prepare_plots(data, revs, props):


def _render(datafile, datas, props, templates):
from .data import plot_data, PlotData
from .data import PlotData, plot_data

# Copy it to not modify a passed value
props = props.copy()
Expand Down
15 changes: 8 additions & 7 deletions dvc/repo/plots/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,10 @@
from copy import copy

import yaml
from dvc.exceptions import DvcException
from funcy import first
from yaml import SafeLoader

from dvc.exceptions import DvcException


class PlotMetricTypeError(DvcException):
def __init__(self, file):
Expand Down Expand Up @@ -101,7 +100,7 @@ def _apply_path(data, path=None, **kwargs):
def _lists(dictionary):
for _, value in dictionary.items():
if isinstance(value, dict):
yield from (_lists(value))
yield from _lists(value)
elif isinstance(value, list):
yield value

Expand All @@ -114,10 +113,12 @@ def _find_data(data, fields=None, **kwargs):
# just look for first list of dicts
fields = set()

for l in _lists(data):
if all(isinstance(dp, dict) for dp in l):
if set(first(l).keys()) & fields == fields:
return l
for lst in _lists(data):
if (
all(isinstance(dp, dict) for dp in lst)
and set(first(lst).keys()) & fields == fields
):
return lst
raise PlotDataStructureError()


Expand Down
3 changes: 2 additions & 1 deletion dvc/repo/reproduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ def reproduce(

def _parse_params(path_params):
from flatten_json import unflatten
from yaml import safe_load, YAMLError
from yaml import YAMLError, safe_load

from dvc.dependency.param import ParamsDependency

ret = {}
Expand Down
Loading