MCPcopy Index your code
hub / github.com/python/cpython / preprocess

Function preprocess

Tools/c-analyzer/c_parser/preprocessor/__init__.py:38–74  ·  view source on GitHub ↗

... CWD should be the project root and "source" should be relative.

(source, *,
               incldirs=None,
               includes=None,
               macros=None,
               samefiles=None,
               filename=None,
               cwd=None,
               tool=True,
               )

Source from the content-addressed store, hash-verified

36# XXX Add more low-level functions to handle permutations?
37
38def preprocess(source, *,
39 incldirs=None,
40 includes=None,
41 macros=None,
42 samefiles=None,
43 filename=None,
44 cwd=None,
45 tool=True,
46 ):
47 """...
48
49 CWD should be the project root and "source" should be relative.
50 """
51 if tool:
52 if not cwd:
53 cwd = os.getcwd()
54 logger.debug(f'CWD: {cwd!r}')
55 logger.debug(f'incldirs: {incldirs!r}')
56 logger.debug(f'includes: {includes!r}')
57 logger.debug(f'macros: {macros!r}')
58 logger.debug(f'samefiles: {samefiles!r}')
59 _preprocess = _get_preprocessor(tool)
60 with _good_file(source, filename) as source:
61 return _preprocess(
62 source,
63 incldirs,
64 includes,
65 macros,
66 samefiles,
67 cwd,
68 ) or ()
69 else:
70 source, filename = _resolve_source(source, filename)
71 # We ignore "includes", "macros", etc.
72 return _pure.preprocess(source, filename, cwd)
73
74 # if _run() returns just the lines:
75# text = _run(source)
76# lines = [line + os.linesep for line in text.splitlines()]
77# lines[-1] = lines[-1].splitlines()[0]

Callers

nothing calls this directly

Calls 5

handling_errorsFunction · 0.85
_get_preprocessorFunction · 0.70
debugMethod · 0.45
preprocessMethod · 0.45
setdefaultMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…