Skip to content

Commit e143236

Browse files
committed
[BUG] Fix version import fallback for Python <3.8 compatibility
Replaced direct version import with a fallback mechanism using `importlib.metadata` or `importlib_metadata` for older Python versions. Ensures robust handling of `__version__` even when the package is not properly installed.
1 parent 8d315cc commit e143236

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

gempy_engine/__init__.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
11
from gempy_engine.API.model.model_api import compute_model
2+
from datetime import datetime
23

3-
from ._version import __version__
4+
try:
5+
from importlib.metadata import version, PackageNotFoundError
6+
except ImportError: # For Python <3.8, fallback
7+
from importlib_metadata import version, PackageNotFoundError
8+
9+
try:
10+
__version__ = version("gempy_engine") # Use package name
11+
except ImportError:
12+
# If it was not installed, then we don't know the version. We could throw a
13+
# warning here, but this case *should* be rare. subsurface should be
14+
# installed properly!
15+
__version__ = 'unknown-'+datetime.today().strftime('%Y%m%d')

0 commit comments

Comments
 (0)