Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.

Commit 945d6a7

Browse files
Update betterproto to v0.1.1 (#20)
* Update lib * Update compiler file * Update betterproto * Fix optional * Use lib from betterproto2 * Remove useless code * Update betterproto * Document how to recompile proto files * Fix import path * Update version number
1 parent 32b55ca commit 945d6a7

File tree

11 files changed

+449
-2955
lines changed

11 files changed

+449
-2955
lines changed

docs/development.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Development
2+
3+
## Recompiling the lib proto files
4+
5+
After some updates in the compiler, it might be useful to recompile the standard Google proto files. As the proto files
6+
are distributed with `protoc`, their path might depend on your installation.
7+
8+
```bash
9+
mkdir lib
10+
protoc \
11+
--python_betterproto2_opt=INCLUDE_GOOGLE \
12+
--python_betterproto2_out=lib \
13+
-I /usr/include/ \
14+
/usr/include/google/protobuf/*.proto
15+
```
16+
17+
The generated files should be distributed in the `betterproto2` package.
18+
19+
!!! warning
20+
These proto files are written with the `proto2` syntax, which is not supported by betterproto. For the compiler to
21+
work, you need to manually patch the generated file to mark the field `oneof_index` in `Field` and
22+
`FieldDescriptorProto` optional.
23+
24+
In the compiler, you also need to compile the [plugin.proto](https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/compiler/plugin.proto)
25+
file in `src/betterproto2_compiler/lib/google.protobug/compiler/__init__.py`.

mkdocs.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ nav:
1414
- Betterproto2 compiler:
1515
- index.md
1616
- Getting started: getting-started.md
17+
- Development: development.md
1718

1819
plugins:
1920
- mkdocstrings

poetry.lock

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

pyproject.toml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "betterproto2_compiler"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
description = "Compiler for betterproto2"
55
authors = ["Adrien Vannson <[email protected]>", "Daniel G. Taylor <[email protected]>"]
66
readme = "README.md"
@@ -13,7 +13,7 @@ packages = [
1313

1414
[tool.poetry.dependencies]
1515
python = "^3.10"
16-
betterproto2 = "0.0.2"
16+
betterproto2 = "^0.1.1"
1717
# The Ruff version is pinned. To update it, also update it in .pre-commit-config.yaml
1818
ruff = "~0.7.4"
1919
grpclib = "^0.4.1"
@@ -102,13 +102,13 @@ cmd = "ruff check src tests"
102102
help = "Check the code with the Ruff linter"
103103

104104
[tool.poe.tasks.generate_lib]
105-
cmd = """
106-
protoc
107-
--plugin=protoc-gen-custom=src/betterproto2_compiler/plugin/main.py
108-
--custom_opt=INCLUDE_GOOGLE
109-
--custom_out=src/betterproto/lib/std
110-
-I /usr/local/include/
111-
/usr/local/include/google/protobuf/**/*.proto
105+
shell = """
106+
protoc \
107+
--plugin=protoc-gen-custom=src/betterproto2_compiler/plugin/main.py \
108+
--custom_opt=INCLUDE_GOOGLE \
109+
--custom_out=src/betterproto2_compiler/lib \
110+
-I /usr/include/ \
111+
/usr/include/google/protobuf/**/*.proto
112112
"""
113113
help = "Regenerate the types in betterproto.lib.std.google"
114114

src/betterproto2_compiler/compile/importing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@
55
TYPE_CHECKING,
66
)
77

8+
from betterproto2.lib.google import protobuf as google_protobuf
9+
810
from ..casing import safe_snake_case
9-
from ..lib.google import protobuf as google_protobuf
1011
from .naming import pythonize_class_name
1112

1213
if TYPE_CHECKING:

0 commit comments

Comments
 (0)