Skip to content

Commit

Permalink
Merge pull request #34 from espressif/fix/visualy_remove_unused_wheels
Browse files Browse the repository at this point in the history
fix(index): Visually removed the nonsense or empty wheels from index
  • Loading branch information
tomassebestik authored Jul 16, 2024
2 parents 5c648fd + e1f6e44 commit ef69a95
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 4 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/only-create-and-upload-index.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: only-create-and-upload-index

on:
workflow_dispatch:

jobs:
triage:
name: Create and Upload Index
runs-on: ubuntu-latest
strategy:
fail-fast: false
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION }}
AWS_BUCKET: ${{ secrets.DL_BUCKET }}
PREFIX: 'pypi'
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install dependencies
run: python -m pip install -r build_requirements.txt

- name: Create and upload Index to S3 bucket
run: |
python create_index_pages.py $AWS_BUCKET
- name: Drop AWS cache
id: invalidate-index-cache
run: aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CACHE_INVALIDATION }} --paths "/pypi/*"
24 changes: 20 additions & 4 deletions create_index_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,37 @@ def _html_loader(path: str) -> str:
for response in response_iterator:
for package in response['Contents']:
res = re.search(r'\/(.*)\/', format(package['Key']))
#continue when package == index.html
if not res:
continue

name = res.group(1).lower()

# Skip the route for the human readable form of the PyPI
if name == 'pretty':
continue

if name not in packages:
packages[name] = []

packages[name].append(Path(package['Key']).name)

# Remove not valid packages to not display them
packages_new = packages.copy()
for package_name, package_values in packages.items():
if len(package_values) < 1:
packages_new.pop(package_name)
if len(package_values) == 1:
if package_values[0] == 'index.html':
packages_new.pop(package_name)

index = []
index_pretty = []
index.append(HTML_HEADER)
index_pretty.append(HTML_PRETTY_HEADER)
for name in packages.keys():
for name in packages_new.keys():
index.append(f' <a href="/pypi/{name}/">{name}/</a>')
index_pretty.append(
f' <div><a href="/pypi/{name}">{name}</a><span>Entries: {len(packages[name])}</span></div><br>'
f' <div><a href="/pypi/{name}">{name}</a><span>Entries: {len(packages_new[name])}</span></div><br>'
)
index.append(HTML_FOOTER)
index_pretty.append(HTML_FOOTER)
Expand All @@ -68,10 +81,13 @@ def _html_loader(path: str) -> str:
'pypi/pretty/index.html',
ExtraArgs={'ACL': 'public-read', 'ContentType':'text/html'})

for name, filenames in packages.items():
for name, filenames in packages_new.items():
index_wheel = []
index_wheel.append(HTML_HEADER)
for fn in filenames:
# Skip HTML source file of the wheel page
if fn == 'index.html':
continue
index_wheel.append(f'<a href="/pypi/{name}/{fn}">{fn}</a><br/>')
index_wheel.append(HTML_FOOTER)

Expand Down

0 comments on commit ef69a95

Please sign in to comment.