in xar/py_util.py [0:0]
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"
)