o ca%@sddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl m Z ddlmZmZed ejZGd d d e Zd d ZddZddZddZdS)N)dist)iglob) bdist_wheel) WheelFile) WheelErrorrequire_pkgresourcesz] (?P.+?)-(?P.+?) (-(?Ppy\d\.\d+) (-(?P.+?))? )?.egg$c@seZdZdZdZddZdS)_bdist_wheel_tagFNcCs |jr |jdur |jSt|S)N)full_tag_suppliedfull_tagrget_tag)selfr3/usr/lib/python3/dist-packages/wheel/cli/convert.pyr s z_bdist_wheel_tag.get_tag)__name__ __module__ __qualname__r r r rrrrr s r cCs$tj|}t|}|std||}tj dd}tj |r?t | }| |Wdn1s9wYn't|D]!}tj||}tj |rZt||qDt|tj||qD|d} | rv| dd} |d<|dp{ddd d d } | dkrd | d dnd } |ddu} | rtt} ntt} | | _| | _d| _|dpd| _| sd| _| | | f| _tj|djdi|}| tj|d|| j|dddj| | fi|}t tj||d }|!|Wdn 1swYt"|dS)NzInvalid egg file name: {}_e2wsuffixpyver.archany_-cprnoneTz{name}-{ver}.dist-infozEGG-INFO egg2wheel generatorz{name}-{ver}-{pyver}-{}-{}.whlwr)#ospathbasename egg_info_rematchrformat groupdicttempfilemkdtempisfilezipfileZipFile extractalllistdirjoinshutilcopy2copytreereplacerr Distributionr root_is_pure python_tagplat_name_supplied plat_namer r egg2distwrite_wheelfiler write_filesrmtree)egg_pathdest_dirfilenamer(egg_infodireggpthsrcrrabiroot_is_purelibbw dist_info_dir wheel_namewfrrrr %sP           r c Csd}|rt|}|std|f|d\}}}|s#td|f|dd}|d\}}}|rA|drA|}|dd}nd }|d\}}} |sTtd|f|r`|d }|d }||| |d S) atExtract metadata from filenames. Extracts the 4 metadataitems needed (name, version, pyversion, arch) from the installer filename and the name of the egg-info directory embedded in the zipfile (if any). The egginfo filename has the format:: name-ver(-pyver)(-arch).egg-info The installer filename has the format:: name-ver.arch(-pyver).exe Some things to note: 1. The installer filename is not definitive. An installer can be renamed and work perfectly well as an installer. So more reliable data should be used whenever possible. 2. The egg-info data should be preferred for the name and version, because these come straight from the distutils metadata, and are mandatory. 3. The pyver from the egg-info data should be ignored, as it is constructed from the version of Python used to build the installer, which is irrelevant - the installer filename is correct here (even to the point that when it's not there, any version is implied). 4. The architecture must be taken from the installer filename, as it is not included in the egg-info data. 5. Architecture-neutral installers still have an architecture because the installer format itself (being executable) is architecture-specific. We should therefore ignore the architecture if the content is pure-python. Nz!Egg info filename %s is not validrz"Installer filename %s is not validpyrrzpy2.py3namever)rPrQrr)r'search ValueError partition rpartition startswithr6group) wininfo_name egginfo_nameegginfow_nameseprestrest2w_pyverw_verw_archrrrparse_wininst_info[s*!    rbcCst|}d}|D] }d|vr|}nq ttj||}d}|D] }|j dr2d}nq&|r:ddi}nddi}d|} d | } g} d}|D]Q}|j d d \} } | } | | d}|duro| | d }|j}|| }||_|j |=||j |<|r| ||s|dr|}qNd |vr|d \}}}qNtjd d}||| Wdn1swYd}|d}|dpddddd}|rd}|dkr|dd}d| |||f}|rtt}ntt}||_||_d|_|dpd|_|sd|_|||f|_tj|d| }| tj||||j!|ddtj||}t"|d }|#|Wdn 1sJwYt$%|dS)Nz .egg-infoTPLATLIBFpurelibrplatlibz%(name)s-%(ver)sz%s.data//rz .egg-info/_b2wrrrrrrrrrOrz %s.dist-info wininst2wheelr!r#)&r.r/namelistrbr$r%r&infolistrBrVsplitlowerget NameToInfoappendendswithrUr+r,r0r6r2rrr7r r8r9r:r;r r r<r=rr>r3r?)r%rAbdwrYrBinforIzipinfopaths dist_infodatadirmemberskeyr&basepatholdnamenewnamer\rrDrHrrrLrJrK wheel_pathrMrrrrhs           3     rhcCsttd|D]1}t|D]*}tj|ddkrt}nt}|r+td|t j ||||r6tdq qdS)Nz wheel convertrz.eggz{}... OK) r rr$r%splitextr rhprintr)sysstdoutflush)filesrAverbosepat installerconvrrrconverts   r)os.pathr$rer3rr+r. distutilsrglobrr wheelfilerrrr compileVERBOSEr'r r rbrhrrrrrs&    6G Z