diff --git a/pipenv/core.py b/pipenv/core.py index 09bdcaa7..79357ce5 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -801,8 +801,8 @@ def do_install_dependencies( for dep, ignore_hash, block in deps_list_bar: if len(procs) < PIPENV_MAX_SUBPROCESS: # Use a specific index, if specified. - dep, index = split_argument(dep, short='i', long_='index') - dep, extra_index = split_argument(dep, long_='extra-index-url') + dep, index = split_argument(dep, short='i', long_='index', num=1) + dep, extra_indexes = split_argument(dep, long_='extra-index-url') # Install the module. c = pip_install( dep, @@ -813,7 +813,7 @@ def do_install_dependencies( block=block, index=index, requirements_dir=requirements_dir, - extra_indexes=extra_index, + extra_indexes=extra_indexes, ) c.dep = dep c.ignore_hash = ignore_hash @@ -833,8 +833,8 @@ def do_install_dependencies( failed_deps_list, label=INSTALL_LABEL2 ): # Use a specific index, if specified. - dep, index = split_argument(dep, short='i', long_='index') - dep, extra_index = split_argument(dep, long_='extra-index-url') + dep, index = split_argument(dep, short='i', long_='index', num=1) + dep, extra_indexes = split_argument(dep, long_='extra-index-url') # Install the module. c = pip_install( dep, @@ -844,7 +844,7 @@ def do_install_dependencies( verbose=verbose, index=index, requirements_dir=requirements_dir, - extra_indexes=extra_index, + extra_indexes=extra_indexes, ) # The Installation failed... if c.return_code != 0: @@ -1887,7 +1887,7 @@ def do_install( index_indicators = ['-i', '--index', '--extra-index-url'] index, extra_indexes = None, None if more_packages and any(more_packages[0].startswith(s) for s in index_indicators): - line, index = split_argument(' '.join(line), short='i', long_='index') + line, index = split_argument(' '.join(line), short='i', long_='index', num=1) line, extra_indexes = split_argument(line, long_='extra-index-url') package_names = line.split() package_name = package_names[0] diff --git a/pipenv/utils.py b/pipenv/utils.py index a63089ed..bc1d54d0 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -1267,7 +1267,7 @@ def handle_remove_readonly(func, path, exc): raise -def split_argument(req, short=None, long_=None): +def split_argument(req, short=None, long_=None, num=-1): """Split an argument from a string (finds None if not present). Uses -short , --long , and --long=arg as permutations. @@ -1275,20 +1275,27 @@ def split_argument(req, short=None, long_=None): returns string, index """ index_entries = [] + import re if long_: - long_ = ' --{0}'.format(long_) - index_entries.extend(['{0}{1}'.format(long_, s) for s in [' ', '=']]) + index_entries.append('--{0}'.format(long_)) if short: - index_entries.append(' -{0} '.format(short)) - index = None - index_entry = first([entry for entry in index_entries if entry in req]) - if index_entry: - req, index = req.split(index_entry) - remaining_line = index.split() - if len(remaining_line) > 1: - index, more_req = remaining_line[0], ' '.join(remaining_line[1:]) - req = '{0} {1}'.format(req, more_req) - return req, index + index_entries.append('-{0}'.format(short)) + match_string = '|'.join(index_entries) + matches = re.findall('(?<=\s)({0})([\s=])(\S+)'.format(match_string), req) + remove_strings = [] + match_values = [] + for match in matches: + match_values.append(match[-1]) + remove_strings.append(''.join(match)) + for string_to_remove in remove_strings: + req = req.replace(' {0}'.format(string_to_remove), '') + if not match_values: + return req, None + if num == 1: + return req, match_values[0] + if num == -1: + return req, match_values + return req, match_values[:num] @contextmanager diff --git a/tests/integration/test_project.py b/tests/integration/test_project.py index d299260e..9a03c5c1 100644 --- a/tests/integration/test_project.py +++ b/tests/integration/test_project.py @@ -111,3 +111,35 @@ def test_maintain_file_line_endings(PipenvInstance, pypi, newlines): actual_newlines, newlines, fn, ) # message because of https://github.com/pytest-dev/pytest/issues/3443 + + +@pytest.mark.project +@pytest.mark.sources +def test_many_indexes(PipenvInstance, pypi): + with PipenvInstance(pypi=pypi, chdir=True) as p: + with open(p.pipfile_path, 'w') as f: + contents = """ +[[source]] +url = "{0}" +verify_ssl = false +name = "testindex" + +[[source]] +url = "https://pypi.org/simple" +verify_ssl = "true" +name = "pypi" + +[[source]] +url = "https://pypi.python.org/simple" +verify_ssl = "true" +name = "legacy" + +[packages] +pytz = "*" +six = {{version = "*", index = "pypi"}} + +[dev-packages] + """.format(os.environ['PIPENV_TEST_INDEX']).strip() + f.write(contents) + c = p.pipenv('install') + assert c.return_code == 0