Skip to content

Commit

Permalink
dvc: comply with both flake8 and black
Browse files Browse the repository at this point in the history
flake8 provides some additional features like unused vars check, etc, so
it makes total sense to use it as well.

Signed-off-by: Ruslan Kuprieiev <ruslan@iterative.ai>
  • Loading branch information
efiop committed Feb 3, 2019
1 parent 1cc2e0e commit 4896f08
Show file tree
Hide file tree
Showing 69 changed files with 938 additions and 266 deletions.
4 changes: 4 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[flake8]
ignore = E203, E266, E501, W503, F403, F401
max-line-length = 79
select = B,C,E,F,W,T4,B9
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ repos:
hooks:
- id: black
language_version: python3.6
- repo: https://gitlab.com/pycqa/flake8
rev: master
hooks:
- id: flake8
language_version: python3.6
4 changes: 3 additions & 1 deletion dvc/analytics.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,9 @@ def _is_enabled(cmd=None):

core = config.config.get(Config.SECTION_CORE, {})
enabled = core.get(Config.SECTION_CORE_ANALYTICS, True)
logger.debug("Analytics is {}abled.".format("en" if enabled else "dis"))
logger.debug(
"Analytics is {}abled.".format("en" if enabled else "dis")
)
return enabled

@staticmethod
Expand Down
4 changes: 3 additions & 1 deletion dvc/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def __init__(self, project):
protected = config.get(Config.SECTION_CACHE_PROTECTED)

sect = {
Config.PRIVATE_CWD: config.get(Config.PRIVATE_CWD, project.dvc_dir),
Config.PRIVATE_CWD: config.get(
Config.PRIVATE_CWD, project.dvc_dir
),
Config.SECTION_REMOTE_URL: cache_dir,
Config.SECTION_CACHE_TYPE: cache_type,
Config.SECTION_CACHE_PROTECTED: protected,
Expand Down
12 changes: 10 additions & 2 deletions dvc/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,11 @@ def parse_args(argv=None):
"-q", "--quiet", action="store_true", default=False, help="Be quiet."
)
log_level_group.add_argument(
"-v", "--verbose", action="store_true", default=False, help="Be verbose."
"-v",
"--verbose",
action="store_true",
default=False,
help="Be verbose.",
)

# Main parser
Expand All @@ -116,7 +120,11 @@ def parse_args(argv=None):
# NOTE: On some python versions action='version' prints to stderr
# instead of stdout https://bugs.python.org/issue18920
parser.add_argument(
"-V", "--version", action=VersionAction, nargs=0, help="Show program's version."
"-V",
"--version",
action=VersionAction,
nargs=0,
help="Show program's version.",
)

# Sub commands
Expand Down
4 changes: 3 additions & 1 deletion dvc/command/add.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ def add_parser(subparsers, parent_parser):
default=False,
help="Recursively add each file under the directory.",
)
add_parser.add_argument("targets", nargs="+", help="Input files/directories.")
add_parser.add_argument(
"targets", nargs="+", help="Input files/directories."
)
add_parser.set_defaults(func=CmdAdd)
11 changes: 9 additions & 2 deletions dvc/command/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ def add_parser(subparsers, parent_parser):

CACHE_HELP = "Manage cache settings."
cache_parser = subparsers.add_parser(
"cache", parents=[parent_parser], description=CACHE_HELP, help=CACHE_HELP
"cache",
parents=[parent_parser],
description=CACHE_HELP,
help=CACHE_HELP,
)

cache_subparsers = cache_parser.add_subparsers(
Expand All @@ -42,7 +45,11 @@ def add_parser(subparsers, parent_parser):
help=CACHE_DIR_HELP,
)
cache_dir_parser.add_argument(
"-u", "--unset", default=False, action="store_true", help="Unset option."
"-u",
"--unset",
default=False,
action="store_true",
help="Unset option.",
)
cache_dir_parser.add_argument(
"value",
Expand Down
4 changes: 3 additions & 1 deletion dvc/command/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ def run(self):
else:
for target in self.args.targets:
self.project.checkout(
target=target, with_deps=self.args.with_deps, force=self.args.force
target=target,
with_deps=self.args.with_deps,
force=self.args.force,
)
return 0

Expand Down
14 changes: 11 additions & 3 deletions dvc/command/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ def _set(self, section, opt, value):
self.config.set(self.configobj, section, opt, value)
self.config.save(self.configobj)
except DvcException:
logger.error("failed to set '{}.{}' to '{}'".format(section, opt, value))
logger.error(
"failed to set '{}.{}' to '{}'".format(section, opt, value)
)
return 1
return 0

Expand Down Expand Up @@ -104,8 +106,14 @@ def add_parser(subparsers, parent_parser):
help=CONFIG_HELP,
)
config_parser.add_argument(
"-u", "--unset", default=False, action="store_true", help="Unset option."
"-u",
"--unset",
default=False,
action="store_true",
help="Unset option.",
)
config_parser.add_argument("name", help="Option name.")
config_parser.add_argument("value", nargs="?", default=None, help="Option value.")
config_parser.add_argument(
"value", nargs="?", default=None, help="Option value."
)
config_parser.set_defaults(func=CmdConfig)
5 changes: 4 additions & 1 deletion dvc/command/daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ def run(self):
def add_parser(subparsers, parent_parser):
DAEMON_HELP = "Service daemon."
daemon_parser = subparsers.add_parser(
"daemon", parents=[parent_parser], description=DAEMON_HELP, help=DAEMON_HELP
"daemon",
parents=[parent_parser],
description=DAEMON_HELP,
help=DAEMON_HELP,
)

