| 1 |
""" |
| 2 |
Checks related to the OpenBLAS version used in CI. |
| 3 |
|
| 4 |
Options: |
| 5 |
1. Check that the BLAS used at build time is (a) scipy-openblas, and (b) its version is |
| 6 |
higher than a given minimum version. Note: this method only seems to give |
| 7 |
the first 3 version components, so 0.3.30.0.7 gets translated to 0.3.30 when reading |
| 8 |
it back out from `scipy.show_config()`. |
| 9 |
2. Check requirements files in the main numpy repo and compare with the numpy-release |
| 10 |
repo. Goal is to ensure that `numpy-release` is not behind. |
| 11 |
|
| 12 |
Both of these checks are primarily useful in a CI job. |
| 13 |
|
| 14 |
Examples: |
| 15 |
|
| 16 |
# Requires install numpy |
| 17 |
$ python check_openblas_version.py --min-version 0.3.30 |
| 18 |
|
| 19 |
# Only needs the requirements files |
| 20 |
$ python check_openblas_version.py --req-files \ |
| 21 |
../numpy-release/requirements/openblas_requirements.txt |
| 22 |
""" |
| 23 |
|
| 24 |
import argparse |
| 25 |
import os.path |
| 26 |
import pprint |
| 27 |
|
| 28 |
|
| 29 |
def check_built_version(min_version): |
| 30 |
import numpy |
| 31 |
deps = numpy.show_config('dicts')['Build Dependencies'] |
| 32 |
assert "blas" in deps |
| 33 |
print("Build Dependencies: blas") |
| 34 |
pprint.pprint(deps["blas"]) |
| 35 |
assert deps["blas"]["version"].split(".") >= min_version.split(".") |
| 36 |
assert deps["blas"]["name"] == "scipy-openblas" |
| 37 |
|
| 38 |
|
| 39 |
def check_requirements_files(reqfile): |
| 40 |
if not os.path.exists(reqfile): |
| 41 |
print(f"Path does not exist: {reqfile}") |
| 42 |
|
| 43 |
def get_version(line): |
| 44 |
req = line.split(";")[0].split("==")[1].split(".")[:5] |
| 45 |
return tuple(int(s) for s in req) |
| 46 |
|
| 47 |
def parse_reqs(reqfile): |
| 48 |
with open(reqfile) as f: |
| 49 |
lines = f.readlines() |
| 50 |
|
| 51 |
v32 = None |
| 52 |
v64 = None |
| 53 |
for line in lines: |
| 54 |
if "scipy-openblas32" in line: |
| 55 |
v32 = get_version(line) |
| 56 |
if "scipy-openblas64" in line: |
| 57 |
v64 = get_version(line) |
| 58 |
if v32 is None or v64 is None: |
| 59 |
raise AssertionError("Expected `scipy-openblas32` and " |
| 60 |
"`scipy-openblas64` in `ci_requirements.txt`, " |
| 61 |
f"got:\n {' '.join(lines)}") |
| 62 |
return v32, v64 |
| 63 |
|
| 64 |
this_dir = os.path.abspath(os.path.dirname(__file__)) |
| 65 |
reqfile_thisrepo = os.path.join(this_dir, '..', 'requirements', |
| 66 |
'ci_requirements.txt') |
| 67 |
|
| 68 |
v32_thisrepo, v64_thisrepo = parse_reqs(reqfile_thisrepo) |
| 69 |
v32_rel, v64_rel = parse_reqs(reqfile) |
| 70 |
|
| 71 |
def compare_versions(v_rel, v_thisrepo, bits): |
| 72 |
if not v_rel >= v_thisrepo: |
| 73 |
raise AssertionError(f"`numpy-release` version of scipy-openblas{bits} " |
| 74 |
f"{v_rel} is behind this repo: {v_thisrepo}") |
| 75 |
|
| 76 |
compare_versions(v64_rel, v64_thisrepo, "64") |
| 77 |
compare_versions(v32_rel, v32_thisrepo, "32") |
| 78 |
|
| 79 |
|
| 80 |
def main(): |
| 81 |
parser = argparse.ArgumentParser() |
| 82 |
parser.add_argument( |
| 83 |
"--req-files", |
| 84 |
type=str, |
| 85 |
help="Path to the requirements file to compare with the one in this repo" |
| 86 |
) |
| 87 |
parser.add_argument( |
| 88 |
"--min-version", |
| 89 |
type=str, |
| 90 |
help="The minimum version that should have been used at build time for " |
| 91 |
"installed `numpy` package" |
| 92 |
) |
| 93 |
args = parser.parse_args() |
| 94 |
|
| 95 |
if args.min_version is None and args.req_files is None: |
| 96 |
raise ValueError("One of `--req-files` or `--min-version` needs to be " |
| 97 |
"specified") |
| 98 |
|
| 99 |
if args.min_version: |
| 100 |
check_built_version(args.min_version) |
| 101 |
|
| 102 |
if args.req_files: |
| 103 |
check_requirements_files(args.req_files) |
| 104 |
|
| 105 |
|
| 106 |
if __name__ == '__main__': |
| 107 |
main() |