Skip to content

Commit

Permalink
Draft support for python3.9 as present in Raspberry Pi OS "bullseye"
Browse files Browse the repository at this point in the history
  • Loading branch information
jpieper committed Nov 22, 2021
1 parent 9d657a8 commit 819c00d
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 29 deletions.
16 changes: 15 additions & 1 deletion BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- python -*-

# Copyright 2020 Josh Pieper, [email protected].
# Copyright 2020-2021 Josh Pieper, [email protected].
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,3 +47,17 @@ test_suite(
"//lib/cpp/mjbots/moteus:test",
],
)

config_setting(
name = "python37",
values = {
"define": "PYTHON=3.7",
},
)

config_setting(
name = "python39",
values = {
"define": "PYTHON=3.9",
},
)
55 changes: 38 additions & 17 deletions lib/python/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- python -*-

# Copyright 2020 Josh Pieper, [email protected].
# Copyright 2020-2021 Josh Pieper, [email protected].
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -22,6 +22,9 @@ load("//tools/workspace:template_file.bzl", "template_file")

VERSION="0.3.14"

PYTHON_SHORT_VERSIONS = ['37', '39']


# It would be nice to pull this from the python source. As it is, the
# below genrule will fail if they don't match, so at least there is
# some verification.
Expand All @@ -35,32 +38,50 @@ pkg_tar(
],
)

template_file(
name = "setup.py",
src = "setup.py.TPL",
substitutions = {
"{{VERSION}}" : '"{}"'.format(VERSION),
},
)

genrule(
name = "bdist_wheel",
srcs = ["setup.py", ":wheel_tar", "README.md"],
[
template_file(
name = "setup_{pyshortver}.py".format(pyshortver=pyshortver),
src = "setup.py.TPL",
substitutions = {
"{{VERSION}}" : '"{}"'.format(VERSION),
"{{PYTHON_SHORT_VERSION}}" : '"{}"'.format(pyshortver),
},
)
for pyshortver in PYTHON_SHORT_VERSIONS
]


[genrule(
name = "bdist_wheel_{pyshortver}".format(pyshortver=pyshortver),
srcs = ["setup_{pyshortver}.py".format(pyshortver=pyshortver),
":wheel_tar", "README.md"],
outs = [
"moteus_pi3hat-{ver}-cp37-abi3-linux_armv7l.whl".format(ver=VERSION),
"moteus_pi3hat-{ver}-cp{pyshortver}-abi3-linux_armv7l.whl".format(
ver=VERSION, pyshortver=pyshortver),
],
cmd = (
"OUTDIR=$$(dirname $(location moteus_pi3hat-{ver}-cp37-abi3-linux_armv7l.whl)) && " +
"OUTDIR=$$(dirname $(location moteus_pi3hat-{ver}-cp{pyshortver}-abi3-linux_armv7l.whl)) && " +
"BUILDDIR=$$OUTDIR/build && " +
"mkdir -p $$BUILDDIR && " +
"tar xf $(location wheel_tar) -C $$BUILDDIR && " +
"cp $(location setup.py) $(location README.md) $$BUILDDIR && " +
"cp $(location setup_{pyshortver}.py) $(location README.md) $$BUILDDIR && " +
"cd $$BUILDDIR && " +
"python3 setup.py bdist_wheel " +
"python3.9 setup_{pyshortver}.py bdist_wheel " +
" --plat-name linux_armv7l " +
" --py-limited-api cp37 " +
" --py-limited-api cp{pyshortver} " +
" --dist-dir .. " +
" 1>/dev/null" +
""
).format(ver=VERSION),
).format(ver=VERSION, pyshortver=pyshortver),
)
for pyshortver in PYTHON_SHORT_VERSIONS
]

filegroup(
name="bdist_wheel",
srcs = select({
"//:python37" : [":bdist_wheel_37"],
"//:python39" : [":bdist_wheel_39"],
}),
)
9 changes: 6 additions & 3 deletions lib/python/moteus_pi3hat/BUILD
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- python -*-

