
    GuibI                       d Z ddlmZ ddl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mZ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ZmZmZ erddl m!Z! ddl"m#Z#  ejH                  e%      Z&d!dZ'd"dZ(	 d#	 	 	 	 	 	 	 d$dZ)	 	 	 d%	 	 	 	 	 	 	 	 	 d&dZ*	 	 	 d'	 	 	 	 	 	 	 	 	 d(dZ+ G d d      Z,d Z-ed)d       Z. G d dej^                        Z0 G d de      Z1 G d d e      Z2y)*ac  
Load setuptools configuration from ``pyproject.toml`` files.

**PRIVATE MODULE**: API reserved for setuptools internal usage only.

To read project metadata, consider using
``build.util.project_wheel_metadata`` (https://pypi.org/project/build/).
For simple scenarios, you can also try parsing the file directly
with the help of ``tomllib`` or ``tomli``.
    )annotationsN)Mapping)contextmanager)partial)TracebackType)TYPE_CHECKINGAnyCallable   )StrPath)	FileErrorInvalidConfigError)SetuptoolsWarning   )expand)_PREVIOUSLY_DEFINED_MissingDynamicapply)SelfDistributionc                t    ddl m} t        | d      5 }|j                  |      cd d d        S # 1 sw Y   y xY w)Nr   )tomllibrb)compat.py310r   openload)filepathr   files      Q/opt/pipecat/venv/lib/python3.12/site-packages/setuptools/config/pyprojecttoml.py	load_filer!   $   s2    &	h	 "||D!" " "s   .7c                   ddl m} |j                  j                  d      }t	        |d      r|j                          	 |j                  |       S # |j                  $ r}d|j                   }|j                  j                  d      dk7  r4t        j                  |       t        j                  |j                         d|j                   d	}t        | d
