From 287fe1bfbfde7255a926774f84576c45c7d5c055 Mon Sep 17 00:00:00 2001 From: Dave Hunt Date: Wed, 1 Aug 2018 17:29:12 +0100 Subject: [PATCH] Replace deprecated implprefix from pluggy with HookimplMarker --- docs/plugins.rst | 5 +++++ src/pypom/__init__.py | 3 +++ src/pypom/newsfragments/90.bugfix | 18 ++++++++++++++++++ src/pypom/view.py | 2 +- 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/pypom/newsfragments/90.bugfix diff --git a/docs/plugins.rst b/docs/plugins.rst index 54a44d4..7c5863c 100644 --- a/docs/plugins.rst +++ b/docs/plugins.rst @@ -23,10 +23,15 @@ Then, in your package implement one or more of the plugin :ref:`hooks` provided by PyPOM. The following example will take a screenshot whenever a page or region has finished loading:: + + from pypom import hookimpl + + @hookimpl def pypom_after_wait_for_page_to_load(page): page.selenium.get_screenshot_as_file(page.__class__.__name__ + '.png') + @hookimpl def pypom_after_wait_for_region_to_load(region): region.root.screenshot(region.__class__.__name__ + '.png') diff --git a/src/pypom/__init__.py b/src/pypom/__init__.py index cfa8df6..68c7b0e 100644 --- a/src/pypom/__init__.py +++ b/src/pypom/__init__.py @@ -1,6 +1,7 @@ from .page import Page # noqa from .region import Region # noqa +import pluggy import selenium # noqa # register selenium support @@ -16,3 +17,5 @@ from .splinter_driver import register as registerSplinter registerSplinter() + +hookimpl = pluggy.HookimplMarker("pypom") diff --git a/src/pypom/newsfragments/90.bugfix b/src/pypom/newsfragments/90.bugfix new file mode 100644 index 0000000..9000f82 --- /dev/null +++ b/src/pypom/newsfragments/90.bugfix @@ -0,0 +1,18 @@ +Replace use of ``implprefix`` with ``HookimplMarker`` due to deprecation. + +Existing PyPOM plugins will need to be updated to import the `hookimpl` and use +it to decorate hook implementations rather than rely on the prefix of the +function names. + +Before:: + + def pypom_after_wait_for_page_to_load(page): + pass + +After:: + + from pypom import hookimpl + + @hookimpl + def pypom_after_wait_for_page_to_load(page): + pass diff --git a/src/pypom/view.py b/src/pypom/view.py index 9e893c5..481a289 100644 --- a/src/pypom/view.py +++ b/src/pypom/view.py @@ -18,7 +18,7 @@ def __init__(self, driver, timeout, pm=None): self.timeout = timeout self.pm = pm if self.pm is None: - self.pm = PluginManager("pypom", implprefix="pypom_") + self.pm = PluginManager("pypom") self.pm.add_hookspecs(hooks) self.pm.load_setuptools_entrypoints("pypom.plugin") self.pm.check_pending()