Skip to content

Commit

Permalink
Resolves Issue #590
Browse files Browse the repository at this point in the history
  • Loading branch information
derks committed Oct 1, 2021
1 parent 025f887 commit aaaf242
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

Bugs:

- `[ext.argparse]` Parse (`self._parser`) not accessible inside `_pre_argument_parsing`

- `[ext.argparse]` Parser (`self._parser`) not accessible inside `_pre_argument_parsing` when `stacked_type = 'embedded'`
- [Issue #569](https://github.com/datafolklabs/cement/issues/569)
- `[ext.configparser]` Overriding config options with environment variables doesn't work correctly with surrounding underscore characters
- [Issue #590](https://github.com/datafolklabs/cement/issues/590)

Features:

Expand Down
3 changes: 2 additions & 1 deletion cement/ext/ext_configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ def _get_env_var(self, section, key):
self.app._meta.config_section, section, key)

env_var = env_var.upper()
env_var = re.sub('[^0-9a-zA-Z]+', '_', env_var)
env_var = re.sub('[^0-9a-zA-Z_]+', '_', env_var)
return env_var

def get(self, section, key, **kwargs):
env_var = self._get_env_var(section, key)

if env_var in os.environ.keys():
return os.environ[env_var]
else:
Expand Down
10 changes: 10 additions & 0 deletions tests/ext/test_ext_configparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@ def test_env_var_override():
section_dict = app.config.get_section_dict('dummy')
assert section_dict['foo'] == 'dummy-not-bar'

# issue/590 - don't sub underscores

app.config.set('testapp', '__foo__', 'bar')
env_var = "TESTAPP___FOO__"

os.environ[env_var] = 'not-bar'
assert app.config.get('testapp', '__foo__') == 'not-bar'
section_dict = app.config.get_section_dict('testapp')
assert section_dict['__foo__'] == 'not-bar'


def test_get_boolean():
with TestApp(config_section='testapp') as app:
Expand Down

0 comments on commit aaaf242

Please sign in to comment.