Skip to content

Commit

Permalink
This modifies the setup.py to install the Nio module in the directory
Browse files Browse the repository at this point in the history
'PyNIO' under <whatever>/site-packages.
It also tries to make the build more portable by changing the form of the
arrayobject include to:
#include <Numeric/arrayobject.h>
since apparently the setup mechanism automatically has the site-packages
directory in the include path. This was recommended by the on-line Python docs.
I also commented out the special compile flags I had enabled for
development.
  • Loading branch information
dbrown committed Sep 8, 2005
1 parent 437d0ee commit 80b4e6c
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
1 change: 1 addition & 0 deletions PyNIO.pth
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
PyNIO
1 change: 1 addition & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#
23 changes: 14 additions & 9 deletions niomodule.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#include "netcdf.h"
#include "Python.h"
#include "nio.h"
#include "arrayobject.h"
#include <Numeric/arrayobject.h>
#include <sys/stat.h>
#include <unistd.h>

Expand All @@ -34,6 +34,7 @@ staticforward PyNIOVariableObject *nio_variable_new(

static PyObject *NIOError;

#if 0
static char *nio_errors[] = {
"No Error",
"Not a nio id",
Expand Down Expand Up @@ -61,6 +62,7 @@ static char *nio_errors[] = {
"", "", "", "", "", "", "", "", "",
"XDR error" /* 32 */
};
#endif

/* Set error string */
static void
Expand Down Expand Up @@ -212,9 +214,9 @@ static void
collect_attributes(int fileid, int varid, PyObject *attributes, int nattrs)
{
NclFile file = (NclFile) fileid;
NclFileAttInfoList *att_list;
NclFileAttInfoList *att_list = NULL;
NclFAttRec *att;
NclFVarRec *fvar;
NclFVarRec *fvar = NULL;
char *name;
int length;
int py_type;
Expand All @@ -230,6 +232,10 @@ collect_attributes(int fileid, int varid, PyObject *attributes, int nattrs)
name = NrmQuarkToString(att->att_name_quark);
md = _NclFileReadAtt(file,att->att_name_quark,NULL);
}
else if (! (att_list && fvar)) {
PyErr_SetString(NIOError, "internal attribute or file variable error");
return;
}
else {
att = att_list->the_att;
name = NrmQuarkToString(att->att_name_quark);
Expand Down Expand Up @@ -263,7 +269,6 @@ collect_attributes(int fileid, int varid, PyObject *attributes, int nattrs)
}
}
}
/* _NclDestroyObj(NclObj)md); */
}
}
#if 0
Expand Down Expand Up @@ -305,7 +310,7 @@ set_attribute(PyNIOFileObject *file, int varid, PyObject *attributes,
NclFile nfile = (NclFile) file->id;
NhlErrorTypes ret;
NclMultiDValData md;
PyArrayObject *array;
PyArrayObject *array = NULL;

if (!value) {
/* delete attribute */
Expand Down Expand Up @@ -362,7 +367,7 @@ set_attribute(PyNIOFileObject *file, int varid, PyObject *attributes,
if (PyString_Check(value)) {
PyDict_SetItemString(attributes, name, value);
}
else {
else if (array) {
PyDict_SetItemString(attributes, name, (PyObject *)array);
}
}
Expand Down Expand Up @@ -606,12 +611,12 @@ PyNIOVariableObject *
PyNIOFile_CreateVariable( PyNIOFileObject *file, char *name,
int typecode, char **dimension_names, int ndim)
{
int *dimids;
PyNIOVariableObject *variable;
int i,id;

if (check_if_open(file, 1)) {
PyNIOVariableObject *variable;
int i,id;
NclFile nfile = (NclFile) file->id;
int *dimids = NULL;
NrmQuark *qdims = NULL;
NhlErrorTypes ret;
NrmQuark qvar;
Expand Down
27 changes: 18 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,23 @@

extra_lib_paths = '/sw/lib'
ncarg_root = os.getenv("NCARG_ROOT") + '/'
python_include = os.path.join(sys.prefix,'include','python'+sys.version[:3]) + '/'
#python_include = os.path.join(sys.prefix,'include','python'+sys.version[:3]) + '/'
ncl_src_dir = '../ni/src/ncl/'
pkgs_pth = os.path.join(sys.exec_prefix, 'lib', 'python'+sys.version[:3],
'site-packages')

module1 = Extension('Nio',
define_macros = [ ('CCOPTIONS','-g'), ('NDEBUG','0') ],
extra_link_args = [ '-g' ],
extra_compile_args = [ '-O0' ],

module1 = Extension('PyNIO/Nio',
# define_macros = [ ('CCOPTIONS','-g'), ('NDEBUG','0') ],
# extra_link_args = [ '-g' ],
# extra_compile_args = [ '-O0' ],
include_dirs = [ncl_src_dir,
ncarg_root + 'include',
python_include + 'Numeric'],
ncarg_root + 'include'],
libraries = ['nio','mfhdf', 'df', 'jpeg','z','netcdf','g2c'],
library_dirs = [ncarg_root + 'lib',
extra_lib_paths],
sources = ['niomodule.c'])
sources = ['niomodule.c']
)

setup (name = 'Nio',
version = '0.1.1b1',
Expand All @@ -27,4 +30,10 @@
long_description = '''
Enables NetCDF-like access for NetCDF (rw), HDF (rw), GRIB (r), and CCM (r) data files
''',
ext_modules = [module1])
package_dir = {'PyNIO' : ''},
ext_modules = [module1],
data_files = [ (pkgs_pth, ["PyNIO.pth"]),
(pkgs_pth + '/PyNIO/test', ["test/nio_demo.py"])
]
)

0 comments on commit 80b4e6c

Please sign in to comment.