okay, so i’m using vscode for pants plugin develop...
# general
f
okay, so i’m using vscode for pants plugin development .. and was wondering if anyone has some tips on language server/ide setup? — i think i got most of stuff working, but if im in a module where i have not yet imported
Process
or
ProcessResult
— i’m not being able to auto import and manage the imports for it … — while if i reference symbols from my local plugin it works just fine — when i do import by hand, vscode knows where the source can be found and i can jump directly into definitions … anyway to make that include detection smarter?
it looks like
pylance
is the default chosen language server
and once i add the import manually — it finds it just fine
w
One odd thing I've noticed is that sometimes vscode's autocomplete (
ctrl + space
for me) won't find it, but quick fix will (
cmd + .
) I think creating a venv with the pants plugin from pypi helps with the autocomplete
Note: In the example above, I'm in the pants main repo.
f
🤔
b
(Is this in Pants repo, or in your own repo?)
f
my own repo
b
It's possible. DO you have the pants req as a separate resolve for your plugins?
f
where i’ve run
./pants export ::
and setup
PYTHONPATH
b
If you exported and pointed the editor to the virtualenv for the pants-plugin resolve it should find everything
f
i have not set it up so intentionally
w
Hmm, does the
./pants export ::
also export the pants-plugin? I would assume it does, but 🤷
b
@wide-midnight-78598 yup.
::
should match some plugin code, and then export will export a ve for the resolve
f
maybe the lang server needs a restart? 🤷
w
Ahh, multiple resolves ...
f
😕
b
That
ve
should have python. Fire that up and try
import pants
?
f
i’ll try that tomorrow and report back 👍
b
I ought to try it locally too. I'm tired of no autocomplete
Also supposedly you can use different envs if you use VS code's multi-project-support.
👍 1
f
okay, i’m not sure exactly what i did — but tried setting a few python interpreters, and now it’s only made it worse 😂 if i just run python from the virtualenv i can
import pants
just fine … if i try through the terminal in vscode, it seems like it’s really wanting to use an old python installed via
pyenv
.. even though i set the interpreter specifically through the command palette
points to the same python that is part of the venv exported by pants … 😕
c
Are you sure it's the right python? I get something like "3.8.10 ('3.8.10': venv)" when pointing to an interpreter in the venv
f
i’m on an M1 mac which i believe requires python 3.9 i also have
Copy code
[python]
interpreter_constraints = ["CPython==3.9.*"]
in
pants.toml
for that reason
c
Yes, I don't mean the exact version, but that vscode mentions that is running the interpreter from a venv. For you it looks like it is the system one. Did you pick the binary from dist/export/python/venvs/... ?
f
yep, but that binary points back to what i have installed through homebrew — which i find a bit odd
trying to trash my setup completely and reinstall everything vscode/python related …
1
okay, so — pants bootstrapped successfully, but now i get …
Copy code
❯ ./pants export ::
11:07:50.70 [ERROR] 1 Exception encountered:

  ProcessExecutionFailure: Process 'Searching for `bash` on PATH=/usr/bin:/bin:/usr/local/bin' failed with exit code -9.
stdout:

stderr:



Use `--keep-sandboxes=on_failure` to preserve the process chroot for inspection.
sheeeeesh! ran the same command with the keep sandboxes on, and then it succeeded bowtie
anyways … continue on;
Copy code
❯ readlink -f dist/export/python/virtualenv/3.9.15/bin/python
/opt/homebrew/Cellar/python@3.9/3.9.15/Frameworks/Python.framework/Versions/3.9/bin/python3.9
below works, no error:
Copy code
❯ ./dist/export/python/virtualenv/3.9.15/bin/python -c "import pants"
vscode can’t still find
pants
modules …. 🤯
i also tried giving it the paths directly by setting
python.analysis.extraPaths
… no dice.
c
So you mean that when you choose the interpreter (at dist/export/...), then vscode still uses the system one? It should detect that it's a link from a venv directory, and use that.
f
well, it links to the homebrew installed one — that is,
Copy code
dist/export/python/virtualenv/3.9.15/bin/python
is a symlink directly to the python installed via homebrew
okay — i bootstrapped pants with a python installed via
pyenv
and after reinstalling vscode, and playing with a bunch of settings trying to add paths manually and all sorts of other “try turning it on and off again” i finally got it to work … and i think once it became happy i didn’t need any of the custom settings anymore and it “just works” ™ now … …. sigh, somedays are just ….
wooo, i think i got it to work …
i don’t know if this depth is too much, but whatever
Copy code
{
            "name": "pants",
            "depth": 10,
            "includeAllSymbols": true,
        }
this config in
"python.analysis.packageIndexDepths":
seems to have done the trick …
image.png
w
This was a wild ride. Are you using stock VSCode or Insiders? I find Insiders to periodically be a bit janky, but not really like this. Without any VSCode modification other than using python/pylance extensions (empty
.vscode
folder too), this process just worked for me (taking
export
out of the picture for now).
Copy code
# From my repo root

# After running this, VSCode sees there is a new .venv and asks me to use it in the workspace, to which I say yes
python3.9 -m venv .venv

source .venv/bin/activate

# First set of squiggles goes away within 1-2 seconds of this install completing
pip install pantsbuild.pants

# Remaining squiggle disappears after this installs
pip install pantsbuild.pants.testutil
It looks like this didn't play out correctly for you. So, I guess this leaves me wondering if this is a weird one-off, if it's something about the M1 environment, or it's related to
./pants export ::
, or all of the above...
And for my sanity, just confirmed after
./pants export ::
- when I set the VSCode interpreter path to:
./dist/export/python/virtualenvs/pants-plugins/3.9.15/bin/python
that auto-complete works and my squiggs disappear.
f
and is python there a symlink to something elsewhere on your system?
w
Yes, to my home brew install I believe
Actually, literally the only place to symlink it for that version