2020-08-29 00:01:41 +08:00
|
|
|
#!/usr/bin/env python3
|
2024-09-04 06:46:03 +08:00
|
|
|
# SPDX-License-Identifier: Apache-2.0
|
|
|
|
# Copyright © 2024 Intel Corporation
|
2020-08-29 00:01:41 +08:00
|
|
|
|
|
|
|
from pathlib import Path
|
2021-01-23 04:48:22 +08:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import sys
|
2020-08-29 00:01:41 +08:00
|
|
|
import typing as T
|
|
|
|
|
2021-06-11 22:58:27 +08:00
|
|
|
from mesonbuild.mesonlib import version_compare
|
|
|
|
|
2020-08-30 21:58:23 +08:00
|
|
|
modules = [
|
2020-09-27 17:15:57 +08:00
|
|
|
# fully typed submodules
|
2022-10-23 11:39:50 +08:00
|
|
|
# 'mesonbuild/ast/',
|
2022-02-25 05:26:51 +08:00
|
|
|
'mesonbuild/cargo/',
|
2022-10-23 11:39:50 +08:00
|
|
|
'mesonbuild/cmake/',
|
|
|
|
'mesonbuild/compilers/',
|
|
|
|
'mesonbuild/dependencies/',
|
|
|
|
'mesonbuild/interpreter/primitives/',
|
|
|
|
'mesonbuild/interpreterbase/',
|
|
|
|
'mesonbuild/linkers/',
|
|
|
|
'mesonbuild/scripts/',
|
2023-07-01 01:40:11 +08:00
|
|
|
'mesonbuild/templates/',
|
2022-10-23 11:39:50 +08:00
|
|
|
'mesonbuild/wrap/',
|
2020-08-30 21:58:23 +08:00
|
|
|
|
2020-09-27 17:15:57 +08:00
|
|
|
# specific files
|
2023-12-14 05:35:37 +08:00
|
|
|
'mesonbuild/ast/introspection.py',
|
2023-12-14 05:20:00 +08:00
|
|
|
'mesonbuild/ast/printer.py',
|
2023-12-14 05:21:02 +08:00
|
|
|
'mesonbuild/ast/postprocess.py',
|
|
|
|
'mesonbuild/ast/visitor.py',
|
2020-09-27 17:15:57 +08:00
|
|
|
'mesonbuild/arglist.py',
|
2021-08-11 02:24:25 +08:00
|
|
|
'mesonbuild/backend/backends.py',
|
2023-12-11 10:48:54 +08:00
|
|
|
'mesonbuild/backend/nonebackend.py',
|
2020-09-27 17:15:57 +08:00
|
|
|
# 'mesonbuild/coredata.py',
|
2022-01-11 02:31:08 +08:00
|
|
|
'mesonbuild/depfile.py',
|
2020-09-27 17:15:57 +08:00
|
|
|
'mesonbuild/envconfig.py',
|
2024-10-02 01:41:59 +08:00
|
|
|
'mesonbuild/environment.py',
|
2021-07-27 06:55:49 +08:00
|
|
|
'mesonbuild/interpreter/compiler.py',
|
2021-07-28 06:29:30 +08:00
|
|
|
'mesonbuild/interpreter/mesonmain.py',
|
2021-06-17 06:27:39 +08:00
|
|
|
'mesonbuild/interpreter/interpreterobjects.py',
|
2021-08-05 04:23:49 +08:00
|
|
|
'mesonbuild/interpreter/type_checking.py',
|
2024-09-04 06:46:03 +08:00
|
|
|
'mesonbuild/machinefile.py',
|
2020-09-27 17:15:57 +08:00
|
|
|
'mesonbuild/mcompile.py',
|
2021-02-21 01:04:01 +08:00
|
|
|
'mesonbuild/mdevenv.py',
|
2022-10-06 17:12:30 +08:00
|
|
|
'mesonbuild/utils/core.py',
|
2022-09-13 21:38:19 +08:00
|
|
|
'mesonbuild/utils/platform.py',
|
|
|
|
'mesonbuild/utils/universal.py',
|
2024-01-03 06:19:19 +08:00
|
|
|
'mesonbuild/utils/vsenv.py',
|
2023-06-22 08:04:01 +08:00
|
|
|
'mesonbuild/mconf.py',
|
2023-06-21 14:10:12 +08:00
|
|
|
'mesonbuild/mdist.py',
|
2023-09-15 22:19:02 +08:00
|
|
|
'mesonbuild/mformat.py',
|
2020-09-27 17:15:57 +08:00
|
|
|
'mesonbuild/minit.py',
|
2021-01-13 04:49:58 +08:00
|
|
|
'mesonbuild/minstall.py',
|
2020-09-27 17:15:57 +08:00
|
|
|
'mesonbuild/mintro.py',
|
|
|
|
'mesonbuild/mlog.py',
|
2021-08-27 02:20:51 +08:00
|
|
|
'mesonbuild/msubprojects.py',
|
2023-01-07 03:23:55 +08:00
|
|
|
'mesonbuild/modules/__init__.py',
|
2025-04-02 01:09:03 +08:00
|
|
|
'mesonbuild/modules/cmake.py',
|
2023-10-16 09:26:58 +08:00
|
|
|
'mesonbuild/modules/cuda.py',
|
2022-07-15 04:12:25 +08:00
|
|
|
'mesonbuild/modules/external_project.py',
|
2020-09-27 17:15:57 +08:00
|
|
|
'mesonbuild/modules/fs.py',
|
2021-12-07 05:13:59 +08:00
|
|
|
'mesonbuild/modules/gnome.py',
|
2021-10-01 00:20:18 +08:00
|
|
|
'mesonbuild/modules/i18n.py',
|
2022-07-15 04:12:25 +08:00
|
|
|
'mesonbuild/modules/icestorm.py',
|
2021-06-19 14:50:15 +08:00
|
|
|
'mesonbuild/modules/java.py',
|
2021-11-24 05:20:40 +08:00
|
|
|
'mesonbuild/modules/keyval.py',
|
2022-03-09 07:10:46 +08:00
|
|
|
'mesonbuild/modules/modtest.py',
|
2022-03-11 02:33:54 +08:00
|
|
|
'mesonbuild/modules/pkgconfig.py',
|
2024-04-10 00:50:13 +08:00
|
|
|
'mesonbuild/modules/_qt.py',
|
2023-01-07 03:39:54 +08:00
|
|
|
'mesonbuild/modules/qt4.py',
|
|
|
|
'mesonbuild/modules/qt5.py',
|
|
|
|
'mesonbuild/modules/qt6.py',
|
2022-07-15 04:12:25 +08:00
|
|
|
'mesonbuild/modules/rust.py',
|
2023-08-18 06:24:03 +08:00
|
|
|
'mesonbuild/modules/simd.py',
|
2021-12-21 04:02:00 +08:00
|
|
|
'mesonbuild/modules/sourceset.py',
|
2022-07-15 04:12:25 +08:00
|
|
|
'mesonbuild/modules/wayland.py',
|
2021-10-09 05:31:25 +08:00
|
|
|
'mesonbuild/modules/windows.py',
|
2020-09-27 17:15:57 +08:00
|
|
|
'mesonbuild/mparser.py',
|
|
|
|
'mesonbuild/msetup.py',
|
|
|
|
'mesonbuild/mtest.py',
|
2020-11-21 03:34:28 +08:00
|
|
|
'mesonbuild/optinterpreter.py',
|
2024-08-31 02:12:57 +08:00
|
|
|
'mesonbuild/options.py',
|
2020-10-02 04:25:16 +08:00
|
|
|
'mesonbuild/programs.py',
|
2023-11-26 15:17:50 +08:00
|
|
|
]
|
|
|
|
additional = [
|
2020-09-27 17:15:57 +08:00
|
|
|
'run_mypy.py',
|
2021-06-08 18:48:33 +08:00
|
|
|
'run_project_tests.py',
|
2021-02-20 04:19:27 +08:00
|
|
|
'run_single_test.py',
|
2021-06-26 01:48:43 +08:00
|
|
|
'tools',
|
|
|
|
'docs/genrefman.py',
|
|
|
|
'docs/refman',
|
2024-07-10 05:21:37 +08:00
|
|
|
'unittests/helpers.py',
|
2020-08-29 00:01:41 +08:00
|
|
|
]
|
|
|
|
|
2021-01-23 04:48:22 +08:00
|
|
|
if os.name == 'posix':
|
2022-09-13 21:38:19 +08:00
|
|
|
modules.append('mesonbuild/utils/posix.py')
|
2021-01-23 04:48:22 +08:00
|
|
|
elif os.name == 'nt':
|
2022-09-13 21:38:19 +08:00
|
|
|
modules.append('mesonbuild/utils/win32.py')
|
2021-01-23 04:48:22 +08:00
|
|
|
|
2020-08-29 00:01:41 +08:00
|
|
|
def check_mypy() -> None:
|
2020-09-27 17:15:57 +08:00
|
|
|
try:
|
|
|
|
import mypy
|
|
|
|
except ImportError:
|
|
|
|
print('Failed import mypy')
|
|
|
|
sys.exit(1)
|
2021-06-11 22:58:27 +08:00
|
|
|
from mypy.version import __version__ as mypy_version
|
2021-06-14 12:24:45 +08:00
|
|
|
if not version_compare(mypy_version, '>=0.812'):
|
|
|
|
print('mypy >=0.812 is required, older versions report spurious errors')
|
2021-06-11 22:58:27 +08:00
|
|
|
sys.exit(1)
|
2020-08-29 00:01:41 +08:00
|
|
|
|
|
|
|
def main() -> int:
|
2020-09-27 17:15:57 +08:00
|
|
|
root = Path(__file__).absolute().parent
|
2020-08-30 21:58:23 +08:00
|
|
|
|
2020-09-27 17:15:57 +08:00
|
|
|
parser = argparse.ArgumentParser(description='Process some integers.')
|
2022-10-23 11:39:50 +08:00
|
|
|
parser.add_argument('files', nargs='*')
|
2023-03-03 04:46:38 +08:00
|
|
|
parser.add_argument('--mypy', help='path to mypy executable')
|
2022-10-23 11:39:50 +08:00
|
|
|
parser.add_argument('-q', '--quiet', action='store_true', help='do not print informational messages')
|
2020-09-27 17:15:57 +08:00
|
|
|
parser.add_argument('-p', '--pretty', action='store_true', help='pretty print mypy errors')
|
2020-09-27 17:21:36 +08:00
|
|
|
parser.add_argument('-C', '--clear', action='store_true', help='clear the terminal before running mypy')
|
2023-08-17 01:03:44 +08:00
|
|
|
parser.add_argument('--allver', action='store_true', help='Check all supported versions of python')
|
2020-08-29 01:29:20 +08:00
|
|
|
|
2023-02-09 04:21:05 +08:00
|
|
|
opts, args = parser.parse_known_args()
|
2025-04-19 07:17:59 +08:00
|
|
|
if not opts.mypy:
|
|
|
|
check_mypy()
|
|
|
|
|
2020-09-27 17:15:57 +08:00
|
|
|
if opts.pretty:
|
|
|
|
args.append('--pretty')
|
2020-08-29 01:29:20 +08:00
|
|
|
|
2020-09-27 17:21:36 +08:00
|
|
|
if opts.clear:
|
|
|
|
print('\x1bc', end='', flush=True)
|
|
|
|
|
2022-10-23 11:39:50 +08:00
|
|
|
to_check = [] # type: T.List[str]
|
2023-11-26 15:17:50 +08:00
|
|
|
additional_to_check = [] # type: T.List[str]
|
2022-10-23 11:39:50 +08:00
|
|
|
if opts.files:
|
|
|
|
for f in opts.files:
|
|
|
|
if f in modules:
|
|
|
|
to_check.append(f)
|
|
|
|
elif any(f.startswith(i) for i in modules):
|
|
|
|
to_check.append(f)
|
2023-11-26 15:17:50 +08:00
|
|
|
elif f in additional:
|
|
|
|
additional_to_check.append(f)
|
|
|
|
elif any(f.startswith(i) for i in additional):
|
|
|
|
additional_to_check.append(f)
|
2022-10-23 11:39:50 +08:00
|
|
|
else:
|
|
|
|
if not opts.quiet:
|
|
|
|
print(f'skipping {f!r} because it is not yet typed')
|
|
|
|
else:
|
|
|
|
to_check.extend(modules)
|
2023-11-26 15:17:50 +08:00
|
|
|
additional_to_check.extend(additional)
|
2022-10-23 11:39:50 +08:00
|
|
|
|
|
|
|
if to_check:
|
2023-03-03 04:46:38 +08:00
|
|
|
command = [opts.mypy] if opts.mypy else [sys.executable, '-m', 'mypy']
|
2022-10-23 11:39:50 +08:00
|
|
|
if not opts.quiet:
|
|
|
|
print('Running mypy (this can take some time) ...')
|
2023-11-26 15:17:50 +08:00
|
|
|
retcode = subprocess.run(command + args + to_check + additional_to_check, cwd=root).returncode
|
2023-08-17 01:03:44 +08:00
|
|
|
if opts.allver and retcode == 0:
|
|
|
|
for minor in range(7, sys.version_info[1]):
|
|
|
|
if not opts.quiet:
|
|
|
|
print(f'Checking mypy with python version: 3.{minor}')
|
|
|
|
p = subprocess.run(command + args + to_check + [f'--python-version=3.{minor}'], cwd=root)
|
|
|
|
if p.returncode != 0:
|
|
|
|
retcode = p.returncode
|
|
|
|
return retcode
|
2022-10-23 11:39:50 +08:00
|
|
|
else:
|
|
|
|
if not opts.quiet:
|
|
|
|
print('nothing to do...')
|
|
|
|
return 0
|
2020-08-29 00:01:41 +08:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-09-27 17:15:57 +08:00
|
|
|
sys.exit(main())
|