I have a few third-party libraries I'm using in my...
# general
m
I have a few third-party libraries I'm using in my project that don't have type stubs. I'd like to write my own stubs for these such that
pants check
is able to pick them up. Is there a recommended way of setting this up?
w
Pants check just delegates to mypy or pyright (https://www.pantsbuild.org/stable/docs/python/goals/check) Are you running into any particular problems?
m
Yes -- I'm using
absl
but it does not include type stubs. I've generated my own and put them in the repo, but
pants check
does not find them. I've tried adding them as resource dependencies, but they're not getting found. Running Pyright in the exported virtual environment is able to pick them up.
w
Have you passed in any additional configuration (https://microsoft.github.io/pyright/#/configuration)? That's strange though, if pyright runs correctly on the exported env, it should also "just work" as part of check.... I wonder if there is a source-root issue? So, maybe pyright thinks you're running in a different directory
Oh, sorry, exported virtual environment. You're not referring to the sandbox there, are you?
m
That's right a virtual env generated with
pants export
w
Okay, so if you run
pants --keep-sandboxes=always check --only=pyright ::
and then check out the created sandbox, does pyright work in there?
m
I'm not sure how namespace packages interact with pyright. Another library I've created stubs for is
boto3
and that one seems to work. I suspect it's working for some libraries and not others due to issues with packages vs namespace packages, but I don't know enough about how Pyright resolves paths to say. I know I've had issues in the past with it finding generated protos when there's an init.py in the corresponding source directory.
I'll try running in the sandbox directly...
w
Yeah, my guess was something to do with that as well. Or, maybe it's just the path. Once you create sandbox, you can try using the __run.sh directly - but if your typings aren't in the sandbox, that'll be a quick check Then you can experiment with pyright configuration in the sandbox directly, and back-apply it into Pants
🙏 1
m
Stepping back, it turns out
absl
does actually have type stubs and I just have an old version pinned...
👍 1