Beispiel #1
0
    def test_get_distribution(self):
        # Test for looking up a distribution by name.
        # Test the lookup of the towel-stuff distribution
        name = 'towel-stuff'  # Note: This is different from the directory name

        d = DistributionPath()
        ed = DistributionPath(include_egg=True)

        # Lookup the distribution
        dist = d.get_distribution(name)
        self.assertIsInstance(dist, InstalledDistribution)
        self.assertEqual(dist.name, name)

        # Verify that an unknown distribution returns None
        self.assertIsNone(d.get_distribution('bogus'))

        # Verify partial name matching doesn't work
        self.assertIsNone(d.get_distribution('towel'))

        # Verify that it does not find egg-info distributions, when not
        # instructed to
        self.assertIsNone(d.get_distribution('bacon'))
        self.assertIsNone(d.get_distribution('cheese'))
        self.assertIsNone(d.get_distribution('strawberry'))
        self.assertIsNone(d.get_distribution('banana'))

        # Now check that it works well in both situations, when egg-info
        # is a file and directory respectively.

        for name in ('cheese', 'bacon', 'banana', 'strawberry'):
            dist = ed.get_distribution(name)
            self.assertIsInstance(dist, EggInfoDistribution)
            self.assertEqual(dist.name, name)
Beispiel #2
0
def install_dist(distname, workdir):
    pfx = '--install-option='
    purelib = pfx + '--install-purelib=%s/purelib' % workdir
    platlib = pfx + '--install-platlib=%s/platlib' % workdir
    headers = pfx + '--install-headers=%s/headers' % workdir
    scripts = pfx + '--install-scripts=%s/scripts' % workdir
    data = pfx + '--install-data=%s/data' % workdir
    cmd = ['pip', 'install',
           '--index-url', 'https://pypi.python.org/simple/',
           '--timeout', '3', '--default-timeout', '3',
           purelib, platlib, headers, scripts, data, distname]
    result = {
        'scripts': os.path.join(workdir, 'scripts'),
        'headers': os.path.join(workdir, 'headers'),
        'data': os.path.join(workdir, 'data'),
    }
    p = subprocess.Popen(cmd, shell=False, stdout=subprocess.PIPE,
                         stderr=subprocess.STDOUT)
    stdout, _ = p.communicate()
    if p.returncode:
        raise ValueError('pip failed to install %s:\n%s' % (distname, stdout))
    for dn in ('purelib', 'platlib'):
        libdir = os.path.join(workdir, dn)
        if os.path.isdir(libdir):
            result[dn] = libdir
            break
    convert_egg_info(libdir, workdir)
    dp = DistributionPath([libdir])
    dist = next(dp.get_distributions())
    md = dist.metadata
    result['name'] = md.name
    result['version'] = md.version
    return result
Beispiel #3
0
    def test_yield_distribution(self):
        # tests the internal function _yield_distributions
        checkLists = lambda x, y: self.assertEqual(sorted(x), sorted(y))

        eggs = [('bacon', '0.1'), ('banana', '0.4'), ('strawberry', '0.6'),
                ('truffles', '5.0'), ('cheese', '2.0.2'),
                ('coconuts-aster', '10.3'), ('nut', 'funkyversion')]
        dists = [('choxie', '2.0.0.9'), ('grammar', '1.0a4'),
                 ('towel-stuff', '0.1'), ('babar', '0.1')]

        d = DistributionPath(include_egg=False)
        d._include_dist = False
        checkLists([], d._yield_distributions())

        d = DistributionPath(include_egg=True)
        d._include_dist = False
        found = [(dist.name, dist.version)
                 for dist in d._yield_distributions()
                 if dist.path.startswith(self.fake_dists_path)]
        checkLists(eggs, found)

        d = DistributionPath()
        found = [(dist.name, dist.version)
                 for dist in d._yield_distributions()
                 if dist.path.startswith(self.fake_dists_path)]
        checkLists(dists, found)

        d = DistributionPath(include_egg=True)
        found = [(dist.name, dist.version)
                 for dist in d._yield_distributions()
                 if dist.path.startswith(self.fake_dists_path)]
        checkLists(dists + eggs, found)
Beispiel #4
0
 def get_dists(self, names, include_egg=False):
     dists = []
     d = DistributionPath(include_egg=include_egg)
     for name in names:
         dist = d.get_distribution(name)
         self.assertNotEqual(dist, None)
         dists.append(dist)
     return dists
