1
1
import { create } from 'gc-hook' ;
2
2
3
- import { RUNNING_IN_WORKER , fetchFiles , fetchJSModules , fetchPaths , writeFile } from './_utils.js' ;
4
- import { getFormat , loader , registerJSModule , run , runAsync , runEvent } from './_python.js' ;
3
+ import { RUNNING_IN_WORKER , createProgress , writeFile } from './_utils.js' ;
4
+ import { getFormat , loader , loadProgress , registerJSModule , run , runAsync , runEvent } from './_python.js' ;
5
5
import { stdio } from './_io.js' ;
6
6
import { isArray } from '../utils.js' ;
7
7
@@ -73,6 +73,8 @@ const applyOverride = () => {
73
73
}
74
74
} ) ;
75
75
} ;
76
+
77
+ const progress = createProgress ( 'py' ) ;
76
78
/* c8 ignore stop */
77
79
78
80
// REQUIRES INTEGRATION TEST
@@ -85,17 +87,17 @@ export default {
85
87
// apply override ASAP then load foreign code
86
88
if ( ! RUNNING_IN_WORKER && config . experimental_create_proxy === 'auto' )
87
89
applyOverride ( ) ;
90
+ progress ( 'Loading Pyodide' ) ;
88
91
const { stderr, stdout, get } = stdio ( ) ;
89
92
const indexURL = url . slice ( 0 , url . lastIndexOf ( '/' ) ) ;
90
93
const interpreter = await get (
91
94
loadPyodide ( { stderr, stdout, indexURL } ) ,
92
95
) ;
93
96
const py_imports = importPackages . bind ( interpreter ) ;
94
97
loader . set ( interpreter , py_imports ) ;
95
- if ( config . files ) await fetchFiles ( this , interpreter , config . files , baseURL ) ;
96
- if ( config . fetch ) await fetchPaths ( this , interpreter , config . fetch , baseURL ) ;
97
- if ( config . js_modules ) await fetchJSModules ( config . js_modules , baseURL ) ;
98
+ await loadProgress ( this , progress , interpreter , config , baseURL ) ;
98
99
if ( config . packages ) await py_imports ( config . packages ) ;
100
+ progress ( 'Loaded Pyodide' ) ;
99
101
return interpreter ;
100
102
} ,
101
103
registerJSModule,
@@ -129,9 +131,21 @@ function transform(value) {
129
131
130
132
// exposed utility to import packages via polyscript.lazy_py_modules
131
133
async function importPackages ( packages ) {
134
+ // temporary patch/fix console.log which is used
135
+ // not only by Pyodide but by micropip too and there's
136
+ // no way to intercept those calls otherwise
137
+ const { log } = console ;
138
+ const _log = ( detail , ...rest ) => {
139
+ log ( detail , ...rest ) ;
140
+ console . log = log ;
141
+ progress ( detail ) ;
142
+ console . log = _log ;
143
+ } ;
144
+ console . log = _log ;
132
145
await this . loadPackage ( 'micropip' ) ;
133
146
const micropip = this . pyimport ( 'micropip' ) ;
134
147
await micropip . install ( packages , { keep_going : true } ) ;
148
+ console . log = log ;
135
149
micropip . destroy ( ) ;
136
150
}
137
151
/* c8 ignore stop */
0 commit comments