This guide is for coding agents working in this repository. Follow these commands and conventions unless the user explicitly asks otherwise.
- Applies to the whole repo.
- Main language: Python.
- Main function: deploy local code to MicroPython devices via
mpremote.
- Cursor rules dir:
.cursor/rules/-> not present. - Cursor single file rules:
.cursorrules-> not present. - Copilot instructions:
.github/copilot-instructions.md-> not present. - If any of these files are added, treat them as higher-priority local instructions.
- Python:
>=3.10(3.11 recommended). - Packaging/config:
pyproject.toml. - CLI entrypoint:
mpy_cli.cli:main. - Console script:
mpy-cli. - Tests:
pytest, undertests/. - CI release workflow:
.github/workflows/release.yml.
Run from repo root:
python3 -m venv .venv
source .venv/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install -e ".[dev]"No dedicated formatter/linter is configured in pyproject.toml.
Testing is the primary quality gate.
# editable install for development
python3 -m pip install -e ".[dev]"
# non-editable install
python3 -m pip install .python3 -m pytest -qpython3 -m pytest -q tests/test_cli.pypython3 -m pytest -q tests/test_cli.py::test_init_command_creates_config_and_ignorepython3 -m pytest -q -k configpython3 -m pytest -q tests/test_docs_and_ci.py
python3 -m pytest -q tests/test_mpremote_backend.py
python3 -m pytest -q tests/test_executor.pypython3 -m compileall mpy_climpy-cli init
mpy-cli config
mpy-cli plan --mode incremental --port /dev/ttyACM0
mpy-cli deploy --mode incremental --port /dev/ttyACM0Non-interactive examples:
mpy-cli plan --mode full --no-interactive --port /dev/ttyACM0
mpy-cli deploy --mode full --no-interactive --yes --port /dev/ttyACM0- Order imports: stdlib -> third-party -> local.
- Prefer explicit imports; avoid wildcard imports.
- Use 4-space indentation.
- Keep long calls split across lines for readability.
- Keep diffs stable (use trailing commas in multiline literals/calls when helpful).
- Add type hints for public functions/methods.
- Type dataclass fields explicitly.
- Use
Literalfor constrained string values (full,incremental). - Use
Protocolfor pluggable interfaces (e.g., logger/scanner contracts).
snake_case: functions, vars, modules.PascalCase: classes/dataclasses.UPPER_CASE: constants.- Errors should end with
Error.
- Follow existing convention: Chinese Doxygen-style docstrings.
- Public APIs should include
@brief; add@param/@returnwhen useful. - Add comments only for non-obvious logic.
- Raise domain-specific exceptions in lower layers:
ConfigErrorGitDiffErrorCommandExecutionError
- At CLI boundaries, convert expected failures to readable messages + exit codes.
- Avoid exposing raw traceback to end users for expected errors.
- Use
setup_logging()frommpy_cli/logging.py. - Keep dual output: console + rotating file logs.
- Preserve deploy progress logs (per operation / per file).
- Prefer
pathlib.Path. - Keep runtime artifacts under project runtime dir (default
.mpy-cli/). - Do not write runtime artifacts to system directories.
- Keep parser behavior, README examples, and tests synchronized.
- If CLI args change, update all three:
mpy_cli/cli.pyREADME.mdparameter sectiontests/test_docs_and_ci.py
full: wipe then upload all allowed files.incremental: compute operations from git changes.- Nested uploads must ensure remote parent directories exist first.
- Test files:
tests/test_*.py. - Test names:
test_<behavior>. - Keep tests behavior-focused and deterministic.
- Add regression tests for every bug fix.
- Keep command examples in
README.mdcurrent. - Keep parameter lists complete when CLI flags change.
- Keep
docs/developer-guide.mdaligned with architecture changes.
- Run targeted tests for changed modules.
- Run full suite:
python3 -m pytest -q. - Verify README command examples still match real CLI behavior.
- Ensure local artifacts are not accidentally staged.