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

Function initGlobalThis

python/pythonmonkey/cli/pmjs.py:308–323  ·  view source on GitHub ↗

Initialize globalThis for pmjs use in the extra-module context (eg -r, -e, -p). This context needs a require function which resolves modules relative to the current working directory at pmjs launch. The global require is to the JS function using a trick instead of a JS-wrapped-Python-wrapped

()

Source from the content-addressed store, hash-verified

306
307
308def initGlobalThis():
309 """
310 Initialize globalThis for pmjs use in the extra-module context (eg -r, -e, -p). This context
311 needs a require function which resolves modules relative to the current working directory at pmjs
312 launch. The global require is to the JS function using a trick instead of a JS-wrapped-Python-wrapped function
313 """
314 global requirePath
315
316 require = pm.createRequire(os.path.abspath(os.getcwd() + '/__pmjs_virtual__'), requirePath)
317 globalThis.require = require
318 globalInitModule = require(
319 os.path.realpath(
320 os.path.dirname(__file__) +
321 "/../lib/pmjs/global-init")) # module load has side-effects
322 globalThis.arguments = sys.argv
323 return globalInitModule
324
325
326def main():

Callers 1

mainFunction · 0.85

Calls 1

requireFunction · 0.85

Tested by

no test coverage detected