Skip to content
Snippets Groups Projects
Commit 2b44091b authored by tuhe's avatar tuhe
Browse files

Week 11

parent c16ac062
Branches
No related tags found
No related merge requests found
Showing
with 61 additions and 0 deletions
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
...@@ -37,3 +37,61 @@ class AsyncTimeLimit(TimeLimit): ...@@ -37,3 +37,61 @@ class AsyncTimeLimit(TimeLimit):
truncated = True truncated = True
return observation, reward, terminated, truncated, info return observation, reward, terminated, truncated, info
def _fix_webassembly_packages(yes_really_do_it=False):
import importlib
import os
assert yes_really_do_it, "This function is for internal use for deploying webassembly projects. Don't use it in your base dir."
spec = importlib.util.find_spec("sympy", None)
base = os.path.dirname(spec.origin)
testf = f"{base}/testing/__init__.py"
if base.startswith("/data/data/"):
# with open(testf, 'w') as f:
# f.write("# Nothingatall")
# with open(f"{base}/testing/runtests.py", 'w') as f:
# f.write("# Nothingatall")
fname = f"{base}/utilities/decorator.py"
assert os.path.isfile(fname)
code = open(fname, 'r').read()
with open(fname, 'w') as f:
# print(f"{fname=}")
f.write(ncode := "\n".join([l for l in code.splitlines() if not l.startswith("from sympy.testing")]))
code = open(fname := f"{base}/utilities/__init__.py", 'r').read()
code = code.replace("from .timeutils import timed", "timed = lambda x: 3")
with open(fname, 'w') as f:
f.write(code)
for fname in [f"{base}/core/parameters.py", f"{base}/matrices/utilities.py"]:
code = open(fname, 'r').read()
code = code.replace("from threading import local", "local = object")
with open(fname, 'w') as f:
f.write(code)
# Fix timeit.
code = open(fname := f"{base}/utilities/timeutils.py", 'r').read()
code = code.replace("import timeit", "# REMOVED")
with open(fname, 'w') as f:
f.write(code)
code = open(fname := f"{base}/testing/runtests.py", 'r').read()
code = code.replace("from timeit import default_timer as clock", "# REMOVED")
# DocTestFinder, DocTestRunner
#
# code = code.replace("import doctest as pdoctest", "# REMOVED")
# code = code.replace("from doctest import DocTestFinder, DocTestRunner", "DocTestFinder, DocTestRunner = object, object")
# code = code.replace("pdoctest._indent", "#REMOVED")
# code = code.replace("import doctest", "# REMOVED")
with open(fname, 'w') as f:
f.write(code)
print("Patched ok.")
"""NB. Remember to also patch Decimal by adding extra stuff like exceptions to the decimal-module which is masked by webassembly."""
pass
...@@ -88,11 +88,14 @@ async def _webassembly_interactive(env, agent, autoplay=False): ...@@ -88,11 +88,14 @@ async def _webassembly_interactive(env, agent, autoplay=False):
def filled_circle(surface, x, y, r, color): def filled_circle(surface, x, y, r, color):
pygame.draw.circle(surface, color, (x, y), r, width=0) pygame.draw.circle(surface, color, (x, y), r, width=0)
def hline(surface, x1, x2, y, color):
pygame.draw.line(surface, color, (x1, y), (x2, y) )
gfxdraw.aapolygon = aapolygon gfxdraw.aapolygon = aapolygon
gfxdraw.filled_polygon = filled_polygon gfxdraw.filled_polygon = filled_polygon
gfxdraw.aacircle = aacircle gfxdraw.aacircle = aacircle
gfxdraw.filled_circle = filled_circle gfxdraw.filled_circle = filled_circle
gfxdraw.hline = hline
# from irlc.utils.player_wrapper import AsyncPlayerWrapperPygame # from irlc.utils.player_wrapper import AsyncPlayerWrapperPygame
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment