pinokiod 1.0.51 → 1.0.53
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/kernel/api/fs/index.js +78 -19
- package/kernel/bin/py.js +20 -0
- package/kernel/python/index.js +1 -11
- package/kernel/python/mod.py +40 -0
- package/package.json +2 -2
- package/server/index.js +4 -0
- package/kernel/python/pip.py +0 -79
package/kernel/api/fs/index.js
CHANGED
|
@@ -113,40 +113,99 @@ class FS {
|
|
|
113
113
|
// pip sharing
|
|
114
114
|
// 1. get all pip items
|
|
115
115
|
let p
|
|
116
|
+
let drive_path
|
|
116
117
|
if (kernel.platform === "win32") {
|
|
117
118
|
p = path.resolve(req.cwd, req.params.venv, "Lib", "site-packages")
|
|
119
|
+
drive_path = "pip/Lib/site-packages"
|
|
118
120
|
} else {
|
|
119
121
|
p = path.resolve(req.cwd, req.params.venv, "lib", "python3.10", "site-packages")
|
|
122
|
+
drive_path = "pip/lib/python3.10/site-packages"
|
|
120
123
|
}
|
|
121
124
|
const res = await kernel.python.call(
|
|
122
|
-
"
|
|
123
|
-
path
|
|
124
|
-
"
|
|
125
|
+
"mod",
|
|
126
|
+
kernel.bin.path("py"),
|
|
127
|
+
"get",
|
|
125
128
|
[p],
|
|
126
129
|
ondata
|
|
127
130
|
)
|
|
128
|
-
|
|
131
|
+
console.log("RES", res)
|
|
129
132
|
// symlink:
|
|
130
133
|
// from => :package_path
|
|
131
134
|
// to => /drives/packages/pip/:package_name/:package_version
|
|
135
|
+
const drivePath = kernel.path("drive")
|
|
136
|
+
const drive = new Pdrive(drivePath)
|
|
132
137
|
for(let name in res) {
|
|
133
|
-
|
|
134
|
-
|
|
138
|
+
/*
|
|
139
|
+
torch: {
|
|
140
|
+
version: "2.1",
|
|
141
|
+
copy: [
|
|
142
|
+
'../../../bin/torchrun',
|
|
143
|
+
'../../../bin/convert-onnx-to-caffe2',
|
|
144
|
+
'../../../bin/convert-caffe2-to-onnx'
|
|
145
|
+
],
|
|
146
|
+
move: [
|
|
147
|
+
"torchgen",
|
|
148
|
+
"functorch",
|
|
149
|
+
"torch"
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
=>
|
|
155
|
+
|
|
156
|
+
{
|
|
157
|
+
copy: {
|
|
158
|
+
'../../../bin/torchrun': path.resolve(p, '../../../bin/torchrun')
|
|
159
|
+
'../../../bin/convert-onnx-to-caffe2': path.resolve(p, '../../../bin/convert-onnx-to-caffe2'),
|
|
160
|
+
'../../../bin/convert-caffe2-to-onnx': path.resolve(p, '../../../bin/convert-caffe2-to-onnx')
|
|
161
|
+
},
|
|
162
|
+
move: {
|
|
163
|
+
"torchgen": "torchgen",
|
|
164
|
+
"functorch": "functorch",
|
|
165
|
+
"torch": "torch"
|
|
166
|
+
},
|
|
167
|
+
parent: "pip/torch/2.1/lib/python3.10/site-packages"
|
|
168
|
+
}
|
|
169
|
+
*/
|
|
170
|
+
const copy = res[name].copy
|
|
171
|
+
const move = res[name].move
|
|
135
172
|
const version = res[name].version
|
|
136
|
-
|
|
173
|
+
|
|
174
|
+
console.log({ name, copy, move, version })
|
|
175
|
+
|
|
176
|
+
if (version) {
|
|
177
|
+
let site_packages_root;
|
|
178
|
+
if (kernel.platform === "win32") {
|
|
179
|
+
site_packages_root = `pip/${name}/${version}/Lib/site-packages`
|
|
180
|
+
} else {
|
|
181
|
+
site_packages_root = `pip/${name}/${version}/lib/python3.10/site-packages`
|
|
182
|
+
}
|
|
183
|
+
const d = {
|
|
184
|
+
copy: {},
|
|
185
|
+
move: {},
|
|
186
|
+
parent: site_packages_root
|
|
187
|
+
}
|
|
188
|
+
for(let relpath of copy) {
|
|
189
|
+
d.copy[relpath] = kernel.path("drive", p, relpath)
|
|
190
|
+
}
|
|
191
|
+
for(let relpath of move) {
|
|
192
|
+
d.move[relpath] = kernel.path("drive", p, relpath)
|
|
193
|
+
}
|
|
194
|
+
console.log("D", name, d)
|
|
195
|
+
ondata({
|
|
196
|
+
raw: "\r\nLINKING DRIVES:\r\n" + JSON.stringify(d, null, 2).replace(/\n/g, "\r\n")
|
|
197
|
+
})
|
|
198
|
+
await drive.create(d)
|
|
199
|
+
ondata({
|
|
200
|
+
raw: "Done.\r\n"
|
|
201
|
+
})
|
|
202
|
+
} else {
|
|
203
|
+
ondata({
|
|
204
|
+
raw: "\r\nNo version specified: " + name + " => Ignore"
|
|
205
|
+
})
|
|
206
|
+
}
|
|
207
|
+
|
|
137
208
|
}
|
|
138
|
-
ondata({
|
|
139
|
-
raw: "\r\nLINKING DRIVES:\r\n" + JSON.stringify(d, null, 2).replace(/\n/g, "\r\n")
|
|
140
|
-
})
|
|
141
|
-
const drivePath = kernel.path("drive")
|
|
142
|
-
const drive = new Pdrive(drivePath)
|
|
143
|
-
await drive.create({
|
|
144
|
-
drive: d,
|
|
145
|
-
parent: "packages/pip"
|
|
146
|
-
})
|
|
147
|
-
ondata({
|
|
148
|
-
raw: "Done.\r\n"
|
|
149
|
-
})
|
|
150
209
|
} else if (req.params.drive) {
|
|
151
210
|
const drivePath = kernel.path("drive")
|
|
152
211
|
const drive = new Pdrive(drivePath)
|
package/kernel/bin/py.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
class Py {
|
|
2
|
+
async install(req, ondata) {
|
|
3
|
+
await this.kernel.exec({
|
|
4
|
+
message: "git clone https://github.com/pinokiocomputer/python py",
|
|
5
|
+
path: this.kernel.path("bin")
|
|
6
|
+
}, ondata)
|
|
7
|
+
await this.kernel.exec({
|
|
8
|
+
message: "pip install -r requirements.txt",
|
|
9
|
+
path: this.kernel.bin.path("py")
|
|
10
|
+
}, ondata)
|
|
11
|
+
}
|
|
12
|
+
async installed() {
|
|
13
|
+
let exists = await this.kernel.exists(this.kernel.bin.path("py"))
|
|
14
|
+
return exists
|
|
15
|
+
}
|
|
16
|
+
async uninstall(req, ondata) {
|
|
17
|
+
await this.kernel.bin.rm(this.kernel.bin.path("py"), ondata)
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
module.exports = Py
|
package/kernel/python/index.js
CHANGED
|
@@ -7,20 +7,10 @@ class Python {
|
|
|
7
7
|
console.log("CALL", { modname, modpath, method, args })
|
|
8
8
|
// if this.proc doesn't exist, create
|
|
9
9
|
if (!this.proc) {
|
|
10
|
-
await this.kernel.exec({
|
|
11
|
-
message: [
|
|
12
|
-
"which pip",
|
|
13
|
-
"pip install fastapi importlib_metadata uvicorn[standard]",
|
|
14
|
-
],
|
|
15
|
-
conda: "base"
|
|
16
|
-
}, (s) => {
|
|
17
|
-
ondata(s)
|
|
18
|
-
})
|
|
19
|
-
console.log("Start uvicorn", __dirname)
|
|
20
10
|
await new Promise((resolve, reject) => {
|
|
21
11
|
this.kernel.exec({
|
|
22
12
|
message: "uvicorn --port 42001 server:app",
|
|
23
|
-
path:
|
|
13
|
+
path: modpath,
|
|
24
14
|
conda: "base"
|
|
25
15
|
}, (s) => {
|
|
26
16
|
// process.stdout.write(s)
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import importlib
|
|
3
|
+
import importlib_metadata
|
|
4
|
+
import os
|
|
5
|
+
# Get all the pip packages for the base path
|
|
6
|
+
def get(sitepackages_base):
|
|
7
|
+
sys.path=[sitepackages_base]
|
|
8
|
+
importlib.invalidate_caches()
|
|
9
|
+
dists = importlib_metadata.packages_distributions()
|
|
10
|
+
dict = {}
|
|
11
|
+
for package_name in dists:
|
|
12
|
+
for dist_name in dists[package_name]:
|
|
13
|
+
dict[dist_name] = {}
|
|
14
|
+
# get package path
|
|
15
|
+
try:
|
|
16
|
+
meta = importlib_metadata.metadata(dist_name)
|
|
17
|
+
files = importlib_metadata.files(dist_name)
|
|
18
|
+
move = set()
|
|
19
|
+
copy = set()
|
|
20
|
+
for file in files:
|
|
21
|
+
filepath = os.path.join(sitepackages_base, file)
|
|
22
|
+
dirpath = os.path.abspath(os.path.dirname(filepath))
|
|
23
|
+
try:
|
|
24
|
+
relpath = Path(dirpath).relative_to(sitepackages_base)
|
|
25
|
+
# site package handling
|
|
26
|
+
chunks = str(relpath).split(os.sep)
|
|
27
|
+
if len(chunks) > 1:
|
|
28
|
+
folder = chunks[0]
|
|
29
|
+
move.add(os.path.join(sitepackages_base, folder))
|
|
30
|
+
except:
|
|
31
|
+
# non site package handling
|
|
32
|
+
# add the full file paths => so they can be copied
|
|
33
|
+
copy.add(str(filepath))
|
|
34
|
+
dict[dist_name]["copy"] = list(copy)
|
|
35
|
+
dict[dist_name]["move"] = list(move)
|
|
36
|
+
except Exception as error:
|
|
37
|
+
print(f"#ERR {error}")
|
|
38
|
+
return dict
|
|
39
|
+
if __name__ == "__main__":
|
|
40
|
+
get("/Users/x/pinokio/api/comfyui.git/app/env/lib/python3.10/site-packages")
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pinokiod",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.53",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"node-calls-python": "^1.8.2",
|
|
44
44
|
"node-downloader-helper": "^2.1.9",
|
|
45
45
|
"node-pty-prebuilt-multiarch-cp": "^0.10.1-pre.48",
|
|
46
|
-
"pdrive": "^0.0.
|
|
46
|
+
"pdrive": "^0.0.23",
|
|
47
47
|
"portfinder": "^1.0.32",
|
|
48
48
|
"random-useragent": "^0.5.0",
|
|
49
49
|
"rimraf": "^5.0.0",
|
package/server/index.js
CHANGED
|
@@ -289,6 +289,8 @@ class Server {
|
|
|
289
289
|
type: "conda",
|
|
290
290
|
name: "nodejs",
|
|
291
291
|
args: "-c conda-forge"
|
|
292
|
+
}, {
|
|
293
|
+
name: "py"
|
|
292
294
|
}]
|
|
293
295
|
let platform = os.platform()
|
|
294
296
|
if (platform === "win32") {
|
|
@@ -528,6 +530,8 @@ class Server {
|
|
|
528
530
|
type: "conda",
|
|
529
531
|
name: "nodejs",
|
|
530
532
|
args: "-c conda-forge"
|
|
533
|
+
}, {
|
|
534
|
+
name: "py"
|
|
531
535
|
}]
|
|
532
536
|
let platform = os.platform()
|
|
533
537
|
if (platform === "win32") {
|
package/kernel/python/pip.py
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import pkg_resources
|
|
2
|
-
import platform
|
|
3
|
-
from pathlib import Path
|
|
4
|
-
import site
|
|
5
|
-
import sysconfig
|
|
6
|
-
import sys
|
|
7
|
-
import importlib
|
|
8
|
-
import importlib_metadata
|
|
9
|
-
import os
|
|
10
|
-
|
|
11
|
-
# Get all the pip packages for the base path
|
|
12
|
-
def list(sitepackages_base):
|
|
13
|
-
# print(f"LIST {sitepackages_base}")
|
|
14
|
-
sys.path=[sitepackages_base]
|
|
15
|
-
importlib.invalidate_caches()
|
|
16
|
-
|
|
17
|
-
# sys.path.insert(0, sitepackages_base)
|
|
18
|
-
print(f"sys.path={sys.path}")
|
|
19
|
-
print(f"sys.meta_path={sys.meta_path}")
|
|
20
|
-
print(f"sys.path_hooks={sys.path_hooks}")
|
|
21
|
-
#dists = importlib_metadata.packages_distributions()
|
|
22
|
-
dists = importlib_metadata.packages_distributions()
|
|
23
|
-
print(f"dists={dists}")
|
|
24
|
-
# print(f"DISTS {dists}")
|
|
25
|
-
|
|
26
|
-
# print(f"SYSPATH {sys.path}")
|
|
27
|
-
# for key in sys.modules:
|
|
28
|
-
# print(f"## {key}: {sys.modules[key]}")
|
|
29
|
-
# print(f"sys.modules={sys.modules}")
|
|
30
|
-
#print(f"BEFORE PATH: {sys.path}")
|
|
31
|
-
#print(f"AFTER PATH: {sys.path}")
|
|
32
|
-
# pkg_resources.working_set.add_entry(sitepackages_base)
|
|
33
|
-
sitepackages_path = sysconfig.get_paths()["purelib"]
|
|
34
|
-
dict = {}
|
|
35
|
-
# packages = importlib.resources.files(package)
|
|
36
|
-
for package_name in dists:
|
|
37
|
-
print(f"package_name={package_name}")
|
|
38
|
-
for dist_name in dists[package_name]:
|
|
39
|
-
# get package path
|
|
40
|
-
try:
|
|
41
|
-
meta = importlib_metadata.metadata(dist_name)
|
|
42
|
-
files = importlib_metadata.files(dist_name)
|
|
43
|
-
|
|
44
|
-
for file in files:
|
|
45
|
-
|
|
46
|
-
#if str(file).startswith("_"):
|
|
47
|
-
if str(file).startswith("__pycache__"):
|
|
48
|
-
continue
|
|
49
|
-
if str(file).startswith("."):
|
|
50
|
-
continue
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
# if the resolved path
|
|
54
|
-
abspath = os.path.join(sitepackages_base, file)
|
|
55
|
-
is_child = Path(abspath).is_relative_to(sitepackages_base) and (sitepackages_base in abspath)
|
|
56
|
-
if is_child:
|
|
57
|
-
relative = str(file)
|
|
58
|
-
chunks = relative.split(os.sep)
|
|
59
|
-
if len(chunks) > 1:
|
|
60
|
-
folder = chunks[0]
|
|
61
|
-
package_path = str(os.path.join(sitepackages_base, folder))
|
|
62
|
-
if not hasattr(dict, folder):
|
|
63
|
-
dict[folder] = {}
|
|
64
|
-
|
|
65
|
-
try:
|
|
66
|
-
dict[folder]["version"] = meta["Version"]
|
|
67
|
-
except:
|
|
68
|
-
print('no version')
|
|
69
|
-
dict[folder]["name"] = folder
|
|
70
|
-
dict[folder]["path"] = package_path
|
|
71
|
-
except Exception as error:
|
|
72
|
-
print(f"#ERR {error}")
|
|
73
|
-
# nothing
|
|
74
|
-
|
|
75
|
-
# get dist path (only if there's a version)
|
|
76
|
-
|
|
77
|
-
print(f"DICT={dict}")
|
|
78
|
-
|
|
79
|
-
return dict
|