Beispiel #5
0
    def test_get_file(self):
        # Create a fake dist
        temp_site_packages = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, temp_site_packages)

        dist_name = 'test'
        dist_info = os.path.join(temp_site_packages, 'test-0.1.dist-info')
        os.mkdir(dist_info)

        metadata_path = os.path.join(dist_info, 'METADATA')
        resources_path = os.path.join(dist_info, 'RESOURCES')

        fp = open(metadata_path, 'w')
        try:
            fp.write(dedent("""\
                Metadata-Version: 1.2
                Name: test
                Version: 0.1
                Summary: test
                Author: me
                """))
        finally:
            fp.close()
        test_path = 'test.cfg'

        fd, test_resource_path = tempfile.mkstemp()
        os.close(fd)
        self.addCleanup(os.remove, test_resource_path)

        fp = open(test_resource_path, 'w')
        try:
            fp.write('Config')
        finally:
            fp.close()

        fp = open(resources_path, 'w')
        try:
            fp.write('%s,%s' % (test_path, test_resource_path))
        finally:
            fp.close()

        # Add fake site-packages to sys.path to retrieve fake dist
        self.addCleanup(sys.path.remove, temp_site_packages)
        sys.path.insert(0, temp_site_packages)

        # Try to retrieve resources paths and files
        d = DistributionPath()
        self.assertEqual(d.get_file_path(dist_name, test_path),
                         test_resource_path)
        self.assertRaises(KeyError, d.get_file_path, dist_name,
                          'i-dont-exist')
Beispiel #6
0
def install_dist(distname, workdir):
    pfx = "--install-option="
    purelib = pfx + "--install-purelib=%s/purelib" % workdir
    platlib = pfx + "--install-platlib=%s/platlib" % workdir
    headers = pfx + "--install-headers=%s/headers" % workdir
    scripts = pfx + "--install-scripts=%s/scripts" % workdir
    data = pfx + "--install-data=%s/data" % workdir
    cmd = [
        "pip",
        "install",
        "--index-url",
        "https://pypi.python.org/simple/",
        "--timeout",
        "3",
        "--default-timeout",
        "3",
        purelib,
        platlib,
        headers,
        scripts,
        data,
        distname,
    ]
    result = {
        "scripts": os.path.join(workdir, "scripts"),
        "headers": os.path.join(workdir, "headers"),
        "data": os.path.join(workdir, "data"),
    }
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    stdout, _ = p.communicate()
    if p.returncode:
        raise ValueError("pip failed to install %s:\n%s" % (distname, stdout))
    for dn in ("purelib", "platlib"):
        libdir = os.path.join(workdir, dn)
        if os.path.isdir(libdir):
            result[dn] = libdir
            break
    convert_egg_info(libdir, workdir)
    dp = DistributionPath([libdir])
    dist = next(dp.get_distributions())
    md = dist.metadata
    result["name"] = md.name
    result["version"] = md.version
    return result
Beispiel #7
0
    def test_get_file(self):
        # Create a fake dist
        temp_site_packages = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, temp_site_packages)

        dist_name = "test"
        dist_info = os.path.join(temp_site_packages, "test-0.1.dist-info")
        os.mkdir(dist_info)

        metadata_path = os.path.join(dist_info, "pydist.json")
        resources_path = os.path.join(dist_info, "RESOURCES")
        md = Metadata()
        md.name = "test"
        md.version = "0.1"
        md.summary = "test"
        md.write(path=metadata_path)
        test_path = "test.cfg"

        fd, test_resource_path = tempfile.mkstemp()
        os.close(fd)
        self.addCleanup(os.remove, test_resource_path)

        fp = open(test_resource_path, "w")
        try:
            fp.write("Config")
        finally:
            fp.close()

        fp = open(resources_path, "w")
        try:
            fp.write("%s,%s" % (test_path, test_resource_path))
        finally:
            fp.close()

        # Add fake site-packages to sys.path to retrieve fake dist
        self.addCleanup(sys.path.remove, temp_site_packages)
        sys.path.insert(0, temp_site_packages)

        # Try to retrieve resources paths and files
        d = DistributionPath()
        self.assertEqual(d.get_file_path(dist_name, test_path), test_resource_path)
        self.assertRaises(KeyError, d.get_file_path, dist_name, "i-dont-exist")
