Skip to content

Commit 221cbcc

Browse files
committed
Initial ci tooling/linting/typechecking
1 parent cac5871 commit 221cbcc

File tree

15 files changed

+1974
-1006
lines changed

15 files changed

+1974
-1006
lines changed

.github/workflows/ci.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: ci
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
lint:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v4
14+
- name: Lint
15+
run: |
16+
make fmt

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.ruff_cache/
2+
tools/

.pre-commit-config.yaml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
repos:
2+
- repo: https://github.com/pre-commit/pre-commit-hooks
3+
rev: v5.0.0
4+
hooks:
5+
- id: trailing-whitespace
6+
- id: end-of-file-fixer
7+
- id: check-yaml
8+
- id: check-json
9+
- id: check-added-large-files
10+
#- id: mixed-line-ending
11+
# args: [ --fix=lf ]
12+
13+
- repo: https://github.com/astral-sh/ruff-pre-commit
14+
rev: v0.8.6
15+
hooks:
16+
- id: ruff
17+
args: [ --fix ]
18+
- id: ruff
19+
args: [ --fix, --select, I ] # import sorting
20+
- id: ruff-format
21+
22+
exclude: 'lib/examples/*'

Makefile

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
.PHONY: all
2+
all: .venv pre-commit-install help
3+
4+
.PHONY: help
5+
help: ## Display this help.
6+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
7+
8+
##@ Development
9+
10+
.venv: ## Create a virtual environment
11+
@echo "Creating virtual environment..."
12+
@$(MAKE) uv
13+
@$(UV) venv
14+
@$(UV) pip install --requirement pyproject.toml
15+
16+
.PHONY: pre-commit-install
17+
pre-commit-install: uv
18+
@echo "Installing pre-commit hooks..."
19+
@$(UVX) pre-commit install > /dev/null
20+
21+
.PHONY: fmt
22+
fmt: pre-commit-install ## Lint and format files
23+
$(UVX) pre-commit run --all-files
24+
25+
typecheck: .venv ## Run type check
26+
@$(UV) run -m pyright .
27+
28+
.PHONY: clean
29+
clean: ## Remove all gitignored files
30+
git clean -dfX
31+
32+
##@ Build Tools
33+
TOOLS_DIR ?= tools
34+
$(TOOLS_DIR):
35+
mkdir -p $(TOOLS_DIR)
36+
37+
### Tool Versions
38+
UV_VERSION ?= 0.5.24
39+
40+
UV_DIR ?= $(TOOLS_DIR)/uv-$(UV_VERSION)
41+
UV ?= $(UV_DIR)/uv
42+
UVX ?= $(UV_DIR)/uvx
43+
.PHONY: uv
44+
uv: $(UV) ## Download uv
45+
$(UV): $(TOOLS_DIR)
46+
@test -s $(UV) || { mkdir -p $(UV_DIR); curl -LsSf https://astral.sh/uv/$(UV_VERSION)/install.sh | UV_INSTALL_DIR=$(UV_DIR) sh > /dev/null; }

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,12 @@ CircuitPython driver for the Semtech SX1280 LoRa chip (2.4 GHz)
33

44
## 🚧 Under construction. Use at your own risk!
55

6-
### Status:
7-
- [x] init and configure
6+
### Status:
7+
- [x] init and configure
88
- [x] confirm Tx - [see example_tx](example_tx.py)
99
- [x] confirm Rx
1010
- [x] exchange packet(s)
1111
- [x] confirm ranging
1212
- [ ] make library user friendly
1313

14-
NOTE: only LoRa aspects implemented thus far. lots of things are hard-coded in. Nearly all LoRa functionality is available (Tx, Rx, Ranging), but message buffer handling isn't streamlined yet.
15-
14+
NOTE: only LoRa aspects implemented thus far. lots of things are hard-coded in. Nearly all LoRa functionality is available (Tx, Rx, Ranging), but message buffer handling isn't streamlined yet.

example.py renamed to examples/example.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@
1010

1111
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
1212

13-
radio = sx1280.SX1280(spi, CS, RESET, BUSY)
13+
radio = sx1280.SX1280(spi, CS, RESET, BUSY)
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import board,time
1+
import time
2+
3+
import board
24
import busio
35
import digitalio
46

57
import sx1280
68

79
CS = digitalio.DigitalInOut(board.D35)
810
RESET = digitalio.DigitalInOut(board.D36)
9-
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
11+
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
1012
DIO1 = digitalio.DigitalInOut(board.D41)
1113
DIO2 = digitalio.DigitalInOut(board.D42)
1214
DIO3 = digitalio.DigitalInOut(board.D38)
@@ -24,9 +26,9 @@
2426
while True:
2527
radio.range()
2628
time.sleep(4)
27-
status=radio.get_Irq_Status()
29+
status = radio.get_Irq_Status()
2830
if status[2] > 0 or status[3] > 0:
2931
data1 = radio.read_range(raw=False)
30-
print('Filtered:',data1)
32+
print("Filtered:", data1)
3133
data2 = radio.read_range(raw=True)
32-
print('Raw:\t',data2)
34+
print("Raw:\t", data2)
Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
import board,time
1+
import time
2+
3+
import board
24
import busio
35
import digitalio
46

57
import sx1280
68

79
CS = digitalio.DigitalInOut(board.D35)
810
RESET = digitalio.DigitalInOut(board.D36)
9-
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
11+
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
1012
DIO1 = digitalio.DigitalInOut(board.D41)
1113
DIO2 = digitalio.DigitalInOut(board.D42)
1214
DIO3 = digitalio.DigitalInOut(board.D38)
@@ -25,5 +27,5 @@
2527
time.sleep(5)
2628
status = radio.get_Irq_Status()
2729
if status[2] > 0 or status[3] > 0:
28-
[print(hex(i)+' ',end='') for i in status]
29-
print('')
30+
[print(hex(i) + " ", end="") for i in status]
31+
print("")

example_rx.py renamed to examples/example_rx.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
'''
1+
"""
22
Working RX example for SX1280 breakout using SAM32
3-
'''
3+
"""
44

5-
import board,time
5+
import time
6+
7+
import board
68
import busio
79
import digitalio
810

911
import sx1280
1012

1113
CS = digitalio.DigitalInOut(board.D35)
1214
RESET = digitalio.DigitalInOut(board.D36)
13-
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
15+
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
1416
DIO1 = digitalio.DigitalInOut(board.D41)
1517
DIO2 = digitalio.DigitalInOut(board.D42)
1618
DIO3 = digitalio.DigitalInOut(board.D31)
@@ -28,6 +30,6 @@
2830

2931
while True:
3032
msg = radio.receive()
31-
if msg != None:
33+
if msg is not None:
3234
print(msg, radio.packet_status)
33-
time.sleep(1)
35+
time.sleep(1)
Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
'''
1+
"""
22
Working TX example for SX1280 breakout using SAM32
3-
'''
3+
"""
44

5-
import board,time
5+
import time
6+
7+
import board
68
import busio
79
import digitalio
810

911
import sx1280
1012

1113
CS = digitalio.DigitalInOut(board.D35)
1214
RESET = digitalio.DigitalInOut(board.D36)
13-
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
15+
BUSY = digitalio.DigitalInOut(board.D37) # lambda DIO0
1416
DIO1 = digitalio.DigitalInOut(board.D41)
1517
DIO2 = digitalio.DigitalInOut(board.D42)
1618
DIO3 = digitalio.DigitalInOut(board.D31)
@@ -23,8 +25,8 @@
2325

2426
radio = sx1280.SX1280(spi, CS, RESET, BUSY, debug=False)
2527

26-
cnt=0
28+
cnt = 0
2729
while True:
28-
cnt+=1
29-
radio.send('ping'+str(cnt))
30-
time.sleep(1)
30+
cnt += 1
31+
radio.send("ping" + str(cnt))
32+
time.sleep(1)

0 commit comments

Comments
 (0)