Skip to content

Commit 727c67b

Browse files
authored
Merge pull request #2194 from jeej3000/clarify-plugin-namespace-packages
Clarify namespace package requirements in plugin discovery guide
2 parents db3d537 + 4dfa8d8 commit 727c67b

1 file changed

Lines changed: 11 additions & 5 deletions

File tree

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,17 @@ 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+
Plugins will also need to list their packages explicitly or use :func:`setuptools.find_namespace_packages`, as
108+
:func:`setuptools.find_packages` skips directories without an
109+
:file:`__init__.py`.
110+
111+
With native namespace packages, ``import myapp.plugins`` raises
112+
:exc:`ModuleNotFoundError` if no installed distribution provides the
113+
``myapp/plugins`` directory. Make sure your discovery code handles that case.
108114

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

0 commit comments

Comments
 (0)