Beispiel #8
0
def convert_egg_info(libdir, prefix):
    files = os.listdir(libdir)
    ei = list(filter(lambda d: d.endswith('.egg-info'), files))[0]
    olddn = os.path.join(libdir, ei)
    di = EGG_INFO_RE.sub('.dist-info', ei)
    newdn = os.path.join(libdir, di)
    os.rename(olddn, newdn)
    files = os.listdir(newdn)
    for oldfn in files:
        pn = os.path.join(newdn, oldfn)
        if oldfn == 'PKG-INFO':
            md = Metadata(path=pn)
            mn = os.path.join(newdn, METADATA_FILENAME)
            md.write(mn)
        os.remove(pn)
    manifest = Manifest(os.path.dirname(libdir))
    manifest.findall()
    dp = DistributionPath([libdir])
    dist = next(dp.get_distributions())
    dist.write_installed_files(manifest.allfiles, prefix)
Beispiel #9
0
    def test_write_exports(self):
        exports = {
            'foo': {
                'v1': ExportEntry('v1', 'p1', 's1', []),
                'v2': ExportEntry('v2', 'p2', 's2', ['f2=a', 'g2']),
            },
            'bar': {
                'v3': ExportEntry('v3', 'p3', 's3', ['f3', 'g3=h']),
                'v4': ExportEntry('v4', 'p4', 's4', ['f4', 'g4']),
            },
        }

        fd, fn = tempfile.mkstemp()
        try:
            os.close(fd)
            d = DistributionPath().get_distribution('babar')    # any one will do
            d.write_exports(exports, fn)
            actual = d.read_exports(fn)
            self.assertEqual(actual, exports)
        finally:
            os.remove(fn)
Beispiel #10
0
    def test_exports_iteration(self):
        d = DistributionPath()
        expected = set(
            (
                ("bar", "baz", "barbaz", ("a=10", "b")),
                ("bar", "crunchie", None, ()),
                ("bar", "towel", "towel", ()),
                ("baz", "towel", "beach_towel", ()),
            )
        )
        entries = list(d.get_exported_entries("foo"))
        for e in entries:
            t = e.name, e.prefix, e.suffix, tuple(e.flags)
            self.assertIn(t, expected)
            expected.remove(t)
        self.assertFalse(expected)  # nothing left
        expected = set(
            (("bar", "baz", "barbaz", ("a=10", "b")), ("bar", "crunchie", None, ()), ("bar", "towel", "towel", ()))
        )
        entries = list(d.get_exported_entries("foo", "bar"))
        for e in entries:
            t = e.name, e.prefix, e.suffix, tuple(e.flags)
            self.assertIn(t, expected)
            expected.remove(t)
        self.assertFalse(expected)  # nothing left

        expected = set(
            (
                ("foofoo", "baz.foo", "bazbar", ()),
                ("real", "cgi", "print_directory", ()),
                ("foofoo", "ferrero", "rocher", ()),
                ("foobar", "hoopy", "frood", ("dent",)),
            )
        )
        entries = list(d.get_exported_entries("bar.baz"))
        for e in entries:
            t = e.name, e.prefix, e.suffix, tuple(e.flags)
            self.assertIn(t, expected)
            expected.remove(t)
        self.assertFalse(expected)  # nothing left
Beispiel #11
0
def convert_egg_info(libdir, prefix):
    files = os.listdir(libdir)
    ei = list(filter(lambda d: d.endswith('.egg-info'), files))[0]
    olddn = os.path.join(libdir, ei)
    di = EGG_INFO_RE.sub('.dist-info', ei)
    newdn = os.path.join(libdir, di)
    os.rename(olddn, newdn)
    renames = {
        'PKG-INFO': 'METADATA',
    }
    files = os.listdir(newdn)
    for oldfn in files:
        pn = os.path.join(newdn, oldfn)
        if oldfn in renames:
            os.rename(pn, os.path.join(newdn, renames[oldfn]))
        else:
            os.remove(pn)
    manifest = Manifest(os.path.dirname(libdir))
    manifest.findall()
    dp = DistributionPath([libdir])
    dist = next(dp.get_distributions())
    dist.write_installed_files(manifest.allfiles, prefix)
