From 32f8b4d36623248672b5f123a5a5c565353c962a Mon Sep 17 00:00:00 2001 From: Luc Papeleux <L.Papeleux@ULiege.be> Date: Wed, 26 Feb 2025 15:52:01 +0100 Subject: [PATCH] use of compile fct in exec .pythonrc.py --- launch.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/launch.py b/launch.py index 2024a95..8489a2f 100755 --- a/launch.py +++ b/launch.py @@ -349,8 +349,12 @@ class LaunchJob(ParametricJob): pin.write(('\tprint ("metafor dir %s not found!")\n'%mtfdir).encode('utf-8')) pin.write(b'\tsys.exit()\n\n') # __file__ has to be defined (with absPath) to execute .pythonc.py - pin.write(('__file__ = r"%s"\n'%os.path.join(mtfdir,'.pythonrc.py')).encode('utf-8')) - pin.write(('exec(open(r"%s").read())\n'%os.path.join(mtfdir,'.pythonrc.py')).encode('utf-8')) + pin.write(('rcfile = r"%s"\n'%os.path.join(mtfdir,'.pythonrc.py')).encode('utf-8')) + pin.write(('script = open(rcfile, encoding="utf-8").read()\n').encode('utf-8')) + pin.write(('exec(compile(script, rcfile, "exec"),{"__file__":rcfile})\n').encode('utf-8')) + + #pin.write(('__file__ = r"%s"\n'%os.path.join(mtfdir,'.pythonrc.py')).encode('utf-8')) + #pin.write(('exec(open(r"%s").read())\n'%os.path.join(mtfdir,'.pythonrc.py')).encode('utf-8')) pin.write(b'import toolbox.battery as b\n') pin.write(b'battery = b.Battery() \n') pin.write(b'battery.keepFacs = True\n') -- GitLab