ó
~9­\c        	   @  s   d  Z  d d l m Z m Z d d l Z d d l m Z d Z d Z	 d   Z
 e
   re e Z	 e Z n  d d d d d d i  d d  Z d S(	   s4   Tools to assist importing optional external modules.i˙˙˙˙(   t   print_functiont   divisionN(   t   StrictVersionc          C  sH   d d  l  }  |  j d d  } | d k r4 t |  St d |   d  S(   Ni˙˙˙˙t   SYMPY_DEBUGt   Falset   Trues&   unrecognized value for SYMPY_DEBUG: %s(   R   R   (   t   ost   getenvt   evalt   RuntimeError(   R   t	   debug_str(    (    s9   lib/python2.7/site-packages/sympy/external/importtools.pyt   __sympy_debug   s    
t   __version__c	         C  s~  t  d k	 r t  n	 | p t } t d k	 r0 t n	 | p9 t } d d l }	 | r t j | k  r | r |	 j d |  d j	 t
 t |   f t d d n  d Sn  |  d k rž d t j k rž d Syi t |  |  }
 | j d	 t    } x> | D]6 } | d
 k rě |
 j d k rě t |  d |  qě qě WWnt t k
 r^| rZ|	 j d |  t d d n  d S| k
 r} | r|	 j d |  t |  f d d n  d SX| rzt |
 |  } | d k	 rÎ| |   } n  t |  t |  k  rz| rsd d l m } t | |  r| } n< t | t t f  rDd j	 t
 t |   } n t |  } |	 j d |  | f t d d n  d Sn  |
 S(   są  
    Import and return a module if it is installed.

    If the module is not installed, it returns None.

    A minimum version for the module can be given as the keyword argument
    min_module_version.  This should be comparable against the module version.
    By default, module.__version__ is used to get the module version.  To
    override this, set the module_version_attr keyword argument.  If the
    attribute of the module to get the version should be called (e.g.,
    module.version()), then set module_version_attr_call_args to the args such
    that module.module_version_attr(*module_version_attr_call_args) returns the
    module's version.

    If the module version is less than min_module_version using the Python <
    comparison, None will be returned, even if the module is installed. You can
    use this to keep from importing an incompatible older version of a module.

    You can also specify a minimum Python version by using the
    min_python_version keyword argument.  This should be comparable against
    sys.version_info.

    If the keyword argument warn_not_installed is set to True, the function will
    emit a UserWarning when the module is not installed.

    If the keyword argument warn_old_version is set to True, the function will
    emit a UserWarning when the library is installed, but cannot be imported
    because of the min_module_version or min_python_version options.

    Note that because of the way warnings are handled, a warning will be
    emitted for each module only once.  You can change the default warning
    behavior by overriding the values of WARN_NOT_INSTALLED and WARN_OLD_VERSION
    in sympy.external.importtools.  By default, WARN_NOT_INSTALLED is False and
    WARN_OLD_VERSION is True.

    This function uses __import__() to import the module.  To pass additional
    options to __import__(), use the __import__kwargs keyword argument.  For
    example, to import a submodule A.B, you must pass a nonempty fromlist option
    to __import__.  See the docstring of __import__().

    This catches ImportError to determine if the module is not installed.  To
    catch additional errors, pass them as a tuple to the catch keyword
    argument.

    Examples
    ========

    >>> from sympy.external import import_module

    >>> numpy = import_module('numpy')

    >>> numpy = import_module('numpy', min_python_version=(2, 7),
    ... warn_old_version=False)

    >>> numpy = import_module('numpy', min_module_version='1.5',
    ... warn_old_version=False) # numpy.__version__ is a string

    >>> # gmpy does not have __version__, but it does have gmpy.version()

    >>> gmpy = import_module('gmpy', min_module_version='1.14',
    ... module_version_attr='version', module_version_attr_call_args=(),
    ... warn_old_version=False)

    >>> # To import a submodule, you must pass a nonempty fromlist to
    >>> # __import__().  The values do not matter.
    >>> p3 = import_module('mpl_toolkits.mplot3d',
    ... __import__kwargs={'fromlist':['something']})

    >>> # matplotlib.pyplot can raise RuntimeError when the display cannot be opened
    >>> matplotlib = import_module('matplotlib',
    ... __import__kwargs={'fromlist':['pyplot']}, catch=(RuntimeError,))

    i˙˙˙˙Ns:   Python version is too old to use %s (%s or newer required)t   .t
   stackleveli   t   numpyt   __pypy__t   fromlistt   collectionst
   matplotlibs   %s module is not installeds    %s module could not be used (%s)(   t   string_typess3   %s version is too old to use (%s or newer required)(   t   WARN_OLD_VERSIONt   NoneR   t   WARN_NOT_INSTALLEDR   t   warningst   syst   version_infot   warnt   joint   mapt   strt   UserWarningt   builtin_module_namest
   __import__t   gett   tuplet   __name__t   ImportErrort   reprt   getattrR   t   core.compatibilityR   t
   isinstancet   list(   t   modulet   min_module_versiont   min_python_versiont   warn_not_installedt   warn_old_versiont   module_version_attrt   module_version_attr_call_argst   __import__kwargst   catchR   t   modt	   from_listt   submodt   et
   modversionR   t   verstr(    (    s9   lib/python2.7/site-packages/sympy/external/importtools.pyt   import_module    s`    O	

		
(    (   t   __doc__t
   __future__R    R   R   t   distutils.versionR   R   R   R   R   R   R:   (    (    (    s9   lib/python2.7/site-packages/sympy/external/importtools.pyt   <module>   s   			