Skip to content

Commit 6c907a7

Browse files
Lock publishing test dependencies (#21446)
The publishing tests resolve an unpinned fixture backend and install an unlocked keyring CLI while registry credentials are available. Pin `pdm-backend` and verify its hashes for fresh and modified fixture builds. Add `keyring` and `keyrings.alt` to the existing script lock and run the harness with `--locked`. Keep publication indexes out of build dependency resolution, and use a temporary keyring for the dedicated test token. The lockfile additions cover the keyring dependency tree. The pinned dependencies still execute on the host with access to test credentials. --------- Co-authored-by: Zsolt Dollenstein <zsol.zsol@gmail.com>
1 parent 61fcea2 commit 6c907a7

5 files changed

Lines changed: 159 additions & 32 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,6 @@ jobs:
184184
name: uv-test-publish
185185
deployment: false
186186
env:
187-
# No dbus in GitHub Actions
188-
PYTHON_KEYRING_BACKEND: keyrings.alt.file.PlaintextKeyring
189187
PYTHON_VERSION: 3.12
190188
permissions:
191189
# For trusted publishing
@@ -259,14 +257,6 @@ jobs:
259257
260258
echo "GITLAB_PYPI_OIDC_TOKEN=${GITLAB_PYPI_OIDC_TOKEN}" >> "${GITHUB_OUTPUT}"
261259
262-
- name: "Add password to keyring"
263-
run: |
264-
# `keyrings.alt` contains the plaintext keyring
265-
./uv tool install --with keyrings.alt keyring
266-
echo $UV_TEST_PUBLISH_KEYRING | keyring set https://test.pypi.org/legacy/?astral-test-keyring __token__
267-
env:
268-
UV_TEST_PUBLISH_KEYRING: ${{ secrets.UV_TEST_PUBLISH_KEYRING }}
269-
270260
- name: "Add password to uv text store"
271261
run: |
272262
./uv auth login https://test.pypi.org/legacy/?astral-test-text-store --token ${UV_TEST_PUBLISH_TEXT_STORE}
@@ -280,6 +270,7 @@ jobs:
280270
RUST_LOG: uv=debug,uv_publish=trace
281271
UV_TEST_PUBLISH_TOKEN: ${{ secrets.UV_TEST_PUBLISH_TOKEN }}
282272
UV_TEST_PUBLISH_PASSWORD: ${{ secrets.UV_TEST_PUBLISH_PASSWORD }}
273+
UV_TEST_PUBLISH_KEYRING: ${{ secrets.UV_TEST_PUBLISH_KEYRING }}
283274
UV_TEST_PUBLISH_GITLAB_PAT: ${{ secrets.UV_TEST_PUBLISH_GITLAB_PAT }}
284275
UV_TEST_PUBLISH_CODEBERG_TOKEN: ${{ secrets.UV_TEST_PUBLISH_CODEBERG_TOKEN }}
285276
UV_TEST_PUBLISH_CLOUDSMITH_TOKEN: ${{ secrets.UV_TEST_PUBLISH_CLOUDSMITH_TOKEN }}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pdm-backend==2.4.9
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# This file was autogenerated by uv via the following command:
2+
# uv pip compile scripts/publish/build-requirements.in --python-version 3.12 --universal --generate-hashes --only-binary=:all: --exclude-newer 2026-08-26 -o scripts/publish/build-requirements.txt
3+
pdm-backend==2.4.9 \
4+
--hash=sha256:8d1064751dadb0c40b1026b46826a448d85c8228a564985c62fb53d4aba538a1 \
5+
--hash=sha256:c41a852ccbf4b567b033db9b2ae78660d7a4ea49307719959ab88a01f0aabb2e
6+
# via -r scripts/publish/build-requirements.in

‎scripts/publish/test_publish.py‎

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22
# requires-python = ">=3.12"
33
# dependencies = [
44
# "httpx[socks]>=0.28.1,<0.29",
5+
# "keyring",
6+
# "keyrings-alt",
57
# "packaging>=24.1,<25",
6-
# "pypi-attestations==0.0.28",
7-
# "sigstore==4.4.0",
8+
# "pypi-attestations>=0.0.28",
9+
# "sigstore>=4.4.0",
810
# ]
911
# [tool.uv]
1012
# no-build = true
@@ -18,7 +20,7 @@
1820
1921
Locally, execute the credentials setting script, then run:
2022
```shell
21-
uv run scripts/publish/test_publish.py local
23+
uv run --locked scripts/publish/test_publish.py local
2224
```
2325
2426
# Setup
@@ -32,10 +34,8 @@
3234
supports, but they both CLI options.
3335
3436
**pypi-keyring**
35-
```console
36-
uv pip install keyring
37-
keyring set https://test.pypi.org/legacy/?astral-test-keyring __token__
38-
```
37+
Set `UV_TEST_PUBLISH_KEYRING` to the dedicated TestPyPI token. The harness stores it
38+
in a temporary keyring.
3939
The query parameter a horrible hack stolen from
4040
https://github.com/pypa/twine/issues/565#issue-555219267
4141
to prevent the other projects from implicitly using the same credentials.
@@ -77,10 +77,11 @@
7777
from pathlib import Path
7878
from shutil import rmtree
7979
from subprocess import PIPE, check_call, run
80-
from tempfile import gettempdir
80+
from tempfile import TemporaryDirectory, gettempdir
8181
from time import sleep
8282

8383
import httpx
84+
from keyrings.alt.file import PlaintextKeyring
8485
from packaging.utils import (
8586
parse_sdist_filename,
8687
parse_wheel_filename,
@@ -337,9 +338,6 @@ def build_project_at_version(
337338
# Add all supported metadata
338339
+ PYPROJECT_TAIL
339340
)
340-
if index_declaration := all_targets[target].index_declaration():
341-
toml += index_declaration
342-
343341
project_root.joinpath("pyproject.toml").write_text(toml)
344342
shutil.copy(
345343
cwd.parent.parent.joinpath("LICENSE-APACHE"),
@@ -360,8 +358,19 @@ def build_project_at_version(
360358
)
361359
init_py.write_text("x = 1")
362360

363-
# Build the project, explicitly overriding no-build from the project's pyproject.toml
364-
check_call([uv, "build", "--build"], cwd=project_root)
361+
check_call(
362+
[
363+
uv,
364+
"build",
365+
"--build-constraint",
366+
cwd / "build-requirements.txt",
367+
"--require-hashes",
368+
],
369+
cwd=project_root,
370+
)
371+
# Publication-only indexes must not participate in building fixtures.
372+
if index_declaration := all_targets[target].index_declaration():
373+
project_root.joinpath("pyproject.toml").write_text(toml + index_declaration)
365374
# Test that we ignore unknown any file.
366375
project_root.joinpath("dist").joinpath(".DS_Store").touch()
367376

@@ -767,12 +776,26 @@ def target_configuration(target: str) -> tuple[dict[str, str], list[str]]:
767776
return env, extra_args
768777

769778

770-
def plan_test(target: str, uv: Path) -> Plan:
779+
def plan_test(target: str, uv: Path, keyring_directory: Path) -> Plan:
771780
"""
772781
Create a test plan for the given target.
773782
"""
774783
configuration = all_targets[target]
775784
env, extra_args = target_configuration(target)
785+
if target == "pypi-keyring":
786+
keyring_file = str(keyring_directory / "keyring.cfg")
787+
keyring = PlaintextKeyring().with_properties(file_path=keyring_file)
788+
keyring.set_password(
789+
configuration.publish_url,
790+
"__token__",
791+
os.environ["UV_TEST_PUBLISH_KEYRING"],
792+
)
793+
env.update(
794+
{
795+
"PYTHON_KEYRING_BACKEND": "keyrings.alt.file.PlaintextKeyring",
796+
"KEYRING_PROPERTY_FILE_PATH": keyring_file,
797+
}
798+
)
776799
return Plan(
777800
uv=uv,
778801
target=target,
@@ -811,12 +834,13 @@ def main():
811834
else:
812835
targets = args.targets
813836

814-
for project_name in targets:
815-
plan = plan_test(project_name, uv)
816-
# Each publish gets its own client, since we may need to introduce
817-
# target-specific authentication.
818-
with httpx.Client(timeout=120) as client:
819-
test_publish_project(plan, client)
837+
with TemporaryDirectory(prefix="uv-publish-keyring-") as temporary:
838+
for project_name in targets:
839+
plan = plan_test(project_name, uv, Path(temporary))
840+
# Each publish gets its own client, since we may need to introduce
841+
# target-specific authentication.
842+
with httpx.Client(timeout=120) as client:
843+
test_publish_project(plan, client)
820844

821845

822846
if __name__ == "__main__":

‎scripts/publish/test_publish.py.lock‎

Lines changed: 107 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ astral-dev-toolchain-cargo-dist = "2026-08-28T04:00:00Z"
1313
[manifest]
1414
requirements = [
1515
{ name = "httpx", extras = ["socks"], specifier = ">=0.28.1,<0.29" },
16+
{ name = "keyring" },
17+
{ name = "keyrings-alt" },
1618
{ name = "packaging", specifier = ">=24.1,<25" },
17-
{ name = "pypi-attestations", specifier = "==0.0.28" },
18-
{ name = "sigstore", specifier = "==4.4.0" },
19+
{ name = "pypi-attestations", specifier = ">=0.0.28" },
20+
{ name = "sigstore", specifier = ">=4.4.0" },
1921
]
2022

2123
[[package]]
@@ -299,6 +301,78 @@ wheels = [
299301
{ url = "https://files.pythonhosted.org/packages/d2/23/408243171aa9aaba178d3e2559159c24c1171a641aa83b67bdd3394ead8e/idna-3.15-py3-none-any.whl", hash = "sha256:048adeaf8c2d788c40fee287673ccaa74c24ffd8dcf09ffa555a2fbb59f10ac8", size = 72340, upload-time = "2026-05-12T22:45:55.733Z" },
300302
]
301303

304+
[[package]]
305+
name = "jaraco-classes"
306+
version = "3.4.0"
307+
source = { registry = "https://pypi.org/simple" }
308+
dependencies = [
309+
{ name = "more-itertools" },
310+
]
311+
sdist = { url = "https://files.pythonhosted.org/packages/06/c0/ed4a27bc5571b99e3cff68f8a9fa5b56ff7df1c2251cc715a652ddd26402/jaraco.classes-3.4.0.tar.gz", hash = "sha256:47a024b51d0239c0dd8c8540c6c7f484be3b8fcf0b2d85c13825780d3b3f3acd", size = 11780, upload-time = "2024-03-31T07:27:36.643Z" }
312+
wheels = [
313+
{ url = "https://files.pythonhosted.org/packages/7f/66/b15ce62552d84bbfcec9a4873ab79d993a1dd4edb922cbfccae192bd5b5f/jaraco.classes-3.4.0-py3-none-any.whl", hash = "sha256:f662826b6bed8cace05e7ff873ce0f9283b5c924470fe664fff1c2f00f581790", size = 6777, upload-time = "2024-03-31T07:27:34.792Z" },
314+
]
315+
316+
[[package]]
317+
name = "jaraco-context"
318+
version = "6.1.2"
319+
source = { registry = "https://pypi.org/simple" }
320+
sdist = { url = "https://files.pythonhosted.org/packages/af/50/4763cd07e722bb6285316d390a164bc7e479db9d90daa769f22578f698b4/jaraco_context-6.1.2.tar.gz", hash = "sha256:f1a6c9d391e661cc5b8d39861ff077a7dc24dc23833ccee564b234b81c82dfe3", size = 16801, upload-time = "2026-03-20T22:13:33.922Z" }
321+
wheels = [
322+
{ url = "https://files.pythonhosted.org/packages/f2/58/bc8954bda5fcda97bd7c19be11b85f91973d67a706ed4a3aec33e7de22db/jaraco_context-6.1.2-py3-none-any.whl", hash = "sha256:bf8150b79a2d5d91ae48629d8b427a8f7ba0e1097dd6202a9059f29a36379535", size = 7871, upload-time = "2026-03-20T22:13:32.808Z" },
323+
]
324+
325+
[[package]]
326+
name = "jaraco-functools"
327+
version = "4.6.0"
328+
source = { registry = "https://pypi.org/simple" }
329+
dependencies = [
330+
{ name = "more-itertools" },
331+
]
332+
sdist = { url = "https://files.pythonhosted.org/packages/6c/1f/c23395957d41ccf27c4e535c3d334c4051e5395b3752057ba4cbaec35c56/jaraco_functools-4.6.0.tar.gz", hash = "sha256:880c577ec9720b3a052d5bc611fb9f2269b3d87902ef42440df443b88e443280", size = 20837, upload-time = "2026-07-14T01:28:02.544Z" }
333+
wheels = [
334+
{ url = "https://files.pythonhosted.org/packages/02/36/ecc85bc96c273dc8a11273ed4782272975e6338d4a3e9228621175edf0e3/jaraco_functools-4.6.0-py3-none-any.whl", hash = "sha256:99e3dc0060c5cbe8fcd1cdb36258e2a65ca40f1566b2033b12abb1bb44dd3c30", size = 11677, upload-time = "2026-07-14T01:28:01.59Z" },
335+
]
336+
337+
[[package]]
338+
name = "jeepney"
339+
version = "0.9.0"
340+
source = { registry = "https://pypi.org/simple" }
341+
sdist = { url = "https://files.pythonhosted.org/packages/7b/6f/357efd7602486741aa73ffc0617fb310a29b588ed0fd69c2399acbb85b0c/jeepney-0.9.0.tar.gz", hash = "sha256:cf0e9e845622b81e4a28df94c40345400256ec608d0e55bb8a3feaa9163f5732", size = 106758, upload-time = "2025-02-27T18:51:01.684Z" }
342+
wheels = [
343+
{ url = "https://files.pythonhosted.org/packages/b2/a3/e137168c9c44d18eff0376253da9f1e9234d0239e0ee230d2fee6cea8e55/jeepney-0.9.0-py3-none-any.whl", hash = "sha256:97e5714520c16fc0a45695e5365a2e11b81ea79bba796e26f9f1d178cb182683", size = 49010, upload-time = "2025-02-27T18:51:00.104Z" },
344+
]
345+
346+
[[package]]
347+
name = "keyring"
348+
version = "25.7.0"
349+
source = { registry = "https://pypi.org/simple" }
350+
dependencies = [
351+
{ name = "jaraco-classes" },
352+
{ name = "jaraco-context" },
353+
{ name = "jaraco-functools" },
354+
{ name = "jeepney", marker = "sys_platform == 'linux'" },
355+
{ name = "pywin32-ctypes", marker = "sys_platform == 'win32'" },
356+
{ name = "secretstorage", marker = "sys_platform == 'linux'" },
357+
]
358+
sdist = { url = "https://files.pythonhosted.org/packages/43/4b/674af6ef2f97d56f0ab5153bf0bfa28ccb6c3ed4d1babf4305449668807b/keyring-25.7.0.tar.gz", hash = "sha256:fe01bd85eb3f8fb3dd0405defdeac9a5b4f6f0439edbb3149577f244a2e8245b", size = 63516, upload-time = "2025-11-16T16:26:09.482Z" }
359+
wheels = [
360+
{ url = "https://files.pythonhosted.org/packages/81/db/e655086b7f3a705df045bf0933bdd9c2f79bb3c97bfef1384598bb79a217/keyring-25.7.0-py3-none-any.whl", hash = "sha256:be4a0b195f149690c166e850609a477c532ddbfbaed96a404d4e43f8d5e2689f", size = 39160, upload-time = "2025-11-16T16:26:08.402Z" },
361+
]
362+
363+
[[package]]
364+
name = "keyrings-alt"
365+
version = "5.0.2"
366+
source = { registry = "https://pypi.org/simple" }
367+
dependencies = [
368+
{ name = "jaraco-classes" },
369+
{ name = "jaraco-context" },
370+
]
371+
sdist = { url = "https://files.pythonhosted.org/packages/5c/7b/e3bf53326e0753bee11813337b1391179582ba5c6851b13e0d9502d15a50/keyrings_alt-5.0.2.tar.gz", hash = "sha256:8f097ebe9dc8b185106502b8cdb066c926d2180e13b4689fd4771a3eab7d69fb", size = 29229, upload-time = "2024-08-14T01:09:28.12Z" }
372+
wheels = [
373+
{ url = "https://files.pythonhosted.org/packages/4a/0d/9c59313ab43d0858a9a665e80763bd830dc78d5f379afc3815e123c486c2/keyrings.alt-5.0.2-py3-none-any.whl", hash = "sha256:6be74693192f3f37bbb752bfac9b86e6177076b17d2ac12a390f1d6abff8ac7c", size = 17930, upload-time = "2024-08-14T01:09:26.785Z" },
374+
]
375+
302376
[[package]]
303377
name = "markdown-it-py"
304378
version = "4.0.0"
@@ -320,6 +394,15 @@ wheels = [
320394
{ url = "https://files.pythonhosted.org/packages/b3/38/89ba8ad64ae25be8de66a6d463314cf1eb366222074cfda9ee839c56a4b4/mdurl-0.1.2-py3-none-any.whl", hash = "sha256:84008a41e51615a49fc9966191ff91509e3c40b939176e643fd50a5c2196b8f8", size = 9979, upload-time = "2022-08-14T12:40:09.779Z" },
321395
]
322396

397+
[[package]]
398+
name = "more-itertools"
399+
version = "11.1.0"
400+
source = { registry = "https://pypi.org/simple" }
401+
sdist = { url = "https://files.pythonhosted.org/packages/de/1d/f4da6f02cdffe04d6362210b807146a26044c88d839208aec273bb0d9184/more_itertools-11.1.0.tar.gz", hash = "sha256:48e8f4d9e7e5878571ecf6f2b4e57634f93cd474cc8cfbd2376f2d11b396e30d", size = 145772, upload-time = "2026-05-22T14:14:29.909Z" }
402+
wheels = [
403+
{ url = "https://files.pythonhosted.org/packages/e8/3d/1087453384dbde46a8c7f9356eead2c58be8a7bf156bca40243377c85715/more_itertools-11.1.0-py3-none-any.whl", hash = "sha256:4b65538ae22f6fed0ce4874efd317463a7489796a0939fa66824dd542125a192", size = 72226, upload-time = "2026-05-22T14:14:28.824Z" },
404+
]
405+
323406
[[package]]
324407
name = "packaging"
325408
version = "24.2"
@@ -497,6 +580,15 @@ wheels = [
497580
{ url = "https://files.pythonhosted.org/packages/f7/0a/9b400d188f2b4983accabca5a9c9ce534d68dbe1b79c45ce87cf36f787c6/pypi_attestations-0.0.28-py3-none-any.whl", hash = "sha256:a7eebfb55f3b9848bb99e15a6c7ff462e0e7d9a1395690426e4d069fa0dd0158", size = 21910, upload-time = "2025-10-16T16:58:06.106Z" },
498581
]
499582

583+
[[package]]
584+
name = "pywin32-ctypes"
585+
version = "0.2.3"
586+
source = { registry = "https://pypi.org/simple" }
587+
sdist = { url = "https://files.pythonhosted.org/packages/85/9f/01a1a99704853cb63f253eea009390c88e7131c67e66a0a02099a8c917cb/pywin32-ctypes-0.2.3.tar.gz", hash = "sha256:d162dc04946d704503b2edc4d55f3dba5c1d539ead017afa00142c38b9885755", size = 29471, upload-time = "2024-08-14T10:15:34.626Z" }
588+
wheels = [
589+
{ url = "https://files.pythonhosted.org/packages/de/3d/8161f7711c017e01ac9f008dfddd9410dff3674334c233bde66e7ba65bbf/pywin32_ctypes-0.2.3-py3-none-any.whl", hash = "sha256:8a1513379d709975552d202d942d9837758905c8d01eb82b8bcc30918929e7b8", size = 30756, upload-time = "2024-08-14T10:15:33.187Z" },
590+
]
591+
500592
[[package]]
501593
name = "requests"
502594
version = "2.33.0"
@@ -566,6 +658,19 @@ wheels = [
566658
{ url = "https://files.pythonhosted.org/packages/25/7a/b0178788f8dc6cafce37a212c99565fa1fe7872c70c6c9c1e1a372d9d88f/rich-14.2.0-py3-none-any.whl", hash = "sha256:76bc51fe2e57d2b1be1f96c524b890b816e334ab4c1e45888799bfaab0021edd", size = 243393, upload-time = "2025-10-09T14:16:51.245Z" },
567659
]
568660

661+
[[package]]
662+
name = "secretstorage"
663+
version = "3.5.0"
664+
source = { registry = "https://pypi.org/simple" }
665+
dependencies = [
666+
{ name = "cryptography" },
667+
{ name = "jeepney" },
668+
]
669+
sdist = { url = "https://files.pythonhosted.org/packages/1c/03/e834bcd866f2f8a49a85eaff47340affa3bfa391ee9912a952a1faa68c7b/secretstorage-3.5.0.tar.gz", hash = "sha256:f04b8e4689cbce351744d5537bf6b1329c6fc68f91fa666f60a380edddcd11be", size = 19884, upload-time = "2025-11-23T19:02:53.191Z" }
670+
wheels = [
671+
{ url = "https://files.pythonhosted.org/packages/b7/46/f5af3402b579fd5e11573ce652019a67074317e18c1935cc0b4ba9b35552/secretstorage-3.5.0-py3-none-any.whl", hash = "sha256:0ce65888c0725fcb2c5bc0fdb8e5438eece02c523557ea40ce0703c266248137", size = 15554, upload-time = "2025-11-23T19:02:51.545Z" },
672+
]
673+
569674
[[package]]
570675
name = "securesystemslib"
571676
version = "1.3.1"

0 commit comments

Comments
 (0)
⌂ 换网址