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

Update to python3 #521

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ The required 3rd party dependencies are:

- Qt4 or Qt5 (Qt 4.8.7 recommended)
- VTK 6.2+ (VTK 7.1.1 recommended)
- Python 2.7 and NumPy
- Python 3.4+ and NumPy

Additionally, you will need CMake 2.8 or greater to configure the source code.

Expand Down
4 changes: 2 additions & 2 deletions cmake/dd-macros.cmake
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
macro(setup_python)
find_package(PythonLibs 2.7 REQUIRED)
find_package(PythonInterp 2.7 REQUIRED)
find_package(PythonLibs 3.4 REQUIRED)
find_package(PythonInterp 3.4 REQUIRED)
endmacro()


Expand Down
4 changes: 2 additions & 2 deletions cmake/modules/FindNumPy.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@

# Finding NumPy involves calling the Python interpreter
if(NumPy_FIND_REQUIRED)
find_package(PythonInterp 2.7 REQUIRED)
find_package(PythonInterp 3.4 REQUIRED)
else()
find_package(PythonInterp 2.7)
find_package(PythonInterp 3.4)
endif()

if(NOT PYTHONINTERP_FOUND)
Expand Down
27 changes: 14 additions & 13 deletions distro/superbuild/cmake/externals.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,21 @@ endif()


if(APPLE)
find_program(PYTHON_CONFIG_EXECUTABLE python-config)
find_program(PYTHON_CONFIG_EXECUTABLE python3-config)
if (NOT PYTHON_CONFIG_EXECUTABLE)
message(SEND_ERROR "python-config executable not found, but python is required.")
message(SEND_ERROR "python3-config executable not found, but python is required.")
endif()
# using "python-config --prefix" so that cmake always uses the python that is
# in the users path, this is a fix for homebrew on Mac:
# https://github.com/Homebrew/homebrew/issues/25118
execute_process(COMMAND ${PYTHON_CONFIG_EXECUTABLE} --prefix OUTPUT_VARIABLE python_prefix OUTPUT_STRIP_TRAILING_WHITESPACE)
set(PYTHON_INCLUDE_DIR ${python_prefix}/include/python2.7)
set(PYTHON_LIBRARY ${python_prefix}/lib/libpython2.7${CMAKE_SHARED_LIBRARY_SUFFIX})
set(PYTHON_INCLUDE_DIR ${python_prefix}/include/python3.6m)
set(PYTHON_LIBRARY ${python_prefix}/lib/libpython3.6m${CMAKE_SHARED_LIBRARY_SUFFIX})
else()
find_package(PythonLibs 2.7 REQUIRED)
set(Python_ADDITIONAL_VERSIONS 3.4) # required for cmake 2.8 on ubuntu 14.04
find_package(PythonLibs 3.4 REQUIRED)
endif()
find_package(PythonInterp 2.7 REQUIRED)
find_package(PythonInterp 3.4 REQUIRED)

set(python_args
-DPYTHON_EXECUTABLE:PATH=${PYTHON_EXECUTABLE}
Expand Down Expand Up @@ -341,19 +342,19 @@ elseif(USE_PRECOMPILED_VTK)

if (ubuntu_version EQUAL 14.04)
if(DD_QT_VERSION EQUAL 4)
set(vtk_package_url ${url_base}/vtk7.1-qt4.8-python2.7-ubuntu14.04.tar.gz)
set(vtk_package_md5 fe5c16f427a497b5713c52a68ecf564d)
set(vtk_package_url ${url_base}/vtk7.1-qt4.8-python3.4-ubuntu14.04.tar.gz)
set(vtk_package_md5 5e9b52be15dccadefdd033c58f055705)
else()
message(FATAL_ERROR "Compiling director with Qt5 is not supported on Ubuntu 14.04. "
"Please set DD_QT_VERSION to 4.")
endif()
elseif(ubuntu_version EQUAL 16.04)
if(DD_QT_VERSION EQUAL 4)
set(vtk_package_url ${url_base}/vtk7.1-qt4.8-python2.7-ubuntu16.04.tar.gz)
set(vtk_package_md5 1291e072405a3982b559ec011c3cf2a1)
set(vtk_package_url ${url_base}/vtk7.1-qt4.8-python3.5-ubuntu16.04.tar.gz)
set(vtk_package_md5 185e718e13ef532e3af4a80397091058)
else()
set(vtk_package_url ${url_base}/vtk7.1-qt5.5-python2.7-ubuntu16.04.tar.gz)
set(vtk_package_md5 5ac930a7b1c083f975115d5970fb1a34)
set(vtk_package_url ${url_base}/vtk7.1-qt5.5-python3.5-ubuntu16.04.tar.gz)
set(vtk_package_md5 00000000000000000000000000000000)
endif()
else()
message(FATAL_ERROR "USE_PRECOMPILED_VTK requires Ubuntu 14.04 or 16.04 "
Expand Down Expand Up @@ -386,7 +387,7 @@ else()
-DBUILD_EXAMPLES:BOOL=OFF
-DVTK_RENDERING_BACKEND:STRING=OpenGL2
-DVTK_QT_VERSION:STRING=${DD_QT_VERSION}
-DVTK_PYTHON_VERSION:STRING=2
-DVTK_PYTHON_VERSION:STRING=3
-DModule_vtkGUISupportQt:BOOL=ON
-DCMAKE_MACOSX_RPATH:BOOL=ON
-DVTK_WRAP_PYTHON:BOOL=ON
Expand Down
25 changes: 12 additions & 13 deletions distro/travis/install_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,27 @@ install_ubuntu_deps_common()
libglib2.0-dev \
libqt4-dev \
lsb-release \
python-coverage \
python-dev \
python-lxml \
python-numpy \
python-yaml \
python3-coverage \
python3-dev \
python3-lxml \
python3-numpy \
python3-yaml \
wget \
xvfb

if [ "$MAKE_DOCS" = "ON" ]; then
apt-get install -y \
doxygen \
graphviz \
python-pip \
python-sphinx
pip install sphinx-rtd-theme
python3-pip \
python3-sphinx
pip3 install sphinx-rtd-theme
fi

if [ "$MAKE_PACKAGE" = "ON" ]; then
apt-get install -y \
curl
fi

}

install_ubuntu_deps()
Expand Down Expand Up @@ -63,13 +62,13 @@ install_osx_deps()
cd $(brew --repository homebrew/core) && git reset --hard 543d8e9b27b9bb25ce4491773684c30c8cb66dcc
#brew upgrade

brew install qt vtk7
brew install qt vtk7python3
brew install doxygen graphviz
brew install glib # for lcm
brew ls --versions python || brew install python
brew ls --versions numpy || brew install numpy || echo "error on brew install numpy"
brew ls --versions python3 || brew install python3
#brew ls --versions numpy || brew install numpy --with-python3 || echo "error on brew install numpy"

pip install pyyaml lxml Sphinx sphinx-rtd-theme coverage
pip3 install numpy pyyaml lxml Sphinx sphinx-rtd-theme coverage
}


Expand Down
2 changes: 1 addition & 1 deletion docs/sphinx/getting_started/build.rst
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The required 3rd party dependencies are:

- Qt4 or Qt5 (Qt 4.8.7 recommended)
- VTK 6.2+ (VTK 7.1.1 recommended)
- Python 2.7 and NumPy
- Python 3.4+ and NumPy

Additionally, you will need CMake 2.8 or greater to configure the source code.

Expand Down
2 changes: 1 addition & 1 deletion src/python/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ foreach(file ${python_files})

set(copied_python_files ${copied_python_files} ${tgt})
get_filename_component(installDirSuffix ${file} PATH)
install(FILES ${tgt} ${tgtDir}/${tgt_we}.pyc DESTINATION ${DD_INSTALL_PYTHON_DIR}/${installDirSuffix} COMPONENT Runtime)
install(FILES ${tgt} DESTINATION ${DD_INSTALL_PYTHON_DIR}/${installDirSuffix} COMPONENT Runtime)
endforeach(file)


Expand Down
2 changes: 1 addition & 1 deletion src/python/compile_all.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@ if success:
file = open('./compile_complete', 'w')
file.write('Done')
else:
print '\nPython byte compile failed.\n'
print('\nPython byte compile failed.\n')
sys.exit(1)
2 changes: 1 addition & 1 deletion src/python/director/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ def updateSysPath(path):
_initCoverage()

# this is for mac homebrew users
#updateSysPath('/usr/local/opt/vtk7/lib/python2.7/site-packages')
#updateSysPath('/usr/local/opt/vtk7/lib/python3.6/site-packages')
2 changes: 1 addition & 1 deletion src/python/director/affordanceitems.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def loadDescription(self, desc, copyMode=COPY_MODE_ALL):
self._renderAllViews()

def syncProperties(self, desc, copyMode=COPY_MODE_ALL):
for propertyName, propertyValue in desc.iteritems():
for propertyName, propertyValue in desc.items():
if copyMode == self.COPY_MODE_SKIP_LOCAL:
if propertyName in self.LOCAL_PROPERTY_NAMES:
continue
Expand Down
2 changes: 1 addition & 1 deletion src/python/director/affordancemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def _notifyPendingUpdates(self):
try:
self.collection.updateDescription(self.getAffordanceDescription(aff), notify=False)
except:
print traceback.format_exc()
print((traceback.format_exc()))

self._pendingUpdates.clear()

Expand Down
2 changes: 1 addition & 1 deletion src/python/director/applogic.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def showPythonConsole():
_exclusiveDockWidgets = {}

def hideDockWidgets(action):
for a, w in _exclusiveDockWidgets.iteritems():
for a, w in _exclusiveDockWidgets.items():
if a is not action:
dock, widget = w
if not dock.isFloating():
Expand Down
20 changes: 10 additions & 10 deletions src/python/director/assimp2vtk.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def getPolyDataForMesh(self, mesh):

