I’ve been looking some more at namespace packages in the context of editables. The big issue is that PEP 420 explicitly requires that namespace packages recalculate their path based on sys.path
every time they are accessed. This means that you cannot just “add” a development directory ~/work/project/foo
as a namespace package - sure, the sys.modules
entry is present, but unless the project directory ~/work/project
is on sys.path
at the time you import from the namespace, it will not be searched.
So the practical implication of this is that namespace packages cannot be supported properly. Note that this is a property of the import machinery, not specific to editable mode (via wheels or otherwise).
Possible workaround include:
- Just add
~/work/project
via a.pth
file. That’s what setuptools does now, and it seems to be acceptable enough. The problem is, it exposes the whole directory, which means it’s not a precise equivalent of a normal install. - Write your own implementation of namespace packages, or steal/monkeypatch the importlib implementation. This looks like it would be tricky to get right, and it would then deliberately not be following PEP 420. I’ve no idea if this is sufficient, as I don’t use implicit namespace packages myself.
The current implementation of the editables
package doesn’t support namespace packages at all, and I intend, at least for now, to keep it that way and make it an explicit limitation.
My question for the PEP is, what do we want to say build_wheel_for_editable
must do? Is it OK for it to just omit namespace packages when building the wheel? Should it be required to fail, and (in effect) say “project cannot be installed as editable”? Is it allowable to implement some sort of limited-functionality equivalent of a namespace package? I’m reluctant to choose that final option, because we’ll then be sucked into writing our own equivalent of PEP 420 without the “dynamic path” feature.