Skip to content

Commit

Permalink
minor changes to nu_conda.nu and nu_msvs.nu (#576)
Browse files Browse the repository at this point in the history
1. feat(nu_conda): add `nu_conda list` to list available envs
2. fix: use `print` instead of `echo` to print warnings
3. doc: change minimum support version to 0.83.0
  • Loading branch information
neur1n authored Aug 12, 2023
1 parent 90a8b0d commit e60d207
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 16 deletions.
3 changes: 2 additions & 1 deletion modules/virtual_environments/nu_conda/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ A simple module for activating and deactivating Conda environments.


## Prerequisites
- [nushell](https://github.com/nushell/nushell) >= 0.73.0
- [nushell](https://github.com/nushell/nushell) >= 0.83.0


## Installation
Expand All @@ -15,6 +15,7 @@ Put `nu_conda.nu` into the module folder of your nushell configuration workspace
use nu_conda.nu # activate module
nu_conda activate py36 # activate a Conda environment, e.g. py36
nu_conda deactivate # deactivate the activated Conda environment
nu_conda list # list available environments, same as `$env.CONDA_ENVS`
```

## How It Works
Expand Down
14 changes: 9 additions & 5 deletions modules/virtual_environments/nu_conda/nu_conda.nu
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,13 @@ export-env {

export def-env activate [name: string] {
if ($env.CONDA_ROOT | is-empty) {
echo "Neither Conda nor Mamba is valid."
print "Neither Conda nor Mamba is valid."
return
}

if not $name in $env.CONDA_ENVS {
echo $"Environment ($name) is invalid. Available:"
echo $env.CONDA_ENVS
if not ($name in $env.CONDA_ENVS) {
print $"Environment ($name) is invalid. Available:"
print $env.CONDA_ENVS
return
}

Expand All @@ -46,7 +46,7 @@ export def-env activate [name: string] {

export def-env deactivate [] {
if ($env.CONDA_ROOT | is-empty) {
echo "Neither Conda nor Mamba is valid."
print "Neither Conda nor Mamba is valid."
return
}

Expand All @@ -55,6 +55,10 @@ export def-env deactivate [] {
load-env {Path: $env.CONDA_BASE_PATH, PATH: $env.CONDA_BASE_PATH}
}

export def-env list [] {
print $env.CONDA_ENVS
}

def update-path-linux [env_path: path] {
let env_path = [
$env_path,
Expand Down
2 changes: 1 addition & 1 deletion modules/virtual_environments/nu_msvs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.73.0
- [nushell](https://github.com/nushell/nushell) >= 0.83.0
- [vswhere](https://github.com/microsoft/vswhere) standalone or comes with VS


Expand Down
27 changes: 18 additions & 9 deletions modules/virtual_environments/nu_msvs/nu_msvs.nu
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ export-env {
((ls $"($env.MSVS_ROOT)/VC/Tools/MSVC/*").name.0 | str replace -a '\\' '/')
})

$env.MSVS_MSDK_ROOT = (REG QUERY 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' /v "InstallationFolder" | str replace '(.|\n)+REG_SZ\s+(.+)' "$2")
$env.MSVS_MSDK_ROOT = ($env.MSVS_MSDK_ROOT | str replace -a '\\' '/')
$env.MSVS_MSDK_ROOT = (registry query --hklm 'SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' InstallationFolder | get value)

$env.MSVS_MSDK_VER = (REG QUERY 'HKLM\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\Windows\v10.0' /v "ProductVersion" | str replace '(.|\n)+REG_SZ\s+(.+)' "$2")
$env.MSVS_MSDK_VER = $"($env.MSVS_MSDK_VER).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",
Expand All @@ -43,7 +41,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)) {
echo "Either Microsoft Visual Studio or MSVC is valid."
print "Either Microsoft Visual Studio or MSVC is valid."
return
}

Expand All @@ -57,19 +55,19 @@ export def-env activate [
})

if (($fh != "x64") and ($fh != "x86")) {
echo $"Wrong host architecture specified: ($fh)."
print $"Wrong host architecture specified: ($fh)."
help n_msvc activate
return
}

if (($ft != "x64") and ($ft != "x86")) {
echo $"Wrong target architecture specified: ($ft)."
print $"Wrong target architecture specified: ($ft)."
help n_msvc activate
return
}

if not ($"($env.MSVS_MSDK_ROOT)bin/($fs)" | path exists) {
echo $"Invalid Windows SDK version specified: ($fs)."
print $"Invalid Windows SDK version specified: ($fs)."
return
}

Expand All @@ -84,6 +82,7 @@ export def-env activate [
$"($env.MSVS_ROOT)/Common7/Tools/devinit",
$"($env.MSVS_ROOT)/MSBuild/Current/bin",
$"($env.MSVS_ROOT)/MSBuild/Current/bin/Roslyn",
$"($env.MSVS_ROOT)/Team Tools/DiagnosticsHub/Collector",
$"($env.MSVS_ROOT)/Team Tools/Performance Tools",
$"($env.MSVS_MSVC_ROOT)/bin/Host($fh)/($ft)",
$"($env.MSVS_MSDK_ROOT)bin/($ft)",
Expand Down Expand Up @@ -125,16 +124,26 @@ export def-env activate [
INCLUDE: $env.MSVS_INCLUDE_PATH,
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
}

export def-env deactivate [] {
if (($env.MSVS_ROOT | is-empty) or ($env.MSVS_MSVC_ROOT | is-empty)) {
echo "Either Microsoft Visual Studio or MSVC is valid."
print "Either Microsoft Visual Studio or MSVC is valid."
return
}

load-env {
Path: $env.MSVS_BASE_PATH,
PATH: $env.MSVS_BASE_PATH
}

hide-env INCLUDE
hide-env LIB
}

0 comments on commit e60d207

Please sign in to comment.