forked from numpy/numpy
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcheck_installed_files.py
91 lines (65 loc) · 2.69 KB
/
check_installed_files.py
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
"""
Check if all the test and .pyi files are installed after building.
Examples::
$ python check_installed_files.py install_dirname
install_dirname:
the relative path to the directory where NumPy is installed after
building and running `meson install`.
Notes
=====
The script will stop on encountering the first missing file in the install dir,
it will not give a full listing. This should be okay, because the script is
meant for use in CI so it's not like many files will be missing at once.
"""
import os
import glob
import sys
CUR_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__)))
ROOT_DIR = os.path.dirname(CUR_DIR)
NUMPY_DIR = os.path.join(ROOT_DIR, 'numpy')
# Files whose installation path will be different from original one
changed_installed_path = {
#'numpy/_build_utils/some_file.py': 'numpy/lib/some_file.py'
}
def main(install_dir):
INSTALLED_DIR = os.path.join(ROOT_DIR, install_dir)
if not os.path.exists(INSTALLED_DIR):
raise ValueError(
f"Provided install dir {INSTALLED_DIR} does not exist"
)
numpy_test_files = get_files(NUMPY_DIR, kind='test')
installed_test_files = get_files(INSTALLED_DIR, kind='test')
# Check test files detected in repo are installed
for test_file in numpy_test_files.keys():
if test_file not in installed_test_files.keys():
raise Exception(
"%s is not installed" % numpy_test_files[test_file]
)
print("----------- All the test files were installed --------------")
numpy_pyi_files = get_files(NUMPY_DIR, kind='stub')
installed_pyi_files = get_files(INSTALLED_DIR, kind='stub')
# Check *.pyi files detected in repo are installed
for pyi_file in numpy_pyi_files.keys():
if pyi_file not in installed_pyi_files.keys():
raise Exception("%s is not installed" % numpy_pyi_files[pyi_file])
print("----------- All the .pyi files were installed --------------")
def get_files(dir_to_check, kind='test'):
files = dict()
patterns = {
'test': f'{dir_to_check}/**/test_*.py',
'stub': f'{dir_to_check}/**/*.pyi',
}
for path in glob.glob(patterns[kind], recursive=True):
relpath = os.path.relpath(path, dir_to_check)
files[relpath] = path
if sys.version_info >= (3, 12):
files = {
k: v for k, v in files.items() if not k.startswith('distutils')
}
return files
if __name__ == '__main__':
if not len(sys.argv) == 2:
raise ValueError("Incorrect number of input arguments, need "
"check_installation.py relpath/to/installed/numpy")
install_dir = sys.argv[1]
main(install_dir)