0{Y0@sddlmZddlZddlZddlZddlZddlZddlmZm Z m Z m Z ddl m Z ddlmZmZmZmZmZejeZdjZejdZd ZGd d d eZdS) )BytesION) sysconfigfsencodedetect_encodingZipFile)finder) FileOperatorget_export_entry convert_pathget_executablein_venva s^#!.*pythonw?[0-9.]*([ ].*)?$a{# -*- coding: utf-8 -*- if __name__ == '__main__': import sys, re def _resolve(module, func): __import__(module) mod = sys.modules[module] parts = func.split('.') result = getattr(mod, parts.pop(0)) for p in parts: result = getattr(result, p) return result try: sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) func = _resolve('%(module)s', '%(func)s') rc = func() # None interpreted as 0 except Exception as e: # only supporting Python >= 2.6 sys.stderr.write('%%s\n' %% e) rc = 1 sys.exit(rc) c@seZdZdZeZdZdddddZddZd dd d Z d d Z e Z ddZ ddZdddZddZeddZejddZejdkrddZndddZdddZdS) ScriptMakerz_ A class to copy or create scripts from source scripts or callable specifications. NTFcCsg||_||_||_d|_d|_tjdk|_td|_ |p]t ||_ dS)NFposixX.Y)rr) source_dir target_dir add_launchersforceclobberosnameset_modesetvariantsr _fileop)selfrrrdry_runfileopr 6/tmp/pip-ok8sy_ze-build/pip/_vendor/distlib/scripts.py__init__Ks     zScriptMaker.__init__cCsg|jddrctjdkrctjj|\}}|jdd}tjj||}n|S)NguiFntpythonpythonw)getrrpathsplitreplacejoin)r executableoptionsdnfnr r r!_get_alternate_executableWs !z%ScriptMaker._get_alternate_executablecCsd}|jr!|j}d}ntjs9t}nqtrptjjtjddtj d}n:tjjtj ddtj dtj df}|r|j ||}n|rd |krd |}nt |}d ||d }y|j d Wn"t k r7td|YnX|d kry|j |Wqt k rtd||fYqXn|S)NTFscriptszpython%sEXEBINDIRz python%s%sVERSION z"%s"s#!s zutf-8z,The shebang (%r) is not decodable from utf-8z?The shebang (%r) is not decodable from the script encoding (%r))r,ris_python_buildr r rr(r+get_pathget_config_varr0rdecodeUnicodeDecodeError ValueError)rencoding post_interpr-enquoter,shebangr r r! _get_shebang^s@             zScriptMaker._get_shebangcCs |jtd|jd|jS)Nmodulefunc)script_templatedictprefixsuffix)rentryr r r!_get_script_textszScriptMaker._get_script_textcCstjj|}|j|S)N)rr(basenamemanifest)rexenamebaser r r! get_manifestszScriptMaker.get_manifestcCs|jotjdk}tjjd}|sA|||}n||dkr_|jd}n|jd}t} t| d} | jd|WdQX| j } |||| }x|D]} tj j |j | } |rtj j | \}}|jdr|} nd| } y|jj| |Wqztk rtjd d | }tj j|rtj|ntj| ||jj| |tjd ytj|Wntk rYnXYqzXntjdkr| jd | rd | |f} ntj j| rH|j rHtjd| qn|jj| ||jrz|jj| gn|j| qWdS)Nr$zutf-8pytwz __main__.pyz.pyz%s.exez:Failed to write executable - trying to use .deleteme logicz %s.deletemez0Able to replace executable using .deleteme logic.z%s.%szSkipping existing file %s)rrrlinesepencode _get_launcherrrwritestrgetvaluer(r+rsplitext startswithrwrite_binary_file Exceptionloggerwarningexistsremoverenamedebugendswithrrset_executable_modeappend)rnamesr@ script_bytes filenamesext use_launcherrSlauncherstreamzfzip_dataroutnamenedfnamer r r! _write_scriptsT            # zScriptMaker._write_scriptc Cs|jdd|}|j|jd}|j}t}d|jkr^|j|nd|jkr|jd|tjdfnd|jkr|jd|tjdd fn|r|j d d rd }nd }|j |||||dS)Nzutf-8r-rXz%s%srzX.Yz%s-%sr#FpywrO) rArIrTrrraddsysversionr'rr) rrHrgr-r@scriptr scriptnamesrhr r r! _make_scripts  !' zScriptMaker._make_scriptcCsAd}tjj|jt|}tjj|jtjj|}|j r||jj || r|t j d|dSyt |d}Wn't k r|jsnd}YnXt|j\}}|jd|j}|s t jd|j|dStj|jdd} | rId}| jd pCd } n|s|rb|jn|jj|||jr|jj|gn|j|nt jd ||j|jjs*|j|| } d |krd } nd} tjj|} |j| g| |j || n|r=|jndS)NFznot copying %s (up-to-date)rbrz"%s: %s is an empty file (skipping)s s Trr1zcopying and adjusting %s -> %sspythonwrurO)!rr(r+rr rrJrrnewerr\raopenIOErrorrrreadlineseekr]get_command_name FIRST_LINE_REmatchr*groupclose copy_filerrcrdinforArrread)rryrgadjustrnfr=lines first_linerr>r@rhror r r! _copy_scriptsR$              %zScriptMaker._copy_scriptcCs |jjS)N)rr)rr r r!r szScriptMaker.dry_runcCs||j_dS)N)rr)rvaluer r r!rsr$cCsftjddkrd}nd}d||f}tjddd}t|j|j}|S) NPZ64Z32z%s%s.exerRrr)structcalcsize__name__rsplitrfindbytes)rkindbitsrZdistlib_packageresultr r r!rUs zScriptMaker._get_launchercCsKg}t|}|dkr1|j||n|j||d||S)a Make a script. :param specification: The specification, which is either a valid export entry specification (to make a script from a callable) or a filename (to make a script by copying from a source location). :param options: A dictionary of options controlling script generation. :return: A list of all absolute pathnames written to. Nr-)r rr{)r specificationr-rgrHr r r!make's   zScriptMaker.makecCs4g}x'|D]}|j|j||q W|S)z Take a list of specifications and make scripts from them, :param specifications: A list of specifications. :return: A list of all absolute pathnames written to, )extendr)rspecificationsr-rgrr r r! make_multiple:s zScriptMaker.make_multiple)r __module__ __qualname____doc__SCRIPT_TEMPLATErDr,r"r0rArI_DEFAULT_MANIFESTrKrNrrr{rpropertyrsetterrrrUrrr r r r!rBs&  .   2 4r)iorloggingrrerrwcompatrrrr resourcesrutilr r r r r getLoggerrr\striprcompilerrobjectrr r r r!s     "(