Generated code has non-existent relative import
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Accessibilité débutants
- 30/100
Piste de recherche
Reproduisez le problème avec les imports proto indiqués, le template buf et buf generate --template buf.gen.additional.yaml --include-imports. Examinez le mypackage.py généré et l’arborescence de sortie, puis comparez le from .google import protobuf en échec aux imports attendus ; c’est terminé lorsque les imports générés se résolvent pour les packages Google indiqués.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Summary
from .google import protobuf which doesn't exist
Reproduction Steps
I’m facing an issue with the imported packages, my protofile has some import like this:
syntax = "proto3";
package mypackage;
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/api/field_behavior.proto";
import "google/protobuf/field_mask.proto";
import "google/api/resource.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/timestamp.proto";
//import "validate/validate.proto";
import "protoc-gen-openapiv2/options/annotations.proto";
I’m running the code generation with buf:
version: v1
managed:
enabled: true
plugins:
# Python
- plugin: buf.build/community/danielgtaylor-betterproto:v1.2.5
out: _gen/pythonbproto2
and the command to run it is: buf generate --template buf.gen.additional.yaml --include-imports
The generated files are like this:
tree mypackage/api/proto/_gen/pythonbproto2
├── __init__.py
├── google
│ ├── __init__.py
│ └── api.py
├── grpc
│ ├── __init__.py
│ └── gateway
│ ├── __init__.py
│ └── protoc_gen_openapiv2
│ ├── __init__.py
│ └── options.py
└── mypackage
However the generated file mypackage.py is expecting a relative dir called google.protobuf which couldn’t be found, it has only the api.py not protobuf.
from .google import protobuf
Expected Results
The imported packages are properly handled. In the normal protoc way of generation, google.protobuf is a package and is imported directly like this: from google.protobuf import empty_pb2 as google_dot_protobuf_dot_empty__pb2
Actual Results
A relative import which doesn't exist: from .google import protobuf
System Information
protoc --version
libprotoc 24.3
buf --version
1.21.0
version: v1
managed:
enabled: true
plugins:
# Python
- plugin: buf.build/community/danielgtaylor-betterproto:v1.2.5
out: _gen/pythonbproto2
I'm not able to use normal command line to generate this:
protoc -I . --python_betterproto_out=lib mypackage.proto
google/api/annotations.proto: File not found.
google/api/client.proto: File not found.
google/api/field_behavior.proto: File not found.
google/api/resource.proto: File not found.
protoc-gen-openapiv2/options/annotations.proto: File not found.
mypackage.proto:5:1: Import "google/api/annotations.proto" was not found or had errors.
mypackage.proto:6:1: Import "google/api/client.proto" was not found or had errors.
mypackage.proto:7:1: Import "google/api/field_behavior.proto" was not found or had errors.
mypackage.proto:9:1: Import "google/api/resource.proto" was not found or had errors.
mypackage.proto:13:1: Import "protoc-gen-openapiv2/options/annotations.proto" was not found or had errors.
Checklist
- I have searched the issues for duplicates.
- I have shown the entire traceback, if possible.
- [] I have verified this issue occurs on the latest prelease of betterproto which can be installed using
pip install -U --pre betterproto, if possible.
- Langage dominant
- Python
- Étoiles
- 1.8k
- Forks
- 235
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de danielgtaylor/python-betterproto
-
Difficulté 3/5 1-2 jours Accessibilité débutants 55/100
-
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 15/100
-
bug investigation needed
Difficulté 3/5 1-2 jours Accessibilité débutants 42/100
-
bug investigation needed
Difficulté 3/5 1-2 jours Accessibilité débutants 45/100
-
bug investigation needed
Difficulté 4/5 3-5 jours Accessibilité débutants 38/100
danielgtaylor/python-betterproto#676 · 3 commentaires ·
Toutes les issues de danielgtaylor/python-betterproto
Issues similaires
-
[Bug]: IndexHandler.post crashes with HTTP 500 on malformed payloads, missing credentials, or when login is disabledPeut-être pris Une pull request liée à cette issue est ouverte ou déjà fusionnée. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
Les mainteneurs répondent en général sous 6 jours
-
Bump zizmor to 1.31.1+Ouvertegithub_actions
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
collective/icalendar#2003 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
bug
Difficulté 2/5 1-3 heures Accessibilité débutants 79/100
-
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
openzim/python-scraperlib#360 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
volcengine/OpenViking#6445 ·
Les mainteneurs répondent en général sous 1 jour