Skip to content

Commit 4ecc541

Browse files
committed
Prefix all internal modules with _ to clarify they're private
Some were already prefixed, but some weren't. This clarifies that pluggy's only public API is what's exported from the top-level `pluggy` module. This will allow internal code to be nicer, not having to defensively prefix internal types and functions with _. Fixes pytest-dev#313.
1 parent 5ca5220 commit 4ecc541

File tree

12 files changed

+41
-38
lines changed

12 files changed

+41
-38
lines changed

changelog/313.removal.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The internal ``pluggy.callers``, ``pluggy.manager`` and ``pluggy.hooks`` are now explicitly marked private by a ``_`` prefix (e.g. ``pluggy._callers``).
2+
Only API exported by the top-level ``pluggy`` module is considered public.

docs/api_reference.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ Api Reference
88
:undoc-members:
99
:show-inheritance:
1010

11-
.. autoclass:: pluggy.callers._Result
12-
.. automethod:: pluggy.callers._Result.get_result
13-
.. automethod:: pluggy.callers._Result.force_result
11+
.. autoclass:: pluggy._callers._Result
12+
.. automethod:: pluggy._callers._Result.get_result
13+
.. automethod:: pluggy._callers._Result.force_result
1414

15-
.. autoclass:: pluggy.hooks._HookCaller
16-
.. automethod:: pluggy.hooks._HookCaller.call_extra
17-
.. automethod:: pluggy.hooks._HookCaller.call_historic
15+
.. autoclass:: pluggy._hooks._HookCaller
16+
.. automethod:: pluggy._hooks._HookCaller.call_extra
17+
.. automethod:: pluggy._hooks._HookCaller.call_historic
1818

19-
.. autoclass:: pluggy.hooks._HookRelay
19+
.. autoclass:: pluggy._hooks._HookRelay

docs/index.rst

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -395,11 +395,11 @@ be implemented as generator function with a single ``yield`` in its body:
395395
if config.use_defaults:
396396
outcome.force_result(defaults)
397397
398-
The generator is :py:meth:`sent <python:generator.send>` a :py:class:`pluggy.callers._Result` object which can
398+
The generator is :py:meth:`sent <python:generator.send>` a :py:class:`pluggy._callers._Result` object which can
399399
be assigned in the ``yield`` expression and used to override or inspect
400400
the final result(s) returned back to the caller using the
401-
:py:meth:`~pluggy.callers._Result.force_result` or
402-
:py:meth:`~pluggy.callers._Result.get_result` methods.
401+
:py:meth:`~pluggy._callers._Result.force_result` or
402+
:py:meth:`~pluggy._callers._Result.get_result` methods.
403403

