Skip to content

Commit

Permalink
Python 3 compatible syntax (#18374)
Browse files Browse the repository at this point in the history
* Python 3 compatible syntax

* fix type
  • Loading branch information
dirk-thomas authored and mikaelarguedas committed Jul 6, 2018
1 parent abcf7ea commit 734df85
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
language: python

python: "2.7"
python:
- "2.7"
- "3.6"

sudo: false

Expand Down
4 changes: 2 additions & 2 deletions doc/scripts/distro_to_rosinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ def translate(distro, translate_dir):

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

if __name__ == '__main__':
if len(sys.argv) != 3:
print "Use %s distro install_folder" % sys.argv[0]
print("Use %s distro install_folder" % sys.argv[0])
sys.exit()
translate(sys.argv[1], sys.argv[2])
4 changes: 2 additions & 2 deletions scripts/check_rosdistro.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@
def printc(text, color):
"""Print in color."""
if sys.stdout.isatty():
print "\033["+codeCodes[color]+"m"+text+"\033[0m"
print("\033["+codeCodes[color]+"m"+text+"\033[0m")
else:
print text
print(text)

def print_test(msg):
printc(msg, 'yellow')
Expand Down
13 changes: 7 additions & 6 deletions test/test_url_validity.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
import subprocess
import sys
import unittest
from urlparse import urlparse
try:
from urllib.parse import urlparse
except ImportError:
from urlparse import urlparse

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

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

diffed_lines = detect_lines(diff)
Expand Down

0 comments on commit 734df85

Please sign in to comment.