Skip to content

Commit 4543b2f

Browse files
jeej3000jeej1kclaude
committed
Clarify namespace package requirements in plugin discovery guide
The "Using namespace packages" section only described pkgutil-style namespace sub-packages (requiring an `__init__.py`), which contradicts PEP 420 native namespace packages. Describe both variants, mention `find_namespace_packages`, and note that `import myapp.plugins` fails when no plugin is installed. Fixes #1104 Co-authored-by: jeej1k <351634202+jeej1k@users.noreply.github.com> Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 5ecbc0d commit 4543b2f

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

‎source/guides/creating-and-discovering-plugins.rst‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,19 @@ but it's not recommended to make your project's main top-level package
100100
bad plugin could cause the entire namespace to break which would in turn make
101101
your project unimportable. For the "namespace sub-package" approach to work,
102102
the plugin packages must omit the :file:`__init__.py` for your top-level
103-
package directory (``myapp`` in this case) and include the namespace-package
104-
style :file:`__init__.py` in the namespace sub-package directory
105-
(``myapp/plugins``). This also means that plugins will need to explicitly pass
106-
a list of packages to :func:`setup`'s ``packages`` argument instead of using
107-
:func:`setuptools.find_packages`.
103+
package directory (``myapp`` in this case). In the namespace sub-package
104+
directory (``myapp/plugins``) they must either omit :file:`__init__.py`, if
105+
you use :ref:`native namespace packages <native-namespace-packages>`, or
106+
include a pkgutil-style :file:`__init__.py`, if you use the legacy approach;
107+
all plugins have to use the same one. Plugins will also need to list their
108+
packages explicitly or use :func:`setuptools.find_namespace_packages`, as
109+
:func:`setuptools.find_packages` skips directories without an
110+
:file:`__init__.py`.
111+
112+
With native namespace packages, ``myapp.plugins`` only exists once at least
113+
one plugin is installed, so ``import myapp.plugins`` raises
114+
:exc:`ModuleNotFoundError` if there are none. Make sure your code handles that
115+
case.
108116

109117
.. warning:: Namespace packages are a complex feature and there are several
110118
different ways to create them. It's highly recommended to read the

0 commit comments

Comments
 (0)