Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .claude/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"permissions": {
"allow": [
"Bash(uv run pytest:*)",
"Bash(git add:*)",
"Bash(uv run mypy:*)",
"Bash(uv run pre-commit:*)"

],
"deny": []
}
}
21 changes: 8 additions & 13 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,11 @@ jobs:
fail-fast: false
matrix:
name: [
"windows-py39",
"windows-py310",
"windows-py313",
"windows-pypy3",

"ubuntu-py310-pytestmain",
"ubuntu-py39",
"ubuntu-py310",
"ubuntu-py311",
"ubuntu-py312",
Expand All @@ -45,32 +44,28 @@ jobs:
]

include:
- name: "windows-py39"
python: "3.9"
- name: "windows-py310"
python: "3.10"
os: windows-latest
tox_env: "py39"
tox_env: "py310"
- name: "windows-py313"
python: "3.13"
os: windows-latest
tox_env: "py313"
- name: "windows-pypy3"
python: "pypy3.9"
python: "pypy3.10"
os: windows-latest
tox_env: "pypy3"
- name: "ubuntu-py310-pytestmain"
python: "3.10"
os: ubuntu-latest
tox_env: "py310-pytestmain"
use_coverage: true
- name: "ubuntu-py39"
python: "3.9"
os: ubuntu-latest
tox_env: "py39"
use_coverage: true
- name: "ubuntu-py310"
python: "3.10"
os: ubuntu-latest
tox_env: "py310"
use_coverage: true
- name: "ubuntu-py311"
python: "3.11"
os: ubuntu-latest
Expand All @@ -87,12 +82,12 @@ jobs:
tox_env: "py313"
use_coverage: true
- name: "ubuntu-pypy3"
python: "pypy3.9"
python: "pypy3.10"
os: ubuntu-latest
tox_env: "pypy3"
use_coverage: true
- name: "ubuntu-benchmark"
python: "3.9"
python: "3.10"
os: ubuntu-latest
tox_env: "benchmark"

Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,6 @@ pip-wheel-metadata/

# pytest-benchmark
.benchmarks/

# Claude Code local settings
.claude/settings.local.json
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ repos:
rev: v3.21.0
hooks:
- id: pyupgrade
args: [--py39-plus]
args: [--py310-plus]
- repo: https://github.com/asottile/blacken-docs
rev: 1.20.0
hooks:
Expand Down
51 changes: 51 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Project Overview

Pluggy is a minimalist production-ready plugin system that serves as the core framework for pytest, datasette and devpi.
It provides hook specification and implementation mechanisms through a plugin manager system.

## Development Commands

All commands use `uv run` for consistent environments.

### Testing
- `uv run pytest` - Run all tests (prefer running all tests for quick feedback)
- `uv run pytest testing/benchmark.py` - Run benchmark tests

### Code Quality
- `uv run pre-commit run -a` - Run all pre-commit hooks (linting, formatting, type checking)
- Always reread files modified by pre-commit

## Development Process

- Always read `src/pluggy/*.py` to get a full picture
- Consider backward compatibility
- Always run all tests: `uv run pytest`
- Always run pre-commit before committing: `uv run pre-commit run -a`
- Prefer running full pre-commit over individual tools (ruff/mypy)



## Core Architecture

### Main Components

- **PluginManager** (`src/pluggy/_manager.py`): Central registry that manages plugins and coordinates hook calls
- **HookCaller** (`src/pluggy/_hooks.py`): Executes hook implementations with proper argument binding
- **HookImpl/HookSpec** (`src/pluggy/_hooks.py`): Represent hook implementations and specifications
- **Result** (`src/pluggy/_result.py`): Handles hook call results and exception propagation
- **Multicall** (`src/pluggy/_callers.py`): Core execution engine for calling multiple hook implementations

### Package Structure
- `src/pluggy/` - Main package source
- `testing/` - Test suite using pytest
- `docs/` - Sphinx documentation and examples
- `changelog/` - Towncrier fragments for changelog generation

## Configuration Files
- `pyproject.toml` - Project metadata, build system, tool configuration (ruff, mypy, setuptools-scm)
- `tox.ini` - Multi-environment testing configuration
- `.pre-commit-config.yaml` - Code quality automation (ruff, mypy, flake8, etc.)
11 changes: 7 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ classifiers = [
"Programming Language :: Python :: Implementation :: PyPy",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3 :: Only",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3.13",
]
description = "plugin and hook calling mechanisms for python"
readme = {file = "README.rst", content-type = "text/x-rst"}
requires-python = ">=3.9"
requires-python = ">=3.10"

dynamic = ["version"]
[project.optional-dependencies]
[dependency-groups]
dev = ["pre-commit", "tox"]
testing = ["pytest", "pytest-benchmark", "coverage"]
testing = ["pytest", "pytest-benchmark", "pytest-cov"]


