module documentation

Python executable used to compile to bytecode.

Exception CompileError A compilation error.
Exception PythonNotFoundError Undocumented
Function can_compile_bytecode_natively Undocumented
Function compile_src_string_to_pyc_string Compile Python source code to pyc data.
Function get_python_executable Get a python executable corresponding to version.
Function _get_python_exe_version Determine the major and minor version of given Python executable.
Function _get_python_exes Find possible python executables to use.
Function _load_data_file Get the contents of a data file.
Function _parse_exe_version_string Parse the version string of a Python executable.
Function _path_to_custom_exe Get the full path to a custom python exe in the pytype/ src directory.
Constant _COMPILE_ERROR_RE Undocumented
Constant _COMPILE_SCRIPT Undocumented
Constant _CUSTOM_PYTHON_EXES Undocumented
def can_compile_bytecode_natively(python_version): (source)

Undocumented

def compile_src_string_to_pyc_string(src, filename, python_version, python_exe: List[str], mode='exec'): (source)

Compile Python source code to pyc data. This may use py_compile if the src is for the same version as we're running, or else it spawns an external process to produce a .pyc file. The generated bytecode (.pyc file) is read and both it and any temporary files are deleted. Args: src: Python sourcecode filename: Name of the source file. For error messages. python_version: Python version, (major, minor). python_exe: A path to a Python interpreter. mode: Same as builtins.compile: "exec" if source consists of a sequence of statements, "eval" if it consists of a single expression, or "single" if it consists of a single interactive statement. Returns: The compiled pyc file as a binary string. Raises: CompileError: If we find a syntax error in the file. IOError: If our compile script failed.

def get_python_executable(version: Tuple[int, ...]) -> Optional[List[str]]: (source)

Get a python executable corresponding to version. Args: version: The required python version Returns: - None: The current host interpreter can compile `version` - [path-to-exe, args]: A valid python-`version` interpreter Raises: PythonNotFoundError: if no suitable interpreter is found.

def _get_python_exe_version(python_exe: List[str]): (source)

Determine the major and minor version of given Python executable. Arguments: python_exe: absolute path to the Python executable Returns: Version as (major, minor) tuple, or None if it could not be determined.

def _get_python_exes(python_version) -> Iterable[List[str]]: (source)

Find possible python executables to use. Arguments: python_version: the version tuple (e.g. (3, 7)) Yields: The path to the executable

def _load_data_file(path): (source)

Get the contents of a data file.

def _parse_exe_version_string(version_str): (source)

Parse the version string of a Python executable. Arguments: version_str: Version string as emitted by running `PYTHON_EXE -V` Returns: Version as (major, minor) tuple, or None if it could not be determined.

def _path_to_custom_exe(relative_path): (source)

Get the full path to a custom python exe in the pytype/ src directory.

_COMPILE_ERROR_RE = (source)

Undocumented

Value
re.compile(r'^(.*) \((.*), line (\d+)\)$')
_COMPILE_SCRIPT: str = (source)

Undocumented

Value
'pyc/compile_bytecode.py'
_CUSTOM_PYTHON_EXES: dict = (source)

Undocumented

Value
{}