-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathto_md.py
More file actions
184 lines (149 loc) · 5.44 KB
/
to_md.py
File metadata and controls
184 lines (149 loc) · 5.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
"""
Usage: `python to_md.py s3data.json > output.md`
To generate 's3data.json', use the following AWS CLI command (no credentials required):
aws s3api list-objects --output json --bucket ifcopenshell-builds --no-sign-request > s3data.json
"""
import itertools
import json
import operator
import re
import sys
from collections import defaultdict
from typing import NamedTuple
from urllib.parse import quote_plus
import humanize
import natsort
from packaging.utils import parse_wheel_filename
PREFIX = "https://s3.amazonaws.com/ifcopenshell-builds/"
class Asset(NamedTuple):
version: str
commit: str
last_modified: str
product: str
os: str
size: int
key: str
def is_valid_product(product):
if product in {"IfcConvert", "IfcGeomServer", "svgfill"}:
return True
elif re.match(r"^ifcopenshell-python-\d{2,3}u?$", product):
return True
return False
def get_bucket_data():
bucket = json.load(open(sys.argv[1]))
for zip_data in bucket["Contents"]:
key: str = zip_data["Key"]
if key.endswith(".zip"):
parts = key.removesuffix(".zip").rsplit("-", 3)
if len(parts) == 4:
product, version, commit, os = parts
if is_valid_product(product):
pass
elif product.count("-") and is_valid_product(product.rsplit("-", 1)[0]) and os == "arm64":
parts = key.removesuffix(".zip").rsplit("-", 4)
product, version, commit, os, arm64 = parts
os = f"{os}-{arm64}"
else:
continue
if len(commit) != 7:
continue
# E.g. searching for 'v0.8.5'.
if not re.match(r"^v\d\.\d\.\d+$", version):
continue
if os in {
"macosm164",
"macos64",
"linux64",
"linuxarm64",
"win32",
"win64",
"linux32",
"win-arm64",
}:
pass
else:
continue
yield Asset(
version,
commit,
zip_data["LastModified"],
product,
os,
zip_data["Size"],
key,
)
elif key.endswith(".whl"):
fixed = key.replace("ifcopenshell-python", "ifcopenshell_python")
fixed = re.sub(r"(v\d\.\d\.\d)(\-|\+)(\w{7})", "v0.8.1+\\3", fixed)
try:
module_name, version, _, tags = parse_wheel_filename(fixed)
except:
continue
if module_name == "ifcopenshell":
module_name += "-python"
if len(tags) != 1:
continue
tag = next(iter(tags))
if "wasm" not in tag.platform:
continue
abi = re.sub("c|p|y", "", tag.abi)
assert version.local is not None
yield Asset(
f"v{version.public}",
version.local,
zip_data["LastModified"],
f"{module_name}-{abi}",
"WASM",
zip_data["Size"],
key,
)
if len(sys.argv) != 2:
print(__doc__)
exit(1)
print("# IfcOpenShell Builds")
print("Source code - [IfcOpenShell/build-listing](https://github.com/IfcOpenShell/build-listing)")
print()
commit_dates: defaultdict[str, list[str]] = defaultdict(list)
for asset in get_bucket_data():
commit_dates[asset.commit].append(asset.last_modified)
hash_to_date = {commit: min(dates) for commit, dates in commit_dates.items()}
data = natsort.natsorted(get_bucket_data(), reverse=True)
for section, subsections in itertools.groupby(data, key=operator.attrgetter("version")):
print("##", section)
for commit, rows in itertools.groupby(
sorted(subsections, key=lambda t: hash_to_date[t.commit], reverse=True),
key=operator.attrgetter("commit"),
):
print(f"### {commit} ({hash_to_date[commit]})")
rows = list(rows)
def unique_sorted(vs: list[str]) -> list[str]:
return natsort.natsorted(set(vs))
product = unique_sorted([r.product for r in rows])
os = unique_sorted([r.os for r in rows])
def format_os(os: str) -> str:
os = os.replace("m1", " M1")
os = os.replace("arm", " ARM")
os = os.replace("os", "OS")
os = os.replace("win-", "win")
os = re.sub(r"(32|64)", r" \1bit", os)
os = f"{os[0].upper()}{os[1:]}"
return os
# Header.
osh = list(map(format_os, os))
existing_products = {(r.product, r.os): (humanize.naturalsize(r.size), quote_plus(r.key)) for r in rows}
print()
print("item|", "|".join(osh))
print("|".join(["---"] + [":---:"] * len(osh)))
# Rows.
for product_ in product:
links: list[str] = []
for os_ in os:
size, filename = existing_products.get((product_, os_), ("-", ""))
if filename:
url = f"{PREFIX}{filename}"
link = f"[{size}]({url})"
else:
link = "-"
links.append(link)
print(product_, "|", "|".join(links))
print()