From f87e434cb2c89582e8bb3310bd97d5c90453df18 Mon Sep 17 00:00:00 2001 From: Daniel van Flymen Date: Fri, 16 Mar 2018 18:34:26 -0400 Subject: [PATCH 1/3] Add explanation to Docs --- docs/advanced.rst | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/docs/advanced.rst b/docs/advanced.rst index ba5a635f..bfc6d94f 100644 --- a/docs/advanced.rst +++ b/docs/advanced.rst @@ -302,6 +302,27 @@ To prevent pipenv from loading the ``.env`` file, set the ``PIPENV_DONT_LOAD_ENV $ PIPENV_DONT_LOAD_ENV=1 pipenv shell +☤ Support for Environment Variables +----------------------------------- + +``pipenv`` supports the usage of environment variables in values. For example: + + [[source]] + url = "https://${PYPI_USERNAME}:${PYPI_PASSWORD}@my_private_repo.example.com/simple" + verify_ssl = true + name = "pypi" + + [dev-packages] + + [packages] + requests = {version="*", index="home"} + maya = {version="*", index="pypi"} + records = "*" + +Environment variables may be specified as ``${MY_ENVAR}`` or ``$MY_ENVAR``. +On Windows, ``%MY_ENVAR%`` is supported in addition to ``${MY_ENVAR}`` or ``$MY_ENVAR``. + + ☤ Configuration With Environment Variables ------------------------------------------ From 66179652b81a32bcfb761ff3adb0bc46a22921cb Mon Sep 17 00:00:00 2001 From: Daniel van Flymen Date: Fri, 16 Mar 2018 18:34:37 -0400 Subject: [PATCH 2/3] Implement Injection --- pipenv/vendor/pipfile/api.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pipenv/vendor/pipfile/api.py b/pipenv/vendor/pipfile/api.py index 9f618db1..12bd27b9 100644 --- a/pipenv/vendor/pipfile/api.py +++ b/pipenv/vendor/pipfile/api.py @@ -62,6 +62,24 @@ class PipfileParser(object): def __repr__(self): return ' Date: Fri, 16 Mar 2018 18:34:45 -0400 Subject: [PATCH 3/3] Add tests --- tests/test_vendor.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_vendor.py b/tests/test_vendor.py index 17c57340..4d7cf196 100644 --- a/tests/test_vendor.py +++ b/tests/test_vendor.py @@ -1,5 +1,6 @@ # Make sure we use the patched packages. import pipenv # noqa +import os from prettytoml import lexer from prettytoml.elements.atomic import AtomicElement @@ -7,6 +8,7 @@ from prettytoml.elements.metadata import ( WhitespaceElement, PunctuationElement, CommentElement ) from prettytoml.elements.table import TableElement +from pipenv.vendor.pipfile.api import PipfileParser def test_table(): @@ -27,3 +29,36 @@ def test_table(): assert set(table.items()) == {('id', 42), ('age', 14)} del table['id'] assert set(table.items()) == {('age', 14)} + + +class TestPipfileParser: + + def test_inject_environment_variables(self): + os.environ['PYTEST_PIPFILE_TEST'] = "XYZ" + p = PipfileParser() + + parsed_dict = p.inject_environment_variables({ + "a_string": "https://$PYTEST_PIPFILE_TEST@something.com", + "another_string": "https://${PYTEST_PIPFILE_TEST}@something.com", + "nested": { + "a_string": "https://$PYTEST_PIPFILE_TEST@something.com", + "another_string": "${PYTEST_PIPFILE_TEST}", + }, + "list": [ + { + "a_string": "https://$PYTEST_PIPFILE_TEST@something.com", + "another_string": "${PYTEST_PIPFILE_TEST}" + }, + {}, + ], + "bool": True, + "none": None, + }) + + assert parsed_dict["a_string"] == "https://XYZ@something.com" + assert parsed_dict["another_string"] == "https://XYZ@something.com" + assert parsed_dict["nested"]["another_string"] == "XYZ" + assert parsed_dict["list"][0]["a_string"] == "https://XYZ@something.com" + assert parsed_dict["list"][1] == {} + assert parsed_dict["bool"] is True + assert parsed_dict["none"] is None