typing: fully annotate mcompile, minit, and msetup

pull/7657/head
Daniel Mensinger 4 years ago
parent 6b1b995b32
commit c637b913c9
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 12
      mesonbuild/mcompile.py
  2. 12
      mesonbuild/minit.py
  3. 10
      mesonbuild/msetup.py
  4. 3
      run_mypy.py

@ -32,7 +32,7 @@ if T.TYPE_CHECKING:
import argparse import argparse
def array_arg(value: str) -> T.List[str]: def array_arg(value: str) -> T.List[str]:
return UserArrayOption(None, value, allow_dups=True, user_input=True).value return T.cast(T.List[str], UserArrayOption(None, value, allow_dups=True, user_input=True).value)
def validate_builddir(builddir: Path) -> None: def validate_builddir(builddir: Path) -> None:
if not (builddir / 'meson-private' / 'coredata.dat' ).is_file(): if not (builddir / 'meson-private' / 'coredata.dat' ).is_file():
@ -45,7 +45,7 @@ def get_backend_from_coredata(builddir: Path) -> str:
""" """
Gets `backend` option value from coredata Gets `backend` option value from coredata
""" """
return coredata.load(str(builddir)).get_builtin_option('backend') return T.cast(str, coredata.load(str(builddir)).get_builtin_option('backend'))
def parse_introspect_data(builddir: Path) -> T.Dict[str, T.List[dict]]: def parse_introspect_data(builddir: Path) -> T.Dict[str, T.List[dict]]:
""" """
@ -97,12 +97,12 @@ class ParsedTargetName:
} }
return type in allowed_types return type in allowed_types
def get_target_from_intro_data(target: ParsedTargetName, builddir: Path, introspect_data: dict) -> dict: def get_target_from_intro_data(target: ParsedTargetName, builddir: Path, introspect_data: T.Dict[str, T.Any]) -> T.Dict[str, T.Any]:
if target.name not in introspect_data: if target.name not in introspect_data:
raise MesonException('Can\'t invoke target `{}`: target not found'.format(target.full_name)) raise MesonException('Can\'t invoke target `{}`: target not found'.format(target.full_name))
intro_targets = introspect_data[target.name] intro_targets = introspect_data[target.name]
found_targets = [] found_targets = [] # type: T.List[T.Dict[str, T.Any]]
resolved_bdir = builddir.resolve() resolved_bdir = builddir.resolve()
@ -169,9 +169,9 @@ def generate_target_name_vs(target: ParsedTargetName, builddir: Path, introspect
# Normalize project name # Normalize project name
# Source: https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-build-specific-targets-in-solutions-by-using-msbuild-exe # Source: https://docs.microsoft.com/en-us/visualstudio/msbuild/how-to-build-specific-targets-in-solutions-by-using-msbuild-exe
target_name = re.sub('[\%\$\@\;\.\(\)\']', '_', intro_target['id']) target_name = re.sub('[\%\$\@\;\.\(\)\']', '_', intro_target['id']) # type: str
rel_path = Path(intro_target['filename'][0]).relative_to(builddir.resolve()).parent rel_path = Path(intro_target['filename'][0]).relative_to(builddir.resolve()).parent
if rel_path != '.': if rel_path != Path('.'):
target_name = str(rel_path / target_name) target_name = str(rel_path / target_name)
return target_name return target_name

@ -25,6 +25,10 @@ from glob import glob
from mesonbuild import mesonlib from mesonbuild import mesonlib
from mesonbuild.environment import detect_ninja from mesonbuild.environment import detect_ninja
from mesonbuild.templates.samplefactory import sameple_generator from mesonbuild.templates.samplefactory import sameple_generator
import typing as T
if T.TYPE_CHECKING:
import argparse
''' '''
we currently have one meson template at this time. we currently have one meson template at this time.
@ -49,7 +53,7 @@ meson compile -C builddir
''' '''
def create_sample(options) -> None: def create_sample(options: 'argparse.Namespace') -> None:
''' '''
Based on what arguments are passed we check for a match in language Based on what arguments are passed we check for a match in language
then check for project type and create new Meson samples project. then check for project type and create new Meson samples project.
@ -63,7 +67,7 @@ def create_sample(options) -> None:
raise RuntimeError('Unreachable code') raise RuntimeError('Unreachable code')
print(INFO_MESSAGE) print(INFO_MESSAGE)
def autodetect_options(options, sample: bool = False) -> None: def autodetect_options(options: 'argparse.Namespace', sample: bool = False) -> None:
''' '''
Here we autodetect options for args not passed in so don't have to Here we autodetect options for args not passed in so don't have to
think about it. think about it.
@ -129,7 +133,7 @@ def autodetect_options(options, sample: bool = False) -> None:
raise SystemExit("Can't autodetect language, please specify it with -l.") raise SystemExit("Can't autodetect language, please specify it with -l.")
print("Detected language: " + options.language) print("Detected language: " + options.language)
def add_arguments(parser): def add_arguments(parser: 'argparse.ArgumentParser') -> None:
''' '''
Here we add args for that the user can passed when making a new Here we add args for that the user can passed when making a new
Meson project. Meson project.
@ -146,7 +150,7 @@ def add_arguments(parser):
parser.add_argument('--type', default=DEFAULT_PROJECT, choices=('executable', 'library'), help="project type. default: {} based project".format(DEFAULT_PROJECT)) parser.add_argument('--type', default=DEFAULT_PROJECT, choices=('executable', 'library'), help="project type. default: {} based project".format(DEFAULT_PROJECT))
parser.add_argument('--version', default=DEFAULT_VERSION, help="project version. default: {}".format(DEFAULT_VERSION)) parser.add_argument('--version', default=DEFAULT_VERSION, help="project version. default: {}".format(DEFAULT_VERSION))
def run(options) -> int: def run(options: 'argparse.Namespace') -> int:
''' '''
Here we generate the new Meson sample project. Here we generate the new Meson sample project.
''' '''

@ -31,7 +31,7 @@ from . import mintro
from .mconf import make_lower_case from .mconf import make_lower_case
from .mesonlib import MesonException from .mesonlib import MesonException
def add_arguments(parser): def add_arguments(parser: argparse.ArgumentParser) -> None:
coredata.register_builtin_arguments(parser) coredata.register_builtin_arguments(parser)
parser.add_argument('--native-file', parser.add_argument('--native-file',
default=[], default=[],
@ -59,7 +59,7 @@ def add_arguments(parser):
parser.add_argument('sourcedir', nargs='?', default=None) parser.add_argument('sourcedir', nargs='?', default=None)
class MesonApp: class MesonApp:
def __init__(self, options): def __init__(self, options: argparse.Namespace) -> None:
(self.source_dir, self.build_dir) = self.validate_dirs(options.builddir, (self.source_dir, self.build_dir) = self.validate_dirs(options.builddir,
options.sourcedir, options.sourcedir,
options.reconfigure, options.reconfigure,
@ -150,7 +150,7 @@ class MesonApp:
raise SystemExit('Directory does not contain a valid build tree:\n{}'.format(build_dir)) raise SystemExit('Directory does not contain a valid build tree:\n{}'.format(build_dir))
return src_dir, build_dir return src_dir, build_dir
def generate(self): def generate(self) -> None:
env = environment.Environment(self.source_dir, self.build_dir, self.options) env = environment.Environment(self.source_dir, self.build_dir, self.options)
mlog.initialize(env.get_log_dir(), self.options.fatal_warnings) mlog.initialize(env.get_log_dir(), self.options.fatal_warnings)
if self.options.profile: if self.options.profile:
@ -158,7 +158,7 @@ class MesonApp:
with mesonlib.BuildDirLock(self.build_dir): with mesonlib.BuildDirLock(self.build_dir):
self._generate(env) self._generate(env)
def _generate(self, env): def _generate(self, env: environment.Environment) -> None:
mlog.debug('Build started at', datetime.datetime.now().isoformat()) mlog.debug('Build started at', datetime.datetime.now().isoformat())
mlog.debug('Main binary:', sys.executable) mlog.debug('Main binary:', sys.executable)
mlog.debug('Build Options:', coredata.get_cmd_line_options(self.build_dir, self.options)) mlog.debug('Build Options:', coredata.get_cmd_line_options(self.build_dir, self.options))
@ -239,7 +239,7 @@ class MesonApp:
os.unlink(cdf) os.unlink(cdf)
raise raise
def run(options) -> int: def run(options: argparse.Namespace) -> int:
coredata.parse_cmd_line_options(options) coredata.parse_cmd_line_options(options)
app = MesonApp(options) app = MesonApp(options)
app.generate() app.generate()

@ -32,7 +32,10 @@ normal_modules = [
strict_modules = [ strict_modules = [
'mesonbuild/interpreterbase.py', 'mesonbuild/interpreterbase.py',
'mesonbuild/minit.py',
'mesonbuild/mparser.py', 'mesonbuild/mparser.py',
'mesonbuild/msetup.py',
'mesonbuild/mcompile.py',
'mesonbuild/mesonlib.py', 'mesonbuild/mesonlib.py',
'mesonbuild/mlog.py', 'mesonbuild/mlog.py',
'mesonbuild/ast', 'mesonbuild/ast',

Loading…
Cancel
Save