3
¿ÞL]ø  ã               @   sž   d dl mZ d dlmZ d dlmZmZ d dlZd dlZd dl	Z	d dl
mZ d dlZd dlmZ d dlmZ d dlZeZG dd	„ d	ejeƒZG d
d„ dƒZdS )é    )Úconvert_path)Úlog)ÚDistutilsErrorÚDistutilsOptionErrorN)Úsix)Úeasy_install)Ú
namespacesc               @   sv   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„ Zedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ ZdS )ÚdevelopzSet up package for developmentz%install package in 'development mode'Ú	uninstallÚuúUninstall this source packageú	egg-path=Nú-Set the path to be used in the .egg-link fileFc             C   s2   | j rd| _| jƒ  | jƒ  n| jƒ  | jƒ  d S )NT)r
   Zmulti_versionÚuninstall_linkZuninstall_namespacesÚinstall_for_developmentZwarn_deprecated_options)Úself© r   ú@/tmp/pip-build-69lrc5qx/setuptools/setuptools/command/develop.pyÚrun    s    
zdevelop.runc             C   s&   d | _ d | _tj| ƒ d | _d| _d S )NÚ.)r
   Úegg_pathr   Úinitialize_optionsÚ
setup_pathZalways_copy_from)r   r   r   r   r   )   s
    
zdevelop.initialize_optionsc             C   s  | j dƒ}|jr,d}|j|jf}t|| ƒ‚|jg| _tj| ƒ | jƒ  | j	ƒ  | j
jtjdƒƒ |jd }tjj| j|ƒ| _|j| _| jd kr tjj|jƒ| _tj| jƒ}tjtjj| j| jƒƒ}||krØtd| ƒ‚tj|tj|tjj|jƒƒ|jd�| _| j| j| j| jƒ| _d S )NÚegg_infoz-Please rename %r to %r before using 'develop'z*.eggz	.egg-linkzA--egg-path must be a relative path from the install directory to )Úproject_name)Úget_finalized_commandZbroken_egg_infor   r   Úegg_nameÚargsr   Úfinalize_optionsÚexpand_basedirsÚexpand_dirsZpackage_indexÚscanÚglobÚosÚpathÚjoinÚinstall_dirÚegg_linkÚegg_baser   ÚabspathÚpkg_resourcesÚnormalize_pathr   ÚDistributionÚPathMetadataÚdistÚ_resolve_setup_pathr   )r   ÚeiÚtemplater   Zegg_link_fnÚtargetr   r   r   r   r   0   s<    




zdevelop.finalize_optionsc             C   sn   | j tjdƒjdƒ}|tjkr0d|jdƒd  }tjtjj	|||ƒƒ}|tjtjƒkrjt
d|tjtjƒƒ‚|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*   r+   r$   r%   r   )r(   r&   r   Zpath_to_setupZresolvedr   r   r   r/   Z   s    
zdevelop._resolve_setup_pathc             C   sH  t jržt| jddƒrž| jddd� | jdƒ | jdƒ}tj|j	ƒ}| jd|d� | jdƒ | jddd� | jdƒ | jdƒ}|| _
|| j_tj||jƒ| j_n"| jdƒ | jdd	d� | jdƒ | jƒ  tjrà| jtjƒ d t_| jƒ  tjd
| j| jƒ | j�s0t| jdƒ�}|j| j
d | j ƒ W d Q R X | jd | j| j ƒ d S )NZuse_2to3FÚbuild_pyr   )Zinplacer   )r(   Ú	build_extr4   zCreating %s (link to %s)ÚwÚ
)r   ÚPY3ÚgetattrÚdistributionÚreinitialize_commandÚrun_commandr   r*   r+   Ú	build_libr   r.   Úlocationr-   r   Ú	_providerZinstall_site_pyÚ
setuptoolsZbootstrap_install_fromr   Zinstall_namespacesr   Úinfor'   r(   Údry_runÚopenÚwriter   Zprocess_distributionÚno_deps)r   Zbpy_cmdZ
build_pathZei_cmdÚfr   r   r   r   n   s6    






 zdevelop.install_for_developmentc             C   s¢   t jj| jƒrztjd| j| jƒ t| jƒ}dd„ |D ƒ}|jƒ  || j	g| j	| j
gfkrhtjd|ƒ d S | jszt j| jƒ | jsŒ| j| jƒ | jjržtjdƒ d S )NzRemoving %s (link to %s)c             S   s   g | ]}|j ƒ ‘qS r   )r7   )Ú.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$   Úexistsr'   r   rG   r(   rI   Úcloser   r   ÚwarnrH   ÚunlinkZ
update_pthr.   r@   Úscripts)r   Zegg_link_fileÚcontentsr   r   r   r   ž   s    
zdevelop.uninstall_linkc             C   s„   || j k	rtj| |ƒS | j|ƒ x^| jjp,g D ]N}tjjt	|ƒƒ}tjj
|ƒ}tj|ƒ�}|jƒ }W d Q R X | j||||ƒ q.W d S )N)r.   r   Úinstall_egg_scriptsÚinstall_wrapper_scriptsr@   rT   r#   r$   r)   r   ÚbasenameÚiorI   ÚreadZinstall_script)r   r.   Úscript_nameZscript_pathÚstrmÚscript_textr   r   r   rV   °   s    

zdevelop.install_egg_scriptsc             C   s   t |ƒ}tj| |ƒS )N)ÚVersionlessRequirementr   rW   )r   r.   r   r   r   rW   Â   s    zdevelop.install_wrapper_scripts)r
   r   r   )r   Nr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Údescriptionr   Úuser_optionsÚboolean_optionsZcommand_consumes_argumentsr   r   r   Ústaticmethodr/   r   r   rV   rW   r   r   r   r   r	      s   	*0r	   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	r^   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'
    c             C   s
   || _ d S )N)Ú_VersionlessRequirement__dist)r   r.   r   r   r   Ú__init__Ö   s    zVersionlessRequirement.__init__c             C   s   t | j|ƒS )N)r?   rg   )r   Únamer   r   r   Ú__getattr__Ù   s    z"VersionlessRequirement.__getattr__c             C   s   | j S )N)r   )r   r   r   r   Úas_requirementÜ   s    z%VersionlessRequirement.as_requirementN)r_   r`   ra   rb   rh   rj   rk   r   r   r   r   r^   Ç   s   r^   )Údistutils.utilr   Ú	distutilsr   Údistutils.errorsr   r   r#   r"   rY   Zsetuptools.externr   r*   Zsetuptools.command.easy_installr   rF   r   ÚtypeZ__metaclass__ZDevelopInstallerr	   r^   r   r   r   r   Ú<module>   s    6