
    X-PhX                    t   U 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	m
Z
 ddlmZmZmZ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 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) ddl*m+Z+ 	 ddl,Z,n# e-$ r Y nw xY wer3ej.        dk    rddl,m/Z/ n!ddl0m/Z1 ddl2m3Z3 ddl,m/Z4 ee4e1f         Z/de5d<   ej.        dk    r	ddl6m7Z7m8Z8 nddl6m7Z7m8Z8 didZ9djdZ:dkd!Z;dldmd+Z<dnd4Z=dod9Z>dpd;Z?dqd<Z@drdCZAdsdIZBdtdJZCdudMZDdvdQZEdwdSZFd"ddd"dTdxdZZGdd"d[d\d"d"d"dddd"d]dydhZHdS )za  Support for building extensions using mypyc with distutils or setuptools

The main entry point is mypycify, which produces a list of extension
modules to be passed to setup. A trivial setup.py for a mypyc built
project, then, looks like:

    from setuptools import setup
    from mypyc.build import mypycify

    setup(name='test_module',
          ext_modules=mypycify(['foo.py']),
    )

See the mypycify docs for additional arguments.

mypycify can integrate with either distutils or setuptools, but needs
to know at import-time whether it is using distutils or setuputils. We
hackily decide based on whether setuptools has been imported already.
    )annotationsN)Iterable)TYPE_CHECKINGAnyNoReturnUnioncast)BuildSource)CompileError)FileSystemCache)process_options)Options)write_junit_xml)generate_annotated_html)
emitmodule)RUNTIME_C_FILESshared_lib_name)Errors)format_modules)exported_name)CompilerOptions      )	Extension)	TypeAliasr   r   )	ccompiler	sysconfigreturntype[Extension]c                     dt           j        v } t           j        dk     r| sdd l}|j        j        }n"| st          j        d           t          j        }|S )N
setuptoolsr   r   zerror: setuptools not installed)sysmodulesversion_infodistutils.corecorer   exitr"   )use_setuptools	distutilsextension_classs      K/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/mypyc/build.pyget_extensionr-   E   sd     "S[0N '!!.!#.2 	8H6777$.    Nonec                 T   t          t          t          t          f         t          j                              } t
          j        dk    r_| d                             dd          | d<   | d                             dd          | d<   | d                             dd          | d<   dS dS )z6Rewrite a bunch of config vars in pretty dubious ways.darwinLDSHAREDz
-arch i386 LDFLAGSCFLAGSN)r	   dictstrr   get_config_varsr#   platformreplace)varss    r,   setup_mypycify_varsr<   W   s    
 S#X	 9 ; ;<<D
|x  
+33L"EEZy/11,CCYh//bAAX  r.   messager7   r   c                .    t          j        |            d S N)r#   r(   )r=   s    r,   failr@   e   s    HWr.   Foptionsr   messages	list[str]dtfloatseriousboolc                    | j         rA| j        d          d| j        d          }t          |||rd |ini | j         || j                   |r$t	          d                    |                     d S d S )Nr   _   
)	junit_xmlpython_versionr   r9   printjoin)rA   rB   rD   rF   
py_versions        r,   emit_messagesrQ   j   s     	
.q1OOG4J14MOO
 (0T8b	
 	
 	
  #dii!!"""""# #r.   mypy_optionsonly_compile_pathsIterable[str] | Nonecompiler_optionsr   fscacheFileSystemCache | None4tuple[list[BuildSource], list[BuildSource], Options]c                   t          | |          \  }}|t          |          fd|D             }n|}|j        rd |D             }|s|||fS t          j        dd         |_        |j        d         dk    rt          d           |j        st          d           d	|_        d	|_	        |j        |_
        d	|_        |D ]%}d	|j                            |j        i           d
<   &|||fS )zCConstruct mypy BuildSources and Options from file and options lists)rV   Nc                &    g | ]}|j         v |S  path).0s	paths_sets     r,   
<listcomp>z#get_mypy_config.<locals>.<listcomp>   s%    GGGq16Y3F3F3F3F3Fr.   c                T    g | ]%}|j         	|j                             d           #|&S )__init__.py)r]   endswith)r^   srcs     r,   ra   z#get_mypy_config.<locals>.<listcomp>   sG     
 
 
CH
=@X=N=N}=]=]

 
 
r.      r   zPython 2 not supportedz0Disabling strict optional checking not supportedTmypyc)r   setseparater#   r%   rM   r@   strict_optionalshow_tracebackexport_typesincrementalpreserve_astsper_module_options
setdefaultmodule)	rR   rS   rU   rV   all_sourcesrA   mypyc_sourcessourcer`   s	           @r,   get_mypy_configru   z   sF    +<IIIK%*++	GGGGKGGG#  

 
(
 
 
  3k722 !-bqb1Ga A%%%&&&" A?@@@!GG*3G G Q QLP"--fmR@@II+w..r.   full_module_namemodule_namedir_name
group_namec           
        d|                      dt          j                  z  }t          j                            ||          }t          t          j                            t                      d                    5 }|                                }ddd           n# 1 swxY w Y   t          ||	                    |t          |          t          |                                |S )a#  Create a C extension shim with a passthrough PyInit function.

    Arguments:
        full_module_name: the dotted full module name
        module_name: the final component of the module name
        dir_name: the directory to place source code
        group_name: the name of the group
    z%s.c.zmodule_shim.tmplN)modnamelibnamefull_modname)r:   ossepr]   rO   openinclude_dirread
write_fileformatr   r   )rv   rw   rx   ry   cnamecpathfshim_templates           r,   generate_c_extension_shimr      s
    %--c26:::EGLL5))E 
bgll;==*<==	>	> !!! ! ! ! ! ! ! ! ! ! ! ! ! ! ! #J//&'788 	 	
 	
   Ls   =BB"%B"r$   c                
   t          |           dk    r| d         S t          j                    }|                    d                    |                                                      |                                dd         S )zGProduce a probably unique name for a group from a list of module names.rJ   r   ,N   )lenhashlibsha1updaterO   encode	hexdigest)r$   hs     r,   ry   ry      si    
7||qqzAHHSXXg%%''(((;;=="r.   c                     t           j                            t           j                            t           j                            t
                              d          S )z9Find the path of the lib-rt dir that needs to be includedzlib-rt)r   r]   rO   abspathdirname__file__r[   r.   r,   r   r      s4    7<<(A(ABBHMMMr.   sourceslist[BuildSource]groupsemitmodule.Groupsr   'tuple[list[list[tuple[str, str]]], str]c                   t          j                     }	 t          j        | ||||          }n]# t          $ rP}t	          ||j        t          j                     |z
  |j                    t          j        d           Y d}~nd}~ww xY wt          j                     }|j	        r-t	          ||j	        ||z
             t          j        d           |j
        rt          d||z
  dd           t          |          }	t          j        |||	|          \  }
}}t          j                     }t	          ||	                                ||z
             |	j        rt          j        d           |j
        rt          d||z
  dd           |j        rt#          |j        ||
|           |d	                    t'          |
                    fS )
a  Drive the actual core compilation step.

    The groups argument describes how modules are assigned to C
    extension modules. See the comments on the Groups type in
    mypyc.emitmodule for details.

    Returns the C source code and (for debugging) the pretty printed IR.
    )rF   rJ   NzParsed and typechecked in z.3fr_   )rU   errorsr   zCompiled to C in rK   )timer   parse_and_typecheckr   rQ   rB   
use_stdoutr#   r(   r   verboserN   r   compile_modules_to_cnew_messages
num_errorsmypyc_annotation_filer   rO   r   )r   rA   r   rV   rU   t0resultet1r   r$   ctextmappert2s                 r,   
generate_cr      s    
B/W.
 
    gqz49;;+;!,FVXXXX 
B} gv}b2g666 ;9279999:::G__F'<!1&  GUF 
B'6..00"r':::  20"r'0000111$ X =vwPVWWW$))N7334444s   . 
BABBcfilesdeps	build_dirextra_compile_argslist[Extension]c                    t                      t          |          |t                      |g||          g}| D ]}|j                            d          d         }t          |j        |||          }	|j        }
|j        sJ t          j                            |j                  d         dk    r|
dz  }
|                     t                      |
|	g|                     |S )a  Produce the list of extension modules when a shared library is needed.

    This creates one shared library extension module that all of the
    others import and then one shim extension module for each
    module in the build, that simply calls an initialization function
    in the shared library.

    The shared library (which lib_name is the name of) is a python
    extension module that exports the real initialization functions in
    Capsules stored in module attributes.
    )r   include_dirsdependsr   r{   rJ   rc   z	.__init__)r   r   )	r-   r   r   rq   splitr   r]   r   append)r   ry   r   r   r   r   
extensionsrt   rw   	shim_filerv   s              r,   build_using_shared_libr     s   ( 	J''%--31	
 	
 	
J  
 
m))#..r2-fm[)U_``	 "={7==%%a(M99+MOO 9+J\  	
 	
 	
 	
 r.   c                j     t                      | d         j        |t                      g|          gS )zProduce the list of extension modules for a standalone extension.

    This contains just one module, since there is no need for a shared module.
    r   )r   r   r   )r-   rq   r   )r   r   r   s      r,   build_single_moduler   7  s?     	AJ%--1		
 	
 	
 r.   r]   contentsc                (   |                     d          }	 t          | d          5 }|                                }ddd           n# 1 swxY w Y   n# t          $ r d}Y nw xY w||k    rt	          j        t          j                            |           d           t          | d          5 }|                    |           ddd           n# 1 swxY w Y   t	          j	        |           j
        dz   }t	          j        | ||f           dS dS )	zWrite data into a file.

    If the file already exists and has the same contents we
    want to write, skip writing so as to preserve the mtime
    and avoid triggering recompilation.
    utf-8rbNT)exist_okwbrJ   )times)r   r   r   OSErrorr   makedirsr]   r   writestatst_mtimeutime)r]   r   encoded_contentsr   old_contentsg	new_mtimes          r,   r   r   H  s     w//$ 	2)*L	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2   '''
BGOOD))D9999$ 	&GG$%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& GDMM*Q.	
i3444444 ('sE   A AA AA AA A#"A#/CCCri   )bool | list[tuple[list[str], str | None]]use_shared_libc                  	
 |du rd | D             }nt          |t                    rg }t                      
|D ]?\  	}	fd| D             }|                    ||f           
                    |           @
fd| D             }|r|                    d |D                        n| dfg}t          |          D ],\  }\  }}|r|st          d |D                       }||f||<   -|S )al  Compute Groups given the input source list and separate configs.

    separate is the user-specified configuration for how to assign
    modules to compilation groups (see mypycify docstring for details).

    This takes that and expands it into our internal representation of
    group configuration, documented in mypyc.emitmodule's definition
    of Group.
    Tc                    g | ]}|gd fS r?   r[   r^   rt   s     r,   ra   z$construct_groups.<locals>.<listcomp>t  s    $L$L$L&vh%5$L$L$Lr.   c                &    g | ]}|j         v |S r[   r\   )r^   re   filess     r,   ra   z$construct_groups.<locals>.<listcomp>y  s%    IIISsx57H7HS7H7H7Hr.   c                    g | ]}|v|	S r[   r[   )r^   re   used_sourcess     r,   ra   z$construct_groups.<locals>.<listcomp>|  s#    LLL#C|4K4K#4K4K4Kr.   c                    g | ]}|gd fS r?   r[   r   s     r,   ra   z$construct_groups.<locals>.<listcomp>~  s    IIIVHd+IIIr.   Nc                    g | ]	}|j         
S r[   rq   r   s     r,   ra   z$construct_groups.<locals>.<listcomp>  s    AAAv}AAAr.   )
isinstancelistrh   r   r   extend	enumeratery   )r   ri   r   r   namegroup_sourcesunused_sourcesigroupr   r   s            @@r,   construct_groupsr   d  sS    4$L$LG$L$L$L	Hd	#	# #uu# 	/ 	/KE4IIIIGIIIMMM=$/000....LLLLLLL 	KMMII.IIIJJJD/" &f-- " "=E4 	C$ 	CAA5AAABBDDMq		Mr.   list[tuple[str, str]]c                    t                      }| D ]-\  }}|                    t          j        d|                     .t	          |          S )zFind all the headers used by a group of cfiles.

    We do this by just regexping the source, which is a bit simpler than
    properly plumbing the data through.

    Arguments:
        cfiles: A list of (file name, file contents) pairs.
    z#include "(.*)")rh   r   refindallsorted)r   headersrI   r   s       r,   get_header_depsr     sP     G A A8rz"4h??@@@@'??r.   )ri   rS   skip_cgen_inputalways_use_shared_libpathsr   
Any | Noner   ;tuple[emitmodule.Groups, list[tuple[list[str], list[str]]]]c                  t                      }t          | ||          \  }}}	t          |          dk    pt          d |D                       p|}
t	          |||
          }|sKt          ||	||          \  }}t          t          j        	                    j
        d          |           n|}g }|D ]}g }|D ]\  }}t          j        	                    j
        |          }|	j        st          ||           t          j                            |          d         dk    r|                    |           fdt          |          D             }|                    ||f           ||fS )zRDo the front and middle end of mypyc building, producing and writing out C source.rJ   c              3  (   K   | ]}d |j         v V  dS )r{   Nr   )r^   xs     r,   	<genexpr>zmypyc_build.<locals>.<genexpr>  s(      661sah666666r.   )rU   zops.txtz.cc                Z    g | ]'}t           j                            j        |          (S r[   )r   r]   rO   
target_dir)r^   deprU   s     r,   ra   zmypyc_build.<locals>.<listcomp>  s-    bbb3-8#>>bbbr.   )r   ru   r   anyr   r   r   r   r]   rO   r   mypyc_skip_c_generationsplitextr   r   )r   rU   ri   rS   r   r   rV   rs   rr   rA   r   r   group_cfilesops_textgroup_cfilenamesr   
cfilenamescfiler   r   s    `                  r,   mypyc_buildr    s    G*9!#3W+ +'M; 	MQ 	!6666666	!   mX~FFF  '!+&'DT"
 "
 "
h 	27<< 0 ;YGGRRRR& ;= 
4 
4
" 	) 	)LE5GLL!1!<eDDE2 )5%(((w&&q)T11!!%(((bbbb/Z`JaJabbbT 23333###r.   31)rS   r   	opt_leveldebug_levelstrip_asserts
multi_fileri   r   r   include_runtime_filesstrict_dunder_typingr   r  r  r  r  r   
str | Noner	  bool | Noner
  c                  t          ||||du|	|
|          }t          | ||||          \  }}t                       t          j                    }t          j        |           |j        }g }|j        dk    r|d| d| ddd	d
ddddddgz  }nK|j        dk    r@|dk    rd}n|dv rd}|dk    rd}n|dk    rd}n|dv rd}|d| d| dddgz  }|r|d d!gz  }g }|j	        st          D ]}t          j                            ||          }t          t          j                            t                      |          d"#          5 }t!          ||                                           d$d$d$           n# 1 swxY w Y   |                    |           g }t'          ||          D ]_\  \  }}\  }}|r+|                    t+          ||||z   |||                     8|                    t-          |||z   |                     `|S )%a	  Main entry point to building using mypyc.

    This produces a list of Extension objects that should be passed as the
    ext_modules parameter to setup.

    Arguments:
        paths: A list of file paths to build. It may also contain mypy options.
        only_compile_paths: If not None, an iterable of paths that are to be
                            the only modules compiled, even if other modules
                            appear in the mypy command line given to paths.
                            (These modules must still be passed to paths.)

        verbose: Should mypyc be more verbose. Defaults to false.

        opt_level: The optimization level, as a string. Defaults to '3' (meaning '-O3').
        debug_level: The debug level, as a string. Defaults to '1' (meaning '-g1').
        strip_asserts: Should asserts be stripped from the generated code.

        multi_file: Should each Python module be compiled into its own C source file.
                    This can reduce compile time and memory requirements at the likely
                    cost of runtime performance of compiled code. Defaults to false.
        separate: Should compiled modules be placed in separate extension modules.
                  If False, all modules are placed in a single shared library.
                  If True, every module is placed in its own library.
                  Otherwise separate should be a list of
                  (file name list, optional shared library name) pairs specifying
                  groups of files that should be placed in the same shared library
                  (while all other modules will be placed in its own library).

                  Each group can be compiled independently, which can
                  speed up compilation, but calls between groups can
                  be slower than calls within a group and can't be
                  inlined.
        target_dir: The directory to write C output files. Defaults to 'build'.
        include_runtime_files: If not None, whether the mypyc runtime library
                               should be directly #include'd instead of linked
                               separately in order to reduce compiler invocations.
                               Defaults to False in multi_file mode, True otherwise.
        strict_dunder_typing: If True, force dunder methods to have the return type
                              of the method strictly, which can lead to more
                              optimization opportunities. Defaults to False.
    F)r  r  r   ri   r   r	  r
  )rS   rU   ri   r   unixz-Oz-gz-Werrorz-Wno-unused-functionz-Wno-unused-labelz-Wno-unreachable-codez-Wno-unused-variablez!-Wno-unused-command-line-argumentz-Wno-unknown-warning-optionz-Wno-unused-but-set-variablez"-Wno-ignored-optimization-argumentz-Wno-cppmsvc0d)r  2r  r  NONEr  FASTLINK)r  r  FULLz/Oz/DEBUG:z/wd4102z/wd4101z/wd4146z/GL-z/wd9025r   )encodingN)r   r  r<   r   new_compilerr   customize_compilerr   compiler_typer	  r   r   r]   rO   r   r   r   r   r   zipr   r   r   )r   rS   r   r  r  r  r  ri   r   r   r	  r
  rU   r   r   compilerr   cflagsshared_cfilenamesr   rt_filer   r   r   lib_namer   r   s                              r,   mypycifyr     s3   v '#&31    +-)'     F 
 *,,H *** +IF''"#"/)*0 
 	
  
	6	)	)II/))I# KKC$KKJ&& K#k##
 	
  	* vy))F
 1 .# 	. 	.Dgll9d33Gbgll;==$77'JJJ .a7AFFHH---. . . . . . . . . . . . . . .$$W----J9<VEU9V9V  5!#5J 	&!!22 	 	 	 	 #M:@Q3QSYZZ    s   	#E88E<	?E<	)r   r    )r   r/   )r=   r7   r   r   )F)
