Skip to content

Commit e67387b

Browse files
committed
improve docs
1 parent 5ae6d30 commit e67387b

File tree

8 files changed

+38
-36
lines changed

8 files changed

+38
-36
lines changed

HOWTO.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ differences already eliminated (strings converted to numbers, floats rounded
1212
with same precision and so on).
1313

1414
But when initial objects must remain unchanged custom handlers may be used:
15-
```
15+
16+
```py
1617
>>> from nested_diff import Differ, handlers
1718
>>>
1819
>>> class FloatHandler(handlers.FloatHandler):
@@ -45,11 +46,23 @@ Ensure `nested_diff` command available, otherwise install it with `pip`:
4546

4647
Add to `.gitconfig` following section:
4748

48-
```
49+
```ini
4950
[difftool "nested_diff"]
5051
cmd = nested_diff $LOCAL $REMOTE
5152
```
5253

5354
and `ndiff = difftool --no-prompt --tool nested_diff` to section `[aliases]`.
5455

5556
Now `ndiff` subcommand available and may be used in the same manner as `diff`.
57+
58+
### How to run tests locally
59+
60+
```sh
61+
# prepare environment
62+
python3 -m venv venv && \
63+
. venv/bin/activate && \
64+
pip install -e '.[cli,test]'
65+
66+
# run tests
67+
pytest
68+
```

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,27 @@ For extra formats support (YAML, TOML) in cli tools, use
2626

2727
## Command line tools
2828

29-
```
29+
```sh
3030
$ cat a.json b.json
3131
[0, [1], 3]
3232
[0, [1, 2], 3]
3333
```
34-
```
34+
35+
```sh
3536
$ nested_diff a.json b.json
3637
[1]
3738
+ [1]
3839
+ 2
3940
```
40-
```
41+
42+
```sh
4143
$ nested_diff a.json b.json --ofmt json > patch.json
4244
$ nested_patch a.json patch.json
4345
```
4446

4547
## Library usage
4648

47-
```
49+
```py
4850
>>> from nested_diff import diff, patch
4951
>>>
5052
>>> a = {'one': 1, 'two': 2, 'three': 3}
@@ -67,7 +69,7 @@ $ nested_patch a.json patch.json
6769

6870
### Formatting diffs
6971

70-
```
72+
```py
7173
>>> from nested_diff import diff, handlers
7274
>>> from nested_diff.formatters import TextFormatter
7375
>>>
@@ -117,9 +119,9 @@ key, except `D` may be omitted during diff computation. `E` key is used with
117119
`D` when entity unable to contain diff by itself (set, frozenset for example);
118120
`D` contain a list of subdiffs in this case.
119121

120-
### Annotated example:
122+
### Annotated example
121123

122-
```
124+
```text
123125
a: {"one": [5,7]}
124126
b: {"one": [5], "two": 2}
125127
opts: U=False # omit unchanged items

nested_diff/__init__.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
#
3-
# Copyright 2018-2023 Michael Samoglyadov
1+
# Copyright 2018-2024 Michael Samoglyadov
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
64
# you may not use this file except in compliance with the License.
@@ -199,7 +197,7 @@ def __init__(self, handlers=None):
199197
def patch(self, target, ndiff):
200198
"""Patch object using nested diff.
201199
202-
This method calls apropriate handler for target value according to
200+
This method calls appropriate handler for target value according to
203201
it's type.
204202
205203
Args:
@@ -271,7 +269,7 @@ def __init__(self, handlers=None, sort_keys=False):
271269
self.set_handler(handler)
272270

273271
def _get_iterator(self, ndiff):
274-
"""Return apropriate iterator for passed nested diff."""
272+
"""Return appropriate iterator for passed nested diff."""
275273
try:
276274
extension_id = ndiff['E']
277275
try:

nested_diff/cli.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
#
3-
# Copyright 2019-2023 Michael Samoglyadov
1+
# Copyright 2019-2024 Michael Samoglyadov
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
64
# you may not use this file except in compliance with the License.
@@ -61,7 +59,8 @@ def cli(cls):
6159
return cls().run()
6260

6361
@property
64-
def dumper(self): # noqa D102
62+
def dumper(self):
63+
"""Return appropriate data dumper."""
6564
try:
6665
return self.__dumper
6766
except AttributeError:
@@ -195,7 +194,7 @@ def get_loader(fmt, **kwargs):
195194
raise RuntimeError(f'Unsupported input format: {fmt}')
196195

197196
def load(self, file_):
198-
"""Load data from file using apropriate loader.
197+
"""Load data from file using appropriate loader.
199198
200199
Args:
201200
file_: File object to load from.
@@ -214,8 +213,7 @@ def load(self, file_):
214213

215214
@staticmethod
216215
def override_excepthook():
217-
"""
218-
Change default exit code for unhandled exceptions from 1 to 127.
216+
"""Change default exit code for unhandled exceptions from 1 to 127.
219217
220218
Mainly for diff tool (version control systems treat 1 as difference
221219
in files).

nested_diff/diff_tool.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
#
3-
# Copyright 2019-2022 Michael Samoglyadov
1+
# Copyright 2019-2024 Michael Samoglyadov
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
64
# you may not use this file except in compliance with the License.

nested_diff/formatters.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
#
3-
# Copyright 2019-2022 Michael Samoglyadov
1+
# Copyright 2019-2024 Michael Samoglyadov
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
64
# you may not use this file except in compliance with the License.
@@ -226,8 +224,7 @@ def format_value(val):
226224

227225

228226
class HtmlFormatter(TextFormatter):
229-
"""
230-
Produce human friendly HTML diff with indenting formatting.
227+
"""Produce human friendly HTML diff with indenting formatting.
231228
232229
Text copied from the browser should be exactly the same as TextFormatter
233230
produce.

nested_diff/handlers.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
#
3-
# Copyright 2022-2023 Michael Samoglyadov
1+
# Copyright 2022-2024 Michael Samoglyadov
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
64
# you may not use this file except in compliance with the License.
@@ -73,7 +71,7 @@ def patch(self, patcher, target, diff): # noqa U100
7371
Patched object.
7472
7573
Raises:
76-
ValueError: Inapropriate diff tag found.
74+
ValueError: Inappropriate diff tag found.
7775
7876
"""
7977
try:

nested_diff/patch_tool.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# -*- coding: utf-8 -*-
2-
#
3-
# Copyright 2019-2023 Michael Samoglyadov
1+
# Copyright 2019-2024 Michael Samoglyadov
42
#
53
# Licensed under the Apache License, Version 2.0 (the "License");
64
# you may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)