Skip to content
This repository has been archived by the owner on Dec 8, 2024. It is now read-only.

Commit

Permalink
move module extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
JR-1991 committed Jan 11, 2024
1 parent c86c151 commit f1391c0
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions sdRDM/generator/utils.py
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)

0 comments on commit f1391c0

Please sign in to comment.