o
    !g                     @   s   d dl Z d dlZd dlZd dlmZmZmZ d dlmZ ddlm	Z	 d dl
mZ d dlmZ d dlmZ G d	d
 d
ejeZG dd dZdS )    N)_normalization_path
namespaces)easy_install   )_read_utf8_with_fallback)log)DistutilsOptionError)convert_pathc                   @   s|   e Zd ZdZdZejddg Zejdg ZdZdd Z	d	d
 Z
dddZedd ZdddZdddZdd Zdd ZdS )developzSet up package for developmentz%install package in 'development mode')	uninstalluzUninstall this source package)z	egg-path=Nz-Set the path to be used in the .egg-link filer   Fc                 C   s2   | j rd| _|   |   n|   |   d S )NT)r   multi_versionuninstall_linkuninstall_namespacesinstall_for_developmentwarn_deprecated_optionsself r   Y/root/parts/websockify/install/lib/python3.10/site-packages/setuptools/command/develop.pyrun   s   
zdevelop.runc                 C   s&   d | _ d | _t|  d | _d| _d S )N.)r   egg_pathr   initialize_options
setup_pathalways_copy_fromr   r   r   r   r   &   s
   

zdevelop.initialize_optionsreturnNc                 C   s  dd l }| d}|jg| _t|  |   |   | j	t

d t|jd }tj| j|| _|j| _| jd u rFtj|j| _t| j}ttj| j| j}||krbtd| |j|||tj|j|jd| _| | j| j| j| _d S )Nr   egg_infoz*.eggz	.egg-linkzA--egg-path must be a relative path from the install directory to project_name)pkg_resourcesget_finalized_commandegg_nameargsr   finalize_optionsexpand_basedirsexpand_dirspackage_indexscanglobr   filename_component_brokenospathjoininstall_diregg_linkegg_baser   abspathr   normpathr	   DistributionPathMetadatar   dist_resolve_setup_pathr   )r   r!   eiegg_link_fntargetr   r   r   r   r%   -   s>   




zdevelop.finalize_optionsc                 C   sj   |  tjdd}|tjkrd|dd  }ttj	|||}ttj}||kr3t
d|||S )z
        Generate a path from egg_base back to '.' where the
        setup script resides and ensure that path points to the
        setup path from $install_dir/$egg_path.
        /z../   zGCan't get a consistent path to setup script from installation directory)replacer,   seprstripcurdircountr   r3   r-   r.   r	   )r1   r/   r   path_to_setupresolvedr@   r   r   r   r7   V   s   
zdevelop._resolve_setup_pathc                 C   s   |  d | jddd |  d tjr| tj d t_|   td| j| j	 | j
sPt| jddd}|| jd	 | j  W d    n1 sKw   Y  | d | j| j  d S )
Nr   	build_extT)inplacezCreating %s (link to %s)wzutf-8)encoding
)run_commandreinitialize_command
setuptoolsbootstrap_install_fromr   install_namespacesr   infor0   r1   dry_runopenwriter   r   process_distributionr6   no_deps)r   fr   r   r   r   k   s   

zdevelop.install_for_developmentc                 C   s   t j| jr9td| j| j dd t| j D }|| j	g| j	| j
gfvr0td| d S | js9t | j | jsB| | j | jjrMtd d S d S )NzRemoving %s (link to %s)c                 S   s   g | ]}|  qS r   )r?   ).0liner   r   r   
<listcomp>   s    z*develop.uninstall_link.<locals>.<listcomp>z$Link points to %s: uninstall abortedz5Note: you must uninstall or replace scripts manually!)r,   r-   existsr0   r   rN   r1   r   
splitlinesr   r   warnrO   unlink
update_pthr6   distributionscripts)r   contentsr   r   r   r      s   zdevelop.uninstall_linkc                 C   sj   || j urt| |S | | | jjpg D ]}tjt	|}tj
|}t|}| |||| qd S N)r6   r   install_egg_scriptsinstall_wrapper_scriptsr]   r^   r,   r-   r2   r
   basenamer   install_script)r   r6   script_namescript_pathscript_textr   r   r   ra      s   

zdevelop.install_egg_scriptsc                 C   s   t |}t| |S r`   )VersionlessRequirementr   rb   r   r6   r   r   r   rb      s   zdevelop.install_wrapper_scriptsr   N)__name__
__module____qualname____doc__descriptionr   user_optionsboolean_optionscommand_consumes_argumentsr   r   r%   staticmethodr7   r   r   ra   rb   r   r   r   r   r      s$    	
)


r   c                   @   s0   e Zd ZdZdddZdefddZd	d
 ZdS )rh   a  
    Adapt a pkg_resources.Distribution to simply return the project
    name as the 'requirement' so that scripts will work across
    multiple versions.

    >>> from pkg_resources import Distribution
    >>> dist = Distribution(project_name='foo', version='1.0')
    >>> str(dist.as_requirement())
    'foo==1.0'
    >>> adapted_dist = VersionlessRequirement(dist)
    >>> str(adapted_dist.as_requirement())
    'foo'
    r   Nc                 C   s
   || _ d S r`   )_VersionlessRequirement__distri   r   r   r   __init__   s   
zVersionlessRequirement.__init__namec                 C   s   t | j|S r`   )getattrrt   )r   rv   r   r   r   __getattr__   s   z"VersionlessRequirement.__getattr__c                 C   s   | j S r`   r   r   r   r   r   as_requirement   s   z%VersionlessRequirement.as_requirementrj   )rk   rl   rm   rn   ru   strrx   ry   r   r   r   r   rh      s
    
rh   )r*   r,   rK   r   r   r   setuptools.command.easy_installr   unicode_utilsr   	distutilsr   distutils.errorsr	   distutils.utilr
   DevelopInstallerr   rh   r   r   r   r   <module>   s     