Skip to content

Commit

Permalink
ci: add more flake8 plugins and fix issues
Browse files Browse the repository at this point in the history
Also cleans up the pylint config file
  • Loading branch information
redeboer committed Apr 28, 2021
1 parent 8f94021 commit feefdfb
Show file tree
Hide file tree
Showing 16 changed files with 54 additions and 48 deletions.
4 changes: 4 additions & 0 deletions .constraints/py3.6.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,12 @@ filelock==3.0.12
flake8-blind-except==0.2.0
flake8-bugbear==21.4.3
flake8-builtins==1.5.3
flake8-comprehensions==3.4.0
flake8-plugin-utils==1.3.1
flake8-polyfill==1.0.2
flake8-pytest-style==1.4.1
flake8-rst-docstrings==0.2.1
flake8-use-fstring==1.1
flake8==3.9.1
flatbuffers==1.12
fuzzywuzzy==0.18.0
Expand Down
4 changes: 4 additions & 0 deletions .constraints/py3.7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ filelock==3.0.12
flake8-blind-except==0.2.0
flake8-bugbear==21.4.3
flake8-builtins==1.5.3
flake8-comprehensions==3.4.0
flake8-plugin-utils==1.3.1
flake8-polyfill==1.0.2
flake8-pytest-style==1.4.1
flake8-rst-docstrings==0.2.1
flake8-use-fstring==1.1
flake8==3.9.1
flatbuffers==1.12
fuzzywuzzy==0.18.0
Expand Down
4 changes: 4 additions & 0 deletions .constraints/py3.8.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ filelock==3.0.12
flake8-blind-except==0.2.0
flake8-bugbear==21.4.3
flake8-builtins==1.5.3
flake8-comprehensions==3.4.0
flake8-plugin-utils==1.3.1
flake8-polyfill==1.0.2
flake8-pytest-style==1.4.1
flake8-rst-docstrings==0.2.1
flake8-use-fstring==1.1
flake8==3.9.1
flatbuffers==1.12
fuzzywuzzy==0.18.0
Expand Down
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ ignore = # more info: https://www.flake8rules.com/
E203 # https://github.com/psf/black#slices
E231 # allowed by black
E501 # https://github.com/psf/black#line-length
FS003 # should be possible to use {} in latex strings
RST299 # missing pygments
RST201 # block quote ends without a blank line (black formatting)
RST301 # unexpected indentation (related to google style docstring)
W503 # https://github.com/psf/black#line-breaks--binary-operators
radon-max-cc = 8
radon-no-assert = True
rst-roles =
attr,
cite,
Expand Down
48 changes: 18 additions & 30 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,32 @@
# and compare the output

[BASIC]
good-names=
_,
i,
j,
k,
p,
q,
x,
good-names-rgxs=
^[px]$,

[VARIABLES]
init-import=yes

[MESSAGES CONTROL]
disable=
C0114, # done by pydocstyle
C0115, # done by pydocstyle
C0116, # done by pydocstyle
C0330, # https://github.com/psf/black/issues/48
RST203, # unexpected indentation
RST301, # related to google style docstring
R0801, # similar lines # https://github.com/PyCQA/pylint/issues/214
logging-fstring-interpolation,
not-callable,
unused-import, # https://www.flake8rules.com/rules/F401
[DESIGN]
max-args=7 # default: 5

[MASTER]
ignore=
conf.py,
sympy
sympy,
ignore-patterns=
.*\.pyi

[DESIGN]
max-args=7 # default: 5
# Minimum number of public methods for a class (see R0903). Default is 2.
# We decrease this to 0, since some rules are "empty" but get decorated.
# Note that some interface classes also just have a single method
min-public-methods=0
[MESSAGES CONTROL]
disable=
duplicate-code, # https://github.com/PyCQA/pylint/issues/214
logging-fstring-interpolation,
missing-class-docstring, # pydocstyle
missing-function-docstring, # pydocstyle
missing-module-docstring, # pydocstyle
redefined-builtin, # flake8-built
too-few-public-methods, # data containers (attrs) and interface classes
unused-import, # https://www.flake8rules.com/rules/F401

[SIMILARITIES]
ignore-imports=yes # https://stackoverflow.com/a/30007053

