From f617a31beb4efbd6f07577e3e22a32add166bd0c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C4=B0sa=20C=C4=B0REL=C4=B0?= <128389454+isa-murat@users.noreply.github.com> Date: Mon, 21 Jul 2025 20:34:02 +0300 Subject: [PATCH] Implemented PowerShell support for virtualenvwrapper functionality (mkvirtualenv, workon, rmvirtualenv) --- README.rst | 37 ++++++++++++++++++++++++ scripts/virtualenvwrapper.ps1 | 53 +++++++++++++++++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 scripts/virtualenvwrapper.ps1 diff --git a/README.rst b/README.rst index fbf7a32..86ccb54 100644 --- a/README.rst +++ b/README.rst @@ -48,6 +48,43 @@ By default, this is ``%USERPROFILE%\Envs``. ~~~~~~~~~~~~~~~~~~~~ **pywin** python version switcher (not included) +PowerShell Support +================== + +PowerShell support has been added to this project. Windows PowerShell users can now use `virtualenvwrapper`-like functionality with familiar commands. + +Installation +------------ + +1. Place the ``virtualenvwrapper.ps1`` file in a suitable directory. +2. Open your PowerShell profile: + + .. code-block:: powershell + + notepad $PROFILE + +3. Add the following line at the end of the profile file: + + .. code-block:: powershell + + . "C:\path\to\virtualenvwrapper.ps1" + +Usage +----- + +.. code-block:: powershell + + mkvirtualenv myenv # Creates and activates a new virtual environment + workon myenv # Activates an existing virtual environment + workon # Lists all available environments + rmvirtualenv myenv # Removes the specified virtual environment + +Note +---- + +This script provides a user experience similar to the original ``virtualenvwrapper`` on Linux/macOS systems. + + If you use several versions of python, you can switch between them using a separate project `pywin `_. It's a lightweight diff --git a/scripts/virtualenvwrapper.ps1 b/scripts/virtualenvwrapper.ps1 new file mode 100644 index 0000000..8375158 --- /dev/null +++ b/scripts/virtualenvwrapper.ps1 @@ -0,0 +1,53 @@ +$env:WORKON_HOME = "$HOME\Envs" + +function workon { + param ( + [String]$env + ) + if ($env) { + if (Test-Path "$env:WORKON_HOME\$env\Scripts\activate.ps1") { + . "$env:WORKON_HOME\$env\Scripts\activate.ps1" + } + else { + Write-Host "virtualenv '$env' does not exist." + Write-Host "Create it with 'mkvirtualenv $env'" + } + } + else { + Write-Host "Pass a name to activate one of the following virtualenvs:" + Write-Host "===============================================================" + Get-ChildItem $env:WORKON_HOME -Name + } +} + +function mkvirtualenv { + param ( + [String]$env + ) + if ($env) { + python -m venv "$env:WORKON_HOME\$env" + . "$env:WORKON_HOME\$env\Scripts\activate.ps1" + } + else { + Write-Host "Please provide a name for the virtual environment." + } +} + +function rmvirtualenv { + param ( + [String]$env + ) + if ($env) { + if (Test-Path "$env:WORKON_HOME\$env") { + Removeⷃ + Remove-Item -Path "$env:WORKON_HOME\$env" -Recurse -Force + Write-Host "Deleted $env:WORKON_HOME\$env" + } + else { + Write-Host "virtualenv '$env' does not exist." + } + } + else { + Write-Host "Please provide a name for the virtual environment." + } +} \ No newline at end of file