
    Ri=                    .   d dl mZ d dlZd dlZd dlZd dlZd dlZd dlZd dlm	Z	m
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 d	d
lmZmZ d	dlmZ d	dlmZ d dlmc mZ d dlZ d dl!m"Z" dZ#ddZ$ G d dej                  Zd Z% G d d          Z&dS )    )annotationsN)IterableIterator)partial)glob)Path)Any)unique_everseen   )StrPathStrPathT)Distribution)SetuptoolsDeprecationWarning)convert_path)z*.pyizpy.typedreturnNonec                x    t          j        | t          j        |           j        t          j        z             d S N)oschmodstatst_modeS_IWRITE)targets    [/Users/shanyulin/my-agent/.venv/lib/python3.11/site-packages/setuptools/command/build_py.pymake_writabler      s,    HVRWV__,t}<=====    c                      e Zd ZU dZded<   dZded<   dZded	<   d=dZ	 	 	 	 d>d? fdZd=dZ	d@dZ
d  ZdAd"ZdBd%Zd& ZdCdD fd)ZdEd+ZdFd-ZdFd.Zd=d/Zd=d0ZdGd5Zd=d6Zd7 Zd8 ZdHd9Zd: ZedId<            Z xZS )Jbuild_pyaX  Enhanced 'build_py' command that includes data files with packages

    The data files are specified via a 'package_data' argument to 'setup()'.
    See 'setuptools.dist.Distribution' for more details.

    Also, this version of the 'build_py' command allows you to specify both
    'py_modules' and 'packages' in the same setup operation.
    r   distributionFbooleditable_modeNzStrPath | Noneexisting_egg_info_dirr   r   c                    t           j                            |            | j        j        | _        | j        j        pi | _        d| j        v r
| j        d= d S d S )N
data_files)origr   finalize_optionsr    package_dataexclude_package_data__dict__selfs    r   r'   zbuild_py.finalize_options.   s^    &&t,,, -:$($5$J$Pb!4=((l+++ )(r   T   infiler   outfiler   preserve_modepreserve_timeslink
str | Nonelevelobjecttuple[StrPathT | str, bool]c                   |r\t          t          |                                                    }t          t          |                                                    }t                                          ||||||          S r   )strr   resolvesuper	copy_file)r,   r.   r/   r0   r1   r2   r4   	__class__s          r   r;   zbuild_py.copy_file5   st      	3f--//00F$w--//1122Gww  G]ND%
 
 	
r   c                0   | j         s| j        r| j        rdS | j         r|                                  | j        r(|                                  |                                  |                     t          j        	                    | d                     dS )z?Build modules, packages, and copy data files to build directoryNF)include_bytecode)

py_modulespackagesr"   build_modulesbuild_packagesbuild_package_databyte_compiler&   r   get_outputsr+   s    r   runzbuild_py.runF   s     	4= 	T5G 	F? 	!   = 	&!!!##%%% 	$-33D53QQRRRRRr   attrr8   r	   c                    |dk    r |                                  | _        | j        S t          j                            | |          S )zlazily compute data filesr%   )_get_data_filesr%   r&   r   __getattr__)r,   rG   s     r   rJ   zbuild_py.__getattr__W   s@    <"2244DO?"}((t444r   c                |    |                                   t          t          | j        | j        pd                    S )z?Generate list of '(package,src_dir,build_dir,filenames)' tuples )analyze_manifestlistmap_get_pkg_data_filesr@   r+   s    r   rI   zbuild_py._get_data_files^   s6    C0$-2E2FFGGGr   %list[tuple[str, str, str, list[str]]]c                    | j                             di            t          t          | j        | j        pd                    S )z
        Generate list of ``(package,src_dir,build_dir,filenames)`` tuples,
        but without triggering any attempt to analyze or build the manifest.
        manifest_filesrL   )r*   
setdefaultrN   rO   rP   r@   r+   s    r   get_data_files_without_manifestz(build_py.get_data_files_without_manifestc   s?     	  !12666C0$-2E2FFGGGr   packagetuple[str, str, str, list[str]]c                    |                      |          t          j        j        | j        g|                    d          z    }fd|                     |          D             }|||fS )N.c                P    g | ]"}t           j                            |          #S rL   )r   pathrelpath).0filesrc_dirs     r   
<listcomp>z0build_py._get_pkg_data_files.<locals>.<listcomp>u   s9     
 
 
 GOOD'**
 
 
r   )get_package_dirr   r[   join	build_libsplitfind_data_files)r,   rV   	build_dir	filenamesr_   s       @r   rP   zbuild_py._get_pkg_data_filesm   s    &&w// GLDN#3gmmC6H6H#HJ	
 
 
 
,,Wg>>
 
 
	 I55r   c                   |                      | j        ||t                    }t          t	          t
          d          |          }t          j                            |          }t          t          j        j        |          }t          j        | j                            |g           |          }|                     |||          S )z6Return filenames for package's data files in 'src_dir')extra_patternsT)	recursive)_get_platform_patternsr(   _IMPLICIT_DATA_FILESrO   r   r   	itertoolschainfrom_iterablefilterr   r[   isfilerS   getexclude_data_files)r,   rV   r_   patternsglobs_expandedglobs_matches
glob_filesfiless           r   re   zbuild_py.find_data_files{   s    ../	 / 
 
 WTT:::HEE!55nEEBGNM::
##GR00
 
 &&w???r   r>   	list[str]c                    | j         r3t          |                                                                           S t	                                          |          S )1See :class:`setuptools.commands.build.SubCommand`)r"   rN   get_output_mappingkeysr:   rE   )r,   r>   r<   s     r   rE   zbuild_py.get_outputs   sM     	://116688999ww""#3444r   dict[str, str]c                    t          j        |                                 |                                           }t	          t          |t          j        d                              S )r{   r   )key)rm   rn    _get_package_data_output_mapping_get_module_mappingdictsortedoperator
itemgetter)r,   mappings     r   r|   zbuild_py.get_output_mapping   sY    /1133$$&&
 
 F7(;A(>(>???@@@r   Iterator[tuple[str, str]]c              #     K   |                                  D ]=\  }}}|                    d          }|                     | j        ||          }||fV  >dS )z5Iterate over all modules producing (dest, src) pairs.rY   N)find_all_modulesrd   get_module_outfilerc   )r,   rV   modulemodule_filefilenames        r   r   zbuild_py._get_module_mapping   sp      ,0,A,A,C,C 	* 	*(GV[mmC((G..t~wOOH[)))))	* 	*r   c              #     K   | j         D ]R\  }}}}|D ]H}t          j                            ||          }t          j                            ||          }||fV  ISdS )z6Iterate over package data producing (dest, src) pairs.N)r%   r   r[   rb   )r,   rV   r_   rf   rg   r   r   srcfiles           r   r   z)build_py._get_package_data_output_mapping   s|      6:o 	( 	(2GWi% ( (i::',,w99w'''''(	( 	(r   c                    |                                  D ]_\  }}|                     t          j                            |                     |                     ||          \  }}t          |           `dS )z$Copy data files into build directoryN)r   mkpathr   r[   dirnamer;   r   )r,   r   r   _outf_copieds        r   rC   zbuild_py.build_package_data   ss    #DDFF 	" 	"OFGKK//000!^^GV<<NE7&!!!!	" 	"r   c                l   i | _         | j        j        sd S i }| j        pdD ]'}||t	          |                     |                    <   (| j        rgt          | j        d                                          r@| j        }t          |d          }|	                    d          
                                }n=|                     d           |                     d          }|j        }|j        j        }t!                      }|                     ||          D ]}t$          j                            t	          |                    \  }	}
d }|
}|	rZ|	|k    rT|	|vrP|	}t$          j                            |	          \  }	}t$          j                            ||
          }
|	r
|	|k    r|	|vP|	|v r|
|k    r|                    |
          rn3|                    ||	         |
          }|r|                    |           | j                             ||	         g                               |           d S )NrL   zSOURCES.txtzutf-8)encodingegg_info)rS   r    include_package_datar@   assert_relativera   r#   r   exists	read_text
splitlinesrun_commandget_finalized_commandr   filelistrx   _IncludePackageDataAbuse_filter_build_filesr   r[   rd   rb   	is_moduleimportable_subpackagewarnrT   append)r,   src_dirsrV   egg_info_dirmanifestrx   ei_cmdcheckr[   dfprevoldfdf
importables                  r   rM   zbuild_py.analyze_manifest   sY   46 5 	F#%}* 	O 	OGGNH_T%9%9'%B%BCCDD &	*T/??FFHH	*  5LL-88H&&&88CCEEEEZ(((//
;;F!?LO)E(**,,ULAA 	M 	MD7==!6!677DAqDD (T		ax&7&7a((2GLLQ''  (T		ax&7&7 H}}99q)) ! ! "'!<!<Xa[!!L!LJ! /

:...#..x{B??FFtLLL!	M 	Mr   rx   Iterable[str]r   Iterator[str]c              #  <  K   |                      d          }|| j        |j        |j        f}d |D             }|D ]_}t          j                            |          t          j                            |          rt          fd|D                       r|V  `dS )a}  
        ``build_meta`` may try to create egg_info outside of the project directory,
        and this can be problematic for certain plugins (reported in issue #3500).

        Extensions might also include between their sources files created on the
        ``build_lib`` and ``build_temp`` directories.

        This function should filter this case of invalid files out.
        buildc                P    g | ]#}|t           j                            |          $S rL   )r   r[   normpath)r]   ps     r   r`   z0build_py._filter_build_files.<locals>.<listcomp>   s-    BBBQBRW%%a((BBBr   c              3      K   | ]}|vV  	d S r   rL   )r]   r   	norm_paths     r   	<genexpr>z/build_py._filter_build_files.<locals>.<genexpr>   s(      -T-TQay.@-T-T-T-T-T-Tr   N)	r   rc   
build_temp
build_baser   r[   r   isabsall)r,   rx   r   r   
build_dirs	norm_dirsr^   r   s          @r   r   zbuild_py._filter_build_files   s       **7330@%BRS
BB*BBB	 	 	D((..I7==&& #-T-T-T-T)-T-T-T*T*T 


	 	r   c                    d S r   rL   r+   s    r   get_data_fileszbuild_py.get_data_files   s    r   c                   	 | j         |         S # t          $ r Y nw xY wt          j                            | ||          }|| j         |<   |r| j        j        s|S | j        j        D ]"}||k    s|                    |dz             r n#|S t          |d          5 }|	                                }ddd           n# 1 swxY w Y   d|vr#t          j                            d| d          |S )z8Check namespace packages' __init__ for declare_namespacerY   rbNs   declare_namespacezNamespace package problem: z is a namespace package, but its
__init__.py does not call declare_namespace()! Please fix it.
(See the setuptools manual under "Namespace Packages" for details.)
")packages_checkedKeyErrorr&   r   check_packager    namespace_packages
startswithopenread	distutilserrorsDistutilsError)r,   rV   package_dirinit_pypkgr   contentss          r   r   zbuild_py.check_package   sl   	(11 	 	 	D	 ---dG[II)0g& 	d/B 	N$7 	 	Cg~~#!>!>~  N'4   	 AvvxxH	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 x//"118g 8 8 8   s    
B<<C C c                n    i | _         t          j                            |            d| _        d | _        d S )NF)r   r&   r   initialize_optionsr"   r#   r+   s    r   r   zbuild_py.initialize_options  s6     "((..."%)"""r   c                    t           j                            | |          }| j        j        *t
          j                            | j        j        |          S |S r   )r&   r   ra   r    src_rootr   r[   rb   )r,   rV   ress      r   ra   zbuild_py.get_package_dir  sF    m++D'::%17<< 1 :C@@@
r   c                (   t                    |                     | j        ||          }fd|D             }t          j                            |          }t          |          fdD             }t          t          |                    S )z6Filter filenames for package's data files in 'src_dir'c              3  B   K   | ]}t          j        |          V  d S r   )fnmatchrp   )r]   patternrx   s     r   r   z.build_py.exclude_data_files.<locals>.<genexpr>$  s/      OO7ug66OOOOOOr   c              3  $   K   | ]
}|v|V  d S r   rL   )r]   fnbads     r   r   z.build_py.exclude_data_files.<locals>.<genexpr>(  s'      77"3277r   )rN   rk   r)   rm   rn   ro   setr
   )	r,   rV   r_   rx   rt   match_groupsmatcheskeepersr   s	      `    @r   rs   zbuild_py.exclude_data_files  s    U..%
 

 POOOhOOO///=='ll7777777OG,,---r   rL   c                    t          j        ||                     dg           |                     |g                     }fd|D             S )z
        yield platform-specific path patterns (suitable for glob
        or fn_match) from a glob-based spec (such as
        self.package_data or self.exclude_package_data)
        matching package in src_dir.
         c              3  r   K   | ]1}t           j                            t          |                    V  2d S r   )r   r[   rb   r   )r]   r   r_   s     r   r   z2build_py._get_platform_patterns.<locals>.<genexpr>9  sQ       
 
  GLL,w"7"788
 
 
 
 
 
r   )rm   rn   rr   )specrV   r_   ri   raw_patternss     `  r   rk   zbuild_py._get_platform_patterns,  sh     !HHRHHWb!!
 


 
 
 
 (
 
 
 	
r   r   r   )TTNr-   )r.   r   r/   r   r0   r!   r1   r!   r2   r3   r4   r5   r   r6   )rG   r8   r   r	   )r   rQ   )rV   r8   r   rW   )T)r>   r!   r   ry   )r   r~   )r   r   )rx   r   r   r   r   r   )rV   r8   r   r8   )rL   )__name__
__module____qualname____doc____annotations__r"   r#   r'   r;   rF   rJ   rI   rU   rP   re   rE   r|   r   r   rC   rM   r   r   r   r   ra   rs   staticmethodrk   __classcell__)r<   s   @r   r   r       s6          M,00000, , , , ##
 
 
 
 
 
 
"S S S S"5 5 5 5H H H
H H H H6 6 6 6@ @ @$5 5 5 5 5 5 5A A A A* * * *( ( ( (" " " "'M 'M 'M 'MR   *     <* * *   . . .  
 
 
 \
 
 
 
 
r   r   c                    t           j                            |           s| S ddlm} t          j        d                                          | z  } ||          )Nr   )DistutilsSetupErrorz
        Error: setup script specifies an absolute path:

            %s

        setup() arguments must *always* be /-separated paths relative to the
        setup.py directory, *never* absolute paths.
        )r   r[   r   distutils.errorsr   textwrapdedentlstrip)r[   r   msgs      r   r   r   @  sp    7== 444444 			
 		
 &((

	  
c
"
""r   c                  H    e Zd ZdZ G d de          ZddZd Zd Zd	 Z	d
S )r   z>Inform users that package or module is included as 'data file'c                      e Zd ZdZdZdS )!_IncludePackageDataAbuse._WarningzU
        Package {importable!r} is absent from the `packages` configuration.
        a|  
        ############################
        # Package would be ignored #
        ############################
        Python recognizes {importable!r} as an importable package[^1],
        but it is absent from setuptools' `packages` configuration.

        This leads to an ambiguous overall configuration. If you want to distribute this
        package, please make sure that {importable!r} is explicitly added
        to the `packages` configuration field.

        Alternatively, you can also rely on setuptools' discovery methods
        (for example by using `find_namespace_packages(...)`/`find_namespace:`
        instead of `find_packages(...)`/`find:`).

        You can read more about "package discovery" on setuptools documentation page:

        - https://setuptools.pypa.io/en/latest/userguide/package_discovery.html

        If you don't want {importable!r} to be distributed and are
        already explicitly excluding {importable!r} via
        `find_namespace_packages(...)/find_namespace` or `find_packages(...)/find`,
        you can try to use `exclude_package_data`, or `include-package-data=False` in
        combination with a more fine grained `package-data` configuration.

        You can read more about "package data files" on setuptools documentation page:

        - https://setuptools.pypa.io/en/latest/userguide/datafiles.html


        [^1]: For Python, any directory (with suitable naming) can be imported,
              even if it does not contain any `.py` files.
              On the other hand, currently there is no concept of package data
              directory, all directories are treated like packages.
        N)r   r   r   _SUMMARY_DETAILSrL   r   r   _Warningr   X  s        "r   r   r   r   c                B    t          t                               | _        d S r   )r   r8   _already_warnedr+   s    r   __init__z!_IncludePackageDataAbuse.__init__  s    "3xzzr   c                    |                     d          o)|d t          d                                                    S )Nz.py)endswithlenisidentifier)r,   r^   s     r   r   z"_IncludePackageDataAbuse.is_module  s6    }}U##J]E

{](;(H(H(J(JJr   c                    t          |          j        }t          t          j        t
          j        |j                            }|rd                    |g|          S d S )NrY   )	r   parentrN   rm   	takewhiler8   r  partsrb   )r,   r  r^   r   r  s        r   r   z._IncludePackageDataAbuse.importable_subpackage  sV    4jjY()939EEFF 	.88V,e,---tr   c                    || j         vr7| j                            |           | j                             |           d S d S )N)r   )r   r   emitadd)r,   r   s     r   r   z_IncludePackageDataAbuse.warn  sN    T111M*555 $$Z00000 21r   Nr   )
r   r   r   r   r   r   r   r   r   r   rL   r   r   r   r   U  s        HH' ' ' ' '/ ' ' 'V* * * *K K K  1 1 1 1 1r   r   r   )'
__future__r   r   rm   r   r   r   r   collections.abcr   r   	functoolsr   r   pathlibr   typingr	   more_itertoolsr
   _pathr   r   distr   warningsr   distutils.command.build_pycommandr   r&   r   r   distutils.utilr   rl   r   r   r   rL   r   r   <module>r     s   " " " " " "       				   . . . . . . . .                         * * * * * * % % % % % % % %       3 3 3 3 3 3 ) ) ) ) ) ) ) ) )     ' ' ' ' ' ', > > > >]
 ]
 ]
 ]
 ]
t} ]
 ]
 ]
@	# # #*>1 >1 >1 >1 >1 >1 >1 >1 >1 >1r   