Skip to content

fix: derive __version__ from dist metadata instead of hardcoding it - #25

Open
robinjhuang wants to merge 2 commits into
mainfrom
fix/version-single-source
Open

fix: derive __version__ from dist metadata instead of hardcoding it#25
robinjhuang wants to merge 2 commits into
mainfrom
fix/version-single-source

Conversation

@robinjhuang

Copy link
Copy Markdown
Member

publish.yml stamps the release tag into pyproject.toml at build time and nowhere else, so the hardcoded __version__ = "0.1.0" in comfy_sdk/__init__.py would have reported the placeholder on every published release — while the wheel metadata and the User-Agent (which already reads dist metadata) reported the real version.

Verified by building with an injected 9.9.9: __version__ and the User-Agent now agree, where before __version__ stayed 0.1.0. Adds a regression test.

publish.yml stamps the release tag into pyproject.toml at build time and
nowhere else, so the hardcoded __version__ = "0.1.0" would have reported
the placeholder on every published release -- while the wheel metadata and
the User-Agent (which already reads dist metadata) said the real version.

Verified by building with an injected 9.9.9: __version__ and the
User-Agent now agree.
@robinjhuang
robinjhuang requested review from a team as code owners July 30, 2026 02:43
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Validation error: Too big: expected string to have <=250 characters at "tone_instructions"
⚙️ Configuration instructions
  • Please see the configuration documentation for more information.
  • You can also validate your configuration using the online YAML validator.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
📝 Walkthrough

Walkthrough

The package version is now read from installed distribution metadata, with a source-tree fallback, and tests verify both successful lookup and missing-metadata behavior.

Changes

Package version resolution

Layer / File(s) Summary
Runtime version lookup and validation
src/comfy_sdk/__init__.py, tests/test_version.py
__version__ uses importlib.metadata.version("comfy-sdk"), falls back to "0+unknown" when metadata is unavailable, and tests cover both paths.

Suggested reviewers: alexisrolland, wei-hai

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/version-single-source
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch fix/version-single-source

Comment @coderabbitai help to get the list of available commands.

@coderabbitai
coderabbitai Bot requested review from alexisrolland and wei-hai July 30, 2026 02:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_version.py`:
- Around line 12-18: Update test_version_matches_installed_distribution_metadata
to mock the importlib.metadata version lookup, return "9.9.9", and assert
comfy_sdk.__version__ resolves to that injected value. Remove the dependency on
the ambient installed "comfy-sdk" distribution while preserving the test’s focus
on version resolution.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 0464cc0e-85a3-4364-9575-c4f731c0d0f5

📥 Commits

Reviewing files that changed from the base of the PR and between 17a618a and 665cd76.

📒 Files selected for processing (2)
  • src/comfy_sdk/__init__.py
  • tests/test_version.py

Comment thread tests/test_version.py Outdated
wei-hai
wei-hai previously approved these changes Jul 30, 2026
…tall

The previous assertion compared __version__ against a live
importlib.metadata lookup, so both sides resolved through the same call and
it passed even when __version__ was re-hardcoded to a literal that happened
to match the installed placeholder -- confirmed by mutation: re-hardcoding
__version__ = "0.1.0" left the old assertion green.

__version__ is bound once at import, so patching the lookup alone asserts
against the value from the first import. The tests now patch and reload,
which fails on that regression, and cover the PackageNotFoundError fallback
that had no test at all. The patched import is undone and reloaded on the
way out; verified no ordering pollution and that __version__ is intact
afterwards.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tests/test_version.py`:
- Around line 43-45: Update test_version_comes_from_the_distribution_metadata to
spy on the injected metadata lookup, assert the returned version remains
"9.9.9", and verify the lookup was called with the exact distribution name
"comfy-sdk".
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d628cbdf-4faa-46c3-886d-ddf6246cb1e5

📥 Commits

Reviewing files that changed from the base of the PR and between 665cd76 and 37e38ad.

📒 Files selected for processing (1)
  • tests/test_version.py

Comment thread tests/test_version.py
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.

3 participants