From 601643c1be40a4ba290ec696f1ff64f85736e087 Mon Sep 17 00:00:00 2001 From: Loren Carvalho <lcarvalho@linkedin.com> Date: Mon, 6 Jul 2015 14:52:12 -0700 Subject: [PATCH] short-circuiting rc values --- pex/variables.py | 7 +++++-- tests/test_variables.py | 8 ++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/pex/variables.py b/pex/variables.py index ddc9a5dc8..7d0d5447f 100644 --- a/pex/variables.py +++ b/pex/variables.py @@ -34,8 +34,11 @@ def iter_help(cls): yield variable_name, variable_type, variable_text def __init__(self, environ=None, rc='~/.pexrc'): - self._environ = self._from_rc(rc) - self._environ.update(environ.copy() if environ else os.environ) + self._environ = environ.copy() if environ else os.environ + if not self.PEX_IGNORE_RCFILES: + rc_values = self._from_rc(rc).copy() + rc_values.update(self._environ) + self._environ = rc_values def copy(self): return self._environ.copy() diff --git a/tests/test_variables.py b/tests/test_variables.py index 32d1c23d9..4199bd487 100644 --- a/tests/test_variables.py +++ b/tests/test_variables.py @@ -98,3 +98,11 @@ def test_pexrc_precedence(): pexrc.flush() v = Variables(environ={'HELLO': 42}, rc=pexrc.name) assert v._get_int('HELLO') == 42 + + +def test_rc_ignore(): + with tempfile.NamedTemporaryFile(mode='w') as pexrc: + pexrc.write('HELLO=FORTYTWO') + pexrc.flush() + v = Variables(environ={'PEX_IGNORE_RC_FILES': True, 'HELLO': 42}, rc=pexrc.name) + assert v._get_int('HELLO') == 42