Skip to content

Commit

Permalink
Revert "Install .pyi files (#17709)"
Browse files Browse the repository at this point in the history
This reverts commit a61a184.
  • Loading branch information
BetsyMcPhail authored Aug 18, 2022
1 parent 33a3348 commit d3d28e2
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 232 deletions.
160 changes: 20 additions & 140 deletions bindings/pydrake/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ load(
"get_pybind_package_info",
)
load("//bindings/pydrake:pydrake.bzl", "add_lint_tests_pydrake")
load("//bindings/pydrake:stubgen.bzl", "generate_python_stubs")

package(default_visibility = [
"//bindings:__subpackages__",
Expand Down Expand Up @@ -358,6 +357,18 @@ drake_py_library(
],
)

install(
name = "install",
install_tests = [
":test/all_install_test.py",
":test/common_install_test.py",
],
targets = PY_LIBRARIES + [":all_py"],
py_dest = PACKAGE_INFO.py_dest,
visibility = ["//visibility:public"],
deps = get_drake_py_installs(PY_LIBRARIES_WITH_INSTALL),
)

drake_cc_googletest(
name = "documentation_pybind_test",
deps = [
Expand Down Expand Up @@ -675,153 +686,22 @@ generate_pybind_coverage(
drake_py_binary(
name = "stubgen",
srcs = ["stubgen.py"],
args = ["--package=pydrake"],
deps = [
":all_py",
"@mypy_internal//:mypy",
],
)

# TODO(jwnimmer-tri): This list should be automatically generated.
PYI_FILES = [
"pydrake/__init__.pyi",
"pydrake/all.pyi",
"pydrake/autodiffutils.pyi",
"pydrake/common/__init__.pyi",
"pydrake/common/_module_py.pyi",
"pydrake/common/all.pyi",
"pydrake/common/compatibility.pyi",
"pydrake/common/containers.pyi",
"pydrake/common/cpp_param.pyi",
"pydrake/common/cpp_template.pyi",
"pydrake/common/deprecation.pyi",
"pydrake/common/eigen_geometry.pyi",
"pydrake/common/jupyter.pyi",
"pydrake/common/pybind11_version.pyi",
"pydrake/common/schema.pyi",
"pydrake/common/value.pyi",
"pydrake/common/yaml.pyi",
"pydrake/examples/__init__.pyi",
"pydrake/examples/_examples_extra.pyi",
"pydrake/examples/acrobot.pyi",
"pydrake/examples/compass_gait.pyi",
"pydrake/examples/manipulation_station.pyi",
"pydrake/examples/multibody/__init__.pyi",
"pydrake/examples/multibody/cart_pole_passive_simulation.pyi",
"pydrake/examples/multibody/pendulum_lqr_monte_carlo_analysis.pyi",
"pydrake/examples/multibody/run_planar_scenegraph_visualizer.pyi",
"pydrake/examples/pendulum.pyi",
"pydrake/examples/quadrotor.pyi",
"pydrake/examples/rimless_wheel.pyi",
"pydrake/examples/van_der_pol.pyi",
"pydrake/forwarddiff.pyi",
"pydrake/geometry.pyi",
"pydrake/lcm.pyi",
"pydrake/manipulation/__init__.pyi",
"pydrake/manipulation/all.pyi",
"pydrake/manipulation/kuka_iiwa.pyi",
"pydrake/manipulation/planner.pyi",
"pydrake/manipulation/schunk_wsg.pyi",
"pydrake/math.pyi",
"pydrake/multibody/__init__.pyi",
"pydrake/multibody/all.pyi",
"pydrake/multibody/benchmarks.pyi",
"pydrake/multibody/inverse_kinematics.pyi",
"pydrake/multibody/jupyter_widgets.pyi",
"pydrake/multibody/math.pyi",
"pydrake/multibody/meshcat.pyi",
"pydrake/multibody/optimization.pyi",
"pydrake/multibody/parsing.pyi",
"pydrake/multibody/plant.pyi",
"pydrake/multibody/tree.pyi",
"pydrake/perception.pyi",
"pydrake/polynomial.pyi",
"pydrake/solvers/__init__.pyi",
"pydrake/solvers/_extra.pyi",
"pydrake/solvers/all.pyi",
"pydrake/solvers/augmented_lagrangian.pyi",
"pydrake/solvers/branch_and_bound.pyi",
"pydrake/solvers/clp.pyi",
"pydrake/solvers/csdp.pyi",
"pydrake/solvers/dreal.pyi",
"pydrake/solvers/gurobi.pyi",
"pydrake/solvers/ibex.pyi",
"pydrake/solvers/ipopt.pyi",
"pydrake/solvers/mathematicalprogram.pyi",
"pydrake/solvers/mixed_integer_optimization_util.pyi",
"pydrake/solvers/mixed_integer_rotation_constraint.pyi",
"pydrake/solvers/mosek.pyi",
"pydrake/solvers/nlopt.pyi",
"pydrake/solvers/osqp.pyi",
"pydrake/solvers/scs.pyi",
"pydrake/solvers/sdpa_free_format.pyi",
"pydrake/solvers/snopt.pyi",
# "pydrake/stubgen.pyi", Don't include this; why is it even generated?
"pydrake/symbolic.pyi",
"pydrake/systems/__init__.pyi",
"pydrake/systems/_resample_interp1d.pyi",
"pydrake/systems/all.pyi",
"pydrake/systems/analysis.pyi",
"pydrake/systems/controllers.pyi",
"pydrake/systems/drawing.pyi",
"pydrake/systems/framework.pyi",
"pydrake/systems/jupyter_widgets.pyi",
"pydrake/systems/lcm.pyi",
"pydrake/systems/meshcat_visualizer.pyi",
"pydrake/systems/perception.pyi",
"pydrake/systems/planar_scenegraph_visualizer.pyi",
"pydrake/systems/primitives.pyi",
"pydrake/systems/pyplot_visualizer.pyi",
"pydrake/systems/rendering.pyi",
"pydrake/systems/scalar_conversion.pyi",
"pydrake/systems/sensors.pyi",
"pydrake/systems/trajectory_optimization.pyi",
"pydrake/trajectories.pyi",
"pydrake/tutorials.pyi",
"pydrake/visualization/__init__.pyi",
"pydrake/visualization/all.pyi",
"pydrake/visualization/meldis.pyi",
"pydrake/visualization/plotting.pyi",
]

# TODO(mwoehlke-kitware): genrule inappropriately gives execute permission to
# all its outputs; see https://github.com/bazelbuild/bazel/issues/3359.
# (Applies to both :pydrake_pyi and, below, :pydrake_typed.)
generate_python_stubs(
name = "pydrake_pyi",
outs = PYI_FILES,
package = "pydrake",
tool = ":stubgen",
)

# PEP 561 marker file; tells tools that type information is available.
genrule(
name = "pydrake_typed",
srcs = [],
outs = ["pydrake/py.typed"],
cmd = "echo '# Marker file for PEP 561.' > $@",
)

install(
name = "install",
install_tests = [
":test/all_install_test.py",
":test/common_install_test.py",
],
targets = PY_LIBRARIES + [":all_py"],
py_dest = PACKAGE_INFO.py_dest,
data = [
":pydrake_pyi",
":pydrake_typed",
],
data_dest = "@PYTHON_SITE_PACKAGES@",
visibility = ["//visibility:public"],
deps = get_drake_py_installs(PY_LIBRARIES_WITH_INSTALL),
)
# TODO(mwoehlke-kitware): actually install the .pyi's.

drake_py_unittest(
name = "pyi_sanity_test",
data = [":pydrake_pyi"],
deps = ["@bazel_tools//tools/python/runfiles"],
name = "stubgen_test",
timeout = "moderate",
deps = [
":all_py",
"@mypy_internal//:mypy",
],
)

add_lint_tests_pydrake(
Expand Down
33 changes: 0 additions & 33 deletions bindings/pydrake/stubgen.bzl

This file was deleted.

11 changes: 0 additions & 11 deletions bindings/pydrake/test/all_install_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ def test_install(self):
env=tool_env
)

def test_type_stubs(self):
# Get pydrake directory.
install_dir = install_test_helper.get_install_dir()
site_packages = \
install_test_helper.get_python_site_packages_dir(install_dir)
# Ensure some files are present.
self.assertTrue(
os.path.exists(os.path.join(site_packages, 'pydrake', 'py.typed')))
self.assertTrue(
os.path.exists(os.path.join(site_packages, 'pydrake', 'all.pyi')))


if __name__ == '__main__':
unittest.main()
29 changes: 0 additions & 29 deletions bindings/pydrake/test/pyi_sanity_test.py

This file was deleted.

36 changes: 36 additions & 0 deletions bindings/pydrake/test/stubgen_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Tests generation of Drake's Python Interface files (.pyi)."""

import os
import unittest

from mypy import stubgen

# Mypy can time out if importing takes an inordinate length of time. Try to
# avoid this by importing ourselves up front when the import isn't being run
# under a timeout.
import pydrake.all


class TestStubgen(unittest.TestCase):
# TODO(mwoehlke-kitware): test the already-generated files instead.
def test_generation(self):
"""Ensure that stubgen runs and generates output.
For now, this is more or less just a smoke test, with a very cursory
check that the output is 'reasonable'.
"""
output_dir = os.environ['TEST_TMPDIR']
args = ['--package', 'pydrake', '--output', output_dir]

# Generate stubs.
result = stubgen.main(args)
self.assertTrue(result is None or result == 0)

# Find some of the expected output and look for an expected function.
expected = os.path.join(output_dir, 'pydrake', '__init__.pyi')
found_expected_decl = False
for line in open(expected, 'r'):
if line.startswith('def getDrakePath():'):
found_expected_decl = True
break
self.assertTrue(found_expected_decl)
4 changes: 0 additions & 4 deletions tools/wheel/image/provision-python.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,8 @@ apt-get -y install --no-install-recommends \

${PYTHON} -m venv /usr/local

# TODO(jwnimmer-tri): Should these be version-pinned? What's the process for
# keeping them up to date if they are?
pip install \
lxml \
matplotlib \
numpy \
pyyaml \
semantic-version \
setuptools \
Expand Down
2 changes: 0 additions & 2 deletions tools/wheel/image/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ def _actually_find_packages():
include_package_data=True,
package_data={
'': find_data_files(
'pydrake/py.typed',
'pydrake/**/*.pyi',
'pydrake/**/*.so',
'pydrake/lib/**',
'pydrake/doc/**',
Expand Down
13 changes: 0 additions & 13 deletions tools/wheel/test/test-wheel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,3 @@ pypi_wheel_max_size = 100 << 20 # 100 MiB
fail_message = f"Wheel is too large ({wheel_size_in_mib:.2f} MiB) for PyPI"
assert wheel_size < pypi_wheel_max_size, fail_message
EOF

python - "$1" << EOF
import os
import pydrake
def assert_exists(path):
assert os.path.exists(path), f"{path!r} does not exist!"
# Check that type information files are present.
pydrake_dir = pydrake.__path__[0]
assert_exists(os.path.join(pydrake_dir, 'py.typed'))
assert_exists(os.path.join(pydrake_dir, 'all.pyi'))
EOF

0 comments on commit d3d28e2

Please sign in to comment.