diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0fb154c98..94d9a04af 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -120,6 +120,8 @@ jobs: uv run --locked python scripts/generate.py --check uv run --locked mypy uv run --locked pytest + - name: Build and install the Python SDK distributions + run: scripts/release/build-python-sdk.sh "$RUNNER_TEMP/python-dist" - run: npm ci - name: Check every Node consumer and integration boundary env: diff --git a/.github/workflows/release-tag.yml b/.github/workflows/release-tag.yml index 8952e61e4..4ab0fd458 100644 --- a/.github/workflows/release-tag.yml +++ b/.github/workflows/release-tag.yml @@ -46,6 +46,31 @@ jobs: echo "version=$LIGHTSPEED_PRODUCT_VERSION" >> "$GITHUB_OUTPUT" echo "staging_tag=staging-${GITHUB_RUN_ID}-${GITHUB_RUN_ATTEMPT}" >> "$GITHUB_OUTPUT" + python: + needs: identity + runs-on: ubuntu-latest + outputs: + artifact_id: ${{ steps.upload.outputs.artifact-id }} + steps: + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + ref: ${{ needs.identity.outputs.sha }} + - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + with: + version: 0.13.8 + python-version: "3.12" + cache-dependency-glob: clients/python/uv.lock + - run: scripts/release/build-python-sdk.sh "$RUNNER_TEMP/python-dist" + - id: upload + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 + with: + name: python-sdk-${{ github.run_id }}-${{ github.run_attempt }} + path: | + ${{ runner.temp }}/python-dist/*.whl + ${{ runner.temp }}/python-dist/*.tar.gz + if-no-files-found: error + retention-days: 30 + linux: needs: identity runs-on: [self-hosted, linux, x64, hz01, protected] @@ -311,8 +336,32 @@ jobs: if-no-files-found: error retention-days: 30 + publish-python: + needs: [build, python] + runs-on: ubuntu-latest + environment: official-release + permissions: + id-token: write + steps: + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8 + with: + artifact-ids: ${{ needs.python.outputs.artifact_id }} + path: python-dist + merge-multiple: true + - uses: astral-sh/setup-uv@68559e99cc807c1eb7e9238fd43a15bba460eec2 # v10.3.3 + with: + version: 0.13.8 + enable-cache: false + - name: Publish the verified wheel and source distribution to PyPI + env: + VERSION: ${{ needs.build.outputs.version }} + run: | + uv publish --trusted-publishing always --check-url https://pypi.org/simple/ \ + "python-dist/lightspeed_ai_sdk-${VERSION}-py3-none-any.whl" \ + "python-dist/lightspeed_ai_sdk-${VERSION}.tar.gz" + publish-release: - needs: build + needs: [build, publish-python] runs-on: [self-hosted, linux, x64, hz01, protected] environment: official-release permissions: diff --git a/clients/python/README.md b/clients/python/README.md index 820d9c2a6..003f55660 100644 --- a/clients/python/README.md +++ b/clients/python/README.md @@ -21,7 +21,7 @@ remain full-authority infrastructure credentials. ```python from uuid import uuid4 -from lightspeed_ai import AsyncLightspeedClient +from lightspeed import AsyncLightspeedClient async with AsyncLightspeedClient( "https://lightspeed.example", token=platform_key @@ -40,7 +40,7 @@ administrators supply an explicit `initialOwner` when provisioning. Native helpe take one parameter dictionary using API field names. The same operations are available through typed `client.call`, for example `await client.call("platform/organizations/list")`. Native parameter and result types -live in `lightspeed_ai.platform_types`. +live in `lightspeed.platform_types`. For local scripts, reuse the named or selected connection saved by `lightspeed login` or `lightspeed connect add`: @@ -70,11 +70,19 @@ its user is an organization Admin. API keys cannot mint other keys. Requires Python 3.12 or newer. [HTTPX](https://www.python-httpx.org/) is the only runtime dependency. -Install from the repository, at the tag of your Lightspeed release, because the -client's types follow that release's API: +Install the stable SDK from PyPI: ```bash -python -m pip install "lightspeed-ai @ git+https://github.com/smartcomputer-ai/lightspeed@v#subdirectory=clients/python" +python -m pip install lightspeed-ai-sdk +``` + +Import the SDK with `from lightspeed import AsyncLightspeedClient`. The client's +types follow the Lightspeed release. Pin `lightspeed-ai-sdk==` +to match your deployment. For a release that predates PyPI publication, install +from its Git tag and use the import shown in that tag's README: + +```bash +python -m pip install "git+https://github.com/smartcomputer-ai/lightspeed@v#subdirectory=clients/python" ``` From a checkout, `python -m pip install ./clients/python` installs the same package. @@ -88,7 +96,7 @@ You need the gateway's `/api/v1` URL, a import asyncio import os -from lightspeed_ai import AsyncLightspeedClient +from lightspeed import AsyncLightspeedClient async def main() -> None: @@ -300,7 +308,7 @@ merges them into one list in the order they happened, with each tool call joined result: ```python -from lightspeed_ai import run_timeline +from lightspeed import run_timeline run = (await client.read_run(session_id, run_id))["run"] @@ -324,12 +332,12 @@ To keep a view current, follow the run with `await_run` and read it again when ## Types -`lightspeed_ai.types` holds every type in the API, named as the API names them and +`lightspeed.types` holds every type in the API, named as the API names them and documented from the contract. Each variant of a tagged union is named after its tag, and checking the tag narrows the type: ```python -from lightspeed_ai.types import SessionEventView +from lightspeed.types import SessionEventView def failure_message(event: SessionEventView) -> str | None: @@ -360,9 +368,9 @@ new ones. ## Write workflow code Temporal workflows that receive tool calls from an integrated session import -`lightspeed_ai.workflow`. It has the contract's signal, query and activity names, and +`lightspeed.workflow`. It has the contract's signal, query and activity names, and helpers for parsing envelopes, deriving IDs, fingerprinting recipes, and building -replies. `lightspeed_ai.workflow_types` has the generated types, which work as the type +replies. `lightspeed.workflow_types` has the generated types, which work as the type hints Temporal decodes workflow arguments and signals from, such as `WorkflowToolStartArgs` and `EmissionEnvelope`. The module depends on no Temporal package and is deterministic. Its functions raise `ValueError` for a value the contract @@ -382,14 +390,14 @@ from temporalio import workflow from temporalio.exceptions import ApplicationError with workflow.unsafe.imports_passed_through(): - from lightspeed_ai.workflow import ( + from lightspeed.workflow import ( DELIVER_EMISSION_SIGNAL, REPLY_COMPLETION_KEY, WORKFLOW_TOOL_RECOVERY_QUERY, reply_promise_id, source_resolution_envelope, ) - from lightspeed_ai.workflow_types import ( + from lightspeed.workflow_types import ( PromiseResolution, WorkflowToolRecoveryResult, WorkflowToolStartArgs, @@ -452,13 +460,13 @@ recovery query answers from those keys. A bound receiver takes `EmissionEnvelope The types, method tables, and most helpers are generated from the committed contracts in `crates/api/contract/` and `crates/temporal-workflow/contract/`, so don't edit `types.py`, `_generated.py`, `workflow_types.py`, or `_workflow_manifest.py` under -`src/lightspeed_ai/` by hand. Helpers come from the TypeScript SDK's +`src/lightspeed/` by hand. Helpers come from the TypeScript SDK's inventory, [`clients/typescript/scripts/helpers.mjs`](../typescript/scripts/helpers.mjs), which the generator reads with Node.js. It requires one named helper for every runtime operation, rejects name collisions and missing implementations, and checks that handwritten helpers expose the complete wire parameters and transport. The helper table above is generated from that same inventory. Helpers that need behavior -of their own live in `src/lightspeed_ai/client.py`; native Platform names come from +of their own live in `src/lightspeed/client.py`; native Platform names come from its shared contract. With [uv](https://docs.astral.sh/uv/) and Node.js installed, from `clients/python`: diff --git a/clients/python/pyproject.toml b/clients/python/pyproject.toml index fd88baf1c..55c709c77 100644 --- a/clients/python/pyproject.toml +++ b/clients/python/pyproject.toml @@ -3,7 +3,7 @@ requires = ["hatchling>=1.27,<2"] build-backend = "hatchling.build" [project] -name = "lightspeed-ai" +name = "lightspeed-ai-sdk" version = "0.12.0" description = "Async Python SDK for the Lightspeed HTTP API" readme = "README.md" @@ -27,7 +27,7 @@ dev = [ ] [tool.hatch.build.targets.wheel] -packages = ["src/lightspeed_ai"] +packages = ["src/lightspeed"] [tool.pytest.ini_options] asyncio_mode = "auto" @@ -36,4 +36,4 @@ testpaths = ["tests"] [tool.mypy] strict = true -files = ["src/lightspeed_ai", "tests/typing_examples.py"] +files = ["src/lightspeed", "tests/typing_examples.py"] diff --git a/clients/python/scripts/generate.py b/clients/python/scripts/generate.py index 42e3aa2f7..5cd615cff 100644 --- a/clients/python/scripts/generate.py +++ b/clients/python/scripts/generate.py @@ -16,7 +16,7 @@ CONTRACT = CLIENTS.parent / "crates/api/contract" PLATFORM_CONTRACT = CLIENTS.parent / "platform/shared/contract" WORKFLOW_CONTRACT = CLIENTS.parent / "crates/temporal-workflow/contract" -OUTPUT = PACKAGE / "src/lightspeed_ai" +OUTPUT = PACKAGE / "src/lightspeed" BANNER = "# Generated by clients/python/scripts/generate.py. Do not edit.\n" diff --git a/clients/python/src/lightspeed_ai/__init__.py b/clients/python/src/lightspeed/__init__.py similarity index 88% rename from clients/python/src/lightspeed_ai/__init__.py rename to clients/python/src/lightspeed/__init__.py index 285673f63..62c84571c 100644 --- a/clients/python/src/lightspeed_ai/__init__.py +++ b/clients/python/src/lightspeed/__init__.py @@ -1,8 +1,8 @@ """Async Python client for the Lightspeed API. `AsyncLightspeedClient` is the entry point. Wire types live in -`lightspeed_ai.types` and are generated from the Lightspeed API contract. -`lightspeed_ai.workflow` has helpers for Temporal workflow code. +`lightspeed.types` and are generated from the Lightspeed API contract. +`lightspeed.workflow` has helpers for Temporal workflow code. """ from . import types, platform_types diff --git a/clients/python/src/lightspeed_ai/_connection.py b/clients/python/src/lightspeed/_connection.py similarity index 100% rename from clients/python/src/lightspeed_ai/_connection.py rename to clients/python/src/lightspeed/_connection.py diff --git a/clients/python/src/lightspeed_ai/_connection_types.py b/clients/python/src/lightspeed/_connection_types.py similarity index 100% rename from clients/python/src/lightspeed_ai/_connection_types.py rename to clients/python/src/lightspeed/_connection_types.py diff --git a/clients/python/src/lightspeed_ai/_endpoint.py b/clients/python/src/lightspeed/_endpoint.py similarity index 100% rename from clients/python/src/lightspeed_ai/_endpoint.py rename to clients/python/src/lightspeed/_endpoint.py diff --git a/clients/python/src/lightspeed_ai/_generated.py b/clients/python/src/lightspeed/_generated.py similarity index 100% rename from clients/python/src/lightspeed_ai/_generated.py rename to clients/python/src/lightspeed/_generated.py diff --git a/clients/python/src/lightspeed_ai/_http.py b/clients/python/src/lightspeed/_http.py similarity index 100% rename from clients/python/src/lightspeed_ai/_http.py rename to clients/python/src/lightspeed/_http.py diff --git a/clients/python/src/lightspeed_ai/_options.py b/clients/python/src/lightspeed/_options.py similarity index 100% rename from clients/python/src/lightspeed_ai/_options.py rename to clients/python/src/lightspeed/_options.py diff --git a/clients/python/src/lightspeed_ai/_platform.py b/clients/python/src/lightspeed/_platform.py similarity index 100% rename from clients/python/src/lightspeed_ai/_platform.py rename to clients/python/src/lightspeed/_platform.py diff --git a/clients/python/src/lightspeed_ai/_workflow_manifest.py b/clients/python/src/lightspeed/_workflow_manifest.py similarity index 100% rename from clients/python/src/lightspeed_ai/_workflow_manifest.py rename to clients/python/src/lightspeed/_workflow_manifest.py diff --git a/clients/python/src/lightspeed_ai/client.py b/clients/python/src/lightspeed/client.py similarity index 100% rename from clients/python/src/lightspeed_ai/client.py rename to clients/python/src/lightspeed/client.py diff --git a/clients/python/src/lightspeed_ai/errors.py b/clients/python/src/lightspeed/errors.py similarity index 100% rename from clients/python/src/lightspeed_ai/errors.py rename to clients/python/src/lightspeed/errors.py diff --git a/clients/python/src/lightspeed_ai/platform_types.py b/clients/python/src/lightspeed/platform_types.py similarity index 100% rename from clients/python/src/lightspeed_ai/platform_types.py rename to clients/python/src/lightspeed/platform_types.py diff --git a/clients/python/src/lightspeed_ai/py.typed b/clients/python/src/lightspeed/py.typed similarity index 100% rename from clients/python/src/lightspeed_ai/py.typed rename to clients/python/src/lightspeed/py.typed diff --git a/clients/python/src/lightspeed_ai/timeline.py b/clients/python/src/lightspeed/timeline.py similarity index 100% rename from clients/python/src/lightspeed_ai/timeline.py rename to clients/python/src/lightspeed/timeline.py diff --git a/clients/python/src/lightspeed_ai/types.py b/clients/python/src/lightspeed/types.py similarity index 100% rename from clients/python/src/lightspeed_ai/types.py rename to clients/python/src/lightspeed/types.py diff --git a/clients/python/src/lightspeed_ai/workflow.py b/clients/python/src/lightspeed/workflow.py similarity index 99% rename from clients/python/src/lightspeed_ai/workflow.py rename to clients/python/src/lightspeed/workflow.py index cecd6bc6d..823604b6f 100644 --- a/clients/python/src/lightspeed_ai/workflow.py +++ b/clients/python/src/lightspeed/workflow.py @@ -3,7 +3,7 @@ A workflow that receives tool calls from an integrated session, or answers them, uses this module for the contract's names, IDs and envelopes. It depends on no Temporal package and does nothing but hash, compare and validate, so it -is deterministic. `lightspeed_ai.workflow_types` holds the contract's types. +is deterministic. `lightspeed.workflow_types` holds the contract's types. Every function raises `ValueError` for a value the contract does not allow. """ diff --git a/clients/python/src/lightspeed_ai/workflow_types.py b/clients/python/src/lightspeed/workflow_types.py similarity index 100% rename from clients/python/src/lightspeed_ai/workflow_types.py rename to clients/python/src/lightspeed/workflow_types.py diff --git a/clients/python/tests/live_platform_connections.py b/clients/python/tests/live_platform_connections.py index 2e72ac4c3..9dea7d399 100644 --- a/clients/python/tests/live_platform_connections.py +++ b/clients/python/tests/live_platform_connections.py @@ -25,7 +25,7 @@ import pytest import httpx -from lightspeed_ai import AsyncLightspeedClient, LightspeedApiError +from lightspeed import AsyncLightspeedClient, LightspeedApiError async def typescript_check(directory: Path, name: str, mode: str, blob_ref: str = "") -> dict: diff --git a/clients/python/tests/test_client.py b/clients/python/tests/test_client.py index 1e8604c32..fe0902067 100644 --- a/clients/python/tests/test_client.py +++ b/clients/python/tests/test_client.py @@ -8,7 +8,7 @@ import httpx import pytest -from lightspeed_ai import ( +from lightspeed import ( CLIENT_HELPERS, MANUAL_CLIENT_HELPERS, OPERATION_INFO, @@ -18,8 +18,8 @@ LightspeedApiError, LightspeedTransportError, ) -from lightspeed_ai import client as implementation -from lightspeed_ai._http import HTTP_OPERATIONS +from lightspeed import client as implementation +from lightspeed._http import HTTP_OPERATIONS PARITY = json.loads((Path(__file__).resolve().parents[2] / "fixtures/gateway-parity.json").read_text()) diff --git a/clients/python/tests/test_connections.py b/clients/python/tests/test_connections.py index 67a5b8849..31d98c2e7 100644 --- a/clients/python/tests/test_connections.py +++ b/clients/python/tests/test_connections.py @@ -6,9 +6,9 @@ import httpx import pytest -from lightspeed_ai import AsyncLightspeedClient, LightspeedApiError, LightspeedTransportError -from lightspeed_ai._endpoint import normalize_endpoint -from lightspeed_ai import _connection +from lightspeed import AsyncLightspeedClient, LightspeedApiError, LightspeedTransportError +from lightspeed._endpoint import normalize_endpoint +from lightspeed import _connection ENDPOINTS = json.loads((Path(__file__).resolve().parents[2] / "fixtures/endpoints.json").read_text()) diff --git a/clients/python/tests/test_gateway_live.py b/clients/python/tests/test_gateway_live.py index 0245f9835..227b43a05 100644 --- a/clients/python/tests/test_gateway_live.py +++ b/clients/python/tests/test_gateway_live.py @@ -8,7 +8,7 @@ import pytest -from lightspeed_ai import AsyncLightspeedClient +from lightspeed import AsyncLightspeedClient pytestmark = pytest.mark.skipif( os.getenv("LIGHTSPEED_TEST_GATEWAY") != "1", reason="opt-in test requires a configured local gateway", diff --git a/clients/python/tests/test_platform.py b/clients/python/tests/test_platform.py index 72069aff7..97f5b3c49 100644 --- a/clients/python/tests/test_platform.py +++ b/clients/python/tests/test_platform.py @@ -3,7 +3,7 @@ import httpx import pytest -from lightspeed_ai import AsyncLightspeedClient, LightspeedApiError +from lightspeed import AsyncLightspeedClient, LightspeedApiError async def test_native_platform_uses_shared_credentials_and_preserves_path_prefix(): diff --git a/clients/python/tests/test_timeline.py b/clients/python/tests/test_timeline.py index 54d45c0af..486b26e3f 100644 --- a/clients/python/tests/test_timeline.py +++ b/clients/python/tests/test_timeline.py @@ -1,4 +1,4 @@ -from lightspeed_ai import run_timeline +from lightspeed import run_timeline def test_timeline_merges_call_entries_and_preserves_in_flight_calls(): diff --git a/clients/python/tests/test_workflow.py b/clients/python/tests/test_workflow.py index dbfc1baae..f3e3e33f3 100644 --- a/clients/python/tests/test_workflow.py +++ b/clients/python/tests/test_workflow.py @@ -1,6 +1,6 @@ import pytest -from lightspeed_ai.workflow import ( +from lightspeed.workflow import ( DELIVER_EMISSION_SIGNAL, REPLY_COMPLETION_KEY, WORKFLOW_CONTRACT_VECTORS, @@ -132,7 +132,7 @@ def test_temporals_data_converter_decodes_the_generated_types(): # arguments decoded from the type hints, before any of its code runs. from temporalio.converter import value_to_type - from lightspeed_ai import AwaitRunResult, RunTimelineItem, types, workflow_types + from lightspeed import AwaitRunResult, RunTimelineItem, types, workflow_types assert value_to_type(workflow_types.WorkflowToolStartArgs, VECTORS["startArgs"]) == VECTORS["startArgs"] assert value_to_type( diff --git a/clients/python/tests/typing_examples.py b/clients/python/tests/typing_examples.py index abea32bb6..b3450da6a 100644 --- a/clients/python/tests/typing_examples.py +++ b/clients/python/tests/typing_examples.py @@ -1,10 +1,10 @@ from typing import assert_type from collections.abc import AsyncIterator -from lightspeed_ai import types as Api +from lightspeed import types as Api -from lightspeed_ai import AsyncLightspeedClient, ClientConnectionResponse -from lightspeed_ai import platform_types as Platform -from lightspeed_ai.types import ( +from lightspeed import AsyncLightspeedClient, ClientConnectionResponse +from lightspeed import platform_types as Platform +from lightspeed.types import ( CredentialGrantPutResponse, McpServerPutResponse, RunReadResponse, diff --git a/clients/python/uv.lock b/clients/python/uv.lock index 4e418edb0..3ae25d9a5 100644 --- a/clients/python/uv.lock +++ b/clients/python/uv.lock @@ -333,7 +333,7 @@ wheels = [ ] [[package]] -name = "lightspeed-ai" +name = "lightspeed-ai-sdk" version = "0.12.0" source = { editable = "." } dependencies = [ diff --git a/docs/documentation/development/changing-contracts.md b/docs/documentation/development/changing-contracts.md index fcbe2419b..fd272b065 100644 --- a/docs/documentation/development/changing-contracts.md +++ b/docs/documentation/development/changing-contracts.md @@ -153,7 +153,7 @@ which a test checks. The Python generator needs [uv](https://docs.astral.sh/uv/) and Node.js. It reads the API and workflow exports and the same helper table, and writes `types.py`, `_generated.py`, `workflow_types.py`, and `_workflow_manifest.py` under -`clients/python/src/lightspeed_ai/`. A new helper belongs in the Python client's +`clients/python/src/lightspeed/`. A new helper belongs in the Python client's README too, which its tests check. The method-action generator updates `platform/backend/src/routes/method-actions.ts`: diff --git a/docs/documentation/development/contributing-and-releasing.md b/docs/documentation/development/contributing-and-releasing.md index 16e54d950..7f1cd65be 100644 --- a/docs/documentation/development/contributing-and-releasing.md +++ b/docs/documentation/development/contributing-and-releasing.md @@ -234,8 +234,20 @@ Pushing the tag starts publication. The protected Linux amd64 and Windows x64 environment must contain `NPM_TOKEN`. The environment only pauses publication if approval rules have actually been configured in GitHub. +Before the first Python release, create the `lightspeed-ai-sdk` project under +**Projects** in the `lightspeed-ai` PyPI organization. [PyPI project setup](https://docs.pypi.org/organization-accounts/actions/project-actions/#create-a-project) + +In the project's **Publishing** settings, add a GitHub trusted publisher. +Enter `smartcomputer-ai` as the GitHub owner, `lightspeed` as +the repository, `release-tag.yml` as the workflow filename and +`official-release` as the environment. The workflow exchanges its GitHub +identity for a short-lived PyPI upload token. [PyPI trusted publisher setup](https://docs.pypi.org/trusted-publishers/adding-a-publisher/) + The release workflow independently tests and builds the tagged source. It -does not promote an already-built main snapshot. Final publication runs +builds a Python wheel and source distribution and installs each in isolation. +After release assembly succeeds, a protected job uploads those exact files +to PyPI. On retry, it checks the hashes of files already published for that +version. Final publication runs through the `official-release` environment, validates the staged bundle by digest, and publishes exact-version OCI aliases, the npm package, and the GitHub Release with its assets. Existing aliases are checked against their diff --git a/docs/documentation/integrating-and-extending/api-and-typescript.md b/docs/documentation/integrating-and-extending/api-and-typescript.md index 984d5b889..968532ad9 100644 --- a/docs/documentation/integrating-and-extending/api-and-typescript.md +++ b/docs/documentation/integrating-and-extending/api-and-typescript.md @@ -151,7 +151,7 @@ Or use the asynchronous Python client. ```python import asyncio -from lightspeed_ai import AsyncLightspeedClient +from lightspeed import AsyncLightspeedClient async def main(): async with await AsyncLightspeedClient.from_connection("work") as client: diff --git a/docs/documentation/integrating-and-extending/workflow-tools.md b/docs/documentation/integrating-and-extending/workflow-tools.md index 85b36b888..82a6a2f5a 100644 --- a/docs/documentation/integrating-and-extending/workflow-tools.md +++ b/docs/documentation/integrating-and-extending/workflow-tools.md @@ -337,7 +337,7 @@ missing completion signal with recovery results available. The [generated workflow contract](../../../crates/temporal-workflow/contract/workflow-contract.md) and the workflow helpers for [TypeScript](../../../clients/typescript/src/workflow.ts) -and [Python](../../../clients/python/src/lightspeed_ai/workflow.py) +and [Python](../../../clients/python/src/lightspeed/workflow.py) own the exact envelopes, identifiers, and signal/query names. Use those helpers instead of copying hashing or workflow-ID rules into your integration. The [Python client README](../../../clients/python/README.md#write-workflow-code) has the diff --git a/scripts/release/build-python-sdk.sh b/scripts/release/build-python-sdk.sh new file mode 100755 index 000000000..1a1461f52 --- /dev/null +++ b/scripts/release/build-python-sdk.sh @@ -0,0 +1,22 @@ +#!/usr/bin/env bash +set -euo pipefail +cd "$(dirname "${BASH_SOURCE[0]}")/../.." +source release/metadata.env + +# uv builds the wheel from the sdist, so missing source files fail here. +out_dir=${1:?usage: build-python-sdk.sh OUTPUT_DIRECTORY} +mkdir -p "$out_dir" +out_dir=$(cd "$out_dir" && pwd) +uv build --python 3.12 --no-sources --out-dir "$out_dir" clients/python + +for file in "lightspeed_ai_sdk-${LIGHTSPEED_PRODUCT_VERSION}.tar.gz" \ + "lightspeed_ai_sdk-${LIGHTSPEED_PRODUCT_VERSION}-py3-none-any.whl"; do + uv run --python 3.12 --isolated --no-project --with "$out_dir/$file" python -I -c ' +import sys +from importlib.metadata import version +from lightspeed import AsyncLightspeedClient + +if version("lightspeed-ai-sdk") != sys.argv[1]: + sys.exit("Installed SDK version differs from the release version") +' "$LIGHTSPEED_PRODUCT_VERSION" +done diff --git a/scripts/release/prepare-version.mjs b/scripts/release/prepare-version.mjs index d37d25156..0d03ea2ee 100644 --- a/scripts/release/prepare-version.mjs +++ b/scripts/release/prepare-version.mjs @@ -12,7 +12,7 @@ export const releasePackages = [ // lockfile each state once. const pythonVersionFiles = [ ['clients/python/pyproject.toml', /^(\[project\]\n(?:[^\[]*?\n)?version = ")([^"]+)"/m], - ['clients/python/uv.lock', /^(\[\[package\]\]\nname = "lightspeed-ai"\nversion = ")([^"]+)"/m], + ['clients/python/uv.lock', /^(\[\[package\]\]\nname = "lightspeed-ai-sdk"\nversion = ")([^"]+)"/m], ]; export function validateVersion(version) { diff --git a/scripts/release/prepare-version.test.mjs b/scripts/release/prepare-version.test.mjs index ca7268c58..93268568f 100644 --- a/scripts/release/prepare-version.test.mjs +++ b/scripts/release/prepare-version.test.mjs @@ -20,8 +20,8 @@ function fixture(t) { write(`crates/${name}/Cargo.toml`, `[package]\nname = "${name}"\nversion.workspace = true\nedition = "2024"\n`); write(`crates/${name}/src/lib.rs`, ''); } - write('clients/python/pyproject.toml', '[build-system]\nrequires = ["hatchling"]\n\n[project]\nname = "lightspeed-ai"\nversion = "0.2.0"\n'); - write('clients/python/uv.lock', 'version = 1\n\n[[package]]\nname = "httpx"\nversion = "0.28.1"\n\n[[package]]\nname = "lightspeed-ai"\nversion = "0.2.0"\nsource = { editable = "." }\n'); + write('clients/python/pyproject.toml', '[build-system]\nrequires = ["hatchling"]\n\n[project]\nname = "lightspeed-ai-sdk"\nversion = "0.2.0"\n'); + write('clients/python/uv.lock', 'version = 1\n\n[[package]]\nname = "httpx"\nversion = "0.28.1"\n\n[[package]]\nname = "lightspeed-ai-sdk"\nversion = "0.2.0"\nsource = { editable = "." }\n'); execFileSync('cargo', ['generate-lockfile', '--offline'], { cwd, stdio: 'pipe' }); return { cwd, write, read }; } @@ -32,8 +32,8 @@ test('preparation updates every released package and lockfile without changing c assert.equal(verifyVersions(f.cwd), '0.3.0'); assert.equal(f.read('release/metadata.env'), 'LIGHTSPEED_PRODUCT_VERSION=0.3.0\nLIGHTSPEED_SCHEMA_REVISION=10\n'); assert.equal((f.read('Cargo.lock').match(/version = "0.3.0"/g) ?? []).length, releasePackages.length); - assert.match(f.read('clients/python/pyproject.toml'), /^name = "lightspeed-ai"\nversion = "0\.3\.0"$/m); - assert.equal(f.read('clients/python/uv.lock'), 'version = 1\n\n[[package]]\nname = "httpx"\nversion = "0.28.1"\n\n[[package]]\nname = "lightspeed-ai"\nversion = "0.3.0"\nsource = { editable = "." }\n'); + assert.match(f.read('clients/python/pyproject.toml'), /^name = "lightspeed-ai-sdk"\nversion = "0\.3\.0"$/m); + assert.equal(f.read('clients/python/uv.lock'), 'version = 1\n\n[[package]]\nname = "httpx"\nversion = "0.28.1"\n\n[[package]]\nname = "lightspeed-ai-sdk"\nversion = "0.3.0"\nsource = { editable = "." }\n'); const lock = f.read('Cargo.lock'); prepareVersion(f.cwd, '0.3.0'); assert.equal(f.read('Cargo.lock'), lock);