Skip to content

Commit 795545c

Browse files
authored
Merge branch 'master' into fixmbgenre
2 parents 459ca64 + 4e7b054 commit 795545c

File tree

11 files changed

+63
-70
lines changed

11 files changed

+63
-70
lines changed

beets/test/helper.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ class ImportSessionFixture(ImportSession):
675675
>>> importer.run()
676676
677677
This imports ``/path/to/import`` into `lib`. It skips the first
678-
album and imports thesecond one with metadata from the tags. For the
678+
album and imports the second one with metadata from the tags. For the
679679
remaining albums, the metadata from the autotagger will be applied.
680680
"""
681681

beets/util/__init__.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1130,7 +1130,10 @@ def get_temp_filename(
11301130
tempdir = get_module_tempdir(module)
11311131
tempdir.mkdir(parents=True, exist_ok=True)
11321132

1133-
_, filename = tempfile.mkstemp(dir=tempdir, prefix=prefix, suffix=suffix)
1133+
descriptor, filename = tempfile.mkstemp(
1134+
dir=tempdir, prefix=prefix, suffix=suffix
1135+
)
1136+
os.close(descriptor)
11341137
return bytestring_path(filename)
11351138

11361139

beetsplug/__init__.py

-20
This file was deleted.

docs/changelog.rst

+5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ New features:
2222

2323
Bug fixes:
2424

25+
* :doc:`plugins/fetchart`: Fix fetchart bug where a tempfile could not be deleted due to never being
26+
properly closed.
27+
:bug:`5521`
2528
* :doc:`plugins/lyrics`: LRCLib will fallback to plain lyrics if synced lyrics
2629
are not found and `synced` flag is set to `yes`.
2730
* Synchronise files included in the source distribution with what we used to
@@ -74,6 +77,8 @@ Bug fixes:
7477
For packagers:
7578

7679
* The minimum supported Python version is now 3.9.
80+
* External plugin developers: ``beetsplug/__init__.py`` file can be removed
81+
from your plugin as beets now uses native/implicit namespace package setup.
7782

7883
Other changes:
7984

docs/dev/plugins.rst

+37-27
Original file line numberDiff line numberDiff line change
@@ -3,47 +3,57 @@
33
Writing Plugins
44
---------------
55

6-
A beets plugin is just a Python module inside the ``beetsplug`` namespace
7-
package. (Check out this `Stack Overflow question about namespace packages`_ if
8-
you haven't heard of them.) So, to make one, create a directory called
9-
``beetsplug`` and put two files in it: one called ``__init__.py`` and one called
10-
``myawesomeplugin.py`` (but don't actually call it that). Your directory
11-
structure should look like this::
6+
A beets plugin is just a Python module or package inside the ``beetsplug``
7+
namespace package. (Check out `this article`_ and `this Stack Overflow
8+
question`_ if you haven't heard about namespace packages.) So, to make one,
9+
create a directory called ``beetsplug`` and add either your plugin module::
1210

1311
beetsplug/
14-
__init__.py
1512
myawesomeplugin.py
1613

17-
.. _Stack Overflow question about namespace packages:
18-
https://stackoverflow.com/questions/1675734/how-do-i-create-a-namespace-package-in-python/1676069#1676069
14+
or your plugin subpackage::
1915

20-
Then, you'll need to put this stuff in ``__init__.py`` to make ``beetsplug`` a
21-
namespace package::
16+
beetsplug/
17+
myawesomeplugin/
18+
__init__.py
19+
myawesomeplugin.py
20+
21+
.. attention::
2222

23-
from pkgutil import extend_path
24-
__path__ = extend_path(__path__, __name__)
23+
You do not anymore need to add a ``__init__.py`` file to the ``beetsplug``
24+
directory. Python treats your plugin as a namespace package automatically,
25+
thus we do not depend on ``pkgutil``-based setup in the ``__init__.py``
26+
file anymore.
2527

26-
That's all for ``__init__.py``; you can can leave it alone. The meat of your
27-
plugin goes in ``myawesomeplugin.py``. There, you'll have to import the
28-
``beets.plugins`` module and define a subclass of the ``BeetsPlugin`` class
29-
found therein. Here's a skeleton of a plugin file::
28+
The meat of your plugin goes in ``myawesomeplugin.py``. There, you'll have to
29+
import ``BeetsPlugin`` from ``beets.plugins`` and subclass it, for example
30+
31+
.. code-block:: python
3032
3133
from beets.plugins import BeetsPlugin
3234
33-
class MyPlugin(BeetsPlugin):
35+
class MyAwesomePlugin(BeetsPlugin):
3436
pass
3537
3638
Once you have your ``BeetsPlugin`` subclass, there's a variety of things your
3739
plugin can do. (Read on!)
3840

39-
To use your new plugin, make sure the directory that contains your
40-
``beetsplug`` directory is in the Python
41-
path (using ``PYTHONPATH`` or by installing in a `virtualenv`_, for example).
42-
Then, as described above, edit your ``config.yaml`` to include
43-
``plugins: myawesomeplugin`` (substituting the name of the Python module
44-
containing your plugin).
41+
To use your new plugin, package your plugin (see how to do this with `poetry`_
42+
or `setuptools`_, for example) and install it into your ``beets`` virtual
43+
environment. Then, add your plugin to beets configuration
4544

46-
.. _virtualenv: https://pypi.org/project/virtualenv
45+
.. code-block:: yaml
46+
47+
# config.yaml
48+
plugins:
49+
- myawesomeplugin
50+
51+
and you're good to go!
52+
53+
.. _this article: https://realpython.com/python-namespace-package/#setting-up-some-namespace-packages
54+
.. _this Stack Overflow question: https://stackoverflow.com/a/27586272/9582674
55+
.. _poetry: https://python-poetry.org/docs/pyproject/#packages
56+
.. _setuptools: https://setuptools.pypa.io/en/latest/userguide/package_discovery.html#finding-simple-packages
4757

4858
.. _add_subcommands:
4959

@@ -249,13 +259,13 @@ The events currently available are:
249259
during a ``beet import`` interactive session. Plugins can use this event for
250260
:ref:`appending choices to the prompt <append_prompt_choices>` by returning a
251261
list of ``PromptChoices``. Parameters: ``task`` and ``session``.
252-
262+
253263
* `mb_track_extract`: called after the metadata is obtained from
254264
MusicBrainz. The parameter is a ``dict`` containing the tags retrieved from
255265
MusicBrainz for a track. Plugins must return a new (potentially empty)
256266
``dict`` with additional ``field: value`` pairs, which the autotagger will
257267
apply to the item, as flexible attributes if ``field`` is not a hardcoded
258-
field. Fields already present on the track are overwritten.
268+
field. Fields already present on the track are overwritten.
259269
Parameter: ``data``
260270

261271
* `mb_album_extract`: Like `mb_track_extract`, but for album tags. Overwrites

docs/faq.rst

+10-8
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,8 @@ pages.
174174
…report a bug in beets?
175175
-----------------------
176176

177-
We use the `issue tracker <https://github.com/beetbox/beets/issues>`__
178-
on GitHub. `Enter a new issue <https://github.com/beetbox/beets/issues/new>`__
179-
there to report a bug. Please follow these guidelines when reporting an issue:
177+
We use the `issue tracker`_ on GitHub where you can `open a new ticket`_.
178+
Please follow these guidelines when reporting an issue:
180179

181180
- Most importantly: if beets is crashing, please `include the
182181
traceback <https://imgur.com/jacoj>`__. Tracebacks can be more
@@ -206,6 +205,7 @@ If you've never reported a bug before, Mozilla has some well-written
206205
`general guidelines for good bug
207206
reports`_.
208207

208+
.. _issue tracker: https://github.com/beetbox/beets/issues
209209
.. _general guidelines for good bug reports: https://developer.mozilla.org/en-US/docs/Mozilla/QA/Bug_writing_guidelines
210210

211211

@@ -343,11 +343,11 @@ read the file. You can also use specialized programs for checking file
343343
integrity---for example, type ``metaflac --list music.flac`` to check
344344
FLAC files.
345345

346-
If beets still complains about a file that seems to be valid, `file a
347-
bug <https://github.com/beetbox/beets/issues/new>`__ and we'll look into
348-
it. There's always a possibility that there's a bug "upstream" in the
349-
`Mutagen <https://github.com/quodlibet/mutagen>`__ library used by beets,
350-
in which case we'll forward the bug to that project's tracker.
346+
If beets still complains about a file that seems to be valid, `open a new
347+
ticket`_ and we'll look into it. There's always a possibility that there's
348+
a bug "upstream" in the `Mutagen <https://github.com/quodlibet/mutagen>`__
349+
library used by beets, in which case we'll forward the bug to that project's
350+
tracker.
351351

352352

353353
.. _importhang:
@@ -398,3 +398,5 @@ try `this Super User answer`_.
398398

399399
.. _this Super User answer: https://superuser.com/a/284361/4569
400400
.. _pip: https://pip.pypa.io/en/stable/
401+
.. _open a new ticket:
402+
https://github.com/beetbox/beets/issues/new?template=bug-report.md

docs/guides/tagger.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ all of these limitations.
7676
Musepack, Windows Media, Opus, and AIFF files are supported. (Do you use
7777
some other format? Please `file a feature request`_!)
7878

79-
.. _file a feature request: https://github.com/beetbox/beets/issues/new
79+
.. _file a feature request:
80+
https://github.com/beetbox/beets/issues/new?template=feature-request.md
8081

8182
Now that that's out of the way, let's tag some music.
8283

setup.cfg

+2
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ allow_any_generics = false
3737
# FIXME: Would be better to actually type the libraries (if under our control),
3838
# or write our own stubs. For now, silence errors
3939
ignore_missing_imports = true
40+
namespace_packages = true
41+
explicit_package_bases = true

test/plugins/lyrics_pages.py

-10
Original file line numberDiff line numberDiff line change
@@ -456,16 +456,6 @@ def backend(self) -> str:
456456
LyricsPage.make(
457457
"https://www.musica.com/letras.asp?letra=59862",
458458
"""
459-
Lady Madonna, children at your feet
460-
Wonder how you manage to make ends meet
461-
Who finds the money when you pay the rent?
462-
Did you think that money was heaven sent?
463-
464-
Friday night arrives without a suitcase
465-
Sunday morning creeping like a nun
466-
Monday's child has learned to tie his bootlace
467-
See how they run
468-
469459
Lady Madonna, baby at your breast
470460
Wonders how you manage to feed the rest
471461

test/plugins/test_importadded.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def setUp(self):
5757
os.path.getmtime(mfile.path) for mfile in self.import_media
5858
)
5959
self.matcher = AutotagStub().install()
60-
self.matcher.macthin = AutotagStub.GOOD
60+
self.matcher.matching = AutotagStub.IDENT
6161
self.importer = self.setup_importer()
6262
self.importer.add_choice(importer.action.APPLY)
6363

test/test_importer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ def setUp(self):
440440
self.prepare_album_for_import(1)
441441
self.setup_importer()
442442
self.matcher = AutotagStub().install()
443-
self.matcher.macthin = AutotagStub.GOOD
443+
self.matcher.matching = AutotagStub.IDENT
444444

445445
def tearDown(self):
446446
super().tearDown()

0 commit comments

Comments
 (0)