diff --git a/README.md b/README.md index 333d974..8a016e2 100644 --- a/README.md +++ b/README.md @@ -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"; diff --git a/betterproto/plugin.py b/betterproto/plugin.py index 4e559e3..98c9cf1 100755 --- a/betterproto/plugin.py +++ b/betterproto/plugin.py @@ -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 ( diff --git a/setup.py b/setup.py index ad1ee29..e3894d2 100644 --- a/setup.py +++ b/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, )