mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2026-11-08 11:46:35 +00:00
Adds a SPOT-aware lint that walks the repo via the cached
project-tree iterator (no `git` subprocess) and fails on any tracked
non-test Python file longer than 500 lines. Files under `tests/` are
intentionally excluded — coverage breadth there reflects feature
matrix, not design weight. A per-file `# nocheck` (or `#nocheck`)
marker in the first 30 lines opts the file out; the marker is
intentionally visible so the cost of carrying long modules is not
silently buried.
Gitignore-aware filtering moves to its own SPOT
-----------------------------------------------
The fnmatch-based `.gitignore` parser/matcher previously lived inline
in `tests/lint/repository/test_test_files_location.py` (and in
near-duplicates across other tests). Pull it into
`utils.cache.gitignore` as a single source of truth:
* `load_gitignore_patterns(root)` — cached pattern loader.
* `is_path_gitignored(rel_path, patterns)` — pure matcher.
* `iter_non_ignored_files(...)` — convenience iterator in
`utils.cache.files` that composes the cached project walk with the
matcher.
`utils.cache._reset_cache_for_tests` now resets the gitignore module
too, so test fixtures that mutate the tree see consistent state.
Refactor / opt-out for existing offenders
-----------------------------------------
Three production files exceeded the cap; addressed each:
* `roles/sys-svc-compose-ca/files/compose_ca.py` — opted out via
`# nocheck: file-size`. The script is delivered to target hosts
via `ansible.builtin.copy` and runs with only the stdlib; splitting
would require also delivering a package, which the role does not
do.
* `tasks/utils/migrate_meta_layout.py` — converted to a package
(`tasks/utils/migrate_meta_layout/`) with focused submodules:
- `__main__` — entrypoint + run-orchestration.
- `yaml_io` — load/dump/empty-dir/deep-merge helpers.
- `credentials` — schema-vs-config collision detection +
runtime-to-schema conversion.
- `role_builder` — per-role meta file emission.
- `indices` — networks + ports + relays index builders.
Run via `python3 -m tasks.utils.migrate_meta_layout`. Largest
submodule is `role_builder.py` at 250 lines.
* `cli/fix/move_unnecessary_dependencies/__main__.py` — split
alongside two new sibling modules in the same package:
- `analysis` — provider/consumer static analysis.
- `apply` — meta rewrite + guarded include-block prepending.
- `yaml_io` — ruamel round-trip helpers + role-tree discovery.
Largest submodule is `analysis.py` at 174 lines.
`make test` green (162 tests, 1 skipped); the new lint passes.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
44 lines
1.7 KiB
Python
44 lines
1.7 KiB
Python
"""In-process caches for runtime data (applications, users, domains).
|
|
|
|
Domain modules:
|
|
|
|
- ``utils.cache.base`` — cross-cutting helpers (constants,
|
|
deep-merge, signatures, render machinery).
|
|
- ``utils.cache.applications`` — variants + ``get_merged_applications``
|
|
(ansible-free at import time, runner-host friendly).
|
|
- ``utils.cache.users`` — ``get_user_defaults``, ``get_merged_users``.
|
|
- ``utils.cache.domains`` — ``get_merged_domains``.
|
|
- ``utils.cache.yaml`` — process-wide ``load_yaml`` /
|
|
``load_yaml_any`` parser cache shared by everything that reads YAML
|
|
off-disk.
|
|
- ``utils.cache.files`` — process-wide project-tree walk +
|
|
file-content cache (``read_text``, ``iter_project_files``,
|
|
``iter_non_ignored_files``).
|
|
- ``utils.cache.gitignore`` — cached ``.gitignore`` pattern loader
|
|
+ path matcher used by lint/integration tests that need a
|
|
"files git would track" view without spawning git.
|
|
|
|
Use the domain module directly. The package-level
|
|
``_reset_cache_for_tests`` clears every domain's caches plus the shared
|
|
fingerprint memo in one call — preferred over hand-rolling N
|
|
``_reset()`` calls per test fixture.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
def _reset_cache_for_tests() -> None:
|
|
"""Orchestrate per-domain cache resets plus the shared fingerprint
|
|
memo. Test fixtures rely on a single entry point so they can stay
|
|
agnostic of how the cache is partitioned across modules."""
|
|
from . import applications, base, domains, files, gitignore, users
|
|
from . import yaml as _yaml_cache
|
|
|
|
applications._reset()
|
|
users._reset()
|
|
domains._reset()
|
|
base._reset()
|
|
_yaml_cache._reset()
|
|
files._reset()
|
|
gitignore._reset()
|