mirror of
https://github.com/OpenHands/OpenHands.git
synced 2025-12-26 05:48:36 +08:00
42 lines
1006 B
Python
42 lines
1006 B
Python
import os
|
|
|
|
|
|
def get_version():
|
|
try:
|
|
from importlib.metadata import PackageNotFoundError, version
|
|
|
|
try:
|
|
return version('openhands-ai')
|
|
except PackageNotFoundError:
|
|
pass
|
|
except ImportError:
|
|
pass
|
|
|
|
try:
|
|
from pkg_resources import DistributionNotFound, get_distribution
|
|
|
|
try:
|
|
return get_distribution('openhands-ai').version
|
|
except DistributionNotFound:
|
|
pass
|
|
except ImportError:
|
|
pass
|
|
|
|
# Try getting the version from pyproject.toml
|
|
try:
|
|
root_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
with open(os.path.join(root_dir, 'pyproject.toml'), 'r') as f:
|
|
for line in f:
|
|
if line.startswith('version ='):
|
|
return line.split('=')[1].strip().strip('"')
|
|
except FileNotFoundError:
|
|
pass
|
|
|
|
return 'unknown'
|
|
|
|
|
|
try:
|
|
__version__ = get_version()
|
|
except Exception:
|
|
__version__ = 'unknown'
|