def test_init_sh_user_windows(self): with tempdir() as conda_temp_prefix: target_path = join(conda_temp_prefix, '.bashrc') conda_prefix = "c:\\Users\\Lars\\miniconda" cygpath_conda_prefix = "/c/Users/Lars/miniconda" initial_content = dals(""" source /c/conda/Scripts/activate root . $(cygpath 'c:\\conda\\Scripts\\activate') root # >>> conda initialize >>> __conda_setup="$('%(prefix)s/bin/conda' shell.bash hook 2> /dev/null)" if [ $? -eq 0 ]; then fi unset __conda_setup # <<< conda initialize <<< . etc/profile.d/conda.sh . etc/profile.d/coda.sh . /somewhere/etc/profile.d/conda.sh source /etc/profile.d/conda.sh \t source %(prefix)s/etc/profile.d/conda.sh """) % { 'prefix': win_path_ok(abspath(conda_prefix)), } with open(target_path, 'w') as fh: fh.write(initial_content) init_sh_user(target_path, conda_prefix, 'bash') with open(target_path) as fh: new_content = fh.read() print(new_content) expected_new_content = dals(""" # source /c/conda/Scripts/activate root # commented out by conda initialize # . $(cygpath 'c:\\conda\\Scripts\\activate') root # commented out by conda initialize # >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! eval "$('%(cygpath_conda_prefix)s/Scripts/conda.exe' shell.bash hook)" # <<< conda initialize <<< # . etc/profile.d/conda.sh # commented out by conda initialize . etc/profile.d/coda.sh # . /somewhere/etc/profile.d/conda.sh # commented out by conda initialize # source /etc/profile.d/conda.sh # commented out by conda initialize # source %(prefix)s/etc/profile.d/conda.sh # commented out by conda initialize """) % { 'prefix': win_path_ok(abspath(conda_prefix)), 'cygpath_conda_prefix': cygpath_conda_prefix, } assert new_content == expected_new_content
def test_init_sh_user_windows(self): with tempdir() as conda_temp_prefix: target_path = join(conda_temp_prefix, '.bashrc') conda_prefix = "c:\\Users\\Lars\\miniconda" cygpath_conda_prefix = "/c/Users/Lars/miniconda" initial_content = dals(""" source /c/conda/Scripts/activate root . $(cygpath 'c:\\conda\\Scripts\\activate') root # >>> conda initialize >>> __conda_setup="$('%(prefix)s/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then fi unset __conda_setup # <<< conda initialize <<< . etc/profile.d/conda.sh . etc/profile.d/coda.sh . /somewhere/etc/profile.d/conda.sh source /etc/profile.d/conda.sh \t source %(prefix)s/etc/profile.d/conda.sh """) % { 'prefix': win_path_ok(abspath(conda_prefix)), } with open(target_path, 'w') as fh: fh.write(initial_content) init_sh_user(target_path, conda_prefix, 'bash') with open(target_path) as fh: new_content = fh.read() print(new_content) expected_new_content = dals(""" # source /c/conda/Scripts/activate root # commented out by conda initialize # . $(cygpath 'c:\\conda\\Scripts\\activate') root # commented out by conda initialize # >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! eval "$('%(cygpath_conda_prefix)s/Scripts/conda.exe' 'shell.bash' 'hook')" # <<< conda initialize <<< # . etc/profile.d/conda.sh # commented out by conda initialize . etc/profile.d/coda.sh # . /somewhere/etc/profile.d/conda.sh # commented out by conda initialize # source /etc/profile.d/conda.sh # commented out by conda initialize # source %(prefix)s/etc/profile.d/conda.sh # commented out by conda initialize """) % { 'prefix': win_path_ok(abspath(conda_prefix)), 'cygpath_conda_prefix': cygpath_conda_prefix, } assert new_content == expected_new_content
def test_init_sh_user_tcsh_unix(self): with tempdir() as conda_temp_prefix: target_path = join(conda_temp_prefix, '.tcshrc') init_sh_user(target_path, conda_temp_prefix, 'tcsh') with open(target_path) as fh: tcshrc_contet = fh.read() conda_csh = "%s/etc/profile.d/conda.csh" % conda_temp_prefix # tcsh/csh doesn't give users the ability to register a function. # Make sure that conda doesn't try to register a function conda_eval_string = "eval \"$__conda_setup\"" assert conda_csh in tcshrc_contet assert conda_eval_string not in tcshrc_contet
def test_init_sh_user_unix(self): with tempdir() as conda_temp_prefix: target_path = join(conda_temp_prefix, '.bashrc') initial_content = dals(""" export PATH="/some/other/conda/bin:$PATH" export PATH="%(prefix)s/bin:$PATH" export PATH="%(prefix)s/bin:$PATH" # >>> conda initialize >>> __conda_setup="$('%(prefix)s/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then fi unset __conda_setup # <<< conda initialize <<< . etc/profile.d/conda.sh . etc/profile.d/coda.sh . /somewhere/etc/profile.d/conda.sh source /etc/profile.d/conda.sh \t source %(prefix)s/etc/profile.d/conda.sh """) % { 'prefix': win_path_backout(abspath(conda_temp_prefix)), } with open(target_path, 'w') as fh: fh.write(initial_content) init_sh_user(target_path, conda_temp_prefix, 'bash') with open(target_path) as fh: new_content = fh.read() expected_new_content = dals(""" export PATH="/some/other/conda/bin:$PATH" # export PATH="%(prefix)s/bin:$PATH" # commented out by conda initialize # export PATH="%(prefix)s/bin:$PATH" # commented out by conda initialize # >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! __conda_setup="$('%(prefix)s/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__conda_setup" else if [ -f "%(prefix)s/etc/profile.d/conda.sh" ]; then . "%(prefix)s/etc/profile.d/conda.sh" else export PATH="%(prefix)s/bin:$PATH" fi fi unset __conda_setup # <<< conda initialize <<< # . etc/profile.d/conda.sh # commented out by conda initialize . etc/profile.d/coda.sh # . /somewhere/etc/profile.d/conda.sh # commented out by conda initialize # source /etc/profile.d/conda.sh # commented out by conda initialize # source %(prefix)s/etc/profile.d/conda.sh # commented out by conda initialize """) % { 'prefix': win_path_backout(abspath(conda_temp_prefix)), } print(new_content) assert new_content == expected_new_content expected_reversed_content = dals(""" export PATH="/some/other/conda/bin:$PATH" export PATH="%(prefix)s/bin:$PATH" export PATH="%(prefix)s/bin:$PATH" . etc/profile.d/conda.sh . etc/profile.d/coda.sh . /somewhere/etc/profile.d/conda.sh source /etc/profile.d/conda.sh source %(prefix)s/etc/profile.d/conda.sh """) % { 'prefix': win_path_backout(abspath(conda_temp_prefix)), } init_sh_user(target_path, conda_temp_prefix, 'bash', reverse=True) with open(target_path) as fh: reversed_content = fh.read() print(reversed_content) assert reversed_content == expected_reversed_content
def test_init_sh_user_unix(self): with tempdir() as conda_temp_prefix: target_path = join(conda_temp_prefix, '.bashrc') initial_content = dals(""" export PATH="/some/other/conda/bin:$PATH" export PATH="%(prefix)s/bin:$PATH" export PATH="%(prefix)s/bin:$PATH" # >>> conda initialize >>> __conda_setup="$('%(prefix)s/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then fi unset __conda_setup # <<< conda initialize <<< . etc/profile.d/conda.sh . etc/profile.d/coda.sh . /somewhere/etc/profile.d/conda.sh source /etc/profile.d/conda.sh \t source %(prefix)s/etc/profile.d/conda.sh """) % { 'prefix': win_path_backout(abspath(conda_temp_prefix)), } with open(target_path, 'w') as fh: fh.write(initial_content) init_sh_user(target_path, conda_temp_prefix, 'bash') with open(target_path) as fh: new_content = fh.read() expected_new_content = dals(""" export PATH="/some/other/conda/bin:$PATH" # export PATH="%(prefix)s/bin:$PATH" # commented out by conda initialize # export PATH="%(prefix)s/bin:$PATH" # commented out by conda initialize # >>> conda initialize >>> # !! Contents within this block are managed by 'conda init' !! __conda_setup="$('%(prefix)s/bin/conda' 'shell.bash' 'hook' 2> /dev/null)" if [ $? -eq 0 ]; then eval "$__conda_setup" else if [ -f "%(prefix)s/etc/profile.d/conda.sh" ]; then . "%(prefix)s/etc/profile.d/conda.sh" else export PATH="%(prefix)s/bin:$PATH" fi fi unset __conda_setup # <<< conda initialize <<< # . etc/profile.d/conda.sh # commented out by conda initialize . etc/profile.d/coda.sh # . /somewhere/etc/profile.d/conda.sh # commented out by conda initialize # source /etc/profile.d/conda.sh # commented out by conda initialize # source %(prefix)s/etc/profile.d/conda.sh # commented out by conda initialize """) % { 'prefix': win_path_backout(abspath(conda_temp_prefix)), } print(new_content) assert new_content == expected_new_content expected_reversed_content = dals(""" export PATH="/some/other/conda/bin:$PATH" export PATH="%(prefix)s/bin:$PATH" export PATH="%(prefix)s/bin:$PATH" . etc/profile.d/conda.sh . etc/profile.d/coda.sh . /somewhere/etc/profile.d/conda.sh source /etc/profile.d/conda.sh source %(prefix)s/etc/profile.d/conda.sh """) % { 'prefix': win_path_backout(abspath(conda_temp_prefix)), } init_sh_user(target_path, conda_temp_prefix, 'bash', reverse=True) with open(target_path) as fh: reversed_content = fh.read() print(reversed_content) assert reversed_content == expected_reversed_content