Skip to content

Commit 3c45370

Browse files
committed
Use importlib_metadata instead of pkg_resources.
1 parent 7b3cfda commit 3c45370

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

nmigen_boards/__init__.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
import pkg_resources
21
try:
3-
__version__ = pkg_resources.get_distribution(__name__).version
4-
except pkg_resources.DistributionNotFound:
5-
pass
2+
try:
3+
from importlib import metadata as importlib_metadata # py3.8+ stdlib
4+
except ImportError:
5+
import importlib_metadata # py3.7- shim
6+
__version__ = importlib_metadata.version(__package__)
7+
except ImportError:
8+
# No importlib_metadata. This shouldn't normally happen, but some people prefer not installing
9+
# packages via pip at all, instead using PYTHONPATH directly or copying the package files into
10+
# `lib/pythonX.Y/site-packages`. Although not a recommended way, we still try to support it.
11+
__version__ = "unknown" # :nocov:

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def local_scheme(version):
2222
setup_requires=["wheel", "setuptools", "setuptools_scm"],
2323
install_requires=[
2424
"nmigen>=0.2,<0.4",
25+
"importlib_metadata; python_version<'3.8'",
2526
],
2627
packages=find_packages(),
2728
project_urls={

0 commit comments

Comments
 (0)