diff --git a/.gitignore b/.gitignore index 7e44cac2..17c23a00 100644 --- a/.gitignore +++ b/.gitignore @@ -109,7 +109,7 @@ profiles .DS_Store # Repo-specific -bin/ +.bin/ # Generated protoset files *.protoset diff --git a/README.md b/README.md index 1c0d9e7f..2aefdf4b 100644 --- a/README.md +++ b/README.md @@ -25,7 +25,6 @@ Construct a new **pyTFE** client, then use the resource services on the client t ### (Recommended) Using explicit config ```python -import os from pytfe import TFEClient, TFEConfig config = TFEConfig( diff --git a/bin/publish-pypi.sh b/bin/publish-pypi.sh new file mode 100755 index 00000000..9185a936 --- /dev/null +++ b/bin/publish-pypi.sh @@ -0,0 +1,84 @@ +#!/usr/bin/env bash +set -euo pipefail + + +PYPI_REPO="${PYPI_REPO:-testpypi}" # "pypi" or "testpypi" +PYPI_TOKEN="${PYPI_TOKEN:-}" # export PYPI_TOKEN="pypi-***" (or test token) +PYTHON="${PYTHON:-python}" # "python" or "python3" +DIST_DIR="dist" +PYPROJECT="pyproject.toml" + + +if [[ ! -f "$PYPROJECT" ]]; then + echo "$PYPROJECT not found (are you in the project root?)" + exit 1 +fi + +if [[ -z "$PYPI_TOKEN" ]]; then + echo "PYPI_TOKEN not set. Run: export PYPI_TOKEN='pypi-XXXX...'" + exit 1 +fi + +# Read project metadata (name & version) from pyproject.toml using Python +read_pyproject() { + "$PYTHON" - <<'PY' +import sys, pathlib +pp = pathlib.Path("pyproject.toml") +if not pp.exists(): + print("unknown|unknown"); sys.exit(0) +try: + import tomllib +except ModuleNotFoundError: + # Python <3.11 fallback + import json, re + # very small fallback parser: good enough to grab name/version in simple cases + text = pp.read_text() + name = re.search(r'(?m)^\s*name\s*=\s*"([^"]+)"', text) + ver = re.search(r'(?m)^\s*version\s*=\s*"([^"]+)"', text) + print(f"{name.group(1) if name else 'unknown'}|{ver.group(1) if ver else 'unknown'}") + sys.exit(0) + +data = tomllib.loads(pp.read_bytes()) +proj = data.get("project", {}) +print(f"{proj.get('name','unknown')}|{proj.get('version','unknown')}") +PY +} + +IFS="|" read -r PKG_NAME PKG_VER < <(read_pyproject) +echo "Package: ${PKG_NAME} Version: ${PKG_VER}" + + +echo "Cleaning old builds..." +rm -rf "$DIST_DIR" build ./*.egg-info + + +echo "Installing build tools..." +$PYTHON -m pip install -q --upgrade pip build twine + +echo "Building sdist & wheel..." +$PYTHON -m build # uses hatchling per your [build-system] + +echo "Validating with twine..." +$PYTHON -m twine check "$DIST_DIR"/* + + +if [[ "$PYPI_REPO" == "testpypi" ]]; then + REPO_URL="https://test.pypi.org/legacy/" + echo "Target: TestPyPI" +else + REPO_URL="https://upload.pypi.org/legacy/" + echo "Target: PyPI" +fi + +# ----------------------------- +# Upload +# ----------------------------- +echo "Uploading distributions..." +$PYTHON -m twine upload \ + --non-interactive \ + --repository-url "$REPO_URL" \ + -u __token__ \ + -p "$PYPI_TOKEN" \ + "$DIST_DIR"/* + +echo "Published ${PKG_NAME} ${PKG_VER} to ${PYPI_REPO}" diff --git a/pyproject.toml b/pyproject.toml index 31f289f2..7f0fc627 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "pytfe" -version = "0.0.1-alpha" +version = "0.1.0" description = "Official Python SDK for HashiCorp Terraform Cloud / Terraform Enterprise (TFE) API v2" readme = "README.md" license = { text = "MPL-2.0" }