|
1 | | -Protobufs / How to handle `fabric-protos` |
2 | | -========================================= |
| 1 | +Protobufs / How this project uses `fabric-protos` |
| 2 | +=============================================== |
3 | 3 |
|
4 | | -Summary |
5 | | -------- |
6 | | - |
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: |
10 | | - |
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. |
16 | | - |
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. |
20 | | - |
21 | | -Recommendation (practical balance) |
22 | | ----------------------------------- |
23 | | - |
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. |
35 | | - |
36 | | -Practical steps (example) |
| 4 | +Current integration model |
37 | 5 | ------------------------- |
38 | 6 |
|
39 | | -1. Add `fabric-protos` as a submodule and pin to a tag: |
| 7 | +This project now consumes official Python protobuf bindings from |
| 8 | +`hyperledger/fabric-protos`. |
| 9 | + |
| 10 | +- Package name: `hyperledger-fabric-protos` |
| 11 | +- Import namespace used by this repository: `fabric_protos` |
| 12 | + |
| 13 | +Install with: |
40 | 14 |
|
41 | 15 | ```bash |
42 | | -git submodule add --depth 1 -b v2.5.0 https://github.com/hyperledger/fabric-protos.git protos/fabric-protos |
43 | | -git submodule update --init --recursive |
| 16 | +PYTHON_BIN=python ./scripts/install_fabric_protos.sh |
44 | 17 | ``` |
45 | 18 |
|
46 | | -2. Generate Python bindings (run from the repository root): |
| 19 | +Why this model |
| 20 | +-------------- |
| 21 | + |
| 22 | +- Avoids vendored generated protobuf drift inside this repository. |
| 23 | +- Keeps protocol bindings aligned with the upstream Fabric protobuf source. |
| 24 | +- Simplifies release and maintenance for `fabric-chaincode-python`. |
| 25 | + |
| 26 | +Version compatibility |
| 27 | +--------------------- |
| 28 | + |
| 29 | +Use dependency ranges compatible with upstream Python bindings: |
| 30 | + |
| 31 | +- `protobuf>=5.27.0,<6.0.0` |
| 32 | +- `grpcio>=1.83.1,<2.0.0` |
| 33 | + |
| 34 | +The installer script uses the following order: |
| 35 | + |
| 36 | +1. Local `../fabric-protos` checkout (runs `make pythonbindings`) |
| 37 | +2. PyPI `hyperledger-fabric-protos` package (if complete) |
| 38 | +3. Official `hyperledger/fabric-protos` git checkout at pinned commit, |
| 39 | + then local build/install of `bindings/python` |
| 40 | + |
| 41 | +Local regeneration (optional) |
| 42 | +----------------------------- |
| 43 | + |
| 44 | +For debugging or contributor workflows, bindings can still be generated from |
| 45 | +a local `fabric-protos` checkout: |
47 | 46 |
|
48 | 47 | ```bash |
49 | | -cd ./fabric-chaincode-python |
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/) |
| 48 | +PROTO_SRC=/path/to/fabric-protos OUT_DIR=$PWD/fabric_protos bash scripts/gen_protos.sh |
52 | 49 | ``` |
53 | 50 |
|
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. |
| 51 | +This is optional and should not be required for normal runtime use. |
57 | 52 |
|
58 | 53 | License |
59 | 54 | ------- |
60 | 55 |
|
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. |
| 56 | +`fabric-protos` is Apache-2.0. If distributing generated bindings yourself, |
| 57 | +keep original licensing notices intact. |
0 commit comments