-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use up-to-date namespace package setup for plugins #5505
base: master
Are you sure you want to change the base?
Conversation
2acfa64
to
fd4e599
Compare
2a0ee8b
to
7981f43
Compare
7981f43
to
9ebb51d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Built the docs and read them. I like the "attention" box. Some suggestions within.
What I miss in general in our docs is for plugin developers if there is anything specific they need to do in there pyproject.toml or setup.py files.
I'm not sure but is it enough to do this in a setup.py?
packages=find_packages(),
or is it better to do this:
packages=['beetsplug.myawesomeplugin'],
Here is some information about it: https://setuptools.pypa.io/en/latest/userguide/package_discovery.html#finding-simple-packages
Also the realpython article states a namespaces=True
directive for a pyproject.toml. Is this required?
[tool.setuptools.packages.find]
where = ["."]
include = ["snake_corp"]
namespaces = true
Should we add the most important parts that need to be in the package config. Maybe only focusing on pyproject.toml and setup.py verisions (I suppose they are the most common) and maybe also link to the above? What do you think? Too much information? Less is more?
You do not anymore need to add a ``__init__.py`` file to the ``beetsplug`` | ||
directory. Python treats your plugin as a namespace package automatically, | ||
thus we do not depend on ``pkgutil``-based setup in the ``__init__.py`` | ||
file anymore. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the general info about (current) namespace packages is already explained in the realpython article, maybe here you can point out this chapter of the python docs just to make sure we document everything potentially interesting for plugin developers (and also those who adopt old/orphaned plugins;-)): https://setuptools.pypa.io/en/latest/userguide/package_discovery.html#legacy-namespace-packages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed most of this section and added links to poetry and setuptools
I prefer explicit (latter) over implicit. For example in beetcamp the following works fine: packages = [{ include = "beetsplug" }] I'm not sure we should include these instructions in the docs since we've got a variety of build tools and each has its own instructions. We haven't got anything special going on here so as long as they somehow include the |
See https://realpython.com/python-namespace-package. This setup is backwards-compatible, so plugins using the old pkgutil-based setup will continue working fine. This setup has an advantage where external plugins will now be able to import modules from 'beetsplug' package for typing purposes. Previously, mypy could not resolve these modules due to presence of `__init__.py`.
c0b7ed2
to
89f1ef4
Compare
Description
Refactor
beetsplug
to use native namespace packages by removing__init__.py
. Update documentation andsetup.cfg
to support namespace packages.Changes
beetsplug/__init__.py
.docs/dev/plugins.rst
to reflect namespace package structure.mypy
configuration insetup.cfg
Motivation
Adopt PEP 420 native namespace packages to simplify plugin management and eliminate the need for
__init__.py
.See https://realpython.com/python-namespace-package.
This setup is backwards-compatible, so plugins using the old pkgutil-based setup will continue working fine.
The advantage with this setup is that external plugins will now be able to import modules from 'beetsplug' package for typing purposes. Previously, mypy could not resolve these modules due to presence of
__init__.py
.