-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet-VenvOutsideProject.ps1
More file actions
38 lines (32 loc) · 1.24 KB
/
Set-VenvOutsideProject.ps1
File metadata and controls
38 lines (32 loc) · 1.24 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
33
34
35
36
37
38
<#
.SYNOPSIS
Tell `uv` to store the Python virtual environment outside the project folder.
.DESCRIPTION
Write an .env file inside the project root folder with an environment variable
that tells `uv` to store the Python virtual environment under the $VenvRootFolder
defined below.
Placing the environment outside the project folder avoids synchronization issues
with Microsoft OneDrive, e.g. <https://github.com/astral-sh/uv/issues/7906>.
Errors if the .env file already exists.
.EXAMPLE
PS> .\scripts\Set-VenvOutsideProject.ps1
#>
Param (
# Where to put the Python virtual environment.
[string]$VenvRootFolder = "C:\venvs"
)
#Requires -Version 7.4
$ErrorActionPreference = "Stop"
$PSNativeCommandUseErrorActionPreference = $true
Import-Module -Name "$PSScriptRoot\Utils.psm1"
$VenvFolder = Join-Path $VenvRootFolder $(Get-ProjectName)
# uv accepts here only forward slashes as path separator.
$Setting = "UV_PROJECT_ENVIRONMENT=$VenvFolder".Replace("\", "/")
$EnvFilePath = Get-EnvFilePath
if (Test-Path $EnvFilePath -PathType Leaf) {
throw "$EnvFilePath already exists. Edit it by hand to include $Setting. Quitting."
}
else {
$Setting | Out-File $EnvFilePath
"Written $EnvFilePath" | Write-Host
}