Description
Environment: Ubuntu 19.10; Python 3.7.5; pip 18.1
References:
- https://packaging.python.org/guides/creating-and-discovering-plugins/#using-namespace-packages
- https://packaging.python.org/guides/packaging-namespace-packages/#native-namespace-packages
I'm attempting to provide a plugin system that only needs to work for Python 3.3+. Namespaces seem like a good fit as they easily allow different types of plugin to be separated out, e.g. myapp.io_plugins
and myapp.viz_plugins
. Given Python 3.3+ then native namespaces seem the way to go, but ...
I am unable to recreate the suggested myapp.plugins
structure from PyPA using pip.
The problems are:
- When installing
myapp
I can't get pip to create an emptymyapp.plugins
namespace package. Probably not a deal breaker (e.g. I can catch theImportError
), but somewhat inconvenient at best. - When installing a plugin, pip states "Successfully installed...", but then goes on to say "Target directory .../myapp already exists..." and fails to install the plugin.
NB. The code in the native namespace example project didn't help. It is equivalent to making myapp
a namespace package, instead of myapp.plugins
and changing it to fit the myapp.plugins
guide broke the behaviour.
I've tried a fair few permutations but the one that seemed closest to the PyPA guide is:
myapp/
├── myapp
│ ├── __init__.py
│ ├── foo.py
│ └── plugins [empty directory]
└── setup.py
Where setup.py
contains either packages=['myapp']
or packages=['myapp', 'myapp.plugins']
. Either way, the myapp.plugins
directory doesn't get created.
python -m pip install -t /path/to/target .
results in (ignoring byte code and dist-info):
myapp/
├── __init__.py
└── foo.py
The plugin is defined as:
myplugin/
├── myapp
│ └── plugins
│ └── myplugin
│ └── __init__.py
└── setup.py
Where setup.py
contains packages=['myapp.plugins.myplugin']
.
python -m pip install -t /path/to/target .
results in (ignoring byte code and dist-info):
Processing /path/to/myplugin
Building wheels for collected packages: MyPlugin
Running setup.py bdist_wheel for MyPlugin ... done
Stored in directory: /tmp/pip-ephem-wheel-cache-...
Successfully built MyPlugin
Installing collected packages: MyPlugin
Successfully installed MyPlugin-1
Target directory /path/to/target/myapp already exists. Specify --upgrade to force replacement.
Despite the Successfully ...
the only change to the installed files is the addition of the MyPlugin dist-info files - the myapp/plugins/myplugin/__init__.py
file is not installed.