Skip to content

Commit c7571ee

Browse files
committed
Изменена структура папок
1 parent b553eeb commit c7571ee

File tree

14 files changed

+53
-48
lines changed

14 files changed

+53
-48
lines changed

gendiff/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from gendiff.controller import generate_diff
1+
from gendiff.gendiff import generate_diff
22

33
__all__ = [
44
"generate_diff",

gendiff/formatters/__init__.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from typing import Literal
2+
3+
from gendiff.diffs_model import DiffsType
4+
from gendiff.formatters.json import format_to_json
5+
from gendiff.formatters.plain import format_to_plain
6+
from gendiff.formatters.stylish import format_to_stylish
7+
8+
DiffViewType = Literal["stylish", "stylish_colored", "json", "plain"]
9+
10+
11+
def format_diffs(
12+
diffs: DiffsType,
13+
view_type: DiffViewType = "stylish"
14+
) -> str:
15+
match view_type:
16+
case "stylish":
17+
return format_to_stylish(diffs)
18+
case "stylish_colored":
19+
return format_to_stylish(diffs, is_colored=True)
20+
case "json":
21+
return format_to_json(diffs)
22+
case "plain":
23+
return format_to_plain(diffs)
24+
case _:
25+
raise ValueError("Unknown name for format output.")
26+
27+
28+
__all__ = [
29+
"DiffViewType",
30+
"format_diffs",
31+
]
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import json
22

3-
from gendiff.models.calc_diff import DiffsType
3+
from gendiff.diffs_model import DiffsType
44

55
INDENT_SYMBOL = " "
66
INDENT_LENGTH = 4
77
INDENT = INDENT_SYMBOL * INDENT_LENGTH
88

99

10-
def get_json_view(diffs: DiffsType) -> str:
10+
def format_to_json(diffs: DiffsType) -> str:
1111
diffs_for_json = [d.model_dump(exclude_none=True) for d in diffs]
1212
dict_for_json = {"diffs": diffs_for_json}
1313

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
from typing import List
22

3-
from gendiff.models.calc_diff import DiffsType
4-
from gendiff.views.plain.utils import dict_value_to_str
3+
from gendiff.diffs_model import DiffsType
4+
from gendiff.formatters.plain_helpers import dict_value_to_str
55

66

7-
def get_plain_view(diffs: DiffsType, property_path: List[str] = []) -> str:
7+
def format_to_plain(diffs: DiffsType, property_path: List[str] = []) -> str:
88
diffs_lines = []
99

1010
for d in diffs:
@@ -14,7 +14,7 @@ def get_plain_view(diffs: DiffsType, property_path: List[str] = []) -> str:
1414
match d.result:
1515
case "equal":
1616
if d.children is not None:
17-
children_view = get_plain_view(
17+
children_view = format_to_plain(
1818
d.children,
1919
current_property_path,
2020
)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from gendiff.models.calc_diff import DictValueType
1+
from gendiff.diffs_model import DictValueType
22

33

44
def dict_value_to_str(value: DictValueType) -> str:
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
from gendiff.models.calc_diff import DiffsType
2-
from gendiff.views.stylish.utils import (
1+
from gendiff.diffs_model import DiffsType
2+
from gendiff.formatters.stylish_helpers import (
33
INDENT,
44
get_diff_line,
55
get_multilines_value_with_indent,
66
)
77

88

9-
def get_stylish_view(diffs: DiffsType, is_colored: bool = False) -> str:
9+
def format_to_stylish(diffs: DiffsType, is_colored: bool = False) -> str:
1010
level = 1
1111
diffs_lines = []
1212
diffs_lines.append("{")
@@ -19,7 +19,7 @@ def get_stylish_view(diffs: DiffsType, is_colored: bool = False) -> str:
1919
match d.result:
2020
case "equal":
2121
if d.children is not None:
22-
children_view = get_stylish_view(d.children, is_colored)
22+
children_view = format_to_stylish(d.children, is_colored)
2323
children_view = get_multilines_value_with_indent(
2424
children_view,
2525
INDENT * level
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from typing import Dict, Optional, Union
22

3-
from gendiff.models.calc_diff import (
3+
from gendiff.diffs_model import (
44
DictValueType,
55
ResultType,
66
)
Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
from gendiff.models.calc_diff import get_diffs
2-
from gendiff.utils.file_parsing import get_data_from_file
3-
from gendiff.views.main import DiffViewType, get_diffs_view
1+
from gendiff.diffs_model import get_diffs
2+
from gendiff.formatters import DiffViewType, format_diffs
3+
from gendiff.utils.file_reader import get_data_from_file
44

55

66
def generate_diff(
@@ -12,6 +12,6 @@ def generate_diff(
1212
dict2 = get_data_from_file(file_path2)
1313

1414
diffs = get_diffs(dict1, dict2)
15-
diffs_view = get_diffs_view(diffs, view_type)
15+
formatted_diffs = format_diffs(diffs, view_type)
1616

17-
return diffs_view
17+
return formatted_diffs

gendiff/models/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)