Passed
Push — main ( 2bcd5c...05fcff )
by Eran
01:27
created

graphinate.server.starlette._mount_static_files()   A

Complexity

Conditions 3

Size

Total Lines 9
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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