Skip to content

Commit d3ba918

Browse files
authored
Merge pull request #20 from nocarryr/importlib_metadata
Use importlib.metadata for runtime `__version__` detection
2 parents e00e192 + 0dcbf27 commit d3ba918

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

pydispatch/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
import sys
22
import warnings
3-
import pkg_resources
3+
try:
4+
import importlib.metadata as importlib_metadata
5+
except ImportError:
6+
import importlib_metadata
47

58
try:
6-
__version__ = pkg_resources.require('python-dispatch')[0].version
9+
__version__ = importlib_metadata.version('python-dispatch')
710
except: # pragma: no cover
811
__version__ = 'unknown'
912

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ license_file = LICENSE.txt
1616
keywords = event properties dispatch
1717
platforms = any
1818
python_requires = >=3.6
19+
install_requires =
20+
importlib_metadata;python_version<'3.8'
1921
classifiers =
2022
Development Status :: 3 - Alpha
2123
Intended Audience :: Developers

tests/test_version_attribute.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
from pathlib import Path
3+
from setuptools.config import read_configuration
4+
5+
6+
PROJECT_ROOT = Path(__file__).parent.parent.resolve()
7+
SETUP_CFG = PROJECT_ROOT / 'setup.cfg'
8+
9+
def get_expected_version(config_file: Path = SETUP_CFG) -> str:
10+
conf_dict = read_configuration(str(config_file))
11+
return conf_dict['metadata']['version']
12+
13+
EXPECTED_VERSION = get_expected_version()
14+
15+
16+
def test_version():
17+
import pydispatch
18+
assert pydispatch.__version__ == EXPECTED_VERSION

0 commit comments

Comments
 (0)