Перейти к содержанию

Ядро

Конфигурация

config

config module-attribute

config = Config()

Config

Config()
Source code in docstr_health/core/config.py
15
16
17
18
19
20
21
def __init__(self) -> None:
    self.pyproject_data = self._pyproject_data()
    self.data = self._data()
    self.parameters = self._parameters()
    self.requires = self._requires()
    self.excluded = self._excluded()
    self._cache_dir = _REPOS_DIR

pyproject_data instance-attribute

pyproject_data = self._pyproject_data()

data instance-attribute

data = self._data()

parameters instance-attribute

parameters = self._parameters()

requires instance-attribute

requires = self._requires()

excluded instance-attribute

excluded = self._excluded()

get_cache_dir

get_cache_dir() -> Path
Source code in docstr_health/core/config.py
23
24
def get_cache_dir(self) -> Path:
    return Path(self._cache_dir)

set_cache_dir

set_cache_dir(dir: Path) -> None
Source code in docstr_health/core/config.py
26
27
def set_cache_dir(self, dir: Path) -> None:
    self._cache_dir = dir

get_logs_dir staticmethod

get_logs_dir() -> Path
Source code in docstr_health/core/config.py
29
30
31
@staticmethod
def get_logs_dir() -> Path:
    return _LOGS_DIR

get_sorted_statuses staticmethod

get_sorted_statuses() -> list[str]
Source code in docstr_health/core/config.py
46
47
48
@staticmethod
def get_sorted_statuses() -> list[str]:
    return ["bad", "warning", "good", "special", "epic"]

get_version

get_version() -> str
Source code in docstr_health/core/config.py
50
51
52
53
54
55
56
57
def get_version(self) -> str:
    try:
        return metadata.version("docstr-health")
    except metadata.PackageNotFoundError:
        data = self.pyproject_data
        if data:
            return data.get("project", {}).get("version", "unknown")
        return "unknown"

get_sorted_general_stat staticmethod

get_sorted_general_stat() -> list[str]
Source code in docstr_health/core/config.py
59
60
61
62
63
64
65
66
67
@staticmethod
def get_sorted_general_stat() -> list[str]:
    return [
        "modules",
        "class",
        "function",
        "async function",
        "total",
    ]

ensure_directories

ensure_directories() -> None
Source code in docstr_health/core/config.py
94
95
96
def ensure_directories(self) -> None:
    self.get_cache_dir().mkdir(parents=True, exist_ok=True)
    self.get_logs_dir().mkdir(parents=True, exist_ok=True)

Перечисления

enums

ModuleStatus

Bases: Enum

COMMON class-attribute instance-attribute

COMMON = 'common'

BAD class-attribute instance-attribute

BAD = 'bad'

WARNING class-attribute instance-attribute

WARNING = 'warning'

GOOD class-attribute instance-attribute

GOOD = 'good'

SPECIAL class-attribute instance-attribute

SPECIAL = 'special'

EPIC class-attribute instance-attribute

EPIC = 'epic'

StatusDocstring

Bases: Enum

BAD class-attribute instance-attribute

BAD = 'bad'

GOOD class-attribute instance-attribute

GOOD = 'good'

SPECIAL class-attribute instance-attribute

SPECIAL = 'special'

EPIC class-attribute instance-attribute

EPIC = 'epic'

StatusProject

Bases: Enum

BAD class-attribute instance-attribute

BAD = 'bad'

WARNING class-attribute instance-attribute

WARNING = 'warning'

GOOD class-attribute instance-attribute

GOOD = 'good'

SPECIAL class-attribute instance-attribute

SPECIAL = 'special'

EPIC class-attribute instance-attribute

EPIC = 'epic'

StatusProjectPrioritized

Bases: Enum

BAD class-attribute instance-attribute

BAD = auto()

WARNING class-attribute instance-attribute

WARNING = auto()

GOOD class-attribute instance-attribute

GOOD = auto()

SPECIAL class-attribute instance-attribute

SPECIAL = auto()

EPIC class-attribute instance-attribute

EPIC = auto()

StatusTypechecking

Bases: Enum

NONE class-attribute instance-attribute

NONE = 'bad'

ARGS class-attribute instance-attribute

ARGS = 'warning'

RETURN class-attribute instance-attribute

RETURN = 'warning'

FULL class-attribute instance-attribute

FULL = 'good'

Исключения

exceptions

DocstrHealthError

Bases: Exception

GitNotInstalledError

GitNotInstalledError(
    message="Git are not installed on this machine. Please, install git before running this command.",
)

Bases: DocstrHealthError

Source code in docstr_health/core/exceptions.py
 8
 9
10
11
12
13
def __init__(
    self,
    message="Git are not installed on this machine. Please, install git before running this command.",
):
    self.message = message
    super().__init__(self.message)

message instance-attribute

message = message

PythonParseError

PythonParseError(file_path: Path, reason: Exception)

Bases: DocstrHealthError

Raised when a Python file cannot be parsed.

Source code in docstr_health/core/exceptions.py
22
23
24
25
def __init__(self, file_path: Path, reason: Exception):
    self.file_path = file_path
    self.reason = reason
    super().__init__(f"{file_path}: {reason}")

file_path instance-attribute

file_path = file_path

reason instance-attribute

reason = reason

PythonFilesNotFound

PythonFilesNotFound(
    message="There are no .py files in the directory being checked.",
)

Bases: DocstrHealthError

Raised when no Python files were found

Source code in docstr_health/core/exceptions.py
31
32
33
34
35
36
def __init__(
    self,
    message="There are no .py files in the directory being checked.",
):
    self.message = message
    super().__init__(self.message)

message instance-attribute

message = message

DirectoryNotFoundError

DirectoryNotFoundError(path: Path)

Bases: DocstrHealthError

Source code in docstr_health/core/exceptions.py
43
44
45
def __init__(self, path: Path):
    self.path = path
    super().__init__(f"Directory not found: {path}")

path instance-attribute

path = path

NotADirectoryPathError

NotADirectoryPathError(path: Path)

Bases: DocstrHealthError

Source code in docstr_health/core/exceptions.py
52
53
54
def __init__(self, path: Path):
    self.path = path
    super().__init__(f"Not a directory: {path}")

path instance-attribute

path = path

Интерфейсы

interfaces

Checkable

Bases: Protocol

Contract for verification purposes.

name property

name: str

get_docstring

get_docstring() -> str | None
Source code in docstr_health/core/interfaces.py
9
def get_docstring(self) -> str | None: ...

Настройки

settings

AppSettings

AppSettings(
    doc_check: bool = False,
    compact: bool = False,
    no_cache: bool = False,
    ignore_tests: bool = False,
    short_names: bool = False,
    ci: bool = False,
    repo_url: str | None = None,
    pypi_package: str | None = None,
    threshold_bad: int | None = None,
    threshold_warning: int | None = None,
    threshold_special: int | None = None,
    threshold_epic: int | None = None,
    cache_dir: Path | None = None,
    excluded: list[str] | None = None,
)
Source code in docstr_health/core/settings.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
def __init__(
    self,
    doc_check: bool = False,
    compact: bool = False,
    no_cache: bool = False,
    ignore_tests: bool = False,
    short_names: bool = False,
    ci: bool = False,
    repo_url: str | None = None,
    pypi_package: str | None = None,
    threshold_bad: int | None = None,
    threshold_warning: int | None = None,
    threshold_special: int | None = None,
    threshold_epic: int | None = None,
    cache_dir: Path | None = None,
    excluded: list[str] | None = None,
) -> None:
    self.doc_check = doc_check
    self.compact = compact
    self.no_cache = no_cache
    self.ignore_tests = ignore_tests
    self.short_names = short_names
    self.ci = ci or config.parameters.get("ci", False)
    self.repo_url = repo_url
    self.pypi_package = pypi_package
    self.threshold_bad = threshold_bad
    self.threshold_warning = threshold_warning
    self.threshold_special = threshold_special
    self.threshold_epic = threshold_epic
    self.cache_dir = cache_dir or config.get_cache_dir()
    self.excluded = excluded or config.excluded

doc_check instance-attribute

doc_check = doc_check

compact instance-attribute

compact = compact

no_cache instance-attribute

no_cache = no_cache

ignore_tests instance-attribute

ignore_tests = ignore_tests

short_names instance-attribute

short_names = short_names

ci instance-attribute

ci = ci or config.parameters.get('ci', False)

repo_url instance-attribute

repo_url = repo_url

pypi_package instance-attribute

pypi_package = pypi_package

threshold_bad instance-attribute

threshold_bad = threshold_bad

threshold_warning instance-attribute

threshold_warning = threshold_warning

threshold_special instance-attribute

threshold_special = threshold_special

threshold_epic instance-attribute

threshold_epic = threshold_epic

cache_dir instance-attribute

cache_dir = cache_dir or config.get_cache_dir()

excluded instance-attribute

excluded = excluded or config.excluded

from_args classmethod

from_args(args: Namespace) -> AppSettings
Source code in docstr_health/core/settings.py
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@classmethod
def from_args(cls, args: Namespace) -> AppSettings:
    return cls(
        doc_check=args.doc_modules,
        compact=args.compact,
        short_names=args.short_names,
        ci=args.ci,
        no_cache=args.no_cache,
        repo_url=args.repo_url,
        pypi_package=args.pypi_package,
        threshold_bad=args.threshold_bad,
        threshold_warning=args.threshold_warning,
        threshold_special=args.threshold_special,
        threshold_epic=args.threshold_epic,
        cache_dir=args.cache_dir,
        ignore_tests=args.ignore_tests,
    )

Логирование

logger

handler module-attribute

handler = RotatingFileHandler(
    config.get_logs_dir() / "app.log",
    maxBytes=1000000,
    backupCount=5,
    encoding="utf-8",
)

console_handler module-attribute

console_handler = logging.StreamHandler()

log_level module-attribute

log_level = logging.DEBUG

logger module-attribute

logger = logging.getLogger(__name__)

Декораторы

decorators

all_timed module-attribute

all_timed: list[float] = []

check_all_functions_time_avg

check_all_functions_time_avg(func: Callable)
Source code in docstr_health/core/decorators.py
 8
 9
10
11
12
13
14
15
16
def check_all_functions_time_avg(func: Callable):
    @wraps(func)
    def wrapper(*args, **kwargs):
        res = func(*args, **kwargs)
        average = sum(all_timed) / len(all_timed)
        print(f"avg = {round(average, 6)}")
        return res

    return wrapper

check_seconds

check_seconds(func: Callable)

Measuring the execution time of a function.

Source code in docstr_health/core/decorators.py
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def check_seconds(func: Callable):
    """Measuring the execution time of a function."""

    @wraps(func)
    def wrapper(*args, **kwargs):
        start = time.time()
        res = func(*args, **kwargs)
        end = time.time()
        timed = end - start
        # print(f"{func.__name__}: {timed:.12f}")
        all_timed.append(timed)
        return res

    return wrapper