Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _get_distribution(self, version):
# Source url for the package
source_url = version['urls'][0] # TODO: prefer whl files
# Build the metadata
mdata = metadata.Metadata(scheme=self.scheme)
mdata.name = version['name']
mdata.version = version['version']
mdata.source_url = mdata.download_url = source_url['url']
# Building the dist and associating the download url
distribution = database.Distribution(mdata)
distribution.locator = self
return distribution
# type: (str) -> Optional[distlib.metadata.Metadata]
parsed_metadata = None
data = io.BytesIO()
with vistir.contextmanagers.open_file(whl_file) as fp:
for chunk in iter(lambda: fp.read(8096), b""):
data.write(chunk)
with zipfile.ZipFile(data, mode="r", compression=zipfile.ZIP_DEFLATED) as zf:
metadata = None
for fn in zf.namelist():
if os.path.basename(fn) == "METADATA":
metadata = fn
break
if metadata is None:
raise RuntimeError("No metadata found in wheel: {0}".format(whl_file))
with zf.open(metadata, "r") as metadata_fh:
parsed_metadata = distlib.metadata.Metadata(fileobj=metadata_fh)
return parsed_metadata
def _get_distribution(self, version):
# Source url for the package
source_url = version['urls'][0] # TODO: prefer whl files
# Build the metadata
mdata = metadata.Metadata(scheme=self.scheme)
mdata.name = version['name']
mdata.version = version['version']
mdata.download_url = source_url['url']
# Building the dist and associating the download url
distribution = database.Distribution(mdata)
distribution.locator = self
return distribution
try:
with tempfile.TemporaryDirectory(prefix='ap_dist') as tmp_dir,\
StringIO() as pkg_info:
with patch('sys.stdout', new_callable=StringIO) as mock_stdout:
dist = run_setup(script_name, ['sdist', '-d', tmp_dir,
'bdist_wheel', '-d', tmp_dir])
local_locator = DirectoryLocator(tmp_dir)
filenames = [Path(urlparse(uri).path)
for uri in local_locator.get_project(dist.metadata.name)['digests'].keys()]
dist.metadata.write_pkg_file(pkg_info)
pkg_info.seek(0)
metadata = Metadata(fileobj=pkg_info)
yield metadata, filenames
finally:
if dist_dir:
os.chdir(current_wd)
def get_local_wheel_metadata(wheel_file):
# type: (str) -> Optional[distlib.metadata.Metadata]
parsed_metadata = None
with io.open(wheel_file, "rb") as fh:
with zipfile.ZipFile(fh, mode="r", compression=zipfile.ZIP_DEFLATED) as zf:
metadata = None
for fn in zf.namelist():
if os.path.basename(fn) == "METADATA":
metadata = fn
break
if metadata is None:
raise RuntimeError("No metadata found in wheel: {0}".format(wheel_file))
with zf.open(metadata, "r") as metadata_fh:
parsed_metadata = distlib.metadata.Metadata(fileobj=metadata_fh)
return parsed_metadata