scripts: include __file__ in globals() (#24341)

This commit is contained in:
Frédéric Péters 2018-06-07 10:18:46 +02:00
parent 240ba37244
commit f0fd073219
1 changed files with 2 additions and 0 deletions

View File

@ -29,6 +29,7 @@ class Script(object):
for path in paths:
script_path = os.path.join(path, script_name + '.py')
if os.path.exists(script_path):
self.__file__ = script_path
self.code = open(script_path).read()
break
else:
@ -45,6 +46,7 @@ class Script(object):
def __call__(self, *args):
data = get_publisher().substitutions.get_context_variables().copy()
data['args'] = args
data['__file__'] = self.__file__
code_object = compile(self.code, self.script_name, 'exec')
eval(code_object, data)
return data.get('result')