Beispiel #12
0
    def test_exports_iteration(self):
        d = DistributionPath()
        expected = set((
            ('bar', 'baz', 'barbaz', ('a=10', 'b')),
            ('bar', 'crunchie', None, ()),
            ('bar', 'towel', 'towel', ()),
            ('baz', 'towel', 'beach_towel', ()),
        ))
        entries = list(d.get_exported_entries('foo'))
        for e in entries:
            t = e.name, e.prefix, e.suffix, tuple(e.flags)
            self.assertIn(t, expected)
            expected.remove(t)
        self.assertFalse(expected)   # nothing left
        expected = set((
            ('bar', 'baz', 'barbaz', ('a=10', 'b')),
            ('bar', 'crunchie', None, ()),
            ('bar', 'towel', 'towel', ()),
        ))
        entries = list(d.get_exported_entries('foo', 'bar'))
        for e in entries:
            t = e.name, e.prefix, e.suffix, tuple(e.flags)
            self.assertIn(t, expected)
            expected.remove(t)
        self.assertFalse(expected)   # nothing left

        expected = set((
            ('foofoo', 'baz.foo', 'bazbar', ()),
            ('real', 'cgi', 'print_directory', ()),
            ('foofoo', 'ferrero', 'rocher', ()),
            ('foobar', 'hoopy', 'frood', ('dent',)),
        ))
        entries = list(d.get_exported_entries('bar.baz'))
        for e in entries:
            t = e.name, e.prefix, e.suffix, tuple(e.flags)
            self.assertIn(t, expected)
            expected.remove(t)
        self.assertFalse(expected)   # nothing left
Beispiel #13
0
    def test_yield_distribution(self):
        # tests the internal function _yield_distributions
        checkLists = lambda x, y: self.assertEqual(sorted(x), sorted(y))

        eggs = [
            ("bacon", "0.1"),
            ("banana", "0.4"),
            ("strawberry", "0.6"),
            ("truffles", "5.0"),
            ("cheese", "2.0.2"),
            ("coconuts-aster", "10.3"),
            ("nut", "funkyversion"),
        ]
        dists = [("choxie", "2.0.0.9"), ("grammar", "1.0a4"), ("towel-stuff", "0.1"), ("babar", "0.1")]

        d = DistributionPath(include_egg=False)
        d._include_dist = False
        checkLists([], d._yield_distributions())

        d = DistributionPath(include_egg=True)
        d._include_dist = False
        found = [
            (dist.name, dist.version) for dist in d._yield_distributions() if dist.path.startswith(self.fake_dists_path)
        ]
        checkLists(eggs, found)

        d = DistributionPath()
        found = [
            (dist.name, dist.version) for dist in d._yield_distributions() if dist.path.startswith(self.fake_dists_path)
        ]
        checkLists(dists, found)

        d = DistributionPath(include_egg=True)
        found = [
            (dist.name, dist.version) for dist in d._yield_distributions() if dist.path.startswith(self.fake_dists_path)
        ]
        checkLists(dists + eggs, found)
Beispiel #14
0
    def uninstall(self, requirement):
        # Currently we assume the distribution path contains only the last
        # version installed
        package_name = util.parse_requirement(requirement).name
        distribution = DistributionPath(include_egg=True).get_distribution(
            package_name)

        # Oh distlib, if the distribution doesn't exist, we'll get None here
        if not distribution:
            raise exceptions.PackageNotInstalled(
                "There's no package named {0} installed in your environment".format(
                    package_name))

        # Distlib is not that smart about paths for files inside of
        # distributions too, so to find the full path to the distribution
        # files, we'll have to concatenate them to this base path manually :/
        base = os.path.dirname(distribution.path)

        # Let's now remove all the installed files
        for path, hash_, size in distribution.list_installed_files():
            os.unlink(os.path.join(base, path))

        # Removing the package directories
        os.rmdir(distribution.path)
Beispiel #15
0
    def find_dependencies(self, package):
        # This weird `reload()` is here cause the `get_provider` method that
        # feeds `get_distribution` uses a variable (working_set) populated in
        # the module body, so it won't get updated just by installing a new
        # package.
        name = distlib.database.parse_requirement(package).name
        dist = DistributionPath().get_distribution(name)

        # This is another ugly thing. There's no other way for retrieving the
        # dependency list for a package until it's installed. If it is a wheel,
        # though, the dependency format will be different.
        # e.g: "ejson (==0.1.3)" will become "ejson==0.1.3"
        for dependency in dist.requires.union(dist.test_requires):
            self.env.request_install(self._spec2installable(dependency),
                                     sender=self.name,
                                     data={'dependency-of': package})
