Skip to content

Commit 58ee416

Browse files
committed
Update pre-release.yml to set the version before uploading to Test PyPI
1 parent 95604cb commit 58ee416

7 files changed

Lines changed: 51 additions & 21 deletions

File tree

.github/workflows/pre-release.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
name: Publish SDK to Test PyPI
2-
on: [workflow_dispatch]
1+
name: Publish pre-release to Test PyPI
2+
on:
3+
push:
4+
branches: [ develop ]
35

46
env:
57
PYTHON_VERSION: 3.13
68

79
jobs:
8-
publish-to-test-pypi:
10+
publish-pre-release:
911
runs-on: ubuntu-latest
1012
permissions:
1113
id-token: write
@@ -17,6 +19,16 @@ jobs:
1719
with:
1820
python-version: ${{ env.PYTHON_VERSION }}
1921
deps-group: release
22+
- name: Set pre-release version
23+
# Note: --no-config intentionally omitted from uv version - it would prevent
24+
# reading pyproject.toml, which is the whole point of this command.
25+
# --frozen skips re-locking since we only need to patch the version, not update deps.
26+
env:
27+
RUN_NUMBER: ${{ github.run_number }}
28+
run: |
29+
SHA=$(git rev-parse --short HEAD)
30+
BASE=$(uv version --short)
31+
uv version --frozen "${BASE}.dev${RUN_NUMBER}+g${SHA}"
2032
- name: Build packages for distribution
2133
run: uv build
2234
- name: Publish packages to Test PyPI

docs/conf.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@
99
# All configuration values have a default; values that are commented out
1010
# serve to show the default.
1111

12+
import importlib.metadata
1213
from datetime import datetime
1314

14-
import splunklib
15-
1615
# If extensions (or modules to document with autodoc) are in another directory,
1716
# add these directories to sys.path here. If the directory is relative to the
1817
# documentation root, use os.path.abspath to make it absolute, like shown here.
@@ -40,17 +39,17 @@
4039
master_doc = "index"
4140

4241
# General information about the project.
43-
project = "Splunk SDK for Python"
44-
copyright = f"{datetime.now().year}, Splunk Inc."
42+
package_name = "splunk-sdk"
43+
project = f"Splunk SDK for Python (f{package_name}/splunklib)"
44+
copyright = f"2011-{datetime.now().year} Splunk, Inc."
4545

4646
# The version info for the project you're documenting, acts as replacement for
4747
# |version| and |release|, also used in various other places throughout the
4848
# built documents.
4949
#
5050
# The short X.Y version.
51-
version = splunklib.__version__
52-
# The full version, including alpha/beta/rc tags.
53-
release = splunklib.__version__
51+
release = importlib.metadata.version(package_name)
52+
version = ".".join(release.split(".")[:2])
5453

5554
# The language for content autogenerated by Sphinx. Refer to documentation
5655
# for a list of supported languages.

pyproject.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ download = "https://github.com/splunk/splunk-sdk-python/releases/latest"
88

99
[project]
1010
name = "splunk-sdk"
11-
dynamic = ["version"]
11+
version = "3.0.0"
1212
description = "Splunk Software Development Kit for Python"
1313
readme = "README.md"
1414
requires-python = ">=3.13"
@@ -71,9 +71,6 @@ packages = [
7171
"splunklib.ai.engines",
7272
]
7373

74-
[tool.setuptools.dynamic]
75-
version = { attr = "splunklib.__version__" }
76-
7774
[tool.basedpyright]
7875
exclude = [".venv"]
7976
allowedUntypedLibraries = ["splunklib"]

splunklib/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,3 @@ def setup_logging(
3232
logging.basicConfig(level=level, format=log_format, datefmt=date_format)
3333

3434

35-
__version_info__ = (2, 2, 0, "alpha")
36-
__version__ = ".".join(map(str, __version_info__))

splunklib/binding.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
:mod:`splunklib.client` module.
2525
"""
2626

27+
import importlib.metadata
2728
import io
2829
import json
2930
import logging
@@ -34,14 +35,13 @@
3435
from contextlib import contextmanager
3536
from datetime import datetime
3637
from functools import wraps
37-
from io import BytesIO
38-
from urllib import parse
3938
from http import client
4039
from http.cookies import SimpleCookie
40+
from io import BytesIO
41+
from urllib import parse
4142
from xml.etree.ElementTree import XML, ParseError
42-
from .data import record
43-
from . import __version__
4443

44+
from .data import record
4545

4646
logger = logging.getLogger(__name__)
4747

@@ -1787,9 +1787,11 @@ def connect(scheme, host, port):
17871787
def request(url, message, **kwargs):
17881788
scheme, host, port, path = _spliturl(url)
17891789
body = message.get("body", "")
1790+
1791+
sdk_version = importlib.metadata.version("splunk-sdk")
17901792
head = {
17911793
"Content-Length": str(len(body)),
1792-
"User-Agent": "splunk-sdk-python/%s" % __version__,
1794+
"User-Agent": f"splunk-sdk-python/{sdk_version}",
17931795
"Accept": "*/*",
17941796
"Connection": "Close",
17951797
} # defaults

tests/unit/test_version.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright © 2011-2026 Splunk, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License"): you may
4+
# not use this file except in compliance with the License. You may obtain
5+
# a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
16+
def test_sdk_version_readable_via_metadata() -> None:
17+
import importlib.metadata
18+
19+
sdk_version = importlib.metadata.version("splunk-sdk")
20+
assert sdk_version, "version should be a non-empty string"
21+
assert "." in sdk_version, f"version {sdk_version!r} should contain a dot"

uv.lock

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

0 commit comments

Comments
 (0)