Iterate all likely interpreters found in `paths`. NB: The paths can either be directories to search for python binaries or the paths of python binaries themselves. :param paths: The paths to look for python interpreters; by default the `PATH`. :param path_filter: An
(cls, paths=None, path_filter=None)
| 959 | |
| 960 | @classmethod |
| 961 | def iter_candidates(cls, paths=None, path_filter=None): |
| 962 | # type: (Optional[Iterable[str]], Optional[PathFilter]) -> Iterator[InterpreterOrError] |
| 963 | """Iterate all likely interpreters found in `paths`. |
| 964 | |
| 965 | NB: The paths can either be directories to search for python binaries or the paths of python |
| 966 | binaries themselves. |
| 967 | |
| 968 | :param paths: The paths to look for python interpreters; by default the `PATH`. |
| 969 | :param path_filter: An optional predicate to test whether a candidate interpreter's binary |
| 970 | path is acceptable. |
| 971 | :return: A heterogeneous iterator over valid interpreters and (python, error) invalid |
| 972 | python binary tuples. |
| 973 | """ |
| 974 | failed_interpreters = OrderedDict() # type: MutableMapping[str, Text] |
| 975 | |
| 976 | def iter_interpreters(): |
| 977 | # type: () -> Iterator[PythonInterpreter] |
| 978 | for candidate in cls._find( |
| 979 | cls._paths(paths=paths), path_filter=path_filter, error_handler=Retain[str]() |
| 980 | ): |
| 981 | if isinstance(candidate, cls): |
| 982 | yield candidate |
| 983 | else: |
| 984 | python, exception = cast("InterpreterIdentificationJobError", candidate) |
| 985 | if isinstance(exception, Job.Error) and exception.stderr: |
| 986 | # We spawned a subprocess to identify the interpreter but the interpreter |
| 987 | # could not run our identification code meaning the interpreter is either |
| 988 | # broken or old enough that it either can't parse our identification code |
| 989 | # or else provide stdlib modules we expect. The stderr should indicate the |
| 990 | # broken-ness appropriately. |
| 991 | failed_interpreters[python] = exception.stderr.strip() |
| 992 | else: |
| 993 | # We couldn't even spawn a subprocess to identify the interpreter. The |
| 994 | # likely OSError should help identify the underlying issue. |
| 995 | failed_interpreters[python] = repr(exception) |
| 996 | |
| 997 | for interpreter in cls._filter(iter_interpreters()): |
| 998 | yield interpreter |
| 999 | |
| 1000 | for python, error in failed_interpreters.items(): |
| 1001 | yield python, error |
| 1002 | |
| 1003 | @classmethod |
| 1004 | def all(cls, paths=None): |