B
    @\5                 @   s   d Z ddlmZmZmZmZ ddlZeeZ	ddl
mZ ddlZddlmZmZ ddlmZ ddlmZ d	Zd
d Zdd ZdddZdS )z& Utilities for checking dependencies

    )absolute_importdivisionprint_functionunicode_literalsN)import_module)PopenPIPE)Version   )settings)import_optionalimport_requireddetect_phantomjsc             C   sH   yt | S  tk
r   Y n( tk
rB   d| }t| Y nX dS )a   Attempt to import an optional dependency.

    Silently returns None if the requested module is not available.

    Args:
        mod_name (str) : name of the optional module to try to import

    Returns:
        imported module or None, if import fails

    z%Failed to import optional module `{}`N)r   ImportError	ExceptionformatlogZ	exception)mod_namemsg r   6lib/python3.7/site-packages/bokeh/util/dependencies.pyr   2   s    
r   c             C   s*   yt | S  tk
r$   t|Y nX dS )aY   Attempt to import a required dependency.

    Raises a RuntimeError if the requested module is not available.

    Args:
        mod_name (str) : name of the required module to try to import
        error_msg (str) : error message to raise when the module is missing

    Returns:
        imported module

    Raises:
        RuntimeError

    N)r   r   RuntimeError)r   Z	error_msgr   r   r   r   F   s    r   2.1c             C   s   t  dk	rt  }nttdr0tdp,d}nd}y~t|dgttd}|  | }t	|d dkr~t
d|d d	 t| }t|d d	}||k rt
d
||f W n tk
r   t
dY nX |S )z Detect if PhantomJS is avaiable in PATH, at a minimum version.

    Args:
        version (str, optional) :
            Required minimum version for PhantomJS (mostly for testing)

    Returns:
        str, path to PhantomJS

    NwhichZ	phantomjsz	--version)stdoutstderr   r   z,Error encountered in PhantomJS detection: %rutf8z=PhantomJS version to old. Version>=%s required, installed: %szPhantomJS is not present in PATH or BOKEH_PHANTOMJS_PATH. Try "conda install phantomjs" or             "npm install -g phantomjs-prebuilt")r   phantomjs_pathhasattrshutilr   r   r   waitZcommunicatelenr   decodeVOSError)versionr   procoutZrequiredZ	installedr   r   r   r   [   s&    

r   )r   )__doc__Z
__future__r   r   r   r   ZloggingZ	getLogger__name__r   	importlibr   r    
subprocessr   r   Zpackaging.versionr	   r$   r   __all__r   r   r   r   r   r   r   <module>	   s   
	