Skip to content
This repository was archived by the owner on Feb 11, 2023. It is now read-only.

Commit e7ccdc0

Browse files
committed
* Make Section.dispatch_event part of public interface
* Update for hookery 1.*
1 parent af3fa48 commit e7ccdc0

File tree

6 files changed

+27
-23
lines changed

6 files changed

+27
-23
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 1.30.0
2+
current_version = 1.31.0
33
commit = true
44
tag = false
55

configmanager/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
__version__ = '1.30.0'
1+
__version__ = '1.31.0'
22

33
from .managers import Config
44
from .items import Item

configmanager/items.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ def set(self, value):
229229
return
230230

231231
if self.section:
232-
self.section._trigger_event(
232+
self.section.dispatch_event(
233233
self.section.hooks.item_value_changed,
234234
item=self,
235235
old_value=old_value,
@@ -255,7 +255,7 @@ def reset(self):
255255
return
256256

257257
if self.section:
258-
self.section._trigger_event(
258+
self.section.dispatch_event(
259259
self.section.hooks.item_value_changed,
260260
item=self,
261261
old_value=old_value,

configmanager/sections.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ def _get_item_or_section(self, key, handle_not_found=True):
205205
resolution = self._tree[key]
206206
else:
207207
if handle_not_found:
208-
result = self._trigger_event(self.hooks.not_found, name=key, section=self)
208+
result = self.dispatch_event(self.hooks.not_found, name=key, section=self)
209209
if result is not None:
210210
resolution = result
211211
else:
@@ -314,7 +314,7 @@ def add_item(self, alias, item):
314314

315315
item._section = self
316316

317-
self._trigger_event(self.hooks.item_added_to_section, alias=alias, section=self, subject=item)
317+
self.dispatch_event(self.hooks.item_added_to_section, alias=alias, section=self, subject=item)
318318

319319
def add_section(self, alias, section):
320320
"""
@@ -334,7 +334,7 @@ def add_section(self, alias, section):
334334
section._section = self
335335
section._section_alias = alias
336336

337-
self._trigger_event(self.hooks.section_added_to_section, alias=alias, section=self, subject=section)
337+
self.dispatch_event(self.hooks.section_added_to_section, alias=alias, section=self, subject=section)
338338

339339
def _get_str_path_separator(self, override=None):
340340
if override is None or override is not_set:
@@ -695,28 +695,32 @@ def _hook_registered(self):
695695
if self.settings.hooks_enabled is None:
696696
self.settings.hooks_enabled = True
697697

698-
def _trigger_event(self, event_, **kwargs):
698+
def dispatch_event(self, event_, **kwargs):
699699
"""
700+
Dispatch section event.
701+
700702
Notes:
701-
If hooks are disabled in a high-in-the-tree Config, and enabled
702-
in one of its descendant Configs, events will still be handled in
703-
the lower Config.
703+
You MUST NOT call event.trigger() directly because
704+
it will circumvent the section settings as well
705+
as ignore the section tree.
704706
707+
If hooks are disabled somewhere up in the tree, and enabled
708+
down below, events will still be dispatched down below because
709+
that's where they originate.
705710
"""
706-
707711
if self.settings.hooks_enabled:
708-
result = self.hooks.handle(event_, **kwargs)
712+
result = self.hooks.dispatch_event(event_, **kwargs)
709713
if result is not None:
710714
return result
711715

712-
# Must also call hooks in parent section
716+
# Must also dispatch the event in parent section
713717
if self.section:
714-
return self.section._trigger_event(event_, **kwargs)
718+
return self.section.dispatch_event(event_, **kwargs)
715719

716720
elif self.section:
717-
# Settings only apply to one section, so must still let
718-
# parent sections trigger the event
719-
self.section._trigger_event(event_, **kwargs)
721+
# Settings only apply to one section, so must still
722+
# dispatch the event in parent sections recursively.
723+
self.section.dispatch_event(event_, **kwargs)
720724

721725

722726
class PathProxy(object):
@@ -730,4 +734,4 @@ def _get_real_object(self):
730734
return self.__path_target
731735

732736
def __getattr__(self, name):
733-
return getattr(self._get_real_object(), name)
737+
return getattr(self._get_real_object(), name)

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
#
22
# Real dependencies
33
#
4-
six==1.10.0
5-
future==0.16.0
6-
hookery<0.4.0
4+
six ==1.10.0
5+
future ==0.16.0
6+
hookery >=1.1.1, <=2.0.0
77

88
#
99
# Potentially optional dependencies

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def read(fname):
2626
description='Forget about configparser, YAML, or JSON parsers. Focus on configuration.',
2727
long_description=read('README.rst'),
2828
packages=['configmanager'],
29-
install_requires=['six==1.10.0', 'future==0.16.0', 'configparser==3.5.0', 'hookery==0.3.2'],
29+
install_requires=['six==1.10.0', 'future==0.16.0', 'configparser==3.5.0', 'hookery >=1.1.1, <=2.0.0'],
3030
extras_require={
3131
'yaml': ['PyYAML'],
3232
'click': ['click'],

0 commit comments

Comments
 (0)