Skip to content
This repository has been archived by the owner on Aug 7, 2024. It is now read-only.

Commit

Permalink
fix: Try updating Pyodide (#1642)
Browse files Browse the repository at this point in the history
* fix: Try updating Pyodide

* Try removing languagePluginLoader

* Update pyodide installation

* Updated initialisation of Pyodide + updated threads lib

* Update pyodide

* Cleanup

* Fix test??

* Cleaning types and imports
  • Loading branch information
faucomte97 authored Apr 27, 2022
1 parent 9a2cc11 commit 4931148
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 27 deletions.
3 changes: 1 addition & 2 deletions game_frontend/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ module.exports = {
'cypress/globals': true,
},
globals: {
pyodide: 'readonly',
languagePluginLoader: 'readonly',
loadPyodide: 'readonly',
OnetrustActiveGroups: 'readonly',
},
rules: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ return MoveAction(direction.NORTH)`
.its('consoleLog.logs')
.then(logs => {
const log = logs.entries().next().value[1]
expect(log).to.deep.equal('IndentationError: expected an indented block\n')
expect(log).to.deep.equal('IndentationError: expected an indented block after function definition on line 1\n')
})
})

Expand Down
2 changes: 1 addition & 1 deletion game_frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
"rxjs": "^6.5.2",
"socket.io-client": "^4.0.0",
"styled-components": "^5.2.0",
"threads": "^1.6.3",
"threads": "^1.7.0",
"webfontloader": "^1.6.28"
},
"esLintConfig": {
Expand Down
3 changes: 1 addition & 2 deletions game_frontend/src/global.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
declare var pyodide: Pyodide
declare var languagePluginLoader: Promise<void>
declare var OnetrustActiveGroups: string
declare function loadPyodide(): Promise<Pyodide>

interface Pyodide {
loadPackage(packages: string[]): Promise<void>
Expand Down
23 changes: 14 additions & 9 deletions game_frontend/src/pyodide/webWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import { expose } from 'threads/worker'
import ComputedTurnResult from './computedTurnResult'

let pyodide: Pyodide

function getAvatarStateFromGameState(gameState: any, playerAvatarID: number): object {
return gameState.players.find(player => player.id === playerAvatarID)
}

async function initializePyodide() {
self.languagePluginUrl = 'https://pyodide-cdn2.iodide.io/v0.15.0/full/'
importScripts('https://pyodide-cdn2.iodide.io/v0.15.0/full/pyodide.js')
await languagePluginLoader
importScripts('https://cdn.jsdelivr.net/pyodide/v0.20.0/full/pyodide.js')
pyodide = await loadPyodide()
await pyodide.loadPackage(['micropip'])
await pyodide.runPythonAsync(`
import micropip
Expand All @@ -18,13 +19,17 @@ micropip.install("${self.location.origin}/static/worker/aimmo_game_worker-0.0.0-
`)

await pyodide.runPythonAsync(`
from simulation import direction
from simulation import location
import contextlib
import sys
from js import Object
from io import StringIO
from pyodide import to_js
from simulation import direction, location
from simulation.action import MoveAction, PickupAction, WaitAction, MoveTowardsAction
from simulation.world_map import WorldMapCreator
from simulation.avatar_state import create_avatar_state
from io import StringIO
import contextlib
from simulation.world_map import WorldMapCreator
@contextlib.contextmanager
Expand Down Expand Up @@ -61,7 +66,7 @@ with capture_output() as output:
serialized_action = action.serialise()
stdout, stderr = output
logs = stdout.getvalue() + stderr.getvalue()
{"action": serialized_action, "log": logs, "turnCount": game_state["turnCount"] + 1}
to_js({"action": serialized_action, "log": logs, "turnCount": game_state["turnCount"] + 1}, dict_converter=Object.fromEntries)
`)
} catch (error) {
return Promise.resolve({
Expand Down
2 changes: 1 addition & 1 deletion game_frontend/src/redux/features/AvatarWorker/operators.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const timeoutIfWorkerTakesTooLong = (
) => computedTurnResult$ =>
computedTurnResult$.pipe(
timeout(PYODIDE_WORKER_PROCESSING_TIME, scheduler),
catchError(() => {
catchError((e) => {
resetWorker(
state$.value.editor.code.codeOnServer,
state$.value.game.connectionParameters.currentAvatarID
Expand Down
34 changes: 23 additions & 11 deletions game_frontend/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3307,6 +3307,13 @@ debug@^4.0.1, debug@^4.1.0, debug@^4.1.1, debug@~4.3.1:
dependencies:
ms "2.1.2"

debug@^4.2.0:
version "4.3.4"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.4.tgz#1319f6579357f2338d3337d2cdd4914bb5dcc865"
integrity sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==
dependencies:
ms "2.1.2"

debug@^4.3.2:
version "4.3.3"
resolved "https://registry.yarnpkg.com/debug/-/debug-4.3.3.tgz#04266e0b70a98d4462e6e288e38259213332b664"
Expand Down Expand Up @@ -5429,6 +5436,11 @@ is-observable@^1.1.0:
dependencies:
symbol-observable "^1.1.0"

is-observable@^2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/is-observable/-/is-observable-2.1.0.tgz#5c8d733a0b201c80dff7bb7c0df58c6a255c7c69"
integrity sha512-DailKdLb0WU+xX8K5w7VsJhapwHLZ9jjmazqCJq4X12CTgqq73TKnbRcnSLuXYPOoLQgV5IrD7ePiX/h1vnkBw==

is-path-cwd@^2.2.0:
version "2.2.0"
resolved "https://registry.yarnpkg.com/is-path-cwd/-/is-path-cwd-2.2.0.tgz#67d43b82664a7b5191fd9119127eb300048a9fdb"
Expand Down Expand Up @@ -7131,10 +7143,10 @@ object.values@^1.1.0, object.values@^1.1.1, object.values@^1.1.2, object.values@
es-abstract "^1.18.0-next.2"
has "^1.0.3"

observable-fns@^0.5.1:
version "0.5.1"
resolved "https://registry.yarnpkg.com/observable-fns/-/observable-fns-0.5.1.tgz#9b56478690dd0fa8603e3a7e7d2975d88bca0904"
integrity sha512-wf7g4Jpo1Wt2KIqZKLGeiuLOEMqpaOZ5gJn7DmSdqXgTdxRwSdBhWegQQpPteQ2gZvzCKqNNpwb853wcpA0j7A==
observable-fns@^0.6.1:
version "0.6.1"
resolved "https://registry.yarnpkg.com/observable-fns/-/observable-fns-0.6.1.tgz#636eae4fdd1132e88c0faf38d33658cc79d87e37"
integrity sha512-9gRK4+sRWzeN6AOewNBTLXir7Zl/i3GB6Yl26gK4flxz8BXVpD3kt8amREmWNb0mxYOGDotvE5a4N+PtGGKdkg==

on-finished@~2.3.0:
version "2.3.0"
Expand Down Expand Up @@ -9708,15 +9720,15 @@ text-table@^0.2.0:
resolved "https://registry.yarnpkg.com/text-table/-/text-table-0.2.0.tgz#7f5ee823ae805207c00af2df4a84ec3fcfa570b4"
integrity sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=

threads@^1.6.3:
version "1.6.3"
resolved "https://registry.yarnpkg.com/threads/-/threads-1.6.3.tgz#89324a93509403c90a169344023151ae1fe4986b"
integrity sha512-tKwFIWRgfAT85KGkrpDt2jWPO8IVH0sLNfB/pXad/VW9eUIY2Zlz+QyeizypXhPHv9IHfqRzvk2t3mPw+imhWw==
threads@^1.7.0:
version "1.7.0"
resolved "https://registry.yarnpkg.com/threads/-/threads-1.7.0.tgz#d9e9627bfc1ef22ada3b733c2e7558bbe78e589c"
integrity sha512-Mx5NBSHX3sQYR6iI9VYbgHKBLisyB+xROCBGjjWm1O9wb9vfLxdaGtmT/KCjUqMsSNW6nERzCW3T6H43LqjDZQ==
dependencies:
callsites "^3.1.0"
debug "^4.1.1"
is-observable "^1.1.0"
observable-fns "^0.5.1"
debug "^4.2.0"
is-observable "^2.1.0"
observable-fns "^0.6.1"
optionalDependencies:
tiny-worker ">= 2"

Expand Down

0 comments on commit 4931148

Please sign in to comment.