Make compiler dependencies optional
This commit is contained in:
parent
5dae20970b
commit
109dc5a8a5
@ -39,13 +39,17 @@ This project is a reimplementation from the ground up focused on idiomatic moder
|
||||
|
||||
## Installation & Getting Started
|
||||
|
||||
First, install the package:
|
||||
First, install the package. Note that the `[compiler]` feature flag tells it to install extra dependencies only needed by the `protoc` plugin:
|
||||
|
||||
```sh
|
||||
# Install both the library and compiler
|
||||
$ pip install betterproto[compiler]
|
||||
|
||||
# Install just the library (to use the generated code output)
|
||||
$ pip install betterproto
|
||||
```
|
||||
|
||||
Now, given a proto file, e.g `example.proto`:
|
||||
Now, given you installed the compiler and have a proto file, e.g `example.proto`:
|
||||
|
||||
```protobuf
|
||||
syntax = "proto3";
|
||||
|
@ -8,7 +8,13 @@ import sys
|
||||
import textwrap
|
||||
from typing import Any, List, Tuple
|
||||
|
||||
import jinja2
|
||||
try:
|
||||
import jinja2
|
||||
except ImportError:
|
||||
print(
|
||||
"Unable to import `jinja2`. Did you install the compiler feature with `pip install betterproto[compiler]`?"
|
||||
)
|
||||
raise SystemExit(1)
|
||||
|
||||
from google.protobuf.compiler import plugin_pb2 as plugin
|
||||
from google.protobuf.descriptor_pb2 import (
|
||||
|
6
setup.py
6
setup.py
@ -14,7 +14,9 @@ setup(
|
||||
packages=find_packages(
|
||||
exclude=["tests", "*.tests", "*.tests.*", "output", "output.*"]
|
||||
),
|
||||
package_data={"betterproto": ["py.typed", "templates"]},
|
||||
install_requires=["grpclib", "protobuf"],
|
||||
package_data={"betterproto": ["py.typed", "templates/template.py"]},
|
||||
python_requires=">=3.7",
|
||||
install_requires=["grpclib"],
|
||||
extras_require={"compiler": ["jinja2", "protobuf"]},
|
||||
zip_safe=False,
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user