Beispiel #16
0
    def test_get_distributions(self):
        # Lookup all distributions found in the ``sys.path``.
        # This test could potentially pick up other installed distributions
        non_egg_dists = [("grammar", "1.0a4"), ("choxie", "2.0.0.9"), ("towel-stuff", "0.1"), ("babar", "0.1")]
        egg_dists = [
            ("bacon", "0.1"),
            ("cheese", "2.0.2"),
            ("coconuts-aster", "10.3"),
            ("banana", "0.4"),
            ("strawberry", "0.6"),
            ("truffles", "5.0"),
            ("nut", "funkyversion"),
        ]

        all_dists = non_egg_dists + egg_dists

        d = DistributionPath()
        ed = DistributionPath(include_egg=True)

        cases = ((d, non_egg_dists, InstalledDistribution), (ed, all_dists, BaseInstalledDistribution))

        fake_dists_path = self.fake_dists_path
        for enabled in (True, False):
            if not enabled:
                d.cache_enabled = False
                ed.cache_enabled = False
                d.clear_cache()
                ed.clear_cache()

            for distset, fake_dists, allowed_class in cases:
                found_dists = []

                # Verify the fake dists have been found.
                dists = list(distset.get_distributions())
                for dist in dists:
                    self.assertIsInstance(dist, allowed_class)
                    if dist.name in dict(fake_dists) and dist.path.startswith(fake_dists_path):
                        found_dists.append((dist.name, dist.version))
                    else:
                        # check that it doesn't find anything more than this
                        self.assertFalse(dist.path.startswith(fake_dists_path))
                    # otherwise we don't care what other dists are found

                # Finally, test that we found all that we were looking for
                self.assertEqual(sorted(found_dists), sorted(fake_dists))
Beispiel #17
0
    def test_distinfo_dirname(self):
        # Given a name and a version, we expect the distinfo_dirname function
        # to return a standard distribution information directory name.

        items = [
            # (name, version, standard_dirname)
            # Test for a very simple single word name and decimal version
            # number
            ('docutils', '0.5', 'docutils-0.5.dist-info'),
            # Test for another except this time with a '-' in the name, which
            # needs to be transformed during the name lookup
            ('python-ldap', '2.5', 'python_ldap-2.5.dist-info'),
            # Test for both '-' in the name and a funky version number
            ('python-ldap', '2.5 a---5', 'python_ldap-2.5 a---5.dist-info'),
            ]

        # Loop through the items to validate the results
        for name, version, standard_dirname in items:
            dirname = DistributionPath.distinfo_dirname(name, version)
            self.assertEqual(dirname, standard_dirname)
Beispiel #18
0
    def test_distinfo_dirname(self):
        # Given a name and a version, we expect the distinfo_dirname function
        # to return a standard distribution information directory name.

        items = [
            # (name, version, standard_dirname)
            # Test for a very simple single word name and decimal version
            # number
            ('docutils', '0.5', 'docutils-0.5.dist-info'),
            # Test for another except this time with a '-' in the name, which
            # needs to be transformed during the name lookup
            ('python-ldap', '2.5', 'python_ldap-2.5.dist-info'),
            # Test for both '-' in the name and a funky version number
            ('python-ldap', '2.5 a---5', 'python_ldap-2.5 a---5.dist-info'),
        ]

        # Loop through the items to validate the results
        for name, version, standard_dirname in items:
            dirname = DistributionPath.distinfo_dirname(name, version)
            self.assertEqual(dirname, standard_dirname)
Beispiel #19
0
 def test_caches(self):
     # sanity check for internal caches
     d = DistributionPath()
     for name in ('_cache', '_cache_egg'):
         self.assertEqual(getattr(d, name).name, {})
         self.assertEqual(getattr(d, name).path, {})
Beispiel #20
0
    def test_provides(self):
        # Test for looking up distributions by what they provide
        checkLists = lambda x, y: self.assertEqual(sorted(x), sorted(y))

        d = DistributionPath()
        ed = DistributionPath(include_egg=True)

        l = [dist.name for dist in d.provides_distribution('truffles')]
        checkLists(l, ['choxie', 'towel-stuff'])

        l = [dist.name for dist in d.provides_distribution('truffles', '1.0')]
        checkLists(l, ['choxie', 'towel-stuff'])

        l = [dist.name for dist in ed.provides_distribution('truffles', '1.0')]
        checkLists(l, ['choxie', 'cheese', 'towel-stuff'])

        l = [dist.name for dist in d.provides_distribution('truffles', '1.1.2')]
        checkLists(l, ['towel-stuff'])

        l = [dist.name for dist in d.provides_distribution('truffles', '1.1')]
        checkLists(l, ['towel-stuff'])

        l = [dist.name for dist in d.provides_distribution('truffles',
                                                           '!=1.1,<=2.0')]
        checkLists(l, ['choxie', 'towel-stuff'])

        l = [dist.name for dist in ed.provides_distribution('truffles',
                                                            '!=1.1,<=2.0')]
        checkLists(l, ['choxie', 'bacon', 'cheese', 'towel-stuff'])

        l = [dist.name for dist in d.provides_distribution('truffles', '>1.0')]
        checkLists(l, ['towel-stuff'])

        l = [dist.name for dist in d.provides_distribution('truffles', '>1.5')]
        checkLists(l, [])

        l = [dist.name for dist in ed.provides_distribution('truffles', '>1.5')]
        checkLists(l, ['bacon', 'truffles'])

        l = [dist.name for dist in d.provides_distribution('truffles', '>=1.0')]
        checkLists(l, ['choxie', 'towel-stuff'])

        l = [dist.name for dist in ed.provides_distribution('strawberry', '0.6')]
        checkLists(l, ['coconuts-aster', 'strawberry'])

        l = [dist.name for dist in ed.provides_distribution('strawberry', '>=0.5')]
        checkLists(l, ['coconuts-aster', 'strawberry'])

        l = [dist.name for dist in ed.provides_distribution('strawberry', '>0.6')]
        checkLists(l, [])

        l = [dist.name for dist in ed.provides_distribution('banana', '0.4')]
        checkLists(l, ['banana', 'coconuts-aster'])

        l = [dist.name for dist in ed.provides_distribution('banana', '>=0.3')]
        checkLists(l, ['banana', 'coconuts-aster'])

        l = [dist.name for dist in ed.provides_distribution('banana', '!=0.4')]
        checkLists(l, [])
Beispiel #21
0
import tempfile

logger = logging.getLogger('wheeler')

from distlib.compat import configparser, filter
from distlib.database import DistributionPath, Distribution, make_graph
from distlib.locators import (JSONLocator, SimpleScrapingLocator,
                              AggregatingLocator, DependencyFinder)
from distlib.manifest import Manifest
from distlib.metadata import Metadata
from distlib.util import parse_requirement, get_package_data
from distlib.wheel import Wheel

EGG_INFO_RE = re.compile(r'(-py\d\.\d)?\.egg-info', re.I)

INSTALLED_DISTS = DistributionPath(include_egg=True)


def get_requirements(data):
    lines = []
    for line in data.splitlines():
        line = line.strip()
        if not line or line[0] == '#':
            continue
        lines.append(line)
    reqts = []
    extras = {}
    result = {'install': reqts, 'extras': extras}
    for line in lines:
        if line[0] != '[':
            reqts.append(line)
Beispiel #22
0
 def check_installed(cls, requirement):
     path = DistributionPath(include_egg=True)
     package_name = util.parse_requirement(requirement).name
     return path.get_distribution(package_name) is not None
Beispiel #23
0
    def test_yield_distribution(self):
        # tests the internal function _yield_distributions
        checkLists = lambda x, y: self.assertEqual(sorted(x), sorted(y))

        eggs = [('bacon', '0.1'), ('banana', '0.4'), ('strawberry', '0.6'),
                ('truffles', '5.0'), ('cheese', '2.0.2'),
                ('coconuts-aster', '10.3'), ('nut', 'funkyversion')]
        dists = [('choxie', '2.0.0.9'), ('grammar', '1.0a4'),
                 ('towel-stuff', '0.1'), ('babar', '0.1')]

        d = DistributionPath(include_egg=False)
        d._include_dist = False
        checkLists([], d._yield_distributions())

        d = DistributionPath(include_egg=True)
        d._include_dist = False
        found = [(dist.name, dist.version)
                 for dist in d._yield_distributions()
                 if dist.path.startswith(self.fake_dists_path)]
        checkLists(eggs, found)

        d = DistributionPath()
        found = [(dist.name, dist.version)
                 for dist in d._yield_distributions()
                 if dist.path.startswith(self.fake_dists_path)]
        checkLists(dists, found)

        d = DistributionPath(include_egg=True)
        found = [(dist.name, dist.version)
                 for dist in d._yield_distributions()
                 if dist.path.startswith(self.fake_dists_path)]
        checkLists(dists + eggs, found)
