Skip to content

Commit

Permalink
Even better PyEditor offline use case (#2050)
Browse files Browse the repository at this point in the history
* Even better PyEditor offline use case

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
WebReflection and pre-commit-ci[bot] committed May 7, 2024
1 parent 9bd4737 commit 8ec3381
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 71 deletions.
124 changes: 62 additions & 62 deletions pyscript.core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pyscript.core/package.json
@@ -1,6 +1,6 @@
{
"name": "@pyscript/core",
"version": "0.4.27",
"version": "0.4.31",
"type": "module",
"description": "PyScript",
"module": "./index.js",
Expand Down Expand Up @@ -43,7 +43,7 @@
"dependencies": {
"@ungap/with-resolvers": "^0.1.0",
"basic-devtools": "^0.1.6",
"polyscript": "^0.12.7",
"polyscript": "^0.12.8",
"sticky-module": "^0.1.1",
"to-json-callback": "^0.1.1",
"type-checked-collections": "^0.1.7"
Expand All @@ -54,17 +54,17 @@
"@codemirror/language": "^6.10.1",
"@codemirror/state": "^6.4.1",
"@codemirror/view": "^6.26.3",
"@playwright/test": "^1.43.1",
"@playwright/test": "^1.44.0",
"@rollup/plugin-commonjs": "^25.0.7",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-terser": "^0.4.4",
"@webreflection/toml-j0.4": "^1.1.3",
"@xterm/addon-fit": "^0.10.0",
"@xterm/addon-web-links": "^0.11.0",
"bun": "^1.1.6",
"bun": "^1.1.7",
"chokidar": "^3.6.0",
"codemirror": "^6.0.1",
"eslint": "^9.1.1",
"eslint": "^9.2.0",
"rollup": "^4.17.2",
"rollup-plugin-postcss": "^4.0.2",
"rollup-plugin-string": "^3.0.0",
Expand Down
5 changes: 4 additions & 1 deletion pyscript.core/src/core.js
Expand Up @@ -84,6 +84,9 @@ export {
exportedWhenDefined as whenDefined,
};

export const offline_interpreter = (config) =>
config?.interpreter && new URL(config.interpreter, location.href).href;

const hooked = new Map();

for (const [TYPE, interpreter] of TYPES) {
Expand Down Expand Up @@ -294,7 +297,7 @@ for (const [TYPE, interpreter] of TYPES) {
interpreter,
hooks,
env: `${TYPE}-script`,
version: config?.interpreter,
version: offline_interpreter(config),
onerror(error, element) {
errors.set(element, error);
},
Expand Down
5 changes: 2 additions & 3 deletions pyscript.core/src/plugins/py-editor.js
@@ -1,6 +1,6 @@
// PyScript py-editor plugin
import { Hook, XWorker, dedent } from "polyscript/exports";
import { TYPES, stdlib } from "../core.js";
import { TYPES, offline_interpreter, stdlib } from "../core.js";

const RUN_BUTTON = `<svg style="height:20px;width:20px;vertical-align:-.125em;transform-origin:center;overflow:visible;color:green" viewBox="0 0 384 512" aria-hidden="true" role="img" xmlns="http://www.w3.org/2000/svg"><g transform="translate(192 256)" transform-origin="96 0"><g transform="translate(0,0) scale(1,1)"><path d="M361 215C375.3 223.8 384 239.3 384 256C384 272.7 375.3 288.2 361 296.1L73.03 472.1C58.21 482 39.66 482.4 24.52 473.9C9.377 465.4 0 449.4 0 432V80C0 62.64 9.377 46.63 24.52 38.13C39.66 29.64 58.21 29.99 73.03 39.04L361 215z" fill="currentColor" transform="translate(-192 -256)"></path></g></g></svg>`;

Expand Down Expand Up @@ -42,8 +42,7 @@ async function execute({ currentTarget }) {
? await import(/* webpackIgnore: true */ "../3rd-party/toml.js")
: JSON;
details.config = parse(await fetch(config).then((r) => r.text()));
const { interpreter } = details.config;
if (interpreter) details.version = interpreter;
details.version = offline_interpreter(details.config);
}

const xworker = XWorker.call(new Hook(null, hooks), srcLink, details);
Expand Down
1 change: 1 addition & 0 deletions pyscript.core/types/core.d.ts
@@ -1,3 +1,4 @@
export function offline_interpreter(config: any): string;
import { stdlib } from "./stdlib.js";
import { optional } from "./stdlib.js";
import TYPES from "./types.js";
Expand Down

0 comments on commit 8ec3381

Please sign in to comment.