Skip to content

Commit 734df85

Browse files
dirk-thomasmikaelarguedas
authored andcommitted
Python 3 compatible syntax (ros#18374)
* Python 3 compatible syntax * fix type
1 parent abcf7ea commit 734df85

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
language: python
22

3-
python: "2.7"
3+
python:
4+
- "2.7"
5+
- "3.6"
46

57
sudo: false
68

doc/scripts/distro_to_rosinstall.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ def translate(distro, translate_dir):
2121

2222
path = os.path.join(translate_dir, "%s.rosinstall" % item.name)
2323
with open(path, 'w+') as f:
24-
print "writing to %s" % path
24+
print("writing to %s" % path)
2525
yaml.safe_dump(rosinstall, f, default_flow_style=False)
2626

2727
if __name__ == '__main__':
2828
if len(sys.argv) != 3:
29-
print "Use %s distro install_folder" % sys.argv[0]
29+
print("Use %s distro install_folder" % sys.argv[0])
3030
sys.exit()
3131
translate(sys.argv[1], sys.argv[2])

scripts/check_rosdistro.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@
3131
def printc(text, color):
3232
"""Print in color."""
3333
if sys.stdout.isatty():
34-
print "\033["+codeCodes[color]+"m"+text+"\033[0m"
34+
print("\033["+codeCodes[color]+"m"+text+"\033[0m")
3535
else:
36-
print text
36+
print(text)
3737

3838
def print_test(msg):
3939
printc(msg, 'yellow')

test/test_url_validity.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
import subprocess
1212
import sys
1313
import unittest
14-
from urlparse import urlparse
14+
try:
15+
from urllib.parse import urlparse
16+
except ImportError:
17+
from urlparse import urlparse
1518

1619
import rosdistro
1720
from scripts import eol_distro_names
@@ -60,11 +63,9 @@ def detect_lines(diffstr):
6063
"""Take a diff string and return a dict of
6164
files with line numbers changed"""
6265
resultant_lines = {}
63-
# diffstr is already utf-8 encoded
66+
# diffstr is already decoded
6467
io = StringIO(diffstr)
65-
# Force utf-8 re: https://github.com/ros/rosdistro/issues/6637
66-
encoding = 'utf-8'
67-
udiff = unidiff.PatchSet(io, encoding)
68+
udiff = unidiff.PatchSet(io)
6869
for file in udiff:
6970
target_lines = []
7071
# if file.path in TARGET_FILES:
@@ -232,7 +233,7 @@ def isolate_yaml_snippets_from_line_numbers(yaml_dict, line_numbers):
232233

233234
def main():
234235
cmd = ('git diff --unified=0 %s' % DIFF_TARGET).split()
235-
diff = subprocess.check_output(cmd)
236+
diff = subprocess.check_output(cmd).decode('utf-8')
236237
# print("output", diff)
237238

238239
diffed_lines = detect_lines(diff)

0 commit comments

Comments
 (0)