404404
.. note::
405405
Hook wrappers can **not** return results (as per generator function
@@ -533,7 +533,7 @@ Also see the :ref:`pytest:firstresult` section in the ``pytest`` docs.
533533
Historic hooks
534534
^^^^^^^^^^^^^^
535535
You can mark a *hookspec* as being *historic* meaning that the hook
536-
can be called with :py:meth:`~pluggy.hooks._HookCaller.call_historic()` **before**
536+
can be called with :py:meth:`~pluggy._hooks._HookCaller.call_historic()` **before**
537537
having been registered:
538538

539539
.. code-block:: python
@@ -655,13 +655,13 @@ The core functionality of ``pluggy`` enables an extension provider
655655
to override function calls made at certain points throughout a program.
656656

657657
A particular *hook* is invoked by calling an instance of
658-
a :py:class:`pluggy.hooks._HookCaller` which in turn *loops* through the
658+
a :py:class:`pluggy._hooks._HookCaller` which in turn *loops* through the
659659
``1:N`` registered *hookimpls* and calls them in sequence.
660660

661661
Every :py:class:`~pluggy.PluginManager` has a ``hook`` attribute
662-
which is an instance of this :py:class:`pluggy.hooks._HookRelay`.
663-
The :py:class:`~pluggy.hooks._HookRelay` itself contains references
664-
(by hook name) to each registered *hookimpl*'s :py:class:`~pluggy.hooks._HookCaller` instance.
662+
which is an instance of this :py:class:`pluggy._hooks._HookRelay`.
663+
The :py:class:`~pluggy._hooks._HookRelay` itself contains references
664+
(by hook name) to each registered *hookimpl*'s :py:class:`~pluggy._hooks._HookCaller` instance.
665665

666666
More practically you call a *hook* like so:
667667

@@ -801,7 +801,7 @@ only useful if you expect that some *hookimpls* may be registered **after** the
801801
hook is initially invoked.
802802

803803
Historic hooks must be :ref:`specially marked <historic>` and called
804-
using the :py:meth:`~pluggy.hooks._HookCaller.call_historic()` method:
804+
using the :py:meth:`~pluggy._hooks._HookCaller.call_historic()` method:
805805

806806
.. code-block:: python
807807
@@ -822,8 +822,8 @@ using the :py:meth:`~pluggy.hooks._HookCaller.call_historic()` method:
822822
# historic callback is invoked here
823823
pm.register(mylateplugin)
824824
825-
Note that if you :py:meth:`~pluggy.hooks._HookCaller.call_historic()`
826-
the :py:class:`~pluggy.hooks._HookCaller` (and thus your calling code)
825+
Note that if you :py:meth:`~pluggy._hooks._HookCaller.call_historic()`
826+
the :py:class:`~pluggy.__hooks._HookCaller` (and thus your calling code)
827827
can not receive results back from the underlying *hookimpl* functions.
828828
Instead you can provide a *callback* for processing results (like the
829829
``callback`` function above) which will be called as each new plugin
@@ -838,19 +838,19 @@ Calling with extras
838838
-------------------
839839
You can call a hook with temporarily participating *implementation* functions
840840
(that aren't in the registry) using the
841-
:py:meth:`pluggy.hooks._HookCaller.call_extra()` method.
841+
:py:meth:`pluggy.__hooks._HookCaller.call_extra()` method.
842842

843843

844844
Calling with a subset of registered plugins
845845
-------------------------------------------
846846
You can make a call using a subset of plugins by asking the
847847
:py:class:`~pluggy.PluginManager` first for a
848-
:py:class:`~pluggy.hooks._HookCaller` with those plugins removed
848+
:py:class:`~pluggy.__hooks._HookCaller` with those plugins removed
849849
using the :py:meth:`pluggy.PluginManager.subset_hook_caller()` method.
850850

851-
You then can use that :py:class:`_HookCaller <pluggy.hooks._HookCaller>`
852-
to make normal, :py:meth:`~pluggy.hooks._HookCaller.call_historic`, or
853-
:py:meth:`~pluggy.hooks._HookCaller.call_extra` calls as necessary.
851+
You then can use that :py:class:`_HookCaller <pluggy.__hooks._HookCaller>`
852+
to make normal, :py:meth:`~pluggy.__hooks._HookCaller.call_historic`, or
853+
:py:meth:`~pluggy.__hooks._HookCaller.call_extra` calls as necessary.
854854

855855
Built-in tracing
856856
****************

src/pluggy/__init__.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
"HookimplMarker",
1414
]
1515

16-
from .manager import PluginManager, PluginValidationError
17-
from .callers import HookCallError
18-
from .hooks import HookspecMarker, HookimplMarker
16+
from ._manager import PluginManager, PluginValidationError
17+
from ._callers import HookCallError
18+
from ._hooks import HookspecMarker, HookimplMarker
File renamed without changes.
File renamed without changes.

src/pluggy/manager.py renamed to src/pluggy/_manager.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import inspect
22
import sys
3-
from . import _tracing
4-
from .callers import _Result, _multicall
5-
from .hooks import HookImpl, _HookRelay, _HookCaller, normalize_hookimpl_opts
63
import warnings
74

5+
from . import _tracing
6+
from ._callers import _Result, _multicall
7+
from ._hooks import HookImpl, _HookRelay, _HookCaller, normalize_hookimpl_opts
8+
89
if sys.version_info >= (3, 8):
910
from importlib import metadata as importlib_metadata
1011
else:
@@ -312,7 +313,7 @@ def add_hookcall_monitoring(self, before, after):
312313
of HookImpl instances and the keyword arguments for the hook call.
313314
314315
``after(outcome, hook_name, hook_impls, kwargs)`` receives the
315-
same arguments as ``before`` but also a :py:class:`pluggy.callers._Result` object
316+
same arguments as ``before`` but also a :py:class:`pluggy._callers._Result` object
316317
which represents the result of the overall hook call.
317318
"""
318319
oldcall = self._inner_hookexec

testing/benchmark.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"""
44
import pytest
55
from pluggy import HookspecMarker, HookimplMarker
6-
from pluggy.hooks import HookImpl
7-
from pluggy.callers import _multicall
6+
from pluggy._hooks import HookImpl
7+
from pluggy._callers import _multicall
88

99

1010
hookspec = HookspecMarker("example")

testing/test_helpers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from pluggy.hooks import varnames
2-
from pluggy.manager import _formatdef
1+
from pluggy._hooks import varnames
2+
from pluggy._manager import _formatdef
33

44

55
def test_varnames():

testing/test_hookcaller.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22

33
from pluggy import HookimplMarker, HookspecMarker, PluginValidationError
4-
from pluggy.hooks import HookImpl
4+
from pluggy._hooks import HookImpl
55

66
hookspec = HookspecMarker("example")
77
hookimpl = HookimplMarker("example")

testing/test_multicall.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from pluggy import HookCallError, HookspecMarker, HookimplMarker
3-
from pluggy.hooks import HookImpl
4-
from pluggy.callers import _multicall
3+
from pluggy._hooks import HookImpl
4+
from pluggy._callers import _multicall
55

66

77
hookspec = HookspecMarker("example")

testing/test_pluginmanager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
HookimplMarker,
1010
HookspecMarker,
1111
)
12-
from pluggy.manager import importlib_metadata
12+
from pluggy._manager import importlib_metadata
1313

1414

1515
hookspec = HookspecMarker("example")

0 commit comments

Comments
 (0)