Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/sdk/python/human-protocol-sdk/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ run-test:
build-package:
make clean-package
make build-contracts
python3 scripts/embed_version.py
python3 setup.py sdist bdist_wheel

publish-package:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1 @@
from pathlib import Path
import json

_base_dir = Path(__file__).resolve().parent.parent
_pkg_json_path = _base_dir / "package.json"
try:
with _pkg_json_path.open("r", encoding="utf-8") as f:
_pkg = json.load(f)
except FileNotFoundError as e:
raise RuntimeError(f"package.json not found at {_pkg_json_path}") from e
except Exception as e:
raise RuntimeError("Failed to read package.json") from e

_v = _pkg.get("version")
if not isinstance(_v, str) or not _v.strip():
raise RuntimeError("Missing or empty 'version' in package.json")

__version__ = _v
__version__ = "5.0.0"
2 changes: 1 addition & 1 deletion packages/sdk/python/human-protocol-sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@human-protocol/python-sdk",
"version": "5.0.0",
"version": "5.0.1",
"private": true,
"description": "Stub package to integrate the Python SDK with Changesets (dev-only).",
"license": "MIT"
Expand Down
30 changes: 30 additions & 0 deletions packages/sdk/python/human-protocol-sdk/scripts/embed_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from pathlib import Path
import json
import re
import sys

root = Path(__file__).resolve().parents[1]
pkg_json = root / "package.json"
init_py = root / "human_protocol_sdk" / "__init__.py"

try:
data = json.loads(pkg_json.read_text(encoding="utf-8"))
ver = data.get("version")
if not isinstance(ver, str) or not ver.strip():
raise ValueError("Missing or empty 'version' in package.json")
except Exception as e:
print(f"[embed_version] Error reading {pkg_json}: {e}", file=sys.stderr)
sys.exit(1)

src = init_py.read_text(encoding="utf-8")
new, count = re.subn(
r'^__version__\s*=\s*["\'].*?["\']\s*$',
f'__version__ = "{ver}"',
src,
flags=re.MULTILINE,
)
print(f"[embed_version] Found {count} existing __version__ entries in {init_py}")
if count == 0:
new = src.rstrip() + f'__version__ = "{ver}"\n'

init_py.write_text(new, encoding="utf-8")
Loading