
    ~pi=                    *   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&y)    )annotationsN)IterableIterator)partial)glob)Path)Any)unique_everseen   )StrPathStrPathT)Distribution)SetuptoolsDeprecationWarning)convert_path)z*.pyizpy.typedc                    t        j                  | t        j                  |       j                  t        j                  z         y N)oschmodstatst_modeS_IWRITE)targets    ]/opt/services/ai/voice_agent/venv/lib/python3.12/site-packages/setuptools/command/build_py.pymake_writabler      s'    HHVRWWV_,,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d#dZd$dZd Zd%d& fdZd'dZd(dZd(dZddZddZ	 	 	 	 	 	 d)dZddZd Zd Zd*dZd Zed+d       Z xZS ),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_dirc                    t         j                  j                  |        | j                  j                  | _        | j                  j
                  xs i | _        d| j                  v r| j                  d= y y )N
data_files)origr   finalize_optionsr   package_dataexclude_package_data__dict__selfs    r   r%   zbuild_py.finalize_options.   s^    &&t, --::$($5$5$J$J$Pb!4==(l+ )r   c                    |rDt        t        |      j                               }t        t        |      j                               }t        |   ||||||      S r   )strr   resolvesuper	copy_file)r*   infileoutfilepreserve_modepreserve_timeslinklevel	__class__s          r   r/   zbuild_py.copy_file5   sU     f--/0F$w-//12Gw G]ND%
 	
r   c                >   | j                   s| j                  r| j                  ry| j                   r| j                          | j                  r | j	                          | j                          | j                  t        j                  j                  | d             y)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   sp    4==T5G5G?? ==!##% 	$--33D53QRr   c                    |dk(  r!| j                         | _        | j                  S t        j                  j	                  | |      S )zlazily compute data filesr#   )_get_data_filesr#   r$   r   __getattr__)r*   attrs     r   rC   zbuild_py.__getattr__W   s;    <"224DO??"}}((t44r   c                |    | j                          t        t        | j                  | j                  xs d            S )z?Generate list of '(package,src_dir,build_dir,filenames)' tuples )analyze_manifestlistmap_get_pkg_data_filesr:   r)   s    r   rB   zbuild_py._get_data_files^   s/    C00$--2E2FGGr   c                    | j                   j                  di        t        t        | j                  | j
                  xs 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_filesrF   )r(   
setdefaultrH   rI   rJ   r:   r)   s    r   get_data_files_without_manifestz(build_py.get_data_files_without_manifestc   s:     	  !126C00$--2E2FGGr   c                &   | j                  |      }t        j                  j                  | j                  g|j                  d      z    }| j                  ||      D cg c]"  }t        j                  j                  ||      $ }}||||fS c c}w N.)get_package_dirr   pathjoin	build_libsplitfind_data_filesrelpath)r*   packagesrc_dir	build_dirfile	filenamess         r   rJ   zbuild_py._get_pkg_data_filesm   s    &&w/ GGLLDNN#3gmmC6H#HJ	
 ,,Wg>
 GGOOD'*
	 
 I55	
s   'Bc                   | j                  | j                  ||t              }t        t	        t
        d      |      }t        j                  j                  |      }t        t        j                  j                  |      }t        j                  | j                  j                  |g       |      }| j                  |||      S )z6Return filenames for package's data files in 'src_dir')extra_patternsT)	recursive)_get_platform_patternsr&   _IMPLICIT_DATA_FILESrI   r   r   	itertoolschainfrom_iterablefilterr   rS   isfilerL   getexclude_data_files)r*   rY   rZ   patternsglobs_expandedglobs_matches
glob_filesfiless           r   rW   zbuild_py.find_data_files{   s    ../	 / 
 WTT:HE!55nEBGGNNM:
##GR0
 &&w??r   c                    | j                   r't        | j                         j                               S t        |   |      S )1See :class:`setuptools.commands.build.SubCommand`)r    rH   get_output_mappingkeysr.   r?   )r*   r8   r6   s     r   r?   zbuild_py.get_outputs   s:    //166899w"#344r   c                    t        j                  | j                         | j                               }t	        t        |t        j                  d                  S )rp   r   )key)rc   rd    _get_package_data_output_mapping_get_module_mappingdictsortedoperator
itemgetter)r*   mappings     r   rq   zbuild_py.get_output_mapping   sG    //113$$&
 F7(;(;A(>?@@r   c              #     K   | j                         D ]:  \  }}}|j                  d      }| j                  | j                  ||      }||f < yw)z5Iterate over all modules producing (dest, src) pairs.rQ   N)find_all_modulesrV   get_module_outfilerU   )r*   rY   modulemodule_filefilenames        r   rv   zbuild_py._get_module_mapping   sV     ,0,A,A,C 	*(GV[mmC(G..t~~wOH[))	*s   AAc              #     K   | j                   D ]T  \  }}}}|D ]H  }t        j                  j                  ||      }t        j                  j                  ||      }||f J V yw)z6Iterate over package data producing (dest, src) pairs.N)r#   r   rS   rT   )r*   rY   rZ   r[   r]   r   r   srcfiles           r   ru   z)build_py._get_package_data_output_mapping   sd     6:oo 	(2GWi% (i:'',,w9w''(	(s   A%A'c                    | j                         D ]S  \  }}| j                  t        j                  j	                  |             | j                  ||      \  }}t        |       U y)z$Copy data files into build directoryN)ru   mkpathr   rS   dirnamer/   r   )r*   r   r   _outf_copieds        r   r=   zbuild_py.build_package_data   sS    #DDF 	"OFGKK/0!^^GV<NE7&!	"r   c                >   i | _         | j                  j                  sy i }| j                  xs dD ]  }||t	        | j                  |            <   ! | j                  r]t        | j                  d      j                         r9| j                  }t        |d      }|j                  d      j                         }nD| j                  d       | j                  d      }|j                  }|j                  j                  }t!               }| j#                  ||      D ]  }t$        j&                  j)                  t	        |            \  }	}
d }|
}|	rY|	|k7  rT|	|vrP|	}t$        j&                  j)                  |	      \  }	}t$        j&                  j+                  ||
      }
|	r
|	|k7  r|	|vrP|	|v s|
|k(  r|j-                  |
      r)|j/                  ||	   |
      }|r|j1                  |       | j                   j3                  ||	   g       j5                  |        y )NrF   zSOURCES.txtzutf-8)encodingegg_info)rL   r   include_package_datar:   assert_relativerR   r!   r   exists	read_text
splitlinesrun_commandget_finalized_commandr   filelistrn   _IncludePackageDataAbuse_filter_build_filesr   rS   rV   rT   	is_moduleimportable_subpackagewarnrM   append)r*   src_dirsrY   egg_info_dirmanifestrn   ei_cmdcheckrS   dfprevoldfdf
importables                  r   rG   zbuild_py.analyze_manifest   s   46  55#%}}* 	OGGNH_T%9%9'%BCD	O
 &&T//?FFH55LL-8H&&&8CCEEZ(//
;F!??LOO))E(*,,ULA 	MD77==!67DAqDDT	ax&7a(2GGLLQ' T	ax&7 H}9q) !&!<!<Xa[!!LJ!

:.##..x{B?FFtL!	Mr   c              #    K   | j                  d      }|| j                  |j                  |j                  f}|D cg c]$  }|st        j
                  j                  |      & }}|D ]Y  }t        j
                  j                  |      t        j
                  j                  |      rt        fd|D              sV| [ yc c}w w)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              3  &   K   | ]  }|v 
 y wr   rF   ).0r   	norm_paths     r   	<genexpr>z/build_py._filter_build_files.<locals>.<genexpr>   s     -TQay.@-Ts   N)	r   rU   
build_temp
build_baser   rS   normpathisabsall)	r*   rn   r   r   
build_dirsp	norm_dirsr\   r   s	           @r   r   zbuild_py._filter_build_files   s      **730@0@%BRBRS
2<BQRWW%%a(B	B 	D((.I77==&#-T)-T*T
	 Cs   :CC!C&AC Cc                     y r   rF   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	                  | ||      }|| j                   |<   |r| j
                  j                  s|S | j
                  j                  D ]  }||k(  s|j                  |dz         s n |S t        |d      5 }|j                         }ddd       n# 1 sw Y   nxY wdvr#t        j                  j                  d| d      |S )z8Check namespace packages' __init__ for declare_namespacerQ   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*   rY   package_dirinit_pypkgr   contentss          r   r   zbuild_py.check_package   s
   	((11 		 ----dG[I)0g&d//BBN$$77 	Cg~#!>	 N'4  	 AvvxH	  	  	 x/""11-gY 78 8  s    	.CCc                l    i | _         t        j                  j                  |        d| _        d | _        y )NF)r   r$   r   initialize_optionsr    r!   r)   s    r   r   zbuild_py.initialize_options  s,     "((."%)"r   c                    t         j                  j                  | |      }| j                  j                  4t
        j                  j                  | j                  j                  |      S |S r   )r$   r   rR   r   src_rootr   rS   rT   )r*   rY   ress      r   rR   zbuild_py.get_package_dir  sP    mm++D':%%177<< 1 1 : :C@@
