mirror of
https://github.com/meshtastic/python.git
synced 2026-06-02 12:45:00 -04:00
2.6 KiB
2.6 KiB
Contributing Example Scripts
Use this guide when adding or updating scripts in examples/.
Must-have checklist before opening a PR
- Script teaches one clear thing (its primary learning goal).
- File name matches that goal.
- Top docstring states purpose, transport scope, behavior, and expected output.
- Script has safe shutdown (
with ...orfinally) and gracefulKeyboardInterrupthandling. - Argument handling is clear (
argparsepreferred). - Errors are explicit (no bare
except:). - The script is not a near-duplicate of an existing example.
Choose the right teaching goal
Each example should have one primary lesson. Keep it focused.
- Good: "Send one text message over serial."
- Good: "Print inbound text messages."
- Avoid: discovery + chat + config mutation all in one script unless that combined flow is the lesson.
Transport scope must be explicit
State exactly what transports are supported and why.
- Serial-only when that keeps the example simplest.
- Multi-transport (Serial/TCP/BLE) only when transport selection is part of the lesson.
- If TCP/BLE are supported, expose explicit flags (
--host,--ble) and document defaults.
Behavior and output should be predictable
Readers should know if the script sends, receives, mutates config, or combines those.
- Receive examples: subscribe to the narrowest pubsub topic that matches the lesson.
- Send examples: clarify destination behavior (broadcast default vs explicit destination).
- Mutation examples: clearly document side effects.
Output should make success easy to confirm:
- Print concise, stable status/event lines.
- Avoid noisy debug output unless the script is specifically diagnostic-focused.
Cleanup and error handling
- Use context managers where practical; otherwise close interfaces in
finally. - Handle
KeyboardInterruptcleanly. - Exit non-zero for invalid args, connection/setup failures, or command failures.
Naming guidance
Use descriptive names tied to the teaching goal.
- Prefer names like
tcp_connection_info_once.pyoverpub_sub_example.py. - Prefer names like
tcp_pubsub_send_and_receive.pyoverpub_sub_example2.py. - Avoid generic names such as
example2.py.
Keep existing filenames only when compatibility or discoverability outweighs clarity.
New script vs extending an existing one
Create a new script when:
- The learning goal is genuinely distinct.
- Combining behaviors would make either example harder to understand.
Extend an existing script when:
- The change deepens the same lesson.
- The resulting script remains focused and readable.