Skip to content
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

Replace pkg_resources with importlib.metadata; bump minor version number #3

Merged
merged 2 commits into from
Mar 30, 2024
Merged
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
7 changes: 5 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
[tool.poetry]
name = "plaster_yaml"
version = "0.1.2"
version = "0.2.0"
description = "A plaster plugin to configure pyramid app with Yaml"
readme = "README.md"
authors = ["Guillaume Gauvrit <guillaume@gauvr.it>"]
include = ["CHANGELOG.md"]
license = "BSD-derived"

[tool.poetry.dependencies]
# See: https://pypi.org/project/backports.entry-points-selectable
importlib_metadata = { version = ">=3.6", python = "<3.10" }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was waiting to drop the python 3.7 support to remove pkg_resources usage.

Is it ok for you to drop python 3.7 support ?

importlib.metadata is avaible in python 3.8
so updating the ligne 13 with the code below should be enough.

python = "^3.8"

python = "^3.7"
plaster = "^1.0"
PyYAML = "^5.4.1"
# Upgraded PyYAML from ^5.4 due to: https://github.com/yaml/pyyaml/issues/601
PyYAML = "^6.0.1"

[tool.poetry.dev-dependencies]
black = "^21.4b0"
Expand Down
14 changes: 12 additions & 2 deletions src/plaster_yaml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
import pkg_resources
import sys

if sys.version_info < (3, 10):
import importlib_metadata

class importlib:
pass

setattr(importlib, "metadata", importlib_metadata)
else:
import importlib.metadata
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is why I dislike that. 11 lines of code to retrieve a version number. this is outstanding.

please remove python 3.7 support and everything will be much simpler.


from .loader import Loader # noqa

__version__ = pkg_resources.get_distribution("plaster-yaml").version
__version__ = importlib.metadata.version("plaster-yaml")
17 changes: 14 additions & 3 deletions src/plaster_yaml/loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,18 @@
from logging.config import dictConfig
from typing import Callable

import pkg_resources
import sys

if sys.version_info < (3, 10):
import importlib_metadata

class importlib:
pass

setattr(importlib, "metadata", importlib_metadata)
else:
import importlib.metadata

import plaster
import yaml

Expand Down Expand Up @@ -39,8 +50,8 @@ def resolve_use(use: str, entrypoint: str) -> Callable:
if scheme != "egg":
raise ValueError(f"{use}: unsupported scheme {scheme}")

distribution = pkg_resources.get_distribution(pkg)
runner = distribution.get_entry_info(entrypoint, name)
eps = importlib.metadata.entry_points(group=entrypoint, name=name)
(runner,) = [ep for ep in eps if ep.module.split(".")[0] == pkg]
return runner.load()


Expand Down
1 change: 0 additions & 1 deletion tests/test_plaster_yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import pytest
from gunicorn.app.pasterapp import serve as gunicorn_serve_paste
from pkg_resources import DistributionNotFound
from waitress import serve_paste as waitress_serve_paste

from plaster_yaml.loader import resolve_use
Expand Down