From 5b124e26e7393581e90d64628ad0690f22d8c862 Mon Sep 17 00:00:00 2001 From: beverly Date: Mon, 8 Feb 2021 17:08:54 +0100 Subject: [PATCH 1/3] add unload_modules to compas_blender --- CHANGELOG.md | 1 + src/compas_blender/utilities/__init__.py | 1 + src/compas_blender/utilities/misc.py | 34 ++++++++++++++++++++++++ 3 files changed, 36 insertions(+) create mode 100644 src/compas_blender/utilities/misc.py diff --git a/CHANGELOG.md b/CHANGELOG.md index eb13dd6db8b1..4dc7759ff341 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added * Added `RobotModel.remove_link`, `RobotModel.remove_joint`, `RobotModel.to_urdf_string`, and `RobotModel.ensure_geometry`. +* Added `compas_blender.unload_modules`. ### Changed diff --git a/src/compas_blender/utilities/__init__.py b/src/compas_blender/utilities/__init__.py index e72bd3ab4ec6..df2b66dbfc30 100644 --- a/src/compas_blender/utilities/__init__.py +++ b/src/compas_blender/utilities/__init__.py @@ -65,6 +65,7 @@ from .objects import * # noqa: F401 F403 from .collections import * # noqa: F401 F403 from .drawing import * # noqa: F401 F403 +from .misc import * # noqa: F401 F403 __all__ = [name for name in dir() if not name.startswith('_')] diff --git a/src/compas_blender/utilities/misc.py b/src/compas_blender/utilities/misc.py new file mode 100644 index 000000000000..38566166a298 --- /dev/null +++ b/src/compas_blender/utilities/misc.py @@ -0,0 +1,34 @@ +from __future__ import absolute_import +from __future__ import division +from __future__ import print_function + +import sys + + +__all__ = [ + 'unload_modules', +] + + +def unload_modules(top_level_module_name): + """Unloads all modules named starting with the specified string. + + This function eases the development workflow when editing a library that is + used from Blender. + + Parameters + ---------- + top_level_module_name : :obj:`str` + Name of the top-level module to unload. + + Returns + ------- + list + List of unloaded module names. + """ + modules = list(filter(lambda m: m.startswith(top_level_module_name), sys.modules)) + + for module in modules: + sys.modules.pop(module) + + return modules \ No newline at end of file From ee1ecb62fe82877ec61dab9caf59c2042ea46b91 Mon Sep 17 00:00:00 2001 From: beverly Date: Mon, 8 Feb 2021 17:18:33 +0100 Subject: [PATCH 2/3] whitespace --- src/compas_blender/utilities/misc.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/compas_blender/utilities/misc.py b/src/compas_blender/utilities/misc.py index 38566166a298..99aef9fac16e 100644 --- a/src/compas_blender/utilities/misc.py +++ b/src/compas_blender/utilities/misc.py @@ -31,4 +31,4 @@ def unload_modules(top_level_module_name): for module in modules: sys.modules.pop(module) - return modules \ No newline at end of file + return modules From 3d032ba70713fac92072c4c5e8c56c45a081bc0d Mon Sep 17 00:00:00 2001 From: beverly Date: Mon, 8 Feb 2021 19:05:27 +0100 Subject: [PATCH 3/3] remove unnecessary imports --- src/compas_blender/utilities/misc.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/compas_blender/utilities/misc.py b/src/compas_blender/utilities/misc.py index 99aef9fac16e..7987119d71f1 100644 --- a/src/compas_blender/utilities/misc.py +++ b/src/compas_blender/utilities/misc.py @@ -1,7 +1,3 @@ -from __future__ import absolute_import -from __future__ import division -from __future__ import print_function - import sys