blitzwing 0.1.3 → 0.1.5

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/install.js +75 -31
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "blitzwing",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
4
4
  "description": "Interactive setup wizard to join a Blitzwing Petals mother swarm as a compute contributor",
5
5
  "bin": {
6
6
  "blitzwing": "bin/blitzwing.js"
package/src/install.js CHANGED
@@ -18,41 +18,85 @@ function venvPip() {
18
18
  return path.join(VENV_PATH, "bin", "pip");
19
19
  }
20
20
 
21
- export function ensurePython() {
22
- // Prefer 3.10/3.11 — Petals/hivemind break on 3.12+ / 3.13+
23
- const candidates = ["python3.11", "python3.10", "python3", "python"];
24
- let py = null;
25
- let ver = "";
26
- for (const cmd of candidates) {
27
- const found = which(cmd);
28
- if (!found) continue;
29
- try {
30
- ver = execFileSync(found, ["--version"], { encoding: "utf8" }).trim();
31
- const m = ver.match(/Python (\d+)\.(\d+)/);
32
- if (!m) continue;
33
- const major = Number(m[1]);
34
- const minor = Number(m[2]);
35
- if (major === 3 && minor >= 10 && minor <= 11) {
36
- py = found;
37
- break;
38
- }
39
- if (!py) {
40
- py = found; // fallback, may fail later
41
- }
42
- } catch {
43
- /* try next */
44
- }
21
+ function pythonVersion(bin) {
22
+ try {
23
+ const ver = execFileSync(bin, ["--version"], { encoding: "utf8" }).trim();
24
+ const m = ver.match(/Python (\d+)\.(\d+)/);
25
+ if (!m) return null;
26
+ return { ver, major: Number(m[1]), minor: Number(m[2]) };
27
+ } catch {
28
+ return null;
45
29
  }
46
- if (!py) {
47
- throw new Error("Python 3.10 or 3.11 is required. Install via conda/miniconda and re-run.");
30
+ }
31
+
32
+ function isPetalsCompatible(info) {
33
+ return info && info.major === 3 && info.minor >= 10 && info.minor <= 11;
34
+ }
35
+
36
+ function pinnedPythonPath() {
37
+ try {
38
+ const p = path.join(HOME_DIR, "python");
39
+ if (!fs.existsSync(p)) return null;
40
+ const bin = fs.readFileSync(p, "utf8").trim();
41
+ return bin || null;
42
+ } catch {
43
+ return null;
48
44
  }
49
- const m = ver.match(/Python (\d+)\.(\d+)/);
50
- if (m && (Number(m[1]) !== 3 || Number(m[2]) > 11)) {
51
- throw new Error(
52
- `${ver} is too new for Petals. Use Python 3.11 (e.g. conda create -n blitzwing python=3.11).`
45
+ }
46
+
47
+ export function ensurePython() {
48
+ // Petals/hivemind break on 3.12+. Never fall back to a too-new interpreter.
49
+ const home = process.env.HOME || process.env.USERPROFILE || "";
50
+ const candidates = [];
51
+ const envBin = process.env.BLITZWING_PYTHON || process.env.PETALS_PYTHON;
52
+ if (envBin) candidates.push(envBin);
53
+ const pinned = pinnedPythonPath();
54
+ if (pinned) candidates.push(pinned);
55
+ if (process.env.CONDA_PREFIX) {
56
+ candidates.push(
57
+ path.join(process.env.CONDA_PREFIX, "bin", "python3.11"),
58
+ path.join(process.env.CONDA_PREFIX, "bin", "python3.10"),
59
+ path.join(process.env.CONDA_PREFIX, "bin", "python")
53
60
  );
54
61
  }
55
- return { py, ver };
62
+ for (const root of ["miniforge3", "mambaforge", "miniconda", "miniconda3", "anaconda3"]) {
63
+ candidates.push(
64
+ path.join(home, root, "envs", "blitzwing", "bin", "python3.11"),
65
+ path.join(home, root, "envs", "blitzwing", "bin", "python")
66
+ );
67
+ }
68
+ candidates.push("python3.11", "python3.10");
69
+
70
+ const tried = [];
71
+ const seen = new Set();
72
+ for (const cmd of candidates) {
73
+ if (!cmd || seen.has(cmd)) continue;
74
+ seen.add(cmd);
75
+ const found = cmd.includes("/") || cmd.includes("\\") ? (fs.existsSync(cmd) ? cmd : null) : which(cmd);
76
+ if (!found) {
77
+ tried.push(`${cmd} (missing)`);
78
+ continue;
79
+ }
80
+ const info = pythonVersion(found);
81
+ if (isPetalsCompatible(info)) {
82
+ fs.mkdirSync(HOME_DIR, { recursive: true });
83
+ fs.writeFileSync(path.join(HOME_DIR, "python"), found + "\n");
84
+ return { py: found, ver: info.ver };
85
+ }
86
+ tried.push(`${found} (${info ? info.ver : "unreadable"})`);
87
+ }
88
+
89
+ throw new Error(
90
+ "Python 3.10 or 3.11 is required (3.12+ will not work).\n" +
91
+ "Checked:\n - " +
92
+ tried.slice(0, 12).join("\n - ") +
93
+ "\nFix:\n" +
94
+ " curl -LsSf https://astral.sh/uv/install.sh | sh && source $HOME/.local/bin/env\n" +
95
+ " uv python install 3.11\n" +
96
+ " export BLITZWING_PYTHON=\"$(uv python find 3.11)\"\n" +
97
+ " mkdir -p ~/.blitzwing && echo \"$BLITZWING_PYTHON\" > ~/.blitzwing/python\n" +
98
+ " blitzwing"
99
+ );
56
100
  }
57
101
 
58
102
  function petalsImportable(python) {