From 865084512f9613ae19332cdbd51689bde442c8b1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Saugat=20Pachhai=20=28=E0=A4=B8=E0=A5=8C=E0=A4=97=E0=A4=BE?= =?UTF-8?q?=E0=A4=A4=29?= Date: Mon, 17 Aug 2020 10:05:30 +0545 Subject: [PATCH 1/2] upgrade to isort5 * 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). --- .pre-commit-config.yaml | 8 ++--- dvc/command/daemon.py | 3 +- dvc/command/dag.py | 4 ++- dvc/command/experiments.py | 2 ++ dvc/command/init.py | 2 +- dvc/command/metrics.py | 1 + dvc/config.py | 2 +- dvc/daemon.py | 2 +- dvc/repo/__init__.py | 45 +++++++++++++++-------------- dvc/repo/experiments/__init__.py | 1 + dvc/repo/gc.py | 1 + dvc/repo/get.py | 2 +- dvc/repo/graph.py | 1 + dvc/repo/move.py | 1 + dvc/repo/plots/__init__.py | 2 +- dvc/repo/plots/data.py | 12 ++++---- dvc/repo/reproduce.py | 3 +- dvc/repo/run.py | 4 +-- dvc/scm/git.py | 3 +- dvc/stage/cache.py | 2 +- dvc/stage/decorators.py | 3 +- dvc/stage/utils.py | 3 +- dvc/system.py | 5 ++-- dvc/tree/azure.py | 2 +- dvc/tree/gs.py | 1 - dvc/updater.py | 1 + dvc/utils/__init__.py | 3 +- setup.cfg | 6 +--- tests/__init__.py | 3 +- tests/func/test_add.py | 3 +- tests/func/test_ls.py | 1 + tests/func/test_repro_multistage.py | 3 +- tests/func/test_run_multistage.py | 8 ++--- tests/remotes/__init__.py | 16 +++++----- tests/remotes/azure.py | 6 ++-- tests/remotes/hdfs.py | 3 +- tests/unit/scm/test_git.py | 2 +- tests/utils/httpd.py | 2 +- 38 files changed, 93 insertions(+), 79 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 7603cd9b9b..81d2bf1b3d 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 @@ -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 diff --git a/dvc/command/daemon.py b/dvc/command/daemon.py index daec0e8cef..bbed4e2e8d 100644 --- a/dvc/command/daemon.py +++ b/dvc/command/daemon.py @@ -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() diff --git a/dvc/command/dag.py b/dvc/command/dag.py index 27acb0b9f0..2cf38e9304 100644 --- a/dvc/command/dag.py +++ b/dvc/command/dag.py @@ -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) @@ -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() @@ -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: diff --git a/dvc/command/experiments.py b/dvc/command/experiments.py index e74dcc53b3..5af865f106 100644 --- a/dvc/command/experiments.py +++ b/dvc/command/experiments.py @@ -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", [])) @@ -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: diff --git a/dvc/command/init.py b/dvc/command/init.py index bfd5bb88e8..8f5e881fcf 100644 --- a/dvc/command/init.py +++ b/dvc/command/init.py @@ -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( diff --git a/dvc/command/metrics.py b/dvc/command/metrics.py index fcffba8fd5..432f17345a 100644 --- a/dvc/command/metrics.py +++ b/dvc/command/metrics.py @@ -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 diff --git a/dvc/config.py b/dvc/config.py index e370489d66..685be624e3 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -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") diff --git a/dvc/daemon.py b/dvc/daemon.py index 0251fb1f2a..61eb8a7fd8 100644 --- a/dvc/daemon.py +++ b/dvc/daemon.py @@ -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 diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py index 329dafa034..c518b726f5 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -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) @@ -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() diff --git a/dvc/repo/experiments/__init__.py b/dvc/repo/experiments/__init__.py index 20963e1faa..4f6ec5aecb 100644 --- a/dvc/repo/experiments/__init__.py +++ b/dvc/repo/experiments/__init__.py @@ -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) diff --git a/dvc/repo/gc.py b/dvc/repo/gc.py index ea86ab4f84..44a64e29b5 100644 --- a/dvc/repo/gc.py +++ b/dvc/repo/gc.py @@ -50,6 +50,7 @@ def gc( ) from contextlib import ExitStack + from dvc.repo import Repo if not repos: diff --git a/dvc/repo/get.py b/dvc/repo/get.py index 1141b00772..f14011f523 100644 --- a/dvc/repo/get.py +++ b/dvc/repo/get.py @@ -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) diff --git a/dvc/repo/graph.py b/dvc/repo/graph.py index fab001a485..325ea6d0b3 100644 --- a/dvc/repo/graph.py +++ b/dvc/repo/graph.py @@ -1,5 +1,6 @@ def check_acyclic(graph): import networkx as nx + from dvc.exceptions import CyclicGraphError try: diff --git a/dvc/repo/move.py b/dvc/repo/move.py index 58f74b563a..1036f73504 100644 --- a/dvc/repo/move.py +++ b/dvc/repo/move.py @@ -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] diff --git a/dvc/repo/plots/__init__.py b/dvc/repo/plots/__init__.py index 4386ca5613..fd63ec228b 100644 --- a/dvc/repo/plots/__init__.py +++ b/dvc/repo/plots/__init__.py @@ -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() diff --git a/dvc/repo/plots/data.py b/dvc/repo/plots/data.py index 9ff23ccf90..78d44164f5 100644 --- a/dvc/repo/plots/data.py +++ b/dvc/repo/plots/data.py @@ -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 @@ -114,10 +114,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() diff --git a/dvc/repo/reproduce.py b/dvc/repo/reproduce.py index 1f60117b45..6fc0cc6cde 100644 --- a/dvc/repo/reproduce.py +++ b/dvc/repo/reproduce.py @@ -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 = {} diff --git a/dvc/repo/run.py b/dvc/repo/run.py index eea3eb05d3..d383f4e25a 100644 --- a/dvc/repo/run.py +++ b/dvc/repo/run.py @@ -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( @@ -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") diff --git a/dvc/scm/git.py b/dvc/scm/git.py index 12b0b198cf..5df270bdae 100644 --- a/dvc/scm/git.py +++ b/dvc/scm/git.py @@ -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: diff --git a/dvc/stage/cache.py b/dvc/stage/cache.py index 0802c036d5..d77a78e3b2 100644 --- a/dvc/stage/cache.py +++ b/dvc/stage/cache.py @@ -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, diff --git a/dvc/stage/decorators.py b/dvc/stage/decorators.py index 3623fb5251..df51f67f8f 100644 --- a/dvc/stage/decorators.py +++ b/dvc/stage/decorators.py @@ -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 = [] diff --git a/dvc/stage/utils.py b/dvc/stage/utils.py index 5957277d94..feb2a348fb 100644 --- a/dvc/stage/utils.py +++ b/dvc/stage/utils.py @@ -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(): diff --git a/dvc/system.py b/dvc/system.py index 3439f41198..1d7f0a9b5b 100644 --- a/dvc/system.py +++ b/dvc/system.py @@ -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 diff --git a/dvc/tree/azure.py b/dvc/tree/azure.py index 5ef3f25948..ee094360d1 100644 --- a/dvc/tree/azure.py +++ b/dvc/tree/azure.py @@ -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}") diff --git a/dvc/tree/gs.py b/dvc/tree/gs.py index c7055a73ad..c35a490b46 100644 --- a/dvc/tree/gs.py +++ b/dvc/tree/gs.py @@ -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: diff --git a/dvc/updater.py b/dvc/updater.py index 92ef1bb889..1eda2a4c81 100644 --- a/dvc/updater.py +++ b/dvc/updater.py @@ -88,6 +88,7 @@ def fetch(self, detach=True): def _get_latest_version(self): import json + import requests try: diff --git a/dvc/utils/__init__.py b/dvc/utils/__init__.py index 8fece228ff..bcceb1f760 100644 --- a/dvc/utils/__init__.py +++ b/dvc/utils/__init__.py @@ -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 @@ -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 diff --git a/setup.cfg b/setup.cfg index c794a46e17..0c5df19e4a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -15,10 +15,6 @@ show_source=true count=true [isort] -include_trailing_comma=true +profile=black known_first_party=dvc,tests -known_third_party=PyInstaller,RangeHTTPServer,boto3,colorama,configobj,distro,dpath,flaky,flufl,funcy,git,grandalf,mock,moto,nanotime,networkx,packaging,pathspec,pygtrie,pylint,pytest,requests,ruamel,setuptools,shortuuid,shtab,toml,tqdm,voluptuous,yaml,zc line_length=79 -force_grid_wrap=0 -use_parentheses=True -multi_line_output=3 diff --git a/tests/__init__.py b/tests/__init__.py index 8d69f84bfa..343dc6fa01 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -2,9 +2,10 @@ # Increasing fd ulimit for tests if os.name == "nt": - import win32file # pylint: disable=import-error import subprocess + import win32file # pylint: disable=import-error + win32file._setmaxstdio(2048) # Workaround for two bugs: diff --git a/tests/func/test_add.py b/tests/func/test_add.py index 92f9525e97..b712d744c7 100644 --- a/tests/func/test_add.py +++ b/tests/func/test_add.py @@ -595,8 +595,9 @@ def test(self): @pytest.fixture def temporary_windows_drive(tmp_path_factory): import string - import win32api # pylint: disable=import-error from ctypes import windll + + import win32api # pylint: disable=import-error from win32con import DDD_REMOVE_DEFINITION # pylint: disable=import-error drives = [ diff --git a/tests/func/test_ls.py b/tests/func/test_ls.py index 4c2681d524..0f65c52f4a 100644 --- a/tests/func/test_ls.py +++ b/tests/func/test_ls.py @@ -74,6 +74,7 @@ def test_ls_repo(tmp_dir, dvc, scm): def test_ls_repo_with_color(tmp_dir, dvc, scm, mocker, monkeypatch, caplog): import logging + from dvc.cli import parse_args tmp_dir.scm_gen(FS_STRUCTURE, commit="init") diff --git a/tests/func/test_repro_multistage.py b/tests/func/test_repro_multistage.py index 1dd363a7dc..c6875f270e 100644 --- a/tests/func/test_repro_multistage.py +++ b/tests/func/test_repro_multistage.py @@ -471,9 +471,8 @@ def test_cyclic_graph_error(tmp_dir, dvc, run_copy): def test_repro_multiple_params(tmp_dir, dvc): - from tests.func.test_run_multistage import supported_params - from dvc.stage.utils import split_params_deps + from tests.func.test_run_multistage import supported_params with (tmp_dir / "params2.yaml").open("w+") as f: yaml.dump(supported_params, f) diff --git a/tests/func/test_run_multistage.py b/tests/func/test_run_multistage.py index 056052342a..8be4c3a045 100644 --- a/tests/func/test_run_multistage.py +++ b/tests/func/test_run_multistage.py @@ -11,8 +11,8 @@ def test_run_with_name(tmp_dir, dvc, run_copy): - from dvc.stage import PipelineStage from dvc.dvcfile import PIPELINE_FILE, PIPELINE_LOCK + from dvc.stage import PipelineStage tmp_dir.dvc_gen("foo", "foo") assert not os.path.exists(PIPELINE_FILE) @@ -24,8 +24,8 @@ def test_run_with_name(tmp_dir, dvc, run_copy): def test_run_no_exec(tmp_dir, dvc, run_copy): - from dvc.stage import PipelineStage from dvc.dvcfile import PIPELINE_FILE, PIPELINE_LOCK + from dvc.stage import PipelineStage tmp_dir.dvc_gen("foo", "foo") assert not os.path.exists(PIPELINE_FILE) @@ -62,8 +62,8 @@ def test_run_with_multistage_and_single_stage(tmp_dir, dvc, run_copy): def test_run_multi_stage_repeat(tmp_dir, dvc, run_copy): + from dvc.dvcfile import PIPELINE_FILE, Dvcfile from dvc.stage import PipelineStage - from dvc.dvcfile import Dvcfile, PIPELINE_FILE tmp_dir.dvc_gen("foo", "foo") run_copy("foo", "foo1", name="copy-foo-foo1") @@ -144,7 +144,7 @@ def test_graph(tmp_dir, dvc): def test_run_dump_on_multistage(tmp_dir, dvc, run_head): - from dvc.dvcfile import Dvcfile, PIPELINE_FILE + from dvc.dvcfile import PIPELINE_FILE, Dvcfile tmp_dir.gen( { diff --git a/tests/remotes/__init__.py b/tests/remotes/__init__.py index 6a5b80166e..54361dda1d 100644 --- a/tests/remotes/__init__.py +++ b/tests/remotes/__init__.py @@ -9,14 +9,6 @@ from .oss import OSS, TEST_OSS_REPO_BUCKET, oss, oss_server # noqa: F401 from .s3 import S3, TEST_AWS_REPO_BUCKET, real_s3, s3 # noqa: F401 -TEST_REMOTE = "upstream" -TEST_CONFIG = { - "cache": {}, - "core": {"remote": TEST_REMOTE}, - "remote": {TEST_REMOTE: {"url": ""}}, -} - - from .gdrive import ( # noqa: F401; noqa: F401 TEST_GDRIVE_REPO_BUCKET, GDrive, @@ -36,6 +28,14 @@ ) +TEST_REMOTE = "upstream" +TEST_CONFIG = { + "cache": {}, + "core": {"remote": TEST_REMOTE}, + "remote": {TEST_REMOTE: {"url": ""}}, +} + + @pytest.fixture(scope="session") def docker(): import os diff --git a/tests/remotes/azure.py b/tests/remotes/azure.py index 27db33298d..b0b31b1d25 100644 --- a/tests/remotes/azure.py +++ b/tests/remotes/azure.py @@ -24,12 +24,12 @@ class Azure(Base, CloudURLInfo): @pytest.fixture(scope="session") def azure_server(docker_compose, docker_services): - from azure.storage.blob import ( # pylint: disable=no-name-in-module - BlobServiceClient, - ) from azure.core.exceptions import ( # pylint: disable=no-name-in-module AzureError, ) + from azure.storage.blob import ( # pylint: disable=no-name-in-module + BlobServiceClient, + ) port = docker_services.port_for("azurite", 10000) connection_string = TEST_AZURE_CONNECTION_STRING.format(port=port) diff --git a/tests/remotes/hdfs.py b/tests/remotes/hdfs.py index f7502b7977..9b5601b8da 100644 --- a/tests/remotes/hdfs.py +++ b/tests/remotes/hdfs.py @@ -70,8 +70,9 @@ def read_text(self, encoding=None, errors=None): @pytest.fixture(scope="session") def hadoop(): - import wget import tarfile + + import wget from appdirs import user_cache_dir if platform.system() != "Linux": diff --git a/tests/unit/scm/test_git.py b/tests/unit/scm/test_git.py index 04b630b6a0..2f82dd04e7 100644 --- a/tests/unit/scm/test_git.py +++ b/tests/unit/scm/test_git.py @@ -98,8 +98,8 @@ def test_is_tracked_unicode(tmp_dir, scm): def test_no_commits(tmp_dir): - from tests.dir_helpers import git_init from dvc.scm.git import Git + from tests.dir_helpers import git_init git_init(".") assert Git().no_commits diff --git a/tests/utils/httpd.py b/tests/utils/httpd.py index 4db94adf19..74ddbc2b75 100644 --- a/tests/utils/httpd.py +++ b/tests/utils/httpd.py @@ -16,8 +16,8 @@ def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) def translate_path(self, path): - import urllib import posixpath + import urllib # NOTE: `directory` was introduced in 3.7 if sys.version_info >= (3, 7): From 14c4237cf70f387a3e21a4124caa292d8fb4d0f0 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Mon, 17 Aug 2020 04:27:01 +0000 Subject: [PATCH 2/2] Restyled by isort --- dvc/config.py | 16 +++------------- dvc/repo/__init__.py | 10 +++------- dvc/repo/experiments/__init__.py | 3 +-- dvc/repo/get.py | 1 - dvc/repo/plots/__init__.py | 3 +-- dvc/repo/plots/data.py | 3 +-- dvc/repo/run.py | 10 +++------- dvc/scm/git.py | 14 ++++---------- dvc/stage/cache.py | 5 ++--- dvc/stage/utils.py | 13 ++++--------- dvc/tree/azure.py | 3 +-- dvc/tree/gs.py | 3 +-- dvc/updater.py | 3 +-- tests/func/test_add.py | 16 ++++++---------- tests/func/test_ls.py | 1 - tests/func/test_repro_multistage.py | 3 +-- tests/func/test_run_multistage.py | 1 - tests/remotes/azure.py | 1 - tests/remotes/hdfs.py | 1 - tests/unit/scm/test_git.py | 1 - 20 files changed, 32 insertions(+), 79 deletions(-) diff --git a/dvc/config.py b/dvc/config.py index 685be624e3..d440668e0d 100644 --- a/dvc/config.py +++ b/dvc/config.py @@ -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__) diff --git a/dvc/repo/__init__.py b/dvc/repo/__init__.py index c518b726f5..2523e60f60 100644 --- a/dvc/repo/__init__.py +++ b/dvc/repo/__init__.py @@ -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 diff --git a/dvc/repo/experiments/__init__.py b/dvc/repo/experiments/__init__.py index 4f6ec5aecb..c6cecc5b0e 100644 --- a/dvc/repo/experiments/__init__.py +++ b/dvc/repo/experiments/__init__.py @@ -8,8 +8,6 @@ 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 @@ -17,6 +15,7 @@ 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__) diff --git a/dvc/repo/get.py b/dvc/repo/get.py index f14011f523..32274c82a0 100644 --- a/dvc/repo/get.py +++ b/dvc/repo/get.py @@ -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 diff --git a/dvc/repo/plots/__init__.py b/dvc/repo/plots/__init__.py index fd63ec228b..07e03808dc 100644 --- a/dvc/repo/plots/__init__.py +++ b/dvc/repo/plots/__init__.py @@ -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__) diff --git a/dvc/repo/plots/data.py b/dvc/repo/plots/data.py index 78d44164f5..2cefd66e8a 100644 --- a/dvc/repo/plots/data.py +++ b/dvc/repo/plots/data.py @@ -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): diff --git a/dvc/repo/run.py b/dvc/repo/run.py index d383f4e25a..ec2a202fc8 100644 --- a/dvc/repo/run.py +++ b/dvc/repo/run.py @@ -1,15 +1,11 @@ import os from contextlib import suppress -from funcy import concat, first, lfilter - from dvc.exceptions import InvalidArgumentError from dvc.stage import PipelineStage -from dvc.stage.exceptions import ( - DuplicateStageName, - InvalidStageName, - StageFileAlreadyExistsError, -) +from dvc.stage.exceptions import (DuplicateStageName, InvalidStageName, + StageFileAlreadyExistsError) +from funcy import concat, first, lfilter from ..exceptions import OutputDuplicationError from . import locked diff --git a/dvc/scm/git.py b/dvc/scm/git.py index 5df270bdae..ae84a25e3e 100644 --- a/dvc/scm/git.py +++ b/dvc/scm/git.py @@ -6,20 +6,14 @@ from functools import partial import yaml -from funcy import cached_property -from pathspec.patterns import GitWildMatchPattern - from dvc.exceptions import GitHookAlreadyExistsError from dvc.progress import Tqdm -from dvc.scm.base import ( - Base, - CloneError, - FileNotInRepoError, - RevError, - SCMError, -) +from dvc.scm.base import (Base, CloneError, FileNotInRepoError, RevError, + SCMError) from dvc.utils import fix_env, is_binary, relpath from dvc.utils.fs import path_isin +from funcy import cached_property +from pathspec.patterns import GitWildMatchPattern logger = logging.getLogger(__name__) diff --git a/dvc/stage/cache.py b/dvc/stage/cache.py index d77a78e3b2..375867dddc 100644 --- a/dvc/stage/cache.py +++ b/dvc/stage/cache.py @@ -3,14 +3,13 @@ from contextlib import contextmanager import yaml -from funcy import first -from voluptuous import Invalid - from dvc.cache.local import _log_exceptions from dvc.schema import COMPILED_LOCK_FILE_STAGE_SCHEMA from dvc.utils import dict_sha256, relpath from dvc.utils.fs import makedirs from dvc.utils.yaml import dump_yaml +from funcy import first +from voluptuous import Invalid from .loader import StageLoader from .serialize import to_single_stage_lockfile diff --git a/dvc/stage/utils.py b/dvc/stage/utils.py index feb2a348fb..6ccb7acf24 100644 --- a/dvc/stage/utils.py +++ b/dvc/stage/utils.py @@ -2,22 +2,17 @@ import pathlib from itertools import product -from funcy import lsplit, rpartial - from dvc import dependency, output from dvc.utils.fs import path_isin +from funcy import lsplit, rpartial from ..dependency import ParamsDependency from ..tree.local import LocalTree from ..tree.s3 import S3Tree from ..utils import dict_md5, format_link, relpath -from .exceptions import ( - MissingDataSource, - StageExternalOutputsError, - StagePathNotDirectoryError, - StagePathNotFoundError, - StagePathOutsideError, -) +from .exceptions import (MissingDataSource, StageExternalOutputsError, + StagePathNotDirectoryError, StagePathNotFoundError, + StagePathOutsideError) def check_stage_path(repo, path, is_wdir=False): diff --git a/dvc/tree/azure.py b/dvc/tree/azure.py index ee094360d1..7a026f1c45 100644 --- a/dvc/tree/azure.py +++ b/dvc/tree/azure.py @@ -3,11 +3,10 @@ import threading from datetime import datetime, timedelta -from funcy import cached_property, wrap_prop - from dvc.path_info import CloudURLInfo from dvc.progress import Tqdm from dvc.scheme import Schemes +from funcy import cached_property, wrap_prop from .base import BaseTree diff --git a/dvc/tree/gs.py b/dvc/tree/gs.py index c35a490b46..6607b8fad3 100644 --- a/dvc/tree/gs.py +++ b/dvc/tree/gs.py @@ -4,12 +4,11 @@ from datetime import timedelta from functools import wraps -from funcy import cached_property, wrap_prop - from dvc.exceptions import DvcException from dvc.path_info import CloudURLInfo from dvc.progress import Tqdm from dvc.scheme import Schemes +from funcy import cached_property, wrap_prop from .base import BaseTree diff --git a/dvc/updater.py b/dvc/updater.py index 1eda2a4c81..b874be952c 100644 --- a/dvc/updater.py +++ b/dvc/updater.py @@ -4,13 +4,12 @@ import time import colorama -from packaging import version - from dvc import __version__ from dvc.config import Config, to_bool from dvc.lock import LockError, make_lock from dvc.utils import boxify, env2bool from dvc.utils.pkg import PKG +from packaging import version logger = logging.getLogger(__name__) diff --git a/tests/func/test_add.py b/tests/func/test_add.py index b712d744c7..7c02a91d52 100644 --- a/tests/func/test_add.py +++ b/tests/func/test_add.py @@ -6,19 +6,14 @@ import time import colorama -import pytest -from mock import call, patch - import dvc as dvc_module +import pytest from dvc.cache import Cache from dvc.dvcfile import DVC_FILE_SUFFIX -from dvc.exceptions import ( - DvcException, - OutputDuplicationError, - OverlappingOutputPathsError, - RecursiveAddingWhileUsingFilename, - YAMLFileCorruptedError, -) +from dvc.exceptions import (DvcException, OutputDuplicationError, + OverlappingOutputPathsError, + RecursiveAddingWhileUsingFilename, + YAMLFileCorruptedError) from dvc.main import main from dvc.output.base import OutputAlreadyTrackedError, OutputIsStageFileError from dvc.repo import Repo as DvcRepo @@ -28,6 +23,7 @@ from dvc.utils import LARGE_DIR_SIZE, file_md5, relpath from dvc.utils.fs import path_isin from dvc.utils.yaml import load_yaml +from mock import call, patch from tests.basic_env import TestDvc from tests.utils import get_gitignore_content diff --git a/tests/func/test_ls.py b/tests/func/test_ls.py index 0f65c52f4a..db1a1404b6 100644 --- a/tests/func/test_ls.py +++ b/tests/func/test_ls.py @@ -3,7 +3,6 @@ import textwrap import pytest - from dvc.exceptions import PathMissingError from dvc.repo import Repo from dvc.scm.base import CloneError diff --git a/tests/func/test_repro_multistage.py b/tests/func/test_repro_multistage.py index c6875f270e..54ced05b18 100644 --- a/tests/func/test_repro_multistage.py +++ b/tests/func/test_repro_multistage.py @@ -4,13 +4,12 @@ import pytest import yaml -from funcy import lsplit - from dvc.dvcfile import PIPELINE_FILE, PIPELINE_LOCK from dvc.exceptions import CyclicGraphError from dvc.main import main from dvc.stage import PipelineStage from dvc.utils.yaml import dump_yaml, parse_yaml +from funcy import lsplit from tests.func import test_repro COPY_SCRIPT_FORMAT = dedent( diff --git a/tests/func/test_run_multistage.py b/tests/func/test_run_multistage.py index 8be4c3a045..7fe13782df 100644 --- a/tests/func/test_run_multistage.py +++ b/tests/func/test_run_multistage.py @@ -3,7 +3,6 @@ import pytest import yaml - from dvc.exceptions import InvalidArgumentError from dvc.repo import Repo from dvc.stage.exceptions import DuplicateStageName, InvalidStageName diff --git a/tests/remotes/azure.py b/tests/remotes/azure.py index b0b31b1d25..8cfd66f31a 100644 --- a/tests/remotes/azure.py +++ b/tests/remotes/azure.py @@ -3,7 +3,6 @@ import uuid import pytest - from dvc.path_info import CloudURLInfo from .base import Base diff --git a/tests/remotes/hdfs.py b/tests/remotes/hdfs.py index 9b5601b8da..27dd04b0f7 100644 --- a/tests/remotes/hdfs.py +++ b/tests/remotes/hdfs.py @@ -5,7 +5,6 @@ from contextlib import contextmanager import pytest - from dvc.path_info import URLInfo from .base import Base diff --git a/tests/unit/scm/test_git.py b/tests/unit/scm/test_git.py index 2f82dd04e7..44dbfc0d6f 100644 --- a/tests/unit/scm/test_git.py +++ b/tests/unit/scm/test_git.py @@ -1,7 +1,6 @@ import os import pytest - from tests.basic_env import TestDvcGit