[VARIABLES]
init-import=yes
5 changes: 4 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,14 @@ format =
black
isort
lint =
flake8 >= 3 # for per-file-ignores
flake8
flake8-blind-except
flake8-bugbear
flake8-builtins
flake8-comprehensions
flake8-pytest-style
flake8-rst-docstrings
flake8-use-fstring
mypy >= 0.570 # attrs support
pep8-naming
pydocstyle
Expand Down
2 changes: 1 addition & 1 deletion src/tensorwaves/optimizer/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class CallbackList(Callback):
"""

def __init__(self, callbacks: Iterable[Callback]) -> None:
self.__callbacks: List[Callback] = list()
self.__callbacks: List[Callback] = []
for callback in callbacks:
self.__callbacks.append(callback)

Expand Down
4 changes: 2 additions & 2 deletions src/tensorwaves/optimizer/minuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def wrapped_gradient(pars: list) -> Iterable[float]:
minuit.migrad()
end_time = time.time()

parameter_values = dict()
parameter_errors = dict()
parameter_values = {}
parameter_errors = {}
for i, name in enumerate(flattened_parameters):
par_state = minuit.params[i]
parameter_values[name] = par_state.value
Expand Down
10 changes: 5 additions & 5 deletions tests/data/test_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def test_generate_data(data_sample: EventCollection):


@pytest.mark.parametrize(
"initial_state_name, final_state_names, expected_sample",
("initial_state", "final_state", "expected_sample"),
[
(
"J/psi(1S)",
Expand Down Expand Up @@ -141,14 +141,14 @@ def test_generate_data(data_sample: EventCollection):
],
)
def test_generate_phsp(
initial_state_name: str,
final_state_names: Sequence[str],
initial_state: str,
final_state: Sequence[str],
expected_sample: EventCollection,
pdg: ParticleCollection,
):
reaction_info = ReactionInfo(
initial_state={-1: pdg[initial_state_name]},
final_state={i: pdg[name] for i, name in enumerate(final_state_names)},
initial_state={-1: pdg[initial_state]},
final_state={i: pdg[name] for i, name in enumerate(final_state)},
)
sample_size = 3
rng = TFUniformRealNumberGenerator(seed=0)
Expand Down
2 changes: 1 addition & 1 deletion tests/optimizer/test_callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@pytest.mark.parametrize(
"callback_type, filename",
("callback_type", "filename"),
[
(CSVSummary, "fit_traceback.csv"),
(YAMLSummary, "fit_result.yml"),
Expand Down
2 changes: 1 addition & 1 deletion tests/optimizer/test_gradient.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def true_gradient(self, parameters: dict) -> dict:
# Now we just evaluate the gradient function at different positions x and
# compare with the expected values
@pytest.mark.parametrize(
"function, params_cases",
("function", "params_cases"),
[
(
Function1D(a=2, b=3, c=5),
Expand Down
2 changes: 1 addition & 1 deletion tests/optimizer/test_minuit.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def gradient(


@pytest.mark.parametrize(
"estimator, initial_params, expected_result",
("estimator", "initial_params", "expected_result"),
[
(
Polynomial1DMinimaEstimator(lambda x: x ** 2 - 1),
Expand Down
4 changes: 2 additions & 2 deletions tests/optimizer/test_parameter_flattener.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def parameter_flattener():


@pytest.mark.parametrize(
"unflattened_parameters, expected_flattened_parameters",
("unflattened_parameters", "expected_flattened_parameters"),
[
(
{"var1": 0.5 + 2j, "var2": -1.2},
Expand All @@ -33,7 +33,7 @@ def test_parameter_flattening(


@pytest.mark.parametrize(
"flattened_parameters, expected_unflattened_parameters",
("flattened_parameters", "expected_unflattened_parameters"),
[
(
{"real_var1": 0.5, "imag_var1": 2.0, "var2": -1.2},
Expand Down
2 changes: 1 addition & 1 deletion tests/optimizer/test_scipy.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def gradient(


@pytest.mark.parametrize(
"estimator, initial_params, expected_result",
("estimator", "initial_params", "expected_result"),
[
(
Polynomial1DMinimaEstimator(lambda x: x ** 2 - 1),
Expand Down
2 changes: 1 addition & 1 deletion tests/test_estimator.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def phsp_dataset() -> DataSample:


@pytest.mark.parametrize(
"model, dataset, true_params",
("model", "dataset", "true_params"),
[
(
gaussian(1.0, 0.1),
Expand Down
4 changes: 2 additions & 2 deletions tests/test_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def function(sympy_model) -> LambdifiedFunction:


@pytest.mark.parametrize(
"test_data, expected_results",
("test_data", "expected_results"),
[
(
{"x": np.array([0.5, 1.0, 1.5, 2.0, 2.5])},
Expand Down Expand Up @@ -73,7 +73,7 @@ def test_helicity(helicity_model: SympyModel):


@pytest.mark.parametrize(
"parameters, variables, backend",
("parameters", "variables", "backend"),
[
({"c_1": 1 + 1j}, {"x": np.array([1, 2, 3])}, "numpy"),
(
Expand Down

0 comments on commit feefdfb

Please sign in to comment.