Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Print py_version.path in replacement of (or in addition to) the py_version.executable when prompting users to select an interpreter to use. #1418

Closed
xulongwu4 opened this issue Oct 4, 2022 · 0 comments · Fixed by #1421
Labels
⭐ enhancement Improvements for existing features

Comments

@xulongwu4
Copy link
Contributor

xulongwu4 commented Oct 4, 2022

Is your feature request related to a problem? Please describe.

Currently, when PDM prompts users to select an interpreter from the ones available in the system, it prints the py_version.executable to the terminal. There is also another variable called py_version.path available. While they are identical most of the time, I noticed that the two can be different for pyenv's python shims, and it can lead to confusing results.

For example, this is the result of running pdm init in an empty folder on my system:

$ pdm init
Creating a pyproject.toml for PDM...
Please enter the Python interpreter to use
0. /usr/bin/python3 (3.10)
1. /usr/bin/python (2.7)
2. /usr/bin/python3.10 (3.10)
3. /home/oulongwu/.local/share/pyenv/versions/3.7.14/bin/python3.7m (3.7)
4. /home/oulongwu/.local/share/pyenv/versions/3.7.14/bin/python3.7 (3.7)
5. /home/oulongwu/.local/share/pyenv/versions/3.6.15/bin/python3.6m (3.6)
6. /home/oulongwu/.local/share/pyenv/versions/3.6.15/bin/python3.6 (3.6)
7. /usr/bin/python2.7 (2.7)
8. /home/oulongwu/.local/share/pipx/venvs/pdm/bin/python (3.10)
Please select (0):

Notice that the first listed interpreter is /usr/bin/python3. If I select 0 and go ahead to finish the init process, and then take a look at .pdm.toml, this is the content is there:

$ cat .pdm.toml
[python]
path = "/home/oulongwu/.local/share/pyenv/shims/python3"

As we can see, the selected interpreter is actually the shim path of pyenv. However, there is no hint for that in the listed interpreters earlier.

Alternatively, if I select a python interpreter with pyenv before I ran pdm init, I get the following result

$ pyenv local 3.7.14
$ pdm init
Creating a pyproject.toml for PDM...
Please enter the Python interpreter to use
0. /home/oulongwu/.local/share/pyenv/versions/3.7.14/bin/python3 (3.7)
1. /home/oulongwu/.local/share/pyenv/versions/3.7.14/bin/python (3.7)
2. /usr/bin/python3.10 (3.10)
3. /home/oulongwu/.local/share/pyenv/versions/3.7.14/bin/python3.7m (3.7)
4. /home/oulongwu/.local/share/pyenv/versions/3.7.14/bin/python3.7 (3.7)
5. /home/oulongwu/.local/share/pyenv/versions/3.7.14/bin/python3.7m (3.7)
6. /home/oulongwu/.local/share/pyenv/versions/3.7.14/bin/python3.7 (3.7)
7. /home/oulongwu/.local/share/pyenv/versions/3.6.15/bin/python3.6m (3.6)
8. /home/oulongwu/.local/share/pyenv/versions/3.6.15/bin/python3.6 (3.6)
9. /usr/bin/python2.7 (2.7)
10. /home/oulongwu/.local/share/pipx/venvs/pdm/bin/python (3.10)

Notice how 3 and 5 are the same, and 4 and 6 are the same. However, if I select them and look at the content of .pdm.toml, I noticed that 5 and 6 correspond to pyenv's python shims, while 3 and 4 points to the interpreters installed in $PYENV_ROOT/versions/3.7.14. Again since there are no hints for that in the selection menu, I found it very confusing.

On the other hand, when I tried to use py_version.path in the selection menu, I got the following in my second experiment above:

$ pyenv local 3.7.14
$ pdm init
Creating a pyproject.toml for PDM...
Please enter the Python interpreter to use
0. /home/oulongwu/.local/share/pyenv/shims/python3 (3.7)
1. /home/oulongwu/.local/share/pyenv/shims/python (3.7)
2. /usr/bin/python3.10 (3.10)
3. /home/oulongwu/.local/share/pyenv/versions/3.7.14/bin/python3.7m (3.7)
4. /home/oulongwu/.local/share/pyenv/versions/3.7.14/bin/python3.7 (3.7)
5. /home/oulongwu/.local/share/pyenv/shims/python3.7m (3.7)
6. /home/oulongwu/.local/share/pyenv/shims/python3.7 (3.7)
7. /home/oulongwu/.local/share/pyenv/versions/3.6.15/bin/python3.6m (3.6)
8. /home/oulongwu/.local/share/pyenv/versions/3.6.15/bin/python3.6 (3.6)
9. /usr/bin/python2.7 (2.7)
10. /home/oulongwu/.local/share/pipx/venvs/pdm/bin/python (3.10)
Please select (0):

This time the pyenv shim paths are distinguished from the actual python interpreter binaries.

Describe the solution you'd like

I think using python_version.path is much less confusing than python_version.executable when pyenv is involved. I suggest we at least print out python_version.path in addition to python_version.executable when providing the interpreter selection menu. We can also just use python_version.path in place of python_version.executable if you are not against the idea. This is also for consistency of the selection with the content written in .pdm.toml.

@xulongwu4 xulongwu4 added the ⭐ enhancement Improvements for existing features label Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐ enhancement Improvements for existing features
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant