B
    3¢\3
  ã               @   sl   d Z ddlm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„ Zdd„ Zd	d
„ ZdS )zQ
Utilities for getting information about Jupyter and the system it's running in.
é    )Úabsolute_importN)Ú	py3compatÚencodingc             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.gitZgitz	rev-parsez--shortZHEAD)ÚstdoutÚstderrÚcwdZ
repositoryÚascii)Ú r	   )ÚosÚpathÚexistsÚjoinÚ
subprocessÚPopenÚPIPEZcommunicateÚOSErrorÚstripÚdecodeÚdirname)Úpkg_pathÚpZcur_pathZpar_pathÚprocZrepo_commitÚ_© r   ú0lib/python3.7/site-packages/notebook/_sysinfo.pyÚpkg_commit_hash   s&    

r   c             C   s8   t | ƒ\}}ttj| ||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_executableZsys_platformÚplatformZos_nameZdefault_encoding)r   ÚdictÚnotebookÚ__version__ÚsysÚversionÚ
executabler   r
   Únamer   ZDEFAULT_ENCODING)r   ÚsrcZhshr   r   r   Úpkg_infoC   s    r&   c           	   C   s,   t j} |  |  |  |  tj¡¡¡¡}t|ƒS )z5Return useful information about the system as a dict.)	r
   r   Úrealpathr   Úabspathr   r   Ú__file__r&   )r   r   r   r   r   Úget_sys_info^   s    r*   )Ú__doc__Z
__future__r   r
   r   Zpprintr!   r   Zipython_genutilsr   r   r   r   r&   r*   r   r   r   r   Ú<module>   s   .