Closed MarcoGorelli closed 3 years ago
Oh haha well spotted :sweat_smile: Sorry should have reported that upstream, but yes I got that impression from a quick glance
The cause is more general: [tool.nbqa.addopts]
in a pyproject.toml
overrides options in .flake8
.
Checked it with the following situation:
Notebook content:
# unused import F401
import numpy as np
# line too long E501
lines = [
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent consequat est nisl. Phasellus accumsan, magna sit amet...",
]
.flake8
:
[flake8]
extend-ignore = E501
pyproject.toml
:
[tool.nbqa.addopts]
flake8 = [
"--extend-ignore=F401",
]
With both pyproject.toml
and .flake8
present, nbqa-flake8 reports E501. If you remove pyproject.toml
, it reports F401.
Thanks for looking into this!
This seems expected then - if you pass the same value to flake8 via the command-line and via .flake8
, then the command-line option will take precedence
Values set at the command line have highest priority, then those in the project configuration file, and finally there are the defaults. However, there are additional command line options which can alter this.
https://flake8.pycqa.org/en/latest/user/configuration.html
Anything set in tool.nbqa.addopts
will be used a command-line argument
If you specify extra flags via both the pyproject.toml file and the command-line, both will be passed on to the underlying command-line tool, with the options specified in pyproject.toml passed first. In this case the exact behaviour will depend on the tool and the option in question. It’s common that subsequent flags override earlier ones, but check the documentation for the tool and option in question to be sure.
https://nbqa.readthedocs.io/en/latest/configuration.html#extra-flags
Ok thanks for the references.
Do you think it should become possible to define --extend-ignore
and --extend-select
in multiple config files? Afaik they can be repeated in the command line, so overwriting them through the config files is counter-intuitive.
The use case here is that I do not care about E402 in notebooks, but do want flake8 to report that error in Python files. (Currently achieved by using --ignore
in .flake8
and --extend-ignore
in tool.nbqa.addopts
.)
The use case here is that I do not care about E402 in notebooks, but do want flake8 to report that error in Python files
If you have --extend-ignore=E501
in .flake8
, couldn't you put --extend-ignore=E402,E501
in tool.nbqa.addopts
?
If you have
--extend-ignore=E501
in.flake8
, couldn't you put--extend-ignore=E402,E501
intool.nbqa.addopts
?
Sure, but that's duplication :smirk: It would mean you have to repeat all ignores/selects for both Python and jupyter notebooks
True 😄 Though if flake8 doesn't support adding to what's in .flake8
, I don't think there's much we can do about that here unfortunately - closing for now then
Just noticed this
https://github.com/ComPWA/ampform/commit/7d400055fc070a719127ed87b1c0e8693acd47c3
I haven't looked into this yet, just opening an issue for it so I don't forget - if that's the case, it sounds like a bug
(cc @redeboer)