Skip to content

Commit

Permalink
short-circuiting rc values
Browse files Browse the repository at this point in the history
  • Loading branch information
lorencarvalho committed Aug 2, 2015
1 parent 5326702 commit 601643c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pex/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
8 changes: 8 additions & 0 deletions tests/test_variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 601643c

Please sign in to comment.