
    YHh!H                    @   d dl m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 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ZmZ erd dlm Z! n	 d dl"m Z!  e#d        ed       d dlm%Z& d Z'dZ(dZ)dZ*ejV                  dk(  rdZ)nejX                  dk7  r	 d dl-Z- e.e-d      xZ)Z(d Z/ G d de!      Z e)sejX                  dk(  r	 	 	 	 	 	 	 	 	 	 d	 	 	 d dZ0ydZ*	 	 	 	 	 	 	 	 	 	 d	 	 	 d dZ0y# e$$ r	 d dlm Z! Y w xY w# e$$ r Y _w xY w)!    )annotationsN)IteratorEXTENSION_SUFFIXES)cache_from_source)Path)TYPE_CHECKING)Distribution)	BaseError)	ExtensionLibrary)log)new_compiler)customize_compilerget_config_var)	build_extzCython.Compiler.MainLDSHARED)_config_varsc                f   t         j                  dk(  ret        j                         }	 dt        d<   dt        d<   dt        d<   t	        |        t        j
                          t        j                  |       y t	        |        y # t        j
                          t        j                  |       w xY w)Ndarwinz0gcc -Wl,-x -dynamiclib -undefined dynamic_lookupr   z -dynamiclibCCSHAREDz.dylibSO)sysplatform_CONFIG_VARScopyr   clearupdate)compilertmps     U/var/www/html/planif/env/lib/python3.12/site-packages/setuptools/command/build_ext.py_customize_compiler_for_shlibr"   *   s    
||x !
	% C $ (6L$!)Lx( $8$  $s   &B +B0Fsharedr   TntRTLD_NOWc                 <    t         D ]  } d| v r| c S | dk(  s| c S  y)z;Return the file extension for an abi3-compliant Extension()z.abi3z.pydNr   )suffixs    r!   get_abi3_suffixr(   N   s0    $ fMvM	
     c                      e Zd ZU ded<   dZdZd ZddZddZddZ	ddZ
dd	Zd
 ZddZd Zd ZddZd ZddZd dZddZd!dZd Zd Zd"ddZd"d#dZd$dZy)%r   r
   distributionFc                    | j                   dc}| _         t        j                  |        || _         |r| j                          yy)z;Build extensions in build directory, then copy if --inplaceFN)inplace
_build_extruncopy_extensions_to_source)selfold_inplaces     r!   r/   zbuild_ext.run]   s;    $(LL%!T\t"**, r)   c                   | j                  |j                        }| j                  |      }|j                  d      }dj	                  |d d       }|j                  |      }t        j                  j	                  |t        j                  j                  |            }t        j                  j	                  | j                  |      }	||	fS )N.)
get_ext_fullnamenameget_ext_filenamesplitjoinget_package_dirospathbasename	build_lib)
r1   build_pyextfullnamefilenamemodpathpackagepackage_dirinplace_fileregular_files
             r!   _get_inplace_equivalentz!build_ext._get_inplace_equivalente   s    ((2((2..%((73B<(..w7ww||K1A1A(1KLww||DNNH=l++r)   c                j   | j                  d      }| j                  D ]  }| j                  ||      \  }}t        j                  j                  |      s|j                  s| j                  ||| j                         |j                  sn| j                  ||      }| j                  ||d        y )Nr@   )levelT)compile)get_finalized_command
extensionsrI   r<   r=   existsoptional	copy_fileverbose_needs_stub_get_equivalent_stub_write_stub_file)r1   r@   rA   rG   rH   inplace_stubs         r!   r0   z#build_ext.copy_extensions_to_sourceo   s    --j9?? 	GC)-)E)EhPS)T&L,
 ww~~l+3<<|\N#88lK%%lC%F	Gr)   c                    t         j                  j                  |      }|j                  j	                  d      \  }}}t         j                  j                  ||       dS Nr4   .py)r<   r=   dirnamer7   
rpartitionr:   )r1   rA   output_filedir__r7   s         r!   rT   zbuild_ext._get_equivalent_stub   sK    ww{+XX((-
1d'',,tT*+3//r)   c              #    K   | j                   sy | j                  d      }| j                  d      j                  xs d}| j                  D ]n  }| j	                  ||      \  }}||f |j
                  s+| j                  ||      }| j                  ||      }t        ||      }t        ||      }	|	|f p y w)Nr@   install_lib )optimization)r-   rM   optimizerN   rI   rS   rT   _compiled_file_name)
r1   r@   optrA   rG   rH   rV   regular_stubinplace_cacheoutput_caches
             r!   _get_output_mappingzbuild_ext._get_output_mapping   s     ||--j9((7@@FB?? 	4C)-)E)EhPS)T&L,..  $88lK#88lK 3Ls S2<cR#]33!	4s   A4B>7AB>c                   t        j                  d      }|r/t        j                  j                  |j	                  d       |z   }n>t        j                  | |      }t        d      }t        |t              st        d      |}|| j                  v r| j                  |   }t               }|j                  r|r|d t        |        |z   }t        |t              rBt         j                  j!                  |      \  }}| j"                  j%                  |t&              S t(        rQ|j*                  rEt         j                  j	                  |      \  }}t         j                  j                  |d|z         S |S )NSETUPTOOLS_EXT_SUFFIXr4   
EXT_SUFFIXzwConfiguration variable EXT_SUFFIX not found for this platform and environment variable SETUPTOOLS_EXT_SUFFIX is missingzdl-)r<   getenvr=   r:   r9   r.   r8   r   
isinstancestrOSErrorext_mapr(   py_limited_apilenr   splitextshlib_compilerlibrary_filenamelibtype	use_stubs_links_to_dynamic)	r1   rB   so_extrC   
ext_suffixrA   abi3_suffixfnds	            r!   r8   zbuild_ext.get_ext_filename   s2   23ww||X^^C%89FBH!224BH'5Jj#.P   Ft||#,,x(C)+K!!k#Ns6{l3kA#w'''**84C**;;BHHs44h/2ww||Aurz22r)   c                f    t        j                  |        d | _        g | _        i | _        d| _        y )NF)r.   initialize_optionsru   shlibsrq   editable_moder1   s    r!   r   zbuild_ext.initialize_options   s.    %%d+""r)   c                   t        j                  |        | j                  xs g | _        | j                  | j                         | j                  D cg c]  }t	        |t
              s| c}| _        | j                  r| j                          | j                  D ]"  }| j                  |j                        |_
        $ | j                  D ]j  }|j                  }|| j                  |<   || j                  |j                  d      d   <   | j                  xr | j                  |      xs d}|xr t        xr t	        |t
               }||_        ||_        | j#                  |      x}|_        t&        j(                  j+                  t&        j(                  j-                  | j.                  |            }|r)||j0                  vr|j0                  j3                  |       |st        s$t&        j4                  |j6                  vsB|j6                  j3                  t&        j4                         m | j8                  rd| _        y y c c}w )Nr4   r5   FT)r.   finalize_optionsrN   check_extensions_listrn   r   r   setup_shlib_compilerr6   r7   
_full_namerq   r9   links_to_dynamicrx   ry   rS   r8   
_file_namer<   r=   rZ   r:   r?   library_dirsappendcurdirruntime_library_dirsr   r-   )r1   rA   rB   ltdnsrC   libdirs          r!   r   zbuild_ext.finalize_options   s   ##D)///R""4??3&*ooRsC9QsR;;%%'?? 	=C!22388<CN	=?? 	;C~~H%(DLL" 58DLL,R01++<$"7"7"<ECCC:c7+C'CB$'C! CO(,(=(=h(GGHs~WW__RWW\\$..(%KLFvS%5%55  ''/yRYYc6N6N%N((//		:#	;& DL 1 Ss   I*Ic                   t        | j                  | j                  | j                        x}| _        t        |       | j                  |j                  | j                         | j                  &| j                  D ]  \  }}|j                  ||        | j                  "| j                  D ]  }|j                  |        | j                  |j                  | j                         | j                  |j                  | j                         | j                   |j#                  | j                          | j$                  |j'                  | j$                         t(        j+                  |      |_        y )N)r   dry_runforce)r   r   r   r   ru   r"   include_dirsset_include_dirsdefinedefine_macroundefundefine_macro	librariesset_librariesr   set_library_dirsrpathset_runtime_library_dirslink_objectsset_link_objectslink_shared_object__get__)r1   r   r7   valuemacros        r!   r   zbuild_ext.setup_shlib_compiler   s<   )5]]DLL

*
 	
4& 	&h/(%%d&7&78;;"#{{ 3e%%dE23::! /''./>>%""4>>2(%%d&7&78::!--djj9(%%d&7&78 '9&@&@&J#r)   c                f    t        |t              r|j                  S t        j                  | |      S N)rn   r   export_symbolsr.   get_export_symbols)r1   rA   s     r!   r   zbuild_ext.get_export_symbols   s+    c7#%%%,,T377r)   c                D   |j                          | j                  }	 t        |t              r| j                  | _        t        j                  | |       |j                  r-| j                  d      j                  }| j                  ||       || _        y # || _        w xY w)Nr@   )_convert_pyx_sources_to_langr   rn   r   ru   r.   build_extensionrS   rM   r?   
write_stub)r1   rA   	_compilerr?   s       r!   r   zbuild_ext.build_extension   s}    ((*MM		&#w' $ 3 3&&tS1 66zBLL		3/%DMIDMs   A0B 	Bc                   t         j                  | j                  D cg c]  }|j                   c}      dj	                  |j                  j                  d      dd dgz         t        fd|j                  D              S c c}w )z?Return true if 'ext' links to a dynamic lib in the same packager4   Nr5   ra   c              3  ,   K   | ]  }|z   v   y wr    ).0libnamelibnamespkgs     r!   	<genexpr>z-build_ext.links_to_dynamic.<locals>.<genexpr>  s     J3=H,Js   )dictfromkeysr   r   r:   r9   anyr   )r1   rA   libr   r   s      @@r!   r   zbuild_ext.links_to_dynamic  sl    
 ==DKK!HS#..!HIhhs~~++C0"5<=JCMMJJJ "Is   B
c                P    g t        j                  |       | j                         S r   )r.   get_source_files_get_internal_dependsr   s    r!   r   zbuild_ext.get_source_files  s&    R,,T2RT5O5O5QRRr)   c              #    K   t        | j                  j                  xs t        j                        j                         }d | j                  D        }dd}|D ]y  }t        |      }|j                         r
 ||d       (d|j                  v r
 ||d       @	 ||z  j                  d      }	 |j                  |       |j                          { y
# t        $ r  ||d       Y w xY w# t        $ r  ||d	       Y w xY ww)zAYield ``ext.depends`` that are contained by the project directoryc              3  B   K   | ]  }|j                   D ]  }|   y wr   )depends)r   rA   deps      r!   r   z2build_ext._get_internal_depends.<locals>.<genexpr>  s      I3S[[Ic3I3Is   c                2    t        j                  d| |       y )NzJdependency %s won't be automatically included in the manifest: the path %s)r   info)	orig_pathreasons     r!   skipz-build_ext._get_internal_depends.<locals>.skip  s    HH8	r)   zmust be relativez..zcan't have `..` segmentsT)strictzdoesn't existzmust be inside the project rootN)r   ro   r   ro   returnNone)r   r+   src_rootr<   r   resolverN   is_absolutepartsrp   relative_to
ValueErroras_posix)r1   project_rootr   r   r   r=   resolveds          r!   r   zbuild_ext._get_internal_depends  s    D--66C"))DLLNI$//I	  	"C9D!S,-tzz!S45(4/888E
$$\2
 --/!/	"  S/*  S;<sH   BDC2C0DC-*D,C--D0DDDDc                    | j                   r't        | j                         j                               S t	        t        j                  |       | j                         z         S r   )r-   listget_output_mappingkeyssortedr.   get_outputs_build_ext__get_stubs_outputsr   s    r!   r   zbuild_ext.get_outputs>  sJ    <<//166899j,,T2T5M5M5OOPPr)   c                P    | j                         }t        t        |d             S )z1See :class:`setuptools.commands.build.SubCommand`c                    | d   S )Nr   r   )xs    r!   <lambda>z.build_ext.get_output_mapping.<locals>.<lambda>F  s
    !A$ r)   )key)ri   r   r   )r1   mappings     r!   r   zbuild_ext.get_output_mappingC  s"    **,F7788r)   c                      fd j                   D        }t        j                  | j                               }t	        d |D              S )Nc              3     K   | ]S  }|j                   rEt        j                  j                  j                  g|j
                  j                  d         U yw)r4   N)rS   r<   r=   r:   r?   r   r9   )r   rA   r1   s     r!   r   z0build_ext.__get_stubs_outputs.<locals>.<genexpr>J  sE      
 GGLLD#..*>*>s*CD
s   AAc              3  ,   K   | ]  \  }}||z     y wr   r   )r   basefnexts      r!   r   z0build_ext.__get_stubs_outputs.<locals>.<genexpr>Q  s     :[T5D5L:s   )rN   	itertoolsproduct!_build_ext__get_output_extensionsr   )r1   ns_ext_basespairss   `  r!   __get_stubs_outputszbuild_ext.__get_stubs_outputsH  sD    

 !!,0L0L0NO:E:::r)   c              #  \   K   d d | j                  d      j                  rd y y w)NrY   z.pycr@   z.pyo)rM   rc   r   s    r!   __get_output_extensionsz!build_ext.__get_output_extensionsS  s.     %%j1::L ;s   *,c                    t        j                  j                  |g|j                  j	                  d       dz   }| j                  |||       y rX   )r<   r=   r:   r   r9   rU   )r1   
output_dirrA   rL   	stub_files        r!   r   zbuild_ext.write_stubY  s?    GGLLHcnn.B.B3.GH5P	ig6r)   c                   t        j                  d|j                  |       |r-t        j                  j                  |      rt        |dz         | j                  st        |dd      5 }t        j                  dt        j                  j                  |j                        d      j                         j                  ddt         z        }|j!                  |       d d d        |r| j#                  |       y y # 1 sw Y   xY w)	Nz writing stub loader for %s to %sz already exists! Please delete.wzutf-8)encodinga7  
                    def __bootstrap__():
                       global __bootstrap__, __file__, __loader__
                       import sys, os, importlib.resources as irs, importlib.util
                    #rtld   import dl
                       with irs.files(__name__).joinpath(
                         a  ) as __file__:
                          del __bootstrap__
                          if '__loader__' in globals():
                              del __loader__
                    #rtld      old_flags = sys.getdlopenflags()
                          old_dir = os.getcwd()
                          try:
                            os.chdir(os.path.dirname(__file__))
                    #rtld        sys.setdlopenflags(dl.RTLD_NOW)
                            spec = importlib.util.spec_from_file_location(
                                       __name__, __file__)
                            mod = importlib.util.module_from_spec(spec)
                            spec.loader.exec_module(mod)
                          finally:
                    #rtld        sys.setdlopenflags(old_flags)
                            os.chdir(old_dir)
                    __bootstrap__()
                    z#rtld)r   r   r   r<   r=   rO   r   r   opentextwrapdedentr>   r   lstripreplace	have_rtldwrite_compile_and_remove_stub)r1   r   rA   rL   fcontents         r!   rU   zbuild_ext._write_stub_file]  s    3S^^YOrww~~i0I(IIJJ||iw7 !1OO ) ''**3>>:= >% 0 VXWWgY&?@5 8  ;!< )))4 =! !s   +A8D  D	c                0   ddl m}  ||gdd| j                         | j                  d      j                  }|dkD  r ||g|d| j                         t
        j                  j                  |      r#| j                  st        j                  |       y y y )Nr   )byte_compileT)rc   r   r   r`   )	distutils.utilr   r   rM   rc   r<   r=   rO   unlink)r1   r   r   rc   s       r!   r   z"build_ext._compile_and_remove_stub  s|    /i[1D$,,O--m<EEa<!	 77>>)$T\\IIi  .:$r)   N)rA   r   r   ztuple[str, str])r   r   )rA   r   r\   ro   r   ro   )r   zIterator[tuple[str, str]])rB   ro   r   ro   )r   z	list[str])r   zIterator[str])r   zdict[str, str])F)r   ro   rA   r   )r   ro   )__name__
__module____qualname____annotations__r   r-   r/   rI   r0   rT   ri   r8   r   r   r   r   r   r   r   r   r   r   r   r   r   rU   r   r   r)   r!   r   r   X   s    MG-,G"0
426# >K68
&KS$"LQ
9
	;7$5L!r)   r   c                R    | j                  | j                  |||||||||	|
||       y r   )linkSHARED_LIBRARY)r1   objectsoutput_libnamer   r   r   r   r   debugextra_preargsextra_postargs
build_temptarget_langs                r!   r   r     s=     			 	
r)   staticc                   |J t         j                  j                  |      \  }}t         j                  j                  |      \  }}| j	                  d      j                  d      r|dd  }| j                  |||||       y )Nr   r      )r<   r=   r9   rt   rv   
startswithcreate_static_lib)r1   r  r	  r   r   r   r   r   r
  r  r  r  r  rC   r>   _exts                   r!   r   r     s{    * !!!!ww}}^<
H))(3$  %007  |Hw*e[Qr)   )
NNNNNFNNNN)r
  boolr   r   )1
__future__r   r   r<   r   r   collections.abcr   importlib.machineryr   importlib.utilr   rd   pathlibr   typingr	   setuptools.distr
   setuptools.errorsr   setuptools.extensionr   r   	distutilsr   distutils.ccompilerr   distutils.sysconfigr   r   distutils.command.build_extr   r.   Cython.Distutils.build_ext
__import__ImportErrorr   r   r"   r   rx   rw   r   r7   dlhasattrr(   r   r   r)   r!   <module>r(     st   "  	 
  $ 2 C    ( ' 3  , BCHF 	)*
 z  =%* 		
<<8IWW_ 'J 77	I
x!
 x!v	 4 !
 
 

B G !R R 
Rs  HGHT  s$   'D .D DDDD