Skip to content

Commit 51ad37c

Browse files
authored
Merge pull request #1 from LexMachinaInc/support-newer-flake8
Support newer flake8's flaky config detection
2 parents 5113b6f + 69bf291 commit 51ad37c

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

flake8_per_file/__init__.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,40 @@
88
"""
99

1010
import os.path
11+
import pathlib
1112
import subprocess
1213
import sys
1314

1415

16+
def find_cfg(arg):
17+
arg_path = pathlib.Path(arg).expanduser().resolve()
18+
for i in range(len(arg_path.parts)):
19+
possible_cfg_path = pathlib.Path(*arg_path.parts[:i]) / 'setup.cfg'
20+
if possible_cfg_path.is_file():
21+
return ('--config', possible_cfg_path)
22+
23+
return ()
24+
25+
1526
def main():
1627
my_flake8 = os.path.join(os.path.dirname(sys.argv[0]), 'flake8')
1728

1829
all_output = ''
1930
returncode = 0
31+
flake_args = []
2032
for arg in sys.argv[1:]:
33+
if arg.startswith('-'):
34+
flake_args.append(arg)
35+
continue
36+
2137
sp_result = subprocess.run(
22-
[my_flake8, arg],
38+
[my_flake8, *flake_args, *find_cfg(arg), arg],
2339
stdout=subprocess.PIPE,
2440
stderr=subprocess.STDOUT,
2541
encoding='utf8',
2642
)
2743
returncode = sp_result.returncode
2844
all_output += sp_result.stdout
2945

30-
sys.stderr.write(all_output)
46+
sys.stdout.write(all_output)
3147
sys.exit(returncode)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "flake8_per_file"
3-
version = "0.1.0"
3+
version = "0.2.0"
44
description = "Per file flake8"
55
authors = ["Gavin Carothers <[email protected]>"]
66
license = "Apache-2.0"

0 commit comments

Comments
 (0)