From 5a98ca3d921a3650c6b9ee7c20f8e1a2da90dbd9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sat, 5 Feb 2022 00:34:28 +0200 Subject: [PATCH 01/16] Start updating nushell scripts for new version --- src/virtualenv/activation/nushell/activate.nu | 132 ++++++++++++------ .../activation/nushell/deactivate.nu | 29 ++-- tests/unit/activation/test_nushell.py | 2 +- 3 files changed, 113 insertions(+), 50 deletions(-) diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu index 9c1e2c290..8089ec731 100644 --- a/src/virtualenv/activation/nushell/activate.nu +++ b/src/virtualenv/activation/nushell/activate.nu @@ -1,41 +1,93 @@ -# Setting all environment variables for the venv -let path-name = (if ((sys).host.name == "Windows") { "Path" } { "PATH" }) -let virtual-env = "__VIRTUAL_ENV__" -let bin = "__BIN_NAME__" -let path-sep = "__PATH_SEP__" - -let old-path = ($nu.path | str collect ($path-sep)) - -let venv-path = ([$virtual-env $bin] | path join) -let new-path = ($nu.path | prepend $venv-path | str collect ($path-sep)) - -# environment variables that will be batched loaded to the virtual env -let new-env = ([ - [name, value]; - [$path-name $new-path] - [_OLD_VIRTUAL_PATH $old-path] - [VIRTUAL_ENV $virtual-env] -]) - -load-env $new-env - -# Creating the new prompt for the session -let virtual_prompt = (if ("__VIRTUAL_PROMPT__" != "") { - "(__VIRTUAL_PROMPT__) " -} { - (build-string '(' ($virtual-env | path basename) ') ') +# This command prepares the required environment variables +def-env activate-virtualenv [] { + def is-string [x] { + ($x | describe) == "string" + } + + def has-env [name: string] { + $name in (env).name + } + + let is-windows = ((sys).host.name | str downcase) == "windows" + let virtual-env = "__VIRTUAL_ENV__" + let bin = "__BIN_NAME__" + let path-sep = "__PATH_SEP__" + let path-name = if $is-windows { + "Path" + } else { + "PATH" + } + + let old-path = ( + if $is-windows { + $env.Path + } else { + $env.PATH + } | if (is-string $in) { + # if Path/PATH is a string, make it a list + $in | split row $path-sep | path expand + } else { + $in + } + ) + + let venv-path = ([$virtual-env $bin] | path join) + let new-path = ($old-path | prepend $venv-path) + + # Creating the new prompt for the session + let virtual-prompt = ( + if ("__VIRTUAL_PROMPT__" == "") { + $"(char lparen)($virtual-env | path basename)(char rparen)" + } else { + "(__VIRTUAL_PROMPT__) " + } + ) + + # Back up the old prompt builder + let old-prompt-command = if (has-env "VIRTUAL_ENV") { + $env._OLD_PROMPT_COMMAND + } else { + if (has-env "PROMPT_COMMAND") { + $env.PROMPT_COMMAND + } else { + "" + } + } + + # If there is no default prompt, then only the env is printed in the prompt + let new-prompt = if (has-env "PROMPT_COMMAND") { + ($"build-string '($virtual-prompt)' (config get prompt | str find-replace "build-string" "")") + #TODO: Check for block vs string! + if ($env.PROMPT_COMMAND | describe) == "block" { + { $"($virtual-prompt)(do $env.PROMPT_COMMAND)" } + } else { + { $"($virtual-prompt)($env.PROMPT_COMMAND)" } + } + } else { + { $"($virtual-prompt)" } + } + + # Environment variables that will be batched loaded to the virtual env + let new-env = { + $path-name : $new-path + _OLD_VIRTUAL_PATH : $old-path + VIRTUAL_ENV : $virtual-env + _OLD_PROMPT_COMMAND : $old-prompt-command + PROMPT_COMMAND : $new-prompt + VIRTUAL_PROMPT : $virtual-prompt + } + + # Activate the environment variables + load-env $new-env +} + +def pydoc [] { + python -m pydoc } -) - -# If there is no default prompt, then only the env is printed in the prompt -let new_prompt = (if ( config | select prompt | empty? ) { - ($"build-string '($virtual_prompt)'") -} { - ($"build-string '($virtual_prompt)' (config get prompt | str find-replace "build-string" "")") -}) -let-env PROMPT_COMMAND = $new_prompt - -# We are using alias as the function definitions because only aliases can be -# removed from the scope -alias pydoc = python -m pydoc -alias deactivate = source "__DEACTIVATE_PATH__" + +def-env deactivate [] { + source "__DEACTIVATE_PATH__" +} + +# Activate the virtualenv +activate-virtualenv diff --git a/src/virtualenv/activation/nushell/deactivate.nu b/src/virtualenv/activation/nushell/deactivate.nu index 405243803..c1445ced4 100644 --- a/src/virtualenv/activation/nushell/deactivate.nu +++ b/src/virtualenv/activation/nushell/deactivate.nu @@ -1,11 +1,22 @@ -# Setting the old path -let path-name = (if ((sys).host.name == "Windows") { "Path" } { "PATH" }) -let-env $path-name = $nu.env._OLD_VIRTUAL_PATH +def-env deactivate-virtualenv [] { + let is-windows = ((sys).host.name | str downcase) == "windows" -# Unleting the environment variables that were created when activating the env -unlet-env VIRTUAL_ENV -unlet-env _OLD_VIRTUAL_PATH -unlet-env PROMPT_COMMAND + let path-name = if $is-windows { + "Path" + } else { + "PATH" + } -unalias pydoc -unalias deactivate + load-env { $path-name : $env._OLD_VIRTUAL_PATH } + + # Hiding the environment variables that were created when activating the env + hide _OLD_VIRTUAL_PATH + hide VIRTUAL_ENV + hide PROMPT_COMMAND + hide VIRTUAL_PROMPT +} + +deactivate-virtualenv + +hide pydoc +hide deactivate diff --git a/tests/unit/activation/test_nushell.py b/tests/unit/activation/test_nushell.py index 6a9c6b96e..40a7b63d4 100644 --- a/tests/unit/activation/test_nushell.py +++ b/tests/unit/activation/test_nushell.py @@ -24,6 +24,6 @@ def __init__(self, session): self.unix_line_ending = not IS_WIN def print_prompt(self): - return r"echo $virtual_prompt; printf '\n'" + return r"$env.VIRTUAL_PROMPT; printf '\n'" activation_tester(Nushell) From 1cc9c2d7d37869b6c04ee4b34c322d1d04671486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sat, 5 Feb 2022 00:50:20 +0200 Subject: [PATCH 02/16] Make `pydoc` an alias --- src/virtualenv/activation/nushell/activate.nu | 8 +++++--- src/virtualenv/activation/nushell/deactivate.nu | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu index 8089ec731..42f6d07ec 100644 --- a/src/virtualenv/activation/nushell/activate.nu +++ b/src/virtualenv/activation/nushell/activate.nu @@ -81,9 +81,11 @@ def-env activate-virtualenv [] { load-env $new-env } -def pydoc [] { - python -m pydoc -} +# def pydoc [] { +# python -m pydoc +# } + +alias pydoc = python -m pydoc def-env deactivate [] { source "__DEACTIVATE_PATH__" diff --git a/src/virtualenv/activation/nushell/deactivate.nu b/src/virtualenv/activation/nushell/deactivate.nu index c1445ced4..e7adb050f 100644 --- a/src/virtualenv/activation/nushell/deactivate.nu +++ b/src/virtualenv/activation/nushell/deactivate.nu @@ -18,5 +18,5 @@ def-env deactivate-virtualenv [] { deactivate-virtualenv -hide pydoc +# hide pydoc hide deactivate From 72e2518069ea81831a51f5037b8ad21704b41262 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sat, 5 Feb 2022 13:55:51 +0200 Subject: [PATCH 03/16] Minor fixes & cleanup --- src/virtualenv/activation/nushell/activate.nu | 1 - tests/unit/activation/test_nushell.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu index 42f6d07ec..64c077d35 100644 --- a/src/virtualenv/activation/nushell/activate.nu +++ b/src/virtualenv/activation/nushell/activate.nu @@ -56,7 +56,6 @@ def-env activate-virtualenv [] { # If there is no default prompt, then only the env is printed in the prompt let new-prompt = if (has-env "PROMPT_COMMAND") { - ($"build-string '($virtual-prompt)' (config get prompt | str find-replace "build-string" "")") #TODO: Check for block vs string! if ($env.PROMPT_COMMAND | describe) == "block" { { $"($virtual-prompt)(do $env.PROMPT_COMMAND)" } diff --git a/tests/unit/activation/test_nushell.py b/tests/unit/activation/test_nushell.py index 40a7b63d4..10d734567 100644 --- a/tests/unit/activation/test_nushell.py +++ b/tests/unit/activation/test_nushell.py @@ -24,6 +24,6 @@ def __init__(self, session): self.unix_line_ending = not IS_WIN def print_prompt(self): - return r"$env.VIRTUAL_PROMPT; printf '\n'" + return r"$'($env.VIRTUAL_PROMPT)(char nl)'" activation_tester(Nushell) From dad8fa8654a11ae44a7e4019f219f817ee76b6c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sat, 5 Feb 2022 18:52:09 +0200 Subject: [PATCH 04/16] Remove newline from expected virtual prompt --- tests/unit/activation/test_nushell.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/activation/test_nushell.py b/tests/unit/activation/test_nushell.py index 10d734567..65c4028bb 100644 --- a/tests/unit/activation/test_nushell.py +++ b/tests/unit/activation/test_nushell.py @@ -24,6 +24,6 @@ def __init__(self, session): self.unix_line_ending = not IS_WIN def print_prompt(self): - return r"$'($env.VIRTUAL_PROMPT)(char nl)'" + return r"$env.VIRTUAL_PROMPT" activation_tester(Nushell) From 2fefc67989d74e4fd55b821b5638f114dd33291b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sat, 5 Feb 2022 19:21:00 +0200 Subject: [PATCH 05/16] Add space to expected prompt --- src/virtualenv/activation/nushell/activate.nu | 1 - tests/unit/activation/test_nushell.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu index 64c077d35..70c8de166 100644 --- a/src/virtualenv/activation/nushell/activate.nu +++ b/src/virtualenv/activation/nushell/activate.nu @@ -56,7 +56,6 @@ def-env activate-virtualenv [] { # If there is no default prompt, then only the env is printed in the prompt let new-prompt = if (has-env "PROMPT_COMMAND") { - #TODO: Check for block vs string! if ($env.PROMPT_COMMAND | describe) == "block" { { $"($virtual-prompt)(do $env.PROMPT_COMMAND)" } } else { diff --git a/tests/unit/activation/test_nushell.py b/tests/unit/activation/test_nushell.py index 65c4028bb..6e809a697 100644 --- a/tests/unit/activation/test_nushell.py +++ b/tests/unit/activation/test_nushell.py @@ -24,6 +24,6 @@ def __init__(self, session): self.unix_line_ending = not IS_WIN def print_prompt(self): - return r"$env.VIRTUAL_PROMPT" + return r"$'($env.VIRTUAL_PROMPT)(char space)'" activation_tester(Nushell) From b29e3877aca617e112dbe0ace6cf0ae3ce468e72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sat, 5 Feb 2022 22:24:01 +0200 Subject: [PATCH 06/16] Collect PATH into string; Do not recurse prompt --- src/virtualenv/activation/nushell/activate.nu | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu index 70c8de166..500164ca3 100644 --- a/src/virtualenv/activation/nushell/activate.nu +++ b/src/virtualenv/activation/nushell/activate.nu @@ -32,7 +32,7 @@ def-env activate-virtualenv [] { ) let venv-path = ([$virtual-env $bin] | path join) - let new-path = ($old-path | prepend $venv-path) + let new-path = ($old-path | prepend $venv-path | str collect $path-sep) # Creating the new prompt for the session let virtual-prompt = ( @@ -57,9 +57,9 @@ def-env activate-virtualenv [] { # If there is no default prompt, then only the env is printed in the prompt let new-prompt = if (has-env "PROMPT_COMMAND") { if ($env.PROMPT_COMMAND | describe) == "block" { - { $"($virtual-prompt)(do $env.PROMPT_COMMAND)" } + { $"($virtual-prompt)(do $env._OLD_PROMPT_COMMAND)" } } else { - { $"($virtual-prompt)($env.PROMPT_COMMAND)" } + { $"($virtual-prompt)($env._OLD_PROMPT_COMMAND)" } } } else { { $"($virtual-prompt)" } From 7c3d9d05afffe376868f5df01af278d49754d3b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sat, 5 Feb 2022 22:26:23 +0200 Subject: [PATCH 07/16] Small fixes --- src/virtualenv/activation/nushell/activate.nu | 4 ++-- tests/unit/activation/test_nushell.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu index 500164ca3..a90038e66 100644 --- a/src/virtualenv/activation/nushell/activate.nu +++ b/src/virtualenv/activation/nushell/activate.nu @@ -37,7 +37,7 @@ def-env activate-virtualenv [] { # Creating the new prompt for the session let virtual-prompt = ( if ("__VIRTUAL_PROMPT__" == "") { - $"(char lparen)($virtual-env | path basename)(char rparen)" + $"(char lparen)($virtual-env | path basename)(char rparen) " } else { "(__VIRTUAL_PROMPT__) " } @@ -56,7 +56,7 @@ def-env activate-virtualenv [] { # If there is no default prompt, then only the env is printed in the prompt let new-prompt = if (has-env "PROMPT_COMMAND") { - if ($env.PROMPT_COMMAND | describe) == "block" { + if ($env._OLD_PROMPT_COMMAND | describe) == "block" { { $"($virtual-prompt)(do $env._OLD_PROMPT_COMMAND)" } } else { { $"($virtual-prompt)($env._OLD_PROMPT_COMMAND)" } diff --git a/tests/unit/activation/test_nushell.py b/tests/unit/activation/test_nushell.py index 6e809a697..65c4028bb 100644 --- a/tests/unit/activation/test_nushell.py +++ b/tests/unit/activation/test_nushell.py @@ -24,6 +24,6 @@ def __init__(self, session): self.unix_line_ending = not IS_WIN def print_prompt(self): - return r"$'($env.VIRTUAL_PROMPT)(char space)'" + return r"$env.VIRTUAL_PROMPT" activation_tester(Nushell) From d469902e2e9ac18a97c93fb5508b6ca797b99737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sun, 6 Feb 2022 14:55:18 +0200 Subject: [PATCH 08/16] Try to fix Path/PATH on Windows; Collect old path --- src/virtualenv/activation/nushell/activate.nu | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu index a90038e66..4813f4748 100644 --- a/src/virtualenv/activation/nushell/activate.nu +++ b/src/virtualenv/activation/nushell/activate.nu @@ -20,7 +20,11 @@ def-env activate-virtualenv [] { let old-path = ( if $is-windows { - $env.Path + if (has-env "Path") { + $env.Path + } else { + $env.PATH + } } else { $env.PATH } | if (is-string $in) { @@ -68,7 +72,7 @@ def-env activate-virtualenv [] { # Environment variables that will be batched loaded to the virtual env let new-env = { $path-name : $new-path - _OLD_VIRTUAL_PATH : $old-path + _OLD_VIRTUAL_PATH : ($old-path | str collect $path-sep) VIRTUAL_ENV : $virtual-env _OLD_PROMPT_COMMAND : $old-prompt-command PROMPT_COMMAND : $new-prompt From 1b900ea35394fb73eee455ae64a4967fad47617f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sun, 6 Feb 2022 15:25:14 +0200 Subject: [PATCH 09/16] Update the right Path/PATH env var --- src/virtualenv/activation/nushell/activate.nu | 6 +++++- src/virtualenv/activation/nushell/deactivate.nu | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu index 4813f4748..918cc9b5f 100644 --- a/src/virtualenv/activation/nushell/activate.nu +++ b/src/virtualenv/activation/nushell/activate.nu @@ -13,7 +13,11 @@ def-env activate-virtualenv [] { let bin = "__BIN_NAME__" let path-sep = "__PATH_SEP__" let path-name = if $is-windows { - "Path" + if (has-env "Path") { + "Path" + } else { + "PATH" + } } else { "PATH" } diff --git a/src/virtualenv/activation/nushell/deactivate.nu b/src/virtualenv/activation/nushell/deactivate.nu index e7adb050f..2e610c032 100644 --- a/src/virtualenv/activation/nushell/deactivate.nu +++ b/src/virtualenv/activation/nushell/deactivate.nu @@ -1,8 +1,16 @@ def-env deactivate-virtualenv [] { + def has-env [name: string] { + $name in (env).name + } + let is-windows = ((sys).host.name | str downcase) == "windows" let path-name = if $is-windows { - "Path" + if (has-env "Path") { + "Path" + } else { + "PATH" + } } else { "PATH" } From 5878f832098f0ccf69850235892048ad7c56b9af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sun, 6 Feb 2022 17:40:14 +0200 Subject: [PATCH 10/16] Misc cleanup and hardening --- src/virtualenv/activation/nushell/activate.nu | 22 +++++++++---------- .../activation/nushell/deactivate.nu | 1 + 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu index 918cc9b5f..ffd065d4c 100644 --- a/src/virtualenv/activation/nushell/activate.nu +++ b/src/virtualenv/activation/nushell/activate.nu @@ -43,16 +43,14 @@ def-env activate-virtualenv [] { let new-path = ($old-path | prepend $venv-path | str collect $path-sep) # Creating the new prompt for the session - let virtual-prompt = ( - if ("__VIRTUAL_PROMPT__" == "") { - $"(char lparen)($virtual-env | path basename)(char rparen) " - } else { - "(__VIRTUAL_PROMPT__) " - } - ) + let virtual-prompt = if ("__VIRTUAL_PROMPT__" == "") { + $"(char lparen)($virtual-env | path basename)(char rparen) " + } else { + "(__VIRTUAL_PROMPT__) " + } # Back up the old prompt builder - let old-prompt-command = if (has-env "VIRTUAL_ENV") { + let old-prompt-command = if (has-env "VIRTUAL_ENV") && (has-env "_OLD_PROMPT_COMMAND") { $env._OLD_PROMPT_COMMAND } else { if (has-env "PROMPT_COMMAND") { @@ -64,10 +62,10 @@ def-env activate-virtualenv [] { # If there is no default prompt, then only the env is printed in the prompt let new-prompt = if (has-env "PROMPT_COMMAND") { - if ($env._OLD_PROMPT_COMMAND | describe) == "block" { - { $"($virtual-prompt)(do $env._OLD_PROMPT_COMMAND)" } + if ($old-prompt-command | describe) == "block" { + { $"($virtual-prompt)(do $old-prompt-command)" } } else { - { $"($virtual-prompt)($env._OLD_PROMPT_COMMAND)" } + { $"($virtual-prompt)($old-prompt-command)" } } } else { { $"($virtual-prompt)" } @@ -76,8 +74,8 @@ def-env activate-virtualenv [] { # Environment variables that will be batched loaded to the virtual env let new-env = { $path-name : $new-path - _OLD_VIRTUAL_PATH : ($old-path | str collect $path-sep) VIRTUAL_ENV : $virtual-env + _OLD_VIRTUAL_PATH : ($old-path | str collect $path-sep) _OLD_PROMPT_COMMAND : $old-prompt-command PROMPT_COMMAND : $new-prompt VIRTUAL_PROMPT : $virtual-prompt diff --git a/src/virtualenv/activation/nushell/deactivate.nu b/src/virtualenv/activation/nushell/deactivate.nu index 2e610c032..c88a5e307 100644 --- a/src/virtualenv/activation/nushell/deactivate.nu +++ b/src/virtualenv/activation/nushell/deactivate.nu @@ -19,6 +19,7 @@ def-env deactivate-virtualenv [] { # Hiding the environment variables that were created when activating the env hide _OLD_VIRTUAL_PATH + hide _OLD_PROMPT_COMMAND hide VIRTUAL_ENV hide PROMPT_COMMAND hide VIRTUAL_PROMPT From ba802e17b3a7e8acdc6b924f743fa81e64168f00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Wed, 2 Mar 2022 22:04:37 +0200 Subject: [PATCH 11/16] Enable hiding pydoc alias --- src/virtualenv/activation/nushell/deactivate.nu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/virtualenv/activation/nushell/deactivate.nu b/src/virtualenv/activation/nushell/deactivate.nu index c88a5e307..c74c23ad4 100644 --- a/src/virtualenv/activation/nushell/deactivate.nu +++ b/src/virtualenv/activation/nushell/deactivate.nu @@ -27,5 +27,5 @@ def-env deactivate-virtualenv [] { deactivate-virtualenv -# hide pydoc +hide pydoc hide deactivate From a1f7ce22c59c645a134f5f3749dc48eeb46e7d60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sun, 6 Mar 2022 17:33:03 +0200 Subject: [PATCH 12/16] Restore PROMPT_COMMAND properly --- src/virtualenv/activation/nushell/deactivate.nu | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/virtualenv/activation/nushell/deactivate.nu b/src/virtualenv/activation/nushell/deactivate.nu index c74c23ad4..51b840bb2 100644 --- a/src/virtualenv/activation/nushell/deactivate.nu +++ b/src/virtualenv/activation/nushell/deactivate.nu @@ -17,11 +17,12 @@ def-env deactivate-virtualenv [] { load-env { $path-name : $env._OLD_VIRTUAL_PATH } + let-env PROMPT_COMMAND = $env._OLD_PROMPT_COMMAND + # Hiding the environment variables that were created when activating the env hide _OLD_VIRTUAL_PATH hide _OLD_PROMPT_COMMAND hide VIRTUAL_ENV - hide PROMPT_COMMAND hide VIRTUAL_PROMPT } From e80e00136a9ef43dce4ad4534b5516be30307200 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sun, 6 Mar 2022 18:16:56 +0200 Subject: [PATCH 13/16] Do not hide pydoc for now --- src/virtualenv/activation/nushell/deactivate.nu | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/virtualenv/activation/nushell/deactivate.nu b/src/virtualenv/activation/nushell/deactivate.nu index 51b840bb2..800e8c7a9 100644 --- a/src/virtualenv/activation/nushell/deactivate.nu +++ b/src/virtualenv/activation/nushell/deactivate.nu @@ -28,5 +28,5 @@ def-env deactivate-virtualenv [] { deactivate-virtualenv -hide pydoc +# hide pydoc hide deactivate From 4ea5d9b059ce02b5957758725d4f8d69012f5bcd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sun, 6 Mar 2022 18:48:40 +0200 Subject: [PATCH 14/16] Make deactivate alias --- src/virtualenv/activation/nushell/activate.nu | 9 +-------- src/virtualenv/activation/nushell/deactivate.nu | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu index ffd065d4c..e2550e884 100644 --- a/src/virtualenv/activation/nushell/activate.nu +++ b/src/virtualenv/activation/nushell/activate.nu @@ -85,15 +85,8 @@ def-env activate-virtualenv [] { load-env $new-env } -# def pydoc [] { -# python -m pydoc -# } - alias pydoc = python -m pydoc - -def-env deactivate [] { - source "__DEACTIVATE_PATH__" -} +alias deactivate = (source "__DEACTIVATE_PATH__") # Activate the virtualenv activate-virtualenv diff --git a/src/virtualenv/activation/nushell/deactivate.nu b/src/virtualenv/activation/nushell/deactivate.nu index 800e8c7a9..51b840bb2 100644 --- a/src/virtualenv/activation/nushell/deactivate.nu +++ b/src/virtualenv/activation/nushell/deactivate.nu @@ -28,5 +28,5 @@ def-env deactivate-virtualenv [] { deactivate-virtualenv -# hide pydoc +hide pydoc hide deactivate From b3232d72187f96e97f9c2e69e48391e411b2d9e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Sun, 13 Mar 2022 21:51:22 +0200 Subject: [PATCH 15/16] Fix deactivate alias --- src/virtualenv/activation/nushell/activate.nu | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu index e2550e884..e9047ff5f 100644 --- a/src/virtualenv/activation/nushell/activate.nu +++ b/src/virtualenv/activation/nushell/activate.nu @@ -85,8 +85,8 @@ def-env activate-virtualenv [] { load-env $new-env } -alias pydoc = python -m pydoc -alias deactivate = (source "__DEACTIVATE_PATH__") - # Activate the virtualenv activate-virtualenv + +alias pydoc = python -m pydoc +alias deactivate = source "__DEACTIVATE_PATH__" From 7d77429e7e39eb506937b2815b7f5e03fdcdbc7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20=C5=BD=C3=A1dn=C3=ADk?= Date: Fri, 18 Mar 2022 23:28:24 +0200 Subject: [PATCH 16/16] Use only single quotes Double quotes gave errors with Windows paths. --- src/virtualenv/activation/nushell/activate.nu | 44 +++++++++---------- .../activation/nushell/deactivate.nu | 10 ++--- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/virtualenv/activation/nushell/activate.nu b/src/virtualenv/activation/nushell/activate.nu index e9047ff5f..ffeff7d45 100644 --- a/src/virtualenv/activation/nushell/activate.nu +++ b/src/virtualenv/activation/nushell/activate.nu @@ -1,30 +1,30 @@ # This command prepares the required environment variables def-env activate-virtualenv [] { def is-string [x] { - ($x | describe) == "string" + ($x | describe) == 'string' } def has-env [name: string] { $name in (env).name } - let is-windows = ((sys).host.name | str downcase) == "windows" - let virtual-env = "__VIRTUAL_ENV__" - let bin = "__BIN_NAME__" - let path-sep = "__PATH_SEP__" + let is-windows = ((sys).host.name | str downcase) == 'windows' + let virtual-env = '__VIRTUAL_ENV__' + let bin = '__BIN_NAME__' + let path-sep = '__PATH_SEP__' let path-name = if $is-windows { - if (has-env "Path") { - "Path" + if (has-env 'Path') { + 'Path' } else { - "PATH" + 'PATH' } } else { - "PATH" + 'PATH' } let old-path = ( if $is-windows { - if (has-env "Path") { + if (has-env 'Path') { $env.Path } else { $env.PATH @@ -43,32 +43,32 @@ def-env activate-virtualenv [] { let new-path = ($old-path | prepend $venv-path | str collect $path-sep) # Creating the new prompt for the session - let virtual-prompt = if ("__VIRTUAL_PROMPT__" == "") { - $"(char lparen)($virtual-env | path basename)(char rparen) " + let virtual-prompt = if ('__VIRTUAL_PROMPT__' == '') { + $'(char lparen)($virtual-env | path basename)(char rparen) ' } else { - "(__VIRTUAL_PROMPT__) " + '(__VIRTUAL_PROMPT__) ' } # Back up the old prompt builder - let old-prompt-command = if (has-env "VIRTUAL_ENV") && (has-env "_OLD_PROMPT_COMMAND") { + let old-prompt-command = if (has-env 'VIRTUAL_ENV') && (has-env '_OLD_PROMPT_COMMAND') { $env._OLD_PROMPT_COMMAND } else { - if (has-env "PROMPT_COMMAND") { + if (has-env 'PROMPT_COMMAND') { $env.PROMPT_COMMAND } else { - "" + '' } } # If there is no default prompt, then only the env is printed in the prompt - let new-prompt = if (has-env "PROMPT_COMMAND") { - if ($old-prompt-command | describe) == "block" { - { $"($virtual-prompt)(do $old-prompt-command)" } + let new-prompt = if (has-env 'PROMPT_COMMAND') { + if ($old-prompt-command | describe) == 'block' { + { $'($virtual-prompt)(do $old-prompt-command)' } } else { - { $"($virtual-prompt)($old-prompt-command)" } + { $'($virtual-prompt)($old-prompt-command)' } } } else { - { $"($virtual-prompt)" } + { $'($virtual-prompt)' } } # Environment variables that will be batched loaded to the virtual env @@ -89,4 +89,4 @@ def-env activate-virtualenv [] { activate-virtualenv alias pydoc = python -m pydoc -alias deactivate = source "__DEACTIVATE_PATH__" +alias deactivate = source '__DEACTIVATE_PATH__' diff --git a/src/virtualenv/activation/nushell/deactivate.nu b/src/virtualenv/activation/nushell/deactivate.nu index 51b840bb2..904f7d0e8 100644 --- a/src/virtualenv/activation/nushell/deactivate.nu +++ b/src/virtualenv/activation/nushell/deactivate.nu @@ -3,16 +3,16 @@ def-env deactivate-virtualenv [] { $name in (env).name } - let is-windows = ((sys).host.name | str downcase) == "windows" + let is-windows = ((sys).host.name | str downcase) == 'windows' let path-name = if $is-windows { - if (has-env "Path") { - "Path" + if (has-env 'Path') { + 'Path' } else { - "PATH" + 'PATH' } } else { - "PATH" + 'PATH' } load-env { $path-name : $env._OLD_VIRTUAL_PATH }