hotspot / App /discovery.py
Mbonea's picture
new age with tortole user works but not tests
b856986
raw
history blame
967 Bytes
# discover_models.py
import importlib
import os
from typing import List
def discover_models(target_file: str,directory: str="./") -> List[str]:
"""
Discover target file (e.g., models.py) in all directories and subdirectories.
:param directory: The root directory to start searching from.
:param target_file: The filename to look for in subdirectories (e.g., "models.py").
:return: A list of module paths as strings.
"""
model_modules = []
# Traverse directory and subdirectories
for root, _, files in os.walk(directory):
if target_file in files:
# Construct the module path, converting file path to dot notation
relative_path = os.path.relpath(root, directory)
module_name = f"{directory.replace('/', '.')}.{relative_path.replace('/', '.')}.{target_file[:-3]}"
model_modules.append(module_name.replace('...',""))
print(model_modules)
return model_modules