def wheel_from_metadata(location, metadata): if not metadata.has_metadata(pkg_resources.DistInfoDistribution.PKG_INFO): return None from email.parser import Parser pkg_info = Parser().parsestr(metadata.get_metadata(pkg_resources.DistInfoDistribution.PKG_INFO)) return pkg_resources.DistInfoDistribution( location=location, metadata=metadata, # TODO(wickman) Is this necessary or will they get picked up correctly? project_name=pkg_info.get('Name'), version=pkg_info.get('Version'), platform=None)
def distribution(self, location, metadata=None): """ Get DistInfoDistribution for wheel """ info = self.distribution_info() return pkg_resources.DistInfoDistribution( location=location, metadata=metadata, project_name=info['name'], version=info['ver'], platform=info['plat'], # trick buildout into believing this dist is a BINARY_DIS # so it invokes our `_call_easy_install` override: precedence=pkg_resources.BINARY_DIST, )
def __init__(self, distribution=None, location=None, importer=None): """ Constructs the WheelDistribution """ if distribution is not None and location is not None: raise self.Error("location and distribution cannot both be set") if distribution is not None: self.distribution = distribution else: # Construct the metadata provider if self.is_wheel_archive(location): importer = importer or zipimport.zipimporter(location) metadata = WheelMetadata(importer) else: root = os.path.dirname(location) metadata = pkg_resources.PathMetadata(root, location) project_name, version, py_version, platform = [None] * 4 match = self.WHEEL_INFO_RE(os.path.basename(metadata.egg_info)) if match: project_name, version, py_version, platform = match.group( "name", "ver", "pyver", "plat" ) py_version = py_version or sys.version_info[0] self.distribution = pkg_resources.DistInfoDistribution( location, metadata, project_name=project_name, version=version, py_version=py_version, platform=platform, ) # self.distribution.egg_info is the only reliable way to get the name. # I'm not sure if egg_info is a public interface, but we already rely # on it for WheelMetadata. wheel_info = os.path.basename(self.distribution.egg_info) parsed_filename = self.WHEEL_INFO_RE(wheel_info) if parsed_filename is None: raise self.Error("Bad wheel '%s'" % wheel_info) self.name, self.ver, self.namever = parsed_filename.group( "name", "ver", "namever" )
dist=pkg_resources.Distribution( location='/path/to/dist', project_name='crunchy-frog', version="0.1", py_version=None, platform=None, ), expected_path='/path/to/dist/crunchy_frog-0.1.egg/EGG-INFO/PKG-INFO'), DistTestCase( description=''' Create a short dist info name ''', dist=pkg_resources.DistInfoDistribution( location='/path/to/dist', project_name='crunchy-frog', version="0.1", py_version=None, platform=None, ), expected_path='/path/to/dist/crunchy_frog-0.1.dist-info/METADATA'), ) @ddt class TestPackageTools(unittest.TestCase): def test_get_local_funding_metadata_from_name(self): package_name = u'mosw' project_funding_url = ptools.get_local_funding_metadata(package_name) self.assertEqual(project_funding_url, 'http://ministry-of-silly-walks.python/fundme')