Skip to content

Commit

Permalink
Run Director using Python 3 (RobotLocomotion#12296)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamiesnape authored Nov 6, 2019
1 parent 20a43f9 commit 5ded94c
Show file tree
Hide file tree
Showing 21 changed files with 34 additions and 157 deletions.
9 changes: 0 additions & 9 deletions lcmtypes/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package(default_visibility = ["//visibility:public"])
load(
"@drake//tools/install:install.bzl",
"install",
"install_py2_duplicates_if_py3",
)
load(
"@drake//tools/skylark:drake_cc.bzl",
Expand Down Expand Up @@ -384,13 +383,6 @@ install(
visibility = ["//visibility:private"],
)

# For Python2-only `drake_visualizer`.
install_py2_duplicates_if_py3(
name = "install_py2_duplicates_if_py3",
targets = [":lcmtypes_drake_py"],
visibility = ["//visibility:private"],
)

install(
name = "install",
install_tests = [":test/drake-lcm-spy_install_test.py"],
Expand All @@ -406,7 +398,6 @@ install(
},
deps = [
":install_drake_cc_headers",
":install_py2_duplicates_if_py3",
"//tools/workspace/optitrack_driver:install",
"@lcm//:install",
"@lcmtypes_bot2_core//:install",
Expand Down
2 changes: 0 additions & 2 deletions setup/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ exports_files([
"ubuntu/binary_distribution/packages-bionic.txt",
"mac/source_distribution/requirements.txt",
"mac/source_distribution/Brewfile",
"mac/binary_distribution/requirements-py2.txt",
"mac/binary_distribution/requirements.txt",
"mac/binary_distribution/Brewfile",
])
Expand All @@ -24,7 +23,6 @@ install_files(
"//tools/cc_toolchain:apple": [
"mac/binary_distribution/Brewfile",
"mac/binary_distribution/install_prereqs.sh",
"mac/binary_distribution/requirements-py2.txt",
"mac/binary_distribution/requirements.txt",
],
"//tools/cc_toolchain:linux": [
Expand Down
9 changes: 1 addition & 8 deletions setup/mac/binary_distribution/install_prereqs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,9 @@ brew uninstall --force dreal
brew untap dreal/dreal &>/dev/null || true
/usr/local/bin/brew bundle --file="${BASH_SOURCE%/*}/Brewfile"

if ! command -v /usr/local/bin/pip2 &>/dev/null; then
echo 'ERROR: pip2 is NOT installed. The post-install step for the python@2 formula may have failed.' >&2
exit 2
fi

/usr/local/bin/pip2 install --upgrade --requirement "${BASH_SOURCE%/*}/requirements-py2.txt"

if ! command -v /usr/local/bin/pip3 &>/dev/null; then
echo 'ERROR: pip3 is NOT installed. The post-install step for the python formula may have failed.' >&2
exit 3
exit 2
fi

/usr/local/bin/pip3 install --upgrade --requirement "${BASH_SOURCE%/*}/requirements.txt"
6 changes: 0 additions & 6 deletions setup/mac/binary_distribution/requirements-py2.txt

This file was deleted.

1 change: 0 additions & 1 deletion setup/mac/binary_distribution/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ matplotlib
pydot
PyYAML
pyzmq
six
tornado
u-msgpack-python
virtualenv
7 changes: 0 additions & 7 deletions setup/ubuntu/binary_distribution/packages-bionic.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,12 @@ libtinyxml2.6.2v5
libxml2
libxt6
libyaml-cpp0.5v5
python
python-lxml
python-matplotlib
python-numpy
python-scipy
python-yaml
python3
python3-lxml
python3-matplotlib
python3-numpy
python3-pydot
python3-scipy
python3-six
python3-tk
python3-tornado
python3-u-msgpack
Expand Down
1 change: 0 additions & 1 deletion tools/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ py_binary(
data = [
"//examples:prod_models",
"@drake_visualizer",
"@drake_visualizer//:lcm_python2",
],
main = "//tools/workspace/drake_visualizer:drake_visualizer.py",
# Python libraries to import.
Expand Down
34 changes: 0 additions & 34 deletions tools/install/install.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -689,40 +689,6 @@ Args:
allowed_externals: List of external packages whose files may be installed.
"""

def install_py2_duplicates_if_py3(
name,
targets = None,
py_dest = "@PYTHON_SITE_PACKAGES@",
**kwargs):
"""
Creates a duplicate install, only if Python3 is Bazel's version of Python.
Otherwise, creates an empty install target.
For `py_dest`, `@PYTHON_SITE_PACKAGES@` will be replaced with
`lib/python2.7/site-packages`.
This is presently only used to support Python2-only `drake_visualizer`.
"""
cur_major, _ = PYTHON_VERSION.split(".")
if cur_major == "3":
py2_targets = targets
else:
py2_targets = []

# Assuming that we will only have one supported major-minor version of
# Python2.
py2_major_minor = "2.7"
py2_dest = py_dest.replace(
"@PYTHON_SITE_PACKAGES@",
"lib/python{}/site-packages".format(py2_major_minor),
)
install(
name = name,
targets = py2_targets,
py_dest = py2_dest,
**kwargs
)

#------------------------------------------------------------------------------
# Generate information to install files to specified destination.
def _install_files_impl(ctx):
Expand Down
4 changes: 1 addition & 3 deletions tools/workspace/drake_visualizer/drake_visualizer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from __future__ import print_function

import argparse
import os
from os.path import exists, join
Expand Down Expand Up @@ -71,7 +69,7 @@ def extract_use_builtin_scripts(argv):
prepend_path("LD_LIBRARY_PATH", "external/vtk/lib")
# TODO(eric.cousineau): Ensure that Drake Visualizer works even when Bazel
# uses a separate version of Python.
prepend_path("PYTHONPATH", "external/vtk/lib/python2.7/site-packages")
prepend_path("PYTHONPATH", "external/vtk/lib/python3.6/site-packages")
elif sys.platform == "darwin":
# Ensure that we handle DYLD_LIBRARY_PATH for @lcm.
set_path("DYLD_LIBRARY_PATH", "external/lcm")
Expand Down
2 changes: 1 addition & 1 deletion tools/workspace/drake_visualizer/plugin/show_frame.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Note that this script runs in the main context of drake-visulizer,
# where many modules and variables already exist in the global scope.
from sets import Set

from director import lcmUtils
from director import applogic
from director import objectmodel as om
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from director.debugVis import DebugData
import director.vtkAll as vtk
import numpy as np
from six import iteritems
from PythonQt import QtCore, QtGui

import drake as lcmdrakemsg
Expand Down Expand Up @@ -209,9 +208,10 @@ def _do_get_contrasting_color(self):
def _do_get_color(self, norm_value):
raise NotImplementedError('Subclasses need to implement this')

def _normalize(self, data, (min_val, max_val)):
def _normalize(self, data, range):
'''Returns an affine mapped version of the data based on the data range
provided'''
(min_val, max_val) = range
if (min_val > max_val):
raise AttributeError(
'Bad range: [{}, {}]'.format(min_val, max_val))
Expand Down Expand Up @@ -382,7 +382,7 @@ def add_subscriber(self):
'CONTACT_RESULTS',
messageClass=lcmdrakemsg.lcmt_contact_results_for_viz,
callback=self.handle_message)
print self._name + ' subscriber added.'
print(self._name + ' subscriber added.')

def remove_subscriber(self):
if self._sub is None:
Expand All @@ -391,7 +391,7 @@ def remove_subscriber(self):
lcmUtils.removeSubscriber(self._sub)
self._sub = None
om.removeFromObjectModel(om.findObjectByName(self._folder_name))
print self._name + ' subscriber removed.'
print(self._name + ' subscriber removed.')

def is_enabled(self):
return self._enabled
Expand Down
5 changes: 2 additions & 3 deletions tools/workspace/drake_visualizer/plugin/show_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
* src/python/director/cameraview.py (CameraImageView)
* src/app/ddBotImageQueue.cpp
"""

import sys
import argparse
import math
Expand Down Expand Up @@ -125,7 +124,7 @@ def render(self):

if self._depth_mapper is not None:
depth_range = self._get_depth_range()
for i in xrange(2):
for i in range(2):
value = [0.] * 6
coloring = self._depth_mapper.GetLookupTable()
coloring.GetNodeValue(i, value)
Expand Down Expand Up @@ -454,7 +453,7 @@ def _on_message(self, msg):
issues = []

msg_frame_names = [image.header.frame_name for image in msg.images]
for (frame_name, handler) in self._handlers.iteritems():
for (frame_name, handler) in self._handlers.items():
if frame_name not in msg_frame_names:
issues.append("Did not find '{}' in message"
.format(frame_name))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# Note that this script runs in the main context of drake-visualizer,
# where many modules and variables already exist in the global scope.

from director import lcmUtils
from director import applogic
from director import objectmodel as om
from director import visualization as vis
from director.debugVis import DebugData
import numpy as np
from PythonQt import QtCore, QtGui
from six import iteritems

import drake as lcmdrakemsg

Expand Down Expand Up @@ -175,7 +175,7 @@ def add_subscriber(self):
'CONTACT_RESULTS',
messageClass=lcmdrakemsg.lcmt_contact_results_for_viz,
callback=self.handle_message)
print self._name + " subscriber added."
print(self._name + " subscriber added.")

def remove_subscriber(self):
if self._sub is None:
Expand All @@ -184,7 +184,7 @@ def remove_subscriber(self):
lcmUtils.removeSubscriber(self._sub)
self._sub = None
om.removeFromObjectModel(om.findObjectByName(self._folder_name))
print self._name + " subscriber removed."
print(self._name + " subscriber removed.")

def is_enabled(self):
return self._enabled
Expand Down Expand Up @@ -253,7 +253,7 @@ def handle_message(self, msg):
if self.magnitude_mode == ContactVisModes.kAutoScale:
auto_scale = 1.0 / max_force

for key, list_of_forces in iteritems(collision_pair_to_forces):
for key, list_of_forces in collision_pair_to_forces.items():
d = DebugData()
for p, v in list_of_forces:
d.addArrow(start=p,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Amalgam of visualizer scripts."""

from __future__ import print_function

from collections import OrderedDict
import os
Expand Down Expand Up @@ -30,7 +29,7 @@ def init_visualizer():
scripts_raw = os.environ["_DRAKE_VISUALIZER_BUILTIN_SCRIPTS"]
print(" Specified: --use_builtin_scripts={}".format(scripts_raw))
if scripts_raw == "all":
scripts = available.keys()
scripts = list(available.keys())
else:
scripts = []
for script in scripts_raw.split(","):
Expand Down
38 changes: 12 additions & 26 deletions tools/workspace/drake_visualizer/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def _impl(repository_ctx):
fail(os_result.error)

if os_result.is_macos:
archive = "dv-0.1.0-337-g70c49254-python-2.7.16-qt-5.12.3-vtk-8.2.0-mac-x86_64.tar.gz" # noqa
sha256 = "54b6bc535691518139ec4902ba7de3af756bd8cbf7a004bf8422b5e2cb6652ef" # noqa
archive = "dv-0.1.0-406-g4c3e570a-python-3.7.5-qt-5.13.2-vtk-8.2.0-mac-x86_64.tar.gz" # noqa
sha256 = "88a2c1b6b908e6ec93425208e7ecca5041a17931755062467b995e18fd52c815" # noqa
elif os_result.ubuntu_release == "18.04":
archive = "dv-0.1.0-337-g70c49254-python-2.7.15-qt-5.9.5-vtk-8.2.0-bionic-x86_64.tar.gz" # noqa
sha256 = "a4d630e907b97fd2e77d2fb8384693494471c9db97be1eaf481c369854c6d50a" # noqa
archive = "dv-0.1.0-406-g4c3e570a-python-3.6.8-qt-5.9.5-vtk-8.2.0-bionic-x86_64.tar.gz" # noqa
sha256 = "70043c4bff0ea142e06b2b26c9dfceb549db5131c14a139bc57e1b4fa35094af" # noqa
else:
fail("Operating system is NOT supported", attr = os_result)

Expand All @@ -77,16 +77,16 @@ def _impl(repository_ctx):
type = "tar.gz",
)

# TODO(jamiesnape): No reason why this file needs to be constructed inline
# now. Move to a package.BUILD.bazel file, or similar, and symlink.
file_content = """# -*- python -*-
# DO NOT EDIT: generated by drake_visualizer_repository()
load("@python//:version.bzl", "PYTHON_VERSION")
licenses([
"notice", # Apache-2.0 AND BSD-3-Clause AND Python-2.0
"reciprocal", # MPL-2.0
"restricted", # LGPL-2.1-only AND LGPL-2.1-or-later AND LGPL-3.0-or-later
"restricted", # LGPL-2.1-only AND LGPL-3.0-or-later
"unencumbered", # Public-Domain
])
Expand All @@ -95,7 +95,6 @@ licenses([
# bot2-lcmgl: LGPL-3.0-or-later
# ctkPythonConsole: Apache-2.0
# Eigen: BSD-3-Clause AND MPL-2.0 AND Public-Domain
# LCM: BSD-3-Clause AND LGPL-2.1-only AND LGPL-2.1-or-later
# Python: Python-2.0
# PythonQt: LGPL-2.1-only
# QtPropertyBrowser: LGPL-2.1-only
Expand All @@ -104,31 +103,20 @@ licenses([
py_library(
name = "drake_visualizer_python_deps",
deps = [
"@lcm//:lcm-python",
"@lcmtypes_bot2_core//:lcmtypes_bot2_core_py",
# TODO(eric.cousineau): Expose VTK Python libraries here for Linux.
"@lcmtypes_robotlocomotion//:lcmtypes_robotlocomotion_py",
],
visibility = ["//visibility:public"],
)
filegroup(
name = "lcm_python2",
srcs = [
"lib/python2.7/site-packages/lcm/__init__.py",
"lib/python2.7/site-packages/lcm/_lcm.so",
],
visibility = ["//visibility:public"],
)
filegroup(
name = "drake_visualizer",
srcs = glob([
"lib/libPythonQt.*",
"lib/libddApp.*",
"lib/python2.7/site-packages/bot_lcmgl/**/*.py",
"lib/python2.7/site-packages/director/**/*.py",
"lib/python2.7/site-packages/director/**/*.so",
"lib/python2.7/site-packages/urdf_parser_py/**/*.py",
"lib/**/*.dylib",
"lib/**/*.py",
"lib/**/*.so",
]) + [
"bin/drake-visualizer",
"share/doc/director/LICENSE.txt",
Expand All @@ -141,13 +129,11 @@ filegroup(
visibility = ["//visibility:public"],
)
PY_VERSION_FILES = PYTHON_VERSION.startswith("3.") and [":lcm_python2"] or []
load("@drake//tools/install:install.bzl", "install_files")
install_files(
name = "install",
dest = ".",
files = [":drake_visualizer"] + PY_VERSION_FILES,
files = [":drake_visualizer"],
visibility = ["//visibility:public"],
)
"""
Expand Down
Loading

0 comments on commit 5ded94c

Please sign in to comment.