Skip to content

Commit 71d619d

Browse files
Add back the Rust codec (#57)
* Add back the Rust codec * Execute the tests with the Rust codec * Install before downloading tests
1 parent 9a4288d commit 71d619d

File tree

4 files changed

+60
-31
lines changed

4 files changed

+60
-31
lines changed

.github/workflows/ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,12 @@ jobs:
6262

6363
- name: Execute test suite
6464
shell: bash
65-
run: poetry run python -m pytest tests/
65+
run: poetry run poe test
66+
67+
- name: Install dependencies with the Rust codec
68+
shell: bash
69+
run: poetry install -E rust-codec
70+
71+
- name: Execute test suite with the Rust codec
72+
shell: bash
73+
run: poetry run poe test

poetry.lock

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

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ python = "^3.10"
1616
grpclib = "^0.4.1"
1717
python-dateutil = "^2.8"
1818
typing-extensions = "^4.7.1"
19-
betterproto-rust-codec = { version = "0.1.1", optional = true }
19+
betterproto2-rust-codec = { version = "^0.1.2", optional = true }
2020

2121
[tool.poetry.group.dev.dependencies]
2222
asv = "^0.4.2"
@@ -43,7 +43,7 @@ cachelib = "^0.10.2"
4343
protoc-gen-python_betterproto = "betterproto2.plugin:main"
4444

4545
[tool.poetry.extras]
46-
rust-codec = ["betterproto-rust-codec"]
46+
rust-codec = ["betterproto2-rust-codec"]
4747

4848
[tool.ruff]
4949
extend-exclude = ["tests/output_*", "src/betterproto2/lib"]

src/betterproto2/__init__.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,6 +1343,23 @@ def _validate_field_groups(cls, values):
13431343
Message.__annotations__ = {} # HACK to avoid typing.get_type_hints breaking :)
13441344

13451345

1346+
try:
1347+
import betterproto2_rust_codec
1348+
except ModuleNotFoundError:
1349+
pass
1350+
else:
1351+
1352+
def parse_patched(self, data: bytes) -> T:
1353+
betterproto2_rust_codec.deserialize(self, data)
1354+
return self
1355+
1356+
def bytes_patched(self) -> bytes:
1357+
return betterproto2_rust_codec.serialize(self)
1358+
1359+
Message.parse = parse_patched
1360+
Message.__bytes__ = bytes_patched
1361+
1362+
13461363
def which_one_of(message: Message, group_name: str) -> Tuple[str, Optional[Any]]:
13471364
"""
13481365
Return the name and value of a message's one-of field group.

0 commit comments

Comments
 (0)