danielgtaylor / danielgtaylor/python-betterproto
ProtoContentBase.proto_file is always the first file of a package
- Langage dominant
- Python
- Étoiles
- 1.8k
- Forks
- 234
- Métriques de merge des PR
- Aucune PR mergée en 30 j
Description
I have a large protobuf package whose messages, etc. are defined over multiple files. However, `ProtoContentBase.proto_file` always refers to the *first* file of the package passed to `protoc`. As a result, when I run `protoc` the comments attached to each class and field are from the first file.
I hacked a solution to this by adding `proto_input_file` to `ProtoContentBase` and passing this as an argument all the way from `generate_code` through `read_protobuf_type`/`read_protobuf_service`, then adding:
- To `OutputTempate`:
```python
@property
def input_files_dict(self) -> Dict[str, FileDescriptorProto]:
"""Dictionary mapping filenames to their FileDescriptorProto objects
Returns
-------
Dict[str, FileDescriptorProto]
Dictionary mapping filenames to their FileDescriptorProto objects
"""
return {f.name: f for f in self.input_files}
```
- to `ProtoContentBase`
```python
@property
def proto_file(self) -> FieldDescriptorProto:
template = self.output_file
return template.input_files_dict[self.proto_input_file]
```
I'd be delighted to contribute a proper fix and open a PR for it, but it'd be good to hear if there's a better approach to solving the problem.
Guide de contribution
Ouvrir le guide de contribution
Piste de recherche
Suivez la façon dont generate_code transmet le contexte à read_protobuf_type et read_protobuf_service, puis examinez ProtoContentBase.proto_file et OutputTempate. Vérifiez comment un package composé de plusieurs fichiers sélectionne le descripteur source pour chaque message et chaque champ. Le travail est terminé lorsque les commentaires générés proviennent du fichier qui définit chaque élément, au lieu de provenir systématiquement du premier fichier d’entrée.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- python
- Domaine
- devtools
- Type d'issue
- Bug
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100