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_CompilePycAction_noarch_python(self): if not softlink_supported(__file__, self.prefix) and on_win: pytest.skip("softlink not supported") target_python_version = '%d.%d' % sys.version_info[:2] sp_dir = get_python_site_packages_short_path(target_python_version) transaction_context = { 'target_python_version': target_python_version, 'target_site_packages_short_path': sp_dir, } package_info = AttrDict(package_metadata=AttrDict(noarch=AttrDict(type=NoarchType.python))) file_link_actions = [ AttrDict( source_short_path='site-packages/something.py', target_short_path=get_python_noarch_target_path('site-packages/something.py', sp_dir), ), AttrDict( # this one shouldn't get compiled source_short_path='something.py', target_short_path=get_python_noarch_target_path('something.py', sp_dir), ), ] axns = CompilePycAction.create_actions(transaction_context, package_info, self.prefix, None, file_link_actions) assert len(axns) == 1 axn = axns[0] assert axn.source_full_path == join(self.prefix, win_path_ok(get_python_noarch_target_path('site-packages/something.py', sp_dir))) assert axn.target_full_path == join(self.prefix, win_path_ok(pyc_path(get_python_noarch_target_path('site-packages/something.py', sp_dir), target_python_version))) # make .py file in prefix that will be compiled mkdir_p(dirname(axn.source_full_path)) with open(axn.source_full_path, 'w') as fh: fh.write("value = 42\n") # symlink the current python python_full_path = join(self.prefix, get_python_short_path(target_python_version)) mkdir_p(dirname(python_full_path)) create_link(sys.executable, python_full_path, LinkType.softlink) axn.execute() assert isfile(axn.target_full_path) # remove the source .py file so we're sure we're importing the pyc file below rm_rf(axn.source_full_path) assert not isfile(axn.source_full_path) if (3,) > sys.version_info >= (3, 5): # we're probably dropping py34 support soon enough anyway imported_pyc_file = load_python_file(axn.target_full_path) assert imported_pyc_file.value == 42 axn.reverse() assert not isfile(axn.target_full_path)
def test_CompilePycAction_noarch_python(self): target_python_version = '%d.%d' % sys.version_info[:2] sp_dir = get_python_site_packages_short_path(target_python_version) transaction_context = { 'target_python_version': target_python_version, 'target_site_packages_short_path': sp_dir, } package_info = AttrDict(package_metadata=AttrDict(noarch=AttrDict(type=NoarchType.python))) file_link_actions = [ AttrDict( source_short_path='site-packages/something.py', target_short_path=get_python_noarch_target_path('site-packages/something.py', sp_dir), ), AttrDict( # this one shouldn't get compiled source_short_path='something.py', target_short_path=get_python_noarch_target_path('something.py', sp_dir), ), ] axns = CompilePycAction.create_actions(transaction_context, package_info, self.prefix, None, file_link_actions) assert len(axns) == 1 axn = axns[0] assert axn.source_full_path == join(self.prefix, win_path_ok(get_python_noarch_target_path('site-packages/something.py', sp_dir))) assert axn.target_full_path == join(self.prefix, win_path_ok(pyc_path(get_python_noarch_target_path('site-packages/something.py', sp_dir), target_python_version))) # make .py file in prefix that will be compiled mkdir_p(dirname(axn.source_full_path)) with open(axn.source_full_path, 'w') as fh: fh.write("value = 42\n") # symlink the current python python_full_path = join(self.prefix, get_python_short_path(target_python_version)) mkdir_p(dirname(python_full_path)) create_link(sys.executable, python_full_path, LinkType.softlink) axn.execute() assert isfile(axn.target_full_path) # remove the source .py file so we're sure we're importing the pyc file below rm_rf(axn.source_full_path) assert not isfile(axn.source_full_path) if (3, ) > sys.version_info >= (3, 5): # we're probably dropping py34 support soon enough anyway imported_pyc_file = load_python_file(axn.target_full_path) assert imported_pyc_file.value == 42 axn.reverse() assert not isfile(axn.target_full_path)
def test_CreatePythonEntryPointAction_noarch_python(self): target_python_version = '%d.%d' % sys.version_info[:2] transaction_context = { 'target_python_version': target_python_version, } package_info = AttrDict(package_metadata=AttrDict(noarch=AttrDict( type=NoarchType.python, entry_points=( 'command1=some.module:main', 'command2=another.somewhere:go', ), ))) axns = CreatePythonEntryPointAction.create_actions(transaction_context, package_info, self.prefix, LinkType.hardlink) grouped_axns = groupby(lambda ax: isinstance(ax, LinkPathAction), axns) windows_exe_axns = grouped_axns.get(True, ()) assert len(windows_exe_axns) == (2 if on_win else 0) py_ep_axns = grouped_axns.get(False, ()) assert len(py_ep_axns) == 2 py_ep_axn = py_ep_axns[0] command, module, func = parse_entry_point_def('command1=some.module:main') assert command == 'command1' if on_win: target_short_path = "%s\\%s-script.py" % (get_bin_directory_short_path(), command) else: target_short_path = "%s/%s" % (get_bin_directory_short_path(), command) assert py_ep_axn.target_full_path == join(self.prefix, target_short_path) assert py_ep_axn.module == module == 'some.module' assert py_ep_axn.func == func == 'main' mkdir_p(dirname(py_ep_axn.target_full_path)) py_ep_axn.execute() assert isfile(py_ep_axn.target_full_path) if not on_win: assert is_executable(py_ep_axn.target_full_path) with open(py_ep_axn.target_full_path) as fh: lines = fh.readlines() first_line = lines[0].strip() last_line = lines[-1].strip() if not on_win: python_full_path = join(self.prefix, get_python_short_path(target_python_version)) assert first_line == "#!%s" % python_full_path assert last_line == "sys.exit(%s())" % func py_ep_axn.reverse() assert not isfile(py_ep_axn.target_full_path) if on_win: windows_exe_axn = windows_exe_axns[0] target_short_path = "%s\\%s.exe" % (get_bin_directory_short_path(), command) assert windows_exe_axn.target_full_path == join(self.prefix, target_short_path) mkdir_p(dirname(windows_exe_axn.target_full_path)) windows_exe_axn.verify() windows_exe_axn.execute() assert isfile(windows_exe_axn.target_full_path) assert is_executable(windows_exe_axn.target_full_path) src = compute_md5sum(join(context.conda_prefix, 'Scripts/conda.exe')) assert src == compute_md5sum(windows_exe_axn.target_full_path) windows_exe_axn.reverse() assert not isfile(windows_exe_axn.target_full_path)
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_CreatePythonEntryPointAction_noarch_python(self): target_python_version = '%d.%d' % sys.version_info[:2] transaction_context = { 'target_python_version': target_python_version, } package_info = AttrDict(package_metadata=AttrDict(noarch=AttrDict( type=NoarchType.python, entry_points=( 'command1=some.module:main', 'command2=another.somewhere:go', ), ))) axns = CreatePythonEntryPointAction.create_actions( transaction_context, package_info, self.prefix, LinkType.hardlink) grouped_axns = groupby(lambda ax: isinstance(ax, LinkPathAction), axns) windows_exe_axns = grouped_axns.get(True, ()) assert len(windows_exe_axns) == (2 if on_win else 0) py_ep_axns = grouped_axns.get(False, ()) assert len(py_ep_axns) == 2 py_ep_axn = py_ep_axns[0] command, module, func = parse_entry_point_def( 'command1=some.module:main') assert command == 'command1' if on_win: target_short_path = "%s\\%s-script.py" % ( get_bin_directory_short_path(), command) else: target_short_path = "%s/%s" % (get_bin_directory_short_path(), command) assert py_ep_axn.target_full_path == join(self.prefix, target_short_path) assert py_ep_axn.module == module == 'some.module' assert py_ep_axn.func == func == 'main' mkdir_p(dirname(py_ep_axn.target_full_path)) py_ep_axn.execute() assert isfile(py_ep_axn.target_full_path) if not on_win: assert is_executable(py_ep_axn.target_full_path) with open(py_ep_axn.target_full_path) as fh: lines = fh.readlines() first_line = lines[0].strip() last_line = lines[-1].strip() if not on_win: python_full_path = join( self.prefix, get_python_short_path(target_python_version)) assert first_line == "#!%s" % python_full_path assert last_line == "sys.exit(%s())" % func py_ep_axn.reverse() assert not isfile(py_ep_axn.target_full_path) if on_win: windows_exe_axn = windows_exe_axns[0] target_short_path = "%s\\%s.exe" % (get_bin_directory_short_path(), command) assert windows_exe_axn.target_full_path == join( self.prefix, target_short_path) mkdir_p(dirname(windows_exe_axn.target_full_path)) windows_exe_axn.verify() windows_exe_axn.execute() assert isfile(windows_exe_axn.target_full_path) assert is_executable(windows_exe_axn.target_full_path) src = compute_md5sum( join(context.conda_prefix, 'Scripts/conda.exe')) assert src == compute_md5sum(windows_exe_axn.target_full_path) windows_exe_axn.reverse() assert not isfile(windows_exe_axn.target_full_path)
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 test_CompileMultiPycAction_noarch_python(self): if not softlink_supported(__file__, self.prefix) and on_win: pytest.skip("softlink not supported") target_python_version = '%d.%d' % sys.version_info[:2] sp_dir = get_python_site_packages_short_path(target_python_version) transaction_context = { 'target_python_version': target_python_version, 'target_site_packages_short_path': sp_dir, } package_info = AttrDict(package_metadata=AttrDict(noarch=AttrDict(type=NoarchType.python))) file_link_actions = [ AttrDict( source_short_path='site-packages/something.py', target_short_path=get_python_noarch_target_path('site-packages/something.py', sp_dir), ), AttrDict( source_short_path='site-packages/another.py', target_short_path=get_python_noarch_target_path('site-packages/another.py', sp_dir), ), AttrDict( # this one shouldn't get compiled source_short_path='something.py', target_short_path=get_python_noarch_target_path('something.py', sp_dir), ), AttrDict( # this one shouldn't get compiled source_short_path='another.py', target_short_path=get_python_noarch_target_path('another.py', sp_dir), ), ] axns = CompileMultiPycAction.create_actions(transaction_context, package_info, self.prefix, None, file_link_actions) assert len(axns) == 1 axn = axns[0] source_full_paths = tuple(axn.source_full_paths) source_full_path0 = source_full_paths[0] source_full_path1 = source_full_paths[1] assert len(source_full_paths) == 2 assert source_full_path0 == join(self.prefix, win_path_ok(get_python_noarch_target_path('site-packages/something.py', sp_dir))) assert source_full_path1 == join(self.prefix, win_path_ok(get_python_noarch_target_path('site-packages/another.py', sp_dir))) target_full_paths = tuple(axn.target_full_paths) target_full_path0 = target_full_paths[0] target_full_path1 = target_full_paths[1] assert len(target_full_paths) == 2 assert target_full_path0 == join(self.prefix, win_path_ok(pyc_path(get_python_noarch_target_path('site-packages/something.py', sp_dir), target_python_version))) assert target_full_path1 == join(self.prefix, win_path_ok(pyc_path(get_python_noarch_target_path('site-packages/another.py', sp_dir), target_python_version))) # make .py file in prefix that will be compiled mkdir_p(dirname(source_full_path0)) with open(source_full_path0, 'w') as fh: fh.write("value = 42\n") mkdir_p(dirname(source_full_path1)) with open(source_full_path1, 'w') as fh: fh.write("value = 43\n") # symlink the current python python_full_path = join(self.prefix, get_python_short_path(target_python_version)) mkdir_p(dirname(python_full_path)) create_link(sys.executable, python_full_path, LinkType.softlink) axn.execute() assert isfile(target_full_path0) assert isfile(target_full_path1) # remove the source .py file so we're sure we're importing the pyc file below rm_rf(source_full_path0) assert not isfile(source_full_path0) rm_rf(source_full_path1) assert not isfile(source_full_path1) imported_pyc_file = load_python_file(target_full_path0) assert imported_pyc_file.value == 42 imported_pyc_file = load_python_file(target_full_path1) assert imported_pyc_file.value == 43 axn.reverse() assert not isfile(target_full_path0) assert not isfile(target_full_path1)