File: check_installed_files.py

package info (click to toggle)
numpy 1%3A2.2.4%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 83,420 kB
  • sloc: python: 248,499; asm: 232,365; ansic: 216,874; cpp: 135,657; f90: 1,540; sh: 938; fortran: 558; makefile: 409; sed: 139; xml: 109; java: 92; perl: 79; cs: 54; javascript: 53; objc: 29; lex: 13; yacc: 9
file content (124 lines) | stat: -rw-r--r-- 4,015 bytes parent folder | download
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
"""
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
import json


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, tests_check):
    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')

    if tests_check == "--no-tests":
        if len(installed_test_files) > 0:
            raise Exception("Test files aren't expected to be installed in %s"
                        ", found %s" % (INSTALLED_DIR, installed_test_files))
        print("----------- No test files were installed --------------")
    else:
        # 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():
            if (tests_check == "--no-tests" and
                    "tests" in numpy_pyi_files[pyi_file]):
                continue
            raise Exception("%s is not installed" % numpy_pyi_files[pyi_file])

    print("----------- All the necessary .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')
        }

    # ignore python files in vendored pythoncapi-compat submodule
    files = {
        k: v for k, v in files.items() if 'pythoncapi-compat' not in k
    }

    return files


if __name__ == '__main__':
    if len(sys.argv) < 2:
        raise ValueError("Incorrect number of input arguments, need "
                         "check_installation.py relpath/to/installed/numpy")

    install_dir = sys.argv[1]
    tests_check = ""
    if len(sys.argv) >= 3:
        tests_check = sys.argv[2]
    main(install_dir, tests_check)

    all_tags = set()

    with open(os.path.join('build', 'meson-info',
                           'intro-install_plan.json'), 'r') as f:
        targets = json.load(f)

    for key in targets.keys():
        for values in list(targets[key].values()):
            if values['tag'] not in all_tags:
                all_tags.add(values['tag'])

    if all_tags != set(['runtime', 'python-runtime', 'devel', 'tests']):
        raise AssertionError(f"Found unexpected install tag: {all_tags}")