|       d d }~ww xY w)Nr   )_validate_pyprojectztrove-classifier_disable_downloadzconfiguration error: `projectzinvalid pyproject.toml config: .
) r#   FORMAT_FUNCTIONSgethasattrr$   validateValidationErrorsummarynamestrip_loggerdebugdetails
ValueError)configr   	validatortrove_classifierexr/   errors          r    r-   r-   +   s    2 11556HI!45**,
:!!&))$$ :)"**677==*MM'"MM"**%1"''!<E7"WI./T9:s   A C&BC!!C&c                8    t        |d||       }t        | ||      S )zeApply the configuration from a ``pyproject.toml`` file into an existing
    distribution object.
    T)read_configuration_apply)distr   ignore_option_errorsr6   s       r    apply_configurationr@   @   s$      $0DdKF$))    c                   t         j                  j                  |       } t         j                  j                  |       st	        d| d      t        |       xs i }|j                  di       }|j                  di       }|j                  di       }|r|s|si S d|j                  di       v rt        j                          d|v rt        j                  d	       |r)|j                  |j                  d|j                         n|j                  dd       ||d<   ||d<   d|v rt        j                  d	       d}||j                  dg       ft        fd|D              rt        d      t        |      5  |d|id}	t        |	|        d
d
d
       |r-t         j                  j!                  |       }
t#        ||
||      S |S # 1 sw Y   :xY w)a  Read given configuration file and returns options from it as a dict.

    :param str|unicode filepath: Path to configuration file in the ``pyproject.toml``
        format.

    :param bool expand: Whether to expand directives and other computed values
        (i.e. post-process the given configuration)

    :param bool ignore_option_errors: Whether to silently ignore
        options, values of which could not be resolved (e.g. due to exceptions
        in directives such as file:, attr:, etc.).
        If False exceptions are propagated as expected.

    :param Distribution|None: Distribution object to which the configuration refers.
        If not given a dummy object will be created and discarded after the
        configuration is read. This is used for auto-discovery of packages and in the
        case a dynamic configuration (e.g. ``attr`` or ``cmdclass``) is expanded.
        When ``expand=False`` this object is simply ignored.

    :rtype: dict
    zConfiguration file z does not exist.r&   tool
setuptoolstools	distutilsz[tool.distutils])subjectNzinclude-package-dataTzext-modulesz[tool.setuptools.ext-modules])zimport-nameszimport-namespacesdynamicc              3  4   K   | ]  }D ]  }||v  
  y wN ).0fieldplaceplacess      r    	<genexpr>z%read_configuration.<locals>.<genexpr>   s!     
Be6
B%5E>
B>
Bs   zSetuptools does not support `import-names` and `import-namespaces` in `pyproject.toml` yet. If your are interested in this feature,  please consider submitting a contribution via pull requests.)r&   rC   )ospathabspathisfiler   r!   r+   _ToolsTypoInMetadataemit_ExperimentalConfigurationinclude_package_data
setdefaultanyNotImplementedError_ignore_errorsr-   dirnameexpand_configuration)r   r   r?   r>   asdictproject_table
tool_tablesetuptools_tablefieldssubsetroot_dirrO   s              @r    r<   r<   L   s   6 wwx(H77>>(#-h\9IJKKx &BFJJy"-MFB'J!~~lB7-+;	vzz'2..!!#j "''0B'C ))5##$:D<U<UV##$:DAF6N/J|(("''0O'P2F]..y"=>F

Bv
BB!L
 	
 
,	- #*\CS4TU"#
 77??8,#FH6JDQQM# #s   ?GGc                :    t        | |||      j                         S )a  Given a configuration with unresolved fields (e.g. dynamic, cmdclass, ...)
    find their final values.

    :param dict config: Dict containing the configuration for the distribution
    :param str root_dir: Top-level directory for the distribution/project
        (the same directory where ``pyproject.toml`` is place)
    :param bool ignore_option_errors: see :func:`read_configuration`
    :param Distribution|None: Distribution object to which the configuration refers.
        If not given a dummy object will be created and discarded after the
        configuration is read. Used in the case a dynamic configuration
        (e.g. ``attr`` or ``cmdclass``).

    :rtype: dict
    )_ConfigExpanderr   )r6   re   r?   r>   s       r    r^   r^      s    ( 68-A4HOOQQrA   c                      e Zd Z	 	 	 d	 	 	 	 	 	 	 	 	 ddZddZddZddZd Zd Zd Z	dd	Z
dd
ZddZ	 	 	 	 ddZddZddZddZ	 	 	 	 	 	 ddZd dZd dZd dZy)!rg   Nc                   || _         |xs t        j                         | _        |j	                  di       | _        | j
                  j	                  dg       | _        |j	                  di       j	                  di       | _        | j                  j	                  di       | _        || _	        || _
        t        t                  | _        y )Nr&   rH   rC   rD   )r6   rQ   getcwdre   r+   project_cfgrH   setuptools_cfgdynamic_cfgr?   _distsetstr_referenced_files)selfr6   re   r?   r>   s        r    __init__z_ConfigExpander.__init__   s      /BIIK!::i4''++Ir:$jj488rJ..229bA$8!
!$SrA   c                    ddl m} | j                  | j                  j	                  dd       d}| j
                  xs  ||      S )Nr   r   r0   )src_rootr0   )setuptools.distr   re   rk   r+   rn   )rr   r   attrss      r    _ensure_distz_ConfigExpander._ensure_dist   s;    0!]]D4D4D4H4HQU4VWzz0\%00rA   c                ~    ||v r-t        | j                        5   |||         ||<   d d d        y y # 1 sw Y   y xY wrJ   )r\   r?   )rr   	containerrM   fns       r    _process_fieldz_ConfigExpander._process_field   sK    I 9 9: 8#%i&6#7	% 8 8 8 8s   3<c                d    | j                   j                  |i       }t        j                  |      S rJ   )rl   r+   _expandcanonic_package_data)rr   rM   package_datas      r    _canonic_package_dataz%_ConfigExpander._canonic_package_data   s+    **..ub9++L99rA   c                   | j                          | j                          | j                  d       | j                         }t        || j                  | j
                        }|5 }|j                  }| j                          | j                  |       | j                  ||       d d d        |j                  j                  | j                         | j                  S # 1 sw Y   :xY w)Nzexclude-package-data)_expand_packagesr   rx   _EnsurePackagesDiscoveredrk   rl   package_dir_expand_data_files_expand_cmdclass_expand_all_dynamicrq   updater6   )rr   r>   ctxensure_discoveredr   s        r    r   z_ConfigExpander.expand   s    ""$""#9:   "'d.>.>@S@ST 	8%+77K##%!!+.$$T;7		8 	%%d&<&<={{	8 	8s   %A CC'c                   | j                   j                  d      }|t        |t        t        f      ry |j                  d      }t        |t
              ro| j                  |d<   | j                   j                  di       |d<   t        | j                        5  t        j                  di || j                   d<   d d d        y y # 1 sw Y   y xY w)Npackagesfindre   package-dirfill_package_dirrK   )rl   r+   
isinstancelisttupledictre   rY   r\   r?   r~   find_packages)rr   r   r   s      r    r   z _ConfigExpander._expand_packages   s    &&**:6z(T5MB||F#dD!#}}D'+':':'E'EmUW'XD#$ 9 9: P292G2G2O$2O##J/P P "P Ps   #CCc                    t        t        j                  | j                        }| j	                  | j
                  d|       y )N)re   z
data-files)r   r~   canonic_data_filesre   r|   rl   )rr   
data_filess     r    r   z"_ConfigExpander._expand_data_files   s0    W77$--P
D//zJrA   c                    | j                   }t        t        j                  ||      }| j	                  | j
                  d|       y )N)r   re   cmdclass)re   r   r~   r   r|   rl   )rr   r   re   r   s       r    r   z _ConfigExpander._expand_cmdclass   s7    ==7++xXD//XFrA   c           
        d}| j                   D ci c]  }||vr|| j                  |||       }}|j                  | j                  ||      xs i | j	                  ||      | j                  |      | j                  |      | j                  |      | j                  |             |j                         D ci c]  \  }}|	|| }}}| j                  j                  |       y c c}w c c}}w )N)versionreadmeentry-pointsscriptsgui-scriptsclassifiersdependenciesoptional-dependencies)r   r   r   r   optional_dependencies)rH   _obtainr   _obtain_entry_points_obtain_version_obtain_readme_obtain_classifiers_obtain_dependencies_obtain_optional_dependenciesitemsrk   )	rr   r>   r   specialrM   obtained_dynamickvupdatess	            r    r   z#_ConfigExpander._expand_all_dynamic   s   	
 
G# 4<<e[99
 

 	%%dK8>B(({;&&t,0062248"&"D"DT"J 	  	
 %5$:$:$<NDAq1a4NN(!
 Os   C+<
C0C0c                `    t        |   |      }|| j                  sd|d}t        |      y y )Nz#No configuration found for dynamic z.
Some dynamic fields need to be specified via `tool.setuptools.dynamic`
others must be specified via the equivalent attribute in `setup.py`.)r   r?   r   )rr   r>   rM   previousmsgs        r    _ensure_previously_setz&_ConfigExpander._ensure_previously_set  sL    &u-d3D$=$=5eY ?Y Y 
 %S)) %>rA   c                n   ddl m} t        | j                        5  | j                  }d|v rF| j
                  j                   ||d                t        j                  |d   |      cd d d        S d|v r#t        j                  |d   ||      cd d d        S t        d| d|      # 1 sw Y   y xY w)Nr   )always_iterabler   attrz	invalid `z`: )more_itertoolsr   r\   r?   re   rq   r   r~   
