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>2019-04-18 15:45:23 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-04-18 16:00:43 +0300
commitdc8dd24351462e73c5d0260564aad9cd56fd6c33 (patch)
tree1bed91a568c961f5d65ef44e4e8f17c9d9259a27 /release/scripts/modules/bpy_types.py
parent6f087be9f97d6e4b8637b297322438cf23491cae (diff)
PyAPI: remove support for importing text blocks as modules
Allowing direct import of text blocks isn't especially useful, instead add `text.as_module()` script authors can do this explicitly if it's needed. Now the text "Register" option executes instead of loading as a module. This removes the need to keep track of the current Main, and C code to override Python's import & reload.
Diffstat (limited to 'release/scripts/modules/bpy_types.py')
-rw-r--r--release/scripts/modules/bpy_types.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/release/scripts/modules/bpy_types.py b/release/scripts/modules/bpy_types.py
index 32e8fe40c6a..fb4ccfaff7a 100644
--- a/release/scripts/modules/bpy_types.py
+++ b/release/scripts/modules/bpy_types.py
@@ -523,6 +523,15 @@ class Text(bpy_types.ID):
self.clear()
self.write(string)
+ def as_module(self):
+ from os.path import splitext
+ from types import ModuleType
+ mod = ModuleType(splitext(self.name)[0])
+ # 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__)
+ return mod
+
class Sound(bpy_types.ID):
__slots__ = ()