Hey, running into some issues with what I'm guessi...
# plugins
c
Hey, running into some issues with what I'm guessing is PYTHONPATH with regards to my in-repo plugin. I have
Copy code
pythonpath = ["%(buildroot)s/pants-plugins"]
in my pants.toml, but I'm getting a
ModuleNotFoundError
e
If your module is
my.plugin
the corresponding file would have to be at
pants-plugins/my/plugin.py
Is that the case? In other words, can you provide more details about your setup and the backtrace?
c
sure. Folder structure is
pants-plugins/cython/{cython_build.py,register.py}
Failed to load the cython.register backend: ModuleNotFoundError("No module named 'cython.register'; 'cython' is not a package",)
pants.toml:
Copy code
[GLOBAL]
pythonpath = ["%(buildroot)/pants-plugins"]
e
Ok, PEP-420 is likely at issue.
Can you try _`touch pants-plugins/cython/__init__.py`?_
c
there's an
__init__.py
in the cython folder as well. Can you expand on what you mean by PEP-420?
e
Ah, ok. Just a sec.
c
I can import it from REPL
if pants-plugins is in PYTHONPATH or PWD
e
Ah, syntax. You need to use
%(buildroot)s/...
You're missing the
s
.
c
Ah, I removed that unsure if it was a typo or not. It changes nothing
it was there originally
same error
e
So in picking
cython
for your package name are you colliding with 3rdparty?
You are.
Try cython2 or anything but cython which https://pypi.org/project/Cython already owns.
My assumption here is your plugin depends on the Cython project. If it does, only one cython package will win unless they set up their project to support namespace packages. Even if they did, you probably want to steer clear of that complication.
Hopefully this fix works and makes sense. If it works but does not make sense I can explain more about python packages, namespace packages, etc. This behavior trips up alot of folks.
c
oh duh, changing it to something else fixed it. It's surprising that it's conflicting because the Cython package name is
Cython
and python modules should be case sensitive, but it's probably better to not have it be so close anyway
e
The project / package name is not the important thing - it need not match the root module / package name at all. It just tends to. The Cython root module is `cython`: https://github.com/cython/cython/blob/master/cython.py
FWIW the Project name normalization is here: https://www.python.org/dev/peps/pep-0503/#normalized-names But, again, that has no bearing on modules / packages provided by a project. The classic example is the setuptools project which provides setuptools and pkg_resources top-level packages both.
The python packaging system has grown organically and looks almost logical which is the gotcha. Its actually not that logical.
j
This thread is very helpful for me avoiding my own collision. 🙏🏽