I need some help getting my first-party type check...
# general
b
I need some help getting my first-party type checks working. I have a directory structured like this:
Copy code
src
├── common
│   ├── auth
|       ├── BUILD
|       ├── auth1.py
|       ├── auth2.py
│       └── mypy-stubs
|           ├── BUILD
|           ├── auth1.pyi
│           └── auth2.pyi
├── services
│   ├── app
|       ├── BUILD
│       └── app.py
I want to run type-checking on
app
, which imports `auth1`/`auth2`. When I list dependencies for
auth
, I see the `pyi`s, but I don't see them in dependencies for
app
. I have tried explicitly listing them app's
BUILD
, and they will be listed as dependencies when I do, but the type check still fails with
error: Cannot find implementation or library stub for module named "common.auth.auth1"
(same error for
auth2
). I feel like I've gotten this to work in the past - what am I missing here?
I'll note that both BUILDs in the auth directory only have
python_sources()
defined. The docs say
Copy code
You can use .pyi files for both first-party and third-party code. Include the .pyi files in the sources field for python_source / python_sources and python_test / python_tests targets. MyPy will use these stubs rather than looking at the implementation.
but I cannot find a place to put the `pyi`s where I do not get the missing stub error.
w
Do you have all your initpys in the right place?
And does mypy know where to look for your stubs?
b
1. Which initpys? I have an init in the
auth
and
app
directories, and an
__init__.pyi
in the
mypy-stubs
directory. 2. I'm using mypy through the
./pants check
goal. My understanding is that it will use standard dependency inference to find the stubs, but clearly that is not the case. How else can I get it to find them?
h
What are your source roots here?
b
Nothing in these directories. I just tried adding
src/common/auth/mypy-stubs/
as a root, but still got the error.
h
Dep inference does rely on source roots being set up correctly. Are
auth
and
services
the top-level packages? If so then
src/
should be a source root (and it may already be one, I just want to verify). You can see your source roots with
./pants roots
b
Yes,
src/
is a source root