-
Notifications
You must be signed in to change notification settings - Fork 557
Expand file tree
/
Copy pathpython.toml
More file actions
175 lines (149 loc) · 5.24 KB
/
python.toml
File metadata and controls
175 lines (149 loc) · 5.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# Python development, build, lint, and format tasks
["python:dev"]
description = "Install Python package in development mode (builds CLI binary)"
depends = ["python:proto"]
run = "uv sync --group dev && uv pip install ."
["python:build"]
description = "Build Python wheel with CLI binary (native)"
depends = ["python:proto"]
run = "uv run maturin build --release"
["python:build:multiarch"]
description = "Build Python wheels for Linux amd64/arm64 with buildx"
depends = ["python:proto"]
run = """
#!/usr/bin/env bash
set -euo pipefail
PLATFORMS=${DOCKER_PLATFORMS:-linux/amd64,linux/arm64}
VERSION=${NAVIGATOR_VERSION:-}
if [ -z "$VERSION" ]; then
VERSION=$(uv run python build/scripts/release.py get-version --python)
fi
VERSION_ARGS=(--build-arg "NAVIGATOR_VERSION=${VERSION}")
if ! docker buildx inspect multiarch >/dev/null 2>&1; then
echo "Creating multi-platform buildx builder..."
docker buildx create --name multiarch --use --bootstrap
else
docker buildx use multiarch
fi
mkdir -p target/wheels
for platform in ${PLATFORMS//,/ }; do
echo "Building wheel for ${platform}..."
docker buildx build \
--builder multiarch \
--platform "${platform}" \
-f deploy/docker/Dockerfile.python-wheels \
--target wheels \
"${VERSION_ARGS[@]}" \
--output type=local,dest=target/wheels \
.
done
ls -la target/wheels/*.whl
"""
["python:build:macos"]
description = "Build Python wheel for macOS arm64"
depends = ["python:proto"]
run = """
#!/usr/bin/env bash
set -euo pipefail
if [ "$(uname -s)" = "Darwin" ]; then
# Avoid failures when RUSTC_WRAPPER is set to an unresolved `sccache` binary.
if command -v sccache >/dev/null 2>&1; then
export RUSTC_WRAPPER="$(command -v sccache)"
else
unset RUSTC_WRAPPER || true
fi
mkdir -p target/wheels
rustup target add aarch64-apple-darwin
uv run maturin build --release --target aarch64-apple-darwin --out target/wheels
else
echo "Building macOS wheel via Docker cross-toolchain"
mise run python:build:macos:docker
fi
ls -la target/wheels/*.whl
"""
["python:build:macos:docker"]
description = "Build Python wheel for macOS arm64 from Docker"
depends = ["python:proto"]
run = """
#!/usr/bin/env bash
set -euo pipefail
VERSION=${NAVIGATOR_VERSION:-}
OSXCROSS_IMAGE_REF=${OSXCROSS_IMAGE:-crazymax/osxcross:latest}
if [ -z "$VERSION" ]; then
VERSION=$(uv run python build/scripts/release.py get-version --python)
fi
mkdir -p target/wheels
docker build \
-f deploy/docker/Dockerfile.python-wheels-macos \
--target wheels \
--build-arg "OSXCROSS_IMAGE=${OSXCROSS_IMAGE_REF}" \
--build-arg "NAVIGATOR_VERSION=${VERSION}" \
--output type=local,dest=target/wheels \
.
ls -la target/wheels/*macosx*arm64.whl
"""
["python:build:all"]
description = "Build Python wheels for Linux and macOS"
depends = ["python:build", "python:build:multiarch", "python:build:macos"]
["python:lint"]
description = "Lint Python code with ruff"
depends = ["python:proto"]
env = { UV_NO_SYNC = "1" }
run = "uv run ruff check {{vars.python_paths}}"
["python:format"]
description = "Format Python code with ruff"
run = "uv run ruff format {{vars.python_paths}}"
["python:typecheck"]
description = "Type check Python code with ty"
depends = ["python:proto"]
run = "uv run ty check {{vars.python_paths}}"
["python:proto"]
description = "Generate Python protobuf stubs from .proto files"
env = { UV_NO_SYNC = "1" }
run = """
#!/usr/bin/env bash
set -euo pipefail
uv run python -m grpc_tools.protoc \
-Iproto \
--python_out=python/navigator/_proto \
--pyi_out=python/navigator/_proto \
--grpc_python_out=python/navigator/_proto \
proto/inference.proto \
proto/navigator.proto \
proto/datamodel.proto \
proto/sandbox.proto
# Fix absolute imports in generated stubs to use package-relative imports
uv run python - <<'PY'
from pathlib import Path
import re
line_rewrites = {
"python/navigator/_proto/inference_pb2_grpc.py": [
(r"^import inference_pb2 as inference__pb2$", "from . import inference_pb2 as inference__pb2"),
],
"python/navigator/_proto/navigator_pb2_grpc.py": [
(r"^import navigator_pb2 as navigator__pb2$", "from . import navigator_pb2 as navigator__pb2"),
(r"^import sandbox_pb2 as sandbox__pb2$", "from . import sandbox_pb2 as sandbox__pb2"),
],
"python/navigator/_proto/navigator_pb2.py": [
(r"^import datamodel_pb2 as datamodel__pb2$", "from . import datamodel_pb2 as datamodel__pb2"),
(r"^import sandbox_pb2 as sandbox__pb2$", "from . import sandbox_pb2 as sandbox__pb2"),
],
"python/navigator/_proto/datamodel_pb2.py": [
(r"^import sandbox_pb2 as sandbox__pb2$", "from . import sandbox_pb2 as sandbox__pb2"),
],
"python/navigator/_proto/datamodel_pb2_grpc.py": [
(r"^import datamodel_pb2 as datamodel__pb2$", "from . import datamodel_pb2 as datamodel__pb2"),
],
"python/navigator/_proto/sandbox_pb2_grpc.py": [
(r"^import sandbox_pb2 as sandbox__pb2$", "from . import sandbox_pb2 as sandbox__pb2"),
],
}
for path, rules in line_rewrites.items():
file_path = Path(path)
text = file_path.read_text()
text = text.replace("from . from . import", "from . import")
for pattern, replacement in rules:
text = re.sub(pattern, replacement, text, flags=re.MULTILINE)
file_path.write_text(text)
PY
"""