@tduyng/pi-devos 0.0.0-stage → 0.13.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1398 -0
- package/LICENSE +201 -0
- package/README.md +213 -2
- package/package.json +45 -4
- package/plugins/devos/agents/reader.md +27 -0
- package/plugins/devos/agents/verifier.md +181 -0
- package/plugins/devos/pi/extension/devos.ts +615 -0
- package/plugins/devos/scripts/check-evidence-router.sh +134 -0
- package/plugins/devos/scripts/evidence-router.py +252 -0
- package/plugins/devos/scripts/gates/check-dod-core.sh +283 -0
- package/plugins/devos/scripts/gates/check-dod.sh +38 -0
- package/plugins/devos/scripts/gates/check-handoff.sh +215 -0
- package/plugins/devos/scripts/gates/check-implementation-boundary.sh +99 -0
- package/plugins/devos/scripts/gates/check-port-source.sh +134 -0
- package/plugins/devos/scripts/gates/check-report-locations.sh +148 -0
- package/plugins/devos/scripts/gates/check-scenario-coverage.sh +102 -0
- package/plugins/devos/scripts/gates/gate-check.mjs +204 -0
- package/plugins/devos/scripts/gates/phase-gate.sh +208 -0
- package/plugins/devos/scripts/gates/plan-template-check.py +147 -0
- package/plugins/devos/scripts/gates/run-gate.sh +148 -0
- package/plugins/devos/scripts/gates/spec-template-check.py +165 -0
- package/plugins/devos/scripts/gates/test-gates.sh +4306 -0
- package/plugins/devos/scripts/gates/test-integrity-rubric.sh +152 -0
- package/plugins/devos/scripts/gates/test-phase-gate.sh +116 -0
- package/plugins/devos/skills/absorb/SKILL.md +75 -0
- package/plugins/devos/skills/absorb/references/distill.md +67 -0
- package/plugins/devos/skills/absorb/scripts/check-refs.sh +108 -0
- package/plugins/devos/skills/absorb/scripts/knowledge.py +258 -0
- package/plugins/devos/skills/build/SKILL.md +71 -0
- package/plugins/devos/skills/build/references/advanced-routing.md +19 -0
- package/plugins/devos/skills/build/references/defect.md +17 -0
- package/plugins/devos/skills/build/references/exposure.md +28 -0
- package/plugins/devos/skills/build/references/hard.md +39 -0
- package/plugins/devos/skills/build/references/refactor.md +66 -0
- package/plugins/devos/skills/build/references/routes.md +56 -0
- package/plugins/devos/skills/build/references/scale.md +84 -0
- package/plugins/devos/skills/build/references/spike.md +19 -0
- package/plugins/devos/skills/build/scripts/construct-census.py +204 -0
- package/plugins/devos/skills/build/scripts/dep-order.py +297 -0
- package/plugins/devos/skills/build/scripts/ledger.sh +228 -0
- package/plugins/devos/skills/build/scripts/route.sh +5 -0
- package/plugins/devos/skills/build/scripts/secret-scan.sh +121 -0
- package/plugins/devos/skills/build/scripts/toolchain-preflight.py +302 -0
- package/plugins/devos/skills/design-taste/SKILL.md +55 -0
- package/plugins/devos/skills/design-taste/references/tells.md +85 -0
- package/plugins/devos/skills/design-taste/scripts/slop-scan.py +305 -0
- package/plugins/devos/skills/docs/SKILL.md +22 -0
- package/plugins/devos/skills/docs/references/backfill.md +54 -0
- package/plugins/devos/skills/docs/references/init.md +43 -0
- package/plugins/devos/skills/docs/references/status.md +71 -0
- package/plugins/devos/skills/docs/references/update.md +80 -0
- package/plugins/devos/skills/explain/SKILL.md +45 -0
- package/plugins/devos/skills/explain/references/quiz.md +21 -0
- package/plugins/devos/skills/frame/SKILL.md +71 -0
- package/plugins/devos/skills/frame/references/boundaries.md +53 -0
- package/plugins/devos/skills/frame/references/decompose.md +96 -0
- package/plugins/devos/skills/frame/references/impact.md +43 -0
- package/plugins/devos/skills/frame/references/interrogate.md +68 -0
- package/plugins/devos/skills/frame/scripts/survey.sh +44 -0
- package/plugins/devos/skills/implement/SKILL.md +36 -0
- package/plugins/devos/skills/implement/references/conditional-plan.md +17 -0
- package/plugins/devos/skills/implement/references/debug-loop.md +7 -0
- package/plugins/devos/skills/implement/references/dod.md +32 -0
- package/plugins/devos/skills/implement/references/implement.md +52 -0
- package/plugins/devos/skills/implement/references/manual-gates.md +16 -0
- package/plugins/devos/skills/implement/references/plan.md +160 -0
- package/plugins/devos/skills/implement/references/resume.md +9 -0
- package/plugins/devos/skills/implement/references/scale.md +86 -0
- package/plugins/devos/skills/implement/references/verify-close.md +61 -0
- package/plugins/devos/skills/implement/references/visual-verification.md +7 -0
- package/plugins/devos/skills/implement/scripts/check-converge.sh +147 -0
- package/plugins/devos/skills/implement/scripts/equivalence-check.sh +140 -0
- package/plugins/devos/skills/implement/scripts/manifest-queue.sh +185 -0
- package/plugins/devos/skills/implement/scripts/ops-log.sh +58 -0
- package/plugins/devos/skills/implement/scripts/pilot-consistency.py +173 -0
- package/plugins/devos/skills/implement/scripts/validate-spec.sh +268 -0
- package/plugins/devos/skills/init/SKILL.md +100 -0
- package/plugins/devos/skills/init/references/archetype-sections.md +15 -0
- package/plugins/devos/skills/init/references/context.md +42 -0
- package/plugins/devos/skills/init/references/conventions-template.md +153 -0
- package/plugins/devos/skills/init/references/reverse-engineer.md +3 -0
- package/plugins/devos/skills/init/references/rule-format.md +58 -0
- package/plugins/devos/skills/init/references/shape-model.md +29 -0
- package/plugins/devos/skills/init/scripts/detect-archetype.py +461 -0
- package/plugins/devos/skills/init/scripts/render-rule.py +114 -0
- package/plugins/devos/skills/init/scripts/reverse-engineer.sh +162 -0
- package/plugins/devos/skills/learn/SKILL.md +29 -0
- package/plugins/devos/skills/learn/references/destinations.md +43 -0
- package/plugins/devos/skills/learn/references/scoring.md +26 -0
- package/plugins/devos/skills/product/SKILL.md +40 -0
- package/plugins/devos/skills/product/references/planner.md +54 -0
- package/plugins/devos/skills/review/SKILL.md +77 -0
- package/plugins/devos/skills/review/references/gaps.md +26 -0
- package/plugins/devos/skills/spec/SKILL.md +58 -0
- package/plugins/devos/skills/spec/references/prototype.md +21 -0
- package/plugins/devos/skills/spec/references/question-craft.md +47 -0
- package/plugins/devos/skills/spec/references/roadmap-link.md +5 -0
- package/plugins/devos/skills/spec/references/write-spec.md +143 -0
- package/plugins/devos/skills/spec/scripts/clarify.sh +173 -0
- package/plugins/devos/skills/status/SKILL.md +67 -0
- package/plugins/devos/skills/status/references/cost.md +38 -0
- package/plugins/devos/skills/status/scripts/artifact-budgets.sh +88 -0
- package/plugins/devos/skills/status/scripts/check-requires.py +556 -0
- package/plugins/devos/skills/status/scripts/context-cost.sh +89 -0
- package/plugins/devos/skills/status/scripts/convention-usage.sh +184 -0
- package/plugins/devos/skills/status/scripts/findings-summary.sh +112 -0
- package/plugins/devos/skills/status/scripts/quality-correlation.sh +282 -0
- package/plugins/devos/skills/status/scripts/sizing-calibration.sh +71 -0
- package/plugins/devos/skills/status/scripts/spec-diff.sh +137 -0
- package/plugins/devos/skills/surgical-diff/SKILL.md +23 -0
- package/plugins/devos/skills/test-integrity/SKILL.md +26 -0
- package/plugins/devos/skills/verification-evidence/SKILL.md +17 -0
- package/plugins/devos/workflows/common/backlog-file-structure.md +44 -0
- package/plugins/devos/workflows/common/category-file-structure.md +41 -0
- package/plugins/devos/workflows/common/feature-line-format.md +10 -0
- package/plugins/devos/workflows/common/roadmap-file-structure.md +51 -0
- package/plugins/devos/workflows/common/suggest-categories.md +76 -0
- package/plugins/devos/workflows/common/suggest-milestones.md +92 -0
- package/plugins/devos/workflows/doc/doc-health.md +137 -0
- package/plugins/devos/workflows/doc/doc-writer.md +44 -0
- package/plugins/devos/workflows/doc/init-documentation.md +196 -0
- package/plugins/devos/workflows/doc/retro-documentation.md +304 -0
- package/plugins/devos/workflows/doc/templates/library.md +58 -0
- package/plugins/devos/workflows/doc/templates/service.md +61 -0
- package/plugins/devos/workflows/doc/update-documentation.md +194 -0
- package/plugins/devos/workflows/doc/write-documentation.md +137 -0
- package/plugins/devos/workflows/product/create-product-mission.md +45 -0
- package/plugins/devos/workflows/product/create-product-roadmap.md +106 -0
- package/plugins/devos/workflows/product/create-product-tech-stack.md +19 -0
- package/plugins/devos/workflows/product/gather-product-info.md +25 -0
- package/plugins/devos/workflows/product/resume-detection.md +70 -0
- package/plugins/devos/workflows/product/reverse-backlog.md +118 -0
- package/plugins/devos/workflows/product/reverse-domain-model.md +86 -0
- package/plugins/devos/workflows/product/reverse-product-plan.md +81 -0
- package/plugins/devos/workflows/product/reverse-tech-stack.md +73 -0
- package/plugins/devos/workflows/product/scan-deep.md +113 -0
- package/plugins/devos/workflows/product/scan-git.md +122 -0
- package/plugins/devos/workflows/product/scan-light.md +154 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# A behavior-preserving change across many units: the verdict, the units, the decisions
|
|
2
|
+
|
|
3
|
+
Load this from the C route when the change touches six or more files, moves code to a target stack the project does not run today, or the user asked for the work to be tracked. A rename, a split, or a version bump inside one project stays on the cheap path: that is the route's own three steps, and it needs none of this.
|
|
4
|
+
|
|
5
|
+
The work half of this profile lives in the implement skill's `references/scale.md`, and the manifest written here is what tells implement to load it. The threshold is a file count because a count can be checked: a model that has to judge "a handful" decides differently every time, and the units it skips are the units nothing tracks.
|
|
6
|
+
|
|
7
|
+
## Step 1: the verdict, before any unit
|
|
8
|
+
|
|
9
|
+
Two questions, both answerable without writing code.
|
|
10
|
+
|
|
11
|
+
**What is the judgment?** Name the command that decides the change is correct (`npm test`, `cargo test`, a parity script) and run it once on the current tree. That run is the baseline: its exit status and its test count. A move to a new stack has no such command yet, and that gap comes first. A change with no judgment is a change with no proof, and a port whose target toolchain is not installed stalls on its first unit.
|
|
12
|
+
|
|
13
|
+
A port to a stack the project does not run today declares that stack in the spec folder, one `key<TAB>value` per row in `target-stack.tsv`:
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
runtime node
|
|
17
|
+
package_manager npm
|
|
18
|
+
build npm run build
|
|
19
|
+
check npm test
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The preflight asks the machine rather than the model, before the first unit:
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
python3 ${CLAUDE_PLUGIN_ROOT}/skills/build/scripts/toolchain-preflight.py --spec SPEC_DIR --root PROJECT_ROOT
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
It looks the tools up on PATH, looks the build command up in the project's own manifest, and runs the check. Three answers come back, and they are kept apart because the fixes differ: a missing toolchain is an install, a build command the project does not declare is a wrong command, and a red check is a red baseline that has to be fixed before the port means anything. A port that learns any of this on its first unit has already spent the unit.
|
|
29
|
+
|
|
30
|
+
**Is this worth doing?** A verdict of "leave it alone" is a valid outcome and the cheapest one. Write it down with the single fact that would change it, then stop. The cost of a port nobody wanted is the whole port.
|
|
31
|
+
|
|
32
|
+
State the cost as a multiplication, never as a total: units of work times the judgment cost per unit, with the multiplier named. "About 40 units at 2 minutes of judgment each" is a plan. "About 20 hours" is a guess that erodes trust when it lands wrong. The judgment cost per unit is not a guess either: the judge prints how long it took, so measure it on the first unit and use that number.
|
|
33
|
+
|
|
34
|
+
**What does the tree still carry?** A legacy tree keeps running while the port lands, so whatever it still carries is still exposed. `references/exposure.md` has the scan, the reading that goes with it, and the ranking. Remove it. Rotate it. Name the rotations the port cannot make, because that one is a task for the human and not a footnote.
|
|
35
|
+
|
|
36
|
+
## Step 2: the units
|
|
37
|
+
|
|
38
|
+
A unit is one file's worth of change, small enough that one worker finishes it and lands it. The manifest lists them, one row per unit, `source<TAB>target`, and the script writes it:
|
|
39
|
+
|
|
40
|
+
```
|
|
41
|
+
bash ${CLAUDE_PLUGIN_ROOT}/skills/build/scripts/dep-order.py --tree legacy --out units.txt
|
|
42
|
+
bash ${CLAUDE_PLUGIN_ROOT}/skills/implement/scripts/manifest-queue.sh init \
|
|
43
|
+
--from-root legacy --to modernized --list units.txt --out SPEC_DIR/manifest.tsv
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
The order is the dependency order: a unit that imports another unit is ported after it, so every unit lands against ported code. The script reads the import statements and prints that order. Reading it by hand costs one file read per unit, and that is the whole tree in the context window. The model writes no order of its own here.
|
|
47
|
+
|
|
48
|
+
A cycle is a finding, not a stop. `dep-order.py` reports cycles at two levels, and the file level is the one that lies. A tree can have a clean file graph and a cyclic package graph, where no order builds even though no single file is in a cycle. The units in a cycle come last in the list, because a cycle is one unit, not two. Port such a cycle as one unit, or break it at one edge and put that edge in the rulebook.
|
|
49
|
+
|
|
50
|
+
The manifest lands in the spec folder, and that is the switch: implement reads a spec folder holding `manifest.tsv` and loads its own half of this profile.
|
|
51
|
+
|
|
52
|
+
## Step 3: the decisions, ranked
|
|
53
|
+
|
|
54
|
+
The rulebook is the one artifact every unit reads, and its contents come from the source tree rather than from taste. The census reads the tree and says which constructs the code uses, how often, and where the first one sits:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
bash ${CLAUDE_PLUGIN_ROOT}/skills/build/scripts/construct-census.py --tree legacy
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
A phase counts only its own units: `construct-census.py --manifest SPEC/phase-1.tsv` reads the manifest's source column instead of a tree.
|
|
61
|
+
|
|
62
|
+
Every construct with a count is a question the port has to answer. The count is the reason one of them matters: a construct the code uses forty times decides the port's shape, and one it uses once is a detail. Write one rule per construct that changes the shape of the code, in the project's own rule files (`devos/standards/rules/<NN>-<category>/<slug>.md`). Leave the rest to the worker.
|
|
63
|
+
|
|
64
|
+
A port's rule is scoped by glob to the target files it governs, like any other rule, so a worker finds it by the file it is writing and not by the construct it happens to be porting. The port's rules and the project's rules live in the same place, because they are the same kind of thing: a rule says what the code does here.
|
|
65
|
+
|
|
66
|
+
Keep the rulebook short. The capsule embeds the rules the change touches, and a port touches every rule it has, and the capsule's budget is 300 lines. A rulebook that grows is a capsule that overflows, and an overflow means the spec splits. The constructs the census counted as rare are the ones that do not need a rule.
|
|
67
|
+
|
|
68
|
+
A port whose rules do not fit one capsule is a port to do in phases. Each phase is its own spec, with its own units taken from the manifest in order and its own share of the rules, so a phase's units build on the ones before it. The phases follow the dependency order the script gave, so nothing in a phase waits for a later one. The slice is a command rather than a hand-written manifest:
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
bash ${CLAUDE_PLUGIN_ROOT}/skills/implement/scripts/manifest-queue.sh slice \
|
|
72
|
+
--manifest SPEC_DIR/manifest.tsv --count 40 --out SPEC_DIR/phase-1.tsv
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The manifest is in dependency order, so a slice is closed under the dependencies: every unit a unit needs is in the slice or in an earlier phase.
|
|
76
|
+
|
|
77
|
+
The census counts sites and knows nothing about meaning, so the rule is yours. Forty bare excepts is a count. Whether a bare except here means a recoverable network error is a question only the code answers.
|
|
78
|
+
|
|
79
|
+
For an upgrade, the target version's own release notes say what it changed. Read them from the installed package rather than from memory, and put each change in the rules next to the construct it touches. A version that changed a construct the code does not use costs nothing, and the census says which those are.
|
|
80
|
+
|
|
81
|
+
## What this does not decide
|
|
82
|
+
|
|
83
|
+
- The target architecture. The `spec` route owns that, and the C route's Invariant only says what must not move.
|
|
84
|
+
- Whether the move is a translation or a redesign. A translation keeps the architecture and the file boundaries, and the rules are a lookup table. A redesign moves both, its rules are a design document, and its unit is a module rather than a file. A redesign is a `spec` route job, and the spec route's plan says which.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# R route: spike (research, no implementation)
|
|
2
|
+
|
|
3
|
+
1. Agree the question and a timebox with the user (default: one session).
|
|
4
|
+
2. Investigate: code reading and small throwaway experiments, clearly marked and never committed.
|
|
5
|
+
3. Write `devos/specs/YYYY-MM-DD-spike-[name]/findings.md`: the question, options tried, evidence, **recommendation**, **gaps**, and what a follow-up implementation spec would look like.
|
|
6
|
+
4. **A claim you could not ground goes under `## Gaps`, never among the evidence.** Each grounded claim names where it came from (`file:line`, a command's output, a URL), never recall, because an ungrounded finding is the failure this discipline exists to prevent. Name what stayed unanswered and what would answer it: a benchmark nobody ran, a version you could not install, a source behind a login, a behavior only production traffic shows. A spike's recommendation is the one output in DevOS that nothing downstream gates, so the part you could not verify is both the part the reader most needs and the part that would disappear silently. `None` is a legitimate answer and costs one line.
|
|
7
|
+
5. No production code changes on this route. If the user picks an option, the follow-up runs as a normal S/M/L.
|
|
8
|
+
6. Close on the footer, naming the command that starts that follow-up and the folder it reads:
|
|
9
|
+
|
|
10
|
+
```
|
|
11
|
+
🎯 Next: /devos:build "[the recommended option, in a sentence]" (findings: devos/specs/[spike-name]/findings.md)
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
R is the one route that ends the run instead of chaining, so this line is the only thing between a written recommendation and a user who has to reconstruct the request from the folder name. On Pi it is `/skill:build` (Step 3 of that skill).
|
|
15
|
+
|
|
16
|
+
## A question about what the tree carries
|
|
17
|
+
|
|
18
|
+
A question about exposure rather than about a decision is the same investigation with a scan as the evidence: `references/exposure.md` has the scan, the reading that goes with it, and the ranking. The scan's report is already a finding list, so the reading is what turns it into a ranking. A rotation of a credential is a task for the human, so name it under `## Gaps` when the work at hand cannot do it.
|
|
19
|
+
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""construct-census: the decisions a port has to make, ranked by how often the code needs them.
|
|
3
|
+
|
|
4
|
+
A port's rulebook is the one artifact every unit reads, and it is the one
|
|
5
|
+
artifact nobody wants to write from nothing. The question it answers is always
|
|
6
|
+
the same shape: what does this source construct become in the target? Which
|
|
7
|
+
means the rulebook's contents are decided by the source tree, not by taste.
|
|
8
|
+
|
|
9
|
+
So the tree is read, and what comes back is a list of constructs with counts,
|
|
10
|
+
one row per construct, most frequent first. The count is the reason a
|
|
11
|
+
construct is a rule: a construct the code uses forty times decides the port's
|
|
12
|
+
shape, and one it uses once is a detail. Reading that list out of the tree by
|
|
13
|
+
hand costs one file read per construct, and the file reads put the whole tree
|
|
14
|
+
in the context window to produce a table this prints in one pass.
|
|
15
|
+
|
|
16
|
+
Python is read with its own parser, so an import is an import and not a
|
|
17
|
+
pattern that looks like one. JavaScript and TypeScript are read by pattern,
|
|
18
|
+
which is the best a text file offers.
|
|
19
|
+
|
|
20
|
+
What it cannot see: what a construct means in this codebase. The census says
|
|
21
|
+
that the code uses forty bare excepts, not that a bare except here means a
|
|
22
|
+
recoverable network error. The rule is the model's; the census is the list to
|
|
23
|
+
write it from.
|
|
24
|
+
|
|
25
|
+
Deterministic, no model calls, no dependency beyond the standard library.
|
|
26
|
+
"""
|
|
27
|
+
from __future__ import annotations
|
|
28
|
+
|
|
29
|
+
import argparse
|
|
30
|
+
import ast
|
|
31
|
+
import re
|
|
32
|
+
import sys
|
|
33
|
+
from collections import Counter
|
|
34
|
+
from pathlib import Path
|
|
35
|
+
|
|
36
|
+
PRUNE = {
|
|
37
|
+
"node_modules", ".git", "vendor", "target", "dist", "build", ".venv",
|
|
38
|
+
"venv", "__pycache__", "out", "coverage", ".next", ".tox", "site-packages",
|
|
39
|
+
}
|
|
40
|
+
PY_SUFFIX = ".py"
|
|
41
|
+
JS_SUFFIXES = (".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx", ".mts", ".cts")
|
|
42
|
+
|
|
43
|
+
JS_PATTERNS = (
|
|
44
|
+
("imports", re.compile(r"""\bfrom\s*['"]([^'"]+)['"]|\bimport\s*['"]([^'"]+)['"]|\brequire\s*\(\s*['"]([^'"]+)['"]"""), "target"),
|
|
45
|
+
("var declarations", re.compile(r"\bvar\s"), "count"),
|
|
46
|
+
("let declarations", re.compile(r"\blet\s"), "count"),
|
|
47
|
+
("const declarations", re.compile(r"\bconst\s"), "count"),
|
|
48
|
+
("loose equality", re.compile(r"[^=!<>]==[^=]"), "count"),
|
|
49
|
+
("try blocks", re.compile(r"\btry\s*\{"), "count"),
|
|
50
|
+
("catch blocks", re.compile(r"\bcatch\s*\("), "count"),
|
|
51
|
+
("throw statements", re.compile(r"\bthrow\s"), "count"),
|
|
52
|
+
("classes", re.compile(r"\bclass\s+\w"), "count"),
|
|
53
|
+
("inheritance", re.compile(r"\bclass\s+\w+\s+extends\b"), "count"),
|
|
54
|
+
("async functions", re.compile(r"\basync\s+function\b|\basync\s*\("), "count"),
|
|
55
|
+
("await", re.compile(r"\bawait\s"), "count"),
|
|
56
|
+
("promise callbacks", re.compile(r"\.then\s*\("), "count"),
|
|
57
|
+
("new Promise", re.compile(r"\bnew\s+Promise\s*\("), "count"),
|
|
58
|
+
("eval calls", re.compile(r"\beval\s*\("), "count"),
|
|
59
|
+
("innerHTML writes", re.compile(r"\.innerHTML\s*="), "count"),
|
|
60
|
+
("web storage", re.compile(r"\b(?:local|session)Storage\b"), "count"),
|
|
61
|
+
("document.write", re.compile(r"\bdocument\.write\s*\("), "count"),
|
|
62
|
+
("string timers", re.compile(r"\bsetTimeout\s*\(\s*['\"]"), "count"),
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def walk(root: Path) -> list[Path]:
|
|
67
|
+
out: list[Path] = []
|
|
68
|
+
for path in sorted(root.rglob("*")):
|
|
69
|
+
if not path.is_file():
|
|
70
|
+
continue
|
|
71
|
+
if any(part in PRUNE for part in path.relative_to(root).parts):
|
|
72
|
+
continue
|
|
73
|
+
out.append(path)
|
|
74
|
+
return out
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def census_python(path: Path, rel: str, counts: Counter, sites: dict) -> None:
|
|
78
|
+
try:
|
|
79
|
+
tree = ast.parse(path.read_text(encoding="utf-8", errors="replace"))
|
|
80
|
+
except SyntaxError:
|
|
81
|
+
return
|
|
82
|
+
|
|
83
|
+
def note(label: str, line: int) -> None:
|
|
84
|
+
counts[label] += 1
|
|
85
|
+
sites.setdefault(label, f"{rel}:{line}")
|
|
86
|
+
|
|
87
|
+
for node in ast.walk(tree):
|
|
88
|
+
if isinstance(node, ast.Import):
|
|
89
|
+
for alias in node.names:
|
|
90
|
+
counts["imports"] += 1
|
|
91
|
+
sites.setdefault("imports", f"{rel}:{node.lineno}")
|
|
92
|
+
elif isinstance(node, ast.ImportFrom):
|
|
93
|
+
counts["imports"] += 1
|
|
94
|
+
sites.setdefault("imports", f"{rel}:{node.lineno}")
|
|
95
|
+
elif isinstance(node, ast.ClassDef):
|
|
96
|
+
note("classes", node.lineno)
|
|
97
|
+
if node.bases:
|
|
98
|
+
note("inheritance", node.lineno)
|
|
99
|
+
if node.decorator_list:
|
|
100
|
+
note("decorators", node.lineno)
|
|
101
|
+
elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
|
102
|
+
note("async functions" if isinstance(node, ast.AsyncFunctionDef) else "functions", node.lineno)
|
|
103
|
+
if node.decorator_list:
|
|
104
|
+
note("decorators", node.lineno)
|
|
105
|
+
if node.returns or any(a.annotation for a in node.args.args):
|
|
106
|
+
note("type annotations", node.lineno)
|
|
107
|
+
for default in node.args.defaults + [d for d in node.args.kw_defaults if d]:
|
|
108
|
+
if isinstance(default, (ast.List, ast.Dict, ast.Set)):
|
|
109
|
+
note("mutable default arguments", node.lineno)
|
|
110
|
+
elif isinstance(node, ast.ExceptHandler):
|
|
111
|
+
note("bare excepts" if node.type is None else "except handlers", node.lineno)
|
|
112
|
+
elif isinstance(node, ast.Global):
|
|
113
|
+
note("global statements", node.lineno)
|
|
114
|
+
elif isinstance(node, (ast.ListComp, ast.DictComp, ast.SetComp, ast.GeneratorExp)):
|
|
115
|
+
note("comprehensions", node.lineno)
|
|
116
|
+
elif isinstance(node, ast.Assert):
|
|
117
|
+
note("asserts", node.lineno)
|
|
118
|
+
elif isinstance(node, ast.Call):
|
|
119
|
+
func = node.func
|
|
120
|
+
name = getattr(func, "id", None) or getattr(func, "attr", None)
|
|
121
|
+
if name in ("eval", "exec"):
|
|
122
|
+
note("eval/exec calls", node.lineno)
|
|
123
|
+
elif name == "open":
|
|
124
|
+
note("open calls", node.lineno)
|
|
125
|
+
elif name == "isinstance":
|
|
126
|
+
note("isinstance checks", node.lineno)
|
|
127
|
+
elif isinstance(node, ast.JoinedStr):
|
|
128
|
+
note("f-strings", node.lineno)
|
|
129
|
+
elif isinstance(node, ast.Compare):
|
|
130
|
+
for op, comparator in zip(node.ops, node.comparators):
|
|
131
|
+
if isinstance(op, (ast.Eq, ast.NotEq)) and isinstance(comparator, ast.Constant) and comparator.value is None:
|
|
132
|
+
note("None comparisons", node.lineno)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def census_javascript(path: Path, rel: str, text: str, counts: Counter, sites: dict) -> None:
|
|
136
|
+
lines = text.splitlines()
|
|
137
|
+
for label, pattern, mode in JS_PATTERNS:
|
|
138
|
+
found = 0
|
|
139
|
+
for number, line in enumerate(lines, 1):
|
|
140
|
+
hits = pattern.findall(line)
|
|
141
|
+
if not hits:
|
|
142
|
+
continue
|
|
143
|
+
found += len(hits) if mode == "count" else 1
|
|
144
|
+
sites.setdefault(label, f"{rel}:{number}")
|
|
145
|
+
if found:
|
|
146
|
+
counts[label] += found
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def main() -> int:
|
|
150
|
+
ap = argparse.ArgumentParser(description="the decisions a port has to make, ranked by how often the code needs them")
|
|
151
|
+
ap.add_argument("--tree", help="the tree to read")
|
|
152
|
+
ap.add_argument("--manifest", help="a manifest whose source column names the files to read, relative to the working directory")
|
|
153
|
+
args = ap.parse_args()
|
|
154
|
+
|
|
155
|
+
files: list[Path] = []
|
|
156
|
+
root: Path | None = None
|
|
157
|
+
if args.manifest:
|
|
158
|
+
manifest = Path(args.manifest)
|
|
159
|
+
if not manifest.is_file():
|
|
160
|
+
print(f"FAIL construct-census: no manifest at {args.manifest}", file=sys.stderr)
|
|
161
|
+
print(" fix: point --manifest at the manifest of the phase you are counting", file=sys.stderr)
|
|
162
|
+
return 2
|
|
163
|
+
for line in manifest.read_text(encoding="utf-8", errors="replace").splitlines()[1:]:
|
|
164
|
+
if not line.strip():
|
|
165
|
+
continue
|
|
166
|
+
source = line.split("\t")[0].strip()
|
|
167
|
+
if source:
|
|
168
|
+
files.append(Path(source))
|
|
169
|
+
elif args.tree:
|
|
170
|
+
root = Path(args.tree).resolve()
|
|
171
|
+
if not root.is_dir():
|
|
172
|
+
print(f"FAIL construct-census: no tree at {args.tree}", file=sys.stderr)
|
|
173
|
+
print(" fix: point --tree at the directory that holds the code", file=sys.stderr)
|
|
174
|
+
return 2
|
|
175
|
+
files = walk(root)
|
|
176
|
+
else:
|
|
177
|
+
print("FAIL construct-census: no tree and no manifest given", file=sys.stderr)
|
|
178
|
+
print(" fix: pass --tree DIR, or --manifest FILE for one phase of a port", file=sys.stderr)
|
|
179
|
+
return 2
|
|
180
|
+
|
|
181
|
+
counts: Counter = Counter()
|
|
182
|
+
sites: dict[str, str] = {}
|
|
183
|
+
for path in files:
|
|
184
|
+
rel = path.relative_to(root).as_posix() if root else path.as_posix()
|
|
185
|
+
if not path.is_file():
|
|
186
|
+
continue
|
|
187
|
+
if rel.endswith(PY_SUFFIX):
|
|
188
|
+
census_python(path, rel, counts, sites)
|
|
189
|
+
if rel.endswith(JS_SUFFIXES):
|
|
190
|
+
census_javascript(path, rel, path.read_text(encoding="utf-8", errors="replace"), counts, sites)
|
|
191
|
+
|
|
192
|
+
print("| Construct | Count | First site |")
|
|
193
|
+
print("|---|---|---|")
|
|
194
|
+
for label, count in sorted(counts.items(), key=lambda kv: (-kv[1], kv[0])):
|
|
195
|
+
print(f"| {label} | {count} | {sites.get(label, '')} |")
|
|
196
|
+
total = sum(counts.values())
|
|
197
|
+
print()
|
|
198
|
+
print(f"construct-census: {len(counts)} constructs, {total} sites in {len(files)} files")
|
|
199
|
+
print("Each construct with a count above zero is a decision the port has to make. Write one rule for it.")
|
|
200
|
+
return 0
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
if __name__ == "__main__":
|
|
204
|
+
sys.exit(main())
|
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""dep-order: the unit order for a port, and the cycles that break it.
|
|
3
|
+
|
|
4
|
+
A port has hundreds of units and one shared decision set. Two things decide
|
|
5
|
+
whether the work is a list or a graph: the order the units land in, and the
|
|
6
|
+
places where no order exists.
|
|
7
|
+
|
|
8
|
+
The order is the dependency order. A unit that imports another unit is ported
|
|
9
|
+
after it, so every unit is ported against ported code. Reading that order out
|
|
10
|
+
of the tree by hand costs one file read per unit, which is the whole tree in
|
|
11
|
+
the context window; this script reads the import statements and prints the
|
|
12
|
+
order, so the tree never enters the context.
|
|
13
|
+
|
|
14
|
+
The cycles are the part a file-level graph misses. A file graph can be clean
|
|
15
|
+
while the package graph is not: package A's file imports package B's file and
|
|
16
|
+
B's file imports A's, and no single file is in a cycle, yet there is no order
|
|
17
|
+
that builds. A port that trusts the file order hits that as a wall of compile
|
|
18
|
+
errors at the end. Both graphs are reported here, and the units in a cycle
|
|
19
|
+
are printed last, because a cycle is one unit, not two.
|
|
20
|
+
|
|
21
|
+
Deterministic, no model calls, no dependency beyond the standard library.
|
|
22
|
+
"""
|
|
23
|
+
from __future__ import annotations
|
|
24
|
+
|
|
25
|
+
import argparse
|
|
26
|
+
import ast
|
|
27
|
+
import re
|
|
28
|
+
import sys
|
|
29
|
+
from pathlib import Path
|
|
30
|
+
|
|
31
|
+
PRUNE = {
|
|
32
|
+
"node_modules", ".git", "vendor", "target", "dist", "build", ".venv",
|
|
33
|
+
"venv", "__pycache__", "out", "coverage", ".next", ".tox",
|
|
34
|
+
}
|
|
35
|
+
PY_SUFFIX = ".py"
|
|
36
|
+
JS_SUFFIXES = (".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx", ".mts", ".cts")
|
|
37
|
+
JS_INDEX = ("index.js", "index.jsx", "index.ts", "index.tsx", "index.mjs")
|
|
38
|
+
|
|
39
|
+
JS_FROM = re.compile(r"""\bfrom\s*['"]([^'"]+)['"]""")
|
|
40
|
+
JS_BARE = re.compile(r"""\bimport\s*['"]([^'"]+)['"]""")
|
|
41
|
+
JS_REQUIRE = re.compile(r"""\brequire\s*\(\s*['"]([^'"]+)['"]\s*\)""")
|
|
42
|
+
JS_DYNAMIC = re.compile(r"""\bimport\s*\(\s*['"]([^'"]+)['"]\s*\)""")
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def walk(root: Path) -> list[Path]:
|
|
46
|
+
out: list[Path] = []
|
|
47
|
+
for path in sorted(root.rglob("*")):
|
|
48
|
+
if not path.is_file():
|
|
49
|
+
continue
|
|
50
|
+
if any(part in PRUNE for part in path.relative_to(root).parts):
|
|
51
|
+
continue
|
|
52
|
+
out.append(path)
|
|
53
|
+
return out
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def py_edges(path: Path, root: Path) -> list[tuple[str, int]]:
|
|
57
|
+
try:
|
|
58
|
+
tree = ast.parse(path.read_text(encoding="utf-8", errors="replace"))
|
|
59
|
+
except SyntaxError:
|
|
60
|
+
return []
|
|
61
|
+
found: list[tuple[str, int]] = []
|
|
62
|
+
for node in ast.walk(tree):
|
|
63
|
+
if isinstance(node, ast.Import):
|
|
64
|
+
for alias in node.names:
|
|
65
|
+
found.append((alias.name, 0))
|
|
66
|
+
elif isinstance(node, ast.ImportFrom):
|
|
67
|
+
found.append((node.module or "", node.level))
|
|
68
|
+
return found
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def resolve_py(spec: str, level: int, source: Path, root: Path, by_path: set[str]) -> str | None:
|
|
72
|
+
if level > 0:
|
|
73
|
+
base = source.parent
|
|
74
|
+
for _ in range(level - 1):
|
|
75
|
+
base = base.parent
|
|
76
|
+
target = base
|
|
77
|
+
else:
|
|
78
|
+
target = root
|
|
79
|
+
if spec:
|
|
80
|
+
target = target / Path(*spec.split("."))
|
|
81
|
+
rel = target.relative_to(root) if target.is_relative_to(root) else None
|
|
82
|
+
if rel is None:
|
|
83
|
+
return None
|
|
84
|
+
for candidate in (rel / "__init__.py", rel.with_suffix(PY_SUFFIX)):
|
|
85
|
+
if candidate.as_posix() in by_path:
|
|
86
|
+
return candidate.as_posix()
|
|
87
|
+
return None
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def js_specs(text: str) -> list[str]:
|
|
91
|
+
specs: list[str] = []
|
|
92
|
+
for pattern in (JS_FROM, JS_BARE, JS_REQUIRE, JS_DYNAMIC):
|
|
93
|
+
specs.extend(pattern.findall(text))
|
|
94
|
+
return specs
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def resolve_js(spec: str, source: Path, root: Path, by_stem: dict[str, str]) -> str | None:
|
|
98
|
+
if not spec.startswith("."):
|
|
99
|
+
return None
|
|
100
|
+
base = (source.parent / spec).resolve()
|
|
101
|
+
try:
|
|
102
|
+
base = base.relative_to(root.resolve())
|
|
103
|
+
except ValueError:
|
|
104
|
+
return None
|
|
105
|
+
text = base.as_posix()
|
|
106
|
+
if text in by_stem:
|
|
107
|
+
return text
|
|
108
|
+
for suffix in JS_SUFFIXES:
|
|
109
|
+
if text + suffix in by_stem:
|
|
110
|
+
return text + suffix
|
|
111
|
+
for index in JS_INDEX:
|
|
112
|
+
if f"{text}/{index}" in by_stem:
|
|
113
|
+
return f"{text}/{index}"
|
|
114
|
+
return None
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
def package_of(rel: str) -> str:
|
|
118
|
+
parts = rel.split("/")
|
|
119
|
+
return "/".join(parts[:-1]) if len(parts) > 1 else "."
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def find_cycles(edges: dict[str, set[str]]) -> list[list[str]]:
|
|
123
|
+
"""Every cycle, each as the path that closes it.
|
|
124
|
+
|
|
125
|
+
Iterative, because a tree with a long import chain is a tree with a deep
|
|
126
|
+
path, and the recursive version of this walked off the interpreter's stack
|
|
127
|
+
at a thousand files.
|
|
128
|
+
"""
|
|
129
|
+
cycles: list[list[str]] = []
|
|
130
|
+
seen: set[frozenset[str]] = set()
|
|
131
|
+
color: dict[str, int] = {}
|
|
132
|
+
|
|
133
|
+
for root in sorted(edges):
|
|
134
|
+
if color.get(root, 0):
|
|
135
|
+
continue
|
|
136
|
+
color[root] = 1
|
|
137
|
+
path = [root]
|
|
138
|
+
stack = [(root, iter(sorted(edges.get(root, ()))))]
|
|
139
|
+
while stack:
|
|
140
|
+
node, children = stack[-1]
|
|
141
|
+
descended = False
|
|
142
|
+
for nxt in children:
|
|
143
|
+
state = color.get(nxt, 0)
|
|
144
|
+
if state == 0:
|
|
145
|
+
color[nxt] = 1
|
|
146
|
+
path.append(nxt)
|
|
147
|
+
stack.append((nxt, iter(sorted(edges.get(nxt, ())))))
|
|
148
|
+
descended = True
|
|
149
|
+
break
|
|
150
|
+
if state == 1:
|
|
151
|
+
cycle = path[path.index(nxt):] + [nxt]
|
|
152
|
+
key = frozenset(cycle)
|
|
153
|
+
if key not in seen:
|
|
154
|
+
seen.add(key)
|
|
155
|
+
cycles.append(cycle)
|
|
156
|
+
if not descended:
|
|
157
|
+
color[node] = 2
|
|
158
|
+
stack.pop()
|
|
159
|
+
path.pop()
|
|
160
|
+
return cycles
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def order(nodes: list[str], deps: dict[str, set[str]]) -> tuple[list[str], list[str]]:
|
|
164
|
+
"""Dependencies first, a round at a time. Nodes in a cycle cannot be ordered, so they go last."""
|
|
165
|
+
known = set(nodes)
|
|
166
|
+
indegree: dict[str, int] = {}
|
|
167
|
+
dependents: dict[str, list[str]] = {n: [] for n in nodes}
|
|
168
|
+
for node in nodes:
|
|
169
|
+
needed = {d for d in deps.get(node, ()) if d in known}
|
|
170
|
+
indegree[node] = len(needed)
|
|
171
|
+
for dep in sorted(needed):
|
|
172
|
+
dependents[dep].append(node)
|
|
173
|
+
out: list[str] = []
|
|
174
|
+
emitted: set[str] = set()
|
|
175
|
+
frontier = sorted(n for n in nodes if indegree[n] == 0)
|
|
176
|
+
while frontier:
|
|
177
|
+
following: list[str] = []
|
|
178
|
+
for node in frontier:
|
|
179
|
+
out.append(node)
|
|
180
|
+
emitted.add(node)
|
|
181
|
+
for dependent in dependents[node]:
|
|
182
|
+
indegree[dependent] -= 1
|
|
183
|
+
if indegree[dependent] == 0:
|
|
184
|
+
following.append(dependent)
|
|
185
|
+
frontier = sorted(following)
|
|
186
|
+
return out, sorted(known - emitted)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
def main() -> int:
|
|
190
|
+
ap = argparse.ArgumentParser(description="the unit order for a port, and the cycles that break it")
|
|
191
|
+
ap.add_argument("--tree", required=True, help="the tree to read")
|
|
192
|
+
ap.add_argument("--lang", default="auto", choices=("auto", "python", "javascript"))
|
|
193
|
+
ap.add_argument("--out", help="write the ordered unit list here")
|
|
194
|
+
ap.add_argument("--report", help="write the cycle report here")
|
|
195
|
+
args = ap.parse_args()
|
|
196
|
+
|
|
197
|
+
root = Path(args.tree).resolve()
|
|
198
|
+
if not root.is_dir():
|
|
199
|
+
print(f"FAIL dep-order: no tree at {args.tree}", file=sys.stderr)
|
|
200
|
+
print(" fix: point --tree at the directory that holds the code", file=sys.stderr)
|
|
201
|
+
return 2
|
|
202
|
+
|
|
203
|
+
files = walk(root)
|
|
204
|
+
rel_paths = {p.relative_to(root).as_posix() for p in files}
|
|
205
|
+
py_files = {r for r in rel_paths if r.endswith(PY_SUFFIX)}
|
|
206
|
+
js_files = {r for r in rel_paths if r.endswith(JS_SUFFIXES)}
|
|
207
|
+
by_path = set(rel_paths)
|
|
208
|
+
by_stem = rel_paths
|
|
209
|
+
|
|
210
|
+
deps: dict[str, set[str]] = {r: set() for r in rel_paths}
|
|
211
|
+
edge_count = 0
|
|
212
|
+
for path in files:
|
|
213
|
+
rel = path.relative_to(root).as_posix()
|
|
214
|
+
if args.lang in ("auto", "python") and rel in py_files:
|
|
215
|
+
for spec, level in py_edges(path, root):
|
|
216
|
+
target = resolve_py(spec, level, path, root, by_path)
|
|
217
|
+
if target:
|
|
218
|
+
deps[rel].add(target)
|
|
219
|
+
edge_count += 1
|
|
220
|
+
if args.lang in ("auto", "javascript") and rel in js_files:
|
|
221
|
+
text = path.read_text(encoding="utf-8", errors="replace")
|
|
222
|
+
for spec in js_specs(text):
|
|
223
|
+
target = resolve_js(spec, path, root, by_stem)
|
|
224
|
+
if target:
|
|
225
|
+
deps[rel].add(target)
|
|
226
|
+
edge_count += 1
|
|
227
|
+
|
|
228
|
+
units = sorted(py_files | js_files) if args.lang == "auto" else sorted(py_files if args.lang == "python" else js_files)
|
|
229
|
+
pkg_deps: dict[str, set[str]] = {}
|
|
230
|
+
for unit, targets in deps.items():
|
|
231
|
+
src_pkg = package_of(unit)
|
|
232
|
+
pkg_deps.setdefault(src_pkg, set())
|
|
233
|
+
for target in targets:
|
|
234
|
+
dst_pkg = package_of(target)
|
|
235
|
+
if dst_pkg != src_pkg:
|
|
236
|
+
pkg_deps[src_pkg].add(dst_pkg)
|
|
237
|
+
|
|
238
|
+
file_cycles = find_cycles(deps)
|
|
239
|
+
pkg_cycles = find_cycles(pkg_deps)
|
|
240
|
+
ordered, stuck = order(units, deps)
|
|
241
|
+
final = ordered + stuck
|
|
242
|
+
|
|
243
|
+
if args.out:
|
|
244
|
+
out = Path(args.out)
|
|
245
|
+
out.parent.mkdir(parents=True, exist_ok=True)
|
|
246
|
+
out.write_text("".join(f"{u}\n" for u in final), encoding="utf-8")
|
|
247
|
+
|
|
248
|
+
lines = [
|
|
249
|
+
f"dep-order: {len(units)} units, {edge_count} edges, "
|
|
250
|
+
f"{len(file_cycles)} file cycles, {len(pkg_cycles)} package cycles",
|
|
251
|
+
]
|
|
252
|
+
for cycle in file_cycles:
|
|
253
|
+
lines.append(" file cycle: " + " -> ".join(cycle))
|
|
254
|
+
for cycle in pkg_cycles:
|
|
255
|
+
lines.append(" package cycle: " + " -> ".join(cycle))
|
|
256
|
+
if stuck:
|
|
257
|
+
lines.append(f" {len(stuck)} units sit in a cycle and are printed last, because a cycle is one unit, not two")
|
|
258
|
+
print("\n".join(lines))
|
|
259
|
+
|
|
260
|
+
if args.report:
|
|
261
|
+
report = [
|
|
262
|
+
"# Dependency report",
|
|
263
|
+
"",
|
|
264
|
+
f"- units: {len(units)}",
|
|
265
|
+
f"- edges: {edge_count}",
|
|
266
|
+
f"- file cycles: {len(file_cycles)}",
|
|
267
|
+
f"- package cycles: {len(pkg_cycles)}",
|
|
268
|
+
"",
|
|
269
|
+
]
|
|
270
|
+
if pkg_cycles:
|
|
271
|
+
report.append("## Package cycles")
|
|
272
|
+
report.append("")
|
|
273
|
+
report.append("No file order exists across these packages. Port each cycle as one unit, or break it at one edge and record that edge in the rulebook.")
|
|
274
|
+
report.append("")
|
|
275
|
+
for cycle in pkg_cycles:
|
|
276
|
+
report.append("- " + " -> ".join(cycle))
|
|
277
|
+
report.append("")
|
|
278
|
+
if file_cycles:
|
|
279
|
+
report.append("## File cycles")
|
|
280
|
+
report.append("")
|
|
281
|
+
for cycle in file_cycles:
|
|
282
|
+
report.append("- " + " -> ".join(cycle))
|
|
283
|
+
report.append("")
|
|
284
|
+
Path(args.report).write_text("\n".join(report), encoding="utf-8")
|
|
285
|
+
|
|
286
|
+
if file_cycles or pkg_cycles:
|
|
287
|
+
print(
|
|
288
|
+
f"FAIL dep-order: {len(pkg_cycles)} package cycle(s) and {len(file_cycles)} file cycle(s) in {args.tree}",
|
|
289
|
+
file=sys.stderr,
|
|
290
|
+
)
|
|
291
|
+
print(" fix: port each cycle as one unit, or break it at one edge and put that edge in the rulebook", file=sys.stderr)
|
|
292
|
+
return 1
|
|
293
|
+
return 0
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
if __name__ == "__main__":
|
|
297
|
+
sys.exit(main())
|