10000 Merge pull request #78 from pyscript/issue-77 · pyscript/polyscript@7b286a9 · GitHub
[go: up one dir, main page]

Skip to content

Commit 7b286a9

Browse files
Merge pull request #78 from pyscript/issue-77
Fix #77 - Allow `configURL` to be passed for custom types
2 parents b369515 + b7819cd commit 7b286a9

28 files changed

+223
-132
lines changed

docs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -586,6 +586,7 @@ The list of options' fields is described as such and all of these are *optional*
586586
| :------------------------ | :-------------------------------------------- | :--------|
587587
| interpreter | `{interpreter: 'pyodide'}` | Specifies the interpreter to use, such as *pyodide*, *micropython*, *wasmoon* or others. |
588588
| config | `{config: 'type.toml'}` `{config: {}}` | Ensure such config is already parsed and available, if not already passed as object, for every custom `type` that execute code. |
589+
| configURL | `{configURL: '/absolute/url/config.json'}` | If the passed `config` is an already resolved object, this field is neded to help resolving files in *fetch* or *packages* or others. |
589590
| version | `{version: '0.23.2'}` | Allow the usage of a specific version of an interpreter, same way `version` attribute works with `<script>` elements. |
590591
| env | `{env: 'my-project'}` | Guarantee same environment for every custom `type`, avoiding conflicts with any other possible default or custom environment. |
591592
| onerror | `(error, element) => { throw error; }` | Allows custom types to intercept early errors possibly happened while bootstrapping elements. |

docs/core.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/core.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

esm/custom.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export const handleCustomType = (node) => {
4141
known.add(node);
4242
const {
4343
interpreter: runtime,
44+
configURL,
4445
config,
4546
version,
4647
env,
@@ -55,6 +56,7 @@ export const handleCustomType = (node) => {
5556
const xworker = XWorker.call(new Hook(null, hooks), worker, {
5657
...nodeInfo(node, type),
5758
version,
59+
configURL,
5860
type: runtime,
5961
custom: type,
6062
config: node.getAttribute('config') || config || {},
@@ -78,6 +80,7 @@ export const handleCustomType = (node) => {
7880
name,
7981
version,
8082
config,
83+
configURL,
8184
runtime
8285
);
8386
engine.then((interpreter) => {

esm/exports.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// this file simply exports enough stuff to allow
22
// 3rd party libraries, including PyScript, to work
3+
import toJSONCallback from 'to-json-callback';
4+
export { toJSONCallback };
5+
36
export * from './fetch-utils.js';
47
export * from './index.js';
58
export * from './script-handler.js';

esm/interpreter/_io.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// REQUIRES INTEGRATION TEST
2+
/* c8 ignore start */
3+
export const io = new WeakMap();
4+
export const stdio = (init) => {
5+
const context = init || console;
6+
const localIO = {
7+
stderr: (context.stderr || console.error).bind(context),
8+
stdout: (context.stdout || console.log).bind(context),
9+
};
10+
return {
11+
stderr: (...args) => localIO.stderr(...args),
12+
stdout: (...args) => localIO.stdout(...args),
13+
async get(engine) {
14+
const interpreter = await engine;
15+
io.set(interpreter, localIO);
16+
return interpreter;
17+
},
18+
};
19+
};
20+
/* c8 ignore stop */

esm/interpreter/_python.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { dedent } from '../utils.js';
2-
import { io } from './_utils.js';
2+
import { io } from './_io.js';
33

44
// REQUIRES INTEGRATION TEST
55
/* c8 ignore start */

esm/interpreter/_utils.js

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,6 @@ import { absoluteURL, all, entries, importCSS, importJS, isArray, isCSS } from '
66

77
// REQUIRES INTEGRATION TEST
88
/* c8 ignore start */
9-
export const io = new WeakMap();
10-
export const stdio = (init) => {
11-
const context = init || console;
12-
const localIO = {
13-
stderr: (context.stderr || console.error).bind(context),
14-
stdout: (context.stdout || console.log).bind(context),
15-
};
16-
return {
17-
stderr: (...args) => localIO.stderr(...args),
18-
stdout: (...args) => localIO.stdo 109F7 ut(...args),
19-
async get(engine) {
20-
const interpreter = await engine;
21-
io.set(interpreter, localIO);
22-
return interpreter;
23-
},
24-
};
25-
};
269

2710
// This should be the only helper needed for all Emscripten based FS exports
2811
export const writeFile = ({ FS, PATH, PATH_FS }, path, buffer) => {

esm/interpreter/micropython.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { fetchFiles, fetchJSModules, fetchPaths, stdio, writeFile } from './_utils.js';
1+
import { fetchFiles, fetchJSModules, fetchPaths, writeFile } from './_utils.js';
22
import { registerJSModule, run, runAsync, runEvent } from './_python.js';
3+
import { stdio } from './_io.js';
34
import mip from '../python/mip.js';
45

56
const type = 'micropython';

esm/interpreter/pyodide.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { fetchFiles, fetchJSModules, fetchPaths, stdio, writeFile } from './_utils.js';
1+
import { fetchFiles, fetchJSModules, fetchPaths, writeFile } from './_utils.js';
22
import { registerJSModule, run, runAsync, runEvent } from './_python.js';
3+
import { stdio } from './_io.js';
34

45
const type = 'pyodide';
56
const toJsOptions = { dict_converter: Object.fromEntries };

0 commit comments

Comments
 (0)
0