Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
md5_digest = zip_md5 or release_urls[0]['md5_digest']
elif release_data:
url = release_data['download_url']
else:
# Only wheel is acceptable
for release_url in release_urls:
if release_url['url'].endswith("none-any.whl"):
url = release_url['url']
md5_digest = release_url['md5_digest']
break
if not url:
raise exceptions.MissingUrlException(
"Url of source archive not found.")
if url == 'UNKNOWN':
raise exceptions.MissingUrlException(
"{0} package has no sources on PyPI, Please ask the maintainer "
"to upload sources.".format(release_data['name']))
if not hashed_format:
url = ("https://files.pythonhosted.org/packages/source"
"/{0[0]}/{0}/{1}").format(name, url.split("/")[-1])
return (url, md5_digest)
self.get_setup_py(temp_dir),
*settings.EXTRACT_DIST_COMMAND_ARGS + ['--stdout'])
current_version = self.base_python_version or str(sys.version_info[0])
# the version provided with `-b` option or default
paths_to_attempt = (get_interpreter_path(version=ver) for ver in (
current_version,
'2' if current_version == '3' else '3' # alternative Python version
))
for path in paths_to_attempt:
try:
logger.info("Running extract_dist command with: {0}".format(
path))
runner.run(path)
return runner.results
except (JSONDecodeError, exc.ExtractionError) as e:
logger.error("Could not extract metadata with: {0}".format(
path))
if all(hasattr(e, a) for a in ('msg', 'pos', 'doc')):
logger.error("Could not parse JSON: {0} at {1}".format(
e.msg, e.pos))
logger.error("The JSON was: {0}".format(e.doc))
self.unsupported_version = current_version
else:
sys.stderr.write("Failed to extract data from setup.py script.\n")
sys.stderr.write("Check the log for details: {0}\n".format(
', '.join(pyp2rpm.logger.destinations)))
raise SystemExit(3)
def get(self, wheel=False):
"""Downloads the package from PyPI.
Returns:
Full path of the downloaded file.
Raises:
PermissionError if the save_dir is not writable.
"""
try:
url = get_url(self.client, self.name, self.version,
wheel, hashed_format=True)[0]
except exceptions.MissingUrlException as e:
raise SystemExit(e)
if wheel:
self.temp_dir = tempfile.mkdtemp()
save_dir = self.temp_dir
else:
save_dir = self.save_dir
save_file = '{0}/{1}'.format(save_dir, url.split('/')[-1])
request.urlretrieve(url, save_file)
logger.info('Downloaded package from PyPI: {0}.'.format(save_file))
return save_file
def inner(self, client=None):
data = extraction_fce(self)
if client is None:
logger.warning("Client is None, it was probably disabled")
data.update_attr('source0', self.archive.name)
return data
try:
release_data = client.release_data(self.name, self.version)
except BaseException:
logger.warning("Some kind of error while communicating with "
"client: {0}.".format(client), exc_info=True)
return data
try:
url, md5_digest = get_url(client, self.name, self.version)
except exc.MissingUrlException:
url, md5_digest = ('FAILED TO EXTRACT FROM PYPI',
'FAILED TO EXTRACT FROM PYPI')
data_dict = {'source0': url, 'md5': md5_digest}
for data_field in settings.PYPI_USABLE_DATA:
data_dict[data_field] = release_data.get(data_field, '')
# we usually get better license representation from trove classifiers
data_dict["license"] = license_from_trove(release_data.get(
'classifiers', ''))
data.set_from(data_dict, update=True)
return data
return inner
def _stripped_name_version(self):
"""Returns filename stripped of the suffix.
Returns:
Filename stripped of the suffix (extension).
"""
# we don't use splitext, because on "a.tar.gz" it returns ("a.tar",
# "gz")
filename = os.path.basename(self.local_file)
for archive_suffix in settings.ARCHIVE_SUFFIXES:
if filename.endswith(archive_suffix):
return filename.rstrip('{0}'.format(archive_suffix))
# if for cycle is exhausted it means no suffix was found
else:
raise exceptions.UnknownArchiveFormatException(
'Unkown archive format of file {0}.'.format(filename))