Allow importing of homebrew material stored in a separate module.

This commit is contained in:
Mark Wolfman
2021-06-11 09:07:48 -05:00
parent b432e67a35
commit 7d564ac1e1
6 changed files with 54 additions and 3 deletions
+28
View File
@@ -0,0 +1,28 @@
"""Tools useful for defining homebrew content."""
from pathlib import Path
import importlib.util
from typing import Union
def import_homebrew(filepath: Union[str, Path]):
"""Import a module file containing homebrew content.
This is intended to be used in a character/GM sheet to load in
homebrew content defined in an external file.
Parameters
==========
filepath
The location of the python file containing the homebrew content.
Returns
=======
mod
The imported module of homebrew content.
"""
spec = importlib.util.spec_from_file_location("module.name", filepath)
mod = importlib.util.module_from_spec(spec)
spec.loader.exec_module(mod)
return mod