Beispiel #24
0
def get_distribution_from_source_file(file_name):
    path = DistributionPath(include_egg=True)
    distribution = path.get_distribution(
        os.path.dirname(file_name) or file_name)
    return distribution
Beispiel #25
0
def get_distribution_from_source_file(file_name):
    path = DistributionPath(include_egg=True)
    distribution = path.get_distribution(
        os.path.dirname(file_name) or file_name)
    return distribution
Beispiel #26
0
    def test_provides(self):
        # Test for looking up distributions by what they provide
        checkLists = lambda x, y: self.assertEqual(sorted(x), sorted(y))

        d = DistributionPath()
        ed = DistributionPath(include_egg=True)

        l = [dist.name for dist in d.provides_distribution("truffles")]
        checkLists(l, ["choxie", "towel-stuff"])

        l = [dist.name for dist in d.provides_distribution("truffles", "1.0")]
        checkLists(l, ["choxie", "towel-stuff"])

        l = [dist.name for dist in ed.provides_distribution("truffles", "1.0")]
        checkLists(l, ["choxie", "cheese", "towel-stuff"])

        l = [dist.name for dist in d.provides_distribution("truffles", "1.1.2")]
        checkLists(l, ["towel-stuff"])

        l = [dist.name for dist in d.provides_distribution("truffles", "1.1")]
        checkLists(l, ["towel-stuff"])

        l = [dist.name for dist in d.provides_distribution("truffles", "!=1.1,<=2.0")]
        checkLists(l, ["choxie", "towel-stuff"])

        l = [dist.name for dist in ed.provides_distribution("truffles", "!=1.1,<=2.0")]
        checkLists(l, ["choxie", "bacon", "cheese", "towel-stuff"])

        l = [dist.name for dist in d.provides_distribution("truffles", ">1.0")]
        checkLists(l, ["towel-stuff"])

        l = [dist.name for dist in d.provides_distribution("truffles", ">1.5")]
        checkLists(l, [])

        l = [dist.name for dist in ed.provides_distribution("truffles", ">1.5")]
        checkLists(l, ["bacon", "truffles"])

        l = [dist.name for dist in d.provides_distribution("truffles", ">=1.0")]
        checkLists(l, ["choxie", "towel-stuff"])

        l = [dist.name for dist in ed.provides_distribution("strawberry", "0.6")]
        checkLists(l, ["coconuts-aster", "strawberry"])

        l = [dist.name for dist in ed.provides_distribution("strawberry", ">=0.5")]
        checkLists(l, ["coconuts-aster", "strawberry"])

        l = [dist.name for dist in ed.provides_distribution("strawberry", ">0.6")]
        checkLists(l, [])

        l = [dist.name for dist in ed.provides_distribution("banana", "0.4")]
        checkLists(l, ["banana", "coconuts-aster"])

        l = [dist.name for dist in ed.provides_distribution("banana", ">=0.3")]
        checkLists(l, ["banana", "coconuts-aster"])

        l = [dist.name for dist in ed.provides_distribution("banana", "!=0.4")]
        checkLists(l, [])
Beispiel #27
0
 def check_installed(cls, requirement):
     path = DistributionPath(include_egg=True)
     package_name = util.parse_requirement(requirement).name
     return path.get_distribution(package_name) is not None
