|
1 | 1 | Protobufs / How to handle `fabric-protos` |
2 | | -======================================== |
| 2 | +========================================= |
3 | 3 |
|
4 | | -Resumen |
| 4 | +Summary |
5 | 5 | ------- |
6 | 6 |
|
7 | | -Hyperledger Fabric define sus interfaces gRPC en `fabric-protos` (Apache-2.0). Para implementar un shim en Python hay dos opciones razonables: |
| 7 | +Hyperledger Fabric defines its gRPC interfaces in the `fabric-protos` repository |
| 8 | +(Apache-2.0). When implementing a Python shim you generally have two practical |
| 9 | +options: |
8 | 10 |
|
9 | | -1. "Submodular / generar": Mantener `fabric-protos` como submódulo (o referenciar una versión fija), y generar los archivos Python (`*_pb2.py`, `*_pb2_grpc.py`) con `grpc_tools.protoc` usando `scripts/gen_protos.sh`. Opcionalmente, incluir los archivos generados en `src/protos/` para simplificar la instalación de usuarios. |
| 11 | +1. "Submodule and generate": Add `fabric-protos` as a submodule (or reference a |
| 12 | + fixed tag) and generate Python bindings (`*_pb2.py`, `*_pb2_grpc.py`) using |
| 13 | + `grpc_tools.protoc` or `protoc` with a Python plugin. The provided |
| 14 | + `scripts/gen_protos.sh` can be used for this. Optionally include the |
| 15 | + generated files in the package for releases to simplify consumers' setup. |
10 | 16 |
|
11 | | -2. "Empaquetar protos pre-generados": Incluir directamente los archivos Python generados en el paquete (`src/`), y documentar la versión de `fabric-protos` usada. Esto evita que los consumidores instalen `grpc_tools` para usar la librería. |
| 17 | +2. "Package pre-generated protos": Commit the generated Python bindings into |
| 18 | + the repository/package and document the exact `fabric-protos` version used to |
| 19 | + generate them. This avoids requiring consumers to generate bindings locally. |
12 | 20 |
|
13 | | -Recomendación (mejor equilibrio al comenzar) |
14 | | ------------------------------------------- |
| 21 | +Recommendation (practical balance) |
| 22 | +---------------------------------- |
15 | 23 |
|
16 | | -- Use `fabric-protos` como submódulo apuntando a la versión que quiere soportar (por ejemplo `v2.4.0`). Esto preserva el historial y permite reproducibilidad. |
17 | | -- Añada `scripts/gen_protos.sh` (ya existe) para generar bindings. Committee los archivos generados en `src/protos/` solo para releases (o para facilitar pruebas), pero mantenga la fuente `.proto` separada. |
18 | | -- En `pyproject.toml` incluya los archivos generados en el paquete (o genere en la fase de `bdist_wheel`). En CI, genere y valide que los archivos generados son consistentes con el submódulo. |
19 | | -- No publique un paquete PyPI con el nombre `fabric-protos-python` que pueda confundirse con proyectos oficiales; si usted ya tiene un paquete con ese nombre, prefiera un nombre con un prefijo (por ejemplo `fabric_protos_py` o `hyperledger_fabric_protos_py`) y documente claramente la compatibilidad de versión. |
| 24 | +- Use `fabric-protos` as a submodule pinned to the exact tag you support. This |
| 25 | + preserves provenance and makes regenerating bindings reproducible. |
| 26 | +- Keep `scripts/gen_protos.sh` in the repo as a canonical way to regenerate |
| 27 | + bindings. Commit generated bindings for release artifacts (or for ease of |
| 28 | + testing), but avoid mixing `.proto` sources into the runtime package unless |
| 29 | + required. |
| 30 | +- In CI, either regenerate the bindings and compare them with the committed |
| 31 | + files, or regenerate them as part of the release build to ensure consistency. |
| 32 | +- Avoid publishing a PyPI package name that could be confused with an official |
| 33 | + upstream package (e.g. `fabric-protos-python`). If publishing generated |
| 34 | + bindings, choose a clear, distinct package name and document compatibility. |
20 | 35 |
|
21 | | -Pasos prácticos (ejemplo) |
| 36 | +Practical steps (example) |
22 | 37 | ------------------------- |
23 | 38 |
|
24 | | -1. Añadir `fabric-protos` como submódulo: |
| 39 | +1. Add `fabric-protos` as a submodule and pin to a tag: |
25 | 40 |
|
26 | 41 | ```bash |
27 | | -git submodule add --depth 1 -b v2.4.0 https://github.com/hyperledger/fabric-protos.git protos/fabric-protos |
| 42 | +git submodule add --depth 1 -b v2.5.0 https://github.com/hyperledger/fabric-protos.git protos/fabric-protos |
28 | 43 | git submodule update --init --recursive |
29 | 44 | ``` |
30 | 45 |
|
31 | | -2. Generar los protos Python (desde la raíz del repo): |
| 46 | +2. Generate Python bindings (run from the repository root): |
32 | 47 |
|
33 | 48 | ```bash |
34 | 49 | cd ./fabric-chaincode-python |
35 | | -./scripts/gen_protos.sh |
36 | | -# los archivos generados irán a src/protos/ por defecto |
| 50 | +PROTO_SRC=protos/fabric-protos bash scripts/gen_protos.sh |
| 51 | +# generated files will be placed where the script is configured (e.g. fabric_protos_python/) |
37 | 52 | ``` |
38 | 53 |
|
39 | | -3. Validar en CI que los protos generados son consistentes o regenerarlos en la fase de build. |
| 54 | +3. In CI: either regenerate and `git diff` against committed bindings to detect |
| 55 | + drift, or regenerate in the build environment so wheel artifacts include the |
| 56 | + bindings. |
40 | 57 |
|
41 | | -Licencia |
42 | | --------- |
| 58 | +License |
| 59 | +------- |
43 | 60 |
|
44 | | -`fabric-protos` está bajo Apache-2.0. Si incluye `.proto` o archivos generados en su repo, conserve la referencia de licencia (no elimine los archivos LICENSE de `fabric-protos` si los copia). Esto es necesario para poder migrar a Hyperledger Labs sin problemas. |
| 61 | +`fabric-protos` is licensed under Apache-2.0. If you include `.proto` files or |
| 62 | +generated bindings from that repository in your project, retain the original |
| 63 | +license notice (do not remove the `LICENSE` files from the `fabric-protos` |
| 64 | +source when copying). This is important if you plan to contribute or migrate the |
| 65 | +project to Hyperledger Labs. |
0 commit comments