diff --git a/islpy/__init__.py b/islpy/__init__.py index ec1a5ab913d605de5a1e3e222bd0a38b14a1ae45..c46c43a2eb2cf4926e6ffc3c656a0800cf6a39cf 100644 --- a/islpy/__init__.py +++ b/islpy/__init__.py @@ -1,3 +1,24 @@ +from __future__ import division + + +# {{{ check gmpy version + +def _check_gmpy_version(): + import gmpy + gmpy_ver_num = tuple(int(s) for s in gmpy.version().split(".")) + + import sys + if sys.version_info >= (3,) and gmpy_ver_num < (1, 17): + raise ImportError("gmpy 1.17 or newer is required for " + "Python 3 support") + +try: + _check_gmpy_version() +except ValueError: + pass + +# }}} + from islpy._isl import * # noqa from islpy.version import * # noqa diff --git a/setup.py b/setup.py index 0e88db284a2550015879a3eb5cd5d10ee49a6dd9..611cab1398b6b54ab0afe9b78ace960f541124e4 100644 --- a/setup.py +++ b/setup.py @@ -127,7 +127,7 @@ def main(): install_requires=[ "pytest>=2", - "gmpy>=1,<2", + "gmpy>=1.17,<2", # "Mako>=0.3.6", ], ext_modules=[ diff --git a/src/wrapper/gmpy.h b/src/wrapper/gmpy.h index 276c560a4d5b461226719248b2a873a7c584d3bd..57476def05c364808ff00ccd04c62770ce17d771 100644 --- a/src/wrapper/gmpy.h +++ b/src/wrapper/gmpy.h @@ -136,6 +136,7 @@ static Pympf_new_RETURN Pympf_new Pympf_new_PROTO; static Pympf_dealloc_RETURN Pympf_dealloc Pympf_dealloc_PROTO; static Pympf_convert_arg_RETURN Pympf_convert_arg Pympf_convert_arg_PROTO; +#if PY_MAJOR_VERSION < 3 #define export_gmpy(m) { \ PyObject *d; \ static void *Pygmpy_API[Pygmpy_API_pointers]; \ @@ -159,6 +160,7 @@ static Pympf_convert_arg_RETURN Pympf_convert_arg Pympf_convert_arg_PROTO; d = PyModule_GetDict(m);\ PyDict_SetItemString(d, "_C_API", c_api_object);\ } +#endif #else /* This section is used in other C-coded modules that use gmpy's API */ @@ -194,6 +196,7 @@ static void **Pygmpy_API; #define Pympf_convert_arg \ (*(Pympf_convert_arg_RETURN (*)Pympf_convert_arg_PROTO) Pygmpy_API[Pympf_convert_arg_NUM]) +#if PY_MAJOR_VERSION < 3 #define import_gmpy() \ { \ PyObject *module = PyImport_ImportModule("gmpy");\ @@ -205,7 +208,14 @@ static void **Pygmpy_API; } \ } \ } - +#else +static int +import_gmpy(void) +{ + Pygmpy_API = (void **)PyCapsule_Import("gmpy._C_API", 0); + return (Pygmpy_API != NULL) ? 0 : -1; +} +#endif #endif #ifdef __cplusplus