Fix the BUG in the __init__ file of openhands to obtain the version (#9840)

Co-authored-by: yinjiaqi <yinjiaqi@baidu.com>
This commit is contained in:
C9luster
2025-07-29 00:13:21 +08:00
committed by GitHub
parent 60e8e55311
commit c677f7284e

View File

@@ -1,4 +1,5 @@
import os
from pathlib import Path
__package_name__ = 'openhands_ai'
@@ -7,10 +8,16 @@ def get_version():
# 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('"')
candidate_paths = [
Path(root_dir) / 'pyproject.toml',
Path(root_dir) / 'openhands' / 'pyproject.toml',
]
for file_path in candidate_paths:
if file_path.is_file():
with open(file_path, 'r') as f:
for line in f:
if line.strip().startswith('version ='):
return line.split('=', 1)[1].strip().strip('"').strip("'")
except FileNotFoundError:
pass