Skip to content

Commit 9dd1c2e

Browse files
stephentoubCopilot
andcommitted
fix(python): derive __version__ from package metadata with dev sentinel
The Python SDK hardcoded __version__ = "0.1.0" in copilot/__init__.py and version = "0.1.0" in pyproject.toml. The publish workflow only rewrites pyproject.toml at release time, so the public runtime __version__ drifted and always reported a stale version regardless of what was published. Derive __version__ from installed package metadata via importlib.metadata, falling back to a 0.0.0.dev0 sentinel (instead of a real-looking version) when no metadata is present. Set the committed pyproject.toml version to the same dev sentinel, matching the .NET and Rust SDKs; CI injects the real version at publish time. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4d2df4c commit 9dd1c2e

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

python/copilot/__init__.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
JSON-RPC based SDK for programmatic control of GitHub Copilot CLI
55
"""
66

7+
from importlib.metadata import PackageNotFoundError
8+
from importlib.metadata import version as _pkg_version
9+
710
from ._mode import (
811
BUILTIN_TOOLS_ISOLATED,
912
CopilotClientMode,
@@ -145,7 +148,13 @@
145148
define_tool,
146149
)
147150

148-
__version__ = "0.1.0"
151+
try:
152+
__version__ = _pkg_version("github-copilot-sdk")
153+
except PackageNotFoundError:
154+
# No installed package metadata (e.g. running from a source checkout that
155+
# was never installed). Use a sentinel that can never masquerade as a real
156+
# release rather than a hardcoded version that would silently go stale.
157+
__version__ = "0.0.0.dev0"
149158

150159
__all__ = [
151160
"AutoModeSwitchHandler",

python/pyproject.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "github-copilot-sdk"
7-
version = "0.1.0"
7+
# Placeholder; the real version is injected at publish time (see
8+
# .github/workflows/publish.yml). Kept as a dev sentinel so source/editable
9+
# installs never report a stale real version, matching the .NET and Rust SDKs.
10+
version = "0.0.0.dev0"
811
description = "Python SDK for GitHub Copilot CLI"
912
readme = "README.md"
1013
requires-python = ">=3.11"

0 commit comments

Comments
 (0)