Skip to content

feat: add SQBRPYTHON node unit rules for Python nodes under python/ - #1490

Merged
chio-labs-delivery[bot] merged 3 commits into
mainfrom
feat/sqbrpython-node-units-v2
Nov 15, 2026
Merged

chio-labs-delivery[bot] merged 3 commits into
mainfrom
feat/sqbrpython-node-units-v2

Conversation

@kvlonge

@kvlonge kvlonge commented Nov 15, 2026

Copy link
Copy Markdown
Contributor

Why

Python nodes under python/ have no enforced shape, so loaders, tasks and assets end up as flat functions mixed with helpers, and each project invents its own layout. SQLBuild can check a single convention, the node unit, the same way it checks SQL.

Changes

  • Adds SQBRPYTHON003–SQBRPYTHON012 (family units): a unit is a folder under a domain holding node.py (one @loader, @task, @asset or @factory that delegates to main()), main.py (one main()), optional checks.py and _helpers/. The rules check the layout, each module's shape, the node signature and description, factory loops over the unit's specs, import boundaries between units and domains, and that nodes are declared only in a unit.
  • sqlbuild-pysource gains a node_units reader; the rules live in python_rules/_helpers/units/, and the existing helpers move into python_rules/_helpers/engine/ unchanged.
  • Docs: "Writing nodes as units" in the Python rules page and the reference table.
  • Release note: projects that select SQBRPYTHON may get new layout findings; selecting SQBR alone never runs Python rules.

DuckShop: the python_rules edge case adds a conforming unit and violations for every new rule, with updated expected findings. The main DuckShop project reports 90 × SQBRPYTHON012, all flat @loader functions; migrating it to units is follow-up work.

Verification

  • cargo test -p sqlbuild-rules -p sqlbuild-pysource, clippy with -D warnings, fensu check.
  • A new scaling guard: 2,000 linked units (node, main and checks) plus 200 undescribed units must evaluate within 5 s, and a 4× larger project must take less than 6.5× as long. Locally the median was 1.9 s. In a 750 → 3,000 unit probe, time grew 4.4× with the new rules on and 3.6× with them off.
  • test_rules.py and the rule-engine unit tests, including the DuckShop edge case (440 passed).
  • make check-ci on the final head.

SQBRPYTHON003 to SQBRPYTHON012 check that each node lives in its own unit
folder under its domain: node.py declares one node or factory that only
returns main(...) with keyword arguments, main.py holds one main() with a
result annotation that fits the node, checks.py holds the unit's checks,
imports stay within the unit's boundaries, factories loop over the unit's
specs, nodes use description= instead of docstrings, and nodes declared
outside a unit's node.py are reported.

The rules are on by default within SQBRPYTHON, so projects that select
SQBRPYTHON may get new layout findings; selecting SQBR alone never runs
them.
… loops

Role folders and shallow node.py files no longer make units. Factory
loops record the name they read through calls and attributes, import-only
TYPE_CHECKING blocks count as imports and are boundary-checked, dotted
imports of other units' nodes may be named in depends_on, and an unused
import is no longer treated as depends_on-only. main bound to a module
no longer counts as delegating.

The unit project indexes files by path and parses them in parallel. A
scaling guard covers a chain of linked units with dense findings. The
Python rule helpers are grouped into engine/ and units/ buckets.
A factory loop now records every name its iterable loads, so loops over
enumerate(SPECS) or sorted(SPECS) read the spec instead of the builtin.
@kvlonge kvlonge added the full-verify Run the full Verify matrix on this pull request label Nov 15, 2026
@chio-labs-delivery
chio-labs-delivery Bot added this pull request to the merge queue Nov 15, 2026
Merged via the queue into main with commit b6e4517 Nov 15, 2026
49 of 74 checks passed
@chio-labs-delivery
chio-labs-delivery Bot deleted the feat/sqbrpython-node-units-v2 branch November 15, 2026 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

full-verify Run the full Verify matrix on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant