Skip to content

Commit

Permalink
remove env-var support
Browse files Browse the repository at this point in the history
  • Loading branch information
mmerickel committed Mar 29, 2018
1 parent 950d884 commit b34a45d
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 50 deletions.
8 changes: 8 additions & 0 deletions CHANGES.rst
@@ -1,3 +1,11 @@
unreleased
==========

- Removed environment variable support entirely for now. The feature requires
bugfixes upstream in PasteDeploy which have not been done yet and this was
breaking people's environments so it is gone for now.
See https://github.com/Pylons/plaster_pastedeploy/pull/15

0.4.2 (2017-11-20)
==================

Expand Down
24 changes: 0 additions & 24 deletions README.rst
Expand Up @@ -67,29 +67,5 @@ Some examples are below:

- ``egg:MyApp?debug=false#foo``

Environment Variables
---------------------

**This feature is not supported on Python 2.**

This binding extends ``pastedeploy`` to inject environ variables as defaults
which are available to use in the INI file. Each ``os.environ`` key is prefixed
with ``ENV_`` and added as a default.

For example:

.. code-block:: ini
[app:main]
debug = %(ENV_APP_DEBUG)s
The only thing to be aware of here is that there is no fallback. The INI file
will fail to parse if the environment variable is not set. The app may be run
like so:

.. code-block:: bash
$ APP_DEBUG=true env/bin/pserve development.ini
.. _PasteDeploy: https://pastedeploy.readthedocs.io/en/latest/
.. _plaster: https://docs.pylonsproject.org/projects/plaster/en/latest/
9 changes: 0 additions & 9 deletions src/plaster_pastedeploy/__init__.py
Expand Up @@ -227,15 +227,6 @@ def _get_defaults(self, defaults=None):
result['here'] = os.getcwd()
else:
result['here'] = os.path.dirname(self.filepath)
if not PY2:
# Only inject environment variables on py3+ where escaping is
# supported. On py2 any environment var with contents of the
# format %(foo)s would break the parser. Unfortunately, this is
# risky enough to simply not support it.
result.update({
'ENV_' + k: v.replace('%', '%%')
for k, v in os.environ.items()
})
result.update(self.uri.options)
if defaults:
result.update(defaults)
Expand Down
4 changes: 0 additions & 4 deletions tests/sample_configs/test_settings.ini
Expand Up @@ -12,7 +12,3 @@ set default_b = override_b
a = a_val
b = b_val
c = %(default_c)s

[section3]
foo = %(ENV_PLASTER_FOO)s
bar = %(ENV_PLASTER_BAR)s
14 changes: 1 addition & 13 deletions tests/test_get_settings.py
Expand Up @@ -17,7 +17,7 @@ def loader(self, fake_packages):

def test_sections(self):
result = self.loader.get_sections()
assert set(result) == {'section1', 'section2', 'section3'}
assert set(result) == {'section1', 'section2'}

def test_missing_section(self):
result = self.loader.get_settings('missing', {'a': 'b'})
Expand Down Expand Up @@ -58,18 +58,6 @@ def test_defaults_passed(self):
assert result.global_conf['default_b'] == 'default_b'
assert result.global_conf['default_c'] == 'default_c'

@pytest.mark.skipif('sys.version_info[0] == 2')
def test_environ_passed_and_escaped(self, monkeypatch):
monkeypatch.setenv('PLASTER_FOO', '%(foo)s')
monkeypatch.setenv('PLASTER_BAR', '%bar')
result = self.loader.get_settings('section3')

assert result['foo'] == '%(foo)s'
assert result.global_conf['ENV_PLASTER_FOO'] == '%(foo)s'

assert result['bar'] == '%bar'
assert result.global_conf['ENV_PLASTER_BAR'] == '%bar'

class TestSectionedURI(TestSimpleUri):
config_uri = test_settings_path + '#section1'

Expand Down

0 comments on commit b34a45d

Please sign in to comment.