@pylair/cli 0.1.0-rc.16 → 0.1.0-rc.18
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 +1 -1
- package/dist/build/bytecode.d.ts +29 -0
- package/dist/build/bytecode.d.ts.map +1 -0
- package/dist/build/bytecode.js +64 -0
- package/dist/build/bytecode.js.map +1 -0
- package/dist/build/download.d.ts +53 -0
- package/dist/build/download.d.ts.map +1 -0
- package/dist/build/download.js +326 -0
- package/dist/build/download.js.map +1 -0
- package/dist/build/notices.d.ts +10 -0
- package/dist/build/notices.d.ts.map +1 -0
- package/dist/build/notices.js +108 -0
- package/dist/build/notices.js.map +1 -0
- package/dist/build/pbs.d.ts +12 -0
- package/dist/build/pbs.d.ts.map +1 -0
- package/dist/build/pbs.js +36 -0
- package/dist/build/pbs.js.map +1 -0
- package/dist/build/python.d.ts +19 -0
- package/dist/build/python.d.ts.map +1 -0
- package/dist/build/python.js +109 -0
- package/dist/build/python.js.map +1 -0
- package/dist/build/sign.d.ts +4 -0
- package/dist/build/sign.d.ts.map +1 -0
- package/dist/build/sign.js +108 -0
- package/dist/build/sign.js.map +1 -0
- package/dist/build/source.d.ts +16 -0
- package/dist/build/source.d.ts.map +1 -0
- package/dist/build/source.js +85 -0
- package/dist/build/source.js.map +1 -0
- package/dist/build/util.d.ts +4 -0
- package/dist/build/util.d.ts.map +1 -0
- package/dist/build/util.js +12 -0
- package/dist/build/util.js.map +1 -0
- package/dist/build.d.ts +6 -77
- package/dist/build.d.ts.map +1 -1
- package/dist/build.js +34 -624
- package/dist/build.js.map +1 -1
- package/dist/cli.d.ts +5 -0
- package/dist/cli.d.ts.map +1 -1
- package/dist/cli.js +11 -4
- package/dist/cli.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -15,7 +15,7 @@ The installed command is `pylair` even though the package is scoped.
|
|
|
15
15
|
|
|
16
16
|
**Release candidate:** while there's no stable release, `latest`
|
|
17
17
|
tracks the newest RC — pin an exact version for reproducibility:
|
|
18
|
-
`npm i -D @pylair/cli@0.1.0-rc.
|
|
18
|
+
`npm i -D @pylair/cli@0.1.0-rc.18`.
|
|
19
19
|
Installers produced by `pylair build` are **unsigned** unless you
|
|
20
20
|
configure code signing — expect Gatekeeper/SmartScreen warnings.
|
|
21
21
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/** Precompiled bytecode for the staged Python tree (docs/build.md,
|
|
2
|
+
* "Precompiled bytecode"). */
|
|
3
|
+
/** pyc invalidation mode shipped in installers — see docs/build.md.
|
|
4
|
+
* checked-hash: installers rewrite mtimes, so timestamp pycs silently
|
|
5
|
+
* invalidate; hash-based headers survive repackaging. checked (not
|
|
6
|
+
* unchecked) re-validates the source hash per import — ~10ms slower on
|
|
7
|
+
* a numpy-sized tree but a post-install source edit recompiles instead
|
|
8
|
+
* of running stale bytecode. Measured (Windows, numpy tree):
|
|
9
|
+
* ~665ms no-pyc / ~267ms checked / ~256ms unchecked per cold import.
|
|
10
|
+
*/
|
|
11
|
+
export declare const PYC_INVALIDATION_MODE: "checked-hash";
|
|
12
|
+
/** Precompile the staged .py tree with the BUNDLED interpreter — same
|
|
13
|
+
* CPython and magic number as the runtime that will load the pycs.
|
|
14
|
+
* An installed app (possibly read-only) must not compile its Python on
|
|
15
|
+
* every launch. Runs post-prune so denied dirs stay uncompiled, and
|
|
16
|
+
* relative args + cwd keep co_filename bundle-relative: identical pycs
|
|
17
|
+
* regardless of build path, tracebacks show `site-packages/…`.
|
|
18
|
+
* `-s`/`-d` would also work; relative args are the smallest version of
|
|
19
|
+
* the same thing.
|
|
20
|
+
*
|
|
21
|
+
* Exit 1 from compileall means "some files failed to compile" — a
|
|
22
|
+
* dependency may ship a py2-only file or invalid fixture that nothing
|
|
23
|
+
* imports. That warns (paths returned) instead of failing the build;
|
|
24
|
+
* the files are left uncompiled and will compile — or fail to import —
|
|
25
|
+
* as normal at runtime. Real failures still throw: the interpreter
|
|
26
|
+
* not starting, a signal, or any other exit code. Returns the failed
|
|
27
|
+
* paths (empty on full success). */
|
|
28
|
+
export declare function compileBytecode(resources: string, python: string, dirs: string[]): string[];
|
|
29
|
+
//# sourceMappingURL=bytecode.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytecode.d.ts","sourceRoot":"","sources":["../../src/build/bytecode.ts"],"names":[],"mappings":"AAAA;8BAC8B;AAM9B;;;;;;;GAOG;AACH,eAAO,MAAM,qBAAqB,EAAG,cAAuB,CAAC;AAE7D;;;;;;;;;;;;;;;oCAeoC;AACpC,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,MAAM,EAAE,GACb,MAAM,EAAE,CAqCV"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/** Precompiled bytecode for the staged Python tree (docs/build.md,
|
|
2
|
+
* "Precompiled bytecode"). */
|
|
3
|
+
import { spawnSync } from "node:child_process";
|
|
4
|
+
import { existsSync } from "node:fs";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
/** pyc invalidation mode shipped in installers — see docs/build.md.
|
|
7
|
+
* checked-hash: installers rewrite mtimes, so timestamp pycs silently
|
|
8
|
+
* invalidate; hash-based headers survive repackaging. checked (not
|
|
9
|
+
* unchecked) re-validates the source hash per import — ~10ms slower on
|
|
10
|
+
* a numpy-sized tree but a post-install source edit recompiles instead
|
|
11
|
+
* of running stale bytecode. Measured (Windows, numpy tree):
|
|
12
|
+
* ~665ms no-pyc / ~267ms checked / ~256ms unchecked per cold import.
|
|
13
|
+
*/
|
|
14
|
+
export const PYC_INVALIDATION_MODE = "checked-hash";
|
|
15
|
+
/** Precompile the staged .py tree with the BUNDLED interpreter — same
|
|
16
|
+
* CPython and magic number as the runtime that will load the pycs.
|
|
17
|
+
* An installed app (possibly read-only) must not compile its Python on
|
|
18
|
+
* every launch. Runs post-prune so denied dirs stay uncompiled, and
|
|
19
|
+
* relative args + cwd keep co_filename bundle-relative: identical pycs
|
|
20
|
+
* regardless of build path, tracebacks show `site-packages/…`.
|
|
21
|
+
* `-s`/`-d` would also work; relative args are the smallest version of
|
|
22
|
+
* the same thing.
|
|
23
|
+
*
|
|
24
|
+
* Exit 1 from compileall means "some files failed to compile" — a
|
|
25
|
+
* dependency may ship a py2-only file or invalid fixture that nothing
|
|
26
|
+
* imports. That warns (paths returned) instead of failing the build;
|
|
27
|
+
* the files are left uncompiled and will compile — or fail to import —
|
|
28
|
+
* as normal at runtime. Real failures still throw: the interpreter
|
|
29
|
+
* not starting, a signal, or any other exit code. Returns the failed
|
|
30
|
+
* paths (empty on full success). */
|
|
31
|
+
export function compileBytecode(resources, python, dirs) {
|
|
32
|
+
const existing = dirs.filter((d) => existsSync(join(resources, d)));
|
|
33
|
+
if (!existing.length)
|
|
34
|
+
return [];
|
|
35
|
+
const r = spawnSync(python, [
|
|
36
|
+
"-m",
|
|
37
|
+
"compileall",
|
|
38
|
+
"-q",
|
|
39
|
+
"-f",
|
|
40
|
+
"-j",
|
|
41
|
+
"0",
|
|
42
|
+
"--invalidation-mode",
|
|
43
|
+
PYC_INVALIDATION_MODE,
|
|
44
|
+
...existing,
|
|
45
|
+
], { cwd: resources, encoding: "utf-8" });
|
|
46
|
+
if (r.error)
|
|
47
|
+
throw new Error(`${python} -m compileall failed to start: ${r.error.message}`);
|
|
48
|
+
if (r.signal || (r.status !== 0 && r.status !== 1)) {
|
|
49
|
+
throw new Error(`${python} -m compileall ${r.signal ? `died on ${r.signal}` : `exited ${r.status}`}`);
|
|
50
|
+
}
|
|
51
|
+
if (r.status === 0)
|
|
52
|
+
return [];
|
|
53
|
+
// Quiet mode still prints `*** Error compiling '<path>'...` per file.
|
|
54
|
+
const failed = [
|
|
55
|
+
...String(r.stderr).matchAll(/^\*\*\* Error compiling '([^']+)'/gm),
|
|
56
|
+
...String(r.stdout).matchAll(/^\*\*\* Error compiling '([^']+)'/gm),
|
|
57
|
+
].map((m) => m[1].replace(/\\\\/g, "\\")); // repr-escaped on Windows
|
|
58
|
+
const shown = failed.slice(0, 10).join("\n ");
|
|
59
|
+
console.warn(`warning: ${failed.length} file(s) failed to byte-compile and are left` +
|
|
60
|
+
` uncompiled — they will compile (or fail to import) as normal at` +
|
|
61
|
+
` runtime:\n ${shown}${failed.length > 10 ? `\n …and ${failed.length - 10} more` : ""}`);
|
|
62
|
+
return failed;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=bytecode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bytecode.js","sourceRoot":"","sources":["../../src/build/bytecode.ts"],"names":[],"mappings":"AAAA;8BAC8B;AAE9B,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAEjC;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,cAAuB,CAAC;AAE7D;;;;;;;;;;;;;;;oCAeoC;AACpC,MAAM,UAAU,eAAe,CAC7B,SAAiB,EACjB,MAAc,EACd,IAAc;IAEd,MAAM,QAAQ,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IACpE,IAAI,CAAC,QAAQ,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IAChC,MAAM,CAAC,GAAG,SAAS,CACjB,MAAM,EACN;QACE,IAAI;QACJ,YAAY;QACZ,IAAI;QACJ,IAAI;QACJ,IAAI;QACJ,GAAG;QACH,qBAAqB;QACrB,qBAAqB;QACrB,GAAG,QAAQ;KACZ,EACD,EAAE,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,CACtC,CAAC;IACF,IAAI,CAAC,CAAC,KAAK;QAAE,MAAM,IA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
1
|
+
/** The python-build-standalone download: retry with backoff, Range
|
|
2
|
+
* resume, progress, the no-data timeout, and the cache plus committed
|
|
3
|
+
* SHA-256 check (docs/build.md, "Slow or flaky networks"). */
|
|
4
|
+
import { get } from "node:https";
|
|
5
|
+
/** A download failure, plus whether trying again could plausibly help:
|
|
6
|
+
* stalls, socket errors, 5xx, 429 and short bodies can; a 404, a refused
|
|
7
|
+
* redirect or a redirect loop will fail the same way every time. */
|
|
8
|
+
export declare class DownloadError extends Error {
|
|
9
|
+
readonly retryable: boolean;
|
|
10
|
+
constructor(message: string, retryable: boolean, cause?: unknown);
|
|
11
|
+
}
|
|
12
|
+
/** The no-data timeout: 30s unless PYLAIR_DOWNLOAD_TIMEOUT_MS says
|
|
13
|
+
* otherwise, clamped to 5s..600s. A value that is not a whole number is an
|
|
14
|
+
* error, not a silent fallback, so a typo does not hide. */
|
|
15
|
+
export declare function downloadTimeoutMs(env?: NodeJS.ProcessEnv): number;
|
|
16
|
+
/** Delay before retry number `retry` (1-based), with jitter. */
|
|
17
|
+
export declare function backoffMs(retry: number, rand?: () => number): number;
|
|
18
|
+
/** Download `url` to `to`, following up to `maxRedirects` redirects and
|
|
19
|
+
* failing after `timeoutMs` with no bytes. The body lands in `to.part`
|
|
20
|
+
* and is renamed into place only once it is complete — a dropped
|
|
21
|
+
* connection must never leave a partial file at the cache path (the
|
|
22
|
+
* SHA check would then refuse every later build until it is deleted by
|
|
23
|
+
* hand). `get` is injectable so tests need no network. */
|
|
24
|
+
export declare function download(url: string, to: string, opts?: {
|
|
25
|
+
get?: typeof get;
|
|
26
|
+
timeoutMs?: number;
|
|
27
|
+
maxRedirects?: number;
|
|
28
|
+
/** Keep `<to>.part` on failure and continue it with a Range request. */
|
|
29
|
+
resume?: boolean;
|
|
30
|
+
/** Progress line sink (default stderr) and its minimum interval. */
|
|
31
|
+
progress?: (line: string) => void;
|
|
32
|
+
progressMs?: number;
|
|
33
|
+
/** Filled in as bytes arrive, for the caller's failure message. */
|
|
34
|
+
state?: {
|
|
35
|
+
total?: number;
|
|
36
|
+
};
|
|
37
|
+
}): Promise<void>;
|
|
38
|
+
/** `download` with up to 4 attempts and exponential backoff. Only failures
|
|
39
|
+
* marked retryable are retried; SHA verification stays with
|
|
40
|
+
* ensureTarball. `sleep` is injectable so tests do not wait. */
|
|
41
|
+
export declare function downloadWithRetry(url: string, to: string, opts?: Parameters<typeof download>[2] & {
|
|
42
|
+
attempts?: number;
|
|
43
|
+
sleep?: (ms: number) => Promise<void>;
|
|
44
|
+
log?: (line: string) => void;
|
|
45
|
+
/** The committed SHA-256, quoted in the manual-download advice. */
|
|
46
|
+
sha256?: string;
|
|
47
|
+
}): Promise<void>;
|
|
48
|
+
/** Cache + integrity for a downloaded asset: a cached file that fails
|
|
49
|
+
* its SHA is deleted and re-downloaded ONCE — a second mismatch still
|
|
50
|
+
* refuses, naming the cache so it is fixable by hand. `dl` injectable
|
|
51
|
+
* for tests. */
|
|
52
|
+
export declare function ensureTarball(url: string, tarball: string, want: string, dl?: (u: string, to: string) => Promise<void>): Promise<void>;
|
|
53
|
+
//# sourceMappingURL=download.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.d.ts","sourceRoot":"","sources":["../../src/build/download.ts"],"names":[],"mappings":"AAAA;;8DAE8D;AAa9D,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AAUjC;;oEAEoE;AACpE,qBAAa,aAAc,SAAQ,KAAK;IACtC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;gBAChB,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,KAAK,CAAC,EAAE,OAAO;CAKjE;AASD;;4DAE4D;AAC5D,wBAAgB,iBAAiB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAU9E;AAWD,gEAAgE;AAChE,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,MAAoB,GAAG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 -0,0 +1,326 @@
|
|
|
1
|
+
/** The python-build-standalone download: retry with backoff, Range
|
|
2
|
+
* resume, progress, the no-data timeout, and the cache plus committed
|
|
3
|
+
* SHA-256 check (docs/build.md, "Slow or flaky networks"). */
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
import { createWriteStream, existsSync, openSync, readFileSync, renameSync, rmSync, statSync, } from "node:fs";
|
|
6
|
+
import { get } from "node:https";
|
|
7
|
+
import { basename, resolve } from "node:path";
|
|
8
|
+
const DOWNLOAD_IDLE_TIMEOUT_MS = 30_000;
|
|
9
|
+
const MAX_REDIRECTS = 5;
|
|
10
|
+
const DOWNLOAD_ATTEMPTS = 4;
|
|
11
|
+
const DOWNLOAD_PROGRESS_MS = 10_000;
|
|
12
|
+
/** Base delay before retries 2, 3 and 4; each gets +-25 percent jitter. */
|
|
13
|
+
const RETRY_BASE_MS = [1_000, 3_000, 8_000];
|
|
14
|
+
/** A download failure, plus whether trying again could plausibly help:
|
|
15
|
+
* stalls, socket errors, 5xx, 429 and short bodies can; a 404, a refused
|
|
16
|
+
* redirect or a redirect loop will fail the same way every time. */
|
|
17
|
+
export class DownloadError extends Error {
|
|
18
|
+
retryable;
|
|
19
|
+
constructor(message, retryable, cause) {
|
|
20
|
+
super(message, cause === undefined ? undefined : { cause });
|
|
21
|
+
this.name = "DownloadError";
|
|
22
|
+
this.retryable = retryable;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
/** Errors that surface from the socket or the response stream are
|
|
26
|
+
* transient by nature; classified ones keep their own verdict. */
|
|
27
|
+
const asTransient = (e) => e instanceof DownloadError
|
|
28
|
+
? e
|
|
29
|
+
: new DownloadError(e instanceof Error ? e.message : String(e), true, e);
|
|
30
|
+
/** The no-data timeout: 30s unless PYLAIR_DOWNLOAD_TIMEOUT_MS says
|
|
31
|
+
* otherwise, clamped to 5s..600s. A value that is not a whole number is an
|
|
32
|
+
* error, not a silent fallback, so a typo does not hide. */
|
|
33
|
+
export function downloadTimeoutMs(env = process.env) {
|
|
34
|
+
const raw = env.PYLAIR_DOWNLOAD_TIMEOUT_MS?.trim();
|
|
35
|
+
if (raw === undefined || raw === "")
|
|
36
|
+
return DOWNLOAD_IDLE_TIMEOUT_MS;
|
|
37
|
+
if (!/^\d+$/.test(raw))
|
|
38
|
+
throw new DownloadError(`PYLAIR_DOWNLOAD_TIMEOUT_MS must be a whole number of milliseconds ` +
|
|
39
|
+
`(5000 to 600000), got "${raw}"`, false);
|
|
40
|
+
return Math.min(600_000, Math.max(5_000, Number(raw)));
|
|
41
|
+
}
|
|
42
|
+
/** "downloaded 12.3 of 45.6 MB (27%)", or without the total when the server
|
|
43
|
+
* did not send a length. */
|
|
44
|
+
function progressLine(received, total) {
|
|
45
|
+
const mb = (n) => (n / 1e6).toFixed(1);
|
|
46
|
+
return Number.isFinite(total) && total > 0
|
|
47
|
+
? `downloaded ${mb(received)} of ${mb(total)} MB (${Math.floor((received / total) * 100)}%)`
|
|
48
|
+
: `downloaded ${mb(received)} MB`;
|
|
49
|
+
}
|
|
50
|
+
/** Delay before retry number `retry` (1-based), with jitter. */
|
|
51
|
+
export function backoffMs(retry, rand = Math.random) {
|
|
52
|
+
const base = RETRY_BASE_MS[Math.min(retry, RETRY_BASE_MS.length) - 1];
|
|
53
|
+
return Math.round(base * (0.75 + 0.5 * rand()));
|
|
54
|
+
}
|
|
55
|
+
/** Download `url` to `to`, following up to `maxRedirects` redirects and
|
|
56
|
+
* failing after `timeoutMs` with no bytes. The body lands in `to.part`
|
|
57
|
+
* and is renamed into place only once it is complete — a dropped
|
|
58
|
+
* connection must never leave a partial file at the cache path (the
|
|
59
|
+
* SHA check would then refuse every later build until it is deleted by
|
|
60
|
+
* hand). `get` is injectable so tests need no network. */
|
|
61
|
+
export function download(url, to, opts) {
|
|
62
|
+
const getImpl = opts?.get ?? get;
|
|
63
|
+
const maxRedirects = opts?.maxRedirects ?? MAX_REDIRECTS;
|
|
64
|
+
const part = `${to}.part`;
|
|
65
|
+
const resume = opts?.resume ?? false;
|
|
66
|
+
return new Promise((res, rej) => {
|
|
67
|
+
// Read inside the executor so a bad PYLAIR_DOWNLOAD_TIMEOUT_MS rejects
|
|
68
|
+
// the promise instead of throwing synchronously.
|
|
69
|
+
const timeoutMs = opts?.timeoutMs ?? downloadTimeoutMs();
|
|
70
|
+
let settled = false;
|
|
71
|
+
let out;
|
|
72
|
+
let ticker;
|
|
73
|
+
const stopTicker = () => {
|
|
74
|
+
if (ticker)
|
|
75
|
+
clearInterval(ticker);
|
|
76
|
+
ticker = undefined;
|
|
77
|
+
};
|
|
78
|
+
// A resumable download keeps its partial file for the next attempt.
|
|
79
|
+
// Cleanup is best-effort and must never throw: it runs inside event
|
|
80
|
+
// handlers where a throw escapes uncaught or skips the rejection
|
|
81
|
+
// entirely, and the cleanup error must never replace the real one.
|
|
82
|
+
// A leftover .part is harmless — the next attempt opens it with "w"
|
|
83
|
+
// or resumes it.
|
|
84
|
+
const dropPart = () => {
|
|
85
|
+
if (!resume)
|
|
86
|
+
try {
|
|
87
|
+
rmSync(part, { force: true });
|
|
88
|
+
}
|
|
89
|
+
catch {
|
|
90
|
+
/* best-effort cleanup: the download error wins */
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
const fail = (e) => {
|
|
94
|
+
if (settled)
|
|
95
|
+
return;
|
|
96
|
+
settled = true;
|
|
97
|
+
stopTicker();
|
|
98
|
+
if (out === undefined) {
|
|
99
|
+
dropPart();
|
|
100
|
+
rej(e);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
// The stream owns the fd. destroy() waits for in-flight writes
|
|
104
|
+
// before closing it — closing early (closeSync) or twice lets a
|
|
105
|
+
// reused fd number absorb the stale op: the write lands in some
|
|
106
|
+
// other file, or the close kills it. .part is removed only once
|
|
107
|
+
// 'close' says the fd is really gone, keeping the rejection
|
|
108
|
+
// ordered after cleanup.
|
|
109
|
+
const s = out;
|
|
110
|
+
out = undefined;
|
|
111
|
+
s.once("close", () => {
|
|
112
|
+
dropPart();
|
|
113
|
+
rej(e);
|
|
114
|
+
});
|
|
115
|
+
s.destroy();
|
|
116
|
+
};
|
|
117
|
+
const onErr = (e) => fail(e instanceof Error ? e : new Error(String(e)));
|
|
118
|
+
// Bytes already on disk from an earlier attempt, asked for with Range.
|
|
119
|
+
// The header goes on every hop, so a redirect to a CDN keeps it.
|
|
120
|
+
let offset = 0;
|
|
121
|
+
const restart = () => {
|
|
122
|
+
rmSync(part, { force: true });
|
|
123
|
+
offset = 0;
|
|
124
|
+
follow(url, 0);
|
|
125
|
+
};
|
|
126
|
+
const follow = (u, redirects) => {
|
|
127
|
+
try {
|
|
128
|
+
if (redirects > maxRedirects)
|
|
129
|
+
return fail(new DownloadError(`GET ${url}: too many redirects (cap ${maxRedirects})`, false));
|
|
130
|
+
const onResponse = (r) => {
|
|
131
|
+
try {
|
|
132
|
+
if (r.statusCode >= 300 && r.statusCode < 400 && r.headers.location) {
|
|
133
|
+
// Location may be relative, and only https targets are
|
|
134
|
+
// fetchable: resolve first, refuse anything else.
|
|
135
|
+
const target = new URL(r.headers.location, u);
|
|
136
|
+
if (target.protocol !== "https:")
|
|
137
|
+
return fail(new DownloadError(`GET ${u}: refusing non-https redirect to ${target.origin}`, false));
|
|
138
|
+
return follow(target.href, redirects + 1);
|
|
139
|
+
}
|
|
140
|
+
// The kept .part is unusable (longer than the file, or not a
|
|
141
|
+
// range the server can serve): start over without Range.
|
|
142
|
+
if (r.statusCode === 416 && offset > 0) {
|
|
143
|
+
r.resume();
|
|
144
|
+
return restart();
|
|
145
|
+
}
|
|
146
|
+
const partial = r.statusCode === 206;
|
|
147
|
+
if (r.statusCode !== 200 && !partial)
|
|
148
|
+
return fail(new DownloadError(`GET ${u} -> ${r.statusCode}`, r.statusCode >= 500 || r.statusCode === 429));
|
|
149
|
+
if (partial) {
|
|
150
|
+
if (offset === 0)
|
|
151
|
+
return fail(new DownloadError(`GET ${u}: 206 to a request without Range`, false));
|
|
152
|
+
const m = /^bytes (\d+)-\d+\/(?:\d+|\*)$/.exec(String(r.headers["content-range"] ?? ""));
|
|
153
|
+
// Appending at the wrong position would corrupt the file.
|
|
154
|
+
if (!m || Number(m[1]) !== offset) {
|
|
155
|
+
r.resume();
|
|
156
|
+
return restart();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
offset = 0; // 200: the server ignored Range, so write it all
|
|
161
|
+
}
|
|
162
|
+
const want = Number(r.headers["content-length"]);
|
|
163
|
+
const total = partial
|
|
164
|
+
? Number(/\/(\d+)$/.exec(String(r.headers["content-range"]))?.[1])
|
|
165
|
+
: want;
|
|
166
|
+
if (opts?.state && Number.isFinite(total))
|
|
167
|
+
opts.state.total = total;
|
|
168
|
+
let got = 0;
|
|
169
|
+
let ended = false;
|
|
170
|
+
// A slow link should look slow, not dead: one plain line on
|
|
171
|
+
// stderr at most every 10s, nothing at all for a fast download.
|
|
172
|
+
stopTicker();
|
|
173
|
+
// Progress is cosmetic: a throwing sink (a closed stderr can
|
|
174
|
+
// make even console.error throw) loses that tick, never the
|
|
175
|
+
// download — and it may recover, so the ticker keeps running.
|
|
176
|
+
ticker = setInterval(() => {
|
|
177
|
+
try {
|
|
178
|
+
(opts?.progress ?? console.error)(progressLine(offset + got, total));
|
|
179
|
+
}
|
|
180
|
+
catch {
|
|
181
|
+
/* cosmetic: swallow and keep going */
|
|
182
|
+
}
|
|
183
|
+
}, opts?.progressMs ?? DOWNLOAD_PROGRESS_MS);
|
|
184
|
+
ticker.unref();
|
|
185
|
+
r.on("data", (c) => {
|
|
186
|
+
got += c.length;
|
|
187
|
+
});
|
|
188
|
+
r.on("end", () => {
|
|
189
|
+
ended = true;
|
|
190
|
+
});
|
|
191
|
+
r.on("error", (e) => fail(asTransient(e)));
|
|
192
|
+
r.on("close", () => {
|
|
193
|
+
if (!ended)
|
|
194
|
+
fail(new DownloadError(`GET ${u}: connection dropped mid-body`, true));
|
|
195
|
+
});
|
|
196
|
+
// Open eagerly: <part>'s existence is synchronous, so no
|
|
197
|
+
// deferred fs.open can land after fail()'s rmSync and recreate
|
|
198
|
+
// the file. autoClose: false keeps fd closing on our explicit
|
|
199
|
+
// destroy() calls only (see fail()).
|
|
200
|
+
const stream = createWriteStream(part, {
|
|
201
|
+
fd: openSync(part, partial ? "a" : "w"),
|
|
202
|
+
autoClose: false,
|
|
203
|
+
});
|
|
204
|
+
out = stream;
|
|
205
|
+
r.pipe(stream);
|
|
206
|
+
stream.on("finish", () => {
|
|
207
|
+
if (settled)
|
|
208
|
+
return;
|
|
209
|
+
out = undefined;
|
|
210
|
+
stream.once("close", () => {
|
|
211
|
+
// fail() may have settled this attempt between 'finish' and
|
|
212
|
+
// 'close' (the request timing out, say). A resumable retry
|
|
213
|
+
// can already own `part` by now, so a stale completion must
|
|
214
|
+
// not touch the filesystem at all.
|
|
215
|
+
if (settled)
|
|
216
|
+
return;
|
|
217
|
+
if (!Number.isNaN(want) && got !== want)
|
|
218
|
+
return fail(new DownloadError(`GET ${u}: incomplete body: ${got} of ${want} bytes`, true));
|
|
219
|
+
settled = true;
|
|
220
|
+
stopTicker();
|
|
221
|
+
// An event handler must never throw: a failed rename rejects
|
|
222
|
+
// the promise (not retryable: it is not a network error).
|
|
223
|
+
try {
|
|
224
|
+
renameSync(part, to);
|
|
225
|
+
}
|
|
226
|
+
catch (e) {
|
|
227
|
+
dropPart();
|
|
228
|
+
return rej(e instanceof Error ? e : new Error(String(e)));
|
|
229
|
+
}
|
|
230
|
+
res();
|
|
231
|
+
});
|
|
232
|
+
stream.destroy();
|
|
233
|
+
});
|
|
234
|
+
stream.on("error", fail);
|
|
235
|
+
}
|
|
236
|
+
catch (e) {
|
|
237
|
+
onErr(e);
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
const req = offset > 0
|
|
241
|
+
? getImpl(u, { headers: { Range: `bytes=${offset}-` } }, onResponse)
|
|
242
|
+
: getImpl(u, onResponse);
|
|
243
|
+
req.setTimeout(timeoutMs, () => req.destroy(new DownloadError(`GET ${u}: timed out: no data for ${timeoutMs / 1000}s`, true)));
|
|
244
|
+
req.on("error", (e) => fail(asTransient(e)));
|
|
245
|
+
}
|
|
246
|
+
catch (e) {
|
|
247
|
+
onErr(e);
|
|
248
|
+
}
|
|
249
|
+
};
|
|
250
|
+
if (resume && existsSync(part))
|
|
251
|
+
offset = statSync(part).size;
|
|
252
|
+
follow(url, 0);
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
/** `download` with up to 4 attempts and exponential backoff. Only failures
|
|
256
|
+
* marked retryable are retried; SHA verification stays with
|
|
257
|
+
* ensureTarball. `sleep` is injectable so tests do not wait. */
|
|
258
|
+
export async function downloadWithRetry(url, to, opts) {
|
|
259
|
+
const state = {};
|
|
260
|
+
const attempts = opts?.attempts ?? DOWNLOAD_ATTEMPTS;
|
|
261
|
+
const sleep = opts?.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
262
|
+
const log = opts?.log ?? ((line) => console.warn(line));
|
|
263
|
+
for (let attempt = 1;; attempt++) {
|
|
264
|
+
try {
|
|
265
|
+
return await download(url, to, { resume: true, state, ...opts });
|
|
266
|
+
}
|
|
267
|
+
catch (e) {
|
|
268
|
+
if (!(e instanceof DownloadError && e.retryable))
|
|
269
|
+
throw e;
|
|
270
|
+
if (attempt >= attempts) {
|
|
271
|
+
const part = `${to}.part`;
|
|
272
|
+
// The .part can vanish between the failed attempt and this line —
|
|
273
|
+
// check-then-use would throw a bare ENOENT over the helpful error.
|
|
274
|
+
let received = 0;
|
|
275
|
+
try {
|
|
276
|
+
received = statSync(part).size;
|
|
277
|
+
}
|
|
278
|
+
catch {
|
|
279
|
+
/* gone or unreadable: report 0 bytes received */
|
|
280
|
+
}
|
|
281
|
+
const size = state.total === undefined ? "unknown" : `${state.total} bytes`;
|
|
282
|
+
throw new DownloadError(`could not download ${url} after ${attempts} attempts: received ` +
|
|
283
|
+
`${received} of ${state.total ?? "an unknown number of"} bytes ` +
|
|
284
|
+
`(last error: ${e.message}). ` +
|
|
285
|
+
`Download the file on a better connection and place it at ${resolve(to)}. ` +
|
|
286
|
+
`Expected size ${size}` +
|
|
287
|
+
(opts?.sha256 ? `, SHA-256 ${opts.sha256}` : "") +
|
|
288
|
+
`. The build verifies it and re-downloads if it does not match.`, false, e);
|
|
289
|
+
}
|
|
290
|
+
const wait = backoffMs(attempt);
|
|
291
|
+
log(`retrying (${attempt + 1} of ${attempts}) in ${Math.round(wait / 1000)}s: ${e.message}`);
|
|
292
|
+
await sleep(wait);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
const sha256File = (p) => createHash("sha256").update(readFileSync(p)).digest("hex");
|
|
297
|
+
/** Cache + integrity for a downloaded asset: a cached file that fails
|
|
298
|
+
* its SHA is deleted and re-downloaded ONCE — a second mismatch still
|
|
299
|
+
* refuses, naming the cache so it is fixable by hand. `dl` injectable
|
|
300
|
+
* for tests. */
|
|
301
|
+
export async function ensureTarball(url, tarball, want, dl = (u2, to2) => downloadWithRetry(u2, to2, { sha256: want })) {
|
|
302
|
+
const cached = existsSync(tarball);
|
|
303
|
+
if (!cached) {
|
|
304
|
+
console.log(`fetching ${basename(tarball)}`);
|
|
305
|
+
await dl(url, tarball);
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
console.log(`using cached ${basename(tarball)}`);
|
|
309
|
+
}
|
|
310
|
+
if (sha256File(tarball) === want)
|
|
311
|
+
return;
|
|
312
|
+
if (!cached)
|
|
313
|
+
throw new Error(`SHA256 mismatch for ${basename(tarball)}: got ${sha256File(tarball)}, ` +
|
|
314
|
+
`want ${want} — refusing to bundle`);
|
|
315
|
+
// A cached-but-corrupt file is the dropped-partial failure mode: one
|
|
316
|
+
// retry, then refuse.
|
|
317
|
+
console.warn(`cached ${basename(tarball)} failed its SHA256 — ` +
|
|
318
|
+
`deleting ${tarball} and re-downloading once`);
|
|
319
|
+
rmSync(tarball, { force: true });
|
|
320
|
+
await dl(url, tarball);
|
|
321
|
+
const got = sha256File(tarball);
|
|
322
|
+
if (got !== want)
|
|
323
|
+
throw new Error(`SHA256 mismatch for ${basename(tarball)} after re-download: got ${got}, ` +
|
|
324
|
+
`want ${want} — refusing to bundle (cache file: ${tarball})`);
|
|
325
|
+
}
|
|
326
|
+
//# sourceMappingURL=download.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"download.js","sourceRoot":"","sources":["../../src/build/download.ts"],"names":[],"mappings":"AAAA;;8DAE8D;AAE9D,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EACL,iBAAiB,EACjB,UAAU,EACV,QAAQ,EACR,YAAY,EACZ,UAAU,EACV,MAAM,EACN,QAAQ,GACT,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,GAAG,EAAE,MAAM,YAAY,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,wBAAwB,GAAG,MAAM,CAAC;AACxC,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,oBAAoB,GAAG,MAAM,CAAC;AACpC,2EAA2E;AAC3E,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;AAE5C;;oEAEoE;AACpE,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,SAAS,CAAU;IAC5B,YAAY,OAAe,EAAE,SAAkB,EAAE,KAAe;QAC9D,KAAK,CAAC,OAAO,EAAE,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;QAC5D,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;QAC5B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;CACF;AAED;kEACkE;AAClE,MAAM,WAAW,GAAG,CAAC,CAAU,EAAS,EA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QAChD,YAAY,OAAO,0BAA0B,CAChD,CAAC;IACF,MAAM,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACjC,MAAM,EAAE,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IACvB,MAAM,GAAG,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC;IAChC,IAAI,GAAG,KAAK,IAAI;QACd,MAAM,IAAI,KAAK,CACb,uBAAuB,QAAQ,CAAC,OAAO,CAAC,2BAA2B,GAAG,IAAI;YACxE,QAAQ,IAAI,sCAAsC,OAAO,GAAG,CAC/D,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/** THIRD-PARTY-NOTICES for the bundle: the licenses of everything it
|
|
2
|
+
* embeds (pylair, the interpreter, every installed wheel). */
|
|
3
|
+
/** Shipped bundles must carry the licenses of what they embed. Collects:
|
|
4
|
+
* pylair's own dual license, the interpreter's license tree (PSF license
|
|
5
|
+
* requires LICENSE text with redistributed CPython), and each wheel's
|
|
6
|
+
* dist-info license files. Runs before prune so nothing collected is
|
|
7
|
+
* deleted afterwards. Returns the notice dir.
|
|
8
|
+
*/
|
|
9
|
+
export declare function stageNotices(resources: string, pylairDir: string): string;
|
|
10
|
+
//# sourceMappingURL=notices.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"notices.d.ts","sourceRoot":"","sources":["../../src/build/notices.ts"],"names":[],"mappings":"AAAA;8DAC8D;AAa9D;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,CA8FzE"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/** THIRD-PARTY-NOTICES for the bundle: the licenses of everything it
|
|
2
|
+
* embeds (pylair, the interpreter, every installed wheel). */
|
|
3
|
+
import { cpSync, existsSync, mkdirSync, readdirSync, readFileSync, rmSync, writeFileSync, } from "node:fs";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
/** Shipped bundles must carry the licenses of what they embed. Collects:
|
|
6
|
+
* pylair's own dual license, the interpreter's license tree (PSF license
|
|
7
|
+
* requires LICENSE text with redistributed CPython), and each wheel's
|
|
8
|
+
* dist-info license files. Runs before prune so nothing collected is
|
|
9
|
+
* deleted afterwards. Returns the notice dir.
|
|
10
|
+
*/
|
|
11
|
+
export function stageNotices(resources, pylairDir) {
|
|
12
|
+
const out = join(resources, "THIRD-PARTY-NOTICES");
|
|
13
|
+
rmSync(out, { recursive: true, force: true });
|
|
14
|
+
mkdirSync(out, { recursive: true });
|
|
15
|
+
const index = [];
|
|
16
|
+
const copyInto = (subdir, src, dest) => {
|
|
17
|
+
mkdirSync(join(out, subdir), { recursive: true });
|
|
18
|
+
cpSync(src, join(out, subdir, dest));
|
|
19
|
+
};
|
|
20
|
+
const LICENSEISH = /^(licen[cs]e|copying|notice|authors|copyright)/i;
|
|
21
|
+
for (const f of ["LICENSE-MIT", "LICENSE-APACHE"]) {
|
|
22
|
+
const src = join(pylairDir, f);
|
|
23
|
+
if (existsSync(src))
|
|
24
|
+
copyInto("pylair", src, f);
|
|
25
|
+
}
|
|
26
|
+
index.push("pylair/ — pylair itself (MIT OR Apache-2.0)");
|
|
27
|
+
// The interpreter: python-build-standalone ships a licenses/ dir holding
|
|
28
|
+
// CPython's license plus every statically-linked dep (OpenSSL, libffi…).
|
|
29
|
+
const pyRoot = join(resources, "python");
|
|
30
|
+
let found = 0;
|
|
31
|
+
const walkPy = (dir) => {
|
|
32
|
+
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
|
33
|
+
const p = join(dir, e.name);
|
|
34
|
+
if (e.isDirectory()) {
|
|
35
|
+
if (e.name.toLowerCase() === "licenses") {
|
|
36
|
+
cpSync(p, join(out, "python", "licenses"), { recursive: true });
|
|
37
|
+
found++;
|
|
38
|
+
}
|
|
39
|
+
else
|
|
40
|
+
walkPy(p);
|
|
41
|
+
}
|
|
42
|
+
else if (LICENSEISH.test(e.name)) {
|
|
43
|
+
copyInto("python", p, e.name);
|
|
44
|
+
found++;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
if (existsSync(pyRoot))
|
|
49
|
+
walkPy(pyRoot);
|
|
50
|
+
if (!found) {
|
|
51
|
+
mkdirSync(join(out, "python"), { recursive: true });
|
|
52
|
+
writeFileSync(join(out, "python", "NOTICE.txt"), "This app bundles CPython (PSF-2.0 license) via python-build-standalone.\n" +
|
|
53
|
+
"License texts were not located in the interpreter tree at build time;\n" +
|
|
54
|
+
"they ship upstream in the python/licenses directory of each\n" +
|
|
55
|
+
"python-build-standalone release.\n");
|
|
56
|
+
console.warn("warning: no license files found under resources/python — wrote placeholder NOTICE");
|
|
57
|
+
}
|
|
58
|
+
index.push("python/ — bundled CPython interpreter (PSF-2.0) and its vendored deps");
|
|
59
|
+
// Wheels: every installed dist-info/egg-info carries license files or
|
|
60
|
+
// license metadata. Copy whichever exists.
|
|
61
|
+
const sp = join(resources, "site-packages");
|
|
62
|
+
let wheels = 0;
|
|
63
|
+
if (existsSync(sp)) {
|
|
64
|
+
for (const e of readdirSync(sp, { withFileTypes: true })) {
|
|
65
|
+
if (!e.isDirectory())
|
|
66
|
+
continue;
|
|
67
|
+
const m = /^(.*?)-[\d.]+.*\.(dist-info|egg-info)$/.exec(e.name);
|
|
68
|
+
if (!m)
|
|
69
|
+
continue;
|
|
70
|
+
const pkg = m[1].replace(/[^\w.-]/g, "_");
|
|
71
|
+
const d = join(sp, e.name);
|
|
72
|
+
let kept = false;
|
|
73
|
+
for (const f of readdirSync(d, { withFileTypes: true })) {
|
|
74
|
+
if (f.isDirectory() && f.name.toLowerCase() === "licenses") {
|
|
75
|
+
cpSync(join(d, f.name), join(out, pkg, "licenses"), { recursive: true });
|
|
76
|
+
kept = true;
|
|
77
|
+
}
|
|
78
|
+
else if (f.isFile() && LICENSEISH.test(f.name)) {
|
|
79
|
+
copyInto(pkg, join(d, f.name), f.name);
|
|
80
|
+
kept = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
const meta = join(d, "METADATA");
|
|
84
|
+
if (existsSync(meta)) {
|
|
85
|
+
const lines = readFileSync(meta, "utf-8")
|
|
86
|
+
.split("\n")
|
|
87
|
+
.filter((l) => /^(License|Classifier: License)/i.test(l));
|
|
88
|
+
// Copyleft is legal to ship but app authors deserve to know they
|
|
89
|
+
// bundled it — warn, never block.
|
|
90
|
+
if (/\b(a?lgpl|gpl)[ -]?v?\d/i.test(lines.join(" ")))
|
|
91
|
+
console.warn(`warning: bundled wheel ${e.name} declares a copyleft license`);
|
|
92
|
+
if (lines.length) {
|
|
93
|
+
mkdirSync(join(out, pkg), { recursive: true });
|
|
94
|
+
writeFileSync(join(out, pkg, "METADATA-LICENSE.txt"), lines.join("\n") + "\n");
|
|
95
|
+
kept = true;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (kept) {
|
|
99
|
+
wheels++;
|
|
100
|
+
index.push(`${pkg}/ — from ${e.name}`);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
writeFileSync(join(out, "INDEX.txt"), index.join("\n") + "\n");
|
|
105
|
+
console.log(`third-party notices: pylair, python interpreter, ${wheels} wheel(s)`);
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=notices.js.map
|