|
20 | 20 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
21 | 21 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
22 | 22 | # SOFTWARE. |
| 23 | +from __future__ import annotations |
23 | 24 |
|
24 | | -"""Currently just copied from linux""" |
| 25 | +import itertools |
| 26 | +try: |
| 27 | + from _collections_abc import Iterator |
| 28 | +except ImportError: |
| 29 | + from collections.abc import Iterator |
25 | 30 |
|
26 | | -from ..linux import get_python_installs, get_path_pythons, get_pyenv_pythons |
| 31 | +from .. import linux |
| 32 | +from ..shared import get_uv_pythons, DetailFinder,PythonInstall |
| 33 | + |
| 34 | + |
| 35 | +# This is the difference from the linux methods |
| 36 | +KNOWN_MANAGED_PATHS = { |
| 37 | + **linux.KNOWN_MANAGED_PATHS, |
| 38 | + "/opt/homebrew": "Homebrew", # ARM Apple |
| 39 | + "/usr/local/opt": "Homebrew", # x86_64 Apple |
| 40 | + "/Applications/Xcode.app": "Xcode", |
| 41 | + "/Library/Developer/CommandLineTools": "Xcode", # Xcode commandline tools |
| 42 | + "/Library/Frameworks/Python.framework": "python.org", |
| 43 | +} |
| 44 | + |
| 45 | + |
| 46 | +def get_path_pythons( |
| 47 | + *, |
| 48 | + finder: DetailFinder | None = None, |
| 49 | + known_paths: dict[str, str] | None = None, |
| 50 | +) -> Iterator[PythonInstall]: |
| 51 | + |
| 52 | + known_paths = KNOWN_MANAGED_PATHS if known_paths is None else known_paths |
| 53 | + |
| 54 | + return linux.get_path_pythons(finder=finder, known_paths=known_paths) |
| 55 | + |
| 56 | + |
| 57 | +def get_python_installs( |
| 58 | + *, |
| 59 | + finder: DetailFinder | None = None, |
| 60 | +) -> Iterator[PythonInstall]: |
| 61 | + listed_pythons = set() |
| 62 | + |
| 63 | + finder = DetailFinder() if finder is None else finder |
| 64 | + |
| 65 | + chain_commands = [ |
| 66 | + linux.get_pyenv_pythons(finder=finder), |
| 67 | + get_uv_pythons(finder=finder), |
| 68 | + get_path_pythons(finder=finder), |
| 69 | + ] |
| 70 | + with finder: |
| 71 | + for py in itertools.chain.from_iterable(chain_commands): |
| 72 | + if py.executable not in listed_pythons: |
| 73 | + yield py |
| 74 | + listed_pythons.add(py.executable) |
0 commit comments