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

Pre-commit hook #713

Closed ncgoodbody closed 2 years ago

ncgoodbody commented 2 years ago

Hello! First off, I love this tool. I'm leading a team of curriculum developers, and we usenbqa-isort and nbqa-black to keep all our code consistent. It's a lifesaver, so thank you for putting it out into the world.

I'm having an issue with nbqa-isort where I can't pass the pre-commit hook even when changes have been made to the file.

For example, I'll have a cell of imports at the top of foo.ipynb

Screen Shot 2022-03-15 at 3 10 12 PM

I'll commit my code and get this message:

nbqa-isort...............................................................Failed
- hook id: nbqa-isort
- files were modified by this hook

Fixing file.ipynb

The imports will be fixed:

Screen Shot 2022-03-15 at 3 05 26 PM

But then when I try to commit the corrected file, I get the same fail message

nbqa-isort...............................................................Failed
- hook id: nbqa-isort
- files were modified by this hook

Fixing file.ipynb

So I end up stuck in a loop where the file is fixed, but I still can't commit it.

Is there something I'm missing? Something in the cell that's throwing off nbqa-isort? Would love some guidance.

Here's what my .pre-commit-config.yaml looks like:

- repo: https://github.com/nbQA-dev/nbQA
  rev: 1.3.1
  hooks:
  - id: nbqa-isort
    args: [--nbqa-exclude=^old_curriculum/]
  - id: nbqa-black
    args: [--nbqa-exclude=^old_curriculum/]
  - id: nbqa-flake8
    args: ['--ignore=E501,E402,W503', --nbqa-exclude=^old_curriculum/]

I'm running MacOS (Big Sur v. 11.6.4 (20G417))

MarcoGorelli commented 2 years ago

Hey @ncgoodbody

Thanks for your kind words, and for your report!

Sounds like this might be a bug - could you please upload your notebook (or a smaller version of the notebook that reproduces the issue) so I can debug?

ncgoodbody commented 2 years ago

This is a great example of rubber duck coding. As I was preparing a notebook for you, I realized that I was running nbqa-black right after nbqa-isort, and they were conflicting. So I set --profile=black, and the problem is solved.

Thanks for your willingness to look at my notebook and, again, for this tool. Keep it up!

MarcoGorelli commented 2 years ago

Ah nice, thanks for letting me know and closing the issue!