From 8eb775a8a508849cb6c525c599593e5c68ed0f14 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Tue, 25 Jun 2024 11:55:22 -0500 Subject: [PATCH 1/2] Remove more Python 2 artifacts We no longer support Python 2 in rosdistro so there's no reason to carry these snippets anymore. --- scripts/rosdistro_build_cache | 8 +------- scripts/rosdistro_convert | 7 +------ scripts/rosdistro_freeze_source | 2 -- scripts/rosdistro_migrate_to_rep_141 | 2 -- scripts/rosdistro_migrate_to_rep_143 | 2 -- src/rosdistro/__init__.py | 2 -- src/rosdistro/aptdistro.py | 5 +---- src/rosdistro/common.py | 2 -- src/rosdistro/develdistro.py | 6 ++---- src/rosdistro/distribution_cache.py | 7 ------- src/rosdistro/distribution_cache_generator.py | 9 +-------- src/rosdistro/freeze_source.py | 7 ------- src/rosdistro/legacy.py | 2 -- src/rosdistro/loader.py | 14 ++++---------- src/rosdistro/manifest_provider/bitbucket.py | 9 ++------- src/rosdistro/manifest_provider/cache.py | 18 ++---------------- src/rosdistro/manifest_provider/github.py | 9 ++------- src/rosdistro/manifest_provider/tar.py | 13 ++----------- src/rosdistro/release_cache.py | 2 -- src/rosdistro/release_cache_generator.py | 2 -- src/rosdistro/rosdistro.py | 10 ++-------- src/rosdistro/verify.py | 2 -- src/rosdistro/writer.py | 2 -- test/test_manifest_providers.py | 14 ++++---------- 24 files changed, 24 insertions(+), 132 deletions(-) diff --git a/scripts/rosdistro_build_cache b/scripts/rosdistro_build_cache index e66077128..da8b955f3 100755 --- a/scripts/rosdistro_build_cache +++ b/scripts/rosdistro_build_cache @@ -33,8 +33,6 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import print_function - import argparse import gzip import logging @@ -94,11 +92,7 @@ def main(): # write the cache data = yaml.dump(cache.get_data(), Dumper=CacheYamlDumper) - # On Python 3, we must encode the unicode yaml str prior to writing it, - # whereas for Python 2, the yaml output is a str which cannot be further - # encoded (compared with a unicode object). - if sys.version_info[0] >= 3: - data = data.encode('utf-8') + data = data.encode('utf-8') with open('%s-cache.yaml' % dist_name, 'wb') as f: print('- write cache file "%s-cache.yaml"' % dist_name) diff --git a/scripts/rosdistro_convert b/scripts/rosdistro_convert index c511b52bb..bdb0c1c8f 100755 --- a/scripts/rosdistro_convert +++ b/scripts/rosdistro_convert @@ -33,16 +33,11 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import print_function - import os import subprocess import sys import tempfile -try: - from urllib.error import HTTPError -except ImportError: - from urllib2 import HTTPError +from urllib.error import HTTPError from rosdistro.common import rmtree from rosdistro.loader import load_url diff --git a/scripts/rosdistro_freeze_source b/scripts/rosdistro_freeze_source index d698f8488..4182cd6ee 100755 --- a/scripts/rosdistro_freeze_source +++ b/scripts/rosdistro_freeze_source @@ -33,8 +33,6 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import print_function - import argparse import os.path import sys diff --git a/scripts/rosdistro_migrate_to_rep_141 b/scripts/rosdistro_migrate_to_rep_141 index 2596b73e6..c0f331a91 100755 --- a/scripts/rosdistro_migrate_to_rep_141 +++ b/scripts/rosdistro_migrate_to_rep_141 @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -from __future__ import print_function - import argparse import gzip import os diff --git a/scripts/rosdistro_migrate_to_rep_143 b/scripts/rosdistro_migrate_to_rep_143 index d2d6a7780..e3dd3605b 100755 --- a/scripts/rosdistro_migrate_to_rep_143 +++ b/scripts/rosdistro_migrate_to_rep_143 @@ -1,7 +1,5 @@ #!/usr/bin/env python3 -from __future__ import print_function - import argparse from rosdistro.verify import _yaml_header_lines diff --git a/src/rosdistro/__init__.py b/src/rosdistro/__init__.py index a7044c8f0..41cfa06ba 100644 --- a/src/rosdistro/__init__.py +++ b/src/rosdistro/__init__.py @@ -31,8 +31,6 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import print_function - import gzip import logging import os diff --git a/src/rosdistro/aptdistro.py b/src/rosdistro/aptdistro.py index 2fb77cc4d..38199c63c 100644 --- a/src/rosdistro/aptdistro.py +++ b/src/rosdistro/aptdistro.py @@ -1,7 +1,4 @@ -try: - from urllib2 import urlopen -except ImportError: - from urllib.request import urlopen +from urllib.request import urlopen class AptDistro: diff --git a/src/rosdistro/common.py b/src/rosdistro/common.py index a7d381a38..4a94a7cc1 100644 --- a/src/rosdistro/common.py +++ b/src/rosdistro/common.py @@ -1,5 +1,3 @@ -from __future__ import print_function - from errno import EACCES, EPERM import os import shutil diff --git a/src/rosdistro/develdistro.py b/src/rosdistro/develdistro.py index 4c388eae2..442b87163 100644 --- a/src/rosdistro/develdistro.py +++ b/src/rosdistro/develdistro.py @@ -1,7 +1,5 @@ -try: - from urllib.request import urlopen -except ImportError: - from urllib2 import urlopen +from urllib.request import urlopen + import yaml diff --git a/src/rosdistro/distribution_cache.py b/src/rosdistro/distribution_cache.py index 90281ffeb..42f416a13 100644 --- a/src/rosdistro/distribution_cache.py +++ b/src/rosdistro/distribution_cache.py @@ -31,8 +31,6 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import print_function - import sys from . import logger @@ -71,11 +69,6 @@ def __init__(self, name, data=None, distribution_file_data=None): self.source_repo_package_xmls[repo_name] = SourceRepositoryCache(repo_data) self.distribution_file.source_packages = self.get_source_packages() - # if Python 2 has converted the xml to unicode, convert it back - for k, v in self.release_package_xmls.items(): - if not isinstance(v, str) and not isinstance(v, bytes): - self.release_package_xmls[k] = v.encode('utf-8') - def get_data(self): data = {} data['type'] = 'cache' diff --git a/src/rosdistro/distribution_cache_generator.py b/src/rosdistro/distribution_cache_generator.py index 3e4e94ea6..8646fe556 100644 --- a/src/rosdistro/distribution_cache_generator.py +++ b/src/rosdistro/distribution_cache_generator.py @@ -31,8 +31,6 @@ # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import print_function - import gzip import os import re @@ -155,12 +153,7 @@ def __init__(self, *args, **kwargs): def ignore_aliases(self, content): """ Allow strings that look like package XML to alias to each other in the YAML output. """ - try: - basestring - except NameError: - # Python 3 - basestring = str - return not (isinstance(content, basestring) and 'abc' in sanitize_xml('abc') assert 'ab c' in sanitize_xml(' ab c ') - # This unicode check should be valid on both Python 2 and 3. + # This unicode check should be valid. assert 'français' in sanitize_xml(' français ') # subsequent parse calls will collapse empty tags, therefore sanitize should do the same From a1b4ba8448815983f8022601a2d58b4c00c42ddf Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Tue, 25 Jun 2024 13:40:51 -0500 Subject: [PATCH 2/2] PR feedback Co-authored-by: Mike Purvis --- scripts/rosdistro_build_cache | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/scripts/rosdistro_build_cache b/scripts/rosdistro_build_cache index da8b955f3..a344373d0 100755 --- a/scripts/rosdistro_build_cache +++ b/scripts/rosdistro_build_cache @@ -90,9 +90,7 @@ def main(): if args.dist_names and dist_name not in args.dist_names: continue # write the cache - data = yaml.dump(cache.get_data(), Dumper=CacheYamlDumper) - - data = data.encode('utf-8') + data = yaml.dump(cache.get_data(), Dumper=CacheYamlDumper).encode() with open('%s-cache.yaml' % dist_name, 'wb') as f: print('- write cache file "%s-cache.yaml"' % dist_name)