Skip to content

Commit

Permalink
fix: no loading of folders without interface
Browse files Browse the repository at this point in the history
  • Loading branch information
ImGajeed76 committed Nov 17, 2024
1 parent 79d92a3 commit aedbc54
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 21 deletions.
7 changes: 4 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@
)
from src.lib.interface_viewer import InterfaceViewer

interface_folder = Path("src/interfaces/testing")
src_folder = Path("src")
root_folder = Path(__file__).parent
interface_folder = root_folder / Path("src/interfaces")
src_folder = root_folder / Path("src")


def main():
interfaces = scan_interfaces(interface_folder, src_folder)

references = create_interface_references(interfaces)
references.extend(create_folder_references(interface_folder))
references.extend(create_folder_references(interfaces, interface_folder))

app = InterfaceViewer("TF Utils", references)
app.run()
Expand Down
45 changes: 27 additions & 18 deletions src/lib/interface_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,34 +118,43 @@ def create_interface_references(
]


def create_folder_references(folder_path: Path) -> List[InterfaceReference]:
def create_folder_references(
interface_infos: List[InterfaceInfo],
interface_folder_path: Path,
) -> List[InterfaceReference]:
"""
Converts folders to InterfaceReference objects.
Args:
folder_path: Path to the folder
interface_infos: List of InterfaceInfo objects
interface_folder_path: Path to the folder containing interface files
Returns:
List of InterfaceReference objects
"""
references = []

for folder in folder_path.glob("**/*"):
if folder.is_dir() and folder.name != "__pycache__":
info_file = folder / "info.md"
info_text = "Folder (no info.md)"
if info_file.exists():
with info_file.open("r") as f:
info_text = f.read().strip()

relative_folder = folder.relative_to(folder_path).as_posix()
references.append(
InterfaceReference(
path=f"root/{relative_folder}",
name=folder.name,
description=info_text,
active=True,
)
interface_paths = [interface_info.path for interface_info in interface_infos]
folder_paths = set()
for interface_path in interface_paths:
interface_folder = interface_path.split("/")
for i in range(1, len(interface_folder)):
folder_paths.add("/".join(interface_folder[:i]))

for folder_path in folder_paths:
info_file = interface_folder_path / folder_path / "info.md"
info_text = "Folder (no info.md)"
if info_file.exists():
with info_file.open("r") as f:
info_text = f.read().strip()

references.append(
InterfaceReference(
path=f"root/{folder_path}",
name=folder_path.split("/")[-1],
description=info_text,
active=True,
)
)

return references

0 comments on commit aedbc54

Please sign in to comment.