diff
====

.. py:module:: diff


Attributes
----------

.. autoapisummary::

   diff.logger


Classes
-------

.. autoapisummary::

   diff.DiffError
   diff.EmptyDiffError


Functions
---------

.. autoapisummary::

   diff.diff
   diff.patch


Module Contents
---------------

.. py:data:: logger

.. py:class:: DiffError

   Bases: :py:obj:`e3.error.E3Error`


   Error returned when the patch command fails.


.. py:class:: EmptyDiffError

   Bases: :py:obj:`DiffError`


   Error returned when the patch is empty.

   These situation can occur when all the patched files are discarded.


.. py:function:: diff(a: str | list[str], b: str | list[str], ignore: str | None = None, item1name: str = 'expected', item2name: str = 'output', ignore_white_chars: bool = True, context: int = 1) -> str

   Compute diff between two files or list of strings.

   :param a: a filename or a list of strings
   :param b: a filename or a list of strings
   :param ignore: all lines matching this pattern in both files are
       ignored during comparison. If set to None, all lines are considered.
   :param item1name: name to display for a in the diff
   :param item2name: name to display for b in the diff
   :param ignore_white_chars: if True (default) then empty lines,
       trailing and leading white chars on each line are ignored
   :param context: positive number of context lines to add to the diff

   :return: A diff string. If the string is equal to '' it means that there
       is no difference


.. py:function:: patch(patch_file: str, working_dir: str, discarded_files: list[str] | collections.abc.Callable[[str], bool] | None = None, filtered_patch: str | None = None) -> None

   Apply a patch, ignoring changes in files matching discarded_files.

   :param patch_file: the file containing the patch to apply
   :param working_dir: the directory where to apply the patch
   :param discarded_files: list of files or glob patterns (or function taking
       a filename and returning a boolean - True if the file should be
       discarded)
   :param filtered_patch: name of the filtered patch. By default append
       '.filtered' to the patch_file name


