U
    {h
                     @   sh   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              
      sx   t |  fdd}tj}dd }|d|| ft j| dddt | t j| d	d
t | t jt 	 |||fS )Nc                    s    fdd}|S )Nc                    sP   | }|j tj |j t  |j t   jt	
  |S N)scopeZuse_utility_coder   Zget_view_utility_codeZshared_utility_qualified_nameZ_get_memviewslice_declare_codeZ_get_typeinfo_to_format_codeZinclude_directoriesappendr   Zget_utility_dir)Zcompsrctree)contextoptionsparse =/tmp/pip-unpacked-wheel-fhl22ezh/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    fdd}|S )Nc                    s
    t _| S r   )r   cimport_from_pyx)noder   r   r   inner!   s    zKcreate_shared_library_pipeline.<locals>.set_cimport_from_pyx.<locals>.innerr   )r   r   r   r   r   set_cimport_from_pyx    s    z<create_shared_library_pipeline.<locals>.set_cimport_from_pyxTZpyxr   )Zexclude_classesF)Zinternalise_c_class_entries)
r   Zparse_stage_factoryr   r   Zcreate_pipelineZinject_pxd_code_stage_factoryZ!inject_utility_code_stage_factoryZ%inject_utility_pxd_code_stage_factoryZabort_on_errorsZgenerate_pyx_code_stage_factory)r   r   r   resultr   Zorig_cimport_from_pyxr   r   r   r   create_shared_library_pipeline   s    

r   c              
   C   s  t   t d  | j}tjtj|d }tj	
| }tjdd |dd}t }tj|| d}tj|| d}t|d W 5 Q R X t|}t|t|t }	t|	| }
t||| |
}t||	\}}|d krt|| W 5 Q R X ||fS )Nr   r   F)parent_moduler   
is_packagez.pyxz.cw)r   Zinit_threadZopen_listing_fileZshared_c_file_pathospathsplitextbasenamer   ContextZfrom_optionsr   ZModuleScopetempfileTemporaryDirectoryjoinopenr
   ZCompilationSourcer	   getcwdZcreate_default_resultobjr   r   Zrun_pipelineshutilcopy)r   Zdest_c_filemodule_namer   r   Z
tmpdirnameZpyx_fileZc_fileZsource_descZcomp_srcr   ZpipelineerrZenddatar   r   r   generate_shared_module4   s&    


r/   )r&   r!   r+   ZCython.Compilerr   r   r   r   r   r   r   ZCython.Compiler.StringEncodingr	   ZCython.Compiler.Scanningr
   r   r/   r   r   r   r   <module>   s   $(