typing: fully annotate cmake.fileapi

pull/7794/head
Daniel Mensinger 4 years ago
parent d9419a4f2a
commit a1b2f15092
No known key found for this signature in database
GPG Key ID: 54DD94C131E277D4
  1. 24
      mesonbuild/cmake/fileapi.py

@ -27,8 +27,8 @@ class CMakeFileAPI:
self.api_base_dir = os.path.join(self.build_dir, '.cmake', 'api', 'v1')
self.request_dir = os.path.join(self.api_base_dir, 'query', 'client-meson')
self.reply_dir = os.path.join(self.api_base_dir, 'reply')
self.cmake_sources = []
self.cmake_configurations = []
self.cmake_sources = [] # type: T.List[CMakeBuildFile]
self.cmake_configurations = [] # type: T.List[CMakeConfiguration]
self.kind_resolver_map = {
'codemodel': self._parse_codemodel,
'cmakeFiles': self._parse_cmakeFiles,
@ -87,7 +87,7 @@ class CMakeFileAPI:
self.kind_resolver_map[i['kind']](i)
def _parse_codemodel(self, data: dict) -> None:
def _parse_codemodel(self, data: T.Dict[str, T.Any]) -> None:
assert('configurations' in data)
assert('paths' in data)
@ -100,7 +100,7 @@ class CMakeFileAPI:
# resolved and the resulting data structure is identical
# to the CMake serve output.
def helper_parse_dir(dir_entry: dict) -> T.Tuple[str, str]:
def helper_parse_dir(dir_entry: T.Dict[str, T.Any]) -> T.Tuple[str, str]:
src_dir = dir_entry.get('source', '.')
bld_dir = dir_entry.get('build', '.')
src_dir = src_dir if os.path.isabs(src_dir) else os.path.join(source_dir, src_dir)
@ -110,7 +110,7 @@ class CMakeFileAPI:
return src_dir, bld_dir
def parse_sources(comp_group: dict, tgt: dict) -> T.Tuple[T.List[str], T.List[str], T.List[int]]:
def parse_sources(comp_group: T.Dict[str, T.Any], tgt: T.Dict[str, T.Any]) -> T.Tuple[T.List[str], T.List[str], T.List[int]]:
gen = []
src = []
idx = []
@ -127,7 +127,7 @@ class CMakeFileAPI:
return src, gen, idx
def parse_target(tgt: dict) -> dict:
def parse_target(tgt: T.Dict[str, T.Any]) -> T.Dict[str, T.Any]:
src_dir, bld_dir = helper_parse_dir(cnf.get('paths', {}))
# Parse install paths (if present)
@ -230,7 +230,7 @@ class CMakeFileAPI:
}]
return tgt_data
def parse_project(pro: dict) -> dict:
def parse_project(pro: T.Dict[str, T.Any]) -> T.Dict[str, T.Any]:
# Only look at the first directory specified in directoryIndexes
# TODO Figure out what the other indexes are there for
p_src_dir = source_dir
@ -268,7 +268,7 @@ class CMakeFileAPI:
self.cmake_configurations += [CMakeConfiguration(cnf_data)]
def _parse_cmakeFiles(self, data: dict) -> None:
def _parse_cmakeFiles(self, data: T.Dict[str, T.Any]) -> None:
assert('inputs' in data)
assert('paths' in data)
@ -309,10 +309,14 @@ class CMakeFileAPI:
return data
def _reply_file_content(self, filename: str) -> dict:
def _reply_file_content(self, filename: str) -> T.Dict[str, T.Any]:
real_path = os.path.join(self.reply_dir, filename)
if not os.path.exists(real_path):
raise CMakeException('File "{}" does not exist'.format(real_path))
with open(real_path, 'r') as fp:
return json.load(fp)
data = json.load(fp)
assert isinstance(data, dict)
for i in data.keys():
assert isinstance(i, str)
return data

Loading…
Cancel
Save