diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..162e4d4 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +clean +build diff --git a/setup.py b/setup.py index b4264a6..be500b9 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,11 @@ +from __future__ import print_function from distutils.sysconfig import get_python_inc, get_python_lib import os import sys ################################################################### # build the extension -# + define_macros = [] undef_macros = [] @@ -26,7 +27,7 @@ include_dirs.extend(get_numpy_include_dirs()) define_macros.append(('USE_NUMPY', None)) undef_macros.append('USE_NUMARRAY') - print >>sys.stderr, "using numpy..." + print("using numpy...", file=sys.stderr) found_module = True # uncommenting the following line retains any previous ppgplot # package and installs this numpy-compatible version as @@ -37,72 +38,72 @@ if not found_module: try: - # Try to use the "numarray" module (2nd option) - # uncomment the following line to disable usage of numarray - #raise ImportError - from distutils.core import setup - from numarray.numarrayext import NumarrayExtension - make_extension = NumarrayExtension - define_macros.append(('USE_NUMARRAY', None)) - print >>sys.stderr, "using numarray..." - found_module = True - # uncommenting the following line retains any previous ppgplot - # package and installs this numpy-compatible version as - # the package ppgplot_numpy - #name = "ppgplot_numarray" + # Try to use the "numarray" module (2nd option) + # uncomment the following line to disable usage of numarray + #raise ImportError + from distutils.core import setup + from numarray.numarrayext import NumarrayExtension + make_extension = NumarrayExtension + define_macros.append(('USE_NUMARRAY', None)) + print("using numarray...", file=sys.stderr) + found_module = True + # uncommenting the following line retains any previous ppgplot + # package and installs this numpy-compatible version as + # the package ppgplot_numpy + #name = "ppgplot_numarray" except ImportError: - pass + pass if not found_module: try: - # Try to use the "Numeric" module (3rd option) - # uncomment the following line to disable usage of Numeric - #raise ImportError - from distutils.core import setup, Extension - make_extension = Extension - include_dirs.append( - os.path.join(get_python_inc(plat_specific=1), "Numeric")) - undef_macros.append('USE_NUMARRAY') - print >>sys.stderr, "using Numeric..." - found_module = True - # uncommenting the following line retains any previous ppgplot - # package and installs this numpy-compatible version as - # the package ppgplot_numpy - #name = "ppgplot_Numeric" + # Try to use the "Numeric" module (3rd option) + # uncomment the following line to disable usage of Numeric + #raise ImportError + from distutils.core import setup, Extension + make_extension = Extension + include_dirs.append( + os.path.join(get_python_inc(plat_specific=1), "Numeric")) + undef_macros.append('USE_NUMARRAY') + print("using Numeric...", file=sys.stderr) + found_module = True + # uncommenting the following line retains any previous ppgplot + # package and installs this numpy-compatible version as + # the package ppgplot_numpy + #name = "ppgplot_Numeric" except ImportError: - pass + pass if not found_module: - raise Exception, "None of numpy, numarray or Numeric found" + raise Exception("None of numpy, numarray or Numeric found") if os.name == "posix": - #libraries.append("png") + libraries.append("png") libraries.append("X11") libraries.append("m") # comment out g2c if compiling with gfortran (typical nowadays) # you may still need this if using an earlier fortran compiler # libraries.append("g2c") library_dirs.append("/usr/X11R6/lib/") - if os.environ.has_key("PGPLOT_DIR"): + if "PGPLOT_DIR" in os.environ: library_dirs.append(os.environ["PGPLOT_DIR"]) include_dirs.append(os.environ["PGPLOT_DIR"]) # locate Aquaterm dynamic library if running Mac OS X SCISOFT # (www.stecf.org/macosxscisoft/) elif os.environ.has_key("SCIDIR"): - libraries.append("aquaterm") + libraries.append("aquaterm") library_dirs.append(os.path.join(os.environ["SCIDIR"], 'lib')) else: print >>sys.stderr, "PGPLOT_DIR env var not defined!" else: - raise Exception, "os not supported" + raise Exception("os not supported") -ext_ppgplot = make_extension(name+'._ppgplot', - [os.path.join('src', '_ppgplot.c')], - include_dirs=include_dirs, - libraries=libraries, - library_dirs=library_dirs, - define_macros=define_macros, - extra_compile_args=extra_compile_args) +ext_ppgplot = make_extension("_"+name, + [os.path.join('src', '_ppgplot.c')], + include_dirs=include_dirs, + libraries=libraries, + library_dirs=library_dirs, + define_macros=define_macros, + extra_compile_args=extra_compile_args) diff --git a/src/_ppgplot.c b/src/_ppgplot.c index f9ece92..d5e05c2 100644 --- a/src/_ppgplot.c +++ b/src/_ppgplot.c @@ -1012,7 +1012,11 @@ PYF(pgcurs) cpgcurs(&x,&y,&ch); +#if PY_MAJOR_VERSION >= 3 + return(Py_BuildValue("ffC",x,y,ch)); +#else return(Py_BuildValue("ffc",x,y,ch)); +#endif } @@ -1029,7 +1033,11 @@ PYF(pgband) cpgband(mode,i,xref,yref,&x,&y,&ch); +#if PY_MAJOR_VERSION >= 3 + return(Py_BuildValue("ffC",x,y,ch)); +#else return(Py_BuildValue("ffc",x,y,ch)); +#endif } PYF(pgqcol) @@ -2241,22 +2249,55 @@ static PyMethodDef PpgMethods[] = { }; /************************************************************************/ +#if PY_MAJOR_VERSION >= 3 + static struct PyModuleDef PpgModule = { + PyModuleDef_HEAD_INIT, + .m_name = "_ppgplot", + .m_doc = "ppgplot", + .m_size = -1, + .m_methods = PpgMethods, + }; +#endif -void -init_ppgplot (void) -{ - PyObject *m, *d; - m = Py_InitModule("_ppgplot", PpgMethods); - d = PyModule_GetDict(m); - import_array(); - PpgIOErr = PyString_FromString("_ppgplot.ioerror"); - PpgTYPEErr = PyString_FromString("_ppgplot.typeerror"); - PpgMEMErr = PyString_FromString("_ppgplot.memerror"); - PyDict_SetItemString(d, "ioerror", PpgIOErr); - PyDict_SetItemString(d, "typeerror", PpgTYPEErr); - PyDict_SetItemString(d, "memerror", PpgMEMErr); +static PyObject * +moduleinit(void) +{ + PyObject *m; + +#if PY_MAJOR_VERSION >= 3 + m = PyModule_Create(&PpgModule); +#else + m = Py_InitModule3("_ppgplot", PpgMethods, NULL); +#endif + import_array(); + PyObject *d = PyModule_GetDict(m); + PpgIOErr = PyUnicode_FromString("_ppgplot.ioerror"); + PpgTYPEErr = PyUnicode_FromString("_ppgplot.typeerror"); + PpgMEMErr = PyUnicode_FromString("_ppgplot.memerror"); + PyDict_SetItemString(d, "ioerror", PpgIOErr); + PyDict_SetItemString(d, "typeerror", PpgTYPEErr); + PyDict_SetItemString(d, "memerror", PpgMEMErr); + + if (m == NULL) + return NULL; + + return m; } +#if PY_MAJOR_VERSION < 3 + PyMODINIT_FUNC + init_ppgplot(void) + { + moduleinit(); + } +#else + PyMODINIT_FUNC + PyInit__ppgplot(void) + { + return moduleinit(); + } +#endif + /************************************************************************/ /* End of _ppgplot.c */ /************************************************************************/