r   c                    t              | j                  | j                  ||      }fd|D        }t        j                  j                  |      }t        |      fdD        }t        t        |            S )z6Filter filenames for package's data files in 'src_dir'c              3  J   K   | ]  }t        j                  |        y wr   )fnmatchrf   )r   patternrn   s     r   r   z.build_py.exclude_data_files.<locals>.<genexpr>$  s     O7ug6Os    #c              3  ,   K   | ]  }|vs|  y wr   rF   )r   fnbads     r   r   z.build_py.exclude_data_files.<locals>.<genexpr>(  s     7"327s   	)rH   ra   r'   rc   rd   re   setr
   )	r*   rY   rZ   rn   rj   match_groupsmatcheskeepersr   s	      `    @r   ri   zbuild_py.exclude_data_files  so    U..%%

 PhO////='l77OG,--r   c                    t        j                  || j                  dg       | j                  |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  p   K   | ]-  }t         j                  j                  t        |             / y wr   )r   rS   rT   r   )r   r   rZ   s     r   r   z2build_py._get_platform_patterns.<locals>.<genexpr>9  s/      
  GGLL,w"78
s   36)rc   rd   rh   )specrY   rZ   r_   raw_patternss     `  r   ra   zbuild_py._get_platform_patterns,  sF     !HHRHHWb!


 (
 	
r   returnNone)TTN   )r0   r   r1   r   r2   r   r3   r   r4   z
str | Noner5   objectr   ztuple[StrPathT | str, bool])rD   r,   r   r	   )r   z%list[tuple[str, str, str, list[str]]])rY   r,   r   ztuple[str, str, str, list[str]])T)r8   r   r   z	list[str])r   zdict[str, str])r   zIterator[tuple[str, str]])rn   zIterable[str]r   r   r   zIterator[str])rY   r,   r   r,   )rF   )__name__
__module____qualname____doc____annotations__r    r!   r%   r/   r@   rC   rB   rN   rJ   rW   r?   rq   rv   ru   r=   rG   r   r   r   r   rR   ri   staticmethodra   __classcell__)r6   s   @r   r   r       s    M4,0>0, ##

 
 	

 
 
 
 
%
"S"5H
H6@$5A*("'MR".5	*<*.  
 
r   r   c                    t         j                  j                  |       s| S ddlm} t        j                  d      j                         | 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   rS   r   distutils.errorsr   textwrapdedentlstrip)rS   r   msgs      r   r   r   @  sP    77==4 			
 &(

	  c
""r   c                  @    e Zd ZdZ G d de      Zd	dZd Zd Zd Z	y)
r   z>Inform users that package or module is included as 'data file'c                      e Zd ZdZdZy)!_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_DETAILSrF   r   r   _Warningr   X  s    "r   r   c                0    t        t                  | _        y r   )r   r,   _already_warnedr)   s    r   __init__z!_IncludePackageDataAbuse.__init__  s    "3xzr   c                b    |j                  d      xr |d t        d        j                         S )Nz.py)endswithlenisidentifier)r*   r\   s     r   r   z"_IncludePackageDataAbuse.is_module  s,    }}U#J]E
{(;(H(H(JJr   c                    t        |      j                  }t        t        j                  t
        j                  |j                              }|rdj                  |g|      S y rP   )	r   parentrH   rc   	takewhiler,   r   partsrT   )r*   r   r\   r   r   s        r   r   z._IncludePackageDataAbuse.importable_subpackage  sO    4jY(()9)9399EF88V,e,--r   c                    || j                   vr8| j                  j                  |       | j                   j                  |       y y )N)r   )r   r   emitadd)r*   r   s     r   r   z_IncludePackageDataAbuse.warn  s>    T111MM*5  $$Z0 2r   Nr   )
r   r   r   r   r   r   r   r   r   r   rF   r   r   r   r   U  s(    H'/ 'V*K1r   r   r   )'
__future__r   r   rc   ry   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   rb   r   r   r   rF   r   r   <module>r     sn    "    	   .     * %  3 ) )  ', >]
t}} ]
@	#*>1 >1r   