Passed
Push — main ( 9813db...5006f2 )
by Douglas
01:43
created

mandos.entries.abstract_entries   A

Complexity

Total Complexity 15

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 75
dl 0
loc 93
rs 10
c 0
b 0
f 0
wmc 15

9 Methods

Rating   Name   Duplication   Size   Complexity  
A Entry._get_searcher() 0 8 1
A Entry.cmd() 0 8 4
A Entry._run() 0 20 2
A Entry.describe() 0 4 1
A Entry.run() 0 3 1
A Entry._get_default_key() 0 8 2
A Entry.get_search_type() 0 4 1
A Entry.test() 0 3 1
A Entry.default_param_values() 0 6 2
1
import abc
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
from pathlib import Path
3
from typing import Generic, Type, Optional, Mapping, Union
4
5
import typer
0 ignored issues
show
introduced by
Unable to import 'typer'
Loading history...
6
from typer.models import OptionInfo
0 ignored issues
show
introduced by
Unable to import 'typer.models'
Loading history...
7
8
from mandos import MANDOS_SETUP, logger
9
from mandos.entries.entries import S
10
from mandos.entries.searcher import Searcher
11
from mandos.model.searches import Search
12
from mandos.model.utils import ReflectionUtils
13
14
15
class Entry(Generic[S], metaclass=abc.ABCMeta):
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
16
    @classmethod
17
    def cmd(cls) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
18
        key = cls._get_default_key()
19
        if isinstance(key, typer.models.OptionInfo):
20
            key = key.default
21
        if key is None or not isinstance(key, str):
22
            raise AssertionError(f"Key for {cls.__name__} is {key}")
23
        return key
24
25
    @classmethod
26
    def describe(cls) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
27
        lines = [line.strip() for line in cls.run.__doc__.splitlines() if line.strip() != ""]
28
        return lines[0]
29
30
    @classmethod
31
    def run(cls, path: Path, **params) -> None:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
32
        raise NotImplementedError()
33
34
    @classmethod
35
    def get_search_type(cls) -> Type[S]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
36
        # noinspection PyTypeChecker
37
        return ReflectionUtils.get_generic_arg(cls, Search)
38
39
    # noinspection PyUnusedLocal
40
    @classmethod
41
    def test(cls, path: Path, **params) -> None:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
42
        cls.run(path, **{**params, **dict(check=True)})
43
44
    @classmethod
45
    def _run(
0 ignored issues
show
best-practice introduced by
Too many arguments (9/5)
Loading history...
Coding Style Naming introduced by
Argument name "to" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
46
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
47
        built: S,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
48
        path: Path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
49
        to: Optional[Path],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
50
        check: bool,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
51
        log: Optional[Path],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
52
        quiet: bool,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
53
        verbose: bool,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
54
        no_setup: bool,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
55
    ):
56
        MANDOS_SETUP(verbose, quiet, log, no_setup)
57
        searcher = cls._get_searcher(built, path, to)
58
        logger.notice(f"Searching {built.key} [{built.search_class}] on {path}")
59
        out = searcher.output_paths[built.key]
60
        if not check:
61
            searcher.search()
62
        logger.notice(f"Done! Wrote to {out}")
63
        return searcher
64
65
    @classmethod
66
    def _get_searcher(
0 ignored issues
show
Coding Style Naming introduced by
Argument name "to" doesn't conform to snake_case naming style ('([^\\W\\dA-Z][^\\WA-Z]2,|_[^\\WA-Z]*|__[^\\WA-Z\\d_][^\\WA-Z]+__)$' pattern)

This check looks for invalid names for a range of different identifiers.

You can set regular expressions to which the identifiers must conform if the defaults do not match your requirements.

If your project includes a Pylint configuration file, the settings contained in that file take precedence.

To find out more about Pylint, please refer to their site.

Loading history...
67
        cls,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
68
        built: S,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
69
        path: Path,
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
70
        to: Optional[Path],
0 ignored issues
show
Coding Style introduced by
Wrong hanging indentation before block (add 4 spaces).
Loading history...
71
    ):
72
        return Searcher([built], [to], path)
73
74
    @classmethod
75
    def default_param_values(cls) -> Mapping[str, Union[str, float, int, Path]]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
76
        return {
77
            param: (value.default if isinstance(value, OptionInfo) else value)
78
            for param, value in ReflectionUtils.default_arg_values(cls.run).items()
79
            if param not in {"key", "path"}
80
        }
81
82
    @classmethod
83
    def _get_default_key(cls) -> str:
84
        vals = ReflectionUtils.default_arg_values(cls.run)
85
        try:
86
            return vals["key"]
87
        except KeyError:
88
            logger.error(f"key not in {vals.keys()} for {cls.__name__}")
89
            raise
90
91
92
__all__ = ["Entry"]
93