Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

137 lines
3.6 KiB
Python
Executable File

#!/usr/bin/env python
# Copyright Advanced Micro Devices, Inc.
# SPDX-License-Identifier: MIT
"""Creates an HTML page for releases for `pip install --find-links` from a subdirectory in an S3 bucket.
For generating an index from local files (e.g. during a CI build), see generate_local_index.py.
Sample usage:
```bash
./build_tools/packaging/python/generate_s3_index.py \
--bucket=therock-dev-python \
--endpoint=s3.us-east-2.amazonaws.com \
--subdir=gfx110X-all \
--output=index.html
```
S3 buckets in `us-east-2` currently used are:
* `therock-dev-python`
* `therock-nightly-python`
"""
import argparse
import boto3
import html
import io
import sys
import textwrap
from urllib.parse import quote
def parse_arguments():
p = argparse.ArgumentParser()
p.add_argument(
"--bucket",
required=True,
help="S3 bucket in which the subdirectory is indexed",
)
p.add_argument(
"--endpoint",
default="s3.us-east-2.amazonaws.com",
help="S3 endpoint used to form the URL",
)
p.add_argument(
"--subdir",
"--subdirectory",
required=True,
help="Subdirectory in S3 bucket which is indexed",
)
p.add_argument(
"--output",
default="-",
help="The file to write the HTML to or '-' for stdout (the default)",
)
return p.parse_args()
def get_objects(bucket_name: str, subdir: str):
s3 = boto3.resource("s3")
bucket = s3.Bucket(bucket_name)
all_objects = bucket.objects.filter(Prefix=subdir)
objects = [obj.key.split(subdir + "/")[1] for obj in all_objects]
if "index.html" in objects:
objects.remove("index.html")
return objects
def add_releases(objects: list, base_url: str, subdir: str, file: io.TextIOWrapper):
file.write(
f' <h2> <a href="https://github.com/ROCm/TheRock">ROCm/TheRock</a> {subdir} packages</h2>\n'
)
for obj in objects:
encoded_url = f"{base_url}/{quote(obj)}" # URL-encode the object key
name = html.escape(obj)
file.write(f' <a href="{encoded_url}">{name}</a><br>\n')
file.write(
" <br><hr>\n"
f' This file was auto-generated with <a href="https://github.com/ROCm/TheRock/blob/main/build_tools/packaging/python/generate_s3_index.py">generate_s3_index.py</a>.\n'
)
def main(args):
objects = get_objects(args.bucket, args.subdir)
url = f"https://{args.bucket}.{args.endpoint}/{args.subdir}"
with sys.stdout if args.output == "-" else open(args.output, "w") as f:
f.write(
textwrap.dedent(
"""\
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
* { padding: 0; margin: 10; }
body {
font-family: sans-serif;
text-rendering: optimizespeed;
background-color: #ffffff;
}
a {
color: #006ed3;
text-decoration: none;
}
a:hover {
color: #319cff;
text-decoration: underline;
}
</style>
</head>
<body>
"""
)
)
add_releases(objects, url, args.subdir, f)
f.write(
textwrap.dedent(
"""\
</body>
</html>
"""
)
)
if __name__ == "__main__":
main(parse_arguments())