nightshift-factory 0.0.0-stage → 0.1.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.
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// npx nightshift-factory [setup|status|...]: installs this version's Python runtime once, under
|
|
3
|
+
// ~/.nightshift/local/runtime/<version>, then runs `nightshift-local <command>` from it (setup by default). The service
|
|
4
|
+
// setup installs runs from that durable runtime, never from npx's cache. A newer version installs beside it; nothing
|
|
5
|
+
// switches until its own setup runs.
|
|
6
|
+
import { spawnSync } from "node:child_process";
|
|
7
|
+
import { existsSync, readFileSync, rmSync, mkdirSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { homedir } from "node:os";
|
|
9
|
+
import { dirname, join } from "node:path";
|
|
10
|
+
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
12
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
13
|
+
const { version } = JSON.parse(readFileSync(join(here, "..", "package.json"), "utf8"));
|
|
14
|
+
const home = process.env.NIGHTSHIFT_LOCAL_HOME || join(homedir(), ".nightshift", "local");
|
|
15
|
+
const runtime = join(home, "runtime", version);
|
|
16
|
+
const python = join(runtime, "bin", "python");
|
|
17
|
+
const installed = join(runtime, ".installed");
|
|
18
|
+
|
|
19
|
+
function die(message) {
|
|
20
|
+
console.error(`nightshift-factory: ${message}`);
|
|
21
|
+
process.exit(1);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function run(command, args, options = {}) {
|
|
25
|
+
const result = spawnSync(command, args, { stdio: "inherit", ...options });
|
|
26
|
+
return result.status ?? 1;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function pythonAtLeast311(command) {
|
|
30
|
+
const result = spawnSync(command, ["-c", "import sys; print(sys.version_info >= (3, 11))"], { encoding: "utf8" });
|
|
31
|
+
return result.status === 0 && result.stdout.trim() === "True";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (!existsSync(installed)) {
|
|
35
|
+
const wheel = join(here, "..", "wheels", `nightshift_local-${version}-py3-none-any.whl`);
|
|
36
|
+
if (!existsSync(wheel)) die(`no runtime wheel in this package (${wheel}): build it with npm pack.`);
|
|
37
|
+
rmSync(runtime, { recursive: true, force: true }); // A half-finished install is redone, never used.
|
|
38
|
+
mkdirSync(dirname(runtime), { recursive: true });
|
|
39
|
+
console.log(`Installing the Night Shift local runtime ${version} in ${runtime}`);
|
|
40
|
+
let status;
|
|
41
|
+
if (spawnSync("uv", ["--version"], { stdio: "ignore" }).status === 0) {
|
|
42
|
+
status = run("uv", ["venv", "--quiet", "--python", ">=3.11", runtime]);
|
|
43
|
+
status ||= run("uv", ["pip", "install", "--quiet", "--python", python, wheel]);
|
|
44
|
+
} else {
|
|
45
|
+
const base = ["python3.13", "python3.12", "python3.11", "python3"].find(pythonAtLeast311);
|
|
46
|
+
if (!base) die("Python 3.11 or newer is needed: install uv (https://docs.astral.sh/uv/) or python3.12.");
|
|
47
|
+
status = run(base, ["-m", "venv", runtime]);
|
|
48
|
+
status ||= run(python, ["-m", "pip", "install", "--quiet", wheel]);
|
|
49
|
+
}
|
|
50
|
+
if (status !== 0) die("installing the runtime failed; run the same command again to retry.");
|
|
51
|
+
writeFileSync(installed, `${version}\n`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const args = process.argv.slice(2);
|
|
55
|
+
process.exit(run(python, ["-m", "nightshift_local.orchestrator", ...(args.length ? args : ["setup"])], {
|
|
56
|
+
env: { ...process.env, NIGHTSHIFT_LOCAL_HOME: home },
|
|
57
|
+
}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nightshift-factory",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Set up Night Shift's local factory on this machine: npx nightshift-factory setup",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"nightshift-factory": "bin/nightshift-factory.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"wheels"
|
|
12
|
+
],
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=18"
|
|
15
|
+
},
|
|
16
|
+
"scripts": {
|
|
17
|
+
"prepack": "node scripts/build-wheel.js"
|
|
18
|
+
},
|
|
19
|
+
"license": "UNLICENSED"
|
|
20
|
+
}
|
|
Binary file
|
package/README.md
DELETED