ccb-essentials is a small collection of thin, typed helpers around the Python standard library (argparse, filesystem, logging, signal, sqlite3, subprocess). Look for simple wrappers, explicit typing, and small utility classes rather than heavy frameworks.
ccb_essentials/— implementation modules (seefilesystem.py,sqlite3.py,subprocess.py,logger.py,argparse.py,signal.py).docs/— human-facing usage examples and API notes (each module has a.mdwith concrete examples).tests/— pytest test-suite to validate behavior.docs/dev.mdandbin/lint.sh— canonical development commands (uses uv).
- Install & sync:
uv sync --extra dev - Run tests:
uv run pytest(orpytestif you use the environment directly) - Lint:
uv run bin/lint.sh(seebin/lint.shfor exact linters used) - Build:
uv build
- Keep helpers small and explicit — functions typically wrap stdlib calls and return basic types (e.g.
Path,Optional[Path],str). Avoid introducing heavy abstractions. - Prefer
pathlib.Pathand explicit checks: many APIs acceptstr|Pathand returnPath(seereal_path,assert_real_dir,assert_real_file). - Typing: package exposes
py.typedso maintain type signatures and mypy-friendly code. - Doc-driven examples: usage examples in
docs/*.mdare the authoritative behavior examples — copy examples from there when writing tests or docs.
ccb_essentials/filesystem.py:real_path(..., mkdir=True)will create directories;assert_real_*functions raise standard file exceptions (FileNotFoundError,NotADirectoryError,OSError). Use these helpers to validate CLI inputs.ccb_essentials/sqlite3.py:Sqlite3wrapssqlite3.Connection. Migrations are plain callables of signature(conn, version) -> bool; the library expects migrations list length to equal final schema version. Settingapplication_idis used to prevent accidentally opening the wrong DB file.ccb_essentials/subprocess.py:subprocess_command()usesshell=Trueand returnsOptional[str](returnsNoneon non-zero exit). When calling from higher-level code, handleNoneexplicitly; to raise on stderr setraise_std_error=True.ccb_essentials/logger.py:StreamToLoggeris a file-like adapter to funnelprint()/stdout into logging — used in examples to replacesys.stdout/sys.stderr.ccb_essentials/signal.py:DelayedKeyboardInterruptis a context manager to postponeKeyboardInterruptsignals during a critical section.
- When adding or changing behavior, add or update tests under
tests/and mirror examples fromdocs/where appropriate. - Run
uv run pytestlocally. Tests are small and rely on the helpers' observable behavior rather than complex fixtures.
- Keep public function signatures stable; consumers may rely on return types (
Optional[Path]vs raising). If you must change exception behavior, update docs and tests. - Preserve simple, explicit error types (don't wrap simple OSErrors in custom exceptions unless justified).
- See
docs/filesystem.md,docs/sqlite3.md,docs/subprocess.md,docs/logger.md, anddocs/signal.mdfor canonical code snippets.