U
    -e                     @   s   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  m	Z
 e je jeZe jddZe jdkrvdgZne jdkrddgZng Zd	Zd
d Zejjdd Zejjdd ZdS )    NZPYARROW_TEST_LD_PATH posixz
-std=c++17ntz"-D_ENABLE_EXTENDED_ALIGNED_STORAGEz
/std:c++17a[  if 1:
    from setuptools import setup
    from Cython.Build import cythonize

    import numpy as np

    import pyarrow as pa

    ext_modules = cythonize({pyx_file!r})
    compiler_opts = {compiler_opts!r}
    custom_ld_path = {test_ld_path!r}

    for ext in ext_modules:
        # XXX required for numpy/numpyconfig.h,
        # included from arrow/python/api.h
        ext.include_dirs.append(np.get_include())
        ext.include_dirs.append(pa.get_include())
        ext.libraries.extend(pa.get_libraries())
        ext.library_dirs.extend(pa.get_library_dirs())
        if custom_ld_path:
            ext.library_dirs.append(custom_ld_path)
        ext.extra_compile_args.extend(compiler_opts)
        print("Extension module:",
              ext, ext.include_dirs, ext.libraries, ext.library_dirs)

    setup(
        ext_modules=ext_modules,
    )
c              	   C   s   t dddg}| |dks"ttjtdd | d  W 5 Q R X t d}| |t 	 }|t dksrttjt
dd | |t t   W 5 Q R X d S )	N         znot an arraymatch{   Z123z*casting scalars of type int64 to type list)paarrayZget_array_lengthAssertionErrorpytestraises	TypeErrorZscalarZcast_scalarutf8NotImplementedErrorlist_Zint64)modZarrZscalZ	cast_scal r   Z/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/pyarrow/tests/test_cython.pycheck_cython_example_moduleF   s    
r   c              
   C   s  ddl }|  n d}ttjt|tjt| | t	j
|ttd}tdd}|| W 5 Q R X t }tjtjdddg|d	 tjdd }tjdt|  ztd
}t| W 5 |t_X dj
d
t d}d}	tjdkrttdsd\}
}	ntjdkrd\}
}	nd\}
}	|	rbtj}|t 7 }|||	dg7 }dd |D }|
|||	< tjtjd|gtj|d W 5 Q R X dS )z(
    Basic test for the Cython API.
    r   Nzpyarrow_cython_example.pyxpyx_filecompiler_optstest_ld_pathsetup.pyw	build_ext	--inplaceenvZpyarrow_cython_examplea'  if 1:
            import sys
            import os

            try:
                # Add dll directory was added on python 3.8
                # and is required in order to find extra DLLs
                # only for win32
                for dir in {library_dirs}:
                    os.add_dll_directory(dir)
            except AttributeError:
                pass

            mod = __import__({mod_name!r})
            arr = mod.make_null_array(5)
            assert mod.get_array_length(arr) == 5
            assert arr.null_count == 5
        )mod_namelibrary_dirswin32Zadd_dll_directory);PATHdarwin):ZDYLD_LIBRARY_PATH)r(   ZLD_LIBRARY_PATHr   c                 S   s   g | ]}|r|qS r   r   ).0pathr   r   r   
<listcomp>   s      z#test_cython_api.<locals>.<listcomp>z-c)stdoutr!   )cythonas_cwdshutilcopyfileosr*   joinherestrsetup_templateformatr   r   openwrite	test_util get_modified_env_with_pythonpath
subprocess
check_callsys
executableinsert
__import__r   r   Zget_library_dirsplatformhasattrgetPIPE)tmpdirr-   r   
setup_codefsubprocess_env	orig_pathr   codeZpath_vardelimpathsr   r   r   test_cython_apiT   s\    
 



rM   c           	   
   C   s   |   ~ d}ttjt|tjt| | tj	|t
td}tdd}|| W 5 Q R X t }tjtjdddg|d W 5 Q R X tjdt|  td	}d
ddg}g }|||j ||ksttjtdd dd }||| W 5 Q R X d S )Nz bound_function_visit_strings.pyxr   r   r   r   r   r    r   Zbound_function_visit_stringsabcwtfr   c                 S   s   | dkrt dd S )NrO   rQ   )
ValueError)sr   r   r   
raise_on_b   s    z&test_visit_strings.<locals>.raise_on_b)r.   r/   r0   r1   r*   r2   r3   r4   r5   r6   r   r   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   Z_visit_stringsappendr   r   r   rR   )	rE   r   rF   rG   rH   r   stringsvisitedrT   r   r   r   test_visit_strings   s6    

 
rX   )r1   r/   r;   r=   r   Zpyarrowr   Zpyarrow.tests.utiltestsutilr9   r*   dirnameabspath__file__r3   environrC   r   namer   r5   r   markr-   rM   rX   r   r   r   r   <module>   s&   



Q