Skip to content

Commit 9a4854d

Browse files
committed
docs: Update conventions after snake_case migration.
1 parent c775c29 commit 9a4854d

2 files changed

Lines changed: 74 additions & 4 deletions

File tree

CLAUDE.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# CLAUDE.md — Project Guidelines
2+
3+
## Project Overview
4+
5+
MicroPython driver library for the [STeaMi](https://www.steami.cc/) board. Each driver lives under `lib/<component>/` and follows a standard structure.
6+
7+
## Driver Structure
8+
9+
Each completed driver must contain:
10+
11+
```
12+
lib/<component>/
13+
├── README.md
14+
├── manifest.py # metadata() + package("<module_name>")
15+
├── <module_name>/
16+
│ ├── __init__.py # exports main class
17+
│ ├── const.py # register constants using micropython.const()
18+
│ └── device.py # main driver class
19+
└── examples/ # English, plural — NOT "exemple" or "example"
20+
└── *.py
21+
```
22+
23+
## Coding Conventions
24+
25+
- **Naming**: `snake_case` for all methods and variables. Enforced by ruff (N802, N803, N806).
26+
- **Constants**: use `from micropython import const` wrapper in `const.py` files.
27+
- **Imports**: `from <module>.const import *` is the project convention (F403/F405 ignored by ruff).
28+
- **Class inheritance**: `class Foo(object):` is the existing convention (Python 2 style, kept for consistency).
29+
- **Time**: use `from time import sleep_ms` (not `utime`, which is deprecated since MicroPython 1.19+).
30+
- **Exceptions**: use `except Exception:` instead of bare `except:` when possible.
31+
- **No debug prints** in production driver code. Enforced by ruff (T20, examples and tests excluded).
32+
33+
## Driver API Conventions
34+
35+
Each driver class must follow these conventions for consistency across the library:
36+
37+
- **Constructor signature**: `def __init__(self, i2c, ..., address=DEFAULT_ADDR)` — first parameter is always `i2c` (not `bus`), address uses keyword argument with a default from `const.py`.
38+
- **Attributes**: `self.i2c` for the I2C bus, `self.address` for the device address (not `self.bus`, `self.addr`).
39+
- **I2C helpers**: use private snake_case methods `_read_reg()`, `_write_reg()` for register access.
40+
- **Time functions**: `from time import sleep_ms` — use `sleep_ms()` with integer milliseconds (not `sleep()` with float seconds, not `from utime import`).
41+
- **Constants**: always wrap register values with `micropython.const()` in `const.py` files.
42+
- **Class style**: `class DriverName(object):` (Python 2 compatible style, kept for MicroPython consistency).
43+
- **Exception handling**: `except Exception:` — never use bare `except:`.
44+
45+
## Linting
46+
47+
- Linter: **ruff** (config in `pyproject.toml`)
48+
- Line length: 99
49+
- Target: Python 3.7
50+
- Run: `ruff check` (CI runs this on PRs)
51+
- Key ignored rules: E722 (bare except), F401/F403/F405 (wildcard imports), E501 (line length)
52+
- Naming rules: N802 (function name), N803 (argument name), N806 (variable name)
53+
- No-print rule: T20 (examples and tests excluded)
54+
55+
## Commit Messages
56+
57+
Format enforced by CI: `<scope>: <Description starting with capital letter ending with .>`
58+
59+
- Pattern: `^[^!]+: [A-Za-z]+.+ .+\.$`
60+
- Max length: 78 characters
61+
- Examples: `hts221: Fix missing self parameter in get_av method.`, `docs: Fix typos in README files.`
62+
63+
## CI Checks
64+
65+
- `.github/workflows/python-linter.yml` — runs `ruff check` on push/PR to main
66+
- `.github/workflows/check-commits.yml` — validates commit message format on PRs
67+
68+
## Related Repositories
69+
70+
- [steamicc/micropython-steami-tutorials](https://github.com/steamicc/micropython-steami-tutorials) — high-level display library (`steami_screen.py`, `steami_gc9a01.py`) that wraps the low-level drivers from this repo.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,8 +249,8 @@ from apds9960 import APDS9960
249249
i2c = machine.I2C(1)
250250
apds = APDS9960(i2c)
251251

252-
apds.enableLightSensor()
253-
light = apds.readAmbientLight()
252+
apds.enable_light_sensor()
253+
light = apds.read_ambient_light()
254254

255255
```
256256

@@ -461,7 +461,7 @@ lib/<component>/
461461
### Coding conventions
462462

463463
- **Constants**: use `from micropython import const` wrapper in `const.py` files.
464-
- **Naming**: `snake_case` for new methods. Legacy `camelCase` is acceptable for I2C helpers to stay consistent with existing drivers.
464+
- **Naming**: `snake_case` for all methods and variables. Enforced by ruff (N802, N803, N806).
465465
- **Class inheritance**: `class Foo(object):` is the existing convention.
466466
- **Time**: use `from time import sleep_ms` (not `utime`, not `sleep()` with float seconds).
467467
- **Exceptions**: use `except Exception:` instead of bare `except:`.
@@ -471,7 +471,7 @@ lib/<component>/
471471

472472
- **Constructor signature**: `def __init__(self, i2c, ..., address=DEFAULT_ADDR)` — first parameter is always `i2c` (not `bus`), address uses keyword argument with a default from `const.py`.
473473
- **Attributes**: `self.i2c` for the I2C bus, `self.address` for the device address (not `self.bus`, `self.addr`).
474-
- **I2C helpers**: use private snake_case methods `_read_reg()`, `_write_reg()` for register access. Legacy names (`setReg`, `getReg`, `i2cReadBytes`, etc.) are acceptable in existing drivers but new drivers must use the standard naming.
474+
- **I2C helpers**: use private snake_case methods `_read_reg()`, `_write_reg()` for register access.
475475

476476
### Linting
477477

0 commit comments

Comments
 (0)