Beispiel #28
0
    def test_get_distribution(self):
        # Test for looking up a distribution by name.
        # Test the lookup of the towel-stuff distribution
        name = 'towel-stuff'  # Note: This is different from the directory name

        d = DistributionPath()
        ed = DistributionPath(include_egg=True)

        # Lookup the distribution
        dist = d.get_distribution(name)
        self.assertIsInstance(dist, InstalledDistribution)
        self.assertEqual(dist.name, name)

        # Verify that an unknown distribution returns None
        self.assertIsNone(d.get_distribution('bogus'))

        # Verify partial name matching doesn't work
        self.assertIsNone(d.get_distribution('towel'))

        # Verify that it does not find egg-info distributions, when not
        # instructed to
        self.assertIsNone(d.get_distribution('bacon'))
        self.assertIsNone(d.get_distribution('cheese'))
        self.assertIsNone(d.get_distribution('strawberry'))
        self.assertIsNone(d.get_distribution('banana'))

        # Now check that it works well in both situations, when egg-info
        # is a file and directory respectively.

        for name in ('cheese', 'bacon', 'banana', 'strawberry'):
            dist = ed.get_distribution(name)
            self.assertIsInstance(dist, EggInfoDistribution)
            self.assertEqual(dist.name, name)
Beispiel #29
0
 def test_modules(self):
     dp = DistributionPath(include_egg=True)
     dist = dp.get_distribution('banana')
     self.assertIsInstance(dist, EggInfoDistribution)
     self.assertEqual(dist.modules, ['banana', 'cavendish'])
Beispiel #30
0
    def test_provides(self):
        # Test for looking up distributions by what they provide
        checkLists = lambda x, y: self.assertEqual(sorted(x), sorted(y))

        d = DistributionPath()
        ed = DistributionPath(include_egg=True)

        l = [dist.name for dist in d.provides_distribution('truffles')]
        checkLists(l, ['choxie', 'towel-stuff'])

        l = [dist.name for dist in d.provides_distribution('truffles', '1.0')]
        checkLists(l, ['choxie', 'towel-stuff'])

        l = [dist.name for dist in ed.provides_distribution('truffles', '1.0')]
        checkLists(l, ['choxie', 'cheese', 'towel-stuff'])

        l = [
            dist.name for dist in d.provides_distribution('truffles', '1.1.2')
        ]
        checkLists(l, ['towel-stuff'])

        l = [dist.name for dist in d.provides_distribution('truffles', '1.1')]
        checkLists(l, ['towel-stuff'])

        l = [
            dist.name
            for dist in d.provides_distribution('truffles', '!=1.1,<=2.0')
        ]
        checkLists(l, ['choxie', 'towel-stuff'])

        l = [
            dist.name
            for dist in ed.provides_distribution('truffles', '!=1.1,<=2.0')
        ]
        checkLists(l, ['choxie', 'bacon', 'cheese', 'towel-stuff'])

        l = [dist.name for dist in d.provides_distribution('truffles', '>1.0')]
        checkLists(l, ['towel-stuff'])

        l = [dist.name for dist in d.provides_distribution('truffles', '>1.5')]
        checkLists(l, [])

        l = [
            dist.name for dist in ed.provides_distribution('truffles', '>1.5')
        ]
        checkLists(l, ['bacon', 'truffles'])

        l = [
            dist.name for dist in d.provides_distribution('truffles', '>=1.0')
        ]
        checkLists(l, ['choxie', 'towel-stuff'])

        l = [
            dist.name
            for dist in ed.provides_distribution('strawberry', '0.6')
        ]
        checkLists(l, ['coconuts-aster', 'strawberry'])

        l = [
            dist.name
            for dist in ed.provides_distribution('strawberry', '>=0.5')
        ]
        checkLists(l, ['coconuts-aster', 'strawberry'])

        l = [
            dist.name
            for dist in ed.provides_distribution('strawberry', '>0.6')
        ]
        checkLists(l, [])

        l = [dist.name for dist in ed.provides_distribution('banana', '0.4')]
        checkLists(l, ['banana', 'coconuts-aster'])

        l = [dist.name for dist in ed.provides_distribution('banana', '>=0.3')]
        checkLists(l, ['banana', 'coconuts-aster'])

        l = [dist.name for dist in ed.provides_distribution('banana', '!=0.4')]
        checkLists(l, [])
Beispiel #31
0
def list_installed():
    dist_path = DistributionPath()

    for dist in dist_path.get_distributions():
        print(dist)
Beispiel #32
0
#!/usr/bin/env python

from distlib.database import DistributionPath
dist_path = DistributionPath()
mylist = list(dist_path.get_distributions())
from distlib.database import make_graph
print(make_graph(mylist))