MCPcopy
hub / github.com/pex-tool/pex / _iter_interpreters

Function _iter_interpreters

pex/pex_bootstrapper.py:133–163  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

131 )
132
133 def _iter_interpreters():
134 # type: () -> Iterator[InterpreterOrError]
135 seen = set() # type: Set[InterpreterOrError]
136
137 normalized_paths = normalize_path(path)
138
139 # Prefer the current interpreter, if valid.
140 current_interpreter = preferred_interpreter or PythonInterpreter.get()
141 if not _valid_path or _valid_path(current_interpreter.binary):
142 if normalized_paths:
143 candidate_paths = frozenset(
144 (current_interpreter.binary, os.path.dirname(current_interpreter.binary))
145 )
146 candidate_paths_in_path = candidate_paths.intersection(normalized_paths)
147 if candidate_paths_in_path:
148 # In case the full path of the current interpreter binary was in the
149 # `normalized_paths` we're searching, remove it to prevent identifying it again
150 # just to then skip it as `seen`.
151 normalized_paths.discard(current_interpreter.binary)
152 seen.add(current_interpreter)
153 yield current_interpreter
154 else:
155 seen.add(current_interpreter)
156 yield current_interpreter
157
158 for interp in PythonInterpreter.iter_candidates(
159 paths=normalized_paths, path_filter=_valid_path
160 ):
161 if interp not in seen:
162 seen.add(interp)
163 yield interp
164
165 def _valid_interpreter(interp):
166 # type: (PythonInterpreter) -> Union[ResolveError, bool]

Callers 1

Calls 5

normalize_pathFunction · 0.85
iter_candidatesMethod · 0.80
getMethod · 0.45
discardMethod · 0.45
addMethod · 0.45

Tested by

no test coverage detected