Helper for building PEX environments.
| 119 | |
| 120 | |
| 121 | class PEXBuilder(object): |
| 122 | """Helper for building PEX environments.""" |
| 123 | |
| 124 | class Error(Exception): |
| 125 | pass |
| 126 | |
| 127 | class ImmutablePEX(Error): |
| 128 | pass |
| 129 | |
| 130 | class InvalidDistribution(Error): |
| 131 | pass |
| 132 | |
| 133 | class InvalidDependency(Error): |
| 134 | pass |
| 135 | |
| 136 | class InvalidExecutableSpecification(Error): |
| 137 | pass |
| 138 | |
| 139 | def __init__( |
| 140 | self, |
| 141 | path=None, # type: Optional[str] |
| 142 | interpreter=None, # type: Optional[PythonInterpreter] |
| 143 | chroot=None, # type: Optional[Chroot] |
| 144 | pex_info=None, # type: Optional[PexInfo] |
| 145 | preamble=None, # type: Optional[str] |
| 146 | copy_mode=CopyMode.LINK, # type: CopyMode.Value |
| 147 | ): |
| 148 | # type: (...) -> None |
| 149 | """Initialize a pex builder. |
| 150 | |
| 151 | :keyword path: The path to write the PEX as it is built. If ``None`` is specified, |
| 152 | a temporary directory will be created. |
| 153 | :keyword interpreter: The interpreter to use to build this PEX environment. If ``None`` |
| 154 | is specified, the current interpreter is used. |
| 155 | :keyword chroot: If specified, preexisting :class:`Chroot` to use for building the PEX. |
| 156 | :keyword pex_info: A preexisting PexInfo to use to build the PEX. |
| 157 | :keyword preamble: If supplied, execute this code prior to bootstrapping this PEX |
| 158 | environment. |
| 159 | :keyword copy_mode: Create the pex environment using the given copy mode. |
| 160 | |
| 161 | .. versionchanged:: 0.8 |
| 162 | The temporary directory created when ``path`` is not specified is now garbage collected on |
| 163 | interpreter exit. |
| 164 | """ |
| 165 | self._interpreter = interpreter or PythonInterpreter.get() |
| 166 | self._chroot = chroot or Chroot(path or safe_mkdtemp()) |
| 167 | self._pex_info = pex_info or PexInfo.default() |
| 168 | self._preamble = preamble or "" |
| 169 | self._copy_mode = ( |
| 170 | CopyMode.LINK if ((copy_mode is CopyMode.SYMLINK) and WINDOWS) else copy_mode |
| 171 | ) |
| 172 | |
| 173 | self._shebang = self._interpreter.identity.hashbang() |
| 174 | self._header = None # type: Optional[str] |
| 175 | self._logger = logging.getLogger(__name__) |
| 176 | self._frozen = False |
| 177 | self._distributions = {} # type: Dict[str, Distribution] |
| 178 |
no outgoing calls