pypa / pipenv

Python Development Workflow for Humans.
https://pipenv.pypa.io
MIT License
24.88k stars 1.87k forks source link

PIPENV_PYTHON with ~ fails to resolve path #4090

Closed lantrix closed 4 years ago

lantrix commented 4 years ago

Running latest Pipenv:

$ pyenv which python
/Users/lantrix/.pyenv/versions/3.8.0/bin/python
$ python --version
Python 3.8.0
$ pipenv --version
pipenv, version 2018.11.26

In debugging, walked through the doco on getting Pipenv to recognise Pyenv version https://pipenv.kennethreitz.org/en/latest/diagnose/#pipenv-does-not-respect-pyenvs-global-and-local-python-versions

Issue description

Had set PIPENV_PYTHON to my pyenv shim, but Pipenv won't detect it.

export PIPENV_PYTHON='~/.pyenv/shims/python'

Expected result

Pipenv spawns a shell within the virtualenv

Actual result

Pipenv complains ~/.pyenv/shims/python is not a python version

Even though it is.

~/.pyenv/shims/python --version
Python 3.8.0

Output of run:

pipenv --verbose shell
Traceback (most recent call last):
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/bin/pipenv", line 11, in <module>
    load_entry_point('pipenv==2018.11.26', 'console_scripts', 'pipenv')()
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/vendor/click/decorators.py", line 64, in new_func
    return ctx.invoke(f, obj, *args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/vendor/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/cli/command.py", line 390, in shell
    pypi_mirror=state.pypi_mirror,
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/core.py", line 2156, in do_shell
    three=three, python=python, validate=False, pypi_mirror=pypi_mirror,
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/core.py", line 574, in ensure_project
    pypi_mirror=pypi_mirror,
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/core.py", line 494, in ensure_virtualenv
    python = ensure_python(three=three, python=python)
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/core.py", line 397, in ensure_python
    path_to_python = find_a_system_python(python)
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/core.py", line 360, in find_a_system_python
    python_entry = finder.find_python_version(line)
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/pythonfinder.py", line 95, in find_python_version
    version_dict = PythonVersion.parse(major)
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/models/python.py", line 359, in parse
    version_dict = parse_python_version(str(version))
  File "/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv/vendor/pythonfinder/utils.py", line 86, in parse_python_version
    raise InvalidPythonVersion("%s is not a python version" % version_str)
pipenv.vendor.pythonfinder.exceptions.InvalidPythonVersion: ~/.pyenv/shims/python is not a python version

Steps to replicate

No Pipfile. Setup a new shell in an empty dir

$ export PIPENV_PYTHON='~/.pyenv/shims/python'
$ mkdir test && cd test
$ pyenv shell 3.8.0
$ pipenv shell

$ pipenv --support Pipenv version: `'2018.11.26'` Pipenv location: `'/usr/local/Cellar/pipenv/2018.11.26_2/libexec/lib/python3.7/site-packages/pipenv'` Python location: `'/usr/local/Cellar/pipenv/2018.11.26_2/libexec/bin/python3.7'` Python installations found:
rmbrad commented 4 years ago

If you just remove the tilde from the quotes the shell will correctly handle its expansion for you.

lantrix commented 4 years ago

Ah so it's literally my misunderstanding of the bash expansion :-(

I did try this and it worked as well:

$ export PIPENV_PYTHON="$HOME/.pyenv/shims/python"

But yeah it makes sense now it's expanding $HOME due to the double quotes.