# Copyright 2020 Josh Pieper, [email protected].
# Copyright 2020-2021 Josh Pieper, [email protected].
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -22,11 +22,14 @@ cc_binary(
"_pi3hat_router.cc",
],
deps = [
"@com_github_pybind_pybind11//:pybind11",
"//lib/cpp/mjbots/pi3hat:libpi3hat",
"//lib/cpp/mjbots/moteus:common",
"@org_llvm_libcxx//:libcxx",
],
] + select({
"//conditions:default" : [],
"//:python37" : ["@com_github_pybind_pybind11//:pybind11_37"],
"//:python39" : ["@com_github_pybind_pybind11//:pybind11_39"],
}),
linkshared = True,
)

Expand Down
6 changes: 4 additions & 2 deletions lib/python/setup.py.TPL
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- python -*-

# Copyright 2020 Josh Pieper, [email protected].
# Copyright 2020-2021 Josh Pieper, [email protected].
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -50,7 +50,9 @@ setuptools.setup(
entry_points = {
'moteus.transports': [ 'pi3hat=moteus_pi3hat:Pi3HatFactory' ],
},
python_requires = '>=3.7, <4',
python_requires = {"37" : ">=3.7, <3.8",
"39" : ">=3.9, <3.10"
}[{{PYTHON_SHORT_VERSION}}],
install_requires = [
'moteus>=0.3.22',
],
Expand Down
11 changes: 8 additions & 3 deletions make_release.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/python3

# Copyright 2020 Josh Pieper, [email protected].
# Copyright 2020-2021 Josh Pieper, [email protected].
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -48,8 +48,13 @@ def main():

run(f'cp bazel-bin/fw/pi3_hat.elf {outdir}/{datestr}-pi3hat-{git_hash}.elf')

run('tools/bazel build --config=pi -c opt //:pi3hat_tools')
run(f'cp bazel-bin/pi3hat_tools.tar.bz2 {outdir}/{datestr}-pi3hat_tools-{git_hash}.tar.bz2')
for pyver in ['3.7', '3.9']:
run(f'tools/bazel build --config=pi --define PYTHON={pyver} -c opt //:pi3hat_tools')
run(f'cp bazel-bin/pi3hat_tools.tar.bz2 {outdir}/{datestr}-pi3hat_tools-cp{pyver.replace(".","")}-{git_hash}.tar.bz2')

wheel_name = subprocess.check_output("tar --list -f bazel-bin/pi3hat_tools.tar.bz2 | grep \.whl$", shell=True).decode('utf8').strip()
run(f'tar -C {outdir} --strip-components 2 --extract -f bazel-bin/pi3hat_tools.tar.bz2 {wheel_name}')


print()
print('DONE')
Expand Down
4 changes: 2 additions & 2 deletions tools/workspace/bazel_deps/repository.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ def bazel_deps_repository(name):
github_archive(
name = name,
repo = "mjbots/bazel_deps",
commit = "f7f68a03982bfcc09faa8cb6e2a1564eacc6106c",
sha256 = "356f34a15c75a4e5e91baedcc9972874ca2395c37f656fb33c9a2f816da88e6c",
commit = "aa535e43e64371aee713badac0e93dd781ee720d",
sha256 = "ac7c64007f21de3782f045d8b389bec9bb488fd2465cc21c31cc0f16fdf71906",
)
11 changes: 10 additions & 1 deletion tools/workspace/pybind11/package.BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@
package(default_visibility = ["//visibility:public"])

cc_library(
name = "pybind11",
name = "pybind11_37",
hdrs = glob(["include/**"]),
includes = ["include"],
deps = [
"@python37//:headers",
],
)

cc_library(
name = "pybind11_39",
hdrs = glob(["include/**"]),
includes = ["include"],
deps = [
"@python39//:headers",
],
)

0 comments on commit 819c00d

Please sign in to comment.