B
    7‹dú	  ã               @   sl   d Z ddlZddlZddlZddlZddlZddlmZmZ ddl	Z	ddl	m
Z
 dd„ Zdd„ Zd	d
„ ZdS )zQ
Utilities for getting information about Jupyter and the system it's running in.
é    N)Ú	py3compatÚencoding)Ú_versionc             C   s¢   t j}d}| }xŽ||krœ|}| | |d¡¡ry.tjddddgtjtj| d}| ¡ \}}W n tk
rt   d}Y nX |rŒd| 	¡  
d	¡fS d
S | |¡}qW d
S )aÂ  Get short form of commit hash given directory `pkg_path`

    We get the commit hash from git if it's a repo.

    If this fail, we return a not-found placeholder tuple

    Parameters
    ----------
    pkg_path : str
       directory containing package
       only used for getting commit from active repo

    Returns
    -------
    hash_from : str
       Where we got the hash from - description
    hash_str : str
       short form of hash
    Nz.gitÚgitz	rev-parsez--shortÚHEAD)ÚstdoutÚstderrÚcwdÚ
repositoryÚascii)Ú r   )ÚosÚpathÚexistsÚjoinÚ
subprocessÚPopenÚPIPEÚcommunicateÚOSErrorÚstripÚdecodeÚdirname)Úpkg_pathÚpZcur_pathZpar_pathÚprocZrepo_commitÚ_© r   ú_/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/nbclassic/_sysinfo.pyÚpkg_commit_hash   s&    

r   c             C   s6   t | ƒ\}}tt| ||tjtjtjt ¡ tjt	j
d
S )zíReturn 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
    )
Znotebook_versionZnotebook_pathZcommit_sourceZcommit_hashÚsys_versionZsys_executableÚsys_platformÚplatformÚos_nameZdefault_encoding)r   Údictr   ÚsysÚversionÚ
executabler"   r   Únamer   ZDEFAULT_ENCODING)r   ÚsrcZhshr   r   r   Úpkg_infoA   s    r*   c           	   C   s,   t j} |  |  |  |  tj¡¡¡¡}t|ƒS )z5Return useful information about the system as a dict.)	r   r   Úrealpathr   Úabspathr   Ú	nbclassicÚ__file__r*   )r   r   r   r   r   Úget_sys_info\   s    r/   )Ú__doc__r   r"   Úpprintr%   r   Zipython_genutilsr   r   r-   r   r   r*   r/   r   r   r   r   Ú<module>   s   .