Skip to content

Commit b7a935a

Browse files
committed
fix: pm.require from the REPL
The stack filename is `<stdin>` for the REPL, which is not a valid path
1 parent bf56f73 commit b7a935a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

python/pythonmonkey/require.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,4 +253,7 @@ def createRequire(filename: str):
253253
def require(moduleIdentifier: str):
254254
# Retrieve the caller’s filename from the call stack
255255
filename = inspect.stack()[1].filename
256+
# From the REPL, the filename is "<stdin>", which is not a valid path
257+
if not os.path.exists(filename):
258+
filename = os.path.join(os.getcwd(), "__main__") # use the CWD instead
256259
return createRequire(filename)(moduleIdentifier)

0 commit comments

Comments
 (0)