PythonMonkey   v1.1.1 (dev)
Loading...
Searching...
No Matches
pythonmonkey.require Namespace Reference

Functions

Union[Dict[str, int], bool] statSync_inner (str filename)
 
str readFileSync (filename, charset)
 
bool existsSync (str filename)
 
Dict load (str filename)
 
 createRequire (filename, Union[List[str], Literal[False]] extraPaths=False, isMain=False)
 
 runProgramModule (filename, argv, extraPaths=[])
 
 require (str moduleIdentifier)
 

Variables

 node_modules
 
dict evalOpts = {'filename': __file__, 'fromPythonFrame': True}
 
 encoding
 
 globalThis = pm.eval("globalThis;", evalOpts)
 
 pmEval
 
 dir
 
 isCompilableUnit
 
 nodeModules
 
 print
 
 write
 
 read
 
 eval
 
 exec
 
 getenv
 
 paths
 
 exit
 
 bootstrap = pm.eval(, evalOpts)
 
 statSync_inner
 
 readFileSync
 
 existsSync
 
 initCtxModule = pm.eval( + ctxModuleSource.read() + , {'filename': node_modules + "/ctx-module/ctx-module.js", 'lineno': 0})
 
 load
 
 createRequireInner = pm.eval(, evalOpts)
 
 requireFromDisk
 
 inspect
 

Function Documentation

◆ createRequire()

pythonmonkey.require.createRequire (   filename,
Union[List[str], Literal[False]]   extraPaths = False,
  isMain = False 
)
returns a require function that resolves modules relative to the filename argument.
Conceptually the same as node:module.createRequire().

example:
from pythonmonkey import createRequire
require = createRequire(__file__)
require('./my-javascript-module')

◆ existsSync()

bool pythonmonkey.require.existsSync ( str  filename)

◆ load()

Dict pythonmonkey.require.load ( str  filename)
Loads a python module using the importlib machinery sourcefileloader, prefills it with an exports object and returns
the module.
If the module is already loaded, returns it.

Args:
    filename (str): The filename of the python module to load.

Returns:
    : The loaded python module

◆ readFileSync()

str pythonmonkey.require.readFileSync (   filename,
  charset 
)
Utility function for reading files.
Returns:
    str: The contents of the file

◆ require()

pythonmonkey.require.require ( str  moduleIdentifier)

◆ runProgramModule()

pythonmonkey.require.runProgramModule (   filename,
  argv,
  extraPaths = [] 
)
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, effectively making its scope a super-global to
   other modules

◆ statSync_inner()

Union[Dict[str, int], bool] pythonmonkey.require.statSync_inner ( str  filename)
Inner function for statSync.

Returns:
    Union[Dict[str, int], False]: The mode of the file or False if the file doesn't exist.

Variable Documentation

◆ bootstrap

pythonmonkey.require.bootstrap = pm.eval(, evalOpts)

◆ createRequireInner

pythonmonkey.require.createRequireInner = pm.eval(, evalOpts)

◆ dir

pythonmonkey.require.dir

◆ encoding

pythonmonkey.require.encoding

◆ eval

pythonmonkey.require.eval

◆ evalOpts

dict pythonmonkey.require.evalOpts = {'filename': __file__, 'fromPythonFrame': True}

◆ exec

pythonmonkey.require.exec

◆ existsSync

pythonmonkey.require.existsSync

◆ exit

pythonmonkey.require.exit

◆ getenv

pythonmonkey.require.getenv

◆ globalThis

pythonmonkey.require.globalThis = pm.eval("globalThis;", evalOpts)

◆ initCtxModule

pythonmonkey.require.initCtxModule = pm.eval( + ctxModuleSource.read() + , {'filename': node_modules + "/ctx-module/ctx-module.js", 'lineno': 0})

◆ inspect

pythonmonkey.require.inspect

◆ isCompilableUnit

pythonmonkey.require.isCompilableUnit

◆ load

pythonmonkey.require.load

◆ node_modules

pythonmonkey.require.node_modules
Initial value:
1= os.path.abspath(
2 os.path.join(
3 importlib.util.find_spec("pminit").submodule_search_locations[0], # type: ignore
4 "..",
5 "pythonmonkey",
6 "node_modules"
7 )
8)

◆ nodeModules

pythonmonkey.require.nodeModules

◆ paths

pythonmonkey.require.paths

◆ pmEval

pythonmonkey.require.pmEval

◆ print

pythonmonkey.require.print

◆ read

pythonmonkey.require.read

◆ readFileSync

pythonmonkey.require.readFileSync

◆ requireFromDisk

pythonmonkey.require.requireFromDisk

◆ statSync_inner

pythonmonkey.require.statSync_inner

◆ write

pythonmonkey.require.write