I'm seeing odd behavior of Pants (on `main`) appar...
# development
b
I'm seeing odd behavior of Pants (on
main
) apparently not being a namespace package? So I'm trying to run
pants
from the latest release in
main
, so I set a
pants_version
and removed
[DEFAULT]
. Then
pants
runs, and errors on not being able to find
pants.explorer.server
. That makes sense, since it isn't bundled into Pants itself. So I add
"%(buildroot)s/src/python"
to
pythonpath
. But the error persists! Doing a little debugging, in
extension_loader
I do
import pants;print(pants.__file__)
and it prints
/home/josh/.cache/nce/65aa4f2a6c1f9bac672c0df94ae34c7170e5c071cda35e9b725945831905c122/bindings/venvs/2.18.0a0/lib/python3.9/site-packages/pants/__init__.py
. According to the internet, namespace packages should have
__file__
set to
None
(or just not have a
__file__
. WTF?!
Hmmmm I'm missing something for sure...
Copy code
josh@cephandrius:~/work/pants$ mkdir -p other_pants/pants
josh@cephandrius:~/work/pants$ cp src/python/pants/__init__.py other_pants/pants
josh@cephandrius:~/work/pants$ touch other_pants/pants/bar.py
josh@cephandrius:~/work/pants$ python3.9
Python 3.9.17 (main, Jun  6 2023, 20:11:04) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append("src/python")
>>> sys.path.append("other_pants")
>>> import pants
>>> pants.__file__
'/home/josh/work/pants/src/python/pants/__init__.py'
Although...
Copy code
>>> import sys; sys.path.append("src/python"); sys.path.append("other_pants")
>>> import pants.bar
>>> pants
<module 'pants' from '/home/josh/work/pants/src/python/pants/__init__.py'>
>>> import pants.util
>>> pants
<module 'pants' from '/home/josh/work/pants/src/python/pants/__init__.py'>
So I think
__file__
is a red herring?
Ah I think I see... Yes
__file__
is a red herring. The true way to tell how things will be loaded is to look at
__path__
. In this case
pants
is loaded first to start, well, executing Pants. And in doing so,
pythonpath
from
pants.toml
isn't considered. That means the built-in Pants is marked down as the only path in
__path__
. To put this back into `python3.9`:
Copy code
josh@cephandrius:~/work/pants$ python3.9
Python 3.9.17 (main, Jun  6 2023, 20:11:04) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append("src/python")
>>> import pants.util
>>> pants.__path__
['/home/josh/work/pants/src/python/pants']
>>> sys.path.append("other_pants")
>>> import pants.bar
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pants.bar'
So, what now? Well, it'd be nice to test if we're squatting on the
pants
name for plugins. Eventually I think we want another repo for blessed-but-not-baked-in plugins. This particular codepath isn't for plugins though. Secondly, I think our
backend_packages
should only be packages baked into Pants itself. Anything not baked in belongs in
internal_plugins
. @curved-television-6568 thoughts?
OK I have the ability to add a test which tests this fundamental assumption. So that's good 🙂
c
yea, so then
pants.explorer
should move out, as that is not meant to be baked in.
1
but I don’t think it belongs in
internal_plugins
either.. it’s meant to become a public plugin
b
Yeah I think that's where we need to figure out how/where we should put external plugins that aren't in our backend
1
c
pants_plugin.explorer
?
b
Maybe we discuss at the next meeting?
👍 1
Or we sidecar on the third party "plugins" discussion
c
kind of related I think.. so yea that makes sense
b
I have some thoughts on what we can do for thirdparty plugins.
E.g. • How should they be tested? • How should they easily support (and test) multiple Pants versions? • How shoudl they be catalogued? • Can we provide infra/tech for docs hosting of them?
c
oh I love all those bullets
b
While I'm spitballing: • How can we help plugin resolution (e.g. deps of plugins) • How can we help ensure plugins have 0 sdist dependencies ◦ We already broke this one, lol
c
help plugin deps is done, or at least started: https://github.com/pantsbuild/pants/pull/19406
b
I think we need to take it farther, honestly.
Like, Pex lockfile far 🙂
c
cool (so, started 😜 )
buut.. if it’s an external plugin, you have your normal dist requirements.. aren’t they enough?
so, it would be for the baked backends then..?
b
No, because those can float in transitivity. meaning your
pants
is not the same as my
pants
in the same repo for the same commit
c
but it sounds risky if a plugin puts a hard pin, that can get real wieldy in compat issues between multiple plugins. Feels like if we want two installs to be identical we need to share a common constraints.txt or similar.
b
Thats why I'm thinking plugins are resolved from a single Pex lockfile 🙂
c
curious how you’d see this working in practice (given multiple potential sources for plugins)
b
what do you mean multiple sources?
c
from different orgs, for instance
b
One lockfile with multiple inputs?
c
do you generate your own lockfile then, for the set of plugins you use?
b
Yeah
c
ok, so that would be the file you can share.. I called it “constraints.txt” but 🥔 🍅
b
...I should dump this into an issue, if there already isn't one
👍 1
Also, plugins are resolved through Pex, so it's the most natural fit, IMHO
💯 1
c
what?
oh, I see
c
yea, was just looking at those lines 😅