okay, so i’m trying to develop my first plugin (da...
# general
f
okay, so i’m trying to develop my first plugin (daunting 😅), and yet again i’m asking for IDE support (mostly for documentation purposes), and since this is now just regular python3 code that should allow for using all the bells and whistles of whatever python language server integration my editor has? … but, i sort of expected more paths to show up after enabling python + plugin development plugins …
Copy code
❯ ./pants roots
pants-plugins
where do i point my editor to to get the proper path for the current version of the pants python libraries? as i understand it pants bundles it’s own python somewhere digging around in
~/.cache/pants
i’ve found
~/.cache/pants/setup/bootstrap-Darwin-arm64/pants.bA7ZRm/install/lib/python3.9/site-packages/
…. which looks promising, but is there some established way through a similar command to get to this path without manual spelunking? and is this enough to get lsp support? let me iterate — i’m in no way a python developer 😆
h
Hi there, welcome! We're definitely happy to help and we try to be Python beginner friendly 🙂 For your IDE, you'd want to use the
export
goal: https://www.pantsbuild.org/docs/setting-up-an-ide#python-third-party-dependencies-and-tools
f
ah, so pants own python libraries are considered 3rd party code? — i guess that makes sense since it’s all — uh hermetic/self-contained or whatever 😉 thanks, i’ll be sure to try that out!
h
Precisely 🙂 that is if you want to run Pants on Pants plugin code, e.g. run tests. Which is recommended but not required
the
pants_requirements
target generator makes sure Pants-as-a-library is the same version used as Pants-as-a-binary
f
neat!
okay, so — trying export and i get
Copy code
❯ ./pants export
08:06:30.66 [INFO] Completed: Building pytest.pex from pytest_default.lock
08:06:30.66 [ERROR] 1 Exception encountered:

  ProcessExecutionFailure: Process 'Building pytest.pex from pytest_default.lock' failed with exit code 1.
stdout:

stderr:
    ERROR: Command errored out with exit status 1:
     command: /Users/dreuss/.cache/pants/named_caches/pex_root/venvs/s/51b60de7/venv/bin/python3.7 -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/Users/dreuss/.cache/pants/named_caches/pex_root/tmp/pip-req-build-if47ksg3/setup.py'"'"'; __file__='"'"'/Users/dreuss/.cache/pants/named_caches/pex_root/tmp/pip-req-build-if47ksg3/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' --no-user-cfg egg_info --egg-base /Users/dreuss/.cache/pants/named_caches/pex_root/tmp/pip-pip-egg-info-_hh2wnqu
         cwd: /Users/dreuss/.cache/pants/named_caches/pex_root/tmp/pip-req-build-if47ksg3/
    Complete output (11 lines):
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/Users/dreuss/.cache/pants/named_caches/pex_root/venvs/s/51b60de7/venv/lib/python3.7/site-packages/setuptools/__init__.py", line 37, in <module>
        from setuptools.dist import Distribution, Feature  # vendor:skip
      File "/Users/dreuss/.cache/pants/named_caches/pex_root/venvs/s/51b60de7/venv/lib/python3.7/site-packages/setuptools/dist.py", line 57, in <module>
        from setuptools import windows_support  # vendor:skip
      File "/Users/dreuss/.cache/pants/named_caches/pex_root/venvs/s/51b60de7/venv/lib/python3.7/site-packages/setuptools/windows_support.py", line 2, in <module>
        import ctypes
      File "/Users/dreuss/.pyenv/versions/3.7.13/lib/python3.7/ctypes/__init__.py", line 7, in <module>
        from _ctypes import Union, Structure, Array
    ModuleNotFoundError: No module named '_ctypes'
this is sort of exactly the types of problems i was hoping not to battle with a tool like pants 😆
w
Is this something that could be a public repo so we could take a look at? This one is weird, because I thought this kinda implies that the installation is whack, or the system is missing the FFI dependencies - but it looks like you're on a Mac? Are you on a Mac M1?
f
yeah, i’m on an M1 — i suspected that was the problem too
it could probably be public — i’ll check if i can repro, it contains basically a hello world plugin, and that’s all
w
I recall there was some stuff to do on an M1, either with homebrew or pyenv first, or maybe it was Python version? But I haven't run into that yet, so, I need to defer to one of the m1 peeps for more info. There are a couple links in the docs that might be useful? https://www.pantsbuild.org/docs/prerequisites#macos
If you're able to publish it, I can test it out on a non-M1
h
@freezing-lamp-12123 I see Python 3.7 there. You will almost certainly need to use 3.9+ if you're on an M1. https://www.pantsbuild.org/docs/python-interpreter-compatibility
f
ah — got it — i’ll try and see if that helps, or i can make it work somehow — thanks for the pointers
❤️ 1
now we’re talking
Copy code
❯ ./pants export
20:27:30.09 [INFO] Initializing scheduler...
20:27:30.20 [INFO] Scheduler initialized.
20:27:33.59 [INFO] Completed: Building pytest.pex from pytest_default.lock
Wrote virtualenv for the tool 'pytest' to dist/export/python/virtualenvs/tools
thanks! .. using 3.9 did the trick ❤️
❤️ 1