Skip to content

Commit 7966a8d

Browse files
committed
Merge pull request #91 from rtbot-dev/RB-388
RB-388 Recover python wheel build
2 parents 9f2c2a8 + 7ed7a40 commit 7966a8d

File tree

5 files changed

+182
-156
lines changed

5 files changed

+182
-156
lines changed

.github/workflows/release.yaml

Lines changed: 51 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,9 @@ jobs:
4444
- name: Test finance
4545
run: |
4646
bazelisk test //libs/finance/test
47-
# - name: Test python
48-
# run: |
49-
# # TODO: make sure we don't have to build the wheel and install it
50-
# # in order to make the test to pass
51-
# bazelisk build //libs/core/wrappers/python:rtbot_wheel
52-
# pip install --force-reinstall dist/bin/libs/core/wrappers/python/rtbot-_VERSION_-py3-none-manylinux2014_x86_64.whl
53-
# bazelisk test //libs/core/wrappers/python:rtbot_test
47+
- name: Test python
48+
run: |
49+
bazelisk test --incompatible_use_python_toolchains=false --python_path=$(which python) //libs/wrappers/python:rtbot_test
5450
- name: Test javascript
5551
run: |
5652
bazelisk test //libs/wrappers/javascript:test
@@ -93,13 +89,12 @@ jobs:
9389
path: dist/bin/libs/api/jsonschema
9490

