B
    3Rcs                 @   s  d Z ddlZddlmZ ddlZejddZej	edZ
ej	edej	edgZefd	d
Zdd Zedkrg Zx e D ]Zeeree qW e  ered ed	ee ed x,eedd eD D ]Zede qW ed ed ed dS )a  

Script will test the RDkit python code for conformance with the agreed format using
yapf.

For each Python file that is found in $RDBASE (excluding the build and External
directories), yapf is used with the style configuration in $RDBASE/setup.cfg.
If a change is required, the difference is printed. At the end of the process,
all non-conformant files are listed and the required yapf command(s) printed.

If changes are found, the script will exit with error code 1, otherwise 0.

    N)
FormatCodeZRDBASE z	setup.cfgZbuildZExternalc             #   s^   xXt | D ]J\ }}t fddtD r.qx&|D ]}|dr4t j |V  q4W qW dS )z/ Find all python files below directory dirname c             3   s   | ]}  |V  qd S )N)
startswith).0d)root #share/RDKit/Scripts/PythonFormat.py	<genexpr>   s    zpythonFiles.<locals>.<genexpr>z.pyN)oswalkanyexcludeDirsendswithpathjoin)dirname_filesfiler   )r   r	   pythonFiles   s    

r   c             C   s   y t | }| }W dQ R X W n4 tk
rT   t | dd}| }W dQ R X Y nX yt|td| d\}}W n tk
r   t|   Y nX |rt| |S )z< Use yapf with the default settings to format file filename Nzlatin-1)encodingT)Zstyle_configZ
print_difffilename)openreadUnicodeErrorr   styleConfig	Exceptionprint)r   fZ
codeBeforeZchangesZchangedr   r   r	   yapfChanges$   s    
r    __main__z.yapf will make changes to the following files:
zGTo apply the required changes to your code use the following command(s)c             c   s&   | ]}| td tjd V  qdS )r      N)replacerdbasesplitr   sep)r   sr   r   r	   r
   A   s    r
   zAyapf --style $RDBASE/setup.cfg --in-place --recursive $RDBASE/{0}r#   z/Code complies with the agreed formatting rules.)__doc__r   Zyapf.yapflib.yapf_apir   sysenvirongetr%   r   r   r   r   r   r    __name__ZchangedFilesr(   appendr   sortedsetformatexitr   r   r   r	   <module>   s0   


