Add some type annotations and fix lints

Some things, like `method[...](...)` or `x: ... = ...` python 3.5
doesn't support, so I made a comment instead with the intention that it
can someday be made into a real annotation.
pull/5254/head
John Ericson 6 years ago committed by Dylan Baker
parent a15a8b7e24
commit 4c2617a9c6
  1. 4
      mesonbuild/build.py
  2. 1
      mesonbuild/compilers/cpp.py
  3. 2
      mesonbuild/coredata.py
  4. 5
      mesonbuild/dependencies/base.py
  5. 4
      mesonbuild/envconfig.py
  6. 15
      mesonbuild/environment.py
  7. 8
      mesonbuild/mesonlib.py
  8. 2
      mesonbuild/mintro.py

@ -28,7 +28,7 @@ from .mesonlib import (
get_filenames_templates_dict, substitute_values,
for_windows, for_darwin, for_cygwin, for_android, has_path_sep
)
from .compilers import is_object, clink_langs, sort_clink, lang_suffixes, get_macos_dylib_install_name
from .compilers import Compiler, is_object, clink_langs, sort_clink, lang_suffixes, get_macos_dylib_install_name
from .interpreterbase import FeatureNew
pch_kwargs = set(['c_pch', 'cpp_pch'])
@ -450,7 +450,7 @@ class BuildTarget(Target):
self.is_unity = unity_opt == 'on' or (unity_opt == 'subprojects' and subproject != '')
self.environment = environment
self.sources = []
self.compilers = OrderedDict()
self.compilers = OrderedDict() # type: OrderedDict[str, Compiler]
self.objects = []
self.external_deps = []
self.include_dirs = []

@ -23,7 +23,6 @@ from .c import CCompiler, VisualStudioCCompiler, ClangClCCompiler, IntelClCCompi
from .compilers import (
gnu_winlibs,
msvc_winlibs,
CompilerType,
ClangCompiler,
GnuCompiler,
ElbrusCompiler,

@ -20,7 +20,7 @@ from pathlib import PurePath
from collections import OrderedDict
from .mesonlib import (
MesonException, MachineChoice, PerMachine,
default_libdir, default_libexecdir, default_prefix, stringlistify
default_libdir, default_libexecdir, default_prefix
)
from .wrap import WrapMode
import ast

@ -14,7 +14,6 @@
# This file contains the detection logic for external dependencies.
# Custom logic for several other packages are in separate files.
from typing import Dict, Any
import copy
import functools
import os
@ -26,7 +25,7 @@ import textwrap
import platform
import itertools
import ctypes
from typing import List, Tuple
from typing import Any, Dict, List, Tuple
from enum import Enum
from pathlib import Path, PurePath
@ -2302,7 +2301,7 @@ class ExtraFrameworkDependency(ExternalDependency):
return 'framework'
def get_dep_identifier(name, kwargs, want_cross):
def get_dep_identifier(name, kwargs, want_cross: bool) -> Tuple:
identifier = (name, want_cross)
for key, value in kwargs.items():
# 'version' is irrelevant for caching; the caller must check version matches

@ -255,7 +255,7 @@ class MachineInfo:
def libdir_layout_is_win(self) -> bool:
return self.is_windows() or self.is_cygwin()
class PerMachineDefaultable(PerMachine[_T]):
class PerMachineDefaultable(PerMachine[typing.Optional[_T]]):
"""Extends `PerMachine` with the ability to default from `None`s.
"""
def __init__(self) -> None:
@ -285,7 +285,7 @@ class PerMachineDefaultable(PerMachine[_T]):
if self.host == self.build:
self.host = None
class MachineInfos(PerMachineDefaultable[typing.Optional[MachineInfo]]):
class MachineInfos(PerMachineDefaultable[MachineInfo]):
def matches_build_machine(self, machine: MachineChoice) -> bool:
return self.build == self[machine]

@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import os, platform, re, sys, shlex, shutil, subprocess
import os, platform, re, sys, shlex, shutil, subprocess, typing
from . import coredata
from .linkers import ArLinker, ArmarLinker, VisualStudioLinker, DLinker, CcrxLinker
@ -28,6 +28,7 @@ from .envconfig import (
)
from . import compilers
from .compilers import (
Compiler,
CompilerType,
is_assembly,
is_header,
@ -83,6 +84,8 @@ from .compilers import (
build_filename = 'meson.build'
CompilersDict = typing.Dict[str, Compiler]
def detect_gcovr(min_version='3.3', new_rootdir_version='4.2', log=False):
gcovr_exe = 'gcovr'
try:
@ -150,7 +153,7 @@ def detect_native_windows_arch():
raise EnvironmentException('Unable to detect native OS architecture')
return arch
def detect_windows_arch(compilers):
def detect_windows_arch(compilers: CompilersDict) -> str:
"""
Detecting the 'native' architecture of Windows is not a trivial task. We
cannot trust that the architecture that Python is built for is the 'native'
@ -190,7 +193,7 @@ def detect_windows_arch(compilers):
return 'x86'
return os_arch
def any_compiler_has_define(compilers, define):
def any_compiler_has_define(compilers: CompilersDict, define):
for c in compilers.values():
try:
if c.has_builtin_define(define):
@ -200,7 +203,7 @@ def any_compiler_has_define(compilers, define):
pass
return False
def detect_cpu_family(compilers):
def detect_cpu_family(compilers: CompilersDict) -> str:
"""
Python is inconsistent in its platform module.
It returns different values for the same cpu.
@ -262,7 +265,7 @@ def detect_cpu_family(compilers):
return trial
def detect_cpu(compilers):
def detect_cpu(compilers: CompilersDict):
if mesonlib.is_windows():
trial = detect_windows_arch(compilers)
else:
@ -295,7 +298,7 @@ def detect_msys2_arch():
return os.environ['MSYSTEM_CARCH']
return None
def detect_machine_info(compilers = None) -> MachineInfo:
def detect_machine_info(compilers: typing.Optional[CompilersDict] = None) -> MachineInfo:
"""Detect the machine we're running on
If compilers are not provided, we cannot know as much. None out those

@ -323,22 +323,20 @@ class MachineChoice(OrderedEnum):
HOST = 1
TARGET = 2
_T = typing.TypeVar('_T')
class PerMachine(typing.Generic[_T]):
def __init__(self, build: typing.Optional[_T], host: typing.Optional[_T], target: typing.Optional[_T]):
def __init__(self, build: _T, host: _T, target: _T):
self.build = build
self.host = host
self.target = target
def __getitem__(self, machine: MachineChoice) -> typing.Optional[_T]:
def __getitem__(self, machine: MachineChoice) -> _T:
return {
MachineChoice.BUILD: self.build,
MachineChoice.HOST: self.host,
MachineChoice.TARGET: self.target
}[machine]
def __setitem__(self, machine: MachineChoice, val: typing.Optional[_T]) -> None:
def __setitem__(self, machine: MachineChoice, val: _T) -> None:
key = {
MachineChoice.BUILD: 'build',
MachineChoice.HOST: 'host',

@ -27,7 +27,7 @@ from . import mlog
from .backend import backends
from .mparser import FunctionNode, ArrayNode, ArgumentNode, StringNode
from typing import List, Optional
import sys, os
import os
import pathlib
def get_meson_info_file(info_dir: str):

Loading…
Cancel
Save