diff --git a/.bumpversion.cfg b/.bumpversion.cfg index 5ab6b13..3a3522f 100644 --- a/.bumpversion.cfg +++ b/.bumpversion.cfg @@ -1,5 +1,5 @@ [bumpversion] -current_version = 1.30.0 +current_version = 1.31.0 commit = true tag = false diff --git a/configmanager/__init__.py b/configmanager/__init__.py index bf05ff1..c5903c8 100644 --- a/configmanager/__init__.py +++ b/configmanager/__init__.py @@ -1,4 +1,4 @@ -__version__ = '1.30.0' +__version__ = '1.31.0' from .managers import Config from .items import Item diff --git a/configmanager/items.py b/configmanager/items.py index cdc7483..8e04d9f 100644 --- a/configmanager/items.py +++ b/configmanager/items.py @@ -229,7 +229,7 @@ def set(self, value): return if self.section: - self.section._trigger_event( + self.section.dispatch_event( self.section.hooks.item_value_changed, item=self, old_value=old_value, @@ -255,7 +255,7 @@ def reset(self): return if self.section: - self.section._trigger_event( + self.section.dispatch_event( self.section.hooks.item_value_changed, item=self, old_value=old_value, diff --git a/configmanager/sections.py b/configmanager/sections.py index 1868c35..1ebcb2a 100644 --- a/configmanager/sections.py +++ b/configmanager/sections.py @@ -205,7 +205,7 @@ def _get_item_or_section(self, key, handle_not_found=True): resolution = self._tree[key] else: if handle_not_found: - result = self._trigger_event(self.hooks.not_found, name=key, section=self) + result = self.dispatch_event(self.hooks.not_found, name=key, section=self) if result is not None: resolution = result else: @@ -314,7 +314,7 @@ def add_item(self, alias, item): item._section = self - self._trigger_event(self.hooks.item_added_to_section, alias=alias, section=self, subject=item) + self.dispatch_event(self.hooks.item_added_to_section, alias=alias, section=self, subject=item) def add_section(self, alias, section): """ @@ -334,7 +334,7 @@ def add_section(self, alias, section): section._section = self section._section_alias = alias - self._trigger_event(self.hooks.section_added_to_section, alias=alias, section=self, subject=section) + self.dispatch_event(self.hooks.section_added_to_section, alias=alias, section=self, subject=section) def _get_str_path_separator(self, override=None): if override is None or override is not_set: @@ -695,28 +695,32 @@ def _hook_registered(self): if self.settings.hooks_enabled is None: self.settings.hooks_enabled = True - def _trigger_event(self, event_, **kwargs): + def dispatch_event(self, event_, **kwargs): """ + Dispatch section event. + Notes: - If hooks are disabled in a high-in-the-tree Config, and enabled - in one of its descendant Configs, events will still be handled in - the lower Config. + You MUST NOT call event.trigger() directly because + it will circumvent the section settings as well + as ignore the section tree. + If hooks are disabled somewhere up in the tree, and enabled + down below, events will still be dispatched down below because + that's where they originate. """ - if self.settings.hooks_enabled: - result = self.hooks.handle(event_, **kwargs) + result = self.hooks.dispatch_event(event_, **kwargs) if result is not None: return result - # Must also call hooks in parent section + # Must also dispatch the event in parent section if self.section: - return self.section._trigger_event(event_, **kwargs) + return self.section.dispatch_event(event_, **kwargs) elif self.section: - # Settings only apply to one section, so must still let - # parent sections trigger the event - self.section._trigger_event(event_, **kwargs) + # Settings only apply to one section, so must still + # dispatch the event in parent sections recursively. + self.section.dispatch_event(event_, **kwargs) class PathProxy(object): @@ -730,4 +734,4 @@ def _get_real_object(self): return self.__path_target def __getattr__(self, name): - return getattr(self._get_real_object(), name) \ No newline at end of file + return getattr(self._get_real_object(), name) diff --git a/requirements.txt b/requirements.txt index 06d7997..fb4367f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,9 +1,9 @@ # # Real dependencies # -six==1.10.0 -future==0.16.0 -hookery<0.4.0 +six ==1.10.0 +future ==0.16.0 +hookery >=1.1.1, <=2.0.0 # # Potentially optional dependencies diff --git a/setup.py b/setup.py index e924c15..b275eb6 100644 --- a/setup.py +++ b/setup.py @@ -26,7 +26,7 @@ def read(fname): description='Forget about configparser, YAML, or JSON parsers. Focus on configuration.', long_description=read('README.rst'), packages=['configmanager'], - install_requires=['six==1.10.0', 'future==0.16.0', 'configparser==3.5.0', 'hookery==0.3.2'], + install_requires=['six==1.10.0', 'future==0.16.0', 'configparser==3.5.0', 'hookery >=1.1.1, <=2.0.0'], extras_require={ 'yaml': ['PyYAML'], 'click': ['click'],