| 54 | |
| 55 | |
| 56 | class IsolatedSysPath(object): |
| 57 | @staticmethod |
| 58 | def _expand_paths(*paths): |
| 59 | # type: (*str) -> OrderedSet[str] |
| 60 | def iter_synonyms(path): |
| 61 | yield path |
| 62 | yield os.path.abspath(path) |
| 63 | yield os.path.realpath(path) |
| 64 | |
| 65 | return OrderedSet(itertools.chain.from_iterable(iter_synonyms(path) for path in paths)) |
| 66 | |
| 67 | @classmethod |
| 68 | def for_pex( |
| 69 | cls, |
| 70 | interpreter, # type: Union[PythonInterpreter, PythonIdentity] |
| 71 | pex, # type: str |
| 72 | pex_pex=None, # type: Optional[str] |
| 73 | ): |
| 74 | # type: (...) -> IsolatedSysPath |
| 75 | ident = interpreter.identity if isinstance(interpreter, PythonInterpreter) else interpreter |
| 76 | sys_path = OrderedSet(ident.sys_path) |
| 77 | sys_path.add(pex) |
| 78 | sys_path.add(Bootstrap.locate().path) |
| 79 | if pex_pex: |
| 80 | sys_path.add(pex_pex) |
| 81 | |
| 82 | site_packages = OrderedSet() # type: OrderedSet[str] |
| 83 | for site_lib in ident.site_packages: |
| 84 | TRACER.log("Discarding site packages path: {site_lib}".format(site_lib=site_lib)) |
| 85 | site_packages.add(site_lib.path) |
| 86 | |
| 87 | extras_paths = OrderedSet() # type: OrderedSet[str] |
| 88 | for extras_path in ident.extras_paths: |
| 89 | TRACER.log("Discarding site extras path: {extras_path}".format(extras_path=extras_path)) |
| 90 | extras_paths.add(extras_path) |
| 91 | |
| 92 | return cls( |
| 93 | sys_path=sys_path, |
| 94 | site_packages=site_packages, |
| 95 | extras_paths=extras_paths, |
| 96 | is_venv=ident.is_venv, |
| 97 | ) |
| 98 | |
| 99 | def __init__( |
| 100 | self, |
| 101 | sys_path, # type: Iterable[str] |
| 102 | site_packages, # type: Iterable[str] |
| 103 | extras_paths=(), # type: Iterable[str] |
| 104 | is_venv=False, # type: bool |
| 105 | ): |
| 106 | # type: (...) -> None |
| 107 | self._sys_path_entries = tuple(self._expand_paths(*sys_path)) |
| 108 | self._site_packages_entries = tuple(self._expand_paths(*site_packages)) |
| 109 | self._extras_paths_entries = tuple(self._expand_paths(*extras_paths)) |
| 110 | self._is_venv = is_venv |
| 111 | |
| 112 | @property |
| 113 | def is_venv(self): |
no outgoing calls