Merge pull request #2015 from pypa/add-pipfile-env-test

Add pipfile env var expansion and test
This commit is contained in:
Dan Ryan
2018-04-18 23:13:52 -04:00
committed by GitHub
2 changed files with 31 additions and 5 deletions
+7 -5
View File
@@ -615,8 +615,12 @@ class Project(object):
def pipfile_sources(self):
if 'source' in self.parsed_pipfile:
sources = []
for s in self.parsed_pipfile['source']:
s['url'] = os.path.expandvars(s['url'])
for i, s in enumerate(self.parsed_pipfile['source']):
for k in s.keys():
if k == 'verify_ssl':
continue
val = os.path.expandvars(self.parsed_pipfile['source'][i][k])
s[k] = val
sources.append(s)
return sources
return [DEFAULT_SOURCE]
@@ -629,10 +633,8 @@ class Project(object):
if sources_:
return sources_
if 'source' in self.parsed_pipfile:
return self.parsed_pipfile['source']
else:
return [DEFAULT_SOURCE]
return self.pipfile_sources
def find_source(self, source):
"""given a source, find it.
+24
View File
@@ -2,6 +2,30 @@
import pytest
import os
from pipenv.project import Project
from pipenv.utils import temp_environ
from pipenv.patched import pipfile
@pytest.mark.project
@pytest.mark.sources
@pytest.mark.environ
def test_pipfile_envvar_expansion(PipenvInstance):
with PipenvInstance(chdir=True) as p:
with temp_environ():
with open(p.pipfile_path, 'w') as f:
f.write("""
[[source]]
url = 'https://${TEST_HOST}/simple'
verify_ssl = false
name = "pypi"
[packages]
pytz = "*"
""".strip())
os.environ['TEST_HOST'] = 'localhost:5000'
project = Project()
assert project.sources[0]['url'] == 'https://localhost:5000/simple'
assert 'localhost:5000' not in str(pipfile.load(p.pipfile_path))
@pytest.mark.project