|
86 | 86 | from typing import Any, Callable, Dict, Iterable, List, Optional, Tuple, Union |
87 | 87 |
|
88 | 88 | # 3rd party |
89 | | -import consolekit.utils |
90 | 89 | import deprecation # type: ignore |
91 | 90 | from packaging import version |
92 | 91 |
|
@@ -605,11 +604,73 @@ def check_dependencies(dependencies: Iterable[str], prt: bool = True) -> List[st |
605 | 604 | return missing_modules |
606 | 605 |
|
607 | 606 |
|
608 | | -coloured_diff = deprecated( |
609 | | - deprecated_in="1.4.0", |
610 | | - removed_in="2.0.0", |
611 | | - current_version=__version__, |
612 | | - details="Import from :mod:`consolekit.utils` (v0.3.0 or later) instead.", |
613 | | - )( |
614 | | - consolekit.utils.coloured_diff |
615 | | - ) |
| 607 | +def coloured_diff( |
| 608 | + *args, |
| 609 | + **kwargs, |
| 610 | + ) -> str: |
| 611 | + r""" |
| 612 | + Compare two sequences of lines; generate the delta as a unified diff. |
| 613 | +
|
| 614 | + Unified diffs are a compact way of showing line changes and a few |
| 615 | + lines of context. The number of context lines is set by ``n`` which |
| 616 | + defaults to three. |
| 617 | +
|
| 618 | + By default, the diff control lines (those with ``---``, ``+++``, or ``@@``) |
| 619 | + are created with a trailing newline. This is helpful so that inputs |
| 620 | + created from ``file.readlines()`` result in diffs that are suitable for |
| 621 | + ``file.writelines()`` since both the inputs and outputs have trailing |
| 622 | + newlines. |
| 623 | +
|
| 624 | + For inputs that do not have trailing newlines, set the lineterm |
| 625 | + argument to ``''`` so that the output will be uniformly newline free. |
| 626 | +
|
| 627 | + The unidiff format normally has a header for filenames and modification |
| 628 | + times. Any or all of these may be specified using strings for |
| 629 | + ``fromfile``, ``tofile``, ``fromfiledate``, and ``tofiledate``. |
| 630 | + The modification times are normally expressed in the ISO 8601 format. |
| 631 | +
|
| 632 | + **Example:** |
| 633 | +
|
| 634 | + >>> for line in coloured_diff('one two three four'.split(), |
| 635 | + ... 'zero one tree four'.split(), 'Original', 'Current', |
| 636 | + ... '2005-01-26 23:30:50', '2010-04-02 10:20:52', |
| 637 | + ... lineterm=''): |
| 638 | + ... print(line) # doctest: +NORMALIZE_WHITESPACE |
| 639 | + --- Original 2005-01-26 23:30:50 |
| 640 | + +++ Current 2010-04-02 10:20:52 |
| 641 | + @@ -1,4 +1,4 @@ |
| 642 | + +zero |
| 643 | + one |
| 644 | + -two |
| 645 | + -three |
| 646 | + +tree |
| 647 | + four |
| 648 | +
|
| 649 | + :param a: |
| 650 | + :param b: |
| 651 | + :param fromfile: |
| 652 | + :param tofile: |
| 653 | + :param fromfiledate: |
| 654 | + :param tofiledate: |
| 655 | + :param n: |
| 656 | + :param lineterm: |
| 657 | + :param removed_colour: The :class:`~consolekit.terminal_colours.Colour` to use for lines that were removed. |
| 658 | + :param added_colour: The :class:`~consolekit.terminal_colours.Colour` to use for lines that were added. |
| 659 | +
|
| 660 | + .. versionadded:: 0.3.0 |
| 661 | +
|
| 662 | + .. deprecated:: 1.4.0 |
| 663 | +
|
| 664 | + Will be removed in versiion 2.0.0. Import from :mod:`consolekit.utils` (v0.3.0 or later) instead. |
| 665 | + """ |
| 666 | + |
| 667 | + # 3rd party |
| 668 | + import consolekit.utils |
| 669 | + |
| 670 | + warnings.warn( |
| 671 | + "domdf_python_tools.utils.coloured_diff is deprecated since v1.4.0 and will be removed in v2.0.0. " |
| 672 | + "Import from consolekit.utils (v0.3.0 or later) instead.", |
| 673 | + DeprecationWarning, |
| 674 | + ) |
| 675 | + |
| 676 | + return consolekit.utils.coloured_diff(*args, **kwargs) |
0 commit comments