-
-
Notifications
You must be signed in to change notification settings - Fork 437
Enhance pdm run
to support specifying Python version
#831
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
Comments
pdm run
to support specifying the Python versionpdm run
to support specifying Python version
pdm run
to support specifying Python versionpdm run
to support specifying Python version
Nice idea! That could be very useful to me too 🙂 I currently use a With what you suggest I'd just have to run Note: rather than |
Thanks for seconding the idea. |
While the feature is mostly good, I have some concerns:
So I doubt if we can do the interpreter selection for users. |
Indeed that's something to consider. I myself am using pyenv, so I have only one interpreter of each minor version available in my PATH, allowing me to always rely on |
Personally I'm fine with having the same prompt when using Since we're discussing this, I've had a question for a while. Is it possible that pdm caches the interpreters selected before, or at least provide a way to configure it? Having to do a selection each time feels tedious, and I assume when working on a specific project, it's very rare that people need to select a different interpreter path for the same Python version. |
I'd definitely not want that 😅 Unless of course there's a |
However, IMO all you need here is no more than a task runner like tox and nox. In fact, they can be installed globally onto your system so you don't need to include them in every project's dependencies. What I want to emphasize is PDM is never to be a swiss knife toolset, but is trying to stay as a core component of Python packaging and connect with various tools in the eco-system which are already doing a great job in their fields.
Lastly, thank you for understanding. |
Sure, I'm fine with keeping this low priority. Let's keep the discussion open so that others can chime in. |
I'll create another FR for configuring interpreter paths for different versions. |
Nice plugin idea indeed @frostming 🙂 |
Is there a reason that using the > pyenv local 3.8.13 && PDM_PYTHON=$(pyenv which python) pdm run python --version
Python 3.8.13
> pyenv local 3.9.12 && PDM_PYTHON=$(pyenv which python) pdm run python --version
Python 3.9.12
> pdm run python --version # python version saved in .pdm.toml is unaffected
Python 3.10.4 |
Sorry for reviving an old issue, but I wanted to share a PDM plugin I created (though haven't yet published). I've recently started using PDM after we switched over WordPress/openverse. I've used Hatch in the past for some projects, and really missed its virtual environment matrix feature. I cobbled together a PDM plugin that does more or less what I was hoping for when I came across this issue: https://git.sr.ht/~sara/pdm-run-matrix. The plugin allows you to specify a matrix of values, including specific Python versions, then auto-manages installing the interpreter, creating and updating virtual environments for each variable combination, and running the script in each venv. This only approximates the features that Hatch has, but so far does what I need it to do. The main thing the plugin is definitely missing is good error handling and reporting (fast fail vs try everything) and probably some additional configuration options for flexibility. I'm not familiar with PDMs internals, so I am almost certain it has severe problems (hence why I haven't published it), and I had to rely on a set of rather unfortunate closures to be able to accomplish some things. @frostming if something along these lines could be added to PDM, and you'd like to collaborate on it, please let me know. I'd be keen to learn more about how PDM works and to contribute something along these lines. Of course, an idea version of this would allow sharing the matrix-generated virtual environments between multiple tests, rather than tests that otherwise share identical matrix configurations having completely isolated environments. I'll play around with that idea in the plugin format as well. |
Amazing @sarayourfriend, thanks for sharing! If you publish it to PyPI.org at some point, do also add it to https://github.com/pdm-project/awesome-pdm 😄 I'll also share that I ended up writing a PDM plugin too to replace my |
@sarayourfriend nice try, the implementation looks neat.
If you mean the I am interested in it and maybe you can publish it as a plugin first and then we will see if there is any possibility building it into PDM. |
Is your feature request related to a problem? Please describe.
N/A
Describe the solution you'd like
As of now,
pdm run
inherits from the current Python version specified bypdm use
. I find that I often need to runpdm use
just to be able to runpdm run
with a specific Python version. It would be convenient ifpdm run
supports something like:Ideally, it shouldn't change the currently selected Python version, but only applies to the command being run.
The text was updated successfully, but these errors were encountered: