|
| 1 | +# Python Code Standards |
| 2 | + |
| 3 | +## Style |
| 4 | + |
| 5 | +- PEP 8 compliant with 127-char line length (configured in pyproject.toml) |
| 6 | +- Google-style docstrings for all public classes and functions |
| 7 | +- Type hints where appropriate |
| 8 | + |
| 9 | +## Formatting and Linting |
| 10 | + |
| 11 | +- **ruff:** Lint (`ruff check --fix --unsafe-fixes hed/ tests/`) |
| 12 | + - Rules enabled: E (pycodestyle errors), W (warnings), F (pyflakes), N (pep8-naming), B (bugbear), C4 (comprehensions) |
| 13 | + - Max McCabe complexity: 10 |
| 14 | + - Excludes: .git, .venv, __pycache__, build, dist, hed/\_version.py, spec_tests submodules |
| 15 | + - Per-file: F401 ignored in `__init__.py` (unused imports are re-exports) |
| 16 | +- **black:** Format (`black hed/ tests/`); 127-char line, targets py310-py314 |
| 17 | +- **codespell:** Spell checking; skips binary/data files, ignores domain-specific words (hed, parms, etc.) |
| 18 | + |
| 19 | +## Naming Conventions |
| 20 | + |
| 21 | +- Classes: PascalCase (e.g., `HedString`, `HedSchema`, `TabularInput`) |
| 22 | +- Functions/methods: snake_case |
| 23 | +- Constants: UPPER_SNAKE_CASE |
| 24 | +- Private members: leading underscore |
| 25 | +- Test methods: may use camelCase (legacy convention; N802 ignored by ruff) |
| 26 | + |
| 27 | +## Import Order (ruff isort) |
| 28 | + |
| 29 | +1. Standard library |
| 30 | +2. Third-party packages |
| 31 | +3. Local `hed` package (`known-first-party = ["hed"]`) |
| 32 | + |
| 33 | +## Dependencies |
| 34 | + |
| 35 | +- **Core:** click, click-option-group, pandas (\<3.0), numpy (>=2.0.2), openpyxl, defusedxml, inflect, semantic-version, portalocker |
| 36 | +- **Dev:** ruff (>=0.8.0), codespell, black[jupyter], mdformat, mdformat-myst |
| 37 | +- **Docs:** sphinx (\<10), furo, sphinx-copybutton, myst-parser, sphinx-autodoc-typehints, linkify-it-py |
| 38 | +- **Test:** coverage |
| 39 | +- **Examples:** jupyter, notebook, nbformat, nbconvert, ipykernel |
| 40 | +- **Target:** Python 3.10+ |
| 41 | + |
| 42 | +## Common Patterns |
| 43 | + |
| 44 | +- `defusedxml` for XML parsing (security; never use stdlib xml directly) |
| 45 | +- DataFrames for tabular data (pandas) |
| 46 | +- `portalocker` for file locking (schema cache at `~/.hedtools/`) |
| 47 | +- `semantic-version` for schema version comparison |
| 48 | +- `click` + `click-option-group` for CLI with grouped options |
| 49 | + |
| 50 | +## Quality Metrics (qlty.toml) |
| 51 | + |
| 52 | +- Max argument count: 4 |
| 53 | +- Max method complexity: 5 |
| 54 | +- Max method lines: 50 |
| 55 | +- Max file lines: 300 |
| 56 | +- Max method count per class: 20 |
| 57 | +- Max nested control flow: 4 |
| 58 | +- Max return statements: 4 |
| 59 | +- Similar/identical code detection enabled |
0 commit comments