Skip to content

Commit

Permalink
Drop deprecated packaging metadata (#69)
Browse files Browse the repository at this point in the history
* Drop deprecated packaging metadata

Keeping __version__ around since it's still widely used, unfortunately.

Fixes #68

* Fix sphinx build error
  • Loading branch information
hynek authored Jun 26, 2024
1 parent 5c365f6 commit d3ccbdd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 61 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@

html_theme = "furo"
html_theme_options = {
"top_of_page_button": None,
"top_of_page_buttons": [],
"light_css_variables": {
"font-stack": "Inter, sans-serif",
"font-stack--monospace": "BerkeleyMono, MonoLisa, ui-monospace, "
Expand Down
31 changes: 3 additions & 28 deletions src/service_identity/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,35 +29,10 @@


def __getattr__(name: str) -> str:
dunder_to_metadata = {
"__version__": "version",
"__description__": "summary",
"__uri__": "",
"__url__": "",
"__email__": "",
}
if name not in dunder_to_metadata:
if name != "__version__":
msg = f"module {__name__} has no attribute {name}"
raise AttributeError(msg)

import warnings
from importlib.metadata import version

from importlib.metadata import metadata

warnings.warn(
f"Accessing service_identity.{name} is deprecated and will be "
"removed in a future release. Use importlib.metadata directly "
"to query packaging metadata.",
DeprecationWarning,
stacklevel=2,
)

meta = metadata("service-identity")

if name in ("__uri__", "__url__"):
return meta["Project-URL"].split(" ", 1)[1]

if name == "__email__":
return meta["Author-email"].split("<", 1)[1].rstrip(">")

return meta[dunder_to_metadata[name]]
return version("service-identity")
36 changes: 4 additions & 32 deletions tests/test_packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,10 @@ def test_version(self):
"""
service_identity.__version__ returns the correct version.
"""
with pytest.deprecated_call():
assert (
metadata.version("service-identity")
== service_identity.__version__
)

def test_description(self):
"""
service_identity.__description__ returns the correct description.
"""
with pytest.deprecated_call():
assert (
"Service identity verification for pyOpenSSL & cryptography."
== service_identity.__description__
)

@pytest.mark.parametrize("name", ["uri", "url"])
def test_uri(self, name):
"""
service_identity.__uri__ & __url__ return the correct project URL.
"""
with pytest.deprecated_call():
assert "https://service-identity.readthedocs.io/" == getattr(
service_identity, f"__{name}__"
)

def test_email(self):
"""
service_identity.__email__ returns Hynek's email address.
"""
with pytest.deprecated_call():
assert "[email protected]" == service_identity.__email__
assert (
metadata.version("service-identity")
== service_identity.__version__
)

def test_does_not_exist(self):
"""
Expand Down

0 comments on commit d3ccbdd

Please sign in to comment.