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

Commit

Permalink
* Make Section.dispatch_event part of public interface
Browse files Browse the repository at this point in the history
* Update for hookery 1.*
  • Loading branch information
jbasko committed Jun 18, 2017
1 parent af3fa48 commit e7ccdc0
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.30.0
current_version = 1.31.0
commit = true
tag = false

Expand Down
2 changes: 1 addition & 1 deletion configmanager/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '1.30.0'
__version__ = '1.31.0'

from .managers import Config
from .items import Item
Expand Down
4 changes: 2 additions & 2 deletions configmanager/items.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
34 changes: 19 additions & 15 deletions configmanager/sections.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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):
"""
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand All @@ -730,4 +734,4 @@ def _get_real_object(self):
return self.__path_target

def __getattr__(self, name):
return getattr(self._get_real_object(), name)
return getattr(self._get_real_object(), name)
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down

0 comments on commit e7ccdc0

Please sign in to comment.