Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python 3 compatibility #544

Merged
merged 3 commits into from
Nov 26, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bin/catkin_make
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,12 @@ def main():

whitelist_pkg_names = get_package_names_with_recursive_dependencies(packages, args.only_pkg_with_deps)
print('Whitelisted packages: %s' % ', '.join(sorted(whitelist_pkg_names)))
packages = {path: p for path, p in packages.iteritems() if p.name in whitelist_pkg_names}
packages = {path: p for path, p in packages.items() if p.name in whitelist_pkg_names}
cmake_args += ['-DCATKIN_WHITELIST_PACKAGES=%s' % ';'.join(sorted(whitelist_pkg_names))]

# verify that specified package exists in workspace
if args.pkg:
packages_by_name = {p.name: path for path, p in packages.iteritems()}
packages_by_name = {p.name: path for path, p in packages.items()}
unknown_packages = [name for name in args.pkg if name not in packages_by_name]
if len(unknown_packages) == len(args.pkg):
# all package names are unknown
Expand Down
4 changes: 2 additions & 2 deletions bin/catkin_prepare_release
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def main():
raise RuntimeError(fmt("@{rf}Aborted release, fix the names of the packages."))

local_modifications = []
for pkg_path, package in packages.iteritems():
for pkg_path, package in packages.items():
# verify that the package.xml files don't have modifications pending
package_xml_path = os.path.join(pkg_path, PACKAGE_MANIFEST_FILENAME)
if has_changes(base_path, package_xml_path, vcs_type):
Expand All @@ -261,7 +261,7 @@ def main():
# check for changelog entries
missing_changelogs = []
missing_changelogs_but_forthcoming = {}
for pkg_path, package in packages.iteritems():
for pkg_path, package in packages.items():
changelog_path = os.path.join(pkg_path, CHANGELOG_FILENAME)
if not os.path.exists(changelog_path):
missing_changelogs.append(package.name)
Expand Down
2 changes: 1 addition & 1 deletion cmake/empy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function(find_python_module module)
# A module's location is usually a directory, but for
# binary modules
# it's a .so file.
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import re, ${module}; print re.compile('/__init__.py.*').sub('',${module}.__file__)"
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c" "import re, ${module}; print(re.compile('/__init__.py.*').sub('',${module}.__file__))"
RESULT_VARIABLE _${module}_status
OUTPUT_VARIABLE _${module}_location
ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
Expand Down
7 changes: 5 additions & 2 deletions cmake/test/download_checkmd5.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
from __future__ import print_function
import os
import sys
import urllib
try:
from urllib.request import urlretrieve
except ImportError:
from urllib import urlretrieve
import hashlib
from optparse import OptionParser

Expand All @@ -21,7 +24,7 @@ def download_md5(uri, dest):

sys.stdout.write('Downloading %s to %s...' % (uri, dest))
sys.stdout.flush()
urllib.urlretrieve(uri, dest)
urlretrieve(uri, dest)
sys.stdout.write('Done\n')


Expand Down
12 changes: 8 additions & 4 deletions python/catkin/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ def run_command(cmd, cwd, quiet=False, colorize=False, add_env=None):
out = io.StringIO() if quiet else sys.stdout
if capture:
while True:
line = unicode(proc.stdout.readline().decode('utf8', 'replace'))
line = proc.stdout.readline().decode('utf8', 'replace')
try:
line = unicode(line)
except NameError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awkward, It might be worth a comment that this is for python2 backwards compatability so that sometime in the future we would come back and clear all backwards compatibility things out.

Maybe we should be flagging everything like that with a unique string for ease of finding.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added note in 0436f6c.

