diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 384338f3..e59642e3 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -63,7 +63,7 @@ repos: attrs>=21.3.0, click, optree, - pluggy, + pluggy>=1.3.0, rich, sqlalchemy>2, types-setuptools, diff --git a/docs/source/_static/md/capture.md b/docs/source/_static/md/capture.md index 4d65089c..71b710bc 100644 --- a/docs/source/_static/md/capture.md +++ b/docs/source/_static/md/capture.md @@ -4,7 +4,7 @@ $ pytask ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 2 tasks. diff --git a/docs/source/_static/md/clean-dry-run-directories.md b/docs/source/_static/md/clean-dry-run-directories.md index c73ed9ee..85cdbff9 100644 --- a/docs/source/_static/md/clean-dry-run-directories.md +++ b/docs/source/_static/md/clean-dry-run-directories.md @@ -4,7 +4,7 @@ $ pytask clean --directories ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/_static/md/clean-dry-run.md b/docs/source/_static/md/clean-dry-run.md index a128bfc4..8c11fad8 100644 --- a/docs/source/_static/md/clean-dry-run.md +++ b/docs/source/_static/md/clean-dry-run.md @@ -4,7 +4,7 @@ $ pytask clean ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/_static/md/collect-nodes.md b/docs/source/_static/md/collect-nodes.md index d5659f78..6587f300 100644 --- a/docs/source/_static/md/collect-nodes.md +++ b/docs/source/_static/md/collect-nodes.md @@ -4,7 +4,7 @@ $ pytask ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/_static/md/collect.md b/docs/source/_static/md/collect.md index 0683a6b8..3604a872 100644 --- a/docs/source/_static/md/collect.md +++ b/docs/source/_static/md/collect.md @@ -4,7 +4,7 @@ $ pytask ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/_static/md/defining-dependencies-products.md b/docs/source/_static/md/defining-dependencies-products.md index 6e734b0e..735967af 100644 --- a/docs/source/_static/md/defining-dependencies-products.md +++ b/docs/source/_static/md/defining-dependencies-products.md @@ -4,7 +4,7 @@ $ pytask ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 2 task. diff --git a/docs/source/_static/md/dry-run.md b/docs/source/_static/md/dry-run.md index 2483e83b..67d6239d 100644 --- a/docs/source/_static/md/dry-run.md +++ b/docs/source/_static/md/dry-run.md @@ -4,7 +4,7 @@ $ pytask --dry-run ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/_static/md/migrating-from-scripts-to-pytask.md b/docs/source/_static/md/migrating-from-scripts-to-pytask.md index 7137b27e..e67d163a 100644 --- a/docs/source/_static/md/migrating-from-scripts-to-pytask.md +++ b/docs/source/_static/md/migrating-from-scripts-to-pytask.md @@ -4,7 +4,7 @@ $ pytask ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/_static/md/pdb.md b/docs/source/_static/md/pdb.md index b606a6a3..ed2164e0 100644 --- a/docs/source/_static/md/pdb.md +++ b/docs/source/_static/md/pdb.md @@ -4,7 +4,7 @@ $ pytask --pdb ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/_static/md/persist-executed.md b/docs/source/_static/md/persist-executed.md index 3cfd5494..4565c85a 100644 --- a/docs/source/_static/md/persist-executed.md +++ b/docs/source/_static/md/persist-executed.md @@ -4,7 +4,7 @@ $ pytask ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/_static/md/persist-persisted.md b/docs/source/_static/md/persist-persisted.md index 0ddc7ec3..ca6662b8 100644 --- a/docs/source/_static/md/persist-persisted.md +++ b/docs/source/_static/md/persist-persisted.md @@ -4,7 +4,7 @@ $ pytask ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/_static/md/persist-skipped.md b/docs/source/_static/md/persist-skipped.md index 827682bb..4a80cdee 100644 --- a/docs/source/_static/md/persist-skipped.md +++ b/docs/source/_static/md/persist-skipped.md @@ -4,7 +4,7 @@ $ pytask --verbose 2 ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/_static/md/profiling-tasks.md b/docs/source/_static/md/profiling-tasks.md index d86e4a6e..e65a6fd4 100644 --- a/docs/source/_static/md/profiling-tasks.md +++ b/docs/source/_static/md/profiling-tasks.md @@ -4,7 +4,7 @@ $ pytask profile ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 18 task. diff --git a/docs/source/_static/md/readme.md b/docs/source/_static/md/readme.md index f309eb1f..63229c53 100644 --- a/docs/source/_static/md/readme.md +++ b/docs/source/_static/md/readme.md @@ -4,7 +4,7 @@ $ pytask ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/_static/md/repeating-tasks.md b/docs/source/_static/md/repeating-tasks.md index 967eb094..74baa72d 100644 --- a/docs/source/_static/md/repeating-tasks.md +++ b/docs/source/_static/md/repeating-tasks.md @@ -4,7 +4,7 @@ $ pytask ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 10 task. diff --git a/docs/source/_static/md/show-locals.md b/docs/source/_static/md/show-locals.md index 0c681d8f..4e10652f 100644 --- a/docs/source/_static/md/show-locals.md +++ b/docs/source/_static/md/show-locals.md @@ -4,7 +4,7 @@ $ pytask --show-locals ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/_static/md/trace.md b/docs/source/_static/md/trace.md index 3a99c1e5..dd802bd2 100644 --- a/docs/source/_static/md/trace.md +++ b/docs/source/_static/md/trace.md @@ -4,7 +4,7 @@ $ pytask --trace ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/_static/md/try-first.md b/docs/source/_static/md/try-first.md index e25b31a1..e00880e1 100644 --- a/docs/source/_static/md/try-first.md +++ b/docs/source/_static/md/try-first.md @@ -4,7 +4,7 @@ $ pytask -s ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 2 task. diff --git a/docs/source/_static/md/try-last.md b/docs/source/_static/md/try-last.md index 1e8f1fc4..fee1d2a1 100644 --- a/docs/source/_static/md/try-last.md +++ b/docs/source/_static/md/try-last.md @@ -4,7 +4,7 @@ $ pytask -s ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 2 task. diff --git a/docs/source/_static/md/warning.md b/docs/source/_static/md/warning.md index 987cdfc0..ef7814fb 100644 --- a/docs/source/_static/md/warning.md +++ b/docs/source/_static/md/warning.md @@ -4,7 +4,7 @@ $ pytask ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/_static/md/write-a-task.md b/docs/source/_static/md/write-a-task.md index 817149c3..93d74ea2 100644 --- a/docs/source/_static/md/write-a-task.md +++ b/docs/source/_static/md/write-a-task.md @@ -4,7 +4,7 @@ $ pytask ──────────────────────────── Start pytask session ──────────────────────────── -Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.0.0 +Platform: win32 -- Python 3.10.0, pytask 0.4.0, pluggy 1.3.0 Root: C:\Users\pytask-dev\git\my_project Collected 1 task. diff --git a/docs/source/changes.md b/docs/source/changes.md index c22df635..a950e4d7 100644 --- a/docs/source/changes.md +++ b/docs/source/changes.md @@ -15,6 +15,7 @@ releases are available on [PyPI](https://pypi.org/project/pytask) and - {pull}`553` deprecates `paths` as a string in configuration and ensures that paths passed via the command line are relative to CWD and paths in the configuration relative to the config file. +- {pull}`555` uses new-style hook wrappers and requires pluggy 1.3 for typing. ## 0.4.5 - 2024-01-09 diff --git a/environment.yml b/environment.yml index 7074be72..1cd3b6fa 100644 --- a/environment.yml +++ b/environment.yml @@ -15,7 +15,7 @@ dependencies: - click - click-default-group - networkx >=2.4 - - pluggy >=1.0.0 + - pluggy >=1.3.0 - optree >=0.9 - rich - sqlalchemy >=2 diff --git a/pyproject.toml b/pyproject.toml index 61b30ca9..7e5aa4f3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -34,7 +34,7 @@ dependencies = [ "networkx>=2.4", "optree>=0.9", "packaging", - "pluggy>=1", + "pluggy>=1.3.0", "rich", "sqlalchemy>=2", 'tomli>=1; python_version < "3.11"', diff --git a/src/_pytask/capture.py b/src/_pytask/capture.py index 520cd7d5..006d8db1 100644 --- a/src/_pytask/capture.py +++ b/src/_pytask/capture.py @@ -724,33 +724,33 @@ def task_capture(self, when: str, task: PTask) -> Generator[None, None, None]: finally: self.suspend(in_=False) - out, err = self.read() - if out: - task.report_sections.append((when, "stdout", out)) - if err: - task.report_sections.append((when, "stderr", err)) + out, err = self.read() + if out: + task.report_sections.append((when, "stdout", out)) + if err: + task.report_sections.append((when, "stderr", err)) # Hooks - @hookimpl(hookwrapper=True) + @hookimpl(wrapper=True) def pytask_execute_task_setup(self, task: PTask) -> Generator[None, None, None]: """Capture output during setup.""" with self.task_capture("setup", task): - yield + return (yield) - @hookimpl(hookwrapper=True) + @hookimpl(wrapper=True) def pytask_execute_task(self, task: PTask) -> Generator[None, None, None]: """Capture output during execution.""" with self.task_capture("call", task): - yield + return (yield) - @hookimpl(hookwrapper=True) + @hookimpl(wrapper=True) def pytask_execute_task_teardown(self, task: PTask) -> Generator[None, None, None]: """Capture output during teardown.""" with self.task_capture("teardown", task): - yield + return (yield) - @hookimpl(hookwrapper=True) + @hookimpl(wrapper=True) def pytask_collect_log(self) -> Generator[None, None, None]: """Suspend capturing at the end of the collection. @@ -763,4 +763,4 @@ def pytask_collect_log(self) -> Generator[None, None, None]: """ self.suspend(in_=True) - yield + return (yield) diff --git a/src/_pytask/debugging.py b/src/_pytask/debugging.py index c95f79d3..88eaef5c 100644 --- a/src/_pytask/debugging.py +++ b/src/_pytask/debugging.py @@ -309,14 +309,14 @@ class PdbDebugger: """Namespace for debugging.""" @staticmethod - @hookimpl(hookwrapper=True) + @hookimpl(wrapper=True) def pytask_execute_task( session: Session, task: PTask ) -> Generator[None, None, None]: """Execute a task by wrapping the function with post-mortem debugger.""" if isinstance(task, PTask): wrap_function_for_post_mortem_debugging(session, task) - yield + return (yield) def wrap_function_for_post_mortem_debugging(session: Session, task: PTask) -> None: @@ -369,14 +369,14 @@ class PdbTrace: """Namespace for tracing.""" @staticmethod - @hookimpl(hookwrapper=True) + @hookimpl(wrapper=True) def pytask_execute_task( session: Session, task: PTask ) -> Generator[None, None, None]: """Wrap the task function with a tracer.""" if isinstance(task, PTask): wrap_function_for_tracing(session, task) - yield + return (yield) def wrap_function_for_tracing(session: Session, task: PTask) -> None: diff --git a/src/_pytask/live.py b/src/_pytask/live.py index 191dc6de..7cd616da 100644 --- a/src/_pytask/live.py +++ b/src/_pytask/live.py @@ -69,14 +69,13 @@ def pytask_post_parse(config: dict[str, Any]) -> None: config["pm"].register(live_collection, "live_collection") -@hookimpl(hookwrapper=True) +@hookimpl(wrapper=True) def pytask_execute(session: Session) -> Generator[None, None, None]: if session.config["verbose"] >= 1: live_execution = session.config["pm"].get_plugin("live_execution") if live_execution: live_execution.n_tasks = len(session.tasks) - - yield + return (yield) @define(eq=False) @@ -147,17 +146,18 @@ class LiveExecution: _reports: list[_ReportEntry] = field(factory=list) _running_tasks: dict[str, PTask] = field(factory=dict) - @hookimpl(hookwrapper=True) + @hookimpl(wrapper=True) def pytask_execute_build(self) -> Generator[None, None, None]: """Wrap the execution with the live manager and yield a table at the end.""" self.live_manager.start() - yield + result = yield self.live_manager.stop(transient=True) table = self._generate_table( reduce_table=False, sort_table=self.sort_final_table, add_caption=False ) if table is not None: console.print(table) + return result @hookimpl(tryfirst=True) def pytask_execute_task_log_start(self, task: PTask) -> bool: @@ -280,11 +280,11 @@ class LiveCollection: _n_collected_tasks: int = 0 _n_errors: int = 0 - @hookimpl(hookwrapper=True) + @hookimpl(wrapper=True) def pytask_collect(self) -> Generator[None, None, None]: """Start the status of the collection.""" self.live_manager.start() - yield + return (yield) @hookimpl def pytask_collect_file_log(self, reports: list[CollectionReport]) -> None: @@ -292,11 +292,11 @@ def pytask_collect_file_log(self, reports: list[CollectionReport]) -> None: self._update_statistics(reports) self._update_status() - @hookimpl(hookwrapper=True) + @hookimpl(wrapper=True) def pytask_collect_log(self) -> Generator[None, None, None]: """Stop the live display when all tasks have been collected.""" self.live_manager.stop(transient=True) - yield + return (yield) def _update_statistics(self, reports: list[CollectionReport]) -> None: """Update the statistics on collected tasks and errors.""" diff --git a/src/_pytask/profile.py b/src/_pytask/profile.py index 9d9ba119..97cbb14d 100644 --- a/src/_pytask/profile.py +++ b/src/_pytask/profile.py @@ -68,13 +68,14 @@ def pytask_post_parse(config: dict[str, Any]) -> None: config["pm"].register(FileSizeNameSpace) -@hookimpl(hookwrapper=True) +@hookimpl(wrapper=True) def pytask_execute_task(task: PTask) -> Generator[None, None, None]: """Attach the duration of the execution to the task.""" start = time.time() - yield + result = yield end = time.time() task.attributes["duration"] = (start, end) + return result @hookimpl diff --git a/src/_pytask/session.py b/src/_pytask/session.py index a28aa2d8..ae772e7a 100644 --- a/src/_pytask/session.py +++ b/src/_pytask/session.py @@ -8,12 +8,7 @@ from _pytask.outcomes import ExitCode from attrs import define from attrs import field - -# HookRelay was published in v1.3. -try: - from pluggy import HookRelay -except ImportError: - from pluggy._hooks import _HookRelay as HookRelay +from pluggy import HookRelay if TYPE_CHECKING: from _pytask.node_protocols import PTask diff --git a/src/_pytask/warnings.py b/src/_pytask/warnings.py index e643c70f..fb09eea9 100644 --- a/src/_pytask/warnings.py +++ b/src/_pytask/warnings.py @@ -57,20 +57,20 @@ class WarningsNameSpace: """A namespace for the warnings plugin.""" @staticmethod - @hookimpl(hookwrapper=True) + @hookimpl(wrapper=True) def pytask_collect(session: Session) -> Generator[None, None, None]: """Catch warnings while executing a task.""" with catch_warnings_for_item(session=session): - yield + return (yield) @staticmethod - @hookimpl(hookwrapper=True) + @hookimpl(wrapper=True) def pytask_execute_task( session: Session, task: PTask ) -> Generator[None, None, None]: """Catch warnings while executing a task.""" with catch_warnings_for_item(session=session, task=task): - yield + return (yield) @staticmethod @hookimpl(trylast=True)