def test_subdir_data_prefers_conda_to_tar_bz2(): channel = Channel(join(dirname(__file__), "..", "data", "conda_format_repo", context.subdir)) # force this to False, because otherwise tests fail when run with old conda-build with env_var('CONDA_USE_ONLY_TAR_BZ2', False, stack_callback=conda_tests_ctxt_mgmt_def_pol): sd = SubdirData(channel) precs = tuple(sd.query("zlib")) assert precs[0].fn.endswith(".conda")
def test_subdir_data_prefers_conda_to_tar_bz2(): channel = Channel(join(dirname(__file__), "..", "data", "conda_format_repo", context.subdir)) sd = SubdirData(channel) precs = tuple(sd.query("zlib")) assert len(precs) == 1 prec = precs[0] assert prec.fn.endswith(".conda")
def test_subdir_data_prefers_conda_to_tar_bz2(): channel = Channel( join(dirname(__file__), "..", "data", "conda_format_repo", context.subdir)) sd = SubdirData(channel) precs = tuple(sd.query("zlib")) assert precs[0].fn.endswith(".conda")
def get_index_r_5(subdir=context.subdir): with open(join(dirname(__file__), 'data', 'index5.json')) as fi: packages = json.load(fi) repodata = { "info": { "subdir": subdir, "arch": context.arch_name, "platform": context.platform, }, "packages": packages, } channel = Channel('https://conda.anaconda.org/channel-5/%s' % subdir) sd = SubdirData(channel) with env_var("CONDA_ADD_PIP_AS_PYTHON_DEPENDENCY", "true", stack_callback=conda_tests_ctxt_mgmt_def_pol): sd._process_raw_repodata_str(json.dumps(repodata)) sd._loaded = True SubdirData._cache_[channel.url(with_credentials=True)] = sd index = {prec: prec for prec in sd._package_records} r = Resolve(index, channels=(channel, )) return index, r
def test_only_use_tar_bz2(): channel = Channel( join(dirname(__file__), "..", "data", "conda_format_repo", context.subdir)) context.use_only_tar_bz2 = True sd = SubdirData(channel) precs = tuple(sd.query("zlib")) assert precs[0].fn.endswith(".tar.bz2")
def test_subdir_data_context_offline(self): with env_var('CONDA_OFFLINE', 'yes', stack_callback=conda_tests_ctxt_mgmt_def_pol): local_channel = Channel( join(dirname(__file__), "..", "data", "conda_format_repo", context.subdir)) sd = SubdirData(channel=local_channel) assert len(sd.query_all('zlib', channels=[local_channel])) > 0 assert len(sd.query_all('zlib')) == 0 assert len(sd.query_all('zlib')) > 1
def execute(args, parser): spec = MatchSpec(args.match_spec) if spec.get_exact_value('subdir'): subdirs = spec.get_exact_value('subdir'), elif args.platform: subdirs = args.platform, else: subdirs = context.subdirs with Spinner("Loading channels", not context.verbosity and not context.quiet, context.json): spec_channel = spec.get_exact_value('channel') channel_urls = (spec_channel, ) if spec_channel else context.channels matches = sorted(SubdirData.query_all(spec, channel_urls, subdirs), key=lambda rec: (rec.name, VersionOrder(rec.version), rec.build)) if not matches: channels_urls = tuple( calculate_channel_urls( channel_urls=context.channels, prepend=not args.override_channels, platform=subdirs[0], use_local=args.use_local, )) from ..exceptions import PackagesNotFoundError raise PackagesNotFoundError((text_type(spec), ), channels_urls) else: return matches
def test_use_only_tar_bz2(): channel = Channel( join(dirname(__file__), "..", "data", "conda_format_repo", context.subdir)) SubdirData.clear_cached_local_channel_data() with env_var('CONDA_USE_ONLY_TAR_BZ2', True, stack_callback=conda_tests_ctxt_mgmt_def_pol): sd = SubdirData(channel) precs = tuple(sd.query("zlib")) assert precs[0].fn.endswith(".tar.bz2") SubdirData.clear_cached_local_channel_data() with env_var('CONDA_USE_ONLY_TAR_BZ2', False, stack_callback=conda_tests_ctxt_mgmt_def_pol): sd = SubdirData(channel) precs = tuple(sd.query("zlib")) assert precs[0].fn.endswith(".conda")
def test_metadata_cache_clearing(): channel = Channel( join(dirname(__file__), "..", "data", "conda_format_repo", context.subdir)) SubdirData.clear_cached_local_channel_data() with patch('conda.core.subdir_data.fetch_repodata_remote_request', wraps=fetch_repodata_remote_request) as fetcher: sd_a = SubdirData(channel) precs_a = tuple(sd_a.query("zlib")) assert fetcher.call_count == 1 SubdirData.clear_cached_local_channel_data() sd_b = SubdirData(channel) assert sd_b is not sd_a precs_b = tuple(sd_b.query("zlib")) assert fetcher.call_count == 2 assert precs_b == precs_a
def get_index_r_2(subdir=context.subdir): with open(join(dirname(__file__), 'data', 'index2.json')) as fi: packages = json.load(fi) repodata = { "info": { "subdir": subdir, "arch": context.arch_name, "platform": context.platform, }, "packages": packages, } channel = Channel('https://conda.anaconda.org/channel-2/%s' % subdir) sd = SubdirData(channel) with env_var("CONDA_ADD_PIP_AS_PYTHON_DEPENDENCY", "false", reset_context): sd._process_raw_repodata_str(json.dumps(repodata)) sd._loaded = True SubdirData._cache_[channel.url(with_credentials=True)] = sd index = {prec: prec for prec in sd._package_records} r = Resolve(index, channels=(channel,)) return index, r
def get_index_r_3(): with open(join(dirname(__file__), 'index3.json')) as fi: packages = json.load(fi) repodata = { "info": { "subdir": context.subdir, "arch": context.arch_name, "platform": context.platform, }, "packages": packages, } channel = Channel('https://conda.anaconda.org/channel-3/%s' % context.subdir) sd = SubdirData(channel) with env_var("CONDA_ADD_PIP_AS_PYTHON_DEPENDENCY", "false", reset_context): sd._process_raw_repodata_str(json.dumps(repodata)) sd._loaded = True SubdirData._cache_[channel.url(with_credentials=True)] = sd index = {Dist(prec): prec for prec in sd._package_records} r = Resolve(index, channels=(channel,)) return index, r
def test_metadata_cache_works(): channel = Channel( join(dirname(__file__), "..", "data", "conda_format_repo", context.subdir)) SubdirData.clear_cached_local_channel_data() # Sadly, on Windows, st_mtime resolution is limited to 2 seconds. (See note in Python docs # on os.stat_result.) To ensure that the timestamp on the existing JSON file is safely # in the past before this test starts, we need to wait for more than 2 seconds... sleep(3) with patch('conda.core.subdir_data.fetch_repodata_remote_request', wraps=fetch_repodata_remote_request) as fetcher: sd_a = SubdirData(channel) precs_a = tuple(sd_a.query("zlib")) assert fetcher.call_count == 1 sd_b = SubdirData(channel) assert sd_b is sd_a precs_b = tuple(sd_b.query("zlib")) assert fetcher.call_count == 1
def clear_subdir_cache(tmpdir): SubdirData.clear_cached_local_channel_data()
def get_index_must_unfreeze(subdir=context.subdir): repodata = { "info": { "subdir": subdir, "arch": context.arch_name, "platform": context.platform, }, "packages": { "foobar-1.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": ["libbar 2.0.*", "libfoo 1.0.*"], "md5": "11ec1194bcc56b9a53c127142a272772", "name": "foobar", "timestamp": 1562861325613, "version": "1.0" }, "foobar-2.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": ["libbar 2.0.*", "libfoo 2.0.*"], "md5": "f8eb5a7fa1ff6dead4e360631a6cd048", "name": "foobar", "version": "2.0" }, "libbar-1.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": [], "md5": "f51f4d48a541b7105b5e343704114f0f", "name": "libbar", "timestamp": 1562858881022, "version": "1.0" }, "libbar-2.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": [], "md5": "27f4e717ed263f909074f64d9cbf935d", "name": "libbar", "timestamp": 1562858881748, "version": "2.0" }, "libfoo-1.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": [], "md5": "ad7c088566ffe2389958daedf8ff312c", "name": "libfoo", "timestamp": 1562858763881, "version": "1.0" }, "libfoo-2.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": [], "md5": "daf7af7086d8f22be49ae11bdc41f332", "name": "libfoo", "timestamp": 1562858836924, "version": "2.0" }, "qux-1.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": ["libbar 2.0.*", "libfoo 1.0.*"], "md5": "18604cbe4f789fe853232eef4babd4f9", "name": "qux", "timestamp": 1562861393808, "version": "1.0" }, "qux-2.0-0.tar.bz2": { "build": "0", "build_number": 0, "depends": ["libbar 1.0.*", "libfoo 2.0.*"], "md5": "892aa4b9ec64b67045a46866ef1ea488", "name": "qux", "timestamp": 1562861394828, "version": "2.0" } } } channel = Channel('https://conda.anaconda.org/channel-freeze/%s' % subdir) sd = SubdirData(channel) with env_var("CONDA_ADD_PIP_AS_PYTHON_DEPENDENCY", "false", stack_callback=conda_tests_ctxt_mgmt_def_pol): sd._process_raw_repodata_str(json.dumps(repodata)) sd._loaded = True SubdirData._cache_[channel.url(with_credentials=True)] = sd index = {prec: prec for prec in sd._package_records} r = Resolve(index, channels=(channel, )) return index, r