U
    {h{                  I   @   s  d dl Z ddlmZ G dd dZdZdZdZdZdZdZ	dZ
dZdZdZdZdZdZdZdZdZedZdZd	Zd	Zd
d Zdd Zdd Zdddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddg g g g ddHZddddZddddZddddddjZdd Z G dd dZ!e! Z!e"e#e$e#ed e!e!e!de#e#e#ddde#ddde#e#e%e%e"e&edd!d"d#d#d"ide e#de!e!edd$d%edd&d'd(!Z'e( D ] \Z)Z*e)e'kre%e*e'e)< qd)d*d+d,d-d.d/d-d/d-d-d/d/d/d/d,d,d,d0d+d+d+d+d1d1d+d+d,d+d+d+d+d)d+d+d+d+d+d2d,d3d3d4d/d+d/d+d+d+d+d52Z+d6d7d8d9d:d;d<d=d>d?d@dAdBdCdDdEdFdGdHdIhZ,dVdJdKZ-dWdLdMZ.dNdO Z/dXdPdQZ0G dRdS dSZ1e$d d dTd ddddd d ddd d i i dddddddddddddddddddU"Z2dS )Y    N   )Utilsc                   @   s:   e Zd Zg ZdddZdd Zdd Zd	d
 Zdd ZdS )ShouldBeFromDirectiveNFc                 C   s&   || _ |p|| _|| _| j|  d S N)options_namedirective_namedisallowknown_directivesappend)selfr   r   r    r   ;/tmp/pip-unpacked-wheel-fhl22ezh/Cython/Compiler/Options.py__init__   s    
zShouldBeFromDirective.__init__c                 C   s   |    d S r   _bad_accessr   r   r   r   __nonzero__   s    z!ShouldBeFromDirective.__nonzero__c                 C   s   |    d S r   r   r   r   r   r   __int__   s    zShouldBeFromDirective.__int__c                 C   s   t t| d S r   )RuntimeErrorreprr   r   r   r   r      s    z!ShouldBeFromDirective._bad_accessc                 C   s   d| j | jf S )NzEIllegal access of '%s' from Options module rather than directive '%s')r   r   r   r   r   r   __repr__   s     zShouldBeFromDirective.__repr__)NF)	__name__
__module____qualname__r	   r   r   r   r   r   r   r   r   r   r      s   
r   TFold_style_globals   c                  C   s\   t jD ]P} t | j}| jtks&tt|t s| j	rLt
d| j| jf q|t| j< qtS )Nz+Option '%s' must be set from directive '%s')r   r	   globalsgetr   r   _directive_defaultsAssertionError
isinstancer   r   option_name)Z
old_optionvaluer   r   r   get_directive_defaults   s    

 r#   c                 K   s,   t | }dD ]}||d  q|| |S )N)test_assert_path_existstest_fail_if_path_existstest_assert_c_code_hastest_fail_if_c_code_hascritical_section)dictpopupdate)outer_directivesZnew_directivesZnew_directives_outnamer   r   r   copy_inherited_directives   s
    
r.   c                 C   s   t | ddddS )NF)bindingprofile	linetrace)r.   )r,   r   r   r   copy_for_internal   s    r2   noc bytes)Hr/   ZboundscheckZ	nonecheckZinitializedcheckfreethreading_compatiblesubinterpreters_compatibleZembedsignatureembedsignature.formatZ
auto_cpdefauto_pickleZ	cdivisionZcdivision_warningscpowZc_api_binop_methodsZoverflowcheckzoverflowcheck.foldZalways_allow_keywordsZallow_none_for_extension_argsZ
wraparoundccomplexZcallspecnogilgilwith_gilr0   r1   emit_code_commentsZannotation_typinginfer_typeszinfer_types.verboseautotestdictautotestdict.cdefautotestdict.alllanguage_levelZfast_getattrZ
py2_importpreliminary_late_includes_cy28iterable_coroutinec_string_typec_string_encodingtype_version_tagZunraisable_tracebacksr   
np_pythranfast_gil
cpp_localslegacy_implicit_noexceptc_compile_guardset_initial_pathwarnzwarn.undeclaredwarn.unreachablewarn.maybe_uninitializedwarn.unusedzwarn.unused_argzwarn.unused_resultzwarn.multiple_declaratorszwarn.deprecated.DEFzwarn.deprecated.IFZshow_performance_hintszoptimize.inline_defnode_callszoptimize.unpack_method_callsz&optimize.unpack_method_calls_in_pyinitzoptimize.use_switchZremove_unreachablecontrol_flow.dot_outputcontrol_flow.dot_annotate_defsr$   r%   r&   r'   formal_grammar)rS   rR   rT   )mapc                    s    fdd}|S )Nc                    s2   d k	r ||}| kr.td|  |f |S )Nz(%s directive must be one of %s, got '%s')r   
ValueError)r-   r"   argsrX   r   r   validate   s      zone_of.<locals>.validater   )rX   r[   r\   r   rZ   r   one_of  s    r]   utf8ascii)r^   zutf-8defaultr_   zus-asciic                 C   st   |sdS t | }|dk	r |S ddl}z||}W n tk
rN   | Y S X dD ]}|||krT|  S qT|S )a  
    >>> normalise_encoding_name('c_string_encoding', 'ascii')
    'ascii'
    >>> normalise_encoding_name('c_string_encoding', 'AsCIi')
    'ascii'
    >>> normalise_encoding_name('c_string_encoding', 'us-ascii')
    'ascii'
    >>> normalise_encoding_name('c_string_encoding', 'utF8')
    'utf8'
    >>> normalise_encoding_name('c_string_encoding', 'utF-8')
    'utf8'
    >>> normalise_encoding_name('c_string_encoding', 'deFAuLT')
    'utf8'
    >>> normalise_encoding_name('c_string_encoding', 'default')
    'utf8'
    >>> normalise_encoding_name('c_string_encoding', 'SeriousLyNoSuch--Encoding')
    'SeriousLyNoSuch--Encoding'
    r5   Nr   )r_   r^   )_normalise_common_encoding_namelowercodecs
getdecoderLookupError)r!   encodingZencoding_namerc   decoderr-   r   r   r   normalise_encoding_name3  s    

rh   c                   @   s   e Zd ZdS )DEFER_ANALYSIS_OF_ARGUMENTSN)r   r   r   r   r   r   r   ri   Y  s   ri   sequence	bytearraystrunicodeZclinicpythonZ
shared_gilZown_gil)!rE   r:   localsfinalcollection_typer=   r>   r(   r?   internalrA   r/   cfuncccallufuncr;   inlinestaticmethodcclassno_gc_clearno_gcreturns	exceptvalrP   freelistrH   rI   trashcantotal_orderingdataclasses.dataclasszdataclasses.fieldr9   r8   )modulerx   )rx   function)r   )rx   )r   with statementr   )r   )classrx   r   )r   r   rx   )r   r   )r   rx   )r   r   rx   )2r:   rp   r<   rq   r=   r>   r?   r(   rv   rs   rt   r{   r|   ro   rw   ry   rz   rr   rx   rB   rD   rC   rP   r$   r%   r&   r'   r}   rW   r@   rH   rI   rJ   rE   r   rK   rF   rL   rG   r~   r   r   rM   ru   rN   rO   rU   rV   r7   r8   rs   rt   rx   r   ru   rv   r|   r{   r?   r}   rz   ry   rJ   rp   r:   rr   rq   r   r%   r$   c                 C   s   t | }|sdS |}|tkrtt|}|dkr2dS |dkr>dS |rb| }|dkrVdS |dkrbdS td| |f nd|tkrz
t|W S  tk
r   td	| |f Y qX n*|tkrt|S t|r|| |S dstdS )
a  
    Parses value as an option value for the given name and returns
    the interpreted value. None is returned if the option does not exist.

    >>> print(parse_directive_value('nonexisting', 'asdf asdfd'))
    None
    >>> parse_directive_value('boundscheck', 'True')
    True
    >>> parse_directive_value('boundscheck', 'true')
    Traceback (most recent call last):
       ...
    ValueError: boundscheck directive must be set to True or False, got 'true'

    >>> parse_directive_value('c_string_encoding', 'us-ascii')
    'ascii'
    >>> parse_directive_value('c_string_type', 'str')
    'str'
    >>> parse_directive_value('c_string_type', 'bytes')
    'bytes'
    >>> parse_directive_value('c_string_type', 'bytearray')
    'bytearray'
    >>> parse_directive_value('c_string_type', 'unicode')
    'str'
    >>> parse_directive_value('c_string_type', 'unnicode')
    Traceback (most recent call last):
    ValueError: c_string_type directive must be one of ('bytes', 'bytearray', 'str', 'unicode'), got 'unnicode'
    NTrueTFalseF)trueyes)falser3   z3%s directive must be set to True or False, got '%s'z0%s directive must be set to an integer, got '%s')	directive_typesr   boolrl   rb   rY   intcallabler   )r-   r"   relaxed_booltypeZ
orig_valuer   r   r   parse_directive_value  sB    
 

 
r   c                 C   s  |dkri }n|}|  dD ]}| }|s.qd|krBtd| dd |  ddD \}}|tkrd}|d	r|dd
 }	tD ](}
|
|	rd}t|
||d}|||
< q|s|std| qt|t	kr||kr|| 
| n
|g||< qt|||d}|||< q|S )aJ  
    Parses a comma-separated list of pragma options. Whitespace
    is not considered.

    >>> parse_directive_list('      ')
    {}
    >>> (parse_directive_list('boundscheck=True') ==
    ... {'boundscheck': True})
    True
    >>> parse_directive_list('  asdf')
    Traceback (most recent call last):
       ...
    ValueError: Expected "=" in option "asdf"
    >>> parse_directive_list('boundscheck=hey')
    Traceback (most recent call last):
       ...
    ValueError: boundscheck directive must be set to True or False, got 'hey'
    >>> parse_directive_list('unknown=True')
    Traceback (most recent call last):
       ...
    ValueError: Unknown option: "unknown"
    >>> warnings = parse_directive_list('warn.all=True')
    >>> len(warnings) > 1
    True
    >>> sum(warnings.values()) == len(warnings)  # all true.
    True
    N,=Expected "=" in option "%s"c                 S   s   g | ]}|  qS r   strip.0sr   r   r   
<listcomp>1  s     z(parse_directive_list.<locals>.<listcomp>   Fz.allT)r   zUnknown option: "%s")splitr   rY   r   endswith
startswithr   r   r   listr
   )r   r   Zignore_unknowncurrent_settingsresultitemr-   r"   foundprefix	directiveZparsed_valuer   r   r   parse_directive_list
  s8    



r   c                 C   s^   | dkrdS | dkrdS | dkr$dS |   r4t| S zt| } W n tk
rT   Y nX | S dS )a  
    Parses value as an option value for the given name and returns
    the interpreted value.

    >>> parse_variable_value('True')
    True
    >>> parse_variable_value('true')
    'true'
    >>> parse_variable_value('us-ascii')
    'us-ascii'
    >>> parse_variable_value('str')
    'str'
    >>> parse_variable_value('123')
    123
    >>> parse_variable_value('1.23')
    1.23

    r   Tr   FNoneN)isdigitr   float	Exception)r"   r   r   r   parse_variable_valueH  s    r   c                 C   sn   |dkri }n|}|  dD ]L}| }|s.qd|krBtd| dd | ddD \}}t|||< q|S )a  
    Parses a comma-separated list of pragma options. Whitespace
    is not considered.

    >>> parse_compile_time_env('      ')
    {}
    >>> (parse_compile_time_env('HAVE_OPENMP=True') ==
    ... {'HAVE_OPENMP': True})
    True
    >>> parse_compile_time_env('  asdf')
    Traceback (most recent call last):
       ...
    ValueError: Expected "=" in option "asdf"
    >>> parse_compile_time_env('NUM_THREADS=4') == {'NUM_THREADS': 4}
    True
    >>> parse_compile_time_env('unknown=anything') == {'unknown': 'anything'}
    True
    Nr   r   r   c                 S   s   g | ]}|  qS r   r   r   r   r   r   r     s     z*parse_compile_time_env.<locals>.<listcomp>r   )r   r   rY   r   )r   r   r   r   r-   r"   r   r   r   parse_compile_time_envl  s    r   c                   @   s*   e Zd ZdZd	ddZdd Zdd ZdS )
