8000 Make compiler dependencies optional · enixdark/python-betterproto@109dc5a · GitHub
[go: up one dir, main page]

Skip to content

Commit 109dc5a

Browse files
committed
Make compiler dependencies optional
1 parent 5dae209 commit 109dc5a

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,17 @@ This project is a reimplementation from the ground up focused on idiomatic moder
3939

4040
## Installation & Getting Started
4141

42-
First, install the package:
42+
First, install the package. Note that the `[compiler]` feature flag tells it to install extra dependencies only needed by the `protoc` plugin:
4343

4444
```sh
45+
# Install both the library and compiler
46+
$ pip install betterproto[compiler]
47+
48+
# Install just the library (to use the generated code output)
4549
$ pip install betterproto
4650
```
4751

48-
Now, given a proto file, e.g `example.proto`:
52+
Now, given you installed the compiler and have a proto file, e.g `example.proto`:
4953

5054
```protobuf
5155
syntax = "proto3";

betterproto/plugin.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
import textwrap
99
from typing import Any, List, Tuple
1010

11-
import jinja2
11+
try:
12+
import jinja2
13+
except ImportError:
14+
print(
15+
"Unable to import `jinja2`. Did you install the compiler feature with `pip install betterproto[compiler]`?"
16+
)
17+
raise SystemExit(1)
1218

1319
from google.protobuf.compiler import plugin_pb2 as plugin
1420
from google.protobuf.descriptor_pb2 import (

setup.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
packages=find_packages(
1515
exclude=["tests", "*.tests", "*.tests.*", "output", "output.*"]
1616
),
17-
package_data={"betterproto": ["py.typed", "templates"]},
18-
install_requires=["grpclib", "protobuf"],
17+
package_data={"betterproto": ["py.typed", "templates/template.py"]},
18+
python_requires=">=3.7",
19+
install_requires=["grpclib"],
20+
extras_require={"compiler": ["jinja2", "protobuf"]},
1921
zip_safe=False,
2022
)

0 commit comments

Comments
 (0)
0