Skip to content

Commit

Permalink
Add flake8 extensions (iterative#4067)
Browse files Browse the repository at this point in the history
* remove unnecessary generators/comprehensions

* Use dict literals

* remove unused variables

* misc fixes

ignore .iteritems, is a false +ve
remove function call in default argument

* Flake8 config: complexity, show source on err, show err counts

* flake8: add extensions

* remove flake8-string-format

* Add flake8-debugger support

* Add flake8-string-format extension

* remove flake8-debugger

It's having some problems to install on Windows in Travis
  • Loading branch information
skshetry authored Jun 18, 2020
1 parent 3a469f2 commit 4af3919
Show file tree
Hide file tree
Showing 14 changed files with 107 additions and 97 deletions.
125 changes: 65 additions & 60 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,63 +1,68 @@
repos:
- hooks:
- id: black
language_version: python3
repo: https://github.com/ambv/black
rev: 19.10b0
- repo: https://github.com/asottile/seed-isort-config
- hooks:
- id: black
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
- hooks:
- id: flake8
language_version: python3
repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
- hooks:
- args:
- -i
- '2'
id: beautysh
language_version: python3
repo: https://github.com/lovesegfault/beautysh
rev: master
- hooks:
- args:
- git-hook
- pre-commit
entry: dvc
id: dvc-pre-commit
language: system
name: DVC pre-commit
stages:
- commit
verbose: true
require_serial: true
- args:
- git-hook
- pre-push
entry: dvc
id: dvc-pre-push
language: system
name: DVC pre-push
stages:
- push
require_serial: true
- always_run: true
args:
- git-hook
- post-checkout
entry: dvc
id: dvc-post-checkout
language: system
minimum_pre_commit_version: 2.2.0
name: DVC post-checkout
stages:
- post-checkout
require_serial: true
repo: local
- id: seed-isort-config
- hooks:
- id: isort
language_version: python3
repo: https://github.com/timothycrosley/isort
rev: 4.3.21
- hooks:
- id: flake8
language_version: python3
additional_dependencies:
- flake8-bugbear
- flake8-comprehensions
- flake8-debugger
- flake8-string-format
repo: https://gitlab.com/pycqa/flake8
rev: 3.7.9
- hooks:
- args:
- -i
- "2"
id: beautysh
language_version: python3
repo: https://github.com/lovesegfault/beautysh
rev: master
- hooks:
- args:
- git-hook
- pre-commit
entry: dvc
id: dvc-pre-commit
language: system
name: DVC pre-commit
stages:
- commit
verbose: true
require_serial: true
- args:
- git-hook
- pre-push
entry: dvc
id: dvc-pre-push
language: system
name: DVC pre-push
stages:
- push
require_serial: true
- always_run: true
args:
- git-hook
- post-checkout
entry: dvc
id: dvc-post-checkout
language: system
minimum_pre_commit_version: 2.2.0
name: DVC post-checkout
stages:
- post-checkout
require_serial: true
repo: local
2 changes: 1 addition & 1 deletion dvc/command/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def _show_md(diff):
entries = diff.get(status, [])
if not entries:
continue
paths = sorted([entry["path"] for entry in entries])
paths = sorted(entry["path"] for entry in entries)
for path in paths:
rows.append([status, path])

Expand Down
2 changes: 1 addition & 1 deletion dvc/dagascii.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def _build_sugiyama_layout(vertexes, edges):
vertex.view = VertexViewer(vertex.data)

# NOTE: determine min box length to create the best layout
minw = min([v.view.w for v in vertexes])
minw = min(v.view.w for v in vertexes)

for edge in edges:
edge.view = EdgeViewer()
Expand Down
2 changes: 1 addition & 1 deletion dvc/remote/ssh/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def walk(self, directory, topdown=True):
yield directory, dirs, nondirs

def walk_files(self, directory):
for root, dirs, files in self.walk(directory):
for root, _, files in self.walk(directory):
for fname in files:
yield posixpath.join(root, fname)

Expand Down
2 changes: 1 addition & 1 deletion dvc/repo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def _collect_graph(self, stages):
continue

dep_key = dep.path_info.parts
overlapping = list(n.value for n in outs.prefixes(dep_key))
overlapping = [n.value for n in outs.prefixes(dep_key)]
if outs.has_subtrie(dep_key):
overlapping.extend(outs.values(prefix=dep_key))

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 @@ -196,7 +196,7 @@ def raw(self, header=True, **kwargs):
)

fieldnames = reader.fieldnames
data = [row for row in reader]
data = list(reader)

