-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUG] package-dir with subpackages (namespaces) does not work with editable install #4248
Comments
Hi @DavidRV00 , Sorry, I just saw that you provided a github repository example. I believe that to make it work you need to set the Can you please remove all the cache (by |
Hi @abravalheri , I want to avoid explicitly listing the packages, because auto-discovery seems to work great, at least for the non-editable install; seems like it's really close to being able to handle it. But if the issue is just that what I'm doing isn't fully supported, then I think we can close this as not-a-bug. Maybe I can make it work with packages.find. |
Hi @DavidRV00 , with a customisation like that, auto-discovery is not supposed to work. It is probably just working by accident... |
Alright, thanks for letting me know. I'll see if I can find some other way to make what I'm trying to do work. |
Hi @DavidRV00, thank you very much for the feedback. I will close this issue for now, because the customisation of |
Hello again @abravalheri , commenting to re-open, because now I've tried out using an explicit list of packages, but I get the same result as before with editable installs. This is what I've added to pyproject.toml:
Again Here, again, is the log output from
Reproducible example
Hopefully this is still just a case of me doing something unsupported, but I'm not sure what it could be. Thanks again for any help! |
Hi @DavidRV00, thank you for the reproducer. This seems to be a tricky one. If I do: >>> import __editable___package_dir_editable_0_0_1_finder as ed
>>> ed._EditableNamespaceFinder.find_spec("different_name.subpkg")
ModuleSpec(name='different_name.subpkg', loader=None, submodule_search_locations=['/tmp/package-dir-editable/src2/my_package2'])
>>> ed._EditableFinder.find_spec("different_name.subpkg.my_module2")
ModuleSpec(name='different_name.subpkg.my_module2', loader=<_frozen_importlib_external.SourceFileLoader object at 0x7fcd914fd490>, origin='/tmp/package-dir-editable/src2/my_package2/my_module2.py')
###
>>> import sys
>>> sys.meta_path
[<class '_frozen_importlib.BuiltinImporter'>, <class '_frozen_importlib.FrozenImporter'>, <class '_frozen_importlib_external.PathFinder'>, <class '__editable___package_dir_editable_0_0_1_finder._EditableFinder'>]
>>> sys.path_hooks
[<class 'zipimport.zipimporter'>, <function FileFinder.path_hook.<locals>.path_hook_for_FileFinder at 0x7fcd917245e0>, <bound method _EditableNamespaceFinder._path_hook of <class '__editable___package_dir_editable_0_0_1_finder._EditableNamespaceFinder'>>]
>>> sys.path
['', '/usr/lib/python312.zip', '/usr/lib/python3.12', '/usr/lib/python3.12/lib-dynload', '/tmp/package-dir-editable/.venv/lib/python3.12/site-packages', '__editable__.package_dir_editable-0.0.1.finder.__path_hook__']
>>> from different_name.subpkg import my_module2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'different_name.subpkg' I can see that the custom finders can successfully locate the packages themselves... But somehow they don't seem to work effectively togheter with the import machinery. This might be a very tricky problem to solve (and take time research, debugging). If anyone in the community would like to provide a PR, that would be much appreciated. |
Thanks for the quick reply, and for looking into it so quick! FWIW, for a little context, the reason I want this kind of directory structure is that I'm trying to put together a system for writing hybrid Python/C packages using just setuptools, CMake, and SWIG. CMake tends to generate code in parallel directory trees that mirror the src tree, so I end up with directories that look like |
Maybe as a workaround while this issue is not solved, try adding Namespaces are notably more complex to handle in custom finders (and that is related to the advice I asked in python/cpython#92054). |
Great, using |
Another note if it's useful: Using |
setuptools version
setuptools==69.1.0
Python version
Python 3.12.2
OS
Artix Linux
Additional environment information
I'm running this in a fresh conda environment.
Description
I have the following slightly odd directory structure:
And this clause in my pyproject.toml:
After running
pip install .
(ie non-editable), I'm able to import modules like this:... but with
pip install -e .
(editable), the second import fails with:Expected behavior
I expect the import behavior to be the same whether the package is installed editable or not.
How to Reproduce
git clone https://github.com/DavidRV00/package-dir-editable
and cd inside.conda create -n package-dir-editable python=3
) and activate it.pip install -e .
inside the project dir.python -c "from different_name.subpkg import my_module2"
Output
The text was updated successfully, but these errors were encountered: