python-discovery 1.1.1__py3-none-any.whl → 1.1.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -210,6 +210,7 @@ def _run_subprocess(
210
210
  code = process.returncode
211
211
  except TimeoutExpired:
212
212
  process.kill()
213
+ process.communicate()
213
214
  out, err, code = "", "timed out", -1
214
215
  except OSError as os_error:
215
216
  out, err, code = "", os_error.strerror, os_error.errno
@@ -469,12 +469,24 @@ class PythonInfo: # noqa: PLR0904
469
469
  if spec.version_specifier is None: # pragma: no cover
470
470
  return True
471
471
  version_info = self.version_info
472
- release = f"{version_info.major}.{version_info.minor}.{version_info.micro}"
473
- if version_info.releaselevel != "final":
474
- suffix = {"alpha": "a", "beta": "b", "candidate": "rc"}.get(version_info.releaselevel)
475
- if suffix is not None: # pragma: no branch # releaselevel is always alpha/beta/candidate here
472
+ for specifier in spec.version_specifier:
473
+ assert specifier.version is not None # noqa: S101
474
+ numeric_version = specifier.version_str
475
+ for prefix in ("rc", "b", "a"):
476
+ if prefix in numeric_version:
477
+ numeric_version = numeric_version.split(prefix)[0]
478
+ break
479
+ precision = numeric_version.count(".") + 1
480
+ release = ".".join(str(c) for c in [version_info.major, version_info.minor, version_info.micro][:precision])
481
+ if (
482
+ version_info.releaselevel != "final"
483
+ and (precision == 3 or specifier.version.pre_type is not None) # noqa: PLR2004
484
+ and (suffix := {"alpha": "a", "beta": "b", "candidate": "rc"}.get(version_info.releaselevel))
485
+ ):
476
486
  release = f"{release}{suffix}{version_info.serial}"
477
- return spec.version_specifier.contains(release)
487
+ if not specifier.contains(release):
488
+ return False
489
+ return True
478
490
 
479
491
  _current_system = None
480
492
  _current = None
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: python-discovery
3
- Version: 1.1.1
3
+ Version: 1.1.3
4
4
  Summary: Python interpreter discovery
5
5
  Project-URL: Changelog, https://github.com/tox-dev/python-discovery/releases
6
6
  Project-URL: Documentation, https://python-discovery.readthedocs.io
@@ -64,8 +64,43 @@ Description-Content-Type: text/markdown
64
64
  # [`python-discovery`](https://python-discovery.readthedocs.io/en/latest/)
65
65
 
66
66
  [![PyPI](https://img.shields.io/pypi/v/python-discovery?style=flat-square)](https://pypi.org/project/python-discovery/)
67
- [![Supported Python
68
- versions](https://img.shields.io/pypi/pyversions/python-discovery.svg)](https://pypi.org/project/python-discovery/)
67
+ [![Supported Python versions](https://img.shields.io/pypi/pyversions/python-discovery.svg)](https://pypi.org/project/python-discovery/)
69
68
  [![Downloads](https://static.pepy.tech/badge/python-discovery/month)](https://pepy.tech/project/python-discovery)
70
69
  [![check](https://github.com/tox-dev/python-discovery/actions/workflows/check.yaml/badge.svg)](https://github.com/tox-dev/python-discovery/actions/workflows/check.yaml)
71
70
  [![Documentation Status](https://readthedocs.org/projects/python-discovery/badge/?version=latest)](https://python-discovery.readthedocs.io/en/latest/?badge=latest)
71
+
72
+ ## What is python-discovery?
73
+
74
+ `python-discovery` is a library for discovering Python interpreters installed on your machine. You may have multiple
75
+ Python versions from system packages, [pyenv](https://github.com/pyenv/pyenv), [mise](https://mise.jdx.dev/),
76
+ [asdf](https://asdf-vm.com/), [uv](https://docs.astral.sh/uv/), or the Windows registry (PEP 514). This library finds
77
+ the right one for you.
78
+
79
+ Give it a requirement like `python3.12` or `>=3.11,<3.13`, and it searches all known locations, verifies each candidate,
80
+ and returns detailed metadata about the match. Results are cached to disk so repeated lookups are fast.
81
+
82
+ ## Usage
83
+
84
+ ```python
85
+ from pathlib import Path
86
+
87
+ from python_discovery import DiskCache, get_interpreter
88
+
89
+ cache = DiskCache(root=Path("~/.cache/python-discovery").expanduser())
90
+ result = get_interpreter("python3.12", cache=cache)
91
+ if result is not None:
92
+ print(result.executable) # /usr/bin/python3.12
93
+ print(result.implementation) # CPython
94
+ print(result.version_info[:3]) # (3, 12, 1)
95
+ ```
96
+
97
+ The `get_interpreter()` function accepts various specification formats:
98
+
99
+ - Absolute path: `/usr/bin/python3.12`
100
+ - Version: `3.12`
101
+ - Implementation prefix: `cpython3.12`
102
+ - PEP 440 specifier: `>=3.10`, `>=3.11,<3.13`
103
+
104
+ ## Documentation
105
+
106
+ Full documentation is available at [python-discovery.readthedocs.io](https://python-discovery.readthedocs.io/en/latest/)
@@ -1,16 +1,16 @@
1
1
  python_discovery/__init__.py,sha256=Omg3KoCm1ETlMYb9UPsxDJ7ygtFyopJUk-_ln2xrmhs,628
2
2
  python_discovery/_cache.py,sha256=bG4fD-h2pdPmb4v9BldbXmJ5Tlt1boiH1Qrz8kp9Dds,5063
3
- python_discovery/_cached_py_info.py,sha256=3C41bIxq9bgrVV2XEZzn2BsOdauDaHKlMxRjwEUU1Yc,8441
3
+ python_discovery/_cached_py_info.py,sha256=CTqnvHCEnub8vE0kkRx9te4UGRGSXcJCXi-XRulkHBU,8475
4
4
  python_discovery/_compat.py,sha256=iqxGuhK9rPaiui80G1H1KrweoMJ16gyLYEmUrSXrp5c,709
5
5
  python_discovery/_discovery.py,sha256=yccO7GNtNuxHtmDHsyqtaASmNHFgKIeEX6Me3jX-GFs,12822
6
- python_discovery/_py_info.py,sha256=KtlIMi8CT_B4G3cyXgN2uXf-ve16nqt08WApnDQK3ac,33080
6
+ python_discovery/_py_info.py,sha256=7JFVTXoah2ivDeWg0KYqys-ZhzlLdSBwSTnAPQqAG7k,33600
7
7
  python_discovery/_py_spec.py,sha256=rhm9uahWSQL3JLyyMmM2HQVhrTMVnHnZEAhArkjeNtM,9601
8
8
  python_discovery/_specifier.py,sha256=PTh6suNTC0hMnFSxFYF_vggdciFLnwxoh1YflSbgCXA,10368
9
9
  python_discovery/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
10
  python_discovery/_windows/__init__.py,sha256=qthcyGh36b3WkeSbZ4ECRRYLbCOCaQu5X_DRZ98tXfk,315
11
11
  python_discovery/_windows/_pep514.py,sha256=JYSQ5tOYbSMOKtVVfOEkyYskBhEoTsImNr3DJcv7XNE,7658
12
12
  python_discovery/_windows/_propose.py,sha256=iMJf6l0TU4SvuV8UsCHHINAe9L5dUT949xyeyMVdong,1565
13
- python_discovery-1.1.1.dist-info/METADATA,sha256=1ai_-_BpIWorroopADBL99vytMc_AlfLxmh0ba_ShzE,4024
14
- python_discovery-1.1.1.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
15
- python_discovery-1.1.1.dist-info/licenses/LICENSE,sha256=kOJeH68qSq6o2V7o5_VziwUqGswMnFgGgQH5Mahr1Yg,1023
16
- python_discovery-1.1.1.dist-info/RECORD,,
13
+ python_discovery-1.1.3.dist-info/METADATA,sha256=i9erm4S9TcyhTiiIaJ0lc6B1Np_1buU1ooT1mzyWtuY,5404
14
+ python_discovery-1.1.3.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
15
+ python_discovery-1.1.3.dist-info/licenses/LICENSE,sha256=kOJeH68qSq6o2V7o5_VziwUqGswMnFgGgQH5Mahr1Yg,1023
16
+ python_discovery-1.1.3.dist-info/RECORD,,