danielgtaylor / danielgtaylor/python-betterproto
How to wrap in a custom setuptools command?
- Lenguaje dominante
- Python
- Estrellas
- 1.8k
- Forks
- 234
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
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?
Guía de contribución
Línea de trabajo
Comienza con el ejemplo de setup.py, especialmente con BuildProtoCommand.run y la configuración de setup_requires, y después ejecuta python setup.py build_proto. Comprueba cómo el comando de setuptools resuelve grpc_tools.protoc y el plugin del compilador de betterproto; se considera terminado cuando el comando genera los módulos correctamente o se documenta el enfoque de empaquetado compatible.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- build-system
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100