Skip to content

Commit 6e80462

Browse files
committed
Merge branch 'main' of github.com:proveskit/circuitpy_flight_software into sdcard_logging
2 parents d445ffd + 2ca1aaf commit 6e80462

File tree

77 files changed

+3132
-1160
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+3132
-1160
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
name: coverage-report
3838
path: .coverage-reports/coverage.xml
3939
- name: SonarQube Scan
40-
uses: SonarSource/sonarqube-scan-action@v4.2.1
40+
uses: SonarSource/sonarqube-scan-action@v5.3.1
4141
env:
4242
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
4343
archive:

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ __pycache__/
33
.coverage*
44
.coverage-reports/
55
.DS_Store
6+
.hypothesis
67
.venv
78
artifacts/
89
coverage-reports/
@@ -12,3 +13,4 @@ build/
1213
pysquared.egg-info/
1314
**/*.mpy
1415
site/
16+
typeshed/

.pre-commit-config.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ repos:
2121
entry: '# type:? *ignore'
2222
language: pygrep
2323
types: [python]
24+
files: ^pysquared/
25+
exclude: ^pysquared/beacon\.py|^pysquared/logger\.py|^pysquared/rtc/manager/microcontroller\.py
26+
27+
- repo: local
28+
hooks:
29+
- id: prevent-pyright-ignore
30+
name: prevent pyright ignore annotations
31+
description: 'Enforce that no `# type: ignore` annotations exist in the codebase.'
32+
entry: '# pyright:? *.*false'
33+
language: pygrep
34+
types: [python]
35+
files: ^pysquared/
2436

2537
- repo: https://github.com/codespell-project/codespell
2638
rev: v2.4.1

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.PHONY: all
2-
all: .venv pre-commit-install
2+
all: .venv typeshed pre-commit-install
33

44
.PHONY: help
55
help: ## Display this help.
@@ -13,6 +13,11 @@ help: ## Display this help.
1313
@$(UV) venv
1414
@$(UV) pip install --requirement pyproject.toml
1515

16+
typeshed: ## Install CircuitPython typeshed stubs
17+
@echo "Installing CircuitPython typeshed stubs..."
18+
@$(MAKE) uv
19+
@$(UV) pip install circuitpython-typeshed==0.1.0 --target typeshed
20+
1621
.PHONY: pre-commit-install
1722
pre-commit-install: uv
1823
@echo "Installing pre-commit hooks..."
@@ -22,7 +27,8 @@ pre-commit-install: uv
2227
fmt: pre-commit-install ## Lint and format files
2328
$(UVX) pre-commit run --all-files
2429

25-
typecheck: .venv ## Run type check
30+
.PHONY: typecheck
31+
typecheck: .venv typeshed ## Run type check
2632
@$(UV) run -m pyright .
2733

2834
.PHONY: test
@@ -68,7 +74,7 @@ $(TOOLS_DIR):
6874
mkdir -p $(TOOLS_DIR)
6975

7076
### Tool Versions
71-
UV_VERSION ?= 0.7.13
77+
UV_VERSION ?= 0.8.14
7278
MPY_CROSS_VERSION ?= 9.0.5
7379

7480
UV_DIR ?= $(TOOLS_DIR)/uv-$(UV_VERSION)

docs/design-guide.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,19 @@ PySquared is built on top of CircuitPython, which is a version of Python designe
1919

2020
We use type hints throughout the PySquared codebase to ensure that our code is clear and maintainable. Type hints help us catch errors early and make it easier to understand the expected types of variables and function parameters.
2121

22-
We do not accept changes with lines that are ignored the type checker i.e. `# type: ignore`. If you run into an issue where you think you need to ignore a type, it is likely a problem with the design of your component. Please take a moment to think about how you can fix the type error instead. If you need help, please reach out for assistance.
22+
We use [typeshed](https://peps.python.org/pep-0561/) stubs to provide more accurate type hints for CircuitPython, replacing the default Python standard library type hints. These CircuitPython-specific stubs are located in the `typeshed/` directory. This helps the typechecker catch compatibility issues with CircuitPython code before running it on a device.
23+
24+
However, using these stubs means that type hints in test files also reference CircuitPython types, not the standard Python types available in the test environment. As a workaround, we add pyright ignore comments (e.g., `# pyright: reportOptionalMemberAccess=false`) when necessary at the top of test files to suppress related errors. This workaround isn’t ideal. If you have suggestions for handling this issue more effectively, please share your feedback.
25+
26+
We do not accept changes to files in the `pysquared/` directory that include lines ignoring the type checker (e.g., `# type: ignore`). The only exceptions are:
27+
28+
- **Upstream Fix in Progress:** If a type error is caused by a bug or limitation in an external dependency, you may ignore the line only when leaving a comment with a link to the issue or PR where it is fixed or a fix is in progress. A valid type hint might look like this:
29+
30+
```python
31+
some_variable = some_function() # type: ignore # PR https://github.com/adafruit/circuitpython/pull/10603
32+
```
33+
34+
If you encounter a type error, first consider if it can be resolved by improving your code's design. If you believe an exception is necessary, please reach out for assistance before proceeding.
2335

2436
??? note "Using the Typing Module"
2537
For more advanced type hinting we can use the Python standard library's `typing` module which was introduced in Python 3.5. This module provides a variety of type hints that can be used to specify more complex types, such as `List`, `Dict`, and `Optional`. CircuitPython does not support the `typing` module so we must wrap the import in a try/except block to avoid import errors. For example:
@@ -120,7 +132,7 @@ The following table lists possible sensor properties, their corresponding types
120132
| duty_cycle | int | 16-bit PWM duty cycle |
121133
| eCO2 | float | equivalent/estimated COin ppm |
122134
| frequency | int | Hertz (Hz) |
123-
| gyro | (float, float, float)| x, y, z radians per second |
135+
| angular velocity | (float, float, float)| x, y, z radians per second |
124136
| light | float | non-unit-specific light levels |
125137
| lux | float | SI lux |
126138
| magnetic | (float, float, float)| x, y, z micro-Tesla (uT) |

mocks/adafruit_lis2mdl/lis2mdl.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
need for actual hardware.
66
"""
77

8+
from pysquared.sensor_reading.magnetic import Magnetic
9+
810

911
class LIS2MDL:
1012
"""A mock LIS2MDL magnetometer."""
@@ -17,4 +19,7 @@ def __init__(self, i2c) -> None:
1719
"""
1820
self.i2c = i2c
1921

20-
magnetic: tuple[float, float, float] = (0.0, 0.0, 0.0)
22+
@property
23+
async def async_magnetic(self):
24+
"""Asynchronously returns a mock magnetic field vector."""
25+
return Magnetic(0.0, 0.0, 0.0)

mocks/adafruit_lsm6ds/lsm6dsox.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,5 @@ def __init__(self, i2c_bus: I2C, address: int) -> None:
2121
...
2222

2323
acceleration: tuple[float, float, float] = (0.0, 0.0, 0.0)
24-
gyro: tuple[float, float, float] = (0.0, 0.0, 0.0)
24+
angular_velocity: tuple[float, float, float] = (0.0, 0.0, 0.0)
2525
temperature: float = 0.0

mocks/adafruit_mcp9808/mcp9808.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
"""Mock for the Adafruit MCP9808 temperature sensor.
2+
3+
This module provides a mock implementation of the Adafruit MCP9808 temperature sensor for
4+
testing purposes. It allows for simulating the behavior of the MCP9808 without the
5+
need for actual hardware.
6+
"""
7+
8+
from busio import I2C
9+
10+
11+
class MCP9808:
12+
"""A mock MCP9808 temperature sensor."""
13+
14+
def __init__(self, i2c: I2C, addr: int) -> None:
15+
"""Initializes the mock MCP9808.
16+
17+
Args:
18+
i2c: The I2C bus to use.
19+
addr: The I2C address of the MCP9808.
20+
"""
21+
self.i2c = i2c
22+
self.addr = addr
23+
24+
temperature = 25.0

mocks/circuitpython/busio.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55
the need for actual hardware.
66
"""
77

8-
from __future__ import annotations
9-
108
from typing import Optional
119

12-
import mocks.circuitpython.microcontroller as microcontroller
10+
import microcontroller
1311

1412

1513
class SPI:

mocks/circuitpython/digitalio.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
the need for actual hardware.
66
"""
77

8-
from __future__ import annotations
9-
10-
import mocks.circuitpython.microcontroller as microcontroller
8+
import microcontroller
119

1210

1311
class DriveMode:

0 commit comments

Comments
 (0)