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. Neverpip, neverpip install, never a hand-made virtual environment. - A package's
pyproject.tomldeclares constraints (httpx>=0.27); the workspace lockfile pins. - Development dependencies go in
[dependency-groups], not in[project.optional-dependencies]. requires-pythonis 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 keepsmainin__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;
Anydoes 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, neverexcept Exception: pass. - Logging through
logging.getLogger(__name__)at module level. Noprintin a library. asynconly in adapters and entrypoints. Domain and application code is synchronous.- Pathlib over
os.path;subprocess.runwith 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, thenpathlib.Pathat every use, so every name shows where it comes from. from a.b import conly whencis a module, for a long package path. Nofrom 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, nott:ct.Iterable,ct.Callable,ct.Mapping. - A package's
__init__.pymay re-export its public names (from orders._order import Order); that is the one place names are imported.
Tests
- pytest, in
tests/next tosrc/, 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
.pyistubs only for third-party packages that ship no types, undertypings/at the package root.- Notebooks are exploration. They are never imported, and their outputs are stripped before commit.
Checks
- Checked by the
ruff-formatandruffhooks against the rootruff.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 afromimport names a module. - The root
ruff.tomlis the only ruff configuration. A[tool.ruff]table in a package'spyproject.tomlsilently 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}-basedpyrighthook: basedpyright inallmode, configured once in the rootpyproject.toml. It reports everyAnythat reaches a name, an unannotated parameter, an override without@t.overrideand 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.lockat the root pins. - A core library holds
domain/andapplication/undersrc/<ctx>/, with import-linter enforcing the direction;/repo:add-packagewrites the contract. - Domain and application never import a generated client, an adapter or a framework.
04 同仓库更多 Skills
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".
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.
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".
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.
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.
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.