3 \Xã@s˜dZddlZddlZddlmZddlmZddlmZddl m Z ddl m Z m Z ddlmZddlZejd ƒZGd d „d eƒZGd d „d ee ƒZdS)zRdistutils.command.build_scripts Implements the Distutils 'build_scripts' command.éN)ÚST_MODE)Ú sysconfig)ÚCommand)Únewer)Ú convert_pathÚ Mixin2to3)Úlogs^#!.*python[0-9.]*([ ].*)?$c@sHeZdZdZdddgZdgZd d „Zd d„Zdd„Zdd„Z dd„Z dS)Ú build_scriptsz("build" scripts (copy and fixup #! line)ú build-dir=Údúdirectory to "build" (copy) toÚforceÚfú1forcibly build everything (ignore file timestampsú executable=Úeú*specify final destination interpreter pathcCs"d|_d|_d|_d|_d|_dS)N)Ú build_dirÚscriptsr Ú executableÚoutfiles)Úself©rú7/usr/lib64/python3.6/distutils/command/build_scripts.pyÚinitialize_optionss z build_scripts.initialize_optionscCs|jddddƒ|jj|_dS) NZbuildr rr r)r r)r r )rr)Zset_undefined_optionsZ distributionr)rrrrÚfinalize_options%s zbuild_scripts.finalize_optionscCs|jS)N)r)rrrrÚget_source_files,szbuild_scripts.get_source_filescCs|js dS|jƒdS)N)rÚ copy_scripts)rrrrÚrun/szbuild_scripts.runc"CsÂ|j|jƒg}g}�x,|jD�] }d}t|ƒ}tjj|jtjj|ƒƒ}|j|ƒ|j rtt ||ƒ rtt j d|ƒqyt |dƒ}Wn tk r¢|jsš‚d}YnXXtj|jƒ\}}|jdƒ|jƒ} | sÚ|jd|ƒqtj| ƒ} | rúd}| jdƒpød } |�rt jd ||jƒ|j|ƒ|j�s tj�s2|j} n(tjjtjd ƒd tjd ƒtjdƒfƒ} tj| ƒ} d| | d} y| jdƒWn$tk �r¦t dj!| ƒƒ‚YnXy| j|ƒWn&tk �rÜt dj!| |ƒƒ‚YnXt |dƒ�}|j"| ƒ|j#|j$ƒƒWdQRX|�r@|j%ƒq|�r*|j%ƒ|j|ƒ|j&||ƒqWtj'dk�rºxh|D]`}|j�rpt jd|ƒnDtj(|ƒt)d@}|dBd@}||k�rVt jd|||ƒtj*||ƒ�qVW||fS)a"Copy each script listed in 'self.scripts'; if it's marked as a Python script in the Unix way (first line matches 'first_line_re', ie. starts with "\#!" and contains "python"), then adjust the first line to refer to the current Python interpreter as we copy. Fznot copying %s (up-to-date)ÚrbNrz%s is an empty file (skipping)Téózcopying and adjusting %s -> %sÚBINDIRz python%s%sÚVERSIONÚEXEs#!ó zutf-8z.The shebang ({!r}) is not decodable from utf-8zAThe shebang ({!r}) is not decodable from the script encoding ({})ÚwbÚposixzchanging mode of %siÿimz!changing mode of %s from %o to %o)+ZmkpathrrrÚosÚpathÚjoinÚbasenameÚappendr rrÚdebugÚopenÚOSErrorÚdry_runÚtokenizeÚdetect_encodingÚreadlineÚseekÚwarnÚ first_line_reÚmatchÚgroupÚinforZ python_buildrÚget_config_varÚfsencodeÚdecodeÚUnicodeDecodeErrorÚ ValueErrorÚformatÚwriteÚ writelinesÚ readlinesÚcloseZ copy_fileÚnameÚstatrÚchmod)rrÚ updated_filesZscriptZadjustZoutfilerÚencodingÚlinesZ first_liner7Z post_interprZshebangZoutfÚfileZoldmodeZnewmoderrrr5s�                  zbuild_scripts.copy_scriptsN)r r r )r rr)rrr) Ú__name__Ú __module__Ú __qualname__Z descriptionZ user_optionsZboolean_optionsrrrrrrrrrr sr c@seZdZdd„ZdS)Úbuild_scripts_2to3cCs&tj|ƒ\}}|js|j|ƒ||fS)N)r rr0Zrun_2to3)rrrGrrrrœs zbuild_scripts_2to3.copy_scriptsN)rKrLrMrrrrrrNšsrN)Ú__doc__r(ÚrerErZ distutilsrZdistutils.corerZdistutils.dep_utilrZdistutils.utilrrrr1Úcompiler6r rNrrrrÚs