Skip to content

Commit 008496a

Browse files
committed
Refactoring: Shuffle logging utils around
1 parent 8fc0d96 commit 008496a

File tree

3 files changed

+30
-29
lines changed

3 files changed

+30
-29
lines changed

django_utils_lib/logger.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,6 @@
11
import logging
2-
from os import get_terminal_size
3-
from typing import List, Union
42

53
from django_utils_lib.constants import PACKAGE_NAME
64

75
pkg_logger = logging.getLogger(PACKAGE_NAME)
86
pkg_logger.setLevel(logging.INFO)
9-
10-
11-
def build_heading_block(heading: Union[str, List[str]], border_width=2) -> str:
12-
"""
13-
Generate a heading, like:
14-
```
15-
===============
16-
== Hello ==
17-
===============
18-
```
19-
"""
20-
terminal_width = get_terminal_size().columns
21-
heading_delim = "".ljust(terminal_width, "=")
22-
heading_lines = [heading_delim]
23-
24-
# Leave space for border, plus one space on each side
25-
border = "=" * border_width
26-
border_width_total = border_width + 1
27-
28-
for line in heading if isinstance(heading, list) else heading.splitlines():
29-
left_inner_padding = int((terminal_width - len(line) - (border_width_total * 2)) / 2)
30-
right_inner_padding = int(terminal_width - left_inner_padding - len(line) - (border_width_total * 2))
31-
heading_lines.append(f"{border} {' ' * left_inner_padding}{line}{' ' * right_inner_padding} {border}")
32-
heading_lines.append(heading_delim)
33-
34-
return "\n".join(heading_lines)

django_utils_lib/logging_utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
from os import get_terminal_size
2+
from typing import List, Union
3+
4+
5+
def build_heading_block(heading: Union[str, List[str]], border_width=2) -> str:
6+
"""
7+
Generate a heading, like:
8+
```
9+
===============
10+
== Hello ==
11+
===============
12+
```
13+
"""
14+
terminal_width = get_terminal_size().columns
15+
heading_delim = "".ljust(terminal_width, "=")
16+
heading_lines = [heading_delim]
17+
18+
# Leave space for border, plus one space on each side
19+
border = "=" * border_width
20+
border_width_total = border_width + 1
21+
22+
for line in heading if isinstance(heading, list) else heading.splitlines():
23+
left_inner_padding = int((terminal_width - len(line) - (border_width_total * 2)) / 2)
24+
right_inner_padding = int(terminal_width - left_inner_padding - len(line) - (border_width_total * 2))
25+
heading_lines.append(f"{border} {' ' * left_inner_padding}{line}{' ' * right_inner_padding} {border}")
26+
heading_lines.append(heading_delim)
27+
28+
return "\n".join(heading_lines)

django_utils_lib/testing/pytest_plugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@
2525
from typing_extensions import NotRequired, TypedDict
2626

2727
from django_utils_lib.constants import PACKAGE_NAME
28-
from django_utils_lib.logger import build_heading_block, pkg_logger
28+
from django_utils_lib.logger import pkg_logger
29+
from django_utils_lib.logging_utils import build_heading_block
2930
from django_utils_lib.testing.utils import PytestNodeID, is_main_pytest_runner, validate_requirement_tagging
3031

3132
BASE_DIR = Path(__file__).resolve().parent

0 commit comments

Comments
 (0)