o
    h                     @   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ejjdd Zejjejjdd ZdS )    N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{   123z<Unsupported cast from int64 to list using function cast_list)paarrayget_array_lengthpytestraises	TypeErrorscalarcast_scalarutf8NotImplementedErrorlist_int64)modarrscal	cast_scal r   M/var/www/vscode/kcb/lib/python3.10/site-packages/pyarrow/tests/test_cython.pycheck_cython_example_moduleD   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env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win32add_dll_directory);PATHdarwin):DYLD_LIBRARY_PATH)r2   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osr6   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   get_library_dirsplatformhasattrgetPIPE)tmpdirr9   r!   
setup_codefsubprocess_env	orig_pathr   codepath_vardelimpathsr   r   r   test_cython_apiU   s`   






"r[   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   bound_function_visit_strings)abcwtfr	   c                 S   s   | dkrt dd S )Nr^   r`   )
ValueError)sr   r   r   
raise_on_b   s   z&test_visit_strings.<locals>.raise_on_b)r:   r;   r<   r=   r6   r>   r?   r@   rA   rB   r"   r#   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   _visit_stringsappendr   r   ra   )	rR   r!   rS   rT   rU   r   stringsvisitedrc   r   r   r   test_visit_strings   s:   

"rh   )r=   r;   rG   rI   r   pyarrowr   pyarrow.tests.utiltestsutilrE   r6   dirnameabspath__file__r?   environrP   r#   namer"   rA   r   marknumpyr9   r[   rh   r   r   r   r   <module>   s,   


Q