
    g_J                         d Z ddlZddlZddlmZ ddlmZ ddlmZm	Z	m
Z
 dee   defdZdee   dee   fd	Z	 dd
ededededef
dZy)zDefines a git hook to allow pre-commit warnings and errors about import order.

usage:
    exit_code = git_hook(strict=True|False, modify=True|False)
    N)Path)List)Configapi
exceptionscommandreturnc                     t        j                  | t         j                  d      }|j                  j	                         S )z
    Run a command and return raw output

    :param str command: the command to run
    :returns: the stdout output of the command
    T)stdoutcheck)
subprocessrunPIPEr   decode)r   results     -/usr/lib/python3/dist-packages/isort/hooks.py
get_outputr      s-     ^^GJOO4HF==!!    c                 z    t        |       }|j                         D cg c]  }|j                          c}S c c}w )z
    Run a command and return lines of output

    :param str command: the command to run
    :returns: list of whitespace-stripped lines output by command
    )r   
splitlinesstrip)r   r   lines      r   	get_linesr      s1      F%+%6%6%89TDJJL999s   8strictmodifylazysettings_filec           	         g d}|r|j                  d       t        |      }|syd}t        |t        j                  j                  t        j                  j                  |d                     }|D ]g  }|j                  d      sddd| g}	t        |	      }
	 t        j                  |
t        |      |	      s|d
z  }|rt        j                  ||       i | r|S dS # t        j                  $ r Y w xY w)a  
    Git pre-commit hook to check staged files for isort errors

    :param bool strict - if True, return number of errors on exit,
        causing the hook to fail. If False, return zero so it will
        just act as a warning.
    :param bool modify - if True, fix the sources if they are not
        sorted properly. If False, only report result without
        modifying anything.
    :param bool lazy - if True, also check/fix unstaged files.
        This is useful if you frequently use ``git commit -a`` for example.
        If False, ony check/fix the staged files for isort errors.
    :param str settings_file - A path to a file to be used as
                               the configuration file for this run.
        When settings_file is the empty string, the configuration file
        will be searched starting at the directory containing the first
        staged file, if any, and going upward in the directory structure.

    :return number of errors if in strict mode, 0 otherwise.
    )gitz
diff-index--cachedz--name-onlyz--diff-filter=ACMRTUXBHEADr    r   )r   settings_pathz.pyr   show:)	file_pathconfig   )r&   )remover   r   ospathdirnameabspathendswithr   r   check_code_stringr   	sort_filer   FileSkipped)r   r   r   r   diff_cmdfiles_modifiederrorsr&   filename
staged_cmdstaged_contentss              r   git_hookr7   $   s    2 bH
#x(NF#ggoobggoonQ6G&HIF # U#1XJ8J(4O,,#tH~f aKFhv>  6"" )) s   ?C$$C:9C:)FFF )__doc__r)   r   pathlibr   typingr   isortr   r   r   strr   r   boolintr7    r   r   <module>rA      s   
 
    ) )"S	 "c ":tCy :T#Y : Z\6#6#"&6#6:6#SV6#6#r   