pinokiod 3.2.198 → 3.2.201

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.
@@ -623,10 +623,26 @@ class Api {
623
623
 
624
624
  rpc.args = args
625
625
 
626
- if (i < script.run.length-1) {
627
- rpc.next = i+1
626
+ if (rpc.hasOwnProperty("next")) {
627
+ console.log("next already exists, don't touch", rpc.next)
628
+ if (typeof rpc.next === "string") {
629
+ let run = script.run
630
+ console.log("run", run)
631
+ for(let i=0; i<run.length; i++) {
632
+ let step = run[i]
633
+ if (step && step.id === rpc.next) {
634
+ rpc.next = i
635
+ break
636
+ }
637
+ }
638
+ }
628
639
  } else {
629
- rpc.next = null
640
+ if (i < script.run.length-1) {
641
+ rpc.next = i+1
642
+ } else {
643
+ rpc.next = null
644
+ }
645
+ console.log("next is not set. compute the next value", rpc.next)
630
646
  }
631
647
 
632
648
  if (rpc.hasOwnProperty("when")) {
@@ -64,7 +64,7 @@ class Local {
64
64
  */
65
65
 
66
66
  let current_env = await Environment.get2(req.parent.path, kernel)
67
- console.log({ current_env })
67
+ // console.log({ current_env })
68
68
 
69
69
  // if the key at current_env.PINOKIO_SHARE_VAR (by default it's 'url') is the variable being set, trigger the share logic
70
70
  if (current_env.PINOKIO_SHARE_VAR && current_env.PINOKIO_SHARE_VAR in req.params) {
@@ -96,13 +96,11 @@ create_default_packages:
96
96
  // console.log("conda list check", { stream })
97
97
  })
98
98
 
99
- console.log("CONDA", res.response)
100
99
  let lines = res.response.split(/[\r\n]+/)
101
100
  let conda_check = {}
102
101
  let conda = new Set()
103
102
  let start = false
104
103
  for(let line of lines) {
105
- console.log({ line, start })
106
104
  if (start) {
107
105
  let chunks = line.split(/\s+/).filter(x => x)
108
106
  if (chunks.length > 1) {
@@ -122,7 +120,6 @@ create_default_packages:
122
120
  let channel = chunks[3]
123
121
  let coerced = semver.coerce(version)
124
122
  let mamba_requirement = ">=24.11.1"
125
- console.log({ name, channel, version })
126
123
  if (semver.satisfies(coerced, mamba_requirement) && channel === "conda-forge") {
127
124
  conda_check.mamba = true
128
125
  }
@@ -133,7 +130,6 @@ create_default_packages:
133
130
  if (name === "sqlite") {
134
131
  let coerced = semver.coerce(version)
135
132
  let sqlite_requirement = ">=3.47.2"
136
- console.log({ coerced, version, sqlite_requirement })
137
133
  if (semver.satisfies(coerced, sqlite_requirement)) {
138
134
  console.log("semver satisfied")
139
135
  conda_check.sqlite = true
@@ -142,9 +142,7 @@ class Bin {
142
142
  this.vs_path_env = mod.mod.env(this.kernel)
143
143
  return null
144
144
  } else {
145
- console.log({ mod })
146
145
  if (mod.mod.env) {
147
- console.log("env", mod.mod.env)
148
146
  return mod.mod.env(this.kernel)
149
147
  } else {
150
148
  return null
@@ -238,63 +236,87 @@ class Bin {
238
236
  let start
239
237
  let conda_check = {}
240
238
  let conda = new Set()
241
- res = await this.exec({ message: `conda list` }, (stream) => {
242
- // process.stdout.write(stream.raw)
243
- // console.log("conda list check", { stream })
239
+
240
+ //////////////////////////////////////////////////////////////////
241
+ // exception handling
242
+ // if importlib_metadata || uvicorn || fastapi exist in the base environment, this.correct_conda = false
243
+ let site_packages_path
244
+ if (this.platform === "win32") {
245
+ site_packages_path = path.resolve(this.kernel.homedir, "bin/miniconda/Lib/site-packages")
246
+ } else {
247
+ site_packages_path = path.resolve(this.kernel.homedir, "bin/miniconda/lib/python3.10/site-packages")
248
+ }
249
+ // check if any of 'uvicorn', 'importlib_metadata', 'fastapi' exists
250
+ let module_paths = ["fastapi", "uvicorn", "importlib_metadata"].map((name) => {
251
+ return path.resolve(site_packages_path, name)
244
252
  })
253
+ let to_reset_exists = false
254
+ for(let module_path of module_paths) {
255
+ let e = await this.kernel.exists(module_path)
256
+ if (!e) {
257
+ to_reset_exists = true
258
+ break;
259
+ }
260
+ }
261
+ console.log({ to_reset_exists })
262
+ if (to_reset_exists) {
263
+ this.correct_conda = false
264
+ } else {
265
+ res = await this.exec({ message: `conda list` }, (stream) => {
266
+ // process.stdout.write(stream.raw)
267
+ // console.log("conda list check", { stream })
268
+ })
245
269
 
246
- console.log("CONDA", res.response)
247
- let lines = res.response.split(/[\r\n]+/)
248
- for(let line of lines) {
249
- console.log({ line, start })
250
- if (start) {
251
- let chunks = line.split(/\s+/).filter(x => x)
252
- if (chunks.length > 1) {
253
- let name = chunks[0]
254
- let version = chunks[1]
255
- conda.add(name)
256
- if (name === "conda") {
257
- //if (String(version) === "24.11.1") {
258
- if (String(version) === "24.11.3") {
259
- conda_check.conda = true
270
+ let lines = res.response.split(/[\r\n]+/)
271
+ for(let line of lines) {
272
+ if (start) {
273
+ let chunks = line.split(/\s+/).filter(x => x)
274
+ if (chunks.length > 1) {
275
+ let name = chunks[0]
276
+ let version = chunks[1]
277
+ conda.add(name)
278
+ if (name === "conda") {
279
+ //if (String(version) === "24.11.1") {
280
+ if (String(version) === "24.11.3") {
281
+ conda_check.conda = true
282
+ }
260
283
  }
261
- }
262
- if (name === "conda-libmamba-solver") {
263
- //if (String(version) === "24.7.0") {
264
- let channel = chunks[3]
265
- let coerced = semver.coerce(version)
266
- let mamba_requirement = ">=24.11.1"
267
- console.log({ name, channel, version })
268
- if (semver.satisfies(coerced, mamba_requirement) && channel === "conda-forge") {
269
- conda_check.mamba = true
284
+ if (name === "conda-libmamba-solver") {
285
+ //if (String(version) === "24.7.0") {
286
+ let channel = chunks[3]
287
+ let coerced = semver.coerce(version)
288
+ let mamba_requirement = ">=24.11.1"
289
+ console.log({ name, channel, version })
290
+ if (semver.satisfies(coerced, mamba_requirement) && channel === "conda-forge") {
291
+ conda_check.mamba = true
292
+ }
270
293
  }
271
- }
272
- // Use sqlite to check if `conda update -y --all` went through successfully
273
- // sometimes it just fails silently so need to check
274
- if (name === "sqlite") {
275
- let coerced = semver.coerce(version)
276
- let sqlite_requirement = ">=3.47.2"
277
- console.log({ coerced, version, sqlite_requirement })
278
- if (semver.satisfies(coerced, sqlite_requirement)) {
279
- console.log("semver satisfied")
280
- conda_check.sqlite = true
281
- } else {
282
- console.log("semver NOT satisfied")
294
+ // Use sqlite to check if `conda update -y --all` went through successfully
295
+ // sometimes it just fails silently so need to check
296
+ if (name === "sqlite") {
297
+ let coerced = semver.coerce(version)
298
+ let sqlite_requirement = ">=3.47.2"
299
+ // console.log({ coerced, version, sqlite_requirement })
300
+ if (semver.satisfies(coerced, sqlite_requirement)) {
301
+ console.log("semver satisfied")
302
+ conda_check.sqlite = true
303
+ } else {
304
+ console.log("semver NOT satisfied")
305
+ }
283
306
  }
284
307
  }
285
- }
286
- } else {
287
- if (/.*name.*version.*build.*channel/i.test(line)) {
288
- start = true
308
+ } else {
309
+ if (/.*name.*version.*build.*channel/i.test(line)) {
310
+ start = true
311
+ }
289
312
  }
290
313
  }
291
- }
292
314
 
293
- console.log({ conda_check })
294
- if (conda_check.conda && conda_check.mamba && conda_check.sqlite) {
295
- this.correct_conda = true
315
+ console.log({ conda_check })
316
+ if (conda_check.conda && conda_check.mamba && conda_check.sqlite) {
317
+ this.correct_conda = true
318
+ }
296
319
  }
297
-
298
320
  this.installed.conda = conda
299
321
  }
300
322
  async refreshInstalled() {
@@ -325,38 +347,38 @@ class Bin {
325
347
  // Try 3 times, because sometimes conda just silently quits with no error message
326
348
  for(let i=0; i<5; i++) {
327
349
  await this.tryList()
328
- console.log(`> conda list ${i}`, Array.from(this.installed.conda))
350
+ // console.log(`> conda list ${i}`, Array.from(this.installed.conda))
329
351
  if (this.installed.conda.size > 0) {
330
352
  break
331
353
  }
332
354
  }
333
355
  }
334
356
 
335
- // 2. pip
336
- let pip = new Set()
337
- if (conda_exists) {
338
- // conda comes with pip
339
- console.log("## check pip")
340
- start = false
341
- res = await this.exec({ message: `pip list` }, (stream) => {
342
- // console.log("pip list check", { stream })
343
- })
344
- console.log("PIP", res.response)
345
- lines = res.response.split(/[\r\n]+/)
346
- for(let line of lines) {
347
- if (start) {
348
- let chunks = line.split(/\s+/).filter(x => x)
349
- if (chunks.length > 1) {
350
- pip.add(chunks[0])
351
- }
352
- } else {
353
- if (/-------.*/i.test(line)) {
354
- start = true
355
- }
356
- }
357
- }
358
- }
359
- this.installed.pip = pip
357
+ // // 2. pip
358
+ // let pip = new Set()
359
+ // if (conda_exists) {
360
+ // // conda comes with pip
361
+ // console.log("## check pip")
362
+ // start = false
363
+ // res = await this.exec({ message: `pip list` }, (stream) => {
364
+ //// console.log("pip list check", { stream })
365
+ // })
366
+ // console.log("PIP", res.response)
367
+ // lines = res.response.split(/[\r\n]+/)
368
+ // for(let line of lines) {
369
+ // if (start) {
370
+ // let chunks = line.split(/\s+/).filter(x => x)
371
+ // if (chunks.length > 1) {
372
+ // pip.add(chunks[0])
373
+ // }
374
+ // } else {
375
+ // if (/-------.*/i.test(line)) {
376
+ // start = true
377
+ // }
378
+ // }
379
+ // }
380
+ // }
381
+ // this.installed.pip = pip
360
382
 
361
383
 
362
384
  if (this.platform === "darwin") {
@@ -427,7 +449,7 @@ class Bin {
427
449
  } else {
428
450
  e4 = false
429
451
  }
430
- console.log({ e, e2, e3, e4, stdout })
452
+ console.log("BREW CHECK", { e, e2, e3, e4 })
431
453
  this.brew_installed = e && e2 && e3 && e4
432
454
 
433
455
  }
@@ -644,7 +666,7 @@ class Bin {
644
666
  if (type === "conda") {
645
667
  return this.kernel.bin.installed.conda.has(name)
646
668
  } else if (type === "pip") {
647
- return this.kernel.bin.installed.pip.has(name)
669
+ return this.kernel.bin.installed.pip && this.kernel.bin.installed.pip.has(name)
648
670
  } else if (type === "brew") {
649
671
  return this.kernel.bin.installed.brew.has(name)
650
672
  } else {
package/kernel/index.js CHANGED
@@ -14,6 +14,7 @@ const Api = require("./api")
14
14
  const Python = require("./python")
15
15
  //const Template = require('./template')
16
16
  const Template = require('jimini')
17
+ const which = require('which')
17
18
  const Shells = require("./shells")
18
19
  const Key = require("./key")
19
20
  const Script = require('./script')
@@ -222,6 +223,25 @@ class Kernel {
222
223
  async wait(options) {
223
224
  await waitOn(options)
224
225
  }
226
+ async getInfo(){
227
+ let info = this.sysinfo
228
+ await this.update_sysinfo()
229
+ let i = {
230
+ platform: this.platform,
231
+ arch: this.arch,
232
+ running: this.api.running,
233
+ home: this.homedir,
234
+ vars: this.vars,
235
+ memory: this.memory,
236
+ procs: this.procs,
237
+ gpu: this.gpu,
238
+ gpus: this.gpus,
239
+ version: this.version,
240
+ ...info
241
+ }
242
+
243
+ this.i = i
244
+ }
225
245
 
226
246
  async synchronize_proxies() {
227
247
  let proxy_registry_path = path.resolve(this.homedir, "proxy_registry")
@@ -309,7 +329,6 @@ class Kernel {
309
329
  this.template = new Template()
310
330
  try {
311
331
  let grant_permission = false
312
- console.log(">>>>>> this.homedir", this.homedir)
313
332
  if (this.homedir) {
314
333
 
315
334
  // 0. create homedir
@@ -357,7 +376,10 @@ class Kernel {
357
376
  if (this.envs) {
358
377
  this.template.update({
359
378
  env: this.envs,
360
- envs: this.envs
379
+ envs: this.envs,
380
+ which: (name) => {
381
+ return which.sync(name, { nothrow: true, path: this.envs.PATH })
382
+ }
361
383
  })
362
384
  }
363
385
  // console.log({ grant_permission })
@@ -381,9 +403,7 @@ class Kernel {
381
403
 
382
404
  //await this.shell.init()
383
405
 
384
- console.log("homedir", this.homedir)
385
406
  if (this.homedir) {
386
- console.log("> 1")
387
407
  await this.template.init({
388
408
  kernel: this,
389
409
  system,
@@ -393,19 +413,16 @@ class Kernel {
393
413
  return this.api.get_proxy_url("/proxy", port)
394
414
  },
395
415
  })
396
- console.log("> 2")
397
416
  this.sys = new Sysinfo()
398
417
  await this.sys.init(this)
399
418
  let info = this.sys.info
400
- await fs.promises.mkdir(this.path("logs"), { recursive: true }).catch((e) => { })
401
- await fs.promises.writeFile(this.path("logs/system.json"), JSON.stringify({
402
- platform: this.platform,
403
- arch: this.arch,
404
- home: this.homedir,
405
- ...info
406
- }, null, 2))
419
+
407
420
  this.sysinfo = info
408
- await this.update_sysinfo()
421
+
422
+ await this.getInfo()
423
+
424
+ await fs.promises.mkdir(this.path("logs"), { recursive: true }).catch((e) => { })
425
+ await fs.promises.writeFile(this.path("logs/system.json"), JSON.stringify(this.i, null, 2))
409
426
  /*
410
427
  this.sys = new Sysinfo()
411
428
  await this.sys.init(this)
package/kernel/shell.js CHANGED
@@ -659,7 +659,7 @@ class Shell {
659
659
  if (params.venv) {
660
660
  let env_path = path.resolve(params.path, params.venv)
661
661
  let activate_path = (this.platform === 'win32' ? path.resolve(env_path, "Scripts", "activate") : path.resolve(env_path, "bin", "activate"))
662
- let deactivate_path = (this.platform === 'win32' ? path.resolve(env_path, "Scripts", "deactivate") : path.resolve(env_path, "bin", "deactivate"))
662
+ let deactivate_path = (this.platform === 'win32' ? path.resolve(env_path, "Scripts", "deactivate") : "deactivate")
663
663
  let env_exists = await this.exists(env_path)
664
664
  if (env_exists) {
665
665
  venv_activation = [
@@ -671,7 +671,7 @@ class Shell {
671
671
  `python -m venv ${env_path}`,
672
672
  (this.platform === "win32" ? `${activate_path} ${env_path}` : `source ${activate_path} ${env_path}`),
673
673
  `python -m pip install --upgrade pip setuptools wheel`,
674
- (this.platform === "win32" ? `${deactivate_path}` : `source ${deactivate_path}`),
674
+ deactivate_path,
675
675
  (this.platform === 'win32' ? `${timeout} /t 1 > nul` : 'sleep 1'),
676
676
  (this.platform === "win32" ? `${activate_path} ${env_path}` : `source ${activate_path} ${env_path}`),
677
677
  (this.platform === 'win32' ? `${timeout} /t 1 > nul` : 'sleep 1'),
@@ -721,9 +721,9 @@ class Shell {
721
721
  this.queue.push(data)
722
722
  }
723
723
  });
724
- this.ptyProcess.onExit((result) => {
725
- console.log(">>>>>>>>>>>>>>>>>>> exec onExit", result)
726
- })
724
+ // this.ptyProcess.onExit((result) => {
725
+ // console.log(">>>>>>>>>>>>>>>>>>> exec onExit", result)
726
+ // })
727
727
  }
728
728
  } catch (e) {
729
729
  console.log("** Error", e)
@@ -747,7 +747,6 @@ class Shell {
747
747
  }
748
748
  }
749
749
  kill(message, force) {
750
- console.log("> KILL", { message, force })
751
750
 
752
751
  this.done = true
753
752
  this.ready = false
@@ -877,7 +876,6 @@ ${cleaned}
877
876
  let cached_msg = msg
878
877
  // todo: may need to handle cases when the command returns immediately with no output (example: 'which brew' returns immediately with no text if brew doesn't exist)
879
878
  setTimeout(() => {
880
- console.log({ cache, cleaned })
881
879
  if (cache === cleaned) {
882
880
  if (this.persistent) {
883
881
  if (this.cb) this.cb({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pinokiod",
3
- "version": "3.2.198",
3
+ "version": "3.2.201",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -59,6 +59,7 @@
59
59
  "systeminformation": "^5.18.4",
60
60
  "uuid": "^9.0.0",
61
61
  "wait-on": "^7.2.0",
62
+ "which": "^5.0.0",
62
63
  "ws": "^8.13.0",
63
64
  "xterm-addon-fit": "^0.8.0",
64
65
  "xterm-addon-serialize": "^0.9.0",
package/server/index.js CHANGED
@@ -229,7 +229,7 @@ class Server {
229
229
  let error = null
230
230
  if (config && config.version) {
231
231
  let coerced = semver.coerce(config.version)
232
- console.log("version", { coerced, v: config.version })
232
+ // console.log("version", { coerced, v: config.version })
233
233
  if (semver.satisfies(coerced, this.kernel.schema)) {
234
234
  console.log("semver satisfied", config.version, this.kernel.schema)
235
235
  } else {
@@ -1761,7 +1761,7 @@ class Server {
1761
1761
  if (type === "conda") {
1762
1762
  return this.kernel.bin.installed.conda.has(name)
1763
1763
  } else if (type === "pip") {
1764
- return this.kernel.bin.installed.pip.has(name)
1764
+ return this.kernel.bin.installed.pip && this.kernel.bin.installed.pip.has(name)
1765
1765
  } else if (type === "brew") {
1766
1766
  return this.kernel.bin.installed.brew.has(name)
1767
1767
  } else {
@@ -2114,6 +2114,9 @@ class Server {
2114
2114
  console.log(`[TRY] reset ${p}`)
2115
2115
  await fse.remove(p)
2116
2116
  console.log(`[DONE] reset ${p}`)
2117
+ console.log("[TRY] Updating to the new version")
2118
+ this.kernel.store.set("version", this.version.pinokiod)
2119
+ console.log("[DONE] Updating to the new version")
2117
2120
  }
2118
2121
  }
2119
2122
 
@@ -3073,6 +3076,12 @@ class Server {
3073
3076
  await compressing.zip.compressDir(folder, zipPath)
3074
3077
  res.json({ success: true })
3075
3078
  }))
3079
+ this.app.get("/pinokio/info", ex(async (req, res) => {
3080
+ console.time("getInfo")
3081
+ await this.kernel.getInfo()
3082
+ console.timeEnd("getInfo")
3083
+ res.json(this.kernel.i || {})
3084
+ }))
3076
3085
  this.app.get("/pinokio/port", ex(async (req, res) => {
3077
3086
  let port = await this.kernel.port()
3078
3087
  res.json({ result: port })