Skip to content

πŸ™Œ OpenHands: AI-Driven Development

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

C9lusterc677f7284ee6
diff --git a/openhands/__init__.py b/openhands/__init__.py
index 29c1c410b3..6f88bb7e3c 100644
--- a/openhands/__init__.py
+++ b/openhands/__init__.py
@@ -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