def getTextureForMaterial(self, material):

materialDict = dict(material.properties.items())
materialDict = dict(list(material.properties.items()))

if 'file' not in materialDict:
return None
Expand All @@ -52,10 +52,10 @@ def getTextureForMaterial(self, material):
texture.EdgeClampOn()
texture.RepeatOn()
else:
print 'failed to load image file:', imageFile
print('failed to load image file:', imageFile)
texture = None
else:
print 'cannot find texture file:', textureFile
print('cannot find texture file:', textureFile)
texture = None

self.textureCache[textureFile] = texture
Expand All @@ -79,7 +79,7 @@ def addToView(self, view):

def setMaterialProperties(self, obj, mesh):
material = mesh.material
props = {k[0]:v for k, v in material.properties.iteritems()}
props = {k[0]:v for k, v in material.properties.items()}

obj.setProperty('Alpha', props['opacity'])
obj.setProperty('Color', props['diffuse'])
Expand All @@ -97,12 +97,12 @@ def setMaterialProperties(self, obj, mesh):

def addMaterialMetaData(polyData, material):

materialDict = dict(material.properties.items())
materialDict = dict(list(material.properties.items()))
textureFile = materialDict['file']

textureFileAbsPath = os.path.join(meshDir, textureFile)
if not os.path.isfile(textureFileAbsPath):
print 'warning, cannot find texture file:', os.path.abspath(textureFileAbsPath)
print('warning, cannot find texture file:', os.path.abspath(textureFileAbsPath))

s = vtk.vtkStringArray()
s.InsertNextValue(textureFile)
Expand Down Expand Up @@ -135,7 +135,7 @@ def assimpMeshToPolyData(mesh):

cells = vtk.vtkCellArray()

for i in xrange(nfaces):
for i in range(nfaces):
face = faces[i]
tri = vtk.vtkTriangle()
tri.GetPointIds().SetId(0, face[0])
Expand Down Expand Up @@ -172,8 +172,8 @@ def assimpTransformToVtk(node):

m = vtk.vtkMatrix4x4()

for r in xrange(4):
for c in xrange(4):
for r in range(4):
for c in range(4):
m.SetElement(r, c, node.matrix[r][c])

t = vtk.vtkTransform()
Expand Down Expand Up @@ -212,7 +212,7 @@ def writeMultiBlockPolyData(polyDataList, outFile):
if __name__ == '__main__':

if len(sys.argv) < 2:
print 'Usage: %s <mesh file>' % sys.argv[0]
print('Usage: %s <mesh file>' % sys.argv[0])
sys.exit(1)


Expand Down
6 changes: 3 additions & 3 deletions src/python/director/asynctaskqueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def addTask(self, task):
def callbackLoop(self):

try:
for i in xrange(10):
for i in range(10):
self.doWork()
if not self.tasks:
self.stop()
Expand Down Expand Up @@ -121,7 +121,7 @@ def doWork(self):

def handleGenerator(self, generator):
try:
result = generator.next()
result = next(generator)
except StopIteration:
self.generators.remove(generator)
else:
Expand Down Expand Up @@ -189,7 +189,7 @@ def __init__(self, message):
self.message = message

def __call__(self):
print self.message
print(self.message)


class UserPromptTask(AsyncTask):
Expand Down
4 changes: 2 additions & 2 deletions src/python/director/atlasdriver.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os
import vtkAll as vtk
from . import vtkAll as vtk
import math
import numpy as np
from collections import deque
Expand Down Expand Up @@ -33,7 +33,7 @@ def onSystemStatus(self, message):
if self.outputConsole is not None:
self.outputConsole.append(message)
else:
print message
print(message)


class AtlasDriver(object):
Expand Down
10 changes: 5 additions & 5 deletions src/python/director/bihandeddemo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os
import sys
import vtkAll as vtk
from . import vtkAll as vtk
import math
import time
import types
Expand Down Expand Up @@ -510,14 +510,14 @@ def sendNeckPitchLookForward(self):


def waitForAtlasBehaviorAsync(self, behaviorName):
assert behaviorName in self.atlasDriver.getBehaviorMap().values()
assert behaviorName in list(self.atlasDriver.getBehaviorMap().values())
while self.atlasDriver.getCurrentBehaviorName() != behaviorName:
yield


def printAsync(self, s):
yield
print s
print(s)


def userPrompt(self, message):
Expand All @@ -526,7 +526,7 @@ def userPrompt(self, message):
return

yield
result = raw_input(message)
result = input(message)
if result != 'y':
raise Exception('user abort.')

Expand Down Expand Up @@ -578,7 +578,7 @@ def commitFootstepPlan(self):

def waitForPlanExecution(self, plan):
planElapsedTime = planplayback.PlanPlayback.getPlanElapsedTime(plan)
print 'waiting for plan execution:', planElapsedTime
print('waiting for plan execution:', planElapsedTime)

return self.delay(planElapsedTime + 1.0)

Expand Down
Loading