Skip to content

fix(cli): sync version with package metadata#21

Open
looooown2006 wants to merge 2 commits intoayhammouda:mainfrom
looooown2006:fix/version-metadata-11
Open

fix(cli): sync version with package metadata#21
looooown2006 wants to merge 2 commits intoayhammouda:mainfrom
looooown2006:fix/version-metadata-11

Conversation

@looooown2006
Copy link
Copy Markdown

@looooown2006 looooown2006 commented May 9, 2026

Summary

  • Read mcp_server_python_docs.__version__ from installed package metadata.
  • Update packaging tests so --version is checked against the metadata version instead of a hardcoded string.
  • Add a regression test that keeps __version__ synchronized with package metadata.

Tests

  • git diff --check
  • uv run ruff check src/ tests/
  • uv run pyright src/
  • uv run mcp-server-python-docs --version
  • uv run pytest tests/test_packaging.py::TestVersionFlag tests/test_packaging.py::TestInstallability::test_module_runnable -q
  • $env:PYTHONUTF8='1'; uv run pytest --tb=short -q

Results:

  • mcp-server-python-docs --version now prints mcp-server-python-docs 0.1.1.
  • UTF-8 full suite: 264 passed, 1 skipped.

Local Windows note:

  • Running uv run pytest --tb=short -q without PYTHONUTF8=1 fails on this Windows shell because several existing Path.read_text() calls use the default GBK locale and hit UTF-8 bytes in repo files. With UTF-8 mode enabled, the same suite passes.

Closes #11.

Summary by CodeRabbit

  • Refactor

    • Version resolution now derives dynamically from installed package metadata with a fallback to source metadata
  • Tests

    • Enhanced version-related tests to validate module and CLI version output against distribution metadata across installed and source-tree import scenarios

Review Change Stack

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: eeeda186-b47d-4553-bf90-db72109c367e

📥 Commits

Reviewing files that changed from the base of the PR and between d4a777f and a6257a3.

📒 Files selected for processing (1)
  • tests/test_packaging.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/test_packaging.py

📝 Walkthrough

Walkthrough

This PR synchronizes package version management by replacing the hardcoded __version__ string with dynamic resolution that reads from installed package metadata, falling back to pyproject.toml when running from source. Tests now verify version consistency across both scenarios.

Changes

Version Resolution and Testing

Layer / File(s) Summary
Version Resolution Implementation
src/mcp_server_python_docs/__init__.py
Added _read_version() function that attempts to load version from importlib.metadata and falls back to parsing pyproject.toml with tomllib; __version__ now derives from this function.
Test Infrastructure
tests/test_packaging.py
Added imports for os and importlib.metadata.version to support subprocess testing and metadata-driven assertions.
Version Consistency Tests
tests/test_packaging.py
Added tests for module version matching installed package metadata and source-tree imports without installed metadata; updated test_version_flag_output() and test_module_runnable() to assert dynamic version instead of hardcoded 0.1.0.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 I hop from wheel to pyproject, sniffing the line,
No numbers carved — just metadata fine.
From installed egg to source-tree nest,
The version I fetch will pass every test. 🥕✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: syncing the CLI version with package metadata instead of using hardcoded values.
Linked Issues check ✅ Passed The PR fulfills all acceptance criteria: reads version from installed metadata, adds regression tests to prevent drift, and ensures CLI output matches package version.
Out of Scope Changes check ✅ Passed All changes directly support the version synchronization objective; no unrelated modifications detected in the init.py or test files.
Docstring Coverage ✅ Passed Docstring coverage is 83.33% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

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_packaging.py`:
- Around line 111-126: The test
test_source_tree_import_without_installed_metadata should be isolated from
repo-installed metadata: add the pytest tmp_path fixture to the test signature
and pass cwd=str(tmp_path) into the subprocess.run call so the child process
runs from an empty temporary directory; keep the existing PYTHONPATH env setup
and other subprocess args unchanged so the test exercises the pyproject.toml
fallback rather than any .dist-info/.egg-info in the repo root.
🪄 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: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: a3e55042-bd34-4122-a04b-2de009c5bfa8

📥 Commits

Reviewing files that changed from the base of the PR and between 6321ff4 and d4a777f.

📒 Files selected for processing (2)
  • src/mcp_server_python_docs/__init__.py
  • tests/test_packaging.py

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

Sync CLI version with package version

1 participant