U
    ZÊ¹j÷  ã                   @   sf   d Z ddlZddlZdZdZdd„ Zeƒ r2dZdZe dej¡Zdd„ Z	ddddd	di d
fdd„Z
dS )z4Tools to assist importing optional external modules.é    Nc                  C   s4   dd l } |  dd¡}|dkr$t|ƒS td| ƒ‚d S )Nr   ZSYMPY_DEBUGÚFalse)ÚTruer   z&unrecognized value for SYMPY_DEBUG: %s)ÚosÚgetenvÚevalÚRuntimeError)r   Z	debug_str© r   úY/var/www/html/bwave/python/venv/lib/python3.8/site-packages/sympy/external/importtools.pyÚ__sympy_debug   s    ÿr
   Tz(\d+ | [a-z]+ | \.)c              	   C   sT   g }t  | ¡D ]<}|r|dkrzt|ƒ}W n tk
r>   Y nX | |¡ qt|ƒS )NÚ.)Ú_component_reÚsplitÚintÚ
ValueErrorÚappendÚtuple)ZvstringÚ
componentsÚxr   r   r	   Úversion_tuple!   s    r   Ú__version__r   c	              
   C   sÀ  t dk	rt n|pd}tdk	r tn|p&d}ddl}	|rjtj|k rj|rf|	jd| d tt|ƒ¡f t	dd� dS zHt
| f|Ž}
| d	d
¡}|D ]&}|dkrˆ|
jdkrˆt
| d | ƒ qˆW nv tk
rà   |rÚ|	jd|  t	dd� Y dS  |k
�r( } z*|�r|	jd| t|ƒf dd� W Y ¢dS d}~X Y nX |�r¼t|
|ƒ}|dk	�rL||Ž }t|ƒt|ƒk �r¼|�r¸t|tƒ�rv|}n*t|ttfƒ�r˜d tt|ƒ¡}nt|ƒ}|	jd| |f t	dd� dS |
S )a¨  
    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,))

    NTFr   z:Python version is too old to use %s (%s or newer required)r   é   )Ú
stacklevelÚfromlistr   ÚcollectionsZ
matplotlibz%s module is not installedz %s module could not be used (%s)z3%s version is too old to use (%s or newer required))ÚWARN_OLD_VERSIONÚWARN_NOT_INSTALLEDÚwarningsÚsysÚversion_infoÚwarnÚjoinÚmapÚstrÚUserWarningÚ
__import__ÚgetÚ__name__ÚImportErrorÚreprÚgetattrr   Ú
isinstancer   Úlist)ÚmoduleZmin_module_versionZmin_python_versionZwarn_not_installedZwarn_old_versionZmodule_version_attrZmodule_version_attr_call_argsZimport_kwargsZcatchr   ÚmodÚ	from_listZsubmodÚeZ
modversionZverstrr   r   r	   Úimport_module0   sr    Oÿÿ
 ÿÿ ýÿþ

ÿ þr0   )Ú__doc__r   Úrer   r   r
   ÚcompileÚVERBOSEr   r   r0   r   r   r   r	   Ú<module>   s$      ý