o
    Zh                     @   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r;dgZne jdkrEd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 g d}| |dksJ tjtdd | d  W d    n1 s'w   Y  t d}| |t  }|t dksBJ tjt	dd | |t 
t   W d    d S 1 s`w   Y  d S )N)         r   znot an arraymatch{   Z123z*casting scalars of type int64 to type list)paarrayZget_array_lengthpytestraises	TypeErrorZscalarZcast_scalarutf8NotImplementedErrorlist_Zint64)modZarrZscalZ	cast_scal r   P/var/www/html/lang_env/lib/python3.10/site-packages/pyarrow/tests/test_cython.pycheck_cython_example_moduleF   s   
"r   c              	   C   s  ddl }|   d}ttjt|tjt| | t	j
|ttd}tdd}|| W d   n1 s:w   Y  t }tjtjdddg|d	 tjdd }tjdt|  ztd
}t| W |t_n|t_w dj
d
t d}d}	tjdkrttdsd\}
}	ntjdkrd\}
}	nd\}
}	|	rtj}|t 7 }|||	dg7 }dd |D }|
|||	< tjtjd|gtj|d W d   dS 1 sw   Y  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_nameZ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`   






"rK   c           	   	   C   s<  |   N d}ttjt|tjt| | tj	|t
td}tdd}|| W d    n1 s6w   Y  t }tjtjdddg|d W d    n1 sUw   Y  tjdt|  td	}g d
}g }|||j ||kszJ tjtdd dd }||| W d    d S 1 sw   Y  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 )NrM   rO   )
ValueError)sr   r   r   
raise_on_b   s   z&test_visit_strings.<locals>.raise_on_b)r,   r-   r.   r/   r(   r0   r1   r2   r3   r4   r   r   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   Z_visit_stringsappendr   r   rP   )	rC   r   rD   rE   rF   r   stringsvisitedrR   r   r   r   test_visit_strings   s:   

"rV   )r/   r-   r9   r;   r   Zpyarrowr   Zpyarrow.tests.utilZtestsutilr7   r(   dirnameabspath__file__r1   environrA   r   namer   r3   r   markr+   rK   rV   r   r   r   r   <module>   s(   



Q