def test_url_custom_channel(self): # scheme and credentials within url should override what's registered in config channel = Channel("https://*****:*****@another.url:8080/with/path/t/new-token/chuck/label/dev") assert channel.canonical_name == "chuck/label/dev" assert channel.location == "another.url:8080/with/path" assert channel.url() == "https://another.url:8080/with/path/chuck/label/dev/%s" % self.platform assert channel.url(True) == "https://*****:*****@another.url:8080/with/path/t/new-token/chuck/label/dev/%s" % self.platform assert channel.urls() == [ "https://another.url:8080/with/path/chuck/label/dev/%s" % self.platform, "https://another.url:8080/with/path/chuck/label/dev/noarch", ] assert channel.urls(True) == [ "https://*****:*****@another.url:8080/with/path/t/new-token/chuck/label/dev/%s" % self.platform, "https://*****:*****@another.url:8080/with/path/t/new-token/chuck/label/dev/noarch", ]
def test_bare_channel(self): url = "http://conda-01" channel = Channel(url) assert channel.scheme == "http" assert channel.location == "conda-01" assert channel.platform is None assert channel.canonical_name == url assert channel.name is None assert channel.base_url == url assert channel.url() == join_url(url, context.subdir) assert channel.urls() == [ join_url(url, context.subdir), join_url(url, 'noarch'), ]
def test_token_in_custom_channel(self): channel = Channel("https://10.2.8.9:8080/conda/t/tk-987-321/bioconda/label/dev") assert channel.name == "bioconda/label/dev" assert channel.location == "10.2.8.9:8080/conda" assert channel.urls() == [ "https://10.2.8.9:8080/conda/bioconda/label/dev/%s" % self.platform, "https://10.2.8.9:8080/conda/bioconda/label/dev/noarch", ] assert channel.urls(with_credentials=True) == [ "https://10.2.8.9:8080/conda/t/tk-987-321/bioconda/label/dev/%s" % self.platform, "https://10.2.8.9:8080/conda/t/tk-987-321/bioconda/label/dev/noarch", ] channel = Channel("https://10.2.8.9:8080/conda/t/tk-987-321/bioconda") assert channel.name == "bioconda" assert channel.location == "10.2.8.9:8080/conda" assert channel.urls() == [ "https://10.2.8.9:8080/conda/bioconda/%s" % self.platform, "https://10.2.8.9:8080/conda/bioconda/noarch", ] assert channel.urls(with_credentials=True) == [ "https://10.2.8.9:8080/conda/t/tk-987-321/bioconda/%s" % self.platform, "https://10.2.8.9:8080/conda/t/tk-987-321/bioconda/noarch", ]
def test_local_channel(self): 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').urls() assert channel.urls()[0].startswith('file:///')
def test_channel_name_subdir_only(self): with env_unmodified(conda_tests_ctxt_mgmt_def_pol): channel = Channel('pkgs/free/win-64') assert channel.scheme == "https" assert channel.location == "repo.anaconda.com" assert channel.platform == 'win-64' == channel.subdir assert channel.name == 'pkgs/free' assert channel.base_url == 'https://repo.anaconda.com/pkgs/free' assert channel.canonical_name == 'defaults' assert channel.url() == 'https://repo.anaconda.com/pkgs/free/win-64' assert channel.urls() == [ 'https://repo.anaconda.com/pkgs/free/win-64', 'https://repo.anaconda.com/pkgs/free/noarch', ]
def test_channel_alias_w_subhcnnale(self): channel = Channel('bioconda/label/dev') assert channel.channel_name == "bioconda/label/dev" assert channel.channel_location == "10.2.3.4:8080/conda" assert channel.platform is None assert channel.package_filename is None assert channel.auth is None assert channel.scheme == "https" assert channel.canonical_name == 'bioconda/label/dev' assert channel.urls() == [ "https://10.2.3.4:8080/conda/bioconda/label/dev/%s" % self.platform, "https://10.2.3.4:8080/conda/bioconda/label/dev/noarch", ] assert channel.token == "tk-123-45"
def test_url_channel_w_platform(self): channel = Channel('https://repo.continuum.io/pkgs/free/osx-64') assert channel.scheme == "https" assert channel.location == "repo.continuum.io" assert channel.platform == 'osx-64' == channel.subdir assert channel.name == 'pkgs/free' assert channel.base_url == 'https://repo.continuum.io/pkgs/free' assert channel.canonical_name == 'defaults' assert channel.url() == 'https://repo.continuum.io/pkgs/free/osx-64' assert channel.urls() == [ 'https://repo.continuum.io/pkgs/free/osx-64', 'https://repo.continuum.io/pkgs/free/noarch', ]
def test_file_channel(self): channel = Channel("file:///var/folders/cp/7r2s_s593j7_cpdtp/T/5d9f5e45/osx-64/flask-0.10.1-py35_2.tar.bz2") assert channel.name == '5d9f5e45' assert channel.location == '/var/folders/cp/7r2s_s593j7_cpdtp/T' assert channel.platform == 'osx-64' assert channel.package_filename == "flask-0.10.1-py35_2.tar.bz2" assert channel.auth is None assert channel.token is None assert channel.scheme == "file" assert channel.url() == "file:///var/folders/cp/7r2s_s593j7_cpdtp/T/5d9f5e45/osx-64/flask-0.10.1-py35_2.tar.bz2" assert channel.urls() == [ "file:///var/folders/cp/7r2s_s593j7_cpdtp/T/5d9f5e45/osx-64", "file:///var/folders/cp/7r2s_s593j7_cpdtp/T/5d9f5e45/noarch" ] assert channel.canonical_name == 'file:///var/folders/cp/7r2s_s593j7_cpdtp/T/5d9f5e45'
def test_Solver_return_value_contract(): solver = Solver('/', (Channel('pkgs/main'),), specs_to_add=('openssl',)) solve_final_state_rv = solver.solve_final_state() assert isiterable(solve_final_state_rv) assert all(isinstance(pref, PackageRecord) for pref in solve_final_state_rv) solve_for_diff_rv = solver.solve_for_diff() assert len(solve_for_diff_rv) == 2 unlink_precs, link_precs = solve_for_diff_rv assert isiterable(unlink_precs) assert all(isinstance(pref, PackageRecord) for pref in unlink_precs) assert isiterable(link_precs) assert all(isinstance(pref, PackageRecord) for pref in link_precs) solve_for_transaction_rv = solver.solve_for_transaction() assert isinstance(solve_for_transaction_rv, UnlinkLinkTransaction)
def test_use_only_tar_bz2(): channel = Channel( join(dirname(__file__), "..", "data", "conda_format_repo", context.subdir)) 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") 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 get_index( channel_urls=(), prepend=True, platform=None, use_local=False, use_cache=False, unknown=None, prefix=None, repodata_fn="repodata.json", ): """Get an index? Function from @wolfv here: https://gist.github.com/wolfv/cd12bd4a448c77ff02368e97ffdf495a. """ real_urls = calculate_channel_urls(channel_urls, prepend, platform, use_local) check_whitelist(real_urls) dlist = api.DownloadTargetList() index = [] for idx, url in enumerate(real_urls): channel = Channel(url) full_url = channel.url(with_credentials=True) + "/" + repodata_fn full_path_cache = os.path.join( create_cache_dir(), cache_fn_url(full_url, repodata_fn), ) sd = api.SubdirData( channel.name + "/" + channel.subdir, full_url, full_path_cache, ) sd.load() index.append((sd, channel)) dlist.add(sd) is_downloaded = dlist.download(True) if not is_downloaded: raise RuntimeError("Error downloading repodata.") return index
def test_file_urls(self): url = "file:///machine/shared_folder" c = Channel(url) assert c.scheme == "file" assert c.auth is None assert c.location == "/machine" assert c.token is None assert c.name == "shared_folder" assert c.platform is None assert c.package_filename is None assert c.canonical_name == "file:///machine/shared_folder" assert c.url() == "file:///machine/shared_folder/%s" % context.subdir assert c.urls() == [ "file:///machine/shared_folder/%s" % context.subdir, "file:///machine/shared_folder/noarch", ]
def test_file_url_with_backslashes(self): url = "file://\\machine\\shared_folder\\path\\conda" c = Channel(url) assert c.scheme == "file" assert c.auth is None assert c.location == "/machine/shared_folder/path" assert c.token is None assert c.name == "conda" assert c.platform is None assert c.package_filename is None assert c.canonical_name == "file:///machine/shared_folder/path/conda" assert c.url() == "file:///machine/shared_folder/path/conda/%s" % context.subdir assert c.urls() == [ "file:///machine/shared_folder/path/conda/%s" % context.subdir, "file:///machine/shared_folder/path/conda/noarch", ]
def test_package_info(self): index_json_record = IndexRecord(build=0, build_number=0, name="test_foo", version=0, channel='defaults', subdir=context.subdir, fn='doesnt-matter', md5='0123456789') icondata = "icondata" package_metadata = PackageMetadata( package_metadata_version=1, noarch=Noarch(type="python", entry_points=["test:foo"]), ) paths = [ PathData( _path="test/path/1", file_mode=FileMode.text, path_type=PathType.hardlink, prefix_placeholder="/opt/anaconda1anaconda2anaconda3", ), PathData(_path="test/path/2", no_link=True, path_type=PathType.hardlink), PathData(_path="test/path/3", path_type=PathType.softlink), PathData(_path="menu/test.json", path_type=PathType.hardlink) ] paths_data = PathsData(paths_version=0, paths=paths) package_info = PackageInfo( extracted_package_dir='/some/path', channel=Channel('defaults'), repodata_record=index_json_record, url='https://some.com/place/file.tar.bz2', index_json_record=index_json_record, icondata=icondata, package_metadata=package_metadata, paths_data=paths_data, ) self.assertIsInstance(package_info.paths_data.paths[0], PathData) self.assertIsInstance(package_info.index_json_record, IndexRecord) self.assertIsInstance(package_info.package_metadata.noarch, Noarch) assert package_info.paths_data.paths[0].path == "test/path/1"
def __init__(self, fn, info): self.fn = fn self.name = info.get('name') self.version = info.get('version') self.build = info.get('build') self.build_number = info.get('build_number') self.channel = info.get('channel') self.schannel = info.get('schannel') self.priority = info.get('priority', None) if self.schannel is None: self.schannel = Channel(self.channel).canonical_name try: self.norm_version = normalized_version(self.version) except ValueError: stderrlog.error("\nThe following stack trace is in reference to " "package:\n\n\t%s\n\n" % fn) raise self.info = info
def test_normalize_urls(self): context = reset_context([join(dirname(__file__), 'condarc')]) current_platform = context.subdir assert DEFAULT_CHANNEL_ALIAS == 'https://conda.anaconda.org' assert context.channel_alias == Channel('https://your.repo/') # assert binstar.channel_prefix(False) == 'https://your.repo/' # assert binstar.binstar_domain == 'https://mybinstar.com/' # assert binstar.binstar_domain_tok == 'https://mybinstar.com/t/01234abcde/' assert context.channels == ("binstar_username", "http://some.custom/channel", "defaults") channel_urls = [ 'defaults', 'system', 'https://conda.anaconda.org/username', 'file:///Users/username/repo', 'https://mybinstar.com/t/5768wxyz/test2', 'https://mybinstar.com/test', 'https://conda.anaconda.org/t/abcdefgh/username', 'username' ] platform = 'osx-64'
def install(prefix, specs, args, env, *_, **kwargs): # TODO: support all various ways this happens # Including 'nodefaults' in the channels list disables the defaults channel_urls = [chan for chan in env.channels if chan != 'nodefaults'] if 'nodefaults' not in env.channels: channel_urls.extend(context.channels) _channel_priority_map = prioritize_channels(channel_urls) channels = IndexedSet(Channel(url) for url in _channel_priority_map) subdirs = IndexedSet(basename(url) for url in _channel_priority_map) solver = Solver(prefix, channels, subdirs, specs_to_add=specs) unlink_link_transaction = solver.solve_for_transaction( prune=getattr(args, 'prune', False)) pfe = unlink_link_transaction._get_pfe() pfe.execute() unlink_link_transaction.execute()
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( channel_urls=(), prepend=True, platform=None, use_local=False, use_cache=False, unknown=None, prefix=None, repodata_fn="repodata.json", ): real_urls = calculate_channel_urls(channel_urls, prepend, platform, use_local) check_whitelist(real_urls) dlist = api.DownloadTargetList() index = [] for url in real_urls: channel = Channel(url) full_url = CondaHttpAuth.add_binstar_token( channel.url(with_credentials=True) + "/" + repodata_fn ) full_path_cache = os.path.join( api.create_cache_dir(), api.cache_fn_url(full_url) ) if channel.name: channel_name = channel.name + "/" + channel.subdir else: channel_name = channel.url(with_credentials=False) sd = api.SubdirData(channel_name, full_url, full_path_cache) sd.load() index.append((sd, channel)) dlist.add(sd) is_downloaded = dlist.download(True) if not is_downloaded: raise RuntimeError("Error downloading repodata.") return index
def test_canonical_name(self): assert Channel( 'https://repo.continuum.io/pkgs/free').canonical_name == "defaults" assert Channel('http://repo.continuum.io/pkgs/free/linux-64' ).canonical_name == "defaults" assert Channel( 'https://conda.anaconda.org/bioconda').canonical_name == "bioconda" assert Channel('http://conda.anaconda.org/bioconda/win-64' ).canonical_name == "bioconda" assert Channel('http://conda.anaconda.org/bioconda/label/main/osx-64' ).canonical_name == "bioconda/label/main" assert Channel( 'http://conda.anaconda.org/t/tk-abc-123-456/bioconda/win-64' ).canonical_name == "bioconda"
def test_url_custom_channel_w_subchan(self): channel = Channel( "http://another.url:8080/with/path/chuck/subchan/label/main") assert channel.canonical_name == "chuck/subchan/label/main" assert channel.location == "another.url:8080/with/path" assert channel.url( ) == "http://another.url:8080/with/path/chuck/subchan/label/main/%s" % self.platform assert channel.url( True ) == "http://*****:*****@another.url:8080/with/path/t/tk-1234/chuck/subchan/label/main/%s" % self.platform assert channel.urls() == [ "http://another.url:8080/with/path/chuck/subchan/label/main/%s" % self.platform, "http://another.url:8080/with/path/chuck/subchan/label/main/noarch", ] assert channel.urls(True) == [ "http://*****:*****@another.url:8080/with/path/t/tk-1234/chuck/subchan/label/main/%s" % self.platform, "http://*****:*****@another.url:8080/with/path/t/tk-1234/chuck/subchan/label/main/noarch", ]
def test_default_channel(self): dc = Channel('defaults') assert isinstance(dc, DefaultChannel) platform = context.subdir assert dc.base_url == 'https://conda.anaconda.org/defaults' assert dc.canonical_name == 'defaults' expected_urls = ['https://repo.continuum.io/pkgs/free/%s/' % platform, 'https://repo.continuum.io/pkgs/free/noarch/', 'https://repo.continuum.io/pkgs/pro/%s/' % platform, 'https://repo.continuum.io/pkgs/pro/noarch/'] if on_win: expected_urls.extend(['https://repo.continuum.io/pkgs/msys2/%s/' % platform, 'https://repo.continuum.io/pkgs/msys2/noarch/']) assert dc.urls == expected_urls assert dc._scheme == "https" assert dc._netloc == "conda.anaconda.org" assert dc._path == "/defaults" assert dc._platform is None
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, } index = {} channel = Channel('defaults') supplement_index_with_repodata(index, repodata, channel, 1) add_feature_records(index) index = frozendict(index) r = Resolve(index) index = r.index return index, r
def get_index( channel_urls=(), prepend=True, platform=None, use_local=False, use_cache=False, unknown=None, prefix=None, repodata_fn="repodata.json", ): real_urls = calculate_channel_urls(channel_urls, prepend, platform, use_local) check_whitelist(real_urls) dlist = mamba_api.DownloadTargetList() index = [] for idx, url in enumerate(real_urls): channel = Channel(url) full_url = channel.url(with_credentials=True) + "/" + repodata_fn full_path_cache = os.path.join(create_cache_dir(), cache_fn_url(full_url, repodata_fn)) # Channels might not have a name. if channel.name is None: name_and_subdir = channel.subdir else: name_and_subdir = channel.name + "/" + channel.subdir sd = mamba_api.SubdirData(name_and_subdir, full_url, full_path_cache) sd.load() index.append((sd, channel)) dlist.add(sd) is_downloaded = dlist.download(True) if not is_downloaded: raise RuntimeError("Error downloading repodata.") return index
def test_dist(self): with env_unmodified(conda_tests_ctxt_mgmt_def_pol): dst = Dist('defaults::foo-1.2.3-4.tar.bz2') a = MatchSpec(dst) b = MatchSpec(a) c = MatchSpec(dst, optional=True, target='burg') d = MatchSpec(a, build='5') assert a == b assert hash(a) == hash(b) assert a is b assert a != c assert hash(a) != hash(c) assert a != d assert hash(a) != hash(d) p = MatchSpec(channel='defaults',name='python',version=VersionSpec('3.5*')) assert p.match(Dist(channel='defaults', dist_name='python-3.5.3-1', name='python', version='3.5.3', build_string='1', build_number=1, base_url=None, platform=None)) assert not p.match(Dist(channel='defaults', dist_name='python-3.6.0-0', name='python', version='3.6.0', build_string='0', build_number=0, base_url=None, platform=None)) assert p.match(Dist(channel='defaults', dist_name='python-3.5.1-0', name='python', version='3.5.1', build_string='0', build_number=0, base_url=None, platform=None)) assert p.match(PackageRecord(name='python', version='3.5.1', build='0', build_number=0, depends=('openssl 1.0.2*', 'readline 6.2*', 'sqlite', 'tk 8.5*', 'xz 5.0.5', 'zlib 1.2*', 'pip'), channel=Channel(scheme='https', auth=None, location='repo.anaconda.com', token=None, name='pkgs/main', platform='osx-64', package_filename=None), subdir='osx-64', fn='python-3.5.1-0.tar.bz2', md5='a813bc0a32691ab3331ac9f37125164c', size=14678857, priority=0, url='https://repo.anaconda.com/pkgs/main/osx-64/python-3.5.1-0.tar.bz2'))
def test_prefix_record_no_channel(self): pr = PrefixRecord( name='austin', version='1.2.3', build_string='py34_2', build_number=2, url= "https://repo.continuum.io/pkgs/free/win-32/austin-1.2.3-py34_2.tar.bz2", subdir="win-32", md5='0123456789', files=(), ) assert pr.channel.canonical_name == 'defaults' assert pr.subdir == "win-32" assert pr.fn == "austin-1.2.3-py34_2.tar.bz2" channel_str = text_type( Channel( "https://repo.continuum.io/pkgs/free/win-32/austin-1.2.3-py34_2.tar.bz2" )) assert channel_str == "https://repo.continuum.io/pkgs/free" assert dict(pr.dump()) == dict( name='austin', version='1.2.3', build='py34_2', build_number=2, url= "https://repo.continuum.io/pkgs/free/win-32/austin-1.2.3-py34_2.tar.bz2", md5='0123456789', files=(), channel=channel_str, subdir="win-32", fn="austin-1.2.3-py34_2.tar.bz2", auth=None, constrains=(), depends=(), noarch=None, preferred_env=None, arch=None, platform=None, )
def get_index(channel_urls=(), prepend=True, platform=None, use_local=False, use_cache=False, unknown=None, prefix=None): channel_urls = calculate_channel_urls(channel_urls, prepend, platform, use_local) check_whitelist(channel_urls) threads = [] result = [] sddata = [FastSubdirData(Channel(x)) for x in channel_urls] for sd in sddata: t = threading.Thread(target=load_channel, args=(sd, result)) threads.append(t) t.start() for t in threads: t.join() return result
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 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 get_index(channel_urls=(), prepend=True, platform=None, use_local=False, use_cache=False, unknown=None, prefix=None, repodata_fn="repodata.json"): real_urls = calculate_channel_urls(channel_urls, prepend, platform, use_local) check_whitelist(real_urls) dlist = api.DownloadTargetList() sddata = [] index = [] for idx, url in enumerate(real_urls): channel = Channel(url) full_url = channel.url(with_credentials=True) + '/' + repodata_fn full_path_cache = os.path.join(api.create_cache_dir(), api.cache_fn_url(full_url)) sd = api.SubdirData(channel.name + '/' + channel.subdir, full_url, full_path_cache) sd.load() index.append((sd, channel)) dlist.add(sd) is_downloaded = dlist.download(True) if not is_downloaded: raise RuntimeError("Error downloading repodata.") return index