-
-
Notifications
You must be signed in to change notification settings - Fork 419
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
feature: Perform operations in a venv without switching to it. #1705
Comments
Let’s brainstorm workflows real quick. Currently, my initialization looks something like this: PY=$(command -v python3.11)
pdm venv create $PY
pdm use -i .venv/bin/python
pdm sync --dev The minimal implementation of above would be something like this: pdm venv create -n lint $PY
pdm sync —-venv=lint -G lint And then: pdm run —venv=lint lint I think that’s a pretty good low-level primitive that opens PDM up to new use-cases! I would still like to point out that you shouldn’t be that dismissive of tox-like behavior. When I develop a package, I use something like tox / nox but for apps – and that’s what I use PDM for due to it’s great locking – I would be happy to drop them! For most people, apps have only one Python version and don’t need any kind of matrices and that’s where I feel the line should be. Even if you develop a package you usually have one main Python version that you use but don’t necessarily want the dependencies from Don’t get me wrong: the above feature is already great and I’ll hide the invocations behind a Justfile or Makefile, but it would be really cool if you would consider a way to define venvs and map them to commands: [tool.pdm.venvs]
lint = { groups=["lint"] }
[tool.pdm.scripts]
lint = { venv= "lint", command="flake8" } Then you can say something like: That would keep it declarative yet explicit. The |
It seems not that different from a tox/hactch env, comparing: [tool.pdm.scripts.lint]
groups = ["lint"]
command = "flake8" If you map the env with a script, there is no need to create a venv manually for the script anymore. Running |
I’m not 100% sure how to parse your response. Are agreeing it would be nice, saying it’s bad, or even suggesting it already works and I’m bad at reading docs? 😅 |
i mean it would be a step too far into the field of tox, and i'd rather leave the possibility to a plugin on it's own, instead of building into pdm. |
I’m open to building my own plugins (like I did with hatch-fancy-pypi-readme :)). By your estimation: does PDM have all the necessary APIs to build a plugin that does what I’ve outlined? |
I think so, but there will be a refactor around the environments module, which is relevant to the plugin. |
Is your feature request related to a problem? Please describe.
The original idea comes from this comment by @hynek
Describe the solution you'd like
Introduce a new option
--venv VENV
so that when given a name, the matching virtual environment will be used as the environment for the particular operation, or PDM will raise an error if none matches.install
,sync
,add
,remove
,update
,list
,info
,run
,show
,use
.python.use_venv
to betrue
.Some other ideas
We will not extend the PDM scripts to automatically provision an environment when running
pdm run <task>
, since 1) it will require to supply with more information, such as which python to use to create that environment, which lockfile to use, and which groups to install; and 2) we don't want to compete withtox
andnox
, it should be easy to achieve the desired behavior with the said tools. Users need to prepare the environments as a preceding step.The text was updated successfully, but these errors were encountered: