Skip to content

Commit 278f531

Browse files
committed
Do not use pkg_resources to get version anymore
Calling `get_distribution` has a significant runtime cost. This commit avoid this call by leveraging the write_to feature of setuptools_scm.
1 parent 2ae40e7 commit 278f531

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ __pycache__/
44
.coverage
55
.tox
66
stagpy.egg-info/
7+
/stagpy/_version.py
78
/stagpy_git/
89
docs/_build/
910
docs/_static/

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ requires = ["setuptools>=51", "setuptools_scm>=6.3.2", "wheel"]
33
build-backend = "setuptools.build_meta"
44

55
[tool.setuptools_scm]
6+
write_to = "stagpy/_version.py"
67

78
[tool.mypy]
89
disallow_untyped_defs = true

stagpy/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
import sys
2525
import typing
2626

27-
from pkg_resources import get_distribution, DistributionNotFound
2827
from setuptools_scm import get_version
2928
from loam.manager import ConfigurationManager
3029

@@ -105,9 +104,10 @@ def load_mplstyle() -> None:
105104
try:
106105
__version__ = get_version(root='..', relative_to=__file__)
107106
except LookupError:
108-
__version__ = get_distribution('stagpy').version
109-
except (DistributionNotFound, ValueError):
110-
__version__ = 'unknown'
107+
try:
108+
from ._version import version as __version__
109+
except ImportError:
110+
__version__ = "unknown"
111111

112112
_CONF_FILES = ([config.CONFIG_FILE, config.CONFIG_LOCAL]
113113
if not ISOLATED else [])

0 commit comments

Comments
 (0)