Skip to content

Commit

Permalink
upgrade to isort5 (iterative#4399)
Browse files Browse the repository at this point in the history
* Imports are no longer moved to top.
* `seed-isort-config` is no longer needed.
* Has a `black`-compatible profile/config.
* Also `isorts` the imports anywhere in the code
  (not just at the top).

Also bumps `restyled-isort` to newest version
  • Loading branch information
skshetry authored Aug 17, 2020
1 parent 31e9cc2 commit c4bc4c8
Show file tree
Hide file tree
Showing 39 changed files with 80 additions and 68 deletions.
6 changes: 1 addition & 5 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 Down
2 changes: 1 addition & 1 deletion .restyled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ restylers:
interpreters:
- python
- name: isort
image: restyled/restyler-isort:v4.3.21
image: restyled/restyler-isort:v5.4.2
command:
- isort
arguments: []
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
2 changes: 1 addition & 1 deletion dvc/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,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
45 changes: 23 additions & 22 deletions dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,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 +441,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
1 change: 1 addition & 0 deletions dvc/repo/experiments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,6 +404,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
2 changes: 1 addition & 1 deletion dvc/repo/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,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
2 changes: 1 addition & 1 deletion dvc/repo/plots/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,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
2 changes: 1 addition & 1 deletion dvc/repo/plots/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,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 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
4 changes: 2 additions & 2 deletions dvc/repo/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def parse_params(path_params):


def _get_file_path(kwargs):
from dvc.dvcfile import DVC_FILE_SUFFIX, DVC_FILE
from dvc.dvcfile import DVC_FILE, DVC_FILE_SUFFIX

out = first(
concat(
Expand Down Expand Up @@ -76,8 +76,8 @@ def _check_stage_exists(dvcfile, stage):
@locked
@scm_context
def run(self, fname=None, no_exec=False, single_stage=False, **kwargs):
from dvc.dvcfile import PIPELINE_FILE, Dvcfile
from dvc.stage import Stage, create_stage
from dvc.dvcfile import Dvcfile, PIPELINE_FILE

if not kwargs.get("cmd"):
raise InvalidArgumentError("command is not specified")
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@

if TYPE_CHECKING:
from dvc.repo import Repo
from dvc.tree.local import LocalTree
from dvc.tree.git import GitTree
from dvc.tree.local import LocalTree


logger = logging.getLogger(__name__)
Expand Down
3 changes: 2 additions & 1 deletion dvc/scm/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,9 +393,10 @@ def get_rev(self):
return self.repo.rev_parse("HEAD").hexsha

def resolve_rev(self, rev):
from git.exc import BadName, GitCommandError
from contextlib import suppress

from git.exc import BadName, GitCommandError

def _resolve_rev(name):
with suppress(BadName, GitCommandError):
try:
Expand Down
2 changes: 1 addition & 1 deletion dvc/stage/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def _load(self, stage):
return None

def _create_stage(self, cache, wdir=None):
from . import create_stage, PipelineStage
from . import PipelineStage, create_stage

stage = create_stage(
PipelineStage,
Expand Down
3 changes: 2 additions & 1 deletion dvc/stage/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
@decorator
def rwlocked(call, read=None, write=None):
import sys
from dvc.rwlock import rwlock

from dvc.dependency.repo import RepoDependency
from dvc.rwlock import rwlock

if read is None:
read = []
Expand Down
3 changes: 2 additions & 1 deletion dvc/stage/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,10 @@ def check_circular_dependency(stage):


def check_duplicated_arguments(stage):
from dvc.exceptions import ArgumentDuplicationError
from collections import Counter

from dvc.exceptions import ArgumentDuplicationError

path_counts = Counter(edge.path_info for edge in stage.deps + stage.outs)

for path, occurrence in path_counts.items():
Expand Down
5 changes: 3 additions & 2 deletions dvc/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,14 @@ def reflink(source, link_name):
@staticmethod
def _getdirinfo(path):
from collections import namedtuple

from win32file import ( # pylint: disable=import-error
CreateFileW,
GetFileInformationByHandle,
FILE_FLAG_BACKUP_SEMANTICS,
FILE_FLAG_OPEN_REPARSE_POINT,
FILE_SHARE_READ,
OPEN_EXISTING,
CreateFileW,
GetFileInformationByHandle,
)

# NOTE: use FILE_FLAG_OPEN_REPARSE_POINT to open symlink itself and not
Expand Down
2 changes: 1 addition & 1 deletion dvc/tree/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ def _az_config(self):
@cached_property
def blob_service(self):
# pylint: disable=no-name-in-module
from azure.storage.blob import BlobServiceClient
from azure.core.exceptions import ResourceNotFoundError
from azure.storage.blob import BlobServiceClient

logger.debug(f"URL {self.path_info}")

Expand Down
1 change: 0 additions & 1 deletion dvc/tree/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ def wrapper(*args, **kwargs):
# Note: must be multiple of 256K.
#
# [#2572]: https://github.com/iterative/dvc/issues/2572

# skipcq: PYL-W0212
multiplier = 40
while True:
Expand Down
1 change: 1 addition & 0 deletions dvc/updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def fetch(self, detach=True):

def _get_latest_version(self):
import json

import requests

try:
Expand Down
3 changes: 2 additions & 1 deletion dvc/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def _fobj_md5(fobj, hash_md5, binary, progress_func=None):

def file_md5(fname, tree=None):
""" get the (md5 hexdigest, md5 digest) of a file """
from dvc.progress import Tqdm
from dvc.istextfile import istextfile
from dvc.progress import Tqdm

if tree:
exists_func = tree.exists
Expand Down Expand Up @@ -364,6 +364,7 @@ def resolve_output(inp, out):

def resolve_paths(repo, out):
from urllib.parse import urlparse

from ..dvcfile import DVC_FILE_SUFFIX
from ..path_info import PathInfo
from .fs import contains_symlink_up_to
Expand Down
Loading

0 comments on commit c4bc4c8

Please sign in to comment.