add extra indexes from pip config files in Pipfile gen

This commit is contained in:
Derek Schaller
2018-02-23 23:39:40 -08:00
parent 828858696b
commit baaddd3cf5
2 changed files with 59 additions and 6 deletions
+22 -6
View File
@@ -12,13 +12,18 @@ import delegator
import pipfile
import toml
from .patched.pip.baseparser import ConfigOptionParser
from .utils import (
mkdir_p, convert_deps_from_pip, pep423_name, recase_file,
find_requirements, is_file, is_vcs, python_version, cleanup_toml,
is_installable_file, is_valid_url, normalize_drive
)
from .environments import PIPENV_MAX_DEPTH, PIPENV_VENV_IN_PROJECT
from .environments import PIPENV_VIRTUALENV, PIPENV_PIPFILE
from .environments import (
PIPENV_MAX_DEPTH,
PIPENV_PIPFILE,
PIPENV_VENV_IN_PROJECT,
PIPENV_VIRTUALENV,
)
if PIPENV_PIPFILE:
if not os.path.isfile(PIPENV_PIPFILE):
@@ -399,11 +404,22 @@ class Project(object):
def create_pipfile(self, python=None):
"""Creates the Pipfile, filled with juicy defaults."""
config_parser = ConfigOptionParser(name=self.name)
install = dict(config_parser.get_config_section('install'))
indexes = install.get('extra-index-url', '').lstrip('\n').split('\n')
# Default source.
pypi_source = {u'url': u'https://pypi.python.org/simple', u'verify_ssl': True, u'name': 'pypi'}
sources = [pypi_source]
for num, index in enumerate(indexes):
if not index:
continue
source_name = 'pip_index_{}'.format(num+1)
sources.append({u'url': index, u'verify_ssl': True, u'name': source_name})
data = {
# Default source.
u'source': [
{u'url': u'https://pypi.python.org/simple', u'verify_ssl': True, 'name': 'pypi'}
],
u'source': sources,
# Default packages.
u'packages': {},
+37
View File
@@ -1,3 +1,5 @@
import os
import pipenv.project
from pipenv.vendor import delegator
@@ -14,6 +16,41 @@ class TestProject():
assert proj.virtualenv_location in proj.download_location
assert proj.download_location.endswith('downloads')
def test_create_pipfile(self):
proj = pipenv.project.Project()
# Create test space.
delegator.run('mkdir test_pipfile')
with open('test_pipfile/pip.conf', 'w') as f:
f.write('[install]\nextra-index-url = \n'
' https://pypi.host.com/simple\n'
' https://remote.packagehost.net/simple')
os.chdir('test_pipfile')
os.environ['PIP_CONFIG_FILE'] = 'pip.conf'
proj.create_pipfile()
proj._pipfile_location = 'Pipfile'
pfile = proj.parsed_pipfile
os.chdir('..')
# Cleanup test space.
delegator.run('rm -fr test_pipfile')
# Confirm source added correctly.
default_source = pfile['source'][0]
assert default_source['url'] == 'https://pypi.python.org/simple'
assert default_source['name'] == 'pypi'
assert default_source['verify_ssl'] is True
config_source_1 = pfile['source'][1]
assert config_source_1['url'] == 'https://pypi.host.com/simple'
assert config_source_1['name'] == 'pip_index_1'
assert config_source_1['verify_ssl'] is True
config_source_2 = pfile['source'][2]
assert config_source_2['url'] == 'https://remote.packagehost.net/simple'
assert config_source_2['name'] == 'pip_index_2'
assert config_source_2['verify_ssl'] is True
def test_parsed_pipfile(self):
proj = pipenv.project.Project()