Skip to content

Commit

Permalink
Use dynamic versioning (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
giograno authored Jan 31, 2025
1 parent 74f08bd commit df18a4f
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 17 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ localstack-pro-azure/tests/otherlangs/dotnet/*/obj

# setuptools_scm version.py
*/*/*/*/version.py
localstack-sdk-python-2/.openapi-generator/
localstack-sdk-python-2/.openapi-generator/

# setuptools_scm version.py
**/version.py
1 change: 0 additions & 1 deletion VERSION

This file was deleted.

3 changes: 0 additions & 3 deletions bin/generate.sh
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/bin/bash

version=$(cat VERSION)

docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli:v7.10.0 generate \
-i https://raw.githubusercontent.com/localstack/openapi/refs/heads/main/openapi/emulators/localstack-spec-latest.yml \
--skip-validate-spec \
-g python \
-o /local//packages/localstack-sdk-generated \
--global-property models,apis,supportingFiles \
-p packageName=localstack.sdk \
-p packageVersion=$version \
--template-dir /local/packages/localstack-sdk-generated/templates \
--global-property apiTests=false,modelTests=false \
--global-property apiDocs=false,modelDocs=False
3 changes: 3 additions & 0 deletions localstack-sdk-python/localstack/sdk/clients.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from localstack.sdk import version
from localstack.sdk.api_client import ApiClient
from localstack.sdk.configuration import Configuration

Expand Down Expand Up @@ -30,3 +31,5 @@ def __init__(self, host: str | None = None, auth_token: str | None = None, **kwa
self.auth_token = auth_token
self.configuration = Configuration(host=self.host)
self._api_client = ApiClient(configuration=self.configuration)
# The generated code comes with 1.0.0 hard-coded. We set here the correct version
self._api_client.user_agent = f"LocalStack SDK/{version.version}/python"
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def __init__(
self.default_headers[header_name] = header_value
self.cookie = cookie
# Set default User-Agent.
self.user_agent = 'OpenAPI-Generator/0.0.4/python'
self.user_agent = 'OpenAPI-Generator/1.0.0/python'
self.client_side_validation = configuration.client_side_validation

def __enter__(self):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ def to_debug_report(self) -> str:
"OS: {env}\n"\
"Python Version: {pyversion}\n"\
"Version of the API: latest\n"\
"SDK Package Version: 0.0.4".\
"SDK Package Version: 1.0.0".\
format(env=sys.platform, pyversion=sys.version)

def get_host_settings(self) -> List[HostSetting]:
Expand Down
10 changes: 7 additions & 3 deletions packages/localstack-sdk-generated/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "localstack-sdk-generated"
version = "0.0.4"
dynamic = ["version"]
description = "LocalStack REST API - Generated Code"
authors = [
{ name = "LocalStack Contributors", email = "[email protected]" }
Expand All @@ -18,13 +18,17 @@ dev-dependencies = [
]

[build-system]
requires = ["setuptools"]
requires = ["setuptools", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
local_scheme = "no-local-version"
root = "../.."

[tool.setuptools]
package-dir = { "" = "."}

[tool.setuptools.packages.find]
where = ["."]
include = ["*"]
exclude = ["tests*"]
exclude = ["tests*"]
10 changes: 7 additions & 3 deletions packages/localstack-sdk-generated/templates/pyproject.mustache
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "localstack-sdk-generated"
version = "{{{packageVersion}}}"
dynamic = ["version"]
description = "LocalStack REST API - Generated Code"
authors = [
{ name = "LocalStack Contributors", email = "[email protected]" }
Expand All @@ -18,13 +18,17 @@ dev-dependencies = [
]

[build-system]
requires = ["setuptools"]
requires = ["setuptools", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
local_scheme = "no-local-version"
root = "../.."

[tool.setuptools]
package-dir = { "" = "."}

[tool.setuptools.packages.find]
where = ["."]
include = ["*"]
exclude = ["tests*"]
exclude = ["tests*"]
10 changes: 8 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "Python SDK for LocalStack"
authors = [
{ name = "LocalStack Team", email = "[email protected]"}
]
version = "0.0.4"
dynamic = ["version"]
dependencies = [
"localstack-sdk-generated"
]
Expand All @@ -17,9 +17,13 @@ Repository = "https://github.com/localstack/localstack-sdk-python.git"
Issues = "https://github.com/localstack/localstack-sdk-python/issues"

[build-system]
requires = ["setuptools>=64"]
requires = ["setuptools>=64", "setuptools_scm>=8"]
build-backend = "setuptools.build_meta"

[tool.setuptools_scm]
version_file = "localstack-sdk-python/localstack/sdk/version.py"
local_scheme = "no-local-version"

[tool.setuptools.dynamic]
readme = { file = ["README.md"], content-type = "text/markdown"}

Expand All @@ -30,6 +34,8 @@ dev-dependencies=[
"boto3>=1.35.40",
]

cache-keys = [{ file = "pyproject.toml" }, { git = { commit = true , tags = true }}]

[tool.uv.sources]
localstack-sdk-generated = { workspace = true }

Expand Down
7 changes: 7 additions & 0 deletions tests/test_client.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import localstack.sdk.aws
from localstack.sdk import version


def test_client_version():
client = localstack.sdk.aws.AWSClient()
assert version.version in client._api_client.user_agent
2 changes: 0 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit df18a4f

Please sign in to comment.