| 1 | Ref: https://github.com/SolidCode/SolidPython/pull/215/commits/921280e851ebfcf7eb4beecbb4f7906207451a1c
|
| 2 | ---
|
| 3 | diff -rupN a/solid/solidpython.py b/solid/solidpython.py
|
| 4 | |
| 5 | |
| 6 | @@ -23,7 +23,9 @@ from typing import Set, Sequence, List,
|
| 7 | from types import ModuleType
|
| 8 | from typing import Callable, Iterable, List, Optional, Sequence, Set, Union, Dict
|
| 9 |
|
| 10 | -import pkg_resources
|
| 11 | +from importlib import metadata
|
| 12 | +from importlib.metadata import PackageNotFoundError
|
| 13 | +
|
| 14 | import re
|
| 15 |
|
| 16 | PathStr = Union[Path, str]
|
| 17 | @@ -567,21 +569,15 @@ def _get_version() -> str:
|
| 18 | Returns SolidPython version
|
| 19 | Returns '<Unknown>' if no version can be found
|
| 20 | """
|
| 21 | - version = '<Unknown>'
|
| 22 | try:
|
| 23 | - # if SolidPython is installed use `pkg_resources`
|
| 24 | - version = pkg_resources.get_distribution('solidpython').version
|
| 25 | -
|
| 26 | - except pkg_resources.DistributionNotFound:
|
| 27 | - # if the running SolidPython is not the one installed via pip,
|
| 28 | - # try to read it from the project setup file
|
| 29 | - version_pattern = re.compile(r"version = ['\"]([^'\"]*)['\"]")
|
| 30 | - version_file_path = Path(__file__).parent.parent / 'pyproject.toml'
|
| 31 | + return metadata.version("solidpython")
|
| 32 | + except PackageNotFoundError:
|
| 33 | + version_file_path = Path(__file__).parent.parent / "pyproject.toml"
|
| 34 | if version_file_path.exists():
|
| 35 | version_match = version_pattern.search(version_file_path.read_text())
|
| 36 | if version_match:
|
| 37 | - version = version_match.group(1)
|
| 38 | - return version
|
| 39 | + return version_match.group(1)
|
| 40 | + return "<Unknown>"
|
| 41 |
|
| 42 | def sp_code_in_scad_comment(calling_file: PathStr) -> str:
|
| 43 | """
|