Skip to content

Commit

Permalink
Use module.__dict__ instead of __all__, filtering out keys that start…
Browse files Browse the repository at this point in the history
… with '_'

This is less astonishing.

CI-17
  • Loading branch information
Jesse Myers committed Nov 22, 2012
1 parent b18f047 commit 1ed9e4a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,14 @@ the default confab console script:
so that given an environment named "foo" and a role named "bar", configuration data would be
merged between **default.py**, **foo.py**, and **bar.py**.

Confab uses the convention that each module's *__all__* value defines its data, e.g.:

__all__ = {'foo': 'bar'}
Confab uses the *__dict__*, but filters out any entries starting with '_' e.g.:

foo = 'bar'
_ignore = this'
Results in:

{'foo': 'bar'}

- Generated and remote configuration files will always be saved to a directory named after
the fully qualified domain name (FQDN) of the target host.
Expand Down
5 changes: 2 additions & 3 deletions confab/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ def import_configuration(module_name, data_dir):
"""
Load configuration from file as python module.
Treats module's __all__ value as the configuration dictionary.
Returns publicly names values in module's __dict__.
"""

# use __all__ as the module's dictionary
def as_dict(module):
try:
return module.__all__
return {k: v for k, v in module.__dict__.iteritems() if not k[0:1] == '_'}
except AttributeError:
return None

Expand Down

0 comments on commit 1ed9e4a

Please sign in to comment.