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

Function compile_file

Lib/compileall.py:132–287  ·  view source on GitHub ↗

Byte-compile one file. Arguments (only fullname is required): fullname: the file to byte-compile ddir: if given, the directory name compiled in to the byte-code file. force: if True, force compilation, even if timestamps are up-to-date quiet: full o

(fullname, ddir=None, force=False, rx=None, quiet=0,
                 legacy=False, optimize=-1,
                 invalidation_mode=None, *, stripdir=None, prependdir=None,
                 limit_sl_dest=None, hardlink_dupes=False)

Source from the content-addressed store, hash-verified

130 return success
131
132def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0,
133 legacy=False, optimize=-1,
134 invalidation_mode=None, *, stripdir=None, prependdir=None,
135 limit_sl_dest=None, hardlink_dupes=False):
136 """Byte-compile one file.
137
138 Arguments (only fullname is required):
139
140 fullname: the file to byte-compile
141 ddir: if given, the directory name compiled in to the
142 byte-code file.
143 force: if True, force compilation, even if timestamps are up-to-date
144 quiet: full output with False or 0, errors only with 1,
145 no output with 2
146 legacy: if True, produce legacy pyc paths instead of PEP 3147 paths
147 optimize: int or list of optimization levels or -1 for level of
148 the interpreter. Multiple levels leads to multiple compiled
149 files each with one optimization level.
150 invalidation_mode: how the up-to-dateness of the pyc will be checked
151 stripdir: part of path to left-strip from source file path
152 prependdir: path to prepend to beginning of original file path, applied
153 after stripdir
154 limit_sl_dest: ignore symlinks if they are pointing outside of
155 the defined path.
156 hardlink_dupes: hardlink duplicated pyc files
157 """
158
159 if ddir is not None and (stripdir is not None or prependdir is not None):
160 raise ValueError(("Destination dir (ddir) cannot be used "
161 "in combination with stripdir or prependdir"))
162
163 success = True
164 fullname = os.fspath(fullname)
165 stripdir = os.fspath(stripdir) if stripdir is not None else None
166 name = os.path.basename(fullname)
167
168 # Without a cache_tag, we can only create legacy .pyc files. None of our
169 # callers seem to expect this, so the best we can do is fail without raising
170 if not legacy and sys.implementation.cache_tag is None:
171 if not quiet:
172 print("No cache tag is available to generate .pyc path for",
173 repr(fullname))
174 return False
175
176 dfile = None
177
178 if ddir is not None:
179 dfile = os.path.join(ddir, name)
180
181 if stripdir is not None:
182 fullname_parts = fullname.split(os.path.sep)
183 stripdir_parts = stripdir.split(os.path.sep)
184
185 if stripdir_parts != fullname_parts[:len(stripdir_parts)]:
186 if quiet < 2:
187 print("The stripdir path {!r} is not a valid prefix for "
188 "source path {!r}; ignoring".format(stripdir, fullname))
189 else:

Callers 2

compile_dirFunction · 0.85
mainFunction · 0.85

Calls 15

PathClass · 0.90
setFunction · 0.85
enumerateFunction · 0.85
islinkMethod · 0.80
openFunction · 0.70
basenameMethod · 0.45
joinMethod · 0.45
splitMethod · 0.45
formatMethod · 0.45
searchMethod · 0.45
resolveMethod · 0.45
isfileMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…