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

pre-commit hooks don't see installed packages #788

Closed l0b0 closed 1 year ago

l0b0 commented 1 year ago

I'm trying to get the following configuration to work in a repo:

  - repo: https://github.com/nbQA-dev/nbQA
    rev: 73e47d5a94b8724ce0b36e7bf29103a6f45dc505 # frozen: 1.6.1
    hooks:
      - id: nbqa-mypy
      - id: nbqa-pylint

When running pre-commit run --all-files, both of these tools complain about not being able to see the dependencies installed in the current environment. For example, from mypy:

[…].ipynb:cell_12:1: error: Cannot find implementation or library stub for module named "geopandas"

And from pylint:

[…].ipynb:cell_1:9:0: E0401: Unable to import 'numpy' (import-error)

But both python <<< 'import geopandas' and python <<< 'import numpy' know about the modules.

l0b0 commented 1 year ago

Hmm, looks like mypy -c 'import numpy' doesn't see numpy either. Please hold…

MarcoGorelli commented 1 year ago

Hmm, looks like mypy -c 'import numpy' doesn't see numpy either. Please hold…

exactly :) nbqa just runs the tool, if it wouldn't work on a python file it won't work on a jupyter notebook

closing then, but thanks for the report

l0b0 commented 1 year ago

In case anyone runs into the same issue with Nix, I was able to fix it in https://github.com/linz/emergency-management-tools/pull/97/files by making sure mypy is part of the first derivation which includes Python.