File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed
Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change 11import os
2- from . import pmpm
2+ import sys
3+ import importlib
4+ import importlib .util
35
46WORK_DIR = os .path .join (
5- os .path .realpath (os .path .dirname (__file__ )),
6- "pythonmonkey"
7+ os .path .realpath (os .path .dirname (__file__ )),
8+ "pythonmonkey"
79)
810
11+ def import_file (module_name : str , file_path : str ):
12+ """
13+ Import a Python file from its relative path directly.
14+
15+ See https://docs.python.org/3/library/importlib.html#importing-a-source-file-directly
16+ """
17+ spec = importlib .util .spec_from_file_location (module_name , file_path )
18+ module = importlib .util .module_from_spec (spec ) # type: ignore
19+ sys .modules [module_name ] = module
20+ spec .loader .exec_module (module ) # type: ignore
21+ return module
22+
923def main ():
10- pmpm .main (WORK_DIR ) # cd pythonmonkey && npm i
24+ pmpm = import_file ("pmpm" , os .path .join (os .path .dirname (__file__ ), "./pmpm.py" )) # from . import pmpm
25+ pmpm .main (WORK_DIR ) # cd pythonmonkey && npm i
1126
1227if __name__ == "__main__" :
13- main ()
28+ main ()
You can’t perform that action at this time.
0 commit comments