@multiplatform.one/cli 8.1.0 → 8.2.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/README.md CHANGED
@@ -163,8 +163,8 @@ sh scripts/scaffold.sh [--app <name>]... [--service <name>]... [--mpo-version <r
163
163
  | `mpo frappe types <doctype…>` | Emit doctype TypeScript types from getdoctype; `--check -o <file>` fails on drift |
164
164
  | `mpo build` | Run the build command |
165
165
  | `mpo test [tier]` | Run unit (default), integration, e2e or visual tests (E2E: `--up-only`, …) |
166
- | `mpo lint` | Run the root `lint` script (`//#lint`), then `ruff check` |
167
- | `mpo format` | Run the root `format` script (`//#format`), then `ruff format` |
166
+ | `mpo lint` | Run the root `lint` script (`//#lint`), then `black --check` and `basedpyright` |
167
+ | `mpo format` | Run the root `format` script (`//#format`), then `black` |
168
168
  | `mpo count` | Count lines of code with `cloc` |
169
169
  | `mpo generate` | Run the turbo `generate` task |
170
170
 
@@ -4,7 +4,7 @@ import { adoptApp } from "../commands/adoptApp.mjs";
4
4
  import { generateDoctypeTypes, typesDrift } from "../commands/doctypeTypes.mjs";
5
5
  import { runE2ESession } from "../commands/e2e.mjs";
6
6
  import { SINGLETON_APPS, init } from "../commands/init.mjs";
7
- import { runRuff } from "../commands/ruff.mjs";
7
+ import { pythonFiles, runPythonTools } from "../commands/pythonTools.mjs";
8
8
  import { updateApp } from "../commands/updateApp.mjs";
9
9
  import { availableServices, parseTestTiers, runBuild, runFrappeBench, runIntegrationTests, runTurboLint, runUnitTests, testTiers, waitFunctions } from "../commands/verbs.mjs";
10
10
  import fsSync from "node:fs";
@@ -272,14 +272,20 @@ program.command("test").argument("[args...]", `test to run: ${testTiers.join(",
272
272
  }
273
273
  });
274
274
  /**
275
- * Run ruff format or check on the Frappe Python apps (if present).
276
- * Returns true if the ruff step failed.
275
+ * Run black, or black --check and basedpyright, on the project's Python files (if any).
276
+ * Returns true if the Python step failed.
277
277
  */
278
- async function ruffStep(mode) {
279
- const frappeApps = path.join(projectRoot, "apps", "frappe", "apps");
280
- if (!fsSync.existsSync(frappeApps)) return false;
281
- console.log(`\n── ${mode === "format" ? "ruff format" : "ruff check"} (Python) ──`);
282
- const reason = await runRuff(mode, path.relative(projectRoot, frappeApps), projectRoot);
278
+ async function pythonStep(mode) {
279
+ let files;
280
+ try {
281
+ files = await pythonFiles(projectRoot);
282
+ } catch (error) {
283
+ console.error(`git ls-files could not list the Python files: ${error.message}`);
284
+ return true;
285
+ }
286
+ if (files.length === 0) return false;
287
+ console.log(`\n── ${mode === "format" ? "black" : "black --check, basedpyright"} (Python) ──`);
288
+ const reason = await runPythonTools(mode, files, projectRoot);
283
289
  if (reason === void 0) return false;
284
290
  console.error(reason);
285
291
  return true;
@@ -293,12 +299,12 @@ program.command("format").description("format all supported files (TS, Python, e
293
299
  stdio: "inherit",
294
300
  cwd: projectRoot
295
301
  });
296
- await ruffStep("format");
302
+ await pythonStep("format");
297
303
  });
298
304
  program.command("lint").description("lint all supported files (TS, Python, etc.) via turbo").action(async () => {
299
305
  const turboFailed = await runTurboLint(projectRoot);
300
- const ruffFailed = await ruffStep("check");
301
- if (turboFailed || ruffFailed) process.exit(1);
306
+ const pythonFailed = await pythonStep("check");
307
+ if (turboFailed || pythonFailed) process.exit(1);
302
308
  });
303
309
  program.command("count").description("count lines of code").action(async () => {
304
310
  await spawn("cloc", ["`git ls-files | grep -E '(html)|(s?css)|(md)|(json)|(yaml)|([jt]sx?)$'`"], {
@@ -0,0 +1,81 @@
1
+ import fsSync from "node:fs";
2
+ import path from "node:path";
3
+ import spawn from "nano-spawn";
4
+
5
+ //#region src/commands/pythonTools.ts
6
+ const pinHint = "uv is pinned in .tool-versions; `make configure` installs it through mise or asdf";
7
+ function errorDetail(error) {
8
+ const e = error ?? {};
9
+ return {
10
+ code: e.cause?.code,
11
+ exitCode: e.exitCode,
12
+ signalName: e.signalName,
13
+ stderr: e.stderr?.trim() || void 0,
14
+ message: e.cause?.message ?? e.message ?? String(error)
15
+ };
16
+ }
17
+ /** Why `uv --version` did not answer, as one line for the lint output. */
18
+ function uvStartFailure(error) {
19
+ const d = errorDetail(error);
20
+ if (d.code === "ENOENT") return `uv is not on PATH. ${pinHint}.`;
21
+ return `uv did not start: ${d.stderr ?? d.message}. ${pinHint}.`;
22
+ }
23
+ /** Why a tool failed once uv had started it, as one line for the lint output. */
24
+ function toolFailure(tool, error) {
25
+ const d = errorDetail(error);
26
+ if (d.signalName) return `${tool} was killed by ${d.signalName}.`;
27
+ if (d.exitCode === 1 && tool === "black --check") return "black --check found files to reformat (listed above).";
28
+ if (d.exitCode === 1 && tool === "basedpyright") return "basedpyright found errors .basedpyright/baseline.json does not hold (listed above).";
29
+ if (d.exitCode !== void 0) return `${tool} exited ${d.exitCode}, a configuration or usage error (see above).`;
30
+ return `${tool} failed: ${d.message}.`;
31
+ }
32
+ /**
33
+ * The Python files git knows under `cwd`, tracked or untracked and not
34
+ * ignored, that are still on disk: the set CI's frappe/lint job checks.
35
+ */
36
+ async function pythonFiles(cwd, spawn$1 = spawn) {
37
+ const { stdout } = await spawn$1("git", [
38
+ "ls-files",
39
+ "-z",
40
+ "--cached",
41
+ "--others",
42
+ "--exclude-standard",
43
+ "--",
44
+ "*.py",
45
+ "*.pyi"
46
+ ], { cwd });
47
+ return [...new Set(stdout.split("\0").filter(Boolean))].filter((file) => fsSync.existsSync(path.join(cwd, file)));
48
+ }
49
+ /**
50
+ * Run black, or black --check then basedpyright, on `files` through the uv
51
+ * project at `cwd`, first proving uv starts and the lock is there, so a missing
52
+ * install or project is reported as that instead of as a lint failure. Returns
53
+ * the reasons it failed, one per line, or undefined when it passed.
54
+ */
55
+ async function runPythonTools(mode, files, cwd, spawn$2 = spawn) {
56
+ try {
57
+ await spawn$2("uv", ["--version"], { cwd });
58
+ } catch (error) {
59
+ return uvStartFailure(error);
60
+ }
61
+ if (!fsSync.existsSync(path.join(cwd, "uv.lock"))) return "No uv.lock at the project root pins black and basedpyright; `mpo update` brings it and pyproject.toml.";
62
+ const steps = mode === "format" ? [["black", ["black"]]] : [["black --check", ["black", "--check"]], ["basedpyright", ["basedpyright"]]];
63
+ const reasons = [];
64
+ for (const [tool, args] of steps) try {
65
+ await spawn$2("uv", [
66
+ "run",
67
+ "--locked",
68
+ ...args,
69
+ ...files
70
+ ], {
71
+ stdio: "inherit",
72
+ cwd
73
+ });
74
+ } catch (error) {
75
+ reasons.push(toolFailure(tool, error));
76
+ }
77
+ return reasons.length > 0 ? reasons.join("\n") : void 0;
78
+ }
79
+
80
+ //#endregion
81
+ export { pythonFiles, runPythonTools, toolFailure, uvStartFailure };
@@ -63,6 +63,29 @@ async function getTurboExcludeFiltersForMissing(root) {
63
63
  }
64
64
  return filters;
65
65
  }
66
+ function frappeEntryName(entry) {
67
+ if (typeof entry === "string") return {
68
+ src: entry,
69
+ name: path.basename(entry)
70
+ };
71
+ if (!entry.source || !entry.name) return void 0;
72
+ return {
73
+ src: entry.source,
74
+ name: entry.name
75
+ };
76
+ }
77
+ function resolveFrappeApp(frappeDir, entry) {
78
+ const named = frappeEntryName(entry);
79
+ if (!named) return void 0;
80
+ const src = named.src.startsWith("file://") ? named.src.slice(7) : named.src;
81
+ if (!src.startsWith("./") && !src.startsWith("../") && !src.startsWith("/")) return void 0;
82
+ const absolutePath = path.isAbsolute(src) ? src : path.resolve(frappeDir, src);
83
+ if (!fsSync.existsSync(absolutePath)) return void 0;
84
+ return {
85
+ name: named.name,
86
+ absolutePath
87
+ };
88
+ }
66
89
  /** Discover frappe apps from frappe.yaml that have local source paths.
67
90
  * Supports both string entries (`- ./apps/core`) and object entries (`- name: core\n source: ./apps/core`). */
68
91
  async function getFrappeApps(root) {
@@ -70,29 +93,7 @@ async function getFrappeApps(root) {
70
93
  const frappeYamlPath = path.join(frappeDir, "frappe.yaml");
71
94
  if (!fsSync.existsSync(frappeYamlPath)) return [];
72
95
  const raw = await fs.readFile(frappeYamlPath, "utf8");
73
- const config = YAML.parse(raw);
74
- const out = [];
75
- for (const app of config?.apps ?? []) {
76
- let src;
77
- let name;
78
- if (typeof app === "string") {
79
- src = app;
80
- name = path.basename(app);
81
- } else {
82
- if (!app.source || !app.name) continue;
83
- src = app.source;
84
- name = app.name;
85
- }
86
- src = src.startsWith("file://") ? src.slice(7) : src;
87
- if (!src.startsWith("./") && !src.startsWith("../") && !src.startsWith("/")) continue;
88
- const absPath = path.isAbsolute(src) ? src : path.resolve(frappeDir, src);
89
- if (!fsSync.existsSync(absPath)) continue;
90
- out.push({
91
- name,
92
- absolutePath: absPath
93
- });
94
- }
95
- return out;
96
+ return (YAML.parse(raw)?.apps ?? []).map((entry) => resolveFrappeApp(frappeDir, entry)).filter((app) => app !== void 0);
96
97
  }
97
98
  const testTiers = [
98
99
  "unit",
package/lib/source.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "cliVersion": "8.1.0",
2
+ "cliVersion": "8.2.0",
3
3
  "url": "https://git.corp.bitspur.com/multiplatform.one/mpo.git",
4
- "sha": "e31385ea6386809a964fcf0fe7ac01b1dc2c7668"
4
+ "sha": "03f857d195f3231a3f880faf802bf3c57b70a911"
5
5
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@multiplatform.one/cli",
3
- "version": "8.1.0",
3
+ "version": "8.2.0",
4
4
  "description": "multiplatform.one cli — mpo init clones and prunes the monorepo, mpo update merges it back",
5
5
  "keywords": [
6
6
  "create-multiplatform-app",
@@ -57,7 +57,7 @@
57
57
  "access": "public"
58
58
  },
59
59
  "dependencies": {
60
- "@multiplatform.one/utils": "^8.1.0",
60
+ "@multiplatform.one/utils": "^8.2.0",
61
61
  "commander": "^15.0.0",
62
62
  "dotenv": "^17.4.2",
63
63
  "inquirer": "^14.2.3",
@@ -19,7 +19,7 @@ import { generateDoctypeTypes, typesDrift } from "../commands/doctypeTypes";
19
19
  import { runE2ESession } from "../commands/e2e";
20
20
  import { SINGLETON_APPS, init } from "../commands/init";
21
21
  import { INIT_APP_PIECES } from "../commands/pieces";
22
- import { runRuff } from "../commands/ruff";
22
+ import { type PythonMode, pythonFiles, runPythonTools } from "../commands/pythonTools";
23
23
  import { updateApp } from "../commands/updateApp";
24
24
  import {
25
25
  availableServices,
@@ -490,15 +490,21 @@ program
490
490
  });
491
491
 
492
492
  /**
493
- * Run ruff format or check on the Frappe Python apps (if present).
494
- * Returns true if the ruff step failed.
493
+ * Run black, or black --check and basedpyright, on the project's Python files (if any).
494
+ * Returns true if the Python step failed.
495
495
  */
496
- async function ruffStep(mode: "format" | "check"): Promise<boolean> {
497
- const frappeApps = path.join(projectRoot, "apps", "frappe", "apps");
498
- if (!fsSync.existsSync(frappeApps)) return false;
499
- const label = mode === "format" ? "ruff format" : "ruff check";
496
+ async function pythonStep(mode: PythonMode): Promise<boolean> {
497
+ let files: string[];
498
+ try {
499
+ files = await pythonFiles(projectRoot);
500
+ } catch (error) {
501
+ console.error(`git ls-files could not list the Python files: ${(error as Error).message}`);
502
+ return true;
503
+ }
504
+ if (files.length === 0) return false;
505
+ const label = mode === "format" ? "black" : "black --check, basedpyright";
500
506
  console.log(`\n── ${label} (Python) ──`);
501
- const reason = await runRuff(mode, path.relative(projectRoot, frappeApps), projectRoot);
507
+ const reason = await runPythonTools(mode, files, projectRoot);
502
508
  if (reason === undefined) return false;
503
509
  console.error(reason);
504
510
  return true;
@@ -512,7 +518,7 @@ program
512
518
  stdio: "inherit",
513
519
  cwd: projectRoot,
514
520
  });
515
- await ruffStep("format");
521
+ await pythonStep("format");
516
522
  });
517
523
 
518
524
  program
@@ -520,8 +526,8 @@ program
520
526
  .description("lint all supported files (TS, Python, etc.) via turbo")
521
527
  .action(async () => {
522
528
  const turboFailed = await runTurboLint(projectRoot);
523
- const ruffFailed = await ruffStep("check");
524
- if (turboFailed || ruffFailed) process.exit(1);
529
+ const pythonFailed = await pythonStep("check");
530
+ if (turboFailed || pythonFailed) process.exit(1);
525
531
  });
526
532
 
527
533
  program
@@ -0,0 +1,134 @@
1
+ import fs from "node:fs";
2
+ import os from "node:os";
3
+ import path from "node:path";
4
+ import nanoSpawn from "nano-spawn";
5
+ import { afterEach, describe, expect, it } from "vitest";
6
+ import { pythonFiles, runPythonTools } from "./pythonTools";
7
+
8
+ type Spawn = typeof nanoSpawn;
9
+
10
+ // Runs a real subprocess in place of uv, so the errors are nano-spawn's own.
11
+ function standIn(script: (args: readonly string[]) => string, calls: string[][] = []): Spawn {
12
+ return ((_file: string, args: readonly string[] = [], options = {}) => {
13
+ calls.push([...args]);
14
+ return nanoSpawn("sh", ["-c", script(args)], options);
15
+ }) as Spawn;
16
+ }
17
+
18
+ const files = ["apps/frappe/serve_dev.py", "scripts/tool.py"];
19
+
20
+ const dirs: string[] = [];
21
+ afterEach(() => {
22
+ for (const dir of dirs.splice(0)) fs.rmSync(dir, { recursive: true, force: true });
23
+ });
24
+
25
+ function tempDir(): string {
26
+ const dir = fs.mkdtempSync(path.join(os.tmpdir(), "fz-10574-"));
27
+ dirs.push(dir);
28
+ return dir;
29
+ }
30
+
31
+ function project(): string {
32
+ const dir = tempDir();
33
+ fs.writeFileSync(path.join(dir, "uv.lock"), "version = 1\n");
34
+ return dir;
35
+ }
36
+
37
+ describe("runPythonTools (MPO-497, FZ-10574)", () => {
38
+ it("names a missing uv and the pin that provides it", async () => {
39
+ const missing = ((_file: string, args: readonly string[] = [], options = {}) =>
40
+ nanoSpawn("fz-10574-no-such-uv", [...args], options)) as Spawn;
41
+ const reason = await runPythonTools("check", files, project(), missing);
42
+ expect(reason).toMatch(/^uv is not on PATH\./);
43
+ expect(reason).toContain(".tool-versions");
44
+ expect(reason).toContain("make configure");
45
+ });
46
+
47
+ it("reports a uv that will not start with what it printed", async () => {
48
+ const shim = standIn(() => "echo 'mise ERROR No version is set for shim: uv' >&2; exit 1");
49
+ const reason = await runPythonTools("check", files, project(), shim);
50
+ expect(reason).toBe(
51
+ "uv did not start: mise ERROR No version is set for shim: uv. uv is pinned in .tool-versions; `make configure` installs it through mise or asdf.",
52
+ );
53
+ });
54
+
55
+ it("checks with black --check, then basedpyright, over the files through the locked uv project", async () => {
56
+ const calls: string[][] = [];
57
+ expect(
58
+ await runPythonTools(
59
+ "check",
60
+ files,
61
+ project(),
62
+ standIn(() => "true", calls),
63
+ ),
64
+ ).toBe(undefined);
65
+ expect(calls).toEqual([
66
+ ["--version"],
67
+ ["run", "--locked", "black", "--check", ...files],
68
+ ["run", "--locked", "basedpyright", ...files],
69
+ ]);
70
+ });
71
+
72
+ it("formats with black alone", async () => {
73
+ const calls: string[][] = [];
74
+ expect(
75
+ await runPythonTools(
76
+ "format",
77
+ files,
78
+ project(),
79
+ standIn(() => "true", calls),
80
+ ),
81
+ ).toBe(undefined);
82
+ expect(calls).toEqual([["--version"], ["run", "--locked", "black", ...files]]);
83
+ });
84
+
85
+ it("names a project without uv.lock before running anything", async () => {
86
+ const calls: string[][] = [];
87
+ const reason = await runPythonTools(
88
+ "check",
89
+ files,
90
+ tempDir(),
91
+ standIn(() => "true", calls),
92
+ );
93
+ expect(reason).toBe(
94
+ "No uv.lock at the project root pins black and basedpyright; `mpo update` brings it and pyproject.toml.",
95
+ );
96
+ expect(calls).toEqual([["--version"]]);
97
+ });
98
+
99
+ it("runs both checks and separates findings from a configuration error", async () => {
100
+ const findings = standIn((args) => (args[0] === "--version" ? "true" : "exit 1"));
101
+ expect(await runPythonTools("check", files, project(), findings)).toBe(
102
+ [
103
+ "black --check found files to reformat (listed above).",
104
+ "basedpyright found errors .basedpyright/baseline.json does not hold (listed above).",
105
+ ].join("\n"),
106
+ );
107
+ const broken = standIn((args) =>
108
+ args[0] === "--version" ? "true" : args.includes("basedpyright") ? "exit 3" : "true",
109
+ );
110
+ expect(await runPythonTools("check", files, project(), broken)).toBe(
111
+ "basedpyright exited 3, a configuration or usage error (see above).",
112
+ );
113
+ });
114
+ });
115
+
116
+ describe("pythonFiles (FZ-10574)", () => {
117
+ it("lists tracked and untracked Python files, never ignored or deleted ones", async () => {
118
+ const dir = tempDir();
119
+ const write = (file: string) => {
120
+ fs.mkdirSync(path.dirname(path.join(dir, file)), { recursive: true });
121
+ fs.writeFileSync(path.join(dir, file), "x = 1\n");
122
+ };
123
+ await nanoSpawn("git", ["init", "--quiet"], { cwd: dir });
124
+ for (const file of ["tracked.py", "gone.py", "notes.txt", "apps/frappe/env/lib/site.py"])
125
+ write(file);
126
+ fs.writeFileSync(path.join(dir, ".gitignore"), "/apps/frappe/env\n");
127
+ await nanoSpawn("git", ["add", "tracked.py", "gone.py", "notes.txt", ".gitignore"], {
128
+ cwd: dir,
129
+ });
130
+ fs.rmSync(path.join(dir, "gone.py"));
131
+ write("typings/frappe/__init__.pyi");
132
+ expect((await pythonFiles(dir)).sort()).toEqual(["tracked.py", "typings/frappe/__init__.pyi"]);
133
+ });
134
+ });
@@ -0,0 +1,106 @@
1
+ import fsSync from "node:fs";
2
+ import path from "node:path";
3
+ import nanoSpawn from "nano-spawn";
4
+
5
+ export type PythonMode = "format" | "check";
6
+
7
+ type Spawn = typeof nanoSpawn;
8
+
9
+ type Tool = "black" | "black --check" | "basedpyright";
10
+
11
+ const pinHint = "uv is pinned in .tool-versions; `make configure` installs it through mise or asdf";
12
+
13
+ function errorDetail(error: unknown): {
14
+ code?: string;
15
+ exitCode?: number;
16
+ signalName?: string;
17
+ stderr?: string;
18
+ message: string;
19
+ } {
20
+ const e = (error ?? {}) as {
21
+ cause?: { code?: string; message?: string };
22
+ exitCode?: number;
23
+ signalName?: string;
24
+ stderr?: string;
25
+ message?: string;
26
+ };
27
+ return {
28
+ code: e.cause?.code,
29
+ exitCode: e.exitCode,
30
+ signalName: e.signalName,
31
+ stderr: e.stderr?.trim() || undefined,
32
+ message: e.cause?.message ?? e.message ?? String(error),
33
+ };
34
+ }
35
+
36
+ /** Why `uv --version` did not answer, as one line for the lint output. */
37
+ export function uvStartFailure(error: unknown): string {
38
+ const d = errorDetail(error);
39
+ if (d.code === "ENOENT") return `uv is not on PATH. ${pinHint}.`;
40
+ const why = d.stderr ?? d.message;
41
+ return `uv did not start: ${why}. ${pinHint}.`;
42
+ }
43
+
44
+ /** Why a tool failed once uv had started it, as one line for the lint output. */
45
+ export function toolFailure(tool: Tool, error: unknown): string {
46
+ const d = errorDetail(error);
47
+ if (d.signalName) return `${tool} was killed by ${d.signalName}.`;
48
+ if (d.exitCode === 1 && tool === "black --check")
49
+ return "black --check found files to reformat (listed above).";
50
+ if (d.exitCode === 1 && tool === "basedpyright")
51
+ return "basedpyright found errors .basedpyright/baseline.json does not hold (listed above).";
52
+ if (d.exitCode !== undefined)
53
+ return `${tool} exited ${d.exitCode}, a configuration or usage error (see above).`;
54
+ return `${tool} failed: ${d.message}.`;
55
+ }
56
+
57
+ /**
58
+ * The Python files git knows under `cwd`, tracked or untracked and not
59
+ * ignored, that are still on disk: the set CI's frappe/lint job checks.
60
+ */
61
+ export async function pythonFiles(cwd: string, spawn: Spawn = nanoSpawn): Promise<string[]> {
62
+ const { stdout } = await spawn(
63
+ "git",
64
+ ["ls-files", "-z", "--cached", "--others", "--exclude-standard", "--", "*.py", "*.pyi"],
65
+ { cwd },
66
+ );
67
+ const listed = new Set(stdout.split("\0").filter(Boolean));
68
+ return [...listed].filter((file) => fsSync.existsSync(path.join(cwd, file)));
69
+ }
70
+
71
+ /**
72
+ * Run black, or black --check then basedpyright, on `files` through the uv
73
+ * project at `cwd`, first proving uv starts and the lock is there, so a missing
74
+ * install or project is reported as that instead of as a lint failure. Returns
75
+ * the reasons it failed, one per line, or undefined when it passed.
76
+ */
77
+ export async function runPythonTools(
78
+ mode: PythonMode,
79
+ files: readonly string[],
80
+ cwd: string,
81
+ spawn: Spawn = nanoSpawn,
82
+ ): Promise<string | undefined> {
83
+ try {
84
+ await spawn("uv", ["--version"], { cwd });
85
+ } catch (error) {
86
+ return uvStartFailure(error);
87
+ }
88
+ if (!fsSync.existsSync(path.join(cwd, "uv.lock")))
89
+ return "No uv.lock at the project root pins black and basedpyright; `mpo update` brings it and pyproject.toml.";
90
+ const steps: [Tool, string[]][] =
91
+ mode === "format"
92
+ ? [["black", ["black"]]]
93
+ : [
94
+ ["black --check", ["black", "--check"]],
95
+ ["basedpyright", ["basedpyright"]],
96
+ ];
97
+ const reasons: string[] = [];
98
+ for (const [tool, args] of steps) {
99
+ try {
100
+ await spawn("uv", ["run", "--locked", ...args, ...files], { stdio: "inherit", cwd });
101
+ } catch (error) {
102
+ reasons.push(toolFailure(tool, error));
103
+ }
104
+ }
105
+ return reasons.length > 0 ? reasons.join("\n") : undefined;
106
+ }
@@ -78,33 +78,36 @@ async function getTurboExcludeFiltersForMissing(root: string): Promise<string[]>
78
78
  return filters;
79
79
  }
80
80
 
81
+ type FrappeEntry = string | { name?: string; source?: string };
82
+ type FrappeApp = { name: string; absolutePath: string };
83
+
84
+ function frappeEntryName(entry: FrappeEntry): { src: string; name: string } | undefined {
85
+ if (typeof entry === "string") return { src: entry, name: path.basename(entry) };
86
+ if (!entry.source || !entry.name) return undefined;
87
+ return { src: entry.source, name: entry.name };
88
+ }
89
+
90
+ function resolveFrappeApp(frappeDir: string, entry: FrappeEntry): FrappeApp | undefined {
91
+ const named = frappeEntryName(entry);
92
+ if (!named) return undefined;
93
+ const src = named.src.startsWith("file://") ? named.src.slice(7) : named.src;
94
+ if (!src.startsWith("./") && !src.startsWith("../") && !src.startsWith("/")) return undefined;
95
+ const absolutePath = path.isAbsolute(src) ? src : path.resolve(frappeDir, src);
96
+ if (!fsSync.existsSync(absolutePath)) return undefined;
97
+ return { name: named.name, absolutePath };
98
+ }
99
+
81
100
  /** Discover frappe apps from frappe.yaml that have local source paths.
82
101
  * Supports both string entries (`- ./apps/core`) and object entries (`- name: core\n source: ./apps/core`). */
83
- async function getFrappeApps(root: string): Promise<{ name: string; absolutePath: string }[]> {
102
+ async function getFrappeApps(root: string): Promise<FrappeApp[]> {
84
103
  const frappeDir = path.join(root, "apps", "frappe");
85
104
  const frappeYamlPath = path.join(frappeDir, "frappe.yaml");
86
105
  if (!fsSync.existsSync(frappeYamlPath)) return [];
87
106
  const raw = await fs.readFile(frappeYamlPath, "utf8");
88
- const config = YAML.parse(raw) as { apps?: (string | { name?: string; source?: string })[] };
89
- const out: { name: string; absolutePath: string }[] = [];
90
- for (const app of config?.apps ?? []) {
91
- let src: string;
92
- let name: string;
93
- if (typeof app === "string") {
94
- src = app;
95
- name = path.basename(app);
96
- } else {
97
- if (!app.source || !app.name) continue;
98
- src = app.source;
99
- name = app.name;
100
- }
101
- src = src.startsWith("file://") ? src.slice(7) : src;
102
- if (!src.startsWith("./") && !src.startsWith("../") && !src.startsWith("/")) continue;
103
- const absPath = path.isAbsolute(src) ? src : path.resolve(frappeDir, src);
104
- if (!fsSync.existsSync(absPath)) continue;
105
- out.push({ name, absolutePath: absPath });
106
- }
107
- return out;
107
+ const config = YAML.parse(raw) as { apps?: FrappeEntry[] };
108
+ return (config?.apps ?? [])
109
+ .map((entry) => resolveFrappeApp(frappeDir, entry))
110
+ .filter((app): app is FrappeApp => app !== undefined);
108
111
  }
109
112
 
110
113
  export const testTiers = ["unit", "integration", "e2e", "visual"] as const;
@@ -0,0 +1,22 @@
1
+ import nanoSpawn from "nano-spawn";
2
+ export type PythonMode = "format" | "check";
3
+ type Spawn = typeof nanoSpawn;
4
+ type Tool = "black" | "black --check" | "basedpyright";
5
+ /** Why `uv --version` did not answer, as one line for the lint output. */
6
+ export declare function uvStartFailure(error: unknown): string;
7
+ /** Why a tool failed once uv had started it, as one line for the lint output. */
8
+ export declare function toolFailure(tool: Tool, error: unknown): string;
9
+ /**
10
+ * The Python files git knows under `cwd`, tracked or untracked and not
11
+ * ignored, that are still on disk: the set CI's frappe/lint job checks.
12
+ */
13
+ export declare function pythonFiles(cwd: string, spawn?: Spawn): Promise<string[]>;
14
+ /**
15
+ * Run black, or black --check then basedpyright, on `files` through the uv
16
+ * project at `cwd`, first proving uv starts and the lock is there, so a missing
17
+ * install or project is reported as that instead of as a lint failure. Returns
18
+ * the reasons it failed, one per line, or undefined when it passed.
19
+ */
20
+ export declare function runPythonTools(mode: PythonMode, files: readonly string[], cwd: string, spawn?: Spawn): Promise<string | undefined>;
21
+ export {};
22
+ //# sourceMappingURL=pythonTools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pythonTools.d.ts","sourceRoot":"","sources":["../../src/commands/pythonTools.ts"],"names":[],"mappings":"AAEA,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE5C,KAAK,KAAK,GAAG,OAAO,SAAS,CAAC;AAE9B,KAAK,IAAI,GAAG,OAAO,GAAG,eAAe,GAAG,cAAc,CAAC;AA2BvD,0EAA0E;AAC1E,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAKrD;AAED,iFAAiF;AACjF,wBAAgB,WAAW,CAAC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAU9D;AAED;;;GAGG;AACH,wBAAsB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,GAAE,KAAiB,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAQ1F;AAED;;;;;GAKG;AACH,wBAAsB,cAAc,CAClC,IAAI,EAAE,UAAU,EAChB,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,GAAG,EAAE,MAAM,EACX,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAwB7B"}
@@ -1 +1 @@
1
- {"version":3,"file":"verbs.d.ts","sourceRoot":"","sources":["../../src/commands/verbs.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,WAAW,EAKjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,SAAS,MAAM,YAAY,CAAC;AAGnC,KAAK,KAAK,GAAG,OAAO,SAAS,CAAC;AAE9B,eAAO,MAAM,iBAAiB,UAA0C,CAAC;AA8FzE,eAAO,MAAM,SAAS,mDAAoD,CAAC;AAE3E,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAElD,8FAA8F;AAC9F,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAQzD;AA2CD,gGAAgG;AAChG,wBAAsB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,GAAE,KAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAS/F;AAED,2HAA2H;AAC3H,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CAmBf;AAED,wFAAwF;AACxF,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,EAAE,EACd,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CA4Cf;AAED,sFAAsF;AACtF,wBAAsB,YAAY,CAChC,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED,0GAA0G;AAC1G,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EAAE,EACd,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,0DAA0D;AAC1D,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAKlF,CAAC"}
1
+ {"version":3,"file":"verbs.d.ts","sourceRoot":"","sources":["../../src/commands/verbs.ts"],"names":[],"mappings":"AAGA,OAAO,EACL,KAAK,WAAW,EAKjB,MAAM,8BAA8B,CAAC;AACtC,OAAO,SAAS,MAAM,YAAY,CAAC;AAGnC,KAAK,KAAK,GAAG,OAAO,SAAS,CAAC;AAE9B,eAAO,MAAM,iBAAiB,UAA0C,CAAC;AAiGzE,eAAO,MAAM,SAAS,mDAAoD,CAAC;AAE3E,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,SAAS,CAAC,CAAC,MAAM,CAAC,CAAC;AAElD,8FAA8F;AAC9F,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,QAAQ,EAAE,CAQzD;AA2CD,gGAAgG;AAChG,wBAAsB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,GAAE,KAAiB,GAAG,OAAO,CAAC,IAAI,CAAC,CAS/F;AAED,2HAA2H;AAC3H,wBAAsB,mBAAmB,CACvC,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CAmBf;AAED,wFAAwF;AACxF,wBAAsB,QAAQ,CAC5B,IAAI,EAAE,MAAM,EAAE,EACd,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CA4Cf;AAED,sFAAsF;AACtF,wBAAsB,YAAY,CAChC,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED,0GAA0G;AAC1G,wBAAsB,cAAc,CAClC,IAAI,EAAE,MAAM,EAAE,EACd,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,MAAM,EACnB,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,IAAI,CAAC,CAEf;AAED,0DAA0D;AAC1D,eAAO,MAAM,aAAa,EAAE,MAAM,CAAC,WAAW,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAKlF,CAAC"}
@@ -1,52 +0,0 @@
1
- import spawn from "nano-spawn";
2
-
3
- //#region src/commands/ruff.ts
4
- const pinHint = "ruff is pinned in .tool-versions; `make configure` installs it through mise or asdf";
5
- function errorDetail(error) {
6
- const e = error ?? {};
7
- return {
8
- code: e.cause?.code,
9
- exitCode: e.exitCode,
10
- signalName: e.signalName,
11
- stderr: e.stderr?.trim() || void 0,
12
- message: e.cause?.message ?? e.message ?? String(error)
13
- };
14
- }
15
- /** Why `ruff --version` did not answer, as one line for the lint output. */
16
- function ruffStartFailure(error) {
17
- const d = errorDetail(error);
18
- if (d.code === "ENOENT") return `ruff is not on PATH. ${pinHint}.`;
19
- return `ruff did not start: ${d.stderr ?? d.message}. ${pinHint}.`;
20
- }
21
- /** Why `ruff <mode>` failed once it had started, as one line for the lint output. */
22
- function ruffRunFailure(mode, target, error) {
23
- const d = errorDetail(error);
24
- if (d.signalName) return `ruff ${mode} was killed by ${d.signalName}.`;
25
- if (d.exitCode === 1 && mode === "check") return `ruff check found problems in ${target} (listed above).`;
26
- if (d.exitCode !== void 0) return `ruff ${mode} exited ${d.exitCode}, a configuration or usage error (see above).`;
27
- return `ruff ${mode} failed: ${d.message}.`;
28
- }
29
- /**
30
- * Run ruff format or check on `target`, first proving ruff starts so a missing
31
- * or broken install is reported as that instead of as a lint failure. Returns
32
- * the reason it failed, or undefined when it passed.
33
- */
34
- async function runRuff(mode, target, cwd, spawn$1 = spawn) {
35
- try {
36
- await spawn$1("ruff", ["--version"], { cwd });
37
- } catch (error) {
38
- return ruffStartFailure(error);
39
- }
40
- try {
41
- await spawn$1("ruff", [mode, target], {
42
- stdio: "inherit",
43
- cwd
44
- });
45
- return;
46
- } catch (error) {
47
- return ruffRunFailure(mode, target, error);
48
- }
49
- }
50
-
51
- //#endregion
52
- export { ruffRunFailure, ruffStartFailure, runRuff };
@@ -1,46 +0,0 @@
1
- import nanoSpawn from "nano-spawn";
2
- import { describe, expect, it } from "vitest";
3
- import { runRuff } from "./ruff";
4
-
5
- type Spawn = typeof nanoSpawn;
6
-
7
- // Runs a real subprocess in place of ruff, so the errors are nano-spawn's own.
8
- function standIn(script: (args: readonly string[]) => string): Spawn {
9
- return ((_file: string, args: readonly string[] = [], options = {}) =>
10
- nanoSpawn("sh", ["-c", script(args)], options)) as Spawn;
11
- }
12
-
13
- describe("runRuff (MPO-497)", () => {
14
- it("names a missing ruff and the pin that provides it", async () => {
15
- const missing = ((_file: string, args: readonly string[] = [], options = {}) =>
16
- nanoSpawn("mpo-497-no-such-ruff", [...args], options)) as Spawn;
17
- const reason = await runRuff("check", "apps/frappe/apps", process.cwd(), missing);
18
- expect(reason).toMatch(/^ruff is not on PATH\./);
19
- expect(reason).toContain(".tool-versions");
20
- expect(reason).toContain("make configure");
21
- });
22
-
23
- it("reports a ruff that will not start with what it printed", async () => {
24
- const shim = standIn(() => "echo 'mise ERROR No version is set for shim: ruff' >&2; exit 1");
25
- const reason = await runRuff("check", "apps/frappe/apps", process.cwd(), shim);
26
- expect(reason).toBe(
27
- "ruff did not start: mise ERROR No version is set for shim: ruff. ruff is pinned in .tool-versions; `make configure` installs it through mise or asdf.",
28
- );
29
- });
30
-
31
- it("separates findings from a configuration error", async () => {
32
- const findings = standIn((args) => (args[0] === "--version" ? "true" : "exit 1"));
33
- expect(await runRuff("check", "apps/frappe/apps", process.cwd(), findings)).toBe(
34
- "ruff check found problems in apps/frappe/apps (listed above).",
35
- );
36
- const broken = standIn((args) => (args[0] === "--version" ? "true" : "exit 2"));
37
- expect(await runRuff("check", "apps/frappe/apps", process.cwd(), broken)).toBe(
38
- "ruff check exited 2, a configuration or usage error (see above).",
39
- );
40
- });
41
-
42
- it("passes when ruff starts and exits 0", async () => {
43
- const clean = standIn(() => "true");
44
- expect(await runRuff("check", "apps/frappe/apps", process.cwd(), clean)).toBeUndefined();
45
- });
46
- });
@@ -1,74 +0,0 @@
1
- import nanoSpawn from "nano-spawn";
2
-
3
- export type RuffMode = "format" | "check";
4
-
5
- type Spawn = typeof nanoSpawn;
6
-
7
- const pinHint =
8
- "ruff is pinned in .tool-versions; `make configure` installs it through mise or asdf";
9
-
10
- function errorDetail(error: unknown): {
11
- code?: string;
12
- exitCode?: number;
13
- signalName?: string;
14
- stderr?: string;
15
- message: string;
16
- } {
17
- const e = (error ?? {}) as {
18
- cause?: { code?: string; message?: string };
19
- exitCode?: number;
20
- signalName?: string;
21
- stderr?: string;
22
- message?: string;
23
- };
24
- return {
25
- code: e.cause?.code,
26
- exitCode: e.exitCode,
27
- signalName: e.signalName,
28
- stderr: e.stderr?.trim() || undefined,
29
- message: e.cause?.message ?? e.message ?? String(error),
30
- };
31
- }
32
-
33
- /** Why `ruff --version` did not answer, as one line for the lint output. */
34
- export function ruffStartFailure(error: unknown): string {
35
- const d = errorDetail(error);
36
- if (d.code === "ENOENT") return `ruff is not on PATH. ${pinHint}.`;
37
- const why = d.stderr ?? d.message;
38
- return `ruff did not start: ${why}. ${pinHint}.`;
39
- }
40
-
41
- /** Why `ruff <mode>` failed once it had started, as one line for the lint output. */
42
- export function ruffRunFailure(mode: RuffMode, target: string, error: unknown): string {
43
- const d = errorDetail(error);
44
- if (d.signalName) return `ruff ${mode} was killed by ${d.signalName}.`;
45
- if (d.exitCode === 1 && mode === "check")
46
- return `ruff check found problems in ${target} (listed above).`;
47
- if (d.exitCode !== undefined)
48
- return `ruff ${mode} exited ${d.exitCode}, a configuration or usage error (see above).`;
49
- return `ruff ${mode} failed: ${d.message}.`;
50
- }
51
-
52
- /**
53
- * Run ruff format or check on `target`, first proving ruff starts so a missing
54
- * or broken install is reported as that instead of as a lint failure. Returns
55
- * the reason it failed, or undefined when it passed.
56
- */
57
- export async function runRuff(
58
- mode: RuffMode,
59
- target: string,
60
- cwd: string,
61
- spawn: Spawn = nanoSpawn,
62
- ): Promise<string | undefined> {
63
- try {
64
- await spawn("ruff", ["--version"], { cwd });
65
- } catch (error) {
66
- return ruffStartFailure(error);
67
- }
68
- try {
69
- await spawn("ruff", [mode, target], { stdio: "inherit", cwd });
70
- return undefined;
71
- } catch (error) {
72
- return ruffRunFailure(mode, target, error);
73
- }
74
- }
@@ -1,15 +0,0 @@
1
- import nanoSpawn from "nano-spawn";
2
- export type RuffMode = "format" | "check";
3
- type Spawn = typeof nanoSpawn;
4
- /** Why `ruff --version` did not answer, as one line for the lint output. */
5
- export declare function ruffStartFailure(error: unknown): string;
6
- /** Why `ruff <mode>` failed once it had started, as one line for the lint output. */
7
- export declare function ruffRunFailure(mode: RuffMode, target: string, error: unknown): string;
8
- /**
9
- * Run ruff format or check on `target`, first proving ruff starts so a missing
10
- * or broken install is reported as that instead of as a lint failure. Returns
11
- * the reason it failed, or undefined when it passed.
12
- */
13
- export declare function runRuff(mode: RuffMode, target: string, cwd: string, spawn?: Spawn): Promise<string | undefined>;
14
- export {};
15
- //# sourceMappingURL=ruff.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ruff.d.ts","sourceRoot":"","sources":["../../src/commands/ruff.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,MAAM,YAAY,CAAC;AAEnC,MAAM,MAAM,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAC;AAE1C,KAAK,KAAK,GAAG,OAAO,SAAS,CAAC;AA4B9B,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAKvD;AAED,qFAAqF;AACrF,wBAAgB,cAAc,CAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,MAAM,CAQrF;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAC3B,IAAI,EAAE,QAAQ,EACd,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,KAAK,GAAE,KAAiB,GACvB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAY7B"}