Skip to content

Commit

Permalink
py2and3: Minor compatibility updates
Browse files Browse the repository at this point in the history
  • Loading branch information
EricCousineau-TRI committed Dec 10, 2018
1 parent 5861852 commit a2fc39e
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 9 deletions.
1 change: 1 addition & 0 deletions bindings/pydrake/common/test/drake_variant_pybind_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ GTEST_TEST(VariantTest, CheckCasting) {
py::module m("__main__");

m.def("VariantToString", &VariantToString, py::arg("value"));
py::globals().attr("update")(m.attr("__dict__"));
ExpectString("VariantToString(1)", "int(1)");
ExpectString("VariantToString(0.5)", "double(0.5)");
ExpectString("VariantToString('foo')", "string(foo)");
Expand Down
5 changes: 4 additions & 1 deletion bindings/pydrake/manipulation/simple_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
and potentially other robotics) applications.
"""

import Tkinter as tk
try:
import tkinter as tk
except ImportError:
import Tkinter as tk
import numpy as np

from pydrake.multibody.multibody_tree.multibody_plant import MultibodyPlant
Expand Down
5 changes: 4 additions & 1 deletion bindings/pydrake/manipulation/test/simple_ui_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import unittest

import numpy as np
import Tkinter as tk
try:
import tkinter as tk
except ImportError:
import Tkinter as tk

from pydrake.common import FindResourceOrThrow
from pydrake.multibody.multibody_tree.multibody_plant import MultibodyPlant
Expand Down
5 changes: 2 additions & 3 deletions bindings/pydrake/systems/drawing.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
installed.
"""

from sys import maxint
from tempfile import NamedTemporaryFile

import matplotlib.pyplot as plt
Expand Down Expand Up @@ -38,6 +37,6 @@ def plot_graphviz(dot_text):
return plt.imshow(plt.imread(f.name), aspect="equal")


def plot_system_graphviz(system, max_depth=maxint):
def plot_system_graphviz(system, **kwargs):
"""Renders a System's Graphviz representation in `matplotlib`."""
return plot_graphviz(system.GetGraphvizString(max_depth))
return plot_graphviz(system.GetGraphvizString(**kwargs))
5 changes: 3 additions & 2 deletions bindings/pydrake/systems/meshcat_visualizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package, Meshcat:
https://github.com/rdeits/meshcat
"""
from __future__ import print_function
import argparse
import math
import webbrowser
Expand Down Expand Up @@ -179,8 +180,8 @@ def load(self):
meshcat.geometry.ObjMeshGeometry.from_file(
geom.string_data[0:-3] + "obj")
else:
print "UNSUPPORTED GEOMETRY TYPE ", \
geom.type, " IGNORED"
print("UNSUPPORTED GEOMETRY TYPE {} IGNORED".format(
geom.type))
continue

# Turn a list of R,G,B elements (any indexable list of >= 3
Expand Down
3 changes: 2 additions & 1 deletion common/test_utilities/drake_py_unittest_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import argparse
import imp
import io
import os
import re
import sys
Expand Down Expand Up @@ -33,7 +34,7 @@
if not found_filename:
raise RuntimeError("No such file found {}!".format(
test_filename))
with open(found_filename, "r") as infile:
with io.open(found_filename, "r", encoding="utf8") as infile:
for line in infile.readlines():
if any([line.startswith("if __name__ =="),
line.strip().startswith("unittest.main")]):
Expand Down
5 changes: 4 additions & 1 deletion examples/manipulation_station/end_effector_teleop.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@

import argparse

import Tkinter as tk
try:
import tkinter as tk
except ImportError:
import Tkinter as tk
import numpy as np

from pydrake.common import FindResourceOrThrow
Expand Down

0 comments on commit a2fc39e

Please sign in to comment.