-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNew-PythonVenv.ps1
More file actions
32 lines (26 loc) · 1.18 KB
/
New-PythonVenv.ps1
File metadata and controls
32 lines (26 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<#
.SYNOPSIS
Create or refresh a Python virtual environment.
.DESCRIPTION
This script requires a `pyproject.toml` configuration file, and
* if present, installs the corresponding package in editable mode
* if present, installs the "dev" dependency group,
The virtual enviroment is replaced if it already exists.
The pinned versions specified e.g. in `uv.lock` or `pylock.toml` are ignored.
Requires uv <https://docs.astral.sh/uv/>.
.EXAMPLE
PS> .\scripts\New-PythonVenv.ps1
#>
#Requires -Version 7.4
$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $true
Import-Module -Name "$PSScriptRoot\Utils.psm1"
"Project root folder: $(Get-ProjectRootFolder)" | Write-Host
$UvRunOptions = Get-UvRunOptions
# As of uv 0.8.15, `uv sync` does not support an `--env-file` option like `uv run` does,
# so we run `uv sync` through `uv run`.
# Trick from https://github.com/astral-sh/uv/issues/8862#issuecomment-2474164670
uv run $UvRunOptions uv sync --upgrade
$PythonVersion = uv run $UvRunOptions python --version
$PythonPath = uv run $UvRunOptions python -c "import sys; print(sys.executable)"
"$PythonVersion at $PythonPath" | Write-Host