INNER CODE UNIT · Python

_include_subst_fn

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

def _include_subst_fn(fpath: Path):
    "Create a regex substitution function that prints a message for the file when a substitution is made"

    parent_dir = fpath.parent

    def f(mat: re.Match[str]) -> str:
        # See groups in INCLUDE_RE
        target = mat['path']
        abs_target = parent_dir / target
        if abs_target.is_file():
            # This should be a relative include:
            newl = f'{mat["directive"]}"./{target}"{mat["tail"]}'
        else:
            newl = f'{mat["directive"]}<{target}>{mat["tail"]}'
        print(f' - {fpath}: update #include directive: {mat[0]!r} → {newl!r}', file=sys.stderr)
        return newl

    return f

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…