On Fri, Feb 8, 2013 at 5:21 PM, Aaron Meurer <notifications@github.com>wrote:

> In sympy/core/compatibility.py:
>
> > +# Minimum version of gmpy changed to 1.13 to allow a single code base to also
> > +# work with gmpy2.
> > +
> > +HAS_GMPY = 0
> > +
> > +try:
> > +    import gmpy2 as gmpy
> > +    if gmpy.version() >= '2.0.0b4':
> > +            HAS_GMPY = 2
> > +except ImportError:
> > +    pass
> > +
> > +try:
> > +    import gmpy
> > +    if gmpy.version() >= '1.13':
> > +        HAS_GMPY = 1
>
> Also, we probably will want a way to use the non-preferred version if both
> are installed, for testing purposes.
>
If both are installed, we should prefer gmpy2 since there are some corner
cases on 64-bit Windows that will not be fixed in gmpy. mpmath is
configured to prefer gmpy2, too.

Regarding testing different versions, how about adding another ground type
called gmpy1? If it is specified, no attempt will be made to load gmpy2.

The following code should work for the detection. I also skip import
gmpy/gmpy2 entirely if python is specified as a ground type. And if gmpy2
is found, then gmpy isn't imported.

def _getenv(key, default=None):
    from os import getenv
    return getenv(key, default)

GROUND_TYPES = _getenv('SYMPY_GROUND_TYPES', 'auto').lower()

HAS_GMPY = 0

if GROUND_TYPES != 'python':
    try:
        try:
            if GROUND_TYPES == 'gmpy1':
                GROUND_TYPES = 'gmpy'
                raise ImportError
            import gmpy2 as gmpy
            if gmpy.version() >= '2.0.0.b4':
                HAS_GMPY = 2
        except ImportError:
            try:
                import gmpy
                if gmpy.version() >= '1.13':
                    HAS_GMPY = 1
            except ImportError:
                raise ImportError
    except:
        pass

if GROUND_TYPES == 'auto':
    if HAS_GMPY:
        GROUND_TYPES = 'gmpy'
    else:
        GROUND_TYPES = 'python'

if GROUND_TYPES == 'gmpy' and not HAS_GMPY:
    from warnings import warn
    warn("gmpy library is not installed, switching to 'python' ground
types")
    GROUND_TYPES = 'python'

casevh

 —
> Reply to this email directly or view it on GitHub<https://github.com/sympy/sympy/pull/1762/files#r2952073>..
>
>