meta: extract module class to dir mapping
Make the mapping of module class to the corresponding directory a method of the ModuleInfo class. This is so it can be re-used by others in the future.
This commit is contained in:
parent
1718740c6c
commit
2d5ec8edad
1 changed files with 11 additions and 8 deletions
|
|
@ -326,16 +326,10 @@ class ModuleInfo:
|
|||
def targets(a):
|
||||
return [t.id for t in filter_type(a.targets, ast.Name)]
|
||||
|
||||
mapping = {
|
||||
"Stage": "stages",
|
||||
"Assembler": "assemblers"
|
||||
}
|
||||
|
||||
if klass not in mapping:
|
||||
base = cls.module_class_to_directory(klass)
|
||||
if not base:
|
||||
raise ValueError(f"Unsupported type: {klass}")
|
||||
|
||||
base = mapping[klass]
|
||||
|
||||
path = os.path.join(root, base, name)
|
||||
try:
|
||||
with open(path) as f:
|
||||
|
|
@ -349,6 +343,15 @@ class ModuleInfo:
|
|||
info = {k: value(v) for k, v in targets if k in names}
|
||||
return cls(klass, name, info)
|
||||
|
||||
@staticmethod
|
||||
def module_class_to_directory(klass: str) -> str:
|
||||
mapping = {
|
||||
"Stage": "stages",
|
||||
"Assembler": "assemblers"
|
||||
}
|
||||
|
||||
return mapping.get(klass)
|
||||
|
||||
|
||||
class Index:
|
||||
"""Index of stages and assemblers
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue