AGENT SKILL

python

Lyngon Python conventions. Invoke before writing or editing a Python file, stub or notebook.

License 许可
Apache-2.0
所属仓库
lyngon/devkit
最近更新
2026-11-14
Stars
★ 0
Forks
0

01 前言 Front Matter

name
python
paths
[ "**/*.py", "**/*.pyi", "**/*.ipynb" ]
description
Lyngon Python conventions. Invoke before writing or editing a Python file, stub or notebook.
user-invocable
false

03 SKILL.md 正文

Python conventions

Project

  • uv manages everything: uv add, uv run, uv sync. Never pip, never pip install, never a hand-made virtual environment.
  • A package's pyproject.toml declares constraints (httpx>=0.27); the workspace lockfile pins.
  • Development dependencies go in [dependency-groups], not in [project.optional-dependencies].
  • requires-python is set once, at the root, to the newest stable release the toolchain provides.
  • Packages use the src/ layout: src/<import_name>/. The import name is the distribution name with underscores.
  • An app exposes its entry point in [project.scripts] and keeps main in __main__.py; nothing else lives in an app.

Code

  • Type hints on every function signature and every module-level name. The code must pass a strict type checker; Any does not cross a package boundary.
  • Domain values are @dataclasses.dataclass(frozen=True, slots=True) or plain classes. pydantic and other validation libraries appear only in adapters and entrypoints, where data enters.
  • Exceptions are typed per domain and raised at the boundary where the rule is broken. Never a bare except, never except Exception: pass.
  • Logging through logging.getLogger(__name__) at module level. No print in a library.
  • async only in adapters and entrypoints. Domain and application code is synchronous.
  • Pathlib over os.path; subprocess.run with an argument list over shell strings.
  • A public module, class or function has a docstring that states its contract or its reason: what it guarantees, what it raises, why it exists. Never the name restated as a sentence.

Imports

  • Import modules, never names: import pathlib, then pathlib.Path at every use, so every name shows where it comes from.
  • from a.b import c only when c is a module, for a long package path. No from x import *.
  • Absolute imports only, also within a package.
  • Fixed aliases, and no others: import typing as t, import collections.abc as ct, import datetime as dt, and the conventional third-party aliases (numpy as np, pandas as pd, polars as pl).
  • Abstract collection types come from ct, not t: ct.Iterable, ct.Callable, ct.Mapping.
  • A package's __init__.py may re-export its public names (from orders._order import Order); that is the one place names are imported.

Tests

  • pytest, in tests/ next to src/, named after the behaviour: test_order_cannot_ship_twice.
  • Fixtures over setup methods; parametrize over copy-paste.
  • Tests import the package the way a consumer does.

Stubs and notebooks

  • .pyi stubs only for third-party packages that ship no types, under typings/ at the package root.
  • Notebooks are exploration. They are never imported, and their outputs are stripped before commit.

Checks

  • Checked by the ruff-format and ruff hooks against the root ruff.toml: every stable ruff rule, minus a short ignore list with a reason on each entry. It also enforces the import rules above, except that a from import names a module.
  • The root ruff.toml is the only ruff configuration. A [tool.ruff] table in a package's pyproject.toml silently replaces it.
  • Silence a single finding with # noqa: CODE # reason. Extend the ignore list only with a reason on the entry.
  • Type-checked by the {name}-basedpyright hook: basedpyright in all mode, configured once in the root pyproject.toml. It reports every Any that reaches a name, an unannotated parameter, an override without @t.override and an unused call result (assign it to _).
  • Silence a single type finding with # pyright: ignore[rule] # reason; a bare ignore is rejected.

With the Lyngon structure

  • One uv workspace at the repository root with explicit members; uv.lock at the root pins.
  • A core library holds domain/ and application/ under src/<ctx>/, with import-linter enforcing the direction; /repo:add-package writes the contract.
  • Domain and application never import a generated client, an adapter or a framework.

04 同仓库更多 Skills

lyngon
lyngon/devkit

unslop

Remove AI writing patterns from prose and give it a voice. Use whenever writing or editing non-code text (docs, READMEs, decision records, posts, commit messages, PR descriptions), before handing it over, and on request: "unslop", "humanize", "make this sound human", "clean up this writing", "edit for voice", "de-AI this text".

★ 0
lyngon
lyngon/devkit

technical

Layered technical-writing standard: Diátaxis structure, Google developer style sentences, STE instruction rules, Global English syntax. Use before writing or reviewing docs, RFCs, readmes, PR descriptions, or commit messages, every time, however small the document.

★ 0
lyngon
lyngon/devkit

simpler

Restate the last message in plain human language, with no jargon. Use when the reader did not follow the last message and says so: "bro", "say that simpler", "in plain words", "no jargon".

★ 0
lyngon
lyngon/devkit

init

Set up a fresh repository, or adopt an existing one, to Lyngon conventions. Interviews the owner relentlessly about purpose, failure modes, audiences, stack and constraints, then writes INTENT.md, .claude/CLAUDE.md, README.md, CONCEPTS.md, decision records, devenv, git hooks, CI and every package in the kind-first Lyngon layout. User-invoked only.

★ 0
lyngon
lyngon/devkit

add-package

Create a package in a Lyngon repository in the directory its kind decides (apps/, libs/, contracts/, tools/, infra/), with README.md, devenv.nix and the layer lint, and register it in its workspace and devenv. Use whenever a new app, service, CLI, library, adapter, contract, schema, tool, infra module or environment is needed, including when one feature needs several packages. Never create a package by hand.

★ 0
lyngon
lyngon/devkit

index

The index of Lyngon's principles, one line per principle saying when it applies and what it demands, each with a file under references/. Invoke before work that takes judgment, such as a design choice, a refactor, a bug fix, a test, a measurement, a script, a document or a question to the owner; then read the file of each principle that applies.

★ 0