Skip to content

Commit e11c365

Browse files
committed
♻️ refactor(tests): stop importing private modules directly
Use from-imports and mocker.patch string paths instead of importing private modules as objects for monkeypatching. Signed-off-by: Bernát Gábor <bgabor8@bloomberg.net>
1 parent 3b381df commit e11c365

38 files changed

+1194
-1159
lines changed

.github/workflows/check.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ jobs:
2424
- "3.12"
2525
- "3.11"
2626
- "3.10"
27+
- "3.9"
28+
- "3.8"
2729
- type-3.8
2830
- type-3.14
2931
- dev

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
runs-on: ubuntu-latest
3434
environment:
3535
name: release
36-
url: https://pypi.org/project/py-discovery/${{ github.ref_name }}
36+
url: https://pypi.org/project/python-discovery/${{ github.ref_name }}
3737
permissions:
3838
id-token: write
3939
steps:

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
*.egg-info
33
dist/
44
.tox/
5-
/src/py_discovery/_version.py
5+
/src/python_discovery/_version.py

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# [`py-discovery`](https://py-discovery.readthedocs.io/en/latest/)
1+
# [`python-discovery`](https://python-discovery.readthedocs.io/en/latest/)
22

3-
[![PyPI](https://img.shields.io/pypi/v/py-discovery?style=flat-square)](https://pypi.org/project/py-discovery/)
3+
[![PyPI](https://img.shields.io/pypi/v/python-discovery?style=flat-square)](https://pypi.org/project/python-discovery/)
44
[![Supported Python
5-
versions](https://img.shields.io/pypi/pyversions/py-discovery.svg)](https://pypi.org/project/py-discovery/)
6-
[![Downloads](https://static.pepy.tech/badge/py-discovery/month)](https://pepy.tech/project/py-discovery)
7-
[![check](https://github.com/tox-dev/py-discovery/actions/workflows/check.yml/badge.svg)](https://github.com/tox-dev/py-discovery/actions/workflows/check.yml)
8-
[![Documentation Status](https://readthedocs.org/projects/py-discovery/badge/?version=latest)](https://py-discovery.readthedocs.io/en/latest/?badge=latest)
5+
versions](https://img.shields.io/pypi/pyversions/python-discovery.svg)](https://pypi.org/project/python-discovery/)
6+
[![Downloads](https://static.pepy.tech/badge/python-discovery/month)](https://pepy.tech/project/python-discovery)
7+
[![check](https://github.com/tox-dev/python-discovery/actions/workflows/check.yml/badge.svg)](https://github.com/tox-dev/python-discovery/actions/workflows/check.yml)
8+
[![Documentation Status](https://readthedocs.org/projects/python-discovery/badge/?version=latest)](https://python-discovery.readthedocs.io/en/latest/?badge=latest)

docs/conf.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
"""Sphinx configuration for python-discovery documentation."""
2+
13
from __future__ import annotations
24

35
from datetime import datetime, timezone
46

5-
from py_discovery import __version__
7+
from python_discovery import __version__
68

79
company = "tox-dev"
8-
name = "py-discovery"
10+
name = "python-discovery"
911
version = ".".join(__version__.split(".")[:2])
1012
release = __version__
11-
copyright = f"2024-{datetime.now(tz=timezone.utc).year}, {company}" # noqa: A001
13+
copyright = f"2026-{datetime.now(tz=timezone.utc).year}, {company}" # noqa: A001
1214

1315
extensions = [
1416
"sphinx.ext.autodoc",

docs/explanation.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
How it works
22
============
33

4-
Where does py-discovery look?
4+
Where does python-discovery look?
55
-------------------------------
66

7-
When you call :func:`~py_discovery.get_interpreter`, the library checks several locations in
7+
When you call :func:`~python_discovery.get_interpreter`, the library checks several locations in
88
order. It stops as soon as it finds an interpreter that matches your spec.
99

1010
.. mermaid::
@@ -44,7 +44,7 @@ How version-manager shims are handled
4444
-----------------------------------------
4545

4646
Version managers like `pyenv <https://github.com/pyenv/pyenv>`_ install thin wrapper scripts called
47-
**shims** (e.g., ``~/.pyenv/shims/python3.12``) that redirect to the real interpreter. py-discovery
47+
**shims** (e.g., ``~/.pyenv/shims/python3.12``) that redirect to the real interpreter. python-discovery
4848
detects these shims and resolves them to the actual binary.
4949

5050
.. mermaid::
@@ -85,7 +85,7 @@ work by storing the result as a JSON file keyed by the interpreter's path.
8585
style Return fill:#4a9f4a,stroke:#2a6f2a,color:#fff
8686
style Run fill:#d9904a,stroke:#8f5f2a,color:#fff
8787

88-
The built-in :class:`~py_discovery.DiskCache` stores files under ``<root>/py_info/4/<sha256>.json``
88+
The built-in :class:`~python_discovery.DiskCache` stores files under ``<root>/py_info/4/<sha256>.json``
8989
with `filelock <https://py-filelock.readthedocs.io/>`_-based locking for safe concurrent access. You
9090
can also pass ``cache=None`` to disable caching, or implement your own backend (see
9191
:doc:`/how-to/standalone-usage`).

docs/how-to/standalone-usage.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ standard locations.
1010

1111
.. code-block:: python
1212
13-
from py_discovery import get_interpreter
13+
from python_discovery import get_interpreter
1414
1515
info = get_interpreter("python3.12", try_first_with=["/opt/python/bin"])
1616
if info is not None:
@@ -19,7 +19,7 @@ standard locations.
1919
Restrict the search environment
2020
---------------------------------
2121

22-
By default, py-discovery reads environment variables like ``PATH`` and ``PYENV_ROOT`` from your
22+
By default, python-discovery reads environment variables like ``PATH`` and ``PYENV_ROOT`` from your
2323
shell. You can override these to control exactly where the library looks.
2424

2525
.. mermaid::
@@ -37,15 +37,15 @@ shell. You can override these to control exactly where the library looks.
3737
3838
import os
3939
40-
from py_discovery import get_interpreter
40+
from python_discovery import get_interpreter
4141
4242
env = {**os.environ, "PATH": "/usr/local/bin:/usr/bin"}
4343
result = get_interpreter("python3.12", env=env)
4444
4545
Read interpreter metadata
4646
---------------------------
4747

48-
Once you have a :class:`~py_discovery.PythonInfo`, you can inspect everything about the interpreter.
48+
Once you have a :class:`~python_discovery.PythonInfo`, you can inspect everything about the interpreter.
4949

5050
.. mermaid::
5151

@@ -67,9 +67,9 @@ Once you have a :class:`~py_discovery.PythonInfo`, you can inspect everything ab
6767
6868
from pathlib import Path
6969
70-
from py_discovery import DiskCache, get_interpreter
70+
from python_discovery import DiskCache, get_interpreter
7171
72-
cache = DiskCache(root=Path("~/.cache/py-discovery").expanduser())
72+
cache = DiskCache(root=Path("~/.cache/python-discovery").expanduser())
7373
info = get_interpreter("python3.12", cache=cache)
7474
7575
info.executable # Resolved path to the binary.
@@ -86,9 +86,9 @@ Once you have a :class:`~py_discovery.PythonInfo`, you can inspect everything ab
8686
Implement a custom cache backend
8787
-----------------------------------
8888

89-
The built-in :class:`~py_discovery.DiskCache` stores results as JSON files with
89+
The built-in :class:`~python_discovery.DiskCache` stores results as JSON files with
9090
`filelock <https://py-filelock.readthedocs.io/>`_-based locking. If you need a different storage
91-
strategy (e.g., in-memory, database-backed), implement the :class:`~py_discovery.PyInfoCache`
91+
strategy (e.g., in-memory, database-backed), implement the :class:`~python_discovery.PyInfoCache`
9292
protocol.
9393

9494
.. mermaid::
@@ -117,7 +117,7 @@ protocol.
117117
118118
from pathlib import Path
119119
120-
from py_discovery import ContentStore, PyInfoCache
120+
from python_discovery import ContentStore, PyInfoCache
121121
122122
123123
class MyContentStore:

docs/index.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
py-discovery
1+
python-discovery
22
============
33

44
You may have multiple Python versions installed on your machine -- system Python, versions from
55
`pyenv <https://github.com/pyenv/pyenv>`_, `mise <https://mise.jdx.dev/>`_,
66
`asdf <https://asdf-vm.com/>`_, `uv <https://docs.astral.sh/uv/>`_, or the Windows registry
7-
(:pep:`514`). ``py-discovery`` finds the right one for you.
7+
(:pep:`514`). ``python-discovery`` finds the right one for you.
88

99
Give it a requirement like ``python3.12`` or ``>=3.11,<3.13``, and it searches all known locations,
1010
verifies each candidate, and returns detailed metadata about the match. Results are cached to disk so
@@ -14,9 +14,9 @@ repeated lookups are fast.
1414
1515
from pathlib import Path
1616
17-
from py_discovery import DiskCache, get_interpreter
17+
from python_discovery import DiskCache, get_interpreter
1818
19-
cache = DiskCache(root=Path("~/.cache/py-discovery").expanduser())
19+
cache = DiskCache(root=Path("~/.cache/python-discovery").expanduser())
2020
result = get_interpreter("python3.12", cache=cache)
2121
if result is not None:
2222
print(result.executable) # /usr/bin/python3.12

docs/reference/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
API reference
22
=============
33

4-
.. automodule:: py_discovery
4+
.. automodule:: python_discovery
55
:members:
66
:undoc-members:
77
:show-inheritance:

docs/tutorial/getting-started.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Installation
66

77
.. code-block:: console
88
9-
pip install py-discovery
9+
pip install python-discovery
1010
1111
Core concepts
1212
-------------
@@ -39,24 +39,24 @@ The simplest use case: get information about the Python that is running right no
3939
4040
from pathlib import Path
4141
42-
from py_discovery import DiskCache, PythonInfo
42+
from python_discovery import DiskCache, PythonInfo
4343
44-
cache = DiskCache(root=Path("~/.cache/py-discovery").expanduser())
44+
cache = DiskCache(root=Path("~/.cache/python-discovery").expanduser())
4545
info = PythonInfo.current_system(cache)
4646
4747
print(info.executable) # /usr/bin/python3.12
4848
print(info.version_info[:3]) # (3, 12, 1)
4949
print(info.implementation) # CPython (or PyPy, GraalPy, etc.)
5050
print(info.architecture) # 64 (or 32)
5151
52-
The returned :class:`~py_discovery.PythonInfo` object contains everything the library knows about that interpreter:
52+
The returned :class:`~python_discovery.PythonInfo` object contains everything the library knows about that interpreter:
5353
paths, version numbers, sysconfig variables, platform details, and more.
5454

5555
Finding a different interpreter
5656
--------------------------------
5757

5858
Usually you need a *specific* Python version, not the one currently running. Pass a **spec** string
59-
to :func:`~py_discovery.get_interpreter` to search your system.
59+
to :func:`~python_discovery.get_interpreter` to search your system.
6060

6161
.. mermaid::
6262

@@ -74,9 +74,9 @@ to :func:`~py_discovery.get_interpreter` to search your system.
7474
7575
from pathlib import Path
7676
77-
from py_discovery import DiskCache, get_interpreter
77+
from python_discovery import DiskCache, get_interpreter
7878
79-
cache = DiskCache(root=Path("~/.cache/py-discovery").expanduser())
79+
cache = DiskCache(root=Path("~/.cache/python-discovery").expanduser())
8080
result = get_interpreter("python3.12", cache=cache)
8181
if result is not None:
8282
print(result.executable)
@@ -90,7 +90,7 @@ You can pass multiple specs as a list -- the library tries each one in order and
9090
Writing specs
9191
-------------
9292

93-
A spec tells py-discovery what to look for. The simplest form is just a version number like ``3.12``.
93+
A spec tells python-discovery what to look for. The simplest form is just a version number like ``3.12``.
9494
You can add more constraints to narrow the search.
9595

9696
.. mermaid::
@@ -139,7 +139,7 @@ Parsing a spec
139139
--------------
140140

141141
You can parse a spec string into its components without searching the system. This is useful for
142-
inspecting what a spec means or for building tools on top of py-discovery.
142+
inspecting what a spec means or for building tools on top of python-discovery.
143143

144144
.. mermaid::
145145

@@ -157,7 +157,7 @@ inspecting what a spec means or for building tools on top of py-discovery.
157157

158158
.. code-block:: python
159159
160-
from py_discovery import PythonSpec
160+
from python_discovery import PythonSpec
161161
162162
spec = PythonSpec.from_string_spec("cpython3.12t-64-arm64")
163163
spec.implementation # "cpython"
@@ -175,6 +175,6 @@ Every call will run a subprocess to query the interpreter, so this is slower for
175175

176176
.. code-block:: python
177177
178-
from py_discovery import get_interpreter
178+
from python_discovery import get_interpreter
179179
180180
result = get_interpreter("python3.12")

0 commit comments

Comments
 (0)