Skip to content

Commit fbe0252

Browse files
chore: Use flake8 for linting (#1191)
* Switch from pyflakes to flake8 for linting in pre-commit hooks and CI - Use flake8 in 'lint' extra * Add flake8 config options to setup.cfg (as opposed to .flake8) * Remove code that existed only to placate pyflakes
1 parent 7cc1534 commit fbe0252

File tree

14 files changed

+34
-23
lines changed

14 files changed

+34
-23
lines changed

.github/workflows/lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ jobs:
2121
python -m pip install --upgrade pip setuptools wheel
2222
python -m pip install --ignore-installed -U -q --no-cache-dir -e .[lint]
2323
python -m pip list
24-
- name: Lint with Pyflakes
24+
- name: Lint with flake8
2525
run: |
26-
python -m pyflakes .
26+
python -m flake8 .
2727
- name: Lint with Black
2828
run: |
2929
black --check --diff --verbose .

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ repos:
33
rev: 20.8b1
44
hooks:
55
- id: black
6+
- repo: https://gitlab.com/pycqa/flake8
7+
rev: 3.8.4
8+
hooks:
9+
- id: flake8
610
- repo: https://github.com/asottile/pyupgrade
711
rev: v2.7.4
812
hooks:

setup.cfg

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,3 +58,12 @@ source-dir = docs
5858
build-dir = docs/_build
5959
all-files = 1
6060
warning-is-error = 1
61+
62+
[flake8]
63+
# E203: whitespace before ':'
64+
# E402: module level import not at top of file
65+
# E501: line too long
66+
extend-ignore = E203, E402, E501
67+
max-line-length = 88
68+
count = True
69+
statistics = True

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
)
2121
)
2222
extras_require['contrib'] = sorted({'matplotlib', 'requests'})
23-
extras_require['lint'] = sorted({'pyflakes', 'black'})
23+
extras_require['lint'] = sorted({'flake8', 'black'})
2424

2525
extras_require['test'] = sorted(
2626
set(

src/pyhf/contrib/cli.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ def cli():
2020
2121
$ python -m pip install pyhf[contrib]
2222
"""
23-
from . import utils # Guard CLI from missing extra
24-
25-
# TODO: https://github.com/scikit-hep/pyhf/issues/863
26-
_ = utils # Placate pyflakes
23+
from . import utils # Guard CLI from missing extra # noqa: F401
2724

2825

2926
@cli.command()

src/pyhf/infer/__init__.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,6 @@ def hypotest(
186186
return tuple(_returns) if len(_returns) > 1 else _returns[0]
187187

188188

189-
from . import intervals
189+
from . import intervals # noqa: F401
190190

191-
# TODO: Can remove intervals when switch to flake8 (Issue #863)
192-
__all__ = ["hypotest", "intervals"]
191+
__all__ = ["hypotest"]

src/pyhf/infer/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@ def create_calculator(calctype, *args, **kwargs):
3636
Returns:
3737
calculator (:obj:`object`): A calculator.
3838
"""
39-
return {'asymptotics': AsymptoticCalculator, 'toybased': ToyCalculator,}[
40-
calctype
41-
](*args, **kwargs)
39+
return {'asymptotics': AsymptoticCalculator, 'toybased': ToyCalculator}[calctype](
40+
*args, **kwargs
41+
)

src/pyhf/optimize/opt_minuit.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ def _get_minimizer(
5252

5353
# Minuit requires jac=callable
5454
if do_grad:
55-
wrapped_objective = lambda pars: objective_and_grad(pars)[0]
56-
jac = lambda pars: objective_and_grad(pars)[1]
55+
wrapped_objective = lambda pars: objective_and_grad(pars)[0] # noqa: E731
56+
jac = lambda pars: objective_and_grad(pars)[1] # noqa: E731
5757
else:
5858
wrapped_objective = objective_and_grad
5959
jac = None

src/pyhf/pdf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ def logpdf(self, pars, data):
731731
): # force to be not scalar, should we changed with #522
732732
return tensorlib.reshape(result, (1,))
733733
return result
734-
except:
734+
except: # noqa: E722
735735
log.error(
736736
f'eval failed for data {tensorlib.tolist(data)} pars: {tensorlib.tolist(pars)}'
737737
)

src/pyhf/readxml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def import_root_histogram(rootdir, filename, path, name, filecache=None):
4040
path = path or ''
4141
path = path.strip('/')
4242
fullpath = str(Path(rootdir).joinpath(filename))
43-
if not fullpath in filecache:
43+
if fullpath not in filecache:
4444
f = uproot.open(fullpath)
4545
filecache[fullpath] = f
4646
else:

0 commit comments

Comments
 (0)