Skip to content

Commit 958618a

Browse files
authored
Merge pull request #16 from hsorby/main
Improve getting version from importlib metadata.
2 parents 9a8bb73 + 9053c3d commit 958618a

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

pyproject.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ name = "cmlibs.maths"
1010
dynamic = ["version"]
1111
keywords = ["Math", "CMLibs", "Zinc"]
1212
readme = "README.rst"
13-
license = {file = "LICENSE"}
13+
license = "Apache-2.0"
1414
authors = [
1515
{ name="Hugh Sorby", email="[email protected]" },
1616
]
@@ -20,13 +20,12 @@ description = "A collection of math functions and algorithms."
2020
requires-python = ">=3.8"
2121
classifiers = [
2222
"Programming Language :: Python :: 3",
23-
"License :: OSI Approved :: Apache Software License",
2423
"Operating System :: OS Independent",
2524
"Topic :: Scientific/Engineering :: Medical Science Apps.",
2625
]
2726

2827
[project.urls]
2928
Homepage = "https://cmlibs.org"
30-
Repository = "https://github.com/CMLibs-Python/cmlibs.utils"
29+
Repository = "https://github.com/CMLibs-Python/cmlibs.maths"
3130

3231
[tool.setuptools_scm]

src/cmlibs/maths/__init__.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,14 @@
1-
import importlib.metadata
1+
from importlib import metadata
22

3-
__version__ = importlib.metadata.version("cmlibs_maths")
3+
4+
def get_version(package_name: str, fallback: str = "X.Y.Z") -> str:
5+
try:
6+
return metadata.version(package_name)
7+
except metadata.PackageNotFoundError:
8+
try:
9+
return metadata.version(package_name.replace(".", "_"))
10+
except metadata.PackageNotFoundError:
11+
return fallback
12+
13+
14+
__version__ = get_version("cmlibs.maths")

0 commit comments

Comments
 (0)