1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-01 06:37:46 +00:00

Add Windows support for venv

As with the Conda script, a few differences have to be considered
when activating on Windows, namely that the correct env var is Path
and the directory containing the executables is "Scripts", not "bin"
This commit is contained in:
Hristo Filaretov 2021-08-05 11:07:46 +02:00
parent 9c7822aa18
commit 6def5d5517
2 changed files with 22 additions and 9 deletions

View file

@ -1,12 +1,25 @@
def venv [name] {
let venv-path = ($name | path expand)
let venv-bin-path = ([$venv-path "bin"] | path join)
def venv [venv-dir] {
let venv-abs-dir = ($venv-dir | path expand)
let venv-name = ($venv-abs-dir | path basename)
let old-path = ($nu.path | str collect (path-sep))
let new-path = ($nu.path | prepend $venv-bin-path | str collect (path-sep))
[[name, value];
[PATH $new-path]
let new-path = (if (windows?) { (venv-path-windows $venv-abs-dir) } { (venv-path-unix $venv-abs-dir) })
let new-env = [[name, value];
[VENV_OLD_PATH $old-path]
[VIRTUAL_ENV $venv-path]]
[VIRTUAL_ENV $venv-name]]
$new-env | append $new-path
}
def venv-path-unix [venv-dir] {
let venv-path = ([$venv-dir "bin"] | path join)
let new-path = ($nu.path | prepend $venv-path | str collect (path-sep))
[[name, value]; [PATH $new-path]]
}
def venv-path-windows [venv-dir] {
let venv-path = ([$venv-dir "Scripts"] | path join)
let new-path = ($nu.path | prepend $venv-path | str collect (path-sep))
[[name, value]; [Path $new-path]]
}
def windows? [] {
@ -16,4 +29,3 @@ def windows? [] {
def path-sep [] {
if (windows?) { ";" } { ":" }
}

View file

@ -1,3 +1,4 @@
let-env PATH = $nu.env.VENV_OLD_PATH
let path-name = (if ((sys).host.name == "Windows") { "Path" } { "PATH" })
let-env $path-name = $nu.env.VENV_OLD_PATH
unlet-env VIRTUAL_ENV
unlet-env VENV_OLD_PATH