read_files	read_attrr5   )rr   	specifier	directiver   r   re   s         r    _expand_directivez!_ConfigExpander._expand_directive$  s     	3D556 	F}}H"&&--oi>O.PQ)))F*;XF		F 	F
 "((6):KR	F 	F y3ymDEE	F s   AB+3B+B++B4c                    || j                   v r#| j                  d| | j                   |   |      S | j                  ||       y )Nztool.setuptools.dynamic.)rm   r   r   )rr   r>   rM   r   s       r    r   z_ConfigExpander._obtain3  sS    D$$$))*5'2  ' 
 	##D%0rA   c                    d| j                   v r4d| j                  v r&t        j                  | j	                  |d|            S y )Nr   )rH   rm   r~   r   r   )rr   r>   r   s      r    r   z_ConfigExpander._obtain_version=  sA    $d6F6F)F??T9k:  rA   c                    d| j                   vry | j                  }d|v r)| j                  |di       |d   j                  dd      dS | j	                  |d       y )Nr   content-typez
text/x-rst)textr   )rH   rm   r   r+   r   )rr   r>   rm   s      r    r   z_ConfigExpander._obtain_readmeF  sj    4<<'&&{" T8R8 +H 5 9 9., W  	##D(3rA   c                     d}t         fd|D              sy  j                  |d|      }|y t        j                  |      did	 fd} |dd        |dd       S )
N)r   r   r   c              3  :   K   | ]  }|j                   v   y wrJ   )rH   )rL   rM   rr   s     r    rP   z7_ConfigExpander._obtain_entry_points.<locals>.<genexpr>Y  s     =U5DLL(=s   r   c                    |v rDj                  |      }| j                  vrt        t        j                  | |            || <   y y rJ   )poprH   r   r   r4   )rM   groupvalueexpandedgroupsrr   s      r    _set_scriptsz:_ConfigExpander._obtain_entry_points.<locals>._set_scriptsd  sJ    

