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

starlette   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

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

2 Functions

Rating   Name   Duplication   Size   Complexity  
A routes() 0 7 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
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