From 78a3d2cf4872fae8eda61c72fef557e87b411b07 Mon Sep 17 00:00:00 2001 From: Scott K Logan Date: Fri, 21 Jun 2024 13:28:09 -0500 Subject: [PATCH] Updates to run and pass flake8-quotes linter (#972) We use this linter plugin elsewhere in the ROS world, so it would be nice to pass the tests here too. --- setup.py | 1 + src/rosdep2/install.py | 6 +++--- src/rosdep2/main.py | 2 +- src/rosdep2/platforms/alpine.py | 2 +- src/rosdep2/platforms/debian.py | 8 ++++---- src/rosdep2/platforms/freebsd.py | 2 +- src/rosdep2/platforms/openembedded.py | 2 +- src/rosdep2/platforms/redhat.py | 4 ++-- src/rosdep2/url_utils.py | 2 +- test/test_flake8.py | 4 ++-- test/test_rosdep_main.py | 4 ++-- 11 files changed, 19 insertions(+), 18 deletions(-) diff --git a/setup.py b/setup.py index 43058a1fd..2e9aebfd6 100644 --- a/setup.py +++ b/setup.py @@ -19,6 +19,7 @@ 'flake8', 'flake8-builtins', 'flake8-comprehensions', + 'flake8-quotes', 'pytest', ], }, diff --git a/src/rosdep2/install.py b/src/rosdep2/install.py index a22ee0067..e30783262 100644 --- a/src/rosdep2/install.py +++ b/src/rosdep2/install.py @@ -40,10 +40,10 @@ def install_main(): - parser = OptionParser(usage="usage: %prog install ", prog=NAME) + parser = OptionParser(usage='usage: %prog install ', prog=NAME) options, args = parser.parse_args() if len(args) != 2: - parser.error("please specify one and only one rdmanifest url") + parser.error('please specify one and only one rdmanifest url') if args[0] != 'install': parser.error("currently only support the 'install' command") rdmanifest_url = args[1] @@ -53,5 +53,5 @@ def install_main(): else: source.install_from_url(rdmanifest_url) except InstallFailed as e: - print("ERROR: installation failed:\n%s" % e, file=sys.stderr) + print('ERROR: installation failed:\n%s' % e, file=sys.stderr) sys.exit(1) diff --git a/src/rosdep2/main.py b/src/rosdep2/main.py index 2bf653515..c059ebd42 100644 --- a/src/rosdep2/main.py +++ b/src/rosdep2/main.py @@ -378,7 +378,7 @@ def _rosdep_main(args): 'If specified end-of-life distros are being ' 'fetched too.') parser.add_option('-t', '--dependency-types', dest='dependency_types', - type="choice", choices=list(VALID_DEPENDENCY_TYPES), + type='choice', choices=list(VALID_DEPENDENCY_TYPES), default=[], action='append', help='Dependency types to install, can be given multiple times. ' 'Choose from {}. Default: all except doc.'.format(VALID_DEPENDENCY_TYPES)) diff --git a/src/rosdep2/platforms/alpine.py b/src/rosdep2/platforms/alpine.py index 73ff61353..b5f5c8007 100644 --- a/src/rosdep2/platforms/alpine.py +++ b/src/rosdep2/platforms/alpine.py @@ -48,7 +48,7 @@ def register_platforms(context): context.add_os_installer_key(OS_ALPINE, PIP_INSTALLER) context.add_os_installer_key(OS_ALPINE, SOURCE_INSTALLER) context.set_default_os_installer_key(OS_ALPINE, lambda self: APK_INSTALLER) - context.set_os_version_type(OS_ALPINE, lambda self: ".".join(self.get_version().split('.')[:2])) + context.set_os_version_type(OS_ALPINE, lambda self: '.'.join(self.get_version().split('.')[:2])) def apk_detect(pkgs, exec_fn=read_stdout): diff --git a/src/rosdep2/platforms/debian.py b/src/rosdep2/platforms/debian.py index 14f36fc6d..de79a43ea 100644 --- a/src/rosdep2/platforms/debian.py +++ b/src/rosdep2/platforms/debian.py @@ -108,8 +108,8 @@ def register_mx(context): print('rosdep detected OS: [%s] aliasing it to: [%s]' % (OS_MX, OS_DEBIAN), file=sys.stderr) release_info = read_os_release() - version = read_os_release()["VERSION"] - context.set_os_override(OS_DEBIAN, version[version.find("(") + 1:version.find(")")]) + version = read_os_release()['VERSION'] + context.set_os_override(OS_DEBIAN, version[version.find('(') + 1:version.find(')')]) def register_pop(context): @@ -239,13 +239,13 @@ def dpkg_detect(pkgs, exec_fn=None): version_lock_map[p.split('=')[0]] = p else: version_lock_map[p] = p - cmd = ['dpkg-query', '-W', '-f=\'${Package} ${Status}\n\''] + cmd = ['dpkg-query', '-W', "-f='${Package} ${Status}\n'"] cmd.extend(version_lock_map.keys()) if exec_fn is None: exec_fn = read_stdout std_out, std_err = exec_fn(cmd, True) - std_out = std_out.replace('\'', '') + std_out = std_out.replace("'", '') pkg_list = std_out.split('\n') for pkg in pkg_list: pkg_row = pkg.split() diff --git a/src/rosdep2/platforms/freebsd.py b/src/rosdep2/platforms/freebsd.py index ee0e57d10..cc3ef671d 100644 --- a/src/rosdep2/platforms/freebsd.py +++ b/src/rosdep2/platforms/freebsd.py @@ -49,7 +49,7 @@ def register_platforms(context): def pkg_detect_single(p, exec_fn): - if p == "builtin": + if p == 'builtin': return True cmd = ['/usr/sbin/pkg', 'query', '%n', p] diff --git a/src/rosdep2/platforms/openembedded.py b/src/rosdep2/platforms/openembedded.py index cd7c8e50a..68ac4e058 100644 --- a/src/rosdep2/platforms/openembedded.py +++ b/src/rosdep2/platforms/openembedded.py @@ -56,7 +56,7 @@ def opkg_detect(pkgs, exec_fn=None): :param exec_fn: function to execute Popen and read stdout (for testing) :return: list elements in *pkgs* that were found installed on the system """ - raise NotImplementedError("opkg_detect is not implemented yet") + raise NotImplementedError('opkg_detect is not implemented yet') class OpkgInstaller(PackageManagerInstaller): diff --git a/src/rosdep2/platforms/redhat.py b/src/rosdep2/platforms/redhat.py index d9c8faffd..8f2ce093f 100644 --- a/src/rosdep2/platforms/redhat.py +++ b/src/rosdep2/platforms/redhat.py @@ -140,7 +140,7 @@ def rpm_expand_py(macro): if '%' not in macro: return macro expanded = rpm.expandMacro(macro) - rd_debug('Expanded rpm macro in \'%s\' to \'%s\'' % (macro, expanded)) + rd_debug("Expanded rpm macro in '%s' to '%s'" % (macro, expanded)) return expanded @@ -153,7 +153,7 @@ def rpm_expand_cmd(macro, exec_fn=None): exec_fn = read_stdout expanded = exec_fn(cmd).strip() - rd_debug('Expanded rpm macro in \'%s\' to \'%s\'' % (macro, expanded)) + rd_debug("Expanded rpm macro in '%s' to '%s'" % (macro, expanded)) return expanded diff --git a/src/rosdep2/url_utils.py b/src/rosdep2/url_utils.py index fbd10faa0..6cccf63ee 100644 --- a/src/rosdep2/url_utils.py +++ b/src/rosdep2/url_utils.py @@ -42,7 +42,7 @@ def urlopen_gzip(url, **kwargs): # http/https URLs need custom requests to specify the user-agent, since some repositories reject # requests from the default user-agent. - if url.startswith("http://") or url.startswith("https://"): + if url.startswith('http://') or url.startswith('https://'): url_request = request.Request(url, headers={ 'Accept-Encoding': 'gzip', 'User-Agent': 'rosdep/{version}'.format(version=__version__), diff --git a/test/test_flake8.py b/test/test_flake8.py index c2c14da74..49edf8d5a 100644 --- a/test/test_flake8.py +++ b/test/test_flake8.py @@ -27,8 +27,8 @@ def test_flake8(): # Calling through subprocess is the most stable way to run it. result = subprocess.run( - [sys.executable, "-m", "flake8"], + [sys.executable, '-m', 'flake8'], cwd=os.path.dirname(os.path.dirname(__file__)), check=False, ) - assert 0 == result.returncode, "flake8 found violations" + assert 0 == result.returncode, 'flake8 found violations' diff --git a/test/test_rosdep_main.py b/test/test_rosdep_main.py index 382949204..1a99d7c91 100644 --- a/test/test_rosdep_main.py +++ b/test/test_rosdep_main.py @@ -168,9 +168,9 @@ def read_stdout(cmd, capture_stderr=False): result = '' elif cmd[0] == 'dpkg-query': if cmd[-1] == 'python3-dev': - result = '\'python3-dev install ok installed\n\'' + result = "'python3-dev install ok installed\n'" else: - result = '\n'.join(["dpkg-query: no packages found matching %s" % f for f in cmd[3:]]) + result = '\n'.join(['dpkg-query: no packages found matching %s' % f for f in cmd[3:]]) if capture_stderr: return result, ''