Repository navigation
process: Python Coding Guidelines #741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8ecf997
process: Python Coding Guidelines
AlexanderLanin 117badd
move guidelines to contribute
AlexanderLanin 689e0cd
Coding Guidelines are docs and not guidelines
AlexanderLanin 101cbfe
fix whitespace
AlexanderLanin 77d6dec
fix 3 review hints
AlexanderLanin 59c8bef
add rust placeholder
AlexanderLanin 0ddbe82
Merge branch 'main' into alex-python-guide
AlexanderLanin b6f7f7a
Merge remote-tracking branch 'upstream/main' into alex-python-guide
AlexanderLanin 565ea1f
fix merge problem
AlexanderLanin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,4 +19,6 @@ Development | |
| :maxdepth: 1 | ||
|
|
||
| development_environment | ||
|
|
||
| cpp/index | ||
| rust/index | ||
| python/index | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| .. | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
|
|
||
| Writing Python Code | ||
| ################### | ||
|
|
||
| .. document:: Coding Guidelines Python | ||
| :id: doc__python_coding_guidelines | ||
| :status: valid | ||
|
|
||
| Coding Guidelines | ||
| ================= | ||
| .. warning:: Python is not meant to be used directly in safety critical systems. The following guidelines are only meant for tooling. | ||
| Every tool written will need to be evaluated for safety criticallity (TCL). | ||
|
|
||
|
|
||
| **Consistency within score matters more than personal preference**. | ||
|
|
||
| The art lies in balancing completeness of this document vs keeping it short, since frankly, no one | ||
| will read a long document. Let's focus on issues that actively come up in real life and are worth | ||
| discussing and agreeing upon, not on things that *might* be important. | ||
|
|
||
| We don't want to write a book here. And we don't have to, since Python is not used for safety | ||
| critical systems. However, to provide sufficient argumentation for code quality when it comes to | ||
| tool qualification it is necessary to have and actively use guidelines. | ||
|
|
||
| This guide is a **living document**—keep it concise, relevant, and practical. | ||
|
|
||
| We assume basic programming and software-engineering know-how and will not repeat basics here! Go | ||
| ask Google or ChatGPT. Or one of these established Python best practice websites: | ||
|
|
||
| - [PEP 8](https://pep8.org/) | ||
| - [The Hitchhiker's Guide to Python](https://docs.python-guide.org/) | ||
| - [Real Python](https://realpython.com/) | ||
|
|
||
| Comments | ||
| -------- | ||
| - The first rule of comments is to write them **only when something is worth explaining**. | ||
| - Comments should explain *why* the code does something, not *what* it does. | ||
| - Avoid redundant comments: if the code is clear enough, a comment is not needed. | ||
| - Take the user's perspective when writing docstrings | ||
|
|
||
| Testing | ||
| ------- | ||
| - **Readability:** For some reason, people tend to forget all they have ever learned about | ||
| readability when writing tests. **Tests do not have tests.** They must be even more readable than | ||
| production code! | ||
|
AlexanderLanin marked this conversation as resolved.
|
||
| - **Mocking is an anti-pattern.** Well... it's complex. We don't want to write a book on mocking | ||
| here. Just really, really consider whether mocking is the best approach. - Favor dependency | ||
| injection and lightweight fixtures over excessive mocking. Mocks should not replace proper | ||
| design. | ||
| - **Do not test every single function or class!** Instead: - Focus on testing *behavior*, not | ||
| implementation details. Overly fine-grained tests lead to brittle code and high maintenance. | ||
| - **Boundary conditions:** - Edge cases often break things. Think about invalid input, large data | ||
| sets, empty cases, and concurrency issues. | ||
|
|
||
| Documentation | ||
| -------------------- | ||
| - If your documentation doesn't fit into a comment, create a `README.md` in the directory of the | ||
| tool. | ||
| - `README.md` should explain the overall architecture and key design decisions. | ||
| - If the design impacts multiple components, consider an architecture diagram. | ||
| - User-facing documentation is stored under `docs/guidance`. | ||
|
|
||
|
|
||
| Tools & Versions | ||
| ================ | ||
|
|
||
| We're using Python, Ruff (linting & formatting), Pyright (linting) and pytest for our tooling. The | ||
| versions are managed by the infrastructure community and will be updated as frequently as possible. | ||
| The configuration is managed by infrastructure and process communities. | ||
|
|
||
| *Compliance to all tools is mandatory, and will be enforced by pull request checks.* | ||
|
|
||
| Currently we do NOT aim at supporting older Python versions. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| .. | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
|
|
||
| Python | ||
| ###### | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 1 | ||
|
|
||
| coding_guidelines |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| .. | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
|
|
||
| Writing Rust Code | ||
| ################# | ||
|
|
||
| .. document:: Coding Guidelines Rust | ||
| :id: doc__rust_coding_guidelines | ||
| :status: invalid | ||
|
|
||
| .. note:: The Rust coding guidelines are not yet defined. This is a placeholder for future content. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| .. | ||
| # ******************************************************************************* | ||
| # Copyright (c) 2025 Contributors to the Eclipse Foundation | ||
| # | ||
| # See the NOTICE file(s) distributed with this work for additional | ||
| # information regarding copyright ownership. | ||
| # | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Apache License Version 2.0 which is available at | ||
| # https://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| # ******************************************************************************* | ||
|
|
||
| Rust | ||
| #### | ||
|
|
||
| .. toctree:: | ||
| :maxdepth: 1 | ||
|
|
||
| coding_guidelines |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.