コード例 #1
0
def test_install_package_with_feature():
    index2 = index.copy()
    index2['mypackage-1.0-featurepy33_0.tar.bz2'] = Record(
        **{
            'build': 'featurepy33_0',
            'build_number': 0,
            'depends': ['python 3.3*'],
            'name': 'mypackage',
            'version': '1.0',
            'features': 'feature',
        })
    index2['feature-1.0-py33_0.tar.bz2'] = Record(
        **{
            'build': 'py33_0',
            'build_number': 0,
            'depends': ['python 3.3*'],
            'name': 'feature',
            'version': '1.0',
            'track_features': 'feature',
        })

    index2 = {Dist(key): value for key, value in iteritems(index2)}
    r = Resolve(index2)

    # It should not raise
    r.install(['mypackage', 'feature 1.0'])
コード例 #2
0
def test_circular_dependencies():
    index2 = index.copy()
    index2['package1-1.0-0.tar.bz2'] = Record(
        **{
            'build': '0',
            'build_number': 0,
            'depends': ['package2'],
            'name': 'package1',
            'requires': ['package2'],
            'version': '1.0',
        })
    index2['package2-1.0-0.tar.bz2'] = Record(
        **{
            'build': '0',
            'build_number': 0,
            'depends': ['package1'],
            'name': 'package2',
            'requires': ['package1'],
            'version': '1.0',
        })
    index2 = {Dist(key): value for key, value in iteritems(index2)}
    r = Resolve(index2)

    assert set(r.find_matches(MatchSpec('package1'))) == {
        Dist('package1-1.0-0.tar.bz2'),
    }
    assert set(r.get_reduced_index(['package1']).keys()) == {
        Dist('package1-1.0-0.tar.bz2'),
        Dist('package2-1.0-0.tar.bz2'),
    }
    assert r.install(['package1']) == r.install(['package2']) == \
        r.install(['package1', 'package2']) == [
        Dist('package1-1.0-0.tar.bz2'),
        Dist('package2-1.0-0.tar.bz2'),
    ]
コード例 #3
0
ファイル: test_resolve.py プロジェクト: wang1352083/conda
def test_channel_priority():
    fn1 = 'pandas-0.10.1-np17py27_0.tar.bz2'
    fn2 = 'other::' + fn1
    spec = ['pandas', 'python 2.7*']
    index2 = index.copy()
    index2[Dist(fn2)] = index2[Dist(fn1)].copy()
    index2 = {Dist(key): value for key, value in iteritems(index2)}
    r2 = Resolve(index2)
    rec = r2.index[Dist(fn2)]

    os.environ['CONDA_CHANNEL_PRIORITY'] = 'True'
    reset_context(())

    r2.index[Dist(fn2)] = Record.from_objects(r2.index[Dist(fn2)], priority=0)
    # Should select the "other", older package because it
    # has a lower channel priority number
    installed1 = r2.install(spec)
    # Should select the newer package because now the "other"
    # package has a higher priority number
    r2.index[Dist(fn2)] = Record.from_objects(r2.index[Dist(fn2)], priority=2)
    installed2 = r2.install(spec)
    # Should also select the newer package because we have
    # turned off channel priority altogether

    os.environ['CONDA_CHANNEL_PRIORITY'] = 'False'
    reset_context(())

    r2.index[Dist(fn2)] = Record.from_objects(r2.index[Dist(fn2)], priority=0)
    installed3 = r2.install(spec)
    assert installed1 != installed2
    assert installed1 != installed3
    assert installed2 == installed3
コード例 #4
0
    def setUp(self):
        self.dist = Dist("channel", "dist_name")
        index_json_records = Record(build=0, build_number=0, name="test_foo", version=0)
        icondata = "icondata"
        paths = [PathInfo(_path="test/path/1", file_mode=FileMode.text, path_type=PathType.hardlink,
                          prefix_placeholder="/opt/anaconda1anaconda2anaconda3", ),
                 PathInfo(_path="test/path/2", no_link=True, path_type=PathType.hardlink),
                 PathInfo(_path="test/path/3", path_type=PathType.softlink),
                 PathInfo(_path="menu/test.json", path_type=PathType.hardlink)]

        self.package_info = PackageInfo(paths_version=0, paths=paths, icondata=icondata,
                                        index_json_record=index_json_records)
コード例 #5
0
    def test_install_tarball_from_local_channel(self):
        with make_temp_env("python flask=0.10.1") as prefix:
            assert_package_is_installed(prefix, 'flask-0.10.1')
            flask_data = [
                p for p in itervalues(linked_data(prefix))
                if p['name'] == 'flask'
            ][0]
            run_command(Commands.REMOVE, prefix, 'flask')
            assert not package_is_installed(prefix, 'flask-0.10.1')
            assert_package_is_installed(prefix, 'python')

            flask_fname = flask_data['fn']
            tar_old_path = join(context.pkgs_dirs[0], flask_fname)

            # Regression test for #2812
            # install from local channel
            flask_data = flask_data.dump()
            for field in ('url', 'channel', 'schannel'):
                del flask_data[field]
            repodata = {
                'info': {},
                'packages': {
                    flask_fname: Record(**flask_data)
                }
            }
            with make_temp_env() as channel:
                subchan = join(channel, context.subdir)
                channel = path_to_url(channel)
                os.makedirs(subchan)
                tar_new_path = join(subchan, flask_fname)
                copyfile(tar_old_path, tar_new_path)
                with bz2.BZ2File(join(subchan, 'repodata.json.bz2'), 'w') as f:
                    f.write(
                        json.dumps(repodata,
                                   cls=EntityEncoder).encode('utf-8'))
                run_command(Commands.INSTALL, prefix, '-c', channel, 'flask',
                            '--json')
                assert_package_is_installed(prefix, channel + '::' + 'flask-')

                run_command(Commands.REMOVE, prefix, 'flask')
                assert not package_is_installed(prefix, 'flask-0')

                # Regression test for 2970
                # install from build channel as a tarball
                conda_bld = join(sys.prefix, 'conda-bld')
                conda_bld_sub = join(conda_bld, context.subdir)
                if not isdir(conda_bld_sub):
                    os.makedirs(conda_bld_sub)
                tar_bld_path = join(conda_bld_sub, flask_fname)
                copyfile(tar_new_path, tar_bld_path)
                # CondaFileNotFoundError: '/home/travis/virtualenv/python2.7.9/conda-bld/linux-64/flask-0.10.1-py27_2.tar.bz2'.
                run_command(Commands.INSTALL, prefix, tar_bld_path)
                assert_package_is_installed(prefix, 'flask-')
コード例 #6
0
    def test_create_meta(self):
        dest_short_paths = ["dest/path/1", "dest/path/2", "dest/path/3"]
        package_installer = PackageInstaller("prefix", {self.dist: {"icon": "icon"}}, self.dist)
        package_installer.package_info = self.package_info
        package_installer.extracted_package_dir = "extracted_package_dir"

        output = package_installer._create_meta(dest_short_paths, LinkType.directory,
                                                "http://test.url")
        expected_output = Record(icon="icon", icondata="icondata", build=0, build_number=0,
                                 name="test_foo", version=0, url="http://test.url",
                                 files=dest_short_paths,
                                 link=Link(source="extracted_package_dir", type=LinkType.directory))
        self.assertEquals(output, expected_output)
コード例 #7
0
    def test_package_info(self):
        index_json_records = Record(build=0, build_number=0, name="test_foo", version=0)
        icondata = "icondata"
        noarch = NoarchInfo(type="python", entry_points=["test:foo"])
        paths = [PathInfo(_path="test/path/1", file_mode=FileMode.text, path_type=PathType.hardlink,
                          prefix_placeholder="/opt/anaconda1anaconda2anaconda3", ),
                 PathInfo(_path="test/path/2", no_link=True, path_type=PathType.hardlink),
                 PathInfo(_path="test/path/3", path_type=PathType.softlink),
                 PathInfo(_path="menu/test.json", path_type=PathType.hardlink)]

        package_info = PackageInfo(paths_version=0, paths=paths, icondata=icondata,
                                   index_json_record=index_json_records, noarch=noarch)
        self.assertIsInstance(package_info.paths[0], PathInfo)
        self.assertIsInstance(package_info.index_json_record, Record)
        self.assertIsInstance(package_info.noarch, NoarchInfo)
        self.assertEquals(package_info.paths[0].path, "test/path/1")
コード例 #8
0
ファイル: test_resolve.py プロジェクト: wang1352083/conda
def test_broken_install():
    installed = r.install(['pandas', 'python 2.7*', 'numpy 1.6*'])
    assert installed == [
        Dist(fname) for fname in [
            'dateutil-2.1-py27_1.tar.bz2', 'numpy-1.6.2-py27_4.tar.bz2',
            'openssl-1.0.1c-0.tar.bz2', 'pandas-0.11.0-np16py27_1.tar.bz2',
            'python-2.7.5-0.tar.bz2', 'pytz-2013b-py27_0.tar.bz2',
            'readline-6.2-0.tar.bz2', 'scipy-0.12.0-np16py27_0.tar.bz2',
            'six-1.3.0-py27_0.tar.bz2', 'sqlite-3.7.13-0.tar.bz2',
            'system-5.8-1.tar.bz2', 'tk-8.5.13-0.tar.bz2',
            'zlib-1.2.7-0.tar.bz2'
        ]
    ]

    # Add a fake package and an incompatible numpy
    installed2 = list(installed)
    installed2[1] = Dist('numpy-1.7.1-py33_p0.tar.bz2')
    installed2.append(Dist('notarealpackage-2.0-0.tar.bz2'))
    assert r.install([], installed2) == installed2
    installed3 = r.install(['numpy'], installed2)
    installed4 = r.remove(['pandas'], installed2)
    assert set(installed4) == set(installed2[:3] + installed2[4:])

    # Remove the installed version of pandas from the index
    index2 = index.copy()
    d = Dist('pandas-0.11.0-np16py27_1.tar.bz2')
    index2[d] = Record.from_objects(index2[d], priority=MAX_CHANNEL_PRIORITY)
    r2 = Resolve(index2)
    installed2 = r2.install(['pandas', 'python 2.7*', 'numpy 1.6*'], installed)
    assert installed2 == [
        Dist(d) for d in [
            'dateutil-2.1-py27_1.tar.bz2', 'numpy-1.6.2-py27_4.tar.bz2',
            'openssl-1.0.1c-0.tar.bz2', 'pandas-0.10.1-np16py27_0.tar.bz2',
            'python-2.7.5-0.tar.bz2', 'pytz-2013b-py27_0.tar.bz2',
            'readline-6.2-0.tar.bz2', 'scipy-0.11.0-np16py27_3.tar.bz2',
            'six-1.3.0-py27_0.tar.bz2', 'sqlite-3.7.13-0.tar.bz2',
            'system-5.8-1.tar.bz2', 'tk-8.5.13-0.tar.bz2',
            'zlib-1.2.7-0.tar.bz2'
        ]
    ]
コード例 #9
0
ファイル: misc.py プロジェクト: nitikaraj11/conda
def explicit(specs,
             prefix,
             verbose=False,
             force_extract=True,
             index_args=None,
             index=None):
    actions = defaultdict(list)
    actions['PREFIX'] = prefix
    actions[
        'op_order'] = RM_FETCHED, FETCH, RM_EXTRACTED, EXTRACT, UNLINK, LINK, SYMLINK_CONDA
    linked = {dist.dist_name: dist for dist in install_linked(prefix)}
    index_args = index_args or {}
    index = index or {}
    verifies = []  # List[Tuple(filename, md5)]
    channels = set()
    for spec in specs:
        if spec == '@EXPLICIT':
            continue

        # Format: (url|path)(:#md5)?
        m = url_pat.match(spec)
        if m is None:
            raise ParseError('Could not parse explicit URL: %s' % spec)
        url_p, fn, md5 = m.group('url_p'), m.group('fn'), m.group('md5')
        if not is_url(url_p):
            if url_p is None:
                url_p = curdir
            elif not isdir(url_p):
                raise CondaFileNotFoundError(join(url_p, fn))
            url_p = path_to_url(url_p).rstrip('/')
        url = "{0}/{1}".format(url_p, fn)

        # is_local: if the tarball is stored locally (file://)
        # is_cache: if the tarball is sitting in our cache
        is_local = not is_url(url) or url.startswith('file://')
        prefix = cached_url(url) if is_local else None
        is_cache = prefix is not None
        if is_cache:
            # Channel information from the cache
            schannel = DEFAULTS if prefix == '' else prefix[:-2]
        else:
            # Channel information from the URL
            channel, schannel = Channel(url).url_channel_wtf
            prefix = '' if schannel == DEFAULTS else schannel + '::'

        fn = prefix + fn
        dist = Dist(fn[:-8])
        # Add explicit file to index so we'll be sure to see it later
        if is_local:
            index[dist] = Record(
                **{
                    'fn': dist.to_filename(),
                    'url': url,
                    'md5': md5,
                    'build': dist.quad[2],
                    'build_number': dist.build_number(),
                    'name': dist.quad[0],
                    'version': dist.quad[1],
                })
            verifies.append((fn, md5))

        pkg_path = is_fetched(dist)
        dir_path = is_extracted(dist)

        # Don't re-fetch unless there is an MD5 mismatch
        # Also remove explicit tarballs from cache, unless the path *is* to the cache
        if pkg_path and not is_cache and (is_local or md5
                                          and md5_file(pkg_path) != md5):
            # This removes any extracted copies as well
            actions[RM_FETCHED].append(dist)
            pkg_path = dir_path = None

        # Don't re-extract unless forced, or if we can't check the md5
        if dir_path and (force_extract or md5 and not pkg_path):
            actions[RM_EXTRACTED].append(dist)
            dir_path = None

        if not dir_path:
            if not pkg_path:
                pkg_path, conflict = find_new_location(dist)
                pkg_path = join(pkg_path, dist.to_filename())
                if conflict:
                    actions[RM_FETCHED].append(Dist(conflict))
                if not is_local:
                    if dist not in index or index[dist].get('not_fetched'):
                        channels.add(schannel)
                    verifies.append((dist.to_filename(), md5))
                actions[FETCH].append(dist)
            actions[EXTRACT].append(dist)

        # unlink any installed package with that name
        name = dist.dist_name
        if name in linked:
            actions[UNLINK].append(linked[name])

        ######################################
        # copied from conda/plan.py   TODO: refactor
        ######################################

        # check for link action
        fetched_dist = dir_path or pkg_path[:-8]
        fetched_dir = dirname(fetched_dist)
        try:
            # Determine what kind of linking is necessary
            if not dir_path:
                # If not already extracted, create some dummy
                # data to test with
                rm_rf(fetched_dist)
                ppath = join(fetched_dist, 'info')
                os.makedirs(ppath)
                index_json = join(ppath, 'index.json')
                with open(index_json, 'w'):
                    pass
            if context.always_copy:
                lt = LINK_COPY
            elif try_hard_link(fetched_dir, prefix, dist):
                lt = LINK_HARD
            elif context.allow_softlinks and not on_win:
                lt = LINK_SOFT
            else:
                lt = LINK_COPY
            actions[LINK].append('%s %d' % (dist, lt))
        except (OSError, IOError):
            actions[LINK].append('%s %d' % (dist, LINK_COPY))
        finally:
            if not dir_path:
                # Remove the dummy data
                try:
                    rm_rf(fetched_dist)
                except (OSError, IOError):
                    pass

    ######################################
    # ^^^^^^^^^^ copied from conda/plan.py
    ######################################

    # Pull the repodata for channels we are using
    if channels:
        index_args = index_args or {}
        index_args = index_args.copy()
        index_args['prepend'] = False
        index_args['channel_urls'] = list(channels)
        index.update(get_index(**index_args))

    # Finish the MD5 verification
    for fn, md5 in verifies:
        info = index.get(Dist(fn))
        if info is None:
            raise PackageNotFoundError(fn, "no package '%s' in index" % fn)
        if md5 and 'md5' not in info:
            sys.stderr.write('Warning: cannot lookup MD5 of: %s' % fn)
        if md5 and info['md5'] != md5:
            raise MD5MismatchError(
                'MD5 mismatch for: %s\n   spec: %s\n   repo: %s' %
                (fn, md5, info['md5']))

    execute_actions(actions, index=index, verbose=verbose)
    return actions
コード例 #10
0
def test_no_features():
    # Without this, there would be another solution including 'scipy-0.11.0-np16py26_p3.tar.bz2'.
    assert r.install(['python 2.6*', 'numpy 1.6*', 'scipy 0.11*'],
                     returnall=True) == [[
                         Dist(fname) for fname in [
                             'numpy-1.6.2-py26_4.tar.bz2',
                             'openssl-1.0.1c-0.tar.bz2',
                             'python-2.6.8-6.tar.bz2',
                             'readline-6.2-0.tar.bz2',
                             'scipy-0.11.0-np16py26_3.tar.bz2',
                             'sqlite-3.7.13-0.tar.bz2',
                             'system-5.8-1.tar.bz2',
                             'tk-8.5.13-0.tar.bz2',
                             'zlib-1.2.7-0.tar.bz2',
                         ]
                     ]]

    assert r.install(
        ['python 2.6*', 'numpy 1.6*', 'scipy 0.11*', 'mkl@'],
        returnall=True) == [[
            Dist(fname) for fname in [
                'mkl-rt-11.0-p0.tar.bz2',  # This,
                'numpy-1.6.2-py26_p4.tar.bz2',  # this,
                'openssl-1.0.1c-0.tar.bz2',
                'python-2.6.8-6.tar.bz2',
                'readline-6.2-0.tar.bz2',
                'scipy-0.11.0-np16py26_p3.tar.bz2',  # and this are different.
                'sqlite-3.7.13-0.tar.bz2',
                'system-5.8-1.tar.bz2',
                'tk-8.5.13-0.tar.bz2',
                'zlib-1.2.7-0.tar.bz2',
            ]
        ]]

    index2 = index.copy()
    index2["pandas-0.12.0-np16py27_0.tar.bz2"] = Record(
        **{
            "build": "np16py27_0",
            "build_number": 0,
            "depends": ["dateutil", "numpy 1.6*", "python 2.7*", "pytz"],
            "name": "pandas",
            "requires": ["dateutil 1.5", "numpy 1.6", "python 2.7", "pytz"],
            "version": "0.12.0"
        })
    # Make it want to choose the pro version by having it be newer.
    index2["numpy-1.6.2-py27_p5.tar.bz2"] = Record(
        **{
            "build": "py27_p5",
            "build_number": 5,
            "depends": ["mkl-rt 11.0", "python 2.7*"],
            "features": "mkl",
            "name": "numpy",
            "pub_date": "2013-04-29",
            "requires": ["mkl-rt 11.0", "python 2.7"],
            "version": "1.6.2"
        })

    index2 = {Dist(key): value for key, value in iteritems(index2)}
    r2 = Resolve(index2)

    # This should not pick any mkl packages (the difference here is that none
    # of the specs directly have mkl versions)
    assert r2.solve(['pandas 0.12.0 np16py27_0', 'python 2.7*'],
                    returnall=True) == [[
                        Dist(fname) for fname in [
                            'dateutil-2.1-py27_1.tar.bz2',
                            'numpy-1.6.2-py27_4.tar.bz2',
                            'openssl-1.0.1c-0.tar.bz2',
                            'pandas-0.12.0-np16py27_0.tar.bz2',
                            'python-2.7.5-0.tar.bz2',
                            'pytz-2013b-py27_0.tar.bz2',
                            'readline-6.2-0.tar.bz2',
                            'six-1.3.0-py27_0.tar.bz2',
                            'sqlite-3.7.13-0.tar.bz2',
                            'system-5.8-1.tar.bz2',
                            'tk-8.5.13-0.tar.bz2',
                            'zlib-1.2.7-0.tar.bz2',
                        ]
                    ]]

    assert r2.solve(
        ['pandas 0.12.0 np16py27_0', 'python 2.7*', 'mkl@'],
        returnall=True)[0] == [[
            Dist(fname) for fname in [
                'dateutil-2.1-py27_1.tar.bz2',
                'mkl-rt-11.0-p0.tar.bz2',  # This
                'numpy-1.6.2-py27_p5.tar.bz2',  # and this are different.
                'openssl-1.0.1c-0.tar.bz2',
                'pandas-0.12.0-np16py27_0.tar.bz2',
                'python-2.7.5-0.tar.bz2',
                'pytz-2013b-py27_0.tar.bz2',
                'readline-6.2-0.tar.bz2',
                'six-1.3.0-py27_0.tar.bz2',
                'sqlite-3.7.13-0.tar.bz2',
                'system-5.8-1.tar.bz2',
                'tk-8.5.13-0.tar.bz2',
                'zlib-1.2.7-0.tar.bz2',
            ]
        ]][0]
コード例 #11
0
def test_nonexistent_deps():
    index2 = index.copy()
    index2['mypackage-1.0-py33_0.tar.bz2'] = Record(
        **{
            'build': 'py33_0',
            'build_number': 0,
            'depends': ['nose', 'python 3.3*', 'notarealpackage 2.0*'],
            'name': 'mypackage',
            'requires': ['nose 1.2.1', 'python 3.3'],
            'version': '1.0',
        })
    index2['mypackage-1.1-py33_0.tar.bz2'] = Record(
        **{
            'build': 'py33_0',
            'build_number': 0,
            'depends': ['nose', 'python 3.3*'],
            'name': 'mypackage',
            'requires': ['nose 1.2.1', 'python 3.3'],
            'version': '1.1',
        })
    index2['anotherpackage-1.0-py33_0.tar.bz2'] = Record(
        **{
            'build': 'py33_0',
            'build_number': 0,
            'depends': ['nose', 'mypackage 1.1'],
            'name': 'anotherpackage',
            'requires': ['nose', 'mypackage 1.1'],
            'version': '1.0',
        })
    index2['anotherpackage-2.0-py33_0.tar.bz2'] = Record(
        **{
            'build': 'py33_0',
            'build_number': 0,
            'depends': ['nose', 'mypackage'],
            'name': 'anotherpackage',
            'requires': ['nose', 'mypackage'],
            'version': '2.0',
        })
    index2 = {Dist(key): value for key, value in iteritems(index2)}
    r = Resolve(index2)

    assert set(r.find_matches(MatchSpec('mypackage'))) == {
        Dist('mypackage-1.0-py33_0.tar.bz2'),
        Dist('mypackage-1.1-py33_0.tar.bz2'),
    }
    assert set(d.to_filename()
               for d in r.get_reduced_index(['mypackage']).keys()) == {
                   'mypackage-1.1-py33_0.tar.bz2', 'nose-1.1.2-py33_0.tar.bz2',
                   'nose-1.2.1-py33_0.tar.bz2', 'nose-1.3.0-py33_0.tar.bz2',
                   'openssl-1.0.1c-0.tar.bz2', 'python-3.3.0-2.tar.bz2',
                   'python-3.3.0-3.tar.bz2', 'python-3.3.0-4.tar.bz2',
                   'python-3.3.0-pro0.tar.bz2', 'python-3.3.0-pro1.tar.bz2',
                   'python-3.3.1-0.tar.bz2', 'python-3.3.2-0.tar.bz2',
                   'readline-6.2-0.tar.bz2', 'sqlite-3.7.13-0.tar.bz2',
                   'system-5.8-0.tar.bz2', 'system-5.8-1.tar.bz2',
                   'tk-8.5.13-0.tar.bz2', 'zlib-1.2.7-0.tar.bz2'
               }

    assert r.install(['mypackage']) == r.install(['mypackage 1.1']) == [
        Dist(dname) for dname in [
            'mypackage-1.1-py33_0.tar.bz2',
            'nose-1.3.0-py33_0.tar.bz2',
            'openssl-1.0.1c-0.tar.bz2',
            'python-3.3.2-0.tar.bz2',
            'readline-6.2-0.tar.bz2',
            'sqlite-3.7.13-0.tar.bz2',
            'system-5.8-1.tar.bz2',
            'tk-8.5.13-0.tar.bz2',
            'zlib-1.2.7-0.tar.bz2',
        ]
    ]
    assert raises(NoPackagesFoundError, lambda: r.install(['mypackage 1.0']))
    assert raises(NoPackagesFoundError,
                  lambda: r.install(['mypackage 1.0', 'burgertime 1.0']))

    assert r.install(['anotherpackage 1.0']) == [
        Dist(dname) for dname in [
            'anotherpackage-1.0-py33_0.tar.bz2',
            'mypackage-1.1-py33_0.tar.bz2',
            'nose-1.3.0-py33_0.tar.bz2',
            'openssl-1.0.1c-0.tar.bz2',
            'python-3.3.2-0.tar.bz2',
            'readline-6.2-0.tar.bz2',
            'sqlite-3.7.13-0.tar.bz2',
            'system-5.8-1.tar.bz2',
            'tk-8.5.13-0.tar.bz2',
            'zlib-1.2.7-0.tar.bz2',
        ]
    ]

    assert r.install(['anotherpackage']) == [
        Dist(dname) for dname in [
            'anotherpackage-2.0-py33_0.tar.bz2',
            'mypackage-1.1-py33_0.tar.bz2',
            'nose-1.3.0-py33_0.tar.bz2',
            'openssl-1.0.1c-0.tar.bz2',
            'python-3.3.2-0.tar.bz2',
            'readline-6.2-0.tar.bz2',
            'sqlite-3.7.13-0.tar.bz2',
            'system-5.8-1.tar.bz2',
            'tk-8.5.13-0.tar.bz2',
            'zlib-1.2.7-0.tar.bz2',
        ]
    ]

    # This time, the latest version is messed up
    index3 = index.copy()
    index3['mypackage-1.1-py33_0.tar.bz2'] = Record(
        **{
            'build': 'py33_0',
            'build_number': 0,
            'depends': ['nose', 'python 3.3*', 'notarealpackage 2.0*'],
            'name': 'mypackage',
            'requires': ['nose 1.2.1', 'python 3.3'],
            'version': '1.1',
        })
    index3['mypackage-1.0-py33_0.tar.bz2'] = Record(
        **{
            'build': 'py33_0',
            'build_number': 0,
            'depends': ['nose', 'python 3.3*'],
            'name': 'mypackage',
            'requires': ['nose 1.2.1', 'python 3.3'],
            'version': '1.0',
        })
    index3['anotherpackage-1.0-py33_0.tar.bz2'] = Record(
        **{
            'build': 'py33_0',
            'build_number': 0,
            'depends': ['nose', 'mypackage 1.0'],
            'name': 'anotherpackage',
            'requires': ['nose', 'mypackage 1.0'],
            'version': '1.0',
        })
    index3['anotherpackage-2.0-py33_0.tar.bz2'] = Record(
        **{
            'build': 'py33_0',
            'build_number': 0,
            'depends': ['nose', 'mypackage'],
            'name': 'anotherpackage',
            'requires': ['nose', 'mypackage'],
            'version': '2.0',
        })
    index3 = {Dist(key): value for key, value in iteritems(index3)}
    r = Resolve(index3)

    assert set(d.to_filename()
               for d in r.find_matches(MatchSpec('mypackage'))) == {
                   'mypackage-1.0-py33_0.tar.bz2',
                   'mypackage-1.1-py33_0.tar.bz2',
               }
    assert set(d.to_filename()
               for d in r.get_reduced_index(['mypackage']).keys()) == {
                   'mypackage-1.0-py33_0.tar.bz2', 'nose-1.1.2-py33_0.tar.bz2',
                   'nose-1.2.1-py33_0.tar.bz2', 'nose-1.3.0-py33_0.tar.bz2',
                   'openssl-1.0.1c-0.tar.bz2', 'python-3.3.0-2.tar.bz2',
                   'python-3.3.0-3.tar.bz2', 'python-3.3.0-4.tar.bz2',
                   'python-3.3.0-pro0.tar.bz2', 'python-3.3.0-pro1.tar.bz2',
                   'python-3.3.1-0.tar.bz2', 'python-3.3.2-0.tar.bz2',
                   'readline-6.2-0.tar.bz2', 'sqlite-3.7.13-0.tar.bz2',
                   'system-5.8-0.tar.bz2', 'system-5.8-1.tar.bz2',
                   'tk-8.5.13-0.tar.bz2', 'zlib-1.2.7-0.tar.bz2'
               }

    assert r.install(['mypackage']) == r.install(['mypackage 1.0']) == [
        Dist(dname) for dname in [
            'mypackage-1.0-py33_0.tar.bz2',
            'nose-1.3.0-py33_0.tar.bz2',
            'openssl-1.0.1c-0.tar.bz2',
            'python-3.3.2-0.tar.bz2',
            'readline-6.2-0.tar.bz2',
            'sqlite-3.7.13-0.tar.bz2',
            'system-5.8-1.tar.bz2',
            'tk-8.5.13-0.tar.bz2',
            'zlib-1.2.7-0.tar.bz2',
        ]
    ]
    assert raises(NoPackagesFoundError, lambda: r.install(['mypackage 1.1']))

    assert r.install(['anotherpackage 1.0']) == [
        Dist(dname) for dname in [
            'anotherpackage-1.0-py33_0.tar.bz2',
            'mypackage-1.0-py33_0.tar.bz2',
            'nose-1.3.0-py33_0.tar.bz2',
            'openssl-1.0.1c-0.tar.bz2',
            'python-3.3.2-0.tar.bz2',
            'readline-6.2-0.tar.bz2',
            'sqlite-3.7.13-0.tar.bz2',
            'system-5.8-1.tar.bz2',
            'tk-8.5.13-0.tar.bz2',
            'zlib-1.2.7-0.tar.bz2',
        ]
    ]

    # If recursive checking is working correctly, this will give
    # anotherpackage 2.0, not anotherpackage 1.0
    assert r.install(['anotherpackage']) == [
        Dist(dname) for dname in [
            'anotherpackage-2.0-py33_0.tar.bz2',
            'mypackage-1.0-py33_0.tar.bz2',
            'nose-1.3.0-py33_0.tar.bz2',
            'openssl-1.0.1c-0.tar.bz2',
            'python-3.3.2-0.tar.bz2',
            'readline-6.2-0.tar.bz2',
            'sqlite-3.7.13-0.tar.bz2',
            'system-5.8-1.tar.bz2',
            'tk-8.5.13-0.tar.bz2',
            'zlib-1.2.7-0.tar.bz2',
        ]
    ]
コード例 #12
0
from conda.base.context import reset_context
from conda.common.compat import iteritems, text_type
from conda.exceptions import NoPackagesFoundError, UnsatisfiableError
from conda.models.dist import Dist
from conda.models.record import Record
from conda.resolve import MatchSpec, Package, Resolve
from os.path import dirname, join

import pytest

from conda.resolve import MatchSpec, Package, Resolve, NoPackagesFound, Unsatisfiable
from tests.helpers import raises

with open(join(dirname(__file__), 'index.json')) as fi:
    index = {
        Dist(key): Record(**value)
        for key, value in iteritems(json.load(fi))
    }

r = Resolve(index)

f_mkl = set(['mkl'])


class TestMatchSpec(unittest.TestCase):
    def test_match(self):
        for spec, res in [
            ('numpy 1.7*', True),
            ('numpy 1.7.1', True),
            ('numpy 1.7', False),
            ('numpy 1.5*', False),
コード例 #13
0
import conda.plan as plan
import conda.instructions as inst
from conda.plan import display_actions
from conda.resolve import Resolve
from conda.utils import on_win
from conda.common.compat import iteritems

# FIXME This should be a relative import
from tests.helpers import captured
from conda import CondaError

from .decorators import skip_if_no_mock
from .helpers import mock

with open(join(dirname(__file__), 'index.json')) as fi:
    index = {Dist(k): Record(**v) for k, v in iteritems(json.load(fi))}
    r = Resolve(index)


def solve(specs):
    return [Dist.from_string(fn) for fn in r.solve(specs)]


class TestMisc(unittest.TestCase):
    def test_split_linkarg(self):
        for arg, res in [('w3-1.2-0', ('w3-1.2-0', LINK_HARD)),
                         ('w3-1.2-0 1', ('w3-1.2-0', 1)),
                         ('w3-1.2-0 1 True', ('w3-1.2-0', 1))]:
            self.assertEqual(inst.split_linkarg(arg), res)

コード例 #14
0
ファイル: test_plan.py プロジェクト: wang1352083/conda
def test_display_actions_link_type():
    os.environ['CONDA_SHOW_CHANNEL_URLS'] = 'False'
    reset_context(())

    actions = defaultdict(
        list, {
            'LINK': [
                'cython-0.19.1-py33_0 2', 'dateutil-1.5-py33_0 2',
                'numpy-1.7.1-py33_0 2', 'python-3.3.2-0 2', 'readline-6.2-0 2',
                'sqlite-3.7.13-0 2', 'tk-8.5.13-0 2', 'zlib-1.2.7-0 2'
            ]
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following NEW packages will be INSTALLED:

    cython:   0.19.1-py33_0 (softlink)
    dateutil: 1.5-py33_0    (softlink)
    numpy:    1.7.1-py33_0  (softlink)
    python:   3.3.2-0       (softlink)
    readline: 6.2-0         (softlink)
    sqlite:   3.7.13-0      (softlink)
    tk:       8.5.13-0      (softlink)
    zlib:     1.2.7-0       (softlink)

"""

    actions = defaultdict(
        list, {
            'LINK': ['cython-0.19.1-py33_0 2', 'dateutil-2.1-py33_1 2'],
            'UNLINK': ['cython-0.19-py33_0', 'dateutil-1.5-py33_0']
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following packages will be UPDATED:

    cython:   0.19-py33_0 --> 0.19.1-py33_0 (softlink)
    dateutil: 1.5-py33_0  --> 2.1-py33_1    (softlink)

"""

    actions = defaultdict(
        list, {
            'LINK': ['cython-0.19-py33_0 2', 'dateutil-1.5-py33_0 2'],
            'UNLINK': ['cython-0.19.1-py33_0', 'dateutil-2.1-py33_1']
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following packages will be DOWNGRADED due to dependency conflicts:

    cython:   0.19.1-py33_0 --> 0.19-py33_0 (softlink)
    dateutil: 2.1-py33_1    --> 1.5-py33_0  (softlink)

"""

    actions = defaultdict(
        list, {
            'LINK': [
                'cython-0.19.1-py33_0 1', 'dateutil-1.5-py33_0 1',
                'numpy-1.7.1-py33_0 1', 'python-3.3.2-0 1', 'readline-6.2-0 1',
                'sqlite-3.7.13-0 1', 'tk-8.5.13-0 1', 'zlib-1.2.7-0 1'
            ]
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following NEW packages will be INSTALLED:

    cython:   0.19.1-py33_0
    dateutil: 1.5-py33_0   \n\
    numpy:    1.7.1-py33_0 \n\
    python:   3.3.2-0      \n\
    readline: 6.2-0        \n\
    sqlite:   3.7.13-0     \n\
    tk:       8.5.13-0     \n\
    zlib:     1.2.7-0      \n\

"""

    actions = defaultdict(
        list, {
            'LINK': ['cython-0.19.1-py33_0 1', 'dateutil-2.1-py33_1 1'],
            'UNLINK': ['cython-0.19-py33_0', 'dateutil-1.5-py33_0']
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following packages will be UPDATED:

    cython:   0.19-py33_0 --> 0.19.1-py33_0
    dateutil: 1.5-py33_0  --> 2.1-py33_1   \n\

"""

    actions = defaultdict(
        list, {
            'LINK': ['cython-0.19-py33_0 1', 'dateutil-1.5-py33_0 1'],
            'UNLINK': ['cython-0.19.1-py33_0', 'dateutil-2.1-py33_1']
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following packages will be DOWNGRADED due to dependency conflicts:

    cython:   0.19.1-py33_0 --> 0.19-py33_0
    dateutil: 2.1-py33_1    --> 1.5-py33_0 \n\

"""

    actions = defaultdict(
        list, {
            'LINK': [
                'cython-0.19.1-py33_0 3', 'dateutil-1.5-py33_0 3',
                'numpy-1.7.1-py33_0 3', 'python-3.3.2-0 3', 'readline-6.2-0 3',
                'sqlite-3.7.13-0 3', 'tk-8.5.13-0 3', 'zlib-1.2.7-0 3'
            ]
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following NEW packages will be INSTALLED:

    cython:   0.19.1-py33_0 (copy)
    dateutil: 1.5-py33_0    (copy)
    numpy:    1.7.1-py33_0  (copy)
    python:   3.3.2-0       (copy)
    readline: 6.2-0         (copy)
    sqlite:   3.7.13-0      (copy)
    tk:       8.5.13-0      (copy)
    zlib:     1.2.7-0       (copy)

"""

    actions = defaultdict(
        list, {
            'LINK': ['cython-0.19.1-py33_0 3', 'dateutil-2.1-py33_1 3'],
            'UNLINK': ['cython-0.19-py33_0', 'dateutil-1.5-py33_0']
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following packages will be UPDATED:

    cython:   0.19-py33_0 --> 0.19.1-py33_0 (copy)
    dateutil: 1.5-py33_0  --> 2.1-py33_1    (copy)

"""

    actions = defaultdict(
        list, {
            'LINK': ['cython-0.19-py33_0 3', 'dateutil-1.5-py33_0 3'],
            'UNLINK': ['cython-0.19.1-py33_0', 'dateutil-2.1-py33_1']
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following packages will be DOWNGRADED due to dependency conflicts:

    cython:   0.19.1-py33_0 --> 0.19-py33_0 (copy)
    dateutil: 2.1-py33_1    --> 1.5-py33_0  (copy)

"""
    os.environ['CONDA_SHOW_CHANNEL_URLS'] = 'True'
    reset_context(())

    d = Dist('cython-0.19.1-py33_0.tar.bz2')
    index[d] = Record.from_objects(index[d], channel='my_channel')

    d = Dist('dateutil-1.5-py33_0.tar.bz2')
    index[d] = Record.from_objects(index[d], channel='my_channel')

    actions = defaultdict(
        list, {
            'LINK': [
                'cython-0.19.1-py33_0 3', 'dateutil-1.5-py33_0 3',
                'numpy-1.7.1-py33_0 3', 'python-3.3.2-0 3', 'readline-6.2-0 3',
                'sqlite-3.7.13-0 3', 'tk-8.5.13-0 3', 'zlib-1.2.7-0 3'
            ]
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following NEW packages will be INSTALLED:

    cython:   0.19.1-py33_0 my_channel (copy)
    dateutil: 1.5-py33_0    my_channel (copy)
    numpy:    1.7.1-py33_0  <unknown>  (copy)
    python:   3.3.2-0       <unknown>  (copy)
    readline: 6.2-0         <unknown>  (copy)
    sqlite:   3.7.13-0      <unknown>  (copy)
    tk:       8.5.13-0      <unknown>  (copy)
    zlib:     1.2.7-0       <unknown>  (copy)

"""

    actions = defaultdict(
        list, {
            'LINK': ['cython-0.19.1-py33_0 3', 'dateutil-2.1-py33_1 3'],
            'UNLINK': ['cython-0.19-py33_0', 'dateutil-1.5-py33_0']
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following packages will be UPDATED:

    cython:   0.19-py33_0 <unknown>  --> 0.19.1-py33_0 my_channel (copy)
    dateutil: 1.5-py33_0  my_channel --> 2.1-py33_1    <unknown>  (copy)

"""

    actions = defaultdict(
        list, {
            'LINK': ['cython-0.19-py33_0 3', 'dateutil-1.5-py33_0 3'],
            'UNLINK': ['cython-0.19.1-py33_0', 'dateutil-2.1-py33_1']
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
コード例 #15
0
ファイル: test_plan.py プロジェクト: wang1352083/conda
def test_display_actions_show_channel_urls():
    os.environ['CONDA_SHOW_CHANNEL_URLS'] = 'True'
    reset_context(())
    actions = defaultdict(
        list, {"FETCH": ['sympy-0.7.2-py27_0', "numpy-1.7.1-py27_0"]})
    # The older test index doesn't have the size metadata
    d = Dist('sympy-0.7.2-py27_0.tar.bz2')
    index[d] = Record.from_objects(d, size=4374752)
    d = Dist('numpy-1.7.1-py27_0.tar.bz2')
    index[d] = Record.from_objects(d, size=5994338)

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following packages will be downloaded:

    package                    |            build
    ---------------------------|-----------------
    sympy-0.7.2                |           py27_0         4.2 MB  defaults
    numpy-1.7.1                |           py27_0         5.7 MB  defaults
    ------------------------------------------------------------
                                           Total:         9.9 MB

"""

    actions = defaultdict(
        list, {
            'PREFIX':
            '/Users/aaronmeurer/anaconda/envs/test',
            'SYMLINK_CONDA': ['/Users/aaronmeurer/anaconda'],
            'LINK': [
                'python-3.3.2-0', 'readline-6.2-0 1', 'sqlite-3.7.13-0 1',
                'tk-8.5.13-0 1', 'zlib-1.2.7-0 1'
            ]
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following NEW packages will be INSTALLED:

    python:   3.3.2-0  <unknown>
    readline: 6.2-0    <unknown>
    sqlite:   3.7.13-0 <unknown>
    tk:       8.5.13-0 <unknown>
    zlib:     1.2.7-0  <unknown>

"""

    actions['UNLINK'] = actions['LINK']
    actions['LINK'] = []

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following packages will be REMOVED:

    python:   3.3.2-0  <unknown>
    readline: 6.2-0    <unknown>
    sqlite:   3.7.13-0 <unknown>
    tk:       8.5.13-0 <unknown>
    zlib:     1.2.7-0  <unknown>

"""

    actions = defaultdict(list, {
        'LINK': ['cython-0.19.1-py33_0'],
        'UNLINK': ['cython-0.19-py33_0']
    })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following packages will be UPDATED:

    cython: 0.19-py33_0 <unknown> --> 0.19.1-py33_0 <unknown>

"""

    actions['LINK'], actions['UNLINK'] = actions['UNLINK'], actions['LINK']

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following packages will be DOWNGRADED due to dependency conflicts:

    cython: 0.19.1-py33_0 <unknown> --> 0.19-py33_0 <unknown>

"""

    actions = defaultdict(
        list, {
            'LINK': [
                'cython-0.19.1-py33_0', 'dateutil-1.5-py33_0',
                'numpy-1.7.1-py33_0'
            ],
            'UNLINK':
            ['cython-0.19-py33_0', 'dateutil-2.1-py33_1', 'pip-1.3.1-py33_1']
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following NEW packages will be INSTALLED:

    numpy:    1.7.1-py33_0 <unknown>

The following packages will be REMOVED:

    pip:      1.3.1-py33_1 <unknown>

The following packages will be UPDATED:

    cython:   0.19-py33_0  <unknown> --> 0.19.1-py33_0 <unknown>

The following packages will be DOWNGRADED due to dependency conflicts:

    dateutil: 2.1-py33_1   <unknown> --> 1.5-py33_0    <unknown>

"""

    actions = defaultdict(
        list, {
            'LINK': ['cython-0.19.1-py33_0', 'dateutil-2.1-py33_1'],
            'UNLINK': ['cython-0.19-py33_0', 'dateutil-1.5-py33_0']
        })

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following packages will be UPDATED:

    cython:   0.19-py33_0 <unknown> --> 0.19.1-py33_0 <unknown>
    dateutil: 1.5-py33_0  <unknown> --> 2.1-py33_1    <unknown>

"""

    actions['LINK'], actions['UNLINK'] = actions['UNLINK'], actions['LINK']

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following packages will be DOWNGRADED due to dependency conflicts:

    cython:   0.19.1-py33_0 <unknown> --> 0.19-py33_0 <unknown>
    dateutil: 2.1-py33_1    <unknown> --> 1.5-py33_0  <unknown>

"""

    actions['LINK'], actions['UNLINK'] = actions['UNLINK'], actions['LINK']

    d = Dist('cython-0.19.1-py33_0.tar.bz2')
    index[d] = Record.from_objects(d, channel='my_channel')
    d = Dist('dateutil-1.5-py33_0.tar.bz2')
    index[d] = Record.from_objects(d, channel='my_channel')

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """
The following packages will be UPDATED:

    cython:   0.19-py33_0 <unknown>  --> 0.19.1-py33_0 my_channel
    dateutil: 1.5-py33_0  my_channel --> 2.1-py33_1    <unknown> \n\

"""

    actions['LINK'], actions['UNLINK'] = actions['UNLINK'], actions['LINK']

    with captured() as c:
        display_actions(actions, index)

    assert c.stdout == """