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

[WIP] conda 4.4 powershell wrapper #6471

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
38 changes: 38 additions & 0 deletions shell/Library/bin/conda.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

# shell setup would be something like adding
# . [CONDA_ROOT]/Library/bin/conda.ps1
# or
# Get-ChildItem "[CONDA_ROOT]\Library\bin\conda.ps1" | %{.$_}

if ( "${_CONDA_EXE}" -eq "" ) {
$scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
$_CONDA_EXE = "$scriptPath/../../bin/conda"
}


function conda {
switch -r ($args[1]) {
"^activate$" {
Invoke-Expression -Command ($_CONDA_EXE shell.powershell activate $args[2..-1] | Out-String)
break
}
"^deactivate$" {
Invoke-Expression -Command ($_CONDA_EXE shell.powershell deactivate $args[2..-1] | Out-String)
break
}
"^(install|update|remove|uninstall)$" {
$_CONDA_EXE $args[1..-1]
Invoke-Expression -Command ($_CONDA_EXE shell.powershell reactivate | Out-String)
break
}
default {
$_CONDA_EXE $args[1..-1]
break
}
}
}


if ( $MyInvocation.InvocationName -ne '.' ) {
conda $args[1..-1]
}
23 changes: 22 additions & 1 deletion tests/test_activate.py
Original file line number Diff line number Diff line change
Expand Up @@ -886,6 +886,14 @@ class InteractiveShell(object):
'init_command': 'source shell/etc/fish/conf.d/conda.fish',
'print_env_var': 'echo $%s',
},
'powershell': {
'activator': 'powershell',
'init_command': None,
'print_env_var': '@echo %%%s%%',
},
'pwsh': {
'base_shell': 'powershell',
}
}

def __init__(self, shell_name):
Expand All @@ -902,7 +910,8 @@ def __enter__(self):

cwd = os.getcwd()
env = os.environ.copy()
joiner = os.pathsep.join if self.shell_name == 'fish' else self.activator.pathsep_join
os_pathsep_joiners = {'fish', 'pwsh'}
joiner = os.pathsep.join if self.shell_name in os_pathsep_joiners else self.activator.pathsep_join
env['PATH'] = joiner(self.activator.path_conversion(concatv(
self.activator._get_path_dirs(join(cwd, 'conda', 'shell')),
(dirname(sys.executable),),
Expand Down Expand Up @@ -949,6 +958,8 @@ def which(executable):
from distutils.spawn import find_executable
return find_executable(executable)

POWERSHELL_EXE_NAME = 'powershell' if on_win else 'pwsh'


@pytest.mark.integration
class ShellWrapperIntegrationTests(TestCase):
Expand Down Expand Up @@ -1117,3 +1128,13 @@ def test_cmd_exe_activate_error(self):

shell.sendline("conda activate -h blah blah")
shell.expect('help requested for activate')

@pytest.mark.skipif(not which(POWERSHELL_EXE_NAME), reason='powershell not installed')
def test_powershell_activate_error(self):
with InteractiveShell(POWERSHELL_EXE_NAME) as shell:
shell.sendline("conda activate environment-not-found-doesnt-exist")
shell.expect('Could not find conda environment: environment-not-found-doesnt-exist')
shell.assert_env_var('errorlevel', '1\r')

shell.sendline("conda activate -h blah blah")
shell.expect('help requested for activate')