diff options
author | Richard van der Hoff <1389908+richvdh@users.noreply.github.com> | 2019-09-24 15:07:26 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-24 15:07:26 +0100 |
commit | bb82be9851ac8e168e217dfd12f32bfd66752338 (patch) | |
tree | 51f3e623ba202f5b42f6585ccae703e682232d3f /synapse/util/module_loader.py | |
parent | Add sid to next_link for email validation (#6097) (diff) | |
parent | docstrings and comments (diff) | |
download | synapse-bb82be9851ac8e168e217dfd12f32bfd66752338.tar.xz |
Merge pull request #6069 from matrix-org/rav/fix_attribute_mapping
Fix a bug with saml attribute maps.
Diffstat (limited to 'synapse/util/module_loader.py')
-rw-r--r-- | synapse/util/module_loader.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/synapse/util/module_loader.py b/synapse/util/module_loader.py index 522acd5aa8..7ff7eb1e4d 100644 --- a/synapse/util/module_loader.py +++ b/synapse/util/module_loader.py @@ -14,12 +14,13 @@ # limitations under the License. import importlib +import importlib.util from synapse.config._base import ConfigError def load_module(provider): - """ Loads a module with its config + """ Loads a synapse module with its config Take a dict with keys 'module' (the module name) and 'config' (the config dict). @@ -38,3 +39,20 @@ def load_module(provider): raise ConfigError("Failed to parse config for %r: %r" % (provider["module"], e)) return provider_class, provider_config + + +def load_python_module(location: str): + """Load a python module, and return a reference to its global namespace + + Args: + location (str): path to the module + + Returns: + python module object + """ + spec = importlib.util.spec_from_file_location(location, location) + if spec is None: + raise Exception("Unable to load module at %s" % (location,)) + mod = importlib.util.module_from_spec(spec) + spec.loader.exec_module(mod) + return mod |