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

Commit 270f374

Browse files
committed
* Make hook names easier to discover for IDEs
* Docs update
1 parent 990657a commit 270f374

5 files changed

Lines changed: 38 additions & 14 deletions

File tree

.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.29.0
2+
current_version = 1.29.1
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.29.0'
1+
__version__ = '1.29.1'
22

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

configmanager/managers.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ def settings(self):
178178
return self._settings
179179

180180
def tracking_context(self):
181+
"""
182+
Returns:
183+
_TrackingContext
184+
"""
181185
return _TrackingContext(self)
182186

183187
@property
@@ -187,7 +191,7 @@ def configparser(self):
187191
``ConfigParser`` (or the backported configparser module in Python 2).
188192
189193
Returns:
190-
:class:`.ConfigPersistenceAdapter`
194+
ConfigPersistenceAdapter
191195
"""
192196
if self._configparser_adapter is None:
193197
self._configparser_adapter = ConfigPersistenceAdapter(
@@ -204,7 +208,7 @@ def json(self):
204208
Adapter to dump/load JSON format strings and files.
205209
206210
Returns:
207-
:class:`.ConfigPersistenceAdapter`
211+
ConfigPersistenceAdapter
208212
"""
209213
if self._json_adapter is None:
210214
self._json_adapter = ConfigPersistenceAdapter(
@@ -219,7 +223,7 @@ def yaml(self):
219223
Adapter to dump/load YAML format strings and files.
220224
221225
Returns:
222-
:class:`.ConfigPersistenceAdapter`
226+
ConfigPersistenceAdapter
223227
"""
224228
if self._yaml_adapter is None:
225229
self._yaml_adapter = ConfigPersistenceAdapter(
@@ -232,6 +236,9 @@ def yaml(self):
232236
def click(self):
233237
"""
234238
click extension
239+
240+
Returns:
241+
ClickExtension
235242
"""
236243
if self._click_extension is None:
237244
from .click_ext import ClickExtension

configmanager/sections.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222
}
2323

2424

25+
class _SectionHooks(HookRegistry):
26+
def __init__(self, section):
27+
super(_SectionHooks, self).__init__(section)
28+
self.not_found = self.register_event('not_found')
29+
self.item_added_to_section = self.register_event('item_added_to_section')
30+
self.section_added_to_section = self.register_event('section_added_to_section')
31+
self.item_value_changed = self.register_event('item_value_changed')
32+
33+
2534
class Section(BaseSection):
2635
"""
2736
Represents a section consisting of items (instances of :class:`.Item`) and other sections
@@ -43,12 +52,8 @@ def __init__(self, schema=None, section=None):
4352
#: Alias of this section with which it was added to its parent section
4453
self._section_alias = None
4554

46-
#: Hooks registry
47-
self._hooks = HookRegistry(self)
48-
self._hooks.not_found = self._hooks.register_event('not_found')
49-
self._hooks.item_added_to_section = self._hooks.register_event('item_added_to_section')
50-
self._hooks.section_added_to_section = self._hooks.register_event('section_added_to_section')
51-
self._hooks.item_value_changed = self._hooks.register_event('item_value_changed')
55+
# Hooks registry
56+
self._hooks = _SectionHooks(self)
5257

5358
# Listen for hook registration so we can enable per-section hooks only when they
5459
# are actually used.
@@ -257,7 +262,7 @@ def get_proxy(self, *key):
257262
def hooks(self):
258263
"""
259264
Returns:
260-
HookRegistry
265+
_SectionHooks
261266
"""
262267
return self._hooks
263268

docs/index.rst

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,14 @@ to be called when this exception is raised:
326326
327327
If this function returns anything other than ``None``, the exception will not be raised.
328328

329-
How can I track changes of config values?
330-
-----------------------------------------
329+
How do I manage changesets of config values?
330+
--------------------------------------------
331331

332332
.. code-block:: python
333+
:emphasize-lines: 4,7,10,13,14
334+
335+
>>> config.greeting.value
336+
'Hello, world!'
333337
334338
>>> with config.tracking_context() as ctx:
335339
... config.greeting.value = 'Hey, what is up!'
@@ -339,3 +343,11 @@ How can I track changes of config values?
339343
340344
>>> ctx.changes[config.greeting]
341345
'Hey, what is up!'
346+
347+
>>> ctx.reset_changes()
348+
>>> ctx.changes
349+
{}
350+
351+
>>> config.greeting.value
352+
'Hello, world!'
353+

0 commit comments

Comments
 (0)