o
    NiR                     @   sp   d dl Z d dlZd dlZd dlZd dl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 Zdd ZdS )	    N)
MemoryViewCodeOptionsPipelineErrorsMainSymtab)EncodedString)FileSourceDescriptorc                    s   t |  fdd}dd }tj}dd }|d|| gt j| dd	d
|t | t j| ddt | t jt 	 |||S )Nc                    s    fdd}|S )Nc                    sP   | }|j tj |j t  |j t   jt	
  |S N)scopeuse_utility_coder   get_view_utility_codeshared_utility_qualified_name_get_memviewslice_declare_code_get_typeinfo_to_format_codeinclude_directoriesappendr   get_utility_dir)compsrctree)contextoptionsparse M/home/ubuntu/.local/lib/python3.10/site-packages/Cython/Build/SharedModule.pygenerate_tree   s   
zTcreate_shared_library_pipeline.<locals>.generate_tree_factory.<locals>.generate_treer   )r   r   r   r   )r   r   generate_tree_factory   s   z=create_shared_library_pipeline.<locals>.generate_tree_factoryc           	      S   s   t j}|d}tt  D ]:}|dsqt |D ],}|| }r+|d }s,q|	| }s4q|
 \}}|dkrH| j||| qq| S )N/.cnameexport)r   UtilityCodeget_special_comment_matcheroslistdirr   endswithread_utilities_hookgroupmatch_section_titlegroupsr   r   load_cached)	module_noder#   match_specialc_utility_filelinemr!   section_titlesection_typer   r   r   generate_c_utilities   s    

z<create_shared_library_pipeline.<locals>.generate_c_utilitiesc                    s    fdd}|S )Nc                    s
    t _| S r   )r   cimport_from_pyx)noder5   r   r   inner2   s   zKcreate_shared_library_pipeline.<locals>.set_cimport_from_pyx.<locals>.innerr   )r5   r8   r   r7   r   set_cimport_from_pyx1   s   z<create_shared_library_pipeline.<locals>.set_cimport_from_pyxTpyxr   )exclude_classesF)internalise_c_class_entries)
r   parse_stage_factoryr   r5   create_pipelineinject_pxd_code_stage_factory!inject_utility_code_stage_factory%inject_utility_pxd_code_stage_factoryabort_on_errorsgenerate_pyx_code_stage_factory)r   r   r   resultr   r4   orig_cimport_from_pyxr9   r   r   r   create_shared_library_pipeline   s0   
	

rF   c              	   C   sF  t   t d  | j}tjtj|d }tj	
| }tjdd |dd}t l}tj|| d}tj|| d}t|d W d    n1 sPw   Y  t|}t|t|t }	t|	| }
t||| |
}t||	\}}|d u rt|| W d    ||fS W d    ||fS 1 sw   Y  ||fS )Nr   r   F)parent_moduler   
is_packagez.pyxr    w)r   init_threadopen_listing_fileshared_c_file_pathr%   pathsplitextbasenamer   Contextfrom_optionsr   ModuleScopetempfileTemporaryDirectoryjoinopenr
   CompilationSourcer	   getcwdcreate_default_resultobjrF   r   run_pipelineshutilcopy)r   dest_c_filemodule_namer   r   
tmpdirnamepyx_filec_filesource_desccomp_srcrD   pipelineerrenddatar   r   r   generate_shared_moduleF   s4   



rg   )r%   rer[   rS   Cython.Compilerr   r   r   r   r   r   r   Cython.Compiler.StringEncodingr	   Cython.Compiler.Scanningr
   rF   rg   r   r   r   r   <module>   s    $9