a
    ø£Be¦	  ã                   @   sH   d Z ddlZddlZddlZddl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.
é    Nc                 C   s˜   t j}d}| }||kr”|}| | |d¡¡rˆz*tjg d¢tjtj| d�}| ¡ \}}W n tyl   d}Y n0 |r„d| 	¡  
d¡fS dS | |¡}q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   úZ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/jupyter_server/_sysinfo.pyÚpkg_commit_hash   s*    ü
r   c              
   C   s2   t | ƒ\}}tj| ||tjtjtjt ¡ 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jupyter_server_versionZjupyter_server_pathZcommit_sourceZcommit_hashÚsys_versionZsys_executableÚsys_platformÚplatformÚos_name)	r   Újupyter_serverÚ__version__ÚsysÚversionÚ
executabler   r
   Úname)r   ÚsrcZhshr   r   r   Úpkg_info>   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_infoY   s    r,   )	Ú__doc__r
   r   r   r#   r!   r   r(   r,   r   r   r   r   Ú<module>   s   0