mirror of
https://github.com/kennethreitz/pipenv.git
synced 2026-06-05 22:50:18 +00:00
Merge pull request #2015 from pypa/add-pipfile-env-test
Add pipfile env var expansion and test
This commit is contained in:
+7
-5
@@ -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.
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user