utils/scanpypi: remove python six module
PATCH 1/1 utils/scanpypi: remove python six module
We dropped support for python2 a while back, as such we can remove the python six module which was only needed for backwards comaptibility with python2.
--- utils/scanpypi | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-)
utils/scanpypi +14 -23
@@ -22,16 +22,10 @@ import tempfile import traceback import importlib import importlib.metadata -import six.moves.urllib.request -import six.moves.urllib.error -import six.moves.urllib.parse -from six.moves import map -from six.moves import zip -from six.moves import input -if six.PY2: - import StringIO -else: - import io +import urllib.request +import urllib.error +import urllib.parse +import io BUF_SIZE = 65536
@@ -225,15 +219,15 @@ class BuildrootPackage(): self.metadata_url = 'https://pypi.org/pypi/{pkg}/json'.format( pkg=self.real_name) try: - pkg_json = six.moves.urllib.request.urlopen(self.metadata_url).read().decode() - except six.moves.urllib.error.HTTPError as error: + pkg_json = urllib.request.urlopen(self.metadata_url).read().decode() + except urllib.error.HTTPError as error: print('ERROR:', error.getcode(), error.msg, file=sys.stderr) print('ERROR: Could not find package {pkg}.\n' 'Check syntax inside the python package index:\n' 'https://pypi.python.org/pypi/ ' .format(pkg=self.real_name)) raise - except six.moves.urllib.error.URLError: + except urllib.error.URLError: print('ERROR: Could not find package {pkg}.\n' 'Check syntax inside the python package index:\n' 'https://pypi.python.org/pypi/ '
@@ -260,7 +254,7 @@ class BuildrootPackage(): 'digests': None}] # 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 - urlpath = six.moves.urllib.parse.urlparse( + urlpath = urllib.parse.urlparse( self.metadata['info']['download_url']).path # urlparse().path give something like # /path/to/file-version.tar.gz
@@ -272,8 +266,8 @@ class BuildrootPackage(): try: print('Downloading package {pkg} from {url}...'.format( pkg=self.real_name, url=download_url['url'])) - download = six.moves.urllib.request.urlopen(download_url['url']) - except six.moves.urllib.error.HTTPError as http_error: + download = urllib.request.urlopen(download_url['url']) + except urllib.error.HTTPError as http_error: download = http_error else: self.used_url = download_url
@@ -288,7 +282,7 @@ class BuildrootPackage(): raise DownloadFailed('Failed to download package {pkg}: ' 'No source archive available' .format(pkg=self.real_name)) - elif download.__class__ == six.moves.urllib.error.HTTPError: + elif download.__class__ == urllib.error.HTTPError: raise download self.filename = self.used_url['filename']
@@ -317,10 +311,7 @@ class BuildrootPackage(): Keyword arguments: tmp_path -- directory where you want the package to be extracted """ - if six.PY2: - as_file = StringIO.StringIO(self.as_string) - else: - as_file = io.BytesIO(self.as_string) + as_file = io.BytesIO(self.as_string) if self.filename[-3:] == 'zip': with zipfile.ZipFile(as_file) as as_zipfile: tmp_pkg = os.path.join(tmp_path, self.buildroot_name)
@@ -797,12 +788,12 @@ def main(): print('Fetching package', package.real_name) try: package.fetch_package_info() - except (six.moves.urllib.error.URLError, six.moves.urllib.error.HTTPError): + except (urllib.error.URLError, urllib.error.HTTPError): continue try: 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, reason=error.reason)) print('Error downloading package :', package.buildroot_name)
Signature · 6 lines
2.43.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
Quoted 5 lines · James Hilliard
We dropped support for python2 a while back, as such we can remove the python six module which was only needed for backwards comaptibility with python2.
Signed-off-by James Hilliard <[email protected]>
Applied to master, thanks.
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
Thomas Perale via buildroot
AppliedIn reply of:
Quoted 5 lines
We dropped support for python2 a while back, as such we can remove the python six module which was only needed for backwards comaptibility with python2.
Signed-off-by James Hilliard <[email protected]>
Applied to 2025.02.x, 2025.05.x & 2025.08.x. Thanks
Quoted 111 lines
--- utils/scanpypi | 37 ++++++++++++++----------------------- 1 file changed, 14 insertions(+), 23 deletions(-)utils/scanpypi +14
-23@@ -22,16 +22,10 @@ import tempfile import traceback import importlib import importlib.metadata -import six.moves.urllib.request -import six.moves.urllib.error -import six.moves.urllib.parse -from six.moves import map -from six.moves import zip -from six.moves import input -if six.PY2: - import StringIO -else: - import io +import urllib.request +import urllib.error +import urllib.parse +import io BUF_SIZE = 65536@@ -225,15 +219,15 @@ class BuildrootPackage(): self.metadata_url = 'https://pypi.org/pypi/{pkg}/json'.format( pkg=self.real_name) try: - pkg_json = six.moves.urllib.request.urlopen(self.metadata_url).read().decode() - except six.moves.urllib.error.HTTPError as error: + pkg_json = urllib.request.urlopen(self.metadata_url).read().decode() + except urllib.error.HTTPError as error: print('ERROR:', error.getcode(), error.msg, file=sys.stderr) print('ERROR: Could not find package {pkg}.\n' 'Check syntax inside the python package index:\n' 'https://pypi.python.org/pypi/ ' .format(pkg=self.real_name)) raise - except six.moves.urllib.error.URLError: + except urllib.error.URLError: print('ERROR: Could not find package {pkg}.\n' 'Check syntax inside the python package index:\n' 'https://pypi.python.org/pypi/ '@@ -260,7 +254,7 @@ class BuildrootPackage(): 'digests': None}] # 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 - urlpath = six.moves.urllib.parse.urlparse( + urlpath = urllib.parse.urlparse( self.metadata['info']['download_url']).path # urlparse().path give something like # /path/to/file-version.tar.gz@@ -272,8 +266,8 @@ class BuildrootPackage(): try: print('Downloading package {pkg} from {url}...'.format( pkg=self.real_name, url=download_url['url'])) - download = six.moves.urllib.request.urlopen(download_url['url']) - except six.moves.urllib.error.HTTPError as http_error: + download = urllib.request.urlopen(download_url['url']) + except urllib.error.HTTPError as http_error: download = http_error else: self.used_url = download_url@@ -288,7 +282,7 @@ class BuildrootPackage(): raise DownloadFailed('Failed to download package {pkg}: ' 'No source archive available' .format(pkg=self.real_name)) - elif download.__class__ == six.moves.urllib.error.HTTPError: + elif download.__class__ == urllib.error.HTTPError: raise download self.filename = self.used_url['filename']@@ -317,10 +311,7 @@ class BuildrootPackage(): Keyword arguments: tmp_path -- directory where you want the package to be extracted """ - if six.PY2: - as_file = StringIO.StringIO(self.as_string) - else: - as_file = io.BytesIO(self.as_string) + as_file = io.BytesIO(self.as_string) if self.filename[-3:] == 'zip': with zipfile.ZipFile(as_file) as as_zipfile: tmp_pkg = os.path.join(tmp_path, self.buildroot_name)@@ -797,12 +788,12 @@ def main(): print('Fetching package', package.real_name) try: package.fetch_package_info() - except (six.moves.urllib.error.URLError, six.moves.urllib.error.HTTPError): + except (urllib.error.URLError, urllib.error.HTTPError): continue try: 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, reason=error.reason)) print('Error downloading package :', package.buildroot_name)Signature · 6 lines
2.43.0 _______________________________________________ buildroot mailing list [email protected] https://lists.buildroot.org/mailman/listinfo/buildroot
_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot