
     hPD                    :   d Z 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	Z	ddl
Z
ddlZddlZddlmZ ddlmZ ddlmZmZmZmZmZmZmZmZmZ 	 ddlmZ ddlmZ  ddl$Z%ddl&Z%ej
                  jO                  d	      xr d
 e	jP                         vZ)ej
                  jO                  d      Z*e)rdndZ+ G d de      Z, ejZ                         Z.ej^                  dd       Z0ddZ1dZ2edd       Z3 G d de       Z	 d	 	 	 	 	 d dZ4d!dZ5d"dZ6 edd      Z7ee%jp                  jr                  ee:   ee:   eeeee:   ee:ee:   f   f         eee:      e;eee:      eee:      eee:      g	ee:   f   Z< G d d      Z=y# e!$ r ddl"mZ  ddl#mZ Y 9w xY w)#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                  l     e Zd ZdZddZddZd fdZed	d       Zej                  d
d       Z xZ
S )Pybind11Extensiona   
    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                "    || j                   d d y Nr   )extra_compile_argsselfflagss     r/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/pybind11/setup_helpers.py_add_cflagszPybind11Extension._add_cflagst   s    &+#    c                "    || j                   d d y r   )extra_link_argsr   s     r   _add_ldflagszPybind11Extension._add_ldflagsw   s    #(Ra r   c                   d| _         |j                  dd      }d|vrd|d<   |j                  dd      }t        |   |i | |r>	 dd l}|j                         }|| j                  vr| j                  j                  |       || _	        g }t        r|ddgz  }n|d	gz  }t        j                  j                  d
d      }t        j                  j                  dd      }	t        j                  |      t        j                  |	      z   }
t!        d |
D              s|dgz  }| j#                  |       y # t        $ r Y w xY w)Nr   cxx_stdlanguagezc++include_pybind11Tz/EHscz/bigobjz-fvisibility=hiddenCFLAGS CPPFLAGSc              3  >   K   | ]  }|j                  d         yw)z-gN)
startswith).0opts     r   	<genexpr>z-Pybind11Extension.__init__.<locals>.<genexpr>   s     Cs~~d+Cs   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%   r2   pyinccflags
env_cflagsenv_cppflagsc_cpp_flags	__class__s              r   r1   zPybind11Extension.__init__z   s;   **Y*V#!&F:!::&8$?$)&)  ,,. 1 11%%,,U3 w	**F,--F"5J::>>*b9L++j1EKK4MMKC{CC5'!  ' s   =D7 7	EEc                    | j                   S )aL  
        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.
        )r.   r   s    r   r#   zPybind11Extension.cxx_std   s     r   c                   | j                   rt        j                  dd       t        r|dk(  rd}|| _         |sy t        j                  |      g}g }t        rdt        j                  vrut        d t        j                         d   j                  d	      d d D              }|d
k  rdnd}d	j                  d t        ||      D              }d| }||gz  }||gz  }| j                  |       | j!                  |       y )Nz8You cannot safely change the cxx_level after setting it!   )
stacklevel      MACOSX_DEPLOYMENT_TARGETc              3  2   K   | ]  }t        |        y wN)intr+   xs     r   r-   z,Pybind11Extension.cxx_std.<locals>.<genexpr>   s     !WQ#a&!W   r   .   )
   	   )rV   rL   c              3  2   K   | ]  }t        |        y wrO   )strrQ   s     r   r-   z,Pybind11Extension.cxx_std.<locals>.<genexpr>   s     #VqCF#VrS   z-mmacosx-version-min=)r.   warningswarnr7   STD_TMPLformatMACOSr8   r9   tupleplatformmac_verr<   joinminr   r!   )r   levelrA   ldflagscurrent_macosdesired_macosmacos_string
