| 1 |
""" |
| 2 |
Check if all the test and .pyi files are installed after building. |
| 3 |
|
| 4 |
Examples:: |
| 5 |
|
| 6 |
$ python check_installed_files.py install_dirname |
| 7 |
|
| 8 |
install_dirname: |
| 9 |
the relative path to the directory where NumPy is installed after |
| 10 |
building and running `meson install`. |
| 11 |
|
| 12 |
Notes |
| 13 |
===== |
| 14 |
|
| 15 |
The script will stop on encountering the first missing file in the install dir, |
| 16 |
it will not give a full listing. This should be okay, because the script is |
| 17 |
meant for use in CI so it's not like many files will be missing at once. |
| 18 |
|
| 19 |
""" |
| 20 |
|
| 21 |
import glob |
| 22 |
import json |
| 23 |
import os |
| 24 |
import sys |
| 25 |
|
| 26 |
CUR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__))) |
| 27 |
ROOT_DIR = os.path.dirname(CUR_DIR) |
| 28 |
NUMPY_DIR = os.path.join(ROOT_DIR, 'numpy') |
| 29 |
|
| 30 |
|
| 31 |
# Files whose installation path will be different from original one |
| 32 |
changed_installed_path = { |
| 33 |
#'numpy/_build_utils/some_file.py': 'numpy/lib/some_file.py' |
| 34 |
} |
| 35 |
|
| 36 |
|
| 37 |
def main(install_dir, tests_check): |
| 38 |
INSTALLED_DIR = os.path.join(ROOT_DIR, install_dir) |
| 39 |
if not os.path.exists(INSTALLED_DIR): |
| 40 |
raise ValueError( |
| 41 |
f"Provided install dir {INSTALLED_DIR} does not exist" |
| 42 |
) |
| 43 |
|
| 44 |
numpy_test_files = get_files(NUMPY_DIR, kind='test') |
| 45 |
installed_test_files = get_files(INSTALLED_DIR, kind='test') |
| 46 |
|
| 47 |
if tests_check == "--no-tests": |
| 48 |
if len(installed_test_files) > 0: |
| 49 |
raise Exception("Test files aren't expected to be installed in %s" |
| 50 |
", found %s" % (INSTALLED_DIR, installed_test_files)) |
| 51 |
print("----------- No test files were installed --------------") |
| 52 |
else: |
| 53 |
# Check test files detected in repo are installed |
| 54 |
for test_file in numpy_test_files.keys(): |
| 55 |
if test_file not in installed_test_files.keys(): |
| 56 |
raise Exception( |
| 57 |
f"{numpy_test_files[test_file]} is not installed" |
| 58 |
) |
| 59 |
|
| 60 |
print("----------- All the test files were installed --------------") |
| 61 |
|
| 62 |
numpy_pyi_files = get_files(NUMPY_DIR, kind='stub') |
| 63 |
installed_pyi_files = get_files(INSTALLED_DIR, kind='stub') |
| 64 |
|
| 65 |
# Check *.pyi files detected in repo are installed |
| 66 |
for pyi_file in numpy_pyi_files.keys(): |
| 67 |
if pyi_file not in installed_pyi_files.keys(): |
| 68 |
if (tests_check == "--no-tests" and |
| 69 |
"tests" in numpy_pyi_files[pyi_file]): |
| 70 |
continue |
| 71 |
raise Exception(f"{numpy_pyi_files[pyi_file]} is not installed") |
| 72 |
|
| 73 |
print("----------- All the necessary .pyi files " |
| 74 |
"were installed --------------") |
| 75 |
|
| 76 |
|
| 77 |
def get_files(dir_to_check, kind='test'): |
| 78 |
files = {} |
| 79 |
patterns = { |
| 80 |
'test': f'{dir_to_check}/**/test_*.py', |
| 81 |
'stub': f'{dir_to_check}/**/*.pyi', |
| 82 |
} |
| 83 |
for path in glob.glob(patterns[kind], recursive=True): |
| 84 |
relpath = os.path.relpath(path, dir_to_check) |
| 85 |
files[relpath] = path |
| 86 |
|
| 87 |
if sys.version_info >= (3, 12): |
| 88 |
files = { |
| 89 |
k: v for k, v in files.items() if not k.startswith('distutils') |
| 90 |
} |
| 91 |
|
| 92 |
# ignore python files in vendored pythoncapi-compat submodule |
| 93 |
files = { |
| 94 |
k: v for k, v in files.items() if 'pythoncapi-compat' not in k |
| 95 |
} |
| 96 |
|
| 97 |
return files |
| 98 |
|
| 99 |
|
| 100 |
if __name__ == '__main__': |
| 101 |
if len(sys.argv) < 2: |
| 102 |
raise ValueError("Incorrect number of input arguments, need " |
| 103 |
"check_installation.py relpath/to/installed/numpy") |
| 104 |
|
| 105 |
install_dir = sys.argv[1] |
| 106 |
tests_check = "" |
| 107 |
if len(sys.argv) >= 3: |
| 108 |
tests_check = sys.argv[2] |
| 109 |
main(install_dir, tests_check) |
| 110 |
|
| 111 |
all_tags = set() |
| 112 |
|
| 113 |
with open(os.path.join('build', 'meson-info', |
| 114 |
'intro-install_plan.json'), 'r') as f: |
| 115 |
targets = json.load(f) |
| 116 |
|
| 117 |
for key in targets.keys(): |
| 118 |
for values in list(targets[key].values()): |
| 119 |
if values['tag'] not in all_tags: |
| 120 |
all_tags.add(values['tag']) |
| 121 |
|
| 122 |
if all_tags != {'runtime', 'python-runtime', 'devel', 'tests'}: |
| 123 |
raise AssertionError(f"Found unexpected install tag: {all_tags}") |