Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing for new distutils

  • Loading branch information...
commit 14db4193112ecc5930154af860228562132e3b48 1 parent c5b2e41
Travis Oliphant authored
Showing with 1,321 additions and 9,600 deletions.
  1. +656 −0 base/code_generators/generate_array_api.py
  2. +185 −0 base/code_generators/generate_ufunc_api.py
  3. +462 −0 base/code_generators/generate_umath.py
  4. +0 −1  distutils/MANIFEST.in
  5. +0 −10 distutils/__init__.py
  6. +0 −128 distutils/absoftfcompiler.py
  7. +0 −332 distutils/ccompiler.py
  8. +0 −30 distutils/command/__init__.py
  9. +0 −5 distutils/command/bdist_rpm.py
  10. +0 −78 distutils/command/build.py
  11. +0 −224 distutils/command/build_clib.py
  12. +0 −377 distutils/command/build_ext.py
  13. +0 −13 distutils/command/build_py.py
  14. +0 −609 distutils/command/build_src.py
  15. +0 −55 distutils/command/config_compiler.py
  16. +0 −102 distutils/command/install.py
  17. +0 −13 distutils/command/install_data.py
  18. +0 −20 distutils/command/install_headers.py
  19. +0 −154 distutils/command/sdist.py
  20. +0 −94 distutils/compaqfcompiler.py
  21. +0 −118 distutils/core.py
  22. +0 −675 distutils/cpuinfo.py
  23. +0 −54 distutils/dist.py
  24. +0 −17 distutils/examples/setup_module_config.py
  25. +0 −11 distutils/examples/setup_module_pure.py
  26. +0 −23 distutils/examples/setup_module_pure_data.py
  27. +0 −27 distutils/examples/setup_module_pure_super.py
  28. +0 −18 distutils/examples/setup_module_svn.py
  29. +0 −645 distutils/exec_command.py
  30. +0 −107 distutils/extension.py
  31. +0 −870 distutils/fcompiler.py
  32. +0 −262 distutils/from_template.py
  33. +0 −41 distutils/g95fcompiler.py
  34. +0 −209 distutils/gnufcompiler.py
  35. +0 −41 distutils/hpuxfcompiler.py
  36. +0 −80 distutils/ibmfcompiler.py
  37. +0 −43 distutils/info_scipy_distutils.py
  38. +0 −174 distutils/intelfcompiler.py
  39. +0 −46 distutils/laheyfcompiler.py
  40. +0 −116 distutils/lib2def.py
  41. +0 −75 distutils/line_endings.py
  42. +0 −100 distutils/log.py
  43. +0 −13 distutils/mingw32_support.py
  44. +0 −213 distutils/mingw32ccompiler.py
  45. +0 −56 distutils/mipsfcompiler.py
  46. +0 −596 distutils/misc_util.py
  47. +0 −39 distutils/nagfcompiler.py
  48. +0 −42 distutils/pgfcompiler.py
  49. +0 −494 distutils/proc.py
  50. +0 −51 distutils/sample_site.cfg
  51. +0 −27 distutils/scipy_distutils_version.py
  52. +0 −16 distutils/setup.py
  53. +0 −40 distutils/setup_scipy_distutils.py
  54. +0 −47 distutils/sunfcompiler.py
  55. +0 −1,517 distutils/system_info.py
  56. 0  distutils/tests/f2py_ext/__init__.py
  57. +0 −12 distutils/tests/f2py_ext/setup.py
  58. +0 −18 distutils/tests/f2py_ext/src/fib1.f
  59. +0 −9 distutils/tests/f2py_ext/src/fib2.pyf
  60. +0 −13 distutils/tests/f2py_ext/tests/test_fib2.py
  61. 0  distutils/tests/f2py_f90_ext/__init__.py
  62. +0 −5 distutils/tests/f2py_f90_ext/include/body.f90
  63. +0 −16 distutils/tests/f2py_f90_ext/setup.py
  64. +0 −6 distutils/tests/f2py_f90_ext/src/foo_free.f90
  65. +0 −13 distutils/tests/f2py_f90_ext/tests/test_foo.py
  66. 0  distutils/tests/gen_ext/__init__.py
  67. +0 −47 distutils/tests/gen_ext/setup.py
  68. +0 −13 distutils/tests/gen_ext/tests/test_fib3.py
  69. 0  distutils/tests/swig_ext/__init__.py
  70. +0 −14 distutils/tests/swig_ext/setup.py
  71. +0 −14 distutils/tests/swig_ext/src/example.c
  72. +0 −11 distutils/tests/swig_ext/src/example.i
  73. +0 −23 distutils/tests/swig_ext/src/zoo.cc
  74. +0 −9 distutils/tests/swig_ext/src/zoo.h
  75. +0 −10 distutils/tests/swig_ext/src/zoo.i
  76. +0 −18 distutils/tests/swig_ext/tests/test_example.py
  77. +0 −17 distutils/tests/swig_ext/tests/test_example2.py
  78. +0 −65 distutils/unixccompiler.py
  79. +0 −51 distutils/vastfcompiler.py
  80. +18 −68 setup.py
