Skip to content

Commit 1b89453

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 70421ab commit 1b89453

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
@@ -105,11 +105,19 @@ but it's not recommended to make your project's main top-level package
105105
bad plugin could cause the entire namespace to break which would in turn make
106106
your project unimportable. For the "namespace sub-package" approach to work,
107107
the plugin packages must omit the :file:`__init__.py` for your top-level
108-
package directory (``myapp`` in this case) and include the namespace-package
109-
style :file:`__init__.py` in the namespace sub-package directory
110-
(``myapp/plugins``). This also means that plugins will need to explicitly pass
111-
a list of packages to :func:`setup`'s ``packages`` argument instead of using
112-
:func:`setuptools.find_packages`.
108+
package directory (``myapp`` in this case). In the namespace sub-package
109+
directory (``myapp/plugins``) they must either omit :file:`__init__.py`, if
110+
you use :ref:`native namespace packages <native-namespace-packages>`, or
111+
include a pkgutil-style :file:`__init__.py`, if you use the legacy approach;
112+
all plugins have to use the same one. Plugins will also need to list their
113+
packages explicitly or use :func:`setuptools.find_namespace_packages`, as
114+
:func:`setuptools.find_packages` skips directories without an
115+
:file:`__init__.py`.
116+
117+
With native namespace packages, ``myapp.plugins`` only exists once at least
118+
one plugin is installed, so ``import myapp.plugins`` raises
119+
:exc:`ModuleNotFoundError` if there are none. Make sure your code handles that
120+
case.
113121

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

0 commit comments

Comments
 (0)