CompilationOptionsz
    See default_options at the end of this module for a list of all possible
    options and CmdLine.usage and CmdLine.parse_command_line() for their
    meaning.
    Nc           
      K   st  g | _ |rt|tr |j}nt}t|}|| t|tt }|dg |r|dt	|dkrddndd
|f }t|t }t|d }t|t| }|rdt	|dkrdndd
|f }t|||d< |d	d
r|d sdd l}	|	d d|d< d|kr*|dr*|d |d< n|dsD|d|d< d|krdd|krd|d |d< | j| d S )Ninclude_pathz3got unknown compilation option%s, please remove: %sr   r   r5   z, compiler_directivesz$got unknown compiler directive%s: %srK   Fcplusr   z%C++ mode forced when in Pythran mode!TrE   rW   )r   r    r   __dict__default_optionsr)   r+   setdifference_updatelenjoinrY   r#   r   warningsrQ   )
r   defaultskwoptionsZunknown_optionsmessageZdirective_defaultsZ
directivesZunknown_directivesr   r   r   r   r     sH    


zCompilationOptions.__init__c                 C   s&   |dkr"| j dd kr"d| j d< d S )Npyr/   T)r   r   )r   Zsource_extensionr   r   r   configure_language_defaults  s    z.CompilationOptions.configure_language_defaultsc                    s  i }| j  D ]\}}|dkr"qq|dkr.qq|dkr:qq|dkrFqq|dkrRqq|dkr^qq|dkrjqq|dkrvqq|d	krqq|d
krqq|dkr|||< q|dkr|||< q|dkr|||< q|dkr|||< q|dkr|rt| dq|||< q fdd  |S )zi
        Return a string that contains all the options that are relevant for cache invalidation.
        )show_versionerrors_to_stderrverbosequiet)output_file
output_dir)depfile)
timestamps)cache)r   )r   )working_path)create_extension)	build_dir)use_listing_filegenerate_pxiannotateannotate_coverage_xml)rW   evaluate_tree_assertions)embedded_metadataemit_linenumsc_line_in_traceback	gdb_debug'relative_path_in_code_position_comments)r   rE   compile_time_envrK   )capi_reexport_cincludescommon_utility_include_dirz& is not compatible with Cython cachingc                    s,   t | tr$t fdd|  D } t| S )z
            Recursively turn item into a string, turning dicts into lists with
            deterministic ordering.
            c                    s    g | ]\}}t | |fqS r   )r   )r   keyr"   to_fingerprintr   r   r     s     zNCompilationOptions.get_fingerprint.<locals>.to_fingerprint.<locals>.<listcomp>)r    r)   sorteditemsr   )r   r   r   r   r     s    
z:CompilationOptions.get_fingerprint.<locals>.to_fingerprint)r   r   NotImplementedError)r   datar   r"   r   r   r   get_fingerprint  sH    




	z"CompilationOptions.get_fingerprint)N)r   r   r   __doc__r   r   r   r   r   r   r   r     s   
-r   r   )"r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rE   rW   r   r   module_namer   r   r   r   r   rK   rN   Zshared_c_file_pathZshared_utility_qualified_name)F)FFN)N)3osr5   r   r   Z
docstringsZembed_pos_in_docstringZ
pre_importZgenerate_cleanup_codeZclear_to_noner   r   Z	fast_failZwarning_errorsZerror_on_unknown_namesZerror_on_uninitializedZconvert_rangeZcache_builtinsZgcc_branch_hintsZlookup_module_cpdefembedr   Zcimport_from_pyxZbuffer_max_dimsZclosure_freelist_sizer#   r.   r2   r   Zextra_warningsr]   r   ra   rh   ri   rl   r   r)   r   r   r   r   r   valZdirective_scopesZimmediate_decorator_directivesr   r   r   r   r   r   r   r   r   r   <module>   s  %
	
[	&

$
=               
<  
>$
& 