pincer.middleware   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 28
dl 0
loc 52
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A get_middleware() 0 28 5
1
# Copyright Pincer 2021-Present
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
# Full MIT License can be found in `LICENSE` at the project root.
3
from __future__ import annotations
4
5
import logging
6
from glob import glob
7
from importlib import import_module
8
from pathlib import Path
9
from typing import TYPE_CHECKING
10
11
from ..utils.directory import chdir
12
13
if TYPE_CHECKING:
14
    from typing import Dict
15
    from ..utils.types import Coro
16
17
18
_log = logging.getLogger(__package__)
19
20
21
def get_middleware() -> Dict[str, Coro]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
22
    middleware_list: Dict[str, Coro] = {}
0 ignored issues
show
introduced by
The variable Coro does not seem to be defined in case TYPE_CHECKING on line 13 is False. Are you sure this can never be the case?
Loading history...
23
24
    with chdir(Path(__file__).parent.resolve()):
25
26
        for middleware_path in glob("*.py"):
27
            if middleware_path.startswith("__"):
28
                continue
29
30
            event = middleware_path[:-3]
31
32
            try:
33
                middleware_list[event] = getattr(
34
                    import_module(f".{event}", package=__name__), "export"
35
                )()
36
            except AttributeError:
37
                _log.warning(
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
38
                    f"Middleware {middleware_path} expected an `export` method."
39
                )
40
41
                continue
42
43
                # raise NoExportMethod(
44
                #    f"Middleware module `{middleware_path}` expected an "
45
                #    "`export` method but none was found!"
46
                # )
47
48
    return middleware_list
49
50
51
middleware: Dict[str, Coro] = get_middleware()
0 ignored issues
show
introduced by
The variable Coro does not seem to be defined in case TYPE_CHECKING on line 13 is False. Are you sure this can never be the case?
Loading history...
52