Work around new(er) python 3 import semantics #3937
RomanHargrave
started this conversation in
Ideas
Replies: 1 comment 2 replies
-
Thanks for pointing this out! I've converted this thread to a discussion so we can talk in a more free-form way about what approach to take. Basically, I think that the |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This is not a bug within beets itself, per-se. I first began
observing this around Python 3.7 or 3.8, and I am currently on 3.8.
This is related to, but not exactly a duplicate of, #3730, where a
user experienced this exact problem.
In configurations where beets, and therefore the core
beetsplug
-namespaced components, are installed in the systempackages directory, installing any beets plugin in the user
directory will result in the entire contents of the
beetsplug
namespace being ignored in favor of that in the user packages
directory. This is ostensibly because python's understanding of
namespaces appears to have changed, and is now incompatible with beets
use of the
beetsplug
namespace as a de-facto search path.Suppose I have the following structure in
/usr/lib/python3.X/site-packages/beetsplug
:and then, as a result of running
pip3 install --user beets-extrafiles
, I had$HOME/.local/lib/python3.X/site-packages/beetsplug
containing thefollowing
In older python distributions, python would consider the contents of
both directories when searching for a module, while newer
distributions will search only the last matching directory. This is
largely desirable because it ensures that some version of a package
installed by the system will not interfere with a different version
installed by the user, should it contain different modules. Instead,
python will simply ignore the system package (assuming that
/usr/lib/python3.X/site-packages
is searched before$HOME/.local/lib/python3.X/site-packages
). In other words, thismeans that once a
beetsplug
directory is created in$HOME/.local/lib/python3.X/site-packages
, any beets plugin notinstalled in that directory effectively does not exist until the
aforementioned directory is removed. In terms of the previously
described directory listings,
beetsplug.absubmit
effectively doesnot exist, but
beetsplug.extrafiles
now does.I had, at some point, found either a mailing list discussion, RFC, or
changelog describing this new behavior; however, because of python's
popularity, and the fact that I do not know what exact choice of words
were used in that article, I currently do not know where to find it
and cannot locate it as any search results remotely relating to python
are all horrid blogs detailing precisely how not to write software
under the premise of teaching one how to code. I will try to find that
article and post it here, if possible.
For users that may install beets via their distribution's package
manager, this means that they are forced to polute the system search
path with files installed using
pip
instead of their distributionspackage manager. This can be more problematic for certain
distributions than others, and can lead to frustrating or unintuitive
behavior. For instance, if
beetsplug.extrafiles
is installed via pipinto the system packages directory, and then a system upgrade results
in a newer python distribution, beets will have been installed in the
new search path along with any plugins installed via the package
manager, but the user may then have to update any packages installed
via pip.
The short term solution, of course, is to install all of beets and its
pugins into either the user or system path, but not both 1;
however, this is both inelegant and potentially frustrating for users
that do not realize what is happening, nor why, and assume that either
beets or the plugin that they have just installed is broken. Python is
not my primary language, and I do not like it very much for several
reasons that are not relevant or worth discussing here, so I can't
offer the most pythonic solution; however, I think one option would
be to expect that all out-of-tree plugins be distributed under another
namespace, and that users then specify the plugin by its fully
qualified name. For instance, instead of
extrafiles
beingbeetsplug.extrafiles
, it might beholzhaus.extrafiles
andspecified in
config.yml
not asextrafiles
but ratherholzhaus.extrafiles
. The plugin search logic would then be updatedto search first for
beetsplug.{name}
and then fall back to{name}
(perhaps only if it contains namespace separators, to avoid confusion
with the vast number of modules that could exist within the root
namespace).
1 Some distributions will prevent the user from installing packages via
pip
outside of the user directory, such as Gentoo:p.s. Sorry about the paragraph width. Github appears to have deviated from normal markdown behavior by not treating contiguous lines of text as a paragraph. I edited most of this with emacs, where I have autofill enabled for markdown.
Beta Was this translation helpful? Give feedback.
All reactions