Skip to content

Commit

Permalink
dvc: modify flake8 configuration
Browse files Browse the repository at this point in the history
Signed-off-by: Ruslan Kuprieiev <ruslan@iterative.ai>
  • Loading branch information
efiop committed Feb 22, 2019
1 parent 281aa61 commit 9ca00ad
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 54 deletions.
5 changes: 4 additions & 1 deletion .flake8
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
[flake8]
ignore = E203, E266, E501, W503, F403, F401
ignore =
E203, # Whitespace before ':'
E266, # Too many leading '#' for block comment
W503, # Line break occurred before a binary operator
max-line-length = 79
select = B,C,E,F,W,T4,B9
10 changes: 8 additions & 2 deletions dvc/command/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,10 @@ def run(self):


def add_parser(subparsers, parent_parser):
METRICS_HELP = "A set of commands to add, manage, collect and display project metrics."
METRICS_HELP = (
"A set of commands to add, manage, collect and display project "
"metrics."
)
metrics_parser = subparsers.add_parser(
"metrics",
parents=[parent_parser],
Expand Down Expand Up @@ -125,7 +128,10 @@ def add_parser(subparsers, parent_parser):
"--recursive",
action="store_true",
default=False,
help="If path is a directory, recursively search and process metric files in path.",
help=(
"If path is a directory, recursively search and process metric "
"files in path."
),
)
metrics_show_parser.set_defaults(func=CmdMetricsShow)

Expand Down
5 changes: 2 additions & 3 deletions dvc/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ def _ask(prompt, limited_to=None):
return answer

print(
"Your response must be one of: {options}. Please try again.".format(
options=limited_to
)
"Your response must be one of: {options}. "
"Please try again.".format(options=limited_to)
)


Expand Down
8 changes: 2 additions & 6 deletions dvc/remote/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

from dvc.utils.compat import str

import os
import re
import errno
import posixpath
from multiprocessing import cpu_count

Expand Down Expand Up @@ -83,10 +81,8 @@ def __init__(self, repo, config):
"\n"
"If you have installed dvc from a binary package and you "
"are still seeing this message, please report it to us "
"using https://github.com/iterative/dvc/issues. Thank you!".format(
url, missing, " ".join(missing), self.scheme
)
)
"using https://github.com/iterative/dvc/issues. Thank you!"
).format(url, missing, " ".join(missing), self.scheme)
raise RemoteMissingDepsError(msg)

def __repr__(self):
Expand Down
1 change: 0 additions & 1 deletion dvc/remote/gs.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

try:
from google.cloud import storage
from google.auth.credentials import Credentials
except ImportError:
storage = None

Expand Down
5 changes: 2 additions & 3 deletions dvc/remote/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,8 @@ def _etag(self, url):

if not etag:
raise DvcException(
"could not find an ETag or Content-MD5 header for '{url}'".format(
url=url
)
"could not find an ETag or "
"Content-MD5 header for '{url}'".format(url=url)
)

if etag.startswith("W/"):
Expand Down
18 changes: 10 additions & 8 deletions dvc/repo/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ def _welcome_message():
border_color="red",
)

