Skip to content

Commit 538251c

Browse files
add test-pypi upload for main
1 parent 33c99f6 commit 538251c

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

.github/workflows/python-tests.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ jobs:
2222
package:
2323
name: Build & inspect our package.
2424
runs-on: ubuntu-latest
25+
env:
26+
# Use no-local-version for package builds to ensure clean versions for PyPI uploads
27+
SETUPTOOLS_SCM_NO_LOCAL: "1"
2528

2629
steps:
2730
- uses: actions/checkout@v4
@@ -117,6 +120,7 @@ jobs:
117120

118121
test-pypi-upload:
119122
runs-on: ubuntu-latest
123+
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
120124
needs: [test]
121125
permissions:
122126
id-token: write

_own_version_helper.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from __future__ import annotations
1010

1111
import logging
12+
import os
1213

1314
from typing import Callable
1415

@@ -22,6 +23,7 @@
2223
from setuptools_scm.fallbacks import parse_pkginfo
2324
from setuptools_scm.version import ScmVersion
2425
from setuptools_scm.version import get_local_node_and_date
26+
from setuptools_scm.version import get_no_local_node
2527
from setuptools_scm.version import guess_next_dev_version
2628

2729
log = logging.getLogger("setuptools_scm")
@@ -48,11 +50,18 @@ def parse(root: str, config: Configuration) -> ScmVersion | None:
4850

4951

5052
def scm_version() -> str:
53+
# Use no-local-version if SETUPTOOLS_SCM_NO_LOCAL is set (for CI uploads)
54+
local_scheme = (
55+
get_no_local_node
56+
if os.environ.get("SETUPTOOLS_SCM_NO_LOCAL")
57+
else get_local_node_and_date
58+
)
59+
5160
return get_version(
5261
relative_to=__file__,
5362
parse=parse,
5463
version_scheme=guess_next_dev_version,
55-
local_scheme=get_local_node_and_date,
64+
local_scheme=local_scheme,
5665
)
5766

5867

docs/integrations.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,9 @@ The environment variable `SETUPTOOLS_SCM_OVERRIDES_FOR_${NORMALIZED_DIST_NAME}`
299299
SETUPTOOLS_SCM_OVERRIDES_FOR_MYPACKAGE='{"local_scheme": "no-local-version"}'
300300
```
301301

302-
#### Alternative: pyproject.toml Configuration
302+
#### Alternative Approaches
303+
304+
**Option 1: pyproject.toml Configuration**
303305

304306
Instead of environment variables, you can configure this in your `pyproject.toml`:
305307

0 commit comments

Comments
 (0)