XylotrechusZ
�
� h
�
�� � d Z ddlZddlZddlmZ ddlmZmZ ddlm Z m
Z
mZ dee defd�Z
dee dee fd �Z dded
edededeee defd�ZdS )z�Defines 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�Optional)�Config�api�
exceptions�command�returnc �v � t j | t j d�� � }|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 �\/builddir/build/BUILD/cloudlinux-venv-1.0.8/venv/lib/python3.11/site-packages/isort/hooks.py�
get_outputr s0 � � �^�G�J�O�4�
H�
H�
H�F��=���!�!�!� c �\ � t | � � }d� |� � � D � � S )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
c �6 � g | ]}|� � � ��S � )�strip)�.0�lines r �
<listcomp>zget_lines.<locals>.<listcomp> s � �9�9�9�T�D�J�J�L�L�9�9�9r )r �
splitlines)r r s r � get_linesr s1 � � ��
�
�F�9�9�V�%6�%6�%8�%8�9�9�9�9r F� �strict�modify�lazy�
settings_file�directoriesc �P � g d�}|r|� d� � |r|� |� � t |� � }|sdS d}t |t j � t j � |d � � � � �� � }|D ]�} | � d� � roddd| � �g}
t |
� � } t j |t | � � |� � � s|d
z
}|rt j
| |�� � �q# t j $ r Y ��w xY w��| r|ndS )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, only 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.
:param list[str] directories - A list of directories to restrict the hook to.
:return number of errors if in strict mode, 0 otherwise.
)�gitz
diff-index�--cachedz--name-onlyz--diff-filter=ACMRTUXB�HEADr'