implement proposal for fetching paths and retaining structure of dirs and packages (#914)

* implement proposal

* update docs and replace py-env

* more docs

* suggested proposal

* update docs

* add to_file parameter

* remove comment from Makefile

* suggested improvements

* move tests from basic to py_config

* retain leading slash from the first path
This commit is contained in:
Madhur Tandon
2022-11-08 17:26:45 +05:30
committed by GitHub
parent 2f452e9dc7
commit 515858f313
27 changed files with 298 additions and 133 deletions

View File

@@ -8,6 +8,7 @@ import { PyLoader } from './components/pyloader';
import { PyodideRuntime } from './pyodide';
import { getLogger } from './logger';
import { handleFetchError, showError, globalExport } from './utils';
import { calculatePaths } from './plugins/fetch';
import { createCustomElements } from './components/elements';
type ImportType = { [key: string]: unknown };
@@ -171,15 +172,15 @@ class PyScriptApp {
// it in Python, which means we need to have the runtime
// initialized. But we could easily do it in JS in parallel with the
// download/startup of pyodide.
const paths = this.config.paths;
logger.info('Paths to fetch: ', paths);
for (const singleFile of paths) {
logger.info(` fetching path: ${singleFile}`);
const [paths, fetchPaths] = calculatePaths(this.config.fetch);
logger.info('Paths to fetch: ', fetchPaths);
for (let i=0; i<paths.length; i++) {
logger.info(` fetching path: ${fetchPaths[i]}`);
try {
await runtime.loadFromFile(singleFile);
await runtime.loadFromFile(paths[i], fetchPaths[i]);
} catch (e) {
//Should we still export full error contents to console?
handleFetchError(<Error>e, singleFile);
handleFetchError(<Error>e, fetchPaths[i]);
}
}
logger.info('All paths fetched');