Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 6 additions & 27 deletions beets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,16 @@
# included in all copies or substantial portions of the Software.


from sys import stderr

import confuse

from .config import IncludeLazyConfig, config
from .util import deprecate_imports

__version__ = "2.5.1"
__author__ = "Adrian Sampson <[email protected]>"
__version__: str = "2.5.1"
__author__: str = "Adrian Sampson <[email protected]>"

__all__: list[str] = ["IncludeLazyConfig", "config"]


def __getattr__(name: str):
def __getattr__(name: str) -> str:
"""Handle deprecated imports."""
return deprecate_imports(
old_module=__name__,
Expand All @@ -34,23 +33,3 @@ def __getattr__(name: str):
name=name,
version="3.0.0",
)


class IncludeLazyConfig(confuse.LazyConfig):
"""A version of Confuse's LazyConfig that also merges in data from
YAML files specified in an `include` setting.
"""

def read(self, user=True, defaults=True):
super().read(user, defaults)

try:
for view in self["include"]:
self.set_file(view.as_filename())
except confuse.NotFoundError:
pass
except confuse.ConfigReadError as err:
stderr.write(f"configuration `import` failed: {err.reason}")


config = IncludeLazyConfig("beets", __name__)
3 changes: 2 additions & 1 deletion beets/autotag/distance.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
from unidecode import unidecode

from beets import config, metadata_plugins
from beets.util import as_string, cached_classproperty, get_most_common_tags
from beets.util import as_string, cached_classproperty
from beets.util.misc import get_most_common_tags

if TYPE_CHECKING:
from collections.abc import Iterator, Sequence
Expand Down
2 changes: 1 addition & 1 deletion beets/autotag/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

from beets import config, logging, metadata_plugins
from beets.autotag import AlbumInfo, AlbumMatch, TrackInfo, TrackMatch, hooks
from beets.util import get_most_common_tags
from beets.util.misc import get_most_common_tags

from .distance import VA_ARTISTS, distance, track_distance

Expand Down
26 changes: 26 additions & 0 deletions beets/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from sys import stderr

import confuse
from typing_extensions import override


class IncludeLazyConfig(confuse.LazyConfig):
"""A version of Confuse's LazyConfig that also merges in data from
YAML files specified in an `include` setting.
"""

@override
def read(self, user: bool = True, defaults: bool = True) -> None:
super().read(user, defaults)

try:
view: confuse.Subview
for view in self["include"]:
self.set_file(view.as_filename())
except confuse.NotFoundError:
pass
except confuse.ConfigReadError as err:
_ = stderr.write(f"configuration `import` failed: {err.reason}")


config: IncludeLazyConfig = IncludeLazyConfig("beets", __name__)
Loading