Skip to content

Commit

Permalink
Replace pkg_resources (#38)
Browse files Browse the repository at this point in the history
Importing pkg_resources is slow.

According to setuptools, use of pkg_resources is discouraged in favor of
importlib.metadata

`importlib.metadata` was introduced in Python 3.8 but there exists a
backport (`importlib_metadata`) for older versions of Python.

See: https://setuptools.pypa.io/en/latest/pkg_resources.html
  • Loading branch information
mgu authored Feb 22, 2023
1 parent e38bc26 commit 3d35380
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
7 changes: 5 additions & 2 deletions onfido/resource.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import pkg_resources
import requests
from .onfido_download import OnfidoDownload
from .exceptions import error_decorator, OnfidoUnknownError
from .mimetype import mimetype_from_name
from .utils import form_data_converter

try:
import importlib.metadata as importlib_metadata
except ImportError:
import importlib_metadata

CURRENT_VERSION = pkg_resources.get_distribution("onfido-python").version
CURRENT_VERSION = importlib_metadata.version("onfido-python")

class Resource:
def __init__(self, api_token, region, timeout):
Expand Down
6 changes: 3 additions & 3 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ packages = [
[tool.poetry.dependencies]
python = ">=3.6,<4"
requests = "^2.24.0"
importlib-metadata = {version = ">=0.12", markers = "python_version < \"3.8\""}

[tool.poetry.dev-dependencies]
pytest = "*"
Expand Down

0 comments on commit 3d35380

Please sign in to comment.