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:
(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)
| 123 | return success |
| 124 | |
| 125 | def compile_file(fullname, ddir=None, force=False, rx=None, quiet=0, |
| 126 | legacy=False, optimize=-1, |
| 127 | invalidation_mode=None, *, stripdir=None, prependdir=None, |
| 128 | limit_sl_dest=None, hardlink_dupes=False): |
| 129 | """Byte-compile one file. |
| 130 | |
| 131 | Arguments (only fullname is required): |
| 132 | |
| 133 | fullname: the file to byte-compile |
| 134 | ddir: if given, the directory name compiled in to the |
| 135 | byte-code file. |
| 136 | force: if True, force compilation, even if timestamps are up-to-date |
| 137 | quiet: full output with False or 0, errors only with 1, |
| 138 | no output with 2 |
| 139 | legacy: if True, produce legacy pyc paths instead of PEP 3147 paths |
| 140 | optimize: int or list of optimization levels or -1 for level of |
| 141 | the interpreter. Multiple levels leads to multiple compiled |
| 142 | files each with one optimization level. |
| 143 | invalidation_mode: how the up-to-dateness of the pyc will be checked |
| 144 | stripdir: part of path to left-strip from source file path |
| 145 | prependdir: path to prepend to beginning of original file path, applied |
| 146 | after stripdir |
| 147 | limit_sl_dest: ignore symlinks if they are pointing outside of |
| 148 | the defined path. |
| 149 | hardlink_dupes: hardlink duplicated pyc files |
| 150 | """ |
| 151 | |
| 152 | if ddir is not None and (stripdir is not None or prependdir is not None): |
| 153 | raise ValueError(("Destination dir (ddir) cannot be used " |
| 154 | "in combination with stripdir or prependdir")) |
| 155 | |
| 156 | success = True |
| 157 | fullname = os.fspath(fullname) |
| 158 | stripdir = os.fspath(stripdir) if stripdir is not None else None |
| 159 | name = os.path.basename(fullname) |
| 160 | |
| 161 | dfile = None |
| 162 | |
| 163 | if ddir is not None: |
| 164 | dfile = os.path.join(ddir, name) |
| 165 | |
| 166 | if stripdir is not None: |
| 167 | fullname_parts = fullname.split(os.path.sep) |
| 168 | stripdir_parts = stripdir.split(os.path.sep) |
| 169 | ddir_parts = list(fullname_parts) |
| 170 | |
| 171 | for spart, opart in zip(stripdir_parts, fullname_parts): |
| 172 | if spart == opart: |
| 173 | ddir_parts.remove(spart) |
| 174 | |
| 175 | dfile = os.path.join(*ddir_parts) |
| 176 | |
| 177 | if prependdir is not None: |
| 178 | if dfile is None: |
| 179 | dfile = os.path.join(prependdir, fullname) |
| 180 | else: |
| 181 | dfile = os.path.join(prependdir, dfile) |
| 182 |