Skip to content

Commit b22f384

Browse files
PyGame - TOML + JSON absolute URL + input patch (pyscript#2313)
* Make config URL canonical * Better baseURL + input patch
1 parent caeab77 commit b22f384

5 files changed

Lines changed: 17 additions & 5 deletions

File tree

core/package-lock.json

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

core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pyscript/core",
3-
"version": "0.6.36",
3+
"version": "0.6.39",
44
"type": "module",
55
"description": "PyScript",
66
"module": "./index.js",

core/src/plugins/py-game.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ import { getText } from "../fetch.js";
1111

1212
const progress = createProgress("py-game");
1313

14+
const inputPatch = `
15+
import builtins
16+
def input(prompt=""):
17+
import js
18+
return js.prompt(prompt)
19+
20+
builtins.input = input
21+
del builtins
22+
del input
23+
`;
24+
1425
let toBeWarned = true;
1526

1627
const hooks = {
@@ -45,7 +56,7 @@ const hooks = {
4556
progress,
4657
wrap.interpreter,
4758
config,
48-
url || location.href,
59+
url ? new URL(url, location.href).href : location.href,
4960
);
5061
}
5162

@@ -63,6 +74,7 @@ const hooks = {
6374
});
6475

6576
await wrap.interpreter.runPythonAsync(stdlib);
77+
wrap.interpreter.runPython(inputPatch);
6678

6779
let code = dedent(script.textContent);
6880
if (script.src) code = await fetch(script.src).then(getText);

core/tests/manual/game/config.toml

Whitespace-only changes.

core/tests/manual/game/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<script type="module" src="../../../dist/core.js"></script>
99
</head>
1010
<body>
11-
<script type="py-game" src="aliens.py" config="{}"></script>
11+
<script type="py-game" src="aliens.py" config="./config.toml"></script>
1212
<div class="demo">
1313
<div class="demo-header">pygame.examples.aliens</div>
1414
<div class="demo-content">

0 commit comments

Comments
 (0)