|
7 | 7 | import os
|
8 | 8 | import sys
|
9 | 9 | from collections import defaultdict
|
| 10 | +from copy import deepcopy |
10 | 11 | from pathlib import Path
|
11 | 12 | from textwrap import dedent
|
12 | 13 | from typing import Any
|
@@ -45,6 +46,19 @@ def get_pants_python_packages(gh: github.Github) -> dict[str, dict[Version, list
|
45 | 46 | return packages
|
46 | 47 |
|
47 | 48 |
|
| 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 | + |
48 | 62 | def _legacy_flat_links(packages: dict[str, dict[Version, list[Any]]]) -> list[str]:
|
49 | 63 | return [
|
50 | 64 | f'<a href="{asset.browser_download_url}">{asset.name}</a><br>'
|
@@ -98,10 +112,12 @@ def _write_package_specific_index(
|
98 | 112 | def main(args):
|
99 | 113 | parser = argparse.ArgumentParser()
|
100 | 114 | parser.add_argument("--url-path-prefix", default="/", action="store")
|
| 115 | + parser.add_argument("--exclude-legacy-links", default=False, action="store_true") |
101 | 116 | parser.add_argument("output_dir", action="store")
|
102 | 117 | opts = parser.parse_args(args)
|
103 | 118 |
|
104 | 119 | github_client = github.Github(auth=github.Auth.Token(os.environ["GH_TOKEN"]))
|
| 120 | + |
105 | 121 | packages = get_pants_python_packages(github_client)
|
106 | 122 | package_names = sorted(packages.keys())
|
107 | 123 |
|
@@ -133,7 +149,12 @@ def main(args):
|
133 | 149 | f"""<li><a href="{prefix}/{package_name}/">{package_name}</a></li>\n"""
|
134 | 150 | )
|
135 | 151 |
|
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))) |
137 | 158 |
|
138 | 159 | f.write(
|
139 | 160 | dedent(
|
|
0 commit comments