Skip to content

Commit 6ec0b53

Browse files
committed
external-project: Add typing annotation
1 parent 9d33820 commit 6ec0b53

File tree

2 files changed

+25
-11
lines changed

2 files changed

+25
-11
lines changed

mesonbuild/modules/unstable_external_project.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,33 @@
1414

1515
import os, subprocess, shlex
1616
from pathlib import Path
17+
import typing as T
1718

1819
from . import ExtensionModule, ModuleReturnValue
1920
from .. import mlog, build
2021
from ..mesonlib import (MesonException, Popen_safe, MachineChoice,
2122
get_variable_regex, do_replacement)
2223
from ..interpreterbase import InterpreterObject, InterpreterException, FeatureNew
2324
from ..interpreterbase import stringArgs, permittedKwargs
24-
from ..interpreter import DependencyHolder, InstallDir
25+
from ..interpreter import Interpreter, DependencyHolder, InstallDir
2526
from ..compilers.compilers import cflags_mapping, cexe_mapping
2627
from ..dependencies.base import InternalDependency, PkgConfigDependency
28+
from ..environment import Environment
2729

2830
class ExternalProject(InterpreterObject):
29-
def __init__(self, interpreter, subdir, project_version, subproject, environment, build_machine, host_machine,
30-
configure_command, configure_options, cross_configure_options, env, verbose):
31+
def __init__(self,
32+
interpreter: Interpreter,
33+
subdir: str,
34+
project_version: T.Dict[str, str],
35+
subproject: str,
36+
environment: Environment,
37+
build_machine: str,
38+
host_machine: str,
39+
configure_command: T.List[str],
40+
configure_options: T.List[str],
41+
cross_configure_options: T.List[str],
42+
env: build.EnvironmentVariables,
43+
verbose: bool):
3144
InterpreterObject.__init__(self)
3245
self.methods.update({'dependency': self.dependency_method,
3346
})
@@ -116,10 +129,10 @@ def _configure(self):
116129
self.build_dir.mkdir(parents=True, exist_ok=True)
117130
self._run('configure', configure_cmd)
118131

119-
def _quote_and_join(self, array):
132+
def _quote_and_join(self, array: T.List[str]) -> str:
120133
return ' '.join([shlex.quote(i) for i in array])
121134

122-
def _validate_configure_options(self, required_keys):
135+
def _validate_configure_options(self, required_keys: T.List[str]):
123136
# Ensure the user at least try to pass basic info to the build system,
124137
# like the prefix, libdir, etc.
125138
for key in required_keys:
@@ -131,7 +144,7 @@ def _validate_configure_options(self, required_keys):
131144
m = 'At least one configure option must contain "{}" key'
132145
raise InterpreterException(m.format(key_format))
133146

134-
def _format_options(self, options, variables):
147+
def _format_options(self, options: T.List[str], variables: T.Dict[str, str]) -> T.List[str]:
135148
out = []
136149
missing = set()
137150
regex = get_variable_regex('meson')
@@ -146,7 +159,7 @@ def _format_options(self, options, variables):
146159
"Variables {} in configure options are missing.".format(var_list))
147160
return out
148161

149-
def _run(self, step, command):
162+
def _run(self, step: str, command: T.List[str]):
150163
mlog.log('External project {}:'.format(self.name), mlog.bold(step))
151164
output = None if self.verbose else subprocess.DEVNULL
152165
p, o, e = Popen_safe(command, cwd=str(self.build_dir), env=self.run_env,

mesonbuild/scripts/externalproject.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,12 @@
1717
import multiprocessing
1818
import subprocess
1919
from pathlib import Path
20+
import typing as T
2021

2122
from ..mesonlib import Popen_safe
2223

2324
class ExternalProject:
24-
def __init__(self, options):
25+
def __init__(self, options: argparse.Namespace):
2526
self.name = options.name
2627
self.src_dir = options.srcdir
2728
self.build_dir = options.builddir
@@ -46,13 +47,13 @@ def write_stampfile(self):
4647
with open(self.stampfile, 'w') as f:
4748
pass
4849

49-
def gnu_make(self):
50+
def gnu_make(self) -> bool:
5051
p, o, e = Popen_safe([self.make, '--version'])
5152
if p.returncode == 0 and 'GNU Make' in o:
5253
return True
5354
return False
5455

55-
def build(self):
56+
def build(self) -> int:
5657
make_cmd = [self.make]
5758
if not self.verbose:
5859
make_cmd.append('--quiet')
@@ -73,7 +74,7 @@ def build(self):
7374

7475
return 0
7576

76-
def _run(self, command):
77+
def _run(self, command: T.List[str]) -> int:
7778
output = None if self.verbose else subprocess.DEVNULL
7879
p, o, e = Popen_safe(command, stderr=subprocess.STDOUT, stdout=output,
7980
cwd=self.build_dir)

0 commit comments

Comments
 (0)