Merge pull request #31 from jargonzombies/doc-and-spelling

Some documentation and misspelling fixes
This commit is contained in:
Regen
2020-11-08 16:48:02 +09:00
committed by GitHub
2 changed files with 37 additions and 11 deletions

View File

@@ -45,6 +45,12 @@ class API(object):
self._generated_list_parsed = False self._generated_list_parsed = False
def query(self) -> bool: def query(self) -> bool:
""" Use CMake's file API to get JSON information about the build tree
Generates a JSON request file for the current build tree and runs
CMake on the build tree. Deletes the request file immediately
after.
"""
if not self.cmake_cache.exists(): if not self.cmake_cache.exists():
return False return False
@@ -77,6 +83,11 @@ class API(object):
return True return True
def read_reply(self) -> bool: def read_reply(self) -> bool:
""" Reads the CMake file API reply file and updates internal state
Reads the result of the previous query file and updates
the targets, the cache entries and the cmake files.
"""
reply = self._build / ".cmake" / "api" / "v1" / "reply" reply = self._build / ".cmake" / "api" / "v1" / "reply"
indices = sorted(reply.glob("index-*.json")) indices = sorted(reply.glob("index-*.json"))
if not indices: if not indices:
@@ -124,7 +135,7 @@ class API(object):
self._cached_variables[name] = "\n\n".join(doc) self._cached_variables[name] = "\n\n".join(doc)
def _read_cmake_files(self, jsonpath: Path): def _read_cmake_files(self, jsonpath: Path):
"""inspect generated list files""" """inspect CMake list files that are used during build generation"""
if not self._builtin_variables or self._generated_list_parsed: if not self._builtin_variables or self._generated_list_parsed:
return return
@@ -132,7 +143,7 @@ class API(object):
with jsonpath.open() as fp: with jsonpath.open() as fp:
cmake_files = json.load(fp) cmake_files = json.load(fp)
# inspect generated list files # Inspect generated list files: Get the values of variables in each script
with tempfile.TemporaryDirectory() as tmpdirname: with tempfile.TemporaryDirectory() as tmpdirname:
tmplist = Path(tmpdirname) / "dump.cmake" tmplist = Path(tmpdirname) / "dump.cmake"
with tmplist.open("w") as fp: with tmplist.open("w") as fp:
@@ -203,6 +214,11 @@ endforeach()
self._parse_modules() self._parse_modules()
def _parse_commands(self) -> None: def _parse_commands(self) -> None:
""" Load docs for builtin cmake functions
Loads the documentation for builtin cmake functions from the result
of `$ cmake --help-commands`.
"""
p = subprocess.run( p = subprocess.run(
[self._cmake, "--help-commands"], [self._cmake, "--help-commands"],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
@@ -231,6 +247,11 @@ endforeach()
self._builtin_commands[command] = "```cmake\n" + signature + "\n```" self._builtin_commands[command] = "```cmake\n" + signature + "\n```"
def _parse_variables(self) -> None: def _parse_variables(self) -> None:
""" Load docs for builtin cmake variables
Loads the documentation for builtin cmake variables from
the result of `$ cmake --help-variables`.
"""
p = subprocess.run( p = subprocess.run(
[self._cmake, "--help-variables"], [self._cmake, "--help-variables"],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
@@ -265,6 +286,11 @@ endforeach()
self._builtin_variables[variable] = doc self._builtin_variables[variable] = doc
def _parse_modules(self) -> None: def _parse_modules(self) -> None:
""" Loads docs for all modules in the cmake distribution
Loads the documentation for cmake modules included in the
distribution from the result of `$ cmake --help-modules`.
"""
p = subprocess.run( p = subprocess.run(
[self._cmake, "--help-modules"], [self._cmake, "--help-modules"],
stdout=subprocess.PIPE, stdout=subprocess.PIPE,

View File

@@ -4,7 +4,7 @@ from .parser import TokenList
class Formatter(object): class Formatter(object):
indnt: str indent: str
lower_identifier: bool lower_identifier: bool
def __init__(self, indent=" ", lower_identifier=True): def __init__(self, indent=" ", lower_identifier=True):
@@ -13,7 +13,7 @@ class Formatter(object):
def format(self, tokens: TokenList) -> str: def format(self, tokens: TokenList) -> str:
cmds: List[str] = [""] cmds: List[str] = [""]
indnet_level = 0 indent_level = 0
for token in tokens: for token in tokens:
if isinstance(token, tuple): if isinstance(token, tuple):
raw_identifier = token[0] raw_identifier = token[0]
@@ -27,9 +27,9 @@ class Formatter(object):
"endmacro", "endmacro",
"endfunction", "endfunction",
): ):
if indnet_level > 0: if indent_level > 0:
indnet_level -= 1 indent_level -= 1
cmds[-1] = self.indent * indnet_level cmds[-1] = self.indent * indent_level
cmds[-1] += identifier if self.lower_identifier else raw_identifier cmds[-1] += identifier if self.lower_identifier else raw_identifier
args = self._format_args(token[1]) args = self._format_args(token[1])
if len(args) < 2: if len(args) < 2:
@@ -37,8 +37,8 @@ class Formatter(object):
else: else:
cmds[-1] += "(\n" cmds[-1] += "(\n"
for arg in args: for arg in args:
cmds[-1] += self.indent * (indnet_level + 1) + arg + "\n" cmds[-1] += self.indent * (indent_level + 1) + arg + "\n"
cmds[-1] += self.indent * indnet_level + ")" cmds[-1] += self.indent * indent_level + ")"
if identifier in ( if identifier in (
"if", "if",
"elseif", "elseif",
@@ -48,14 +48,14 @@ class Formatter(object):
"macro", "macro",
"function", "function",
): ):
indnet_level += 1 indent_level += 1
elif token == "\n": elif token == "\n":
cmds.append("") cmds.append("")
elif token[0] == "#": elif token[0] == "#":
if cmds[-1]: if cmds[-1]:
cmds[-1] += token cmds[-1] += token
else: else:
cmds[-1] = self.indent * indnet_level + token cmds[-1] = self.indent * indent_level + token
elif cmds[-1]: elif cmds[-1]:
cmds[-1] += token cmds[-1] += token