Skip to content

Commit 426107a

Browse files
authored
fix: get package version from installed module instead of pyproject.toml (#438)
1 parent 93be587 commit 426107a

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/agentscope_runtime/engine/deployers/utils/detached_app.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,29 @@ def _parse_pyproject_toml(pyproject_path: Path) -> List[str]:
305305

306306
def _get_package_version() -> str:
307307
"""
308-
Get the package version from pyproject.toml file.
308+
Get the package version.
309+
310+
Tries multiple methods in order:
311+
1. Import from agentscope_runtime.version module
312+
2. Fallback to parsing pyproject.toml (for development)
309313
310314
Returns:
311315
str: The version string, or empty string if not found
312316
"""
313-
# Try to find pyproject.toml in the current directory and parent
314-
# directories
317+
# Method 1: Try importing from version module directly
318+
try:
319+
from agentscope_runtime.version import __version__
320+
321+
if __version__:
322+
# Remove 'v' prefix if present (e.g., "v1.1.0b3" -> "1.1.0b3")
323+
return __version__.lstrip("v")
324+
except ImportError:
325+
pass
326+
327+
# Method 2: Fallback to pyproject.toml (for development from source)
328+
if tomllib is None:
329+
return ""
330+
315331
current_dir = Path(__file__).parent
316332
for _ in range(6): # Look up to 6 levels up
317333
pyproject_path = current_dir / "pyproject.toml"

0 commit comments

Comments
 (0)