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

mandos.model   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 93
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 56
dl 0
loc 93
rs 10
c 0
b 0
f 0
wmc 7

5 Methods

Rating   Name   Duplication   Size   Complexity  
A MandosResources.path() 0 5 2
A MandosResources.json() 0 4 1
A CompoundStruct.simple_str() 0 4 2
A MandosResources.a_path() 0 9 1
A MandosResources.contains() 0 4 1
1
from __future__ import annotations
0 ignored issues
show
introduced by
Missing module docstring
Loading history...
2
3
import abc
4
import typing
5
from dataclasses import dataclass
6
from pathlib import Path
7
from typing import Optional, TypeVar, Union
8
9
from pocketutils.core.dot_dict import NestedDotDict
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.dot_dict'
Loading history...
10
from pocketutils.core.hashers import Hasher
0 ignored issues
show
introduced by
Unable to import 'pocketutils.core.hashers'
Loading history...
11
from pocketutils.tools.common_tools import CommonTools
0 ignored issues
show
introduced by
Unable to import 'pocketutils.tools.common_tools'
Loading history...
12
13
from mandos.model.settings import MANDOS_SETTINGS
14
from mandos.model.utils import MiscUtils
15
16
17
class Api(metaclass=abc.ABCMeta):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
18
    """ """
19
20
21
class CompoundNotFoundError(LookupError):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
22
    """ """
23
24
25
class MultipleMatchesError(ValueError):
0 ignored issues
show
Documentation introduced by
Empty class docstring
Loading history...
26
    """ """
27
28
29
T = TypeVar("T", covariant=True)
0 ignored issues
show
Coding Style Naming introduced by
Class name "T" doesn't conform to PascalCase naming style ('[^\\W\\da-z][^\\W_]+$' 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...
30
31
32
@dataclass(frozen=True, repr=True, order=True)
33
class CompoundStruct:
34
    """
35
    Uniform data view for ChEMBL, PubChem, etc.
36
    Contains the source db (e.g. "pubchem"), the ID as a str, the inchi, and the inchikey.
37
    """
38
39
    db: str
0 ignored issues
show
Coding Style Naming introduced by
Attribute name "db" 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...
40
    id: str
0 ignored issues
show
Coding Style Naming introduced by
Attribute name "id" 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...
41
    inchi: str
42
    inchikey: str
43
44
    @property
45
    def simple_str(self) -> str:
0 ignored issues
show
introduced by
Missing function or method docstring
Loading history...
46
        db = "" if self.db.lower() == "chembl" else self.db + " "
0 ignored issues
show
Coding Style Naming introduced by
Variable name "db" 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...
47
        return f"[{db}{self.id} : {self.inchikey}]"
48
49
50
class MandosResources:
0 ignored issues
show
introduced by
Missing class docstring
Loading history...
51
52
    start_time = MiscUtils.utc()
53
    start_time_local = start_time.astimezone()
54
    start_timestamp = start_time.isoformat(timespec="milliseconds")
55
    start_timestamp_filesys = start_time_local.strftime("%Y-%m-%d_%H-%M-%S")
56
    hasher: Hasher = Hasher("sha256", buffer_size=16 * 1024)
57
58
    @classmethod
59
    def contains(cls, *nodes: Union[Path, str], suffix: Optional[str] = None) -> bool:
60
        """Returns whether a resource file (or dir) exists."""
61
        return cls.path(*nodes, suffix=suffix).exists()
62
63
    @classmethod
64
    def path(cls, *nodes: Union[Path, str], suffix: Optional[str] = None) -> Path:
65
        """Gets a path of a test resource file under ``resources/``."""
66
        path = Path(Path(__file__).parent.parent, "resources", *nodes)
67
        return path.with_suffix(path.suffix if suffix is None else suffix)
68
69
    @classmethod
70
    def a_path(cls, *nodes: Union[Path, str], suffixes: Optional[typing.Set[str]] = None) -> Path:
71
        """Gets a path of a test resource file under ``resources/``, ignoring suffix."""
72
        path = Path(Path(__file__).parent.parent, "resources", *nodes)
73
        return CommonTools.only(
74
            [
75
                p
76
                for p in path.parent.glob(path.stem + "*")
77
                if p.is_file() and (suffixes is None or p.suffix in suffixes)
78
            ]
79
        )
80
81
    @classmethod
82
    def json(cls, *nodes: Union[Path, str], suffix: Optional[str] = None) -> NestedDotDict:
83
        """Reads a JSON file under ``resources/``."""
84
        return NestedDotDict.read_json(cls.path(*nodes, suffix=suffix))
85
86
87
__all__ = [
88
    "Api",
89
    "CompoundStruct",
90
    "CompoundNotFoundError",
91
    "MultipleMatchesError",
92
    "MandosResources",
93
]
94