3
d=                 @   s8   d dl Z d dlZd dlZd dlZdZdd Zdd ZdS )    NzCOMMIT_INFO.txtc       	      C   s   t jj| t}t jj|s&td| tj }t|dd}|j	| W dQ R X |j
dd}|jdsnd|fS |j
dd	}|d
krd|fS tjdtjtj| dd}|j \}}|rd|j j fS dS )a  Get short form of commit hash given directory `pkg_path`

    There should be a file called 'COMMIT_INFO.txt' in `pkg_path`.  This is a
    file in INI file format, with at least one section: ``commit hash`` and two
    variables ``archive_subst_hash`` and ``install_hash``.  The first has a
    substitution pattern in it which may have been filled by the execution of
    ``git archive`` if this is an archive generated that way.  The second is
    filled in by the installation, if the installation is from a git archive.

    We get the commit hash from (in order of preference):

    * A substituted value in ``archive_subst_hash``
    * A written commit hash value in ``install_hash`
    * git's output, if we are in a git repository

    If all these fail, we return a not-found placeholder tuple

    Parameters
    ----------
    pkg_path : str
       directory containing package

    Returns
    -------
    hash_from : str
       Where we got the hash from - description
    hash_str : str
       short form of hash
    zMissing commit info file %szutf-8)encodingNzcommit hashZarchive_subst_hashz$Formatzarchive substitutionZinstall_hash installationzgit rev-parse --short HEADT)stdoutstderrcwdshell
repository(none found)<not found>)r
   r   )ospathjoinCOMMIT_INFO_FNAMEisfileIOErrorconfigparserRawConfigParseropen	read_fileget
startswith
subprocessPopenPIPEcommunicatedecodestrip)	pkg_pathpthZ
cfg_parserfpZarchive_substZinstall_substprocZrepo_commit_ r#   1/tmp/pip-build-7vycvbft/nipype/nipype/pkg_info.pypkg_commit_hash   s,    
r%   c       	      C   sp   t | \}}ddlm} ddl}ddl}ddl}ddl}ddl}t| |||t	j
t	jt	j|j|j|j|j|jdS )zReturn dict describing the context of this package

    Parameters
    ----------
    pkg_path : str
       path containing __init__.py for package

    Returns
    -------
    context : dict
       with named parameters of interest
       )VERSIONr   N)r   Zcommit_sourceZcommit_hashZnipype_versionsys_versionZsys_executablesys_platformZnumpy_versionZscipy_versionZnetworkx_versionZnibabel_versionZtraits_version)r%   infor'   networkxnibabelnumpyscipytraitsdictsysversion
executableplatform__version__)	r   srcZhshr'   r+   r,   r-   r.   r/   r#   r#   r$   get_pkg_infoD   s(    r7   )r   r   r1   r   r   r%   r7   r#   r#   r#   r$   <module>   s   9