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>2016-05-02 14:01:10 +0300
committerCampbell Barton <ideasman42@gmail.com>2016-05-02 14:06:15 +0300
commitf28c626574ee2de46f6b6de1d1c41b9e1d8307ef (patch)
tree578f0614a43a6c0e11095e91612acda22ff2df0f /tests/python/bl_load_py_modules.py
parent143f6c4bb24a88f76fe9823d6ad461896f3a76af (diff)
Fix bl_load_py_modules test
- scripts that execute directly need to include their basedir in the sys.path - modules which are in a directory without an __init__.py weren't importing.
Diffstat (limited to 'tests/python/bl_load_py_modules.py')
-rw-r--r--tests/python/bl_load_py_modules.py46
1 files changed, 45 insertions, 1 deletions
diff --git a/tests/python/bl_load_py_modules.py b/tests/python/bl_load_py_modules.py
index 4256cba0933..c13679d16f0 100644
--- a/tests/python/bl_load_py_modules.py
+++ b/tests/python/bl_load_py_modules.py
@@ -38,6 +38,12 @@ BLACKLIST = {
'io_import_dxf', # Because of cydxfentity.so dependency
}
+# Some modules need to add to the `sys.path`.
+MODULE_SYS_PATHS = {
+ # Runs in a Python subprocess, so its expected its basedir can be imported.
+ "io_blend_utils.blendfile_pack": ".",
+ }
+
if not bpy.app.build_options.freestyle:
BLACKLIST.add("render_freestyle_svg")
@@ -46,6 +52,34 @@ BLACKLIST_DIRS = (
) + tuple(addon_utils.paths()[1:])
+def module_names_recursive(mod_dir, *, parent=None):
+ """
+ a version of bpy.path.module_names that includes non-packages
+ """
+
+ is_package = os.path.exists(os.path.join(mod_dir, "__init__.py"))
+
+ for n in os.listdir(mod_dir):
+ if not n.startswith((".", "_")):
+ submod_full = os.path.join(mod_dir, n)
+ if os.path.isdir(submod_full):
+ if not parent:
+ subparent = n
+ else:
+ subparent = parent + "." + n
+ yield from module_names_recursive(submod_full, parent=subparent)
+ elif n.endswith(".py") and is_package is False:
+ submod = n[:-3]
+ if parent:
+ submod = parent + "." + submod
+ yield submod, submod_full
+
+
+def module_names_all(mod_dir):
+ yield from bpy.path.module_names(mod_dir)
+ yield from module_names_recursive(mod_dir)
+
+
def addon_modules_sorted():
modules = addon_utils.modules({})
modules[:] = [mod for mod in modules if not mod.__file__.startswith(BLACKLIST_DIRS)]
@@ -130,12 +164,22 @@ def load_modules():
filepath = m.__file__
if os.path.basename(filepath).startswith("__init__."):
mod_dir = os.path.dirname(filepath)
- for submod, submod_full in bpy.path.module_names(mod_dir):
+ for submod, submod_full in module_names_all(mod_dir):
# fromlist is ignored, ugh.
mod_name_full = m.__name__ + "." + submod
+
+ sys_path_back = sys.path[:]
+
+ sys.path.extend([
+ os.path.normpath(os.path.join(mod_dir, f))
+ for f in MODULE_SYS_PATHS.get(mod_name_full, ())
+ ])
+
__import__(mod_name_full)
mod_imp = sys.modules[mod_name_full]
+ sys.path[:] = sys_path_back
+
# check we load what we ask for.
assert(os.path.samefile(mod_imp.__file__, submod_full))