From 9d7a288670c3e253f5a2f1511f78ff3179bc5d88 Mon Sep 17 00:00:00 2001 From: Lucid One Date: Fri, 5 Jul 2019 19:17:01 -0400 Subject: [PATCH 1/3] Support for loading config from "<(/usr/bin/envsubst < template)" --- src/configobj/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/configobj/__init__.py b/src/configobj/__init__.py index 928c208..2bd2c84 100644 --- a/src/configobj/__init__.py +++ b/src/configobj/__init__.py @@ -1212,7 +1212,7 @@ def _load(self, infile, configspec): if isinstance(infile, six.string_types): self.filename = infile - if os.path.isfile(infile): + if os.path.exists(infile): with open(infile, 'rb') as h: content = h.readlines() or [] elif self.file_error: From 8b271284747471acf3e494301747454402198457 Mon Sep 17 00:00:00 2001 From: Lucid One Date: Sat, 6 Jul 2019 03:55:58 -0400 Subject: [PATCH 2/3] Check if infile isdir() Co-Authored-By: Aliaksei Urbanski --- src/configobj/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/configobj/__init__.py b/src/configobj/__init__.py index 2bd2c84..16da19d 100644 --- a/src/configobj/__init__.py +++ b/src/configobj/__init__.py @@ -1212,7 +1212,7 @@ def _load(self, infile, configspec): if isinstance(infile, six.string_types): self.filename = infile - if os.path.exists(infile): + if os.path.exists(infile) and not os.path.isdir(infile): with open(infile, 'rb') as h: content = h.readlines() or [] elif self.file_error: From ae4b6ab17d9ae6878a77b898018fa9edd60bbc81 Mon Sep 17 00:00:00 2001 From: Lucid One Date: Sat, 6 Jul 2019 03:59:18 -0400 Subject: [PATCH 3/3] Added tests for <(envsubst < template) --- src/tests/conf_envsubst.py | 4 ++++ src/tests/envsubst.ini.template | 4 ++++ src/tests/test_validate_envsubst.py | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+) create mode 100644 src/tests/conf_envsubst.py create mode 100644 src/tests/envsubst.ini.template create mode 100644 src/tests/test_validate_envsubst.py diff --git a/src/tests/conf_envsubst.py b/src/tests/conf_envsubst.py new file mode 100644 index 0000000..be790de --- /dev/null +++ b/src/tests/conf_envsubst.py @@ -0,0 +1,4 @@ +import sys +import configobj + +print(configobj.ConfigObj(sys.argv[1])) diff --git a/src/tests/envsubst.ini.template b/src/tests/envsubst.ini.template new file mode 100644 index 0000000..304e892 --- /dev/null +++ b/src/tests/envsubst.ini.template @@ -0,0 +1,4 @@ +# Template test + +shell = ${SHELL} + diff --git a/src/tests/test_validate_envsubst.py b/src/tests/test_validate_envsubst.py new file mode 100644 index 0000000..bdbae18 --- /dev/null +++ b/src/tests/test_validate_envsubst.py @@ -0,0 +1,18 @@ +# *- coding: utf-8 -*- +# pylint: disable=wildcard-import, missing-docstring, no-self-use, bad-continuation +# pylint: disable=invalid-name, redefined-outer-name, too-few-public-methods + +import os + +import pytest +import subprocess + +@pytest.fixture() +def thisdir(): + return os.path.dirname(os.path.join(os.getcwd(), __file__)) + + +def test_validate_template(thisdir,capsys): + templatepath = os.path.join(thisdir, 'envsubst.ini.template') + out = subprocess.check_output(["bash","-c","export SHELL=/bin/bash && python %s/conf_envsubst.py <(envsubst < %s)"%(thisdir,templatepath)]) + assert out.decode() == "{'shell': '/bin/bash'}\n"