From d95857c11969ac7c4c5b291242efd52be8202a6a Mon Sep 17 00:00:00 2001 From: neur1n Date: Fri, 7 Jun 2024 20:36:00 +0800 Subject: [PATCH] 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 --- .../virtual_environments/nu_conda/README.md | 2 +- .../virtual_environments/nu_conda/nu_conda.nu | 52 +++++++------ .../virtual_environments/nu_msvs/README.md | 2 +- .../virtual_environments/nu_msvs/nu_msvs.nu | 76 +++++++++---------- 4 files changed, 66 insertions(+), 66 deletions(-) diff --git a/modules/virtual_environments/nu_conda/README.md b/modules/virtual_environments/nu_conda/README.md index bee83c6..75d74fa 100644 --- a/modules/virtual_environments/nu_conda/README.md +++ b/modules/virtual_environments/nu_conda/README.md @@ -3,7 +3,7 @@ A simple module for activating and deactivating Conda environments. ## Prerequisites -- [nushell](https://github.com/nushell/nushell) >= 0.83.0 +- [nushell](https://github.com/nushell/nushell) >= 0.94.0 ## Installation diff --git a/modules/virtual_environments/nu_conda/nu_conda.nu b/modules/virtual_environments/nu_conda/nu_conda.nu index 89a9b4d..d17d15a 100644 --- a/modules/virtual_environments/nu_conda/nu_conda.nu +++ b/modules/virtual_environments/nu_conda/nu_conda.nu @@ -1,30 +1,32 @@ 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 = ( - if not (which mamba | is-empty) { - (mamba info --envs --json | from json) - } else if not (which conda | is-empty) { - (conda info --envs --json | from json) - } else { - ('{"root_prefix": "", "envs": ""}' | from json) - }) + let info = ( + if not (which mamba | is-empty) { + (mamba info --envs --json | from json) + } else if not (which conda | is-empty) { + (conda info --envs --json | from json) + } else { + ('{"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| - if $it == $info.root_prefix { - $acc | upsert "base" $it - } else { - $acc | upsert ($it | path basename) $it - }}) + $env.CONDA_ENVS = ($info.envs | reduce -f {} {|it, acc| + if $it == $info.root_prefix { + $acc | upsert "base" $it + } else { + $acc | upsert ($it | path basename) $it + }}) - $env.CONDA_CURR = null + $env.CONDA_CURR = null + } } export def --env activate [name: string] { if ($env.CONDA_ROOT | is-empty) { - print "Neither Conda nor Mamba is valid." + print "Neither Conda nor Mamba is available." return } @@ -35,7 +37,7 @@ export def --env activate [name: string] { } let new_path = ( - if ((sys).host.name == "Windows") { + if ((sys host).name == "Windows") { update-path-windows ($env.CONDA_ENVS | get $name) } else { update-path-linux ($env.CONDA_ENVS | get $name) @@ -46,7 +48,7 @@ export def --env activate [name: string] { export def --env deactivate [] { if ($env.CONDA_ROOT | is-empty) { - print "Neither Conda nor Mamba is valid." + print "Neither Conda nor Mamba is available." return } @@ -56,11 +58,11 @@ export def --env deactivate [] { } export def --env list [] { - $env.CONDA_ENVS | - flatten | - transpose | - rename name path | - insert active { |it| $it.name == $env.CONDA_CURR } | + $env.CONDA_ENVS | + flatten | + transpose | + rename name path | + insert active { |it| $it.name == $env.CONDA_CURR } | move path --after active } diff --git a/modules/virtual_environments/nu_msvs/README.md b/modules/virtual_environments/nu_msvs/README.md index c8be425..cf9bd97 100644 --- a/modules/virtual_environments/nu_msvs/README.md +++ b/modules/virtual_environments/nu_msvs/README.md @@ -3,7 +3,7 @@ A module for Using Microsoft Visual Studio (MSVS) command line tools from Nushel ## 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 diff --git a/modules/virtual_environments/nu_msvs/nu_msvs.nu b/modules/virtual_environments/nu_msvs/nu_msvs.nu index ee0db76..1dbfa83 100644 --- a/modules/virtual_environments/nu_msvs/nu_msvs.nu +++ b/modules/virtual_environments/nu_msvs/nu_msvs.nu @@ -1,38 +1,42 @@ export-env { - $env.MSVS_BASE_PATH = $env.Path + if not ("MSVS_ACTIVATED" in $env) { + $env.MSVS_BASE_PATH = $env.Path - let info = ( - if not (which vswhere | is-empty) { - (vswhere -format json | from json) - } else { - ('{"installationPath": [""]}' | from json) - } - ) + let info = ( + if not (which vswhere | is-empty) { + (vswhere -format json | from json) + } else { + ('{"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 = ( - if not ($"($env.MSVS_ROOT)/VC/Tools/MSVC/" | path exists) { - "" - } else if (ls ($"($env.MSVS_ROOT)/VC/Tools/MSVC/*" | into glob) | is-empty) { - "" - } else { - ((ls ($"($env.MSVS_ROOT)/VC/Tools/MSVC/*" | into glob)).name.0 | str replace -a '\\' '/') - }) + $env.MSVS_MSVC_ROOT = ( + if not ($"($env.MSVS_ROOT)/VC/Tools/MSVC/" | path exists) { + "" + } else if (ls ($"($env.MSVS_ROOT)/VC/Tools/MSVC/*" | into glob) | is-empty) { + "" + } else { + ((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_ROOT)/Include/($env.MSVS_MSDK_VER)/cppwinrt/winrt", - $"($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)/shared", - $"($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)/winrt" - ] | str join ";") + $env.MSVS_INCLUDE_PATH = ([ + $"($env.MSVS_ROOT)/Include/($env.MSVS_MSDK_VER)/cppwinrt/winrt", + $"($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)/shared", + $"($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)/winrt" + ] | str join ";") + + $env.MSVS_ACTIVATED = false + } } 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 ] { 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 } @@ -125,17 +129,12 @@ export def --env activate [ LIB: $lib_path } - hide-env MSVS_BASE_PATH - hide-env MSVS_ROOT - hide-env MSVS_MSVC_ROOT - hide-env MSVS_MSDK_ROOT - hide-env MSVS_MSDK_VER - hide-env MSVS_INCLUDE_PATH + $env.MSVS_ACTIVATED = true } export def --env deactivate [] { - if (($env.MSVS_ROOT | is-empty) or ($env.MSVS_MSVC_ROOT | is-empty)) { - print "Either Microsoft Visual Studio or MSVC is valid." + if (($env.MSVS_ROOT? | is-empty) or ($env.MSVS_MSVC_ROOT? | is-empty)) { + print "Neither Microsoft Visual Studio nor MSVC is available." return } @@ -144,6 +143,5 @@ export def --env deactivate [] { PATH: $env.MSVS_BASE_PATH } - hide-env INCLUDE - hide-env LIB + $env.MSVS_ACTIVATED = false }