5),,_-D-DUE-RSS"'	 rA   r   console_scriptsr   gui_scripts)rM   rp   r   rp   )rZ   r   r~   entry_points)rr   r>   r   rc   r   r   r   r   s   `     @@r    r   z$_ConfigExpander._obtain_entry_pointsU  sp     <=f==||D.+><%%d+/=v.F	( 	Y 12]M2rA   c                j    d| j                   v r%| j                  |di       }|r|j                         S y )Nr   )rH   r   
splitlinesrr   r>   r   s      r    r   z#_ConfigExpander._obtain_classifiersp  s5    DLL(LL}b9E''))rA   c                `    d| j                   v r | j                  |di       }|rt        |      S y )Nr   )rH   r   _parse_requirements_listr   s      r    r   z$_ConfigExpander._obtain_dependenciesw  s1    T\\)LL~r:E/66rA   c                2   d| j                   vry d| j                  v rb| j                  d   }t        |t              sJ |j	                         D ci c]%  \  }}|t        | j                  d| |i             ' c}}S | j                  |d       y c c}}w )Nr   z.tool.setuptools.dynamic.optional-dependencies.)rH   rm   r   r   r   r   r   r   )rr   r>   optional_dependencies_mapr   r   s        r    r   z-_ConfigExpander._obtain_optional_dependencies~  s    "$,,6"d&6&66(,(8(89P(Q%7>>> )B(G(G(I	 %E9 /**HP! 	 	 	##D*AB	s   *BNFN)
r6   r   re   StrPath | Noner?   boolr>   Distribution | NonereturnNone)r   r   )rz   r   rM   rp   r{   r
   )zpackage-data)r   Mapping[str, str])r>   r   r   r   )r>   r   rM   rp   )r   rp   r   r   )r>   r   rM   rp   r   r   )r>   r   r   zdict[str, str] | None)r>   r   r   r   r   z dict[str, dict[str, Any]] | None)r>   r   )__name__
