Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

compatibility for Python 3 #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

clean
build
87 changes: 44 additions & 43 deletions setup.py
Original file line number Diff line number Diff line change
@@ -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 = []
Expand All @@ -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
Expand All @@ -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)



Expand Down
67 changes: 54 additions & 13 deletions src/_ppgplot.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
}


Expand All @@ -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)
Expand Down Expand Up @@ -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 */
/************************************************************************/
Expand Down