Skip to content

Commit 499c8aa

Browse files
authored
Fix PyPI publish test script (#14116)
The script stumbled over a newline introduced in pypi/warehouse#18266 (which is valid). Also fixed: Don't read versions for the same package from other indexes. We were using `project_name` here instead of `target`, while using the latter and only reading from a single index simplifies the code too.
1 parent 2fc9221 commit 499c8aa

File tree

1 file changed

+29
-31
lines changed

1 file changed

+29
-31
lines changed

scripts/publish/test_publish.py

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -163,39 +163,37 @@ def index_declaration(self) -> str | None:
163163
}
164164

165165

166-
def get_latest_version(project_name: str, client: httpx.Client) -> Version:
166+
def get_latest_version(target: str, client: httpx.Client) -> Version:
167167
"""Return the latest version on all indexes of the package."""
168168
# To keep the number of packages small we reuse them across targets, so we have to
169169
# pick a version that doesn't exist on any target yet
170170
versions = set()
171-
for target_config in all_targets.values():
172-
if target_config.project_name != project_name:
173-
continue
174-
url = target_config.index_url + project_name + "/"
175-
176-
# Get with retries
177-
error = None
178-
for _ in range(5):
179-
try:
180-
versions.update(collect_versions(url, client))
181-
break
182-
except httpx.HTTPError as err:
183-
error = err
184-
print(
185-
f"Error getting version for {project_name}, sleeping for 1s: {err}",
186-
file=sys.stderr,
187-
)
188-
time.sleep(1)
189-
except InvalidSdistFilename as err:
190-
# Sometimes there's a link that says "status page"
191-
error = err
192-
print(
193-
f"Invalid index page for {project_name}, sleeping for 1s: {err}",
194-
file=sys.stderr,
195-
)
196-
time.sleep(1)
197-
else:
198-
raise RuntimeError(f"Failed to fetch {url}") from error
171+
target_config = all_targets[target]
172+
url = target_config.index_url + target_config.project_name + "/"
173+
174+
# Get with retries
175+
error = None
176+
for _ in range(5):
177+
try:
178+
versions.update(collect_versions(url, client))
179+
break
180+
except httpx.HTTPError as err:
181+
error = err
182+
print(
183+
f"Error getting version for {target_config.project_name}, sleeping for 1s: {err}",
184+
file=sys.stderr,
185+
)
186+
time.sleep(1)
187+
except InvalidSdistFilename as err:
188+
# Sometimes there's a link that says "status page"
189+
error = err
190+
print(
191+
f"Invalid index page for {target_config.project_name}, sleeping for 1s: {err}",
192+
file=sys.stderr,
193+
)
194+
time.sleep(1)
195+
else:
196+
raise RuntimeError(f"Failed to fetch {url}") from error
199197
return max(versions)
200198

201199

@@ -223,7 +221,7 @@ def get_filenames(url: str, client: httpx.Client) -> list[str]:
223221
response = client.get(url)
224222
data = response.text
225223
# Works for the indexes in the list
226-
href_text = r"<a(?: +[\w-]+=(?:'[^']+'|\"[^\"]+\"))* *>([^<>]+)</a>"
224+
href_text = r"<a(?:\s*[\w-]+=(?:'[^']+'|\"[^\"]+\"))* *>([^<>]+)</a>"
227225
return [m.group(1) for m in re.finditer(href_text, data)]
228226

229227

@@ -363,7 +361,7 @@ def publish_project(target: str, uv: Path, client: httpx.Client):
363361
print(f"\nPublish {project_name} for {target}", file=sys.stderr)
364362

365363
# The distributions are build to the dist directory of the project.
366-
previous_version = get_latest_version(project_name, client)
364+
previous_version = get_latest_version(target, client)
367365
version = get_new_version(previous_version)
368366
project_dir = build_project_at_version(target, version, uv)
369367

0 commit comments

Comments
 (0)