From 6a3e5a28e68725c0aa888eff884790ca13d69f0d Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Fri, 21 Jun 2024 13:02:41 -0500 Subject: [PATCH 1/3] Remove more Python 2 artifacts (#973) --- src/rosdep2/__init__.py | 2 -- src/rosdep2/catkin_packages.py | 2 -- src/rosdep2/catkin_support.py | 2 -- src/rosdep2/core.py | 2 -- src/rosdep2/install.py | 2 -- src/rosdep2/installers.py | 2 -- src/rosdep2/lookup.py | 2 -- src/rosdep2/main.py | 2 -- src/rosdep2/meta.py | 7 ------- src/rosdep2/platforms/arch.py | 1 - src/rosdep2/platforms/cygwin.py | 2 -- src/rosdep2/platforms/debian.py | 1 - src/rosdep2/platforms/gem.py | 2 -- src/rosdep2/platforms/npm.py | 2 -- src/rosdep2/platforms/pip.py | 2 -- src/rosdep2/platforms/redhat.py | 1 - src/rosdep2/platforms/source.py | 2 -- src/rosdep2/rospack.py | 2 -- src/rosdep2/rospkg_loader.py | 2 -- src/rosdep2/shell_utils.py | 2 -- src/rosdep2/sources_list.py | 2 -- test/test_flake8.py | 8 +++----- test/test_metadata.py | 22 +--------------------- test/test_rosdep.py | 2 -- test/test_rosdep_installers.py | 2 -- test/test_rosdep_lookup.py | 2 -- 26 files changed, 4 insertions(+), 76 deletions(-) diff --git a/src/rosdep2/__init__.py b/src/rosdep2/__init__.py index 9bb29b63f..9b21aa434 100644 --- a/src/rosdep2/__init__.py +++ b/src/rosdep2/__init__.py @@ -31,8 +31,6 @@ rosdep library and command-line tool """ -from __future__ import print_function - from ._version import __version__ import sys diff --git a/src/rosdep2/catkin_packages.py b/src/rosdep2/catkin_packages.py index 3d8b72c60..8dc1342b8 100644 --- a/src/rosdep2/catkin_packages.py +++ b/src/rosdep2/catkin_packages.py @@ -1,5 +1,3 @@ -from __future__ import print_function - import os import sys diff --git a/src/rosdep2/catkin_support.py b/src/rosdep2/catkin_support.py index 4fb3fb3b8..cea367c06 100644 --- a/src/rosdep2/catkin_support.py +++ b/src/rosdep2/catkin_support.py @@ -15,8 +15,6 @@ """ -from __future__ import print_function - import os from subprocess import Popen, PIPE, CalledProcessError diff --git a/src/rosdep2/core.py b/src/rosdep2/core.py index 07f318de2..f3758ad76 100644 --- a/src/rosdep2/core.py +++ b/src/rosdep2/core.py @@ -25,8 +25,6 @@ # ARISING IN 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 sys import traceback diff --git a/src/rosdep2/install.py b/src/rosdep2/install.py index b092669e1..a22ee0067 100644 --- a/src/rosdep2/install.py +++ b/src/rosdep2/install.py @@ -29,8 +29,6 @@ Script for installing rdmanifest-described resources """ -from __future__ import print_function - import os import sys from optparse import OptionParser diff --git a/src/rosdep2/installers.py b/src/rosdep2/installers.py index 342df780e..62f267b61 100644 --- a/src/rosdep2/installers.py +++ b/src/rosdep2/installers.py @@ -27,8 +27,6 @@ # Author Tully Foote/tfoote@willowgarage.com, Ken Conley/kwc@willowgarage.com -from __future__ import print_function - import os import subprocess import traceback diff --git a/src/rosdep2/lookup.py b/src/rosdep2/lookup.py index 77f6f24f3..52892e265 100644 --- a/src/rosdep2/lookup.py +++ b/src/rosdep2/lookup.py @@ -27,8 +27,6 @@ # Author Tully Foote/tfoote@willowgarage.com, Ken Conley/kwc@willowgarage.com -from __future__ import print_function - import sys import yaml diff --git a/src/rosdep2/main.py b/src/rosdep2/main.py index 9240e53ea..51f942955 100644 --- a/src/rosdep2/main.py +++ b/src/rosdep2/main.py @@ -31,8 +31,6 @@ Command-line interface to rosdep library """ -from __future__ import print_function - import errno import os import sys diff --git a/src/rosdep2/meta.py b/src/rosdep2/meta.py index b8cd9006b..5e748fcd8 100644 --- a/src/rosdep2/meta.py +++ b/src/rosdep2/meta.py @@ -32,13 +32,6 @@ except ImportError: import pickle -try: - FileNotFoundError -except NameError: - # Python 2 compatibility - # https://stackoverflow.com/questions/21367320/ - FileNotFoundError = IOError - import rospkg from ._version import __version__ diff --git a/src/rosdep2/platforms/arch.py b/src/rosdep2/platforms/arch.py index d9301f43d..7ec70c71a 100644 --- a/src/rosdep2/platforms/arch.py +++ b/src/rosdep2/platforms/arch.py @@ -27,7 +27,6 @@ # Author Tully Foote/tfoote@willowgarage.com -from __future__ import print_function import subprocess import sys diff --git a/src/rosdep2/platforms/cygwin.py b/src/rosdep2/platforms/cygwin.py index 2808f1dc3..76050498d 100644 --- a/src/rosdep2/platforms/cygwin.py +++ b/src/rosdep2/platforms/cygwin.py @@ -27,8 +27,6 @@ # Tingfan Wu tingfan@gmail.com -from __future__ import print_function - from rospkg.os_detect import OS_CYGWIN from .source import SOURCE_INSTALLER diff --git a/src/rosdep2/platforms/debian.py b/src/rosdep2/platforms/debian.py index 8bb78c5b2..14f36fc6d 100644 --- a/src/rosdep2/platforms/debian.py +++ b/src/rosdep2/platforms/debian.py @@ -27,7 +27,6 @@ # Author Tully Foote, Ken Conley -from __future__ import print_function import subprocess import sys diff --git a/src/rosdep2/platforms/gem.py b/src/rosdep2/platforms/gem.py index 6a8ece812..ec1f669e3 100644 --- a/src/rosdep2/platforms/gem.py +++ b/src/rosdep2/platforms/gem.py @@ -28,8 +28,6 @@ # Author Ruben Smits/ruben.smits@intermodalics.eu -from __future__ import print_function - import subprocess from ..core import InstallFailed diff --git a/src/rosdep2/platforms/npm.py b/src/rosdep2/platforms/npm.py index 279229424..1c9b41cf0 100644 --- a/src/rosdep2/platforms/npm.py +++ b/src/rosdep2/platforms/npm.py @@ -26,8 +26,6 @@ # ARISING IN 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 diff --git a/src/rosdep2/platforms/pip.py b/src/rosdep2/platforms/pip.py index 8ca4ba03a..5c2db4152 100644 --- a/src/rosdep2/platforms/pip.py +++ b/src/rosdep2/platforms/pip.py @@ -27,8 +27,6 @@ # Author Tully Foote/tfoote@willowgarage.com -from __future__ import print_function - import os import subprocess import sys diff --git a/src/rosdep2/platforms/redhat.py b/src/rosdep2/platforms/redhat.py index 687f11e8b..d9c8faffd 100644 --- a/src/rosdep2/platforms/redhat.py +++ b/src/rosdep2/platforms/redhat.py @@ -27,7 +27,6 @@ # Author Tully Foote/tfoote@willowgarage.com -from __future__ import print_function import subprocess import sys diff --git a/src/rosdep2/platforms/source.py b/src/rosdep2/platforms/source.py index b3dcf3e7d..82084042b 100644 --- a/src/rosdep2/platforms/source.py +++ b/src/rosdep2/platforms/source.py @@ -27,8 +27,6 @@ # Author Tully Foote/tfoote@willowgarage.com -from __future__ import print_function - import os try: from urllib.request import urlretrieve diff --git a/src/rosdep2/rospack.py b/src/rosdep2/rospack.py index c51044994..661e1618a 100644 --- a/src/rosdep2/rospack.py +++ b/src/rosdep2/rospack.py @@ -32,8 +32,6 @@ is a ROSpackage or a system dependency """ -from __future__ import print_function - import subprocess from .main import _get_default_RosdepLookup diff --git a/src/rosdep2/rospkg_loader.py b/src/rosdep2/rospkg_loader.py index af9affe99..def3406fe 100644 --- a/src/rosdep2/rospkg_loader.py +++ b/src/rosdep2/rospkg_loader.py @@ -32,8 +32,6 @@ filesystem. """ -from __future__ import print_function - import os import catkin_pkg.package diff --git a/src/rosdep2/shell_utils.py b/src/rosdep2/shell_utils.py index 70b42fd5d..6d36fab31 100644 --- a/src/rosdep2/shell_utils.py +++ b/src/rosdep2/shell_utils.py @@ -27,8 +27,6 @@ # Author Tully Foote/tfoote@willowgarage.com -from __future__ import print_function - import os import sys import stat diff --git a/src/rosdep2/sources_list.py b/src/rosdep2/sources_list.py index 3339fe39c..85d0bc193 100644 --- a/src/rosdep2/sources_list.py +++ b/src/rosdep2/sources_list.py @@ -27,8 +27,6 @@ # Author Ken Conley/kwc@willowgarage.com -from __future__ import print_function - import os import sys import yaml diff --git a/test/test_flake8.py b/test/test_flake8.py index ebb90fc6c..c2c14da74 100644 --- a/test/test_flake8.py +++ b/test/test_flake8.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -from __future__ import print_function - import os import subprocess import sys @@ -28,9 +26,9 @@ def test_flake8(): # See: https://flake8.pycqa.org/en/latest/user/python-api.html # Calling through subprocess is the most stable way to run it. - # We still need to support Python 2.7, so we can't use run() - ret_code = subprocess.call( + result = subprocess.run( [sys.executable, "-m", "flake8"], cwd=os.path.dirname(os.path.dirname(__file__)), + check=False, ) - assert 0 == ret_code, "flake8 found violations" + assert 0 == result.returncode, "flake8 found violations" diff --git a/test/test_metadata.py b/test/test_metadata.py index 424a5acc0..240eb9ebe 100644 --- a/test/test_metadata.py +++ b/test/test_metadata.py @@ -25,29 +25,9 @@ # ARISING IN 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 sys - -try: - from tempfile import TemporaryDirectory -except ImportError: - import tempfile - import shutil - - class TemporaryDirectory(object): - """Python 2 compatible class.""" - - def __init__(self): - self.name = None - - def __enter__(self): - self.name = tempfile.mkdtemp() - return self.name - - def __exit__(self, t, v, tb): - shutil.rmtree(self.name) +from tempfile import TemporaryDirectory from rosdep2.meta import MetaDatabase diff --git a/test/test_rosdep.py b/test/test_rosdep.py index fee1c334b..9d6f99ee1 100644 --- a/test/test_rosdep.py +++ b/test/test_rosdep.py @@ -25,8 +25,6 @@ # ARISING IN 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 sys diff --git a/test/test_rosdep_installers.py b/test/test_rosdep_installers.py index 5638d9caa..a19dcf2f4 100644 --- a/test/test_rosdep_installers.py +++ b/test/test_rosdep_installers.py @@ -25,8 +25,6 @@ # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE # POSSIBILITY OF SUCH DAMAGE. -from __future__ import print_function - from contextlib import contextmanager from unittest import SkipTest from unittest.mock import Mock, patch diff --git a/test/test_rosdep_lookup.py b/test/test_rosdep_lookup.py index 176abd0d0..edf22771b 100644 --- a/test/test_rosdep_lookup.py +++ b/test/test_rosdep_lookup.py @@ -25,8 +25,6 @@ # ARISING IN 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 yaml From fbce4d416706c8d74b06bb92b1fbefc76ea11a22 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Fri, 21 Jun 2024 13:06:06 -0500 Subject: [PATCH 2/3] Un-pin flake8 and resolve new violations (#975) --- setup.py | 2 +- src/rosdep2/catkin_packages.py | 2 +- src/rosdep2/gbpdistro_support.py | 8 ++++---- src/rosdep2/installers.py | 6 +++--- src/rosdep2/lookup.py | 10 +++++----- src/rosdep2/main.py | 6 +++--- src/rosdep2/platforms/osx.py | 2 +- src/rosdep2/rep3.py | 2 +- src/rosdep2/sources_list.py | 4 ++-- test/test_rosdep_source.py | 4 ++-- 10 files changed, 23 insertions(+), 23 deletions(-) diff --git a/setup.py b/setup.py index addc1bd77..db12d0f69 100644 --- a/setup.py +++ b/setup.py @@ -16,7 +16,7 @@ 'python_requires': '>=3.6', 'extras_require': { 'test': [ - 'flake8 < 6', + 'flake8', 'flake8-comprehensions', 'pytest', ], diff --git a/src/rosdep2/catkin_packages.py b/src/rosdep2/catkin_packages.py index 8dc1342b8..e232d2ee2 100644 --- a/src/rosdep2/catkin_packages.py +++ b/src/rosdep2/catkin_packages.py @@ -31,7 +31,7 @@ def find_catkin_packages_in(path, verbose=False): print('found in cache.', file=sys.stderr) return _catkin_packages_cache[path] packages = find_packages(path) - if type(packages) == dict and packages != {}: + if type(packages) is dict and packages != {}: package_names = [package.name for package in packages.values()] if verbose: print('found ' + str(len(packages)) + ' packages.') diff --git a/src/rosdep2/gbpdistro_support.py b/src/rosdep2/gbpdistro_support.py index 0b523c6d5..be4936147 100644 --- a/src/rosdep2/gbpdistro_support.py +++ b/src/rosdep2/gbpdistro_support.py @@ -74,9 +74,9 @@ def gbprepo_to_rosdep_data(gbpdistro_data, targets_data, url=''): # (e.g. doesn't separate gbpdistro vs. targets, nor provide # origin), but rushing this implementation a bit. try: - if not type(targets_data) == dict: + if not type(targets_data) is dict: raise InvalidData('targets data must be a dict') - if not type(gbpdistro_data) == dict: + if not type(gbpdistro_data) is dict: raise InvalidData('gbpdistro data must be a dictionary') if gbpdistro_data['type'] != 'gbp': raise InvalidData('gbpdistro must be of type "gbp"') @@ -94,11 +94,11 @@ def gbprepo_to_rosdep_data(gbpdistro_data, targets_data, url=''): rosdep_data = {} gbp_repos = gbpdistro_data['repositories'] # Ensure gbp_repos is a dict - if type(gbp_repos) != dict: + if type(gbp_repos) is not dict: raise InvalidData('invalid repo spec in gbpdistro data: ' + str(gbp_repos) + '. Invalid repositories entry, must be dict.') for rosdep_key, repo in gbp_repos.items(): - if type(repo) != dict: + if type(repo) is not dict: raise InvalidData('invalid repo spec in gbpdistro data: ' + str(repo)) diff --git a/src/rosdep2/installers.py b/src/rosdep2/installers.py index 62f267b61..20a996d06 100644 --- a/src/rosdep2/installers.py +++ b/src/rosdep2/installers.py @@ -339,13 +339,13 @@ def resolve(self, rosdep_args): See :meth:`Installer.resolve()` """ packages = None - if type(rosdep_args) == dict: + if type(rosdep_args) is dict: packages = rosdep_args.get('packages', []) if isinstance(packages, str): packages = packages.split() elif isinstance(rosdep_args, str): packages = rosdep_args.split(' ') - elif type(rosdep_args) == list: + elif type(rosdep_args) is list: packages = rosdep_args else: raise InvalidData('Invalid rosdep args: %s' % (rosdep_args)) @@ -397,7 +397,7 @@ def get_depends(self, rosdep_args): necessary if the package manager doesn't handle dependencies. """ - if self.supports_depends and type(rosdep_args) == dict: + if self.supports_depends and type(rosdep_args) is dict: return rosdep_args.get('depends', []) return [] # Default return empty list diff --git a/src/rosdep2/lookup.py b/src/rosdep2/lookup.py index 52892e265..abe7e45bf 100644 --- a/src/rosdep2/lookup.py +++ b/src/rosdep2/lookup.py @@ -100,12 +100,12 @@ def get_rule_for_platform(self, os_name, os_version, installer_keys, default_ins queried_os = os_name queried_ver = os_version - if type(data) != dict: + if type(data) is not dict: raise InvalidData('rosdep value for [%s] must be a dictionary' % (self.rosdep_key), origin=self.origin) if os_name not in data: if '*' not in data: raise ResolutionError(rosdep_key, data, queried_os, queried_ver, 'No definition of [%s] for OS [%s]' % (rosdep_key, os_name)) - elif type(data['*']) != dict: + elif type(data['*']) is not dict: raise InvalidData('rosdep value under OS wildcard for [%s] must specify a package manager' % (rosdep_key)) os_name = '*' data = data[os_name] @@ -114,7 +114,7 @@ def get_rule_for_platform(self, os_name, os_version, installer_keys, default_ins # REP 111: rosdep first interprets the key as a # PACKAGE_MANAGER. If this test fails, it will be interpreted # as an OS_VERSION_CODENAME. - if type(data) == dict: + if type(data) is dict: for installer_key in installer_keys: if installer_key in data: data = data[installer_key] @@ -122,7 +122,7 @@ def get_rule_for_platform(self, os_name, os_version, installer_keys, default_ins break else: # data must be a dictionary, string, or list - if type(data) == dict: + if type(data) is dict: # check for # hardy: # apt: @@ -141,7 +141,7 @@ def get_rule_for_platform(self, os_name, os_version, installer_keys, default_ins if os_version not in data: os_version = '*' data = data[os_version] - if type(data) == dict: + if type(data) is dict: for installer_key in installer_keys: if installer_key in data: data = data[installer_key] diff --git a/src/rosdep2/main.py b/src/rosdep2/main.py index 51f942955..2bf653515 100644 --- a/src/rosdep2/main.py +++ b/src/rosdep2/main.py @@ -63,9 +63,9 @@ from .lookup import RosdepLookup, ResolutionError, prune_catkin_packages from .meta import MetaDatabase from .rospkg_loader import DEFAULT_VIEW_KEY -from .sources_list import update_sources_list, get_sources_cache_dir,\ - download_default_sources_list, SourcesListLoader, CACHE_INDEX,\ - get_sources_list_dir, get_default_sources_list_file,\ +from .sources_list import update_sources_list, get_sources_cache_dir, \ + download_default_sources_list, SourcesListLoader, CACHE_INDEX, \ + get_sources_list_dir, get_default_sources_list_file, \ DEFAULT_SOURCES_LIST_URL from .rosdistrohelper import PreRep137Warning diff --git a/src/rosdep2/platforms/osx.py b/src/rosdep2/platforms/osx.py index e789dc9c7..f137822b9 100644 --- a/src/rosdep2/platforms/osx.py +++ b/src/rosdep2/platforms/osx.py @@ -323,7 +323,7 @@ def handle_options(options): if packages: options = [] install_flags = [] - if type(rosdep_args) == dict: + if type(rosdep_args) is dict: options = coerce_to_list(rosdep_args.get('options', [])) install_flags = coerce_to_list(rosdep_args.get('install_flags', [])) diff --git a/src/rosdep2/rep3.py b/src/rosdep2/rep3.py index 0c17a8faa..fb6c93e18 100644 --- a/src/rosdep2/rep3.py +++ b/src/rosdep2/rep3.py @@ -62,7 +62,7 @@ def download_targets_data(targets_url=None): targets_data = yaml.safe_load(text) except Exception as e: raise DownloadFailure('Failed to download target platform data for gbpdistro:\n\t%s' % (str(e))) - if type(targets_data) == list: + if type(targets_data) is list: # convert to dictionary new_targets_data = {} for t in targets_data: diff --git a/src/rosdep2/sources_list.py b/src/rosdep2/sources_list.py index 85d0bc193..fd62532cd 100644 --- a/src/rosdep2/sources_list.py +++ b/src/rosdep2/sources_list.py @@ -142,7 +142,7 @@ def __init__(self, type_, url, tags, origin=None): parsed = urlparse.urlparse(url) if not parsed.scheme or (parsed.scheme != 'file' and not parsed.netloc) or parsed.path in ('', '/'): raise ValueError('url must be a fully-specified URL with scheme, hostname, and path: %s' % (str(url))) - if not type(tags) == list: + if not type(tags) is list: raise ValueError('tags must be a list: %s' % (str(tags))) self.type = type_ @@ -302,7 +302,7 @@ def download_rosdep_data(url): text = f.read() f.close() data = yaml.safe_load(text) - if type(data) != dict: + if type(data) is not dict: raise DownloadFailure('rosdep data from [%s] is not a YAML dictionary' % (url)) return data except (URLError, httplib.HTTPException) as e: diff --git a/test/test_rosdep_source.py b/test/test_rosdep_source.py index 1c24944bd..d0a8ae18d 100644 --- a/test/test_rosdep_source.py +++ b/test/test_rosdep_source.py @@ -215,7 +215,7 @@ def test_SourceInstaller_resolve(): pass resolved = installer.resolve(dict(uri=url, md5sum=md5sum_good)) - assert type(resolved) == list + assert type(resolved) is list assert len(resolved) == 1 # test for reinstall (to check the depends in rdmanifest) dependencies = installer.get_depends(dict(uri=url, md5sum=md5sum_good)) @@ -227,7 +227,7 @@ def test_SourceInstaller_resolve(): # test again to activate caching resolved = installer.resolve(dict(uri=url, md5sum=md5sum_good)) - assert type(resolved) == list, 'Cache should also return a list' + assert type(resolved) is list, 'Cache should also return a list' assert len(resolved) == 1 resolved = resolved[0] assert resolved.install_command == rep122_install_command From d56814c135c0eddd67752b0bf16306e54462b80a Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Fri, 21 Jun 2024 13:23:23 -0500 Subject: [PATCH 3/3] Updates to run and pass flake8-builtins (#974) There are flake8-builtins violations which appear as part of rosdep's public API. We'll supporess those to avoid breaking API, but still add the linter plugin so we don't regress more. --- setup.py | 1 + src/rosdep2/meta.py | 2 +- src/rosdep2/sources_list.py | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/setup.py b/setup.py index db12d0f69..43058a1fd 100644 --- a/setup.py +++ b/setup.py @@ -17,6 +17,7 @@ 'extras_require': { 'test': [ 'flake8', + 'flake8-builtins', 'flake8-comprehensions', 'pytest', ], diff --git a/src/rosdep2/meta.py b/src/rosdep2/meta.py index 5e748fcd8..697217588 100644 --- a/src/rosdep2/meta.py +++ b/src/rosdep2/meta.py @@ -88,7 +88,7 @@ def __init__(self, cache_dir=None): self._cache_dir = cache_dir self._loaded = {} - def set(self, category, metadata): + def set(self, category, metadata): # noqa: A003 """Add or overwrite metadata in the cache.""" wrapper = CacheWrapper(category, metadata) # print(category, metadata) diff --git a/src/rosdep2/sources_list.py b/src/rosdep2/sources_list.py index fd62532cd..8c98f2e26 100644 --- a/src/rosdep2/sources_list.py +++ b/src/rosdep2/sources_list.py @@ -229,8 +229,8 @@ def __str__(self): def __repr__(self): return repr((self.type, self.url, self.tags, self.rosdep_data, self.origin)) - @property - def type(self): + @property # noqa: A003 + def type(self): # noqa: A003 """ :returns: data source type """