mandos   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 101
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 66
dl 0
loc 101
rs 10
c 0
b 0
f 0
wmc 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A MandosUtils.get_query_type() 0 19 4
A MandosResources.path() 0 4 1
A MandosResources.metadata() 0 4 1
A MandosUtils.stars() 0 6 3
A MandosResources.json() 0 3 1
1
"""
2
Metadata for this project.
3
"""
4
5
import enum
6
import logging
7
import re
8
from dataclasses import dataclass
9
from datetime import datetime, timezone
10
from importlib.metadata import PackageNotFoundError
0 ignored issues
show
Bug introduced by
The name metadata does not seem to exist in module importlib.
Loading history...
introduced by
Unable to import 'importlib.metadata'
Loading history...
11
from importlib.metadata import metadata as __load
0 ignored issues
show
Bug introduced by
The name metadata does not seem to exist in module importlib.
Loading history...
introduced by
Unable to import 'importlib.metadata'
Loading history...
12
from pathlib import Path
13
from typing import Union, Mapping, Any
14
15
from pocketutils.core.dot_dict import NestedDotDict
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.dot_dict'
Loading history...
16
17
pkg = Path(__file__).absolute().parent.name
18
logger = logging.getLogger(pkg)
19
_metadata = None
0 ignored issues
show
Coding Style Naming introduced by
Constant name "_metadata" doesn't conform to UPPER_CASE naming style ('([^\\W\\da-z][^\\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...
20
try:
21
    _metadata = __load(Path(__file__).absolute().parent.name)
22
    __status__ = "Development"
23
    __copyright__ = "Copyright 2016–2021"
24
    __date__ = "2020-08-14"
25
    __uri__ = _metadata["home-page"]
26
    __title__ = _metadata["name"]
27
    __summary__ = _metadata["summary"]
28
    __license__ = _metadata["license"]
29
    __version__ = _metadata["version"]
30
    __author__ = _metadata["author"]
31
    __maintainer__ = _metadata["maintainer"]
32
    __contact__ = _metadata["maintainer"]
33
except PackageNotFoundError:  # pragma: no cover
34
    logger.error(f"Could not load package metadata for {pkg}. Is it installed?")
0 ignored issues
show
introduced by
Use lazy % formatting in logging functions
Loading history...
35
36
37
class MandosResources:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
38
    @classmethod
39
    def metadata(cls) -> Mapping[str, Any]:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
40
        # noinspection PyTypeChecker
41
        return _metadata
42
43
    @classmethod
44
    def path(cls, *nodes: Union[Path, str]) -> Path:
45
        """Gets a path of a test resource file under resources/."""
46
        return Path(Path(__file__).parent, "resources", *nodes)
47
48
    @classmethod
49
    def json(cls, *nodes: Union[Path, str]) -> NestedDotDict:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
50
        return NestedDotDict.read_json(Path(Path(__file__).parent, "resources", *nodes))
51
52
53
class QueryType(enum.Enum):
54
    """
55
    X
56
    """
57
58
    inchi = enum.auto()
59
    inchikey = enum.auto()
60
    chembl = enum.auto()
61
    smiles = enum.auto()
62
63
64
class MandosUtils:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
65
    @classmethod
66
    def stars(cls, pvalue: float) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
67
        for k, v in {0.001: "*" * 4, 0.005: "*" * 3, 0.01: "*" * 2, 0.05: "*", 0.1: "+"}.items():
0 ignored issues
show
Coding Style Naming introduced by
Variable name "v" 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...
68
            if pvalue < k:
69
                return v
70
        return "ns"
71
72
    @classmethod
73
    def get_query_type(cls, inchikey: str) -> QueryType:
74
        """
75
        Returns the type of query.
76
77
        Args:
78
            inchikey:
79
80
        Returns:
81
82
        """
83
        if inchikey.startswith("InChI="):
0 ignored issues
show
unused-code introduced by
Unnecessary "elif" after "return"
Loading history...
84
            return QueryType.inchi
85
        elif re.compile(r"[A-Z]{14}-[A-Z]{10}-[A-Z]").fullmatch(inchikey):
86
            return QueryType.inchikey
87
        elif re.compile(r"CHEMBL[0-9]+").fullmatch(inchikey):
88
            return QueryType.chembl
89
        else:
90
            return QueryType.smiles
91
92
93
if __name__ == "__main__":  # pragma: no cover
94
    if _metadata is not None:
95
        print(f"{pkg} (v{_metadata['version']})")
96
    else:
97
        print("Unknown project info")
98
99
100
__all__ = ["MandosResources", "QueryType", "MandosUtils"]
101