summaryrefslogtreecommitdiffhomepage
path: root/packages/sdk/python/scripts/publish.py
diff options
context:
space:
mode:
authorKevin King <[email protected]>2025-10-28 19:32:45 -0400
committerGitHub <[email protected]>2025-10-28 18:32:45 -0500
commit0e60f666043910afb96e9de2f84b0b8a68c7e4d6 (patch)
tree6ca20af712e2faca6262f029d6d8499c9888eb50 /packages/sdk/python/scripts/publish.py
parentfc8db6cdf9cb81e29c5dda69c8646aa52e453a9c (diff)
downloadopencode-0e60f666043910afb96e9de2f84b0b8a68c7e4d6.tar.gz
opencode-0e60f666043910afb96e9de2f84b0b8a68c7e4d6.zip
ignore: python sdk (#2779)
Co-authored-by: Aiden Cline <[email protected]>
Diffstat (limited to 'packages/sdk/python/scripts/publish.py')
-rw-r--r--packages/sdk/python/scripts/publish.py68
1 files changed, 68 insertions, 0 deletions
diff --git a/packages/sdk/python/scripts/publish.py b/packages/sdk/python/scripts/publish.py
new file mode 100644
index 000000000..f591006a0
--- /dev/null
+++ b/packages/sdk/python/scripts/publish.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python3
+"""
+Python SDK publishing helper.
+
+- Builds sdist and wheel using `python -m build` into dist/
+- Uploads using twine. Configure either TestPyPI or PyPI via environment:
+
+Environment variables:
+ REPOSITORY : "pypi" (default) or "testpypi"
+ PYPI_TOKEN : API token (e.g., pypi-XXXX). For TestPyPI, use the TestPyPI token.
+
+Examples:
+ REPOSITORY=testpypi PYPI_TOKEN=${{TEST_PYPI_API_TOKEN}} uv run --project packages/sdk/python python packages/sdk/python/scripts/publish.py
+"""
+from __future__ import annotations
+
+import os
+import subprocess
+from pathlib import Path
+
+
+def run(cmd: list[str], cwd: Path | None = None) -> None:
+ print("$", " ".join(cmd))
+ subprocess.run(cmd, cwd=str(cwd) if cwd else None, check=True)
+
+
+def main() -> int:
+ sdk_dir = Path(__file__).resolve().parent.parent
+ repo = os.environ.get("REPOSITORY", "pypi").strip()
+ token = os.environ.get("PYPI_TOKEN")
+ if not token:
+ print("ERROR: PYPI_TOKEN not set", flush=True)
+ return 1
+
+ dist = sdk_dir / "dist"
+ if dist.exists():
+ for f in dist.iterdir():
+ f.unlink()
+
+ # Build
+ run(["python", "-m", "build"], cwd=sdk_dir)
+
+ # Upload
+ repo_url = {
+ "pypi": "https://upload.pypi.org/legacy/",
+ "testpypi": "https://test.pypi.org/legacy/",
+ }.get(repo, repo)
+
+ env = os.environ.copy()
+ env["TWINE_USERNAME"] = "__token__"
+ env["TWINE_PASSWORD"] = token
+
+ print(f"Uploading to {repo_url}")
+ subprocess.run(
+ ["python", "-m", "twine", "check", "dist/*"], cwd=sdk_dir, check=True
+ )
+ subprocess.run(
+ ["python", "-m", "twine", "upload", "--repository-url", repo_url, "dist/*"],
+ cwd=sdk_dir,
+ check=True,
+ env=env,
+ )
+ print("Publish complete")
+ return 0
+
+
+if __name__ == "__main__":
+ raise SystemExit(main())