Skip to content

Commit 44648dc

Browse files
authored
Merge pull request #356 from sourcebots/future-api
A new API
2 parents 2c4836a + 26b0da6 commit 44648dc

Some content is hidden

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

54 files changed

+3326
-1658
lines changed

.github/workflows/test_build.yml

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ jobs:
1010
fail-fast: false
1111
matrix:
1212
os: [ubuntu-latest]
13-
py_version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
13+
py_version: ["3.9", "3.9", "3.10", "3.11", "3.12", "3.13"]
1414
include:
1515
- os: windows-latest
16-
py_version: "3.8"
16+
py_version: "3.9"
1717
- os: windows-latest
18-
py_version: "3.12"
18+
py_version: "3.12" # WinSDK doesn't support 3.13, need to update april-vision
1919
- os: macos-latest
20-
py_version: "3.8"
20+
py_version: "3.9"
2121
- os: macos-latest
22-
py_version: "3.12"
22+
py_version: "3.13"
2323
runs-on: ${{ matrix.os }}
2424
steps:
2525
- uses: actions/checkout@v4
@@ -35,16 +35,13 @@ jobs:
3535
python -m pip install .[dev,vision]
3636
- name: Lint
3737
run: |
38-
make lint
39-
- name: Isort
40-
run: |
41-
make isort-check
38+
poe lint
4239
- name: Typecheck
4340
run: |
44-
make type
41+
poe type
4542
- name: Run tests
4643
run: |
47-
make test
44+
poe test
4845
4946
build:
5047
permissions:
@@ -55,18 +52,18 @@ jobs:
5552
- uses: actions/checkout@v4
5653
with:
5754
fetch-depth: 0
58-
- name: Set up Python 3.8
55+
- name: Set up Python 3.10
5956
uses: actions/setup-python@v5
6057
with:
61-
python-version: "3.8"
58+
python-version: "3.10"
6259
- name: Install dependencies
6360
run: |
64-
python -m pip install --upgrade pip build
61+
python -m pip install --upgrade pip build poethepoet
6562
# Install package to generate version info
6663
python -m pip install .
6764
- name: Build package
6865
run: |
69-
make build
66+
poe build
7067
- name: Save built package
7168
uses: actions/upload-artifact@v4
7269
with:

Makefile

Lines changed: 0 additions & 33 deletions
This file was deleted.

pyproject.toml

Lines changed: 79 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,32 @@
1+
# ### Linting Rules ###
2+
[tool.ruff]
3+
target-version = "py39"
4+
line-length = 95
5+
lint.select = [
6+
"D", # pydocstyle
7+
"E", # pycodestyle error
8+
"F", # pyflakes
9+
"I", # isort
10+
"W", # pycodestyle warning
11+
"RUF", # ruff-specific
12+
"B006", # mutable default argument
13+
"B021", # f-string docstring
14+
"COM818", # warn about implicitly creating a tuple
15+
"SLF001", # warn about accessing private members, these can be noqa'd when necessary
16+
]
17+
lint.preview = true # Enable preview to get the rest of pycodestyle errors
18+
lint.ignore = [
19+
"D104", # Ignore missing docstring in public package
20+
"D105", # Ignore missing docstring in magic method
21+
"D107", # Ignore missing docstring in __init__
22+
"D401", # Ignore first line of docstring should be in imperative mood
23+
"D203", # Ignore 1 blank line required before class docstring
24+
"D212", # Ignore Multi-line docstring summary should start at the first line
25+
"RUF005", # Allow alternate iterable unpacking
26+
"RUF015", # Allow + concatenation
27+
]
28+
29+
# ### Formatting Rules ###
130
[tool.mypy]
231
mypy_path = "stubs"
332

@@ -19,6 +48,11 @@ disallow_untyped_decorators = true
1948

2049
check_untyped_defs = true
2150

