diff options
author | Daniel Mensinger <daniel@mensinger-ka.de> | 2020-01-06 15:27:38 +0100 |
---|---|---|
committer | Daniel Mensinger <daniel@mensinger-ka.de> | 2020-01-08 15:28:17 +0100 |
commit | 09b53c534f74806ebc49bb2fcdfbae0e3b26fb84 (patch) | |
tree | 4466a6005333d6d1ae7d67cbaf24fb63e104df6a /mesonbuild/mintro.py | |
parent | f3199edaf8802e2a59fed2f83e825e09b9d4bd0d (diff) | |
download | meson-09b53c534f74806ebc49bb2fcdfbae0e3b26fb84.zip meson-09b53c534f74806ebc49bb2fcdfbae0e3b26fb84.tar.gz meson-09b53c534f74806ebc49bb2fcdfbae0e3b26fb84.tar.bz2 |
types: import typing as T (fixes #6333)
Diffstat (limited to 'mesonbuild/mintro.py')
-rw-r--r-- | mesonbuild/mintro.py | 88 |
1 files changed, 44 insertions, 44 deletions
diff --git a/mesonbuild/mintro.py b/mesonbuild/mintro.py index ff9f1d9..ba5901b 100644 --- a/mesonbuild/mintro.py +++ b/mesonbuild/mintro.py @@ -26,7 +26,7 @@ from .ast import IntrospectionInterpreter, build_target_functions, AstConditionL from . import mlog from .backend import backends from .mparser import FunctionNode, ArrayNode, ArgumentNode, StringNode -from typing import Any, Callable, Dict, List, Optional, Sequence, Tuple, Union +import typing as T import os import pathlib @@ -36,22 +36,22 @@ def get_meson_info_file(info_dir: str) -> str: def get_meson_introspection_version() -> str: return '1.0.0' -def get_meson_introspection_required_version() -> List[str]: +def get_meson_introspection_required_version() -> T.List[str]: return ['>=1.0', '<2.0'] class IntroCommand: def __init__(self, desc: str, - func: Optional[Callable[[], Union[dict, list]]] = None, - no_bd: Optional[Callable[[IntrospectionInterpreter], Union[dict, list]]] = None) -> None: + func: T.Optional[T.Callable[[], T.Union[dict, list]]] = None, + no_bd: T.Optional[T.Callable[[IntrospectionInterpreter], T.Union[dict, list]]] = None) -> None: self.desc = desc + '.' self.func = func self.no_bd = no_bd -def get_meson_introspection_types(coredata: Optional[cdata.CoreData] = None, - builddata: Optional[build.Build] = None, - backend: Optional[backends.Backend] = None, - sourcedir: Optional[str] = None) -> Dict[str, IntroCommand]: +def get_meson_introspection_types(coredata: T.Optional[cdata.CoreData] = None, + builddata: T.Optional[build.Build] = None, + backend: T.Optional[backends.Backend] = None, + sourcedir: T.Optional[str] = None) -> T.Dict[str, IntroCommand]: if backend and builddata: benchmarkdata = backend.create_test_serialisation(builddata.get_benchmarks()) testdata = backend.create_test_serialisation(builddata.get_tests()) @@ -60,15 +60,15 @@ def get_meson_introspection_types(coredata: Optional[cdata.CoreData] = None, benchmarkdata = testdata = installdata = None return { - 'benchmarks': IntroCommand('List all benchmarks', func=lambda: list_benchmarks(benchmarkdata)), - 'buildoptions': IntroCommand('List all build options', func=lambda: list_buildoptions(coredata), no_bd=list_buildoptions_from_source), - 'buildsystem_files': IntroCommand('List files that make up the build system', func=lambda: list_buildsystem_files(builddata)), - 'dependencies': IntroCommand('List external dependencies', func=lambda: list_deps(coredata), no_bd=list_deps_from_source), + 'benchmarks': IntroCommand('T.List all benchmarks', func=lambda: list_benchmarks(benchmarkdata)), + 'buildoptions': IntroCommand('T.List all build options', func=lambda: list_buildoptions(coredata), no_bd=list_buildoptions_from_source), + 'buildsystem_files': IntroCommand('T.List files that make up the build system', func=lambda: list_buildsystem_files(builddata)), + 'dependencies': IntroCommand('T.List external dependencies', func=lambda: list_deps(coredata), no_bd=list_deps_from_source), 'scan_dependencies': IntroCommand('Scan for dependencies used in the meson.build file', no_bd=list_deps_from_source), - 'installed': IntroCommand('List all installed files and directories', func=lambda: list_installed(installdata)), + 'installed': IntroCommand('T.List all installed files and directories', func=lambda: list_installed(installdata)), 'projectinfo': IntroCommand('Information about projects', func=lambda: list_projinfo(builddata), no_bd=list_projinfo_from_source), - 'targets': IntroCommand('List top level targets', func=lambda: list_targets(builddata, installdata, backend), no_bd=list_targets_from_source), - 'tests': IntroCommand('List all unit tests', func=lambda: list_tests(testdata)), + 'targets': IntroCommand('T.List top level targets', func=lambda: list_targets(builddata, installdata, backend), no_bd=list_targets_from_source), + 'tests': IntroCommand('T.List all unit tests', func=lambda: list_tests(testdata)), } def add_arguments(parser): @@ -103,12 +103,12 @@ def list_installed(installdata): res[path] = os.path.join(installdata.prefix, installpath) return res -def list_targets_from_source(intr: IntrospectionInterpreter) -> List[Dict[str, Union[bool, str, List[Union[str, Dict[str, Union[str, List[str], bool]]]]]]]: - tlist = [] # type: List[Dict[str, Union[bool, str, List[Union[str, Dict[str, Union[str, List[str], bool]]]]]]] +def list_targets_from_source(intr: IntrospectionInterpreter) -> T.List[T.Dict[str, T.Union[bool, str, T.List[T.Union[str, T.Dict[str, T.Union[str, T.List[str], bool]]]]]]]: + tlist = [] # type: T.List[T.Dict[str, T.Union[bool, str, T.List[T.Union[str, T.Dict[str, T.Union[str, T.List[str], bool]]]]]]] for i in intr.targets: - sources = [] # type: List[str] + sources = [] # type: T.List[str] for n in i['sources']: - args = [] # type: List[Union[str, StringNode]] + args = [] # type: T.List[T.Union[str, StringNode]] if isinstance(n, FunctionNode): args = list(n.args.arguments) if n.func_name in build_target_functions: @@ -143,8 +143,8 @@ def list_targets_from_source(intr: IntrospectionInterpreter) -> List[Dict[str, U return tlist -def list_targets(builddata: build.Build, installdata, backend: backends.Backend) -> List[Dict[str, Union[bool, str, List[Union[str, Dict[str, Union[str, List[str], bool]]]]]]]: - tlist = [] # type: List[Dict[str, Union[bool, str, List[Union[str, Dict[str, Union[str, List[str], bool]]]]]]] +def list_targets(builddata: build.Build, installdata, backend: backends.Backend) -> T.List[T.Dict[str, T.Union[bool, str, T.List[T.Union[str, T.Dict[str, T.Union[str, T.List[str], bool]]]]]]]: + tlist = [] # type: T.List[T.Dict[str, T.Union[bool, str, T.List[T.Union[str, T.Dict[str, T.Union[str, T.List[str], bool]]]]]]] build_dir = builddata.environment.get_build_dir() src_dir = builddata.environment.get_source_dir() @@ -177,11 +177,11 @@ def list_targets(builddata: build.Build, installdata, backend: backends.Backend) tlist.append(t) return tlist -def list_buildoptions_from_source(intr: IntrospectionInterpreter) -> List[Dict[str, Union[str, bool, int, List[str]]]]: +def list_buildoptions_from_source(intr: IntrospectionInterpreter) -> T.List[T.Dict[str, T.Union[str, bool, int, T.List[str]]]]: return list_buildoptions(intr.coredata) -def list_buildoptions(coredata: cdata.CoreData) -> List[Dict[str, Union[str, bool, int, List[str]]]]: - optlist = [] # type: List[Dict[str, Union[str, bool, int, List[str]]]] +def list_buildoptions(coredata: cdata.CoreData) -> T.List[T.Dict[str, T.Union[str, bool, int, T.List[str]]]]: + optlist = [] # type: T.List[T.Dict[str, T.Union[str, bool, int, T.List[str]]]] dir_option_names = ['bindir', 'datadir', @@ -204,7 +204,7 @@ def list_buildoptions(coredata: cdata.CoreData) -> List[Dict[str, Union[str, boo test_options = {k: o for k, o in coredata.builtins.items() if k in test_option_names} core_options = {k: o for k, o in coredata.builtins.items() if k in core_option_names} - def add_keys(options: Dict[str, cdata.UserOption], section: str, machine: str = 'any') -> None: + def add_keys(options: T.Dict[str, cdata.UserOption], section: str, machine: str = 'any') -> None: for key in sorted(options.keys()): opt = options[key] optdict = {'name': key, 'value': opt.value, 'section': section, 'machine': machine} @@ -245,23 +245,23 @@ def list_buildoptions(coredata: cdata.CoreData) -> List[Dict[str, Union[str, boo add_keys(test_options, 'test') return optlist -def find_buildsystem_files_list(src_dir) -> List[str]: +def find_buildsystem_files_list(src_dir) -> T.List[str]: # I feel dirty about this. But only slightly. - filelist = [] # type: List[str] + filelist = [] # type: T.List[str] for root, _, files in os.walk(src_dir): for f in files: if f == 'meson.build' or f == 'meson_options.txt': filelist.append(os.path.relpath(os.path.join(root, f), src_dir)) return filelist -def list_buildsystem_files(builddata: build.Build) -> List[str]: +def list_buildsystem_files(builddata: build.Build) -> T.List[str]: src_dir = builddata.environment.get_source_dir() filelist = find_buildsystem_files_list(src_dir) filelist = [os.path.join(src_dir, x) for x in filelist] return filelist -def list_deps_from_source(intr: IntrospectionInterpreter) -> List[Dict[str, Union[str, bool]]]: - result = [] # type: List[Dict[str, Union[str, bool]]] +def list_deps_from_source(intr: IntrospectionInterpreter) -> T.List[T.Dict[str, T.Union[str, bool]]]: + result = [] # type: T.List[T.Dict[str, T.Union[str, bool]]] for i in intr.dependencies: keys = [ 'name', @@ -273,8 +273,8 @@ def list_deps_from_source(intr: IntrospectionInterpreter) -> List[Dict[str, Unio result += [{k: v for k, v in i.items() if k in keys}] return result -def list_deps(coredata: cdata.CoreData) -> List[Dict[str, Union[str, List[str]]]]: - result = [] # type: List[Dict[str, Union[str, List[str]]]] +def list_deps(coredata: cdata.CoreData) -> T.List[T.Dict[str, T.Union[str, T.List[str]]]]: + result = [] # type: T.List[T.Dict[str, T.Union[str, T.List[str]]]] for d in coredata.deps.host.values(): if d.found(): result += [{'name': d.name, @@ -283,8 +283,8 @@ def list_deps(coredata: cdata.CoreData) -> List[Dict[str, Union[str, List[str]]] 'link_args': d.get_link_args()}] return result -def get_test_list(testdata) -> List[Dict[str, Union[str, int, List[str], Dict[str, str]]]]: - result = [] # type: List[Dict[str, Union[str, int, List[str], Dict[str, str]]]] +def get_test_list(testdata) -> T.List[T.Dict[str, T.Union[str, int, T.List[str], T.Dict[str, str]]]]: + result = [] # type: T.List[T.Dict[str, T.Union[str, int, T.List[str], T.Dict[str, str]]]] for t in testdata: to = {} if isinstance(t.fname, str): @@ -306,13 +306,13 @@ def get_test_list(testdata) -> List[Dict[str, Union[str, int, List[str], Dict[st result.append(to) return result -def list_tests(testdata) -> List[Dict[str, Union[str, int, List[str], Dict[str, str]]]]: +def list_tests(testdata) -> T.List[T.Dict[str, T.Union[str, int, T.List[str], T.Dict[str, str]]]]: return get_test_list(testdata) -def list_benchmarks(benchdata) -> List[Dict[str, Union[str, int, List[str], Dict[str, str]]]]: +def list_benchmarks(benchdata) -> T.List[T.Dict[str, T.Union[str, int, T.List[str], T.Dict[str, str]]]]: return get_test_list(benchdata) -def list_projinfo(builddata: build.Build) -> Dict[str, Union[str, List[Dict[str, str]]]]: +def list_projinfo(builddata: build.Build) -> T.Dict[str, T.Union[str, T.List[T.Dict[str, str]]]]: result = {'version': builddata.project_version, 'descriptive_name': builddata.project_name, 'subproject_dir': builddata.subproject_dir} @@ -325,7 +325,7 @@ def list_projinfo(builddata: build.Build) -> Dict[str, Union[str, List[Dict[str, result['subprojects'] = subprojects return result -def list_projinfo_from_source(intr: IntrospectionInterpreter) -> Dict[str, Union[str, List[Dict[str, str]]]]: +def list_projinfo_from_source(intr: IntrospectionInterpreter) -> T.Dict[str, T.Union[str, T.List[T.Dict[str, str]]]]: sourcedir = intr.source_root files = find_buildsystem_files_list(sourcedir) files = [os.path.normpath(x) for x in files] @@ -339,7 +339,7 @@ def list_projinfo_from_source(intr: IntrospectionInterpreter) -> Dict[str, Union intr.project_data['subproject_dir'] = intr.subproject_dir return intr.project_data -def print_results(options, results: Sequence[Tuple[str, Union[dict, List[Any]]]], indent: int) -> int: +def print_results(options, results: T.Sequence[T.Tuple[str, T.Union[dict, T.List[T.Any]]]], indent: int) -> int: if not results and not options.force_dict: print('No command specified') return 1 @@ -360,7 +360,7 @@ def run(options) -> int: datadir = os.path.join(options.builddir, datadir) infodir = os.path.join(options.builddir, infodir) indent = 4 if options.indent else None - results = [] # type: List[Tuple[str, Union[dict, List[Any]]]] + results = [] # type: T.List[T.Tuple[str, T.Union[dict, T.List[T.Any]]]] sourcedir = '.' if options.builddir == 'meson.build' else options.builddir[:-11] intro_types = get_meson_introspection_types(sourcedir=sourcedir) @@ -413,9 +413,9 @@ def run(options) -> int: return print_results(options, results, indent) -updated_introspection_files = [] # type: List[str] +updated_introspection_files = [] # type: T.List[str] -def write_intro_info(intro_info: Sequence[Tuple[str, Union[dict, List[Any]]]], info_dir: str) -> None: +def write_intro_info(intro_info: T.Sequence[T.Tuple[str, T.Union[dict, T.List[T.Any]]]], info_dir: str) -> None: global updated_introspection_files for i in intro_info: out_file = os.path.join(info_dir, 'intro-{}.json'.format(i[0])) @@ -429,7 +429,7 @@ def write_intro_info(intro_info: Sequence[Tuple[str, Union[dict, List[Any]]]], i def generate_introspection_file(builddata: build.Build, backend: backends.Backend) -> None: coredata = builddata.environment.get_coredata() intro_types = get_meson_introspection_types(coredata=coredata, builddata=builddata, backend=backend) - intro_info = [] # type: List[Tuple[str, Union[dict, List[Any]]]] + intro_info = [] # type: T.List[T.Tuple[str, T.Union[dict, T.List[T.Any]]]] for key, val in intro_types.items(): if not val.func: @@ -445,7 +445,7 @@ def update_build_options(coredata: cdata.CoreData, info_dir) -> None: write_intro_info(intro_info, info_dir) -def split_version_string(version: str) -> Dict[str, Union[str, int]]: +def split_version_string(version: str) -> T.Dict[str, T.Union[str, int]]: vers_list = version.split('.') return { 'full': version, |