utils/scanpypi: remove python six module

We dropped support for python2 a while back in [1], as such we
can remove the python six module which was only needed for
backwards comaptibility with python2.

[1] 2743ce00ca

Signed-off-by: James Hilliard <james.hilliard1@gmail.com>
[Julien: add commit ref removing python2 support]
Signed-off-by: Julien Olivain <ju.o@free.fr>
This commit is contained in:
James Hilliard
2025-09-15 14:27:37 -06:00
committed by Julien Olivain
parent 6448c3b425
commit 53eb75ef53

View File

@@ -22,16 +22,10 @@ import tempfile
import traceback import traceback
import importlib import importlib
import importlib.metadata import importlib.metadata
import six.moves.urllib.request import urllib.request
import six.moves.urllib.error import urllib.error
import six.moves.urllib.parse import urllib.parse
from six.moves import map import io
from six.moves import zip
from six.moves import input
if six.PY2:
import StringIO
else:
import io
BUF_SIZE = 65536 BUF_SIZE = 65536
@@ -225,15 +219,15 @@ class BuildrootPackage():
self.metadata_url = 'https://pypi.org/pypi/{pkg}/json'.format( self.metadata_url = 'https://pypi.org/pypi/{pkg}/json'.format(
pkg=self.real_name) pkg=self.real_name)
try: try:
pkg_json = six.moves.urllib.request.urlopen(self.metadata_url).read().decode() pkg_json = urllib.request.urlopen(self.metadata_url).read().decode()
except six.moves.urllib.error.HTTPError as error: except urllib.error.HTTPError as error:
print('ERROR:', error.getcode(), error.msg, file=sys.stderr) print('ERROR:', error.getcode(), error.msg, file=sys.stderr)
print('ERROR: Could not find package {pkg}.\n' print('ERROR: Could not find package {pkg}.\n'
'Check syntax inside the python package index:\n' 'Check syntax inside the python package index:\n'
'https://pypi.python.org/pypi/ ' 'https://pypi.python.org/pypi/ '
.format(pkg=self.real_name)) .format(pkg=self.real_name))
raise raise
except six.moves.urllib.error.URLError: except urllib.error.URLError:
print('ERROR: Could not find package {pkg}.\n' print('ERROR: Could not find package {pkg}.\n'
'Check syntax inside the python package index:\n' 'Check syntax inside the python package index:\n'
'https://pypi.python.org/pypi/ ' 'https://pypi.python.org/pypi/ '
@@ -260,7 +254,7 @@ class BuildrootPackage():
'digests': None}] 'digests': None}]
# In this case, we can't get the name of the downloaded file # In this case, we can't get the name of the downloaded file
# from the pypi api, so we need to find it, this should work # from the pypi api, so we need to find it, this should work
urlpath = six.moves.urllib.parse.urlparse( urlpath = urllib.parse.urlparse(
self.metadata['info']['download_url']).path self.metadata['info']['download_url']).path
# urlparse().path give something like # urlparse().path give something like
# /path/to/file-version.tar.gz # /path/to/file-version.tar.gz
@@ -272,8 +266,8 @@ class BuildrootPackage():
try: try:
print('Downloading package {pkg} from {url}...'.format( print('Downloading package {pkg} from {url}...'.format(
pkg=self.real_name, url=download_url['url'])) pkg=self.real_name, url=download_url['url']))
download = six.moves.urllib.request.urlopen(download_url['url']) download = urllib.request.urlopen(download_url['url'])
except six.moves.urllib.error.HTTPError as http_error: except urllib.error.HTTPError as http_error:
download = http_error download = http_error
else: else:
self.used_url = download_url self.used_url = download_url
@@ -288,7 +282,7 @@ class BuildrootPackage():
raise DownloadFailed('Failed to download package {pkg}: ' raise DownloadFailed('Failed to download package {pkg}: '
'No source archive available' 'No source archive available'
.format(pkg=self.real_name)) .format(pkg=self.real_name))
elif download.__class__ == six.moves.urllib.error.HTTPError: elif download.__class__ == urllib.error.HTTPError:
raise download raise download
self.filename = self.used_url['filename'] self.filename = self.used_url['filename']
@@ -317,10 +311,7 @@ class BuildrootPackage():
Keyword arguments: Keyword arguments:
tmp_path -- directory where you want the package to be extracted tmp_path -- directory where you want the package to be extracted
""" """
if six.PY2: as_file = io.BytesIO(self.as_string)
as_file = StringIO.StringIO(self.as_string)
else:
as_file = io.BytesIO(self.as_string)
if self.filename[-3:] == 'zip': if self.filename[-3:] == 'zip':
with zipfile.ZipFile(as_file) as as_zipfile: with zipfile.ZipFile(as_file) as as_zipfile:
tmp_pkg = os.path.join(tmp_path, self.buildroot_name) tmp_pkg = os.path.join(tmp_path, self.buildroot_name)
@@ -797,12 +788,12 @@ def main():
print('Fetching package', package.real_name) print('Fetching package', package.real_name)
try: try:
package.fetch_package_info() package.fetch_package_info()
except (six.moves.urllib.error.URLError, six.moves.urllib.error.HTTPError): except (urllib.error.URLError, urllib.error.HTTPError):
continue continue
try: try:
package.download_package() package.download_package()
except six.moves.urllib.error.HTTPError as error: except urllib.error.HTTPError as error:
print('Error: {code} {reason}'.format(code=error.code, print('Error: {code} {reason}'.format(code=error.code,
reason=error.reason)) reason=error.reason))
print('Error downloading package :', package.buildroot_name) print('Error downloading package :', package.buildroot_name)