4
4
5
5
import { expose } from 'comlink' ;
6
6
7
- import { DriveFS } from '@jupyterlite/contents' ;
7
+ import { DriveFS , DriveFSEmscriptenNodeOps , IEmscriptenFSNode , IStats } from '@jupyterlite/contents' ;
8
8
9
9
declare function createXeusModule ( options : any ) : any ;
10
10
11
11
globalThis . Module = { } ;
12
12
13
+ // TODO Remove this. This is to ensure we always perform node ops on Nodes and
14
+ // not Streams, but why is it needed??? Why do we get Streams and not Nodes from
15
+ // emscripten in the case of xeus-python???
16
+ class StreamNodeOps extends DriveFSEmscriptenNodeOps {
17
+
18
+ private getNode ( nodeOrStream : any ) {
19
+ if ( nodeOrStream [ "node" ] ) {
20
+ return nodeOrStream [ "node" ] ;
21
+ }
22
+ return nodeOrStream ;
23
+ } ;
24
+
25
+ lookup ( parent : IEmscriptenFSNode , name : string ) : IEmscriptenFSNode {
26
+ return super . lookup ( this . getNode ( parent ) , name ) ;
27
+ } ;
28
+
29
+ getattr ( node : IEmscriptenFSNode ) : IStats {
30
+ return super . getattr ( this . getNode ( node ) ) ;
31
+ } ;
32
+
33
+ setattr ( node : IEmscriptenFSNode , attr : IStats ) : void {
34
+ super . setattr ( this . getNode ( node ) , attr ) ;
35
+ } ;
36
+
37
+ mknod (
38
+ parent : IEmscriptenFSNode ,
39
+ name : string ,
40
+ mode : number ,
41
+ dev : any
42
+ ) : IEmscriptenFSNode {
43
+ return super . mknod ( this . getNode ( parent ) , name , mode , dev ) ;
44
+ } ;
45
+
46
+ rename ( oldNode : IEmscriptenFSNode , newDir : IEmscriptenFSNode , newName : string ) : void {
47
+ super . rename ( this . getNode ( oldNode ) , this . getNode ( newDir ) , newName ) ;
48
+ } ;
49
+
50
+ rmdir ( parent : IEmscriptenFSNode , name : string ) : void {
51
+ super . rmdir ( this . getNode ( parent ) , name ) ;
52
+ } ;
53
+
54
+ readdir ( node : IEmscriptenFSNode ) : string [ ] {
55
+ return super . readdir ( this . getNode ( node ) ) ;
56
+ } ;
57
+
58
+ }
59
+
60
+ // TODO Remove this when we don't need StreamNodeOps anymore
61
+ class LoggingDrive extends DriveFS {
62
+ constructor ( options : DriveFS . IOptions ) {
63
+ super ( options ) ;
64
+
65
+ this . node_ops = new StreamNodeOps ( this ) ;
66
+ }
67
+ }
68
+
13
69
// when a toplevel cell uses an await, the cell is implicitly
14
70
// wrapped in a async function. Since the webloop - eventloop
15
71
// implementation does not support `eventloop.run_until_complete(f)`
@@ -46,35 +102,26 @@ class XeusPythonKernel {
46
102
mount ( driveName : string , mountpoint : string , baseUrl : string ) : void {
47
103
const { FS , PATH , ERRNO_CODES } = globalThis . Module ;
48
104
49
- console . log ( 'mounting drivefs' , driveName , mountpoint , baseUrl ) ;
50
-
51
- this . _drive = new DriveFS ( {
105
+ this . _drive = new LoggingDrive ( {
52
106
FS ,
53
107
PATH ,
54
108
ERRNO_CODES ,
55
109
baseUrl,
56
110
driveName,
57
111
mountpoint
58
112
} ) ;
59
- console . log ( 'mkdir mountpoint' ) ;
60
113
61
114
FS . mkdir ( mountpoint ) ;
62
115
FS . mount ( this . _drive , { } , mountpoint ) ;
63
- console . log ( 'chdir mountpoint' ) ;
64
116
FS . chdir ( mountpoint ) ;
65
- console . log ( 'done chdir mountpoint' ) ;
66
117
}
67
118
68
119
cd ( path : string ) {
69
120
if ( ! path ) {
70
121
return ;
71
122
}
72
123
73
- const { FS } = globalThis . Module ;
74
-
75
- console . log ( 'chdir path' , path ) ;
76
- FS . chdir ( path ) ;
77
- console . log ( 'done chdir path' ) ;
124
+ globalThis . Module . FS . chdir ( path ) ;
78
125
}
79
126
80
127
async processMessage ( event : any ) : Promise < void > {
@@ -90,8 +137,6 @@ class XeusPythonKernel {
90
137
globalThis . toplevel_promise = null ;
91
138
}
92
139
93
- console . log ( 'received this in the worker' , event ) ;
94
-
95
140
const msg_type = event . msg . header . msg_type ;
96
141
97
142
if ( msg_type === 'input_reply' ) {
@@ -104,20 +149,12 @@ class XeusPythonKernel {
104
149
private async initialize ( resolve : ( ) => void ) {
105
150
importScripts ( './xpython_wasm.js' ) ;
106
151
107
- console . log ( 'init xeus kernel' ) ;
108
-
109
152
globalThis . Module = await createXeusModule ( { } ) ;
110
153
111
- console . log ( 'done init xeus kernel' ) ;
112
-
113
154
importScripts ( './python_data.js' ) ;
114
155
115
- console . log ( 'loaded python data' ) ;
116
-
117
156
await this . waitRunDependency ( ) ;
118
157
119
- console . log ( 'waited run deps' ) ;
120
-
121
158
this . _raw_xkernel = new globalThis . Module . xkernel ( ) ;
122
159
this . _raw_xserver = this . _raw_xkernel . get_server ( ) ;
123
160
@@ -131,10 +168,9 @@ class XeusPythonKernel {
131
168
}
132
169
133
170
private async waitRunDependency ( ) {
134
- const promise = new Promise ( ( resolve : any ) => {
171
+ const promise = new Promise < void > ( resolve => {
135
172
globalThis . Module . monitorRunDependencies = ( n : number ) => {
136
173
if ( n === 0 ) {
137
- console . log ( 'all `RunDependencies` loaded' ) ;
138
174
resolve ( ) ;
139
175
}
140
176
} ;
0 commit comments