pass
if proc.returncode is not None or not line:
break
try:
Expand Down Expand Up @@ -749,11 +753,11 @@ def build_workspace_isolated(

whitelist_pkg_names = get_package_names_with_recursive_dependencies(packages, only_pkg_with_deps)
print('Whitelisted packages: %s' % ', '.join(sorted(whitelist_pkg_names)))
packages = {path: p for path, p in packages.iteritems() if p.name in whitelist_pkg_names}
packages = {path: p for path, p in packages.items() if p.name in whitelist_pkg_names}

# verify that specified package exists in workspace
if build_packages:
packages_by_name = {p.name: path for path, p in packages.iteritems()}
packages_by_name = {p.name: path for path, p in packages.items()}
unknown_packages = [p for p in build_packages if p not in packages_by_name]
if unknown_packages:
sys.exit('Packages not found in the workspace: %s' % ', '.join(unknown_packages))
Expand Down Expand Up @@ -925,7 +929,7 @@ def cmake_input_changed(packages, build_path, cmake_args=None, filename='catkin_
def get_package_names_with_recursive_dependencies(packages, pkg_names):
dependencies = set([])
check_pkg_names = set(pkg_names)
packages_by_name = {p.name: p for path, p in packages.iteritems()}
packages_by_name = {p.name: p for path, p in packages.items()}
while check_pkg_names:
pkg_name = check_pkg_names.pop()
if pkg_name in packages_by_name:
Expand Down
2 changes: 1 addition & 1 deletion python/catkin/find_in_workspaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def find_in_workspaces(search_dirs=None, project=None, path=None, _workspaces=ge
source_paths = get_source_paths(workspace)
for source_path in source_paths:
packages = find_packages(source_path)
matching_packages = [p for p, pkg in packages.iteritems() if pkg.name == project]
matching_packages = [p for p, pkg in packages.items() if pkg.name == project]
if matching_packages:
p = os.path.join(source_path, matching_packages[0])
if path is not None:
Expand Down
2 changes: 1 addition & 1 deletion python/catkin/package_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def update_versions(paths, new_version):
raise RuntimeError('Could not bump version number in file %s: %s' % (package_path, str(rue)))
files[package_path] = new_package_str
# if all replacements successful, write back modified package.xml
for package_path, new_package_str in files.iteritems():
for package_path, new_package_str in files.items():
with open(package_path, 'w') as f:
f.write(new_package_str)

Expand Down
20 changes: 14 additions & 6 deletions python/catkin/tidy_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,20 @@
# code copied from rosunit/src/junitxml.py


RE_XML_ILLEGAL = '([\u0000-\u0008\u000b-\u000c\u000e-\u001f\ufffe-\uffff])' + \
'|' + \
'([%s-%s][^%s-%s])|([^%s-%s][%s-%s])|([%s-%s]$)|(^[%s-%s])' % \
(unichr(0xd800), unichr(0xdbff), unichr(0xdc00), unichr(0xdfff),
unichr(0xd800), unichr(0xdbff), unichr(0xdc00), unichr(0xdfff),
unichr(0xd800), unichr(0xdbff), unichr(0xdc00), unichr(0xdfff))
try:
RE_XML_ILLEGAL = '([\u0000-\u0008\u000b-\u000c\u000e-\u001f\ufffe-\uffff])' + \
'|' + \
'([%s-%s][^%s-%s])|([^%s-%s][%s-%s])|([%s-%s]$)|(^[%s-%s])' % \
(unichr(0xd800), unichr(0xdbff), unichr(0xdc00), unichr(0xdfff),
unichr(0xd800), unichr(0xdbff), unichr(0xdc00), unichr(0xdfff),
unichr(0xd800), unichr(0xdbff), unichr(0xdc00), unichr(0xdfff))
except NameError:
RE_XML_ILLEGAL = '([\u0000-\u0008\u000b-\u000c\u000e-\u001f\ufffe-\uffff])' + \
'|' + \
'([%s-%s][^%s-%s])|([^%s-%s][%s-%s])|([%s-%s]$)|(^[%s-%s])' % \
(chr(0xd800), chr(0xdbff), chr(0xdc00), chr(0xdfff),
chr(0xd800), chr(0xdbff), chr(0xdc00), chr(0xdfff),
chr(0xd800), chr(0xdbff), chr(0xdc00), chr(0xdfff))
_SAFE_XML_REGEX = re.compile(RE_XML_ILLEGAL)


Expand Down
5 changes: 4 additions & 1 deletion test/unit_tests/test_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@ def __init__(self, popen):

def readline(self):
self.__popen.returncode = 0
return unichr(2018)
try:
return unichr(2018)
except NameError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto above

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added note in 0436f6c.

return chr(2018)

class MockPopen(object):
def __init__(self, *args, **kwargs):
Expand Down
5 changes: 4 additions & 1 deletion test/unit_tests/test_test_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import unittest
import tempfile
import shutil
from cStringIO import StringIO
try:
from io import StringIO
except ImportError:
from cStringIO import StringIO


try:
Expand Down