Skip to content

Commit 9d7807b

Browse files
Add py_wheel rule, clean old rules and canonize python version (#41)
1 parent 9c9454a commit 9d7807b

File tree

6 files changed

+239
-2
lines changed

6 files changed

+239
-2
lines changed

.github/workflows/prerelease.yml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Pre-release Tesseract
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
create_version:
13+
runs-on: ubuntu-24.04
14+
steps:
15+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
16+
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
17+
with:
18+
python-version: '3.10'
19+
- name: Create version
20+
run: |
21+
mkdir version
22+
echo "$(python _version.py).dev$(date '+%Y%m%d%H%M%S')" > version/version.txt
23+
cat version/version.txt
24+
- uses: actions/upload-artifact@master
25+
with:
26+
name: version-file
27+
path: version
28+
29+
build_wheels:
30+
runs-on: ${{ matrix.os }}
31+
needs: [create_version]
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
include:
36+
- os: ubuntu-24.04
37+
arch: x86_64
38+
- os: macos-13
39+
arch: auto
40+
41+
steps:
42+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
43+
- name: Set up Python
44+
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
45+
with:
46+
python-version: '3.10'
47+
48+
- uses: actions/download-artifact@master
49+
with:
50+
name: version-file
51+
path: version
52+
53+
- name: Set up Bazel
54+
uses: bazel-contrib/setup-bazel@0.14.0
55+
with:
56+
bazelisk-cache: true
57+
disk-cache: ${{ github.workflow }}
58+
repository-cache: true
59+
60+
- name: Build package
61+
run: |
62+
bazel build --define VERSION="$(cat version/version.txt)" :tesseract_decoder_wheel
63+
64+
- uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
65+
with:
66+
name: python-wheels-${{ matrix.os }}
67+
path: ./bazel-bin/*.whl
68+
69+
release-wheels:
70+
name: Publish all wheels
71+
needs: [build_wheels]
72+
runs-on: ubuntu-24.04
73+
74+
steps:
75+
- name: Download build artifacts
76+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
77+
with:
78+
pattern: python-wheels-*
79+
merge-multiple: true
80+
path: wheelhouse/
81+
82+
- name: Publish package to testpypi
83+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
84+
with:
85+
repository_url: https://test.pypi.org/legacy/
86+
user: __token__
87+
password: ${{ secrets.TEST_PYPI_TOKEN }}
88+
packages_dir: wheelhouse/
89+
verbose: true
90+
91+
- name: Publish package to pypi
92+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
93+
with:
94+
user: __token__
95+
password: ${{ secrets.PYPI_TOKEN }}
96+
packages_dir: wheelhouse/
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
name: Stable-release Tesseract
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
permissions:
8+
contents: read
9+
10+
jobs:
11+
create_version:
12+
runs-on: ubuntu-24.04
13+
steps:
14+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
15+
- uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
16+
with:
17+
python-version: '3.10'
18+
- name: Create version
19+
run: |
20+
mkdir version
21+
echo "$(python _version.py)" > version/version.txt
22+
cat version/version.txt
23+
- uses: actions/upload-artifact@master
24+
with:
25+
name: version-file
26+
path: version
27+
28+
build_wheels:
29+
runs-on: ${{ matrix.os }}
30+
needs: [create_version]
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
include:
35+
- os: ubuntu-24.04
36+
arch: x86_64
37+
- os: macos-13
38+
arch: auto
39+
40+
steps:
41+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
42+
- name: Set up Python
43+
uses: actions/setup-python@42375524e23c412d93fb67b49958b491fce71c38 # v5
44+
with:
45+
python-version: '3.10'
46+
47+
- uses: actions/download-artifact@master
48+
with:
49+
name: version-file
50+
path: version
51+
52+
- name: Set up Bazel
53+
uses: bazel-contrib/setup-bazel@0.14.0
54+
with:
55+
bazelisk-cache: true
56+
disk-cache: ${{ github.workflow }}
57+
repository-cache: true
58+
59+
- name: Build package
60+
run: |
61+
bazel build --define VERSION="$(cat version/version.txt)" :tesseract_decoder_wheel
62+
63+
- uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
64+
with:
65+
name: python-wheels-${{ matrix.os }}
66+
path: ./bazel-bin/*.whl
67+
68+
release-wheels:
69+
name: Publish all wheels
70+
needs: [build_wheels]
71+
runs-on: ubuntu-24.04
72+
73+
steps:
74+
- name: Download build artifacts
75+
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
76+
with:
77+
pattern: python-wheels-*
78+
merge-multiple: true
79+
path: wheelhouse/
80+
81+
82+
- name: Publish package to testpypi
83+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
84+
with:
85+
repository_url: https://test.pypi.org/legacy/
86+
user: __token__
87+
password: ${{ secrets.TEST_PYPI_TOKEN }}
88+
packages_dir: wheelhouse/
89+
verbose: true
90+
91+
- name: Publish package to pypi
92+
uses: pypa/gh-action-pypi-publish@27b31702a0e7fc50959f5ad993c78deac1bdfc29
93+
with:
94+
user: __token__
95+
password: ${{ secrets.PYPI_TOKEN }}
96+
packages_dir: wheelhouse/

BUILD

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
load("@rules_python//python:packaging.bzl", "py_wheel")
2+
3+
filegroup(
4+
name="package_description",
5+
srcs=["README.md"],
6+
visibility = ["//visibility:public"],
7+
)
8+
9+
10+
filegroup(
11+
name="package_data",
12+
srcs=["LICENSE"],
13+
visibility = ["//visibility:public"],
14+
)
15+
16+
py_wheel(
17+
name="tesseract_decoder_wheel",
18+
distribution = "tesseract_decoder",
19+
deps=[
20+
"//src:tesseract_decoder",
21+
":package_data",
22+
],
23+
version = "$(VERSION)",
24+
requires=[
25+
"stim",
26+
],
27+
platform= select({
28+
"@platforms//os:macos": "macosx_10_13_x86_64",
29+
"@platforms//os:windows": "win32",
30+
"@platforms//os:linux": "manylinux_2_17_x86_64.manylinux2014_x86_64",
31+
}),
32+
description_file=":package_description",
33+
description_content_type="text/markdown",
34+
summary="A search-based decoder for quantum error correction (QEC).",
35+
author="The Tesseract Decoder Authors.",
36+
homepage="https://github.com/quantumlib/tesseract-decoder",
37+
)

MODULE.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ bazel_dep(name = "pybind11_bazel", version = "2.13.6")
88

99
DEFAULT_PYTHON_VERSION = "3.11"
1010

11+
python = use_extension("@rules_python//python/extensions:python.bzl", "python")
12+
python.toolchain(python_version = DEFAULT_PYTHON_VERSION, is_default = True)
13+
1114
python_configure = use_extension("@pybind11_bazel//:python_configure.bzl", "extension")
1215
use_repo(python_configure, "local_config_python")
1316

@@ -16,7 +19,7 @@ pip = use_extension("@rules_python//python/extensions:pip.bzl", "pip")
1619

1720
pip.parse(
1821
hub_name = "pypi",
19-
python_version = "3.11",
22+
python_version = DEFAULT_PYTHON_VERSION,
2023
requirements_lock = "//src/py:requirements_lock.txt",
2124
)
2225

_version.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Version of Tesseract's python distribution
2+
3+
__version__ = '0.1.1'
4+
5+
if __name__ == '__main__':
6+
print(__version__)

src/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ cc_library(
6363
],
6464
)
6565

66-
6766
pybind_library(
6867
name = "tesseract_decoder_pybind",
6968
srcs = [

0 commit comments

Comments
 (0)