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..7987119d71f1 --- /dev/null +++ b/src/compas_blender/utilities/misc.py @@ -0,0 +1,30 @@ +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