ó
mÜJ]c           @` s½   d  Z  d d l m Z m Z m Z m Z d d l Z e j 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 „  Z d „  Z d d „ Z d S(   u&    Utilities for checking dependencies

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   import_module(   t   Popent   PIPE(   t   Versioni   (   t   settingsu   import_optionalu   import_requiredu   detect_phantomjsc         C` sR   y t  |  ƒ SWn= t k
 r! n- t k
 rM d j |  ƒ } t j | ƒ n Xd S(   u   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

    u%   Failed to import optional module `{}`N(   R   t   ImportErrort	   Exceptiont   formatt   logt	   exception(   t   mod_namet   msg(    (    s6   lib/python2.7/site-packages/bokeh/util/dependencies.pyt   import_optional2   s    c         C` s2   y t  |  ƒ SWn t k
 r- t | ƒ ‚ n Xd S(   uY   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	   t   RuntimeError(   R   t	   error_msg(    (    s6   lib/python2.7/site-packages/bokeh/util/dependencies.pyt   import_requiredF   s    u   2.1c         C` s*  t  j ƒ  d k	 r! t  j ƒ  } n- t t d ƒ rH t j d ƒ pB d } n d } y¸ t | d g d t d t ƒ} | j ƒ  | j	 ƒ  } t
 | d ƒ d k r» t d | d j d	 ƒ ƒ ‚ n  t |  ƒ } t | d j d	 ƒ ƒ } | | k  rt d
 | | f ƒ ‚ n  Wn t k
 r%t d ƒ ‚ n X| S(   uç    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

    u   whichu	   phantomjsu	   --versiont   stdoutt   stderri   i    u,   Error encountered in PhantomJS detection: %ru   utf8u=   PhantomJS version to old. Version>=%s required, installed: %suŠ   PhantomJS is not present in PATH or BOKEH_PHANTOMJS_PATH. Try "conda install phantomjs" or             "npm install -g phantomjs-prebuilt"N(   R   t   phantomjs_patht   Nonet   hasattrt   shutilt   whichR   R   t   waitt   communicatet   lenR   t   decodet   Vt   OSError(   t   versionR   t   proct   outt   requiredt	   installed(    (    s6   lib/python2.7/site-packages/bokeh/util/dependencies.pyt   detect_phantomjs[   s&    
 (   u   import_optionalu   import_requiredu   detect_phantomjs(   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggert   __name__R   t	   importlibR   R   t
   subprocessR   R   t   packaging.versionR   R   R   t   __all__R   R   R&   (    (    (    s6   lib/python2.7/site-packages/bokeh/util/dependencies.pyt   <module>	   s   "  		