diff --git a/ChangeLog b/ChangeLog index e62b4ab..e8cd9ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,6 +4,11 @@ ChangeLog Next version ------------ +*Bugfix:* + + * Allows to override a configuration containing a dash. + + 1.7.0 (2017-02-23) ------------------ diff --git a/docs/reference.rst b/docs/reference.rst index aa3c4e4..8c3442b 100644 --- a/docs/reference.rst +++ b/docs/reference.rst @@ -32,6 +32,10 @@ The ``ConfigGetter`` class are looked up under ``
_`` instead of ``_
_``; use this setup with care, since getconf might load variables that weren't intended for this application. + .. warning:: Using dash in section or key would prevent from overriding values using environment variables. + Dash are converted to underscore internally, but if you have the same variable using underscore, it would + override both of them. + .. method:: getstr(key[, default='']) Retrieve a key from available environments. diff --git a/getconf/base.py b/getconf/base.py index 19f79c4..161508c 100644 --- a/getconf/base.py +++ b/getconf/base.py @@ -146,7 +146,7 @@ def _env_key(self, key, section=''): args = (key,) if self.namespace is not NO_NAMESPACE: args = (self.namespace,) + args - return '_'.join(arg.upper() for arg in args) + return '_'.join(arg.upper() for arg in args).replace('-', '_') def _read_env(self, key): """Handle environ-related logic.""" diff --git a/tests/config/example.ini b/tests/config/example.ini index 583bb25..58fa25d 100644 --- a/tests/config/example.ini +++ b/tests/config/example.ini @@ -10,3 +10,4 @@ noascii = Åuŧølīß [no-interpolation] nointerpolation = %(noascii) +with-dashes = no-dash diff --git a/tests/test_base.py b/tests/test_base.py index c775c69..ccd06cf 100644 --- a/tests/test_base.py +++ b/tests/test_base.py @@ -56,6 +56,15 @@ def test_environ_settings(self): self.assertEqual('blah', getter.getstr('foo', 'foo')) self.assertEqual('', getter.getstr('bar')) + def test_environ_dash_declaration(self): + """Test when a section declaration contains a dash""" + getter = getconf.ConfigGetter('TESTNS', [self.example_path]) + with Environ(TESTNS_NO_INTERPOLATION_NOINTERPOLATION="no-interpolation"): + self.assertEqual('no-interpolation', getter.getstr('no-interpolation.nointerpolation')) + + with Environ(TESTNS_NO_INTERPOLATION_WITH_DASHES="value"): + self.assertEqual('value', getter.getstr('no-interpolation.with-dashes')) + def test_environ_section(self): """Test fetching section.key from environment.""" getter = getconf.ConfigGetter('TESTNS')