daemon_subparsers = daemon_parser.add_subparsers(
Expand Down
27 changes: 21 additions & 6 deletions dvc/command/data_sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,14 @@ def add_parser(subparsers, parent_parser):
# Pull
PULL_HELP = "Pull data files from the cloud."
pull_parser = subparsers.add_parser(
"pull", parents=[parent_cache_parser], description=PULL_HELP, help=PULL_HELP
"pull",
parents=[parent_cache_parser],
description=PULL_HELP,
help=PULL_HELP,
)
pull_parser.add_argument(
"-r", "--remote", help="Remote repository to pull from."
)
pull_parser.add_argument("-r", "--remote", help="Remote repository to pull from.")
pull_parser.add_argument(
"-a",
"--all-branches",
Expand Down Expand Up @@ -149,9 +154,14 @@ def add_parser(subparsers, parent_parser):
# Push
PUSH_HELP = "Push data files to the cloud."
push_parser = subparsers.add_parser(
"push", parents=[parent_cache_parser], description=PUSH_HELP, help=PUSH_HELP
"push",
parents=[parent_cache_parser],
description=PUSH_HELP,
help=PUSH_HELP,
)
push_parser.add_argument(
"-r", "--remote", help="Remote repository to push to."
)
push_parser.add_argument("-r", "--remote", help="Remote repository to push to.")
push_parser.add_argument(
"-a",
"--all-branches",
Expand Down Expand Up @@ -185,9 +195,14 @@ def add_parser(subparsers, parent_parser):
# Fetch
FETCH_HELP = "Fetch data files from the cloud."
fetch_parser = subparsers.add_parser(
"fetch", parents=[parent_cache_parser], description=FETCH_HELP, help=FETCH_HELP
"fetch",
parents=[parent_cache_parser],
description=FETCH_HELP,
help=FETCH_HELP,
)
fetch_parser.add_argument(
"-r", "--remote", help="Remote repository to fetch from."
)
fetch_parser.add_argument("-r", "--remote", help="Remote repository to fetch from.")
fetch_parser.add_argument(
"-a",
"--all-branches",
Expand Down
14 changes: 11 additions & 3 deletions dvc/command/destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,20 @@ def run_cmd(self):

def add_parser(subparsers, parent_parser):
DESTROY_HELP = (
"Destroy dvc. Will remove all project's information, " "data files and cache."
"Destroy dvc. Will remove all project's information, "
"data files and cache."
)
destroy_parser = subparsers.add_parser(
"destroy", parents=[parent_parser], description=DESTROY_HELP, help=DESTROY_HELP
"destroy",
parents=[parent_parser],
description=DESTROY_HELP,
help=DESTROY_HELP,
)
destroy_parser.add_argument(
"-f", "--force", action="store_true", default=False, help="Force destruction."
"-f",
"--force",
action="store_true",
default=False,
help="Force destruction.",
)
destroy_parser.set_defaults(func=CmdDestroy)
5 changes: 4 additions & 1 deletion dvc/command/imp.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ def run(self):
def add_parser(subparsers, parent_parser):
IMPORT_HELP = "Import files from URL."
import_parser = subparsers.add_parser(
"import", parents=[parent_parser], description=IMPORT_HELP, help=IMPORT_HELP
"import",
parents=[parent_parser],
description=IMPORT_HELP,
help=IMPORT_HELP,
)
import_parser.add_argument(
"url",
Expand Down
4 changes: 3 additions & 1 deletion dvc/command/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def run_cmd(self):

def add_parser(subparsers, parent_parser):
"""Setup parser for `dvc init`."""
INIT_HELP = "Initialize dvc over a directory " "(should already be a git dir)."
INIT_HELP = (
"Initialize dvc over a directory " "(should already be a git dir)."
)
init_parser = subparsers.add_parser(
"init", parents=[parent_parser], description=INIT_HELP, help=INIT_HELP
)
Expand Down
5 changes: 4 additions & 1 deletion dvc/command/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ def run_cmd(self):
def add_parser(subparsers, parent_parser):
INSTALL_HELP = "Install dvc hooks into the repository."
install_parser = subparsers.add_parser(
"install", parents=[parent_parser], description=INSTALL_HELP, help=INSTALL_HELP
"install",
parents=[parent_parser],
description=INSTALL_HELP,
help=INSTALL_HELP,
)
install_parser.set_defaults(func=CmdInstall)
9 changes: 7 additions & 2 deletions dvc/command/lock.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ def run(self, unlock=False):
self.project.lock_stage(target, unlock=unlock)
except DvcException:
logger.error(
"failed to {}lock '{}'".format("un" if unlock else "", target)
"failed to {}lock '{}'".format(
"un" if unlock else "", target
)
)

return 1
Expand All @@ -39,7 +41,10 @@ def add_parser(subparsers, parent_parser):

UNLOCK_HELP = "Unlock DVC file."
unlock_parser = subparsers.add_parser(
"unlock", parents=[parent_parser], description=UNLOCK_HELP, help=UNLOCK_HELP
"unlock",
parents=[parent_parser],
description=UNLOCK_HELP,
help=UNLOCK_HELP,
)
unlock_parser.add_argument("targets", nargs="+", help="DVC files.")
unlock_parser.set_defaults(func=CmdUnlock)
12 changes: 9 additions & 3 deletions dvc/command/metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ def run(self):
class CmdMetricsAdd(CmdBase):
def run(self):
try:
self.project.metrics_add(self.args.path, self.args.type, self.args.xpath)
self.project.metrics_add(
self.args.path, self.args.type, self.args.xpath
)
except DvcException:
msg = "failed to add metric file '{}'".format(self.args.path)
logger.error(msg)
Expand All @@ -83,11 +85,15 @@ def run(self):
def add_parser(subparsers, parent_parser):
METRICS_HELP = "Get metrics from all branches."
metrics_parser = subparsers.add_parser(
"metrics", parents=[parent_parser], description=METRICS_HELP, help=METRICS_HELP
"metrics",
parents=[parent_parser],
description=METRICS_HELP,
help=METRICS_HELP,
)

metrics_subparsers = metrics_parser.add_subparsers(
dest="cmd", help="Use dvc metrics CMD --help for command-specific help."
dest="cmd",
help="Use dvc metrics CMD --help for command-specific help.",
)

fix_subparsers(metrics_subparsers)
Expand Down
8 changes: 6 additions & 2 deletions dvc/command/move.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ def run(self):
try:
self.project.move(self.args.src, self.args.dst)
except DvcException:
msg = "failed to move '{}' -> '{}'".format(self.args.src, self.args.dst)
msg = "failed to move '{}' -> '{}'".format(
self.args.src, self.args.dst
)
logger.error(msg)
return 1
return 0
Expand All @@ -26,6 +28,8 @@ def add_parser(subparsers, parent_parser):
move_parser = subparsers.add_parser(
"move", parents=[parent_parser], description=description, help=help
)
move_parser.add_argument("src", help="Source path to a data file or directory.")
move_parser.add_argument(
"src", help="Source path to a data file or directory."
)
move_parser.add_argument("dst", help="Destination path.")
move_parser.set_defaults(func=CmdMove)
25 changes: 19 additions & 6 deletions dvc/command/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ def __build_graph(self, target, commands, outs):
stage = Stage.load(self.project, target)
node = os.path.relpath(stage.path, self.project.root_dir)

pipelines = list(filter(lambda g: node in g.nodes(), self.project.pipelines()))
pipelines = list(
filter(lambda g: node in g.nodes(), self.project.pipelines())
)

assert len(pipelines) == 1
G = pipelines[0]
Expand Down Expand Up @@ -99,10 +101,15 @@ def run(self, unlock=False):
for target in self.args.targets:
try:
if self.args.ascii:
self._show_ascii(target, self.args.commands, self.args.outs)
self._show_ascii(
target, self.args.commands, self.args.outs
)
elif self.args.dot:
self.__write_dot(
target, self.args.commands, self.args.outs, self.args.dot
target,
self.args.commands,
self.args.outs,
self.args.dot,
)
else:
self._show(target, self.args.commands, self.args.outs)
Expand Down Expand Up @@ -139,7 +146,8 @@ def add_parser(subparsers, parent_parser):
)

pipeline_subparsers = pipeline_parser.add_subparsers(
dest="cmd", help="Use dvc pipeline CMD --help for command-specific help."
dest="cmd",
help="Use dvc pipeline CMD --help for command-specific help.",
)

fix_subparsers(pipeline_subparsers)
Expand Down Expand Up @@ -167,9 +175,14 @@ def add_parser(subparsers, parent_parser):
help="Print output files instead of paths to DVC files.",
)
pipeline_show_parser.add_argument(
"--ascii", action="store_true", default=False, help="Output DAG as ASCII."
"--ascii",
action="store_true",
default=False,
help="Output DAG as ASCII.",
)
pipeline_show_parser.add_argument(
"--dot", help="Write DAG in .dot format."
)
pipeline_show_parser.add_argument("--dot", help="Write DAG in .dot format.")
pipeline_show_parser.add_argument(
"targets", nargs="*", help="DVC files. 'Dvcfile' by default."
)
Expand Down
Loading

0 comments on commit 4896f08

Please sign in to comment.