def test_package_name_glob(self):
        '''package_name_glob().'''

        self.assertTrue(len(impl.package_name_glob('a*')) > 5)
        self.assertTrue('bash' in impl.package_name_glob('ba*h'))
        self.assertEqual(impl.package_name_glob('bash'), ['bash'])
        self.assertEqual(impl.package_name_glob('xzywef*'), [])
    def test_package_name_glob(self):
        '''package_name_glob().'''

        self.assertTrue(len(impl.package_name_glob('a*')) > 5)
        self.assertTrue('bash' in impl.package_name_glob('ba*h'))
        self.assertEqual(impl.package_name_glob('bash'), ['bash'])
        self.assertEqual(impl.package_name_glob('xzywef*'), [])
def package_versions(*packages):
    '''Return a text listing of package names and versions.

    Arguments may be package names or globs, e. g. "foo*"
    '''
    versions = []
    for package_pattern in packages:
        if not package_pattern:
            continue

        matching_packages = packaging.package_name_glob(package_pattern)

        if not matching_packages:
            versions.append((package_pattern, 'N/A'))

        for package in sorted(matching_packages):
            try:
                version = packaging.get_version(package)
            except ValueError:
                version = 'N/A'
            if version is None:
                version = 'N/A'
            versions.append((package, version))

    package_width, version_width = \
        map(max, [map(len, t) for t in zip(*versions)])

    fmt = '%%-%ds %%s' % package_width
    return '\n'.join([fmt % v for v in versions])
Beispiel #4
0
def package_versions(*packages):
    """Return a text listing of package names and versions.

    Arguments may be package names or globs, e. g. "foo*"
    """
    versions = []
    for package_pattern in packages:
        if not package_pattern:
            continue

        matching_packages = packaging.package_name_glob(package_pattern)

        if not matching_packages:
            versions.append((package_pattern, "N/A"))

        for package in sorted(matching_packages):
            try:
                version = packaging.get_version(package)
            except ValueError:
                version = "N/A"
            if version is None:
                version = "N/A"
            versions.append((package, version))

    package_width, version_width = map(max, [map(len, t) for t in zip(*versions)])

    fmt = "%%-%ds %%s" % package_width
    return "\n".join([fmt % v for v in versions])