Re: inject arbitrary python code into leo's node

2020-11-28 Thread gar
What I actually did. I created in myLeoSettings @string 'import-leo-user-libs-dir' node with path to dir where all of my modules reside and @data ''import-leo-user-libs-loader' node where loader code resides. @data ''import-leo-user-libs-loader' def import_leo_user_lib(*names): i

Re: inject arbitrary python code into leo's node

2020-11-27 Thread gar
tried. doesnt actually help. functions can deal with g&c, methods not. very strange that :-) 2020-11-27 23:06 GMT+03:00, tbp1...@gmail.com : > Try including g and c in the exec environment - > > environment = {'c': c, 'g': g} > exec(open(c.config.getString('lib-dir') + "/lib.py").read(), environme

Re: inject arbitrary python code into leo's node

2020-11-27 Thread tbp1...@gmail.com
Try including g and c in the exec environment - environment = {'c': c, 'g': g} exec(open(c.config.getString('lib-dir') + "/lib.py").read(), environment) On Friday, November 27, 2020 at 2:04:12 PM UTC-5 gar wrote: > I did simpler. In myLeoSettings I created a @string with path to the > libfile

Re: inject arbitrary python code into leo's node

2020-11-27 Thread gar
I did simpler. In myLeoSettings I created a @string with path to the libfile (it can there be customized by OS/hostname) In the command I just load the lib with: exec(open(c.config.getString('lib-dir') + "/lib.py").read()) and it loads pretty well. When I call any function from thay lib - it eve

Re: inject arbitrary python code into leo's node

2020-11-27 Thread tbp1...@gmail.com
You could also add your directories to the pythonpath by adding a .pth file containing the path(s), possibly in your application's directory or in site-packages. On Friday, November 27, 2020 at 11:18:58 AM UTC-5 tbp1...@gmail.com wrote: > You could put the packages into some standard location k

Re: inject arbitrary python code into leo's node

2020-11-27 Thread tbp1...@gmail.com
You could put the packages into some standard location known by Python, like sitecustomize. On Friday, November 27, 2020 at 10:33:25 AM UTC-5 gar wrote: > yeah, just reinvented that right now. > but actually I would love to avoid hardcoding the path > but got no idea which location should be the

Re: inject arbitrary python code into leo's node

2020-11-27 Thread gar
yeah, just reinvented that right now. but actually I would love to avoid hardcoding the path but got no idea which location should be the default one пятница, 27 ноября 2020 г. в 18:26:07 UTC+3, tbp1...@gmail.com: > Wouldn't this work, as long as you know the path already? > > import sys > sys.p

Re: inject arbitrary python code into leo's node

2020-11-27 Thread tbp1...@gmail.com
Wouldn't this work, as long as you know the path already? import sys sys.path.insert(path_to_lib, 0) import lib This would cause Python to look first in path_to_lib for the import. I've used this technique a few times myself. On Friday, November 27, 2020 at 9:16:06 AM UTC-5 gar wrote: > What I

Re: inject arbitrary python code into leo's node

2020-11-27 Thread gar
What I've done by now. In the very beginning of the command which wants to use my library's code I write: import importlib.util spec = importlib.util.spec_from_file_location("module.name", "") ltools = importlib.util.module_from_spec(spec) spec.loader.exec_module(ltools) lib.init(c, g) lib by i

inject arbitrary python code into leo's node

2020-11-26 Thread gar
here is what I need. Say I am trying to build leo-based IDE for js/ts/lua/sql. I have a number of common action like 'run selection in the external interpreter and place output to leo's tab' 'feed source file to some tool and replace content with output' and so on. They all are quite big pieces of