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

resolve several issues in nu_conda and nu_msvs (#872)

1. fix: update `(sys).host` to `sys host` to work for 0.94.x
2. fix: handle incorrect behaviors when re-importing nu_conda or nu_msvs
3. doc: update minimum requirements of nushell in README.md
This commit is contained in:
neur1n 2024-06-07 20:36:00 +08:00 committed by GitHub
parent de2829091f
commit d95857c119
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 66 additions and 66 deletions

View file

@ -3,7 +3,7 @@ A simple module for activating and deactivating Conda environments.
## Prerequisites ## Prerequisites
- [nushell](https://github.com/nushell/nushell) >= 0.83.0 - [nushell](https://github.com/nushell/nushell) >= 0.94.0
## Installation ## Installation

View file

@ -1,30 +1,32 @@
export-env { export-env {
$env.CONDA_BASE_PATH = (if ((sys).host.name == "Windows") {$env.Path} else {$env.PATH}) if not ("CONDA_CURR" in $env) {
$env.CONDA_BASE_PATH = (if ((sys host).name == "Windows") {$env.Path} else {$env.PATH})
let info = ( let info = (
if not (which mamba | is-empty) { if not (which mamba | is-empty) {
(mamba info --envs --json | from json) (mamba info --envs --json | from json)
} else if not (which conda | is-empty) { } else if not (which conda | is-empty) {
(conda info --envs --json | from json) (conda info --envs --json | from json)
} else { } else {
('{"root_prefix": "", "envs": ""}' | from json) ('{"root_prefix": "", "envs": ""}' | from json)
}) })
$env.CONDA_ROOT = $info.root_prefix $env.CONDA_ROOT = $info.root_prefix
$env.CONDA_ENVS = ($info.envs | reduce -f {} {|it, acc| $env.CONDA_ENVS = ($info.envs | reduce -f {} {|it, acc|
if $it == $info.root_prefix { if $it == $info.root_prefix {
$acc | upsert "base" $it $acc | upsert "base" $it
} else { } else {
$acc | upsert ($it | path basename) $it $acc | upsert ($it | path basename) $it
}}) }})
$env.CONDA_CURR = null $env.CONDA_CURR = null
}
} }
export def --env activate [name: string] { export def --env activate [name: string] {
if ($env.CONDA_ROOT | is-empty) { if ($env.CONDA_ROOT | is-empty) {
print "Neither Conda nor Mamba is valid." print "Neither Conda nor Mamba is available."
return return
} }
@ -35,7 +37,7 @@ export def --env activate [name: string] {
} }
let new_path = ( let new_path = (
if ((sys).host.name == "Windows") { if ((sys host).name == "Windows") {
update-path-windows ($env.CONDA_ENVS | get $name) update-path-windows ($env.CONDA_ENVS | get $name)
} else { } else {
update-path-linux ($env.CONDA_ENVS | get $name) update-path-linux ($env.CONDA_ENVS | get $name)
@ -46,7 +48,7 @@ export def --env activate [name: string] {
export def --env deactivate [] { export def --env deactivate [] {
if ($env.CONDA_ROOT | is-empty) { if ($env.CONDA_ROOT | is-empty) {
print "Neither Conda nor Mamba is valid." print "Neither Conda nor Mamba is available."
return return
} }
@ -56,11 +58,11 @@ export def --env deactivate [] {
} }
export def --env list [] { export def --env list [] {
$env.CONDA_ENVS | $env.CONDA_ENVS |
flatten | flatten |
transpose | transpose |
rename name path | rename name path |
insert active { |it| $it.name == $env.CONDA_CURR } | insert active { |it| $it.name == $env.CONDA_CURR } |
move path --after active move path --after active
} }

View file

@ -3,7 +3,7 @@ A module for Using Microsoft Visual Studio (MSVS) command line tools from Nushel
## Prerequisites ## Prerequisites
- [nushell](https://github.com/nushell/nushell) >= 0.91.0 - [nushell](https://github.com/nushell/nushell) >= 0.94.0
- [vswhere](https://github.com/microsoft/vswhere) standalone or comes with VS - [vswhere](https://github.com/microsoft/vswhere) standalone or comes with VS

View file

@ -1,38 +1,42 @@
export-env { export-env {
$env.MSVS_BASE_PATH = $env.Path if not ("MSVS_ACTIVATED" in $env) {
$env.MSVS_BASE_PATH = $env.Path
let info = ( let info = (
if not (which vswhere | is-empty) { if not (which vswhere | is-empty) {
(vswhere -format json | from json) (vswhere -format json | from json)
} else { } else {
('{"installationPath": [""]}' | from json) ('{"installationPath": [""]}' | from json)
} }
) )
$env.MSVS_ROOT = ($info.installationPath.0 | str replace -a '\\' '/') $env.MSVS_ROOT = ($info.installationPath.0 | str replace -a '\\' '/')
$env.MSVS_MSVC_ROOT = ( $env.MSVS_MSVC_ROOT = (
if not ($"($env.MSVS_ROOT)/VC/Tools/MSVC/" | path exists) { if not ($"($env.MSVS_ROOT)/VC/Tools/MSVC/" | path exists) {
"" ""
} else if (ls ($"($env.MSVS_ROOT)/VC/Tools/MSVC/*" | into glob) | is-empty) { } else if (ls ($"($env.MSVS_ROOT)/VC/Tools/MSVC/*" | into glob) | is-empty) {
"" ""
} else { } else {
((ls ($"($env.MSVS_ROOT)/VC/Tools/MSVC/*" | into glob)).name.0 | str replace -a '\\' '/') ((ls ($"($env.MSVS_ROOT)/VC/Tools/MSVC/*" | into glob)).name.0 | str replace -a '\\' '/')
}) })
$env.MSVS_MSDK_ROOT = (registry query --hklm 'SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder | get value) $env.MSVS_MSDK_ROOT = (registry query --hklm 'SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder | get value)
$env.MSVS_MSDK_VER = (registry query --hklm 'SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' ProductVersion | get value) + ".0" $env.MSVS_MSDK_VER = (registry query --hklm 'SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' ProductVersion | get value) + ".0"
$env.MSVS_INCLUDE_PATH = ([ $env.MSVS_INCLUDE_PATH = ([
$"($env.MSVS_ROOT)/Include/($env.MSVS_MSDK_VER)/cppwinrt/winrt", $"($env.MSVS_ROOT)/Include/($env.MSVS_MSDK_VER)/cppwinrt/winrt",
$"($env.MSVS_MSVC_ROOT)/include", $"($env.MSVS_MSVC_ROOT)/include",
$"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/cppwinrt/winrt", $"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/cppwinrt/winrt",
$"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/shared", $"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/shared",
$"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/ucrt", $"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/ucrt",
$"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/um", $"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/um",
$"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/winrt" $"($env.MSVS_MSDK_ROOT)Include/($env.MSVS_MSDK_VER)/winrt"
] | str join ";") ] | str join ";")
$env.MSVS_ACTIVATED = false
}
} }
export def --env activate [ export def --env activate [
@ -41,7 +45,7 @@ export def --env activate [
--sdk (-s): string = "latest" # Version of Windows SDK, must be "latest" or a valid version string --sdk (-s): string = "latest" # Version of Windows SDK, must be "latest" or a valid version string
] { ] {
if (($env.MSVS_ROOT | is-empty) or ($env.MSVS_MSVC_ROOT | is-empty)) { if (($env.MSVS_ROOT | is-empty) or ($env.MSVS_MSVC_ROOT | is-empty)) {
print "Either Microsoft Visual Studio or MSVC is valid." print "Neither Microsoft Visual Studio nor MSVC is available."
return return
} }
@ -125,17 +129,12 @@ export def --env activate [
LIB: $lib_path LIB: $lib_path
} }
hide-env MSVS_BASE_PATH $env.MSVS_ACTIVATED = true
hide-env MSVS_ROOT
hide-env MSVS_MSVC_ROOT
hide-env MSVS_MSDK_ROOT
hide-env MSVS_MSDK_VER
hide-env MSVS_INCLUDE_PATH
} }
export def --env deactivate [] { export def --env deactivate [] {
if (($env.MSVS_ROOT | is-empty) or ($env.MSVS_MSVC_ROOT | is-empty)) { if (($env.MSVS_ROOT? | is-empty) or ($env.MSVS_MSVC_ROOT? | is-empty)) {
print "Either Microsoft Visual Studio or MSVC is valid." print "Neither Microsoft Visual Studio nor MSVC is available."
return return
} }
@ -144,6 +143,5 @@ export def --env deactivate [] {
PATH: $env.MSVS_BASE_PATH PATH: $env.MSVS_BASE_PATH
} }
hide-env INCLUDE $env.MSVS_ACTIVATED = false
hide-env LIB
} }