-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add deprecation warning for musicbrainz.enabled but use it to load the plugin, centralise deprecations handling
#6127
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
Open
snejus
wants to merge
7
commits into
master
Choose a base branch
from
always-enable-mb
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
b04e827
Move deprecate_imports to beets.util.deprecation
snejus 737908b
Centralise warnings for maintainers into deprecate_for_maintainers
snejus 8e7dbae
Add deprecate_for_user function
snejus 07d8a23
Load musicbrainz implicitly and supply a deprecation warning
snejus 2b9efca
Warn users of deprecated musicbrainz.enabled option
snejus e3fa528
Do not show a warning to users that have musicbrainz disabled
snejus 9fdcd0a
Do not force load musicbrainz, add a test to show the behaviour
snejus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,7 @@ | |
|
|
||
| import confuse | ||
|
|
||
| from .util import deprecate_imports | ||
| from .util.deprecation import deprecate_imports | ||
|
|
||
| __version__ = "2.5.1" | ||
| __author__ = "Adrian Sampson <[email protected]>" | ||
|
|
@@ -26,13 +26,7 @@ | |
| def __getattr__(name: str): | ||
| """Handle deprecated imports.""" | ||
| return deprecate_imports( | ||
| old_module=__name__, | ||
| new_module_by_name={ | ||
| "art": "beetsplug._utils", | ||
| "vfs": "beetsplug._utils", | ||
| }, | ||
| name=name, | ||
| version="3.0.0", | ||
| __name__, {"art": "beetsplug._utils", "vfs": "beetsplug._utils"}, name | ||
| ) | ||
|
|
||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| from __future__ import annotations | ||
|
|
||
| import warnings | ||
| from importlib import import_module | ||
| from typing import TYPE_CHECKING, Any | ||
|
|
||
| from packaging.version import Version | ||
|
|
||
| import beets | ||
|
|
||
| if TYPE_CHECKING: | ||
| from logging import Logger | ||
|
|
||
|
|
||
| def _format_message(old: str, new: str | None = None) -> str: | ||
| next_major = f"{Version(beets.__version__).major + 1}.0.0" | ||
| msg = f"{old} is deprecated and will be removed in version {next_major}." | ||
| if new: | ||
| msg += f" Use {new} instead." | ||
|
|
||
| return msg | ||
|
|
||
|
|
||
| def deprecate_for_user( | ||
| logger: Logger, old: str, new: str | None = None | ||
| ) -> None: | ||
| logger.warning(_format_message(old, new)) | ||
|
|
||
|
|
||
| def deprecate_for_maintainers( | ||
| old: str, new: str | None = None, stacklevel: int = 1 | ||
| ) -> None: | ||
| """Issue a deprecation warning visible to maintainers during development. | ||
|
|
||
| Emits a DeprecationWarning that alerts developers about deprecated code | ||
| patterns. Unlike user-facing warnings, these are primarily for internal | ||
| code maintenance and appear during test runs or with warnings enabled. | ||
| """ | ||
| warnings.warn( | ||
| _format_message(old, new), DeprecationWarning, stacklevel=stacklevel + 1 | ||
| ) | ||
|
|
||
|
|
||
| def deprecate_imports( | ||
| old_module: str, new_module_by_name: dict[str, str], name: str | ||
| ) -> Any: | ||
| """Handle deprecated module imports by redirecting to new locations. | ||
|
|
||
| Facilitates gradual migration of module structure by intercepting import | ||
| attempts for relocated functionality. Issues deprecation warnings while | ||
| transparently providing access to the moved implementation, allowing | ||
| existing code to continue working during transition periods. | ||
| """ | ||
| if new_module := new_module_by_name.get(name): | ||
| deprecate_for_maintainers( | ||
| f"'{old_module}.{name}'", f"'{new_module}.{name}'", stacklevel=2 | ||
| ) | ||
|
|
||
| return getattr(import_module(new_module), name) | ||
| raise AttributeError(f"module '{old_module}' has no attribute '{name}'") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
Could you try to keep the trailing commas here? I recon we might add more imports here in the future.
See COM812:
The presence of a trailing comma can reduce diff size when parameters or elements are added or removed from function calls, function definitions, literals, etc.