This repository has been archived by the owner on Dec 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,31 @@ | ||
from enum import Enum | ||
import inspect | ||
import re | ||
|
||
from sdRDM.base.importedmodules import ImportedModules | ||
from sdRDM.tools.gitutils import ObjectNode | ||
|
||
|
||
def camel_to_snake(name): | ||
"""Turns a camel cased name into snake case""" | ||
name = re.sub("(.)([A-Z][a-z]+)", r"\1_\2", name) | ||
return re.sub("([a-z0-9])([A-Z])", r"\1_\2", name).lower() | ||
|
||
|
||
def extract_modules(lib, links) -> ImportedModules: | ||
"""Extracts root nodes and specified modules from a generated API""" | ||
|
||
# Get all classes present | ||
classes = { | ||
obj.__name__: ObjectNode(obj) | ||
for obj in lib.__dict__.values() | ||
if inspect.isclass(obj) and not issubclass(obj, Enum) | ||
} | ||
|
||
enums = { | ||
obj.__name__: ObjectNode(obj) | ||
for obj in lib.__dict__.values() | ||
if inspect.isclass(obj) and issubclass(obj, Enum) | ||
} | ||
|
||
return ImportedModules(classes=classes, enums=enums, links=links) |