__module____qualname__rs   rx   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rK   rA   r    rg   rg      s     $(%*$(,, !, #	,
 ", 
,"18
:"
PKG
)<*6G /@	)6rA   rg   c                    | j                         D cg c]3  }|j                         r!|j                         j                  d      s|5 c}S c c}w )N#)r   r1   
startswith)r   lines     r    r   r     sI     $$&::<

 7 7 < 	  s   8Ac              #     K   | sd  y 	 d  y # t         $ r9}t        j                  d|j                  j                   d|        Y d }~y d }~ww xY ww)Nzignored error: z - )	Exceptionr2   r3   	__class__r   )r?   r9   s     r    r\   r\     sP     H H(=(='>c"FGGHs*   A A	A/AAAAc                  X     e Zd Z	 	 	 	 	 	 	 	 d fdZd fdZ	 	 	 	 	 	 	 	 d fdZ xZS )r   c                @    t         |   |       || _        || _        y rJ   )superrs   _project_cfg_setuptools_cfg)rr   distributionrk   rl   r   s       r    rs   z"_EnsurePackagesDiscovered.__init__  s"     	&'-rA   c                   | j                   | j                  }}|j                  di       }|j                  |j                  xs i        ||_        |j
                  j                          |j                  j                  *| j                  j                  d      |j                  _        |j                  |j                  d      |_        |j                  |j                  d      |_        t        | 9         S )zWhen entering the context, the values of ``packages``, ``py_modules`` and
        ``package_dir`` that are missing in ``dist`` are copied from ``setuptools_cfg``.
        r   r0   
py-modulesr   )rn   r   rY   r   r   set_defaults_ignore_ext_modulesmetadatar0   r   r+   
py_modulesr   r   	__enter__)rr   r>   cfgr   r   s       r    r   z#_EnsurePackagesDiscovered.__enter__  s     JJ 4 4c&)nn]B&G4++1r2&--/ ==%!%!2!2!6!6v!>DMM??"!ggl3DO== GGJ/DMw ""rA   c                    | j                   j                  d| j                  j                         | j                   j                  d| j                  j                         t
        |   |||      S )zWhen exiting the context, if values of ``packages``, ``py_modules`` and
        ``package_dir`` are missing in ``setuptools_cfg``, copy from ``dist``.
        r   r   )r   rY   rn   r   r   r   __exit__)rr   exc_type	exc_value	tracebackr   s       r    r   z"_EnsurePackagesDiscovered.__exit__  sY     	''
DJJ4G4GH''djj6K6KLw)Y??rA   )r   r   rk   r   rl   r   r   r   )r   r   )r   ztype[BaseException] | Noner   zBaseException | Noner   zTracebackType | Noner   r   )r   r   r   rs   r   r   __classcell__)r   s   @r    r   r     sc    .(.7;.MQ.	.#,@,@ (@ (	@
 
@ @rA   r   c                      e Zd ZdZy)rW   z``{subject}` in `pyproject.toml` is still *experimental* and likely to change in future releases.Nr   r   r   _SUMMARYrK   rA   r    rW   rW     s    	3 rA   rW   c                      e Zd ZdZy)rU   zNIgnoring [tools.setuptools] in pyproject.toml, did you mean [tool.setuptools]?Nr   rK   rA   r    rU   rU     s
    X rA   rU   )r   r   r   r   )r6   r   r   r   r   r   )F)r>   r   r   r   r?   r   r   r   )TFN)
r   r   r   r   r?   r   r>   r   r   zdict[str, Any]r   )
r6   r   re   r   r?   r   r>   r   r   r   )r?   r   )3__doc__
__future__r   loggingrQ   collections.abcr   
contextlibr   	functoolsr   typesr   typingr   r	   r
   _pathr   errorsr   r   warningsr   r)   r   r~   _apply_pyprojecttomlr   r   r   r=   typing_extensionsr   rv   r   	getLoggerr   r2   r!   r-   r@   r<   r^   rg   r   r\   EnsurePackagesDiscoveredr   rW   rU   rK   rA   r    <module>r     sl  	 #  	 # %   / /  2 (  W W&,
'

H
%":0 "'	*
	*	* 	* 		* !& $	OOO O 	O
 Oh  $!& $	RRR R 	R
 
R.Z Zz H H*@ @ @ *@Z!2 , rA   