INNER CODE UNIT · Python

_fixup_includes

mongodb/mongo-cxx-driver · etc/format.py:194

def _fixup_includes(fpath: Path, *, mode: RunMode) -> bool:
    """
    Apply #include-fixup to the content of the given source file.
    """
    # Split into lines
    old_lines = fpath.read_text().split('\n')
    # Do a regex substitution on ever line:
    rx = re.compile(INCLUDE_RE, re.VERBOSE)
    new_lines = [rx.sub(_include_subst_fn(fpath), ln) for ln in old_lines]
    # Did we change anything?
    did_change = new_lines != old_lines
    # We changed something. What do we do next?
    match did_change, mode:
        case False, _:
            # No file changes. Nothing to do
            return True
        case _, 'apply':
            # We are applying changes. Write the lines back into the file and tell

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…