51+
[[tool.mypy.overrides]]
52+
# Ignore type checking for the tests
53+
module = ["tests.*"]
54+
ignore_errors = true
55+
2256
[tool.isort]
2357
atomic = true
2458
balanced_wrapping = true
@@ -50,11 +84,12 @@ authors = [{name = "SourceBots", email = "[email protected]"}]
5084
readme = "README.md"
5185
license = {file = "LICENSE"}
5286
dynamic = ["version"]
53-
requires-python = ">=3.8"
87+
requires-python = ">=3.9"
5488
dependencies = [
5589
"pyserial >=3,<4",
5690
"april_vision==2.2.0",
5791
"typing-extensions; python_version<'3.10'",
92+
"python-dotenv==1.0.1",
5893
]
5994
classifiers = [
6095
"Topic :: Software Development :: Libraries :: Python Modules",
@@ -71,8 +106,8 @@ Documentation = "https://docs.sourcebots.co.uk"
71106

72107
[project.optional-dependencies]
73108
dev = [
74-
"flake8",
75-
"isort",
109+
"poethepoet >=0.0.1,<1",
110+
"ruff >=0.9,<1",
76111
"mypy==1.10.0; python_version<'3.9'",
77112
"mypy>=1.7,<2; python_version>='3.9'",
78113
"build",
@@ -83,3 +118,44 @@ dev = [
83118
]
84119
vision = ["opencv-python-headless >=4,<5"]
85120
mqtt = ["paho-mqtt >=2,<3"]
121+
122+
# ### Tasks ###
123+
[tool.poe.env]
124+
PYMODULE = "sbot"
125+
PYFOLDERS = "sbot tests"
126+
127+
[tool.poe.tasks.lint]
128+
help = "Run ruff against the project to check for linting errors."
129+
cmd = "ruff check $PYFOLDERS"
130+
131+
[tool.poe.tasks.type]
132+
help = "Run mypy against the project to check for type errors."
133+
cmd = "python -m mypy $PYMODULE"
134+
135+
[tool.poe.tasks.test]
136+
help = "Run pytest against the project to check for test errors."
137+
cmd = "python -m pytest --cov=$PYMODULE --cov-report=term --cov-report=xml tests"
138+
139+
[tool.poe.tasks.test-html]
140+
help = "Run pytest against the project to check for test errors."
141+
cmd = "python -m pytest --cov=$PYMODULE --cov-report=html tests"
142+
143+
[tool.poe.tasks.check]
144+
help = "Check the project for linting, type and test errors."
145+
sequence = ["lint", "type", "test"]
146+
147+
[tool.poe.tasks.fix]
148+
help = "Use ruff to fix any auto-fixable linting errors."
149+
cmd = "ruff check --fix-only $PYFOLDERS"
150+
151+
[tool.poe.tasks.build]
152+
help = "Build the wheel and source distributions."
153+
cmd = "python -m build"
154+
155+
[tool.poe.tasks.clean]
156+
help = "Clean the project of any build artifacts."
157+
sequence = [
158+
"shutil:rmtree('dist', ignore_errors=1)",
159+
"shutil:rmtree('build', ignore_errors=1)",
160+
]
161+
default_item_type = "script"

sbot/__init__.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,32 @@
1-
from .arduino import AnalogPins, GPIOPinMode
2-
from .exceptions import (
3-
BoardDisconnectionError, MetadataKeyError, MetadataNotReadyError,
4-
)
5-
from .game_specific import GAME_LENGTH
6-
from .leds import Colour
7-
from .logging import add_trace_level
8-
from .motor_board import MotorPower
9-
from .power_board import Note, PowerOutputPosition
10-
from .robot import Robot
1+
from os import environ as _environ
112

12-
add_trace_level()
3+
from ._arduinos import AnalogPin, GPIOPinMode
4+
from ._leds import Colour
5+
from ._motors import MotorPower
6+
from ._power import PowerOutputPosition
7+
from ._utils import Note
8+
9+
if 'SBOT_PYTEST' not in _environ:
10+
from .robot import arduino, comp, leds, motors, power, servos, utils, vision
1311

1412
BRAKE = MotorPower.BRAKE
1513
COAST = MotorPower.COAST
1614

1715
__all__ = [
18-
'AnalogPins',
1916
'BRAKE',
20-
'BoardDisconnectionError',
2117
'COAST',
18+
'AnalogPin',
2219
'Colour',
23-
'GAME_LENGTH',
2420
'GPIOPinMode',
25-
'MetadataKeyError',
26-
'MetadataNotReadyError',
21+
'MotorPower',
2722
'Note',
2823
'PowerOutputPosition',
29-
'Robot',
24+
'arduino',
25+
'comp',
26+
'leds',
27+
'motors',
28+
'power',
29+
'servos',
30+
'utils',
31+
'vision',
3032
]

0 commit comments

Comments
 (0)