[tool.setuptools]
packages = ["pluggy"]
Expand Down Expand Up @@ -67,6 +67,9 @@ lines-after-imports = 2

[tool.setuptools_scm]

[tool.uv]
default-groups = ["dev", "testing"]

[tool.towncrier]
package = "pluggy"
package_dir = "src/pluggy"
Expand Down
10 changes: 6 additions & 4 deletions src/pluggy/_callers.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,12 @@ def _raise_wrapfail(
def _warn_teardown_exception(
hook_name: str, hook_impl: HookImpl, e: BaseException
) -> None:
msg = "A plugin raised an exception during an old-style hookwrapper teardown.\n"
msg += f"Plugin: {hook_impl.plugin_name}, Hook: {hook_name}\n"
msg += f"{type(e).__name__}: {e}\n"
msg += "For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning" # noqa: E501
msg = (
f"A plugin raised an exception during an old-style hookwrapper teardown.\n"
f"Plugin: {hook_impl.plugin_name}, Hook: {hook_name}\n"
f"{type(e).__name__}: {e}\n"
f"For more information see https://pluggy.readthedocs.io/en/stable/api_reference.html#pluggy.PluggyTeardownRaisedWarning" # noqa: E501
)
warnings.warn(PluggyTeardownRaisedWarning(msg), stacklevel=6)


Expand Down
44 changes: 44 additions & 0 deletions src/pluggy/_compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""
Compatibility layer for legacy setuptools/pkg_resources API.
This module provides backward compatibility wrappers around modern
importlib.metadata, allowing gradual migration away from setuptools.
"""

from __future__ import annotations

import importlib.metadata
from typing import Any


class DistFacade:
"""Facade providing pkg_resources.Distribution-like interface.
This class wraps importlib.metadata.Distribution to provide a
compatibility layer for code expecting the legacy pkg_resources API.
The primary difference is the ``project_name`` attribute which
pkg_resources provided but importlib.metadata.Distribution does not.
"""

__slots__ = ("_dist",)

def __init__(self, dist: importlib.metadata.Distribution) -> None:
self._dist = dist

@property
def project_name(self) -> str:
"""Get the project name (for pkg_resources compatibility).
This is equivalent to dist.metadata["name"] but matches the
pkg_resources.Distribution.project_name attribute.
"""
name: str = self.metadata["name"]
return name

def __getattr__(self, attr: str) -> Any:
"""Delegate all other attributes to the wrapped Distribution."""
return getattr(self._dist, attr)

def __dir__(self) -> list[str]:
"""List available attributes including facade additions."""
return sorted(dir(self._dist) + ["_dist", "project_name"])
20 changes: 10 additions & 10 deletions src/pluggy/_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import annotations

from collections.abc import Callable
from collections.abc import Generator
from collections.abc import Mapping
from collections.abc import Sequence
Expand All @@ -12,29 +13,26 @@
import sys
from types import ModuleType
from typing import Any
from typing import Callable
from typing import Final
from typing import final
from typing import Optional
from typing import overload
from typing import TYPE_CHECKING
from typing import TypedDict
from typing import TypeVar
from typing import Union
import warnings

from ._result import Result


_T = TypeVar("_T")
_F = TypeVar("_F", bound=Callable[..., object])
_Namespace = Union[ModuleType, type]
_Namespace = ModuleType | type
_Plugin = object
_HookExec = Callable[
[str, Sequence["HookImpl"], Mapping[str, object], bool],
Union[object, list[object]],
object | list[object],
]
_HookImplFunction = Callable[..., Union[_T, Generator[None, Result[_T], None]]]
_HookImplFunction = Callable[..., _T | Generator[None, Result[_T], None]]


class HookspecOpts(TypedDict):
Expand Down Expand Up @@ -374,7 +372,7 @@ def __getattr__(self, name: str) -> HookCaller: ...
_HookRelay = HookRelay


_CallHistory = list[tuple[Mapping[str, object], Optional[Callable[[Any], None]]]]
_CallHistory = list[tuple[Mapping[str, object], Callable[[Any], None] | None]]


class HookCaller:
Expand Down Expand Up @@ -534,9 +532,11 @@ def call_historic(
res = self._hookexec(self.name, self._hookimpls.copy(), kwargs, False)
if result_callback is None:
return
if isinstance(res, list):
for x in res:
result_callback(x)
# Historic hooks are called with firstresult=False and cannot have wrappers,
# so the result is always a list.
assert isinstance(res, list), "historic call should always return a list"
for x in res:
result_callback(x)

def call_extra(
self, methods: Sequence[Callable[..., object]], kwargs: Mapping[str, object]
Expand Down
Loading