mirror of
https://github.com/pyscript/pyscript.git
synced 2025-12-19 18:27:29 -05:00
* Fix #2304 - Make pyimport work as expected * [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>
This commit is contained in:
committed by
GitHub
parent
f2bbc6ed5f
commit
caeab77a8e
@@ -33,6 +33,7 @@ const hooks = {
|
|||||||
config = parse(text);
|
config = parse(text);
|
||||||
}
|
}
|
||||||
if (config.packages) {
|
if (config.packages) {
|
||||||
|
await wrap.interpreter.loadPackage("micropip");
|
||||||
const micropip = wrap.interpreter.pyimport("micropip");
|
const micropip = wrap.interpreter.pyimport("micropip");
|
||||||
await micropip.install(config.packages, {
|
await micropip.install(config.packages, {
|
||||||
keep_going: true,
|
keep_going: true,
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
12
core/tests/manual/issue-2304/index.html
Normal file
12
core/tests/manual/issue-2304/index.html
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<link rel="stylesheet" href="../../../dist/core.css">
|
||||||
|
<script type="module" src="../../../dist/core.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div id="status">Status:</div>
|
||||||
|
<canvas id="canvas" width="200" height="200"></canvas>
|
||||||
|
<script type="py-game" src="./main.py" config="./pyscript.toml"></script>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
34
core/tests/manual/issue-2304/main.py
Normal file
34
core/tests/manual/issue-2304/main.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import sys
|
||||||
|
print("Starting test...")
|
||||||
|
|
||||||
|
# Try NumPy
|
||||||
|
try:
|
||||||
|
import numpy as np
|
||||||
|
arr = np.array([1, 2, 3])
|
||||||
|
print(f"NumPy works: {arr.mean()}")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"NumPy error: {e}")
|
||||||
|
|
||||||
|
# Try PyGame without NumPy first
|
||||||
|
try:
|
||||||
|
print("Testing PyGame...")
|
||||||
|
import pygame
|
||||||
|
screen = pygame.display.set_mode((200, 200))
|
||||||
|
screen.fill((255, 0, 0)) # Fill with red
|
||||||
|
pygame.display.flip()
|
||||||
|
print("PyGame works!")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"PyGame error: {e}")
|
||||||
|
|
||||||
|
# Now try PyGame with NumPy
|
||||||
|
try:
|
||||||
|
print("Testing PyGame+NumPy...")
|
||||||
|
color_array = np.random.randint(0, 255, size=(50, 50, 3), dtype=np.uint8)
|
||||||
|
surface = pygame.surfarray.make_surface(color_array)
|
||||||
|
screen.blit(surface, (75, 75))
|
||||||
|
pygame.display.flip()
|
||||||
|
print("PyGame+NumPy integration works!")
|
||||||
|
except Exception as e:
|
||||||
|
print(f"PyGame+NumPy integration error: {e}")
|
||||||
|
|
||||||
|
print("Test completed")
|
||||||
2
core/tests/manual/issue-2304/pyscript.toml
Normal file
2
core/tests/manual/issue-2304/pyscript.toml
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
name = "PyGame Numpy Minimal Example Copy"
|
||||||
|
packages = [ "numpy", ]
|
||||||
Reference in New Issue
Block a user