Make compiler dependencies optional

This commit is contained in:
Daniel G. Taylor 2019-10-22 21:08:30 -07:00
parent 5dae20970b
commit df8518d04d
No known key found for this signature in database
GPG Key ID: 7BD6DC99C9A87E22
3 changed files with 17 additions and 5 deletions

View File

@ -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";

View File

@ -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 (

View File

@ -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,
)