@roomi-fields/grillhouse 0.26.0 → 0.27.0
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/.claude-plugin/plugin.json +1 -1
- package/cadre/templates/projet/CLAUDE.md +7 -0
- package/cadre/templates/projet/docs/ARCHITECTURE.md +15 -0
- package/cadre/templates/python/package.json +18 -0
- package/charte.md +22 -0
- package/docs/ARCHITECTURE.md +58 -17
- package/docs/CADRE.md +7 -6
- package/docs/INTERFACE.md +96 -32
- package/package.json +1 -1
- package/scripts/circuit.mjs +44 -8
- package/scripts/commande-du-langage.mjs +2 -2
- package/scripts/commandes-composees.mjs +156 -0
- package/scripts/composition-des-langages.mjs +306 -0
- package/scripts/conformite.mjs +1 -3
- package/scripts/dernier-vert.mjs +15 -2
- package/scripts/engendres.mjs +170 -0
- package/scripts/enveloppe/travail-de-la-copie.mjs +82 -8
- package/scripts/gardes-du-cadre.mjs +7 -4
- package/scripts/grillhouse-maj.mjs +152 -99
- package/scripts/index-interfaces.mjs +78 -0
- package/scripts/init.mjs +5 -5
- package/scripts/integration/file.mjs +74 -13
- package/scripts/integration/integrer.mjs +50 -62
- package/scripts/jointure.d.ts +26 -13
- package/scripts/langages/cargo/binaires.mjs +29 -6
- package/scripts/langages/cargo/clippy.mjs +4 -2
- package/scripts/langages/cargo/commandes.mjs +45 -7
- package/scripts/langages/cargo/exemples.mjs +1 -15
- package/scripts/langages/cargo/index-interfaces.mjs +20 -3
- package/scripts/langages/cargo/index.mjs +9 -10
- package/scripts/langages/cargo/mise-a-jour.mjs +2 -1
- package/scripts/langages/cargo/sccache.mjs +29 -0
- package/scripts/langages/python/binaires.json +3 -0
- package/scripts/langages/python/binaires.mjs +59 -0
- package/scripts/langages/python/commandes.mjs +411 -0
- package/scripts/langages/python/composants.mjs +272 -0
- package/scripts/langages/python/exemples.mjs +260 -0
- package/scripts/langages/python/index-interfaces.mjs +77 -0
- package/scripts/langages/python/index.mjs +94 -0
- package/scripts/langages/python/lot.mjs +76 -0
- package/scripts/langages/python/mise-a-jour.mjs +54 -0
- package/scripts/langages/python/tailles-des-tests.mjs +102 -0
- package/scripts/langages/python/verdict.mjs +85 -0
- package/scripts/langages/typescript/exemples.mjs +1 -20
- package/scripts/langages/typescript/index-interfaces.mjs +10 -3
- package/scripts/langages/typescript/index.mjs +11 -15
- package/scripts/langages-des-paquets.mjs +171 -0
- package/scripts/langages.mjs +60 -41
- package/scripts/migrations/0.27.0-langages-dans-l-architecture.mjs +182 -0
- package/scripts/migrations.mjs +2 -0
- package/scripts/outils-cles.mjs +1 -1
- package/scripts/session-start.sh +34 -9
- package/scripts/sources.mjs +2 -1
- package/scripts/sous-commandes.mjs +5 -3
- package/scripts/tableau-des-composants.mjs +138 -0
- package/scripts/verrous/verrou.mjs +3 -2
- package/skills/grill/SKILL.md +9 -1
- package/skills/pitmaster/SKILL.md +6 -1
- package/skills/redacteur/references/documents-d-un-composant.md +12 -0
- package/skills/testwriter/SKILL.md +6 -0
|
@@ -17,6 +17,13 @@
|
|
|
17
17
|
// share a server, whatever the environment says. An abstract socket writes no file, so that
|
|
18
18
|
// neither the read-only copy nor the 108 bytes of a socket's path bind it, and it goes with its
|
|
19
19
|
// server, leaving no stale file. The disk cache stays common.
|
|
20
|
+
// - The server starts before each run of cargo that compiles, under the machine's `/tmp`
|
|
21
|
+
// (`demarrerLeServeur`): sccache 0.19.0 starts its server by binding a socket of a path under
|
|
22
|
+
// TMPDIR (`<TMPDIR>/sccacheXXXXXX/sock`, src/commands.rs, `run_server_process`), which fails
|
|
23
|
+
// past the 108 bytes of a socket's path (« path must be shorter than SUN_LEN »), and the
|
|
24
|
+
// temporary directory of a pass of tests under the working directory of a session passes them
|
|
25
|
+
// (grillhouse-qmk, OSC Bridge OB-p58). Cargo then finds the server running and starts none; it
|
|
26
|
+
// keeps its own temporary directory, the pass's.
|
|
20
27
|
// - A wrapper the project sets already is its own: the run keeps it, without sccache. It is read
|
|
21
28
|
// as cargo reads it: the environment (`RUSTC_WRAPPER`, `CARGO_BUILD_RUSTC_WRAPPER`), then
|
|
22
29
|
// `build.rustc-wrapper` of each `.cargo/config.toml` (or `.cargo/config`) from the project up to
|
|
@@ -24,6 +31,7 @@
|
|
|
24
31
|
// - A machine without sccache on the PATH of the command is refused before any run of cargo, in
|
|
25
32
|
// one line that names it and the command that installs it (`sccacheAbsent`), rather than on the
|
|
26
33
|
// error of cargo that cannot run its wrapper.
|
|
34
|
+
import { spawnSync } from 'node:child_process';
|
|
27
35
|
import { createHash } from 'node:crypto';
|
|
28
36
|
import { accessSync, constants, readFileSync, readlinkSync, realpathSync } from 'node:fs';
|
|
29
37
|
import { createRequire } from 'node:module';
|
|
@@ -36,6 +44,10 @@ const require = createRequire(import.meta.url);
|
|
|
36
44
|
/** The cache of sccache, from the home: what the envelope opens in writing. */
|
|
37
45
|
export const CACHE = '~/.cache/sccache/';
|
|
38
46
|
|
|
47
|
+
// The machine's temporary directory, short whatever the copy: the one the server of sccache starts
|
|
48
|
+
// under (`demarrerLeServeur`), an empty one proper to the session in an envelope.
|
|
49
|
+
const COURT = '/tmp';
|
|
50
|
+
|
|
39
51
|
// The directories of cargo's configuration for a run in <racine> under <env>, in cargo's order:
|
|
40
52
|
// `.cargo` of the project and of each parent up to the root, then `$CARGO_HOME`.
|
|
41
53
|
function dossiersDeConfiguration(racine, env) {
|
|
@@ -123,6 +135,23 @@ export function sccacheAbsent(racine, env) {
|
|
|
123
135
|
: "⛔ sccache absent du PATH : cargo compile à travers lui (RUSTC_WRAPPER=sccache) ; `npx grillhouse maj` l'installe avec les autres binaires du module cargo.";
|
|
124
136
|
}
|
|
125
137
|
|
|
138
|
+
/**
|
|
139
|
+
* Starts the server of sccache of the copy at <racine> under <env> (`avecSccache`), under the
|
|
140
|
+
* machine's temporary directory (`COURT`), unless the project sets its own wrapper; a server
|
|
141
|
+
* already running stays, and its refusal of a second one is no failure.
|
|
142
|
+
* @param {string} racine
|
|
143
|
+
* @param {NodeJS.ProcessEnv} env the environment before `avecSccache`
|
|
144
|
+
*/
|
|
145
|
+
export function demarrerLeServeur(racine, env) {
|
|
146
|
+
if (lanceurDuProjet(racine, env)) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
spawnSync('sccache', ['--start-server'], {
|
|
150
|
+
env: { ...avecSccache(racine, env), TMPDIR: COURT },
|
|
151
|
+
stdio: 'ignore',
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
|
|
126
155
|
/**
|
|
127
156
|
* <env> with rustc wrapped by sccache for the copy at <racine>, its cache the home's, its server
|
|
128
157
|
* the copy's; <env> as it is when the project sets its own wrapper.
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The installation of uv, the binary of the module python (./binaires.json), by the commands its
|
|
3
|
+
// share of the update describes (`miseAJour.installation`, scripts/jointure.d.ts), which the core
|
|
4
|
+
// runs.
|
|
5
|
+
//
|
|
6
|
+
// node binaires.mjs liste the binaries installed, JSON on the standard output
|
|
7
|
+
// node binaires.mjs installer <nom>@<version> installs one binary at its version
|
|
8
|
+
//
|
|
9
|
+
// - `liste`: `{ "uv": <version> }` from `uv --version` (`uv 0.10.4 (…)`); `{}` when uv is absent
|
|
10
|
+
// or fails, so that the update installs it.
|
|
11
|
+
// - `installer`: the standalone installer of Astral at the version, as uv's documentation gives it
|
|
12
|
+
// (`curl -LsSf https://astral.sh/uv/<version>/install.sh | sh`), its output this process's
|
|
13
|
+
// error stream, its code this process's, the profiles of the shell left as they are
|
|
14
|
+
// (UV_NO_MODIFY_PATH); a failure names on the error stream the command to type.
|
|
15
|
+
import { spawnSync } from 'node:child_process';
|
|
16
|
+
import { pathToFileURL } from 'node:url';
|
|
17
|
+
|
|
18
|
+
/** The binaries installed: `{ uv: <version> }`, `{}` without uv. */
|
|
19
|
+
export function installes() {
|
|
20
|
+
const r = spawnSync('uv', ['--version'], { encoding: 'utf8' });
|
|
21
|
+
const m = r.status === 0 ? /^uv (\S+)/.exec(r.stdout ?? '') : null;
|
|
22
|
+
return m ? { uv: m[1] } : {};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** The command of the shell that installs uv at <version>. */
|
|
26
|
+
export const commandeDInstallation = version =>
|
|
27
|
+
`curl -LsSf https://astral.sh/uv/${version}/install.sh | sh`;
|
|
28
|
+
|
|
29
|
+
/** Installs <cible> (`uv@<version>`): the exit code of the installer. */
|
|
30
|
+
export function installer(cible) {
|
|
31
|
+
const [nom, version] = cible.split('@');
|
|
32
|
+
if (nom !== 'uv' || !version) {
|
|
33
|
+
process.stderr.write(`⛔ binaire inconnu du module python : ${cible} (uv@<version>)\n`);
|
|
34
|
+
return 2;
|
|
35
|
+
}
|
|
36
|
+
const commande = commandeDInstallation(version);
|
|
37
|
+
const r = spawnSync('sh', ['-c', commande], {
|
|
38
|
+
stdio: ['ignore', 2, 2],
|
|
39
|
+
env: { ...process.env, UV_NO_MODIFY_PATH: '1' },
|
|
40
|
+
});
|
|
41
|
+
const code = r.error ? 127 : (r.status ?? 1);
|
|
42
|
+
if (code !== 0) {
|
|
43
|
+
const cause = r.error ? r.error.message : `code ${code}`;
|
|
44
|
+
process.stderr.write(`⛔ \`${commande}\` échoue (${cause}) ; lance-la.\n`);
|
|
45
|
+
}
|
|
46
|
+
return code;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
50
|
+
const [nom, cible] = process.argv.slice(2);
|
|
51
|
+
if (nom === 'liste') {
|
|
52
|
+
process.stdout.write(`${JSON.stringify(installes())}\n`);
|
|
53
|
+
} else if (nom === 'installer' && cible) {
|
|
54
|
+
process.exitCode = installer(cible);
|
|
55
|
+
} else {
|
|
56
|
+
process.stderr.write('usage: binaires.mjs liste | installer <nom>@<version>\n');
|
|
57
|
+
process.exitCode = 2;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The commands of the module python, the demand `commandes` of the join (scripts/jointure.d.ts):
|
|
3
|
+
// each one this script with its name first, `{ script, args }`, described, never run, by
|
|
4
|
+
// `commandes`; run by `grillhouse <commande>` in the root of the project, its arguments after.
|
|
5
|
+
//
|
|
6
|
+
// npx grillhouse tests [--force] [<chemin>…] [--<option>…] tester
|
|
7
|
+
// npx grillhouse verifier [--tout | --gardes] verifier
|
|
8
|
+
// node commandes.mjs typer typer
|
|
9
|
+
// npx grillhouse preparer preparer
|
|
10
|
+
// npx grillhouse tests-de-nuit tests-de-nuit
|
|
11
|
+
// npx grillhouse tailles-des-tests | index-interfaces each guard, its own script
|
|
12
|
+
//
|
|
13
|
+
// - Each command plays in the folder of each package (./composants.mjs), one after the other, by
|
|
14
|
+
// uv, which reads its pyproject.toml, its uv.lock (`--locked`: a lock out of date is refused, as
|
|
15
|
+
// `npm ci`), and the Python its `requires-python` and its `.python-version` ask.
|
|
16
|
+
// - `tester` plays pytest in each package that plays tests: `uv run --locked --group test pytest`,
|
|
17
|
+
// the group `test` holding pytest and what the tests depend on, its JUnit report in the family
|
|
18
|
+
// `xunit1` (./verdict.mjs). A path, written from the root, chooses the package that holds it,
|
|
19
|
+
// and pytest plays that path alone; a path out of every package is refused, named, and nothing
|
|
20
|
+
// plays (code 2). Without a path, every package that plays tests plays, or, under the circuit's
|
|
21
|
+
// mark (`GRILLHOUSE_DEPUIS_LE_VERT`), the packages the changes since the last green touch
|
|
22
|
+
// (./lot.mjs), every package when no last green counts; the night tests (`*_nuit_test.py`) are
|
|
23
|
+
// left out (`--ignore-glob`), and a night test plays when its own file is named. `--force`
|
|
24
|
+
// changes nothing: pytest keeps no result to replay. Another option goes to pytest.
|
|
25
|
+
// - `verifier` plays, in each package the changes since the last green touch (every package with
|
|
26
|
+
// `--tout`, or when no last green counts), the typing then the tests of the day; green, it keeps
|
|
27
|
+
// the last green (scripts/dernier-vert.mjs). It plays under the lock of the machine
|
|
28
|
+
// (`avecLaMachine` of ./jointure), as the module cargo's. `verifier --gardes` plays the guards
|
|
29
|
+
// alone: the project's root scripts `grillhouse:gardes` then `gardes` the package.json holds.
|
|
30
|
+
// - `typer`: `uv run --locked python -m compileall`, the folders whose name begins with a dot (the
|
|
31
|
+
// `.venv`) left out. `preparer`: `uv sync --locked --group test`.
|
|
32
|
+
// - `tests-de-nuit`: pytest on the night tests of each package that holds some; none, nothing
|
|
33
|
+
// plays and the code is 0. The night (scripts/nuit.sh) runs it.
|
|
34
|
+
// - Each command plays under a temporary directory of its pass, the guard of the temporary
|
|
35
|
+
// directory: a base (`ouvrirBase` of ./jointure) named in TMPDIR, TMP and TEMP, removed at the
|
|
36
|
+
// end of the pass, green, red or interrupted; what the tests left there fails the pass (code 1),
|
|
37
|
+
// each name written on the error stream, the lock files uv takes there (`uv-<hash>.lock`) apart,
|
|
38
|
+
// which the base removes with the rest. A test makes its temporary
|
|
39
|
+
// directory or file with `tempfile` (`TemporaryDirectory`, `NamedTemporaryFile`), removed at
|
|
40
|
+
// its end, a failed test included, never `mkdtemp` by hand.
|
|
41
|
+
// - Python writes its bytecode under one tree at the root, `__pycache__` (PYTHONPYCACHEPREFIX),
|
|
42
|
+
// which the envelope makes proper to the session (`sorties.propres` of ./index.mjs); uv the
|
|
43
|
+
// environment of each package under `.venv/<dossier>` at the root (UV_PROJECT_ENVIRONMENT), and
|
|
44
|
+
// pytest its cache under `.pytest_cache/<dossier>` (`cache_dir`), where the envelope opens them
|
|
45
|
+
// in writing, rather than in the package's folder, which a session whose plan does not write the
|
|
46
|
+
// package could not write.
|
|
47
|
+
// - While the environment names a results directory (`GRILLHOUSE_RESULTATS`), the run writes
|
|
48
|
+
// there what ./verdict.mjs reads: its tasks, each planned before it plays, and the JUnit report
|
|
49
|
+
// of each run of pytest.
|
|
50
|
+
// - uv absent from the PATH: one line that names it and `npx grillhouse maj`, which installs it.
|
|
51
|
+
// - The exit code: 0 when every task is green, 75 when the only reds are « à repasser », 1
|
|
52
|
+
// otherwise; 2 for a path refused or a command unknown.
|
|
53
|
+
import { spawnSync } from 'node:child_process';
|
|
54
|
+
import { mkdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
55
|
+
import { constants, tmpdir } from 'node:os';
|
|
56
|
+
import path from 'node:path';
|
|
57
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
58
|
+
import { RESULTATS } from '../../resultats.mjs';
|
|
59
|
+
import {
|
|
60
|
+
AttenteDeLaMachine,
|
|
61
|
+
avecLaMachine,
|
|
62
|
+
CHANGEMENTS,
|
|
63
|
+
DEPUIS_LE_VERT,
|
|
64
|
+
garderLeVert,
|
|
65
|
+
ligneDesRestes,
|
|
66
|
+
mesure,
|
|
67
|
+
ouvrirBase,
|
|
68
|
+
retirerALInterruption,
|
|
69
|
+
} from '../../services-du-noyau.mjs';
|
|
70
|
+
import {
|
|
71
|
+
composantDans,
|
|
72
|
+
composants,
|
|
73
|
+
estDeNuit,
|
|
74
|
+
fichiersDeTest,
|
|
75
|
+
GROUPE,
|
|
76
|
+
joueDesTests,
|
|
77
|
+
} from './composants.mjs';
|
|
78
|
+
import { touchesDesFichiers } from './lot.mjs';
|
|
79
|
+
import { JUNIT, TACHES } from './verdict.mjs';
|
|
80
|
+
|
|
81
|
+
const ICI = fileURLToPath(import.meta.url);
|
|
82
|
+
export const NOMS = ['tester', 'verifier', 'typer', 'preparer', 'tests-de-nuit'];
|
|
83
|
+
const A_REPASSER = 75;
|
|
84
|
+
const RACINE = '//';
|
|
85
|
+
/** The night tests, which the day leaves out. */
|
|
86
|
+
export const DE_NUIT = '*_nuit_test.py';
|
|
87
|
+
/** The tree of the bytecode of Python, at the root. */
|
|
88
|
+
export const PYCACHE = '__pycache__';
|
|
89
|
+
/** The environments of uv and the caches of pytest, one per package, at the root. */
|
|
90
|
+
export const VENV = '.venv';
|
|
91
|
+
export const CACHE_DE_PYTEST = '.pytest_cache';
|
|
92
|
+
|
|
93
|
+
/** The guards of the module: each its name and its script beside this one. */
|
|
94
|
+
export const GARDES = [
|
|
95
|
+
{ nom: 'tailles-des-tests', args: [] },
|
|
96
|
+
{ nom: 'index-interfaces', args: ['--verifier'] },
|
|
97
|
+
].map(g => ({
|
|
98
|
+
...g,
|
|
99
|
+
script: path.join(path.dirname(ICI), `${g.nom}.mjs`),
|
|
100
|
+
}));
|
|
101
|
+
|
|
102
|
+
/** The commands of the module, each this script and its name; then each guard, its script. */
|
|
103
|
+
export const commandes = () =>
|
|
104
|
+
Object.fromEntries([
|
|
105
|
+
...NOMS.map(n => [n, { script: ICI, args: [n] }]),
|
|
106
|
+
...GARDES.map(g => [g.nom, { script: g.script, args: [] }]),
|
|
107
|
+
]);
|
|
108
|
+
|
|
109
|
+
// The run of the tasks of a command in <racine>: each planned, then played, written in the
|
|
110
|
+
// results directory <env> names.
|
|
111
|
+
function passe(racine, env) {
|
|
112
|
+
const dossier = env[RESULTATS] || null;
|
|
113
|
+
const id = `${Date.now()}-${process.pid}`;
|
|
114
|
+
const taches = [];
|
|
115
|
+
const rapports = {};
|
|
116
|
+
const environnement = { ...env, PYTHONPYCACHEPREFIX: path.join(racine, PYCACHE) };
|
|
117
|
+
const ecrire = () => {
|
|
118
|
+
if (!dossier) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
mkdirSync(path.join(dossier, TACHES), { recursive: true });
|
|
122
|
+
writeFileSync(
|
|
123
|
+
path.join(dossier, TACHES, `${id}.json`),
|
|
124
|
+
`${JSON.stringify({ taches, rapports }, null, 2)}\n`
|
|
125
|
+
);
|
|
126
|
+
};
|
|
127
|
+
return {
|
|
128
|
+
racine,
|
|
129
|
+
prevoir(paquet, dossierDuPaquet, script, tests, args, programme = 'uv') {
|
|
130
|
+
const t = {
|
|
131
|
+
tache: `${paquet}#${script}`,
|
|
132
|
+
paquet,
|
|
133
|
+
dossier: path.relative(racine, dossierDuPaquet) || '.',
|
|
134
|
+
script,
|
|
135
|
+
tests,
|
|
136
|
+
code: null,
|
|
137
|
+
cache: null,
|
|
138
|
+
journal: null,
|
|
139
|
+
};
|
|
140
|
+
taches.push(t);
|
|
141
|
+
ecrire();
|
|
142
|
+
return { t, args, cwd: dossierDuPaquet, programme };
|
|
143
|
+
},
|
|
144
|
+
// The JUnit report of a run of pytest of the package <nom> at <dossierDuPaquet>, its option;
|
|
145
|
+
// none without a results directory.
|
|
146
|
+
junit(nom, dossierDuPaquet) {
|
|
147
|
+
if (!dossier) {
|
|
148
|
+
return [];
|
|
149
|
+
}
|
|
150
|
+
const f = `${id}-${nom}.xml`;
|
|
151
|
+
rapports[f] = dossierDuPaquet;
|
|
152
|
+
return ['-o', 'junit_family=xunit1', `--junit-xml=${path.join(dossier, JUNIT, f)}`];
|
|
153
|
+
},
|
|
154
|
+
jouer({ t, args, cwd, programme }) {
|
|
155
|
+
// The environment of uv of the package, at the root (`sorties` of ./index.mjs).
|
|
156
|
+
const venv = path.join(racine, VENV, path.relative(racine, cwd));
|
|
157
|
+
const r = spawnSync(programme, args, {
|
|
158
|
+
cwd,
|
|
159
|
+
env: { ...environnement, UV_PROJECT_ENVIRONMENT: venv },
|
|
160
|
+
stdio: 'inherit',
|
|
161
|
+
});
|
|
162
|
+
if (r.error?.code === 'ENOENT' && programme === 'uv') {
|
|
163
|
+
process.stderr.write("⛔ uv absent du PATH : `npx grillhouse maj` l'installe.\n");
|
|
164
|
+
}
|
|
165
|
+
t.code = r.error ? 127 : (r.status ?? 128 + (constants.signals[r.signal] ?? 0));
|
|
166
|
+
ecrire();
|
|
167
|
+
return t.code;
|
|
168
|
+
},
|
|
169
|
+
code() {
|
|
170
|
+
const rouges = taches.filter(t => t.code !== 0);
|
|
171
|
+
if (rouges.length === 0) {
|
|
172
|
+
return 0;
|
|
173
|
+
}
|
|
174
|
+
return rouges.every(t => t.code === A_REPASSER) ? A_REPASSER : 1;
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
const UV_RUN = ['run', '--locked'];
|
|
180
|
+
|
|
181
|
+
// Plays pytest in the run <p> for each `{ c, chemins }` of <choix>, `chemins` from the package's
|
|
182
|
+
// folder (empty: the whole package, the night left out), <options> given to pytest.
|
|
183
|
+
function jouerLesTests(p, choix, options) {
|
|
184
|
+
for (const { c, chemins } of choix) {
|
|
185
|
+
const selection = chemins.length ? chemins : [`--ignore-glob=${DE_NUIT}`];
|
|
186
|
+
const cache = path.join(p.racine, CACHE_DE_PYTEST, path.relative(p.racine, c.dossier));
|
|
187
|
+
const args = [...UV_RUN, '--group', GROUPE, 'pytest', '-o', `cache_dir=${cache}`];
|
|
188
|
+
args.push(...p.junit(c.nom, c.dossier));
|
|
189
|
+
p.jouer(p.prevoir(c.nom, c.dossier, 'pytest', true, [...args, ...selection, ...options]));
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
// The packages the changes since the last green of <racine> touch; every package with <tout> or
|
|
194
|
+
// without a last green that counts. `{ choix, m }`, `m` the measure.
|
|
195
|
+
function depuisLeVert(racine, tous, tout, env) {
|
|
196
|
+
const m = mesure(racine, { tout, dans: env.TMPDIR });
|
|
197
|
+
process.stderr.write(`${m.ligne}\n`);
|
|
198
|
+
const f = m.env[CHANGEMENTS];
|
|
199
|
+
if (!f) {
|
|
200
|
+
return { choix: tous, m };
|
|
201
|
+
}
|
|
202
|
+
const ch = JSON.parse(readFileSync(f, 'utf8'));
|
|
203
|
+
const t = touchesDesFichiers(racine, [...ch.fichiers, ...ch.supprimes]);
|
|
204
|
+
const nommes = new Set(t.touches.map(c => c.dossier));
|
|
205
|
+
return { choix: tous.filter(c => nommes.has(c.dossier)), m };
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// The packages the paths <chemins> choose in <racine>: `{ choix }`, or `{ refus }`.
|
|
209
|
+
function choisir(racine, tous, chemins) {
|
|
210
|
+
const parDossier = new Map();
|
|
211
|
+
const refus = [];
|
|
212
|
+
for (const chemin of chemins) {
|
|
213
|
+
const c = composantDans(tous, racine, chemin);
|
|
214
|
+
if (!c) {
|
|
215
|
+
refus.push(`${chemin} : hors de tout paquet Python (pyproject.toml)`);
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
const rel = path.relative(c.dossier, path.resolve(racine, chemin)) || '.';
|
|
219
|
+
const deja = parDossier.get(c.dossier) ?? { c, chemins: [] };
|
|
220
|
+
deja.chemins.push(rel);
|
|
221
|
+
parDossier.set(c.dossier, deja);
|
|
222
|
+
}
|
|
223
|
+
return refus.length ? { refus } : { choix: [...parDossier.values()] };
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// The pass of `tester` in <racine>, its arguments <args>, under <env>.
|
|
227
|
+
function tester(racine, args, env) {
|
|
228
|
+
const p = passe(racine, env);
|
|
229
|
+
const tous = composants(racine);
|
|
230
|
+
const chemins = args.filter(a => !a.startsWith('-'));
|
|
231
|
+
const options = args.filter(a => a.startsWith('-') && a !== '--force');
|
|
232
|
+
if (chemins.length) {
|
|
233
|
+
const r = choisir(racine, tous, chemins);
|
|
234
|
+
if (r.refus) {
|
|
235
|
+
for (const l of r.refus) {
|
|
236
|
+
process.stderr.write(`⛔ ${l}\n`);
|
|
237
|
+
}
|
|
238
|
+
return 2;
|
|
239
|
+
}
|
|
240
|
+
jouerLesTests(p, r.choix, options);
|
|
241
|
+
return p.code();
|
|
242
|
+
}
|
|
243
|
+
let m = null;
|
|
244
|
+
let choix = tous;
|
|
245
|
+
if (env[DEPUIS_LE_VERT]) {
|
|
246
|
+
({ choix, m } = depuisLeVert(racine, tous, args.includes('--force'), env));
|
|
247
|
+
}
|
|
248
|
+
try {
|
|
249
|
+
const avec = choix.filter(c => joueDesTests(racine, c)).map(c => ({ c, chemins: [] }));
|
|
250
|
+
jouerLesTests(p, avec, options);
|
|
251
|
+
} finally {
|
|
252
|
+
m?.retirer();
|
|
253
|
+
}
|
|
254
|
+
return p.code();
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// The pass of `verifier` in <racine>, under the lock of the machine: the typing and the tests of
|
|
258
|
+
// the packages the changes since the last green touch; green, it keeps the last green.
|
|
259
|
+
function verifier(racine, args, env) {
|
|
260
|
+
const p = passe(racine, env);
|
|
261
|
+
if (args.includes('--gardes')) {
|
|
262
|
+
return gardes(racine, p);
|
|
263
|
+
}
|
|
264
|
+
const { choix, m } = depuisLeVert(racine, composants(racine), args.includes('--tout'), env);
|
|
265
|
+
try {
|
|
266
|
+
for (const c of choix) {
|
|
267
|
+
typerLePaquet(p, c);
|
|
268
|
+
}
|
|
269
|
+
jouerLesTests(
|
|
270
|
+
p,
|
|
271
|
+
choix.filter(c => joueDesTests(racine, c)).map(c => ({ c, chemins: [] })),
|
|
272
|
+
[]
|
|
273
|
+
);
|
|
274
|
+
const code = p.code();
|
|
275
|
+
if (code === 0 && m.etat) {
|
|
276
|
+
garderLeVert(m.etat);
|
|
277
|
+
}
|
|
278
|
+
return code;
|
|
279
|
+
} finally {
|
|
280
|
+
m.retirer();
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// The typing of the package <c> in the run <p>: compileall, the folders of a dot left out.
|
|
285
|
+
const typerLePaquet = (p, c) =>
|
|
286
|
+
p.jouer(
|
|
287
|
+
p.prevoir(c.nom, c.dossier, 'compileall', false, [
|
|
288
|
+
...UV_RUN,
|
|
289
|
+
'python',
|
|
290
|
+
'-m',
|
|
291
|
+
'compileall',
|
|
292
|
+
'-q',
|
|
293
|
+
'-x',
|
|
294
|
+
String.raw`/\.`,
|
|
295
|
+
'.',
|
|
296
|
+
])
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
// The scripts of guards of the project, in the order they play: the frame's, then its own.
|
|
300
|
+
const SCRIPTS_DE_GARDES = ['grillhouse:gardes', 'gardes'];
|
|
301
|
+
|
|
302
|
+
// The pass of `verifier --gardes` in <racine>: each script of SCRIPTS_DE_GARDES the root
|
|
303
|
+
// package.json holds, a task of the root; no test.
|
|
304
|
+
function gardes(racine, p) {
|
|
305
|
+
let scripts = {};
|
|
306
|
+
try {
|
|
307
|
+
scripts = JSON.parse(readFileSync(path.join(racine, 'package.json'), 'utf8')).scripts ?? {};
|
|
308
|
+
} catch {
|
|
309
|
+
scripts = {};
|
|
310
|
+
}
|
|
311
|
+
for (const nom of SCRIPTS_DE_GARDES.filter(n => typeof scripts[n] === 'string')) {
|
|
312
|
+
p.jouer(p.prevoir(RACINE, racine, nom, false, ['run', '--silent', nom], 'npm'));
|
|
313
|
+
}
|
|
314
|
+
return p.code();
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// What the tools write at the root of the temporary directory, which the guard of the base
|
|
318
|
+
// tolerates and the base removes with the rest: Node's compile cache, which npm enables; the lock
|
|
319
|
+
// file uv takes on the environment of a project (`uv-<hash>.lock`, measured with uv 0.10.4).
|
|
320
|
+
const DES_OUTILS = n => n === 'node-compile-cache' || /^uv-[0-9a-f]+\.lock$/.test(n);
|
|
321
|
+
|
|
322
|
+
// Plays <jouer>(env) under the base of a pass of <genre> in the temporary directory of <env>,
|
|
323
|
+
// named in TMPDIR, TMP and TEMP: its code, 1 when the tests left something there, named.
|
|
324
|
+
function sousLaBase(genre, env, jouer) {
|
|
325
|
+
const base = ouvrirBase(genre, { dans: env.TMPDIR || tmpdir() });
|
|
326
|
+
const lacher = retirerALInterruption(base.fermer);
|
|
327
|
+
try {
|
|
328
|
+
const code = jouer({ ...env, ...base.env });
|
|
329
|
+
const ligne = ligneDesRestes(base.restes().filter(n => !DES_OUTILS(n)));
|
|
330
|
+
if (!ligne) {
|
|
331
|
+
return code;
|
|
332
|
+
}
|
|
333
|
+
process.stderr.write(`${ligne}\n`);
|
|
334
|
+
return code === 0 || code === A_REPASSER ? 1 : code;
|
|
335
|
+
} finally {
|
|
336
|
+
lacher();
|
|
337
|
+
base.fermer();
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Runs the command <nom> with <args> in the project at <racine>: its exit code.
|
|
343
|
+
* @param {string} nom one of NOMS
|
|
344
|
+
* @param {string[]} args its arguments
|
|
345
|
+
* @param {{ racine?: string, env?: NodeJS.ProcessEnv }} [o]
|
|
346
|
+
*/
|
|
347
|
+
export function lancer(nom, args, { racine = process.cwd(), env = process.env } = {}) {
|
|
348
|
+
if (nom === 'tester') {
|
|
349
|
+
return sousLaBase('tests', env, e => tester(racine, args, e));
|
|
350
|
+
}
|
|
351
|
+
if (nom === 'tests-de-nuit') {
|
|
352
|
+
return sousLaBase('tests', env, e => {
|
|
353
|
+
const p = passe(racine, e);
|
|
354
|
+
const choix = composants(racine)
|
|
355
|
+
.map(c => ({
|
|
356
|
+
c,
|
|
357
|
+
chemins: fichiersDeTest(c.dossier)
|
|
358
|
+
.filter(f => estDeNuit(path.basename(f)))
|
|
359
|
+
.map(f => path.relative(c.dossier, f)),
|
|
360
|
+
}))
|
|
361
|
+
.filter(x => x.chemins.length);
|
|
362
|
+
jouerLesTests(p, choix, []);
|
|
363
|
+
return p.code();
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
if (nom === 'verifier') {
|
|
367
|
+
const dire = l => process.stdout.write(`${l}\n`);
|
|
368
|
+
try {
|
|
369
|
+
return sousLaBase('verification', env, envBase =>
|
|
370
|
+
avecLaMachine(envMachine => verifier(racine, args, envMachine), {
|
|
371
|
+
env: envBase,
|
|
372
|
+
racine,
|
|
373
|
+
dire,
|
|
374
|
+
})
|
|
375
|
+
);
|
|
376
|
+
} catch (e) {
|
|
377
|
+
if (!(e instanceof AttenteDeLaMachine)) {
|
|
378
|
+
throw e;
|
|
379
|
+
}
|
|
380
|
+
dire(e.message);
|
|
381
|
+
return e.code;
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (nom === 'typer' || nom === 'preparer') {
|
|
385
|
+
return sousLaBase('tests', env, e => {
|
|
386
|
+
const p = passe(racine, e);
|
|
387
|
+
for (const c of composants(racine)) {
|
|
388
|
+
if (nom === 'typer') {
|
|
389
|
+
typerLePaquet(p, c);
|
|
390
|
+
} else {
|
|
391
|
+
p.jouer(
|
|
392
|
+
p.prevoir(c.nom, c.dossier, 'sync', false, ['sync', '--locked', '--group', GROUPE])
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
return p.code();
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
process.stderr.write(`⛔ commande inconnue du module python : ${nom} (${NOMS.join(', ')})\n`);
|
|
400
|
+
return 2;
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
if (import.meta.url === pathToFileURL(process.argv[1] ?? '').href) {
|
|
404
|
+
const [nom, ...args] = process.argv.slice(2);
|
|
405
|
+
try {
|
|
406
|
+
process.exitCode = lancer(nom, args);
|
|
407
|
+
} catch (e) {
|
|
408
|
+
process.stderr.write(`${e.message}\n`);
|
|
409
|
+
process.exitCode = 1;
|
|
410
|
+
}
|
|
411
|
+
}
|