Skip to content
This repository was archived by the owner on Sep 12, 2024. It is now read-only.

Commit 819f029

Browse files
committed
Remove usage of deprecated pkg_resources
1 parent 43469a4 commit 819f029

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

duffel_api/utils.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1-
"""Assorted auxiliary functions"""
1+
"""Assorted auxiliary functions."""
22
from datetime import datetime
33
from typing import Any
44

55

66
def identity(value: Any) -> Any:
7-
"""Given a value, return the exact same value"""
7+
"""Given a value, return the exact same value."""
88
return value
99

1010

1111
def get_and_transform(dict: dict, key: str, fn, default=None):
12-
"""Get a value from a dictionary and transform it or return
13-
None if the key isn't present"""
12+
"""Get a value from a dictionary and transform it or return None if the key isn't
13+
present.
14+
"""
1415
try:
1516
value = dict[key]
1617
if value is None:
@@ -22,14 +23,14 @@ def get_and_transform(dict: dict, key: str, fn, default=None):
2223

2324

2425
def version() -> str:
25-
"""Return the version specified in the package (setup.py) during runtime"""
26-
import pkg_resources
26+
"""Return the version specified in the package (setup.py) during runtime."""
27+
from importlib.metadata import version
2728

28-
return pkg_resources.require("duffel_api")[0].version
29+
return version("duffel_api")
2930

3031

3132
def parse_datetime(value: str) -> datetime:
32-
"""Parse a datetime string regardless of having milliseconds or not"""
33+
"""Parse a datetime string regardless of having milliseconds or not."""
3334
# There are inconsistent formats used for the field, therefore we try to accomodate
3435
# instead of making an API breaking change.
3536
if len(value) == 20:

tests/test_utils.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
import pytest
44

5-
from duffel_api.utils import parse_datetime
5+
from duffel_api.utils import parse_datetime, version
6+
7+
8+
def test_version():
9+
# We only check for any content for now
10+
assert version()
611

712

813
def test_parse_datetime():

0 commit comments

Comments
 (0)