Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolve several issues in nu_conda and nu_msvs #872

Merged
merged 1 commit into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 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.83.0
- [nushell](https://github.com/nushell/nushell) >= 0.94.0


## Installation
Expand Down
60 changes: 31 additions & 29 deletions modules/virtual_environments/nu_conda/nu_conda.nu
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
export-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)
})

$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_CURR = null
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)
})

$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_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
}

Expand All @@ -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)
Expand All @@ -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
}

Expand All @@ -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
}

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.91.0
- [nushell](https://github.com/nushell/nushell) >= 0.94.0
- [vswhere](https://github.com/microsoft/vswhere) standalone or comes with VS


Expand Down
88 changes: 43 additions & 45 deletions modules/virtual_environments/nu_msvs/nu_msvs.nu
Original file line number Diff line number Diff line change
@@ -1,38 +1,42 @@
export-env {
$env.MSVS_BASE_PATH = $env.Path

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_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_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 ";")
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)
}
)

$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_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_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 [
Expand All @@ -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
}

Expand Down Expand Up @@ -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
}

Expand All @@ -144,6 +143,5 @@ export def --env deactivate [] {
PATH: $env.MSVS_BASE_PATH
}

hide-env INCLUDE
hide-env LIB
$env.MSVS_ACTIVATED = false
}
Loading