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

Switch to python 3 #583

Merged
merged 3 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 4 additions & 4 deletions cmake/Python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# Python Setup
##############################################################################

# Pin down python 2.7
find_package(PythonLibs 2.7 REQUIRED)
find_package(PythonInterp 2.7 REQUIRED)
# Pin down python 3.6
find_package(PythonLibs 3.6 REQUIRED)
find_package(PythonInterp 3.6 REQUIRED)

# Unfortunately no easy way to get site-packages / dist-packages
set(PYTHON_INSTALL_DIR lib/python${PYTHON_VERSION_MAJOR}.${PYTHON_VERSION_MINOR}/site-packages)

if(NOT PYBIND11_PYTHON_VERSION)
set(PYBIND11_PYTHON_VERSION "2.7" CACHE STRING "Python version to use for compiling modules")
set(PYBIND11_PYTHON_VERSION "3.6" CACHE STRING "Python version to use for compiling modules")
endif()
find_package(pybind11 REQUIRED)
2 changes: 0 additions & 2 deletions python/delphyne/cmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
# Imports
##############################################################################

from __future__ import print_function

import delphyne.console as console

##############################################################################
Expand Down
4 changes: 1 addition & 3 deletions python/delphyne/console.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand Down Expand Up @@ -33,8 +33,6 @@
# Imports
##############################################################################

from __future__ import print_function

import os
import sys

Expand Down
4 changes: 1 addition & 3 deletions python/delphyne/demos/city.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2018 Toyota Research Institute
#
Expand All @@ -10,8 +10,6 @@
# Imports
##############################################################################

from __future__ import print_function

import os.path
import random

Expand Down
4 changes: 1 addition & 3 deletions python/delphyne/demos/crash.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2018 Toyota Research Institute
#
Expand All @@ -9,8 +9,6 @@
# Imports
##############################################################################

from __future__ import print_function

import math
import numpy as np

Expand Down
4 changes: 1 addition & 3 deletions python/delphyne/demos/dragway.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand All @@ -9,8 +9,6 @@
# Imports
##############################################################################

from __future__ import print_function

import delphyne.maliput as maliput
import delphyne.simulation as simulation
import delphyne.utilities as utilities
Expand Down
4 changes: 1 addition & 3 deletions python/delphyne/demos/gazoo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand All @@ -10,8 +10,6 @@
# Imports
##############################################################################

from __future__ import print_function

import os.path

import delphyne.maliput as maliput
Expand Down
4 changes: 1 addition & 3 deletions python/delphyne/demos/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand All @@ -12,8 +12,6 @@
# Imports
##############################################################################

from __future__ import print_function

import argparse

import delphyne.cmdline as cmdline
Expand Down
3 changes: 1 addition & 2 deletions python/delphyne/demos/keyop.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand All @@ -10,7 +10,6 @@
# Imports
##############################################################################

from __future__ import print_function
from select import select

import atexit
Expand Down
4 changes: 1 addition & 3 deletions python/delphyne/demos/mobil_perf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2018 Toyota Research Institute
#
Expand All @@ -9,8 +9,6 @@
# Imports
##############################################################################

from __future__ import print_function

import math

import delphyne.maliput as maliput
Expand Down
4 changes: 1 addition & 3 deletions python/delphyne/demos/realtime.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand All @@ -11,8 +11,6 @@
# Imports
##############################################################################

from __future__ import print_function

import os
import sys

Expand Down
6 changes: 2 additions & 4 deletions python/delphyne/demos/roads.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand All @@ -9,8 +9,6 @@
# Imports
##############################################################################

from __future__ import print_function

import os
import sys

Expand Down Expand Up @@ -112,7 +110,7 @@ def main():
file_path=args.filename
)
)
except RuntimeError, error:
except RuntimeError as error:
print("There was an error trying to load the road network:")
print(str(error))
print("Exiting the simulation")
Expand Down
4 changes: 1 addition & 3 deletions python/delphyne/demos/scriptlets.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand All @@ -16,8 +16,6 @@
# Imports
##############################################################################

from __future__ import print_function

import os.path

