-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1cc503b
commit e0410ca
Showing
7 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
import os | ||
|
||
from virtualenv.util.path import Path | ||
from virtualenv.util.six import ensure_text | ||
|
||
from ..via_template import ViaTemplateActivator | ||
|
||
|
||
class NushellActivator(ViaTemplateActivator): | ||
def templates(self): | ||
yield Path("activate.nu") | ||
yield Path("deactivate.nu") | ||
|
||
def replacements(self, creator, dest_folder): | ||
# Due to nushell scoping, it isn't easy to create a function that will | ||
# deactivate the environment. For that reason a __DEACTIVATE_PATH__ | ||
# replacement pointing to the deactivate.nu file is created | ||
|
||
return { | ||
"__VIRTUAL_PROMPT__": "" if self.flag_prompt is None else self.flag_prompt, | ||
"__VIRTUAL_ENV__": ensure_text(str(creator.dest)), | ||
"__VIRTUAL_NAME__": creator.env_name, | ||
"__BIN_NAME__": ensure_text(str(creator.bin_dir.relative_to(creator.dest))), | ||
"__PATH_SEP__": ensure_text(os.pathsep), | ||
"__DEACTIVATE_PATH__": ensure_text(str(Path(dest_folder) / "deactivate.nu")), | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Setting all environment variables for the venv | ||
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 $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__" | ||
} { | ||
$virtual-env | path basename | ||
} | ||
) | ||
|
||
# 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 '(char lparen)' '($virtual_prompt)' '(char rparen) ' ") | ||
} { | ||
($"build-string '(char lparen)' '($virtual_prompt)' '(char rparen) ' (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__" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Setting the old path | ||
let path-name = (if ((sys).host.name == "Windows") { "Path" } { "PATH" }) | ||
let-env $path-name = $nu.env._OLD_VIRTUAL_PATH | ||
|
||
# Unleting the environment variables that were created when activating the env | ||
unlet-env VIRTUAL_ENV | ||
unlet-env _OLD_VIRTUAL_PATH | ||
unlet-env PROMPT_COMMAND | ||
|
||
unalias pydoc | ||
unalias deactivate |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from __future__ import absolute_import, unicode_literals | ||
|
||
import sys | ||
|
||
if sys.version_info > (3,): | ||
from shutil import which | ||
else: | ||
from distutils.spawn import find_executable as which | ||
|
||
|
||
from virtualenv.activation import NushellActivator | ||
from virtualenv.info import IS_WIN | ||
|
||
|
||
def test_nushell(activation_tester_class, activation_tester): | ||
class Nushell(activation_tester_class): | ||
def __init__(self, session): | ||
cmd = which("nu") | ||
if cmd is None and IS_WIN: | ||
cmd = "c:\\program files\\nu\\bin\\nu.exe" | ||
|
||
super(Nushell, self).__init__(NushellActivator, session, cmd, "activate.nu", "nu") | ||
|
||
self.unix_line_ending = not IS_WIN | ||
|
||
activation_tester(Nushell) |