
    yIf                        d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ  ed          d	z  Z G d
 de          Z G d d          ZdS )    )annotationsN)Path)Literal)GitCommandError)Git)Repotestsz.pylint_primer_testsc                  $     e Zd ZdZd fdZ xZS )DirtyPrimerDirectoryExceptionz'We can't pull if there's local changes.path
Path | strc                R    t                                          d| d           d S )Nzm

/!\ Can't pull /!\

In order for the prepare command to be able to pull please cleanup your local repo:
cd z

git diff
)super__init__)selfr   	__class__s     \/var/www/piapp/venv/lib/python3.11/site-packages/pylint/testutils/_primer/package_to_lint.pyr   z&DirtyPrimerDirectoryException.__init__   sB    
 	  		
 		
 		
 		
 		
    )r   r   )__name__
__module____qualname____doc__r   __classcell__)r   s   @r   r   r      sC        11

 

 

 

 

 

 

 

 

 

r   r   c                      e Zd ZU dZded<   	 ded<   	 ded<   	 ded<   	 ded	<   	 ded
<   	 ded<   	 	 	 	 	 dddZedd            Zedd            Zedd            Z	edd            Z
ddZddZddZdS ) PackageToLintzARepresents data about a package to be tested during primer tests.strurlbranch	list[str]directories
str | Nonecommitpylint_additional_argspylintrc_relpathminimum_pythonNlist[str] | NonereturnNonec                l    || _         || _        || _        || _        |pg | _        || _        || _        d S )N)r   r   r    r"   r#   r$   r%   )r   r   r   r    r"   r#   r$   r%   s           r   r   zPackageToLint.__init__:   sD     &&<&B# 0,r   Path | Literal['']c                2    | j         dS | j        | j         z  S )N )r$   clone_directoryr   s    r   pylintrczPackageToLint.pylintrcL   s!     (2#d&;;;r   r   c                    d                     | j                            d          dd                                       dd          }t          |z  S )z#Directory to clone repository into./Nz.gitr,   )joinr   splitreplacePRIMER_DIRECTORY_PATH)r   
clone_names     r   r-   zPackageToLint.clone_directoryS   sG     XXdhnnS11"##677??KK
$z11r   c                *      fd j         D             S )zThe paths we need to lint.c                >    g | ]}t          j        |z            S  )r   r-   ).0r   r   s     r   
<listcomp>z/PackageToLint.paths_to_lint.<locals>.<listcomp>\   s)    NNNTD(4/00NNNr   )r    r.   s   `r   paths_to_lintzPackageToLint.paths_to_lintY   s#     ONNNT=MNNNNr   c                F    g }|d| j          gz  }| j        |z   | j        z   S )Nz	--rcfile=)r/   r=   r#   )r   optionss     r   pylint_argszPackageToLint.pylint_args^   s5    ///00!G+d.IIIr   c                    t          j        d| j                   | j                                        s|                                 S |                                 S )a  Concatenates the target directory and clones the file.

        Not expected to be tested as the primer won't work if it doesn't.
        It's tested in the continuous integration primers, only the coverage
        is not calculated on everything. If lazy clone breaks for local use
        we'll probably notice because we'll have a fatal when launching the
        primer locally.
        zLazy cloning %s)logginginfor   r-   exists_clone_repository_pull_repositoryr.   s    r   
lazy_clonezPackageToLint.lazy_clonee   sT     	&111#**,, 	,))+++$$&&&r   c                    | j         t          | j                  | j        dd}t	          j        d|           t          j        | j         | j        | j        d          }t          |j        j	        j
                  S )N   )r   to_pathr   depthz&Directory does not exists, cloning: %s)r   r   r-   r   rB   rC   r   
clone_fromheadobjecthexsha)r   r?   repos      r   rE   zPackageToLint._clone_repositorys   s}    84/00k	)
 )
 	=wGGG$"6t{RS
 
 
 49#*+++r   c                `   t                                          | j        | j                                      d          d         }t          | j                  j        j        j	        }||k    rt          j        d||           	 t          | j                  }|                                rt          | j                  |j        j        }|                                 n># t"          $ r}t%          d| j                   |d }~ww xY wt          j        d           t'          |          S )N	r   z?Remote sha is '%s' while local sha is '%s': pulling new commitszFailed to clone repository for zRepository already up to date.)r   	ls_remoter   r   r4   r   r-   rM   rN   rO   rB   rC   is_dirtyr   remotesoriginpullr   SystemErrorr   )r   remote_sha1_commitlocal_sha1_commitrP   rV   es         r   rF   zPackageToLint._pull_repository   s)    UU__TXt{CCII$OOPQR !566;BI!222LQ"!  
	D011==?? N78LMMM,"   !Ld6JLL 
 L9:::%&&&s   AC# #
D
-DD
)NNNN)r   r   r   r   r    r   r"   r!   r#   r&   r$   r!   r%   r!   r'   r(   )r'   r*   )r'   r   )r'   r   )r'   r   )r   r   r   r   __annotations__r   propertyr/   r-   r=   r@   rG   rE   rF   r:   r   r   r   r   "   sj        KKHHH)KKK,?/%%%%&    Q: "37'+%)- - - - -$ < < < X< 2 2 2 X2
 O O O XO J J J XJ' ' ' ', , , ,' ' ' ' ' 'r   r   )
__future__r   rB   pathlibr   typingr   gitr   git.cmdr   git.repor   r6   	Exceptionr   r   r:   r   r   <module>re      s   
 # " " " " "                               W(>> 
 
 
 
 
I 
 
 
 s' s' s' s' s' s' s' s' s' s'r   