import random
Expand Down
26 changes: 16 additions & 10 deletions python/delphyne/launcher.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand Down Expand Up @@ -62,12 +62,18 @@ def launch(self, command, label=None, cwd=None, environ=None):
stdin=self.devnull,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True, # otherwise the terminal control
# characters (e.g. for colors) are
# escaped.
env=command_env)
else:
process = subprocess.Popen(
command,
stdin=self.devnull,
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
universal_newlines=True, # otherwise the terminal control
# characters (e.g. for colors) are
# escaped.
cwd=cwd,
env=command_env)
flags = fcntl.fcntl(process.stdout, fcntl.F_GETFL)
Expand All @@ -78,15 +84,15 @@ def launch(self, command, label=None, cwd=None, environ=None):
time.sleep(0.05)
self._poll()
if self.returncode is not None:
print process.stdout.read(),
print "[%s] %s failed to launch" % (self.name, label)
print(process.stdout.read())
print("[%s] %s failed to launch" % (self.name, label))
sys.exit(self.returncode or 1)

def _poll(self):
for child in self.children:
ret = child.process.poll()
if ret is not None:
print "[%s] %s exited %d" % (self.name, child.label, ret)
print("[%s] %s exited %d" % (self.name, child.label, ret))
if self.returncode is None:
self.returncode = ret
return self.returncode
Expand All @@ -102,8 +108,8 @@ def _wait(self, duration):
now = time.time()
elapsed = now - start
if elapsed > duration:
print "[%s] %s exited via duration elapsed" % (
self.name, self.name)
print("[%s] %s exited via duration elapsed" %
(self.name, self.name))
self.returncode = 0
self.done = True

Expand All @@ -117,8 +123,8 @@ def _wait(self, duration):
if not lines:
continue

print '\n'.join(
["[%s] %s" % (child.label, line) for line in lines])
print('\n'.join(["[%s] %s" % (child.label, line)
for line in lines]))
sys.stdout.flush()

def wait(self, duration):
Expand All @@ -132,8 +138,8 @@ def wait(self, duration):
self._wait(duration)
except KeyboardInterrupt:
# This is considered success; we ran until the user stopped us.
print "[%s] %s exited via keyboard interrupt" % (
self.name, self.name)
print("[%s] %s exited via keyboard interrupt" %
(self.name, self.name))
self.returncode = 0
assert self.returncode is not None

Expand Down
7 changes: 2 additions & 5 deletions python/delphyne/toolkit/replay.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2018 Toyota Research Institute
#
Expand All @@ -11,11 +11,8 @@
# Imports
##############################################################################

from __future__ import print_function

import argparse
import contextlib
import itertools
import os
import shutil
import sys
Expand Down Expand Up @@ -123,7 +120,7 @@ def main():
for relative_path in os.listdir(root_path)
]
found_files = [path for path in found_paths if os.path.isfile(path)]
args.log_file = next(itertools.ifilter(is_log_file, sorted(
args.log_file = next(filter(is_log_file, sorted(
found_files, key=os.path.getmtime, reverse=True
)), None)

Expand Down
4 changes: 1 addition & 3 deletions python/delphyne/utilities.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand All @@ -12,8 +12,6 @@
# Imports
##############################################################################

from __future__ import print_function

import os
import sys
import time
Expand Down
2 changes: 1 addition & 1 deletion python/examples/delphyne-city
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2018 Toyota Research Institute
#
Expand Down
2 changes: 1 addition & 1 deletion python/examples/delphyne-crash
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2018 Toyota Research Institute
#
Expand Down
2 changes: 1 addition & 1 deletion python/examples/delphyne-dragway
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand Down
2 changes: 1 addition & 1 deletion python/examples/delphyne-gazoo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand Down
2 changes: 1 addition & 1 deletion python/examples/delphyne-keyop
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand Down
2 changes: 1 addition & 1 deletion python/examples/delphyne-mobil-perf
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2018 Toyota Research Institute
#
Expand Down
2 changes: 1 addition & 1 deletion python/examples/delphyne-realtime
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand Down
2 changes: 1 addition & 1 deletion python/examples/delphyne-roads
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand Down
2 changes: 1 addition & 1 deletion python/examples/delphyne-scriptlets
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand Down
2 changes: 1 addition & 1 deletion python/scripts/delphyne-replay
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2018 Toyota Research Institute
#
Expand Down
2 changes: 1 addition & 1 deletion test/regression/python/simulation_runner_py_test.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2.7
#!/usr/bin/env python3
#
# Copyright 2017 Toyota Research Institute
#
Expand Down
Loading