rA   r   rB   rC   rD   rE   rF   rG   r   r/   )
rR   rC   rS   rT   rU   r   rV   rW   r   rX   )
rv   r7   rw   r7   rx   r7   ry   r7   r   r7   )r$   rC   r   r7   )r   r7   )r   r   rA   r   r   r   rV   r   rU   r   r   r   )r   r   ry   r7   r   rC   r   rC   r   r7   r   rC   r   r   )r   r   r   rC   r   rC   r   r   )r]   r7   r   r7   r   r/   )r   r   ri   r   r   rG   r   r   )r   r   r   rC   )r   rC   rU   r   ri   r   rS   rT   r   r   r   rG   r   r   )r   rC   rS   rT   r   rG   r  r7   r  r7   r  rG   r  rG   ri   r   r   r   r   r  r	  r  r
  rG   r   r   )I__doc__
__future__r   r   os.pathr   r   r#   r   collections.abcr   typingr   r   r   r   r	   
mypy.buildr
   mypy.errorsr   mypy.fscacher   	mypy.mainr   mypy.optionsr   	mypy.utilr   mypyc.annotater   mypyc.codegenr   mypyc.commonr   r   mypyc.errorsr   mypyc.ir.pprintr   mypyc.namegenr   mypyc.optionsr   r"   ImportErrorr%   r   r&   _distutils_Extensiontyping_extensionsr   _setuptools_Extension__annotations__r*   r   r   r-   r<   r@   rQ   ru   r   ry   r   r   r   r   r   r   r   r  r   r[   r.   r,   <module>r8     s!    ( # " " " " "   				 



  $ $ $ $ $ $ < < < < < < < < < < < < < < " " " " " " $ $ $ $ $ $ ( ( ( ( ( ( % % % % % %             % % % % % % 2 2 2 2 2 2 $ $ $ $ $ $ 9 9 9 9 9 9 9 9       * * * * * * ' ' ' ' ' ' ) ) ) ) ) )	 	 	 	D	  	R
7""(((((((DDDDDD//////AAAAAA$%:<P%PQ	QQQQw.................   $B B B B   
# # # # # (/ (/ (/ (/V   >   N N N N
15 15 15 15h- - - -`   "5 5 5 58$ $ $ $N   ( ;@/3"&"'4$ 4$ 4$ 4$ 4$ 4$t 04:?"&!)-!&a a a a a a a as   B BB