Skip to content

Commit

Permalink
[wheel] Add rules to create a platform-independent wheel (#16)
Browse files Browse the repository at this point in the history
Upgrade rules_python to 0.24.0.

Remove spurous liblcm dependency from lcm-gen.
  • Loading branch information
jwnimmer-tri authored Jul 17, 2023
1 parent f9dab23 commit 8ade24c
Show file tree
Hide file tree
Showing 7 changed files with 115 additions and 35 deletions.
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,32 @@ This repository contains a python application which translates data
streamed from the Optitrack Motive software (aka NatNet) into LCM
messages.

To build:
## To build and run locally:

```bazel build //...```
```
bazel run //src:optitrack_client
```

To run:
## To build a wheel:

```bazel run //src:optitrack_client```
```
bazel build //wheel
```

Then (within a virtual environment), install the wheel file:

```
pip install bazel-bin/wheel/optitrack_driver-*-py3-none-any.whl
```

Then (within the virtual environment), run the program as either:

```
python -m optitrack.client
```

or

```
bin/optitrack_client
```
5 changes: 3 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ python_repository(name = "python")

http_archive(
name = "rules_python",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.0.1/rules_python-0.0.1.tar.gz",
sha256 = "aa96a691d3a8177f3215b14b0edc9641787abaaa30363a080165d06ab65e1161",
url = "https://github.com/bazelbuild/rules_python/releases/download/0.24.0/rules_python-0.24.0.tar.gz",
strip_prefix = "rules_python-0.24.0",
sha256 = "0a8003b044294d7840ac7d9d73eef05d6ceb682d7516781a4ec62eeb34702578",
)

load("@rules_python//python:repositories.bzl", "py_repositories")
Expand Down
28 changes: 0 additions & 28 deletions install-optitrack.sh

This file was deleted.

36 changes: 36 additions & 0 deletions lcmtypes/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,41 @@ LCM_SRCS = [
"optitrack_skeleton_t.lcm",
]

# Also provide the srcs in a package-specific subdir.
[
genrule(
name = "_cp_" + x,
srcs = [x],
outs = ["optitrack/" + x],
cmd = "cp $< $@",
visibility = ["//visibility:private"],
)
for x in LCM_SRCS
]

filegroup(
name = "lcm_srcs_with_subdir",
srcs = [
":optitrack/" + x
for x in LCM_SRCS
],
)

lcm_cc_library(
name = "optitrack_lcmtypes",
lcm_package = "optitrack",
lcm_srcs = LCM_SRCS,
linkstatic = 1,
)

filegroup(
name = "cxx_srcs",
srcs = [
":optitrack/" + x.replace(".lcm", ".hpp")
for x in LCM_SRCS
],
)

lcm_py_library(
name = "py_optitrack_lcmtypes",
lcm_package = "optitrack",
Expand All @@ -38,3 +66,11 @@ lcm_java_library(
lcm_package = "optitrack",
lcm_srcs = LCM_SRCS,
)

filegroup(
name = "java_srcs",
srcs = [
":optitrack/" + x.replace(".lcm", ".java")
for x in LCM_SRCS
],
)
2 changes: 1 addition & 1 deletion tools/lcm.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ cc_binary(
cc_binary(
name = "lcm-gen",
srcs = [
"lcm/lcm_version.h",
"lcmgen/emit_c.c",
"lcmgen/emit_cpp.c",
"lcmgen/emit_csharp.c",
Expand All @@ -150,7 +151,6 @@ cc_binary(
copts = LCM_COPTS,
includes = ["."],
deps = [
":lcm",
"@glib",
],
)
Expand Down
1 change: 1 addition & 0 deletions version.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERSION = "0.0.20230714"
48 changes: 48 additions & 0 deletions wheel/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# -*- python -*-
# This file contains rules for the Bazel build system; see https://bazel.build.

load("//:version.bzl", "VERSION")
load("@rules_python//python:packaging.bzl", "py_wheel")

licenses(["notice"])

package(default_visibility = ["//visibility:private"])

genrule(
name = "_cp_client",
srcs = ["//src:optitrack_client.py"],
outs = ["optitrack/client.py"],
cmd = "cp $< $@",
)

py_library(
name = "client",
srcs = [":optitrack/client.py"],
)

py_wheel(
name = "wheel",
visibility = ["//visibility:public"],
distribution = "optitrack_driver",
version = VERSION,
summary = "Translates data streamed from the Optitrack Motive software into LCM messages.",
requires = [
"lcm",
],
entry_points = {
"console_scripts": [
"optitrack_client = optitrack.client:main",
],
},
deps = [
":client",
"//lcmtypes:cxx_srcs",
"//lcmtypes:java_srcs",
"//lcmtypes:lcm_srcs_with_subdir",
"//lcmtypes:py_optitrack_lcmtypes",
],
strip_path_prefixes = [
"lcmtypes/",
"wheel/",
],
)

0 comments on commit 8ade24c

Please sign in to comment.