meta: add method to list modules of a given class
New Index.list_modules_for_class method that will list the names of all the modules of a certain class, like 'Stage' or 'Assembler'.
This commit is contained in:
parent
2d5ec8edad
commit
dd00c4f478
1 changed files with 13 additions and 1 deletions
|
|
@ -25,7 +25,7 @@ import copy
|
|||
import os
|
||||
import json
|
||||
from collections import deque
|
||||
from typing import Dict, Iterable, Optional
|
||||
from typing import Dict, Iterable, List, Optional
|
||||
|
||||
import jsonschema
|
||||
|
||||
|
|
@ -365,6 +365,18 @@ class Index:
|
|||
self._module_info = {}
|
||||
self._schemata = {}
|
||||
|
||||
def list_modules_for_class(self, klass: str) -> List[str]:
|
||||
"""List all available modules for the given `klass`"""
|
||||
module_path = ModuleInfo.module_class_to_directory(klass)
|
||||
|
||||
if not module_path:
|
||||
raise ValueError(f"Unsupported nodule class: {klass}")
|
||||
|
||||
path = os.path.join(self.path, module_path)
|
||||
modules = filter(lambda f: os.path.isfile(f"{path}/{f}"),
|
||||
os.listdir(path))
|
||||
return list(modules)
|
||||
|
||||
def get_module_info(self, klass, name) -> Optional[ModuleInfo]:
|
||||
"""Obtain `ModuleInfo` for a given stage or assembler"""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue