Skip to content

Commit

Permalink
pydrake: Expose pybind11 version information
Browse files Browse the repository at this point in the history
  • Loading branch information
EricCousineau-TRI committed Feb 21, 2018
1 parent 80f92a8 commit 6d25f60
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
25 changes: 25 additions & 0 deletions bindings/pydrake/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ load(
"drake_py_library",
"drake_py_test",
)
load(
"//tools/workspace/pybind11:repository.bzl",
"generate_pybind11_version_py_file",
)

package(default_visibility = [
"//bindings/pydrake:__subpackages__",
Expand Down Expand Up @@ -132,6 +136,19 @@ drake_cc_library(
hdrs = ["type_safe_index_pybind.h"],
)

generate_pybind11_version_py_file(
name = "pybind11_version.py",
)

drake_py_library(
name = "pybind11_version_py",
srcs = ["pybind11_version.py"],
tags = ["nolint"], # Do not lint generated files.
deps = [
":module_py",
],
)

PY_LIBRARIES_WITH_INSTALL = [
":eigen_geometry_py",
]
Expand All @@ -142,6 +159,7 @@ PY_LIBRARIES = [
":cpp_template_py",
":module_py",
":module_shim_py",
":pybind11_version_py",
]

# Symbol roll-up (for user ease).
Expand Down Expand Up @@ -261,4 +279,11 @@ drake_pybind_cc_googletest(
],
)

drake_py_test(
name = "pybind11_version_test",
deps = [
":pybind11_version_py",
],
)

add_lint_tests()
20 changes: 20 additions & 0 deletions bindings/pydrake/util/test/pybind11_version_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
"""
Tests `pybind11` version information available from Drake.
"""

from __future__ import print_function

import pydrake.util.pybind11_version as mut

import unittest


class TestPybind11Version(unittest.TestCase):
def test_values(self):
self.assertTrue(isinstance(mut.repository, str))
self.assertTrue(isinstance(mut.commit, str))
self.assertTrue(isinstance(mut.sha256, str))


if __name__ == '__main__':
unittest.main()
32 changes: 29 additions & 3 deletions tools/workspace/pybind11/repository.bzl
Original file line number Diff line number Diff line change
@@ -1,12 +1,38 @@
# -*- python -*-

load("//tools/workspace:generate_file.bzl", "generate_file")
load("@drake//tools/workspace:github.bzl", "github_archive")

_REPOSITORY = "RobotLocomotion/pybind11"

_COMMIT = "e19086472c664078b0ba77432001a89f97784c8d"

_SHA256 = "62f1ae603f896e810339a23ed8695e6273d0936c6d77bd150cade67b76b06373"

def pybind11_repository(name):
github_archive(
name = name,
repository = "RobotLocomotion/pybind11",
commit = "e19086472c664078b0ba77432001a89f97784c8d",
sha256 = "62f1ae603f896e810339a23ed8695e6273d0936c6d77bd150cade67b76b06373", # noqa
repository = _REPOSITORY,
commit = _COMMIT,
sha256 = _SHA256,
build_file = "@drake//tools/workspace/pybind11:package.BUILD.bazel",
)

def generate_pybind11_version_py_file(name):
vars = dict(
repository = repr(_REPOSITORY),
commit = repr(_COMMIT),
sha256 = repr(_SHA256),
)
generate_file(
name = name,
content = '''
"""
Provides information on the external fork of `pybind11` used by `pydrake`.
"""
repository = {repository}
commit = {commit}
sha256 = {sha256}
'''.format(**vars)
)

0 comments on commit 6d25f60

Please sign in to comment.