Skip to content

Commit

Permalink
Merge pull request #471 from bluetech/unblock
Browse files Browse the repository at this point in the history
Add `PluginManager.unblock` method to unblock a name
  • Loading branch information
bluetech committed Jan 24, 2024
2 parents 3a28b4d + 13b3661 commit ebeb2f2
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/pluggy/_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,16 @@ def is_blocked(self, name: str) -> bool:
"""Return whether the given plugin name is blocked."""
return name in self._name2plugin and self._name2plugin[name] is None

def unblock(self, name: str) -> bool:
"""Unblocks a name.
Returns whether the name was actually blocked.
"""
if self._name2plugin.get(name, -1) is None:
del self._name2plugin[name]
return True
return False

def add_hookspecs(self, module_or_class: _Namespace) -> None:
"""Add new hook specifications defined in the given ``module_or_class``.
Expand Down
7 changes: 7 additions & 0 deletions testing/test_pluginmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,13 @@ class A:
pm.unregister(name="somename")
assert pm.is_blocked("somename")

# Unblock.
assert not pm.unblock("someothername")
assert pm.unblock("somename")
assert not pm.is_blocked("somename")
assert not pm.unblock("somename")
assert pm.register(A(), "somename")


def test_register_mismatch_method(he_pm: PluginManager) -> None:
class hello:
Expand Down

0 comments on commit ebeb2f2

Please sign in to comment.