Skip to content

Commit fd88505

Browse files
chore: define the package version in source code (#96)
### what define the version in the package source code ### why it's easier to access and can be extracted by the packaging tool ### testing n/a ### docs n/a
1 parent f33cdc6 commit fd88505

6 files changed

Lines changed: 16 additions & 15 deletions

File tree

pyproject.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "stacklet.client.platform"
7-
version = "2025.11.0"
87
description = "Stacklet Platform Client"
9-
authors = [{ name = "Sonny Shi", email = "sonny@stacklet.io" }]
8+
authors = [{ name = "Stacklet Engineering", email = "foss+stacklet-admin@stacklet.io" }]
9+
maintainers = [{ name = "Stacklet Engineering", email = "foss+stacklet-admin@stacklet.io" }]
1010
requires-python = ">=3.9,<=3.14"
1111
readme = "README.md"
1212
license = "Apache-2.0"
13-
maintainers = [{ name = "Stacklet", email = "hello@stacklet.io" }]
1413
dependencies = [
1514
"click>=8.0.1,<9",
1615
"requests>=2.32.4,<3",
@@ -21,6 +20,7 @@ dependencies = [
2120
"charset_normalizer>=3.4.2,<4",
2221
"jmespath>=1.0.1,<2",
2322
]
23+
dynamic = [ "version" ]
2424

2525
[project.scripts]
2626
stacklet-admin = "stacklet.client.platform.cli:cli"
@@ -39,6 +39,9 @@ dev = [
3939
"deptry>=0.23.1,<0.24",
4040
]
4141

42+
[tool.hatch.version]
43+
path = "stacklet/client/platform/__init__.py"
44+
4245
[tool.hatch.build.targets.sdist]
4346
include = [
4447
"stacklet",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
# Copyright Stacklet, Inc.
22
# SPDX-License-Identifier: Apache-2.0
3+
4+
__version__ = "2025.11.0"

stacklet/client/platform/commands/cube.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from ..context import StackletContext
1616
from ..exceptions import MissingToken
17-
from ..utils import get_user_agent
17+
from ..utils import USER_AGENT
1818

1919

2020
@click.group()
@@ -72,7 +72,7 @@ def _request(context: StackletContext, method: str, path: str, payload: Any = No
7272
headers={
7373
"Authorization": f"Bearer {token}",
7474
"Content-Type": "application/json",
75-
"User-Agent": get_user_agent(),
75+
"User-Agent": USER_AGENT,
7676
},
7777
json=payload,
7878
)

stacklet/client/platform/executor.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from .context import StackletContext
1010
from .exceptions import MissingToken
1111
from .registry import PluginRegistry
12-
from .utils import PAGINATION_OPTIONS, get_user_agent, wrap_command
12+
from .utils import PAGINATION_OPTIONS, USER_AGENT, wrap_command
1313

1414

1515
class StackletGraphqlExecutor:
@@ -31,7 +31,7 @@ def __init__(self, context: StackletContext):
3131
self.session.headers.update(
3232
{
3333
"Authorization": f"Bearer {token}",
34-
"User-Agent": get_user_agent(),
34+
"User-Agent": USER_AGENT,
3535
}
3636
)
3737

stacklet/client/platform/utils.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Copyright Stacklet, Inc.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
import importlib.metadata
54
import logging
65
from pathlib import Path
76

87
import click
98

9+
from . import __version__
10+
11+
USER_AGENT = f"stacklet.client.platform/{__version__}"
12+
1013

1114
def expand_user_path(ctx, param, value):
1215
"""Callback for click options to expand user paths."""
@@ -79,9 +82,3 @@ def setup_logging(level):
7982
root_handler = logging.getLogger()
8083
if level:
8184
root_handler.setLevel(level=get_log_level(level))
82-
83-
84-
def get_user_agent():
85-
package = "stacklet.client.platform"
86-
version = importlib.metadata.version(package)
87-
return f"{package}/{version}"

uv.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)