Compiles the given python source files using this compiler's interpreter. :param root: The root path all the source files are found under. :param relpaths: The relative paths from the `root` of the source files to compile. :returns: A list of relative paths of the compiled b
(self, root, relpaths)
| 79 | self._interpreter = interpreter |
| 80 | |
| 81 | def compile(self, root, relpaths): |
| 82 | # type: (str, Iterable[str]) -> List[Text] |
| 83 | """Compiles the given python source files using this compiler's interpreter. |
| 84 | |
| 85 | :param root: The root path all the source files are found under. |
| 86 | :param relpaths: The relative paths from the `root` of the source files to compile. |
| 87 | :returns: A list of relative paths of the compiled bytecode files. |
| 88 | :raises: A :class:`Compiler.Error` if there was a problem bytecode compiling any of the files. |
| 89 | """ |
| 90 | with named_temporary_file() as fp: |
| 91 | fp.write( |
| 92 | to_bytes(_COMPILER_MAIN % {"root": root, "relpaths": relpaths}, encoding="utf-8") |
| 93 | ) |
| 94 | fp.flush() |
| 95 | |
| 96 | try: |
| 97 | _, out, _ = self._interpreter.execute(args=[fp.name]) |
| 98 | except Executor.NonZeroExit as e: |
| 99 | raise self.CompilationFailure( |
| 100 | "encountered %r during bytecode compilation.\nstderr was:\n%s\n" % (e, e.stderr) |
| 101 | ) |
| 102 | |
| 103 | return cast("Text", out).splitlines() |