Skip to content

Check that each src/leaf package's modules import each other without a cycle - #7230

Merged
max-sixty merged 1 commit into
mainfrom
deslop-please
Nov 26, 2026
Merged

max-sixty merged 1 commit into
mainfrom
deslop-please

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

import-linter's layers contract checks only the imports between src/leaf's eight packages, so the modules inside a package could import each other in a cycle, and six groups did. The cuts that ended them have landed (#7216, #7217, #7218, #7222, #7224). This adds import-linter's own acyclic_siblings contract over every package (ancestors = leaf.*). It recurses into subpackages such as served_state and render_gate, so a new cycle fails pre-commit as an upward import does, naming the import that closes it.

A planted deferred import from presence into delivery, and one from served_state.context into served_state.page, each fail the contract; the tree as it stands passes. The config's header now says how to fix a cycle, and that a deferred import counts like any other, so deferring one ends no cycle; src/AGENTS.md states the rule beside the layering one.

The maintainer asked for the cycles inside agents to be broken; this widens that to every package and keeps them broken. The two allowances the layers contract still lists are cut by #7223 and the PR after it.

Tests: lint-imports (both contracts), pre-commit, and the two planted cycles above.

This was written by Claude Code on behalf of max-sixty

…a cycle

import-linter's layers contract checks only the imports between `src/leaf`'s eight
packages, so the modules inside a package could import each other in a cycle, and six
groups did. The cuts that ended them have landed (#7216, #7217, #7218, #7222, #7224);
this adds import-linter's `acyclic_siblings` contract over every package
(`ancestors = leaf.*`), which recurses into subpackages, such as `served_state` and
`render_gate`, so a new cycle fails pre-commit as an upward import does.

A planted deferred import from `presence` into `delivery`, and one from
`served_state.context` into `served_state.page`, each fail the contract, naming the
import; the tree as it stands passes.

The config's header says how to fix a cycle, and that a deferred import counts like any
other, so deferring one ends no cycle. `src/AGENTS.md` states the rule beside the
layering one.
@max-sixty
max-sixty merged commit f085142 into main Nov 26, 2026
6 checks passed
@max-sixty
max-sixty deleted the deslop-please branch November 26, 2026 05:15
max-sixty added a commit that referenced this pull request Nov 26, 2026
…#7243)

Moves 71 imports from inside functions to the top of their modules, in
19 files, so those modules' tops list what they depend on. Each one
moved names a module that importing its own module already loads: for
every `leaf` module, a fresh `import` loads the same modules on this
branch as on main, so no process loads anything more. Many were placed
inside functions to dodge an import cycle, which no longer works, since
the `acyclic_siblings` contract (#7230) counts an import inside a
function as it counts one at the top.

`src/AGENTS.md` now says when an import belongs inside a function: where
loading it with its module would add start-up work to a process started
often, fail on a platform, or set off an effect.
`source/registry/schema.py`'s header now says when pywhatwgurl loads.

To weigh: the other 336 stay inside functions, each keeping a module out
of some process that loads its module. A first version also moved 52
that no hook or common agent command needed deferred; Codex's review
found six rarer processes that then loaded more, such as `page export
--runtime` and `page open`, so only the moves no process can notice went
in. `deepcopy` stays inside `state_definition`, since Python 3.15's
`dataclasses` no longer loads `copy`.

`test_forks` patched `active_enclosing` where it is defined, which
`forks` used to look up at each call; it now patches `forks`' copy.

Tests: `lint-imports`, each `leaf` module imported alone, the module
probe of 34 processes, and 548 model tests of the touched modules.

> _This was written by Claude Code on behalf of max-sixty_
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants