o
    ™Ìb  ã                   @  s`   d dl mZ d dlZd dlmZ erd dlmZ ddlmZ	 ddl
mZ ddd„Zddd„ZdS )é    )ÚannotationsN)ÚTYPE_CHECKING)Ú	TypeGuardé   )Ú_types)ÚtraceÚpathú_t.PathTÚ	scm_filesúset[str]Úscm_dirsÚreturnú	list[str]c                   sV  t j t j | ¡¡}tƒ }g }t j|ddD ]’\}}}t j t j |¡¡‰d‡‡fdd„‰ ˆ|vr8g |d	d	…< qt j |¡r_t j ˆ|¡ t j	¡s_| 
t j | t j || ¡¡¡ g |d	d	…< qˆ|v rjg |d	d	…< q‡ fd
d„|D ƒ|d	d	…< |D ])}	ˆ |	ƒr€qyt j ||	¡}
t j t j |
¡¡ˆv r¢| 
t j | t j |
|¡¡¡ qy| ˆ¡ q|S )a<   setuptools compatible file finder that follows symlinks

    - path: the root directory from which to search
    - scm_files: set of scm controlled files and symlinks
      (including symlinks to directories)
    - scm_dirs: set of scm controlled directories
      (including directories containing no scm controlled files)

    scm_files and scm_dirs must be absolute with symlinks resolved (realpath),
    with normalized case (normcase)

    Spec here: http://setuptools.readthedocs.io/en/latest/setuptools.html#        adding-support-for-revision-control-systems
    T)ÚfollowlinksÚnÚstrr   Úboolc                   s*   t j ˆ t j | ¡¡}t j |¡o|ˆvS )N)Úosr   ÚjoinÚnormcaseÚislink)r   Úfn)Úrealdirpathr
   © ú>usr/lib/python3.10/site-packages/setuptools_scm/file_finder.pyÚ_link_not_in_scm%   s   z(scm_find_files.<locals>._link_not_in_scmNc                   s   g | ]}ˆ |ƒs|‘qS r   r   )Ú.0Zdn)r   r   r   Ú
<listcomp>9   ó    z"scm_find_files.<locals>.<listcomp>)r   r   r   r   )r   r   r   ÚrealpathÚsetÚwalkr   ÚrelpathÚ
startswithÚpardirÚappendr   Úadd)r   r
   r   r   ÚseenÚresÚdirpathÚdirnamesÚ	filenamesÚfilenameZfullfilenamer   )r   r   r
   r   Úscm_find_files   s<   ÿþ€r-   Útoplevelú
str | NoneúTypeGuard[str]c                 C  sB   | du rdS t j dd¡ t j¡}dd„ |D ƒ}t| |ƒ | |vS )ú NFZSETUPTOOLS_SCM_IGNORE_VCS_ROOTSÚ c                 S  s   g | ]}t j |¡‘qS r   )r   r   r   )r   Úpr   r   r   r   K   r   z*is_toplevel_acceptable.<locals>.<listcomp>)r   ÚenvironÚgetÚsplitÚpathsepr   )r.   Zignoredr   r   r   Úis_toplevel_acceptableE   s   
r8   )r   r	   r
   r   r   r   r   r   )r.   r/   r   r0   )Ú
__future__r   r   Útypingr   Útyping_extensionsr   r2   r   Z_tÚutilsr   r-   r8   r   r   r   r   Ú<module>   s    
8