
    OgRD                    d   S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
r
SSKrSSKrSSKJr  SSKJr  SSKJrJrJrJrJrJrJrJrJr   SSKJr  SSKJr   SSK$r%SSK&r%\R
                  RO                  S	5      =(       a    S
\	RP                  " 5       ;  r)\R
                  RO                  S5      r*\)(       a  SOSr+ " S S\5      r,\RZ                  " 5       r.\R^                  SS j5       r0SS jr1Sr2\" 5       SS j5       r3 " S S\ 5      r S     S S jjr4S!S jr5S"S jr6\" SSS9r7\\%Rp                  Rr                  \\:   \\:   \\\\\:   \\:\\:   4   4         \\\:      \;\\\:      \\\:      \\\:      /	\\:   4   r< " S S5      r=g! \! a    SSK"Jr   SSK#Jr   GNNf = f)#a>  
This module provides helpers for C++11+ projects using pybind11.

LICENSE:

Copyright (c) 2016 Wenzel Jakob <wenzel.jakob@epfl.ch>, All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice, this
   list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
   this list of conditions and the following disclaimer in the documentation
   and/or other materials provided with the distribution.

3. Neither the name of the copyright holder nor the names of its contributors
   may be used to endorse or promote products derived from this software
   without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    )annotationsN)	lru_cache)Path)	AnyCallableIterableIteratorListOptionalTupleTypeVarUnion)	Extension)	build_extwin32mingwdarwinz
/std:c++{}z
-std=c++{}c                     ^  \ rS rSrSrS	S jrS	S jrS
U 4S jjr\SS j5       r	\	R                  SS j5       r	SrU =r$ )Pybind11ExtensionY   a  
Build a C++11+ Extension module with pybind11. This automatically adds the
recommended flags when you init the extension and assumes C++ sources - you
can further modify the options yourself.

The customizations are:

* ``/EHsc`` and ``/bigobj`` on Windows
* ``stdlib=libc++`` on macOS
* ``visibility=hidden`` and ``-g0`` on Unix

Finally, you can set ``cxx_std`` via constructor or afterwards to enable
flags for C++ std, and a few extra helper flags related to the C++ standard
level. It is _highly_ recommended you either set this, or use the provided
``build_ext``, which will search for the highest supported extension for
you if the ``cxx_std`` property is not set. Do not set the ``cxx_std``
property more than once, as flags are added when you set it. Set the
property to None to disable the addition of C++ standard flags.

