Skip to content

Commit 3f65150

Browse files
committed
chore: Enhance CONTRIBUTING.md with guidelines for adding new proto files
Added a section detailing the requirement to create corresponding `__init__.py` files in the `/py/*` directory when new proto files are added to the `/proto/*` directory. This ensures proper package recognition in Python and includes examples and rationale for the requirement. Signed-off-by: Richard Sandoval <[email protected]>
1 parent 07c70e4 commit 3f65150

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

CONTRIBUTING.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,42 @@ etc.) in one go too:
4545
python -m pip install -e .[dev]
4646
```
4747

48+
### Adding new proto files
49+
50+
When you create a new directory or add proto files in the `/proto/*` directory
51+
structure, you **must** create a corresponding `__init__.py` file in the
52+
matching `/py/*` directory path.
53+
54+
For example, if you add a new proto file at:
55+
```
56+
proto/frequenz/api/common/v1/new_module/example.proto
57+
```
58+
59+
You need to create:
60+
```
61+
py/frequenz/api/common/v1/new_module/__init__.py
62+
```
63+
64+
**Why is this required?**
65+
66+
Python requires `__init__.py` files to treat directories as packages. Without
67+
these files:
68+
- The generated Python code from your proto files won't be importable
69+
- The package hierarchy won't be recognized by Python
70+
- Import statements will fail when trying to use the generated protobuf bindings
71+
72+
The `__init__.py` file should include:
73+
- A license header (see existing files for the template)
74+
- A docstring describing the module's purpose
75+
76+
**Example `__init__.py` content:**
77+
```python
78+
# License: MIT
79+
# Copyright © 2025 Frequenz Energy-as-a-Service GmbH
80+
81+
"""Description of what this module provides."""
82+
```
83+
4884
If you don't want to install all the dependencies, you can also use `nox` to
4985
run the tests and other checks creating its own virtual environments:
5086

0 commit comments

Comments
 (0)