Skip to content

Commit

Permalink
Merge branch 'master' into cottsay/flake8-quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
cottsay committed Jun 21, 2024
2 parents d82e3f5 + d56814c commit 6a20ae3
Show file tree
Hide file tree
Showing 31 changed files with 31 additions and 102 deletions.
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
'python_requires': '>=3.6',
'extras_require': {
'test': [
'flake8 < 6',
'flake8',
'flake8-builtins',
'flake8-comprehensions',
'flake8-quotes',
'pytest',
Expand Down
2 changes: 0 additions & 2 deletions src/rosdep2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
rosdep library and command-line tool
"""

from __future__ import print_function

from ._version import __version__

import sys
Expand Down
4 changes: 1 addition & 3 deletions src/rosdep2/catkin_packages.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

import os
import sys

Expand Down Expand Up @@ -33,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.')
Expand Down
2 changes: 0 additions & 2 deletions src/rosdep2/catkin_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
"""

from __future__ import print_function

import os

from subprocess import Popen, PIPE, CalledProcessError
Expand Down
2 changes: 0 additions & 2 deletions src/rosdep2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/rosdep2/gbpdistro_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"')
Expand All @@ -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))

Expand Down
2 changes: 0 additions & 2 deletions src/rosdep2/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
Script for installing rdmanifest-described resources
"""

from __future__ import print_function

import os
import sys
from optparse import OptionParser
Expand Down
8 changes: 3 additions & 5 deletions src/rosdep2/installers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

# Author Tully Foote/[email protected], Ken Conley/[email protected]

from __future__ import print_function

import os
import subprocess
import traceback
Expand Down Expand Up @@ -341,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))
Expand Down Expand Up @@ -399,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

Expand Down
12 changes: 5 additions & 7 deletions src/rosdep2/lookup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

# Author Tully Foote/[email protected], Ken Conley/[email protected]

from __future__ import print_function

import sys
import yaml

Expand Down Expand Up @@ -102,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]
Expand All @@ -116,15 +114,15 @@ 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]
return_key = installer_key
break
else:
# data must be a dictionary, string, or list
if type(data) == dict:
if type(data) is dict:
# check for
# hardy:
# apt:
Expand All @@ -143,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]
Expand Down
8 changes: 3 additions & 5 deletions src/rosdep2/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
Command-line interface to rosdep library
"""

from __future__ import print_function

import errno
import os
import sys
Expand Down Expand Up @@ -65,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

Expand Down
9 changes: 1 addition & 8 deletions src/rosdep2/meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__
Expand Down Expand Up @@ -95,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)
Expand Down
1 change: 0 additions & 1 deletion src/rosdep2/platforms/arch.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

# Author Tully Foote/[email protected]

from __future__ import print_function
import subprocess
import sys

Expand Down
2 changes: 0 additions & 2 deletions src/rosdep2/platforms/cygwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

# Tingfan Wu [email protected]

from __future__ import print_function

from rospkg.os_detect import OS_CYGWIN

from .source import SOURCE_INSTALLER
Expand Down
1 change: 0 additions & 1 deletion src/rosdep2/platforms/debian.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

# Author Tully Foote, Ken Conley

from __future__ import print_function
import subprocess
import sys

Expand Down
2 changes: 0 additions & 2 deletions src/rosdep2/platforms/gem.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@

# Author Ruben Smits/[email protected]

from __future__ import print_function

import subprocess

from ..core import InstallFailed
Expand Down
2 changes: 0 additions & 2 deletions src/rosdep2/platforms/npm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion src/rosdep2/platforms/osx.py
Original file line number Diff line number Diff line change
Expand Up @@ -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', []))

Expand Down
2 changes: 0 additions & 2 deletions src/rosdep2/platforms/pip.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

# Author Tully Foote/[email protected]

from __future__ import print_function

import os
import subprocess
import sys
Expand Down
1 change: 0 additions & 1 deletion src/rosdep2/platforms/redhat.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@

# Author Tully Foote/[email protected]

from __future__ import print_function
import subprocess
import sys

Expand Down
2 changes: 0 additions & 2 deletions src/rosdep2/platforms/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

# Author Tully Foote/[email protected]

from __future__ import print_function

import os
try:
from urllib.request import urlretrieve
Expand Down
2 changes: 1 addition & 1 deletion src/rosdep2/rep3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 0 additions & 2 deletions src/rosdep2/rospack.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
is a ROSpackage or a system dependency
"""

from __future__ import print_function

import subprocess

from .main import _get_default_RosdepLookup
Expand Down
2 changes: 0 additions & 2 deletions src/rosdep2/rospkg_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
filesystem.
"""

from __future__ import print_function

import os

import catkin_pkg.package
Expand Down
2 changes: 0 additions & 2 deletions src/rosdep2/shell_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

# Author Tully Foote/[email protected]

from __future__ import print_function

import os
import sys
import stat
Expand Down
10 changes: 4 additions & 6 deletions src/rosdep2/sources_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@

# Author Ken Conley/[email protected]

from __future__ import print_function

import os
import sys
import yaml
Expand Down Expand Up @@ -144,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_
Expand Down Expand Up @@ -231,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
"""
Expand Down Expand Up @@ -304,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:
Expand Down
8 changes: 3 additions & 5 deletions test/test_flake8.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Loading

0 comments on commit 6a20ae3

Please sign in to comment.