MCPcopy Create free account
hub / github.com/Distributive-Network/PythonMonkey / runProgramModule

Function runProgramModule

python/pythonmonkey/require.py:401–415  ·  view source on GitHub ↗

Run the program module. This loads the code from disk, sets up the execution environment, and then invokes the program module (aka main module). The program module is different from other modules in that 1. it cannot return (must throw) 2. the outermost block scope is the global scope, effe

(filename, argv, extraPaths=[])

Source from the content-addressed store, hash-verified

399
400
401def runProgramModule(filename, argv, extraPaths=[]):
402 """
403 Run the program module. This loads the code from disk, sets up the execution environment, and then
404 invokes the program module (aka main module). The program module is different from other modules in that
405 1. it cannot return (must throw)
406 2. the outermost block scope is the global scope, effectively making its scope a super-global to
407 other modules
408 """
409 fullFilename = os.path.abspath(filename)
410 createRequire(fullFilename, extraPaths, True)
411 globalThis.__filename = fullFilename
412 globalThis.__dirname = os.path.dirname(fullFilename)
413 with open(fullFilename, encoding="utf-8", mode="r") as mainModuleSource:
414 pm.eval(mainModuleSource.read(), {'filename': fullFilename, 'noScriptRval': True})
415 # forcibly run in file mode. We shouldn't be getting the last expression of the script as the result value.
416
417# The pythonmonkey require export. Every time it is used, the stack is inspected so that the filename
418# passed to createRequire is correct. This is necessary so that relative requires work. If the filename

Callers

nothing calls this directly

Calls 1

createRequireFunction · 0.85

Tested by

no test coverage detected