Skip to content

Commit

Permalink
Adding Python 2 support (#11)
Browse files Browse the repository at this point in the history
Adding Python 2 support.
  • Loading branch information
Jason authored Nov 11, 2020
1 parent 813e52f commit 1fc1ef5
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FROM quay.io/pypa/manylinux2014_x86_64

RUN yum install npm git -y -q && npm install -g @bazel/bazelisk
RUN yum install npm git python-devel python2-pip -y -q && npm install -g @bazel/bazelisk && pip install wheel && pip install --upgrade pip

RUN mkdir -p /tmp/embag /tmp/pip_build /tmp/out
COPY WORKSPACE /tmp/embag
Expand Down
2 changes: 0 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ load("@pybind11_bazel//:python_configure.bzl", "python_configure")

python_configure(
name = "local_config_python",
# Change this to "2" when compiling for Python 2. I'm unclear if it's possible to have both targets at the same time...
python_version = "3",
)

# Experimental python rules
Expand Down
55 changes: 32 additions & 23 deletions pip_package/build.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,36 @@
#!/bin/bash -e

# Build embag for various version of Python
for version in cp35-cp35m \
cp36-cp36m \
cp37-cp37m \
cp38-cp38 \
cp39-cp39
do
# Link the correct version of python
ln -sf /opt/python/$version/bin/python /usr/bin/python3
# Build embag libs and echo test binary
(cd /tmp/embag && \
PYTHON_BIN_PATH=/opt/python/$version/bin/python bazel build //python:libembag.so //embag_echo:embag_echo && \
bazel test test:* --test_output=all)
function build() {
PYTHON_PATH=$1
PYTHON_VERSION=$2

# Build embag libs and echo test binary
(cd /tmp/embag &&
PYTHON_BIN_PATH="$PYTHON_PATH/python" bazel build //python:libembag.so //embag_echo:embag_echo &&
PYTHON_BIN_PATH="$PYTHON_PATH/python" bazel test //test:embag_test "//test:embag_test_python$PYTHON_VERSION" --cache_test_results=no --test_output=all)

# Build wheel
cp /tmp/embag/bazel-bin/python/libembag.so /tmp/pip_build/embag
(cd /tmp/pip_build && "$PYTHON_PATH/python" setup.py bdist_wheel &&
auditwheel repair /tmp/pip_build/dist/embag*.whl --plat manylinux2014_x86_64 &&
"$PYTHON_PATH/pip" install wheelhouse/embag*.whl &&
"$PYTHON_PATH/python" -c 'import embag; embag.View(); print("Successfully loaded embag!")' &&
cp wheelhouse/* /tmp/out &&
rm wheelhouse/* &&
rm -rf build dist)
}

# Build wheel
cp /tmp/embag/bazel-bin/python/libembag.so /tmp/pip_build/embag
(cd /tmp/pip_build && /opt/python/$version/bin/python setup.py bdist_wheel && \
auditwheel repair /tmp/pip_build/dist/embag*.whl --plat manylinux2014_x86_64 && \
/opt/python/$version/bin/pip install wheelhouse/embag*.whl && \
/opt/python/$version/bin/python -c 'import embag; embag.View(); print("Successfully loaded embag!")' &&\
cp wheelhouse/* /tmp/out && \
rm wheelhouse/* && \
rm -rf build dist)
done
# Build embag for Python 2 (soon to be deprecated)
build "/usr/bin" 2

# Build embag for various version of Python 3
for version in cp35-cp35m \
cp36-cp36m \
cp37-cp37m \
cp38-cp38 \
cp39-cp39; do
# Link the correct version of python
ln -sf /opt/python/$version/bin/python /usr/bin/python3

build "/opt/python/$version/bin" 3
done
2 changes: 1 addition & 1 deletion pip_package/macos_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ cp -r pip_package/* README.md LICENSE /tmp/pip_build

# Build embag libs and echo test binary
bazel build //python:libembag.so //embag_echo:embag_echo && \
bazel test test:* --test_output=all
bazel test //test:embag_test //test:embag_test_python3 --test_output=all

# Build wheel
cp bazel-bin/python/libembag.so /tmp/pip_build/embag
Expand Down
2 changes: 2 additions & 0 deletions pip_package/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def finalize_options(self):
'License :: OSI Approved :: MIT License',
'Operating System :: POSIX',
'Operating System :: MacOS',
'Programming Language :: Python :: 2',
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
Expand Down
24 changes: 24 additions & 0 deletions pip_package/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#import embag as rosbag
import embag


#bag = rosbag.Bag('_2019-05-29-18-10-41_190.bag')
#bag = rosbag.Bag('truck-201_run-15955_2020-03-12-00-06-09_slim_107.bag')
#bag = rosbag.Bag('truck-201_run-15955_2020-03-12-00-06-09_luminar_107.bag')

#for topic, msg, t in bag.read_messages(topics=['/luminar_pointcloud']):
#for topic, msg, t in bag.read_messages(topics=['/perception/tracked_lanes']):
#for topic, msg, t in bag.read_messages(topics=['/applanix/nav']):
#for topic, msg, t in bag.read_messages(topics=['/diagnostics']):
# print(topic)
# print(t)
# print(msg)

#bag.close()

view = embag.View().addBag('/home/jason/Downloads/truck-203_run-16938_2020-06-29-21-50-28_slim_6.bag')
for msg in view.getMessages('/diagnostics'):
#for msg in view.getMessages('/self_driving_state'):
print(msg.topic)
print(msg.timestamp.to_sec())
print(msg)
15 changes: 14 additions & 1 deletion test/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,23 @@ cc_test(
)

py_test(
name = "embag_test_python",
name = "embag_test_python3",
main = "embag_test_python.py",
srcs = ["embag_test_python.py"],
data = [
"test.bag",
"//python:libembag.so",
],
python_version = "PY3",
)

py_test(
name = "embag_test_python2",
main = "embag_test_python.py",
srcs = ["embag_test_python.py"],
data = [
"test.bag",
"//python:libembag.so",
],
python_version = "PY2",
)

0 comments on commit 1fc1ef5

Please sign in to comment.