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.05k stars 41 forks source link

nbqa-ruff-check hooks do not take into account pyproject.toml #868

Open martibosch opened 2 months ago

martibosch commented 2 months ago

I have the following setup with nbqa 1.9.0 and ruff 0.6.4:

# pyproject.toml
[tool.nbqa.addopts]
ruff = [
    "--ignore=D,I",
]
# .pre-commit-config.yaml
  - repo: https://github.com/nbQA-dev/nbQA
    rev: 1.9.0
    hooks:
      - id: nbqa-ruff-check
        args: ["--fix"]
      - id: nbqa-ruff-format
      - id: nbqa-ruff-check

Nonetheless, pre-commit hooks still raise D100 and I001 in my notebooks. A workaround is to use:

# .pre-commit-config.yaml
  - repo: https://github.com/nbQA-dev/nbQA
    rev: 1.9.0
    hooks:
      - id: nbqa-ruff-check
        args: ["--fix", "--ignore=D,I"]
      - id: nbqa-ruff-format
      - id: nbqa-ruff-check
        args: ["--ignore=D,I"]

However, this requires me to "duplicate" the configuration. Is there any way to make nbqa take pyproject.toml into account with the new nbqa-ruff-check hook?

MarcoGorelli commented 2 months ago

thanks for the report 🙏 investigations + fixes are welcome

minrk commented 3 weeks ago

@martibosch I think you should have ruff check instead of ruff to affect nbqa-ruff-check:

[tool.nbqa.addopts]
"ruff check" = [
    "--ignore=D,I",
]

or perhaps better to configure ruff directly:

[tool.ruff.lint]
ignore = ["D", "I"]

or if this is in nbqa config in order to only affect notebooks, after #870 you should be able to do:

[tool.ruff.lint.per-file-ignores]
"**/*nbqa_ipynb.py" = ["D", "I"]