From 845e739380c27be5e305af99f501fdfae233132f Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 17 Sep 2022 15:51:03 -0400 Subject: [PATCH 1/4] Add test to ensure varnames are calculated correctly. Ref #596. --- conftest.py | 2 -- keyring/devpi_client.py | 8 ++++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/conftest.py b/conftest.py index ab0021e0..2dce06d4 100644 --- a/conftest.py +++ b/conftest.py @@ -19,5 +19,3 @@ def macos_api_ignore(): collect_ignore.extend(['keyring/backends/macOS/api.py'] * macos_api_ignore()) - -collect_ignore.append('keyring/devpi_client.py') diff --git a/keyring/devpi_client.py b/keyring/devpi_client.py index dfc02452..33003d4c 100644 --- a/keyring/devpi_client.py +++ b/keyring/devpi_client.py @@ -1,12 +1,12 @@ import contextlib -from pluggy import HookimplMarker +import pluggy import keyring from keyring.errors import KeyringError -hookimpl = HookimplMarker("devpiclient") +hookimpl = pluggy.HookimplMarker("devpiclient") # https://github.com/jaraco/jaraco.context/blob/c3a9b739/jaraco/context.py#L205 @@ -16,4 +16,8 @@ @hookimpl() @suppress(KeyringError) def devpiclient_get_password(url, username): + """ + >>> pluggy._hooks.varnames(devpiclient_get_password) + (('url', 'username'), ()) + """ return keyring.get_password(url, username) From 1dc13e5d965077ae430c0559d9c514463bafacd5 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 17 Sep 2022 15:53:46 -0400 Subject: [PATCH 2/4] Add workaround for pytest-dev/pluggy#358. Fixes #596. --- CHANGES.rst | 5 +++++ keyring/devpi_client.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index cc050eaf..3259ca83 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,8 @@ +v23.9.3 +------- + +* #596: Add workaround for devpi_client hook with wrapped implementation. + v23.9.2 ------- diff --git a/keyring/devpi_client.py b/keyring/devpi_client.py index 33003d4c..9d97ed36 100644 --- a/keyring/devpi_client.py +++ b/keyring/devpi_client.py @@ -13,7 +13,16 @@ suppress = type('suppress', (contextlib.suppress, contextlib.ContextDecorator), {}) +def restore_signature(func): + # workaround for pytest-dev/pluggy#358 + def wrapper(url, username): + return func(url, username) + + return wrapper + + @hookimpl() +@restore_signature @suppress(KeyringError) def devpiclient_get_password(url, username): """ From 002de2d5a4f44c0c0be00ff97dcfa70bb8120f26 Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 17 Sep 2022 16:04:23 -0400 Subject: [PATCH 3/4] Also use functools.wraps on the wrapper in case the hook machinery relies on the name of the function. --- keyring/devpi_client.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/keyring/devpi_client.py b/keyring/devpi_client.py index 9d97ed36..72dfd507 100644 --- a/keyring/devpi_client.py +++ b/keyring/devpi_client.py @@ -1,4 +1,5 @@ import contextlib +import functools import pluggy @@ -15,6 +16,7 @@ def restore_signature(func): # workaround for pytest-dev/pluggy#358 + @functools.wraps(func) def wrapper(url, username): return func(url, username) @@ -28,5 +30,6 @@ def devpiclient_get_password(url, username): """ >>> pluggy._hooks.varnames(devpiclient_get_password) (('url', 'username'), ()) + >>> """ return keyring.get_password(url, username) From d666c5c818fbfc00f642cfeb24cb90aab94035cd Mon Sep 17 00:00:00 2001 From: "Jason R. Coombs" Date: Sat, 17 Sep 2022 16:05:30 -0400 Subject: [PATCH 4/4] Remove superfluous import by using the exception from the namespace. --- keyring/devpi_client.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/keyring/devpi_client.py b/keyring/devpi_client.py index 72dfd507..6a2b1898 100644 --- a/keyring/devpi_client.py +++ b/keyring/devpi_client.py @@ -3,8 +3,7 @@ import pluggy -import keyring -from keyring.errors import KeyringError +import keyring.errors hookimpl = pluggy.HookimplMarker("devpiclient") @@ -25,7 +24,7 @@ def wrapper(url, username): @hookimpl() @restore_signature -@suppress(KeyringError) +@suppress(keyring.errors.KeyringError) def devpiclient_get_password(url, username): """ >>> pluggy._hooks.varnames(devpiclient_get_password)