Skip to content

Commit dc9637b

Browse files
nielspardongiospada
authored andcommitted
chore: remove dependency on protoletariat and update protobuf (substrait-io#138)
Protoletariat is using an outdated version of protobuf and does not seem to be actively maintained. By changing the way we generate the Python code from the proto files we can remove the dependency on protoletariat and update to the latest protobuf version. Additionally, this adds the code formatting and lint fixing Make targets to the codegen target and fixes some formatting issues that were introduced in a prior PR. --------- Signed-off-by: Niels Pardon <[email protected]>
1 parent 6632ae1 commit dc9637b

27 files changed

+5260
-4560
lines changed

.devcontainer/Dockerfile

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ RUN bash -c "source $HOME/.sdkman/bin/sdkman-init.sh && \
55
sdk install java 25-graalce"
66
RUN mkdir -p ~/lib && cd ~/lib && curl -L -O http://www.antlr.org/download/antlr-4.13.2-complete.jar
77
ENV ANTLR_JAR="~/lib/antlr-4.13.2-complete.jar"
8-
# protoc 29.5 is the last version with protobuf python v5 which is compatible with protoletariat v3
9-
RUN cd ~ && curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v29.5/protoc-29.5-linux-x86_64.zip && \
10-
unzip protoc-29.5-linux-x86_64.zip -d ~/.local && \
11-
rm protoc-29.5-linux-x86_64.zip
8+
RUN cd ~ && curl -LO https://github.com/protocolbuffers/protobuf/releases/download/v33.2/protoc-33.2-linux-x86_64.zip && \
9+
unzip protoc-33.2-linux-x86_64.zip -d ~/.local && \
10+
rm protoc-33.2-linux-x86_64.zip
1211
RUN curl -sSL "https://github.com/bufbuild/buf/releases/download/v1.58.0/buf-$(uname -s)-$(uname -m)" -o ~/.local/bin/buf && chmod +x ~/.local/bin/buf
1312
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
1413
USER root

.github/workflows/ruff.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ jobs:
3131
3232
- name: Run ruff formatter
3333
run: |
34-
uvx [email protected] format
34+
uvx [email protected] format --check

buf.gen.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version: v2
22
plugins:
3-
- protoc_builtin: python
4-
out: src/substrait/gen
5-
- remote: buf.build/community/nipunn1313-mypy:v3.6.0
6-
out: src/substrait/gen
3+
- remote: buf.build/protocolbuffers/python:v33.2
4+
out: src
5+
- remote: buf.build/community/nipunn1313-mypy:v4.0.0
6+
out: src

gen_proto.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,23 @@
22

33
set -eou pipefail
44

5-
namespace=proto
5+
namespace=substrait.gen.proto
66
submodule_dir=./third_party/substrait
77
src_dir="$submodule_dir"/proto
88
tmp_dir=./buf_work_dir
9-
dest_dir=./src/substrait/gen
9+
dest_dir=./src
1010
extension_dir=./src/substrait/extensions
1111

1212
# Prefix the protobuf files with a unique configuration to prevent namespace conflicts
1313
# with other substrait packages. Save output to the work dir.
1414
python "$submodule_dir"/tools/proto_prefix.py "$tmp_dir" "$namespace" "$src_dir"
1515

1616
# Remove the old python protobuf files
17-
rm -rf "$dest_dir/proto"
17+
rm -rf "$dest_dir/substrait/gen/proto"
1818

1919
# Generate the new python protobuf files
2020
buf generate
21-
uv run protol --in-place --create-package --python-out "$dest_dir" buf
21+
find "$dest_dir/substrait/gen" -type d -exec touch {}/__init__.py \;
2222

2323
# Remove the old extension files
2424
rm -rf "$extension_dir"

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ authors = [{name = "Substrait contributors", email = "[email protected]
55
license = {text = "Apache-2.0"}
66
readme = "README.md"
77
requires-python = ">=3.10,<3.14"
8-
dependencies = ["protobuf >=3.19.1,<6"]
8+
dependencies = ["protobuf >=6.33,<7"]
99
dynamic = ["version"]
1010

1111
[tool.setuptools_scm]
@@ -17,7 +17,7 @@ sql = ["sqloxide", "deepdiff"]
1717

1818
[dependency-groups]
1919
dev = ["pytest >= 7.0.0", "antlr4-python3-runtime", "pyyaml", "sqloxide", "deepdiff", "duckdb<=1.2.2", "datafusion"]
20-
gen_proto = ["protobuf >=3.19.1,<6", "protoletariat >= 3.0.0"]
20+
gen_proto = ["protobuf >=6.33,<7"]
2121
gen_extensions = ["datamodel-code-generator"]
2222

2323
[tool.pytest.ini_options]

src/substrait/builders/type.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,6 @@ def precision_timestamp_tz(precision: int, nullable=True) -> stt.Type:
223223
)
224224

225225

226-
227226
def struct(types: Iterable[stt.Type], nullable=True) -> stt.Type:
228227
return stt.Type(
229228
struct=stt.Type.Struct(

src/substrait/gen/proto/__init__.pyi

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/substrait/gen/proto/algebra_pb2.py

Lines changed: 359 additions & 339 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/substrait/gen/proto/algebra_pb2.pyi

Lines changed: 2630 additions & 2342 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/substrait/gen/proto/capabilities_pb2.py

Lines changed: 29 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)