Skip to content

Commit

Permalink
fix: ensure importable by non-pyodide environment
Browse files Browse the repository at this point in the history
  • Loading branch information
CNSeniorious000 committed May 23, 2024
1 parent 72aa4eb commit 925d758
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
6 changes: 5 additions & 1 deletion reasonify-headless/reasonify/tools/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from importlib import import_module
from pathlib import Path
from traceback import format_exception_only


def register_all():
for file in Path(__file__).parent.glob("*.py"):
if file.stem != "__init__":
import_module(f".{file.stem}", __package__)
try:
import_module(f".{file.stem}", __package__)
except ModuleNotFoundError as e:
print(*format_exception_only(e))
15 changes: 11 additions & 4 deletions reasonify-headless/reasonify/tools/input.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from js import window
from contextlib import suppress

from ..utils.tool import tool

Expand All @@ -7,7 +7,14 @@
def input(prompt: str):
"""return the input from the user, useful for asking questions to the user"""

if res := window.prompt(prompt):
return res
with suppress(ModuleNotFoundError):
from js import window

raise IOError("User cancelled the input (refused to input anything)")
if res := window.prompt(prompt):
return res

raise IOError("User cancelled the input (refused to input anything)")

from builtins import input

return input(prompt)

0 comments on commit 925d758

Please sign in to comment.