winipedia-utils 0.2.10__py3-none-any.whl → 0.2.17__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of winipedia-utils might be problematic. Click here for more details.
- winipedia_utils/concurrent/concurrent.py +245 -245
- winipedia_utils/concurrent/multiprocessing.py +130 -130
- winipedia_utils/concurrent/multithreading.py +93 -93
- winipedia_utils/consts.py +21 -21
- winipedia_utils/data/__init__.py +1 -1
- winipedia_utils/data/dataframe/__init__.py +1 -1
- winipedia_utils/data/dataframe/cleaning.py +378 -378
- winipedia_utils/data/structures/__init__.py +1 -1
- winipedia_utils/data/structures/dicts.py +16 -16
- winipedia_utils/git/__init__.py +1 -1
- winipedia_utils/git/gitignore/__init__.py +1 -1
- winipedia_utils/git/gitignore/gitignore.py +136 -136
- winipedia_utils/git/pre_commit/__init__.py +1 -1
- winipedia_utils/git/pre_commit/config.py +70 -70
- winipedia_utils/git/pre_commit/hooks.py +127 -109
- winipedia_utils/git/pre_commit/run_hooks.py +49 -49
- winipedia_utils/iterating/__init__.py +1 -1
- winipedia_utils/iterating/iterate.py +29 -29
- winipedia_utils/logging/ansi.py +6 -6
- winipedia_utils/logging/config.py +64 -64
- winipedia_utils/logging/logger.py +26 -26
- winipedia_utils/modules/class_.py +119 -119
- winipedia_utils/modules/function.py +101 -101
- winipedia_utils/modules/module.py +379 -379
- winipedia_utils/modules/package.py +390 -390
- winipedia_utils/oop/mixins/meta.py +333 -333
- winipedia_utils/oop/mixins/mixin.py +37 -37
- winipedia_utils/os/__init__.py +1 -1
- winipedia_utils/os/os.py +63 -63
- winipedia_utils/projects/__init__.py +1 -1
- winipedia_utils/projects/poetry/__init__.py +1 -1
- winipedia_utils/projects/poetry/config.py +117 -117
- winipedia_utils/projects/poetry/poetry.py +31 -31
- winipedia_utils/projects/project.py +48 -48
- winipedia_utils/resources/__init__.py +1 -1
- winipedia_utils/resources/svgs/__init__.py +1 -1
- winipedia_utils/resources/svgs/download_arrow.svg +2 -2
- winipedia_utils/resources/svgs/exit_fullscreen_icon.svg +5 -5
- winipedia_utils/resources/svgs/fullscreen_icon.svg +2 -2
- winipedia_utils/resources/svgs/menu_icon.svg +3 -3
- winipedia_utils/resources/svgs/pause_icon.svg +3 -3
- winipedia_utils/resources/svgs/play_icon.svg +16 -16
- winipedia_utils/resources/svgs/plus_icon.svg +23 -23
- winipedia_utils/resources/svgs/svg.py +15 -15
- winipedia_utils/security/__init__.py +1 -1
- winipedia_utils/security/cryptography.py +29 -29
- winipedia_utils/security/keyring.py +70 -70
- winipedia_utils/setup.py +47 -47
- winipedia_utils/testing/assertions.py +23 -23
- winipedia_utils/testing/convention.py +177 -177
- winipedia_utils/testing/create_tests.py +297 -297
- winipedia_utils/testing/fixtures.py +28 -28
- winipedia_utils/testing/tests/base/fixtures/__init__.py +1 -1
- winipedia_utils/testing/tests/base/fixtures/fixture.py +6 -6
- winipedia_utils/testing/tests/base/fixtures/scopes/class_.py +33 -33
- winipedia_utils/testing/tests/base/fixtures/scopes/function.py +7 -7
- winipedia_utils/testing/tests/base/fixtures/scopes/module.py +33 -33
- winipedia_utils/testing/tests/base/fixtures/scopes/package.py +7 -7
- winipedia_utils/testing/tests/base/fixtures/scopes/session.py +296 -296
- winipedia_utils/testing/tests/base/utils/utils.py +111 -111
- winipedia_utils/testing/tests/conftest.py +32 -32
- winipedia_utils/text/string.py +126 -126
- winipedia_utils-0.2.17.dist-info/METADATA +716 -0
- winipedia_utils-0.2.17.dist-info/RECORD +80 -0
- {winipedia_utils-0.2.10.dist-info → winipedia_utils-0.2.17.dist-info}/licenses/LICENSE +21 -21
- winipedia_utils/testing/tests/test_0.py +0 -8
- winipedia_utils-0.2.10.dist-info/METADATA +0 -355
- winipedia_utils-0.2.10.dist-info/RECORD +0 -81
- {winipedia_utils-0.2.10.dist-info → winipedia_utils-0.2.17.dist-info}/WHEEL +0 -0
|
@@ -1,109 +1,127 @@
|
|
|
1
|
-
"""module contains functions that return the input for subprocess.run().
|
|
2
|
-
|
|
3
|
-
Each function is named after the hook it represents. The docstring of each function
|
|
4
|
-
describes the hook it represents. The function returns a list of strings that
|
|
5
|
-
represent the command to run. The first string is the command, and the following
|
|
6
|
-
strings are the arguments to the command. These funcs will be called by
|
|
7
|
-
run_hooks.py, which will pass the returned list to subprocess.run().
|
|
8
|
-
"""
|
|
9
|
-
|
|
10
|
-
from pathlib import Path
|
|
11
|
-
|
|
12
|
-
from winipedia_utils.projects.poetry.poetry import (
|
|
13
|
-
POETRY_PATH,
|
|
14
|
-
POETRY_RUN_ARGS,
|
|
15
|
-
POETRY_RUN_PYTHON_ARGS,
|
|
16
|
-
POETRY_RUN_RUFF_ARGS,
|
|
17
|
-
)
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
def
|
|
21
|
-
"""
|
|
22
|
-
|
|
23
|
-
This function returns the input for subprocess.run() to
|
|
24
|
-
|
|
25
|
-
"""
|
|
26
|
-
return [POETRY_PATH, "
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
def
|
|
30
|
-
"""
|
|
31
|
-
|
|
32
|
-
This function returns the input for subprocess.run() to
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
1
|
+
"""module contains functions that return the input for subprocess.run().
|
|
2
|
+
|
|
3
|
+
Each function is named after the hook it represents. The docstring of each function
|
|
4
|
+
describes the hook it represents. The function returns a list of strings that
|
|
5
|
+
represent the command to run. The first string is the command, and the following
|
|
6
|
+
strings are the arguments to the command. These funcs will be called by
|
|
7
|
+
run_hooks.py, which will pass the returned list to subprocess.run().
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
|
|
12
|
+
from winipedia_utils.projects.poetry.poetry import (
|
|
13
|
+
POETRY_PATH,
|
|
14
|
+
POETRY_RUN_ARGS,
|
|
15
|
+
POETRY_RUN_PYTHON_ARGS,
|
|
16
|
+
POETRY_RUN_RUFF_ARGS,
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _version_patch() -> list[str | Path]:
|
|
21
|
+
"""Patch the version in pyproject.toml.
|
|
22
|
+
|
|
23
|
+
This function returns the input for subprocess.run() to patch the version
|
|
24
|
+
in pyproject.toml.
|
|
25
|
+
"""
|
|
26
|
+
return [POETRY_PATH, "version", "patch"]
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def _add_version_patch_to_git() -> list[str | Path]:
|
|
30
|
+
"""Add the version patch to git.
|
|
31
|
+
|
|
32
|
+
This function returns the input for subprocess.run() to add the version
|
|
33
|
+
patch to git, so that the hook does not fail bc the file was changed.
|
|
34
|
+
"""
|
|
35
|
+
return [*POETRY_RUN_ARGS, "git", "add", "pyproject.toml"]
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def _update_package_manager() -> list[str | Path]:
|
|
39
|
+
"""Update the package manager.
|
|
40
|
+
|
|
41
|
+
This function returns the input for subprocess.run() to update the package
|
|
42
|
+
manager.
|
|
43
|
+
"""
|
|
44
|
+
return [POETRY_PATH, "self", "update"]
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def _install_packages() -> list[str | Path]:
|
|
48
|
+
"""Install all dependencies.
|
|
49
|
+
|
|
50
|
+
This function returns the input for subprocess.run() to install all dependencies.
|
|
51
|
+
"""
|
|
52
|
+
return [POETRY_PATH, "install"]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def _update_packages() -> list[str | Path]:
|
|
56
|
+
"""Update all dependencies.
|
|
57
|
+
|
|
58
|
+
This function returns the input for subprocess.run() to update all dependencies.
|
|
59
|
+
"""
|
|
60
|
+
return [POETRY_PATH, "update"]
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def _lock_dependencies() -> list[str | Path]:
|
|
64
|
+
"""Lock the dependencies.
|
|
65
|
+
|
|
66
|
+
This function returns the input for subprocess.run() to lock the dependencies.
|
|
67
|
+
"""
|
|
68
|
+
return [POETRY_PATH, "lock"]
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _check_configurations() -> list[str | Path]:
|
|
72
|
+
"""Check that poetry.lock and pyproject.toml is up to date.
|
|
73
|
+
|
|
74
|
+
This function returns the input for subprocess.run() to check that poetry.lock
|
|
75
|
+
is up to date.
|
|
76
|
+
"""
|
|
77
|
+
return [POETRY_PATH, "check", "--strict"]
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _creating_tests() -> list[str | Path]:
|
|
81
|
+
"""Create all tests for the project.
|
|
82
|
+
|
|
83
|
+
This function returns the input for subprocess.run() to create all tests.
|
|
84
|
+
"""
|
|
85
|
+
return [*POETRY_RUN_PYTHON_ARGS, "-m", "winipedia_utils.testing.create_tests"]
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
def _linting() -> list[str | Path]:
|
|
89
|
+
"""Check the code.
|
|
90
|
+
|
|
91
|
+
This function returns the input for subprocess.run() to lint the code.
|
|
92
|
+
It autofixes all errors that can be autofixed with --fix.
|
|
93
|
+
"""
|
|
94
|
+
return [*POETRY_RUN_RUFF_ARGS, "check", "--fix"]
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _formating() -> list[str | Path]:
|
|
98
|
+
"""Format the code.
|
|
99
|
+
|
|
100
|
+
This function calls ruff format to format the code.
|
|
101
|
+
"""
|
|
102
|
+
return [*POETRY_RUN_RUFF_ARGS, "format"]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def _type_checking() -> list[str | Path]:
|
|
106
|
+
"""Check the types.
|
|
107
|
+
|
|
108
|
+
This function returns the input for subprocess.run() to check the static types.
|
|
109
|
+
"""
|
|
110
|
+
return [*POETRY_RUN_ARGS, "mypy"]
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
def _security_checking() -> list[str | Path]:
|
|
114
|
+
"""Check the security of the code.
|
|
115
|
+
|
|
116
|
+
This function returns the input for subprocess.run() to check the security of
|
|
117
|
+
the code.
|
|
118
|
+
"""
|
|
119
|
+
return [*POETRY_RUN_ARGS, "bandit", "-c", "pyproject.toml", "-r", "."]
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _testing() -> list[str | Path]:
|
|
123
|
+
"""Run the tests.
|
|
124
|
+
|
|
125
|
+
This function returns the input for subprocess.run() to run all tests.
|
|
126
|
+
"""
|
|
127
|
+
return [*POETRY_RUN_ARGS, "pytest"]
|
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
"""Contains the pre-commit to run all hooks required by the winipedia_utils package.
|
|
2
|
-
|
|
3
|
-
This script is meant to be run by pre-commit (https://pre-commit.com/)
|
|
4
|
-
and should not be modified manually.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
import sys
|
|
8
|
-
|
|
9
|
-
from winipedia_utils.git.pre_commit import hooks
|
|
10
|
-
from winipedia_utils.logging.ansi import GREEN, RED, RESET
|
|
11
|
-
from winipedia_utils.logging.logger import get_logger
|
|
12
|
-
from winipedia_utils.modules.function import get_all_functions_from_module
|
|
13
|
-
from winipedia_utils.os.os import run_subprocess
|
|
14
|
-
|
|
15
|
-
logger = get_logger(__name__)
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
def _run_all_hooks() -> None:
|
|
19
|
-
"""Import all funcs defined in hooks.py and runs them."""
|
|
20
|
-
hook_funcs = get_all_functions_from_module(hooks)
|
|
21
|
-
|
|
22
|
-
exit_code = 0
|
|
23
|
-
for hook_func in hook_funcs:
|
|
24
|
-
subprocess_args = hook_func()
|
|
25
|
-
result = run_subprocess(
|
|
26
|
-
subprocess_args, check=False, capture_output=True, text=True
|
|
27
|
-
)
|
|
28
|
-
passed = result.returncode == 0
|
|
29
|
-
|
|
30
|
-
log_method = logger.info
|
|
31
|
-
passed_str = (f"{GREEN}PASSED" if passed else f"{RED}FAILED") + RESET
|
|
32
|
-
if not passed:
|
|
33
|
-
log_method = logger.error
|
|
34
|
-
passed_str += f"\n{result.stdout}"
|
|
35
|
-
exit_code = 1
|
|
36
|
-
# make the dashes always the same lentgth by adjusting to len of hook name
|
|
37
|
-
num_dashes = 50 - len(hook_func.__name__)
|
|
38
|
-
log_method(
|
|
39
|
-
"Hook %s -%s> %s",
|
|
40
|
-
hook_func.__name__,
|
|
41
|
-
"-" * num_dashes,
|
|
42
|
-
passed_str,
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
sys.exit(exit_code)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if __name__ == "__main__":
|
|
49
|
-
_run_all_hooks()
|
|
1
|
+
"""Contains the pre-commit to run all hooks required by the winipedia_utils package.
|
|
2
|
+
|
|
3
|
+
This script is meant to be run by pre-commit (https://pre-commit.com/)
|
|
4
|
+
and should not be modified manually.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from winipedia_utils.git.pre_commit import hooks
|
|
10
|
+
from winipedia_utils.logging.ansi import GREEN, RED, RESET
|
|
11
|
+
from winipedia_utils.logging.logger import get_logger
|
|
12
|
+
from winipedia_utils.modules.function import get_all_functions_from_module
|
|
13
|
+
from winipedia_utils.os.os import run_subprocess
|
|
14
|
+
|
|
15
|
+
logger = get_logger(__name__)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _run_all_hooks() -> None:
|
|
19
|
+
"""Import all funcs defined in hooks.py and runs them."""
|
|
20
|
+
hook_funcs = get_all_functions_from_module(hooks)
|
|
21
|
+
|
|
22
|
+
exit_code = 0
|
|
23
|
+
for hook_func in hook_funcs:
|
|
24
|
+
subprocess_args = hook_func()
|
|
25
|
+
result = run_subprocess(
|
|
26
|
+
subprocess_args, check=False, capture_output=True, text=True
|
|
27
|
+
)
|
|
28
|
+
passed = result.returncode == 0
|
|
29
|
+
|
|
30
|
+
log_method = logger.info
|
|
31
|
+
passed_str = (f"{GREEN}PASSED" if passed else f"{RED}FAILED") + RESET
|
|
32
|
+
if not passed:
|
|
33
|
+
log_method = logger.error
|
|
34
|
+
passed_str += f"\n{result.stdout}"
|
|
35
|
+
exit_code = 1
|
|
36
|
+
# make the dashes always the same lentgth by adjusting to len of hook name
|
|
37
|
+
num_dashes = 50 - len(hook_func.__name__)
|
|
38
|
+
log_method(
|
|
39
|
+
"Hook %s -%s> %s",
|
|
40
|
+
hook_func.__name__,
|
|
41
|
+
"-" * num_dashes,
|
|
42
|
+
passed_str,
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
sys.exit(exit_code)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
if __name__ == "__main__":
|
|
49
|
+
_run_all_hooks()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"""__init__ module for winipedia_utils.iterating."""
|
|
1
|
+
"""__init__ module for winipedia_utils.iterating."""
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
"""Iterating utilities for handling iterables.
|
|
2
|
-
|
|
3
|
-
This module provides utility functions for working with iterables,
|
|
4
|
-
including getting the length of an iterable with a default value.
|
|
5
|
-
These utilities help with iterable operations and manipulations.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
from collections.abc import Iterable
|
|
9
|
-
from typing import Any
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def get_len_with_default(iterable: Iterable[Any], default: int | None = None) -> int:
|
|
13
|
-
"""Get the length of an iterable with a default value.
|
|
14
|
-
|
|
15
|
-
Args:
|
|
16
|
-
iterable: Iterable to get the length of
|
|
17
|
-
default: Default value to return if the iterable is empty
|
|
18
|
-
|
|
19
|
-
Returns:
|
|
20
|
-
Length of the iterable or the default value if the iterable is empty
|
|
21
|
-
|
|
22
|
-
"""
|
|
23
|
-
try:
|
|
24
|
-
return len(iterable) # type: ignore[arg-type]
|
|
25
|
-
except TypeError as e:
|
|
26
|
-
if default is None:
|
|
27
|
-
msg = "Can't get length of iterable and no default value provided"
|
|
28
|
-
raise TypeError(msg) from e
|
|
29
|
-
return default
|
|
1
|
+
"""Iterating utilities for handling iterables.
|
|
2
|
+
|
|
3
|
+
This module provides utility functions for working with iterables,
|
|
4
|
+
including getting the length of an iterable with a default value.
|
|
5
|
+
These utilities help with iterable operations and manipulations.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from collections.abc import Iterable
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_len_with_default(iterable: Iterable[Any], default: int | None = None) -> int:
|
|
13
|
+
"""Get the length of an iterable with a default value.
|
|
14
|
+
|
|
15
|
+
Args:
|
|
16
|
+
iterable: Iterable to get the length of
|
|
17
|
+
default: Default value to return if the iterable is empty
|
|
18
|
+
|
|
19
|
+
Returns:
|
|
20
|
+
Length of the iterable or the default value if the iterable is empty
|
|
21
|
+
|
|
22
|
+
"""
|
|
23
|
+
try:
|
|
24
|
+
return len(iterable) # type: ignore[arg-type]
|
|
25
|
+
except TypeError as e:
|
|
26
|
+
if default is None:
|
|
27
|
+
msg = "Can't get length of iterable and no default value provided"
|
|
28
|
+
raise TypeError(msg) from e
|
|
29
|
+
return default
|
winipedia_utils/logging/ansi.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"""ANSI escape codes for terminal output."""
|
|
2
|
-
|
|
3
|
-
RESET = "\033[0m"
|
|
4
|
-
|
|
5
|
-
RED = "\033[91m"
|
|
6
|
-
GREEN = "\033[92m"
|
|
1
|
+
"""ANSI escape codes for terminal output."""
|
|
2
|
+
|
|
3
|
+
RESET = "\033[0m"
|
|
4
|
+
|
|
5
|
+
RED = "\033[91m"
|
|
6
|
+
GREEN = "\033[92m"
|
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
"""Logging configuration for winipedia_utils.
|
|
2
|
-
|
|
3
|
-
This module provides a standardized logging configuration dictionary that can be
|
|
4
|
-
used with Python's logging.config.dictConfig() to set up consistent logging
|
|
5
|
-
across the application. The configuration includes formatters, handlers, and
|
|
6
|
-
logger settings for different components.
|
|
7
|
-
"""
|
|
8
|
-
|
|
9
|
-
# This dictionary can be passed directly to logging.config.dictConfig().
|
|
10
|
-
# It sets up a single console handler that prints **all** log levels
|
|
11
|
-
# (DEBUG, INFO, WARNING, ERROR and CRITICAL) using one consistent format.
|
|
12
|
-
|
|
13
|
-
from typing import Any
|
|
14
|
-
|
|
15
|
-
LOGGING_CONFIG: dict[str, Any] = {
|
|
16
|
-
"version": 1, # Mandatory schema version for dictConfig
|
|
17
|
-
"disable_existing_loggers": False, # Keep any loggers already created elsewhere
|
|
18
|
-
# ---------------------------- #
|
|
19
|
-
# Define a single formatter #
|
|
20
|
-
# ---------------------------- #
|
|
21
|
-
"formatters": {
|
|
22
|
-
"standard": { # You can reference this formatter by name
|
|
23
|
-
"format": (
|
|
24
|
-
"%(asctime)s | " # • %(asctime)s human-readable timestamp
|
|
25
|
-
"%(levelname)-8s | " # • %(asctime)s human-readable timestamp
|
|
26
|
-
"%(filename)s:" # • %(filename)s source file where the call was made
|
|
27
|
-
"%(lineno)d | " # • %(lineno)d line number in that file
|
|
28
|
-
"%(message)s" # • %(message)s the log message itself
|
|
29
|
-
),
|
|
30
|
-
"datefmt": "%Y-%m-%d %H:%M:%S", # Override default timestamp style
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
# --------------------------- #
|
|
34
|
-
# Define the console output #
|
|
35
|
-
# --------------------------- #
|
|
36
|
-
"handlers": {
|
|
37
|
-
"console": {
|
|
38
|
-
"class": "logging.StreamHandler", # Send logs to sys.stderr
|
|
39
|
-
"level": "DEBUG", # Capture *everything* ≥ DEBUG
|
|
40
|
-
"formatter": "standard", # Use the formatter above
|
|
41
|
-
"stream": "ext://sys.stdout", # Emit to stdout instead of stderr
|
|
42
|
-
},
|
|
43
|
-
},
|
|
44
|
-
# ------------------------------------------------------- #
|
|
45
|
-
# Attach the handler to either the root logger or named #
|
|
46
|
-
# loggers. Below we set up the root so every message in #
|
|
47
|
-
# your application uses this setup automatically. #
|
|
48
|
-
# ------------------------------------------------------- #
|
|
49
|
-
"root": {
|
|
50
|
-
"level": "DEBUG", # Accept all levels from DEBUG upward
|
|
51
|
-
"handlers": ["console"], # Pipe them through the console handler
|
|
52
|
-
},
|
|
53
|
-
# ------------------------------------------------------- #
|
|
54
|
-
# Optionally, tweak individual libraries if they are #
|
|
55
|
-
# too noisy. For example, silence urllib3 INFO chatter. #
|
|
56
|
-
# ------------------------------------------------------- #
|
|
57
|
-
"loggers": {
|
|
58
|
-
"urllib3": {
|
|
59
|
-
"level": "WARNING", # Raise urllib3's threshold to WARNING
|
|
60
|
-
"handlers": ["console"],
|
|
61
|
-
"propagate": False, # Prevent double-logging to the root
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
}
|
|
1
|
+
"""Logging configuration for winipedia_utils.
|
|
2
|
+
|
|
3
|
+
This module provides a standardized logging configuration dictionary that can be
|
|
4
|
+
used with Python's logging.config.dictConfig() to set up consistent logging
|
|
5
|
+
across the application. The configuration includes formatters, handlers, and
|
|
6
|
+
logger settings for different components.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
# This dictionary can be passed directly to logging.config.dictConfig().
|
|
10
|
+
# It sets up a single console handler that prints **all** log levels
|
|
11
|
+
# (DEBUG, INFO, WARNING, ERROR and CRITICAL) using one consistent format.
|
|
12
|
+
|
|
13
|
+
from typing import Any
|
|
14
|
+
|
|
15
|
+
LOGGING_CONFIG: dict[str, Any] = {
|
|
16
|
+
"version": 1, # Mandatory schema version for dictConfig
|
|
17
|
+
"disable_existing_loggers": False, # Keep any loggers already created elsewhere
|
|
18
|
+
# ---------------------------- #
|
|
19
|
+
# Define a single formatter #
|
|
20
|
+
# ---------------------------- #
|
|
21
|
+
"formatters": {
|
|
22
|
+
"standard": { # You can reference this formatter by name
|
|
23
|
+
"format": (
|
|
24
|
+
"%(asctime)s | " # • %(asctime)s human-readable timestamp
|
|
25
|
+
"%(levelname)-8s | " # • %(asctime)s human-readable timestamp
|
|
26
|
+
"%(filename)s:" # • %(filename)s source file where the call was made
|
|
27
|
+
"%(lineno)d | " # • %(lineno)d line number in that file
|
|
28
|
+
"%(message)s" # • %(message)s the log message itself
|
|
29
|
+
),
|
|
30
|
+
"datefmt": "%Y-%m-%d %H:%M:%S", # Override default timestamp style
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
# --------------------------- #
|
|
34
|
+
# Define the console output #
|
|
35
|
+
# --------------------------- #
|
|
36
|
+
"handlers": {
|
|
37
|
+
"console": {
|
|
38
|
+
"class": "logging.StreamHandler", # Send logs to sys.stderr
|
|
39
|
+
"level": "DEBUG", # Capture *everything* ≥ DEBUG
|
|
40
|
+
"formatter": "standard", # Use the formatter above
|
|
41
|
+
"stream": "ext://sys.stdout", # Emit to stdout instead of stderr
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
# ------------------------------------------------------- #
|
|
45
|
+
# Attach the handler to either the root logger or named #
|
|
46
|
+
# loggers. Below we set up the root so every message in #
|
|
47
|
+
# your application uses this setup automatically. #
|
|
48
|
+
# ------------------------------------------------------- #
|
|
49
|
+
"root": {
|
|
50
|
+
"level": "DEBUG", # Accept all levels from DEBUG upward
|
|
51
|
+
"handlers": ["console"], # Pipe them through the console handler
|
|
52
|
+
},
|
|
53
|
+
# ------------------------------------------------------- #
|
|
54
|
+
# Optionally, tweak individual libraries if they are #
|
|
55
|
+
# too noisy. For example, silence urllib3 INFO chatter. #
|
|
56
|
+
# ------------------------------------------------------- #
|
|
57
|
+
"loggers": {
|
|
58
|
+
"urllib3": {
|
|
59
|
+
"level": "WARNING", # Raise urllib3's threshold to WARNING
|
|
60
|
+
"handlers": ["console"],
|
|
61
|
+
"propagate": False, # Prevent double-logging to the root
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
}
|
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
"""Logger utilities for winipedia_utils.
|
|
2
|
-
|
|
3
|
-
This module provides functions for creating and configuring loggers
|
|
4
|
-
throughout the application. It applies the standardized logging configuration
|
|
5
|
-
defined in the config module to ensure consistent logging behavior.
|
|
6
|
-
"""
|
|
7
|
-
|
|
8
|
-
import logging
|
|
9
|
-
from logging.config import dictConfig
|
|
10
|
-
|
|
11
|
-
from winipedia_utils.logging.config import LOGGING_CONFIG
|
|
12
|
-
|
|
13
|
-
dictConfig(LOGGING_CONFIG)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
def get_logger(name: str) -> logging.Logger:
|
|
17
|
-
"""Get a logger with the given name.
|
|
18
|
-
|
|
19
|
-
Args:
|
|
20
|
-
name: The name for the logger, typically __name__ from the calling module
|
|
21
|
-
|
|
22
|
-
Returns:
|
|
23
|
-
A configured logger instance with the specified name
|
|
24
|
-
|
|
25
|
-
"""
|
|
26
|
-
return logging.getLogger(name)
|
|
1
|
+
"""Logger utilities for winipedia_utils.
|
|
2
|
+
|
|
3
|
+
This module provides functions for creating and configuring loggers
|
|
4
|
+
throughout the application. It applies the standardized logging configuration
|
|
5
|
+
defined in the config module to ensure consistent logging behavior.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import logging
|
|
9
|
+
from logging.config import dictConfig
|
|
10
|
+
|
|
11
|
+
from winipedia_utils.logging.config import LOGGING_CONFIG
|
|
12
|
+
|
|
13
|
+
dictConfig(LOGGING_CONFIG)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def get_logger(name: str) -> logging.Logger:
|
|
17
|
+
"""Get a logger with the given name.
|
|
18
|
+
|
|
19
|
+
Args:
|
|
20
|
+
name: The name for the logger, typically __name__ from the calling module
|
|
21
|
+
|
|
22
|
+
Returns:
|
|
23
|
+
A configured logger instance with the specified name
|
|
24
|
+
|
|
25
|
+
"""
|
|
26
|
+
return logging.getLogger(name)
|