o
    @a                     @   sp   d 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Z edZ	dd Z
dd Zd	d
 Zedkr6e  dS dS )zG Script to run Pythran file compilation with specified g++ like flags.     N)CompileErrorpythranc                 c   s$    |   D ]
}| sq|V  qdS )z*Read argument from file in a prettier way.N)splitstrip)arg_linearg r   -/usr/lib/python3/dist-packages/pythran/run.pyconvert_arg_line_to_args   s   r
   c                 C   sH   | j | j| j| j| j| j| jd}dD ]}t| |d}|r!|||< q|S )z
    Build a dictionnary with an entry for cppflags, ldflags, and cxxflags.

    These options are filled according to the command line defined options

    )Zdefine_macrosZundef_macrosinclude_dirsZextra_compile_argsZlibrary_dirsZextra_link_argsconfig)optsN)definesundefsr   extra_flagslibraries_dirr   getattr)argsZcompiler_optionsZparamvalr   r   r	   compile_flags   s   		r   c               
   C   s  d} t jdkr| d7 } tjddd| dd}|jd	td
d |jddtdd |jddddd |jddddd |jddddd |jddddd |jdddd d |jd!d"d#tjjd$ |jd%d&d'd(d)t	 d* |jd+d,d-d(d.t	 d* |jd/d0d1d(d2t	 d* |jd3d4d5d(d6t	 d* |jd7d8d5d(d9t	 d* |jd:d;d;d(d<t	 d* t
|_
|tjd=d  \}}||_|jrd>|_|jd? |jr|jrtd@ td= |jrttj |jrttj |jrtjtjj|j |jr|jstjtjj znt j !|j"st#dA$|j"t j %t j &|j"\}}|dBvr-t'dC$||dDkr\|j(r>t#dE$|j"|jrJt#dF$|j"tj)||j"|j*fi t+| W d S tj,|j"f|j*|j|j(dGt+| W d S  t-y } ztdHt|  td= W Y d }~d S d }~w t#y } ztdIt|  td= W Y d }~d S d }~w tj.j/j0y } ztdJt|  td= W Y d }~d S d }~w tj1j2y } ztdKt|  td= W Y d }~d S d }~w t3y } ztdLt|  td= W Y d }~d S d }~w t4y)   tdM   t5yJ } ztdNt|  td= W Y d }~d S d }~ww )ON-nt/r   z!pythran: a python to C++ compilerzIt's a megablast!@)progdescriptionepilogprefix_charsfromfile_prefix_chars
input_filez:the pythran module to compile, either a .py or a .cpp file)typehelpz-ooutput_filez'path to generated file. Honors %%{ext}.)destr    r!   z-Poptimize_only
store_truez1only run the high-level optimizer, do not compile)r#   actionr!   z-Etranslate_onlyz'only run the translator, do not compilez-eraw_translate_onlyz0similar to -E, but does not generate python gluez-vverbosezbe more verbosez-wwarn_offzbe less verbosez-Vz	--versionversion)r&   r+   z-pr   passappendz8any pythran optimization to apply before code generation)r#   metavarr&   r!   defaultz-Ir   Zinclude_dirz7any include dir relevant to the underlying C++ compilerz-Lr   Zldflagsz%any search dir relevant to the linkerz-Dr   Zmacro_definitionz<any macro definition relevant to the underlying C++ compilerz-Ur   z7any macro undef relevant to the underlying C++ compilerz--configr   zconfig additional params   TZENABLE_PYTHON_MODULEz.Unexpected combination: -w and -v? Daoubennek?zinput file `{0}' not found).cppz.pyz!Unsupported file extension: '{0}'r1   zEDo you really ask for Python-to-Python on this C++ input file: '{0}'?zBDo you really ask for Python-to-C++ on this C++ input file: '{0}'?)r"   ZcpponlyZpyonlyz(I've got a bad feeling about this...
E: z%Chair to keyboard interface error
E: zYou shall not pass!
E: zQI am in trouble. Your input file does not seem to match Pythran's constraints...
z%Cover me Jack. Jack? Jaaaaack!!!!
E: zyMAYDAY, MAYDAY, MAYDAY; pythran compiler; code area out of control
E: not implemented feature needed, bash the developerszGBy Jove! Your environment does not seem to provide all what we need
E: )6osnameargparseArgumentParseradd_argumentstrr   r+   __version__listr
   parse_known_argssysargvr   r(   r'   r   r-   r)   r*   loggerZcriticalexitZsetLevelloggingINFOZERRORr   Z
update_cfgZcfgZlint_cfgpathexistsr   
ValueErrorformatsplitextbasenameSyntaxErrorr$   Zcompile_cxxfiler"   r   Zcompile_pythranfileIOErrortypesZtogZPythranTypeErrorZsyntaxZPythranSyntaxErrorr   NotImplementedErrorEnvironmentError)r   parserr   ZextraZmodule_nameexter   r   r	   run2   s4  


















rO   __main__)__doc__r4   r?   r2   r;   r   Zdistutils.errorsr   Z	getLoggerr=   r
   r   rO   __name__r   r   r   r	   <module>   s   
 &