macosx_mins           r   r#   zPybind11Extension.cxx_std   s    ??MMJWX 5B;E//%()/rzzA "!W(2B2B2DQ2G2M2Mc2RSUTU2V!WWM',rzGxM88#VC}4U#VVL0?Jzl"F
|#G '"r   )r   	list[str]returnNone)r>   r   r?   r   rk   rl   )rk   rP   )rd   rP   rk   rl   )__name__
__module____qualname____doc__r   r!   r1   propertyr#   setter__classcell__rE   s   @r   r   r   Y   sD    4,)$!L   ^^!# !#r   r   c               #  z  K   t         5  t        j                         } 	 t        j                         }t        j
                  |       | t        j
                  |        t        j                  |       	 ddd       y# t        j
                  |        t        j                         w xY w# 1 sw Y   yxY ww)z:Prepare and enter a temporary directory, cleanup when doneN)tmp_chdir_lockr8   getcwdtempfilemkdtempchdirshutilrmtree)olddirtmpdirs     r   	tmp_chdirr      s     
 
 "	"%%'FHHVLHHVMM&!" " HHVMM&!" "s3   B;B/-B *B/7	B; ,B,,B//B84B;c                   t               5  t        d      }|j                  dd       	 | j                  t	        |      g|g       	 ddd       y# t
        j                  j                  $ r Y ddd       yw xY w# 1 sw Y   yxY w)	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compilerY   	distutilserrorsCompileError)compilerflagfnames      r   has_flagr      s     
 	_%@7S	c%j\4&A 	 	 ,, 		 			 	s.   A>A	A>A;0A>:A;;A>>Bc                    t         ryg d}|D ]%  }t        | t        j                  |            s#|c S  d}t	        |      )z\
    Return the max supported C++ std level (17, 14, or 11). Returns latest on Windows.
    latest)rU   rL   rK   z9Unsupported compiler -- at least C++11 support is needed!)r7   r   r\   r]   RuntimeError)r   levelsrd   msgs       r   auto_cpp_levelr      sI     F Hhooe45L FC
s
r   c                  $     e Zd ZdZd fdZ xZS )r   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                    | j                   D ]9  }t        |d      s|j                  dk(  s t        | j                        |_        ; t        |           y)zV
        Build extensions, injecting C++ std for Pybind11Extension if needed.
        r.   r   N)
extensionshasattrr.   r   r   r#   r0   build_extensions)r   extrE   s     r   r   zbuild_ext.build_extensions  sJ    
 ?? 	<CsL)cnn.A,T]];	< 	 "r   )rk   rl   )rm   rn   ro   rp   r   rs   rt   s   @r   r   r     s    	# 	#r   r   c                Z   g }|P| D ]H  }t         j                  j                  |      \  }}t         j                  j                  t         j                  j	                  |d            r`t         j                  j                  |      \  }}t         j                  j                  t         j                  j	                  |d            r`t         j                  j                  t         j                  j                  ||            \  }}|j                  t         j                  j                  d      }|j                  t        ||g             K |S | D ]  }|j                         D ]  \  }}|j                  |      st         j                  j                  t         j                  j                  ||            \  }}|j                  t         j                  j                  d      }|r|dz   |z   }|j                  t        ||g               d| d| d}	t        |	       |S )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__.pyrT   zpath zC is not a child of any of the directories listed in 'package_dir' ())r8   pathr<   existsrb   splitextrelpathreplacesepr5   r   itemsr*   
ValueError)
pathspackage_dirextsr   parent_relnamequalified_nameprefixr   s
             r   intree_extensionsr   "  s    D 	CDd+IFA''..fm!DEGGMM&1	 ''..fm!DE))"''//$*GHJGQ$__RWW[[#>NKK).4&AB	C  ")//1 	"NFFv&WW--bggoodF.KL
!(c!B%+c\N%BN-ntfEF	" v %%0M4  S/!"  Kr   c                    t        j                  |       j                  t        j                  |      j                  k  S )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.
    )r8   statst_mtime)objsrcs     r   naive_recompiler   L  s+     773<  2773<#8#888r   c                     y)zi
    This is the safest but slowest choice (and is the default) - will always
    recompile sources.
    T )obgr   s     r   no_recompiler   U  s    
 r   SParallelCompile)boundc                  X    e Zd ZdZdZdddef	 	 	 	 	 	 	 	 	 d
dZddZddZddZ	dd	Z
y)r   ae  
    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                J    || _         || _        || _        || _        g | _        y rO   )r   r   r   r   r   )r   r   r   r   r   s        r   r1   zParallelCompile.__init__  s(     .+-	r   c                J     	 	 	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd}|S )z[
        Builds a function object usable as distutils.ccompiler.CCompiler.compile.
        c	                     j                  |||||      \  }}	 j                  ||      j                  }
j                  =t	        t
        j                  j                  j                  j                              }
d fd}	 dd l}ddl	m
} |
dk(  r:	 j                         }
j                  rj                  |
k  rj                  n|
}
|
dkD  r+ |
      5 }|j                  ||	      D ]  } 	 d d d        |	S |	D ]
  } ||        |	S # t        $ r d}
Y w xY w# t        $ r d}
Y _w xY w# 1 sw Y   |	S xY w)Nc                    	 |    \  }}t        j                  j                  |       rj	                  | |      rj                  | ||       y y # t         $ r Y y w xY wrO   )KeyErrorr8   r   r   r   _compile)	r   r   r   buildcc_argsr   r   pp_optsr   s	      r   _single_compilezKParallelCompile.function.<locals>.compile_function.<locals>._single_compile  sh    $SzHC ww~~c*d.B.B3.L%%c3WngV /M   s   A 	A A r   )
ThreadPool   )r   r   rk   rl   )_setup_compile_get_cc_argsr   r   rP   r8   r9   r:   multiprocessing.synchronizemultiprocessing.poolr   ImportError	cpu_countr   NotImplementedErrorimap_unordered)r   sources
output_dirmacrosr4   debugextra_preargsr   dependsobjectsthreadsr   multiprocessingr   poolr   obr   r   r   r   s   `      `         @@@r   compile_functionz2ParallelCompile.function.<locals>.compile_function  sh    ?G>U>UFL'7N?;FG^We ++GUMJG llG {{&bjjnnT[[$,,GHW W 3; !| -779G*.((txx'7IdhhwG {( D!00'J  N " (B#B'( N%   +  G  Ns0   
D! '9D2 -E!D/.D/2E ?E E)NNNFNNN)r   zdistutils.ccompiler.CCompilerr   rj   r   
str | Noner   z0list[tuple[str] | tuple[str, str | None]] | Noner4   list[str] | Noner   boolr   r   r   r   r   r   rk   r   r   )r   r   s   ` r   functionzParallelCompile.function  s     &*GK-1.2/3(,8	38	8	 #8	 E	8	
 +8	 8	 ,8	 -8	 &8	 8	t  r   c                `    | j                         t        j                  j                  _        | S )z[
        Installs the compile function into distutils.ccompiler.CCompiler.compile.
        )r   r   	ccompiler	CCompilerr   rG   s    r   installzParallelCompile.install  s#     15	%%-r   c                    | j                   j                  t        j                  j                  j
                         | j                         S rO   )r   r5   r   r   r   r   r   rG   s    r   	__enter__zParallelCompile.__enter__  s2    		,,66>>?||~r   c                r    | j                   j                         t        j                  j                  _        y rO   )r   r/   r   r   r   r   )r   r>   s     r   __exit__zParallelCompile.__exit__  s     04			%%-r   )
r   r   r   rP   r   rP   r   zCallable[[str, str], bool]rk   rl   )rk   CCompilerMethod)r   r   rk   r   )r>   r   rk   rl   )rm   rn   ro   rp   	__slots__r   r1   r   r   r   r   r   r   r   r   r   t  si    !F HI "6B.. . 	.
 4. 
.? B@r   )rk   zIterator[str])r   r   r   rY   rk   r   )r   r   rk   z	str | intrO   )r   zIterable[str]r   zdict[str, str] | Nonerk   zlist[Pybind11Extension])r   rY   r   rY   rk   r   )r   rY   r   rY   rk   r   )>rp   
__future__r   
contextlibr8   r`   r;   r{   sys	sysconfigrx   	threadingrZ   	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_platformr7   r^   r\   r   Lockrv   contextmanagerr   r   cpp_flag_cacher   r   r   r   r   r   r   rY   r   r   r   r   r   r   <module>r      s  L #  	    
      
 
 
<2D  	llg&R7:P):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