Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .devcontainer/python/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
{
"name": "ESPHome-Config (Python)",
"image": "mcr.microsoft.com/devcontainers/python:1-3.14-bookworm",

"features": {
"ghcr.io/devcontainers/features/common-utils:2": {},
"ghcr.io/devcontainers/features/github-cli:1": {}
},

"mounts": [
{
"source": "${localEnv:HOME}${localEnv:USERPROFILE}/.ssh/id_ed25519.pub",
Comment thread
ptr727 marked this conversation as resolved.
Resolved
"target": "/home/vscode/.ssh/id_ed25519.pub",
"type": "bind",
"readonly": true
},
{
"source": "${localEnv:HOME}${localEnv:USERPROFILE}/.config/git/allowed_signers",
"target": "/home/vscode/.config/git/allowed_signers",
"type": "bind",
"readonly": true
},
{
"source": "${localEnv:HOME}${localEnv:USERPROFILE}/.config/gh",
"target": "/home/vscode/.config/gh",
"type": "bind",
"readonly": false
}
],
Comment thread
ptr727 marked this conversation as resolved.
Resolved

"remoteUser": "vscode",

// The bind-mount on macOS hosts surfaces /home/vscode/.ssh as root-owned.
// Chown it back so writes from inside the container land cleanly.
// Those include the known_hosts updates gh and git make.
// Idempotent on Linux and WSL2.
"onCreateCommand": "sudo install -d -m 700 -o vscode -g vscode /home/vscode/.ssh",

// Install pinned uv and pre-warm the project environment.
"postCreateCommand": ".devcontainer/python/post-create.sh",

"customizations": {
"vscode": {
// Python tooling for the uv workspace, beside the ESPHome container one level up.
"extensions": [
"arahata.linter-actionlint",
"charliermarsh.ruff",
"davidanson.vscode-markdownlint",
"editorconfig.editorconfig",
"github.vscode-github-actions",
"gruntfuggly.todo-tree",
"ms-azuretools.vscode-docker",
"ms-python.python",
"streetsidesoftware.code-spell-checker",
"timonwong.shellcheck",
"yzhang.markdown-all-in-one"
]
}
}
}
47 changes: 47 additions & 0 deletions .devcontainer/python/post-create.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash
set -Eeuo pipefail

script_dir=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd)
repository_dir=$(cd -- "$script_dir/../.." && pwd)

# Install uv (Astral) for the Python project.
# It is idempotent, since re-running overwrites in place.
# The installer drops the binary in $HOME/.local/bin.
# It also updates user shell init to add it to PATH for new shells.
# We add it to the current PATH explicitly so the rest of this script can invoke `uv`.
#
# The uv version is pinned via the version-prefixed install URL.
# That URL is https://astral.sh/uv/<version>/install.sh.
# A broken or compromised upstream `latest` script therefore cannot silently change what runs.
# Bump UV_VERSION when you've reviewed release notes.
#
# We re-install when uv is missing OR when the installed version doesn't match the pin.
# The latter handles a contributor or an earlier pin leaving another uv version on PATH.
# The pin is what's reproducible and what the lockfile is generated against.
UV_VERSION="0.11.8"
installed_uv_version=""
if command -v uv >/dev/null 2>&1; then
installed_uv_version="$(uv --version | awk '{print $2}')"
fi
if [[ "$installed_uv_version" != "$UV_VERSION" ]]; then
# Download the pinned installer to a temp file first instead of piping `curl ... | sh`.
# This produces a logged sha256 of exactly the bytes we ran.
# A compromised installer therefore leaves a forensic trail.
# It also lets a future change pin a known-good checksum (set EXPECTED_SHA below).
installer=$(mktemp -t uv-install.XXXXXX.sh)
Comment thread
ptr727 marked this conversation as resolved.
Resolved
trap 'rm -f "$installer"' EXIT
curl -LsSf "https://astral.sh/uv/${UV_VERSION}/install.sh" -o "$installer"
actual_sha=$(sha256sum "$installer" | awk '{print $1}')
echo "uv installer (v${UV_VERSION}) sha256: ${actual_sha}" >&2
# EXPECTED_SHA="<paste-from-trusted-source>" # set to enforce
if [[ -n "${EXPECTED_SHA:-}" && "${actual_sha}" != "${EXPECTED_SHA}" ]]; then
echo "uv installer sha256 mismatch - refusing to run" >&2
exit 1
fi
sh "$installer"
export PATH="$HOME/.local/bin:$PATH"
fi

if [[ -f "$repository_dir/pyproject.toml" && -f "$repository_dir/uv.lock" ]]; then
uv sync --frozen --project "$repository_dir"
fi
14 changes: 1 addition & 13 deletions .github/actions/validate/action.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Validate ESPHome sources action
description: Run repository-specific spelling, Python, and C++ checks.
description: Run repository-specific spelling and C++ checks.

runs:
using: composite
Expand All @@ -11,20 +11,8 @@ runs:
files: |
DEVICES.md
easystart/README.md
easystart/python/README.md
incremental_files_only: false

- name: Setup uv step
uses: astral-sh/setup-uv@20cfd1bf945f4377ade1205e4dbc17946fc9a30d # v10.0.1

- name: Lint Python step
shell: bash
working-directory: easystart/python
run: |
set -Eeuo pipefail
uvx ruff@0.15.22 check .
uvx ruff@0.15.22 format --check .

- name: Lint C++ step
shell: bash
run: |
Expand Down
20 changes: 20 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ updates:
patterns:
- "*"

- package-ecosystem: "uv"
target-branch: "main"
directory: "/"
schedule:
interval: "daily"
groups:
pypi-deps:
patterns:
- "*"

# Develop branch.
- package-ecosystem: "devcontainers"
target-branch: "develop"
Expand All @@ -45,3 +55,13 @@ updates:
actions-deps:
patterns:
- "*"

- package-ecosystem: "uv"
target-branch: "develop"
directory: "/"
schedule:
interval: "daily"
groups:
pypi-deps:
patterns:
- "*"
2 changes: 2 additions & 0 deletions .github/workflows/publish-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ jobs:
uses: ptr727/ProjectTemplate/.github/workflows/validate-task.yml@d28ed043207e78d55bf1f0d803ba9dc2ac2b3fee # 2.0.657
permissions:
contents: read
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

publish:
name: Publish project release job
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:
uses: ptr727/ProjectTemplate/.github/workflows/validate-task.yml@d28ed043207e78d55bf1f0d803ba9dc2ac2b3fee # 2.0.657
permissions:
contents: read
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

# Change gate for the compile test, plus the template matrix definition.
# An esp-idf build costs minutes, so gate on what the test covers.
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ __pycache__/
*.pyc
.ruff_cache/
.mypy_cache/
.venv/
.coverage
coverage.xml

# ESPHome
logs/
Expand Down
52 changes: 39 additions & 13 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,18 +64,17 @@
}
},
// Python group.
// The easystart BLE monitor is a lint-only subtree with no packaged project, no lockfile, and no tests.
// It runs through uvx with no install step rather than `uv run`.
// The ruff version is pinned to match the CI workflow.
// The root pyproject.toml is a uv workspace holding every Python project in the repo, so each task runs once at the workspace root.
// Sequencing uses dependsOn rather than shell chaining.
{
"label": "Ruff Format",
"type": "process",
"command": "uvx",
"command": "uv",
"args": [
"ruff@0.15.22",
"run",
"ruff",
"format"
],
"options": { "cwd": "${workspaceFolder}/easystart/python" },
"problemMatcher": [],
"presentation": {
"showReuseMessage": false,
Expand All @@ -85,35 +84,34 @@
{
"label": "Ruff Check",
"type": "process",
"command": "uvx",
"command": "uv",
"args": [
"ruff@0.15.22",
"run",
"ruff",
"check"
],
"options": { "cwd": "${workspaceFolder}/easystart/python" },
"problemMatcher": [],
"presentation": {
"showReuseMessage": false,
"clear": false
}
},
{
// Editor parity only - CI gates on ruff, pyright runs here and in Pylance.
"label": "Python Types",
"type": "process",
"command": "uvx",
"command": "uv",
"args": [
"run",
"pyright"
],
"options": { "cwd": "${workspaceFolder}/easystart/python" },
"problemMatcher": [],
"presentation": {
"showReuseMessage": false,
"clear": false
}
},
{
// The clean-compile aggregator - formats in place, then lints, then type-checks, in order.
// The clean-compile aggregator formats in place, then lints, then type-checks, in order.
"label": "Python Format",
"dependsOrder": "sequence",
"dependsOn": [
Expand All @@ -123,6 +121,34 @@
],
"problemMatcher": []
},
{
"label": "Python Test",
"type": "process",
"command": "uv",
"args": [
"run",
"pytest"
],
"group": { "kind": "test", "isDefault": true },
"problemMatcher": [],
"presentation": {
"showReuseMessage": false,
"clear": false
}
},
{
"label": "uv Sync",
"type": "process",
"command": "uv",
"args": [
"sync"
],
"problemMatcher": [],
"presentation": {
"showReuseMessage": false,
"clear": false
}
},
// Lint group - run on demand via Docker (--pull=always forces each to re-pull the current :latest).
// Mirrors the CI lint gate.
// Broad live spell-checking is the cspell extension's job.
Expand Down
12 changes: 8 additions & 4 deletions CODESTYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,14 @@ This is packaged as the `python-codestyle` Skill at `.agents/skills/python-codes

### This Repository's Python

One Python subtree, [`easystart/python`][easystart-python], the standalone EasyStart BLE monitor. It takes the `lint-only` profile: a single script that declares its own runtime dependency through PEP 723 inline metadata and runs with `uv run easystart_monitor.py`, and a `pyproject.toml` carrying **only** tool config, no `[project]`, no `[build-system]`, and no `uv.lock`, because that metadata would misrepresent it as a shippable package.
All Python in this repository lives in one **uv workspace** rooted at the repository root, and every project in it takes the `build` profile. The root [`pyproject.toml`][root-pyproject] is a virtual workspace root with no `[project]` of its own: it lists the member projects, holds the shared `dev` dependency group, and carries the one `[tool.ruff]`, `[tool.pyright]`, and `[tool.pytest.ini_options]` configuration every member uses. The single root `uv.lock` pins every member's dependencies and the dev tools together. The one member today is [`easystart/python`][easystart-python], the EasyStart BLE monitor, a `src`-layout project with its own `[project]`, `[build-system]`, and an `easystart-monitor` console script.

- **ruff is the only CI gate**, run as `uvx ruff@0.15.22 check .` and `uvx ruff@0.15.22 format --check .` from the subtree, carrying the pin the next bullet explains so a command copied from here is the command CI runs. A `[tool.pyright]` block in **standard** mode keeps Pylance quiet in the editor. There is no mypy gate: the subtree is one script importing an untyped BLE library, so a second type checker adds nothing over Pylance.
- **The ruff version is pinned**, `uvx ruff@0.15.22`, in the CI step and in the VS Code tasks alike so the two cannot drift. This is a deliberate divergence from the fleet default of running `uvx <tool>@latest` unpinned. The fleet reasons that a manual pin Dependabot does not track goes stale silently, and this repository reasons that an unpinned linter turns an upstream release into a surprise CI failure on an unrelated change. The divergence is raised with the fleet rather than settled locally, so expect this bullet to move once that is decided.
- **There is no pytest suite**, so the coverage expectation is N/A. `.py` files follow this repository's LF line-ending default, per [GOVERNANCE.md "Line Endings"][line-endings].
- **uv is the only supported toolchain.** Run everything from the repository root with `uv run`, which syncs the workspace first: `uv run ruff check`, `uv run ruff format --check`, `uv run pyright`, `uv run pytest`, and a member's own script such as `uv run easystart-monitor`. There is no pip or `requirements.txt` path.
- **The hub validator is the CI gate.** A root `pyproject.toml`, `uv.lock`, and `tests/` are what its tree detection keys on, so it runs `uv sync --all-groups --frozen`, ruff, pyright, and pytest with coverage uploaded to Codecov, with no repository-specific CI step. The Codecov statuses are informational, per `codecov.yml`.
- **pyright is strict over each member's `src`** and standard over the tests. Its `include` lists only member source and `tests`, so the ESPHome codegen under `easystart/components`, which imports `esphome` rather than a workspace dependency, stays out of the type check while ruff still lints and formats it.
- **Tests live under the root `tests/`**, one folder per member package, such as `tests/easystart_monitor/`, and `--cov=<package>` in `addopts` selects what each member contributes to coverage.
- **Adding a project** is a new member directory with its own `pyproject.toml` and `src/<package>/`, a line in the root `members` and `src` lists, its `src` in the pyright `include` and `strict` lists, its package in the pytest `--cov` selectors, a `tests/<package>/` folder, and a `uv lock`.
- `.py` files follow this repository's LF line-ending default, per [GOVERNANCE.md "Line Endings"][line-endings].

## Shell

Expand Down Expand Up @@ -98,3 +101,4 @@ Semantic and static analysis is deliberately out of scope. The downstream ESPHom
[operations-documenting-a-device]: ./OPERATIONS.md#documenting-a-device
[readme]: ./README.md
[root]: ./.editorconfig
[root-pyproject]: ./pyproject.toml
13 changes: 7 additions & 6 deletions OPERATIONS.md
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,16 @@ The CeilSense carries an LD2412 24 GHz radar, and every control it offers is exp
- **The vendor package exposes no gate thresholds at all**, so tuning one costs a firmware change. The template carries the vendor entity set, and a device that needs thresholds declares them in its own config.
- **Declare all fourteen gates or none.** `LD2412Component::set_gate_threshold()` writes the whole array and dereferences every entry, and its early-out tests `.empty()` on a `std::array`, which is never true. A partial declaration leaves null entries and crashes the device on the first threshold write.

## Linting the Python Utility
## Python Workspace

The EasyStart BLE monitor under `easystart/python` is a lint-only subtree: ruff gates CI, and pyright is editor parity via Pylance. There is no packaged project, no lockfile, and no test suite, so the script runs and lints through `uvx` with no install step. Use the ruff version pinned in [`test-pull-request.yml`][test-workflow] so a local run matches CI:
All Python is one uv workspace rooted at the repository root, laid out in `CODESTYLE.md` "This Repository's Python". The hub validator runs the same commands in CI. Run them from the repository root:

```shell
cd easystart/python
uvx ruff@0.15.22 check .
uvx ruff@0.15.22 format --check .
uvx pyright .
uv sync
uv run ruff check
uv run ruff format --check
uv run pyright
uv run pytest
```

The generic linters (editorconfig-checker, actionlint, markdownlint, and cspell) are the fleet set, invoked as documented in `GOVERNANCE.md` "Running the Linters Locally (Known-Working Invocations)", a hub-only section read in a hub checkout rather than carried here. ESPHome config and compile validation is separate, covered above.
Expand Down
13 changes: 13 additions & 0 deletions codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Codecov configuration.
# Codecov's coverage statuses are advisory: they report and trend coverage, never gating a PR.
# - informational: true makes project and patch statuses advisory (always pass), so a coverage delta never blocks a PR.
# - Distinct from the upload step's fail_ci_if_error: false, which only guards upload errors.
# - A repo may override this to enforce a coverage threshold.
coverage:
status:
project:
default:
informational: true
patch:
default:
informational: true
2 changes: 2 additions & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"accessibilities",
"Adafruit",
"adcn",
"addopts",
"Allman",
"aoycocr",
"apikey",
Expand Down Expand Up @@ -230,6 +231,7 @@
"SVGA",
"Tasmota",
"tempp",
"testpaths",
"ThinkNode",
"timonwong",
"Triaging",
Expand Down
Loading
Loading