MCPcopy Index your code
hub / github.com/RustPython/RustPython / compile_file

Function compile_file

Lib/compileall.py:132–279  ·  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 dfile = None
169
170 if ddir is not None:
171 dfile = os.path.join(ddir, name)
172
173 if stripdir is not None:
174 fullname_parts = fullname.split(os.path.sep)
175 stripdir_parts = stripdir.split(os.path.sep)
176
177 if stripdir_parts != fullname_parts[:len(stripdir_parts)]:
178 if quiet < 2:
179 print("The stripdir path {!r} is not a valid prefix for "
180 "source path {!r}; ignoring".format(stripdir, fullname))
181 else:
182 dfile = os.path.join(*fullname_parts[len(stripdir_parts):])
183
184 if prependdir is not None:
185 if dfile is None:
186 dfile = os.path.join(prependdir, fullname)
187 else:
188 dfile = os.path.join(prependdir, dfile)
189

Callers 2

compile_dirFunction · 0.85
mainFunction · 0.85

Calls 15

PathClass · 0.90
lenFunction · 0.85
isinstanceFunction · 0.85
sortedFunction · 0.85
setFunction · 0.85
enumerateFunction · 0.85
basenameMethod · 0.80
islinkMethod · 0.80
openFunction · 0.70
printFunction · 0.50
joinMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected