substrate.py¶
clew/substrate.py
What the substrate can parse, asked of the substrate itself.
compiled_languages
frozenset[str] clew.substrate.compiled_languages()
Every language key this substrate build can parse.
Source · 18 lines
def compiled_languages() -> frozenset[str]:
"""Cached: the answer is fixed for the life of the process, since it is decided by
which cargo features the installed wheel was built with. Tests clear the cache.
@brief The substrate's compiled-in language keys.
@return A frozenset of keys, possibly empty.
"""
try:
import lang_parsing_substrate as lps
return frozenset(info.key for info in lps.languages())
except (ImportError, AttributeError) as exc:
## Not `logger.debug`: a build that silently indexes nothing is the failure this
## project exists to avoid, and the operator cannot see a debug line.
logger.error("lang-parsing-substrate reports no languages (%s)", exc)
return frozenset()
Activity · 6 steps
Requirements
Flows
has_language
bool clew.substrate.has_language(str key)
Whether this substrate build can parse one language.
Called by _grammar_available, chunk_rst
Tested by 7 tests
test_a_file_merely_ending_in_the_cmake_name_is_not_cmake, test_a_language_the_substrate_does_not_have_is_absent, test_a_shell_script_routes_to_the_bash_grammar, test_an_unimportable_substrate_degrades_rather_than_raising, test_the_cmake_file_name_routes_even_though_its_extension_is_txt, test_the_gate_is_capability_not_version, test_the_shell_doc_block_reaches_the_row
Calls compiled_languages
Source · 5 lines
def has_language(key: str) -> bool:
"""@brief Capability test for one language key."""
return key in compiled_languages()
Activity · 1 steps
Requirements
Flows
missing_languages
tuple[str, ...] clew.substrate.missing_languages(Iterable[str] keys)
Which of the asked-for languages this substrate build lacks.
Source · 9 lines
def missing_languages(keys: Iterable[str]) -> tuple[str, ...]:
"""Order follows the caller's, not the set's, so a logged or served list reads the
way the caller wrote it rather than in hash order.
@brief The absent subset of the asked-for keys.
@return A tuple of missing keys.
"""
present = compiled_languages()
return tuple(key for key in keys if key not in present)1 more lines, not shown