If you want to add pybind11 headers manually, for example for an exact
git checkout, then set ``include_pybind11=False``.
c                     XR                   S S& g Nr   )extra_compile_argsselfflagss     [/Users/admin/workspace/ai/Jarvis/env/lib/python3.13/site-packages/pybind11/setup_helpers.py_add_cflagsPybind11Extension._add_cflagst   s    &+#    c                     XR                   S S& g r   )extra_link_argsr   s     r   _add_ldflagsPybind11Extension._add_ldflagsw   s    #(Ra r    c                  > SU l         UR                  SS5      nSU;  a  SUS'   UR                  SS5      n[        TU ]  " U0 UD6  U(       a?   SS KnUR                  5       nX`R                  ;  a  U R                  R                  U5        X0l	        / n[        (       a  USS/-  nOUS	/-  n[        R                  R                  S
S5      n[        R                  R                  SS5      n	[        R                  " U5      [        R                  " U	5      -   n
[!        S U
 5       5      (       d  US/-  nU R#                  U5        g ! [         a     Nf = f)Nr   cxx_stdlanguagezc++include_pybind11Tz/EHscz/bigobjz-fvisibility=hiddenCFLAGS CPPFLAGSc              3  B   #    U  H  oR                  S 5      v   M     g7f)z-gN)
startswith).0opts     r   	<genexpr>-Pybind11Extension.__init__.<locals>.<genexpr>   s     C{~~d++{s   z-g0)
_cxx_levelpopsuper__init__pybind11get_includeinclude_dirsappendModuleNotFoundErrorr&   WINosenvirongetshlexsplitanyr   )r   argskwargsr&   r(   r6   pyinccflags
env_cflagsenv_cppflagsc_cpp_flags	__class__s              r   r5   Pybind11Extension.__init__z   s<   **Y*V#!&F:!::&8$?$)&)  ,,. 1 11%%,,U3 3w	**F,--F"5J::>>*b9L++j1EKK4MMKC{CCC5'!  ' s   >E 
EEc                    U R                   $ )a  
The CXX standard level. If set, will add the required flags. If left at
0, it will trigger an automatic search when pybind11's build_ext is
used. If None, will have no effect.  Besides just the flags, this may
add a macos-min 10.9 or 10.14 flag if MACOSX_DEPLOYMENT_TARGET is
unset.
)r2   r   s    r   r&   Pybind11Extension.cxx_std   s     r    c                ,   U R                   (       a  [        R                  " SSS9  [        (       a  US:X  a  SnXl         U(       d  g [        R                  U5      /n/ n[        (       a  S[        R                  ;  at  [        S [        R                  " 5       S   R                  S	5      S S  5       5      nUS
:  a  SOSnS	R                  S [        XE5       5       5      nSU 3nX'/-  nX7/-  nU R                  U5        U R!                  U5        g )Nz8You cannot safely change the cxx_level after setting it!   )
stacklevel      MACOSX_DEPLOYMENT_TARGETc              3  8   #    U  H  n[        U5      v   M     g 7fN)intr.   xs     r   r0   ,Pybind11Extension.cxx_std.<locals>.<genexpr>   s     !W2VQ#a&&2V   r   .   )
   	   )r]   rR   c              3  8   #    U  H  n[        U5      v   M     g 7frU   )strrW   s     r   r0   rY      s     #V4UqCFF4UrZ   z-mmacosx-version-min=)r2   warningswarnr;   STD_TMPLformatMACOSr<   r=   tupleplatformmac_verr@   joinminr   r#   )r   levelrE   ldflagscurrent_macosdesired_macosmacos_string
macosx_mins           r   r&   rM      s    ??MMJWX 35B;E//%()5/rzzA "!W(2B2B2DQ2G2M2Mc2RSUTU2V!WWM',rzGxM88#VC4U#VVL0?Jl"F|#G '"r    )r2   r&   )r   	list[str]returnNone)rB   r   rC   r   rr   rs   )rr   rV   )rk   rV   rr   rs   )__name__
__module____qualname____firstlineno____doc__r   r#   r5   propertyr&   setter__static_attributes____classcell__rI   s   @r   r   r   Y   sD    4,)$!L   ^^!# !#r    r   c               #    #    [            [        R                  " 5       n  [        R                  " 5       n[        R
                  " U5        Uv   [        R
                  " U 5        [        R                  " U5         SSS5        g! [        R
                  " U 5        [        R                  " W5        f = f! , (       d  f       g= f7f)z:Prepare and enter a temporary directory, cleanup when doneN)tmp_chdir_lockr<   getcwdtempfilemkdtempchdirshutilrmtree)olddirtmpdirs     r   	tmp_chdirr      s{     
 
	"%%'FHHVLHHVMM&! 
 HHVMM&! 
s3   CB6/B,B6<	C.B33B66
C Cc                   [        5          [        S5      nUR                  SSS9   U R                  [	        U5      /U/S9   SSS5        g! [
        R                  R                   a     SSS5        gf = f! , (       d  f       g= f)	z
Return the flag if a flag name is supported on the
specified compiler, otherwise None (can be used as a boolean).
If multiple flags are passed, return the first that matches.
zflagcheck.cppz%int main (int, char **) { return 0; }zutf-8)encoding)extra_postargsNFT)r   r   
write_textcompiler`   	distutilserrorsCompileError)compilerflagfnames      r   has_flagr      s     
_%@7S	c%j\4&A  
 ,, 	 
	 
s.   A9AA9A6+A95A66A99
Bc                    [         (       a  g/ SQnU H+  n[        U [        R                  U5      5      (       d  M)  Us  $    Sn[	        U5      e)zT
Return the max supported C++ std level (17, 14, or 11). Returns latest on Windows.
latest)r\   rR   rQ   z9Unsupported compiler -- at least C++11 support is needed!)r;   r   rc   rd   RuntimeError)r   levelsrk   msgs       r   auto_cpp_levelr      sI     sFHhooe455L  FC
s
r    c                  0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r   i  z
Customized build_ext that allows an auto-search for the highest supported
C++ level for Pybind11Extension. This is only needed for the auto-search
for now, and is completely optional otherwise.
c                   > U R                    HB  n[        US5      (       d  M  UR                  S:X  d  M(  [        U R                  5      Ul        MD     [        TU ]  5         g)zF
Build extensions, injecting C++ std for Pybind11Extension if needed.
r2   r   N)
extensionshasattrr2   r   r   r&   r4   build_extensions)r   extrI   s     r   r   build_ext.build_extensions  sH    
 ??CsL))cnn.A,T]]; # 	 "r     )rr   rs   )rt   ru   rv   rw   rx   r   r{   r|   r}   s   @r   r   r     s    	# 	#r    r   c                   / nUGcX  U  GHO  n[         R                  R                  U5      u  pE[         R                  R                  [         R                  R	                  US5      5      (       ae  [         R                  R                  U5      u  pE[         R                  R                  [         R                  R	                  US5      5      (       a  Me  [         R                  R                  [         R                  R                  X45      5      u  peUR                  [         R                  R                  S5      nUR                  [        Xs/5      5        GMR     U$ U  H  nUR                  5        H  u  pUR                  U5      (       d  M  [         R                  R                  [         R                  R                  X45      5      u  peUR                  [         R                  R                  S5      nU(       a  US-   U-   nUR                  [        Xs/5      5          M     SU SU S3n	[        U	5      e   U$ )a  
Generate Pybind11Extensions from source files directly located in a Python
source tree.

``package_dir`` behaves as in ``setuptools.setup``.  If unset, the Python
package root parent is determined as the first parent directory that does
not contain an ``__init__.py`` file.
z__init__.pyr[   zpath zC is not a child of any of the directories listed in 'package_dir' ())r<   pathr@   existsri   splitextrelpathreplacesepr9   r   itemsr-   
ValueError)
pathspackage_dirextsr   parent_relnamequalified_nameprefixr   s
             r   intree_extensionsr   "  s    DDd+IF''..fm!DEEGGMM&1	 ''..fm!DEE))"''//$*GHJG$__RWW[[#>NKK).&AB  )//1NFv&&WW--bggood.KL
!(c!B%+c\N%BN-nfEF 2 v %%0M4  S/!   Kr    c                    [         R                  " U 5      R                  [         R                  " U5      R                  :  $ )z
This will recompile only if the source file changes. It does not check
header files, so a more advanced function or Ccache is better if you have
editable header files in your package.
)r<   statst_mtime)objsrcs     r   naive_recompiler   L  s+     773<  2773<#8#888r    c                    g)z]
This is the safest but slowest choice (and is the default) - will always
recompile sources.
Tr   )obgr   s     r   no_recompiler   U  s    
 r    SParallelCompile)boundc                  l    \ rS rSrSrSrSSS\4         SS jjrSS jrSS jr	SS	 jr
SS
 jrSrg)r   it  a  
Make a parallel compile function. Inspired by
numpy.distutils.ccompiler.CCompiler.compile and cppimport.

This takes several arguments that allow you to customize the compile
function created:

envvar:
    Set an environment variable to control the compilation threads, like
    NPY_NUM_BUILD_JOBS
default:
    0 will automatically multithread, or 1 will only multithread if the
    envvar is set.
max:
    The limit for automatic multithreading if non-zero
needs_recompile:
    A function of (obj, src) that returns True when recompile is needed.  No
    effect in isolated mode; use ccache instead, see
    https://github.com/matplotlib/matplotlib/issues/1507/

To use::

    ParallelCompile("NPY_NUM_BUILD_JOBS").install()

or::

    with ParallelCompile("NPY_NUM_BUILD_JOBS"):
        setup(...)

By default, this assumes all files need to be recompiled. A smarter
function can be provided via needs_recompile.  If the output has not yet
been generated, the compile will always run, and this function is not
called.
)envvardefaultmax_oldneeds_recompileNr   c                B    Xl         X l        X0l        X@l        / U l        g rU   )r   r   r   r   r   )r   r   r   r   r   s        r   r5   ParallelCompile.__init__  s      .+-	r    c                P   ^         S                   SU 4S jjjnU$ )zK
Builds a function object usable as distutils.ccompiler.CCompiler.compile.
c	                  >^ ^^^^ T R                  X#XAUT5      u  p9mmmT R                  TXV5      mTR                  n
TR                  b=  [	        [
        R                  R                  TR                  TR                  5      5      n
SUUU UUU4S jjn SS KnSSK	J
n  U
S:X  a@   WR                  5       n
TR                  (       a  TR                  U
:  a  TR                  OU
n
U
S:  a+  W" U
5       nUR                  X5       H  nM     S S S 5        U	$ U	 H  nU" U5        M     U	$ ! [         a    Sn
 Nf = f! [         a    Sn
 Ndf = f! , (       d  f       U	$ = f)Nc                   >  TU    u  p[        R                  R                  U 5      (       a  TR	                  X5      (       a  TR                  XUTTT5        g g ! [          a     g f = frU   )KeyErrorr<   r   r   r   _compile)	r   r   r   buildcc_argsr   r   pp_optsr   s	      r   _single_compileKParallelCompile.function.<locals>.compile_function.<locals>._single_compile  sh    $SzHC ww~~c**d.B.B3.L.L%%cWngV /M   s   A 
A('A(r   )
ThreadPool   )r   r   rr   rs   )_setup_compile_get_cc_argsr   r   rV   r<   r=   r>   multiprocessing.synchronizemultiprocessing.poolr   ImportError	cpu_countr   NotImplementedErrorimap_unordered)r   sources
output_dirmacrosr8   debugextra_preargsr   dependsobjectsthreadsr   multiprocessingr   poolr   obr   r   r   r   s   `      `         @@@r   compile_function2ParallelCompile.function.<locals>.compile_function  sS    ?G>U>UL7N?;F^We ++GUJG llG {{&bjjnnT[[$,,GHW W 3; !| -779G*.((txx'7IdhhwG {(D!00J K ) N "B#B' " N%   +  G  )( Ns0   
D* '?D< 4E*D98D9<E
E
E)NNNFNNN)r   zdistutils.ccompiler.CCompilerr   rq   r   
str | Noner   z0list[tuple[str] | tuple[str, str | None]] | Noner8   list[str] | Noner   boolr   r   r   r   r   r   rr   r   r   )r   r   s   ` r   functionParallelCompile.function  s     &*GK-1.2/3(,8	38	8	 #8	 E	8	
 +8	 8	 ,8	 -8	 &8	 8	 8	t  r    c                `    U R                  5       [        R                  R                  l        U $ )zK
Installs the compile function into distutils.ccompiler.CCompiler.compile.
)r   r   	ccompiler	CCompilerr   rL   s    r   installParallelCompile.install  s#     15	%%-r    c                    U R                   R                  [        R                  R                  R
                  5        U R                  5       $ rU   )r   r9   r   r   r   r   r   rL   s    r   	__enter__ParallelCompile.__enter__  s2    		,,66>>?||~r    c                r    U R                   R                  5       [        R                  R                  l        g rU   )r   r3   r   r   r   r   )r   rB   s     r   __exit__ParallelCompile.__exit__  s     04			%%-r    )r   r   r   r   r   )
r   r   r   rV   r   rV   r   zCallable[[str, str], bool]rr   rs   )rr   CCompilerMethod)r   r   rr   r   )rB   r   rr   rs   )rt   ru   rv   rw   rx   	__slots__r   r5   r   r   r   r   r{   r   r    r   r   r   t  si    !F HI "6B.. . 	.
 4. 
.? B@r    )rr   zIterator[str])r   r   r   r`   rr   r   )r   r   rr   z	str | intrU   )r   zIterable[str]r   zdict[str, str] | Nonerr   zlist[Pybind11Extension])r   r`   r   r`   rr   r   )r   r`   r   r`   rr   r   )>rx   
__future__r   
contextlibr<   rg   r?   r   sys	sysconfigr   	threadingra   	functoolsr   pathlibr   typingr   r   r   r	   r
   r   r   r   r   
setuptoolsr   
_Extensionsetuptools.command.build_extr   
_build_extr   distutils.command.build_extdistutils.extensiondistutils.ccompilerr   distutils.errorsr-   get_platformr;   re   rc   r   Lockr   contextmanagerr   r   cpp_flag_cacher   r   r   r   r   r   r   r`   r   r   r   r   r    r   <module>r     s   L #  	    
      
 
 
<2D  	llg&R7):P:P:R+R)<Lt#
 t#p ! " " (   $#
 #( @D'''<''T9 C()%%S	eE#Jc8C=.@(AABCDcccc
 	I*@@ @@a	  < <;	<s   F F/.F/