Create an interpreter from the given `binary`. :param binary: The path to the python interpreter binary. :param pyenv: A custom Pyenv installation for handling pyenv shim identification. Auto-detected by default. :param cwd: The cwd to use as a base to
(
cls,
binary, # type: str
pyenv=None, # type: Optional[Pyenv]
cwd=None, # type: Optional[str]
ignore_cached=False, # type: bool
)
| 1247 | |
| 1248 | @classmethod |
| 1249 | def from_binary( |
| 1250 | cls, |
| 1251 | binary, # type: str |
| 1252 | pyenv=None, # type: Optional[Pyenv] |
| 1253 | cwd=None, # type: Optional[str] |
| 1254 | ignore_cached=False, # type: bool |
| 1255 | ): |
| 1256 | # type: (...) -> PythonInterpreter |
| 1257 | """Create an interpreter from the given `binary`. |
| 1258 | |
| 1259 | :param binary: The path to the python interpreter binary. |
| 1260 | :param pyenv: A custom Pyenv installation for handling pyenv shim identification. |
| 1261 | Auto-detected by default. |
| 1262 | :param cwd: The cwd to use as a base to look for python version files from. The process cwd |
| 1263 | by default. |
| 1264 | :param ignore_cached: If the binary has already been identified, ignore the cached |
| 1265 | identification and re-identify. |
| 1266 | :return: an interpreter created from the given `binary`. |
| 1267 | """ |
| 1268 | python = cls._resolve_pyenv_shim(binary, pyenv=pyenv, cwd=cwd) |
| 1269 | if python is None: |
| 1270 | raise cls.IdentificationError("The pyenv shim at {} is not active.".format(binary)) |
| 1271 | |
| 1272 | try: |
| 1273 | return cast( |
| 1274 | PythonInterpreter, |
| 1275 | cls._spawn_from_binary(python, ignore_cached=ignore_cached).await_result(), |
| 1276 | ) |
| 1277 | except Job.Error as e: |
| 1278 | raise cls.IdentificationError("Failed to identify {}: {}".format(binary, e)) |
| 1279 | |
| 1280 | @classmethod |
| 1281 | def matches_binary_name(cls, path): |