nbQA-dev / nbQA

Run ruff, isort, pyupgrade, mypy, pylint, flake8, and more on Jupyter Notebooks
https://nbqa.readthedocs.io/en/latest/index.html
MIT License
1.04k stars 41 forks source link

Is extend-ignore taken into account? #669

Closed MarcoGorelli closed 3 years ago

MarcoGorelli commented 3 years ago

Just noticed this

https://github.com/ComPWA/ampform/commit/7d400055fc070a719127ed87b1c0e8693acd47c3

  • ci: use ignore instead of extend-ignore nbQA does not take extend-ignore into account

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)

redeboer commented 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

redeboer commented 3 years ago

The cause is more general: [tool.nbqa.addopts] in a pyproject.toml overrides options in .flake8.

Checked it with the following situation:

With both pyproject.toml and .flake8 present, nbqa-flake8 reports E501. If you remove pyproject.toml, it reports F401.

MarcoGorelli commented 3 years ago

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

redeboer commented 3 years ago

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.)

MarcoGorelli commented 3 years ago

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?

redeboer commented 3 years ago

If you have --extend-ignore=E501 in .flake8, couldn't you put --extend-ignore=E402,E501 in tool.nbqa.addopts?

Sure, but that's duplication :smirk: It would mean you have to repeat all ignores/selects for both Python and jupyter notebooks

MarcoGorelli commented 3 years ago

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