GM! I'm trying to write a plugin for `pyright` to ...
# plugins
d
GM! I'm trying to write a plugin for
pyright
to be used with
./pants check
and things seem to be nearly there; current problem i'm running into is related to pyright not having access to the venv to be able to determine imports. One solution that occurred to me was to use PathGlobs to grab the
python-default
venv from
./pants export
but pants seems to hard-ignore the
dist/
folder even if I add
"!dist", "!/dist/"
to global.pants_ignore in pants.toml Has anyone done something like this before? Any ideas or tips?
👍 1
I can get it working by copying the venv to a different folder and using it with PathGlobs, but that seems like a lot of extra steps
w
https://github.com/pantsbuild/pants/pull/17235 There is the start of one in the pants repo already (recent). However, it could definitely use some love, if you'd like to give it a crack?
👀 1
At the moment, it's specifically configurations and probably some bugs around dep handling, I feel like I missed a bunch of use cases there
d
ahhhh ok! There's some neat stuff here. Will be taking a closer look
w
👍 Just a heads up, I don't think that's in a release, because 2.15 was in/around alphas when that was approved, so it might be a 2.16 thing (but I haven't looked into it honestly)
1
d
yep yep, no worries there; in the short term we can pull it out as a local plugin
w
👍 Hmm, actually, it may even be in 2.15.ax, but yeah, definitely still experimental 🙂 I wrote the Node backend, so it made sense for me to quickly tack in the roots of Pyright, but I'm not a pyright expert 🙂 v
💯 1
d
ok, exciting stuff, I pulled some pieces of what is there and have it working and am adding support for the config files that pyright supports (locally, will share upstream when ready). One small question that I don't have strong opinions on: Is there a particular reason to use the NpxProcess over the pip-installable version of pyright? ACK that both will end up using node, since pyright itself is a node tool. I've got it running (and previously did before seeing what you shared this morning) using PexProcess and the pip-installable version, so wanted to ask for when i'm ready to share back up-stream and create a PR
Adding the support for the config files is actually pretty straight-forward, so shouldn't take long
👍 1
w
to use the NpxProcess over the pip-installable version of pyright
🤷 We have Node available, and if the pip solution is going to install node anyways, may as well go to the source. From the docs:
This project works by first checking if node is in the
PATH
. If it is not, then we download node at runtime using nodeenv and then install the pyright npm package using
npx
.
So, it does what we do, but I think we run into some weird cache ownerships, like nodeenv is in the venv, which installs node, which installs pyright, but that was all kicked off from a pex venv? I don't even know who owns what anymore 🙂
1
Actually, this is an interesting question - assuming node doesn't get installed globally would this guarantee only a single node is installed, for every time we need to put pyright into a pex? It's turtles all the way down, my brain can't comprehend how all of this would interact.
d
haha fair enough! My current thoughts (some of this is us-specific): until the version that has support for pyright (with the config file support i'll be submitting a PR for) is released we'll need to use an in-repo plugin version that doesn't rely on NpxProcess (since it's not currently released) Once the version that has NpxProcess and the config support is in a released version, we can abandon the in-repo plugin we'll use altogether
w
(since it's not currently released)
Oh really? I thought it made it into a release
d
oh maybe i misread your comments then!
I thought you had said it was alpha
w
If this works, then we have access in the pants version.
Copy code
"pants.backend.experimental.javascript",
or 
    "pants.backend.experimental.javascript.lint.prettier",
The
pyright
support itself, is definitely experimental. However, if you take a look here, I messed up the cherry pick process (https://github.com/pantsbuild/pants/issues/17225), so the latest
pyright
support isn't in 2.15.0.a1. If you're stripping code out of
main
into your own in-repo plugin, and we have
experimental.javascript
in your version of Pants, we should be ready to rock
1
d
👍 I'll take a peek around TY!
👍 1
h
+1 that PRs hugely welcomed to improve upstream Pyright support! What some people do is have a local version plugin, but upstream the improvements to Pants. Then once you can upgrade to 2.16, delete your local plugin
b
+1 That this would be a terrific and much-appreciated contribution to upstream. I'm confident that there are a number of community members who'd leap on opportunity to use it.