dbousque / lymp

Use Python functions and objects from OCaml
MIT License
72 stars 1 forks source link

Ability to run modules from packages #12

Open XVilka opened 6 years ago

XVilka commented 6 years ago

Currently if I have 'mypkg' directory with 'init.py' and 'mymod.py' with 'myfunc' in it - it fails to get the function from the main. I use

let py_entrypoint pymod =
   get_string pymod "myfunc"

let py = Lymp.init ~exec:interpreter tmp_scripts_path in
let result = match (Int32.to_int script.typ) with
   | Some 1 -> (* Python snippet *)
        let snippet = get_module py mname in
        (* run snippet entry point *)
        let res = py_entrypoint snippet in
        close py;
        res
    | Some 2 -> (* Python ZIP of the module *)
        (* call unzip first *)
        exec_unzip ~dpath:tmp_scripts_path ~fpath:spath;
        let modname = mname ^ ".mymod" in
        let pymodule = get_module py modname in
        (* run module entry point *)
        let res = py_entrypoint pymodule in
        close py;
        res

if I change it to the "mymod.myfunc" in "py_entrypoint" - it still fails