Skip to content

fix: get package version from installed module instead of pyproject.toml#438

Merged
rayrayraykk merged 2 commits intoagentscope-ai:mainfrom
bcfre:dev
Feb 11, 2026
Merged

fix: get package version from installed module instead of pyproject.toml#438
rayrayraykk merged 2 commits intoagentscope-ai:mainfrom
bcfre:dev

Conversation

@bcfre
Copy link
Copy Markdown
Contributor

@bcfre bcfre commented Feb 6, 2026

Description

[Describe what this PR does and why]

Fix _get_package_version() failing to retrieve version when the package is installed via pip/uv.

Problem: The original implementation only attempts to find and parse pyproject.toml to get the package version. This causes two issues:

  1. Missing pyproject.toml: When agentscope-runtime is installed into a virtual environment (e.g., .venv via uv or pip), the pyproject.toml file does not exist in the installed package location, causing the function to return an empty string.

  2. Wrong pyproject.toml: If the user's local project has its own pyproject.toml file, the function may mistakenly read the user's project version instead of the agentscope-runtime version.

Solution: Prioritize importing the version from agentscope_runtime.version module (which is always available in the installed package), and only fallback to parsing pyproject.toml for development scenarios where running from source.

Related Issue: N/A

Security Considerations: N/A

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Refactoring

Component(s) Affected

  • Engine
  • Sandbox
  • Tools
  • Common
  • Documentation
  • Tests
  • CI/CD

Checklist

  • Pre-commit hooks pass
  • Tests pass locally
  • Documentation updated (if needed)
  • Ready for review

Testing

[How to test these changes]

# After installing the package via pip/uv
from agentscope_runtime.engine.deployers.utils.detached_app import _get_package_version
print(_get_package_version())  # Should output: "1.1.0b3" (or current version)

Additional Notes

[Optional: any other context]

@bcfre bcfre requested a review from a team February 6, 2026 10:00
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello @bcfre, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the package version retrieval mechanism within agentscope-runtime to ensure accurate version reporting across different installation and development scenarios. The primary goal is to prevent issues where the version might be incorrectly read from a local pyproject.toml or not found at all when the package is installed via tools like pip or uv.

Highlights

  • Version Retrieval Logic: The _get_package_version function now prioritizes importing the version directly from the agentscope_runtime.version module, ensuring accurate version reporting for installed packages.
  • Fallback Mechanism: Parsing pyproject.toml is now a fallback method, primarily intended for development environments, addressing issues where pyproject.toml might be missing or incorrect in installed package locations.
  • Version String Normalization: The function includes logic to strip a leading 'v' character from the retrieved version string (e.g., "v1.1.0b3" becomes "1.1.0b3") for consistency.
Changelog
  • src/agentscope_runtime/engine/deployers/utils/detached_app.py
    • Modified the _get_package_version function to first attempt importing __version__ from agentscope_runtime.version.
    • Added logic to remove a 'v' prefix from the version string if present.
    • Updated the function's docstring to reflect the new version retrieval strategy, emphasizing the fallback to pyproject.toml for development.
    • Ensured pyproject.toml parsing is only attempted if tomllib is available.
Activity
  • The pull request was created by bcfre.
  • No human activity (comments, reviews, or approvals) has been recorded yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@cla-assistant
Copy link
Copy Markdown

cla-assistant bot commented Feb 6, 2026

CLA assistant check
All committers have signed the CLA.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly addresses a bug where the package version could not be retrieved when installed via pip/uv. The approach of first trying to get the version from the installed module and falling back to parsing pyproject.toml is sound. I've provided one suggestion to use importlib.metadata which is the standard and more robust way to get an installed package's version in modern Python.

Comment thread src/agentscope_runtime/engine/deployers/utils/detached_app.py
Copy link
Copy Markdown
Member

@rayrayraykk rayrayraykk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for your contributions to AgentScope!

@rayrayraykk rayrayraykk merged commit 426107a into agentscope-ai:main Feb 11, 2026
7 checks passed
@rayrayraykk
Copy link
Copy Markdown
Member

@all-contributors please add @bcfre for code

@allcontributors
Copy link
Copy Markdown
Contributor

@rayrayraykk

I've put up a pull request to add @bcfre! 🎉

@bcfre bcfre deleted the dev branch February 11, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants