Skip to content

Commit eabc5a2

Browse files
authored
Merge pull request #20 from bringauto/python_protobuf_as_module
Python protobuf files restructured to work as a module
2 parents ef7710d + 9010f9e commit eabc5a2

9 files changed

Lines changed: 38 additions & 9 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
_*
2+
!__init__.py
23
cmake-build-*
34
.idea

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CMAKE_MINIMUM_REQUIRED(VERSION 3.25 FATAL_ERROR)
22
PROJECT(fleet-protocol C CXX)
33

4-
SET(FLEET_PROTOCOL_VERSION 2.0.0)
4+
SET(FLEET_PROTOCOL_VERSION 2.0.3)
55
SET(FLEET_PROTOCOL_NAMESPACE "fleet-protocol-interface::")
66

77
OPTION(BRINGAUTO_PACKAGE "Package creation" OFF)

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ If a message field is not mandatory, then it's marked as OPTIONAL by "OPTIONAL"
7878
as the last comment in documentation for the given field.
7979
Optional fields have defaults as described in the [ProtoBuf] v3 doc.
8080

81+
### Python protobuf files
82+
83+
To use the compiled python protobuf files in a project, install the module in `protobuf/compiled/python`.
84+
For example: add this project as a submodule and add `file:fleet-protocol/protobuf/compiled/python` to `requirements.txt`. Then it can be imported as `fleet_protocol_protobuf_files`.
85+
8186
## Repo structure
8287

8388
This repository contains a basic C API and CMake project to easily

protobuf/README.md

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ TARGET_LINK_LIBRARIES(<target> PUBLIC protobuf::libprotobuf protobuf-cpp-interfa
1818

1919
## Compilation
2020

21-
Compile to all languages:
21+
Compile to all languages: (compiling python requires an extra step!)
2222

2323
```
24-
find protobuf/definition -name "*.proto" -exec protoc -I=protobuf/definition --cpp_out=compiled/cpp --csharp_out=compiled/cs --python_out=compiled/python --go_out=compiled/go/ --go_opt=paths=source_relative {} +
24+
find definition -name "*.proto" -exec protoc -I=./definition --cpp_out=./compiled/cpp --csharp_out=./compiled/cs --python_out=./compiled/python/fleet_protocol_protobuf_files --go_out=./compiled/go/ --go_opt=paths=source_relative {} +
2525
```
2626

2727
To compile files to a specific language only, use the specific `*_out` options in command.
@@ -30,19 +30,33 @@ Note that protoc doesn't support double asterisks (**), so it should be used wit
3030
**C++**
3131

3232
```
33-
find protobuf/definition -name "*.proto" -exec protoc -I=./definition --cpp_out=./compiled/cpp {} +
33+
find definition -name "*.proto" -exec protoc -I=./definition --cpp_out=./compiled/cpp {} +
3434
```
3535

3636
**C#**
3737

3838
```
39-
find protobuf/definition -name "*.proto" -exec protoc -I=./definition --csharp_out=./compiled/cpp {} +
39+
find definition -name "*.proto" -exec protoc -I=./definition --csharp_out=./compiled/cs {} +
4040
```
4141

4242
**Python**
4343

4444
```
45-
find protobuf/definition -name "*.proto" -exec protoc -I=./definition --python_out=./compiled/cpp {} +
45+
find definition -name "*.proto" -exec protoc -I=./definition --python_out=./compiled/python/fleet_protocol_protobuf_files {} +
46+
```
47+
48+
Afterwards, edit all local imports to start with `fleet_protocol_protobuf_files.`
49+
50+
e.g.:
51+
52+
from
53+
```python
54+
import InternalProtocol_pb2 as InternalProtocol__pb2
55+
```
56+
57+
to
58+
```python
59+
import fleet_protocol_protobuf_files.InternalProtocol_pb2 as InternalProtocol__pb2
4660
```
4761

4862
**GO**
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build
2+
*.egg-info

protobuf/compiled/python/ExternalProtocol_pb2.py renamed to protobuf/compiled/python/fleet_protocol_protobuf_files/ExternalProtocol_pb2.py

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protobuf/compiled/python/InternalProtocol_pb2.py renamed to protobuf/compiled/python/fleet_protocol_protobuf_files/InternalProtocol_pb2.py

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

protobuf/compiled/python/fleet_protocol_protobuf_files/__init__.py

Whitespace-only changes.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[project]
2+
name = "fleet_protocol_protobuf_files"
3+
version = "2.0.3"
4+
5+
6+
[tool.setuptools.packages.find]
7+
include = ["fleet_protocol_protobuf_files"]

0 commit comments

Comments
 (0)