def test_initialize_dev_cmd_exe(self): with env_vars({'CONDA_DRY_RUN': 'true', 'CONDA_VERBOSITY': '0'}, reset_context): with tempdir() as conda_temp_prefix: new_py = abspath(join(conda_temp_prefix, get_python_short_path())) mkdir_p(dirname(new_py)) create_link(abspath(sys.executable), new_py, LinkType.hardlink if on_win else LinkType.softlink) with captured() as c: initialize_dev('cmd.exe', dev_env_prefix=conda_temp_prefix, conda_source_root=dirname(CONDA_PACKAGE_ROOT)) print(c.stdout) print(c.stderr, file=sys.stderr) if on_win: modified_files = ( 'conda.exe', 'conda-env.exe', 'conda-script.py', 'conda-env-script.py', 'conda.bat', '_conda_activate.bat', 'conda_auto_activate.bat', 'conda_hook.bat', 'activate.bat', 'activate.bat', 'deactivate.bat', 'activate', 'deactivate', 'conda.sh', 'conda.fish', 'conda.xsh', 'conda.csh', 'site-packages', # remove conda in site-packages dir 'conda.egg-link', 'easy-install.pth', 'conda.egg-info', ) else: modified_files = ( 'conda', 'conda-env', 'activate', 'deactivate', 'conda.sh', 'conda.fish', 'conda.xsh', 'conda.csh', 'site-packages', # remove conda in site-packages dir 'conda.egg-link', 'easy-install.pth', 'conda.egg-info', ) stderr = c.stderr.replace('no change', 'modified') assert stderr.count('modified') == len(modified_files) for fn in modified_files: line = next(line for line in stderr.splitlines() if line.strip().endswith(fn)) assert line.strip().startswith('modified'), line
def test_initialize_dev_cmd_exe(self): with env_vars({'CONDA_DRY_RUN': 'true', 'CONDA_VERBOSITY': '0'}, reset_context): with tempdir() as conda_temp_prefix: new_py = abspath(join(conda_temp_prefix, get_python_short_path())) mkdir_p(dirname(new_py)) create_link(abspath(sys.executable), new_py, LinkType.hardlink if on_win else LinkType.softlink) with captured() as c: initialize_dev('cmd.exe', dev_env_prefix=conda_temp_prefix, conda_source_root=dirname(CONDA_PACKAGE_ROOT)) print(c.stdout) print(c.stderr, file=sys.stderr) if on_win: modified_files = ( 'conda.exe', 'conda-env.exe', 'conda-script.py', 'conda-env-script.py', 'conda.bat', '_conda_activate.bat', 'conda_auto_activate.bat', 'conda_hook.bat', 'activate.bat', 'activate.bat', 'deactivate.bat', 'activate', 'deactivate', 'conda.sh', 'conda.fish', 'conda.xsh', 'conda.csh', 'site-packages', # remove conda in site-packages dir 'conda.egg-link', 'easy-install.pth', 'conda.egg-info', ) else: modified_files = ( 'conda', 'conda-env', 'activate', 'deactivate', 'conda.sh', 'conda.fish', 'conda.xsh', 'conda.csh', 'site-packages', # remove conda in site-packages dir 'conda.egg-link', 'easy-install.pth', 'conda.egg-info', ) stderr = c.stderr.replace('no change', 'modified') assert stderr.count('modified') == len(modified_files) for fn in modified_files: line = next(line for line in stderr.splitlines() if line.strip().endswith(fn)) assert line.strip().startswith('modified'), line
def test_initialize_dev_bash(self): with pytest.raises(CondaValueError): initialize_dev('bash', conda_source_root=join('a', 'b', 'c')) with env_var('CONDA_DRY_RUN', 'true', reset_context): with tempdir() as conda_temp_prefix: new_py = abspath( join(conda_temp_prefix, get_python_short_path())) mkdir_p(dirname(new_py)) create_link(abspath(sys.executable), new_py, LinkType.hardlink if on_win else LinkType.softlink) with captured() as c: initialize_dev('bash', dev_env_prefix=conda_temp_prefix) print(c.stdout) print(c.stderr, file=sys.stderr) if on_win: modified_files = ( 'conda.exe', 'conda-env.exe', 'conda-script.py', 'conda-env-script.py', 'conda.bat', 'conda.bat', 'conda-hook.bat', 'activate.bat', 'deactivate.bat', 'activate', 'deactivate', 'conda.sh', 'conda.fish', 'conda.xsh', 'conda.csh', 'site-packages', 'conda-dev.pth', ) else: modified_files = ( 'conda', 'conda-env', 'activate', 'deactivate', 'conda.sh', 'conda.fish', 'conda.xsh', 'conda.csh', 'site-packages', # remove conda in site-packages dir 'conda-dev.pth', ) stderr = c.stderr.replace('no change', 'modified') assert stderr.count('modified') == len(modified_files) stderr = "".join(s.strip('\n\r') for s in stderr.splitlines()) for fn in modified_files: assert '%s modified' % fn in stderr assert "unset CONDA_SHLVL" in c.stdout
def test_initialize_dev_bash(self): with pytest.raises(CondaValueError): initialize_dev('bash', conda_source_root=join('a', 'b', 'c')) with env_vars({'CONDA_DRY_RUN': 'true', 'CONDA_VERBOSITY': '0'}, stack_callback=conda_tests_ctxt_mgmt_def_pol): with tempdir() as conda_temp_prefix: new_py = abspath(join(conda_temp_prefix, get_python_short_path())) mkdir_p(dirname(new_py)) create_link(abspath(sys.executable), new_py, LinkType.hardlink if on_win else LinkType.softlink) with captured() as c: initialize_dev('bash', dev_env_prefix=conda_temp_prefix, conda_source_root=dirname(CONDA_PACKAGE_ROOT)) print(c.stdout) print(c.stderr, file=sys.stderr) if on_win: modified_files = ( 'conda.exe', 'conda-env.exe', 'conda-script.py', 'conda-env-script.py', 'conda.bat', # condabin/conda.bat 'conda.bat', # Library/bin/conda.bat '_conda_activate.bat', 'rename_tmp.bat', 'conda_auto_activate.bat', 'conda_hook.bat', 'activate.bat', 'activate.bat', 'deactivate.bat', 'activate', 'deactivate', 'conda.sh', 'conda.fish', 'Conda.psm1', 'conda-hook.ps1', 'conda.xsh', 'conda.csh', 'site-packages', # remove conda in site-packages dir 'conda.egg-link', 'easy-install.pth', 'conda.egg-info', ) else: modified_files = ( 'conda', # condabin/conda 'conda', # bin/conda 'conda-env', 'activate', 'deactivate', 'conda.sh', 'conda.fish', 'Conda.psm1', 'conda-hook.ps1', 'conda.xsh', 'conda.csh', 'site-packages', # remove conda in site-packages dir 'conda.egg-link', 'easy-install.pth', 'conda.egg-info', ) stderr = c.stderr.replace('no change', 'modified') assert stderr.count('modified') == len(modified_files) for fn in modified_files: line = next(line for line in stderr.splitlines() if line.strip().endswith(fn)) assert line.strip().startswith('modified'), line assert "unset CONDA_SHLVL" in c.stdout
def test_initialize_dev_bash(self): with pytest.raises(CondaValueError): initialize_dev('bash', conda_source_root=join('a', 'b', 'c')) with env_vars({'CONDA_DRY_RUN': 'true', 'CONDA_VERBOSITY': '0'}, conda_tests_ctxt_mgmt_def_pol): with tempdir() as conda_temp_prefix: new_py = abspath(join(conda_temp_prefix, get_python_short_path())) mkdir_p(dirname(new_py)) create_link(abspath(sys.executable), new_py, LinkType.hardlink if on_win else LinkType.softlink) with captured() as c: initialize_dev('bash', dev_env_prefix=conda_temp_prefix, conda_source_root=dirname(CONDA_PACKAGE_ROOT)) print(c.stdout) print(c.stderr, file=sys.stderr) if on_win: modified_files = ( 'conda.exe', 'conda-env.exe', 'conda-script.py', 'conda-env-script.py', 'conda.bat', # condabin/conda.bat 'conda.bat', # Library/bin/conda.bat '_conda_activate.bat', 'rename_tmp.bat', 'conda_auto_activate.bat', 'conda_hook.bat', 'activate.bat', 'activate.bat', 'deactivate.bat', 'activate', 'deactivate', 'conda.sh', 'conda.fish', 'Conda.psm1', 'conda-hook.ps1', 'conda.xsh', 'conda.csh', 'site-packages', # remove conda in site-packages dir 'conda.egg-link', 'easy-install.pth', 'conda.egg-info', ) else: modified_files = ( 'conda', # condabin/conda 'conda', # bin/conda 'conda-env', 'activate', 'deactivate', 'conda.sh', 'conda.fish', 'Conda.psm1', 'conda-hook.ps1', 'conda.xsh', 'conda.csh', 'site-packages', # remove conda in site-packages dir 'conda.egg-link', 'easy-install.pth', 'conda.egg-info', ) stderr = c.stderr.replace('no change', 'modified') assert stderr.count('modified') == len(modified_files) for fn in modified_files: line = next(line for line in stderr.splitlines() if line.strip().endswith(fn)) assert line.strip().startswith('modified'), line assert "unset CONDA_SHLVL" in c.stdout
def shell_init(args): if args.all: selected_shells = COMPATIBLE_SHELLS else: selected_shells = tuple(args.shells) if not selected_shells: if on_win: selected_shells = ("cmd.exe", "powershell") if on_mac: selected_shells = ("bash", "zsh") else: selected_shells = ("bash", ) if args.dev: assert (len(selected_shells) == 1 ), "--dev can only handle one shell at a time right now" shell = selected_shells[0] return initialize_dev(shell) else: for_user = args.user if not (args.install and args.user and args.system): for_user = True if args.no_user: for_user = False anaconda_prompt = on_win and args.anaconda_prompt exit_code = initialize( context.conda_prefix, selected_shells, for_user, args.system, anaconda_prompt, args.reverse, ) changed = False if not exit_code and not args.reverse: plan = make_initialize_plan( context.conda_prefix, selected_shells, for_user, args.system, anaconda_prompt, args.reverse, ) for el in plan: if el.get("function") == "init_sh_user": args = el.get("kwargs") target_path = args["target_path"] conda_prefix = args["conda_prefix"] add_mamba_to_rcfile(target_path, conda_prefix) changed = True if el.get("function") == "init_sh_system": args = el.get("kwargs") target_path = args["target_path"] conda_prefix = args["conda_prefix"] add_mamba_to_rcfile(target_path, conda_prefix) changed = True if changed: print("\n==> For changes to take effect, close" "and re-open your current shell. <==\n") return exit_code