9591
build_wheels:
96-
name: Build wheel on ${{ matrix.os }}
92+
name: Build wheel on ${{ matrix.os }} Python ${{ matrix.python-version }}
9793
runs-on: ${{ matrix.os }}
9894
strategy:
9995
matrix:
100-
os: [ubuntu-20.04, macOS-11, windows-2019]
101-
# TODO: add more python versions later, when we can afford the cost
102-
#python: [3.11]
96+
os: [ubuntu-20.04, macOS-12]
97+
python-version: ["3.10", "3.11", "3.12", "3.13"]
10398
steps:
10499
- uses: actions/checkout@v3
105100
- uses: pnpm/[email protected]
@@ -109,21 +104,49 @@ jobs:
109104
- args: [--frozen-lockfile]
110105
- uses: actions/setup-python@v4
111106
with:
112-
python-version: 3.11 #${{ matrix.python }}
107+
python-version: ${{ matrix.python-version }}
113108
- name: Mount bazel caches
114109
uses: actions/cache@v3
115110
with:
116111
path: |
117112
"~/.cache/bazel"
118-
key: bazel-cache-${{ matrix.os }}
113+
key: bazel-cache-${{ matrix.os }}-py${{ matrix.python-version }}
119114
- uses: bazelbuild/setup-bazelisk@v2
120115
- name: Build wheel
121116
run: |
122117
bazelisk build --stamp //libs/wrappers/python:rtbot_wheel
118+
- name: Rename wheel with platform tag
119+
run: |
120+
cd dist/bin/libs/wrappers/python/
121+
WHEEL_FILE="rtbot.whl"
122+
if [ -f "$WHEEL_FILE" ]; then
123+
# Extract version from wheel metadata
124+
VERSION=$(python -c "
125+
import zipfile, re
126+
with zipfile.ZipFile('$WHEEL_FILE', 'r') as z:
127+
for name in z.namelist():
128+
if '.dist-info/METADATA' in name:
129+
# Extract version from rtbot-VERSION.dist-info/METADATA
130+
dist_info_dir = name.split('/')[0]
131+
version = dist_info_dir.replace('rtbot-', '').replace('.dist-info', '')
132+
print(version)
133+
break
134+
")
135+
# Determine platform tag
136+
if [ "${{ runner.os }}" = "Linux" ]; then
137+
PLATFORM="manylinux2014_x86_64"
138+
else
139+
PLATFORM="macosx_10_9_x86_64"
140+
fi
141+
# Create properly named wheel
142+
NEW_NAME="rtbot-${VERSION}-py3-none-${PLATFORM}.whl"
143+
cp "$WHEEL_FILE" "$NEW_NAME"
144+
echo "Created wheel: $NEW_NAME"
145+
fi
123146
- uses: actions/upload-artifact@v3
124147
with:
125-
name: wheel-${{ matrix.os }}.tar
126-
path: dist/bin/libs/wrappers/python/rtbot-*.whl
148+
name: wheel-${{ matrix.os }}-py${{ matrix.python-version }}
149+
path: dist/bin/libs/wrappers/python/rtbot-*-py3-none-*.whl
127150

128151
publish:
129152
needs:
@@ -149,18 +172,12 @@ jobs:
149172
run: |
150173
GIT_TAG=${{ github.ref_name }}
151174
echo "version=${GIT_TAG:1}" >> $GITHUB_OUTPUT
152-
- uses: actions/download-artifact@v3
153-
with:
154-
name: wheel-ubuntu-20.04.tar
155-
path: wheel-linux
156-
- uses: actions/download-artifact@v3
157-
with:
158-
name: wheel-macOS-11.tar
159-
path: wheel-macos
160-
- uses: actions/download-artifact@v3
175+
# Download all wheel artifacts
176+
- name: Download all wheel artifacts
177+
uses: actions/download-artifact@v3
161178
with:
162-
name: wheel-windows-2019.tar
163-
path: wheel-windows
179+
path: wheels/
180+
pattern: wheel-*
164181
- uses: actions/download-artifact@v3
165182
with:
166183
name: npm-wasm.tar
@@ -173,18 +190,14 @@ jobs:
173190
with:
174191
name: jsonschema.tar
175192
path: jsonschema
176-
- name: Patch files before publishing
193+
- name: Organize wheels for release
177194
run: |
178-
ls -l
179-
cd wheel-linux
180-
mv rtbot-_VERSION_-py3-none-manylinux2014_x86_64.whl rtbot-${{ steps.version.outputs.version }}-py3-none-manylinux2014_x86_64.whl
181-
cd ..
182-
cd wheel-macos
183-
mv rtbot-_VERSION_-py3-none-macosx_10_7_x86_64.whl rtbot-${{ steps.version.outputs.version }}-py3-none-macosx_10_7_x86_64.whl
184-
cd ..
185-
cd wheel-windows
186-
mv rtbot-_VERSION_-py3-none-win_amd64.whl rtbot-${{ steps.version.outputs.version }}-py3-none-win_amd64.whl
187-
cd ..
195+
ls -la wheels/
196+
# Create directories for organizing wheels
197+
mkdir -p wheel-organized
198+
# Copy all wheels to organized directory
199+
find wheels/ -name "*.whl" -exec cp {} wheel-organized/ \;
200+
ls -la wheel-organized/
188201
# copy repo readme to main npm package
189202
cp README.md ./npm-rtbot
190203
# package npm files, which will be used on the github release
@@ -208,7 +221,5 @@ jobs:
208221
files: |
209222
*.tar.gz
210223
jsonschema/*
211-
wheel-linux/*
212-
wheel-macos/*
213-
wheel-windows/*
224+
wheel-organized/*
214225
fail_on_unmatched_files: true

BUILD.bazel

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ load("@aspect_rules_js//js:defs.bzl", "js_library")
22
load("@aspect_rules_ts//ts:defs.bzl", "ts_config")
33
load("@npm//:defs.bzl", "npm_link_all_packages")
44
load("@aspect_rules_js//npm:defs.bzl", "npm_link_package")
5+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
6+
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
57

68
package(default_visibility = ["//visibility:public"])
79

@@ -35,3 +37,17 @@ js_library(
3537
name = "package_json",
3638
srcs = ["package.json"],
3739
)
40+
41+
# Global version computation that can be reused across all targets
42+
write_file(
43+
name = "version_tmpl",
44+
out = "version.txt.tmpl",
45+
content = ["{{RTBOT_VERSION}}"],
46+
)
47+
48+
expand_template(
49+
name = "version",
50+
out = "version.txt",
51+
stamp_substitutions = {"{{RTBOT_VERSION}}": "{{RTBOT_VERSION}}"},
52+
template = ":version_tmpl",
53+
)

libs/wrappers/python/BUILD.bazel

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ load("@pybind11_bazel//:build_defs.bzl", "pybind_extension")
22
load("@rules_python//python:packaging.bzl", "py_package", "py_wheel")
33
load("//tools/generator:generator.bzl", "rtbot_generate")
44
load("@aspect_bazel_lib//lib:copy_to_directory.bzl", "copy_to_directory")
5+
load("@aspect_bazel_lib//lib:expand_template.bzl", "expand_template")
6+
load("@bazel_skylib//rules:write_file.bzl", "write_file")
57
load("@py_deps//:requirements.bzl", "requirement")
68

79
package(default_visibility = ["//visibility:public"])
@@ -68,25 +70,28 @@ copy_to_directory(
6870
}),
6971
)
7072

71-
genrule(
72-
name = "version",
73-
outs = ["version.txt"],
74-
cmd = "cat bazel-out/stable-status.txt | grep '^VERSION ' | cut -d' ' -f2 > $@",
75-
stamp = 1,
76-
)
73+
# Use global version from root BUILD.bazel
7774

7875
py_wheel(
79-
name = "rtbot_wheel",
76+
name = "rtbot_wheel_base",
8077
distribution = "rtbot",
8178
python_tag = "py3",
8279
stamp = 1,
8380
strip_path_prefixes = [
8481
"libs/wrappers/python",
8582
],
86-
version = "0.1.0", # We'll need to read from version file in setup.py
83+
version = "{RTBOT_VERSION}", # Dynamic version from workspace status
8784
deps = [":copy"],
8885
)
8986

87+
genrule(
88+
name = "rtbot_wheel",
89+
srcs = [":rtbot_wheel_base", "//:version"],
90+
outs = ["rtbot.whl"],
91+
cmd = "cp $(location :rtbot_wheel_base) $(location rtbot.whl)",
92+
stamp = 1,
93+
)
94+
9095
py_test(
9196
name = "rtbot_test",
9297
srcs = ["rtbot_test.py"],

0 commit comments

Comments
 (0)