View
656 base/code_generators/generate_array_api.py
@@ -0,0 +1,656 @@
+
+# doc is comment_documentation
+
+# use list so order is preserved.
+objectapi_list = [
+ (r"""Set internal structure with number functions that all
+ arrays will use
+ """,
+ 'SetNumericOps','PyObject *dict','int'),
+
+ (r"""Get dictionary showing number functions that all
+ arrays will use
+ """,
+ 'GetNumericOps','void','PyObject *'),
+
+
+ (r"""For object arrays, increment all internal references.
+ """,
+ 'INCREF','PyArrayObject *','int'),
+
+ (r"""Decrement all internal references for object arrays.
+ """,
+ 'XDECREF','PyArrayObject *','int'),
+
+ (r"""Set the array print function to be a Python function.
+ """,
+ 'SetStringFunction','PyObject *op, int repr','void'),
+
+ (r"""Get the PyArray_Descr structure for a type.
+ """,
+ 'DescrFromType','int','PyArray_Descr *'),
+
+ (r"""Get pointer to zero of correct type for array.
+ """,
+ 'Zero', 'PyArrayObject *', 'char *'),
+
+ (r"""Get pointer to one of correct type for array
+ """,
+ 'One', 'PyArrayObject *', 'char *'),
+
+
+ (r"""Cast an array to a different type.
+ """,
+ 'Cast','PyArrayObject *, int','PyObject *'),
+
+ (r"""Cast an array using typecode structure.
+ """,
+ 'CastToType','PyArrayObject *, PyArray_Typecode *','PyObject *'),
+
+ (r"""Cast to an already created array.
+ """,
+ 'CastTo', 'PyArrayObject *, PyArrayObject *', 'int'),
+
+ (r"""Check the type coercion rules.
+ """,
+ 'CanCastSafely','int fromtype, int totype','int'),
+
+ (r"""Return the typecode of the array a Python object would be
+ converted to
+ """,
+ 'ObjectType','PyObject *, int','int'),
+
+ (r"""Return type typecode from array scalar.
+ """,
+ 'TypecodeFromScalar','PyObject *, PyArray_Typecode *','void'),
+
+ (r"""Compute the size of an array (in number of items)
+ """,
+ 'Size','PyObject *','intp'),
+
+ (r"""Get scalar-equivalent to 0-d array
+ """,
+ 'Scalar', 'char *, int, int, int', 'PyObject *'),
+
+ (r"""Get scalar-equivalent to 0-d array
+ """,
+ 'ToScalar', 'char *, PyArrayObject *', 'PyObject *'),
+
+ (r"""Get 0-dim array from scalar
+ """,
+ 'FromScalar', 'PyObject *, PyArray_Typecode *', 'PyObject *'),
+
+ (r"""Construct an empty array from dimensions and typenum
+ """,
+ 'FromDims','int nd, int *, int typenum','PyObject *'),
+
+ (r"""Construct an array from dimensions, typenum, and a pointer
+ to the data. Python will never free this (unless you later set
+ the OWN_DATA flag).
+ """,
+ 'FromDimsAndData','int, int *, int, char *','PyObject *'),
+
+ (r"""Construct an array from an arbitrary Python Object.
+ Last two integers are min_dimensions, and max_dimensions.
+ If max_dimensions = 0, then any number of dimensions are allowed.
+ Fix the dimension by setting min_dimension == max_dimension.
+ If the array is already contiguous (and aligned and not swapped)
+ no copy is done, just a new reference created.
+ """,
+ 'ContiguousFromObject',
+ 'PyObject *, int typenum, int, int',
+ 'PyObject *'),
+
+ (r"""Same as ContiguousFromObject except ensure a copy.
+ """,
+ 'CopyFromObject','PyObject *, int, int, int','PyObject *'),
+
+ (r"""Can return a discontiguous array (but aligned and byteswapped)
+ """,
+ 'FromObject','PyObject *, int, int, int','PyObject *'),
+
+ (r"""
+ """,
+ 'FromAny', 'PyObject *, PyArray_Typecode *, int, int, int', 'PyObject *'),
+
+ (r"""
+ """,
+ 'FromFile', 'FILE *, PyArray_Typecode *, intp, char *','PyObject *'),
+
+ (r"""
+ """,
+ 'FromBuffer', 'PyObject *, PyArray_Typecode *, intp, int','PyObject *'),
+
+ (r"""Return either an array or the appropriate Python object if the
+ array is 0d and matches a Python type.
+ """,
+ 'Return','PyArrayObject *','PyObject *'),
+
+ (r"""Get a subset of bytes from each element of the array
+ """,
+ 'GetField', 'PyArrayObject *, PyArray_Typecode *, int', 'PyObject *'),
+
+ (r"""
+ """,
+ 'Byteswap', 'PyArrayObject *, bool', 'PyObject *'),
+
+ (r"""Resize (reallocate data). Only works if nothing else is
+ referencing this array and it is contiguous.
+ """,
+ 'Resize','PyArrayObject *ap, PyArray_Dims *newshape','PyObject *'),
+
+ (r"""Copy an array.
+ """,
+ 'Copy','PyArrayObject *','PyObject *'),
+
+ (r"""Like FromDimsAndData but uses the Descr structure instead of
+ typecode as input.
+ """,
+ 'FromDimsAndDataAndDescr','int, int *, PyArray_Descr *, char *',
+ 'PyObject *'),
+
+ (r"""Copy an Array to another array.
+ """,
+ 'CopyArray','PyArrayObject *dest, PyArrayObject *src','int'),
+
+ (r"""To List
+ """,
+ 'ToList','PyArrayObject *', 'PyObject *'),
+
+ (r"""To File
+ """,
+ 'ToFile','PyArrayObject *, FILE *, char *, char *', 'int'),
+
+ (r"""
+ """,
+ 'Dump', 'PyObject *, PyObject *, int', 'int'),
+
+ (r"""
+ """,
+ 'Dumps', 'PyObject *, int', 'PyObject *'),
+
+
+ (r"""Is the typenum valid?
+ """,
+ 'ValidType','int','int'),
+
+ (r"""Update Several Flags at once.
+ """,
+ 'UpdateFlags','PyArrayObject *, int','void'),
+
+ (r"""Generic new array creation routine.
+ """,
+ 'New','PyTypeObject *, int nd, intp *dims, int type, intp *strides, char *data, int itemsize, int fortran, PyArrayObject *arr', 'PyObject *'),
+
+ (r"""Get Priority from object
+ """,
+ 'GetPriority', 'PyObject *, double', 'double'),
+
+ (r"""Get Buffers.
+ """,
+ 'GetBuffer','int num','char *'),
+
+ (r"""Get Iterator.
+ """,
+ 'IterNew','PyObject *', 'PyObject *'),
+
+ (r"""Map Iterator.
+ """,
+ 'MapIterNew', 'PyObject *', 'PyObject *'),
+
+ (r"""Bind Map Iterator
+ """,
+ 'MapIterBind', 'PyArrayMapIterObject *, PyArrayObject *', 'void'),
+
+ (r"""Bind Map Iterator
+ """,
+ 'MapIterReset', 'PyArrayMapIterObject *', 'void'),
+
+ (r"""
+ """,
+ 'MapIterNext', 'PyArrayMapIterObject *', 'void'),
+
+ (r"""
+ """,
+ 'PyIntAsInt', 'PyObject *', 'int'),
+
+ (r"""
+ """,
+ 'PyIntAsIntp','PyObject *', 'intp'),
+
+ (r"""
+ """,
+ 'Broadcast', 'PyArrayMultiIterObject *', 'int'),
+
+ (r"""
+ """,
+ 'FillObjectArray', 'PyArrayObject *, PyObject *','void'),
+
+ (r"""
+ """,
+ 'CheckStrides', 'int, int, intp, intp *, intp *', 'bool')
+
+ ]
+
+multiapi_list = [
+ (r"""Return Transpose.
+ """,
+ 'Transpose','PyArrayObject *, PyObject *','PyObject *'),
+
+ (r"""Take
+ """,
+ 'Take','PyArrayObject *, PyObject *, int axis','PyObject *'),
+
+ (r"""Put values into an array
+ """,
+ 'Put','PyArrayObject *arr, PyObject *items, PyObject *values','PyObject *'),
+
+ (r"""Put values into an array according to a mask.
+ """,
+ 'PutMask','PyArrayObject *arr, PyObject *mask, PyObject *values','PyObject *'),
+
+ (r"""Repeat the array.
+ """,
+ 'Repeat','PyArrayObject *, PyObject *, int','PyObject *'),
+
+ (r"""Numeric.choose()
+ """,
+ 'Choose','PyArrayObject *, PyObject *','PyObject *'),
+
+ (r"""Sort an array
+ """,
+ 'Sort','PyArrayObject *, int', 'PyObject *'),
+
+ (r"""ArgSort an array
+ """,
+ 'ArgSort','PyArrayObject *, int','PyObject *'),
+
+ (r"""Numeric.searchsorted(a,v)
+ """,
+ 'SearchSorted','PyArrayObject *, PyObject *','PyObject *'),
+
+ (r"""ArgMax
+ """,
+ 'ArgMax','PyArrayObject *, int','PyObject *'),
+
+ (r"""ArgMin
+ """,
+ 'ArgMin','PyArrayObject *, int','PyObject *'),
+
+ (r"""Reshape an array
+ """,
+ 'Reshape','PyArrayObject *, PyObject *','PyObject *'),
+
+ (r"""New shape for an array
+ """,
+ 'Newshape','PyArrayObject *, PyArray_Dims *','PyObject *'),
+
+ (r"""View
+ """,
+ 'View','PyArrayObject *, PyArray_Typecode *','PyObject *'),
+
+ (r"""SwapAxes
+ """,
+ 'SwapAxes','PyArrayObject *, int, int','PyObject *'),
+
+ (r"""Max
+ """,
+ 'Max','PyArrayObject *, int','PyObject *'),
+
+ (r"""Min
+ """,
+ 'Min','PyArrayObject *, int','PyObject *'),
+
+ (r"""Ptp
+ """,
+ 'Ptp','PyArrayObject *, int','PyObject *'),
+
+ (r"""Mean
+ """,
+ 'Mean','PyArrayObject *, int, int','PyObject *'),
+
+ (r"""Trace
+ """,
+ 'Trace','PyArrayObject *, int, int, int, int','PyObject *'),
+
+ (r"""Diagonal
+ """,
+ 'Diagonal','PyArrayObject *, int, int, int','PyObject *'),
+
+ (r"""Clip
+ """,
+ 'Clip','PyArrayObject *, PyObject *, PyObject *','PyObject *'),
+
+ (r"""Conjugate
+ """,
+ 'Conjugate','PyArrayObject *','PyObject *'),
+
+ (r"""Nonzero
+ """,
+ 'Nonzero','PyArrayObject *','PyObject *'),
+
+ (r"""Std
+ """,
+ 'Std','PyArrayObject *, int, int','PyObject *'),
+
+ (r"""Sum
+ """,
+ 'Sum','PyArrayObject *, int, int','PyObject *'),
+
+ (r"""CumSum
+ """,
+ 'CumSum','PyArrayObject *, int, int','PyObject *'),
+
+ (r"""Prod
+ """,
+ 'Prod','PyArrayObject *, int, int','PyObject *'),
+
+ (r"""CumProd
+ """,
+ 'CumProd','PyArrayObject *, int, int','PyObject *'),
+
+ (r"""All
+ """,
+ 'All','PyArrayObject *, int','PyObject *'),
+
+ (r"""Any
+ """,
+ 'Any','PyArrayObject *, int','PyObject *'),
+
+ (r"""Compress
+ """,
+ 'Compress','PyArrayObject *, PyObject *, int','PyObject *'),
+
+ (r"""Flatten
+ """,
+ 'Flatten','PyArrayObject *','PyObject *'),
+
+ (r"""Ravel
+ """,
+ 'Ravel','PyArrayObject *','PyObject *'),
+
+ (r"""Sign
+ """,
+ 'Sign','PyArrayObject *','PyObject *'),
+
+ (r"""Round
+ """,
+ 'Round','PyArrayObject *, int','PyObject *'),
+
+ (r"""Multiply a List
+ """,
+ 'MultiplyList','intp *lp, int n','intp'),
+
+ (r"""Compare Lists
+ """,
+ 'CompareLists','intp *, intp *, int n','int'),
+
+ (r"""Simulat a C-array
+ """,
+ "AsCArray",'PyObject **, void *ptr, intp *, int, int','int'),
+
+ (r"""Convert to a 1D C-array
+ """,
+ 'As1D','PyObject **, char **ptr, int *d1, int typecode','int'),
+
+ (r"""Convert to a 2D C-array
+ """,
+ 'As2D','PyObject **, char ***ptr, int *d1, int *d2, int typecode','int'),
+
+ (r"""Free pointers created if As2D is called
+ """,
+ 'Free','PyObject *, void *','int'),
+
+ (r"""Useful to pass as converter function for O& processing in
+ PyArgs_ParseTuple.
+ """,
+ 'Converter','PyObject *, PyObject **','int'),
+
+ (r"""PyArray_IntpFromSequence
+ """,
+ 'IntpFromSequence', 'PyObject *, intp *, int', 'int'),
+
+ (r"""Concatenate an arbitrary Python sequence into
+ an array.
+ """,
+ 'Concatenate','PyObject *, int','PyObject *'),
+
+ (r"""Numeric.innerproduct(a,v)
+ """,
+ 'InnerProduct','PyObject *, PyObject *','PyObject *'),
+
+ (r"""Numeric.matrixproduct(a,v)
+ """,
+ 'MatrixProduct','PyObject *, PyObject *','PyObject *'),
+
+ (r"""Fast Copy and Transpose
+ """,
+ 'CopyAndTranspose','PyObject *','PyObject *'),
+
+ (r"""Numeric.correlate(a1,a2,mode)
+ """,
+ 'Correlate','PyObject *, PyObject *, int mode','PyObject *'),
+
+ (r"""Typestr converter
+ """,
+ 'TypestrConvert', 'int, int', 'int'),
+
+ (r"""Get typenum from an object -- a converter function
+ """,
+ 'TypecodeConverter','PyObject *, PyArray_Typecode *', 'int'),
+
+ (r"""Get intp chunk from sequence
+ """,
+ 'IntpConverter', 'PyObject *, PyArray_Dims *', 'int'),
+
+ (r"""Get buffer chunk from object
+ """,
+ 'BufferConverter', 'PyObject *, PyArray_Chunk *', 'int'),
+
+ (r"""Get axis from an object (possibly None) -- a converter function,
+ """,
+ 'AxisConverter','PyObject *, int *', 'int'),
+
+ (r"""Convert an object to true / false
+ """,
+ 'BoolConverter','PyObject *, bool *', 'int'),
+
+ (r"""
+ """,
+ 'EquivalentTypes', 'PyArray_Typecode *, PyArray_Typecode *', 'bool'),
+
+ (r"""
+ """,
+ 'EquivArrTypes', 'PyArrayObject *, PyArrayObject *', 'bool'),
+
+ (r"""Zeros
+ """,
+ 'Zeros', 'int, intp *, PyArray_Typecode *', 'PyObject *'),
+
+ (r"""Empty
+ """,
+ 'Empty', 'int, intp *, PyArray_Typecode *', 'PyObject *'),
+
+
+ (r"""Where
+ """,
+ 'Where', 'PyObject *, PyObject *, PyObject *', 'PyObject *'),
+
+ (r"""Arange
+ """,
+ 'Arange', 'double, double, double, int', 'PyObject *')
+
+ ]
+
+
+types = ['Generic','Numeric','Integer','SignedInteger','UnsignedInteger',
+ 'Floating', 'Complex', 'Flexible', 'Character',
+ 'Bool','Byte','Short','Int', 'Long', 'LongLong', 'UByte', 'UShort',
+ 'UInt', 'ULong', 'ULongLong', 'Float', 'Double', 'LongDouble',
+ 'CFloat', 'CDouble', 'CLongDouble', 'Object', 'String', 'Unicode',
+ 'Void']
+
+# API fixes for __arrayobject_api.h
+
+fixed = 3
+numtypes = len(types) + fixed
+numobject = len(objectapi_list) + numtypes
+nummulti = len(multiapi_list)
+numtotal = numobject + nummulti
+
+
+module_list = []
+extension_list = []
+init_list = []
+
+# setup types
+for k, atype in enumerate(types):
+ num = fixed + k
+ astr = " (void *) &Py%sArrType_Type," % types[k]
+ init_list.append(astr)
+ astr = "static PyTypeObject Py%sArrType_Type;" % types[k]
+ module_list.append(astr)
+ astr = "#define Py%sArrType_Type (*(PyTypeObject *)PyArray_API[%d])" % \
+ (types[k], num)
+ extension_list.append(astr)
+
+
+#setup object API
+for k, item in enumerate(objectapi_list):
+ num = numtypes + k
+ astr = "static %s PyArray_%s \\\n (%s);" % \
+ (item[3],item[1],item[2])
+ module_list.append(astr)
+ astr = "#define PyArray_%s \\\n (*(%s (*)(%s)) \\\n"\
+ " PyArray_API[%d])" % (item[1],item[3],item[2],num)
+ extension_list.append(astr)
+ astr = " (void *) PyArray_%s," % item[1]
+ init_list.append(astr)
+
+
+##outstr = r"""
+###ifdef _ARRAYOBJECT
+
+##static PyTypeObject PyArray_Type;
+##static PyTypeObject PyArrayIter_Type;
+
+##%s
+
+
+###else
+
+###define PyArray_Type (*(PyTypeObject *)PyArray_API[0])
+###define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[1])
+
+##%s
+
+###endif
+##""" % ('\n'.join(module_list), '\n'.join(extension_list))
+
+### Write out to header
+##fid = open('__arrayobject_api.h','w')
+##fid.write(outstr)
+##fid.close()
+
+
+##outstr = r"""
+##/* Export only these pointers */
+
+##void *arrayobject_API[] = {
+## (void *) &PyArray_Type,
+## (void *) &PyArrayIter_Type,
+##%s
+##};
+##""" % '\n'.join(init_list)
+
+###Write out to c-code
+##fid = open('__arrayobject_api.c','w')
+##fid.write(outstr)
+##fid.close()
+
+
+#module_list = []
+#extension_list = []
+#init_list = []
+
+# setup multiarray module API
+for k, item in enumerate(multiapi_list):
+ num = numobject + k
+ astr = "static %s PyArray_%s \\\n (%s);" % \
+ (item[3],item[1],item[2])
+ module_list.append(astr)
+ astr = "#define PyArray_%s \\\n (*(%s (*)(%s)) \\\n"\
+ " PyArray_API[%d])" % (item[1],item[3],item[2],num)
+ extension_list.append(astr)
+ astr = " (void *) PyArray_%s," % item[1]
+ init_list.append(astr)
+
+
+outstr = r"""
+#ifdef _MULTIARRAYMODULE
+
+static PyTypeObject PyArray_Type;
+static PyTypeObject PyArrayIter_Type;
+static PyTypeObject PyArrayMapIter_Type;
+
+%s
+
+#else
+
+static void **PyArray_API=NULL;
+
+#define PyArray_Type (*(PyTypeObject *)PyArray_API[0])
+#define PyArrayIter_Type (*(PyTypeObject *)PyArray_API[1])
+#define PyArrayMapIter_Type (*(PyTypeObject *)PyArray_API[2])
+
+%s
+
+static int
+import_array(void)
+{
+ PyObject *numpy = PyImport_ImportModule("scipy.base.multiarray");
+ PyObject *c_api = NULL;
+ if (numpy == NULL) return -1;
+ c_api = PyObject_GetAttrString(numpy, "_ARRAY_API");
+ if (c_api == NULL) {Py_DECREF(numpy); return -1;}
+ if (PyCObject_Check(c_api)) {
+ PyArray_API = (void **)PyCObject_AsVoidPtr(c_api);
+ }
+ Py_DECREF(c_api);
+ Py_DECREF(numpy);
+ if (PyArray_API == NULL) return -1;
+ return 0;
+}
+
+#endif
+
+""" % ('\n'.join(module_list),
+ '\n'.join(extension_list))
+
+# Write to header
+fid = open('__multiarray_api.h','w')
+fid.write(outstr)
+fid.close()
+
+
+outstr = r"""
+/* These pointers will be stored in the C-object for use in other
+ extension modules
+*/
+
+void *PyArray_API[] = {
+ (void *) &PyArray_Type,
+ (void *) &PyArrayIter_Type,
+ (void *) &PyArrayMapIter_Type,
+%s
+};
+""" % '\n'.join(init_list)
+
+# Write to c-code
+fid = open('__multiarray_api.c','w')
+fid.write(outstr)
+fid.close()
+
+
+
+
View
185 base/code_generators/generate_ufunc_api.py
@@ -0,0 +1,185 @@
+
+# doc is comment_documentation
+
+# use list so order is preserved.
+ufunc_api_list = [
+ (r"""
+ """,
+ 'FromFuncAndData', 'PyUFuncGenericFunction *, void **, char *, int, int, int, int, char *, char *, int', 'PyObject *'),
+ (r"""
+ """,
+ 'GenericFunction', 'PyUFuncObject *, PyObject *, PyArrayObject **', 'int'),
+
+ (r"""
+ """,
+ 'f_f_As_d_d','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'd_d','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'f_f','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'g_g','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'F_F_As_D_D','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'F_F','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'D_D','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'G_G','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'O_O','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'ff_f_As_dd_d','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'ff_f','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'dd_d','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'gg_g','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'FF_F_As_DD_D','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'DD_D','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'FF_F','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'GG_G','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'OO_O','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'O_O_method','char **, intp *, intp *, void *','void'),
+
+ (r"""
+ """,
+ 'checkfperr', 'int, PyObject *', 'int'),
+
+ (r"""
+ """,
+ 'clearfperr', 'void', 'void')
+
+]
+
+# API fixes for __arrayobject_api.h
+
+fixed = 1
+nummulti = len(ufunc_api_list)
+numtotal = fixed + nummulti
+
+
+module_list = []
+extension_list = []
+init_list = []
+
+#setup object API
+for k, item in enumerate(ufunc_api_list):
+ num = fixed + k
+ astr = "static %s PyUFunc_%s \\\n (%s);" % \
+ (item[3],item[1],item[2])
+ module_list.append(astr)
+ astr = "#define PyUFunc_%s \\\n (*(%s (*)(%s)) \\\n"\
+ " PyUFunc_API[%d])" % (item[1],item[3],item[2],num)
+ extension_list.append(astr)
+ astr = " (void *) PyUFunc_%s," % item[1]
+ init_list.append(astr)
+
+
+outstr = r"""
+#ifdef _UMATHMODULE
+
+static PyTypeObject PyUFunc_Type;
+
+%s
+
+#else
+
+static void **PyUFunc_API;
+
+#define PyUFunc_Type (*(PyTypeObject *)PyUFunc_API[0])
+
+%s
+
+static int
+import_ufunc(void)
+{
+ PyObject *numpy = PyImport_ImportModule("scipy.base.umath");
+ PyObject *c_api = NULL;
+
+ if (numpy == NULL) return -1;
+ c_api = PyObject_GetAttrString(numpy, "_UFUNC_API");
+ if (c_api == NULL) {Py_DECREF(numpy); return -1;}
+ if (PyCObject_Check(c_api)) {
+ PyUFunc_API = (void **)PyCObject_AsVoidPtr(c_api);
+ }
+ Py_DECREF(c_api);
+ Py_DECREF(numpy);
+ if (PyUFunc_API == NULL) return -1;
+ return 0;
+}
+
+#endif
+
+""" % ('\n'.join(module_list),
+ '\n'.join(extension_list))
+
+# Write to header
+fid = open('__ufunc_api.h','w')
+fid.write(outstr)
+fid.close()
+
+
+outstr = r"""
+/* These pointers will be stored in the C-object for use in other
+ extension modules
+*/
+
+void *PyUFunc_API[] = {
+ (void *) &PyUFunc_Type,
+%s
+};
+""" % '\n'.join(init_list)
+
+# Write to c-code
+fid = open('__ufunc_api.c','w')
+fid.write(outstr)
+fid.close()
+
+
+
+
View
462 base/code_generators/generate_umath.py
@@ -0,0 +1,462 @@
+
+import string
+import re
+
+Zero = "PyUFunc_Zero"
+One = "PyUFunc_One"
+None_ = "PyUFunc_None"
+#each entry in defdict is
+
+#name: [string of chars for which it is defined,
+# string of characters using func interface,
+# tuple of strings giving funcs for data,
+# (in, out),
+# identity,
+# docstring]
+
+all = '?bBhHiIlLqQfdgFDGO'
+ints = 'bBhHiIlLqQ'
+intsO = ints + 'O'
+bintsO = '?'+ints+'O'
+flts = 'fdg'
+fltsO = flts+'O'
+fltsM = flts+'M'
+cmplx = 'FDG'
+cmplxO = cmplx+'O'
+cmplxM = cmplx+'M'
+noint = flts+cmplx+'O'
+nointM = flts+cmplx+'M'
+all = '?'+ints+flts+cmplxO
+nobool = all[1:]
+nobool_or_obj = all[1:-1]
+intflt = ints+flts
+nocmplx = '?'+ints+flts
+nocmplxO = nocmplx+'O'
+nocmplxM = nocmplx+'M'
+noobj = all[:-1]
+
+defdict = {
+'add': [all,'O',("PyNumber_Add",),
+ (2,1), Zero,
+ "Add the arguments elementwise."
+ ],
+'subtract' : [all,'O',("PyNumber_Subtract",),
+ (2,1), Zero,
+ "Subtract the arguments elementwise."
+ ],
+'multiply' : [all,cmplxO,
+ ("prod,"*3,"PyNumber_Multiply",),
+ (2,1), One,
+ "Multiply the arguments elementwise."
+ ],
+'divide' : [nobool,cmplxO,
+ ("quot,"*3,"PyNumber_Divide",),
+ (2,1), One,
+ "Divide the arguments elementwise."
+ ],
+'floor_divide' : [nobool, cmplxO,
+ ("floor_quot,"*3,
+ "PyNumber_FloorDivide"),
+ (2,1), One,
+ "Floor divide the arguments elementwise."
+ ],
+'true_divide' : [nobool, cmplxO,
+ ("quot,"*3,"PyNumber_TrueDivide"),
+ (2,1), One,
+ "True divide the arguments elementwise.",
+ 'f'*4+'d'*6+flts+cmplxO
+ ],
+'conjugate' : [nobool_or_obj, 'M',
+ ('"conjugate"',),
+ (1,1), None,
+ "take the conjugate elementwise."
+ ],
+'remainder' : [intflt,fltsO,
+ ("fmod,"*3, "PyNumber_Remainder"),
+ (2,1), Zero,
+ "remainder(x,y) returns x % y elementwise."
+ ],
+'power' : [nobool,noint,
+ ("pow,"*6,
+ "PyNumber_Power"),
+ (2,1), One,
+ "power(x,y) == x**y elementwise."
+ ],
+'absolute' : [all,'O',
+ ("PyNumber_Absolute",),
+ (1,1), None,
+ "absolute value elementwise."
+ ],
+'negative' : [all,cmplxO,
+ ("neg,"*3,"PyNumber_Negative"),
+ (1,1), None,
+ "negative elements",
+ ],
+'greater' : [all,'',(),(2,1), None,
+ "greater(x,y) is the bool array x > y.",
+ '?'*len(all)
+ ],
+'greater_equal' : [all,'',(),(2,1), None,
+ "greater_equal(x,y) is the bool array x >= y.",
+ '?'*len(all)
+ ],
+'less' : [all,'',(),(2,1), None,
+ "less(x,y) is the bool array x < y.",
+ '?'*len(all)
+ ],
+'less_equal' : [all,'',(),(2,1), None,
+ "less_equal(x,y) is the bool array x <= y.",
+ '?'*len(all)
+ ],
+'equal' : [all, '', (), (2,1), None,
+ "equal(x,y) is the bool array x == y.",
+ '?'*len(all)
+ ],
+'not_equal' : [all, '', (), (2,1), None,
+ "not_equal(x,y) is the bool array x != y.",
+ '?'*len(all)
+ ],
+'logical_and': [nocmplxM,'M',('"logical_and"',),
+ (2,1), One,
+ "logical and of arguments elementwise.",
+ '?'*len(nocmplxM)
+ ],
+'logical_or': [nocmplxM,'M',('"logical_or"',),
+ (2,1), Zero,
+ "logical or of arguments elementwise.",
+ '?'*len(nocmplxM)
+ ],
+'logical_xor': [nocmplxM, 'M', ('"logical_xor"',),
+ (2,1), None,
+ "logical xor of arguments elementwise.",
+ '?'*len(nocmplxM)
+ ],
+'logical_not' : [nocmplxM, 'M', ('"logical_not"',),
+ (1,1), None,
+ "logical not of argument elementwise.",
+ '?'*len(nocmplxM)
+ ],
+'maximum' : [noobj,'',(),
+ (2,1), None,
+ "maximum of two arrays elementwise."],
+'minimum' : [noobj,'',(),
+ (2,1), None,
+ "minimum of two arrays elementwise."],
+'bitwise_and' : [bintsO,'O',("PyNumber_And",),
+ (2,1), One,
+ "bitwise and of two arrays elementwise."],
+'bitwise_or' : [bintsO, 'O', ("PyNumber_Or",),
+ (2,1), Zero,
+ "bitwise or of two arrays elementwise."],
+'bitwise_xor' : [bintsO, 'O', ("PyNumber_Xor",),
+ (2,1), None,
+ "bitwise xor of two arrays elementwise."],
+'invert' : [bintsO,'O', ("PyNumber_Invert",),
+ (1,1), None,
+ "bit inversion elementwise."
+ ],
+'left_shift' : [intsO, 'O', ("PyNumber_Lshift",),
+ (2,1), None,
+ "left_shift(n,m) is n << m (n shifted to left by m bits) elementwise."
+ ],
+'right_shift' : [intsO, 'O', ("PyNumber_Rshift",),
+ (2,1), None,
+ "right_shift(n,m) is n >> m (n shifted to right by m bits) elementwise."
+ ],
+'arccos' : [nointM, nointM,
+ ("acos,"*6, '"arccos"'),
+ (1, 1), None,
+ "inverse cosine elementwise."
+ ],
+'arcsin': [nointM, nointM,
+ ("asin,"*6, '"arcsin"'),
+ (1, 1), None,
+ "inverse sine elementwise."
+ ],
+'arctan': [nointM, nointM,
+ ("atan,"*6, '"arctan"'),
+ (1, 1), None,
+ "inverse tangent elementwise."
+ ],
+'arccosh' : [nointM, nointM,
+ ("acosh,"*6, '"arccosh"'),
+ (1, 1), None,
+ "inverse hyperbolic cosine elementwise."
+ ],
+'arcsinh': [nointM, nointM,
+ ("asinh,"*6, '"arcsinh"'),
+ (1, 1), None,
+ "inverse hyperbolic sine elementwise."
+ ],
+'arctanh': [nointM, nointM,
+ ("atanh,"*6, '"arctanh"'),
+ (1, 1), None,
+ "inverse hyperbolic tangent elementwise."
+ ],
+'cos': [nointM, nointM,
+ ("cos,"*6, '"cos"'),
+ (1, 1), None,
+ "cosine elementwise."
+ ],
+'sin': [nointM, nointM,
+ ("sin,"*6, '"sin"'),
+ (1, 1), None,
+ "sine elementwise."
+ ],
+'tan': [nointM, nointM,
+ ("tan,"*6, '"tan"'),
+ (1, 1), None,
+ "tangent elementwise."
+ ],
+'cosh': [nointM, nointM,
+ ("cosh,"*6, '"cosh"'),
+ (1, 1), None,
+ "hyperbolic cosine elementwise."
+ ],
+'sinh': [nointM, nointM,
+ ("sinh,"*6, '"sinh"'),
+ (1, 1), None,
+ "hyperbolic sine elementwise."
+ ],
+'tanh': [nointM, nointM,
+ ("tanh,"*6, '"tanh"'),
+ (1, 1), None,
+ "hyperbolic tangent elementwise."
+ ],
+'exp' : [nointM, nointM,
+ ("exp,"*6, '"exp"'),
+ (1, 1), None,
+ "e**x elementwise."
+ ],
+'log' : [nointM, nointM,
+ ("log,"*6, '"log"'),
+ (1, 1), None,
+ "log(x) elementwise."
+ ],
+'log10' : [nointM, nointM,
+ ("log10,"*6, '"log10"'),
+ (1, 1), None,
+ "log10(x) elementwise."
+ ],
+'sqrt' : [nointM, nointM,
+ ("sqrt,"*6, '"sqrt"'),
+ (1,1), None,
+ "sqrt(x) elementwise."
+ ],
+'ceil' : [fltsM, fltsM,
+ ("ceil,"*3, '"ceil"'),
+ (1,1), None,
+ "elementwise smallest integer >= x."
+ ],
+'fabs' : [fltsM, fltsM,
+ ("fabs,"*3, '"fabs"'),
+ (1,1), None,
+ "absolute values."
+ ],
+'floor' : [fltsM, fltsM,
+ ("floor,"*3, '"floor"'),
+ (1,1), None,
+ "elementwise largest integer <= x"
+ ],
+'arctan2' : [fltsM, fltsM,
+ ("atan2,"*3, '"arctan2"'),
+ (2,1), None,
+ "arctan2(x,y) is a safe and corrent tan(x/y)"
+ ],
+'fmod' : [fltsM, fltsM,
+ ("fmod,"*3,'"fmod"'),
+ (2,1), None,
+ "fmod(x,y) is remainder(x,y)"],
+'hypot' : [fltsM, fltsM,
+ ("hypot,"*3, '"hypot"'),
+ (2,1), None,
+ "sqrt(x**2 + y**2) elementwise"
+ ]
+}
+
+
+def indent(st,spaces):
+ indention = ' '*spaces
+ indented = indention + string.replace(st,'\n','\n'+indention)
+ # trim off any trailing spaces
+ indented = re.sub(r' +$',r'',indented)
+ return indented
+
+chartoname = {'?': 'bool',
+ 'b': 'byte',
+ 'B': 'ubyte',
+ 'h': 'short',
+ 'H': 'ushort',
+ 'i': 'int',
+ 'I': 'uint',
+ 'l': 'long',
+ 'L': 'ulong',
+ 'q': 'longlong',
+ 'Q': 'ulonglong',
+ 'f': 'float',
+ 'd': 'double',
+ 'g': 'longdouble',
+ 'F': 'cfloat',
+ 'D': 'cdouble',
+ 'G': 'clongdouble',
+ 'O': 'OBJECT',
+ 'M': 'OBJECT',
+ }
+
+chartotype1 = {'f': 'f_f',
+ 'd': 'd_d',
+ 'g': 'g_g',
+ 'F': 'F_F',
+ 'D': 'D_D',
+ 'G': 'G_G',
+ 'O': 'O_O',
+ 'M': 'O_O_method'}
+
+chartotype2 = {'f': 'ff_f',
+ 'd': 'dd_d',
+ 'g': 'gg_g',
+ 'F': 'FF_F',
+ 'D': 'DD_D',
+ 'G': 'GG_G',
+ 'O': 'OO_O',
+ 'M': 'O_O_method'}
+#for each name
+# 1) create functions, data, and signature
+# 2) fill in functions and data in InitOperators
+# 3) add function.
+
+def make_arrays(funcdict):
+ # functions array contains an entry for every type implemented
+ # NULL should be placed where PyUfunc_ style function will be filled in later
+ #
+ code1list = []
+ code2list = []
+ for name, vals in funcdict.iteritems():
+ funclist = []
+ datalist = []
+ siglist = []
+ k=0;
+ sub=0;
+ if vals[3][0] > 1:
+ thedict = chartotype2
+ else:
+ thedict = chartotype1
+ for char in vals[0]:
+ if char in vals[1]:
+ funclist.append('NULL')
+ astr = '%s_functions[%d] = PyUFunc_%s;' % \
+ (name, k, thedict[char])
+ code2list.append(astr)
+ thisfunc = vals[2][sub]
+ if len(thisfunc) > 8 and thisfunc[:8] == "PyNumber":
+ astr = '%s_data[%d] = (void *) %s;' % \
+ (name, k, thisfunc)
+ code2list.append(astr)
+ datalist.append('(void *)NULL');
+ else:
+ datalist.append('(void *)%s' % thisfunc)
+ sub += 1
+ else:
+ datalist.append('(void *)NULL');
+ funclist.append('%s_%s' % (chartoname[char].upper(), name))
+ siglist.append('PyArray_%s' % chartoname[char].upper())
+ if vals[3][0] > 1:
+ siglist.append('PyArray_%s' % chartoname[char].upper())
+ if len(vals) > 6: # have output specification
+ siglist.append('PyArray_%s' % chartoname[vals[6][k]].upper())
+ else:
+ siglist.append('PyArray_%s' % chartoname[char].upper())
+ k += 1
+ funcnames = ', '.join(funclist)
+ signames = ', '.join(siglist)
+ datanames = ', '.join(datalist)
+ code1list.append("static PyUFuncGenericFunction %s_functions[] = { %s };" \
+ % (name, funcnames))
+ code1list.append("static void * %s_data[] = { %s };" \
+ % (name, datanames))
+ code1list.append("static char %s_signatures[] = { %s };" \
+ % (name, signames))
+ return "\n".join(code1list),"\n".join(code2list)
+
+def make_ufuncs(funcdict):
+ code3list = []
+ for name, vals in funcdict.items():
+ mlist = []
+ mlist.append(\
+r"""f = PyUFunc_FromFuncAndData(%s_functions, %s_data, %s_signatures, %d,
+ %d, %d, %s, "%s",
+ "%s", 0);""" % (name,name,name,len(vals[0]),
+ vals[3][0], vals[3][1], vals[4],
+ name, vals[5]))
+ mlist.append(r"""PyDict_SetItemString(dictionary, "%s", f);"""%name)
+ mlist.append(r"""Py_DECREF(f);""")
+ code3list.append('\n'.join(mlist))
+ return '\n'.join(code3list)
+
+
+def convert_vals(funcdict):
+ for name, vals in funcdict.iteritems():
+ if vals[4] is None:
+ vals[4] = None_
+ vals2 = vals[2]
+ if len(vals2) > 0:
+ alist = vals2[0].split(',')
+ if len(alist) == 4:
+ a = alist[0]
+ if 'f' in vals[1]:
+ newlist = [ a+'f', a, a+'l']
+ else:
+ newlist = ['nc_'+a+'f', 'nc_'+a, 'nc_'+a+'l']
+ elif len(alist) == 7:
+ a = alist[0]
+ newlist = [a+'f', a, a+'l','nc_'+a+'f', 'nc_'+a, 'nc_'+a+'l']
+ else:
+ newlist = alist
+ newlist = newlist + list(vals2[1:])
+ vals[2] = tuple(newlist)
+ funcdict[name] = vals
+
+
+def make_code(funcdict,filename):
+ convert_vals(funcdict)
+ code1, code2 = make_arrays(funcdict)
+ code3 = make_ufuncs(funcdict)
+ code2 = indent(code2,4)
+ code3 = indent(code3,4)
+ code = r"""
+
+/** Warning this file is autogenerated!!!
+
+ Please make changes to the code generator program (%s)
+**/
+
+%s
+
+static void
+InitOperators(PyObject *dictionary) {
+ PyObject *f;
+
+%s
+%s
+}
+""" % (filename, code1, code2, code3)
+ return code;
+
+
+if __name__ == "__main__":
+ filename = __file__
+ fid = open('__umath_generated.c','w')
+ code = make_code(defdict, filename)
+ fid.write(code)
+ fid.close()
+
+
+
+
+
+
+
+
+
+
+
View
1  distutils/MANIFEST.in
@@ -1 +0,0 @@
-include setup.py
View
10 distutils/__init__.py
@@ -1,10 +0,0 @@
-# Need to do something here to get distutils subsumed...
-from info_scipy_distutils import __doc__
-from scipy_distutils_version import scipy_distutils_version as __version__
-
-import sys
-
-# Must import local ccompiler ASAP in order to get
-# customized CCompiler.spawn effective.
-import ccompiler
-import unixccompiler
View
128 distutils/absoftfcompiler.py
@@ -1,128 +0,0 @@
-
-# http://www.absoft.com/literature/osxuserguide.pdf
-# http://www.absoft.com/documentation.html
-
-# Notes:
-# - when using -g77 then use -DUNDERSCORE_G77 to compile f2py
-# generated extension modules (works for f2py v2.45.241_1936 and up)
-
-import os
-import sys
-
-from cpuinfo import cpu
-from fcompiler import FCompiler, dummy_fortran_file
-from misc_util import cyg2win32
-
-class AbsoftFCompiler(FCompiler):
-
- compiler_type = 'absoft'
- #version_pattern = r'FORTRAN 77 Compiler (?P<version>[^\s*,]*).*?Absoft Corp'
- version_pattern = r'(f90:.*?Absoft Pro FORTRAN Version|FORTRAN 77 Compiler)'+\
- r' (?P<version>[^\s*,]*)(.*?Absoft Corp|)'
-
- # samt5735(8)$ f90 -V -c dummy.f
- # f90: Copyright Absoft Corporation 1994-2002; Absoft Pro FORTRAN Version 8.0
- # Note that fink installs g77 as f77, so need to use f90 for detection.
-
- executables = {
- 'version_cmd' : ["f90", "-V -c %(fname)s.f -o %(fname)s.o" \
- % {'fname':cyg2win32(dummy_fortran_file())}],
- 'compiler_f77' : ["f77"],
- 'compiler_fix' : ["f90"],
- 'compiler_f90' : ["f90"],
- 'linker_so' : ["f90"],
- 'archiver' : ["ar", "-cr"],
- 'ranlib' : ["ranlib"]
- }
-
- if os.name=='nt':
- library_switch = '/out:' #No space after /out:!
-
- module_dir_switch = None
- module_include_switch = '-p'
-
- def get_flags_linker_so(self):
- if os.name=='nt':
- opt = ['/dll']
- else:
- opt = ["-K","shared"]
- return opt
-
- def library_dir_option(self, dir):
- if os.name=='nt':
- return ['-link','/PATH:"%s"' % (dir)]
- return "-L" + dir
-
- def library_option(self, lib):
- if os.name=='nt':
- return '%s.lib' % (lib)
- return "-l" + lib
-
- def get_library_dirs(self):
- opt = FCompiler.get_library_dirs(self)
- d = os.environ.get('ABSOFT')
- if d:
- opt.append(os.path.join(d,'LIB'))
- return opt
-
- def get_libraries(self):
- opt = FCompiler.get_libraries(self)
- opt.extend(['fio','f90math','fmath'])
- if os.name =='nt':
- opt.append('COMDLG32')
- return opt
-
- def get_flags(self):
- opt = FCompiler.get_flags(self)
- if os.name != 'nt':
- opt.extend(['-s'])
- if self.get_version():
- if self.get_version()>='8.2':
- opt.append('-fpic')
- return opt
-
- def get_flags_f77(self):
- opt = FCompiler.get_flags_f77(self)
- opt.extend(['-N22','-N90','-N110'])
- v = self.get_version()
- if os.name == 'nt':
- if v and v>='8.0':
- opt.extend(['-f','-N15'])
- else:
- opt.append('-f')
- if v:
- if v<='4.6':
- opt.append('-B108')
- else:
- # Though -N15 is undocumented, it works with
- # Absoft 8.0 on Linux
- opt.append('-N15')
- return opt
-
- def get_flags_f90(self):
- opt = FCompiler.get_flags_f90(self)
- opt.extend(["-YCFRL=1","-YCOM_NAMES=LCS","-YCOM_PFX","-YEXT_PFX",
- "-YCOM_SFX=_","-YEXT_SFX=_","-YEXT_NAMES=LCS"])
- if self.get_version():
- if self.get_version()>'4.6':
- opt.extend(["-YDEALLOC=ALL"])
- return opt
-
- def get_flags_fix(self):
- opt = FCompiler.get_flags_fix(self)
- opt.extend(["-YCFRL=1","-YCOM_NAMES=LCS","-YCOM_PFX","-YEXT_PFX",
- "-YCOM_SFX=_","-YEXT_SFX=_","-YEXT_NAMES=LCS"])
- opt.extend(["-f","fixed"])
- return opt
-
- def get_flags_opt(self):
- opt = ['-O']
- return opt
-
-if __name__ == '__main__':
- from distutils import log
- log.set_verbosity(2)
- from fcompiler import new_fcompiler
- compiler = new_fcompiler(compiler='absoft')
- compiler.customize()
- print compiler.get_version()
View
332 distutils/ccompiler.py
@@ -1,332 +0,0 @@
-
-import re
-import os
-import sys
-import new
-
-from distutils.ccompiler import *
-from distutils import ccompiler
-from distutils.sysconfig import customize_compiler
-from distutils.version import LooseVersion
-
-import log
-from exec_command import exec_command
-from misc_util import compiler_to_string, cyg2win32
-from distutils.spawn import _nt_quote_args
-
-# Using customized CCompiler.spawn.
-def CCompiler_spawn(self, cmd, display=None):
- if display is None:
- display = cmd
- if type(display) is type([]): display = ' '.join(display)
- log.info(display)
- if type(cmd) is type([]) and os.name == 'nt':
- cmd = _nt_quote_args(cmd)
- s,o = exec_command(cmd)
- if s:
- if type(cmd) is type([]):
- cmd = ' '.join(cmd)
- print o
- raise DistutilsExecError,\
- 'Command "%s" failed with exit status %d' % (cmd, s)
-CCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)
-
-def CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):
- if output_dir is None:
- output_dir = ''
- obj_names = []
- for src_name in source_filenames:
- base, ext = os.path.splitext(os.path.normpath(src_name))
- base = os.path.splitdrive(base)[1] # Chop off the drive
- base = base[os.path.isabs(base):] # If abs, chop off leading /
- if base.startswith('..'):
- # Resolve starting relative path components, middle ones
- # (if any) have been handled by os.path.normpath above.
- i = base.rfind('..')+2
- d = base[:i]
- d = os.path.basename(os.path.abspath(d))
- base = d + base[i:]
- if ext not in self.src_extensions:
- raise UnknownFileError, \
- "unknown file type '%s' (from '%s')" % (ext, src_name)
- if strip_dir:
- base = os.path.basename(base)
- obj_name = os.path.join(output_dir,base + self.obj_extension)
- obj_names.append(obj_name)
- return obj_names
-
-CCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,
- None,CCompiler)
-
-def CCompiler_compile(self, sources, output_dir=None, macros=None,
- include_dirs=None, debug=0, extra_preargs=None,
- extra_postargs=None, depends=None):
- # This method is effective only with Python >=2.3 distutils.
- # Any changes here should be applied also to fcompiler.compile
- # method to support pre Python 2.3 distutils.
- if not sources:
- return []
- from fcompiler import FCompiler
- if isinstance(self, FCompiler):
- display = []
- for fc in ['f77','f90','fix']:
- fcomp = getattr(self,'compiler_'+fc)
- if fcomp is None:
- continue
- display.append("%s(%s) options: '%s'" % (os.path.basename(fcomp[0]),
- fc,
- ' '.join(fcomp[1:])))
- display = '\n'.join(display)
- else:
- ccomp = self.compiler_so
- display = "%s options: '%s'" % (os.path.basename(ccomp[0]),
- ' '.join(ccomp[1:]))
- log.info(display)
- macros, objects, extra_postargs, pp_opts, build = \
- self._setup_compile(output_dir, macros, include_dirs, sources,
- depends, extra_postargs)
- cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)
- display = "compile options: '%s'" % (' '.join(cc_args))
- if extra_postargs:
- display += "\nextra options: '%s'" % (' '.join(extra_postargs))
- log.info(display)
-
- # build any sources in same order as they were originally specified
- # especially important for fortran .f90 files using modules
- if isinstance(self, FCompiler):
- objects_to_build = build.keys()
- for obj in objects:
- if obj in objects_to_build:
- src, ext = build[obj]
- if self.compiler_type=='absoft':
- obj = cyg2win32(obj)
- src = cyg2win32(src)
- self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
- else:
- for obj, (src, ext) in build.items():
- self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)
-
- # Return *all* object filenames, not just the ones we just built.
- return objects
-
-CCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)
-
-def CCompiler_customize_cmd(self, cmd):
- """ Customize compiler using distutils command.
- """
- log.info('customize %s using %s' % (self.__class__.__name__,
- cmd.__class__.__name__))
- if getattr(cmd,'include_dirs',None) is not None:
- self.set_include_dirs(cmd.include_dirs)
- if getattr(cmd,'define',None) is not None:
- for (name,value) in cmd.define:
- self.define_macro(name, value)
- if getattr(cmd,'undef',None) is not None:
- for macro in cmd.undef:
- self.undefine_macro(macro)
- if getattr(cmd,'libraries',None) is not None:
- self.set_libraries(self.libraries + cmd.libraries)
- if getattr(cmd,'library_dirs',None) is not None:
- self.set_library_dirs(self.library_dirs + cmd.library_dirs)
- if getattr(cmd,'rpath',None) is not None:
- self.set_runtime_library_dirs(cmd.rpath)
- if getattr(cmd,'link_objects',None) is not None:
- self.set_link_objects(cmd.link_objects)
- return
-
-CCompiler.customize_cmd = new.instancemethod(\
- CCompiler_customize_cmd,None,CCompiler)
-
-def CCompiler_show_customization(self):
- if 0:
- for attrname in ['include_dirs','define','undef',
- 'libraries','library_dirs',
- 'rpath','link_objects']:
- attr = getattr(self,attrname,None)
- if not attr:
- continue
- log.info("compiler '%s' is set to %s" % (attrname,attr))
- try: self.get_version()
- except: pass
- if log._global_log.threshold<2:
- print '*'*80
- print self.__class__
- print compiler_to_string(self)
- print '*'*80
-
-CCompiler.show_customization = new.instancemethod(\
- CCompiler_show_customization,None,CCompiler)
-
-
-def CCompiler_customize(self, dist, need_cxx=0):
- # See FCompiler.customize for suggested usage.
- log.info('customize %s' % (self.__class__.__name__))
- customize_compiler(self)
- if need_cxx:
- if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:
- if sys.version[:3]>='2.3':
- if not self.compiler_cxx:
- self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\
- + self.compiler[1:]
- else:
- self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\
- + self.compiler[1:]
- else:
- log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)
- return
-
-CCompiler.customize = new.instancemethod(\
- CCompiler_customize,None,CCompiler)
-
-def CCompiler_get_version(self, force=0, ok_status=[0]):
- """ Compiler version. Returns None if compiler is not available. """
- if not force and hasattr(self,'version'):
- return self.version
- if not (hasattr(self,'version_cmd') and
- hasattr(self,'version_pattern')):
- #log.warn('%s does not provide version_cmd and version_pattern attributes' \
- # % (self.__class__))
- return
-
- cmd = ' '.join(self.version_cmd)
- status, output = exec_command(cmd,use_tee=0)
- version = None
- if status in ok_status:
- m = re.match(self.version_pattern,output)
- if m:
- version = m.group('version')
- assert version,`version`
- version = LooseVersion(version)
- self.version = version
- return version
-
-CCompiler.get_version = new.instancemethod(\
- CCompiler_get_version,None,CCompiler)
-
-if sys.platform == 'win32':
- compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',
- "Mingw32 port of GNU C Compiler for Win32"\
- "(for MSC built Python)")
- if os.environ.get('OSTYPE','')=='msys' or \
- os.environ.get('MSYSTEM','')=='MINGW32':
- # On windows platforms, we want to default to mingw32 (gcc)
- # because msvc can't build blitz stuff.
- log.info('Setting mingw32 as default compiler for nt.')
- ccompiler._default_compilers = (('nt', 'mingw32'),) \
- + ccompiler._default_compilers
-
-
-_distutils_new_compiler = new_compiler
-def new_compiler (plat=None,
- compiler=None,
- verbose=0,
- dry_run=0,
- force=0):
- # Try first C compilers from scipy_distutils.
- if plat is None:
- plat = os.name
- try:
- if compiler is None:
- compiler = get_default_compiler(plat)
- (module_name, class_name, long_description) = compiler_class[compiler]
- except KeyError:
- msg = "don't know how to compile C/C++ code on platform '%s'" % plat
- if compiler is not None:
- msg = msg + " with '%s' compiler" % compiler
- raise DistutilsPlatformError, msg
- module_name = "scipy_distutils." + module_name
- try:
- __import__ (module_name)
- except ImportError, msg:
- print msg,'in scipy_distutils, trying from distutils..'
- module_name = module_name[6:]
- try:
- __import__(module_name)
- except ImportError, msg:
- raise DistutilsModuleError, \
- "can't compile C/C++ code: unable to load module '%s'" % \
- module_name
- try:
- module = sys.modules[module_name]
- klass = vars(module)[class_name]
- except KeyError:
- raise DistutilsModuleError, \
- ("can't compile C/C++ code: unable to find class '%s' " +
- "in module '%s'") % (class_name, module_name)
- compiler = klass(None, dry_run, force)
- log.debug('new_fcompiler returns %s' % (klass))
- return compiler
-
-ccompiler.new_compiler = new_compiler
-
-
-_distutils_gen_lib_options = gen_lib_options
-def gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries):
- r = _distutils_gen_lib_options(compiler, library_dirs,
- runtime_library_dirs, libraries)
- lib_opts = []
- for i in r:
- if type(i) is type([]):
- lib_opts.extend(i)
- else:
- lib_opts.append(i)
- return lib_opts
-ccompiler.gen_lib_options = gen_lib_options
-
-
-##Fix distutils.util.split_quoted:
-import re,string
-_wordchars_re = re.compile(r'[^\\\'\"%s ]*' % string.whitespace)
-_squote_re = re.compile(r"'(?:[^'\\]|\\.)*'")
-_dquote_re = re.compile(r'"(?:[^"\\]|\\.)*"')
-_has_white_re = re.compile(r'\s')
-def split_quoted(s):
- s = string.strip(s)
- words = []
- pos = 0
-
- while s:
- m = _wordchars_re.match(s, pos)
- end = m.end()
- if end == len(s):
- words.append(s[:end])
- break
-
- if s[end] in string.whitespace: # unescaped, unquoted whitespace: now
- words.append(s[:end]) # we definitely have a word delimiter
- s = string.lstrip(s[end:])
- pos = 0
-
- elif s[end] == '\\': # preserve whatever is being escaped;
- # will become part of the current word
- s = s[:end] + s[end+1:]
- pos = end+1
-
- else:
- if s[end] == "'": # slurp singly-quoted string
- m = _squote_re.match(s, end)
- elif s[end] == '"': # slurp doubly-quoted string
- m = _dquote_re.match(s, end)
- else:
- raise RuntimeError, \
- "this can't happen (bad char '%c')" % s[end]
-
- if m is None:
- raise ValueError, \
- "bad string (mismatched %s quotes?)" % s[end]
-
- (beg, end) = m.span()
- if _has_white_re.search(s[beg+1:end-1]):
- s = s[:beg] + s[beg+1:end-1] + s[end:]
- pos = m.end() - 2
- else:
- # Keeping quotes when a quoted word does not contain
- # white-space. XXX: send a patch to distutils
- pos = m.end()
-
- if pos >= len(s):
- words.append(s)
- break
-
- return words
-ccompiler.split_quoted = split_quoted
View
30 distutils/command/__init__.py
@@ -1,30 +0,0 @@
-"""distutils.command
-
-Package containing implementation of all the standard Distutils
-commands."""
-
-__revision__ = "$Id$"
-
-distutils_all = [ 'build_py',
- 'build_scripts',
- 'clean',
- 'install_lib',
- 'install_scripts',
- 'bdist',
- 'bdist_dumb',
- 'bdist_wininst',
- ]
-
-__import__('distutils.command',globals(),locals(),distutils_all)
-
-__all__ = ['build',
- 'config_compiler',
- 'build_src',
- 'build_ext',
- 'build_clib',
- 'install',
- 'install_data',
- 'install_headers',
- 'bdist_rpm',
- 'sdist',
- ] + distutils_all
View
5 distutils/command/bdist_rpm.py
@@ -1,5 +0,0 @@
-from distutils.command.bdist_rpm import bdist_rpm as old_bdist_rpm
-
-class bdist_rpm(old_bdist_rpm):
-
- pass
View
78 distutils/command/build.py
@@ -1,78 +0,0 @@
-# Need to override the build command to include building of fortran libraries
-# This class must be used as the entry for the build key in the cmdclass
-# dictionary which is given to the setup command.
-
-__revision__ = "$Id$"
-
-import sys, os
-from distutils import util
-from distutils.command.build import build as old_build
-
-class build(old_build):
-
- sub_commands = [('config_fc', lambda *args: 1), # new feature
- ('build_src', old_build.has_ext_modules), # new feature
- ('build_py', old_build.has_pure_modules),
- ('build_clib', old_build.has_c_libraries),
- ('build_ext', old_build.has_ext_modules),
- ('build_scripts', old_build.has_scripts),
- ]
-
- def get_plat_specifier(self):
- """ Return a unique string that identifies this platform.
- The string is used to build path names and contains no
- spaces or control characters. (we hope)
- """
- plat_specifier = ".%s-%s" % (util.get_platform(), sys.version[0:3])
-
- #--------------------------------------------------------------------
- # get rid of spaces -- added for OS X support.
- # Use '_' like python2.3
- #--------------------------------------------------------------------
- plat_specifier = plat_specifier.replace(' ','_')
-
- #--------------------------------------------------------------------
- # make lower case ?? is this desired'
- #--------------------------------------------------------------------
- #plat_specifier = plat_specifier.lower()
-
- return plat_specifier
-
- def finalize_options (self):
-
- #--------------------------------------------------------------------
- # This line is re-factored to a function -- everything else in the
- # function is identical to the finalize_options function in the
- # standard distutils build.
- #--------------------------------------------------------------------
- #plat_specifier = ".%s-%s" % (get_platform(), sys.version[0:3])
- plat_specifier = self.get_plat_specifier()
-
- # 'build_purelib' and 'build_platlib' just default to 'lib' and
- # 'lib.<plat>' under the base build directory. We only use one of
- # them for a given distribution, though --
- if self.build_purelib is None:
- self.build_purelib = os.path.join(self.build_base, 'lib')
- if self.build_platlib is None:
- self.build_platlib = os.path.join(self.build_base,
- 'lib' + plat_specifier)
-
- # 'build_lib' is the actual directory that we will use for this
- # particular module distribution -- if user didn't supply it, pick
- # one of 'build_purelib' or 'build_platlib'.
- if self.build_lib is None:
- if self.distribution.ext_modules:
- self.build_lib = self.build_platlib
- else:
- self.build_lib = self.build_purelib
-
- # 'build_temp' -- temporary directory for compiler turds,
- # "build/temp.<plat>"
- if self.build_temp is None:
- self.build_temp = os.path.join(self.build_base,
- 'temp' + plat_specifier)
- if self.build_scripts is None:
- self.build_scripts = os.path.join(self.build_base,
- 'scripts-' + sys.version[0:3])
-
- # finalize_options ()
View
224 distutils/command/build_clib.py
@@ -1,224 +0,0 @@
-""" Modified version of build_clib that handles fortran source files.
-"""
-
-import os
-import string
-import sys
-import re
-from glob import glob
-from types import *
-from distutils.command.build_clib import build_clib as old_build_clib
-from distutils.command.build_clib import show_compilers
-
-from scipy_distutils import log, misc_util
-from distutils.dep_util import newer_group
-from scipy_distutils.misc_util import filter_sources, \
- has_f_sources, has_cxx_sources
-
-def get_headers(directory_list):
- # get *.h files from list of directories
- headers = []
- for dir in directory_list:
- head = glob(os.path.join(dir,"*.h")) #XXX: *.hpp files??
- headers.extend(head)
-
- return headers
-
-def get_directories(list_of_sources):
- # get unique directories from list of sources.
- direcs = []
- for file in list_of_sources:
- dir = os.path.split(file)
- if dir[0] != '' and not dir[0] in direcs:
- direcs.append(dir[0])
- return direcs
-
-class build_clib(old_build_clib):
-
- description = "build C/C++/F libraries used by Python extensions"
-
- user_options = old_build_clib.user_options + [
- ('fcompiler=', None,
- "specify the Fortran compiler type"),
- ]
-
- def initialize_options(self):
- old_build_clib.initialize_options(self)
- self.fcompiler = None
- return
-
- def finalize_options(self):
- old_build_clib.finalize_options(self)
- self.set_undefined_options('build_ext',
- ('fcompiler', 'fcompiler'))
-
- #XXX: This is hackish and probably unnecessary,
- # could we get rid of this?
- from scipy_distutils import misc_util
- extra_includes = misc_util.get_environ_include_dirs()
- if extra_includes:
- print "XXX: are you sure you'll need PYTHONINCLUDES env. variable??"
- self.include_dirs.extend(extra_includes)
-
- return
-
- def have_f_sources(self):
- for (lib_name, build_info) in self.libraries:
- if has_f_sources(build_info.get('sources',[])):
- return 1
- return 0
-
- def have_cxx_sources(self):
- for (lib_name, build_info) in self.libraries:
- if has_cxx_sources(build_info.get('sources',[])):
- return 1
- return 0
-
- def run(self):
- if not self.libraries:
- return
-
- # Make sure that library sources are complete.
- for (lib_name, build_info) in self.libraries:
- if not misc_util.all_strings(build_info.get('sources',[])):
- raise TypeError,'Library "%s" sources contains unresolved'\
- ' items (call build_src before built_clib).' % (lib_name)
-
- from distutils.ccompiler import new_compiler
- self.compiler = new_compiler(compiler=self.compiler,
- dry_run=self.dry_run,
- force=self.force)
- self.compiler.customize(self.distribution,need_cxx=self.have_cxx_sources())
-
- libraries = self.libraries
- self.libraries = None
- self.compiler.customize_cmd(self)
- self.libraries = libraries
-
- self.compiler.show_customization()
-
- if self.have_f_sources():
- from scipy_distutils.fcompiler import new_fcompiler
- self.fcompiler = new_fcompiler(compiler=self.fcompiler,
- verbose=self.verbose,
- dry_run=self.dry_run,
- force=self.force)
- self.fcompiler.customize(self.distribution)
-
- libraries = self.libraries
- self.libraries = None
- self.fcompiler.customize_cmd(self)
- self.libraries = libraries
-
- self.fcompiler.show_customization()
-
- self.build_libraries(self.libraries)
- return
-
- def get_source_files(self):
- from build_ext import is_local_src_dir
- self.check_library_list(self.libraries)
- filenames = []
- def visit_func(filenames,dirname,names):
- if os.path.basename(dirname) in ['CVS','.svn']:
- names[:] = []
- return
- for name in names:
- if name[-1] in "#~":
- continue
- fullname = os.path.join(dirname,name)
- if os.path.isfile(fullname):
- filenames.append(fullname)
- for (lib_name, build_info) in self.libraries:
- sources = build_info.get('sources',[])
- sources = filter(lambda s:type(s) is StringType,sources)
- filenames.extend(sources)
- filenames.extend(get_headers(get_directories(sources)))
- depends = build_info.get('depends',[])
- for d in depends:
- if is_local_src_dir(d):
- os.path.walk(d,visit_func,filenames)
- elif os.path.isfile(d):
- filenames.append(d)
- return filenames
-
- def build_libraries(self, libraries):
-
- compiler = self.compiler
- fcompiler = self.fcompiler
-
- for (lib_name, build_info) in libraries:
- sources = build_info.get('sources')
- if sources is None or type(sources) not in (ListType, TupleType):
- raise DistutilsSetupError, \
- ("in 'libraries' option (library '%s'), " +
- "'sources' must be present and must be " +
- "a list of source filenames") % lib_name
- sources = list(sources)
-
- lib_file = compiler.library_filename(lib_name,
- output_dir=self.build_clib)
-
- depends = sources + build_info.get('depends',[])
- if not (self.force or newer_group(depends, lib_file, 'newer')):
- log.debug("skipping '%s' library (up-to-date)", lib_name)
- continue
- else:
- log.info("building '%s' library", lib_name)
-
- macros = build_info.get('macros')
- include_dirs = build_info.get('include_dirs')
- extra_postargs = build_info.get('extra_compiler_args') or []
-
- c_sources, cxx_sources, f_sources, fmodule_sources \
- = filter_sources(sources)
-
- if self.compiler.compiler_type=='msvc':
- # this hack works around the msvc compiler attributes
- # problem, msvc uses its own convention :(
- c_sources += cxx_sources
- cxx_sources = []
-
- if fmodule_sources:
- print 'XXX: Fortran 90 module support not implemented or tested'
- f_sources.extend(fmodule_sources)
-
- objects = []
- if c_sources:
- log.info("compiling C sources")
- objects = compiler.compile(c_sources,
- output_dir=self.build_temp,
- macros=macros,
- include_dirs=include_dirs,
- debug=self.debug,
- extra_postargs=extra_postargs)
-
- if cxx_sources:
- log.info("compiling C++ sources")
- old_compiler = self.compiler.compiler_so[0]
- self.compiler.compiler_so[0] = self.compiler.compiler_cxx[0]
-
- cxx_objects = compiler.compile(cxx_sources,
- output_dir=self.build_temp,
- macros=macros,
- include_dirs=include_dirs,
- debug=self.debug,
- extra_postargs=extra_postargs)
- objects.extend(cxx_objects)
-
- self.compiler.compiler_so[0] = old_compiler
-
- if f_sources:
- log.info("compiling Fortran sources")
- f_objects = fcompiler.compile(f_sources,
- output_dir=self.build_temp,
- macros=macros,
- include_dirs=include_dirs,
- debug=self.debug,
- extra_postargs=[])
- objects.extend(f_objects)
-
- self.compiler.create_static_lib(objects, lib_name,
- output_dir=self.build_clib,
- debug=self.debug)
- return
View
377 distutils/command/build_ext.py
@@ -1,377 +0,0 @@
-""" Modified version of build_ext that handles fortran source files.
-"""
-
-import os
-import string
-import sys
-from glob import glob
-from types import *
-
-from distutils.dep_util import newer_group, newer
-from distutils.command.build_ext import build_ext as old_build_ext
-
-from scipy_distutils.command.build_clib import get_headers,get_directories
-from scipy_distutils import misc_util, log
-from scipy_distutils.misc_util import filter_sources, has_f_sources, \
- has_cxx_sources
-from distutils.errors import DistutilsFileError
-
-class build_ext (old_build_ext):
-