logger.info(
msg = (
"{yellow}What's next?{nc}\n"
"{yellow}------------{nc}\n"
"- Check out the documentation: {blue}https://dvc.org/doc{nc}\n"
"- Get help and share ideas: {blue}https://dvc.org/chat{nc}\n"
"- Star us on GitHub: {blue}https://github.com/iterative/dvc{nc}".format(
yellow=colorama.Fore.YELLOW,
blue=colorama.Fore.BLUE,
nc=colorama.Fore.RESET,
)
"- Star us on GitHub: {blue}https://github.com/iterative/dvc{nc}"
).format(
yellow=colorama.Fore.YELLOW,
blue=colorama.Fore.BLUE,
nc=colorama.Fore.RESET,
)

logger.info(msg)


def init(root_dir=os.curdir, no_scm=False, force=False):
"""
Expand All @@ -56,8 +58,8 @@ def init(root_dir=os.curdir, no_scm=False, force=False):
scm = SCM(root_dir)
if type(scm) == Base and not no_scm:
raise InitError(
"{repo} is not tracked by any supported scm tool"
" (e.g. git). Use '--no-scm' if you don't want to use any scm.".format(
"{repo} is not tracked by any supported scm tool (e.g. git). "
"Use '--no-scm' if you don't want to use any scm.".format(
repo=root_dir
)
)
Expand Down
5 changes: 4 additions & 1 deletion dvc/repo/metrics/modify.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ def modify(repo, path, typ=None, xpath=None, delete=False):
if typ is not None:
typ = typ.lower().strip()
if typ not in ["raw", "json", "csv", "tsv", "hcsv", "htsv"]:
msg = "metric type '{typ}' is not supported, must be one of [{types}]"
msg = (
"metric type '{typ}' is not supported, "
"must be one of [{types}]"
)
raise DvcException(
msg.format(typ=typ, types=", ".join(supported_types))
)
Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/move.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from dvc.exceptions import MoveNotDataSourceError, DvcException
from dvc.exceptions import MoveNotDataSourceError


def _expand_target_path(from_path, to_path):
Expand Down
12 changes: 6 additions & 6 deletions dvc/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,9 @@ def _changed_deps(self):

if self.is_callback:
logger.warning(
"Dvc file '{fname}' is a 'callback' stage (has a command and"
" no dependencies) and thus always considered as changed.".format(
fname=self.relpath
)
"Dvc file '{fname}' is a 'callback' stage "
"(has a command and no dependencies) and thus always "
"considered as changed.".format(fname=self.relpath)
)
return True

Expand Down Expand Up @@ -265,8 +264,9 @@ def reproduce(
# Removing outputs only if we actually have command to reproduce
self.remove_outs(ignore_remove=False)

msg = "Going to reproduce '{stage}'. Are you sure you want to continue?".format(
stage=self.relpath
msg = (
"Going to reproduce '{stage}'. "
"Are you sure you want to continue?".format(stage=self.relpath)
)

if interactive and not prompt.confirm(msg):
Expand Down
1 change: 0 additions & 1 deletion dvc/updater.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from __future__ import unicode_literals
from dvc.utils.compat import str

import sys
import os
Expand Down
7 changes: 5 additions & 2 deletions dvc/utils/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,17 @@ def encode(u, encoding=None):
return u.encode(encoding, "replace")


# NOTE: cast_bytes_py2 is taken from https://github.com/ipython/ipython_genutils
# NOTE: cast_bytes_py2 is taken from
# https://github.com/ipython/ipython_genutils
def cast_bytes(s, encoding=None):
if not isinstance(s, bytes):
return encode(s, encoding)
return s


# NOTE _makedirs is taken from https://github.com/python/cpython/blob/3ce3dea60646d8a5a1c952469a2eb65f937875b3/Lib/os.py#L196-L226
# NOTE _makedirs is taken from
# https://github.com/python/cpython/blob/
# 3ce3dea60646d8a5a1c952469a2eb65f937875b3/Lib/os.py#L196-L226
def _makedirs(name, mode=0o777, exist_ok=False):
head, tail = os.path.split(name)
if not tail:
Expand Down
1 change: 0 additions & 1 deletion tests/test_add.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from mock import patch

from dvc.main import main
from dvc.state import State
from dvc.utils import file_md5
from dvc.stage import Stage
from dvc.exceptions import DvcException
Expand Down
5 changes: 4 additions & 1 deletion tests/test_checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,10 @@ def test(self):
msg = str(exc)
self.assertEqual(
msg,
"'gitbranch' does not exist. Did you mean 'git checkout gitbranch'?",
(
"'gitbranch' does not exist. "
"Did you mean 'git checkout gitbranch'?"
),
)

try:
Expand Down
1 change: 0 additions & 1 deletion tests/test_commit.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import yaml
import shutil

from tests.basic_env import TestDvc
from dvc.stage import StageCommitError
Expand Down
10 changes: 6 additions & 4 deletions tests/test_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,9 @@ def test_wrong_type_add(self):
ret = main(["metrics", "add", "metric.unknown", "-t", "unknown"])
self.assertEqual(ret, 1)
self.assertIn(
"failed to add metric file 'metric.unknown' - metric type 'unknown'"
" is not supported, must be one of [raw, json, csv, tsv, hcsv, htsv]",
"failed to add metric file 'metric.unknown' - metric type "
"'unknown' is not supported, must be one of "
"[raw, json, csv, tsv, hcsv, htsv]",
logger.logger.handlers[1].stream.getvalue(),
)

Expand Down Expand Up @@ -394,8 +395,9 @@ def test_wrong_type_modify(self):
)
self.assertEqual(ret, 1)
self.assertIn(
"failed to modify metric file settings - metric type 'unknown'"
" is not supported, must be one of [raw, json, csv, tsv, hcsv, htsv]",
"failed to modify metric file settings - metric type "
"'unknown' is not supported, must be one of "
"[raw, json, csv, tsv, hcsv, htsv]",
logger.logger.handlers[1].stream.getvalue(),
)

Expand Down
25 changes: 14 additions & 11 deletions tests/test_repro.py
Original file line number Diff line number Diff line change
Expand Up @@ -803,13 +803,15 @@ def check_already_cached(self, stage):

patch_run = patch.object(stage, "_run", wraps=stage._run)

with self.dvc.state, patch_download as mock_download, patch_checkout as mock_checkout, patch_run as mock_run:
with self.dvc.state:
with patch_download as mock_download:
with patch_checkout as mock_checkout:
with patch_run as mock_run:
stage.run()

stage.run()

mock_run.assert_not_called()
mock_download.assert_not_called()
mock_checkout.assert_called_once()
mock_run.assert_not_called()
mock_download.assert_not_called()
mock_checkout.assert_called_once()

def corrupted_cache(self):
os.unlink("bar.dvc")
Expand All @@ -827,12 +829,13 @@ def corrupted_cache(self):

patch_run = patch.object(stage, "_run", wraps=stage._run)

with self.dvc.state, patch_checkout as mock_checkout, patch_run as mock_run:

stage.run()
with self.dvc.state:
with patch_checkout as mock_checkout:
with patch_run as mock_run:
stage.run()

mock_run.assert_called_once()
mock_checkout.assert_not_called()
mock_run.assert_called_once()
mock_checkout.assert_not_called()

@patch("dvc.prompt.confirm", return_value=True)
def test(self, mock_prompt):
Expand Down
4 changes: 3 additions & 1 deletion tests/unit/remote/azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ class TestRemoteAzure(TestCase):
)

def test_init_compat(self):
url = "azure://ContainerName={container_name};{connection_string}".format(
url = (
"azure://ContainerName={container_name};{connection_string}"
).format(
container_name=self.container_name,
connection_string=self.connection_string,
)
Expand Down

0 comments on commit 9ca00ad

Please sign in to comment.