Repository: pex-tool/pex

Issue:
--index-url option is not passed to the build step in PEX
Hello

With pex 2.1.0, I have an issue when trying to package an app with dependencies using an external PyPi server.

The options used in the commande line is not passed to pip in the end leading to an error.

Here is an example :

Input command :

`pex . -e rackconf.marathon.run:main -o dist/rackconf --validate-entry-point --not-zip-safe --compile --index=http://build-nexus.crto.in/repository/pypi/simple`

Output is :

```
  ERROR: Command errored out with exit status 1:
   command: /private/tmp/.tox-build-current/unknown/bundle/bin/python3.6 /private/var/folders/5m/kdmz6msd16x_xldyfj7z4s98pk9plw/T/tmp54pb4o_4/.deps/pip/pip install --ignore-installed --no-user --prefix /private/var/folders/5m/kdmz6msd16x_xldyfj7z4s98pk9plw/T/pip-build-env-i_ko8iix/normal --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'numpy>=1.18,<2.0' 'openpyxl>=3.0,<4.0' 'PICOS>=1.2,<2.0' 'django-cors-headers>=3.2,<4.0' 'django-bootstrap4>=1.1,<2.0' 'PuLP>=2.0,<3.0' 'pandas>=0.25.3,<0.26.0' 'docopt>=0.6.2,<0.7.0' 'django-mesos-criteo>=1.0,<2.0' 'django-extensions>=2.2,<3.0' 'sentry-sdk>=0.14.1,<0.15.0' 'pymysql>=0.9.3,<0.10.0' 'progressbar2>=3.47,<4.0' 'whitenoise>=5.0,<6.0'
       cwd: None
  Complete output (17 lines):
  Collecting numpy<2.0,>=1.18
    Using cached numpy-1.18.1-cp36-cp36m-macosx_10_9_x86_64.whl (15.2 MB)
  Processing /Users/b.vallet/Library/Caches/pip/wheels/a2/97/2a/d5e43384faa87a34b198b8d75e03e7130e70321ea446f98703/openpyxl-3.0.3-py2.py3-none-any.whl
  Processing /Users/b.vallet/Library/Caches/pip/wheels/e2/1f/e0/6a4ba65c75c958043bc14c52e997623d7ca4d9cdeb6b3e9bad/PICOS-1.2.0.post35-py3-none-any.whl
  Collecting django-cors-headers<4.0,>=3.2
    Using cached django_cors_headers-3.2.1-py3-none-any.whl (14 kB)
  Collecting django-bootstrap4<2.0,>=1.1
    Using cached django_bootstrap4-1.1.1-py3-none-any.whl (26 kB)
  Collecting PuLP<3.0,>=2.0
    Using cached PuLP-2.0-py3-none-any.whl (39.2 MB)
  Collecting pandas<0.26.0,>=0.25.3
    Using cached pandas-0.25.3-cp36-cp36m-macosx_10_9_x86_64.whl (10.4 MB)
  Processing /Users/b.vallet/Library/Caches/pip/wheels/9b/04/dd/7daf4150b6d9b12949298737de9431a324d4b797ffd63f526e/docopt-0.6.2-py2.py3-none-any.whl
  ERROR: Could not find a version that satisfies the requirement django-mesos-criteo<2.0,>=1.0 (from versions: none)
  ERROR: No matching distribution found for django-mesos-criteo<2.0,>=1.0
  WARNING: You are using pip version 20.0.dev0; however, version 20.0.2 is available.
  You should consider upgrading via the 'pip install --upgrade pip' command.
  ----------------------------------------
ERROR: Command errored out with exit status 1: /private/tmp/.tox-build-current/unknown/bundle/bin/python3.6 /private/var/folders/5m/kdmz6msd16x_xldyfj7z4s98pk9plw/T/tmp54pb4o_4/.deps/pip/pip install --ignore-installed --no-user --prefix /private/var/folders/5m/kdmz6msd16x_xldyfj7z4s98pk9plw/T/pip-build-env-i_ko8iix/normal --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'numpy>=1.18,<2.0' 'openpyxl>=3.0,<4.0' 'PICOS>=1.2,<2.0' 'django-cors-headers>=3.2,<4.0' 'django-bootstrap4>=1.1,<2.0' 'PuLP>=2.0,<3.0' 'pandas>=0.25.3,<0.26.0' 'docopt>=0.6.2,<0.7.0' 'django-mesos-criteo>=1.0,<2.0' 'django-extensions>=2.2,<3.0' 'sentry-sdk>=0.14.1,<0.15.0' 'pymysql>=0.9.3,<0.10.0' 'progressbar2>=3.47,<4.0' 'whitenoise>=5.0,<6.0' Check the logs for full command output.
Traceback (most recent call last):
  File "/private/tmp/.tox-build-current/unknown/bundle/bin/pex", line 10, in <module>
    sys.exit(main())
  File "/private/tmp/.tox-build-current/unknown/bundle/lib/python3.6/site-packages/pex/bin/pex.py", line 662, in main
    pex_builder = build_pex(reqs, options)
  File "/private/tmp/.tox-build-current/unknown/bundle/lib/python3.6/site-packages/pex/bin/pex.py", line 594, in build_pex
    ignore_errors=options.ignore_errors)
  File "/private/tmp/.tox-build-current/unknown/bundle/lib/python3.6/site-packages/pex/resolver.py", line 778, in resolve_multi
    return list(resolve_request.resolve_distributions(ignore_errors=ignore_errors))
  File "/private/tmp/.tox-build-current/unknown/bundle/lib/python3.6/site-packages/pex/resolver.py", line 511, in resolve_distributions
    raise_type=Untranslateable):
  File "/private/tmp/.tox-build-current/unknown/bundle/lib/python3.6/site-packages/pex/resolver.py", line 363, in _run_parallel
    for result in execute_parallel(self._max_parallel_jobs, inputs, spawn_func, raise_type):
  File "/private/tmp/.tox-build-current/unknown/bundle/lib/python3.6/site-packages/pex/jobs.py", line 228, in execute_parallel
    raise error
pex.resolver.Untranslateable: pid: 269 -> /private/tmp/.tox-build-current/unknown/bundle/bin/python3.6 /var/folders/5m/kdmz6msd16x_xldyfj7z4s98pk9plw/T/tmp54pb4o_4 --disable-pip-version-check --isolated --exists-action i -q --cache-dir /Users/b.vallet/.pex wheel --no-deps --wheel-dir /Users/b.vallet/.pex/built_wheels/local_projects/./45bd628349414968de9d3b108c2119790fe98685/cp36-cp36m.01d147a376df42a39fd467fc9a29bc62 /Users/b.vallet/Workspace/python-projects/rackconf/. raised Executing /private/tmp/.tox-build-current/unknown/bundle/bin/python3.6 /var/folders/5m/kdmz6msd16x_xldyfj7z4s98pk9plw/T/tmp54pb4o_4 --disable-pip-version-check --isolated --exists-action i -q --cache-dir /Users/b.vallet/.pex wheel --no-deps --wheel-dir /Users/b.vallet/.pex/built_wheels/local_projects/./45bd628349414968de9d3b108c2119790fe98685/cp36-cp36m.01d147a376df42a39fd467fc9a29bc62 /Users/b.vallet/Workspace/python-projects/rackconf/. failed with 1
ERROR: InvocationError for command /private/tmp/.tox-build-current/unknown/bundle/bin/poetry run pex . -e rackconf.marathon.run:main -o dist/rackconf --validate-entry-point --not-zip-safe --compile --index=http://build-nexus.crto.in/repository/pypi/simple (exited with code 1)
```


Discussion:

Resolving patch:
diff --git a/pex/resolver.py b/pex/resolver.py
--- a/pex/resolver.py
+++ b/pex/resolver.py
@@ -410,6 +410,8 @@ def _spawn_wheel_build(self, built_wheels_dir, build_request):
       distributions=[build_request.source_path],
       wheel_dir=build_result.build_dir,
       cache=self._cache,
+      indexes=self._indexes,
+      find_links=self._find_links,
       interpreter=build_request.target.get_interpreter()
     )
     return SpawnedJob.wait(job=build_job, result=build_result)


Test patch: