graphinate.server.starlette   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 22
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Functions

Rating   Name   Duplication   Size   Complexity  
A routes() 0 4 1
A _mount_static_files() 0 9 3
1
from collections.abc import Mapping
2
from pathlib import Path
3
4
from starlette.routing import Mount, Route
5
from starlette.staticfiles import StaticFiles
6
7
from ..web import paths_mapping
8
from .views import favicon_route
9
10
11
def _mount_static_files(named_paths: Mapping[str, Path]) -> list[Mount]:
12
    mounts = []
13
    for name, path in named_paths.items():
14
        if not name.startswith('__'):
15
            index_file = path / 'index.html'
16
            static_files = StaticFiles(directory=path, html=index_file.exists(), check_dir=True)
17
            mount = Mount(path=f"/{name}", app=static_files, name=name)
18
            mounts.append(mount)
19
    return mounts
20
21
22
def routes():
23
    route_list: list[Mount | Route] = _mount_static_files(paths_mapping)
24
    route_list.append(favicon_route())
25
    return route_list
26
27
28
__all__ = ('routes',)
29