Skip to content
This repository was archived by the owner on Jun 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
run: poetry config virtualenvs.in-project true

- name: Set up cache
uses: actions/cache@v3
uses: actions/cache@v4
id: cache
with:
path: .venv
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
shell: bash
run: poetry install

- uses: pre-commit/action@v2.0.3
- uses: pre-commit/action@v3.0.1

Check warning on line 48 in .github/workflows/code-quality.yml

View check run for this annotation

GitHub Advanced Security / CodeQL

Unpinned tag for a non-immutable Action in workflow

Unpinned 3rd party Action 'Code Quality' step [Uses Step](1) uses 'pre-commit/action' with ref 'v3.0.1', not a pinned commit hash

Check warning

Code scanning / CodeQL

Unpinned tag for a non-immutable Action in workflow Medium

Unpinned 3rd party Action 'Code Quality' step
Uses Step
uses 'pre-commit/action' with ref 'v3.0.1', not a pinned commit hash

- name: Pyright
shell: bash
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v4

- name: Set up Python 3.10
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.10"

Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ci:

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.4
rev: v0.9.3
hooks:
- id: ruff-format
args: ["--diff", "src", "tests"]
Expand Down
14 changes: 14 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

The betterproto2 compiler is a plugin of `protoc`, you first need to [install](https://grpc.io/docs/protoc-installation/) it.

You can also use it from `grpcio-tools`:

```sh
pip install grpcio-tools
```


## Install `betterproto2_compiler`

It is possible to install `betterproto2_compiler` using pip:
Expand All @@ -15,6 +22,7 @@ pip install betterproto2_compiler
!!! warning
The compiler needs Python 3.10, 3.11 or 3.12. Don't worry! The generated code will be compatible with all Python versions from Python 3.8 to Python 3.13.


## Compile a proto file

Create the following `example.proto` file.
Expand All @@ -35,3 +43,9 @@ You should now be able to compile it using:
mkdir lib
protoc -I . --python_betterproto2_out=lib example.proto
```

If you installed `protoc` with `grpc-tools`, the command will be:

```mkdir lib
python -m grpc-tools.protoc -I . --python_betterproto2_out=lib example.proto
```
147 changes: 124 additions & 23 deletions poetry.lock

Large diffs are not rendered by default.

24 changes: 17 additions & 7 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
[tool.poetry]
[project]
name = "betterproto2_compiler"
version = "0.2.3"
description = "Compiler for betterproto2"
authors = ["Adrien Vannson <[email protected]>", "Daniel G. Taylor <[email protected]>"]
authors = [
{ name = "Adrien Vannson", email = "[email protected]" },
{ name = "Daniel G. Taylor", email = "[email protected]" },
]
readme = "README.md"
repository = "https://github.com/betterproto/python-betterproto2-compiler"
keywords = ["protobuf", "gRPC", "compiler"]
license = "MIT"
requires-python = ">=3.10,<4.0"
dynamic = ["dependencies"]

[project.urls]
Documentation = "https://betterproto.github.io/python-betterproto2-compiler/"
Repository = "https://github.com/betterproto/python-betterproto2-compiler"

[project.scripts]
protoc-gen-python_betterproto2 = "betterproto2_compiler.plugin:main"

[tool.poetry]
packages = [
{ include = "betterproto2_compiler", from = "src" }
]
Expand All @@ -15,7 +28,7 @@ packages = [
python = "^3.10"
betterproto2 = "^0.2.1"
# The Ruff version is pinned. To update it, also update it in .pre-commit-config.yaml
ruff = "~0.7.4"
ruff = "~0.9.3"
grpclib = "^0.4.1"
jinja2 = ">=3.0.3"
typing-extensions = "^4.7.1"
Expand All @@ -33,9 +46,6 @@ ipykernel = "^6.29.5"
pytest = "^6.2.5"
protobuf = "^4"

[tool.poetry.scripts]
protoc-gen-python_betterproto2 = "betterproto2_compiler.plugin:main"

[tool.ruff]
extend-exclude = ["tests/output_*", "src/betterproto2_compiler/lib"]
target-version = "py310"
Expand Down
4 changes: 2 additions & 2 deletions src/betterproto2_compiler/known_types/timestamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ def timestamp_to_json(dt: datetime.datetime) -> str:
return f"{result}Z"
if (nanos % 1e6) == 0:
# Serialize 3 fractional digits.
return f"{result}.{int(nanos // 1e6) :03d}Z"
return f"{result}.{int(nanos // 1e6):03d}Z"
if (nanos % 1e3) == 0:
# Serialize 6 fractional digits.
return f"{result}.{int(nanos // 1e3) :06d}Z"
return f"{result}.{int(nanos // 1e3):06d}Z"
# Serialize 9 fractional digits.
return f"{result}.{nanos:09d}"
2 changes: 1 addition & 1 deletion tests/generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ async def generate_test_case_output(test_case_input_path: Path, test_case_name:
"Usage: python generate.py [-h] [-v] [DIRECTORIES or NAMES]",
"Generate python classes for standard tests.",
"",
"DIRECTORIES One or more relative or absolute directories of test-cases to generate" "classes for.",
"DIRECTORIES One or more relative or absolute directories of test-cases to generateclasses for.",
" python generate.py inputs/bool inputs/double inputs/enum",
"",
"NAMES One or more test-case names to generate classes for.",
Expand Down
Loading