You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+193-2Lines changed: 193 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,9 @@ This repository holds all the code written by UW Orbital's firmware team. This i
6
6
7
7
-[Getting Started](#getting-started)
8
8
-[Contributing](#contributing)
9
-
-[Style Guide](#style-guide)
9
+
-[C Style Guide](#c-style-guide)
10
+
-[Python Style Guide](#python-style-guide)
11
+
-[Pytest Style Guide](#pytest-style-guide)
10
12
-[Authors](#authors)
11
13
12
14
**[Back to top](#table-of-contents)**
@@ -181,7 +183,7 @@ We use Code Composer Studio for debugging the firmware. **TODO**: Write a tutori
181
183
182
184
**[Back to top](#table-of-contents)**
183
185
184
-
## Style Guide
186
+
## C Style Guide
185
187
186
188
### Comments
187
189
@@ -246,6 +248,195 @@ Some of these rules don't apply in certain cases. Use your better judgement. To
246
248
247
249
**[Back to top](#table-of-contents)**
248
250
251
+
## Python Style Guide
252
+
253
+
- We will be following the Python language style guide [PEP8](https://peps.python.org/pep-0008/)
254
+
- If there are any discrepancies between this style guide and PEP8, this style guide takes precedence.
255
+
256
+
### Type Hinting Convention
257
+
258
+
All function and method parameters (except for the `self` and `cls` parameters) and return signatures should be type hinted.
259
+
260
+
```python
261
+
def my_add(num1: int, num2: int) -> int:
262
+
"""
263
+
@brief Adds two numbers together
264
+
265
+
@param num1 - The first number to add.
266
+
@param num2 - The second number to add.
267
+
@return Returns the sum of the two numbers.
268
+
"""
269
+
return num1 + num2
270
+
```
271
+
272
+
### Comments
273
+
274
+
#### Single Line Comments
275
+
276
+
Variable and function names should be descriptive enough to understand even without comments. Comments are needed to describe any complicated logic. Use `#` for single-line comments.
277
+
278
+
#### Function and Method Comments
279
+
280
+
Function and method comments using `""" """` should exist below the function declaration. For methods, the `self` or `cls` parameter does not require a description.
281
+
282
+
```python
283
+
def my_add(num1: int, num2: int) -> int:
284
+
"""
285
+
@brief Adds two numbers together
286
+
287
+
@param num1 - The first number to add.
288
+
@param num2 - The second number to add.
289
+
@return Returns the sum of the two numbers.
290
+
"""
291
+
return num1 + num2
292
+
```
293
+
294
+
```python
295
+
def increase_x(self, count: int) -> None:
296
+
"""
297
+
@brief Increases the x attribute by the count.
298
+
299
+
@param count - Count to increase the x attribute by.
300
+
"""
301
+
self.x += count
302
+
```
303
+
304
+
#### File Header Comments
305
+
306
+
File comments are not required
307
+
308
+
#### Class Comments
309
+
310
+
- Class comments should exist after the class definition
311
+
- Provide a brief description given class purpose
312
+
- Provide a section in the class comment listing the attributes, their type and purpose
313
+
- Enum class comments do not require listing the attributes
314
+
315
+
```python
316
+
class PointTwoDimension:
317
+
"""
318
+
@brief Class for storing a 2D point
319
+
@attribute x (int) - x coordinate of the point
320
+
@attribute y (int) - y coordinate of the point
321
+
"""
322
+
323
+
def __init__(x: int, y: int):
324
+
self.x = x
325
+
self.y = y
326
+
327
+
@dataclasses.dataclass
328
+
class PointTwoDimension:
329
+
"""
330
+
@brief Class for storing a 2D point
331
+
@attribute x (int) - x coordinate of the point
332
+
@attribute y (int) - y coordinate of the point
333
+
"""
334
+
335
+
x: int
336
+
y: int
337
+
```
338
+
```python
339
+
import enum
340
+
341
+
# No comments required
342
+
class ErrorCode(enum.Enum):
343
+
"""
344
+
@brief Enum for the error codes
345
+
"""
346
+
347
+
SUCCESS = 0
348
+
INVALID_ARG = 1
349
+
```
350
+
351
+
### Naming Conventions
352
+
353
+
- `variable_names`, `field_names` and `function_constants` in snake_case
354
+
- `_private_field_names`, and `_private_method_names()` in \_snake_case
355
+
- `function_names()` and `method_names()` in snake_case
356
+
- `CONSTANT_NAMES: Final` and `ENUM_OPTIONS` in CAPITAL_SNAKE_CASE for module and class constants (not for local constant)
357
+
- `file_names` in snake_case
358
+
- `ClassName` in PascalCase
359
+
```python
360
+
# For brevity, the class comments were removed but they should be in real code
0 commit comments