interplane.Get Omega
Read in your language

CUDApp

CUDA++: AIEN’s GPU machine-code toolchain, runtime and driver client for NVIDIA GPUs without the CUDA toolkit. Hardware coverage and driver replacement limits are explicit.

Brought by drakestapleton

branch main Branches Tags History

CUDApp / evidence / MAX-INTEROP / G1 / wheel_inventory.py

40 lines · 2043 bytes Raw Blame History
1#!/usr/bin/env python3
2"""File-level licence inventory of installed MAX/Mojo wheels, from RECORD.
3Throwaway diagnostic. usage: wheel_inventory.py SITE_PACKAGES OUT_TSV"""
4import collections, csv, glob, os, re, sys
5
6site, out = sys.argv[1:3]
7spdx = re.compile(r"SPDX-License-Identifier:\s*([^\n*#]+)")
8counts = collections.Counter()
9with open(out, "w") as fo:
10 fo.write("dist\tversion\tdeclared_licence\tpath\trecord_hash\tsize\tfile_header_licence\n")
11 for di in sorted(glob.glob(os.path.join(site, "*.dist-info"))):
12 base = os.path.basename(di)
13 if not re.match(r"(max|mojo|modular)", base):
14 continue
15 meta = open(os.path.join(di, "METADATA"), errors="replace").read()
16 name = re.search(r"^Name: (.+)$", meta, re.M).group(1)
17 ver = re.search(r"^Version: (.+)$", meta, re.M).group(1)
18 dec = (re.search(r"^License(?:-Expression)?: (.+)$", meta, re.M) or [None, ""])[1]
19 for row in csv.reader(open(os.path.join(di, "RECORD"))):
20 path, h, size = (row + ["", ""])[:3]
21 hdr = ""
22 full = os.path.join(site, path)
23 if os.path.isfile(full) and not path.endswith((".so", ".mojoc", ".mojopkg", ".pyc")) and "/bin/" not in path:
24 try:
25 t = open(full, "rb").read(4096).decode("utf-8", "replace")
26 m = spdx.search(t)
27 if m:
28 hdr = m.group(1).strip().rstrip("-*/ ").strip()
29 elif "Apache License" in t and "LLVM" in t:
30 hdr = "Apache-2.0 WITH LLVM-exception"
31 elif "Apache License" in t:
32 hdr = "Apache-2.0"
33 except OSError:
34 pass
35 ext = os.path.splitext(path)[1] or "(none)"
36 fo.write(f"{name}\t{ver}\t{dec}\t{path}\t{h}\t{size}\t{hdr}\n")
37 counts[(name, ver, dec, hdr or "(no header)", ext if not hdr else "")] += 1
38for k, c in sorted(counts.items()):
39 if c >= 1:
40 print(c, *k, sep="\t")