Skip to main content

A plugin for pdm that enables virtualenv management

Project description

pdm-venv

Tests pypi version pre-commit Code style: black

A plugin for pdm that enables virtualenv management

Requirements

pdm-venv requires Python>=3.7

Installation

On PDM 1.6.4+, you can install the plugin directly by:

$ pdm plugin add pdm-venv

If pdm is installed via pipx(the recommended way), run:

$ pipx inject pdm pdm-venv

Otherwise if pdm is installed via Homebrew, run:

$ $(brew --prefix pdm)/libexec/bin/pip install pdm-venv

Or install with pip to the user site:

$ python -m pip install --user pdm-venv

Note that pdm-venv must be installed to the same environment as pdm.

Usage

pdm-venv enhances pdm's CLI with the support of virtualenv creation and management. With pdm-venv installed, the default value of use_venv will turn to True, you can disable the whole plugin by pdm config use_venv false.

Create a virtualenv

# Create a virtualenv based on 3.8 interpreter
$ pdm venv create 3.8
# Assign a different name other than the version string
$ pdm venv create --name for-test 3.8
# Use venv as the backend to create, support 3 backends: virtualenv(default), venv, conda
$ pdm venv create --with venv 3.9

List all virtualenv created with this project

$ pdm venv list
Virtualenvs created with this project:

-  3.8.6: C:\Users\Frost Ming\AppData\Local\pdm\pdm\venvs\test-project-8Sgn_62n-3.8.6
-  for-test: C:\Users\Frost Ming\AppData\Local\pdm\pdm\venvs\test-project-8Sgn_62n-for-test
-  3.9.1: C:\Users\Frost Ming\AppData\Local\pdm\pdm\venvs\test-project-8Sgn_62n-3.9.1

The name before the colon(:) is the key of the virtualenv which is used in remove and activate commands below.

Remove a virtualenv

$ pdm venv remove for-test
Virtualenvs created with this project:
Will remove: C:\Users\Frost Ming\AppData\Local\pdm\pdm\venvs\test-project-8Sgn_62n-for-test, continue? [y/N]:y
Removed C:\Users\Frost Ming\AppData\Local\pdm\pdm\venvs\test-project-8Sgn_62n-for-test

Activate a virtualenv

Instead of spawning a subshell like what pipenv and poetry do, pdm-venv doesn't create the shell for you but print the activate command to the console. In this way you won't lose the fancy shell features. You can then feed the output to eval to activate the virtualenv without leaving the current shell:

Bash/csh/zsh

$ eval $(pdm venv activate for-test)
(test-project-8Sgn_62n-for-test) $  # Virtualenv entered

Fish

$ eval (pdm venv activate for-test)

Powershell

PS1> Invoke-Expression (pdm venv activate for-test)

You can make your own shell shortcut function to avoid the input of long command. Here is an example of Bash:

pdm_venv_activate() {
    eval $('pdm' 'venv' 'activate' "$1")
}

Then you can activate it by pdm_venv_activate $venv_name and deactivate by deactivate directly.

Additionally, if the saved Python interpreter is a venv Python, you can omit the name argument following activate.

Switch Python interpreter

When pdm-venv is enabled, Python interpreters associated with the venvs will also show in the interpreter list of pdm use or pdm init command.

Additionally, if pdm detects it is inside an active virtualenv by examining VIRTUAL_ENV env var, it will reuse that virtualenv for later actions.

Virtualenv auto creation

If no Python interpreter is selected for the project, pdm-venv will take charge to create one for you and select the venv interpreter automatically, just like what pipenv and poetry do. Additionaly, if config item venv.in_project is True, pdm-venv will create the virtualenv in ${PROJECT_ROOT}/.venv.

Configuration

Config Item Description Default Value Available in Project Env var
venv.location The root directory to store virtualenvs appdirs.user_data_dir() / "venvs" No
venv.backend The default backend used to create virtualenvs virtualenv No
venv.in_project Create virtualenv in .venv under project root False Yes PDM_VENV_IN_PROJECT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pdm-venv-0.5.0.tar.gz (13.3 kB view details)

Uploaded Source

Built Distribution

pdm_venv-0.5.0-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file pdm-venv-0.5.0.tar.gz.

File metadata

  • Download URL: pdm-venv-0.5.0.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for pdm-venv-0.5.0.tar.gz
Algorithm Hash digest
SHA256 fbe9e3ea13f79c9b18ec7eb11ceec7ae161cf55d1a6fac3edbfe86ab451609f2
MD5 68a602e6eda486d251a66242af8c8ec0
BLAKE2b-256 e8caf9149acb53c70732ced0bd504d3ffd286d6aa75ab5244f0be617bf92d032

See more details on using hashes here.

Provenance

File details

Details for the file pdm_venv-0.5.0-py3-none-any.whl.

File metadata

  • Download URL: pdm_venv-0.5.0-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/32.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.62.3 importlib-metadata/4.11.1 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.8.12

File hashes

Hashes for pdm_venv-0.5.0-py3-none-any.whl
Algorithm Hash digest
SHA256 92419606b7f6a5fd5c5e8e0be8208937dc2d2f54ceb25d736a74c050938928bc
MD5 baed71b6a9d88bbb53ccb0f53296e866
BLAKE2b-256 1b9c4e5ee2ff2ebad89d12a0472bfc6160b994994368d8193dff330b4e2565f2

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page