Skip to content

chore(structure): split hook modules into role-specific files - #6

Merged
RonnyPfannschmidt merged 1 commit into
mainfrom
refactor/split-hook-modules
Sep 24, 2026
Merged

RonnyPfannschmidt merged 1 commit into
mainfrom
refactor/split-hook-modules

Conversation

@RonnyPfannschmidt

@RonnyPfannschmidt RonnyPfannschmidt commented Jul 24, 2026 •

Copy link
Copy Markdown
Owner

Written by Grok 4.5 via Cursor for the pluggy maintainers; I prompted it, it did the work, I read it.

Review PR — step 1 of 7.

This PR targets the previous step's branch, so its diff is only this step's change. Review happens here. The corresponding upstream PR, which is the one that actually merges, is pytest-dev#703.

Merges happen upstream one step at a time, bottom-up. When step 1 lands upstream, this PR is closed and the rest of the stack is rebased onto the new main.

Step Branch Review (downstream) Merge (upstream)
1 refactor/split-hook-modules #6 pytest-dev#703 ←
2 refactor/configuration-objects #5 pytest-dev#704
3 refactor/markers-attach-config #7 pytest-dev#706
4 refactor/hookimpl-wrapper-types #8 pytest-dev#707
5 refactor/hookcaller-and-execution #9 pytest-dev#708
6 refactor/project-spec #10 pytest-dev#709
7 refactor/async-submitter #11 pytest-dev#710

Chain step 01 of the internal-refactoring series.

Splits _hooks.py into role-specific modules (_config, _decorators, _caller, _impl, _execution) with _hooks.py kept as a compat re-export layer.

Part of the stacked chain: each PR in this chain targets the previous step's branch so it shows only its own diff. The full-diff PRs against pytest-dev/pluggy link back here.

Summary by Sourcery

Split the monolithic internal hooks module into role-specific modules while preserving backward-compatible re-exports.

Enhancements:

  • Factor hook specification/implementation configuration types into a dedicated _config module.
  • Extract hook markers, specifications, and helper utilities into a new _decorators module.
  • Extract hook caller and relay logic into a new _caller module.
  • Extract hook implementation representation into a new _impl module.
  • Extract multicall execution and wrapper teardown handling into a new _execution module.
  • Update _hooks and _callers to act as thin compatibility layers that re-export symbols from the new modules.

@sourcery-ai

sourcery-ai Bot commented Jul 24, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Refactors pluggy’s internal hook machinery into role-specific modules while preserving the original public surface via re-export shims for backward compatibility.

File-Level Changes

Change Details Files
Split monolithic _hooks.py into role-focused modules and turn _hooks.py into a compatibility re-export layer.
  • Remove inlined hook types, markers, caller, spec, and implementation classes from _hooks.py.
  • Introduce new modules for configuration, decorators/specs, callers/relay, implementations, and execution.
  • Update _hooks.py to import from the new modules and define a consolidated all for the legacy import path.
src/pluggy/_hooks.py
src/pluggy/_config.py
src/pluggy/_decorators.py
src/pluggy/_caller.py
src/pluggy/_implementation.py
src/pluggy/_execution.py
Extract hook execution (multicall and wrapper machinery) into a dedicated _execution module and keep _callers.py as a thin re-export shim.
  • Move Teardown type alias, run_old_style_hookwrapper, _raise_wrapfail, _warn_teardown_exception, and _multicall into _execution.py.
  • Simplify _callers.py to import the execution helpers from _execution and re-export them via all.
  • Preserve existing behaviour and signatures while only changing where functionality lives.
src/pluggy/_callers.py
src/pluggy/_execution.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="src/pluggy/_caller.py" line_range="271" />
<code_context>
+    """A proxy to another HookCaller which manages calls to all registered
+    plugins except the ones from remove_plugins."""
+
+    # This class is unusual: in inhertits from `HookCaller` so all of
+    # the *code* runs in the class, but it delegates all underlying *data*
+    # to the original HookCaller.
</code_context>
<issue_to_address>
**nitpick (typo):** Fix typo in comment: "inhertits" should be "inherits".

Please fix the spelling here so the comment remains clear for future maintainers, given it documents a subtle design choice.

```suggestion
    # This class is unusual: it inherits from `HookCaller` so all of
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread src/pluggy/_caller.py
"""A proxy to another HookCaller which manages calls to all registered
plugins except the ones from remove_plugins."""

# This class is unusual: in inhertits from `HookCaller` so all of

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick (typo): Fix typo in comment: "inhertits" should be "inherits".

Please fix the spelling here so the comment remains clear for future maintainers, given it documents a subtle design choice.

Suggested change
# This class is unusual: in inhertits from `HookCaller` so all of
# This class is unusual: it inherits from `HookCaller` so all of

@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the refactor/split-hook-modules branch from 8c3f2f7 to 7489fdb Compare July 24, 2026 16:53
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the refactor/split-hook-modules branch 3 times, most recently from f795cf2 to fcece74 Compare August 12, 2026 11:14
@RonnyPfannschmidt
RonnyPfannschmidt added this pull request to stack #12 September 12, 2026 18:31
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the refactor/split-hook-modules branch 2 times, most recently from 451ce94 to d1439c6 Compare September 12, 2026 19:14
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the refactor/split-hook-modules branch 2 times, most recently from 2c009ff to 4e3e55a Compare September 23, 2026 05:57
Move hook types, markers, callers, implementations, and multicall out of
the monolithic _hooks/_callers modules so later typed-config and
CompletionHook work can land without thrashing one huge file. Keep
_hooks and _callers as re-export shims for import compatibility.

Co-authored-by: Cursor AI <ai@cursor.sh>
Co-authored-by: Cursor Grok 4.5 <grok@cursor.com>
@RonnyPfannschmidt
RonnyPfannschmidt force-pushed the refactor/split-hook-modules branch from 4e3e55a to 17d4ee9 Compare September 24, 2026 11:24
@RonnyPfannschmidt
RonnyPfannschmidt merged commit f91048b into main Sep 24, 2026
15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant