Skip to content

Commit 6d855ee

Browse files
committed
refactor: simplify version retrieval logic
Remove complex fallback mechanism for package version. Keep only importlib.metadata.version() which works in production. If it fails, gracefully return None.
1 parent 2678a4f commit 6d855ee

File tree

1 file changed

+3
-29
lines changed

1 file changed

+3
-29
lines changed

src/reachy_mini/daemon/daemon.py

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,38 +42,12 @@ def __init__(self, log_level: str = "INFO", wireless_version: bool = False) -> N
4242
self.wireless_version = wireless_version
4343

4444
self.backend: "RobotBackend | MujocoBackend | None" = None
45-
# Get package version - try multiple methods
46-
package_version = None
45+
# Get package version
4746
try:
48-
# Method 1: Try importlib.metadata (works when package is installed)
4947
package_version = version("reachy_mini")
50-
except Exception:
51-
try:
52-
# Method 2: Try reading from pyproject.toml directly (fallback)
53-
import os
54-
import re
55-
# Try to find pyproject.toml relative to this file
56-
current_dir = os.path.dirname(__file__)
57-
# Go up: daemon/ -> daemon/ -> reachy_mini/ -> src/ -> reachy_mini/
58-
pyproject_path = os.path.join(
59-
current_dir, "..", "..", "..", "..", "pyproject.toml"
60-
)
61-
pyproject_path = os.path.abspath(pyproject_path)
62-
if os.path.exists(pyproject_path):
63-
# Simple regex to extract version from pyproject.toml
64-
with open(pyproject_path, "r", encoding="utf-8") as f:
65-
content = f.read()
66-
match = re.search(r'version\s*=\s*["\']([^"\']+)["\']', content)
67-
if match:
68-
package_version = match.group(1)
69-
except Exception as e:
70-
# Method 3: Fallback to None
71-
self.logger.debug(f"Could not get package version: {e}")
72-
package_version = None
73-
74-
if package_version:
7548
self.logger.info(f"Daemon version: {package_version}")
76-
else:
49+
except Exception:
50+
package_version = None
7751
self.logger.warning("Could not determine daemon version")
7852

7953
self._status = DaemonStatus(

0 commit comments

Comments
 (0)