return [
OrderedDict([(field, data_point[field]) for field in fieldnames])
Expand Down
14 changes: 6 additions & 8 deletions dvc/repo/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def _walk(self, root, trie, topdown=True):
files = []

root_len = len(root.parts)
for key, out in trie.iteritems(prefix=root.parts):
for key, out in trie.iteritems(prefix=root.parts): # noqa: B301
if key == root.parts:
continue

Expand All @@ -153,14 +153,12 @@ def _walk(self, root, trie, topdown=True):

files.append(name)

if topdown:
dirs = list(dirs)
yield root.fspath, dirs, files
assert topdown
dirs = list(dirs)
yield root.fspath, dirs, files

for dname in dirs:
yield from self._walk(root / dname, trie)
else:
assert False
for dname in dirs:
yield from self._walk(root / dname, trie)

def walk(
self, top, topdown=True, onerror=None, download_callback=None, **kwargs
Expand Down
34 changes: 16 additions & 18 deletions dvc/scm/git/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,24 +37,22 @@ def update_git(self, op_code, cur_count, max_count=None, message=""):
def code2desc(op_code):
from git import RootUpdateProgress as OP

ops = dict(
(
(OP.COUNTING, "Counting"),
(OP.COMPRESSING, "Compressing"),
(OP.WRITING, "Writing"),
(OP.RECEIVING, "Receiving"),
(OP.RESOLVING, "Resolving"),
(OP.FINDING_SOURCES, "Finding sources"),
(OP.CHECKING_OUT, "Checking out"),
(OP.CLONE, "Cloning"),
(OP.FETCH, "Fetching"),
(OP.UPDWKTREE, "Updating working tree"),
(OP.REMOVE, "Removing"),
(OP.PATHCHANGE, "Changing path"),
(OP.URLCHANGE, "Changing URL"),
(OP.BRANCHCHANGE, "Changing branch"),
)
)
ops = {
OP.COUNTING: "Counting",
OP.COMPRESSING: "Compressing",
OP.WRITING: "Writing",
OP.RECEIVING: "Receiving",
OP.RESOLVING: "Resolving",
OP.FINDING_SOURCES: "Finding sources",
OP.CHECKING_OUT: "Checking out",
OP.CLONE: "Cloning",
OP.FETCH: "Fetching",
OP.UPDWKTREE: "Updating working tree",
OP.REMOVE: "Removing",
OP.PATHCHANGE: "Changing path",
OP.URLCHANGE: "Changing URL",
OP.BRANCHCHANGE: "Changing branch",
}
return ops.get(op_code & OP.OP_MASK, "")


Expand Down
3 changes: 2 additions & 1 deletion dvc/scm/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ def walk_files(self, top):
class WorkingTree(BaseTree):
"""Proxies the repo file access methods to working tree files"""

def __init__(self, repo_root=os.getcwd()):
def __init__(self, repo_root=None):
repo_root = repo_root or os.getcwd()
self.repo_root = repo_root

@property
Expand Down
2 changes: 1 addition & 1 deletion dvc/stage/serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _serialize_params_values(params: List[ParamsDependency]):
def to_pipeline_file(stage: "PipelineStage"):
wdir = resolve_wdir(stage.wdir, stage.path)
params, deps = split_params_deps(stage)
deps = sorted([d.def_path for d in deps])
deps = sorted(d.def_path for d in deps)
params = _serialize_params_keys(params)

outs, metrics, plots = _serialize_outs(stage.outs)
Expand Down
7 changes: 6 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,13 @@ ignore=
E203, # Whitespace before ':'
E266, # Too many leading '#' for block comment
W503, # Line break occurred before a binary operator
P1, # unindexed parameters in the str.format, see:
# https://pypi.org/project/flake8-string-format/
max_line_length=79
select=B,C,E,F,W,T4,B9
max-complexity = 15
select=B,C,E,F,W,T4,B902,T,P
show_source=true
count=true

[isort]
include_trailing_comma=true
Expand Down
3 changes: 3 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@ def run(self):
"moto==1.3.14.dev464",
"rangehttpserver==1.2.0",
"beautifulsoup4==4.4.0",
"flake8-bugbear",
"flake8-comprehensions",
"flake8-string-format",
]

if (sys.version_info) >= (3, 6):
Expand Down
2 changes: 1 addition & 1 deletion tests/func/test_dvcfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_stage_collection(tmp_dir, dvc):
always_changed=True,
single_stage=True,
)
assert {s for s in dvc.stages} == {stage1, stage3, stage2}
assert set(dvc.stages) == {stage1, stage3, stage2}


def test_remove_stage(tmp_dir, dvc, run_copy):
Expand Down
4 changes: 2 additions & 2 deletions tests/func/test_gc.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def _test_gc(self):
class TestGCBranchesTags(TestDvcGit):
def _check_cache(self, num):
total = 0
for root, dirs, files in os.walk(os.path.join(".dvc", "cache")):
for _, _, files in os.walk(os.path.join(".dvc", "cache")):
total += len(files)
self.assertEqual(total, num)

Expand Down Expand Up @@ -112,7 +112,7 @@ def test(self):
class TestGCMultipleDvcRepos(TestDvcGit):
def _check_cache(self, num):
total = 0
for root, dirs, files in os.walk(os.path.join(".dvc", "cache")):
for _, _, files in os.walk(os.path.join(".dvc", "cache")):
total += len(files)
self.assertEqual(total, num)

Expand Down

0 comments on commit 4af3919

Please sign in to comment.