Skip to content

Commit 3977009

Browse files
committed
Add version badges
1 parent e7ea568 commit 3977009

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

.github/workflows/wheels.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,10 @@ jobs:
343343
main/tools/store_info.py wheelhouse/${{ inputs.name }}/*.json --store main/build.json
344344
rm wheelhouse/${{ inputs.name }}/*.json
345345
346+
- name: Update version icons
347+
run: |
348+
main/tools/update_icons --store main/build.json --readme main/README.md
349+
346350
- name: Commit wheels
347351
working-directory: wheelhouse
348352
run: |
@@ -365,7 +369,7 @@ jobs:
365369
fi
366370
git config user.name github-actions[bot]
367371
git config user.email 41898282+github-actions[bot]@users.noreply.github.com
368-
git add build.json
372+
git add build.json README.md
369373
git commit -m "ci: Store info for ${{ inputs.name }}-${{ needs.meta.outputs.version }}"
370374
git push origin HEAD:main
371375

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# numpy-mkl
22

3+
[![NumPy](https://img.shields.io/badge/NumPy-2.1_%7C_2.2_%7C_2.3-013243)](https://numpy.org/)
4+
[![SciPy](https://img.shields.io/badge/SciPy-1.15.2_%7C_1.15.3-8caae6)](https://scipy.org/)
5+
[![mkl-service](https://img.shields.io/badge/mkl--service-v2.4.2-3b5526)](https://github.com/IntelPython/mkl-service)
6+
37
This repository provides binary wheels for NumPy and SciPy, linked to Intel's high-performance
48
[oneAPI Math Kernel
59
Library](https://www.intel.com/content/www/us/en/developer/tools/oneapi/onemkl.html) for Intel CPUs.

tools/update_icons

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import json
5+
from pathlib import Path
6+
7+
ICONS = {
8+
'numpy': '[![NumPy](https://img.shields.io/badge/NumPy-{0}-013243)](https://numpy.org/)',
9+
'scipy': '[![SciPy](https://img.shields.io/badge/SciPy-{0}-8caae6)](https://scipy.org/)',
10+
'mkl_service': '[![mkl-service](https://img.shields.io/badge/mkl--service-{0}-3b5526)](https://github.com/IntelPython/mkl-service)',
11+
}
12+
13+
14+
def fetch_builds(path):
15+
if isinstance(path, str):
16+
path = Path(path)
17+
store = json.loads(path.read_text()) if path.exists() else {}
18+
return list(store.keys())
19+
20+
21+
def fetch_versions(package, builds):
22+
versions = {_.split('-')[1] for _ in builds if _.startswith(package)}
23+
formatted = {format_version(_, len(versions)) for _ in versions}
24+
return '_%7C_'.join(sorted(formatted))
25+
26+
27+
def format_version(v, len_):
28+
major, minor, patch = v.split('.')
29+
if len_ > 3:
30+
return '.'.join((major, minor))
31+
if len_ == 1:
32+
return 'v' + v
33+
return v
34+
35+
36+
def make_icon(package, builds):
37+
versions = fetch_versions(package, builds)
38+
return ICONS[package].format(versions)
39+
40+
41+
if __name__ == '__main__':
42+
parser = argparse.ArgumentParser(description='Update version icons')
43+
parser.add_argument('-s', '--store', required=True, type=str, help='store file')
44+
parser.add_argument('-r', '--readme', required=True, type=str, help='readme file')
45+
46+
args = parser.parse_args()
47+
builds = fetch_builds(Path(args.store))
48+
readme = Path(args.readme)
49+
50+
with readme.open() as f:
51+
lines = f.readlines()
52+
53+
for p in ('numpy', 'scipy', 'mkl_service'):
54+
for i, l in enumerate(lines):
55+
if l.startswith(ICONS[p][:45]):
56+
lines[i] = make_icon(p, builds) + '\n'
57+
58+
with readme.open('w') as f:
59+
f.writelines(lines)

0 commit comments

Comments
 (0)