Skip to content

Commit 8314e91

Browse files
authored
Merge branch 'main' into guhan/isr-logging
2 parents 11122ce + cd58692 commit 8314e91

23 files changed

+1493
-806
lines changed

README.md

Lines changed: 193 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ This repository holds all the code written by UW Orbital's firmware team. This i
66

77
- [Getting Started](#getting-started)
88
- [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)
1012
- [Authors](#authors)
1113

1214
**[Back to top](#table-of-contents)**
@@ -181,7 +183,7 @@ We use Code Composer Studio for debugging the firmware. **TODO**: Write a tutori
181183
182184
**[Back to top](#table-of-contents)**
183185
184-
## Style Guide
186+
## C Style Guide
185187
186188
### Comments
187189
@@ -246,6 +248,195 @@ Some of these rules don't apply in certain cases. Use your better judgement. To
246248
247249
**[Back to top](#table-of-contents)**
248250
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
361+
import dataclasses
362+
363+
@dataclasses.dataclass
364+
class PointTwoDimension:
365+
x: int
366+
y: int
367+
368+
class PointTwoDimension:
369+
def __init__(x: int, y: int):
370+
self.x = x
371+
self.y = y
372+
```
373+
374+
375+
- `EnumName` in PascalCase
376+
377+
```python
378+
import enum
379+
380+
class ErrorCode(enum.Enum):
381+
SUCCESS = 0
382+
INVALID_ARG = 1
383+
384+
# Accessing:
385+
ErrorCode.SUCCESS # <ErrorCode.SUCCESS: 0>
386+
ErrorCode.INVALID_ARG # <ErrorCode.INVALID_ARG: 1>
387+
```
388+
389+
### Imports
390+
391+
#### Grouping Imports
392+
393+
- Local imports (e.g. `import cc1120_driver`)
394+
- External library imports (e.g. `import requests`) (Must be included in the `requirements.txt`)
395+
- Standard library imports (e.g. `import math`)
396+
397+
#### Notes about imports
398+
399+
- Imports should only be used at the top of the file (no function or scoped imports)
400+
- Only modules should be imported
401+
402+
```python
403+
# module1 contains very_long_module_name and function foo and variable var.
404+
# very_long_module_name contains bar
405+
406+
# Yes:
407+
from module1 import very_long_module_name as module2 # Casting to shorter name
408+
import module1
409+
410+
module1.foo()
411+
module1.var
412+
module2.bar()
413+
414+
# No:
415+
from module1.very_long_module_name import bar
416+
from module1 import foo, var
417+
418+
foo()
419+
var
420+
bar()
421+
```
422+
423+
### Other Style Guide Points
424+
425+
- Only imports, function, class, and constants declarations and the `if __name__ == '__main__'` should be in module scope
426+
- Entry point to a script or program should be through the `main` function
427+
- Use double quotes for strings `"` over single quotes `'`
428+
- Add a trailing comma after elements of a list, if you wish to make/preserve each element on a separate line
429+
430+
**[Back to top](#table-of-contents)**
431+
432+
## Pytest Style Guide
433+
434+
- All functions that are to be tested should go into a Python file starting with `test_`
435+
- All functions that are to be tested **must** start with `test_` (This is a Pytest requirement)
436+
- Type hints are optional for Pytest functions (functions that start with `test_` in a Pytest file)
437+
438+
**[Back to top](#table-of-contents)**
439+
249440
## Authors
250441
This codebase was developed by the members of UW Orbital, the University of Waterloo's CubeSat design team.
251442

gs/sun/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ usage: ephemeris.py [-h] [-s STEP_SIZE] [-t TARGET] [-o OUTPUT] [-d] [-p {0,1,2}
1414
Position Ephemeris Retriever
1515

1616
positional arguments:
17-
- start_time Start time in the format YYYY-MM-DD or JD#
18-
- stop_time Stop time in the format YYYY-MM-DD or JD#
17+
- start_time Start time in the format YYYY-MM-DD or JD#. Must be the same format as stop time.
18+
- stop_time Stop time in the format YYYY-MM-DD or JD#. Must be the same format as start time.
1919

2020
options:
2121
- -h, --help <br>

0 commit comments

Comments
 (0)