Ref: https://github.com/SolidCode/SolidPython/pull/215/commits/921280e851ebfcf7eb4beecbb4f7906207451a1c --- diff -rupN a/solid/solidpython.py b/solid/solidpython.py --- a/solid/solidpython.py 2021-10-02 18:52:16.690056300 +0000 +++ b/solid/solidpython.py 2026-03-31 23:53:13.360000000 +0000 @@ -23,7 +23,9 @@ from typing import Set, Sequence, List, from types import ModuleType from typing import Callable, Iterable, List, Optional, Sequence, Set, Union, Dict -import pkg_resources +from importlib import metadata +from importlib.metadata import PackageNotFoundError + import re PathStr = Union[Path, str] @@ -567,21 +569,15 @@ def _get_version() -> str: Returns SolidPython version Returns '' if no version can be found """ - version = '' try: - # if SolidPython is installed use `pkg_resources` - version = pkg_resources.get_distribution('solidpython').version - - except pkg_resources.DistributionNotFound: - # if the running SolidPython is not the one installed via pip, - # try to read it from the project setup file - version_pattern = re.compile(r"version = ['\"]([^'\"]*)['\"]") - version_file_path = Path(__file__).parent.parent / 'pyproject.toml' + return metadata.version("solidpython") + except PackageNotFoundError: + version_file_path = Path(__file__).parent.parent / "pyproject.toml" if version_file_path.exists(): version_match = version_pattern.search(version_file_path.read_text()) if version_match: - version = version_match.group(1) - return version + return version_match.group(1) + return "" def sp_code_in_scad_comment(calling_file: PathStr) -> str: """