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

pdm run does not parse the requested python version correctly #1414

Closed
1 task done
xulongwu4 opened this issue Oct 3, 2022 · 0 comments
Closed
1 task done

pdm run does not parse the requested python version correctly #1414

xulongwu4 opened this issue Oct 3, 2022 · 0 comments
Labels
🐛 bug Something isn't working

Comments

@xulongwu4
Copy link
Contributor

xulongwu4 commented Oct 3, 2022

  • I have searched the issue tracker and believe that this is not a duplicate.

Make sure you run commands with -v flag before pasting the output.

Steps to reproduce

  1. Create a fresh project with python3.7 as the interpreter
$ mkdir -p project
$ cd project
$ pdm init
  1. Try invoking the python interpreter with different version numbers
$ pdm run python3
Python 3.7.12 (default, Sep 26 2021, 21:12:22)
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ pdm run python3.10
Python 3.7.12 (default, Sep 26 2021, 21:12:22)
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
$ pdm run python3.20
Python 3.7.12 (default, Sep 26 2021, 21:12:22)
[GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>

Actual behavior

No matter what version I request with pdm run python3.X, pdm always pick the selected python3.7 as the interpreter.

Expected behavior

If python3.X is not configured for the current project, I would expect pdm run python3.X to fall back to search in the system PATH variable. Thus if I do pdm run python3.10, it should give me python3.10 in the system PATH, and if I do pdm run python3.20, it should produce an error message like the following:

[PdmUsageError]: Command 'python3.20' is not found on your PATH.

This way, the handling of python interpreter would be consistent with the handling of other executables by pdm run.

Possible causes

I believe the cause if the usage of splitext in parsing the command sent to pdm run in pdm/models/environment.py:

python = os.path.splitext(command)[0]
version = python[6:]

The first line discards the version string after the first dot, so python3.20 would be parsed as python3 going forward. I think this is a bug.

Environment Information

# Paste the output of `pdm info && pdm info --env` below:

$ pdm info
PDM version:
  2.1.4
Python Interpreter:
  /usr/bin/python3.7 (3.7)
Project Root:
  /home/oulongwu/tmp/project
Project Packages:
  /home/oulongwu/tmp/project/__pypackages__/3.7


$ pdm info --env
{
  "implementation_name": "cpython",
  "implementation_version": "3.7.12",
  "os_name": "posix",
  "platform_machine": "x86_64",
  "platform_release": "5.15.68-218.current",
  "platform_system": "Linux",
  "platform_version": "#1 SMP PREEMPT Sat Sep 17 01:51:42 UTC 2022",
  "python_full_version": "3.7.12",
  "platform_python_implementation": "CPython",
  "python_version": "3.7",
  "sys_platform": "linux"
}
@xulongwu4 xulongwu4 added the 🐛 bug Something isn't working label Oct 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant