diff options
Diffstat (limited to 'reflect.py')
-rw-r--r-- | reflect.py | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/reflect.py b/reflect.py new file mode 100644 index 0000000..2cfb2f3 --- /dev/null +++ b/reflect.py @@ -0,0 +1,31 @@ +from dataclasses import dataclass +import importlib +import inspect +import pkgutil +import sys +import os + +@dataclass +class Reflect: + client_code_path:str + imported_modules = {} + + def __post_init__(self): + sys.path.insert(1, self.client_code_path) + self.client_modules = [p for p in pkgutil.iter_modules() if str(p[0])[12:-2] == self.client_code_path] + + def import_module(self, module_name): + for module in self.client_modules: + if module.name == module_name: + self.imported_modules[module_name] = importlib.import_module(module.name) + + def get_module_doc(self, module_name): + return inspect.getdoc(self.imported_modules[module_name]) + + +if __name__ == "__main__": + user_code_path = "/media/veracrypt1/Nextcloud/UniStuff/3.0 - CMP 3rd Year Project/ExampleSubmissions/Submission_A" + + reflect = Reflect(user_code_path) + reflect.import_module("pjtool") + print(reflect.get_module_doc("pjtool")) |