@pylair/cli 0.1.0-rc.20 → 0.1.0-rc.21

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.
@@ -0,0 +1,33 @@
1
+ /** Wrap-mode pieces of `pylair dev`, `pylair build` and `pylair doctor`:
2
+ * what to import to prove the framework survived pruning, the runtime file
3
+ * the plugin reads, and what to stage.
4
+ */
5
+ import type { PylairConfig } from "./config.js";
6
+ import { type WrapConfig } from "./wrapconfig.js";
7
+ /** The directory the app is staged into inside the bundle, whatever the
8
+ * source dir is called. Fixed so `tauri.conf.json` never needs editing when
9
+ * `source` changes (`"resources/app": "app/"`). */
10
+ export declare const STAGED_APP = "app";
11
+ /** Top-level names never staged when the source dir is the project root
12
+ * (`source = "."`): the project's own tooling, not the app. */
13
+ export declare const ROOT_SOURCE_EXCLUDES: string[];
14
+ /** `python -m uvicorn ...` style: the module a `command` runs, if it is run
15
+ * with the interpreter's `-m`. */
16
+ export declare function commandModule(cmd: string[] | undefined): string | undefined;
17
+ /** What to import to show the bundle can run: the launcher itself
18
+ * (`pylair.wrap`, which must be one of the app's dependencies: the supervisor
19
+ * starts `python -m pylair.wrap`), and the framework: gradio and streamlit by
20
+ * name; for `command`, the `-m` module when there is one. */
21
+ export declare function smokeImports(w: WrapConfig): string[];
22
+ /** Run the imports with `python`. Returns the failure text, or undefined
23
+ * when every import worked (or there was nothing to import). */
24
+ export declare function runSmokeImports(python: string, mods: string[], env: Record<string, string>, cwd: string): string | undefined;
25
+ /** Write the file the plugin reads at startup. */
26
+ export declare function writeRuntimeFile(path: string, cfg: PylairConfig, source: string): void;
27
+ /** `tauri dev` validates every `bundle.resources` path eagerly, but they
28
+ * only exist after `pylair build`: make placeholders (a dir, or an empty
29
+ * object for a `.json` file). `pylair build` replaces them. */
30
+ export declare function ensureDevResources(appDir: string, keys: string[]): void;
31
+ /** Is `source` the project root itself? */
32
+ export declare function sourceIsRoot(appDir: string, source: string): boolean;
33
+ //# sourceMappingURL=wrapbuild.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapbuild.d.ts","sourceRoot":"","sources":["../src/wrapbuild.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAKH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAiB,KAAK,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAEjE;;mDAEmD;AACnD,eAAO,MAAM,UAAU,QAAQ,CAAC;AAEhC;+DAC+D;AAC/D,eAAO,MAAM,oBAAoB,UAAwD,CAAC;AAE1F;kCACkC;AAClC,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAO3E;AAED;;;6DAG6D;AAC7D,wBAAgB,YAAY,CAAC,CAAC,EAAE,UAAU,GAAG,MAAM,EAAE,CAMpD;AAED;gEACgE;AAChE,wBAAgB,eAAe,CAC7B,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EAAE,EACd,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,EAC3B,GAAG,EAAE,MAAM,GACV,MAAM,GAAG,SAAS,CAOpB;AAED,kDAAkD;AAClD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,CAItF;AAED;;+DAE+D;AAC/D,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,CAWvE;AAED,2CAA2C;AAC3C,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAEpE"}
@@ -0,0 +1,83 @@
1
+ /** Wrap-mode pieces of `pylair dev`, `pylair build` and `pylair doctor`:
2
+ * what to import to prove the framework survived pruning, the runtime file
3
+ * the plugin reads, and what to stage.
4
+ */
5
+ import { spawnSync } from "node:child_process";
6
+ import { existsSync, mkdirSync, writeFileSync } from "node:fs";
7
+ import { dirname, join, resolve } from "node:path";
8
+ import { runtimeConfig } from "./wrapconfig.js";
9
+ /** The directory the app is staged into inside the bundle, whatever the
10
+ * source dir is called. Fixed so `tauri.conf.json` never needs editing when
11
+ * `source` changes (`"resources/app": "app/"`). */
12
+ export const STAGED_APP = "app";
13
+ /** Top-level names never staged when the source dir is the project root
14
+ * (`source = "."`): the project's own tooling, not the app. */
15
+ export const ROOT_SOURCE_EXCLUDES = ["src-tauri", "node_modules", "ui", "dist", "target"];
16
+ /** `python -m uvicorn ...` style: the module a `command` runs, if it is run
17
+ * with the interpreter's `-m`. */
18
+ export function commandModule(cmd) {
19
+ if (!cmd || cmd.length < 3)
20
+ return undefined;
21
+ const prog = cmd[0].replace(/\\/g, "/").split("/").pop().toLowerCase().replace(/\.exe$/, "");
22
+ if (!/^python(\d+(\.\d+)*)?$/.test(prog))
23
+ return undefined;
24
+ if (cmd[1] !== "-m")
25
+ return undefined;
26
+ const mod = cmd[2];
27
+ return /^[A-Za-z_][A-Za-z0-9_.]*$/.test(mod) ? mod : undefined;
28
+ }
29
+ /** What to import to show the bundle can run: the launcher itself
30
+ * (`pylair.wrap`, which must be one of the app's dependencies: the supervisor
31
+ * starts `python -m pylair.wrap`), and the framework: gradio and streamlit by
32
+ * name; for `command`, the `-m` module when there is one. */
33
+ export function smokeImports(w) {
34
+ const launcher = "pylair.wrap";
35
+ if (w.framework === "gradio")
36
+ return [launcher, "gradio"];
37
+ if (w.framework === "streamlit")
38
+ return [launcher, "streamlit"];
39
+ const m = commandModule(w.cmd);
40
+ return m ? [launcher, m] : [launcher];
41
+ }
42
+ /** Run the imports with `python`. Returns the failure text, or undefined
43
+ * when every import worked (or there was nothing to import). */
44
+ export function runSmokeImports(python, mods, env, cwd) {
45
+ if (!mods.length)
46
+ return undefined;
47
+ const code = mods.map((m) => `import ${m}`).join("; ") + `; print("imports ok")`;
48
+ const r = spawnSync(python, ["-c", code], { encoding: "utf-8", cwd, env: { ...process.env, ...env } });
49
+ if (r.error)
50
+ return `could not run ${python}: ${r.error.message}`;
51
+ if (r.status === 0)
52
+ return undefined;
53
+ return (r.stderr || r.stdout || `exit ${r.status}`).trim().split(/\r?\n/).slice(-3).join(" | ");
54
+ }
55
+ /** Write the file the plugin reads at startup. */
56
+ export function writeRuntimeFile(path, cfg, source) {
57
+ if (!cfg.wrap)
58
+ throw new Error("not a wrap-mode app");
59
+ mkdirSync(dirname(path), { recursive: true });
60
+ writeFileSync(path, JSON.stringify(runtimeConfig(cfg.wrap, source), null, 2) + "\n");
61
+ }
62
+ /** `tauri dev` validates every `bundle.resources` path eagerly, but they
63
+ * only exist after `pylair build`: make placeholders (a dir, or an empty
64
+ * object for a `.json` file). `pylair build` replaces them. */
65
+ export function ensureDevResources(appDir, keys) {
66
+ for (const rel of keys) {
67
+ const p = join(appDir, "src-tauri", rel);
68
+ if (existsSync(p))
69
+ continue;
70
+ if (rel.endsWith(".json")) {
71
+ mkdirSync(dirname(p), { recursive: true });
72
+ writeFileSync(p, "{}\n");
73
+ }
74
+ else {
75
+ mkdirSync(p, { recursive: true });
76
+ }
77
+ }
78
+ }
79
+ /** Is `source` the project root itself? */
80
+ export function sourceIsRoot(appDir, source) {
81
+ return resolve(appDir, source) === resolve(appDir);
82
+ }
83
+ //# sourceMappingURL=wrapbuild.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapbuild.js","sourceRoot":"","sources":["../src/wrapbuild.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEnD,OAAO,EAAE,aAAa,EAAmB,MAAM,iBAAiB,CAAC;AAEjE;;mDAEmD;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AI,EAAE,CAAC,CAAC;IAC9C,aAAa,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;AACvF,CAAC;AAED;;+DAE+D;AAC/D,MAAM,UAAU,kBAAkB,CAAC,MAAc,EAAE,IAAc;IAC/D,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,MAAM,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,WAAW,EAAE,GAAG,CAAC,CAAC;QACzC,IAAI,UAAU,CAAC,CAAC,CAAC;YAAE,SAAS;QAC5B,IAAI,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;YAC1B,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;YAC3C,aAAa,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QAC3B,CAAC;aAAM,CAAC;YACN,SAAS,CAAC,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC;QACpC,CAAC;IACH,CAAC;AACH,CAAC;AAED,2CAA2C;AAC3C,MAAM,UAAU,YAAY,CAAC,MAAc,EAAE,MAAc;IACzD,OAAO,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,OAAO,CAAC,MAAM,CAAC,CAAC;AACrD,CAAC"}
@@ -0,0 +1,52 @@
1
+ /** `[tool.pylair.wrap]` parsing and validation (wrap mode, W2).
2
+ *
3
+ * Wrap mode shows an existing Python web UI in the window. The config here
4
+ * is the single source of truth: `pylair dev` and `pylair build` turn it
5
+ * into the launcher command line (`launcherArgs`) and the runtime file the
6
+ * plugin reads (`runtimeConfig`).
7
+ */
8
+ export type Mode = "bridge" | "wrap";
9
+ export declare const MODES: readonly Mode[];
10
+ export type WrapFramework = "command" | "gradio" | "streamlit";
11
+ export declare const WRAP_FRAMEWORKS: readonly WrapFramework[];
12
+ /** Where a download from the wrapped page goes: a native Save As dialog
13
+ * (default) or straight into the user's Downloads folder. */
14
+ export type DownloadMode = "ask" | "downloads";
15
+ export interface WrapConfig {
16
+ framework: WrapFramework;
17
+ /** gradio / streamlit: the app's entry file, relative to `source`. */
18
+ entry?: string;
19
+ /** command: argv of the server; `{port}` is replaced by the launcher. */
20
+ cmd?: string[];
21
+ /** Path probed for readiness and health. Unset means the launcher's own
22
+ * per-framework default ("/" for command, /config for gradio,
23
+ * /_stcore/health for streamlit), which is picked so a slow first page is
24
+ * never a probe miss; setting it here overrides that. */
25
+ readyPath?: string;
26
+ /** Seconds the supervisor waits for the server to answer (default 120). */
27
+ readyTimeout: number;
28
+ downloads: DownloadMode;
29
+ }
30
+ /** Validate a raw `[tool.pylair.wrap]` table. Every message names the key
31
+ * and what is allowed: this is the first thing a new wrap user reads. */
32
+ export declare function parseWrapConfig(raw: unknown, pyproject?: string): WrapConfig;
33
+ /** Findings about a valid wrap config that do not stop a build (printed by
34
+ * `pylair doctor`, `dev` and `build`). */
35
+ export declare function wrapWarnings(w: WrapConfig): string[];
36
+ /** The launcher command line for this config, minus the interpreter:
37
+ * `python -m pylair.wrap --framework F [--entry E] [--cmd ...] --ready-path P`.
38
+ * Launcher options come before `--cmd`, so the command's own arguments can
39
+ * never be mistaken for launcher options (docs/protocol-v1.md section 4.1). */
40
+ export declare function launcherArgs(w: WrapConfig): string[];
41
+ /** What the plugin reads at startup: `<resources>/pylair-wrap.json` in a
42
+ * packaged app, the file `PYLAIR_WRAP_CONFIG` names under `pylair dev`.
43
+ * `source` is the staged source dir, which the server runs in. */
44
+ export interface WrapRuntime {
45
+ version: 1;
46
+ source: string;
47
+ launcher: string[];
48
+ readyTimeoutSecs: number;
49
+ downloads: DownloadMode;
50
+ }
51
+ export declare function runtimeConfig(w: WrapConfig, source: string): WrapRuntime;
52
+ //# sourceMappingURL=wrapconfig.d.ts.map
@@ -0,0 +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AAE,MAAM,GAAG,WAAW,CAQxE"}
@@ -0,0 +1,117 @@
1
+ /** `[tool.pylair.wrap]` parsing and validation (wrap mode, W2).
2
+ *
3
+ * Wrap mode shows an existing Python web UI in the window. The config here
4
+ * is the single source of truth: `pylair dev` and `pylair build` turn it
5
+ * into the launcher command line (`launcherArgs`) and the runtime file the
6
+ * plugin reads (`runtimeConfig`).
7
+ */
8
+ export const MODES = ["bridge", "wrap"];
9
+ export const WRAP_FRAMEWORKS = ["command", "gradio", "streamlit"];
10
+ const WRAP_KEYS = ["framework", "entry", "cmd", "ready-path", "ready-timeout", "downloads"];
11
+ function err(pyproject, msg) {
12
+ return new Error(`[tool.pylair.wrap] ${msg} (${pyproject})`);
13
+ }
14
+ /** Validate a raw `[tool.pylair.wrap]` table. Every message names the key
15
+ * and what is allowed: this is the first thing a new wrap user reads. */
16
+ export function parseWrapConfig(raw, pyproject = "pyproject.toml") {
17
+ if (raw === undefined || raw === null)
18
+ throw new Error(`mode = "wrap" needs a [tool.pylair.wrap] table in ${pyproject}, e.g.\n` +
19
+ ` [tool.pylair.wrap]\n` +
20
+ ` framework = "command"\n` +
21
+ ` cmd = ["python", "-m", "myapp", "--port", "{port}"]`);
22
+ if (typeof raw !== "object" || Array.isArray(raw))
23
+ throw err(pyproject, "must be a table");
24
+ const t = raw;
25
+ const unknown = Object.keys(t).filter((k) => !WRAP_KEYS.includes(k));
26
+ if (unknown.length)
27
+ throw err(pyproject, `unknown key${unknown.length > 1 ? "s" : ""} ${unknown.map((k) => `"${k}"`).join(", ")}; ` +
28
+ `allowed: ${WRAP_KEYS.join(", ")}`);
29
+ const fw = t.framework;
30
+ if (fw === undefined)
31
+ throw err(pyproject, `framework is required (one of ${WRAP_FRAMEWORKS.join(", ")})`);
32
+ if (typeof fw !== "string" || !WRAP_FRAMEWORKS.includes(fw))
33
+ throw err(pyproject, `framework must be one of ${WRAP_FRAMEWORKS.map((f) => `"${f}"`).join(", ")}, got ${JSON.stringify(fw)}`);
34
+ const framework = fw;
35
+ let entry;
36
+ if (t.entry !== undefined) {
37
+ if (typeof t.entry !== "string" || !t.entry.trim())
38
+ throw err(pyproject, "entry must be a non-empty string");
39
+ entry = t.entry;
40
+ const norm = entry.replace(/\\/g, "/");
41
+ if (norm.startsWith("/") || /^[A-Za-z]:/.test(norm) || norm.split("/").includes(".."))
42
+ throw err(pyproject, `entry must be a path inside the source dir (no absolute path, no ".."): ${JSON.stringify(entry)}`);
43
+ }
44
+ let cmd;
45
+ if (t.cmd !== undefined) {
46
+ if (!Array.isArray(t.cmd) || t.cmd.length === 0 || t.cmd.some((a) => typeof a !== "string"))
47
+ throw err(pyproject, "cmd must be a non-empty array of strings (the server's argv)");
48
+ cmd = t.cmd;
49
+ if (!cmd[0].trim())
50
+ throw err(pyproject, "cmd[0] (the program) must not be empty");
51
+ }
52
+ if (framework === "command") {
53
+ if (!cmd)
54
+ throw err(pyproject, `framework "command" needs cmd = ["python", "-m", "myapp", "--port", "{port}"]`);
55
+ if (entry !== undefined)
56
+ throw err(pyproject, `entry is not used by framework "command" (use cmd)`);
57
+ }
58
+ else {
59
+ if (entry === undefined)
60
+ throw err(pyproject, `framework "${framework}" needs entry = "app.py" (the file to run)`);
61
+ if (cmd !== undefined)
62
+ throw err(pyproject, `cmd is only for framework "command"; "${framework}" runs entry`);
63
+ }
64
+ const readyPath = t["ready-path"];
65
+ if (readyPath !== undefined &&
66
+ (typeof readyPath !== "string" || !readyPath.startsWith("/") || /\s/.test(readyPath)))
67
+ throw err(pyproject, `ready-path must be a path starting with "/" and without spaces, got ${JSON.stringify(readyPath)}`);
68
+ const readyTimeout = t["ready-timeout"] ?? 120;
69
+ if (typeof readyTimeout !== "number" ||
70
+ !Number.isInteger(readyTimeout) ||
71
+ readyTimeout < 1 ||
72
+ readyTimeout > 3600)
73
+ throw err(pyproject, `ready-timeout must be a whole number of seconds from 1 to 3600, got ${JSON.stringify(readyTimeout)}`);
74
+ const downloads = t.downloads ?? "ask";
75
+ if (downloads !== "ask" && downloads !== "downloads")
76
+ throw err(pyproject, `downloads must be "ask" (Save As dialog) or "downloads" (straight to Downloads), got ${JSON.stringify(downloads)}`);
77
+ return { framework, entry, cmd, readyPath, readyTimeout, downloads };
78
+ }
79
+ /** Findings about a valid wrap config that do not stop a build (printed by
80
+ * `pylair doctor`, `dev` and `build`). */
81
+ export function wrapWarnings(w) {
82
+ const out = [];
83
+ if (w.framework === "command" && w.cmd) {
84
+ if (!w.cmd.some((a) => a.includes("{port}")))
85
+ out.push(`cmd has no "{port}": the server must read $PYLAIR_PORT, otherwise it listens ` +
86
+ `somewhere the window cannot reach`);
87
+ const bad = w.cmd.find((a) => a === "0.0.0.0" || a === "::" || a.endsWith("=0.0.0.0"));
88
+ if (bad)
89
+ out.push(`cmd binds ${bad}: the server would be reachable from the network. ` +
90
+ `Bind 127.0.0.1 (docs/security.md section 9)`);
91
+ }
92
+ return out;
93
+ }
94
+ /** The launcher command line for this config, minus the interpreter:
95
+ * `python -m pylair.wrap --framework F [--entry E] [--cmd ...] --ready-path P`.
96
+ * Launcher options come before `--cmd`, so the command's own arguments can
97
+ * never be mistaken for launcher options (docs/protocol-v1.md section 4.1). */
98
+ export function launcherArgs(w) {
99
+ const a = ["-m", "pylair.wrap", "--framework", w.framework];
100
+ if (w.entry !== undefined)
101
+ a.push("--entry", w.entry);
102
+ if (w.readyPath !== undefined)
103
+ a.push("--ready-path", w.readyPath);
104
+ if (w.cmd)
105
+ a.push("--cmd", ...w.cmd);
106
+ return a;
107
+ }
108
+ export function runtimeConfig(w, source) {
109
+ return {
110
+ version: 1,
111
+ source,
112
+ launcher: launcherArgs(w),
113
+ readyTimeoutSecs: w.readyTimeout,
114
+ downloads: w.downloads,
115
+ };
116
+ }
117
+ //# sourceMappingURL=wrapconfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wrapconfig.js","sourceRoot":"","sources":["../src/wrapconfig.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,MAAM,CAAC,MAAM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,aAAa,GAAG,oDAAoD;gBAClE,6CAA6C,CAChD,CAAC;IACN,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;+EAG+E;AAC/E,MAAM,UAAU,YAAY,CAAC,CAAa;IACxC,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,aAAa,EAAE,aAAa,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC;IAC5D,IAAI,CAAC,CAAC,KAAK,KAAK,SAAS;QAAE,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;IACtD,IAAI,CAAC,CAAC,SAAS,KAAK,SAAS;QAAE,CAAC,CAAC,IAAI,CAAC,cAAc,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC;IACnE,IAAI,CAAC,CAAC,GAAG;QAAE,CAAC,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IACrC,OAAO,CAAC,CAAC;AACX,CAAC;AAaD,MAAM,UAAU,aAAa,CAAC,CAAa,EAAE,MAAc;IACzD,OAAO;QACL,OAAO,EAAE,CAAC;QACV,MAAM;QACN,QAAQ,EAAE,YAAY,CAAC,CAAC,CAAC;QACzB,gBAAgB,EAAE,CAAC,CAAC,YAAY;QAChC,SAAS,EAAE,CAAC,CAAC,SAAS;KACvB,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pylair/cli",
3
- "version": "0.1.0-rc.20",
3
+ "version": "0.1.0-rc.21",
4
4
  "description": "Pylair CLI: dev, build, doctor, codegen",
5
5
  "license": "MIT OR Apache-2.0",
6
6
  "repository": {