Skip to content

Commit

Permalink
experiment with phasing out top-level links (#5)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tdyas authored Feb 18, 2025
1 parent 86a3e57 commit 0c44724
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .github/workflows/pages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
run: |
mkdir -p github-pages
pants run :generate_index -- --url-path-prefix=/simple github-pages/simple
# Experiment: Generate a distinct index without legacy top-level links for recent Pants versions.
pants run :generate_index -- --url-path-prefix=/edge/simple --exclude-legacy-links github-pages/edge/simple
env:
GH_TOKEN: ${{ github.token }}
- name: Upload artifact
Expand Down
23 changes: 22 additions & 1 deletion generate_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import os
import sys
from collections import defaultdict
from copy import deepcopy
from pathlib import Path
from textwrap import dedent
from typing import Any
Expand Down Expand Up @@ -45,6 +46,19 @@ def get_pants_python_packages(gh: github.Github) -> dict[str, dict[Version, list
return packages


def _apply_version_filter(
packages: dict[str, dict[Version, list[Any]]], max_version: Version
) -> None:
to_delete: set[tuple[str, Version]] = set()
for package_name, package in packages.items():
for version in package.keys():
if version >= max_version:
to_delete.add((package_name, version))

for name, version in to_delete:
del packages[name][version]


def _legacy_flat_links(packages: dict[str, dict[Version, list[Any]]]) -> list[str]:
return [
f'<a href="{asset.browser_download_url}">{asset.name}</a><br>'
Expand Down Expand Up @@ -98,10 +112,12 @@ def _write_package_specific_index(
def main(args):
parser = argparse.ArgumentParser()
parser.add_argument("--url-path-prefix", default="/", action="store")
parser.add_argument("--exclude-legacy-links", default=False, action="store_true")
parser.add_argument("output_dir", action="store")
opts = parser.parse_args(args)

github_client = github.Github(auth=github.Auth.Token(os.environ["GH_TOKEN"]))

packages = get_pants_python_packages(github_client)
package_names = sorted(packages.keys())

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

f.write("\n".join(_legacy_flat_links(packages)))
if opts.exclude_legacy_links:
packages_copy = deepcopy(packages)
_apply_version_filter(packages_copy, Version("2.25.0.dev0"))
f.write("\n".join(_legacy_flat_links(packages_copy)))
else:
f.write("\n".join(_legacy_flat_links(packages)))

f.write(
dedent(
Expand Down

0 comments on commit 0c44724

Please sign in to comment.