AcademySoftwareFoundation / AcademySoftwareFoundation/rez
rez-pip fails if the user has not run `rez-bind` for a specific Python version
- Dominant language
- Python
- Stars
- 1.1k
- Forks
- 374
- Avg merge
- 9d 12h
- Merged PRs (30d)
- 5
Description
# Summary
It looks like, when rez-pip runs with a Python version, it attempts to resolve for that version + pip. And if a pip package exists, but not for that Python version, rez-pip fails midway instead of installing the PyPI package using a different resolve.
# Reproduction Steps
```sh
cd rez
git checkout 2.72.0
python install.py -v ~/rez
export PATH=~/rez/bin/rez:$PATH
source ~/rez/completion/complete.sh
rez-bind python
rez-bind pip
rez-bind python --exe `which python3` # In my case, Python 3.6
rez-pip --install parso --python-version=3.6
```
# Error Encountered
```
Traceback (most recent call last):
File "/home/selecaoone///rez-2.72.0-python-2.7/bin/rez/rez-pip", line 8, in
sys.exit(run_rez_pip())
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/cli/_entry_points.py", line 178, in run_rez_pip
return run("pip")
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/cli/_main.py", line 170, in run
returncode = run_cmd()
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/cli/_main.py", line 162, in run_cmd
return func(opts, opts.parser, extra_arg_groups)
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/cli/pip.py", line 76, in command
extra_args=opts.extra)
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/pip.py", line 261, in pip_install_package
py_exe, context = find_pip(pip_version, python_version)
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/pip.py", line 95, in find_pip
python_version, pip_version=version
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/pip.py", line 203, in find_pip_from_context
py_exe = find_python_in_context(context)
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/pip.py", line 142, in find_python_in_context
python_package = context.get_resolved_package("python")
File "/home/selecaoone/rez-2.72.0-python-2.7/lib/python2.7/site-packages/rez/resolved_context.py", line 434, in get_resolved_package
pkgs = [x for x in self._resolved_packages if x.name == name]
TypeError: 'NoneType' object is not iterable
```
# Suggested Fix?
Add this code:
```python
if context.status == ResolverStatus.failed:
print_error('Package request "%s" could not be resolved.', package_request)
return None, None, None
```
Here: https://github.com/nerdvegas/rez/blob/master/src/rez/pip.py#L202
When I do this, it fails to resolve the package_request, `["python-3.6", "pip"]`, but finds another context which it can resolve. And then the package installs properly.
Contributor guide
Research direction
Start in src/rez/pip.py around find_pip_from_context and the find_pip call shown in the traceback. Reproduce the failure with rez-pip --install parso --python-version=3.6, then inspect how an unresolved ["python-3.6", "pip"] context is handled. Done means the failed context is handled without a TypeError and an alternate resolvable context can install the package.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100