Skip to content

Commit 0c44724

Browse files
authored
experiment with phasing out top-level links (#5)
Experiment with phasing out top-level links for Pants artifacts to better comply with PEP 0503. The new experimental index is generated at https://wheels.pantsbuild.org/edge/simple and does not generate top-level links for 2.25.x and later versions.
1 parent 86a3e57 commit 0c44724

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

.github/workflows/pages.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ jobs:
4141
run: |
4242
mkdir -p github-pages
4343
pants run :generate_index -- --url-path-prefix=/simple github-pages/simple
44+
# Experiment: Generate a distinct index without legacy top-level links for recent Pants versions.
45+
pants run :generate_index -- --url-path-prefix=/edge/simple --exclude-legacy-links github-pages/edge/simple
4446
env:
4547
GH_TOKEN: ${{ github.token }}
4648
- name: Upload artifact

generate_index.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import os
88
import sys
99
from collections import defaultdict
10+
from copy import deepcopy
1011
from pathlib import Path
1112
from textwrap import dedent
1213
from typing import Any
@@ -45,6 +46,19 @@ def get_pants_python_packages(gh: github.Github) -> dict[str, dict[Version, list
4546
return packages
4647

4748

49+
def _apply_version_filter(
50+
packages: dict[str, dict[Version, list[Any]]], max_version: Version
51+
) -> None:
52+
to_delete: set[tuple[str, Version]] = set()
53+
for package_name, package in packages.items():
54+
for version in package.keys():
55+
if version >= max_version:
56+
to_delete.add((package_name, version))
57+
58+
for name, version in to_delete:
59+
del packages[name][version]
60+
61+
4862
def _legacy_flat_links(packages: dict[str, dict[Version, list[Any]]]) -> list[str]:
4963
return [
5064
f'<a href="{asset.browser_download_url}">{asset.name}</a><br>'
@@ -98,10 +112,12 @@ def _write_package_specific_index(
98112
def main(args):
99113
parser = argparse.ArgumentParser()
100114
parser.add_argument("--url-path-prefix", default="/", action="store")
115+
parser.add_argument("--exclude-legacy-links", default=False, action="store_true")
101116
parser.add_argument("output_dir", action="store")
102117
opts = parser.parse_args(args)
103118

104119
github_client = github.Github(auth=github.Auth.Token(os.environ["GH_TOKEN"]))
120+
105121
packages = get_pants_python_packages(github_client)
106122
package_names = sorted(packages.keys())
107123

@@ -133,7 +149,12 @@ def main(args):
133149
f"""<li><a href="{prefix}/{package_name}/">{package_name}</a></li>\n"""
134150
)
135151

136-
f.write("\n".join(_legacy_flat_links(packages)))
152+
if opts.exclude_legacy_links:
153+
packages_copy = deepcopy(packages)
154+
_apply_version_filter(packages_copy, Version("2.25.0.dev0"))
155+
f.write("\n".join(_legacy_flat_links(packages_copy)))
156+
else:
157+
f.write("\n".join(_legacy_flat_links(packages)))
137158

138159
f.write(
139160
dedent(

0 commit comments

Comments
 (0)