def test_pinned_specs(): specs_1 = ("numpy 1.11", "python >3") with env_var('CONDA_PINNED_PACKAGES', '/'.join(specs_1), reset_context): pinned = plan.get_pinned_specs("/none") assert pinned == specs_1 specs_2 = ("scipy ==0.14.2", "openjdk >=8") with tempdir() as td: mkdir_p(join(td, 'conda-meta')) with open(join(td, 'conda-meta', 'pinned'), 'w') as fh: fh.write("\n".join(specs_2)) fh.write("\n") pinned = plan.get_pinned_specs(td) assert pinned == specs_2 with tempdir() as td: mkdir_p(join(td, 'conda-meta')) with open(join(td, 'conda-meta', 'pinned'), 'w') as fh: fh.write("\n".join(specs_1)) fh.write("\n") with env_var('CONDA_PREFIX', td, reset_context): run_command(Commands.CONFIG, "--env --add pinned_packages requests=2.13") with env_var('CONDA_PINNED_PACKAGES', '/'.join(specs_2), reset_context): pinned = plan.get_pinned_specs(td) assert pinned == specs_2 + ("requests 2.13", ) + specs_1
def test_local_channel(self): conda_bld_path = join(gettempdir(), 'conda-bld') mkdir_p(conda_bld_path) try: with env_var('CONDA_CROOT', conda_bld_path, reset_context): Channel._reset_state() channel = Channel('local') assert channel._channels[0].name.rsplit('/', 1)[-1] == 'conda-bld' assert channel.channel_name == "local" assert channel.platform is None assert channel.package_filename is None assert channel.auth is None assert channel.token is None assert channel.scheme is None assert channel.canonical_name == "local" local_channel_first_subchannel = channel._channels[0].name channel = Channel(local_channel_first_subchannel) assert channel.channel_name == local_channel_first_subchannel assert channel.platform is None assert channel.package_filename is None assert channel.auth is None assert channel.token is None assert channel.scheme == "file" assert channel.canonical_name == "local" assert channel.urls() == Channel(local_channel_first_subchannel).urls() assert channel.urls()[0].startswith('file:///') finally: rm_rf(conda_bld_path)
def main(): _, args = parse_args(sys.argv[1:]) args = args.__dict__ config = Config(**args) init_api_context() config.output_folder = os.path.abspath(config.output_folder) if not os.path.exists(config.output_folder): mkdir_p(config.output_folder) print(f"Updating build index: {(config.output_folder)}\n") update_index(config.output_folder, verbose=config.debug, threads=1) recipe = args["recipe"][0] if args["test"]: api.test(recipe, config=config) else: api.build( recipe, post=args["post"], build_only=args["build_only"], notest=args["notest"], config=config, variants=args["variants"], )
def test_activate_same_environment(self): with tempdir() as td: mkdir_p(join(td, 'conda-meta')) activate_d_dir = mkdir_p(join(td, 'etc', 'conda', 'activate.d')) activate_d_1 = join(activate_d_dir, 'see-me.sh') activate_d_2 = join(activate_d_dir, 'dont-see-me.bat') touch(join(activate_d_1)) touch(join(activate_d_2)) old_prefix = td deactivate_d_dir = mkdir_p(join(old_prefix, 'etc', 'conda', 'deactivate.d')) deactivate_d_1 = join(deactivate_d_dir, 'see-me.sh') deactivate_d_2 = join(deactivate_d_dir, 'dont-see-me.bat') touch(join(deactivate_d_1)) touch(join(deactivate_d_2)) with env_var('CONDA_SHLVL', '1'): with env_var('CONDA_PREFIX', old_prefix): activator = Activator('posix') builder = activator.build_activate(td) set_vars = { 'CONDA_PROMPT_MODIFIER': "(%s) " % td, 'CONDA_SHLVL': 1, } assert builder['unset_vars'] == () assert builder['set_vars'] == set_vars assert builder['activate_scripts'] == (activator.path_conversion(activate_d_1),) assert builder['deactivate_scripts'] == (activator.path_conversion(deactivate_d_1),)
def test_build_deactivate_shlvl_1(self): with tempdir() as td: mkdir_p(join(td, 'conda-meta')) deactivate_d_dir = mkdir_p(join(td, 'etc', 'conda', 'deactivate.d')) deactivate_d_1 = join(deactivate_d_dir, 'see-me-deactivate.sh') deactivate_d_2 = join(deactivate_d_dir, 'dont-see-me.bat') touch(join(deactivate_d_1)) touch(join(deactivate_d_2)) with env_var('CONDA_SHLVL', '1'): with env_var('CONDA_PREFIX', td): activator = Activator('posix') original_path = tuple(activator._get_starting_path_list()) builder = activator.build_deactivate() assert builder['unset_vars'] == ( 'CONDA_PREFIX', 'CONDA_DEFAULT_ENV', 'CONDA_PYTHON_EXE', 'CONDA_PROMPT_MODIFIER', ) new_path = activator.pathsep_join(activator.path_conversion(original_path)) assert builder['set_vars'] == { 'PATH': new_path, 'CONDA_SHLVL': 0, } assert builder['activate_scripts'] == () assert builder['deactivate_scripts'] == (activator.path_conversion(deactivate_d_1),)
def test_clean_logfiles(clear_cache): """Logfiles are found in pkgs_dir/.logs. Since these log files are uniquely implemented for the experimental libmamba release we will mock the log files. """ pkg = "bzip2" with make_temp_package_cache() as pkgs_dir: # logfiles don't exist ahead of time assert not _get_logfiles(pkgs_dir) with make_temp_env(pkg): # mimic logfiles being created logs = join(pkgs_dir, CONDA_LOGS_DIR) mkdir_p(logs) path = join(logs, f"{datetime.utcnow():%Y%m%d-%H%M%S-%f}.log") with open(path, "w"): pass # logfiles exist assert path in _get_logfiles(pkgs_dir) # --json flag is regression test for #5451 stdout, _, _ = run_command(Commands.CLEAN, "", "--logfiles", "--yes", "--json") json_loads(stdout) # assert valid json # logfiles removed assert not _get_logfiles(pkgs_dir) # logfiles still removed assert not _get_logfiles(pkgs_dir)
def test_build_activate_shlvl_0(self): with tempdir() as td: mkdir_p(join(td, 'conda-meta')) activate_d_dir = mkdir_p(join(td, 'etc', 'conda', 'activate.d')) activate_d_1 = join(activate_d_dir, 'see-me.sh') activate_d_2 = join(activate_d_dir, 'dont-see-me.bat') touch(join(activate_d_1)) touch(join(activate_d_2)) with env_var('CONDA_SHLVL', '0'): with env_var('CONDA_PREFIX', ''): activator = Activator('posix') builder = activator.build_activate(td) new_path = activator.pathsep_join(activator._add_prefix_to_path(td)) assert builder['unset_vars'] == () set_vars = { 'CONDA_PYTHON_EXE': sys.executable, 'PATH': new_path, 'CONDA_PREFIX': td, 'CONDA_SHLVL': 1, 'CONDA_DEFAULT_ENV': td, 'CONDA_PROMPT_MODIFIER': "(%s) " % td, } assert builder['set_vars'] == set_vars assert builder['activate_scripts'] == [activate_d_1] assert builder['deactivate_scripts'] == ()
def test_clean_tarballs_and_packages(self): pkgs_dir = PackageCache.first_writable().pkgs_dir mkdir_p(pkgs_dir) pkgs_dir_hold = pkgs_dir + '_hold' try: shutil.move(pkgs_dir, pkgs_dir_hold) with make_temp_env("flask") as prefix: pkgs_dir_contents = [join(pkgs_dir, d) for d in os.listdir(pkgs_dir)] pkgs_dir_dirs = [d for d in pkgs_dir_contents if isdir(d)] pkgs_dir_tarballs = [f for f in pkgs_dir_contents if f.endswith('.tar.bz2')] assert any(basename(d).startswith('flask-') for d in pkgs_dir_dirs) assert any(basename(f).startswith('flask-') for f in pkgs_dir_tarballs) run_command(Commands.CLEAN, prefix, "--packages --yes") run_command(Commands.CLEAN, prefix, "--tarballs --yes") pkgs_dir_contents = [join(pkgs_dir, d) for d in os.listdir(pkgs_dir)] pkgs_dir_dirs = [d for d in pkgs_dir_contents if isdir(d)] pkgs_dir_tarballs = [f for f in pkgs_dir_contents if f.endswith('.tar.bz2')] assert any(basename(d).startswith('flask-') for d in pkgs_dir_dirs) assert not any(basename(f).startswith('flask-') for f in pkgs_dir_tarballs) run_command(Commands.CLEAN, prefix, "--packages --yes") pkgs_dir_contents = [join(pkgs_dir, d) for d in os.listdir(pkgs_dir)] pkgs_dir_dirs = [d for d in pkgs_dir_contents if isdir(d)] assert not any(basename(d).startswith('flask-') for d in pkgs_dir_dirs) finally: rm_rf(pkgs_dir) shutil.move(pkgs_dir_hold, pkgs_dir) PackageCache.clear()
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 run_build(args): folder = args.recipe_dir or os.path.dirname(args.target) variant = {} if args.target_platform: variant["target_platform"] = args.target_platform cbc, config = get_config(folder, variant, args.variant_config_files) cbc["target_platform"] = [args.target_platform] if not os.path.exists(config.output_folder): mkdir_p(config.output_folder) console.print(f"Updating build index: {(config.output_folder)}\n") update_index(config.output_folder, verbose=config.debug, threads=1) all_recipes = find_all_recipes(args.target, config) # [noqa] console.print("\n[yellow]Assembling all recipes and variants[/yellow]\n") for recipe in all_recipes: build_recipe( args, recipe["recipe_file"], cbc, config, notest=getattr(args, "notest", False), )
def test_build_activate_shlvl_2(self): with tempdir() as td: mkdir_p(join(td, 'conda-meta')) activate_d_dir = mkdir_p(join(td, 'etc', 'conda', 'activate.d')) activate_d_1 = join(activate_d_dir, 'see-me.sh') activate_d_2 = join(activate_d_dir, 'dont-see-me.bat') touch(join(activate_d_1)) touch(join(activate_d_2)) old_prefix = join(td, 'old') deactivate_d_dir = mkdir_p(join(old_prefix, 'etc', 'conda', 'deactivate.d')) deactivate_d_1 = join(deactivate_d_dir, 'see-me.sh') deactivate_d_2 = join(deactivate_d_dir, 'dont-see-me.bat') touch(join(deactivate_d_1)) touch(join(deactivate_d_2)) with env_var('CONDA_SHLVL', '2'): with env_var('CONDA_PREFIX', old_prefix): activator = Activator('posix') builder = activator.build_activate(td) new_path = activator.pathsep_join(activator._add_prefix_to_path(td)) assert builder['unset_vars'] == () set_vars = { 'PATH': new_path, 'CONDA_PREFIX': td, 'CONDA_DEFAULT_ENV': td, 'CONDA_PROMPT_MODIFIER': "(%s) " % td, } assert builder['set_vars'] == set_vars assert builder['activate_scripts'] == (activator.path_conversion(activate_d_1),) assert builder['deactivate_scripts'] == (activator.path_conversion(deactivate_d_1),)
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_local_channel(self): conda_bld_path = join(gettempdir(), 'conda-bld') mkdir_p(conda_bld_path) try: with env_var('CONDA_CROOT', conda_bld_path, reset_context): Channel._reset_state() channel = Channel('local') assert channel._channels[0].name.rsplit('/', 1)[-1] == 'conda-bld' assert channel.channel_name == "local" assert channel.platform is None assert channel.package_filename is None assert channel.auth is None assert channel.token is None assert channel.scheme is None assert channel.canonical_name == "local" local_channel_first_subchannel = channel._channels[0].name channel = Channel(local_channel_first_subchannel) assert channel.channel_name == local_channel_first_subchannel assert channel.platform is None assert channel.package_filename is None assert channel.auth is None assert channel.token is None assert channel.scheme == "file" assert channel.canonical_name == "local" assert channel.urls() == Channel(local_channel_first_subchannel).urls() assert channel.urls()[0].startswith('file:///') finally: rm_rf(conda_bld_path)
def test_activate_same_environment(self): with tempdir() as td: mkdir_p(join(td, 'conda-meta')) activate_d_dir = mkdir_p(join(td, 'etc', 'conda', 'activate.d')) activate_d_1 = join(activate_d_dir, 'see-me.sh') activate_d_2 = join(activate_d_dir, 'dont-see-me.bat') touch(join(activate_d_1)) touch(join(activate_d_2)) old_prefix = td deactivate_d_dir = mkdir_p(join(old_prefix, 'etc', 'conda', 'deactivate.d')) deactivate_d_1 = join(deactivate_d_dir, 'see-me.sh') deactivate_d_2 = join(deactivate_d_dir, 'dont-see-me.bat') touch(join(deactivate_d_1)) touch(join(deactivate_d_2)) with env_var('CONDA_SHLVL', '2'): with env_var('CONDA_PREFIX', old_prefix): activator = Activator('posix') builder = activator.build_activate(td) assert builder['unset_vars'] == () assert builder['set_vars'] == {} assert builder['activate_scripts'] == [activate_d_1] assert builder['deactivate_scripts'] == [deactivate_d_1]
def run_build(args): if getattr(args, "json", False): global console console.quiet = True selected_features = extract_features(args.features) folder = args.recipe_dir or os.path.dirname(args.target) variant = {"target_platform": args.target_platform or context.subdir} cbc, config = get_config(folder, variant, args.variant_config_files) cbc["target_platform"] = [variant["target_platform"]] if not os.path.exists(config.output_folder): mkdir_p(config.output_folder) console.print(f"Updating build index: {(config.output_folder)}\n") update_index(config.output_folder, verbose=config.debug, threads=1) all_recipes = find_all_recipes(args.target, config) # [noqa] console.print("\n[yellow]Assembling all recipes and variants[/yellow]\n") for recipe in all_recipes: build_recipe( args.command, recipe["recipe_file"], cbc, config, selected_features=selected_features, notest=getattr(args, "notest", False), skip_existing=getattr(args, "skip_existing", False) != "default", interactive=getattr(args, "interactive", False), skip_fast=getattr(args, "skip_existing", "default") == "fast", )
def test_build_activate_shlvl_1(self): with tempdir() as td: mkdir_p(join(td, 'conda-meta')) activate_d_dir = mkdir_p(join(td, 'etc', 'conda', 'activate.d')) activate_d_1 = join(activate_d_dir, 'see-me.sh') activate_d_2 = join(activate_d_dir, 'dont-see-me.bat') touch(join(activate_d_1)) touch(join(activate_d_2)) old_prefix = '/old/prefix' with env_var('CONDA_SHLVL', '1'): with env_var('CONDA_PREFIX', old_prefix): activator = Activator('posix') builder = activator.build_activate(td) new_path = activator.pathsep_join(activator._add_prefix_to_path(td)) conda_prompt_modifier = "(%s) " % td ps1 = conda_prompt_modifier + os.environ.get('PS1', '') assert builder['unset_vars'] == () set_vars = { 'PS1': ps1, } export_vars = { 'PATH': new_path, 'CONDA_PREFIX': td, 'CONDA_PREFIX_1': old_prefix, 'CONDA_SHLVL': 2, 'CONDA_DEFAULT_ENV': td, 'CONDA_PROMPT_MODIFIER': conda_prompt_modifier, } assert builder['set_vars'] == set_vars assert builder['export_vars'] == export_vars assert builder['activate_scripts'] == (activator.path_conversion(activate_d_1),) assert builder['deactivate_scripts'] == ()
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 setUp(self): tempdirdir = gettempdir() prefix_dirname = str(uuid4())[:4] + ' ' + str(uuid4())[:4] self.prefix = join(tempdirdir, prefix_dirname) mkdir_p(join(self.prefix, 'conda-meta')) assert isdir(self.prefix) touch(join(self.prefix, 'conda-meta', 'history'))
def make_test_file(target_dir, suffix='', contents=''): if not isdir(target_dir): mkdir_p(target_dir) fn = str(uuid4())[:8] full_path = join(target_dir, fn + suffix) with open(full_path, 'w') as fh: fh.write(contents or str(uuid4())) return full_path
def make_test_file(target_dir, suffix=''): if not isdir(target_dir): mkdir_p(target_dir) fn = str(uuid4())[:8] full_path = join(target_dir, fn + suffix) with open(full_path, 'w') as fh: fh.write(str(uuid4())) return full_path
def copy_recipe(m): if m.config.include_recipe and m.include_recipe(): # store the rendered recipe.yaml file, plus information about where it came from # and what version of conda-build created it recipe_dir = join(m.config.info_dir, "recipe") mkdir_p(recipe_dir) original_recipe = "" if m.is_output: _copy_output_recipe(m, recipe_dir) else: _copy_top_level_recipe(m.path, m.config, recipe_dir) original_recipe = m.meta_path output_metadata = m.copy() # hard code the build string, so that tests don't get it mixed up build = output_metadata.meta.get("build", {}) build["string"] = output_metadata.build_id() output_metadata.meta["build"] = build # just for lack of confusion, don't show outputs in final rendered recipes if "outputs" in output_metadata.meta: del output_metadata.meta["outputs"] if "parent_recipe" in output_metadata.meta.get("extra", {}): del output_metadata.meta["extra"]["parent_recipe"] utils.sort_list_in_nested_structure(output_metadata.meta, ("build/script", "test/commands")) rendered = output_yaml(output_metadata) if original_recipe: with open(original_recipe, "rb") as f: original_recipe_text = UnicodeDammit(f.read()).unicode_markup if not original_recipe or not original_recipe_text == rendered: with open(join(recipe_dir, "recipe.yaml"), "w") as f: f.write("# This file created by boa {}\n".format(boa_version)) if original_recipe: f.write("# recipe.yaml template originally from:\n") f.write("# " + get_repository_info(m.path) + "\n") f.write( "# ------------------------------------------------\n\n") f.write(rendered) if original_recipe: utils.copy_into( original_recipe, os.path.join(recipe_dir, "recipe.yaml.template"), timeout=m.config.timeout, locking=m.config.locking, clobber=True, ) # dump the full variant in use for this package to the recipe folder with open(os.path.join(recipe_dir, "conda_build_config.yaml"), "w") as f: yaml.dump(m.config.variant, f)
def make_dot_d_files(self, extension): mkdir_p(join(self.prefix, 'etc', 'conda', 'activate.d')) mkdir_p(join(self.prefix, 'etc', 'conda', 'deactivate.d')) touch(join(self.prefix, 'etc', 'conda', 'activate.d', 'ignore.txt')) touch(join(self.prefix, 'etc', 'conda', 'deactivate.d', 'ignore.txt')) touch(join(self.prefix, 'etc', 'conda', 'activate.d', 'activate1' + extension)) touch(join(self.prefix, 'etc', 'conda', 'deactivate.d', 'deactivate1' + extension))
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 _create_env_conda_43(prefix, index, full_list_of_packages): assert CONDA_VERSION_MAJOR_MINOR >= (4, 3) from conda.core.package_cache import ProgressiveFetchExtract from conda.core.link import UnlinkLinkTransaction from conda.gateways.disk.create import mkdir_p pfe = ProgressiveFetchExtract(index, full_list_of_packages) pfe.execute() mkdir_p(prefix) txn = UnlinkLinkTransaction.create_from_dists(index, prefix, (), full_list_of_packages) txn.execute()
def setUp(self): tempdirdir = gettempdir() prefix_dirname = str(uuid4())[:4] + ' ' + str(uuid4())[:4] self.prefix = join(tempdirdir, prefix_dirname) mkdir_p(self.prefix) assert isdir(self.prefix) pkgs_dirname = str(uuid4())[:4] + ' ' + str(uuid4())[:4] self.pkgs_dir = join(tempdirdir, pkgs_dirname) mkdir_p(self.pkgs_dir) assert isdir(self.pkgs_dir)
def setUp(self): tempdirdir = gettempdir() prefix_dirname = str(uuid4())[:4] + ' ' + str(uuid4())[:4] self.prefix = join(tempdirdir, prefix_dirname) mkdir_p(join(self.prefix, 'conda-meta')) assert isdir(self.prefix) touch(join(self.prefix, 'conda-meta', 'history')) self.hold_environ = os.environ.copy() for var in POP_THESE: os.environ.pop(var, None)
def setUp(self): tempdirdir = gettempdir() prefix_dirname = str(uuid4())[:4] + ' ' + str(uuid4())[:4] + '-prefix' self.prefix = join(tempdirdir, prefix_dirname) mkdir_p(self.prefix) assert isdir(self.prefix) pkgs_dirname = str(uuid4())[:4] + ' ' + str(uuid4())[:4] self.pkgs_dir = join(tempdirdir, pkgs_dirname) mkdir_p(self.pkgs_dir) assert isdir(self.pkgs_dir)
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_clean_tarballs_and_packages(self): pkgs_dir = PackageCache.first_writable().pkgs_dir mkdir_p(pkgs_dir) pkgs_dir_hold = pkgs_dir + '_hold' try: shutil.move(pkgs_dir, pkgs_dir_hold) with make_temp_env("flask") as prefix: pkgs_dir_contents = [ join(pkgs_dir, d) for d in os.listdir(pkgs_dir) ] pkgs_dir_dirs = [d for d in pkgs_dir_contents if isdir(d)] pkgs_dir_tarballs = [ f for f in pkgs_dir_contents if f.endswith('.tar.bz2') ] assert any( basename(d).startswith('flask-') for d in pkgs_dir_dirs) assert any( basename(f).startswith('flask-') for f in pkgs_dir_tarballs) run_command(Commands.CLEAN, prefix, "--packages --yes") run_command(Commands.CLEAN, prefix, "--tarballs --yes") pkgs_dir_contents = [ join(pkgs_dir, d) for d in os.listdir(pkgs_dir) ] pkgs_dir_dirs = [d for d in pkgs_dir_contents if isdir(d)] pkgs_dir_tarballs = [ f for f in pkgs_dir_contents if f.endswith('.tar.bz2') ] assert any( basename(d).startswith('flask-') for d in pkgs_dir_dirs) assert not any( basename(f).startswith('flask-') for f in pkgs_dir_tarballs) run_command(Commands.CLEAN, prefix, "--packages --yes") pkgs_dir_contents = [ join(pkgs_dir, d) for d in os.listdir(pkgs_dir) ] pkgs_dir_dirs = [d for d in pkgs_dir_contents if isdir(d)] assert not any( basename(d).startswith('flask-') for d in pkgs_dir_dirs) finally: rm_rf(pkgs_dir) shutil.move(pkgs_dir_hold, pkgs_dir) PackageCache.clear()
def make_temp_package_cache(): prefix = make_temp_prefix(use_restricted_unicode=on_win) pkgs_dir = join(prefix, "pkgs") mkdir_p(pkgs_dir) touch(join(pkgs_dir, PACKAGE_CACHE_MAGIC_FILE)) try: with env_var("CONDA_PKGS_DIRS", pkgs_dir, stack_callback=conda_tests_ctxt_mgmt_def_pol): assert context.pkgs_dirs == (pkgs_dir, ) yield pkgs_dir finally: rmtree(prefix, ignore_errors=True) if pkgs_dir in PackageCacheData._cache_: del PackageCacheData._cache_[pkgs_dir]
def gen_test_env_paths(envs, shell, num_test_folders=5): """People need not use all the test folders listed here. This is only for shortening the environment string generation. Also encapsulates paths in double quotes. """ paths = [os.path.join(envs, "test {}".format(test_folder+1)) for test_folder in range(num_test_folders)] for path in paths[:2]: # These tests assume only the first two paths can be activated # Create symlinks ONLY for the first two folders. # symlink_conda(path, sys.prefix, shell) mkdir_p(join(path, 'conda-meta')) touch(join(path, 'conda-meta', 'history')) converter = shells[shell]["path_to"] paths = [converter(path) for path in paths] return paths
def gen_test_env_paths(envs, shell, num_test_folders=5): """People need not use all the test folders listed here. This is only for shortening the environment string generation. Also encapsulates paths in double quotes. """ paths = [os.path.join(envs, "test {}".format(test_folder+1)) for test_folder in range(num_test_folders)] for path in paths[:2]: # These tests assume only the first two paths can be activated # Create symlinks ONLY for the first two folders. # symlink_conda(path, sys.prefix, shell) mkdir_p(join(path, 'conda-meta')) touch(join(path, 'conda-meta', 'history')) converter = shells[shell]["path_to"] paths = [converter(path) for path in paths] return paths
def output_yaml(metadata, filename=None, suppress_outputs=False): local_metadata = metadata.copy() if (suppress_outputs and local_metadata.is_output and "outputs" in local_metadata.meta): del local_metadata.meta["outputs"] output = yaml.dump((local_metadata.meta), default_flow_style=False, indent=4) if filename: if any(sep in filename for sep in ("\\", "/")): mkdir_p(os.path.dirname(filename)) with open(filename, "w") as f: f.write(output) return "Wrote yaml to %s" % filename else: return output
def test_conda_bld_path(self): conda_bld_path = join(gettempdir(), 'conda-bld') conda_bld_url = path_to_url(conda_bld_path) try: mkdir_p(conda_bld_path) with env_var('CONDA_BLD_PATH', conda_bld_path, stack_callback=conda_tests_ctxt_mgmt_def_pol): assert len(context.conda_build_local_paths) >= 1 assert context.conda_build_local_paths[0] == conda_bld_path channel = Channel('local') assert channel.channel_name == "local" assert channel.channel_location is None assert channel.platform is None assert channel.package_filename is None assert channel.auth is None assert channel.token is None assert channel.scheme is None assert channel.canonical_name == "local" assert channel.url() is None urls = list( concat(( join_url(url, context.subdir), join_url(url, 'noarch'), ) for url in context.conda_build_local_urls)) assert channel.urls() == urls channel = Channel(conda_bld_url) assert channel.canonical_name == "local" assert channel.platform is None assert channel.package_filename is None assert channel.auth is None assert channel.token is None assert channel.scheme == "file" assert channel.urls() == [ join_url(conda_bld_url, context.subdir), join_url(conda_bld_url, 'noarch'), ] assert channel.url() == join_url(conda_bld_url, context.subdir) assert channel.channel_name.lower() == win_path_backout( conda_bld_path).lstrip('/').lower() assert channel.channel_location == '' # location really is an empty string; all path information is in channel_name assert channel.canonical_name == "local" finally: rm_rf(conda_bld_path)
def test_default_env(self): activator = Activator('posix') assert 'root' == activator._default_env(context.root_prefix) with tempdir() as td: assert td == activator._default_env(td) p = mkdir_p(join(td, 'envs', 'named-env')) assert 'named-env' == activator._default_env(p)
def test_build_deactivate_shlvl_2(self): with tempdir() as td: mkdir_p(join(td, 'conda-meta')) deactivate_d_dir = mkdir_p(join(td, 'etc', 'conda', 'deactivate.d')) deactivate_d_1 = join(deactivate_d_dir, 'see-me-deactivate.sh') deactivate_d_2 = join(deactivate_d_dir, 'dont-see-me.bat') touch(join(deactivate_d_1)) touch(join(deactivate_d_2)) old_prefix = join(td, 'old') activate_d_dir = mkdir_p(join(old_prefix, 'etc', 'conda', 'activate.d')) activate_d_1 = join(activate_d_dir, 'see-me-activate.sh') activate_d_2 = join(activate_d_dir, 'dont-see-me.bat') touch(join(activate_d_1)) touch(join(activate_d_2)) with env_var('CONDA_SHLVL', '2'): with env_var('CONDA_PREFIX_1', old_prefix): with env_var('CONDA_PREFIX', td): activator = Activator('posix') original_path = tuple(activator._get_starting_path_list()) builder = activator.build_deactivate() assert builder['unset_vars'] == ('CONDA_PREFIX_1',) new_path = activator.pathsep_join(activator.path_conversion(original_path)) conda_prompt_modifier = "(%s) " % old_prefix ps1 = conda_prompt_modifier + os.environ.get('PS1', '') set_vars = { 'PS1': ps1, } export_vars = { 'PATH': new_path, 'CONDA_SHLVL': 1, 'CONDA_PREFIX': old_prefix, 'CONDA_DEFAULT_ENV': old_prefix, 'CONDA_PROMPT_MODIFIER': conda_prompt_modifier, } assert builder['set_vars'] == set_vars assert builder['export_vars'] == export_vars assert builder['activate_scripts'] == (activator.path_conversion(activate_d_1),) assert builder['deactivate_scripts'] == (activator.path_conversion(deactivate_d_1),)
def run_build(args): folder = args.recipe_dir cbc, config = get_config(folder) # target = os.path.dirname(args.target) if not os.path.exists(config.output_folder): mkdir_p(config.output_folder) console.print(f"Updating build index: {(config.output_folder)}\n") update_index(config.output_folder, verbose=config.debug, threads=1) all_recipes = find_all_recipes(args.target, config) # [noqa] console.print("\n[yellow]Assembling all recipes and variants[/yellow]\n") for recipe in all_recipes: build_recipe(args, recipe["recipe_file"], cbc, config)
def test_conda_bld_path(self): conda_bld_path = join(gettempdir(), 'conda-bld') conda_bld_url = path_to_url(conda_bld_path) try: mkdir_p(conda_bld_path) with env_var('CONDA_BLD_PATH', conda_bld_path, reset_context): assert len(context.conda_build_local_paths) >= 1 assert context.conda_build_local_paths[0] == conda_bld_path channel = Channel('local') assert channel.channel_name == "local" assert channel.channel_location is None assert channel.platform is None assert channel.package_filename is None assert channel.auth is None assert channel.token is None assert channel.scheme is None assert channel.canonical_name == "local" assert channel.url() is None urls = list(concat(( join_url(url, context.subdir), join_url(url, 'noarch'), ) for url in context.conda_build_local_urls)) assert channel.urls() == urls channel = Channel(conda_bld_url) assert channel.canonical_name == "local" assert channel.platform is None assert channel.package_filename is None assert channel.auth is None assert channel.token is None assert channel.scheme == "file" assert channel.urls() == [ join_url(conda_bld_url, context.subdir), join_url(conda_bld_url, 'noarch'), ] assert channel.url() == join_url(conda_bld_url, context.subdir) assert channel.channel_name.lower() == win_path_backout(conda_bld_path).lstrip('/').lower() assert channel.channel_location == '' # location really is an empty string; all path information is in channel_name assert channel.canonical_name == "local" finally: rm_rf(conda_bld_path)
def test_target_prefix(self): with tempdir() as prefix: mkdir_p(join(prefix, 'first', 'envs')) mkdir_p(join(prefix, 'second', 'envs')) create_package_cache_directory(join(prefix, 'first', 'pkgs')) create_package_cache_directory(join(prefix, 'second', 'pkgs')) envs_dirs = (join(prefix, 'first', 'envs'), join(prefix, 'second', 'envs')) with env_var('CONDA_ENVS_DIRS', os.pathsep.join(envs_dirs), reset_context): # with both dirs writable, choose first reset_context((), argparse_args=AttrDict(name='blarg', func='create')) assert context.target_prefix == join(envs_dirs[0], 'blarg') # with first dir read-only, choose second PackageCacheData._cache_.clear() make_read_only(join(envs_dirs[0], '.conda_envs_dir_test')) reset_context((), argparse_args=AttrDict(name='blarg', func='create')) assert context.target_prefix == join(envs_dirs[1], 'blarg') # if first dir is read-only but environment exists, choose first PackageCacheData._cache_.clear() mkdir_p(join(envs_dirs[0], 'blarg')) touch(join(envs_dirs[0], 'blarg', 'history')) reset_context((), argparse_args=AttrDict(name='blarg', func='create')) assert context.target_prefix == join(envs_dirs[0], 'blarg')
def test_remove_link_to_dir(): with tempdir() as td: dst_link = join(td, "test_link") src_dir = join(td, "test_dir") test_file = join(td, "test_file") mkdir_p(src_dir) touch(test_file) assert isdir(src_dir) assert not islink(src_dir) assert not islink(dst_link) if not softlink_supported(test_file, td) and on_win: pytest.skip("softlink not supported") symlink(src_dir, dst_link) assert islink(dst_link) assert rm_rf(dst_link) assert not isdir(dst_link) assert not islink(dst_link) assert not lexists(dst_link) assert isdir(src_dir) assert rm_rf(src_dir) assert not isdir(src_dir) assert not islink(src_dir)
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 setUp(self): tempdirdir = gettempdir() dirname = str(uuid.uuid4())[:8] self.test_dir = join(tempdirdir, dirname) mkdir_p(self.test_dir) assert isdir(self.test_dir)
def test_dist_with_channel_url(self): # standard named channel url = "https://repo.anaconda.com/pkgs/free/win-64/spyder-app-2.3.8-py27_0.tar.bz2" d = Dist(url) assert d.channel == 'defaults' assert d.name == 'spyder-app' assert d.version == '2.3.8' assert d.build_string == 'py27_0' assert d.to_url() == url assert d.is_channel is True # standard url channel url = "https://not.real.continuum.io/pkgs/free/win-64/spyder-app-2.3.8-py27_0.tar.bz2" d = Dist(url) assert d.channel == 'defaults' # because pkgs/anaconda is in defaults assert d.name == 'spyder-app' assert d.version == '2.3.8' assert d.build_string == 'py27_0' assert d.to_url() == url assert d.is_channel is True # another standard url channel url = "https://not.real.continuum.io/not/anaconda/win-64/spyder-app-2.3.8-py27_0.tar.bz2" d = Dist(url) assert d.channel == 'https://not.real.continuum.io/not/anaconda' assert d.name == 'spyder-app' assert d.version == '2.3.8' assert d.build_string == 'py27_0' assert d.to_url() == url assert d.is_channel is True # local file url that is a named channel conda_bld_path = join(gettempdir(), 'conda-bld') try: mkdir_p(conda_bld_path) with env_var('CONDA_BLD_PATH', conda_bld_path, stack_callback=conda_tests_ctxt_mgmt_def_pol): url = path_to_url(join_url(context.croot, 'osx-64', 'bcrypt-3.1.1-py35_2.tar.bz2')) d = Dist(url) assert d.channel == 'local' assert d.name == 'bcrypt' assert d.version == '3.1.1' assert d.build_string == 'py35_2' assert d.to_url() == url assert d.is_channel is True finally: rm_rf(conda_bld_path) # local file url that is not a named channel url = join_url('file:///some/location/on/disk', 'osx-64', 'bcrypt-3.1.1-py35_2.tar.bz2') d = Dist(url) assert d.channel == 'file:///some/location/on/disk' assert d.name == 'bcrypt' assert d.version == '3.1.1' assert d.build_string == 'py35_2' assert d.to_url() == url assert d.is_channel is True
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)