danielgtaylor / danielgtaylor/python-betterproto
How to wrap in a custom setuptools command?
- Vorherrschende Sprache
- Python
- Sterne
- 1.8k
- Forks
- 234
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
Is it possible to compile .proto files with the betterproto plugin from a custom setuptools command? For example, ```python setup.py build_proto```
This is what my setup.py looks like:
```
import os
import pkg_resources
from setuptools import Command, setup
class BuildProtoCommand(Command):
"""Command to generate project *_pb2.py modules from proto files."""
description = "build grpc protobuf modules"
user_options = []
def initialize_options(self):
pass
def finalize_options(self):
pass
def run(self):
from grpc_tools import protoc
proto_files = []
inclusion_root = os.path.abspath(".")
for root, _, files in os.walk(inclusion_root):
for filename in files:
if filename.endswith(".proto"):
proto_files.append(os.path.abspath(os.path.join(root, filename)))
well_known_protos_include = pkg_resources.resource_filename("grpc_tools", "_proto")
for proto_file in proto_files:
proto_dir = os.path.dirname(proto_file)
command = [
"grpc_tools.protoc",
f"--proto_path={proto_dir}",
f"--proto_path={well_known_protos_include}",
f"--python_betterproto_out={proto_dir}",
proto_file,
]
if protoc.main(command) != 0:
raise Exception(f"error: {command} failed")
setup(
name="mypackage",
version="0.2.0",
cmdclass={
"build_proto": BuildProtoCommand,
},
packages=["mypackage"],
setup_requires=[
"betterproto[compiler]",
"grpcio-tools",
],
)
```
The problem here is that calling ```python setup.py build_proto``` causes all of the setup_requires packages to be installed as .eggs, and the ```protoc-gen-python_betterproto``` executable is not found by ```protoc```, so it doesn't know how to interpret the ```--python_betterproto_out``` flag.
I just wanted to double-check if this even supported functionality, or if betterproto is not intended to be used with setuptools at all and I need to migrate my package to pyproject.toml or something?
Beitragsleitfaden
Rechercherichtung
Beginne mit dem setup.py-Beispiel, insbesondere mit BuildProtoCommand.run und der setup_requires-Konfiguration, und führe anschließend python setup.py build_proto aus. Prüfe, wie der setuptools-Befehl grpc_tools.protoc und das betterproto-Compiler-Plugin auflöst; die Aufgabe gilt als erledigt, wenn der Befehl entweder die Module erfolgreich generiert oder der unterstützte Packaging-Ansatz dokumentiert ist.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- build-system
- Issue-Typ
- Bug
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 35/100