Skip to content

Commit b4c6b0f

Browse files
committed
4th step
1 parent 7e0197b commit b4c6b0f

File tree

11 files changed

+94
-9
lines changed

11 files changed

+94
-9
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.venv/
2+
dist/
3+
__pycache__/

Makefile

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
lint:
2+
ruff check gendiff
3+
4+
install:
5+
uv sync
6+
7+
build:
8+
uv build
9+
10+
package-install:
11+
uv tool dist/*.whl

gendiff/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from gendiff.gen_diff import generate_diff
2+
3+
4+
__all__ = (
5+
"generate_diff",
6+
)
70 Bytes
Binary file not shown.

gendiff/gen_diff.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import json
2+
import pathlib
3+
4+
5+
def open_f(path_to_file) -> dict:
6+
with open(path_to_file) as file:
7+
return json.load(file)
8+
9+
10+
def generate_diff(file1, file2):
11+
file1 = open_f(file1)
12+
file2 = open_f(file2)
13+
sorted_keys_f1 = sorted(list(file1))
14+
sorted_keys_f2 = sorted(list(file2))
15+
res = '''{
16+
'''
17+
for i in sorted_keys_f1:
18+
if i in sorted_keys_f2:
19+
if file1[i] == file2[i]:
20+
res += f' {i}: {file1[i]}\n'
21+
else:
22+
res +=f''' - {i}: {file1[i]}
23+
+ {i}: {file2[i]}\n'''
24+
else:
25+
res += f' - {i}: {file1[i]}\n'
26+
for i in sorted_keys_f2:
27+
if i not in sorted_keys_f1:
28+
res += f' + {i}: {file2[i]}\n'
29+
res += '}'
30+
return res
-7 Bytes
Binary file not shown.
150 Bytes
Binary file not shown.

gendiff/scripts/gen_diff.py

Lines changed: 0 additions & 6 deletions
This file was deleted.

gendiff/scripts/gendiff.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import argparse
2-
import json
2+
from gendiff.gen_diff import generate_diff
33

44

55
def main():
@@ -10,7 +10,8 @@ def main():
1010
parser.add_argument('first_file')
1111
parser.add_argument('second_file')
1212
parser.add_argument('-f', '--format', help='set format of output')
13-
return parser.parse_args()
13+
diff = generate_diff(parser.parse_args().first_file, parser.parse_args().second_file)
14+
return diff
1415

1516

1617
if __name__ == "__main__":

pyproject.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,10 @@ build-backend = "hatchling.build"
1313
[tool.hatch.build.targets.wheel]
1414
packages = ["gendiff"]
1515

16+
[dependency-groups]
17+
dev = [
18+
"ruff>=0.9.1",
19+
]
20+
1621
[project.scripts]
17-
gendiff = "gendiff.scripts.gendiff:main"
22+
gendiff = "gendiff.scripts.gendiff:main"

0 commit comments

Comments
 (0)