Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
Support basic interpolation in INI loader.
Browse files Browse the repository at this point in the history
Closes #27.
  • Loading branch information
inklesspen committed Jun 17, 2015
1 parent b9b3e94 commit 43abc4b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Expand Up @@ -9,6 +9,7 @@ unreleased
* Removed useless console_script entry point.
* Changed loader detection to only consider the final extension in a filename.
* Support and test egg specifications with no named entry point (because it's 'main').
* Support basic interpolation (``here`` and ``__file__``) in the built-in INI loader.

0.2.0 (2015-06-14)
-----------------------------------------
Expand Down
6 changes: 5 additions & 1 deletion src/montague/ini.py
Expand Up @@ -35,6 +35,10 @@ def __init__(self, path):

def _read(self):
# We need to keep the parser around so the logging conversion can use it.
path_defaults = {
'here': os.path.dirname(self.path),
'__file__': self.path,
}
self._parser = SafeConfigParser()
self._parser.read(self.path)
self._globals = self._parser.defaults()
Expand All @@ -45,7 +49,7 @@ def _read(self):
if option in self._globals:
continue
try:
section_data[option] = self._parser.get(section, option)
section_data[option] = self._parser.get(section, option, vars=path_defaults)
except InterpolationError:
section_data[option] = self._parser.get(section, option, raw=True)
return data
Expand Down
2 changes: 2 additions & 0 deletions tests/config_files/simple_config.ini
Expand Up @@ -3,6 +3,8 @@ foo = bar

[application:main]
use = package:montague_testapps#basic_app
ini_dir = %(here)s
ini_file = %(__file__)s

[application:egg]
use = egg:montague_testapps#other
Expand Down
6 changes: 5 additions & 1 deletion tests/test_ini_handling.py
Expand Up @@ -22,7 +22,11 @@ def test_read_config():
'foo': 'bar',
},
'application': {
'main': {'use': 'package:montague_testapps#basic_app'},
'main': {
'use': 'package:montague_testapps#basic_app',
'ini_dir': ini_dir,
'ini_file': ini_path,
},
'egg': {'use': 'egg:montague_testapps#other'},
'filtered-app': {
'filter-with': 'filter',
Expand Down

0 comments on commit 43abc4b

Please sign in to comment.