def module_docstring(module_path: os.PathLike) -> str: import ast import inspect module_path = Path(module_path) try: module_ast = ast.parse(module_path.read_text(), filename=module_path.name) except SyntaxError: return '' module_doc = ast.get_docstring(module_ast) non_import_body = module_ast.body non_import_body = [ node for node in module_ast.body if not isinstance(node, (ast.Import, ast.ImportFrom)) ] if not module_doc and len(non_import_body) == 1 and isinstance( non_import_body[0], (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)): module_doc = ast.get_docstring(non_import_body[0]) if not module_doc: return '' return inspect.cleandoc(module_doc).splitlines()[0]
def parse_summary_json(self, summary_file: os.PathLike) -> None: """Parse a traning's summary json file. This populates the class properties with values and the resulting dictionary is saved to be accessible via the summary property. The common class properties (which all BaseTrainSummarys have by defition) besides `summary` are `features`, `region`, and `selecton_used`. This function will define those, so all BaseTrainSummary inheriting classes should call the super implementation of this method if a daughter implementation is necessary to add additional summary properties. Parameters ---------- summary_file : os.PathLike The summary json file. """ self._summary = json.loads(summary_file.read_text()) self._features = self.summary["features"] self._region = self.summary["region"] self._selection_used = self.summary["selection_used"]
def wrastf(src_path: os.PathLike) -> str: return wrasts(src_path.read_text())