Repository navigation
feat: add SQBRPYTHON node unit rules for Python nodes under python/ - #1490
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
SQBRPYTHON003–SQBRPYTHON012(familyunits): a unit is a folder under a domain holdingnode.py(one@loader,@task,@assetor@factorythat delegates tomain()),main.py(onemain()), optionalchecks.pyand_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-pysourcegains anode_unitsreader; the rules live inpython_rules/_helpers/units/, and the existing helpers move intopython_rules/_helpers/engine/unchanged.SQBRPYTHONmay get new layout findings; selectingSQBRalone never runs Python rules.DuckShop: the
python_rulesedge case adds a conforming unit and violations for every new rule, with updated expected findings. The main DuckShop project reports 90 ×SQBRPYTHON012, all flat@loaderfunctions; migrating it to units is follow-up work.Verification
cargo test -p sqlbuild-rules -p sqlbuild-pysource, clippy with-D warnings,fensu check.test_rules.pyand the rule-engine unit tests, including the DuckShop edge case (440 passed).make check-cion the final head.