straight-action-80318
01/14/2023, 7:59 PM./pants check path/to/dir
just gives me error: Cannot find implementation or library stub for module named
errors for all my imports. Running the actual ./pants run
seems to work just fine.
Do I need to setup mypy somehow to correctly understand the structure of my pants workspace? For example explicitly putting the root or something in the options?wide-midnight-78598
01/14/2023, 8:02 PMstraight-action-80318
01/14/2023, 8:42 PM__init__.py
straight-action-80318
01/14/2023, 8:42 PMstraight-action-80318
01/14/2023, 8:42 PMwide-midnight-78598
01/14/2023, 8:44 PMmypy
can do whatever it want, however. So, if it's complaining about something, it's probably init or config (using namespace packages, for example).
You can try it out by manually pip installing the same mypy version you're using in pants, and running directly. It should give you a similar resultwide-midnight-78598
01/14/2023, 8:45 PMstraight-action-80318
01/14/2023, 10:14 PMstraight-action-80318
01/14/2023, 10:15 PMstraight-action-80318
01/14/2023, 10:15 PM$ ./pants run src/project/main.py
5
$ ./pants check ::
14:15:27.14 [ERROR] Completed: Typecheck using MyPy - mypy failed (exit code 1).
src/project/main.py:1: error: Cannot find implementation or library stub for module named "project.lib"
src/project/main.py:1: note: See <https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports>
Found 1 error in 1 file (checked 2 source files)
✕ mypy failed.
straight-action-80318
01/14/2023, 10:16 PMproject.lib
, maybe because the root of the repo is src
?wide-midnight-78598
01/14/2023, 10:17 PMstraight-action-80318
01/14/2023, 10:20 PMstraight-action-80318
01/14/2023, 10:20 PMwide-midnight-78598
01/14/2023, 10:24 PMmypy
directly and run mypy .
- you get the same error.
(.venv) ⏺ scratch/pants-mypy-test % mypy . ⎇ main*
src/project/main.py:1: error: Cannot find implementation or library stub for module named "project.lib" [import]
src/project/main.py:1: note: See <https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports>
In this situation, Pants is just passing through the error it gets from the underlying tools.
if you run ./pants check :: --keep-sandboxes=always
you can hop into exactly what's being run in the __run.sh
scriptwide-midnight-78598
01/14/2023, 10:25 PMmypy
configuration I think, to see what you can do to get it passing.straight-action-80318
01/14/2023, 10:26 PMwide-midnight-78598
01/14/2023, 10:29 PM