Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-06-07 07:04:26 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-06-07 07:04:26 +0300
commit98876d46efb4533c2d5115dfd17cd663054d1d2c (patch)
treef8eb1a59318b944478b48761f6f5142f2234a29c /release
parent7ef2b760dc233d61a2350e20d4e65cb76dbb9311 (diff)
Fix T88899: `__file__` not set for `text.as_module()`
Diffstat (limited to 'release')
-rw-r--r--release/scripts/modules/bpy_types.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index aa540eeb23b..d7e31a8ec5d 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -560,9 +560,17 @@ class Text(bpy_types.ID):
self.write(string)
def as_module(self):
- from os.path import splitext
+ import bpy
+ from os.path import splitext, join
from types import ModuleType
- mod = ModuleType(splitext(self.name)[0])
+ name = self.name
+ mod = ModuleType(splitext(name)[0])
+ # This is a fake file-path, set this since some scripts check `__file__`,
+ # error messages may include this as well.
+ # NOTE: the file path may be a blank string if the file hasn't been saved.
+ mod.__dict__.update({
+ "__file__": join(bpy.data.filepath, name),
+ })
# TODO: We could use Text.compiled (C struct member)
# if this is called often it will be much faster.
exec(self.as_string(), mod.__dict__)