tests and agents.md
This commit is contained in:
+28
@@ -5,7 +5,9 @@ asks for confirmation, then builds and uploads.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import configparser
|
||||
import json
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tomllib
|
||||
@@ -23,6 +25,26 @@ TEST_PYPI_JSON_URL = "https://test.pypi.org/pypi/{package}/json"
|
||||
TEST_PYPI_UPLOAD_URL = "https://test.pypi.org/legacy/"
|
||||
|
||||
|
||||
def load_pypirc_token(use_test_pypi: bool) -> str | None:
|
||||
"""Read a token from ~/.pypirc for the matching index, if present.
|
||||
|
||||
`uv publish` does not read ~/.pypirc (twine convention), so we surface it
|
||||
through UV_PUBLISH_TOKEN. Returns None when no matching token is found.
|
||||
"""
|
||||
pypirc = Path.home() / ".pypirc"
|
||||
if not pypirc.is_file():
|
||||
return None
|
||||
parser = configparser.ConfigParser()
|
||||
try:
|
||||
parser.read(pypirc)
|
||||
except configparser.Error:
|
||||
return None
|
||||
section = "testpypi" if use_test_pypi else "pypi"
|
||||
if not parser.has_section(section):
|
||||
return None
|
||||
return parser.get(section, "password", fallback=None)
|
||||
|
||||
|
||||
def fetch_latest_revision(blender_version: str, use_test_pypi: bool) -> int | None:
|
||||
"""Fetch the latest revision for a Blender version from PyPI.
|
||||
|
||||
@@ -175,6 +197,11 @@ def publish_version(
|
||||
|
||||
# Publish
|
||||
print(f" Publishing to {publish_url}...")
|
||||
env = os.environ.copy()
|
||||
if "UV_PUBLISH_TOKEN" not in env:
|
||||
token = load_pypirc_token(use_test_pypi)
|
||||
if token:
|
||||
env["UV_PUBLISH_TOKEN"] = token
|
||||
result = subprocess.run(
|
||||
[
|
||||
"uv",
|
||||
@@ -184,6 +211,7 @@ def publish_version(
|
||||
publish_url,
|
||||
],
|
||||
cwd=str(SCRIPT_DIR),
|
||||
env=env,
|
||||
)
|
||||
if result.returncode != 0:
|
||||
print("Publish failed.", file=sys.stderr)
|
||||
|
||||
Reference in New Issue
Block a user