mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2026-04-07 23:02:40 +02:00
Fix `ModuleNotFoundError: No module named 'pkg_resources'` error when building with setuptools 82. Ref: https://gitlab.alpinelinux.org/alpine/aports/-/issues/18025
44 lines
1.7 KiB
Diff
44 lines
1.7 KiB
Diff
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 '<Unknown>' if no version can be found
|
|
"""
|
|
- version = '<Unknown>'
|
|
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 "<Unknown>"
|
|
|
|
def sp_code_in_scad_comment(calling_file: PathStr) -> str:
|
|
"""
|