[ { "hash": "66d1a0865cfde0da460684fe4e88e99a967d8e46", "msg": "added some overloaded \"=\" methods for ListMmbr and DictMmbr classes so that\nassignment from standard C++ types was possible. Now\n\na[0] = \"hello\";\na[1] = 1.3;\na[2] = 1;\n\nshould work for dicts and lists. I think I will overload tuples also to do\nthis, although perhaps immutability says this shouldn't happen...\n\nI expect this is still slow as Christmas compared to using the Python API.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-09-15T07:19:25+00:00", "author_timezone": 0, "committer_date": "2002-09-15T07:19:25+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "83e0c5812a4c3fbc44cf074a7010b8a4b6595bb5" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 0, "insertions": 116, "lines": 116, "files": 4, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "weave/scxx/PWOImp.cpp", "new_path": "weave/scxx/PWOImp.cpp", "filename": "PWOImp.cpp", "extension": "cpp", "change_type": "MODIFY", "diff": "@@ -6,6 +6,7 @@\n #include \"PWOMSequence.h\"\n #include \"PWOMapping.h\"\n #include \"PWOCallable.h\"\n+#include \"PWONumber.h\"\n \n // incref new owner, and decref old owner, and adjust to new owner\n void PWOBase::GrabRef(PyObject* newObj)\n@@ -28,11 +29,73 @@ PWOListMmbr& PWOListMmbr::operator=(const PWOBase& other) {\n _parent.setItem(_ndx, *this);\n return *this;\n }\n+\n+PWOListMmbr& PWOListMmbr::operator=(int other) {\n+ GrabRef(PWONumber(other));\n+ _parent.setItem(_ndx, *this);\n+ return *this;\n+}\n+\n+PWOListMmbr& PWOListMmbr::operator=(float other) {\n+ GrabRef(PWONumber(other));\n+ _parent.setItem(_ndx, *this);\n+ return *this;\n+}\n+\n+PWOListMmbr& PWOListMmbr::operator=(double other) {\n+ GrabRef(PWONumber(other));\n+ _parent.setItem(_ndx, *this);\n+ return *this;\n+}\n+\n+PWOListMmbr& PWOListMmbr::operator=(const char* other) {\n+ GrabRef(PWOString(other));\n+ _parent.setItem(_ndx, *this);\n+ return *this;\n+}\n+\n+PWOListMmbr& PWOListMmbr::operator=(std::string other) {\n+ GrabRef(PWOString(other.c_str()));\n+ _parent.setItem(_ndx, *this);\n+ return *this;\n+}\n+\n PWOMappingMmbr& PWOMappingMmbr::operator=(const PWOBase& other) {\n GrabRef(other);\n _parent.setItem(_key, *this);\n return *this;\n }\n+\n+PWOMappingMmbr& PWOMappingMmbr::operator=(int other) {\n+ GrabRef(PWONumber(other));\n+ _parent.setItem(_key, *this);\n+ return *this;\n+}\n+\n+PWOMappingMmbr& PWOMappingMmbr::operator=(float other) {\n+ GrabRef(PWONumber(other));\n+ _parent.setItem(_key, *this);\n+ return *this;\n+}\n+\n+PWOMappingMmbr& PWOMappingMmbr::operator=(double other) {\n+ GrabRef(PWONumber(other));\n+ _parent.setItem(_key, *this);\n+ return *this;\n+}\n+\n+PWOMappingMmbr& PWOMappingMmbr::operator=(const char* other) {\n+ GrabRef(PWOString(other));\n+ _parent.setItem(_key, *this);\n+ return *this;\n+}\n+\n+PWOMappingMmbr& PWOMappingMmbr::operator=(std::string other) {\n+ GrabRef(PWOString(other.c_str()));\n+ _parent.setItem(_key, *this);\n+ return *this;\n+}\n+\n PWOBase PWOCallable::call() const {\n static PWOTuple _empty;\n PyObject *rslt = PyEval_CallObjectWithKeywords(*this, _empty, NULL);\n", "added_lines": 63, "deleted_lines": 0, "source_code": "/******************************************** \n copyright 1999 McMillan Enterprises, Inc.\n www.mcmillan-inc.com\n*********************************************/\n#include \"PWOSequence.h\"\n#include \"PWOMSequence.h\"\n#include \"PWOMapping.h\"\n#include \"PWOCallable.h\"\n#include \"PWONumber.h\"\n\n // incref new owner, and decref old owner, and adjust to new owner\nvoid PWOBase::GrabRef(PyObject* newObj)\n{\n // be careful to incref before decref if old is same as new\n Py_XINCREF(newObj);\n Py_XDECREF(_own);\n _own = _obj = newObj;\n}\n\nPWOTuple::PWOTuple(const PWOList& list)\n : PWOSequence (PyList_AsTuple(list)) { LoseRef(_obj); }\n\nPWOListMmbr::PWOListMmbr(PyObject* obj, PWOList& parent, int ndx) \n : PWOBase(obj), _parent(parent), _ndx(ndx) { }\n\nPWOListMmbr& PWOListMmbr::operator=(const PWOBase& other) {\n GrabRef(other);\n //Py_XINCREF(_obj); // this one is for setItem to steal\n _parent.setItem(_ndx, *this);\n return *this;\n}\n\nPWOListMmbr& PWOListMmbr::operator=(int other) {\n GrabRef(PWONumber(other));\n _parent.setItem(_ndx, *this);\n return *this;\n}\n\nPWOListMmbr& PWOListMmbr::operator=(float other) {\n GrabRef(PWONumber(other));\n _parent.setItem(_ndx, *this);\n return *this;\n}\n\nPWOListMmbr& PWOListMmbr::operator=(double other) {\n GrabRef(PWONumber(other));\n _parent.setItem(_ndx, *this);\n return *this;\n}\n\nPWOListMmbr& PWOListMmbr::operator=(const char* other) {\n GrabRef(PWOString(other));\n _parent.setItem(_ndx, *this);\n return *this;\n}\n\nPWOListMmbr& PWOListMmbr::operator=(std::string other) {\n GrabRef(PWOString(other.c_str()));\n _parent.setItem(_ndx, *this);\n return *this;\n}\n\nPWOMappingMmbr& PWOMappingMmbr::operator=(const PWOBase& other) {\n GrabRef(other);\n _parent.setItem(_key, *this);\n return *this;\n}\n\nPWOMappingMmbr& PWOMappingMmbr::operator=(int other) {\n GrabRef(PWONumber(other));\n _parent.setItem(_key, *this);\n return *this;\n}\n\nPWOMappingMmbr& PWOMappingMmbr::operator=(float other) {\n GrabRef(PWONumber(other));\n _parent.setItem(_key, *this);\n return *this;\n}\n\nPWOMappingMmbr& PWOMappingMmbr::operator=(double other) {\n GrabRef(PWONumber(other));\n _parent.setItem(_key, *this);\n return *this;\n}\n\nPWOMappingMmbr& PWOMappingMmbr::operator=(const char* other) {\n GrabRef(PWOString(other));\n _parent.setItem(_key, *this);\n return *this;\n}\n\nPWOMappingMmbr& PWOMappingMmbr::operator=(std::string other) {\n GrabRef(PWOString(other.c_str()));\n _parent.setItem(_key, *this);\n return *this;\n}\n\nPWOBase PWOCallable::call() const {\n static PWOTuple _empty;\n PyObject *rslt = PyEval_CallObjectWithKeywords(*this, _empty, NULL);\n if (rslt == 0)\n throw 1;\n return rslt;\n}\nPWOBase PWOCallable::call(PWOTuple& args) const {\n PyObject *rslt = PyEval_CallObjectWithKeywords(*this, args, NULL);\n if (rslt == 0)\n throw 1;\n return rslt;\n}\nPWOBase PWOCallable::call(PWOTuple& args, PWOMapping& kws) const {\n PyObject *rslt = PyEval_CallObjectWithKeywords(*this, args, kws);\n if (rslt == 0)\n throw 1;\n return rslt;\n}\n\nvoid Fail(PyObject* exc, const char* msg)\n{\n PyErr_SetString(exc, msg);\n throw 1;\n}\n", "source_code_before": "/******************************************** \n copyright 1999 McMillan Enterprises, Inc.\n www.mcmillan-inc.com\n*********************************************/\n#include \"PWOSequence.h\"\n#include \"PWOMSequence.h\"\n#include \"PWOMapping.h\"\n#include \"PWOCallable.h\"\n\n // incref new owner, and decref old owner, and adjust to new owner\nvoid PWOBase::GrabRef(PyObject* newObj)\n{\n // be careful to incref before decref if old is same as new\n Py_XINCREF(newObj);\n Py_XDECREF(_own);\n _own = _obj = newObj;\n}\n\nPWOTuple::PWOTuple(const PWOList& list)\n : PWOSequence (PyList_AsTuple(list)) { LoseRef(_obj); }\n\nPWOListMmbr::PWOListMmbr(PyObject* obj, PWOList& parent, int ndx) \n : PWOBase(obj), _parent(parent), _ndx(ndx) { }\n\nPWOListMmbr& PWOListMmbr::operator=(const PWOBase& other) {\n GrabRef(other);\n //Py_XINCREF(_obj); // this one is for setItem to steal\n _parent.setItem(_ndx, *this);\n return *this;\n}\nPWOMappingMmbr& PWOMappingMmbr::operator=(const PWOBase& other) {\n GrabRef(other);\n _parent.setItem(_key, *this);\n return *this;\n}\nPWOBase PWOCallable::call() const {\n static PWOTuple _empty;\n PyObject *rslt = PyEval_CallObjectWithKeywords(*this, _empty, NULL);\n if (rslt == 0)\n throw 1;\n return rslt;\n}\nPWOBase PWOCallable::call(PWOTuple& args) const {\n PyObject *rslt = PyEval_CallObjectWithKeywords(*this, args, NULL);\n if (rslt == 0)\n throw 1;\n return rslt;\n}\nPWOBase PWOCallable::call(PWOTuple& args, PWOMapping& kws) const {\n PyObject *rslt = PyEval_CallObjectWithKeywords(*this, args, kws);\n if (rslt == 0)\n throw 1;\n return rslt;\n}\n\nvoid Fail(PyObject* exc, const char* msg)\n{\n PyErr_SetString(exc, msg);\n throw 1;\n}\n", "methods": [ { "name": "PWOBase::GrabRef", "long_name": "PWOBase::GrabRef( PyObject * newObj)", "filename": "PWOImp.cpp", "nloc": 6, "complexity": 1, "token_count": 26, "parameters": [ "newObj" ], "start_line": 12, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PWOTuple::PWOTuple", "long_name": "PWOTuple::PWOTuple( const PWOList & list)", "filename": "PWOImp.cpp", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "list" ], "start_line": 20, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "PWOListMmbr::PWOListMmbr", "long_name": "PWOListMmbr::PWOListMmbr( PyObject * obj , PWOList & parent , int ndx)", "filename": "PWOImp.cpp", "nloc": 2, "complexity": 1, "token_count": 32, "parameters": [ "obj", "parent", "ndx" ], "start_line": 23, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "PWOListMmbr::operator =", "long_name": "PWOListMmbr::operator =( const PWOBase & other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "other" ], "start_line": 26, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PWOListMmbr::operator =", "long_name": "PWOListMmbr::operator =( int other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "other" ], "start_line": 33, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOListMmbr::operator =", "long_name": "PWOListMmbr::operator =( float other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "other" ], "start_line": 39, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOListMmbr::operator =", "long_name": "PWOListMmbr::operator =( double other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "other" ], "start_line": 45, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOListMmbr::operator =", "long_name": "PWOListMmbr::operator =( const char * other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 34, "parameters": [ "other" ], "start_line": 51, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOListMmbr::operator =", "long_name": "PWOListMmbr::operator =( std :: string other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 38, "parameters": [ "std" ], "start_line": 57, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOMappingMmbr::operator =", "long_name": "PWOMappingMmbr::operator =( const PWOBase & other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "other" ], "start_line": 63, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOMappingMmbr::operator =", "long_name": "PWOMappingMmbr::operator =( int other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "other" ], "start_line": 69, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOMappingMmbr::operator =", "long_name": "PWOMappingMmbr::operator =( float other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "other" ], "start_line": 75, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOMappingMmbr::operator =", "long_name": "PWOMappingMmbr::operator =( double other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "other" ], "start_line": 81, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOMappingMmbr::operator =", "long_name": "PWOMappingMmbr::operator =( const char * other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 34, "parameters": [ "other" ], "start_line": 87, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOMappingMmbr::operator =", "long_name": "PWOMappingMmbr::operator =( std :: string other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 38, "parameters": [ "std" ], "start_line": 93, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOCallable::call", "long_name": "PWOCallable::call() const", "filename": "PWOImp.cpp", "nloc": 7, "complexity": 2, "token_count": 38, "parameters": [], "start_line": 99, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PWOCallable::call", "long_name": "PWOCallable::call( PWOTuple & args) const", "filename": "PWOImp.cpp", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "args" ], "start_line": 106, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PWOCallable::call", "long_name": "PWOCallable::call( PWOTuple & args , PWOMapping & kws) const", "filename": "PWOImp.cpp", "nloc": 6, "complexity": 2, "token_count": 41, "parameters": [ "args", "kws" ], "start_line": 112, "end_line": 117, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "Fail", "long_name": "Fail( PyObject * exc , const char * msg)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [ "exc", "msg" ], "start_line": 119, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "PWOBase::GrabRef", "long_name": "PWOBase::GrabRef( PyObject * newObj)", "filename": "PWOImp.cpp", "nloc": 6, "complexity": 1, "token_count": 26, "parameters": [ "newObj" ], "start_line": 11, "end_line": 17, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PWOTuple::PWOTuple", "long_name": "PWOTuple::PWOTuple( const PWOList & list)", "filename": "PWOImp.cpp", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "list" ], "start_line": 19, "end_line": 20, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "PWOListMmbr::PWOListMmbr", "long_name": "PWOListMmbr::PWOListMmbr( PyObject * obj , PWOList & parent , int ndx)", "filename": "PWOImp.cpp", "nloc": 2, "complexity": 1, "token_count": 32, "parameters": [ "obj", "parent", "ndx" ], "start_line": 22, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "PWOListMmbr::operator =", "long_name": "PWOListMmbr::operator =( const PWOBase & other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "other" ], "start_line": 25, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PWOMappingMmbr::operator =", "long_name": "PWOMappingMmbr::operator =( const PWOBase & other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "other" ], "start_line": 31, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOCallable::call", "long_name": "PWOCallable::call() const", "filename": "PWOImp.cpp", "nloc": 7, "complexity": 2, "token_count": 38, "parameters": [], "start_line": 36, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "PWOCallable::call", "long_name": "PWOCallable::call( PWOTuple & args) const", "filename": "PWOImp.cpp", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "args" ], "start_line": 43, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "PWOCallable::call", "long_name": "PWOCallable::call( PWOTuple & args , PWOMapping & kws) const", "filename": "PWOImp.cpp", "nloc": 6, "complexity": 2, "token_count": 41, "parameters": [ "args", "kws" ], "start_line": 49, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "Fail", "long_name": "Fail( PyObject * exc , const char * msg)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [ "exc", "msg" ], "start_line": 56, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "PWOMappingMmbr::operator =", "long_name": "PWOMappingMmbr::operator =( float other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "other" ], "start_line": 75, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOMappingMmbr::operator =", "long_name": "PWOMappingMmbr::operator =( double other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "other" ], "start_line": 81, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOMappingMmbr::operator =", "long_name": "PWOMappingMmbr::operator =( int other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "other" ], "start_line": 69, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOMappingMmbr::operator =", "long_name": "PWOMappingMmbr::operator =( const char * other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 34, "parameters": [ "other" ], "start_line": 87, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOMappingMmbr::operator =", "long_name": "PWOMappingMmbr::operator =( std :: string other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 38, "parameters": [ "std" ], "start_line": 93, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOListMmbr::operator =", "long_name": "PWOListMmbr::operator =( const char * other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 34, "parameters": [ "other" ], "start_line": 51, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOListMmbr::operator =", "long_name": "PWOListMmbr::operator =( double other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "other" ], "start_line": 45, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOListMmbr::operator =", "long_name": "PWOListMmbr::operator =( int other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "other" ], "start_line": 33, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOListMmbr::operator =", "long_name": "PWOListMmbr::operator =( std :: string other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 38, "parameters": [ "std" ], "start_line": 57, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "PWOListMmbr::operator =", "long_name": "PWOListMmbr::operator =( float other)", "filename": "PWOImp.cpp", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "other" ], "start_line": 39, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 99, "complexity": 22, "token_count": 658, "diff_parsed": { "added": [ "#include \"PWONumber.h\"", "", "PWOListMmbr& PWOListMmbr::operator=(int other) {", " GrabRef(PWONumber(other));", " _parent.setItem(_ndx, *this);", " return *this;", "}", "", "PWOListMmbr& PWOListMmbr::operator=(float other) {", " GrabRef(PWONumber(other));", " _parent.setItem(_ndx, *this);", " return *this;", "}", "", "PWOListMmbr& PWOListMmbr::operator=(double other) {", " GrabRef(PWONumber(other));", " _parent.setItem(_ndx, *this);", " return *this;", "}", "", "PWOListMmbr& PWOListMmbr::operator=(const char* other) {", " GrabRef(PWOString(other));", " _parent.setItem(_ndx, *this);", " return *this;", "}", "", "PWOListMmbr& PWOListMmbr::operator=(std::string other) {", " GrabRef(PWOString(other.c_str()));", " _parent.setItem(_ndx, *this);", " return *this;", "}", "", "", "PWOMappingMmbr& PWOMappingMmbr::operator=(int other) {", " GrabRef(PWONumber(other));", " _parent.setItem(_key, *this);", " return *this;", "}", "", "PWOMappingMmbr& PWOMappingMmbr::operator=(float other) {", " GrabRef(PWONumber(other));", " _parent.setItem(_key, *this);", " return *this;", "}", "", "PWOMappingMmbr& PWOMappingMmbr::operator=(double other) {", " GrabRef(PWONumber(other));", " _parent.setItem(_key, *this);", " return *this;", "}", "", "PWOMappingMmbr& PWOMappingMmbr::operator=(const char* other) {", " GrabRef(PWOString(other));", " _parent.setItem(_key, *this);", " return *this;", "}", "", "PWOMappingMmbr& PWOMappingMmbr::operator=(std::string other) {", " GrabRef(PWOString(other.c_str()));", " _parent.setItem(_key, *this);", " return *this;", "}", "" ], "deleted": [] } }, { "old_path": "weave/scxx/PWOMSequence.h", "new_path": "weave/scxx/PWOMSequence.h", "filename": "PWOMSequence.h", "extension": "h", "change_type": "MODIFY", "diff": "@@ -11,6 +11,7 @@\n \n #include \"PWOBase.h\"\n #include \"PWOSequence.h\"\n+#include \n \n \n class PWOList;\n@@ -23,6 +24,11 @@ public:\n PWOListMmbr(PyObject* obj, PWOList& parent, int ndx);\n virtual ~PWOListMmbr() {};\n PWOListMmbr& operator=(const PWOBase& other);\n+ PWOListMmbr& operator=(int other);\n+ PWOListMmbr& operator=(float other);\n+ PWOListMmbr& operator=(double other);\n+ PWOListMmbr& operator=(const char* other);\n+ PWOListMmbr& operator=(std::string other);\n };\n \n class PWOList : public PWOSequence\n", "added_lines": 6, "deleted_lines": 0, "source_code": "/******************************************** \n copyright 1999 McMillan Enterprises, Inc.\n www.mcmillan-inc.com\n*********************************************/\n#if !defined(PWOMSEQUENCE_H_INCLUDED_)\n#define PWOMSEQUENCE_H_INCLUDED_\n\n#if _MSC_VER >= 1000\n#pragma once\n#endif // _MSC_VER >= 1000\n\n#include \"PWOBase.h\"\n#include \"PWOSequence.h\"\n#include \n\n\nclass PWOList;\n\nclass PWOListMmbr : public PWOBase\n{\n PWOList& _parent;\n int _ndx;\npublic:\n PWOListMmbr(PyObject* obj, PWOList& parent, int ndx);\n virtual ~PWOListMmbr() {};\n PWOListMmbr& operator=(const PWOBase& other);\n PWOListMmbr& operator=(int other);\n PWOListMmbr& operator=(float other);\n PWOListMmbr& operator=(double other);\n PWOListMmbr& operator=(const char* other);\n PWOListMmbr& operator=(std::string other);\n};\n\nclass PWOList : public PWOSequence\n{\npublic:\n PWOList(int size=0) : PWOSequence (PyList_New(size)) { LoseRef(_obj); }\n PWOList(const PWOList& other) : PWOSequence(other) {};\n PWOList(PyObject* obj) : PWOSequence(obj) {\n _violentTypeCheck();\n };\n virtual ~PWOList() {};\n\n virtual PWOList& operator=(const PWOList& other) {\n GrabRef(other);\n return *this;\n };\n PWOList& operator=(const PWOBase& other) {\n GrabRef(other);\n _violentTypeCheck();\n return *this;\n };\n virtual void _violentTypeCheck() {\n if (!PyList_Check(_obj)) { //should probably check the sequence methods for non-0 setitem\n GrabRef(0);\n Fail(PyExc_TypeError, \"Not a mutable sequence\");\n }\n };\n //PySequence_DelItem ##lists\n bool delItem(int i) {\n int rslt = PySequence_DelItem(_obj, i);\n if (rslt == -1)\n Fail(PyExc_RuntimeError, \"cannot delete item\");\n return true;\n };\n //PySequence_DelSlice ##lists\n bool delSlice(int lo, int hi) {\n int rslt = PySequence_DelSlice(_obj, lo, hi);\n if (rslt == -1)\n Fail(PyExc_RuntimeError, \"cannot delete slice\");\n return true;\n };\n //PySequence_GetItem ##lists - return PWOListMmbr (mutable) otherwise just a PWOBase\n PWOListMmbr operator [] (int i) { // can't be virtual\n //PyObject* o = PySequence_GetItem(_obj, i); assumes item is valid\n PyObject* o = PyList_GetItem(_obj, i); // get a \"borrowed\" refcount\n //Py_XINCREF(o);\n //if (o == 0)\n // Fail(PyExc_IndexError, \"index out of range\");\n return PWOListMmbr(o, *this, i); // this increfs\n };\n //PySequence_SetItem ##Lists\n void setItem(int ndx, PWOBase& val) {\n //int rslt = PySequence_SetItem(_obj, ndx, val); - assumes old item is valid\n int rslt = PyList_SetItem(_obj, ndx, val);\n val.disOwn(); //when using PyList_SetItem, he steals my reference\n if (rslt==-1)\n Fail(PyExc_IndexError, \"Index out of range\");\n };\n //PySequence_SetSlice ##Lists\n void setSlice(int lo, int hi, const PWOSequence& slice) {\n int rslt = PySequence_SetSlice(_obj, lo, hi, slice);\n if (rslt==-1)\n Fail(PyExc_RuntimeError, \"Error setting slice\");\n };\n //PyList_Append\n PWOList& append(const PWOBase& other) {\n int rslt = PyList_Append(_obj, other);\n if (rslt==-1) {\n PyErr_Clear(); //Python sets one \n Fail(PyExc_RuntimeError, \"Error appending\");\n };\n return *this;\n };\n //PyList_AsTuple\n // problem with this is it's created on the heap\n //virtual PWOTuple& asTuple() const {\n // PyObject* rslt = PyList_AsTuple(_obj);\n // PWOTuple rtrn = new PWOTuple(rslt);\n // Py_XDECREF(rslt); //AsTuple set refcnt to 1, PWOTuple(rslt) increffed\n // return *rtrn;\n //};\n //PyList_GetItem - inherited OK\n //PyList_GetSlice - inherited OK\n //PyList_Insert\n PWOList& insert(int ndx, PWOBase& other) {\n int rslt = PyList_Insert(_obj, ndx, other);\n if (rslt==-1) {\n PyErr_Clear(); //Python sets one \n Fail(PyExc_RuntimeError, \"Error inserting\");\n };\n return *this;\n };\n //PyList_New\n //PyList_Reverse\n PWOList& reverse() {\n int rslt = PyList_Reverse(_obj);\n if (rslt==-1) {\n PyErr_Clear(); //Python sets one \n Fail(PyExc_RuntimeError, \"Error reversing\");\n };\n return *this; //HA HA - Guido can't stop me!!!\n };\n //PyList_SetItem - using abstract\n //PyList_SetSlice - using abstract\n //PyList_Size - inherited OK\n //PyList_Sort\n PWOList& sort() {\n int rslt = PyList_Sort(_obj);\n if (rslt==-1) {\n PyErr_Clear(); //Python sets one \n Fail(PyExc_RuntimeError, \"Error sorting\");\n };\n return *this; //HA HA - Guido can't stop me!!!\n };\n};\n\n#endif // PWOMSEQUENCE_H_INCLUDED_\n", "source_code_before": "/******************************************** \n copyright 1999 McMillan Enterprises, Inc.\n www.mcmillan-inc.com\n*********************************************/\n#if !defined(PWOMSEQUENCE_H_INCLUDED_)\n#define PWOMSEQUENCE_H_INCLUDED_\n\n#if _MSC_VER >= 1000\n#pragma once\n#endif // _MSC_VER >= 1000\n\n#include \"PWOBase.h\"\n#include \"PWOSequence.h\"\n\n\nclass PWOList;\n\nclass PWOListMmbr : public PWOBase\n{\n PWOList& _parent;\n int _ndx;\npublic:\n PWOListMmbr(PyObject* obj, PWOList& parent, int ndx);\n virtual ~PWOListMmbr() {};\n PWOListMmbr& operator=(const PWOBase& other);\n};\n\nclass PWOList : public PWOSequence\n{\npublic:\n PWOList(int size=0) : PWOSequence (PyList_New(size)) { LoseRef(_obj); }\n PWOList(const PWOList& other) : PWOSequence(other) {};\n PWOList(PyObject* obj) : PWOSequence(obj) {\n _violentTypeCheck();\n };\n virtual ~PWOList() {};\n\n virtual PWOList& operator=(const PWOList& other) {\n GrabRef(other);\n return *this;\n };\n PWOList& operator=(const PWOBase& other) {\n GrabRef(other);\n _violentTypeCheck();\n return *this;\n };\n virtual void _violentTypeCheck() {\n if (!PyList_Check(_obj)) { //should probably check the sequence methods for non-0 setitem\n GrabRef(0);\n Fail(PyExc_TypeError, \"Not a mutable sequence\");\n }\n };\n //PySequence_DelItem ##lists\n bool delItem(int i) {\n int rslt = PySequence_DelItem(_obj, i);\n if (rslt == -1)\n Fail(PyExc_RuntimeError, \"cannot delete item\");\n return true;\n };\n //PySequence_DelSlice ##lists\n bool delSlice(int lo, int hi) {\n int rslt = PySequence_DelSlice(_obj, lo, hi);\n if (rslt == -1)\n Fail(PyExc_RuntimeError, \"cannot delete slice\");\n return true;\n };\n //PySequence_GetItem ##lists - return PWOListMmbr (mutable) otherwise just a PWOBase\n PWOListMmbr operator [] (int i) { // can't be virtual\n //PyObject* o = PySequence_GetItem(_obj, i); assumes item is valid\n PyObject* o = PyList_GetItem(_obj, i); // get a \"borrowed\" refcount\n //Py_XINCREF(o);\n //if (o == 0)\n // Fail(PyExc_IndexError, \"index out of range\");\n return PWOListMmbr(o, *this, i); // this increfs\n };\n //PySequence_SetItem ##Lists\n void setItem(int ndx, PWOBase& val) {\n //int rslt = PySequence_SetItem(_obj, ndx, val); - assumes old item is valid\n int rslt = PyList_SetItem(_obj, ndx, val);\n val.disOwn(); //when using PyList_SetItem, he steals my reference\n if (rslt==-1)\n Fail(PyExc_IndexError, \"Index out of range\");\n };\n //PySequence_SetSlice ##Lists\n void setSlice(int lo, int hi, const PWOSequence& slice) {\n int rslt = PySequence_SetSlice(_obj, lo, hi, slice);\n if (rslt==-1)\n Fail(PyExc_RuntimeError, \"Error setting slice\");\n };\n //PyList_Append\n PWOList& append(const PWOBase& other) {\n int rslt = PyList_Append(_obj, other);\n if (rslt==-1) {\n PyErr_Clear(); //Python sets one \n Fail(PyExc_RuntimeError, \"Error appending\");\n };\n return *this;\n };\n //PyList_AsTuple\n // problem with this is it's created on the heap\n //virtual PWOTuple& asTuple() const {\n // PyObject* rslt = PyList_AsTuple(_obj);\n // PWOTuple rtrn = new PWOTuple(rslt);\n // Py_XDECREF(rslt); //AsTuple set refcnt to 1, PWOTuple(rslt) increffed\n // return *rtrn;\n //};\n //PyList_GetItem - inherited OK\n //PyList_GetSlice - inherited OK\n //PyList_Insert\n PWOList& insert(int ndx, PWOBase& other) {\n int rslt = PyList_Insert(_obj, ndx, other);\n if (rslt==-1) {\n PyErr_Clear(); //Python sets one \n Fail(PyExc_RuntimeError, \"Error inserting\");\n };\n return *this;\n };\n //PyList_New\n //PyList_Reverse\n PWOList& reverse() {\n int rslt = PyList_Reverse(_obj);\n if (rslt==-1) {\n PyErr_Clear(); //Python sets one \n Fail(PyExc_RuntimeError, \"Error reversing\");\n };\n return *this; //HA HA - Guido can't stop me!!!\n };\n //PyList_SetItem - using abstract\n //PyList_SetSlice - using abstract\n //PyList_Size - inherited OK\n //PyList_Sort\n PWOList& sort() {\n int rslt = PyList_Sort(_obj);\n if (rslt==-1) {\n PyErr_Clear(); //Python sets one \n Fail(PyExc_RuntimeError, \"Error sorting\");\n };\n return *this; //HA HA - Guido can't stop me!!!\n };\n};\n\n#endif // PWOMSEQUENCE_H_INCLUDED_\n", "methods": [ { "name": "PWOListMmbr::~PWOListMmbr", "long_name": "PWOListMmbr::~PWOListMmbr()", "filename": "PWOMSequence.h", "nloc": 1, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 25, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOList::PWOList", "long_name": "PWOList::PWOList( int size = 0)", "filename": "PWOMSequence.h", "nloc": 1, "complexity": 1, "token_count": 22, "parameters": [ "size" ], "start_line": 37, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOList::PWOList", "long_name": "PWOList::PWOList( const PWOList & other)", "filename": "PWOMSequence.h", "nloc": 1, "complexity": 1, "token_count": 14, "parameters": [ "other" ], "start_line": 38, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOList::PWOList", "long_name": "PWOList::PWOList( PyObject * obj)", "filename": "PWOMSequence.h", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "obj" ], "start_line": 39, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOList::~PWOList", "long_name": "PWOList::~PWOList()", "filename": "PWOMSequence.h", "nloc": 1, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 42, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOList::operator =", "long_name": "PWOList::operator =( const PWOList & other)", "filename": "PWOMSequence.h", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "other" ], "start_line": 44, "end_line": 47, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "PWOList::operator =", "long_name": "PWOList::operator =( const PWOBase & other)", "filename": "PWOMSequence.h", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [ "other" ], "start_line": 48, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOList::_violentTypeCheck", "long_name": "PWOList::_violentTypeCheck()", "filename": "PWOMSequence.h", "nloc": 6, "complexity": 2, "token_count": 27, "parameters": [], "start_line": 53, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOList::delItem", "long_name": "PWOList::delItem( int i)", "filename": "PWOMSequence.h", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "i" ], "start_line": 60, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOList::delSlice", "long_name": "PWOList::delSlice( int lo , int hi)", "filename": "PWOMSequence.h", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "lo", "hi" ], "start_line": 67, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOList::operator [ ]", "long_name": "PWOList::operator [ ]( int i)", "filename": "PWOMSequence.h", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "i" ], "start_line": 74, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "PWOList::setItem", "long_name": "PWOList::setItem( int ndx , PWOBase & val)", "filename": "PWOMSequence.h", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "ndx", "val" ], "start_line": 83, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "PWOList::setSlice", "long_name": "PWOList::setSlice( int lo , int hi , const PWOSequence & slice)", "filename": "PWOMSequence.h", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "lo", "hi", "slice" ], "start_line": 91, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOList::append", "long_name": "PWOList::append( const PWOBase & other)", "filename": "PWOMSequence.h", "nloc": 8, "complexity": 2, "token_count": 44, "parameters": [ "other" ], "start_line": 97, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "PWOList::insert", "long_name": "PWOList::insert( int ndx , PWOBase & other)", "filename": "PWOMSequence.h", "nloc": 8, "complexity": 2, "token_count": 48, "parameters": [ "ndx", "other" ], "start_line": 116, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "PWOList::reverse", "long_name": "PWOList::reverse()", "filename": "PWOMSequence.h", "nloc": 8, "complexity": 2, "token_count": 38, "parameters": [], "start_line": 126, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "PWOList::sort", "long_name": "PWOList::sort()", "filename": "PWOMSequence.h", "nloc": 8, "complexity": 2, "token_count": 38, "parameters": [], "start_line": 138, "end_line": 145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 } ], "methods_before": [ { "name": "PWOListMmbr::~PWOListMmbr", "long_name": "PWOListMmbr::~PWOListMmbr()", "filename": "PWOMSequence.h", "nloc": 1, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 24, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOList::PWOList", "long_name": "PWOList::PWOList( int size = 0)", "filename": "PWOMSequence.h", "nloc": 1, "complexity": 1, "token_count": 22, "parameters": [ "size" ], "start_line": 31, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOList::PWOList", "long_name": "PWOList::PWOList( const PWOList & other)", "filename": "PWOMSequence.h", "nloc": 1, "complexity": 1, "token_count": 14, "parameters": [ "other" ], "start_line": 32, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOList::PWOList", "long_name": "PWOList::PWOList( PyObject * obj)", "filename": "PWOMSequence.h", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "obj" ], "start_line": 33, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOList::~PWOList", "long_name": "PWOList::~PWOList()", "filename": "PWOMSequence.h", "nloc": 1, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 36, "end_line": 36, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOList::operator =", "long_name": "PWOList::operator =( const PWOList & other)", "filename": "PWOMSequence.h", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "other" ], "start_line": 38, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "PWOList::operator =", "long_name": "PWOList::operator =( const PWOBase & other)", "filename": "PWOMSequence.h", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [ "other" ], "start_line": 42, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOList::_violentTypeCheck", "long_name": "PWOList::_violentTypeCheck()", "filename": "PWOMSequence.h", "nloc": 6, "complexity": 2, "token_count": 27, "parameters": [], "start_line": 47, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOList::delItem", "long_name": "PWOList::delItem( int i)", "filename": "PWOMSequence.h", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "i" ], "start_line": 54, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOList::delSlice", "long_name": "PWOList::delSlice( int lo , int hi)", "filename": "PWOMSequence.h", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "lo", "hi" ], "start_line": 61, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOList::operator [ ]", "long_name": "PWOList::operator [ ]( int i)", "filename": "PWOMSequence.h", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "i" ], "start_line": 68, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "PWOList::setItem", "long_name": "PWOList::setItem( int ndx , PWOBase & val)", "filename": "PWOMSequence.h", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "ndx", "val" ], "start_line": 77, "end_line": 83, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "PWOList::setSlice", "long_name": "PWOList::setSlice( int lo , int hi , const PWOSequence & slice)", "filename": "PWOMSequence.h", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "lo", "hi", "slice" ], "start_line": 85, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOList::append", "long_name": "PWOList::append( const PWOBase & other)", "filename": "PWOMSequence.h", "nloc": 8, "complexity": 2, "token_count": 44, "parameters": [ "other" ], "start_line": 91, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "PWOList::insert", "long_name": "PWOList::insert( int ndx , PWOBase & other)", "filename": "PWOMSequence.h", "nloc": 8, "complexity": 2, "token_count": 48, "parameters": [ "ndx", "other" ], "start_line": 110, "end_line": 117, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "PWOList::reverse", "long_name": "PWOList::reverse()", "filename": "PWOMSequence.h", "nloc": 8, "complexity": 2, "token_count": 38, "parameters": [], "start_line": 120, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "PWOList::sort", "long_name": "PWOList::sort()", "filename": "PWOMSequence.h", "nloc": 8, "complexity": 2, "token_count": 38, "parameters": [], "start_line": 132, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 102, "complexity": 26, "token_count": 638, "diff_parsed": { "added": [ "#include ", " PWOListMmbr& operator=(int other);", " PWOListMmbr& operator=(float other);", " PWOListMmbr& operator=(double other);", " PWOListMmbr& operator=(const char* other);", " PWOListMmbr& operator=(std::string other);" ], "deleted": [] } }, { "old_path": "weave/scxx/PWOMapping.h", "new_path": "weave/scxx/PWOMapping.h", "filename": "PWOMapping.h", "extension": "h", "change_type": "MODIFY", "diff": "@@ -7,6 +7,8 @@\n \n #include \"PWOBase.h\"\n #include \"PWOMSequence.h\"\n+#include \"PWONumber.h\"\n+#include \n \n class PWOMapping;\n \n@@ -24,6 +26,11 @@ public:\n Py_XDECREF(_key);\n };\n PWOMappingMmbr& operator=(const PWOBase& other);\n+ PWOMappingMmbr& operator=(int other);\n+ PWOMappingMmbr& operator=(float other);\n+ PWOMappingMmbr& operator=(double other);\n+ PWOMappingMmbr& operator=(const char* other);\n+ PWOMappingMmbr& operator=(std::string other);\n };\n \n class PWOMapping : public PWOBase\n@@ -61,6 +68,15 @@ public:\n PWOString _key(key);\n return PWOMappingMmbr(rslt, *this, _key);\n };\n+\n+ PWOMappingMmbr operator [] (std::string key) {\n+ PyObject* rslt = PyMapping_GetItemString(_obj, (char*) key.c_str());\n+ if (rslt==0)\n+ PyErr_Clear();\n+ PWOString _key(key.c_str());\n+ return PWOMappingMmbr(rslt, *this, _key);\n+ };\n+ \n //PyDict_GetItem\n PWOMappingMmbr operator [] (PyObject* key) {\n PyObject* rslt = PyDict_GetItem(_obj, key);\n@@ -68,6 +84,33 @@ public:\n // Fail(PyExc_KeyError, \"Key not found\");\n return PWOMappingMmbr(rslt, *this, key);\n };\n+\n+ //PyDict_GetItem\n+ PWOMappingMmbr operator [] (int key) {\n+ PWONumber _key = PWONumber(key);\n+ PyObject* rslt = PyDict_GetItem(_obj, _key);\n+ //if (rslt==0)\n+ // Fail(PyExc_KeyError, \"Key not found\");\n+ return PWOMappingMmbr(rslt, *this, _key);\n+ };\n+ \n+ //PyDict_GetItem\n+ PWOMappingMmbr operator [] (float key) {\n+ PWONumber _key = PWONumber(key);\n+ PyObject* rslt = PyDict_GetItem(_obj, _key);\n+ //if (rslt==0)\n+ // Fail(PyExc_KeyError, \"Key not found\");\n+ return PWOMappingMmbr(rslt, *this, _key);\n+ };\n+\n+ PWOMappingMmbr operator [] (double key) {\n+ PWONumber _key = PWONumber(key);\n+ PyObject* rslt = PyDict_GetItem(_obj, _key);\n+ //if (rslt==0)\n+ // Fail(PyExc_KeyError, \"Key not found\");\n+ return PWOMappingMmbr(rslt, *this, _key);\n+ };\n+ \n //PyMapping_HasKey\n bool hasKey(PyObject* key) const {\n return PyMapping_HasKey(_obj, key)==1;\n", "added_lines": 43, "deleted_lines": 0, "source_code": "/******************************************** \n copyright 1999 McMillan Enterprises, Inc.\n www.mcmillan-inc.com\n*********************************************/\n#if !defined(PWOMAPPING_H_INCLUDED_)\n#define PWOMAPPING_H_INCLUDED_\n\n#include \"PWOBase.h\"\n#include \"PWOMSequence.h\"\n#include \"PWONumber.h\"\n#include \n\nclass PWOMapping;\n\nclass PWOMappingMmbr : public PWOBase\n{\n PWOMapping& _parent;\n PyObject* _key;\npublic:\n PWOMappingMmbr(PyObject* obj, PWOMapping& parent, PyObject* key)\n : PWOBase(obj), _parent(parent), _key(key)\n {\n Py_XINCREF(_key);\n };\n virtual ~PWOMappingMmbr() {\n Py_XDECREF(_key);\n };\n PWOMappingMmbr& operator=(const PWOBase& other);\n PWOMappingMmbr& operator=(int other);\n PWOMappingMmbr& operator=(float other);\n PWOMappingMmbr& operator=(double other);\n PWOMappingMmbr& operator=(const char* other);\n PWOMappingMmbr& operator=(std::string other);\n};\n\nclass PWOMapping : public PWOBase\n{\npublic:\n PWOMapping() : PWOBase (PyDict_New()) { LoseRef(_obj); }\n PWOMapping(const PWOMapping& other) : PWOBase(other) {};\n PWOMapping(PyObject* obj) : PWOBase(obj) {\n _violentTypeCheck();\n };\n virtual ~PWOMapping() {};\n\n virtual PWOMapping& operator=(const PWOMapping& other) {\n GrabRef(other);\n return *this;\n };\n PWOMapping& operator=(const PWOBase& other) {\n GrabRef(other);\n _violentTypeCheck();\n return *this;\n };\n virtual void _violentTypeCheck() {\n if (!PyMapping_Check(_obj)) {\n GrabRef(0);\n Fail(PyExc_TypeError, \"Not a mapping\");\n }\n };\n\n //PyMapping_GetItemString\n //PyDict_GetItemString\n PWOMappingMmbr operator [] (const char* key) {\n PyObject* rslt = PyMapping_GetItemString(_obj, (char*) key);\n if (rslt==0)\n PyErr_Clear();\n PWOString _key(key);\n return PWOMappingMmbr(rslt, *this, _key);\n };\n\n PWOMappingMmbr operator [] (std::string key) {\n PyObject* rslt = PyMapping_GetItemString(_obj, (char*) key.c_str());\n if (rslt==0)\n PyErr_Clear();\n PWOString _key(key.c_str());\n return PWOMappingMmbr(rslt, *this, _key);\n };\n \n //PyDict_GetItem\n PWOMappingMmbr operator [] (PyObject* key) {\n PyObject* rslt = PyDict_GetItem(_obj, key);\n //if (rslt==0)\n // Fail(PyExc_KeyError, \"Key not found\");\n return PWOMappingMmbr(rslt, *this, key);\n };\n\n //PyDict_GetItem\n PWOMappingMmbr operator [] (int key) {\n PWONumber _key = PWONumber(key);\n PyObject* rslt = PyDict_GetItem(_obj, _key);\n //if (rslt==0)\n // Fail(PyExc_KeyError, \"Key not found\");\n return PWOMappingMmbr(rslt, *this, _key);\n };\n \n //PyDict_GetItem\n PWOMappingMmbr operator [] (float key) {\n PWONumber _key = PWONumber(key);\n PyObject* rslt = PyDict_GetItem(_obj, _key);\n //if (rslt==0)\n // Fail(PyExc_KeyError, \"Key not found\");\n return PWOMappingMmbr(rslt, *this, _key);\n };\n\n PWOMappingMmbr operator [] (double key) {\n PWONumber _key = PWONumber(key);\n PyObject* rslt = PyDict_GetItem(_obj, _key);\n //if (rslt==0)\n // Fail(PyExc_KeyError, \"Key not found\");\n return PWOMappingMmbr(rslt, *this, _key);\n };\n \n //PyMapping_HasKey\n bool hasKey(PyObject* key) const {\n return PyMapping_HasKey(_obj, key)==1;\n };\n //PyMapping_HasKeyString\n bool hasKey(const char* key) const {\n return PyMapping_HasKeyString(_obj, (char*) key)==1;\n };\n //PyMapping_Length\n //PyDict_Size\n int len() const {\n return PyMapping_Length(_obj);\n };\n //PyMapping_SetItemString\n //PyDict_SetItemString\n void setItem(const char* key, PyObject* val) {\n int rslt = PyMapping_SetItemString(_obj, (char*) key, val);\n if (rslt==-1)\n Fail(PyExc_RuntimeError, \"Cannot add key / value\");\n };\n //PyDict_SetItem\n void setItem(PyObject* key, PyObject* val) const {\n int rslt = PyDict_SetItem(_obj, key, val);\n if (rslt==-1)\n Fail(PyExc_KeyError, \"Key must be hashable\");\n };\n //PyDict_Clear\n void clear() {\n PyDict_Clear(_obj);\n };\n //PyDict_DelItem\n void delItem(PyObject* key) {\n int rslt = PyMapping_DelItem(_obj, key);\n if (rslt==-1)\n Fail(PyExc_KeyError, \"Key not found\");\n };\n //PyDict_DelItemString\n void delItem(const char* key) {\n int rslt = PyDict_DelItemString(_obj, (char*) key);\n if (rslt==-1)\n Fail(PyExc_KeyError, \"Key not found\");\n };\n //PyDict_Items\n PWOList items() const {\n PyObject* rslt = PyMapping_Items(_obj);\n if (rslt==0)\n Fail(PyExc_RuntimeError, \"Failed to get items\");\n return LoseRef(rslt);\n };\n //PyDict_Keys\n PWOList keys() const {\n PyObject* rslt = PyMapping_Keys(_obj);\n if (rslt==0)\n Fail(PyExc_RuntimeError, \"Failed to get keys\");\n return LoseRef(rslt);\n };\n //PyDict_New - default constructor\n //PyDict_Next\n //PyDict_Values\n PWOList values() const {\n PyObject* rslt = PyMapping_Values(_obj);\n if (rslt==0)\n Fail(PyExc_RuntimeError, \"Failed to get values\");\n return LoseRef(rslt);\n };\n};\n\n#endif // PWOMAPPING_H_INCLUDED_\n", "source_code_before": "/******************************************** \n copyright 1999 McMillan Enterprises, Inc.\n www.mcmillan-inc.com\n*********************************************/\n#if !defined(PWOMAPPING_H_INCLUDED_)\n#define PWOMAPPING_H_INCLUDED_\n\n#include \"PWOBase.h\"\n#include \"PWOMSequence.h\"\n\nclass PWOMapping;\n\nclass PWOMappingMmbr : public PWOBase\n{\n PWOMapping& _parent;\n PyObject* _key;\npublic:\n PWOMappingMmbr(PyObject* obj, PWOMapping& parent, PyObject* key)\n : PWOBase(obj), _parent(parent), _key(key)\n {\n Py_XINCREF(_key);\n };\n virtual ~PWOMappingMmbr() {\n Py_XDECREF(_key);\n };\n PWOMappingMmbr& operator=(const PWOBase& other);\n};\n\nclass PWOMapping : public PWOBase\n{\npublic:\n PWOMapping() : PWOBase (PyDict_New()) { LoseRef(_obj); }\n PWOMapping(const PWOMapping& other) : PWOBase(other) {};\n PWOMapping(PyObject* obj) : PWOBase(obj) {\n _violentTypeCheck();\n };\n virtual ~PWOMapping() {};\n\n virtual PWOMapping& operator=(const PWOMapping& other) {\n GrabRef(other);\n return *this;\n };\n PWOMapping& operator=(const PWOBase& other) {\n GrabRef(other);\n _violentTypeCheck();\n return *this;\n };\n virtual void _violentTypeCheck() {\n if (!PyMapping_Check(_obj)) {\n GrabRef(0);\n Fail(PyExc_TypeError, \"Not a mapping\");\n }\n };\n\n //PyMapping_GetItemString\n //PyDict_GetItemString\n PWOMappingMmbr operator [] (const char* key) {\n PyObject* rslt = PyMapping_GetItemString(_obj, (char*) key);\n if (rslt==0)\n PyErr_Clear();\n PWOString _key(key);\n return PWOMappingMmbr(rslt, *this, _key);\n };\n //PyDict_GetItem\n PWOMappingMmbr operator [] (PyObject* key) {\n PyObject* rslt = PyDict_GetItem(_obj, key);\n //if (rslt==0)\n // Fail(PyExc_KeyError, \"Key not found\");\n return PWOMappingMmbr(rslt, *this, key);\n };\n //PyMapping_HasKey\n bool hasKey(PyObject* key) const {\n return PyMapping_HasKey(_obj, key)==1;\n };\n //PyMapping_HasKeyString\n bool hasKey(const char* key) const {\n return PyMapping_HasKeyString(_obj, (char*) key)==1;\n };\n //PyMapping_Length\n //PyDict_Size\n int len() const {\n return PyMapping_Length(_obj);\n };\n //PyMapping_SetItemString\n //PyDict_SetItemString\n void setItem(const char* key, PyObject* val) {\n int rslt = PyMapping_SetItemString(_obj, (char*) key, val);\n if (rslt==-1)\n Fail(PyExc_RuntimeError, \"Cannot add key / value\");\n };\n //PyDict_SetItem\n void setItem(PyObject* key, PyObject* val) const {\n int rslt = PyDict_SetItem(_obj, key, val);\n if (rslt==-1)\n Fail(PyExc_KeyError, \"Key must be hashable\");\n };\n //PyDict_Clear\n void clear() {\n PyDict_Clear(_obj);\n };\n //PyDict_DelItem\n void delItem(PyObject* key) {\n int rslt = PyMapping_DelItem(_obj, key);\n if (rslt==-1)\n Fail(PyExc_KeyError, \"Key not found\");\n };\n //PyDict_DelItemString\n void delItem(const char* key) {\n int rslt = PyDict_DelItemString(_obj, (char*) key);\n if (rslt==-1)\n Fail(PyExc_KeyError, \"Key not found\");\n };\n //PyDict_Items\n PWOList items() const {\n PyObject* rslt = PyMapping_Items(_obj);\n if (rslt==0)\n Fail(PyExc_RuntimeError, \"Failed to get items\");\n return LoseRef(rslt);\n };\n //PyDict_Keys\n PWOList keys() const {\n PyObject* rslt = PyMapping_Keys(_obj);\n if (rslt==0)\n Fail(PyExc_RuntimeError, \"Failed to get keys\");\n return LoseRef(rslt);\n };\n //PyDict_New - default constructor\n //PyDict_Next\n //PyDict_Values\n PWOList values() const {\n PyObject* rslt = PyMapping_Values(_obj);\n if (rslt==0)\n Fail(PyExc_RuntimeError, \"Failed to get values\");\n return LoseRef(rslt);\n };\n};\n\n#endif // PWOMAPPING_H_INCLUDED_\n", "methods": [ { "name": "PWOMappingMmbr::PWOMappingMmbr", "long_name": "PWOMappingMmbr::PWOMappingMmbr( PyObject * obj , PWOMapping & parent , PyObject * key)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "obj", "parent", "key" ], "start_line": 20, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOMappingMmbr::~PWOMappingMmbr", "long_name": "PWOMappingMmbr::~PWOMappingMmbr()", "filename": "PWOMapping.h", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 25, "end_line": 27, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOMapping::PWOMapping", "long_name": "PWOMapping::PWOMapping()", "filename": "PWOMapping.h", "nloc": 1, "complexity": 1, "token_count": 17, "parameters": [], "start_line": 39, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOMapping::PWOMapping", "long_name": "PWOMapping::PWOMapping( const PWOMapping & other)", "filename": "PWOMapping.h", "nloc": 1, "complexity": 1, "token_count": 14, "parameters": [ "other" ], "start_line": 40, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOMapping::PWOMapping", "long_name": "PWOMapping::PWOMapping( PyObject * obj)", "filename": "PWOMapping.h", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "obj" ], "start_line": 41, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOMapping::~PWOMapping", "long_name": "PWOMapping::~PWOMapping()", "filename": "PWOMapping.h", "nloc": 1, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 44, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOMapping::operator =", "long_name": "PWOMapping::operator =( const PWOMapping & other)", "filename": "PWOMapping.h", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "other" ], "start_line": 46, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "PWOMapping::operator =", "long_name": "PWOMapping::operator =( const PWOBase & other)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [ "other" ], "start_line": 50, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOMapping::_violentTypeCheck", "long_name": "PWOMapping::_violentTypeCheck()", "filename": "PWOMapping.h", "nloc": 6, "complexity": 2, "token_count": 27, "parameters": [], "start_line": 55, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOMapping::operator [ ]", "long_name": "PWOMapping::operator [ ]( const char * key)", "filename": "PWOMapping.h", "nloc": 7, "complexity": 2, "token_count": 53, "parameters": [ "key" ], "start_line": 64, "end_line": 70, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "PWOMapping::operator [ ]", "long_name": "PWOMapping::operator [ ]( std :: string key)", "filename": "PWOMapping.h", "nloc": 7, "complexity": 2, "token_count": 61, "parameters": [ "std" ], "start_line": 72, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "PWOMapping::operator [ ]", "long_name": "PWOMapping::operator [ ]( PyObject * key)", "filename": "PWOMapping.h", "nloc": 4, "complexity": 1, "token_count": 32, "parameters": [ "key" ], "start_line": 81, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOMapping::operator [ ]", "long_name": "PWOMapping::operator [ ]( int key)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "key" ], "start_line": 89, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "PWOMapping::operator [ ]", "long_name": "PWOMapping::operator [ ]( float key)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "key" ], "start_line": 98, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "PWOMapping::operator [ ]", "long_name": "PWOMapping::operator [ ]( double key)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "key" ], "start_line": 106, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "PWOMapping::hasKey", "long_name": "PWOMapping::hasKey( PyObject * key) const", "filename": "PWOMapping.h", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "key" ], "start_line": 115, "end_line": 117, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOMapping::hasKey", "long_name": "PWOMapping::hasKey( const char * key) const", "filename": "PWOMapping.h", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "key" ], "start_line": 119, "end_line": 121, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOMapping::len", "long_name": "PWOMapping::len() const", "filename": "PWOMapping.h", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 124, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOMapping::setItem", "long_name": "PWOMapping::setItem( const char * key , PyObject * val)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "key", "val" ], "start_line": 129, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOMapping::setItem", "long_name": "PWOMapping::setItem( PyObject * key , PyObject * val) const", "filename": "PWOMapping.h", "nloc": 5, "complexity": 2, "token_count": 39, "parameters": [ "key", "val" ], "start_line": 135, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOMapping::clear", "long_name": "PWOMapping::clear()", "filename": "PWOMapping.h", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 141, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOMapping::delItem", "long_name": "PWOMapping::delItem( PyObject * key)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 2, "token_count": 32, "parameters": [ "key" ], "start_line": 145, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOMapping::delItem", "long_name": "PWOMapping::delItem( const char * key)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "key" ], "start_line": 151, "end_line": 155, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOMapping::items", "long_name": "PWOMapping::items() const", "filename": "PWOMapping.h", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [], "start_line": 157, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOMapping::keys", "long_name": "PWOMapping::keys() const", "filename": "PWOMapping.h", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [], "start_line": 164, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOMapping::values", "long_name": "PWOMapping::values() const", "filename": "PWOMapping.h", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [], "start_line": 173, "end_line": 178, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "methods_before": [ { "name": "PWOMappingMmbr::PWOMappingMmbr", "long_name": "PWOMappingMmbr::PWOMappingMmbr( PyObject * obj , PWOMapping & parent , PyObject * key)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "obj", "parent", "key" ], "start_line": 18, "end_line": 22, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOMappingMmbr::~PWOMappingMmbr", "long_name": "PWOMappingMmbr::~PWOMappingMmbr()", "filename": "PWOMapping.h", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 23, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOMapping::PWOMapping", "long_name": "PWOMapping::PWOMapping()", "filename": "PWOMapping.h", "nloc": 1, "complexity": 1, "token_count": 17, "parameters": [], "start_line": 32, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOMapping::PWOMapping", "long_name": "PWOMapping::PWOMapping( const PWOMapping & other)", "filename": "PWOMapping.h", "nloc": 1, "complexity": 1, "token_count": 14, "parameters": [ "other" ], "start_line": 33, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOMapping::PWOMapping", "long_name": "PWOMapping::PWOMapping( PyObject * obj)", "filename": "PWOMapping.h", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "obj" ], "start_line": 34, "end_line": 36, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOMapping::~PWOMapping", "long_name": "PWOMapping::~PWOMapping()", "filename": "PWOMapping.h", "nloc": 1, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 37, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOMapping::operator =", "long_name": "PWOMapping::operator =( const PWOMapping & other)", "filename": "PWOMapping.h", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "other" ], "start_line": 39, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "PWOMapping::operator =", "long_name": "PWOMapping::operator =( const PWOBase & other)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [ "other" ], "start_line": 43, "end_line": 47, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOMapping::_violentTypeCheck", "long_name": "PWOMapping::_violentTypeCheck()", "filename": "PWOMapping.h", "nloc": 6, "complexity": 2, "token_count": 27, "parameters": [], "start_line": 48, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOMapping::operator [ ]", "long_name": "PWOMapping::operator [ ]( const char * key)", "filename": "PWOMapping.h", "nloc": 7, "complexity": 2, "token_count": 53, "parameters": [ "key" ], "start_line": 57, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "PWOMapping::operator [ ]", "long_name": "PWOMapping::operator [ ]( PyObject * key)", "filename": "PWOMapping.h", "nloc": 4, "complexity": 1, "token_count": 32, "parameters": [ "key" ], "start_line": 65, "end_line": 70, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOMapping::hasKey", "long_name": "PWOMapping::hasKey( PyObject * key) const", "filename": "PWOMapping.h", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "key" ], "start_line": 72, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOMapping::hasKey", "long_name": "PWOMapping::hasKey( const char * key) const", "filename": "PWOMapping.h", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "key" ], "start_line": 76, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOMapping::len", "long_name": "PWOMapping::len() const", "filename": "PWOMapping.h", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 81, "end_line": 83, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOMapping::setItem", "long_name": "PWOMapping::setItem( const char * key , PyObject * val)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "key", "val" ], "start_line": 86, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOMapping::setItem", "long_name": "PWOMapping::setItem( PyObject * key , PyObject * val) const", "filename": "PWOMapping.h", "nloc": 5, "complexity": 2, "token_count": 39, "parameters": [ "key", "val" ], "start_line": 92, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOMapping::clear", "long_name": "PWOMapping::clear()", "filename": "PWOMapping.h", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [], "start_line": 98, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOMapping::delItem", "long_name": "PWOMapping::delItem( PyObject * key)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 2, "token_count": 32, "parameters": [ "key" ], "start_line": 102, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOMapping::delItem", "long_name": "PWOMapping::delItem( const char * key)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 2, "token_count": 37, "parameters": [ "key" ], "start_line": 108, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOMapping::items", "long_name": "PWOMapping::items() const", "filename": "PWOMapping.h", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [], "start_line": 114, "end_line": 119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOMapping::keys", "long_name": "PWOMapping::keys() const", "filename": "PWOMapping.h", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [], "start_line": 121, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOMapping::values", "long_name": "PWOMapping::values() const", "filename": "PWOMapping.h", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [], "start_line": 130, "end_line": 135, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "PWOMapping::operator [ ]", "long_name": "PWOMapping::operator [ ]( double key)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "key" ], "start_line": 106, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "PWOMapping::operator [ ]", "long_name": "PWOMapping::operator [ ]( std :: string key)", "filename": "PWOMapping.h", "nloc": 7, "complexity": 2, "token_count": 61, "parameters": [ "std" ], "start_line": 72, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "PWOMapping::operator [ ]", "long_name": "PWOMapping::operator [ ]( float key)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "key" ], "start_line": 98, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "PWOMapping::operator [ ]", "long_name": "PWOMapping::operator [ ]( int key)", "filename": "PWOMapping.h", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "key" ], "start_line": 89, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 } ], "nloc": 133, "complexity": 36, "token_count": 899, "diff_parsed": { "added": [ "#include \"PWONumber.h\"", "#include ", " PWOMappingMmbr& operator=(int other);", " PWOMappingMmbr& operator=(float other);", " PWOMappingMmbr& operator=(double other);", " PWOMappingMmbr& operator=(const char* other);", " PWOMappingMmbr& operator=(std::string other);", "", " PWOMappingMmbr operator [] (std::string key) {", " PyObject* rslt = PyMapping_GetItemString(_obj, (char*) key.c_str());", " if (rslt==0)", " PyErr_Clear();", " PWOString _key(key.c_str());", " return PWOMappingMmbr(rslt, *this, _key);", " };", "", "", " //PyDict_GetItem", " PWOMappingMmbr operator [] (int key) {", " PWONumber _key = PWONumber(key);", " PyObject* rslt = PyDict_GetItem(_obj, _key);", " //if (rslt==0)", " // Fail(PyExc_KeyError, \"Key not found\");", " return PWOMappingMmbr(rslt, *this, _key);", " };", "", " //PyDict_GetItem", " PWOMappingMmbr operator [] (float key) {", " PWONumber _key = PWONumber(key);", " PyObject* rslt = PyDict_GetItem(_obj, _key);", " //if (rslt==0)", " // Fail(PyExc_KeyError, \"Key not found\");", " return PWOMappingMmbr(rslt, *this, _key);", " };", "", " PWOMappingMmbr operator [] (double key) {", " PWONumber _key = PWONumber(key);", " PyObject* rslt = PyDict_GetItem(_obj, _key);", " //if (rslt==0)", " // Fail(PyExc_KeyError, \"Key not found\");", " return PWOMappingMmbr(rslt, *this, _key);", " };", "" ], "deleted": [] } }, { "old_path": "weave/scxx/PWOSequence.h", "new_path": "weave/scxx/PWOSequence.h", "filename": "PWOSequence.h", "extension": "h", "change_type": "MODIFY", "diff": "@@ -82,6 +82,10 @@ public:\n int len() const {\n return PySequence_Length(_obj);\n };\n+ // added length for compatibility with std::string.\n+ int length() const {\n+ return PySequence_Length(_obj);\n+ };\n //PySequence_Repeat\n PWOSequence operator * (int count) const {\n PyObject* rslt = PySequence_Repeat(_obj, count);\n", "added_lines": 4, "deleted_lines": 0, "source_code": "/******************************************** \n copyright 1999 McMillan Enterprises, Inc.\n www.mcmillan-inc.com\n*********************************************/\n#if !defined(PWOSEQUENCE_H_INCLUDED_)\n#define PWOSEQUENCE_H_INCLUDED_\n\n#include \"PWOBase.h\"\n\n// This isn't being picked up out of PWOBase.h for some reason\nvoid Fail(PyObject*, const char* msg);\n\nclass PWOSequence : public PWOBase\n{\npublic:\n PWOSequence() : PWOBase() {};\n PWOSequence(const PWOSequence& other) : PWOBase(other) {};\n PWOSequence(PyObject* obj) : PWOBase(obj) {\n _violentTypeCheck();\n };\n virtual ~PWOSequence() {}\n\n virtual PWOSequence& operator=(const PWOSequence& other) {\n GrabRef(other);\n return *this;\n };\n /*virtual*/ PWOSequence& operator=(const PWOBase& other) {\n GrabRef(other);\n _violentTypeCheck();\n return *this;\n };\n virtual void _violentTypeCheck() {\n if (!PySequence_Check(_obj)) {\n GrabRef(0);\n Fail(PyExc_TypeError, \"Not a sequence\");\n }\n };\n //PySequence_Concat\n PWOSequence operator+(const PWOSequence& rhs) const {\n PyObject* rslt = PySequence_Concat(_obj, rhs);\n if (rslt==0)\n Fail(PyExc_TypeError, \"Improper rhs for +\");\n return LoseRef(rslt);\n };\n //PySequence_Count\n int count(const PWOBase& value) const {\n int rslt = PySequence_Count(_obj, value);\n if (rslt == -1)\n Fail(PyExc_RuntimeError, \"failure in count\");\n return rslt;\n };\n //PySequence_GetItem ##lists - return PWOListMmbr (mutable) otherwise just a PWOBase\n PWOBase operator [] (int i) const { //can't be virtual\n PyObject* o = PySequence_GetItem(_obj, i);\n if (o == 0)\n Fail(PyExc_IndexError, \"index out of range\");\n return LoseRef(o);\n };\n //PySequence_GetSlice\n //virtual PWOSequence& operator [] (PWSlice& x) {...};\n PWOSequence getSlice(int lo, int hi) const {\n PyObject* o = PySequence_GetSlice(_obj, lo, hi);\n if (o == 0)\n Fail(PyExc_IndexError, \"could not obtain slice\");\n return LoseRef(o);\n };\n //PySequence_In\n bool in(const PWOBase& value) const {\n int rslt = PySequence_In(_obj, value);\n if (rslt==-1)\n Fail(PyExc_RuntimeError, \"problem in in\");\n return (rslt==1);\n };\n //PySequence_Index\n int index(const PWOBase& value) const {\n int rslt = PySequence_Index(_obj, value);\n if (rslt==-1)\n Fail(PyExc_IndexError, \"value not found\");\n return rslt;\n };\n //PySequence_Length\n int len() const {\n return PySequence_Length(_obj);\n };\n // added length for compatibility with std::string.\n int length() const {\n return PySequence_Length(_obj);\n };\n //PySequence_Repeat\n PWOSequence operator * (int count) const {\n PyObject* rslt = PySequence_Repeat(_obj, count);\n if (rslt==0)\n Fail(PyExc_RuntimeError, \"sequence repeat failed\");\n return LoseRef(rslt);\n };\n //PySequence_Tuple\n};\n\nclass PWOList;\n\nclass PWOTuple : public PWOSequence\n{\npublic:\n PWOTuple(int sz=0) : PWOSequence (PyTuple_New(sz)) { LoseRef(_obj); }\n PWOTuple(const PWOTuple& other) : PWOSequence(other) { }\n PWOTuple(PyObject* obj) : PWOSequence(obj) { _violentTypeCheck(); }\n PWOTuple(const PWOList& list);\n virtual ~PWOTuple() {};\n\n virtual PWOTuple& operator=(const PWOTuple& other) {\n GrabRef(other);\n return *this;\n };\n /*virtual*/ PWOTuple& operator=(const PWOBase& other) {\n GrabRef(other);\n _violentTypeCheck();\n return *this;\n };\n virtual void _violentTypeCheck() {\n if (!PyTuple_Check(_obj)) {\n GrabRef(0);\n Fail(PyExc_TypeError, \"Not a Python Tuple\");\n }\n };\n void setItem(int ndx, PWOBase& val) {\n int rslt = PyTuple_SetItem(_obj, ndx, val);\n val.disOwn(); //when using PyTuple_SetItem, he steals my reference\n if (rslt==-1)\n Fail(PyExc_IndexError, \"Index out of range\");\n };\n};\n\nclass PWOString : public PWOSequence\n{\npublic:\n PWOString() : PWOSequence() {};\n PWOString(const char* s)\n : PWOSequence(PyString_FromString((char* )s)) { LoseRef(_obj); }\n PWOString(const char* s, int sz)\n : PWOSequence(PyString_FromStringAndSize((char* )s, sz)) { LoseRef(_obj); }\n PWOString(const PWOString& other)\n : PWOSequence(other) {};\n PWOString(PyObject* obj)\n : PWOSequence(obj) { _violentTypeCheck(); };\n PWOString(const PWOBase& other)\n : PWOSequence(other) { _violentTypeCheck(); };\n virtual ~PWOString() {};\n\n virtual PWOString& operator=(const PWOString& other) {\n GrabRef(other);\n return *this;\n };\n PWOString& operator=(const PWOBase& other) {\n GrabRef(other);\n _violentTypeCheck();\n return *this;\n };\n virtual void _violentTypeCheck() {\n if (!PyString_Check(_obj)) {\n GrabRef(0);\n Fail(PyExc_TypeError, \"Not a Python String\");\n }\n };\n operator const char* () const {\n return PyString_AsString(_obj);\n };\n static PWOString format(const PWOString& fmt, PWOTuple& args){\n PyObject * rslt =PyString_Format(fmt, args);\n if (rslt==0)\n Fail(PyExc_RuntimeError, \"string format failed\");\n return LoseRef(rslt);\n };\n};\n#endif // PWOSEQUENCE_H_INCLUDED_\n", "source_code_before": "/******************************************** \n copyright 1999 McMillan Enterprises, Inc.\n www.mcmillan-inc.com\n*********************************************/\n#if !defined(PWOSEQUENCE_H_INCLUDED_)\n#define PWOSEQUENCE_H_INCLUDED_\n\n#include \"PWOBase.h\"\n\n// This isn't being picked up out of PWOBase.h for some reason\nvoid Fail(PyObject*, const char* msg);\n\nclass PWOSequence : public PWOBase\n{\npublic:\n PWOSequence() : PWOBase() {};\n PWOSequence(const PWOSequence& other) : PWOBase(other) {};\n PWOSequence(PyObject* obj) : PWOBase(obj) {\n _violentTypeCheck();\n };\n virtual ~PWOSequence() {}\n\n virtual PWOSequence& operator=(const PWOSequence& other) {\n GrabRef(other);\n return *this;\n };\n /*virtual*/ PWOSequence& operator=(const PWOBase& other) {\n GrabRef(other);\n _violentTypeCheck();\n return *this;\n };\n virtual void _violentTypeCheck() {\n if (!PySequence_Check(_obj)) {\n GrabRef(0);\n Fail(PyExc_TypeError, \"Not a sequence\");\n }\n };\n //PySequence_Concat\n PWOSequence operator+(const PWOSequence& rhs) const {\n PyObject* rslt = PySequence_Concat(_obj, rhs);\n if (rslt==0)\n Fail(PyExc_TypeError, \"Improper rhs for +\");\n return LoseRef(rslt);\n };\n //PySequence_Count\n int count(const PWOBase& value) const {\n int rslt = PySequence_Count(_obj, value);\n if (rslt == -1)\n Fail(PyExc_RuntimeError, \"failure in count\");\n return rslt;\n };\n //PySequence_GetItem ##lists - return PWOListMmbr (mutable) otherwise just a PWOBase\n PWOBase operator [] (int i) const { //can't be virtual\n PyObject* o = PySequence_GetItem(_obj, i);\n if (o == 0)\n Fail(PyExc_IndexError, \"index out of range\");\n return LoseRef(o);\n };\n //PySequence_GetSlice\n //virtual PWOSequence& operator [] (PWSlice& x) {...};\n PWOSequence getSlice(int lo, int hi) const {\n PyObject* o = PySequence_GetSlice(_obj, lo, hi);\n if (o == 0)\n Fail(PyExc_IndexError, \"could not obtain slice\");\n return LoseRef(o);\n };\n //PySequence_In\n bool in(const PWOBase& value) const {\n int rslt = PySequence_In(_obj, value);\n if (rslt==-1)\n Fail(PyExc_RuntimeError, \"problem in in\");\n return (rslt==1);\n };\n //PySequence_Index\n int index(const PWOBase& value) const {\n int rslt = PySequence_Index(_obj, value);\n if (rslt==-1)\n Fail(PyExc_IndexError, \"value not found\");\n return rslt;\n };\n //PySequence_Length\n int len() const {\n return PySequence_Length(_obj);\n };\n //PySequence_Repeat\n PWOSequence operator * (int count) const {\n PyObject* rslt = PySequence_Repeat(_obj, count);\n if (rslt==0)\n Fail(PyExc_RuntimeError, \"sequence repeat failed\");\n return LoseRef(rslt);\n };\n //PySequence_Tuple\n};\n\nclass PWOList;\n\nclass PWOTuple : public PWOSequence\n{\npublic:\n PWOTuple(int sz=0) : PWOSequence (PyTuple_New(sz)) { LoseRef(_obj); }\n PWOTuple(const PWOTuple& other) : PWOSequence(other) { }\n PWOTuple(PyObject* obj) : PWOSequence(obj) { _violentTypeCheck(); }\n PWOTuple(const PWOList& list);\n virtual ~PWOTuple() {};\n\n virtual PWOTuple& operator=(const PWOTuple& other) {\n GrabRef(other);\n return *this;\n };\n /*virtual*/ PWOTuple& operator=(const PWOBase& other) {\n GrabRef(other);\n _violentTypeCheck();\n return *this;\n };\n virtual void _violentTypeCheck() {\n if (!PyTuple_Check(_obj)) {\n GrabRef(0);\n Fail(PyExc_TypeError, \"Not a Python Tuple\");\n }\n };\n void setItem(int ndx, PWOBase& val) {\n int rslt = PyTuple_SetItem(_obj, ndx, val);\n val.disOwn(); //when using PyTuple_SetItem, he steals my reference\n if (rslt==-1)\n Fail(PyExc_IndexError, \"Index out of range\");\n };\n};\n\nclass PWOString : public PWOSequence\n{\npublic:\n PWOString() : PWOSequence() {};\n PWOString(const char* s)\n : PWOSequence(PyString_FromString((char* )s)) { LoseRef(_obj); }\n PWOString(const char* s, int sz)\n : PWOSequence(PyString_FromStringAndSize((char* )s, sz)) { LoseRef(_obj); }\n PWOString(const PWOString& other)\n : PWOSequence(other) {};\n PWOString(PyObject* obj)\n : PWOSequence(obj) { _violentTypeCheck(); };\n PWOString(const PWOBase& other)\n : PWOSequence(other) { _violentTypeCheck(); };\n virtual ~PWOString() {};\n\n virtual PWOString& operator=(const PWOString& other) {\n GrabRef(other);\n return *this;\n };\n PWOString& operator=(const PWOBase& other) {\n GrabRef(other);\n _violentTypeCheck();\n return *this;\n };\n virtual void _violentTypeCheck() {\n if (!PyString_Check(_obj)) {\n GrabRef(0);\n Fail(PyExc_TypeError, \"Not a Python String\");\n }\n };\n operator const char* () const {\n return PyString_AsString(_obj);\n };\n static PWOString format(const PWOString& fmt, PWOTuple& args){\n PyObject * rslt =PyString_Format(fmt, args);\n if (rslt==0)\n Fail(PyExc_RuntimeError, \"string format failed\");\n return LoseRef(rslt);\n };\n};\n#endif // PWOSEQUENCE_H_INCLUDED_\n", "methods": [ { "name": "PWOSequence::PWOSequence", "long_name": "PWOSequence::PWOSequence()", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 16, "end_line": 16, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOSequence::PWOSequence", "long_name": "PWOSequence::PWOSequence( const PWOSequence & other)", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 14, "parameters": [ "other" ], "start_line": 17, "end_line": 17, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOSequence::PWOSequence", "long_name": "PWOSequence::PWOSequence( PyObject * obj)", "filename": "PWOSequence.h", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "obj" ], "start_line": 18, "end_line": 20, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOSequence::~PWOSequence", "long_name": "PWOSequence::~PWOSequence()", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 21, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOSequence::operator =", "long_name": "PWOSequence::operator =( const PWOSequence & other)", "filename": "PWOSequence.h", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "other" ], "start_line": 23, "end_line": 26, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "PWOSequence::operator =", "long_name": "PWOSequence::operator =( const PWOBase & other)", "filename": "PWOSequence.h", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [ "other" ], "start_line": 27, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOSequence::_violentTypeCheck", "long_name": "PWOSequence::_violentTypeCheck()", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 27, "parameters": [], "start_line": 32, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOSequence::operator +", "long_name": "PWOSequence::operator +( const PWOSequence & rhs) const", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 41, "parameters": [ "rhs" ], "start_line": 39, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOSequence::count", "long_name": "PWOSequence::count( const PWOBase & value) const", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "value" ], "start_line": 46, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOSequence::operator [ ]", "long_name": "PWOSequence::operator [ ]( int i) const", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 40, "parameters": [ "i" ], "start_line": 53, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOSequence::getSlice", "long_name": "PWOSequence::getSlice( int lo , int hi) const", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "lo", "hi" ], "start_line": 61, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOSequence::in", "long_name": "PWOSequence::in( const PWOBase & value) const", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 41, "parameters": [ "value" ], "start_line": 68, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOSequence::index", "long_name": "PWOSequence::index( const PWOBase & value) const", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "value" ], "start_line": 75, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOSequence::len", "long_name": "PWOSequence::len() const", "filename": "PWOSequence.h", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 82, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOSequence::length", "long_name": "PWOSequence::length() const", "filename": "PWOSequence.h", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 86, "end_line": 88, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOSequence::operator *", "long_name": "PWOSequence::operator *( int count) const", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "count" ], "start_line": 90, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOTuple::PWOTuple", "long_name": "PWOTuple::PWOTuple( int sz = 0)", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 22, "parameters": [ "sz" ], "start_line": 104, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOTuple::PWOTuple", "long_name": "PWOTuple::PWOTuple( const PWOTuple & other)", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 14, "parameters": [ "other" ], "start_line": 105, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOTuple::PWOTuple", "long_name": "PWOTuple::PWOTuple( PyObject * obj)", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 17, "parameters": [ "obj" ], "start_line": 106, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOTuple::~PWOTuple", "long_name": "PWOTuple::~PWOTuple()", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 108, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOTuple::operator =", "long_name": "PWOTuple::operator =( const PWOTuple & other)", "filename": "PWOSequence.h", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "other" ], "start_line": 110, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "PWOTuple::operator =", "long_name": "PWOTuple::operator =( const PWOBase & other)", "filename": "PWOSequence.h", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [ "other" ], "start_line": 114, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOTuple::_violentTypeCheck", "long_name": "PWOTuple::_violentTypeCheck()", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 27, "parameters": [], "start_line": 119, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOTuple::setItem", "long_name": "PWOTuple::setItem( int ndx , PWOBase & val)", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "ndx", "val" ], "start_line": 125, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOString::PWOString", "long_name": "PWOString::PWOString()", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 136, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOString::PWOString", "long_name": "PWOString::PWOString( const char * s)", "filename": "PWOSequence.h", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "s" ], "start_line": 137, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "PWOString::PWOString", "long_name": "PWOString::PWOString( const char * s , int sz)", "filename": "PWOSequence.h", "nloc": 2, "complexity": 1, "token_count": 31, "parameters": [ "s", "sz" ], "start_line": 139, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "PWOString::PWOString", "long_name": "PWOString::PWOString( const PWOString & other)", "filename": "PWOSequence.h", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "other" ], "start_line": 141, "end_line": 142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "PWOString::PWOString", "long_name": "PWOString::PWOString( PyObject * obj)", "filename": "PWOSequence.h", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "obj" ], "start_line": 143, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "PWOString::PWOString", "long_name": "PWOString::PWOString( const PWOBase & other)", "filename": "PWOSequence.h", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "other" ], "start_line": 145, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "PWOString::~PWOString", "long_name": "PWOString::~PWOString()", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 147, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOString::operator =", "long_name": "PWOString::operator =( const PWOString & other)", "filename": "PWOSequence.h", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "other" ], "start_line": 149, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "PWOString::operator =", "long_name": "PWOString::operator =( const PWOBase & other)", "filename": "PWOSequence.h", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [ "other" ], "start_line": 153, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOString::_violentTypeCheck", "long_name": "PWOString::_violentTypeCheck()", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 27, "parameters": [], "start_line": 158, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOString::operator const char *", "long_name": "PWOString::operator const char *() const", "filename": "PWOSequence.h", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 164, "end_line": 166, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOString::format", "long_name": "PWOString::format( const PWOString & fmt , PWOTuple & args)", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "fmt", "args" ], "start_line": 167, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "methods_before": [ { "name": "PWOSequence::PWOSequence", "long_name": "PWOSequence::PWOSequence()", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 16, "end_line": 16, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOSequence::PWOSequence", "long_name": "PWOSequence::PWOSequence( const PWOSequence & other)", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 14, "parameters": [ "other" ], "start_line": 17, "end_line": 17, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOSequence::PWOSequence", "long_name": "PWOSequence::PWOSequence( PyObject * obj)", "filename": "PWOSequence.h", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "obj" ], "start_line": 18, "end_line": 20, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOSequence::~PWOSequence", "long_name": "PWOSequence::~PWOSequence()", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 21, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOSequence::operator =", "long_name": "PWOSequence::operator =( const PWOSequence & other)", "filename": "PWOSequence.h", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "other" ], "start_line": 23, "end_line": 26, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "PWOSequence::operator =", "long_name": "PWOSequence::operator =( const PWOBase & other)", "filename": "PWOSequence.h", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [ "other" ], "start_line": 27, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOSequence::_violentTypeCheck", "long_name": "PWOSequence::_violentTypeCheck()", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 27, "parameters": [], "start_line": 32, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOSequence::operator +", "long_name": "PWOSequence::operator +( const PWOSequence & rhs) const", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 41, "parameters": [ "rhs" ], "start_line": 39, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOSequence::count", "long_name": "PWOSequence::count( const PWOBase & value) const", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "value" ], "start_line": 46, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOSequence::operator [ ]", "long_name": "PWOSequence::operator [ ]( int i) const", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 40, "parameters": [ "i" ], "start_line": 53, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOSequence::getSlice", "long_name": "PWOSequence::getSlice( int lo , int hi) const", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "lo", "hi" ], "start_line": 61, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOSequence::in", "long_name": "PWOSequence::in( const PWOBase & value) const", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 41, "parameters": [ "value" ], "start_line": 68, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOSequence::index", "long_name": "PWOSequence::index( const PWOBase & value) const", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "value" ], "start_line": 75, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOSequence::len", "long_name": "PWOSequence::len() const", "filename": "PWOSequence.h", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 82, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOSequence::operator *", "long_name": "PWOSequence::operator *( int count) const", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "count" ], "start_line": 86, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOTuple::PWOTuple", "long_name": "PWOTuple::PWOTuple( int sz = 0)", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 22, "parameters": [ "sz" ], "start_line": 100, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOTuple::PWOTuple", "long_name": "PWOTuple::PWOTuple( const PWOTuple & other)", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 14, "parameters": [ "other" ], "start_line": 101, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOTuple::PWOTuple", "long_name": "PWOTuple::PWOTuple( PyObject * obj)", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 17, "parameters": [ "obj" ], "start_line": 102, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOTuple::~PWOTuple", "long_name": "PWOTuple::~PWOTuple()", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 104, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOTuple::operator =", "long_name": "PWOTuple::operator =( const PWOTuple & other)", "filename": "PWOSequence.h", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "other" ], "start_line": 106, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "PWOTuple::operator =", "long_name": "PWOTuple::operator =( const PWOBase & other)", "filename": "PWOSequence.h", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [ "other" ], "start_line": 110, "end_line": 114, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOTuple::_violentTypeCheck", "long_name": "PWOTuple::_violentTypeCheck()", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 27, "parameters": [], "start_line": 115, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOTuple::setItem", "long_name": "PWOTuple::setItem( int ndx , PWOBase & val)", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "ndx", "val" ], "start_line": 121, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOString::PWOString", "long_name": "PWOString::PWOString()", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 132, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOString::PWOString", "long_name": "PWOString::PWOString( const char * s)", "filename": "PWOSequence.h", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "s" ], "start_line": 133, "end_line": 134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "PWOString::PWOString", "long_name": "PWOString::PWOString( const char * s , int sz)", "filename": "PWOSequence.h", "nloc": 2, "complexity": 1, "token_count": 31, "parameters": [ "s", "sz" ], "start_line": 135, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "PWOString::PWOString", "long_name": "PWOString::PWOString( const PWOString & other)", "filename": "PWOSequence.h", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "other" ], "start_line": 137, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "PWOString::PWOString", "long_name": "PWOString::PWOString( PyObject * obj)", "filename": "PWOSequence.h", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "obj" ], "start_line": 139, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "PWOString::PWOString", "long_name": "PWOString::PWOString( const PWOBase & other)", "filename": "PWOSequence.h", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "other" ], "start_line": 141, "end_line": 142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "PWOString::~PWOString", "long_name": "PWOString::~PWOString()", "filename": "PWOSequence.h", "nloc": 1, "complexity": 1, "token_count": 5, "parameters": [], "start_line": 143, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 1, "top_nesting_level": 1 }, { "name": "PWOString::operator =", "long_name": "PWOString::operator =( const PWOString & other)", "filename": "PWOSequence.h", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "other" ], "start_line": 145, "end_line": 148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "PWOString::operator =", "long_name": "PWOString::operator =( const PWOBase & other)", "filename": "PWOSequence.h", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [ "other" ], "start_line": 149, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "PWOString::_violentTypeCheck", "long_name": "PWOString::_violentTypeCheck()", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 27, "parameters": [], "start_line": 154, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "PWOString::operator const char *", "long_name": "PWOString::operator const char *() const", "filename": "PWOSequence.h", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 160, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PWOString::format", "long_name": "PWOString::format( const PWOString & fmt , PWOTuple & args)", "filename": "PWOSequence.h", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "fmt", "args" ], "start_line": 163, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "PWOSequence::length", "long_name": "PWOSequence::length() const", "filename": "PWOSequence.h", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [], "start_line": 86, "end_line": 88, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 } ], "nloc": 146, "complexity": 48, "token_count": 954, "diff_parsed": { "added": [ " // added length for compatibility with std::string.", " int length() const {", " return PySequence_Length(_obj);", " };" ], "deleted": [] } } ] }, { "hash": "74944fabc1dcaf0a42418029366eae8af23316bc", "msg": "fix typo in warning messages", "author": { "name": "skip", "email": "skip@localhost" }, "committer": { "name": "skip", "email": "skip@localhost" }, "author_date": "2002-09-16T20:22:52+00:00", "author_timezone": 0, "committer_date": "2002-09-16T20:22:52+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "66d1a0865cfde0da460684fe4e88e99a967d8e46" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 2, "insertions": 2, "lines": 4, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "weave/build_tools.py", "new_path": "weave/build_tools.py", "filename": "build_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -312,7 +312,7 @@ def configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n- print \"warning: specified temp_dir '%s' does not exist or is \" \\\n+ print \"warning: specified temp_dir '%s' does not exist \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n@@ -328,7 +328,7 @@ def configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n- print \"warning: specified build_dir '%s' does not exist or is \" \\\n+ print \"warning: specified build_dir '%s' does not exist \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n", "added_lines": 2, "deleted_lines": 2, "source_code": "\"\"\" Tools for compiling C/C++ code to extension modules\n\n The main function, build_extension(), takes the C/C++ file\n along with some other options and builds a Python extension.\n It uses distutils for most of the heavy lifting.\n \n choose_compiler() is also useful (mainly on windows anyway)\n for trying to determine whether MSVC++ or gcc is available.\n MSVC doesn't handle templates as well, so some of the code emitted\n by the python->C conversions need this info to choose what kind\n of code to create.\n \n The other main thing here is an alternative version of the MingW32\n compiler class. The class makes it possible to build libraries with\n gcc even if the original version of python was built using MSVC. It\n does this by converting a pythonxx.lib file to a libpythonxx.a file.\n Note that you need write access to the pythonxx/lib directory to do this.\n\"\"\"\n\nimport sys,os,string,time\nimport tempfile\nimport exceptions\n\n# If linker is 'gcc', this will convert it to 'g++'\n# necessary to make sure stdc++ is linked in cross-platform way.\nimport distutils.sysconfig\n\nold_init_posix = distutils.sysconfig._init_posix\n\ndef _init_posix():\n old_init_posix()\n ld = distutils.sysconfig._config_vars['LDSHARED']\n #distutils.sysconfig._config_vars['LDSHARED'] = ld.replace('gcc','g++')\n # FreeBSD names gcc as cc, so the above find and replace doesn't work. \n # So, assume first entry in ld is the name of the linker -- gcc or cc or \n # whatever. This is a sane assumption, correct?\n # If the linker is gcc, set it to g++\n link_cmds = ld.split() \n if gcc_exists(link_cmds[0]):\n link_cmds[0] = 'g++'\n ld = ' '.join(link_cmds)\n distutils.sysconfig._config_vars['LDSHARED'] = ld \n\ndistutils.sysconfig._init_posix = _init_posix \n# end force g++\n\n\nclass CompileError(exceptions.Exception):\n pass\n \ndef build_extension(module_path,compiler_name = '',build_dir = None,\n temp_dir = None, verbose = 0, **kw):\n \"\"\" Build the file given by module_path into a Python extension module.\n \n build_extensions uses distutils to build Python extension modules.\n kw arguments not used are passed on to the distutils extension\n module. Directory settings can handle absoulte settings, but don't\n currently expand '~' or environment variables.\n \n module_path -- the full path name to the c file to compile. \n Something like: /full/path/name/module_name.c \n The name of the c/c++ file should be the same as the\n name of the module (i.e. the initmodule() routine)\n compiler_name -- The name of the compiler to use. On Windows if it \n isn't given, MSVC is used if it exists (is found).\n gcc is used as a second choice. If neither are found, \n the default distutils compiler is used. Acceptable \n names are 'gcc', 'msvc' or any of the compiler names \n shown by distutils.ccompiler.show_compilers()\n build_dir -- The location where the resulting extension module \n should be placed. This location must be writable. If\n it isn't, several default locations are tried. If the \n build_dir is not in the current python path, a warning\n is emitted, and it is added to the end of the path.\n build_dir defaults to the current directory.\n temp_dir -- The location where temporary files (*.o or *.obj)\n from the build are placed. This location must be \n writable. If it isn't, several default locations are \n tried. It defaults to tempfile.gettempdir()\n verbose -- 0, 1, or 2. 0 is as quiet as possible. 1 prints\n minimal information. 2 is noisy. \n **kw -- keyword arguments. These are passed on to the \n distutils extension module. Most of the keywords\n are listed below.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n \n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list \n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability) \n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line) \n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n success = 0\n from distutils.core import setup, Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n compiler_name = choose_compiler(compiler_name)\n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n try:\n if verbose == 1:\n print 'Compiling code...'\n \n # set compiler verboseness 2 or more makes it output results\n if verbose > 1: verb = 1 \n else: verb = 0\n \n t1 = time.time() \n # add module to the needed source code files and build extension\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n \n # ! This was fixed at beginning of file by using g++ on most \n # !machines. We'll have to check how to handle it on non-gcc machines \n ## add module to the needed source code files and build extension\n ## FIX this is g++ specific. It probably should be fixed for other\n ## Unices/compilers. Find a generic solution\n #if compiler_name != 'msvc':\n # libraries = kw.get('libraries',[])\n # kw['libraries'] = ['stdc++'] + libraries \n # !\n \n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n platform = sys.platform\n version = sys.version.lower()\n if platform[:5] == 'sunos' and version.find('gcc') != -1:\n extra_link_args = kw.get('extra_link_args',[])\n kw['extra_link_args'] = ['-mimpure-text'] + extra_link_args\n \n ext = Extension(module_name, **kw)\n \n # the switcheroo on SystemExit here is meant to keep command line\n # sessions from exiting when compiles fail.\n builtin = sys.modules['__builtin__']\n old_SysExit = builtin.__dict__['SystemExit']\n builtin.__dict__['SystemExit'] = CompileError\n \n # distutils for MSVC messes with the environment, so we save the\n # current state and restore them afterward.\n import copy\n environ = copy.deepcopy(os.environ)\n try:\n setup(name = module_name, ext_modules = [ext],verbose=verb)\n finally:\n # restore state\n os.environ = environ \n # restore SystemExit\n builtin.__dict__['SystemExit'] = old_SysExit\n t2 = time.time()\n \n if verbose == 1:\n print 'finished compiling (sec): ', t2 - t1 \n success = 1\n configure_python_path(build_dir)\n except SyntaxError: #TypeError:\n success = 0 \n \n # restore argv after our trick... \n restore_sys_argv()\n \n return success\n\nold_argv = []\ndef configure_sys_argv(compiler_name,temp_dir,build_dir):\n # We're gonna play some tricks with argv here to pass info to distutils \n # which is really built for command line use. better way??\n global old_argv\n old_argv = sys.argv[:] \n sys.argv = ['','build_ext','--build-lib', build_dir,\n '--build-temp',temp_dir] \n if compiler_name == 'gcc':\n sys.argv.insert(2,'--compiler='+compiler_name)\n elif compiler_name:\n sys.argv.insert(2,'--compiler='+compiler_name)\n\ndef restore_sys_argv():\n sys.argv = old_argv\n \ndef configure_python_path(build_dir): \n #make sure the module lives in a directory on the python path.\n python_paths = [os.path.abspath(x) for x in sys.path]\n if os.path.abspath(build_dir) not in python_paths:\n #print \"warning: build directory was not part of python path.\"\\\n # \" It has been appended to the path.\"\n sys.path.append(os.path.abspath(build_dir))\n\ndef choose_compiler(compiler_name=''):\n \"\"\" Try and figure out which compiler is gonna be used on windows.\n On other platforms, it just returns whatever value it is given.\n \n converts 'gcc' to 'mingw32' on win32\n \"\"\"\n if sys.platform == 'win32': \n if not compiler_name:\n # On Windows, default to MSVC and use gcc if it wasn't found\n # wasn't found. If neither are found, go with whatever\n # the default is for distutils -- and probably fail...\n if msvc_exists():\n compiler_name = 'msvc'\n elif gcc_exists():\n compiler_name = 'mingw32'\n elif compiler_name == 'gcc':\n compiler_name = 'mingw32'\n else:\n # don't know how to force gcc -- look into this.\n if compiler_name == 'gcc':\n compiler_name = 'unix' \n return compiler_name\n \ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n version = distutils.msvccompiler.get_devstudio_version()\n if version:\n result = 1\n return result\n\ndef configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n print \"warning: specified temp_dir '%s' does not exist \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n\n # final check that that directories are writable. \n if not os.access(temp_dir,os.W_OK):\n msg = \"Either the temp or build directory wasn't writable. Check\" \\\n \" these locations: '%s'\" % temp_dir \n raise ValueError, msg\n return temp_dir\n\ndef configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n print \"warning: specified build_dir '%s' does not exist \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n if build_dir is None:\n #default to building in the home directory of the given module. \n build_dir = os.curdir\n # if it doesn't work use the current directory. This should always\n # be writable. \n if not os.access(build_dir,os.W_OK):\n print \"warning:, neither the module's directory nor the \"\\\n \"current directory are writable. Using the temporary\"\\\n \"directory.\"\n build_dir = tempfile.gettempdir()\n\n # final check that that directories are writable.\n if not os.access(build_dir,os.W_OK):\n msg = \"The build directory wasn't writable. Check\" \\\n \" this location: '%s'\" % build_dir\n raise ValueError, msg\n \n return os.path.abspath(build_dir) \n \nif sys.platform == 'win32':\n import distutils.cygwinccompiler\n # the same as cygwin plus some additional parameters\n class Mingw32CCompiler (distutils.cygwinccompiler.CygwinCCompiler):\n \"\"\" A modified MingW32 compiler compatible with an MSVC built Python.\n \n \"\"\"\n \n compiler_type = 'mingw32'\n \n def __init__ (self,\n verbose=0,\n dry_run=0,\n force=0):\n \n distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose, \n dry_run, force)\n \n # A real mingw32 doesn't need to specify a different entry point,\n # but cygwin 2.91.57 in no-cygwin-mode needs it.\n if self.gcc_version <= \"2.91.57\":\n entry_point = '--entry _DllMain@12'\n else:\n entry_point = ''\n if self.linker_dll == 'dllwrap':\n self.linker = 'dllwrap' + ' --driver-name g++'\n elif self.linker_dll == 'gcc':\n self.linker = 'g++' \n # **changes: eric jones 4/11/01\n # 1. Check for import library on Windows. Build if it doesn't exist.\n if not import_library_exists():\n build_import_library()\n \n # **changes: eric jones 4/11/01\n # 2. increased optimization and turned off all warnings\n # 3. also added --driver-name g++\n #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n # compiler_so='gcc -mno-cygwin -mdll -O2 -w',\n # linker_exe='gcc -mno-cygwin',\n # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' \n # % (self.linker, entry_point))\n self.set_executables(compiler='g++ -mno-cygwin -O2 -w',\n compiler_so='g++ -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',\n linker_exe='g++ -mno-cygwin',\n linker_so='%s -mno-cygwin -mdll -static %s' \n % (self.linker, entry_point))\n \n # Maybe we should also append -mthreads, but then the finished\n # dlls need another dll (mingwm10.dll see Mingw32 docs)\n # (-mthreads: Support thread-safe exception handling on `Mingw32') \n \n # no additional libraries needed \n self.dll_libraries=[]\n \n # __init__ ()\n \n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n # We should also check the version of gcc available...\n #distutils.ccompiler._default_compilers['nt'] = 'mingw32'\n #distutils.ccompiler._default_compilers = (('nt', 'mingw32'))\n # reset the Mingw32 compiler in distutils to the one defined above\n distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler\n \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if os.name == 'nt':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n import lib2def as lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print 'WARNING: failed to build import library for gcc. Linking will fail.'\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\n\n\n", "source_code_before": "\"\"\" Tools for compiling C/C++ code to extension modules\n\n The main function, build_extension(), takes the C/C++ file\n along with some other options and builds a Python extension.\n It uses distutils for most of the heavy lifting.\n \n choose_compiler() is also useful (mainly on windows anyway)\n for trying to determine whether MSVC++ or gcc is available.\n MSVC doesn't handle templates as well, so some of the code emitted\n by the python->C conversions need this info to choose what kind\n of code to create.\n \n The other main thing here is an alternative version of the MingW32\n compiler class. The class makes it possible to build libraries with\n gcc even if the original version of python was built using MSVC. It\n does this by converting a pythonxx.lib file to a libpythonxx.a file.\n Note that you need write access to the pythonxx/lib directory to do this.\n\"\"\"\n\nimport sys,os,string,time\nimport tempfile\nimport exceptions\n\n# If linker is 'gcc', this will convert it to 'g++'\n# necessary to make sure stdc++ is linked in cross-platform way.\nimport distutils.sysconfig\n\nold_init_posix = distutils.sysconfig._init_posix\n\ndef _init_posix():\n old_init_posix()\n ld = distutils.sysconfig._config_vars['LDSHARED']\n #distutils.sysconfig._config_vars['LDSHARED'] = ld.replace('gcc','g++')\n # FreeBSD names gcc as cc, so the above find and replace doesn't work. \n # So, assume first entry in ld is the name of the linker -- gcc or cc or \n # whatever. This is a sane assumption, correct?\n # If the linker is gcc, set it to g++\n link_cmds = ld.split() \n if gcc_exists(link_cmds[0]):\n link_cmds[0] = 'g++'\n ld = ' '.join(link_cmds)\n distutils.sysconfig._config_vars['LDSHARED'] = ld \n\ndistutils.sysconfig._init_posix = _init_posix \n# end force g++\n\n\nclass CompileError(exceptions.Exception):\n pass\n \ndef build_extension(module_path,compiler_name = '',build_dir = None,\n temp_dir = None, verbose = 0, **kw):\n \"\"\" Build the file given by module_path into a Python extension module.\n \n build_extensions uses distutils to build Python extension modules.\n kw arguments not used are passed on to the distutils extension\n module. Directory settings can handle absoulte settings, but don't\n currently expand '~' or environment variables.\n \n module_path -- the full path name to the c file to compile. \n Something like: /full/path/name/module_name.c \n The name of the c/c++ file should be the same as the\n name of the module (i.e. the initmodule() routine)\n compiler_name -- The name of the compiler to use. On Windows if it \n isn't given, MSVC is used if it exists (is found).\n gcc is used as a second choice. If neither are found, \n the default distutils compiler is used. Acceptable \n names are 'gcc', 'msvc' or any of the compiler names \n shown by distutils.ccompiler.show_compilers()\n build_dir -- The location where the resulting extension module \n should be placed. This location must be writable. If\n it isn't, several default locations are tried. If the \n build_dir is not in the current python path, a warning\n is emitted, and it is added to the end of the path.\n build_dir defaults to the current directory.\n temp_dir -- The location where temporary files (*.o or *.obj)\n from the build are placed. This location must be \n writable. If it isn't, several default locations are \n tried. It defaults to tempfile.gettempdir()\n verbose -- 0, 1, or 2. 0 is as quiet as possible. 1 prints\n minimal information. 2 is noisy. \n **kw -- keyword arguments. These are passed on to the \n distutils extension module. Most of the keywords\n are listed below.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n \n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list \n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability) \n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line) \n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n success = 0\n from distutils.core import setup, Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n compiler_name = choose_compiler(compiler_name)\n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n try:\n if verbose == 1:\n print 'Compiling code...'\n \n # set compiler verboseness 2 or more makes it output results\n if verbose > 1: verb = 1 \n else: verb = 0\n \n t1 = time.time() \n # add module to the needed source code files and build extension\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n \n # ! This was fixed at beginning of file by using g++ on most \n # !machines. We'll have to check how to handle it on non-gcc machines \n ## add module to the needed source code files and build extension\n ## FIX this is g++ specific. It probably should be fixed for other\n ## Unices/compilers. Find a generic solution\n #if compiler_name != 'msvc':\n # libraries = kw.get('libraries',[])\n # kw['libraries'] = ['stdc++'] + libraries \n # !\n \n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n platform = sys.platform\n version = sys.version.lower()\n if platform[:5] == 'sunos' and version.find('gcc') != -1:\n extra_link_args = kw.get('extra_link_args',[])\n kw['extra_link_args'] = ['-mimpure-text'] + extra_link_args\n \n ext = Extension(module_name, **kw)\n \n # the switcheroo on SystemExit here is meant to keep command line\n # sessions from exiting when compiles fail.\n builtin = sys.modules['__builtin__']\n old_SysExit = builtin.__dict__['SystemExit']\n builtin.__dict__['SystemExit'] = CompileError\n \n # distutils for MSVC messes with the environment, so we save the\n # current state and restore them afterward.\n import copy\n environ = copy.deepcopy(os.environ)\n try:\n setup(name = module_name, ext_modules = [ext],verbose=verb)\n finally:\n # restore state\n os.environ = environ \n # restore SystemExit\n builtin.__dict__['SystemExit'] = old_SysExit\n t2 = time.time()\n \n if verbose == 1:\n print 'finished compiling (sec): ', t2 - t1 \n success = 1\n configure_python_path(build_dir)\n except SyntaxError: #TypeError:\n success = 0 \n \n # restore argv after our trick... \n restore_sys_argv()\n \n return success\n\nold_argv = []\ndef configure_sys_argv(compiler_name,temp_dir,build_dir):\n # We're gonna play some tricks with argv here to pass info to distutils \n # which is really built for command line use. better way??\n global old_argv\n old_argv = sys.argv[:] \n sys.argv = ['','build_ext','--build-lib', build_dir,\n '--build-temp',temp_dir] \n if compiler_name == 'gcc':\n sys.argv.insert(2,'--compiler='+compiler_name)\n elif compiler_name:\n sys.argv.insert(2,'--compiler='+compiler_name)\n\ndef restore_sys_argv():\n sys.argv = old_argv\n \ndef configure_python_path(build_dir): \n #make sure the module lives in a directory on the python path.\n python_paths = [os.path.abspath(x) for x in sys.path]\n if os.path.abspath(build_dir) not in python_paths:\n #print \"warning: build directory was not part of python path.\"\\\n # \" It has been appended to the path.\"\n sys.path.append(os.path.abspath(build_dir))\n\ndef choose_compiler(compiler_name=''):\n \"\"\" Try and figure out which compiler is gonna be used on windows.\n On other platforms, it just returns whatever value it is given.\n \n converts 'gcc' to 'mingw32' on win32\n \"\"\"\n if sys.platform == 'win32': \n if not compiler_name:\n # On Windows, default to MSVC and use gcc if it wasn't found\n # wasn't found. If neither are found, go with whatever\n # the default is for distutils -- and probably fail...\n if msvc_exists():\n compiler_name = 'msvc'\n elif gcc_exists():\n compiler_name = 'mingw32'\n elif compiler_name == 'gcc':\n compiler_name = 'mingw32'\n else:\n # don't know how to force gcc -- look into this.\n if compiler_name == 'gcc':\n compiler_name = 'unix' \n return compiler_name\n \ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n version = distutils.msvccompiler.get_devstudio_version()\n if version:\n result = 1\n return result\n\ndef configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n print \"warning: specified temp_dir '%s' does not exist or is \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n\n # final check that that directories are writable. \n if not os.access(temp_dir,os.W_OK):\n msg = \"Either the temp or build directory wasn't writable. Check\" \\\n \" these locations: '%s'\" % temp_dir \n raise ValueError, msg\n return temp_dir\n\ndef configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n print \"warning: specified build_dir '%s' does not exist or is \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n if build_dir is None:\n #default to building in the home directory of the given module. \n build_dir = os.curdir\n # if it doesn't work use the current directory. This should always\n # be writable. \n if not os.access(build_dir,os.W_OK):\n print \"warning:, neither the module's directory nor the \"\\\n \"current directory are writable. Using the temporary\"\\\n \"directory.\"\n build_dir = tempfile.gettempdir()\n\n # final check that that directories are writable.\n if not os.access(build_dir,os.W_OK):\n msg = \"The build directory wasn't writable. Check\" \\\n \" this location: '%s'\" % build_dir\n raise ValueError, msg\n \n return os.path.abspath(build_dir) \n \nif sys.platform == 'win32':\n import distutils.cygwinccompiler\n # the same as cygwin plus some additional parameters\n class Mingw32CCompiler (distutils.cygwinccompiler.CygwinCCompiler):\n \"\"\" A modified MingW32 compiler compatible with an MSVC built Python.\n \n \"\"\"\n \n compiler_type = 'mingw32'\n \n def __init__ (self,\n verbose=0,\n dry_run=0,\n force=0):\n \n distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose, \n dry_run, force)\n \n # A real mingw32 doesn't need to specify a different entry point,\n # but cygwin 2.91.57 in no-cygwin-mode needs it.\n if self.gcc_version <= \"2.91.57\":\n entry_point = '--entry _DllMain@12'\n else:\n entry_point = ''\n if self.linker_dll == 'dllwrap':\n self.linker = 'dllwrap' + ' --driver-name g++'\n elif self.linker_dll == 'gcc':\n self.linker = 'g++' \n # **changes: eric jones 4/11/01\n # 1. Check for import library on Windows. Build if it doesn't exist.\n if not import_library_exists():\n build_import_library()\n \n # **changes: eric jones 4/11/01\n # 2. increased optimization and turned off all warnings\n # 3. also added --driver-name g++\n #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n # compiler_so='gcc -mno-cygwin -mdll -O2 -w',\n # linker_exe='gcc -mno-cygwin',\n # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' \n # % (self.linker, entry_point))\n self.set_executables(compiler='g++ -mno-cygwin -O2 -w',\n compiler_so='g++ -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',\n linker_exe='g++ -mno-cygwin',\n linker_so='%s -mno-cygwin -mdll -static %s' \n % (self.linker, entry_point))\n \n # Maybe we should also append -mthreads, but then the finished\n # dlls need another dll (mingwm10.dll see Mingw32 docs)\n # (-mthreads: Support thread-safe exception handling on `Mingw32') \n \n # no additional libraries needed \n self.dll_libraries=[]\n \n # __init__ ()\n \n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n # We should also check the version of gcc available...\n #distutils.ccompiler._default_compilers['nt'] = 'mingw32'\n #distutils.ccompiler._default_compilers = (('nt', 'mingw32'))\n # reset the Mingw32 compiler in distutils to the one defined above\n distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler\n \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if os.name == 'nt':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n import lib2def as lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print 'WARNING: failed to build import library for gcc. Linking will fail.'\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\n\n\n", "methods": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [], "start_line": 30, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 49, "complexity": 9, "token_count": 364, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 51, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 171, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name , temp_dir , build_dir )", "filename": "build_tools.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [ "compiler_name", "temp_dir", "build_dir" ], "start_line": 224, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "build_tools.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 236, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "configure_python_path", "long_name": "configure_python_path( build_dir )", "filename": "build_tools.py", "nloc": 4, "complexity": 3, "token_count": 51, "parameters": [ "build_dir" ], "start_line": 239, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "build_tools.py", "nloc": 13, "complexity": 7, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 247, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 270, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "build_tools.py", "nloc": 14, "complexity": 4, "token_count": 71, "parameters": [], "start_line": 292, "end_line": 309, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 311, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 327, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_tools.py", "nloc": 22, "complexity": 5, "token_count": 117, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 364, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 2 }, { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "build_tools.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 418, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 428, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 459, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 463, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [], "start_line": 30, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 49, "complexity": 9, "token_count": 364, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 51, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 171, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name , temp_dir , build_dir )", "filename": "build_tools.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [ "compiler_name", "temp_dir", "build_dir" ], "start_line": 224, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "build_tools.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 236, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "configure_python_path", "long_name": "configure_python_path( build_dir )", "filename": "build_tools.py", "nloc": 4, "complexity": 3, "token_count": 51, "parameters": [ "build_dir" ], "start_line": 239, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "build_tools.py", "nloc": 13, "complexity": 7, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 247, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 270, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "build_tools.py", "nloc": 14, "complexity": 4, "token_count": 71, "parameters": [], "start_line": 292, "end_line": 309, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 311, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 327, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_tools.py", "nloc": 22, "complexity": 5, "token_count": 117, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 364, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 2 }, { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "build_tools.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 418, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 428, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 459, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 463, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 327, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 311, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 } ], "nloc": 230, "complexity": 56, "token_count": 1440, "diff_parsed": { "added": [ " print \"warning: specified temp_dir '%s' does not exist \" \\", " print \"warning: specified build_dir '%s' does not exist \" \\" ], "deleted": [ " print \"warning: specified temp_dir '%s' does not exist or is \" \\", " print \"warning: specified build_dir '%s' does not exist or is \" \\" ] } } ] }, { "hash": "ef494feebe6224fb56ba36961b60d609f74551ee", "msg": "The existing code couldn't possibly work on shared machines, as weave\nwas trying to write to /tmp/pythonNM_intermediate for all users.\nThese changes are aimed at fixing that problem. An extra directory\nlayer, currently defined by whoami() (new function) is inserted, e.g.,\n\n /tmp/skip/pythonNM_intermediate\n\nSomebody with more cross-platform experience should check whoami() for\nportability issues (does M$ have to fiddle everything they touch?).\n\nOther related bits:\n\n * added create_dir() which will create a path, including any missing\n intermediate paths.\n\n * moved the tempfile import to the top level (function-level imports\n got much slower in Python 2.2, so are normally to be avoided).\n\n * dumped the os.access() calls in favor of a new is_writable()\n function which simply checks to see if it can create a file in the\n given directory. access() is almost never what you want... ;-)\n is_writable() should also be checked for portability issues.", "author": { "name": "skip", "email": "skip@localhost" }, "committer": { "name": "skip", "email": "skip@localhost" }, "author_date": "2002-09-16T20:45:55+00:00", "author_timezone": 0, "committer_date": "2002-09-16T20:45:55+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "74944fabc1dcaf0a42418029366eae8af23316bc" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 12, "insertions": 38, "lines": 50, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "weave/catalog.py", "new_path": "weave/catalog.py", "filename": "catalog.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -33,6 +33,7 @@\n \n import os,sys,string\n import pickle\n+import tempfile\n \n try:\n import dbhash\n@@ -110,7 +111,34 @@ def unique_file(d,expr):\n fname+'.pyd' in files):\n break\n return os.path.join(d,fname)\n- \n+\n+def create_dir(p):\n+ \"\"\" Create a directory and any necessary intermediate directories.\"\"\"\n+ if not os.path.exists(p):\n+ try:\n+ os.mkdir(p)\n+ except OSError:\n+ # perhaps one or more intermediate path components don't exist\n+ # try to create them\n+ base,dir = os.path.split(p)\n+ create_dir(base)\n+ # don't enclose this one in try/except - we want the user to\n+ # get failure info\n+ os.mkdir(p)\n+\n+def is_writable(dir):\n+ dummy = os.path.join(dir, \"dummy\")\n+ try:\n+ open(dummy, 'w')\n+ except IOError:\n+ return 0\n+ os.unlink(dummy)\n+ return 1\n+\n+def whoami():\n+ \"\"\"return a string identifying the user.\"\"\"\n+ return os.environ.get(\"USER\") or os.environ.get(\"USERNAME\") or \"unknown\"\n+\n def default_dir():\n \"\"\" Return a default location to store compiled files and catalogs.\n \n@@ -127,7 +155,6 @@ def default_dir():\n to try and keep people from being able to sneak a bad module\n in on you. \n \"\"\"\n- import tempfile \n python_name = \"python%d%d_compiled\" % tuple(sys.version_info[:2]) \n if sys.platform != 'win32':\n try:\n@@ -136,35 +163,34 @@ def default_dir():\n temp_dir = `os.getuid()` + '_' + python_name\n path = os.path.join(tempfile.gettempdir(),temp_dir) \n else:\n- path = os.path.join(tempfile.gettempdir(),python_name)\n+ path = os.path.join(tempfile.gettempdir(),\"%s\"%whoami(),python_name)\n \n if not os.path.exists(path):\n- os.mkdir(path)\n+ create_dir(path)\n os.chmod(path,0700) # make it only accessible by this user.\n- if not os.access(path,os.W_OK):\n+ if not is_writable(path):\n print 'warning: default directory is not write accessible.'\n- print 'defualt:', path\n+ print 'default:', path\n return path\n \n def intermediate_dir():\n \"\"\" Location in temp dir for storing .cpp and .o files during\n builds.\n \"\"\"\n- import tempfile \n python_name = \"python%d%d_intermediate\" % tuple(sys.version_info[:2]) \n- path = os.path.join(tempfile.gettempdir(),python_name)\n+ path = os.path.join(tempfile.gettempdir(),\"%s\"%whoami(),python_name)\n if not os.path.exists(path):\n- os.mkdir(path)\n+ create_dir(path)\n return path\n \n def default_temp_dir():\n path = os.path.join(default_dir(),'temp')\n if not os.path.exists(path):\n- os.mkdir(path)\n+ create_dir(path)\n os.chmod(path,0700) # make it only accessible by this user.\n- if not os.access(path,os.W_OK):\n+ if not is_writable(path):\n print 'warning: default directory is not write accessible.'\n- print 'defualt:', path\n+ print 'default:', path\n return path\n \n \n", "added_lines": 38, "deleted_lines": 12, "source_code": "\"\"\" Track relationships between compiled extension functions & code fragments\n\n catalog keeps track of which compiled(or even standard) functions are \n related to which code fragments. It also stores these relationships\n to disk so they are remembered between Python sessions. When \n \n a = 1\n compiler.inline('printf(\"printed from C: %d\",a);',['a'] )\n \n is called, inline() first looks to see if it has seen the code \n 'printf(\"printed from C\");' before. If not, it calls \n \n catalog.get_functions('printf(\"printed from C: %d\", a);')\n \n which returns a list of all the function objects that have been compiled\n for the code fragment. Multiple functions can occur because the code\n could be compiled for different types for 'a' (although not likely in\n this case). The catalog first looks in its cache and quickly returns\n a list of the functions if possible. If the cache lookup fails, it then\n looks through possibly multiple catalog files on disk and fills its\n cache with all the functions that match the code fragment. \n \n In case where the code fragment hasn't been compiled, inline() compiles\n the code and then adds it to the catalog:\n \n function = \n catalog.add_function('printf(\"printed from C: %d\", a);',function)\n \n add_function() adds function to the front of the cache. function,\n along with the path information to its module, are also stored in a\n persistent catalog for future use by python sessions. \n\"\"\" \n\nimport os,sys,string\nimport pickle\nimport tempfile\n\ntry:\n import dbhash\n import shelve\n dumb = 0\nexcept ImportError:\n import dumb_shelve as shelve\n dumb = 1\n\n#For testing...\n#import dumb_shelve as shelve\n#dumb = 1\n\n#import shelve\n#dumb = 0\n \ndef getmodule(object):\n \"\"\" Discover the name of the module where object was defined.\n \n This is an augmented version of inspect.getmodule that can discover \n the parent module for extension functions.\n \"\"\"\n import inspect\n value = inspect.getmodule(object)\n if value is None:\n #walk trough all modules looking for function\n for name,mod in sys.modules.items():\n # try except used because of some comparison failures\n # in wxPoint code. Need to review this\n try:\n if mod and object in mod.__dict__.values():\n value = mod\n # if it is a built-in module, keep looking to see\n # if a non-builtin also has it. Otherwise quit and\n # consider the module found. (ain't perfect, but will \n # have to do for now).\n if string.find('(built-in)',str(mod)) is -1:\n break\n \n except (TypeError, KeyError):\n pass \n return value\n\ndef expr_to_filename(expr):\n \"\"\" Convert an arbitrary expr string to a valid file name.\n \n The name is based on the md5 check sum for the string and\n Something that was a little more human readable would be \n nice, but the computer doesn't seem to care.\n \"\"\"\n import md5\n base = 'sc_'\n return base + md5.new(expr).hexdigest()\n\ndef unique_file(d,expr):\n \"\"\" Generate a unqiue file name based on expr in directory d\n \n This is meant for use with building extension modules, so\n a file name is considered unique if none of the following\n extension '.cpp','.o','.so','module.so','.py', or '.pyd'\n exists in directory d. The fully qualified path to the\n new name is returned. You'll need to append your own\n extension to it before creating files.\n \"\"\"\n files = os.listdir(d)\n #base = 'scipy_compile'\n base = expr_to_filename(expr)\n for i in range(1000000):\n fname = base + `i`\n if not (fname+'.cpp' in files or\n fname+'.o' in files or\n fname+'.so' in files or\n fname+'module.so' in files or\n fname+'.py' in files or\n fname+'.pyd' in files):\n break\n return os.path.join(d,fname)\n\ndef create_dir(p):\n \"\"\" Create a directory and any necessary intermediate directories.\"\"\"\n if not os.path.exists(p):\n try:\n os.mkdir(p)\n except OSError:\n # perhaps one or more intermediate path components don't exist\n # try to create them\n base,dir = os.path.split(p)\n create_dir(base)\n # don't enclose this one in try/except - we want the user to\n # get failure info\n os.mkdir(p)\n\ndef is_writable(dir):\n dummy = os.path.join(dir, \"dummy\")\n try:\n open(dummy, 'w')\n except IOError:\n return 0\n os.unlink(dummy)\n return 1\n\ndef whoami():\n \"\"\"return a string identifying the user.\"\"\"\n return os.environ.get(\"USER\") or os.environ.get(\"USERNAME\") or \"unknown\"\n\ndef default_dir():\n \"\"\" Return a default location to store compiled files and catalogs.\n \n XX is the Python version number in all paths listed below\n On windows, the default location is the temporary directory\n returned by gettempdir()/pythonXX.\n \n On Unix, ~/.pythonXX_compiled is the default location. If it doesn't\n exist, it is created. The directory is marked rwx------.\n \n If for some reason it isn't possible to build a default directory\n in the user's home, /tmp/_pythonXX_compiled is used. If it \n doesn't exist, it is created. The directory is marked rwx------\n to try and keep people from being able to sneak a bad module\n in on you. \n \"\"\"\n python_name = \"python%d%d_compiled\" % tuple(sys.version_info[:2]) \n if sys.platform != 'win32':\n try:\n path = os.path.join(os.environ['HOME'],'.' + python_name)\n except KeyError:\n temp_dir = `os.getuid()` + '_' + python_name\n path = os.path.join(tempfile.gettempdir(),temp_dir) \n else:\n path = os.path.join(tempfile.gettempdir(),\"%s\"%whoami(),python_name)\n \n if not os.path.exists(path):\n create_dir(path)\n os.chmod(path,0700) # make it only accessible by this user.\n if not is_writable(path):\n print 'warning: default directory is not write accessible.'\n print 'default:', path\n return path\n\ndef intermediate_dir():\n \"\"\" Location in temp dir for storing .cpp and .o files during\n builds.\n \"\"\"\n python_name = \"python%d%d_intermediate\" % tuple(sys.version_info[:2]) \n path = os.path.join(tempfile.gettempdir(),\"%s\"%whoami(),python_name)\n if not os.path.exists(path):\n create_dir(path)\n return path\n \ndef default_temp_dir():\n path = os.path.join(default_dir(),'temp')\n if not os.path.exists(path):\n create_dir(path)\n os.chmod(path,0700) # make it only accessible by this user.\n if not is_writable(path):\n print 'warning: default directory is not write accessible.'\n print 'default:', path\n return path\n\n \ndef os_dependent_catalog_name():\n \"\"\" Generate catalog name dependent on OS and Python version being used.\n \n This allows multiple platforms to have catalog files in the\n same directory without stepping on each other. For now, it \n bases the name of the value returned by sys.platform and the\n version of python being run. If this isn't enough to descriminate\n on some platforms, we can try to add other info. It has \n occured to me that if we get fancy enough to optimize for different\n architectures, then chip type might be added to the catalog name also.\n \"\"\"\n version = '%d%d' % sys.version_info[:2]\n return sys.platform+version+'compiled_catalog'\n \ndef catalog_path(module_path):\n \"\"\" Return the full path name for the catalog file in the given directory.\n \n module_path can either be a file name or a path name. If it is a \n file name, the catalog file name in its parent directory is returned.\n If it is a directory, the catalog file in that directory is returned.\n\n If module_path doesn't exist, None is returned. Note though, that the\n catalog file does *not* have to exist, only its parent. '~', shell\n variables, and relative ('.' and '..') paths are all acceptable.\n \n catalog file names are os dependent (based on sys.platform), so this \n should support multiple platforms sharing the same disk space \n (NFS mounts). See os_dependent_catalog_name() for more info.\n \"\"\"\n module_path = os.path.expanduser(module_path)\n module_path = os.path.expandvars(module_path)\n module_path = os.path.abspath(module_path)\n if not os.path.exists(module_path):\n catalog_file = None\n elif not os.path.isdir(module_path):\n module_path,dummy = os.path.split(module_path)\n catalog_file = os.path.join(module_path,os_dependent_catalog_name())\n else: \n catalog_file = os.path.join(module_path,os_dependent_catalog_name())\n return catalog_file\n\ndef get_catalog(module_path,mode='r'):\n \"\"\" Return a function catalog (shelve object) from the path module_path\n\n If module_path is a directory, the function catalog returned is\n from that directory. If module_path is an actual module_name,\n then the function catalog returned is from its parent directory.\n mode uses the standard 'c' = create, 'n' = new, 'r' = read, \n 'w' = write file open modes available for anydbm databases.\n \n Well... it should be. Stuck with dumbdbm for now and the modes\n almost don't matter. We do some checking for 'r' mode, but that\n is about it.\n \n See catalog_path() for more information on module_path.\n \"\"\"\n if mode not in ['c','r','w','n']:\n msg = \" mode must be 'c', 'n', 'r', or 'w'. See anydbm for more info\"\n raise ValueError, msg\n catalog_file = catalog_path(module_path)\n try:\n # code reliant on the fact that we are using dumbdbm\n if dumb and mode == 'r' and not os.path.exists(catalog_file+'.dat'):\n sh = None\n else:\n sh = shelve.open(catalog_file,mode)\n except: # not sure how to pin down which error to catch yet\n sh = None\n return sh\n\nclass catalog:\n \"\"\" Stores information about compiled functions both in cache and on disk.\n \n catalog stores (code, list_of_function) pairs so that all the functions\n that have been compiled for code are available for calling (usually in\n inline or blitz).\n \n catalog keeps a dictionary of previously accessed code values cached \n for quick access. It also handles the looking up of functions compiled \n in previously called Python sessions on disk in function catalogs. \n catalog searches the directories in the PYTHONCOMPILED environment \n variable in order loading functions that correspond to the given code \n fragment. A default directory is also searched for catalog functions. \n On unix, the default directory is usually '~/.pythonxx_compiled' where \n xx is the version of Python used. On windows, it is the directory \n returned by temfile.gettempdir(). Functions closer to the front are of \n the variable list are guaranteed to be closer to the front of the \n function list so that they will be called first. See \n get_cataloged_functions() for more info on how the search order is \n traversed.\n \n Catalog also handles storing information about compiled functions to\n a catalog. When writing this information, the first writable catalog\n file in PYTHONCOMPILED path is used. If a writable catalog is not\n found, it is written to the catalog in the default directory. This\n directory should always be writable.\n \"\"\"\n def __init__(self,user_path_list=None):\n \"\"\" Create a catalog for storing/searching for compiled functions. \n \n user_path_list contains directories that should be searched \n first for function catalogs. They will come before the path\n entries in the PYTHONCOMPILED environment varilable.\n \"\"\"\n if type(user_path_list) == type('string'):\n self.user_path_list = [user_path_list]\n elif user_path_list:\n self.user_path_list = user_path_list\n else:\n self.user_path_list = []\n self.cache = {}\n self.module_dir = None\n self.paths_added = 0\n \n def set_module_directory(self,module_dir):\n \"\"\" Set the path that will replace 'MODULE' in catalog searches.\n \n You should call clear_module_directory() when your finished\n working with it.\n \"\"\"\n self.module_dir = module_dir\n def get_module_directory(self):\n \"\"\" Return the path used to replace the 'MODULE' in searches.\n \"\"\"\n return self.module_dir\n def clear_module_directory(self):\n \"\"\" Reset 'MODULE' path to None so that it is ignored in searches. \n \"\"\"\n self.module_dir = None\n \n def get_environ_path(self):\n \"\"\" Return list of paths from 'PYTHONCOMPILED' environment variable.\n \n On Unix the path in PYTHONCOMPILED is a ':' separated list of\n directories. On Windows, a ';' separated list is used. \n \"\"\"\n paths = []\n if os.environ.has_key('PYTHONCOMPILED'):\n path_string = os.environ['PYTHONCOMPILED'] \n if sys.platform == 'win32':\n #probably should also look in registry\n paths = path_string.split(';')\n else: \n paths = path_string.split(':')\n return paths \n\n def build_search_order(self):\n \"\"\" Returns a list of paths that are searched for catalogs. \n \n Values specified in the catalog constructor are searched first,\n then values found in the PYTHONCOMPILED environment variable.\n The directory returned by default_dir() is always returned at\n the end of the list.\n \n There is a 'magic' path name called 'MODULE' that is replaced\n by the directory defined by set_module_directory(). If the\n module directory hasn't been set, 'MODULE' is ignored.\n \"\"\"\n \n paths = self.user_path_list + self.get_environ_path()\n search_order = []\n for path in paths:\n if path == 'MODULE':\n if self.module_dir:\n search_order.append(self.module_dir)\n else:\n search_order.append(path)\n search_order.append(default_dir())\n return search_order\n\n def get_catalog_files(self):\n \"\"\" Returns catalog file list in correct search order.\n \n Some of the catalog files may not currently exists.\n However, all will be valid locations for a catalog\n to be created (if you have write permission).\n \"\"\"\n files = map(catalog_path,self.build_search_order())\n files = filter(lambda x: x is not None,files)\n return files\n\n def get_existing_files(self):\n \"\"\" Returns all existing catalog file list in correct search order.\n \"\"\"\n files = self.get_catalog_files()\n # open every stinking file to check if it exists.\n # This is because anydbm doesn't provide a consistent naming \n # convention across platforms for its files \n existing_files = []\n for file in files:\n if get_catalog(os.path.dirname(file),'r') is not None:\n existing_files.append(file)\n # This is the non-portable (and much faster) old code\n #existing_files = filter(os.path.exists,files)\n return existing_files\n\n def get_writable_file(self,existing_only=0):\n \"\"\" Return the name of the first writable catalog file.\n \n Its parent directory must also be writable. This is so that\n compiled modules can be written to the same directory.\n \"\"\"\n # note: both file and its parent directory must be writeable\n if existing_only:\n files = self.get_existing_files()\n else:\n files = self.get_catalog_files()\n # filter for (file exists and is writable) OR directory is writable\n def file_test(x):\n from os import access, F_OK, W_OK\n return (access(x,F_OK) and access(x,W_OK) or\n access(os.path.dirname(x),W_OK))\n writable = filter(file_test,files)\n if writable:\n file = writable[0]\n else:\n file = None\n return file\n \n def get_writable_dir(self):\n \"\"\" Return the parent directory of first writable catalog file.\n \n The returned directory has write access.\n \"\"\"\n return os.path.dirname(self.get_writable_file())\n \n def unique_module_name(self,code,module_dir=None):\n \"\"\" Return full path to unique file name that in writable location.\n \n The directory for the file is the first writable directory in \n the catalog search path. The unique file name is derived from\n the code fragment. If, module_dir is specified, it is used\n to replace 'MODULE' in the search path.\n \"\"\"\n if module_dir is not None:\n self.set_module_directory(module_dir)\n try:\n d = self.get_writable_dir()\n finally:\n if module_dir is not None:\n self.clear_module_directory()\n return unique_file(d,code)\n\n def path_key(self,code):\n \"\"\" Return key for path information for functions associated with code.\n \"\"\"\n return '__path__' + code\n \n def configure_path(self,cat,code):\n \"\"\" Add the python path for the given code to the sys.path\n \n unconfigure_path() should be called as soon as possible after\n imports associated with code are finished so that sys.path \n is restored to normal.\n \"\"\"\n try:\n paths = cat[self.path_key(code)]\n self.paths_added = len(paths)\n sys.path = paths + sys.path\n except:\n self.paths_added = 0 \n \n def unconfigure_path(self):\n \"\"\" Restores sys.path to normal after calls to configure_path()\n \n Remove the previously added paths from sys.path\n \"\"\"\n sys.path = sys.path[self.paths_added:]\n self.paths_added = 0\n\n def get_cataloged_functions(self,code):\n \"\"\" Load all functions associated with code from catalog search path.\n \n Sometimes there can be trouble loading a function listed in a\n catalog file because the actual module that holds the function \n has been moved or deleted. When this happens, that catalog file\n is \"repaired\", meaning the entire entry for this function is \n removed from the file. This only affects the catalog file that\n has problems -- not the others in the search path.\n \n The \"repair\" behavior may not be needed, but I'll keep it for now.\n \"\"\"\n mode = 'r'\n cat = None\n function_list = []\n for path in self.build_search_order():\n cat = get_catalog(path,mode)\n if cat is not None and cat.has_key(code):\n # set up the python path so that modules for this\n # function can be loaded.\n self.configure_path(cat,code)\n try: \n function_list += cat[code]\n except: #SystemError and ImportError so far seen \n # problems loading a function from the catalog. Try to\n # repair the cause.\n cat.close()\n self.repair_catalog(path,code)\n self.unconfigure_path() \n return function_list\n\n\n def repair_catalog(self,catalog_path,code):\n \"\"\" Remove entry for code from catalog_path\n \n Occasionally catalog entries could get corrupted. An example\n would be when a module that had functions in the catalog was\n deleted or moved on the disk. The best current repair method is \n just to trash the entire catalog entry for this piece of code. \n This may loose function entries that are valid, but thats life.\n \n catalog_path must be writable for repair. If it isn't, the\n function exists with a warning. \n \"\"\"\n writable_cat = None\n if not os.path.exists(catalog_path):\n return\n try:\n writable_cat = get_catalog(catalog_path,'w')\n except:\n print 'warning: unable to repair catalog entry\\n %s\\n in\\n %s' % \\\n (code,catalog_path)\n return \n if writable_cat.has_key(code):\n print 'repairing catalog by removing key'\n del writable_cat[code]\n \n # it is possible that the path key doesn't exist (if the function registered\n # was a built-in function), so we have to check if the path exists before\n # arbitrarily deleting it.\n path_key = self.path_key(code) \n if writable_cat.has_key(path_key):\n del writable_cat[path_key] \n \n def get_functions_fast(self,code):\n \"\"\" Return list of functions for code from the cache.\n \n Return an empty list if the code entry is not found.\n \"\"\"\n return self.cache.get(code,[])\n \n def get_functions(self,code,module_dir=None):\n \"\"\" Return the list of functions associated with this code fragment.\n \n The cache is first searched for the function. If an entry\n in the cache is not found, then catalog files on disk are \n searched for the entry. This is slooooow, but only happens\n once per code object. All the functions found in catalog files\n on a cache miss are loaded into the cache to speed up future calls.\n The search order is as follows:\n \n 1. user specified path (from catalog initialization)\n 2. directories from the PYTHONCOMPILED environment variable\n 3. The temporary directory on your platform.\n\n The path specified by module_dir will replace the 'MODULE' \n place holder in the catalog search path. See build_search_order()\n for more info on the search path. \n \"\"\" \n # Fast!! try cache first.\n if self.cache.has_key(code):\n return self.cache[code]\n \n # 2. Slow!! read previously compiled functions from disk.\n try:\n self.set_module_directory(module_dir)\n function_list = self.get_cataloged_functions(code)\n # put function_list in cache to save future lookups.\n if function_list:\n self.cache[code] = function_list\n # return function_list, empty or otherwise.\n finally:\n self.clear_module_directory()\n return function_list\n\n def add_function(self,code,function,module_dir=None):\n \"\"\" Adds a function to the catalog.\n \n The function is added to the cache as well as the first\n writable file catalog found in the search path. If no\n code entry exists in the cache, the on disk catalogs\n are loaded into the cache and function is added to the\n beginning of the function list.\n \n The path specified by module_dir will replace the 'MODULE' \n place holder in the catalog search path. See build_search_order()\n for more info on the search path. \n \"\"\" \n\n # 1. put it in the cache.\n if self.cache.has_key(code):\n if function not in self.cache[code]:\n self.cache[code].insert(0,function)\n else:\n # if it is in the cache, then it is also\n # been persisted \n return\n else: \n # Load functions and put this one up front\n self.cache[code] = self.get_functions(code) \n self.fast_cache(code,function)\n # 2. Store the function entry to disk. \n try:\n self.set_module_directory(module_dir)\n self.add_function_persistent(code,function)\n finally:\n self.clear_module_directory()\n \n def add_function_persistent(self,code,function):\n \"\"\" Store the code->function relationship to disk.\n \n Two pieces of information are needed for loading functions\n from disk -- the function pickle (which conveniently stores\n the module name, etc.) and the path to its module's directory.\n The latter is needed so that the function can be loaded no\n matter what the user's Python path is.\n \"\"\" \n # add function to data in first writable catalog\n mode = 'c' # create if doesn't exist, otherwise, use existing\n cat_dir = self.get_writable_dir()\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n cat_dir = default_dir()\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n cat_dir = default_dir() \n cat_file = catalog_path(cat_dir)\n print 'problems with default catalog -- removing'\n import glob\n files = glob.glob(cat_file+'*')\n for f in files:\n os.remove(f)\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n raise ValueError, 'Failed to access a catalog for storing functions' \n # Prabhu was getting some corrupt catalog errors. I'll put a try/except\n # to protect against this, but should really try and track down the issue.\n function_list = [function]\n try:\n function_list = function_list + cat.get(code,[])\n except pickle.UnpicklingError:\n pass\n cat[code] = function_list\n # now add needed path information for loading function\n module = getmodule(function)\n try:\n # built in modules don't have the __file__ extension, so this\n # will fail. Just pass in this case since path additions aren't\n # needed for built-in modules.\n mod_path,f=os.path.split(os.path.abspath(module.__file__))\n pkey = self.path_key(code)\n cat[pkey] = [mod_path] + cat.get(pkey,[])\n except:\n pass\n\n def fast_cache(self,code,function):\n \"\"\" Move function to the front of the cache entry for code\n \n If future calls to the function have the same type signature,\n this will speed up access significantly because the first\n function call is correct.\n \n Note: The cache added to the inline_tools module is significantly\n faster than always calling get_functions, so this isn't\n as necessary as it used to be. Still, it's probably worth\n doing. \n \"\"\"\n try:\n if self.cache[code][0] == function:\n return\n except: # KeyError, IndexError \n pass\n try:\n self.cache[code].remove(function)\n except ValueError:\n pass\n # put new function at the beginning of the list to search.\n self.cache[code].insert(0,function)\n \ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "source_code_before": "\"\"\" Track relationships between compiled extension functions & code fragments\n\n catalog keeps track of which compiled(or even standard) functions are \n related to which code fragments. It also stores these relationships\n to disk so they are remembered between Python sessions. When \n \n a = 1\n compiler.inline('printf(\"printed from C: %d\",a);',['a'] )\n \n is called, inline() first looks to see if it has seen the code \n 'printf(\"printed from C\");' before. If not, it calls \n \n catalog.get_functions('printf(\"printed from C: %d\", a);')\n \n which returns a list of all the function objects that have been compiled\n for the code fragment. Multiple functions can occur because the code\n could be compiled for different types for 'a' (although not likely in\n this case). The catalog first looks in its cache and quickly returns\n a list of the functions if possible. If the cache lookup fails, it then\n looks through possibly multiple catalog files on disk and fills its\n cache with all the functions that match the code fragment. \n \n In case where the code fragment hasn't been compiled, inline() compiles\n the code and then adds it to the catalog:\n \n function = \n catalog.add_function('printf(\"printed from C: %d\", a);',function)\n \n add_function() adds function to the front of the cache. function,\n along with the path information to its module, are also stored in a\n persistent catalog for future use by python sessions. \n\"\"\" \n\nimport os,sys,string\nimport pickle\n\ntry:\n import dbhash\n import shelve\n dumb = 0\nexcept ImportError:\n import dumb_shelve as shelve\n dumb = 1\n\n#For testing...\n#import dumb_shelve as shelve\n#dumb = 1\n\n#import shelve\n#dumb = 0\n \ndef getmodule(object):\n \"\"\" Discover the name of the module where object was defined.\n \n This is an augmented version of inspect.getmodule that can discover \n the parent module for extension functions.\n \"\"\"\n import inspect\n value = inspect.getmodule(object)\n if value is None:\n #walk trough all modules looking for function\n for name,mod in sys.modules.items():\n # try except used because of some comparison failures\n # in wxPoint code. Need to review this\n try:\n if mod and object in mod.__dict__.values():\n value = mod\n # if it is a built-in module, keep looking to see\n # if a non-builtin also has it. Otherwise quit and\n # consider the module found. (ain't perfect, but will \n # have to do for now).\n if string.find('(built-in)',str(mod)) is -1:\n break\n \n except (TypeError, KeyError):\n pass \n return value\n\ndef expr_to_filename(expr):\n \"\"\" Convert an arbitrary expr string to a valid file name.\n \n The name is based on the md5 check sum for the string and\n Something that was a little more human readable would be \n nice, but the computer doesn't seem to care.\n \"\"\"\n import md5\n base = 'sc_'\n return base + md5.new(expr).hexdigest()\n\ndef unique_file(d,expr):\n \"\"\" Generate a unqiue file name based on expr in directory d\n \n This is meant for use with building extension modules, so\n a file name is considered unique if none of the following\n extension '.cpp','.o','.so','module.so','.py', or '.pyd'\n exists in directory d. The fully qualified path to the\n new name is returned. You'll need to append your own\n extension to it before creating files.\n \"\"\"\n files = os.listdir(d)\n #base = 'scipy_compile'\n base = expr_to_filename(expr)\n for i in range(1000000):\n fname = base + `i`\n if not (fname+'.cpp' in files or\n fname+'.o' in files or\n fname+'.so' in files or\n fname+'module.so' in files or\n fname+'.py' in files or\n fname+'.pyd' in files):\n break\n return os.path.join(d,fname)\n \ndef default_dir():\n \"\"\" Return a default location to store compiled files and catalogs.\n \n XX is the Python version number in all paths listed below\n On windows, the default location is the temporary directory\n returned by gettempdir()/pythonXX.\n \n On Unix, ~/.pythonXX_compiled is the default location. If it doesn't\n exist, it is created. The directory is marked rwx------.\n \n If for some reason it isn't possible to build a default directory\n in the user's home, /tmp/_pythonXX_compiled is used. If it \n doesn't exist, it is created. The directory is marked rwx------\n to try and keep people from being able to sneak a bad module\n in on you. \n \"\"\"\n import tempfile \n python_name = \"python%d%d_compiled\" % tuple(sys.version_info[:2]) \n if sys.platform != 'win32':\n try:\n path = os.path.join(os.environ['HOME'],'.' + python_name)\n except KeyError:\n temp_dir = `os.getuid()` + '_' + python_name\n path = os.path.join(tempfile.gettempdir(),temp_dir) \n else:\n path = os.path.join(tempfile.gettempdir(),python_name)\n \n if not os.path.exists(path):\n os.mkdir(path)\n os.chmod(path,0700) # make it only accessible by this user.\n if not os.access(path,os.W_OK):\n print 'warning: default directory is not write accessible.'\n print 'defualt:', path\n return path\n\ndef intermediate_dir():\n \"\"\" Location in temp dir for storing .cpp and .o files during\n builds.\n \"\"\"\n import tempfile \n python_name = \"python%d%d_intermediate\" % tuple(sys.version_info[:2]) \n path = os.path.join(tempfile.gettempdir(),python_name)\n if not os.path.exists(path):\n os.mkdir(path)\n return path\n \ndef default_temp_dir():\n path = os.path.join(default_dir(),'temp')\n if not os.path.exists(path):\n os.mkdir(path)\n os.chmod(path,0700) # make it only accessible by this user.\n if not os.access(path,os.W_OK):\n print 'warning: default directory is not write accessible.'\n print 'defualt:', path\n return path\n\n \ndef os_dependent_catalog_name():\n \"\"\" Generate catalog name dependent on OS and Python version being used.\n \n This allows multiple platforms to have catalog files in the\n same directory without stepping on each other. For now, it \n bases the name of the value returned by sys.platform and the\n version of python being run. If this isn't enough to descriminate\n on some platforms, we can try to add other info. It has \n occured to me that if we get fancy enough to optimize for different\n architectures, then chip type might be added to the catalog name also.\n \"\"\"\n version = '%d%d' % sys.version_info[:2]\n return sys.platform+version+'compiled_catalog'\n \ndef catalog_path(module_path):\n \"\"\" Return the full path name for the catalog file in the given directory.\n \n module_path can either be a file name or a path name. If it is a \n file name, the catalog file name in its parent directory is returned.\n If it is a directory, the catalog file in that directory is returned.\n\n If module_path doesn't exist, None is returned. Note though, that the\n catalog file does *not* have to exist, only its parent. '~', shell\n variables, and relative ('.' and '..') paths are all acceptable.\n \n catalog file names are os dependent (based on sys.platform), so this \n should support multiple platforms sharing the same disk space \n (NFS mounts). See os_dependent_catalog_name() for more info.\n \"\"\"\n module_path = os.path.expanduser(module_path)\n module_path = os.path.expandvars(module_path)\n module_path = os.path.abspath(module_path)\n if not os.path.exists(module_path):\n catalog_file = None\n elif not os.path.isdir(module_path):\n module_path,dummy = os.path.split(module_path)\n catalog_file = os.path.join(module_path,os_dependent_catalog_name())\n else: \n catalog_file = os.path.join(module_path,os_dependent_catalog_name())\n return catalog_file\n\ndef get_catalog(module_path,mode='r'):\n \"\"\" Return a function catalog (shelve object) from the path module_path\n\n If module_path is a directory, the function catalog returned is\n from that directory. If module_path is an actual module_name,\n then the function catalog returned is from its parent directory.\n mode uses the standard 'c' = create, 'n' = new, 'r' = read, \n 'w' = write file open modes available for anydbm databases.\n \n Well... it should be. Stuck with dumbdbm for now and the modes\n almost don't matter. We do some checking for 'r' mode, but that\n is about it.\n \n See catalog_path() for more information on module_path.\n \"\"\"\n if mode not in ['c','r','w','n']:\n msg = \" mode must be 'c', 'n', 'r', or 'w'. See anydbm for more info\"\n raise ValueError, msg\n catalog_file = catalog_path(module_path)\n try:\n # code reliant on the fact that we are using dumbdbm\n if dumb and mode == 'r' and not os.path.exists(catalog_file+'.dat'):\n sh = None\n else:\n sh = shelve.open(catalog_file,mode)\n except: # not sure how to pin down which error to catch yet\n sh = None\n return sh\n\nclass catalog:\n \"\"\" Stores information about compiled functions both in cache and on disk.\n \n catalog stores (code, list_of_function) pairs so that all the functions\n that have been compiled for code are available for calling (usually in\n inline or blitz).\n \n catalog keeps a dictionary of previously accessed code values cached \n for quick access. It also handles the looking up of functions compiled \n in previously called Python sessions on disk in function catalogs. \n catalog searches the directories in the PYTHONCOMPILED environment \n variable in order loading functions that correspond to the given code \n fragment. A default directory is also searched for catalog functions. \n On unix, the default directory is usually '~/.pythonxx_compiled' where \n xx is the version of Python used. On windows, it is the directory \n returned by temfile.gettempdir(). Functions closer to the front are of \n the variable list are guaranteed to be closer to the front of the \n function list so that they will be called first. See \n get_cataloged_functions() for more info on how the search order is \n traversed.\n \n Catalog also handles storing information about compiled functions to\n a catalog. When writing this information, the first writable catalog\n file in PYTHONCOMPILED path is used. If a writable catalog is not\n found, it is written to the catalog in the default directory. This\n directory should always be writable.\n \"\"\"\n def __init__(self,user_path_list=None):\n \"\"\" Create a catalog for storing/searching for compiled functions. \n \n user_path_list contains directories that should be searched \n first for function catalogs. They will come before the path\n entries in the PYTHONCOMPILED environment varilable.\n \"\"\"\n if type(user_path_list) == type('string'):\n self.user_path_list = [user_path_list]\n elif user_path_list:\n self.user_path_list = user_path_list\n else:\n self.user_path_list = []\n self.cache = {}\n self.module_dir = None\n self.paths_added = 0\n \n def set_module_directory(self,module_dir):\n \"\"\" Set the path that will replace 'MODULE' in catalog searches.\n \n You should call clear_module_directory() when your finished\n working with it.\n \"\"\"\n self.module_dir = module_dir\n def get_module_directory(self):\n \"\"\" Return the path used to replace the 'MODULE' in searches.\n \"\"\"\n return self.module_dir\n def clear_module_directory(self):\n \"\"\" Reset 'MODULE' path to None so that it is ignored in searches. \n \"\"\"\n self.module_dir = None\n \n def get_environ_path(self):\n \"\"\" Return list of paths from 'PYTHONCOMPILED' environment variable.\n \n On Unix the path in PYTHONCOMPILED is a ':' separated list of\n directories. On Windows, a ';' separated list is used. \n \"\"\"\n paths = []\n if os.environ.has_key('PYTHONCOMPILED'):\n path_string = os.environ['PYTHONCOMPILED'] \n if sys.platform == 'win32':\n #probably should also look in registry\n paths = path_string.split(';')\n else: \n paths = path_string.split(':')\n return paths \n\n def build_search_order(self):\n \"\"\" Returns a list of paths that are searched for catalogs. \n \n Values specified in the catalog constructor are searched first,\n then values found in the PYTHONCOMPILED environment variable.\n The directory returned by default_dir() is always returned at\n the end of the list.\n \n There is a 'magic' path name called 'MODULE' that is replaced\n by the directory defined by set_module_directory(). If the\n module directory hasn't been set, 'MODULE' is ignored.\n \"\"\"\n \n paths = self.user_path_list + self.get_environ_path()\n search_order = []\n for path in paths:\n if path == 'MODULE':\n if self.module_dir:\n search_order.append(self.module_dir)\n else:\n search_order.append(path)\n search_order.append(default_dir())\n return search_order\n\n def get_catalog_files(self):\n \"\"\" Returns catalog file list in correct search order.\n \n Some of the catalog files may not currently exists.\n However, all will be valid locations for a catalog\n to be created (if you have write permission).\n \"\"\"\n files = map(catalog_path,self.build_search_order())\n files = filter(lambda x: x is not None,files)\n return files\n\n def get_existing_files(self):\n \"\"\" Returns all existing catalog file list in correct search order.\n \"\"\"\n files = self.get_catalog_files()\n # open every stinking file to check if it exists.\n # This is because anydbm doesn't provide a consistent naming \n # convention across platforms for its files \n existing_files = []\n for file in files:\n if get_catalog(os.path.dirname(file),'r') is not None:\n existing_files.append(file)\n # This is the non-portable (and much faster) old code\n #existing_files = filter(os.path.exists,files)\n return existing_files\n\n def get_writable_file(self,existing_only=0):\n \"\"\" Return the name of the first writable catalog file.\n \n Its parent directory must also be writable. This is so that\n compiled modules can be written to the same directory.\n \"\"\"\n # note: both file and its parent directory must be writeable\n if existing_only:\n files = self.get_existing_files()\n else:\n files = self.get_catalog_files()\n # filter for (file exists and is writable) OR directory is writable\n def file_test(x):\n from os import access, F_OK, W_OK\n return (access(x,F_OK) and access(x,W_OK) or\n access(os.path.dirname(x),W_OK))\n writable = filter(file_test,files)\n if writable:\n file = writable[0]\n else:\n file = None\n return file\n \n def get_writable_dir(self):\n \"\"\" Return the parent directory of first writable catalog file.\n \n The returned directory has write access.\n \"\"\"\n return os.path.dirname(self.get_writable_file())\n \n def unique_module_name(self,code,module_dir=None):\n \"\"\" Return full path to unique file name that in writable location.\n \n The directory for the file is the first writable directory in \n the catalog search path. The unique file name is derived from\n the code fragment. If, module_dir is specified, it is used\n to replace 'MODULE' in the search path.\n \"\"\"\n if module_dir is not None:\n self.set_module_directory(module_dir)\n try:\n d = self.get_writable_dir()\n finally:\n if module_dir is not None:\n self.clear_module_directory()\n return unique_file(d,code)\n\n def path_key(self,code):\n \"\"\" Return key for path information for functions associated with code.\n \"\"\"\n return '__path__' + code\n \n def configure_path(self,cat,code):\n \"\"\" Add the python path for the given code to the sys.path\n \n unconfigure_path() should be called as soon as possible after\n imports associated with code are finished so that sys.path \n is restored to normal.\n \"\"\"\n try:\n paths = cat[self.path_key(code)]\n self.paths_added = len(paths)\n sys.path = paths + sys.path\n except:\n self.paths_added = 0 \n \n def unconfigure_path(self):\n \"\"\" Restores sys.path to normal after calls to configure_path()\n \n Remove the previously added paths from sys.path\n \"\"\"\n sys.path = sys.path[self.paths_added:]\n self.paths_added = 0\n\n def get_cataloged_functions(self,code):\n \"\"\" Load all functions associated with code from catalog search path.\n \n Sometimes there can be trouble loading a function listed in a\n catalog file because the actual module that holds the function \n has been moved or deleted. When this happens, that catalog file\n is \"repaired\", meaning the entire entry for this function is \n removed from the file. This only affects the catalog file that\n has problems -- not the others in the search path.\n \n The \"repair\" behavior may not be needed, but I'll keep it for now.\n \"\"\"\n mode = 'r'\n cat = None\n function_list = []\n for path in self.build_search_order():\n cat = get_catalog(path,mode)\n if cat is not None and cat.has_key(code):\n # set up the python path so that modules for this\n # function can be loaded.\n self.configure_path(cat,code)\n try: \n function_list += cat[code]\n except: #SystemError and ImportError so far seen \n # problems loading a function from the catalog. Try to\n # repair the cause.\n cat.close()\n self.repair_catalog(path,code)\n self.unconfigure_path() \n return function_list\n\n\n def repair_catalog(self,catalog_path,code):\n \"\"\" Remove entry for code from catalog_path\n \n Occasionally catalog entries could get corrupted. An example\n would be when a module that had functions in the catalog was\n deleted or moved on the disk. The best current repair method is \n just to trash the entire catalog entry for this piece of code. \n This may loose function entries that are valid, but thats life.\n \n catalog_path must be writable for repair. If it isn't, the\n function exists with a warning. \n \"\"\"\n writable_cat = None\n if not os.path.exists(catalog_path):\n return\n try:\n writable_cat = get_catalog(catalog_path,'w')\n except:\n print 'warning: unable to repair catalog entry\\n %s\\n in\\n %s' % \\\n (code,catalog_path)\n return \n if writable_cat.has_key(code):\n print 'repairing catalog by removing key'\n del writable_cat[code]\n \n # it is possible that the path key doesn't exist (if the function registered\n # was a built-in function), so we have to check if the path exists before\n # arbitrarily deleting it.\n path_key = self.path_key(code) \n if writable_cat.has_key(path_key):\n del writable_cat[path_key] \n \n def get_functions_fast(self,code):\n \"\"\" Return list of functions for code from the cache.\n \n Return an empty list if the code entry is not found.\n \"\"\"\n return self.cache.get(code,[])\n \n def get_functions(self,code,module_dir=None):\n \"\"\" Return the list of functions associated with this code fragment.\n \n The cache is first searched for the function. If an entry\n in the cache is not found, then catalog files on disk are \n searched for the entry. This is slooooow, but only happens\n once per code object. All the functions found in catalog files\n on a cache miss are loaded into the cache to speed up future calls.\n The search order is as follows:\n \n 1. user specified path (from catalog initialization)\n 2. directories from the PYTHONCOMPILED environment variable\n 3. The temporary directory on your platform.\n\n The path specified by module_dir will replace the 'MODULE' \n place holder in the catalog search path. See build_search_order()\n for more info on the search path. \n \"\"\" \n # Fast!! try cache first.\n if self.cache.has_key(code):\n return self.cache[code]\n \n # 2. Slow!! read previously compiled functions from disk.\n try:\n self.set_module_directory(module_dir)\n function_list = self.get_cataloged_functions(code)\n # put function_list in cache to save future lookups.\n if function_list:\n self.cache[code] = function_list\n # return function_list, empty or otherwise.\n finally:\n self.clear_module_directory()\n return function_list\n\n def add_function(self,code,function,module_dir=None):\n \"\"\" Adds a function to the catalog.\n \n The function is added to the cache as well as the first\n writable file catalog found in the search path. If no\n code entry exists in the cache, the on disk catalogs\n are loaded into the cache and function is added to the\n beginning of the function list.\n \n The path specified by module_dir will replace the 'MODULE' \n place holder in the catalog search path. See build_search_order()\n for more info on the search path. \n \"\"\" \n\n # 1. put it in the cache.\n if self.cache.has_key(code):\n if function not in self.cache[code]:\n self.cache[code].insert(0,function)\n else:\n # if it is in the cache, then it is also\n # been persisted \n return\n else: \n # Load functions and put this one up front\n self.cache[code] = self.get_functions(code) \n self.fast_cache(code,function)\n # 2. Store the function entry to disk. \n try:\n self.set_module_directory(module_dir)\n self.add_function_persistent(code,function)\n finally:\n self.clear_module_directory()\n \n def add_function_persistent(self,code,function):\n \"\"\" Store the code->function relationship to disk.\n \n Two pieces of information are needed for loading functions\n from disk -- the function pickle (which conveniently stores\n the module name, etc.) and the path to its module's directory.\n The latter is needed so that the function can be loaded no\n matter what the user's Python path is.\n \"\"\" \n # add function to data in first writable catalog\n mode = 'c' # create if doesn't exist, otherwise, use existing\n cat_dir = self.get_writable_dir()\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n cat_dir = default_dir()\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n cat_dir = default_dir() \n cat_file = catalog_path(cat_dir)\n print 'problems with default catalog -- removing'\n import glob\n files = glob.glob(cat_file+'*')\n for f in files:\n os.remove(f)\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n raise ValueError, 'Failed to access a catalog for storing functions' \n # Prabhu was getting some corrupt catalog errors. I'll put a try/except\n # to protect against this, but should really try and track down the issue.\n function_list = [function]\n try:\n function_list = function_list + cat.get(code,[])\n except pickle.UnpicklingError:\n pass\n cat[code] = function_list\n # now add needed path information for loading function\n module = getmodule(function)\n try:\n # built in modules don't have the __file__ extension, so this\n # will fail. Just pass in this case since path additions aren't\n # needed for built-in modules.\n mod_path,f=os.path.split(os.path.abspath(module.__file__))\n pkey = self.path_key(code)\n cat[pkey] = [mod_path] + cat.get(pkey,[])\n except:\n pass\n\n def fast_cache(self,code,function):\n \"\"\" Move function to the front of the cache entry for code\n \n If future calls to the function have the same type signature,\n this will speed up access significantly because the first\n function call is correct.\n \n Note: The cache added to the inline_tools module is significantly\n faster than always calling get_functions, so this isn't\n as necessary as it used to be. Still, it's probably worth\n doing. \n \"\"\"\n try:\n if self.cache[code][0] == function:\n return\n except: # KeyError, IndexError \n pass\n try:\n self.cache[code].remove(function)\n except ValueError:\n pass\n # put new function at the beginning of the list to search.\n self.cache[code].insert(0,function)\n \ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "methods": [ { "name": "getmodule", "long_name": "getmodule( object )", "filename": "catalog.py", "nloc": 13, "complexity": 7, "token_count": 79, "parameters": [ "object" ], "start_line": 53, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "expr_to_filename", "long_name": "expr_to_filename( expr )", "filename": "catalog.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "expr" ], "start_line": 80, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "unique_file", "long_name": "unique_file( d , expr )", "filename": "catalog.py", "nloc": 13, "complexity": 8, "token_count": 89, "parameters": [ "d", "expr" ], "start_line": 91, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "create_dir", "long_name": "create_dir( p )", "filename": "catalog.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "p" ], "start_line": 115, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "is_writable", "long_name": "is_writable( dir )", "filename": "catalog.py", "nloc": 8, "complexity": 2, "token_count": 38, "parameters": [ "dir" ], "start_line": 129, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "whoami", "long_name": "whoami( )", "filename": "catalog.py", "nloc": 2, "complexity": 3, "token_count": 25, "parameters": [], "start_line": 138, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "default_dir", "long_name": "default_dir( )", "filename": "catalog.py", "nloc": 17, "complexity": 5, "token_count": 141, "parameters": [], "start_line": 142, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "intermediate_dir", "long_name": "intermediate_dir( )", "filename": "catalog.py", "nloc": 6, "complexity": 2, "token_count": 58, "parameters": [], "start_line": 176, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "default_temp_dir", "long_name": "default_temp_dir( )", "filename": "catalog.py", "nloc": 9, "complexity": 3, "token_count": 56, "parameters": [], "start_line": 186, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "os_dependent_catalog_name", "long_name": "os_dependent_catalog_name( )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 197, "end_line": 209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "catalog_path", "long_name": "catalog_path( module_path )", "filename": "catalog.py", "nloc": 12, "complexity": 3, "token_count": 105, "parameters": [ "module_path" ], "start_line": 211, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "get_catalog", "long_name": "get_catalog( module_path , mode = 'r' )", "filename": "catalog.py", "nloc": 13, "complexity": 6, "token_count": 80, "parameters": [ "module_path", "mode" ], "start_line": 238, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , user_path_list = None )", "filename": "catalog.py", "nloc": 10, "complexity": 3, "token_count": 60, "parameters": [ "self", "user_path_list" ], "start_line": 294, "end_line": 309, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "set_module_directory", "long_name": "set_module_directory( self , module_dir )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "module_dir" ], "start_line": 311, "end_line": 317, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_module_directory", "long_name": "get_module_directory( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 318, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "clear_module_directory", "long_name": "clear_module_directory( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 322, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_environ_path", "long_name": "get_environ_path( self )", "filename": "catalog.py", "nloc": 9, "complexity": 3, "token_count": 55, "parameters": [ "self" ], "start_line": 327, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "build_search_order", "long_name": "build_search_order( self )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 62, "parameters": [ "self" ], "start_line": 343, "end_line": 365, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_catalog_files", "long_name": "get_catalog_files( self )", "filename": "catalog.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 367, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_existing_files", "long_name": "get_existing_files( self )", "filename": "catalog.py", "nloc": 7, "complexity": 3, "token_count": 48, "parameters": [ "self" ], "start_line": 378, "end_line": 391, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "get_writable_file.file_test", "long_name": "get_writable_file.file_test( x )", "filename": "catalog.py", "nloc": 4, "complexity": 3, "token_count": 43, "parameters": [ "x" ], "start_line": 405, "end_line": 408, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 2 }, { "name": "get_writable_file", "long_name": "get_writable_file( self , existing_only = 0 )", "filename": "catalog.py", "nloc": 12, "complexity": 3, "token_count": 55, "parameters": [ "self", "existing_only" ], "start_line": 393, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "get_writable_dir", "long_name": "get_writable_dir( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 416, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "unique_module_name", "long_name": "unique_module_name( self , code , module_dir = None )", "filename": "catalog.py", "nloc": 9, "complexity": 4, "token_count": 53, "parameters": [ "self", "code", "module_dir" ], "start_line": 423, "end_line": 438, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "path_key", "long_name": "path_key( self , code )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "code" ], "start_line": 440, "end_line": 443, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "configure_path", "long_name": "configure_path( self , cat , code )", "filename": "catalog.py", "nloc": 7, "complexity": 2, "token_count": 47, "parameters": [ "self", "cat", "code" ], "start_line": 445, "end_line": 457, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "unconfigure_path", "long_name": "unconfigure_path( self )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 459, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_cataloged_functions", "long_name": "get_cataloged_functions( self , code )", "filename": "catalog.py", "nloc": 15, "complexity": 5, "token_count": 86, "parameters": [ "self", "code" ], "start_line": 467, "end_line": 496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 1 }, { "name": "repair_catalog", "long_name": "repair_catalog( self , catalog_path , code )", "filename": "catalog.py", "nloc": 16, "complexity": 5, "token_count": 83, "parameters": [ "self", "catalog_path", "code" ], "start_line": 499, "end_line": 529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "get_functions_fast", "long_name": "get_functions_fast( self , code )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "code" ], "start_line": 531, "end_line": 536, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_functions", "long_name": "get_functions( self , code , module_dir = None )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 65, "parameters": [ "self", "code", "module_dir" ], "start_line": 538, "end_line": 570, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 1 }, { "name": "add_function", "long_name": "add_function( self , code , function , module_dir = None )", "filename": "catalog.py", "nloc": 14, "complexity": 4, "token_count": 97, "parameters": [ "self", "code", "function", "module_dir" ], "start_line": 572, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "add_function_persistent", "long_name": "add_function_persistent( self , code , function )", "filename": "catalog.py", "nloc": 31, "complexity": 7, "token_count": 194, "parameters": [ "self", "code", "function" ], "start_line": 605, "end_line": 650, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "fast_cache", "long_name": "fast_cache( self , code , function )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 59, "parameters": [ "self", "code", "function" ], "start_line": 652, "end_line": 674, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 676, "end_line": 678, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 680, "end_line": 682, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "getmodule", "long_name": "getmodule( object )", "filename": "catalog.py", "nloc": 13, "complexity": 7, "token_count": 79, "parameters": [ "object" ], "start_line": 52, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "expr_to_filename", "long_name": "expr_to_filename( expr )", "filename": "catalog.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "expr" ], "start_line": 79, "end_line": 88, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "unique_file", "long_name": "unique_file( d , expr )", "filename": "catalog.py", "nloc": 13, "complexity": 8, "token_count": 89, "parameters": [ "d", "expr" ], "start_line": 90, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "default_dir", "long_name": "default_dir( )", "filename": "catalog.py", "nloc": 18, "complexity": 5, "token_count": 145, "parameters": [], "start_line": 114, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 }, { "name": "intermediate_dir", "long_name": "intermediate_dir( )", "filename": "catalog.py", "nloc": 7, "complexity": 2, "token_count": 56, "parameters": [], "start_line": 149, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "default_temp_dir", "long_name": "default_temp_dir( )", "filename": "catalog.py", "nloc": 9, "complexity": 3, "token_count": 64, "parameters": [], "start_line": 160, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "os_dependent_catalog_name", "long_name": "os_dependent_catalog_name( )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 171, "end_line": 183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "catalog_path", "long_name": "catalog_path( module_path )", "filename": "catalog.py", "nloc": 12, "complexity": 3, "token_count": 105, "parameters": [ "module_path" ], "start_line": 185, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "get_catalog", "long_name": "get_catalog( module_path , mode = 'r' )", "filename": "catalog.py", "nloc": 13, "complexity": 6, "token_count": 80, "parameters": [ "module_path", "mode" ], "start_line": 212, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , user_path_list = None )", "filename": "catalog.py", "nloc": 10, "complexity": 3, "token_count": 60, "parameters": [ "self", "user_path_list" ], "start_line": 268, "end_line": 283, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "set_module_directory", "long_name": "set_module_directory( self , module_dir )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "module_dir" ], "start_line": 285, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_module_directory", "long_name": "get_module_directory( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 292, "end_line": 295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "clear_module_directory", "long_name": "clear_module_directory( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 296, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_environ_path", "long_name": "get_environ_path( self )", "filename": "catalog.py", "nloc": 9, "complexity": 3, "token_count": 55, "parameters": [ "self" ], "start_line": 301, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "build_search_order", "long_name": "build_search_order( self )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 62, "parameters": [ "self" ], "start_line": 317, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_catalog_files", "long_name": "get_catalog_files( self )", "filename": "catalog.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 341, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_existing_files", "long_name": "get_existing_files( self )", "filename": "catalog.py", "nloc": 7, "complexity": 3, "token_count": 48, "parameters": [ "self" ], "start_line": 352, "end_line": 365, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "get_writable_file.file_test", "long_name": "get_writable_file.file_test( x )", "filename": "catalog.py", "nloc": 4, "complexity": 3, "token_count": 43, "parameters": [ "x" ], "start_line": 379, "end_line": 382, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 2 }, { "name": "get_writable_file", "long_name": "get_writable_file( self , existing_only = 0 )", "filename": "catalog.py", "nloc": 12, "complexity": 3, "token_count": 55, "parameters": [ "self", "existing_only" ], "start_line": 367, "end_line": 388, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "get_writable_dir", "long_name": "get_writable_dir( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 390, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "unique_module_name", "long_name": "unique_module_name( self , code , module_dir = None )", "filename": "catalog.py", "nloc": 9, "complexity": 4, "token_count": 53, "parameters": [ "self", "code", "module_dir" ], "start_line": 397, "end_line": 412, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "path_key", "long_name": "path_key( self , code )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "code" ], "start_line": 414, "end_line": 417, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "configure_path", "long_name": "configure_path( self , cat , code )", "filename": "catalog.py", "nloc": 7, "complexity": 2, "token_count": 47, "parameters": [ "self", "cat", "code" ], "start_line": 419, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "unconfigure_path", "long_name": "unconfigure_path( self )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 433, "end_line": 439, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_cataloged_functions", "long_name": "get_cataloged_functions( self , code )", "filename": "catalog.py", "nloc": 15, "complexity": 5, "token_count": 86, "parameters": [ "self", "code" ], "start_line": 441, "end_line": 470, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 1 }, { "name": "repair_catalog", "long_name": "repair_catalog( self , catalog_path , code )", "filename": "catalog.py", "nloc": 16, "complexity": 5, "token_count": 83, "parameters": [ "self", "catalog_path", "code" ], "start_line": 473, "end_line": 503, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "get_functions_fast", "long_name": "get_functions_fast( self , code )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "code" ], "start_line": 505, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_functions", "long_name": "get_functions( self , code , module_dir = None )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 65, "parameters": [ "self", "code", "module_dir" ], "start_line": 512, "end_line": 544, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 1 }, { "name": "add_function", "long_name": "add_function( self , code , function , module_dir = None )", "filename": "catalog.py", "nloc": 14, "complexity": 4, "token_count": 97, "parameters": [ "self", "code", "function", "module_dir" ], "start_line": 546, "end_line": 577, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "add_function_persistent", "long_name": "add_function_persistent( self , code , function )", "filename": "catalog.py", "nloc": 31, "complexity": 7, "token_count": 194, "parameters": [ "self", "code", "function" ], "start_line": 579, "end_line": 624, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "fast_cache", "long_name": "fast_cache( self , code , function )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 59, "parameters": [ "self", "code", "function" ], "start_line": 626, "end_line": 648, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 650, "end_line": 652, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 654, "end_line": 656, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "whoami", "long_name": "whoami( )", "filename": "catalog.py", "nloc": 2, "complexity": 3, "token_count": 25, "parameters": [], "start_line": 138, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "intermediate_dir", "long_name": "intermediate_dir( )", "filename": "catalog.py", "nloc": 6, "complexity": 2, "token_count": 58, "parameters": [], "start_line": 176, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "default_temp_dir", "long_name": "default_temp_dir( )", "filename": "catalog.py", "nloc": 9, "complexity": 3, "token_count": 56, "parameters": [], "start_line": 186, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "is_writable", "long_name": "is_writable( dir )", "filename": "catalog.py", "nloc": 8, "complexity": 2, "token_count": 38, "parameters": [ "dir" ], "start_line": 129, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "create_dir", "long_name": "create_dir( p )", "filename": "catalog.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "p" ], "start_line": 115, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_dir", "long_name": "default_dir( )", "filename": "catalog.py", "nloc": 17, "complexity": 5, "token_count": 141, "parameters": [], "start_line": 142, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 } ], "nloc": 368, "complexity": 108, "token_count": 2034, "diff_parsed": { "added": [ "import tempfile", "", "def create_dir(p):", " \"\"\" Create a directory and any necessary intermediate directories.\"\"\"", " if not os.path.exists(p):", " try:", " os.mkdir(p)", " except OSError:", " # perhaps one or more intermediate path components don't exist", " # try to create them", " base,dir = os.path.split(p)", " create_dir(base)", " # don't enclose this one in try/except - we want the user to", " # get failure info", " os.mkdir(p)", "", "def is_writable(dir):", " dummy = os.path.join(dir, \"dummy\")", " try:", " open(dummy, 'w')", " except IOError:", " return 0", " os.unlink(dummy)", " return 1", "", "def whoami():", " \"\"\"return a string identifying the user.\"\"\"", " return os.environ.get(\"USER\") or os.environ.get(\"USERNAME\") or \"unknown\"", "", " path = os.path.join(tempfile.gettempdir(),\"%s\"%whoami(),python_name)", " create_dir(path)", " if not is_writable(path):", " print 'default:', path", " path = os.path.join(tempfile.gettempdir(),\"%s\"%whoami(),python_name)", " create_dir(path)", " create_dir(path)", " if not is_writable(path):", " print 'default:', path" ], "deleted": [ "", " import tempfile", " path = os.path.join(tempfile.gettempdir(),python_name)", " os.mkdir(path)", " if not os.access(path,os.W_OK):", " print 'defualt:', path", " import tempfile", " path = os.path.join(tempfile.gettempdir(),python_name)", " os.mkdir(path)", " os.mkdir(path)", " if not os.access(path,os.W_OK):", " print 'defualt:', path" ] } } ] }, { "hash": "51b6df86d02200d48bc84349be34629e00e48784", "msg": "changes to get SciPy to build with Sun's Forte Fortran compilers. I\nsuspect there may be more changes in the near future. The\nsun_fortran_compiler class seems a bit too complex to me. In fact, it\nseems like it declares info for two or four compilers. Should it be\nsplit into two or more classes?", "author": { "name": "skip", "email": "skip@localhost" }, "committer": { "name": "skip", "email": "skip@localhost" }, "author_date": "2002-09-17T01:25:57+00:00", "author_timezone": 0, "committer_date": "2002-09-17T01:25:57+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "ef494feebe6224fb56ba36961b60d609f74551ee" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 12, "insertions": 17, "lines": 29, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/command/build_flib.py", "new_path": "scipy_distutils/command/build_flib.py", "filename": "build_flib.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -587,7 +587,7 @@ class sun_fortran_compiler(fortran_compiler_base):\n \n vendor = 'Sun'\n #ver_match = r'f77: (?P[^\\s*,]*)'\n- ver_match = r'f90: Sun (?P[^\\s*,]*)'\n+ ver_match = r'f90: (Forte Developer 7 Fortran 95|Sun) (?P[^\\s*,]*)'\n \n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n@@ -598,23 +598,23 @@ def __init__(self, fc=None, f90c=None, verbose=0):\n f90c = 'f90'\n \n self.f77_compiler = fc # not tested\n- self.f77_switches = ' -pic '\n- self.f77_opt = ' -fast -dalign '\n+ self.f77_switches = ' -pic'\n+ self.f77_opt = ' -fast -dalign -xtarget=generic -R/opt/SUNWspro/lib'\n \n self.f90_compiler = f90c\n self.f90_switches = ' -fixed ' # ??? why fixed?\n- self.f90_opt = ' -fast -dalign '\n+ self.f90_opt = ' -fast -dalign -xtarget=generic -R/opt/SUNWspro/lib'\n \n self.ver_cmd = self.f90_compiler + ' -V'\n \n #self.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\n- self.libraries = ['fsu', 'F77', 'M77', 'sunmath', 'm']\n+ self.libraries = ['fsu', 'F77', 'M77', 'sunmath',\n+ 'mvec', 'f77compat', 'm']\n \n #threaded\n #self.libraries = ['f90', 'F77_mt', 'sunmath_mt', 'm', 'thread']\n #self.libraries = []\n self.library_dirs = self.find_lib_dir()\n- #print 'sun:',self.library_dirs\n \n def build_module_switch(self,module_dirs):\n res = ''\n@@ -624,7 +624,7 @@ def build_module_switch(self,module_dirs):\n return res\n \n def find_lib_dir(self):\n- library_dirs = []\n+ library_dirs = [\"/opt/SUNWspro/prod/lib\"]\n lib_match = r'### f90: Note: LD_RUN_PATH\\s*= '\\\n '(?P[^\\s.]*).*'\n cmd = self.f90_compiler + ' -dryrun dummy.f'\n@@ -632,6 +632,8 @@ def find_lib_dir(self):\n exit_status, output = run_command(cmd)\n if not exit_status:\n libs = re.findall(lib_match,output)\n+ if libs[0] == \"(null)\":\n+ del libs[0]\n if libs:\n library_dirs = string.split(libs[0],':')\n self.get_version() # force version calculation\n@@ -639,10 +641,15 @@ def find_lib_dir(self):\n library_dirs.append(os.path.join(compiler_home,\n self.version,'lib'))\n return library_dirs\n+\n def get_runtime_library_dirs(self):\n return self.find_lib_dir()\n+\n def get_extra_link_args(self):\n- return ['-mimpure-text']\n+ return [\"-Bdynamic\", \"-G\"]\n+\n+ def get_linker_so(self):\n+ return [self.f77_compiler]\n \n \n class mips_fortran_compiler(fortran_compiler_base):\n@@ -1125,16 +1132,14 @@ def get_fortran_files(files):\n return match_extension(files,'f90|f95|for|f77|ftn|f')\n \n def find_fortran_compiler(vendor=None, fc=None, f90c=None, verbose=0):\n- fcompiler = None\n for compiler_class in all_compilers:\n if vendor is not None and vendor != compiler_class.vendor:\n continue\n #print compiler_class\n compiler = compiler_class(fc,f90c,verbose = verbose)\n if compiler.is_available():\n- fcompiler = compiler\n- break\n- return fcompiler\n+ return compiler\n+ return None\n \n all_compilers = [absoft_fortran_compiler,\n mips_fortran_compiler,\n", "added_lines": 17, "deleted_lines": 12, "source_code": "\"\"\" Implements the build_flib command which should go into Distutils\n at some point.\n \n Note:\n Right now, we're dynamically linking to the Fortran libraries on \n some platforms (Sun for sure). This is fine for local installations\n but a bad thing for redistribution because these libraries won't\n live on any machine that doesn't have a fortran compiler installed.\n It is pretty hard (impossible?) to get gcc to pass the right compiler\n flags on Sun to get the linker to use static libs for the fortran\n stuff. Investigate further...\n\nBugs:\n *** Options -e and -x have no effect when used with --help-compiler\n options. E.g. \n ./setup.py build_flib --help-compiler -e g77-3.0\n finds g77-2.95.\n How to extract these options inside the show_compilers function?\n *** compiler.is_available() method may not work correctly on nt\n because of lack of knowledge how to get exit status in\n run_command function. However, it may give reasonable results\n based on a version string.\n *** Some vendors provide different compilers for F77 and F90\n compilations. Currently, checking the availability of these\n compilers is based on only checking the availability of the\n corresponding F77 compiler. If it exists, then F90 is assumed\n to exist also.\n *** F compiler from Fortran Compiler is _not_ supported, though it\n is defined below. The reasons is that this F95 compiler is\n incomplete: it does not support external procedures\n that are needed to facilitate calling F90 module routines\n from C and subsequently from Python. See also\n http://cens.ioc.ee/pipermail/f2py-users/2002-May/000265.html\n\nOpen issues:\n *** User-defined compiler flags. Do we need --fflags?\n\nFortran compilers (as to be used with --fcompiler= option):\n Absoft\n Sun\n SGI\n Intel\n Itanium\n NAG\n Compaq\n Digital\n Gnu\n VAST\n F [unsupported]\n\"\"\"\n\nimport distutils\nimport distutils.dep_util, distutils.dir_util\nimport os,sys,string\nimport commands,re\nfrom types import *\nfrom distutils.ccompiler import CCompiler,gen_preprocess_options\nfrom distutils.command.build_clib import build_clib\nfrom distutils.errors import *\nfrom scipy_distutils.misc_util import red_text,green_text,yellow_text,\\\n cyan_text\n\nclass FortranCompilerError (CCompilerError):\n \"\"\"Some compile/link operation failed.\"\"\"\nclass FortranCompileError (FortranCompilerError):\n \"\"\"Failure to compile one or more Fortran source files.\"\"\"\nclass FortranBuildError (FortranCompilerError):\n \"\"\"Failure to build Fortran library.\"\"\"\n\nif os.name == 'nt':\n def run_command(command):\n \"\"\" not sure how to get exit status on nt. \"\"\"\n in_pipe,out_pipe = os.popen4(command)\n in_pipe.close()\n text = out_pipe.read()\n return 0, text\nelse:\n run_command = commands.getstatusoutput\n\ndef show_compilers():\n for compiler_class in all_compilers:\n compiler = compiler_class()\n if compiler.is_available():\n print cyan_text(compiler)\n\nclass build_flib (build_clib):\n\n description = \"build f77/f90 libraries used by Python extensions\"\n\n user_options = [\n ('build-flib', 'b',\n \"directory to build f77/f90 libraries to\"),\n ('build-temp', 't',\n \"directory to put temporary build by-products\"),\n ('debug', 'g',\n \"compile with debugging information\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ('fcompiler=', 'c',\n \"specify the compiler type\"),\n ('fcompiler-exec=', 'e',\n \"specify the path to F77 compiler\"),\n ('f90compiler-exec=', 'x',\n \"specify the path to F90 compiler\"),\n ]\n\n boolean_options = ['debug', 'force']\n\n help_options = [\n ('help-compiler', None,\n \"list available compilers\", show_compilers),\n ]\n\n def initialize_options (self):\n\n self.build_flib = None\n self.build_temp = None\n\n self.fortran_libraries = None\n self.define = None\n self.undef = None\n self.debug = None\n self.force = 0\n self.fcompiler = None\n self.fcompiler_exec = None\n self.f90compiler_exec = None\n\n # initialize_options()\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_flib'),\n ('build_temp', 'build_temp'),\n ('debug', 'debug'),\n ('force', 'force'))\n\n self.announce('running find_fortran_compiler')\n fc = find_fortran_compiler(self.fcompiler,\n self.fcompiler_exec,\n self.f90compiler_exec,\n verbose = self.verbose)\n if not fc:\n raise DistutilsOptionError, 'Fortran compiler not available: %s'\\\n % (self.fcompiler)\n else:\n self.announce('using '+cyan_text('%s Fortran compiler' % fc))\n self.fcompiler = fc\n if self.has_f_libraries():\n self.fortran_libraries = self.distribution.fortran_libraries\n self.check_library_list(self.fortran_libraries)\n \n # finalize_options()\n\n def has_f_libraries(self):\n return self.distribution.fortran_libraries \\\n and len(self.distribution.fortran_libraries) > 0\n\n def run (self):\n if not self.has_f_libraries():\n return\n self.build_libraries(self.fortran_libraries)\n\n # run ()\n\n def has_f_library(self,name):\n if self.has_f_libraries():\n # If self.fortran_libraries is None at this point\n # then it means that build_flib was called before\n # build. Always call build before build_flib.\n for (lib_name, build_info) in self.fortran_libraries:\n if lib_name == name:\n return 1\n \n def get_library_names(self, name=None):\n if not self.has_f_libraries():\n return None\n\n lib_names = []\n\n if name is None:\n for (lib_name, build_info) in self.fortran_libraries:\n lib_names.append(lib_name)\n\n if self.fcompiler is not None:\n lib_names.extend(self.fcompiler.get_libraries())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n for n in build_info.get('libraries',[]):\n lib_names.append(n)\n #XXX: how to catch recursive calls here?\n lib_names.extend(self.get_library_names(n))\n break\n return lib_names\n\n def get_fcompiler_library_names(self):\n #if not self.has_f_libraries():\n # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_libraries()\n return []\n\n def get_fcompiler_library_dirs(self):\n #if not self.has_f_libraries():\n # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_library_dirs()\n return []\n\n # get_library_names ()\n\n def get_library_dirs(self, name=None):\n if not self.has_f_libraries():\n return []\n\n lib_dirs = [] \n\n if name is None:\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_library_dirs())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n lib_dirs.extend(build_info.get('library_dirs',[]))\n for n in build_info.get('libraries',[]):\n lib_dirs.extend(self.get_library_dirs(n))\n break\n\n return lib_dirs\n\n # get_library_dirs ()\n\n def get_runtime_library_dirs(self):\n #if not self.has_f_libraries():\n # return []\n\n lib_dirs = []\n\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_runtime_library_dirs())\n \n return lib_dirs\n\n # get_library_dirs ()\n\n def get_source_files (self):\n if not self.has_f_libraries():\n return []\n\n self.check_library_list(self.fortran_libraries)\n filenames = []\n\n # Gets source files specified \n for ext in self.fortran_libraries:\n filenames.extend(ext[1]['sources'])\n\n return filenames \n \n def build_libraries (self, fortran_libraries):\n \n fcompiler = self.fcompiler\n \n for (lib_name, build_info) in fortran_libraries:\n self.announce(\" building '%s' library\" % lib_name)\n\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'fortran_libraries' option (library '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % lib_name\n sources = list(sources)\n module_dirs = build_info.get('module_dirs')\n module_files = build_info.get('module_files')\n\n\n include_dirs = build_info.get('include_dirs')\n\n if include_dirs:\n fcompiler.set_include_dirs(include_dirs)\n for n,v in build_info.get('define_macros') or []:\n fcompiler.define_macro(n,v)\n for n in build_info.get('undef_macros') or []:\n fcompiler.undefine_macro(n)\n\n if module_files:\n fcompiler.build_library(lib_name, module_files,\n temp_dir=self.build_temp)\n \n fcompiler.build_library(lib_name, sources,\n module_dirs, temp_dir=self.build_temp)\n\n # for loop\n\n # build_libraries ()\n\nclass fortran_compiler_base(CCompiler):\n\n vendor = None\n ver_match = None\n\n compiler_type = 'fortran'\n executables = {}\n\n compile_switch = ' -c '\n object_switch = ' -o '\n lib_prefix = 'lib'\n lib_suffix = '.a'\n lib_ar = 'ar -cur '\n lib_ranlib = 'ranlib '\n\n def __init__(self,verbose=0,dry_run=0,force=0):\n # Default initialization. Constructors of derived classes MUST\n # call this function.\n CCompiler.__init__(self,verbose,dry_run,force)\n\n self.version = None\n \n self.f77_switches = ''\n self.f77_opt = ''\n self.f77_debug = ''\n \n self.f90_switches = ''\n self.f90_opt = ''\n self.f90_debug = ''\n \n #self.libraries = []\n #self.library_dirs = []\n\n if self.vendor is None:\n raise DistutilsInternalError,\\\n '%s must define vendor attribute'%(self.__class__)\n if self.ver_match is None:\n raise DistutilsInternalError,\\\n '%s must define ver_match attribute'%(self.__class__)\n\n def to_object(self,\n dirty_files,\n module_dirs=None,\n temp_dir=''):\n files = string.join(dirty_files)\n f90_files = get_f90_files(dirty_files)\n f77_files = get_f77_files(dirty_files)\n if f90_files != []:\n obj1 = self.f90_compile(f90_files,module_dirs,temp_dir = temp_dir)\n else:\n obj1 = []\n if f77_files != []:\n obj2 = self.f77_compile(f77_files, temp_dir = temp_dir)\n else:\n obj2 = []\n return obj1 + obj2\n\n def source_to_object_names(self,source_files, temp_dir=''):\n file_list = map(lambda x: os.path.basename(x),source_files)\n file_base_ext = map(lambda x: os.path.splitext(x),file_list)\n object_list = map(lambda x: x[0] +'.o',file_base_ext)\n object_files = map(lambda x,td=temp_dir: os.path.join(td,x),object_list)\n return object_files\n \n def source_and_object_pairs(self,source_files, temp_dir=''):\n object_files = self.source_to_object_names(source_files,temp_dir)\n file_pairs = zip(source_files,object_files)\n return file_pairs\n \n def f_compile(self,compiler,switches, source_files,\n module_dirs=None, temp_dir=''):\n\n pp_opts = gen_preprocess_options(self.macros,self.include_dirs)\n\n switches = switches + ' ' + string.join(pp_opts,' ')\n\n module_switch = self.build_module_switch(module_dirs)\n file_pairs = self.source_and_object_pairs(source_files,temp_dir)\n object_files = []\n for source,object in file_pairs:\n if distutils.dep_util.newer(source,object):\n cmd = compiler + ' ' + switches + ' '+\\\n module_switch + \\\n self.compile_switch + source + \\\n self.object_switch + object\n self.announce(yellow_text(cmd))\n failure = os.system(cmd)\n if failure:\n raise FortranCompileError,\\\n 'failure during compile (exit status = %s)' % failure\n object_files.append(object)\n return object_files\n #return all object files to make sure everything is archived \n #return map(lambda x: x[1], file_pairs)\n\n def f90_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f90_switches, self.f90_opt))\n return self.f_compile(self.f90_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n def f77_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f77_switches, self.f77_opt))\n return self.f_compile(self.f77_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n def build_module_switch(self, module_dirs):\n return ''\n\n def create_static_lib(self, object_files, library_name,\n output_dir='', debug=None, skip_ranlib=0):\n lib_file = os.path.join(output_dir,\n self.lib_prefix+library_name+self.lib_suffix)\n objects = string.join(object_files)\n if objects:\n cmd = '%s%s %s' % (self.lib_ar,lib_file,objects)\n self.announce(yellow_text(cmd))\n failure = os.system(cmd)\n if failure:\n raise FortranBuildError,\\\n 'failure during build (exit status = %s)'%failure \n if self.lib_ranlib and not skip_ranlib:\n # Digital,MIPSPro compilers do not have ranlib.\n cmd = '%s %s' %(self.lib_ranlib,lib_file)\n self.announce(yellow_text(cmd))\n failure = os.system(cmd)\n if failure:\n raise FortranBuildError,\\\n 'failure during build (exit status = %s)'%failure \n\n def build_library(self,library_name,source_list,module_dirs=None,\n temp_dir = ''):\n #make sure the temp directory exists before trying to build files\n import distutils.dir_util\n distutils.dir_util.mkpath(temp_dir)\n\n #this compiles the files\n object_list = self.to_object(source_list,\n module_dirs,\n temp_dir)\n\n # actually we need to use all the object file names here to\n # make sure the library is always built. It could occur that an\n # object file exists but hasn't been put in the archive. (happens\n # a lot when builds fail once and are restarted).\n object_list = self.source_to_object_names(source_list, temp_dir)\n\n if os.name == 'nt' or sys.platform[:4] == 'irix':\n # I (pearu) had the same problem on irix646 ...\n # I think we can make this \"bunk\" default as skip_ranlib\n # feature speeds things up.\n # XXX:Need to check if Digital compiler works here.\n\n # This is pure bunk...\n # Windows fails for long argument strings on the command line.\n # if objects is real long (> 2048 chars or so on my machine),\n # the command fails (cmd.exe /e:2048 on w2k).\n # for now we'll split linking into to steps which should work for\n objects = object_list[:]\n while objects:\n #obj,objects = objects[:20],objects[20:]\n i = 0\n obj = []\n while i<1900 and objects:\n i = i + len(objects[0]) + 1\n obj.append(objects[0])\n objects = objects[1:]\n self.create_static_lib(obj,library_name,temp_dir,\n skip_ranlib = len(objects))\n else:\n self.create_static_lib(object_list,library_name,temp_dir)\n\n def dummy_fortran_files(self):\n import tempfile \n d = tempfile.gettempdir()\n dummy_name = os.path.join(d,'__dummy.f')\n dummy = open(dummy_name,'w')\n dummy.write(\" subroutine dummy()\\n end\\n\")\n dummy.close()\n return (os.path.join(d,'__dummy.f'),os.path.join(d,'__dummy.o'))\n \n def is_available(self):\n return self.get_version()\n \n def get_version(self):\n \"\"\"Return the compiler version. If compiler is not available,\n return empty string.\"\"\"\n # XXX: Is there compilers that have no version? If yes,\n # this test will fail even if the compiler is available.\n if self.version is not None:\n # Finding version is expensive, so return previously found\n # version string.\n return self.version\n self.version = ''\n # works I think only for unix...\n #if self.verbose:\n self.announce('detecting %s Fortran compiler...'%(self.vendor))\n self.announce(yellow_text(self.ver_cmd))\n exit_status, out_text = run_command(self.ver_cmd)\n out_text2 = out_text.split('\\n')[0]\n if not exit_status:\n self.announce('found %s' %(green_text(out_text2)))\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\n else:\n self.announce('%s: %s' % (exit_status,red_text(out_text2)))\n return self.version\n\n def get_libraries(self):\n return self.libraries\n def get_library_dirs(self):\n return self.library_dirs\n def get_extra_link_args(self):\n return []\n def get_runtime_library_dirs(self):\n return []\n def get_linker_so(self):\n \"\"\"\n If a compiler requires specific linker then return a list\n containing a linker executable name and linker options.\n Otherwise, return None.\n \"\"\"\n\n def __str__(self):\n return \"%s %s\" % (self.vendor, self.get_version())\n\n\nclass absoft_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Absoft'\n ver_match = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n # got rid of -B108 cause it was generating 2 underscores instead\n # of one on the newest version. Now we use -YEXT_SFX=_ to \n # specify the output format\n if os.name == 'nt':\n self.f90_switches = '-f fixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -Q100'\n self.f77_switches = '-N22 -N90 -N110'\n self.f77_opt = '-O -Q100'\n self.libraries = ['fio', 'fmath', 'f90math', 'COMDLG32']\n else:\n self.f90_switches = '-ffixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -B101' \n self.f77_switches = '-N22 -N90 -N110 -B108'\n self.f77_opt = '-O -B101'\n\n self.libraries = ['fio', 'f77math', 'f90math']\n \n try:\n dir = os.environ['ABSOFT'] \n self.library_dirs = [os.path.join(dir,'lib')]\n except KeyError:\n self.library_dirs = []\n\n self.ver_cmd = self.f77_compiler + ' -V -c %s -o %s' % \\\n self.dummy_fortran_files()\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -p' + mod\n return res\n\n def get_extra_link_args(self):\n return []\n # Couldn't get this to link for anything using gcc.\n #dr = \"c:\\\\Absoft62\\\\lib\"\n #libs = ['fio.lib', 'COMDLG32.lib','fmath.lib', 'f90math.lib','libcomdlg32.a' ] \n #libs = map(lambda x,dr=dr:os.path.join(dr,x),libs)\n #return libs\n\n\nclass sun_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Sun'\n #ver_match = r'f77: (?P[^\\s*,]*)'\n ver_match = r'f90: (Forte Developer 7 Fortran 95|Sun) (?P[^\\s*,]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc # not tested\n self.f77_switches = ' -pic'\n self.f77_opt = ' -fast -dalign -xtarget=generic -R/opt/SUNWspro/lib'\n\n self.f90_compiler = f90c\n self.f90_switches = ' -fixed ' # ??? why fixed?\n self.f90_opt = ' -fast -dalign -xtarget=generic -R/opt/SUNWspro/lib'\n\n self.ver_cmd = self.f90_compiler + ' -V'\n\n #self.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\n self.libraries = ['fsu', 'F77', 'M77', 'sunmath',\n 'mvec', 'f77compat', 'm']\n \n #threaded\n #self.libraries = ['f90', 'F77_mt', 'sunmath_mt', 'm', 'thread']\n #self.libraries = []\n self.library_dirs = self.find_lib_dir()\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -M' + mod\n return res\n\n def find_lib_dir(self):\n library_dirs = [\"/opt/SUNWspro/prod/lib\"]\n lib_match = r'### f90: Note: LD_RUN_PATH\\s*= '\\\n '(?P[^\\s.]*).*'\n cmd = self.f90_compiler + ' -dryrun dummy.f'\n self.announce(yellow_text(cmd))\n exit_status, output = run_command(cmd)\n if not exit_status:\n libs = re.findall(lib_match,output)\n if libs[0] == \"(null)\":\n del libs[0]\n if libs:\n library_dirs = string.split(libs[0],':')\n self.get_version() # force version calculation\n compiler_home = os.path.dirname(library_dirs[0])\n library_dirs.append(os.path.join(compiler_home,\n self.version,'lib'))\n return library_dirs\n\n def get_runtime_library_dirs(self):\n return self.find_lib_dir()\n\n def get_extra_link_args(self):\n return [\"-Bdynamic\", \"-G\"]\n\n def get_linker_so(self):\n return [self.f77_compiler]\n\n\nclass mips_fortran_compiler(fortran_compiler_base):\n\n vendor = 'SGI'\n ver_match = r'MIPSpro Compilers: Version (?P[^\\s*,]*)'\n lib_ranlib = '' # XXX: should we use `ar -s' here?\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f77_switches = ' -n32 -KPIC '\n self.f77_opt = ' -O3 '\n\n self.f90_compiler = f90c\n self.f90_switches = ' -n32 -KPIC -fixedform ' # why fixed ???\n self.f90_opt = ' ' \n\n self.ver_cmd = self.f77_compiler + ' -version '\n\n #self.libraries = ['fortran', 'ftn', 'm']\n # -lfortran is redundant with MIPSPro 7.30\n self.libraries = ['ftn', 'm']\n self.library_dirs = self.find_lib_dir()\n\n\n def build_module_switch(self,module_dirs):\n res = ''\n return res \n def find_lib_dir(self):\n library_dirs = []\n return library_dirs\n def get_runtime_library_dirs(self):\n\treturn self.find_lib_dir() \n def get_extra_link_args(self):\n\treturn []\n\nclass hpux_fortran_compiler(fortran_compiler_base):\n\n vendor = 'HP'\n ver_match = r'HP F90 (?P[^\\s*,]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f90'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f77_switches = ' +pic=long '\n self.f77_opt = ' -O3 '\n\n self.f90_compiler = f90c\n self.f90_switches = ' +pic=long '\n self.f90_opt = ' -O3 '\n\n self.ver_cmd = self.f77_compiler + ' +version '\n\n self.libraries = ['m']\n self.library_dirs = []\n\n def get_version(self):\n if self.version is not None:\n return self.version\n self.version = ''\n self.announce(yellow_text(self.ver_cmd))\n exit_status, out_text = run_command(self.ver_cmd)\n if self.verbose:\n out_text = out_text.split('\\n')[0]\n if exit_status in [0,256]:\n # 256 seems to indicate success on HP-UX but keeping\n # also 0. Or does 0 exit status mean something different\n # in this platform?\n self.announce('found: '+green_text(out_text))\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\n else:\n self.announce('%s: %s' % (exit_status,red_text(out_text)))\n return self.version\n\nclass gnu_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Gnu'\n ver_match = r'GNU Fortran (?P[^\\s*]*)'\n gcc_lib_dir = None\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n\n gcc_lib_dir = self.find_lib_directories()\n if gcc_lib_dir and \\\n os.path.isfile(os.path.join(gcc_lib_dir[0],'libg2c-pic.a')):\n g2c = 'g2c-pic'\n else:\n g2c = 'g2c'\n if sys.platform == 'win32':\n self.libraries = ['gcc',g2c]\n self.library_dirs = gcc_lib_dir\n else:\n # On linux g77 does not need lib_directories to be specified.\n self.libraries = [g2c]\n\n switches = ' -Wall -fno-second-underscore '\n\n if os.name != 'nt':\n switches = switches + ' -fPIC '\n\n self.f77_switches = switches\n self.ver_cmd = self.f77_compiler + ' --version '\n\n self.f77_opt = self.get_opt()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 -funroll-loops '\n \n # only check for more optimization if g77 can handle it.\n if self.get_version():\n if self.version >= '0.5.26': # is gcc >= 3.x.x\n if cpu.is_AthlonK6():\n opt = opt + ' -march=k6 '\n elif cpu.is_AthlonK7():\n opt = opt + ' -march=athlon '\n if cpu.is_i686():\n opt = opt + ' -march=i686 '\n elif cpu.is_i586():\n opt = opt + ' -march=i586 '\n elif cpu.is_i486():\n opt = opt + ' -march=i486 '\n elif cpu.is_i386():\n opt = opt + ' -march=i386 '\n if cpu.is_Intel():\n opt = opt + ' -malign-double -fomit-frame-pointer ' \n return opt\n \n def find_lib_directories(self):\n if self.gcc_lib_dir is not None:\n return self.gcc_lib_dir\n self.announce('running gnu_fortran_compiler.find_lib_directories')\n self.gcc_lib_dir = []\n lib_dir = []\n match = r'Reading specs from (.*)/specs'\n\n # works I think only for unix...\n cmd = '%s -v' % self.f77_compiler\n self.announce(yellow_text(cmd))\n exit_status, out_text = run_command(cmd)\n if not exit_status:\n m = re.findall(match,out_text)\n if m:\n assert len(m)==1,`m`\n self.gcc_lib_dir = m\n return self.gcc_lib_dir\n\n def get_linker_so(self):\n lnk = None\n # win32 linking should be handled by standard linker\n if ((sys.platform != 'win32') and\n (sys.platform != 'cygwin') and\n (os.uname()[0] != 'Darwin')):\n lnk = [self.f77_compiler,'-shared']\n return lnk\n\n def get_extra_link_args(self):\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work.\n args = [] \n if (hasattr(os,'uname') and (os.uname()[0] == 'SunOS')):\n args = ['-mimpure-text']\n return args\n\n def f90_compile(self,source_files,module_files,temp_dir=''):\n raise DistutilsExecError, 'f90 not supported by Gnu'\n\n\n#http://developer.intel.com/software/products/compilers/f50/linux/\nclass intel_ia32_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Intel' # Intel(R) Corporation \n ver_match = r'Intel\\(R\\) Fortran Compiler for 32-bit applications, '\\\n 'Version (?P[^\\s*]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'ifc'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -KPIC '\n\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n if cpu.has_fdiv_bug():\n switches = switches + ' -fdiv_check '\n if cpu.has_f00f_bug():\n switches = switches + ' -0f_check '\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -FI -w90 -w95 '\n\n self.f77_opt = self.f90_opt = self.get_opt()\n \n debug = ' -g -C '\n self.f77_debug = self.f90_debug = debug\n\n self.ver_cmd = self.f77_compiler+' -FI -V -c %s -o %s' %\\\n self.dummy_fortran_files()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 '\n if cpu.is_PentiumPro() or cpu.is_PentiumII():\n opt = opt + ' -tpp6 -xi '\n elif cpu.is_PentiumIII():\n opt = opt + ' -tpp6 '\n elif cpu.is_Pentium():\n opt = opt + ' -tpp5 '\n elif cpu.is_PentiumIV():\n opt = opt + ' -tpp7 -xW '\n elif cpu.has_mmx():\n opt = opt + ' -xM '\n return opt\n \n\n def get_linker_so(self):\n return [self.f77_compiler,'-shared']\n\n\nclass intel_itanium_fortran_compiler(intel_ia32_fortran_compiler):\n\n vendor = 'Itanium'\n ver_match = r'Intel\\(R\\) Fortran 90 Compiler Itanium\\(TM\\) Compiler'\\\n ' for the Itanium\\(TM\\)-based applications,'\\\n ' Version (?P[^\\s*]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n if fc is None:\n fc = 'efc'\n intel_ia32_fortran_compiler.__init__(self, fc, f90c, verbose=verbose)\n\n\nclass nag_fortran_compiler(fortran_compiler_base):\n\n vendor = 'NAG'\n ver_match = r'NAGWare Fortran 95 compiler Release (?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f95'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ''\n debug = ' -g -gline -g90 -nan -C '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -fixed '\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -target=native '\n return opt\n\n def get_linker_so(self):\n return [self.f77_compiler,'-Wl,-shared']\n\n\n# http://www.fortran.com/F/compilers.html\n#\n# We define F compiler here but it is quite useless\n# because it does not support external procedures\n# which are needed for calling F90 module routines\n# through f2py generated wrappers.\nclass f_fortran_compiler(fortran_compiler_base):\n\n vendor = 'F'\n ver_match = r'Fortran Company/NAG F compiler Release (?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'F'\n if f90c is None:\n f90c = 'F'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n self.ver_cmd = self.f90_compiler+' -V '\n\n gnu = gnu_fortran_compiler('g77')\n if not gnu.is_available(): # F compiler requires gcc.\n self.version = ''\n return\n if not self.is_available():\n return\n\n if self.verbose:\n print red_text(\"\"\"\nWARNING: F compiler is unsupported due to its incompleteness.\n Send complaints to its vendor. For adding its support\n to scipy_distutils, it must support external procedures.\n\"\"\")\n\n self.f90_switches = ''\n self.f90_debug = ' -g -gline -g90 -C '\n self.f90_opt = ' -O '\n\n #self.f77_switches = gnu.f77_switches\n #self.f77_debug = gnu.f77_debug\n #self.f77_opt = gnu.f77_opt\n\n def get_linker_so(self):\n return ['gcc','-shared']\n\n\nclass vast_fortran_compiler(fortran_compiler_base):\n\n vendor = 'VAST'\n ver_match = r'\\s*Pacific-Sierra Research vf90 (Personal|Professional)'\\\n '\\s+(?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n d,b = os.path.split(f90c)\n vf90 = os.path.join(d,'v'+b)\n self.ver_cmd = vf90+' -v '\n\n gnu = gnu_fortran_compiler(fc)\n if not gnu.is_available(): # VAST compiler requires g77.\n self.version = ''\n return\n if not self.is_available():\n return\n\n self.f77_switches = gnu.f77_switches\n self.f77_debug = gnu.f77_debug\n self.f77_opt = gnu.f77_opt \n\n # XXX: need f90 switches, debug, opt\n\n def get_linker_so(self):\n return [self.f90_compiler,'-shared']\n\n\nclass compaq_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Compaq'\n ver_match = r'Compaq Fortran (?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'fort'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -assume no2underscore -nomixed_str_len_arg '\n debug = ' -g -check_bounds '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n # XXX: uncomment if required\n #self.libraries = ' -lUfor -lfor -lFutil -lcpml -lots -lc '\n\n # XXX: fix the version showing flag\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -align dcommons -arch host -assume bigarrays'\\\n ' -assume nozsize -math_library fast -tune host '\n return opt\n\n def get_linker_so(self):\n return [self.f77_compiler,'-shared']\n\n\n#http://www.compaq.com/fortran\nclass digital_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Digital'\n ver_match = r'DIGITAL Visual Fortran Optimizing Compiler'\\\n ' Version (?P[^\\s]*).*'\n\n compile_switch = ' /c '\n object_switch = ' /object:'\n lib_prefix = ''\n lib_suffix = '.lib'\n lib_ar = 'lib.exe /OUT:'\n lib_ranlib = ''\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'DF'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n self.ver_cmd = self.f77_compiler+' /what '\n\n if self.is_available():\n #XXX: is this really necessary???\n from distutils.msvccompiler import find_exe\n self.lib_ar = find_exe(\"lib.exe\", self.version) + ' /OUT:'\n\n switches = ' /nologo /MD /W1 /iface:cref /iface=nomixed_str_len_arg '\n debug = ' '\n\n self.f77_switches = ' /f77rtl /fixed ' + switches\n self.f90_switches = switches\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n def get_opt(self):\n # XXX: use also /architecture, see gnu_fortran_compiler\n return ' /Ox '\n\n\ndef match_extension(files,ext):\n match = re.compile(r'.*[.]('+ext+r')\\Z',re.I).match\n return filter(lambda x,match = match: match(x),files)\n\ndef get_f77_files(files):\n return match_extension(files,'for|f77|ftn|f')\n\ndef get_f90_files(files):\n return match_extension(files,'f90|f95')\n\ndef get_fortran_files(files):\n return match_extension(files,'f90|f95|for|f77|ftn|f')\n\ndef find_fortran_compiler(vendor=None, fc=None, f90c=None, verbose=0):\n for compiler_class in all_compilers:\n if vendor is not None and vendor != compiler_class.vendor:\n continue\n #print compiler_class\n compiler = compiler_class(fc,f90c,verbose = verbose)\n if compiler.is_available():\n return compiler\n return None\n\nall_compilers = [absoft_fortran_compiler,\n mips_fortran_compiler,\n sun_fortran_compiler,\n intel_ia32_fortran_compiler,\n intel_itanium_fortran_compiler,\n nag_fortran_compiler,\n compaq_fortran_compiler,\n digital_fortran_compiler,\n vast_fortran_compiler,\n hpux_fortran_compiler,\n f_fortran_compiler,\n gnu_fortran_compiler,\n ]\n\nif __name__ == \"__main__\":\n show_compilers()\n", "source_code_before": "\"\"\" Implements the build_flib command which should go into Distutils\n at some point.\n \n Note:\n Right now, we're dynamically linking to the Fortran libraries on \n some platforms (Sun for sure). This is fine for local installations\n but a bad thing for redistribution because these libraries won't\n live on any machine that doesn't have a fortran compiler installed.\n It is pretty hard (impossible?) to get gcc to pass the right compiler\n flags on Sun to get the linker to use static libs for the fortran\n stuff. Investigate further...\n\nBugs:\n *** Options -e and -x have no effect when used with --help-compiler\n options. E.g. \n ./setup.py build_flib --help-compiler -e g77-3.0\n finds g77-2.95.\n How to extract these options inside the show_compilers function?\n *** compiler.is_available() method may not work correctly on nt\n because of lack of knowledge how to get exit status in\n run_command function. However, it may give reasonable results\n based on a version string.\n *** Some vendors provide different compilers for F77 and F90\n compilations. Currently, checking the availability of these\n compilers is based on only checking the availability of the\n corresponding F77 compiler. If it exists, then F90 is assumed\n to exist also.\n *** F compiler from Fortran Compiler is _not_ supported, though it\n is defined below. The reasons is that this F95 compiler is\n incomplete: it does not support external procedures\n that are needed to facilitate calling F90 module routines\n from C and subsequently from Python. See also\n http://cens.ioc.ee/pipermail/f2py-users/2002-May/000265.html\n\nOpen issues:\n *** User-defined compiler flags. Do we need --fflags?\n\nFortran compilers (as to be used with --fcompiler= option):\n Absoft\n Sun\n SGI\n Intel\n Itanium\n NAG\n Compaq\n Digital\n Gnu\n VAST\n F [unsupported]\n\"\"\"\n\nimport distutils\nimport distutils.dep_util, distutils.dir_util\nimport os,sys,string\nimport commands,re\nfrom types import *\nfrom distutils.ccompiler import CCompiler,gen_preprocess_options\nfrom distutils.command.build_clib import build_clib\nfrom distutils.errors import *\nfrom scipy_distutils.misc_util import red_text,green_text,yellow_text,\\\n cyan_text\n\nclass FortranCompilerError (CCompilerError):\n \"\"\"Some compile/link operation failed.\"\"\"\nclass FortranCompileError (FortranCompilerError):\n \"\"\"Failure to compile one or more Fortran source files.\"\"\"\nclass FortranBuildError (FortranCompilerError):\n \"\"\"Failure to build Fortran library.\"\"\"\n\nif os.name == 'nt':\n def run_command(command):\n \"\"\" not sure how to get exit status on nt. \"\"\"\n in_pipe,out_pipe = os.popen4(command)\n in_pipe.close()\n text = out_pipe.read()\n return 0, text\nelse:\n run_command = commands.getstatusoutput\n\ndef show_compilers():\n for compiler_class in all_compilers:\n compiler = compiler_class()\n if compiler.is_available():\n print cyan_text(compiler)\n\nclass build_flib (build_clib):\n\n description = \"build f77/f90 libraries used by Python extensions\"\n\n user_options = [\n ('build-flib', 'b',\n \"directory to build f77/f90 libraries to\"),\n ('build-temp', 't',\n \"directory to put temporary build by-products\"),\n ('debug', 'g',\n \"compile with debugging information\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ('fcompiler=', 'c',\n \"specify the compiler type\"),\n ('fcompiler-exec=', 'e',\n \"specify the path to F77 compiler\"),\n ('f90compiler-exec=', 'x',\n \"specify the path to F90 compiler\"),\n ]\n\n boolean_options = ['debug', 'force']\n\n help_options = [\n ('help-compiler', None,\n \"list available compilers\", show_compilers),\n ]\n\n def initialize_options (self):\n\n self.build_flib = None\n self.build_temp = None\n\n self.fortran_libraries = None\n self.define = None\n self.undef = None\n self.debug = None\n self.force = 0\n self.fcompiler = None\n self.fcompiler_exec = None\n self.f90compiler_exec = None\n\n # initialize_options()\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_flib'),\n ('build_temp', 'build_temp'),\n ('debug', 'debug'),\n ('force', 'force'))\n\n self.announce('running find_fortran_compiler')\n fc = find_fortran_compiler(self.fcompiler,\n self.fcompiler_exec,\n self.f90compiler_exec,\n verbose = self.verbose)\n if not fc:\n raise DistutilsOptionError, 'Fortran compiler not available: %s'\\\n % (self.fcompiler)\n else:\n self.announce('using '+cyan_text('%s Fortran compiler' % fc))\n self.fcompiler = fc\n if self.has_f_libraries():\n self.fortran_libraries = self.distribution.fortran_libraries\n self.check_library_list(self.fortran_libraries)\n \n # finalize_options()\n\n def has_f_libraries(self):\n return self.distribution.fortran_libraries \\\n and len(self.distribution.fortran_libraries) > 0\n\n def run (self):\n if not self.has_f_libraries():\n return\n self.build_libraries(self.fortran_libraries)\n\n # run ()\n\n def has_f_library(self,name):\n if self.has_f_libraries():\n # If self.fortran_libraries is None at this point\n # then it means that build_flib was called before\n # build. Always call build before build_flib.\n for (lib_name, build_info) in self.fortran_libraries:\n if lib_name == name:\n return 1\n \n def get_library_names(self, name=None):\n if not self.has_f_libraries():\n return None\n\n lib_names = []\n\n if name is None:\n for (lib_name, build_info) in self.fortran_libraries:\n lib_names.append(lib_name)\n\n if self.fcompiler is not None:\n lib_names.extend(self.fcompiler.get_libraries())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n for n in build_info.get('libraries',[]):\n lib_names.append(n)\n #XXX: how to catch recursive calls here?\n lib_names.extend(self.get_library_names(n))\n break\n return lib_names\n\n def get_fcompiler_library_names(self):\n #if not self.has_f_libraries():\n # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_libraries()\n return []\n\n def get_fcompiler_library_dirs(self):\n #if not self.has_f_libraries():\n # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_library_dirs()\n return []\n\n # get_library_names ()\n\n def get_library_dirs(self, name=None):\n if not self.has_f_libraries():\n return []\n\n lib_dirs = [] \n\n if name is None:\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_library_dirs())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n lib_dirs.extend(build_info.get('library_dirs',[]))\n for n in build_info.get('libraries',[]):\n lib_dirs.extend(self.get_library_dirs(n))\n break\n\n return lib_dirs\n\n # get_library_dirs ()\n\n def get_runtime_library_dirs(self):\n #if not self.has_f_libraries():\n # return []\n\n lib_dirs = []\n\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_runtime_library_dirs())\n \n return lib_dirs\n\n # get_library_dirs ()\n\n def get_source_files (self):\n if not self.has_f_libraries():\n return []\n\n self.check_library_list(self.fortran_libraries)\n filenames = []\n\n # Gets source files specified \n for ext in self.fortran_libraries:\n filenames.extend(ext[1]['sources'])\n\n return filenames \n \n def build_libraries (self, fortran_libraries):\n \n fcompiler = self.fcompiler\n \n for (lib_name, build_info) in fortran_libraries:\n self.announce(\" building '%s' library\" % lib_name)\n\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'fortran_libraries' option (library '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % lib_name\n sources = list(sources)\n module_dirs = build_info.get('module_dirs')\n module_files = build_info.get('module_files')\n\n\n include_dirs = build_info.get('include_dirs')\n\n if include_dirs:\n fcompiler.set_include_dirs(include_dirs)\n for n,v in build_info.get('define_macros') or []:\n fcompiler.define_macro(n,v)\n for n in build_info.get('undef_macros') or []:\n fcompiler.undefine_macro(n)\n\n if module_files:\n fcompiler.build_library(lib_name, module_files,\n temp_dir=self.build_temp)\n \n fcompiler.build_library(lib_name, sources,\n module_dirs, temp_dir=self.build_temp)\n\n # for loop\n\n # build_libraries ()\n\nclass fortran_compiler_base(CCompiler):\n\n vendor = None\n ver_match = None\n\n compiler_type = 'fortran'\n executables = {}\n\n compile_switch = ' -c '\n object_switch = ' -o '\n lib_prefix = 'lib'\n lib_suffix = '.a'\n lib_ar = 'ar -cur '\n lib_ranlib = 'ranlib '\n\n def __init__(self,verbose=0,dry_run=0,force=0):\n # Default initialization. Constructors of derived classes MUST\n # call this function.\n CCompiler.__init__(self,verbose,dry_run,force)\n\n self.version = None\n \n self.f77_switches = ''\n self.f77_opt = ''\n self.f77_debug = ''\n \n self.f90_switches = ''\n self.f90_opt = ''\n self.f90_debug = ''\n \n #self.libraries = []\n #self.library_dirs = []\n\n if self.vendor is None:\n raise DistutilsInternalError,\\\n '%s must define vendor attribute'%(self.__class__)\n if self.ver_match is None:\n raise DistutilsInternalError,\\\n '%s must define ver_match attribute'%(self.__class__)\n\n def to_object(self,\n dirty_files,\n module_dirs=None,\n temp_dir=''):\n files = string.join(dirty_files)\n f90_files = get_f90_files(dirty_files)\n f77_files = get_f77_files(dirty_files)\n if f90_files != []:\n obj1 = self.f90_compile(f90_files,module_dirs,temp_dir = temp_dir)\n else:\n obj1 = []\n if f77_files != []:\n obj2 = self.f77_compile(f77_files, temp_dir = temp_dir)\n else:\n obj2 = []\n return obj1 + obj2\n\n def source_to_object_names(self,source_files, temp_dir=''):\n file_list = map(lambda x: os.path.basename(x),source_files)\n file_base_ext = map(lambda x: os.path.splitext(x),file_list)\n object_list = map(lambda x: x[0] +'.o',file_base_ext)\n object_files = map(lambda x,td=temp_dir: os.path.join(td,x),object_list)\n return object_files\n \n def source_and_object_pairs(self,source_files, temp_dir=''):\n object_files = self.source_to_object_names(source_files,temp_dir)\n file_pairs = zip(source_files,object_files)\n return file_pairs\n \n def f_compile(self,compiler,switches, source_files,\n module_dirs=None, temp_dir=''):\n\n pp_opts = gen_preprocess_options(self.macros,self.include_dirs)\n\n switches = switches + ' ' + string.join(pp_opts,' ')\n\n module_switch = self.build_module_switch(module_dirs)\n file_pairs = self.source_and_object_pairs(source_files,temp_dir)\n object_files = []\n for source,object in file_pairs:\n if distutils.dep_util.newer(source,object):\n cmd = compiler + ' ' + switches + ' '+\\\n module_switch + \\\n self.compile_switch + source + \\\n self.object_switch + object\n self.announce(yellow_text(cmd))\n failure = os.system(cmd)\n if failure:\n raise FortranCompileError,\\\n 'failure during compile (exit status = %s)' % failure\n object_files.append(object)\n return object_files\n #return all object files to make sure everything is archived \n #return map(lambda x: x[1], file_pairs)\n\n def f90_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f90_switches, self.f90_opt))\n return self.f_compile(self.f90_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n def f77_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f77_switches, self.f77_opt))\n return self.f_compile(self.f77_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n def build_module_switch(self, module_dirs):\n return ''\n\n def create_static_lib(self, object_files, library_name,\n output_dir='', debug=None, skip_ranlib=0):\n lib_file = os.path.join(output_dir,\n self.lib_prefix+library_name+self.lib_suffix)\n objects = string.join(object_files)\n if objects:\n cmd = '%s%s %s' % (self.lib_ar,lib_file,objects)\n self.announce(yellow_text(cmd))\n failure = os.system(cmd)\n if failure:\n raise FortranBuildError,\\\n 'failure during build (exit status = %s)'%failure \n if self.lib_ranlib and not skip_ranlib:\n # Digital,MIPSPro compilers do not have ranlib.\n cmd = '%s %s' %(self.lib_ranlib,lib_file)\n self.announce(yellow_text(cmd))\n failure = os.system(cmd)\n if failure:\n raise FortranBuildError,\\\n 'failure during build (exit status = %s)'%failure \n\n def build_library(self,library_name,source_list,module_dirs=None,\n temp_dir = ''):\n #make sure the temp directory exists before trying to build files\n import distutils.dir_util\n distutils.dir_util.mkpath(temp_dir)\n\n #this compiles the files\n object_list = self.to_object(source_list,\n module_dirs,\n temp_dir)\n\n # actually we need to use all the object file names here to\n # make sure the library is always built. It could occur that an\n # object file exists but hasn't been put in the archive. (happens\n # a lot when builds fail once and are restarted).\n object_list = self.source_to_object_names(source_list, temp_dir)\n\n if os.name == 'nt' or sys.platform[:4] == 'irix':\n # I (pearu) had the same problem on irix646 ...\n # I think we can make this \"bunk\" default as skip_ranlib\n # feature speeds things up.\n # XXX:Need to check if Digital compiler works here.\n\n # This is pure bunk...\n # Windows fails for long argument strings on the command line.\n # if objects is real long (> 2048 chars or so on my machine),\n # the command fails (cmd.exe /e:2048 on w2k).\n # for now we'll split linking into to steps which should work for\n objects = object_list[:]\n while objects:\n #obj,objects = objects[:20],objects[20:]\n i = 0\n obj = []\n while i<1900 and objects:\n i = i + len(objects[0]) + 1\n obj.append(objects[0])\n objects = objects[1:]\n self.create_static_lib(obj,library_name,temp_dir,\n skip_ranlib = len(objects))\n else:\n self.create_static_lib(object_list,library_name,temp_dir)\n\n def dummy_fortran_files(self):\n import tempfile \n d = tempfile.gettempdir()\n dummy_name = os.path.join(d,'__dummy.f')\n dummy = open(dummy_name,'w')\n dummy.write(\" subroutine dummy()\\n end\\n\")\n dummy.close()\n return (os.path.join(d,'__dummy.f'),os.path.join(d,'__dummy.o'))\n \n def is_available(self):\n return self.get_version()\n \n def get_version(self):\n \"\"\"Return the compiler version. If compiler is not available,\n return empty string.\"\"\"\n # XXX: Is there compilers that have no version? If yes,\n # this test will fail even if the compiler is available.\n if self.version is not None:\n # Finding version is expensive, so return previously found\n # version string.\n return self.version\n self.version = ''\n # works I think only for unix...\n #if self.verbose:\n self.announce('detecting %s Fortran compiler...'%(self.vendor))\n self.announce(yellow_text(self.ver_cmd))\n exit_status, out_text = run_command(self.ver_cmd)\n out_text2 = out_text.split('\\n')[0]\n if not exit_status:\n self.announce('found %s' %(green_text(out_text2)))\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\n else:\n self.announce('%s: %s' % (exit_status,red_text(out_text2)))\n return self.version\n\n def get_libraries(self):\n return self.libraries\n def get_library_dirs(self):\n return self.library_dirs\n def get_extra_link_args(self):\n return []\n def get_runtime_library_dirs(self):\n return []\n def get_linker_so(self):\n \"\"\"\n If a compiler requires specific linker then return a list\n containing a linker executable name and linker options.\n Otherwise, return None.\n \"\"\"\n\n def __str__(self):\n return \"%s %s\" % (self.vendor, self.get_version())\n\n\nclass absoft_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Absoft'\n ver_match = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n # got rid of -B108 cause it was generating 2 underscores instead\n # of one on the newest version. Now we use -YEXT_SFX=_ to \n # specify the output format\n if os.name == 'nt':\n self.f90_switches = '-f fixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -Q100'\n self.f77_switches = '-N22 -N90 -N110'\n self.f77_opt = '-O -Q100'\n self.libraries = ['fio', 'fmath', 'f90math', 'COMDLG32']\n else:\n self.f90_switches = '-ffixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -B101' \n self.f77_switches = '-N22 -N90 -N110 -B108'\n self.f77_opt = '-O -B101'\n\n self.libraries = ['fio', 'f77math', 'f90math']\n \n try:\n dir = os.environ['ABSOFT'] \n self.library_dirs = [os.path.join(dir,'lib')]\n except KeyError:\n self.library_dirs = []\n\n self.ver_cmd = self.f77_compiler + ' -V -c %s -o %s' % \\\n self.dummy_fortran_files()\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -p' + mod\n return res\n\n def get_extra_link_args(self):\n return []\n # Couldn't get this to link for anything using gcc.\n #dr = \"c:\\\\Absoft62\\\\lib\"\n #libs = ['fio.lib', 'COMDLG32.lib','fmath.lib', 'f90math.lib','libcomdlg32.a' ] \n #libs = map(lambda x,dr=dr:os.path.join(dr,x),libs)\n #return libs\n\n\nclass sun_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Sun'\n #ver_match = r'f77: (?P[^\\s*,]*)'\n ver_match = r'f90: Sun (?P[^\\s*,]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc # not tested\n self.f77_switches = ' -pic '\n self.f77_opt = ' -fast -dalign '\n\n self.f90_compiler = f90c\n self.f90_switches = ' -fixed ' # ??? why fixed?\n self.f90_opt = ' -fast -dalign '\n\n self.ver_cmd = self.f90_compiler + ' -V'\n\n #self.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\n self.libraries = ['fsu', 'F77', 'M77', 'sunmath', 'm']\n \n #threaded\n #self.libraries = ['f90', 'F77_mt', 'sunmath_mt', 'm', 'thread']\n #self.libraries = []\n self.library_dirs = self.find_lib_dir()\n #print 'sun:',self.library_dirs\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -M' + mod\n return res\n\n def find_lib_dir(self):\n library_dirs = []\n lib_match = r'### f90: Note: LD_RUN_PATH\\s*= '\\\n '(?P[^\\s.]*).*'\n cmd = self.f90_compiler + ' -dryrun dummy.f'\n self.announce(yellow_text(cmd))\n exit_status, output = run_command(cmd)\n if not exit_status:\n libs = re.findall(lib_match,output)\n if libs:\n library_dirs = string.split(libs[0],':')\n self.get_version() # force version calculation\n compiler_home = os.path.dirname(library_dirs[0])\n library_dirs.append(os.path.join(compiler_home,\n self.version,'lib'))\n return library_dirs\n def get_runtime_library_dirs(self):\n return self.find_lib_dir()\n def get_extra_link_args(self):\n return ['-mimpure-text']\n\n\nclass mips_fortran_compiler(fortran_compiler_base):\n\n vendor = 'SGI'\n ver_match = r'MIPSpro Compilers: Version (?P[^\\s*,]*)'\n lib_ranlib = '' # XXX: should we use `ar -s' here?\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f77_switches = ' -n32 -KPIC '\n self.f77_opt = ' -O3 '\n\n self.f90_compiler = f90c\n self.f90_switches = ' -n32 -KPIC -fixedform ' # why fixed ???\n self.f90_opt = ' ' \n\n self.ver_cmd = self.f77_compiler + ' -version '\n\n #self.libraries = ['fortran', 'ftn', 'm']\n # -lfortran is redundant with MIPSPro 7.30\n self.libraries = ['ftn', 'm']\n self.library_dirs = self.find_lib_dir()\n\n\n def build_module_switch(self,module_dirs):\n res = ''\n return res \n def find_lib_dir(self):\n library_dirs = []\n return library_dirs\n def get_runtime_library_dirs(self):\n\treturn self.find_lib_dir() \n def get_extra_link_args(self):\n\treturn []\n\nclass hpux_fortran_compiler(fortran_compiler_base):\n\n vendor = 'HP'\n ver_match = r'HP F90 (?P[^\\s*,]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f90'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f77_switches = ' +pic=long '\n self.f77_opt = ' -O3 '\n\n self.f90_compiler = f90c\n self.f90_switches = ' +pic=long '\n self.f90_opt = ' -O3 '\n\n self.ver_cmd = self.f77_compiler + ' +version '\n\n self.libraries = ['m']\n self.library_dirs = []\n\n def get_version(self):\n if self.version is not None:\n return self.version\n self.version = ''\n self.announce(yellow_text(self.ver_cmd))\n exit_status, out_text = run_command(self.ver_cmd)\n if self.verbose:\n out_text = out_text.split('\\n')[0]\n if exit_status in [0,256]:\n # 256 seems to indicate success on HP-UX but keeping\n # also 0. Or does 0 exit status mean something different\n # in this platform?\n self.announce('found: '+green_text(out_text))\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\n else:\n self.announce('%s: %s' % (exit_status,red_text(out_text)))\n return self.version\n\nclass gnu_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Gnu'\n ver_match = r'GNU Fortran (?P[^\\s*]*)'\n gcc_lib_dir = None\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n\n gcc_lib_dir = self.find_lib_directories()\n if gcc_lib_dir and \\\n os.path.isfile(os.path.join(gcc_lib_dir[0],'libg2c-pic.a')):\n g2c = 'g2c-pic'\n else:\n g2c = 'g2c'\n if sys.platform == 'win32':\n self.libraries = ['gcc',g2c]\n self.library_dirs = gcc_lib_dir\n else:\n # On linux g77 does not need lib_directories to be specified.\n self.libraries = [g2c]\n\n switches = ' -Wall -fno-second-underscore '\n\n if os.name != 'nt':\n switches = switches + ' -fPIC '\n\n self.f77_switches = switches\n self.ver_cmd = self.f77_compiler + ' --version '\n\n self.f77_opt = self.get_opt()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 -funroll-loops '\n \n # only check for more optimization if g77 can handle it.\n if self.get_version():\n if self.version >= '0.5.26': # is gcc >= 3.x.x\n if cpu.is_AthlonK6():\n opt = opt + ' -march=k6 '\n elif cpu.is_AthlonK7():\n opt = opt + ' -march=athlon '\n if cpu.is_i686():\n opt = opt + ' -march=i686 '\n elif cpu.is_i586():\n opt = opt + ' -march=i586 '\n elif cpu.is_i486():\n opt = opt + ' -march=i486 '\n elif cpu.is_i386():\n opt = opt + ' -march=i386 '\n if cpu.is_Intel():\n opt = opt + ' -malign-double -fomit-frame-pointer ' \n return opt\n \n def find_lib_directories(self):\n if self.gcc_lib_dir is not None:\n return self.gcc_lib_dir\n self.announce('running gnu_fortran_compiler.find_lib_directories')\n self.gcc_lib_dir = []\n lib_dir = []\n match = r'Reading specs from (.*)/specs'\n\n # works I think only for unix...\n cmd = '%s -v' % self.f77_compiler\n self.announce(yellow_text(cmd))\n exit_status, out_text = run_command(cmd)\n if not exit_status:\n m = re.findall(match,out_text)\n if m:\n assert len(m)==1,`m`\n self.gcc_lib_dir = m\n return self.gcc_lib_dir\n\n def get_linker_so(self):\n lnk = None\n # win32 linking should be handled by standard linker\n if ((sys.platform != 'win32') and\n (sys.platform != 'cygwin') and\n (os.uname()[0] != 'Darwin')):\n lnk = [self.f77_compiler,'-shared']\n return lnk\n\n def get_extra_link_args(self):\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work.\n args = [] \n if (hasattr(os,'uname') and (os.uname()[0] == 'SunOS')):\n args = ['-mimpure-text']\n return args\n\n def f90_compile(self,source_files,module_files,temp_dir=''):\n raise DistutilsExecError, 'f90 not supported by Gnu'\n\n\n#http://developer.intel.com/software/products/compilers/f50/linux/\nclass intel_ia32_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Intel' # Intel(R) Corporation \n ver_match = r'Intel\\(R\\) Fortran Compiler for 32-bit applications, '\\\n 'Version (?P[^\\s*]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'ifc'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -KPIC '\n\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n if cpu.has_fdiv_bug():\n switches = switches + ' -fdiv_check '\n if cpu.has_f00f_bug():\n switches = switches + ' -0f_check '\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -FI -w90 -w95 '\n\n self.f77_opt = self.f90_opt = self.get_opt()\n \n debug = ' -g -C '\n self.f77_debug = self.f90_debug = debug\n\n self.ver_cmd = self.f77_compiler+' -FI -V -c %s -o %s' %\\\n self.dummy_fortran_files()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 '\n if cpu.is_PentiumPro() or cpu.is_PentiumII():\n opt = opt + ' -tpp6 -xi '\n elif cpu.is_PentiumIII():\n opt = opt + ' -tpp6 '\n elif cpu.is_Pentium():\n opt = opt + ' -tpp5 '\n elif cpu.is_PentiumIV():\n opt = opt + ' -tpp7 -xW '\n elif cpu.has_mmx():\n opt = opt + ' -xM '\n return opt\n \n\n def get_linker_so(self):\n return [self.f77_compiler,'-shared']\n\n\nclass intel_itanium_fortran_compiler(intel_ia32_fortran_compiler):\n\n vendor = 'Itanium'\n ver_match = r'Intel\\(R\\) Fortran 90 Compiler Itanium\\(TM\\) Compiler'\\\n ' for the Itanium\\(TM\\)-based applications,'\\\n ' Version (?P[^\\s*]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n if fc is None:\n fc = 'efc'\n intel_ia32_fortran_compiler.__init__(self, fc, f90c, verbose=verbose)\n\n\nclass nag_fortran_compiler(fortran_compiler_base):\n\n vendor = 'NAG'\n ver_match = r'NAGWare Fortran 95 compiler Release (?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f95'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ''\n debug = ' -g -gline -g90 -nan -C '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -fixed '\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -target=native '\n return opt\n\n def get_linker_so(self):\n return [self.f77_compiler,'-Wl,-shared']\n\n\n# http://www.fortran.com/F/compilers.html\n#\n# We define F compiler here but it is quite useless\n# because it does not support external procedures\n# which are needed for calling F90 module routines\n# through f2py generated wrappers.\nclass f_fortran_compiler(fortran_compiler_base):\n\n vendor = 'F'\n ver_match = r'Fortran Company/NAG F compiler Release (?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'F'\n if f90c is None:\n f90c = 'F'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n self.ver_cmd = self.f90_compiler+' -V '\n\n gnu = gnu_fortran_compiler('g77')\n if not gnu.is_available(): # F compiler requires gcc.\n self.version = ''\n return\n if not self.is_available():\n return\n\n if self.verbose:\n print red_text(\"\"\"\nWARNING: F compiler is unsupported due to its incompleteness.\n Send complaints to its vendor. For adding its support\n to scipy_distutils, it must support external procedures.\n\"\"\")\n\n self.f90_switches = ''\n self.f90_debug = ' -g -gline -g90 -C '\n self.f90_opt = ' -O '\n\n #self.f77_switches = gnu.f77_switches\n #self.f77_debug = gnu.f77_debug\n #self.f77_opt = gnu.f77_opt\n\n def get_linker_so(self):\n return ['gcc','-shared']\n\n\nclass vast_fortran_compiler(fortran_compiler_base):\n\n vendor = 'VAST'\n ver_match = r'\\s*Pacific-Sierra Research vf90 (Personal|Professional)'\\\n '\\s+(?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n d,b = os.path.split(f90c)\n vf90 = os.path.join(d,'v'+b)\n self.ver_cmd = vf90+' -v '\n\n gnu = gnu_fortran_compiler(fc)\n if not gnu.is_available(): # VAST compiler requires g77.\n self.version = ''\n return\n if not self.is_available():\n return\n\n self.f77_switches = gnu.f77_switches\n self.f77_debug = gnu.f77_debug\n self.f77_opt = gnu.f77_opt \n\n # XXX: need f90 switches, debug, opt\n\n def get_linker_so(self):\n return [self.f90_compiler,'-shared']\n\n\nclass compaq_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Compaq'\n ver_match = r'Compaq Fortran (?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'fort'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -assume no2underscore -nomixed_str_len_arg '\n debug = ' -g -check_bounds '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n # XXX: uncomment if required\n #self.libraries = ' -lUfor -lfor -lFutil -lcpml -lots -lc '\n\n # XXX: fix the version showing flag\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -align dcommons -arch host -assume bigarrays'\\\n ' -assume nozsize -math_library fast -tune host '\n return opt\n\n def get_linker_so(self):\n return [self.f77_compiler,'-shared']\n\n\n#http://www.compaq.com/fortran\nclass digital_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Digital'\n ver_match = r'DIGITAL Visual Fortran Optimizing Compiler'\\\n ' Version (?P[^\\s]*).*'\n\n compile_switch = ' /c '\n object_switch = ' /object:'\n lib_prefix = ''\n lib_suffix = '.lib'\n lib_ar = 'lib.exe /OUT:'\n lib_ranlib = ''\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'DF'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n self.ver_cmd = self.f77_compiler+' /what '\n\n if self.is_available():\n #XXX: is this really necessary???\n from distutils.msvccompiler import find_exe\n self.lib_ar = find_exe(\"lib.exe\", self.version) + ' /OUT:'\n\n switches = ' /nologo /MD /W1 /iface:cref /iface=nomixed_str_len_arg '\n debug = ' '\n\n self.f77_switches = ' /f77rtl /fixed ' + switches\n self.f90_switches = switches\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n def get_opt(self):\n # XXX: use also /architecture, see gnu_fortran_compiler\n return ' /Ox '\n\n\ndef match_extension(files,ext):\n match = re.compile(r'.*[.]('+ext+r')\\Z',re.I).match\n return filter(lambda x,match = match: match(x),files)\n\ndef get_f77_files(files):\n return match_extension(files,'for|f77|ftn|f')\n\ndef get_f90_files(files):\n return match_extension(files,'f90|f95')\n\ndef get_fortran_files(files):\n return match_extension(files,'f90|f95|for|f77|ftn|f')\n\ndef find_fortran_compiler(vendor=None, fc=None, f90c=None, verbose=0):\n fcompiler = None\n for compiler_class in all_compilers:\n if vendor is not None and vendor != compiler_class.vendor:\n continue\n #print compiler_class\n compiler = compiler_class(fc,f90c,verbose = verbose)\n if compiler.is_available():\n fcompiler = compiler\n break\n return fcompiler\n\nall_compilers = [absoft_fortran_compiler,\n mips_fortran_compiler,\n sun_fortran_compiler,\n intel_ia32_fortran_compiler,\n intel_itanium_fortran_compiler,\n nag_fortran_compiler,\n compaq_fortran_compiler,\n digital_fortran_compiler,\n vast_fortran_compiler,\n hpux_fortran_compiler,\n f_fortran_compiler,\n gnu_fortran_compiler,\n ]\n\nif __name__ == \"__main__\":\n show_compilers()\n", "methods": [ { "name": "run_command", "long_name": "run_command( command )", "filename": "build_flib.py", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "command" ], "start_line": 71, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "show_compilers", "long_name": "show_compilers( )", "filename": "build_flib.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [], "start_line": 80, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_flib.py", "nloc": 11, "complexity": 1, "token_count": 55, "parameters": [ "self" ], "start_line": 114, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "build_flib.py", "nloc": 20, "complexity": 3, "token_count": 122, "parameters": [ "self" ], "start_line": 130, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "has_f_libraries", "long_name": "has_f_libraries( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 2, "token_count": 23, "parameters": [ "self" ], "start_line": 154, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 22, "parameters": [ "self" ], "start_line": 158, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "has_f_library", "long_name": "has_f_library( self , name )", "filename": "build_flib.py", "nloc": 5, "complexity": 4, "token_count": 32, "parameters": [ "self", "name" ], "start_line": 165, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "get_library_names", "long_name": "get_library_names( self , name = None )", "filename": "build_flib.py", "nloc": 17, "complexity": 8, "token_count": 117, "parameters": [ "self", "name" ], "start_line": 174, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_fcompiler_library_names", "long_name": "get_fcompiler_library_names( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 24, "parameters": [ "self" ], "start_line": 196, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_fcompiler_library_dirs", "long_name": "get_fcompiler_library_dirs( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 24, "parameters": [ "self" ], "start_line": 203, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self , name = None )", "filename": "build_flib.py", "nloc": 15, "complexity": 7, "token_count": 109, "parameters": [ "self", "name" ], "start_line": 212, "end_line": 229, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 5, "complexity": 2, "token_count": 31, "parameters": [ "self" ], "start_line": 233, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_flib.py", "nloc": 8, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 246, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , fortran_libraries )", "filename": "build_flib.py", "nloc": 25, "complexity": 10, "token_count": 181, "parameters": [ "self", "fortran_libraries" ], "start_line": 259, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 100, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 312, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "to_object", "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 89, "parameters": [ "self", "dirty_files", "module_dirs", "temp_dir" ], "start_line": 337, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "source_to_object_names", "long_name": "source_to_object_names( self , source_files , temp_dir = '' )", "filename": "build_flib.py", "nloc": 6, "complexity": 1, "token_count": 89, "parameters": [ "self", "source_files", "temp_dir" ], "start_line": 354, "end_line": 359, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "source_and_object_pairs", "long_name": "source_and_object_pairs( self , source_files , temp_dir = '' )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "self", "source_files", "temp_dir" ], "start_line": 361, "end_line": 364, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f_compile", "long_name": "f_compile( self , compiler , switches , source_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 20, "complexity": 4, "token_count": 147, "parameters": [ "self", "compiler", "switches", "source_files", "module_dirs", "temp_dir" ], "start_line": 366, "end_line": 388, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "f90_compile", "long_name": "f90_compile( self , source_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self", "source_files", "module_dirs", "temp_dir" ], "start_line": 392, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f77_compile", "long_name": "f77_compile( self , source_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self", "source_files", "module_dirs", "temp_dir" ], "start_line": 397, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "module_dirs" ], "start_line": 402, "end_line": 403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "create_static_lib", "long_name": "create_static_lib( self , object_files , library_name , output_dir = '' , debug = None , skip_ranlib = 0 )", "filename": "build_flib.py", "nloc": 19, "complexity": 6, "token_count": 138, "parameters": [ "self", "object_files", "library_name", "output_dir", "debug", "skip_ranlib" ], "start_line": 405, "end_line": 424, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "build_library", "long_name": "build_library( self , library_name , source_list , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 21, "complexity": 6, "token_count": 149, "parameters": [ "self", "library_name", "source_list", "module_dirs", "temp_dir" ], "start_line": 426, "end_line": 466, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "dummy_fortran_files", "long_name": "dummy_fortran_files( self )", "filename": "build_flib.py", "nloc": 8, "complexity": 1, "token_count": 69, "parameters": [ "self" ], "start_line": 468, "end_line": 475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "is_available", "long_name": "is_available( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 477, "end_line": 478, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_version", "long_name": "get_version( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 4, "token_count": 130, "parameters": [ "self" ], "start_line": 480, "end_line": 503, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 505, "end_line": 506, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 507, "end_line": 508, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 509, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 511, "end_line": 512, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 1, "complexity": 1, "token_count": 6, "parameters": [ "self" ], "start_line": 513, "end_line": 518, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 520, "end_line": 521, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 31, "complexity": 5, "token_count": 185, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 529, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 6, "complexity": 3, "token_count": 27, "parameters": [ "self", "module_dirs" ], "start_line": 570, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 577, "end_line": 578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 110, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 592, "end_line": 617, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 6, "complexity": 3, "token_count": 27, "parameters": [ "self", "module_dirs" ], "start_line": 619, "end_line": 624, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "find_lib_dir", "long_name": "find_lib_dir( self )", "filename": "build_flib.py", "nloc": 18, "complexity": 4, "token_count": 122, "parameters": [ "self" ], "start_line": 626, "end_line": 643, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 645, "end_line": 646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 648, "end_line": 649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 651, "end_line": 652, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 100, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 661, "end_line": 682, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "module_dirs" ], "start_line": 685, "end_line": 687, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "find_lib_dir", "long_name": "find_lib_dir( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 688, "end_line": 690, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 691, "end_line": 692, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 693, "end_line": 694, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 95, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 701, "end_line": 720, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "get_version", "long_name": "get_version( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 5, "token_count": 125, "parameters": [ "self" ], "start_line": 722, "end_line": 740, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 24, "complexity": 7, "token_count": 156, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 748, "end_line": 779, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 21, "complexity": 10, "token_count": 117, "parameters": [ "self" ], "start_line": 781, "end_line": 803, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "find_lib_directories", "long_name": "find_lib_directories( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 4, "token_count": 98, "parameters": [ "self" ], "start_line": 805, "end_line": 822, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 7, "complexity": 4, "token_count": 51, "parameters": [ "self" ], "start_line": 824, "end_line": 831, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 5, "complexity": 3, "token_count": 39, "parameters": [ "self" ], "start_line": 833, "end_line": 841, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "f90_compile", "long_name": "f90_compile( self , source_files , module_files , temp_dir = '' )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "source_files", "module_files", "temp_dir" ], "start_line": 843, "end_line": 844, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 22, "complexity": 5, "token_count": 148, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 854, "end_line": 882, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 15, "complexity": 7, "token_count": 85, "parameters": [ "self" ], "start_line": 884, "end_line": 898, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 901, "end_line": 902, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 39, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 912, "end_line": 915, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 108, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 923, "end_line": 942, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 944, "end_line": 946, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 948, "end_line": 949, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 24, "complexity": 6, "token_count": 116, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 963, "end_line": 991, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 997, "end_line": 998, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 20, "complexity": 5, "token_count": 136, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 1007, "end_line": 1031, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 1035, "end_line": 1036, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 14, "complexity": 3, "token_count": 99, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 1044, "end_line": 1066, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 1068, "end_line": 1071, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 1073, "end_line": 1074, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 18, "complexity": 4, "token_count": 129, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 1091, "end_line": 1114, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 1116, "end_line": 1118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "match_extension", "long_name": "match_extension( files , ext )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 44, "parameters": [ "files", "ext" ], "start_line": 1121, "end_line": 1123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "get_f77_files", "long_name": "get_f77_files( files )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "files" ], "start_line": 1125, "end_line": 1126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "get_f90_files", "long_name": "get_f90_files( files )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "files" ], "start_line": 1128, "end_line": 1129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "get_fortran_files", "long_name": "get_fortran_files( files )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "files" ], "start_line": 1131, "end_line": 1132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "find_fortran_compiler", "long_name": "find_fortran_compiler( vendor = None , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 8, "complexity": 5, "token_count": 60, "parameters": [ "vendor", "fc", "f90c", "verbose" ], "start_line": 1134, "end_line": 1142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "methods_before": [ { "name": "run_command", "long_name": "run_command( command )", "filename": "build_flib.py", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "command" ], "start_line": 71, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "show_compilers", "long_name": "show_compilers( )", "filename": "build_flib.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [], "start_line": 80, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_flib.py", "nloc": 11, "complexity": 1, "token_count": 55, "parameters": [ "self" ], "start_line": 114, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "build_flib.py", "nloc": 20, "complexity": 3, "token_count": 122, "parameters": [ "self" ], "start_line": 130, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "has_f_libraries", "long_name": "has_f_libraries( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 2, "token_count": 23, "parameters": [ "self" ], "start_line": 154, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 22, "parameters": [ "self" ], "start_line": 158, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "has_f_library", "long_name": "has_f_library( self , name )", "filename": "build_flib.py", "nloc": 5, "complexity": 4, "token_count": 32, "parameters": [ "self", "name" ], "start_line": 165, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "get_library_names", "long_name": "get_library_names( self , name = None )", "filename": "build_flib.py", "nloc": 17, "complexity": 8, "token_count": 117, "parameters": [ "self", "name" ], "start_line": 174, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_fcompiler_library_names", "long_name": "get_fcompiler_library_names( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 24, "parameters": [ "self" ], "start_line": 196, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_fcompiler_library_dirs", "long_name": "get_fcompiler_library_dirs( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 24, "parameters": [ "self" ], "start_line": 203, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self , name = None )", "filename": "build_flib.py", "nloc": 15, "complexity": 7, "token_count": 109, "parameters": [ "self", "name" ], "start_line": 212, "end_line": 229, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 5, "complexity": 2, "token_count": 31, "parameters": [ "self" ], "start_line": 233, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_flib.py", "nloc": 8, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 246, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , fortran_libraries )", "filename": "build_flib.py", "nloc": 25, "complexity": 10, "token_count": 181, "parameters": [ "self", "fortran_libraries" ], "start_line": 259, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 100, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 312, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "to_object", "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 89, "parameters": [ "self", "dirty_files", "module_dirs", "temp_dir" ], "start_line": 337, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "source_to_object_names", "long_name": "source_to_object_names( self , source_files , temp_dir = '' )", "filename": "build_flib.py", "nloc": 6, "complexity": 1, "token_count": 89, "parameters": [ "self", "source_files", "temp_dir" ], "start_line": 354, "end_line": 359, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "source_and_object_pairs", "long_name": "source_and_object_pairs( self , source_files , temp_dir = '' )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "self", "source_files", "temp_dir" ], "start_line": 361, "end_line": 364, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f_compile", "long_name": "f_compile( self , compiler , switches , source_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 20, "complexity": 4, "token_count": 147, "parameters": [ "self", "compiler", "switches", "source_files", "module_dirs", "temp_dir" ], "start_line": 366, "end_line": 388, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "f90_compile", "long_name": "f90_compile( self , source_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self", "source_files", "module_dirs", "temp_dir" ], "start_line": 392, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f77_compile", "long_name": "f77_compile( self , source_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self", "source_files", "module_dirs", "temp_dir" ], "start_line": 397, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "module_dirs" ], "start_line": 402, "end_line": 403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "create_static_lib", "long_name": "create_static_lib( self , object_files , library_name , output_dir = '' , debug = None , skip_ranlib = 0 )", "filename": "build_flib.py", "nloc": 19, "complexity": 6, "token_count": 138, "parameters": [ "self", "object_files", "library_name", "output_dir", "debug", "skip_ranlib" ], "start_line": 405, "end_line": 424, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "build_library", "long_name": "build_library( self , library_name , source_list , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 21, "complexity": 6, "token_count": 149, "parameters": [ "self", "library_name", "source_list", "module_dirs", "temp_dir" ], "start_line": 426, "end_line": 466, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "dummy_fortran_files", "long_name": "dummy_fortran_files( self )", "filename": "build_flib.py", "nloc": 8, "complexity": 1, "token_count": 69, "parameters": [ "self" ], "start_line": 468, "end_line": 475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "is_available", "long_name": "is_available( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 477, "end_line": 478, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_version", "long_name": "get_version( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 4, "token_count": 130, "parameters": [ "self" ], "start_line": 480, "end_line": 503, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 505, "end_line": 506, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 507, "end_line": 508, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 509, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 511, "end_line": 512, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 1, "complexity": 1, "token_count": 6, "parameters": [ "self" ], "start_line": 513, "end_line": 518, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 520, "end_line": 521, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 31, "complexity": 5, "token_count": 185, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 529, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 6, "complexity": 3, "token_count": 27, "parameters": [ "self", "module_dirs" ], "start_line": 570, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 577, "end_line": 578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 106, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 592, "end_line": 616, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 6, "complexity": 3, "token_count": 27, "parameters": [ "self", "module_dirs" ], "start_line": 619, "end_line": 624, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "find_lib_dir", "long_name": "find_lib_dir( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 108, "parameters": [ "self" ], "start_line": 626, "end_line": 641, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 642, "end_line": 643, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 644, "end_line": 645, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 100, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 654, "end_line": 675, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "module_dirs" ], "start_line": 678, "end_line": 680, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "find_lib_dir", "long_name": "find_lib_dir( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 681, "end_line": 683, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 684, "end_line": 685, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 686, "end_line": 687, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 95, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 694, "end_line": 713, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "get_version", "long_name": "get_version( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 5, "token_count": 125, "parameters": [ "self" ], "start_line": 715, "end_line": 733, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 24, "complexity": 7, "token_count": 156, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 741, "end_line": 772, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 21, "complexity": 10, "token_count": 117, "parameters": [ "self" ], "start_line": 774, "end_line": 796, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "find_lib_directories", "long_name": "find_lib_directories( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 4, "token_count": 98, "parameters": [ "self" ], "start_line": 798, "end_line": 815, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 7, "complexity": 4, "token_count": 51, "parameters": [ "self" ], "start_line": 817, "end_line": 824, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 5, "complexity": 3, "token_count": 39, "parameters": [ "self" ], "start_line": 826, "end_line": 834, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "f90_compile", "long_name": "f90_compile( self , source_files , module_files , temp_dir = '' )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "source_files", "module_files", "temp_dir" ], "start_line": 836, "end_line": 837, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 22, "complexity": 5, "token_count": 148, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 847, "end_line": 875, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 15, "complexity": 7, "token_count": 85, "parameters": [ "self" ], "start_line": 877, "end_line": 891, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 894, "end_line": 895, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 39, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 905, "end_line": 908, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 108, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 916, "end_line": 935, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 937, "end_line": 939, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 941, "end_line": 942, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 24, "complexity": 6, "token_count": 116, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 956, "end_line": 984, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 990, "end_line": 991, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 20, "complexity": 5, "token_count": 136, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 1000, "end_line": 1024, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 1028, "end_line": 1029, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 14, "complexity": 3, "token_count": 99, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 1037, "end_line": 1059, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 1061, "end_line": 1064, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 1066, "end_line": 1067, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 18, "complexity": 4, "token_count": 129, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 1084, "end_line": 1107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 1109, "end_line": 1111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "match_extension", "long_name": "match_extension( files , ext )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 44, "parameters": [ "files", "ext" ], "start_line": 1114, "end_line": 1116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "get_f77_files", "long_name": "get_f77_files( files )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "files" ], "start_line": 1118, "end_line": 1119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "get_f90_files", "long_name": "get_f90_files( files )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "files" ], "start_line": 1121, "end_line": 1122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "get_fortran_files", "long_name": "get_fortran_files( files )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "files" ], "start_line": 1124, "end_line": 1125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "find_fortran_compiler", "long_name": "find_fortran_compiler( vendor = None , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 10, "complexity": 5, "token_count": 65, "parameters": [ "vendor", "fc", "f90c", "verbose" ], "start_line": 1127, "end_line": 1137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 110, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 592, "end_line": 617, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 651, "end_line": 652, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "find_lib_dir", "long_name": "find_lib_dir( self )", "filename": "build_flib.py", "nloc": 18, "complexity": 4, "token_count": 122, "parameters": [ "self" ], "start_line": 626, "end_line": 643, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "find_fortran_compiler", "long_name": "find_fortran_compiler( vendor = None , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 8, "complexity": 5, "token_count": 60, "parameters": [ "vendor", "fc", "f90c", "verbose" ], "start_line": 1134, "end_line": 1142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 648, "end_line": 649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "nloc": 830, "complexity": 207, "token_count": 4932, "diff_parsed": { "added": [ " ver_match = r'f90: (Forte Developer 7 Fortran 95|Sun) (?P[^\\s*,]*)'", " self.f77_switches = ' -pic'", " self.f77_opt = ' -fast -dalign -xtarget=generic -R/opt/SUNWspro/lib'", " self.f90_opt = ' -fast -dalign -xtarget=generic -R/opt/SUNWspro/lib'", " self.libraries = ['fsu', 'F77', 'M77', 'sunmath',", " 'mvec', 'f77compat', 'm']", " library_dirs = [\"/opt/SUNWspro/prod/lib\"]", " if libs[0] == \"(null)\":", " del libs[0]", "", "", " return [\"-Bdynamic\", \"-G\"]", "", " def get_linker_so(self):", " return [self.f77_compiler]", " return compiler", " return None" ], "deleted": [ " ver_match = r'f90: Sun (?P[^\\s*,]*)'", " self.f77_switches = ' -pic '", " self.f77_opt = ' -fast -dalign '", " self.f90_opt = ' -fast -dalign '", " self.libraries = ['fsu', 'F77', 'M77', 'sunmath', 'm']", " #print 'sun:',self.library_dirs", " library_dirs = []", " return ['-mimpure-text']", " fcompiler = None", " fcompiler = compiler", " break", " return fcompiler" ] } } ] }, { "hash": "3bfc473f92dbf3827c02d0e0950658dc95ee19e6", "msg": "dolled up some of the comments", "author": { "name": "skip", "email": "skip@localhost" }, "committer": { "name": "skip", "email": "skip@localhost" }, "author_date": "2002-09-17T12:52:14+00:00", "author_timezone": 0, "committer_date": "2002-09-17T12:52:14+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "51b6df86d02200d48bc84349be34629e00e48784" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 5, "insertions": 21, "lines": 26, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_distutils/command/build_flib.py", "new_path": "scipy_distutils/command/build_flib.py", "filename": "build_flib.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -584,11 +584,27 @@ def get_extra_link_args(self):\n \n \n class sun_fortran_compiler(fortran_compiler_base):\n-\n+ \"\"\"specify/detect settings for Sun's Forte compiler\n+\n+ Recent Sun Fortran compilers are FORTRAN 90/95 beasts. F77 support is\n+ handled by the same compiler, so even if you are asking for F77 you're\n+ getting a FORTRAN 95 compiler. Since most (all?) the code currently\n+ being compiled for SciPy is FORTRAN 77 code, the list of libraries\n+ contains various F77-related libraries. Not sure what would happen if\n+ you tried to actually compile and link FORTRAN 95 code with these\n+ settings.\n+\n+ Note also that the 'Forte' name is passe. Sun's latest compiler is\n+ named 'Sun ONE Studio 7, Compiler Collection'. Heaven only knows what\n+ the version string for that baby will be.\n+ \"\"\"\n+ \n vendor = 'Sun'\n+\n+ # old compiler - any idea what the proper flags would be?\n #ver_match = r'f77: (?P[^\\s*,]*)'\n- ver_match = r'f90: (Forte Developer 7 Fortran 95|Sun) (?P[^\\s*,]*)'\n \n+ ver_match = r'f90: (Forte Developer 7 Fortran 95|Sun) (?P[^\\s*,]*)'\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n \n@@ -597,17 +613,17 @@ def __init__(self, fc=None, f90c=None, verbose=0):\n if f90c is None:\n f90c = 'f90'\n \n- self.f77_compiler = fc # not tested\n+ self.f77_compiler = fc\n self.f77_switches = ' -pic'\n self.f77_opt = ' -fast -dalign -xtarget=generic -R/opt/SUNWspro/lib'\n \n self.f90_compiler = f90c\n- self.f90_switches = ' -fixed ' # ??? why fixed?\n+ # -fixed specifies fixed-format instead of free-format F90/95 code\n+ self.f90_switches = ' -fixed -pic'\n self.f90_opt = ' -fast -dalign -xtarget=generic -R/opt/SUNWspro/lib'\n \n self.ver_cmd = self.f90_compiler + ' -V'\n \n- #self.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\n self.libraries = ['fsu', 'F77', 'M77', 'sunmath',\n 'mvec', 'f77compat', 'm']\n \n", "added_lines": 21, "deleted_lines": 5, "source_code": "\"\"\" Implements the build_flib command which should go into Distutils\n at some point.\n \n Note:\n Right now, we're dynamically linking to the Fortran libraries on \n some platforms (Sun for sure). This is fine for local installations\n but a bad thing for redistribution because these libraries won't\n live on any machine that doesn't have a fortran compiler installed.\n It is pretty hard (impossible?) to get gcc to pass the right compiler\n flags on Sun to get the linker to use static libs for the fortran\n stuff. Investigate further...\n\nBugs:\n *** Options -e and -x have no effect when used with --help-compiler\n options. E.g. \n ./setup.py build_flib --help-compiler -e g77-3.0\n finds g77-2.95.\n How to extract these options inside the show_compilers function?\n *** compiler.is_available() method may not work correctly on nt\n because of lack of knowledge how to get exit status in\n run_command function. However, it may give reasonable results\n based on a version string.\n *** Some vendors provide different compilers for F77 and F90\n compilations. Currently, checking the availability of these\n compilers is based on only checking the availability of the\n corresponding F77 compiler. If it exists, then F90 is assumed\n to exist also.\n *** F compiler from Fortran Compiler is _not_ supported, though it\n is defined below. The reasons is that this F95 compiler is\n incomplete: it does not support external procedures\n that are needed to facilitate calling F90 module routines\n from C and subsequently from Python. See also\n http://cens.ioc.ee/pipermail/f2py-users/2002-May/000265.html\n\nOpen issues:\n *** User-defined compiler flags. Do we need --fflags?\n\nFortran compilers (as to be used with --fcompiler= option):\n Absoft\n Sun\n SGI\n Intel\n Itanium\n NAG\n Compaq\n Digital\n Gnu\n VAST\n F [unsupported]\n\"\"\"\n\nimport distutils\nimport distutils.dep_util, distutils.dir_util\nimport os,sys,string\nimport commands,re\nfrom types import *\nfrom distutils.ccompiler import CCompiler,gen_preprocess_options\nfrom distutils.command.build_clib import build_clib\nfrom distutils.errors import *\nfrom scipy_distutils.misc_util import red_text,green_text,yellow_text,\\\n cyan_text\n\nclass FortranCompilerError (CCompilerError):\n \"\"\"Some compile/link operation failed.\"\"\"\nclass FortranCompileError (FortranCompilerError):\n \"\"\"Failure to compile one or more Fortran source files.\"\"\"\nclass FortranBuildError (FortranCompilerError):\n \"\"\"Failure to build Fortran library.\"\"\"\n\nif os.name == 'nt':\n def run_command(command):\n \"\"\" not sure how to get exit status on nt. \"\"\"\n in_pipe,out_pipe = os.popen4(command)\n in_pipe.close()\n text = out_pipe.read()\n return 0, text\nelse:\n run_command = commands.getstatusoutput\n\ndef show_compilers():\n for compiler_class in all_compilers:\n compiler = compiler_class()\n if compiler.is_available():\n print cyan_text(compiler)\n\nclass build_flib (build_clib):\n\n description = \"build f77/f90 libraries used by Python extensions\"\n\n user_options = [\n ('build-flib', 'b',\n \"directory to build f77/f90 libraries to\"),\n ('build-temp', 't',\n \"directory to put temporary build by-products\"),\n ('debug', 'g',\n \"compile with debugging information\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ('fcompiler=', 'c',\n \"specify the compiler type\"),\n ('fcompiler-exec=', 'e',\n \"specify the path to F77 compiler\"),\n ('f90compiler-exec=', 'x',\n \"specify the path to F90 compiler\"),\n ]\n\n boolean_options = ['debug', 'force']\n\n help_options = [\n ('help-compiler', None,\n \"list available compilers\", show_compilers),\n ]\n\n def initialize_options (self):\n\n self.build_flib = None\n self.build_temp = None\n\n self.fortran_libraries = None\n self.define = None\n self.undef = None\n self.debug = None\n self.force = 0\n self.fcompiler = None\n self.fcompiler_exec = None\n self.f90compiler_exec = None\n\n # initialize_options()\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_flib'),\n ('build_temp', 'build_temp'),\n ('debug', 'debug'),\n ('force', 'force'))\n\n self.announce('running find_fortran_compiler')\n fc = find_fortran_compiler(self.fcompiler,\n self.fcompiler_exec,\n self.f90compiler_exec,\n verbose = self.verbose)\n if not fc:\n raise DistutilsOptionError, 'Fortran compiler not available: %s'\\\n % (self.fcompiler)\n else:\n self.announce('using '+cyan_text('%s Fortran compiler' % fc))\n self.fcompiler = fc\n if self.has_f_libraries():\n self.fortran_libraries = self.distribution.fortran_libraries\n self.check_library_list(self.fortran_libraries)\n \n # finalize_options()\n\n def has_f_libraries(self):\n return self.distribution.fortran_libraries \\\n and len(self.distribution.fortran_libraries) > 0\n\n def run (self):\n if not self.has_f_libraries():\n return\n self.build_libraries(self.fortran_libraries)\n\n # run ()\n\n def has_f_library(self,name):\n if self.has_f_libraries():\n # If self.fortran_libraries is None at this point\n # then it means that build_flib was called before\n # build. Always call build before build_flib.\n for (lib_name, build_info) in self.fortran_libraries:\n if lib_name == name:\n return 1\n \n def get_library_names(self, name=None):\n if not self.has_f_libraries():\n return None\n\n lib_names = []\n\n if name is None:\n for (lib_name, build_info) in self.fortran_libraries:\n lib_names.append(lib_name)\n\n if self.fcompiler is not None:\n lib_names.extend(self.fcompiler.get_libraries())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n for n in build_info.get('libraries',[]):\n lib_names.append(n)\n #XXX: how to catch recursive calls here?\n lib_names.extend(self.get_library_names(n))\n break\n return lib_names\n\n def get_fcompiler_library_names(self):\n #if not self.has_f_libraries():\n # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_libraries()\n return []\n\n def get_fcompiler_library_dirs(self):\n #if not self.has_f_libraries():\n # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_library_dirs()\n return []\n\n # get_library_names ()\n\n def get_library_dirs(self, name=None):\n if not self.has_f_libraries():\n return []\n\n lib_dirs = [] \n\n if name is None:\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_library_dirs())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n lib_dirs.extend(build_info.get('library_dirs',[]))\n for n in build_info.get('libraries',[]):\n lib_dirs.extend(self.get_library_dirs(n))\n break\n\n return lib_dirs\n\n # get_library_dirs ()\n\n def get_runtime_library_dirs(self):\n #if not self.has_f_libraries():\n # return []\n\n lib_dirs = []\n\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_runtime_library_dirs())\n \n return lib_dirs\n\n # get_library_dirs ()\n\n def get_source_files (self):\n if not self.has_f_libraries():\n return []\n\n self.check_library_list(self.fortran_libraries)\n filenames = []\n\n # Gets source files specified \n for ext in self.fortran_libraries:\n filenames.extend(ext[1]['sources'])\n\n return filenames \n \n def build_libraries (self, fortran_libraries):\n \n fcompiler = self.fcompiler\n \n for (lib_name, build_info) in fortran_libraries:\n self.announce(\" building '%s' library\" % lib_name)\n\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'fortran_libraries' option (library '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % lib_name\n sources = list(sources)\n module_dirs = build_info.get('module_dirs')\n module_files = build_info.get('module_files')\n\n\n include_dirs = build_info.get('include_dirs')\n\n if include_dirs:\n fcompiler.set_include_dirs(include_dirs)\n for n,v in build_info.get('define_macros') or []:\n fcompiler.define_macro(n,v)\n for n in build_info.get('undef_macros') or []:\n fcompiler.undefine_macro(n)\n\n if module_files:\n fcompiler.build_library(lib_name, module_files,\n temp_dir=self.build_temp)\n \n fcompiler.build_library(lib_name, sources,\n module_dirs, temp_dir=self.build_temp)\n\n # for loop\n\n # build_libraries ()\n\nclass fortran_compiler_base(CCompiler):\n\n vendor = None\n ver_match = None\n\n compiler_type = 'fortran'\n executables = {}\n\n compile_switch = ' -c '\n object_switch = ' -o '\n lib_prefix = 'lib'\n lib_suffix = '.a'\n lib_ar = 'ar -cur '\n lib_ranlib = 'ranlib '\n\n def __init__(self,verbose=0,dry_run=0,force=0):\n # Default initialization. Constructors of derived classes MUST\n # call this function.\n CCompiler.__init__(self,verbose,dry_run,force)\n\n self.version = None\n \n self.f77_switches = ''\n self.f77_opt = ''\n self.f77_debug = ''\n \n self.f90_switches = ''\n self.f90_opt = ''\n self.f90_debug = ''\n \n #self.libraries = []\n #self.library_dirs = []\n\n if self.vendor is None:\n raise DistutilsInternalError,\\\n '%s must define vendor attribute'%(self.__class__)\n if self.ver_match is None:\n raise DistutilsInternalError,\\\n '%s must define ver_match attribute'%(self.__class__)\n\n def to_object(self,\n dirty_files,\n module_dirs=None,\n temp_dir=''):\n files = string.join(dirty_files)\n f90_files = get_f90_files(dirty_files)\n f77_files = get_f77_files(dirty_files)\n if f90_files != []:\n obj1 = self.f90_compile(f90_files,module_dirs,temp_dir = temp_dir)\n else:\n obj1 = []\n if f77_files != []:\n obj2 = self.f77_compile(f77_files, temp_dir = temp_dir)\n else:\n obj2 = []\n return obj1 + obj2\n\n def source_to_object_names(self,source_files, temp_dir=''):\n file_list = map(lambda x: os.path.basename(x),source_files)\n file_base_ext = map(lambda x: os.path.splitext(x),file_list)\n object_list = map(lambda x: x[0] +'.o',file_base_ext)\n object_files = map(lambda x,td=temp_dir: os.path.join(td,x),object_list)\n return object_files\n \n def source_and_object_pairs(self,source_files, temp_dir=''):\n object_files = self.source_to_object_names(source_files,temp_dir)\n file_pairs = zip(source_files,object_files)\n return file_pairs\n \n def f_compile(self,compiler,switches, source_files,\n module_dirs=None, temp_dir=''):\n\n pp_opts = gen_preprocess_options(self.macros,self.include_dirs)\n\n switches = switches + ' ' + string.join(pp_opts,' ')\n\n module_switch = self.build_module_switch(module_dirs)\n file_pairs = self.source_and_object_pairs(source_files,temp_dir)\n object_files = []\n for source,object in file_pairs:\n if distutils.dep_util.newer(source,object):\n cmd = compiler + ' ' + switches + ' '+\\\n module_switch + \\\n self.compile_switch + source + \\\n self.object_switch + object\n self.announce(yellow_text(cmd))\n failure = os.system(cmd)\n if failure:\n raise FortranCompileError,\\\n 'failure during compile (exit status = %s)' % failure\n object_files.append(object)\n return object_files\n #return all object files to make sure everything is archived \n #return map(lambda x: x[1], file_pairs)\n\n def f90_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f90_switches, self.f90_opt))\n return self.f_compile(self.f90_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n def f77_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f77_switches, self.f77_opt))\n return self.f_compile(self.f77_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n def build_module_switch(self, module_dirs):\n return ''\n\n def create_static_lib(self, object_files, library_name,\n output_dir='', debug=None, skip_ranlib=0):\n lib_file = os.path.join(output_dir,\n self.lib_prefix+library_name+self.lib_suffix)\n objects = string.join(object_files)\n if objects:\n cmd = '%s%s %s' % (self.lib_ar,lib_file,objects)\n self.announce(yellow_text(cmd))\n failure = os.system(cmd)\n if failure:\n raise FortranBuildError,\\\n 'failure during build (exit status = %s)'%failure \n if self.lib_ranlib and not skip_ranlib:\n # Digital,MIPSPro compilers do not have ranlib.\n cmd = '%s %s' %(self.lib_ranlib,lib_file)\n self.announce(yellow_text(cmd))\n failure = os.system(cmd)\n if failure:\n raise FortranBuildError,\\\n 'failure during build (exit status = %s)'%failure \n\n def build_library(self,library_name,source_list,module_dirs=None,\n temp_dir = ''):\n #make sure the temp directory exists before trying to build files\n import distutils.dir_util\n distutils.dir_util.mkpath(temp_dir)\n\n #this compiles the files\n object_list = self.to_object(source_list,\n module_dirs,\n temp_dir)\n\n # actually we need to use all the object file names here to\n # make sure the library is always built. It could occur that an\n # object file exists but hasn't been put in the archive. (happens\n # a lot when builds fail once and are restarted).\n object_list = self.source_to_object_names(source_list, temp_dir)\n\n if os.name == 'nt' or sys.platform[:4] == 'irix':\n # I (pearu) had the same problem on irix646 ...\n # I think we can make this \"bunk\" default as skip_ranlib\n # feature speeds things up.\n # XXX:Need to check if Digital compiler works here.\n\n # This is pure bunk...\n # Windows fails for long argument strings on the command line.\n # if objects is real long (> 2048 chars or so on my machine),\n # the command fails (cmd.exe /e:2048 on w2k).\n # for now we'll split linking into to steps which should work for\n objects = object_list[:]\n while objects:\n #obj,objects = objects[:20],objects[20:]\n i = 0\n obj = []\n while i<1900 and objects:\n i = i + len(objects[0]) + 1\n obj.append(objects[0])\n objects = objects[1:]\n self.create_static_lib(obj,library_name,temp_dir,\n skip_ranlib = len(objects))\n else:\n self.create_static_lib(object_list,library_name,temp_dir)\n\n def dummy_fortran_files(self):\n import tempfile \n d = tempfile.gettempdir()\n dummy_name = os.path.join(d,'__dummy.f')\n dummy = open(dummy_name,'w')\n dummy.write(\" subroutine dummy()\\n end\\n\")\n dummy.close()\n return (os.path.join(d,'__dummy.f'),os.path.join(d,'__dummy.o'))\n \n def is_available(self):\n return self.get_version()\n \n def get_version(self):\n \"\"\"Return the compiler version. If compiler is not available,\n return empty string.\"\"\"\n # XXX: Is there compilers that have no version? If yes,\n # this test will fail even if the compiler is available.\n if self.version is not None:\n # Finding version is expensive, so return previously found\n # version string.\n return self.version\n self.version = ''\n # works I think only for unix...\n #if self.verbose:\n self.announce('detecting %s Fortran compiler...'%(self.vendor))\n self.announce(yellow_text(self.ver_cmd))\n exit_status, out_text = run_command(self.ver_cmd)\n out_text2 = out_text.split('\\n')[0]\n if not exit_status:\n self.announce('found %s' %(green_text(out_text2)))\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\n else:\n self.announce('%s: %s' % (exit_status,red_text(out_text2)))\n return self.version\n\n def get_libraries(self):\n return self.libraries\n def get_library_dirs(self):\n return self.library_dirs\n def get_extra_link_args(self):\n return []\n def get_runtime_library_dirs(self):\n return []\n def get_linker_so(self):\n \"\"\"\n If a compiler requires specific linker then return a list\n containing a linker executable name and linker options.\n Otherwise, return None.\n \"\"\"\n\n def __str__(self):\n return \"%s %s\" % (self.vendor, self.get_version())\n\n\nclass absoft_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Absoft'\n ver_match = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n # got rid of -B108 cause it was generating 2 underscores instead\n # of one on the newest version. Now we use -YEXT_SFX=_ to \n # specify the output format\n if os.name == 'nt':\n self.f90_switches = '-f fixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -Q100'\n self.f77_switches = '-N22 -N90 -N110'\n self.f77_opt = '-O -Q100'\n self.libraries = ['fio', 'fmath', 'f90math', 'COMDLG32']\n else:\n self.f90_switches = '-ffixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -B101' \n self.f77_switches = '-N22 -N90 -N110 -B108'\n self.f77_opt = '-O -B101'\n\n self.libraries = ['fio', 'f77math', 'f90math']\n \n try:\n dir = os.environ['ABSOFT'] \n self.library_dirs = [os.path.join(dir,'lib')]\n except KeyError:\n self.library_dirs = []\n\n self.ver_cmd = self.f77_compiler + ' -V -c %s -o %s' % \\\n self.dummy_fortran_files()\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -p' + mod\n return res\n\n def get_extra_link_args(self):\n return []\n # Couldn't get this to link for anything using gcc.\n #dr = \"c:\\\\Absoft62\\\\lib\"\n #libs = ['fio.lib', 'COMDLG32.lib','fmath.lib', 'f90math.lib','libcomdlg32.a' ] \n #libs = map(lambda x,dr=dr:os.path.join(dr,x),libs)\n #return libs\n\n\nclass sun_fortran_compiler(fortran_compiler_base):\n \"\"\"specify/detect settings for Sun's Forte compiler\n\n Recent Sun Fortran compilers are FORTRAN 90/95 beasts. F77 support is\n handled by the same compiler, so even if you are asking for F77 you're\n getting a FORTRAN 95 compiler. Since most (all?) the code currently\n being compiled for SciPy is FORTRAN 77 code, the list of libraries\n contains various F77-related libraries. Not sure what would happen if\n you tried to actually compile and link FORTRAN 95 code with these\n settings.\n\n Note also that the 'Forte' name is passe. Sun's latest compiler is\n named 'Sun ONE Studio 7, Compiler Collection'. Heaven only knows what\n the version string for that baby will be.\n \"\"\"\n \n vendor = 'Sun'\n\n # old compiler - any idea what the proper flags would be?\n #ver_match = r'f77: (?P[^\\s*,]*)'\n\n ver_match = r'f90: (Forte Developer 7 Fortran 95|Sun) (?P[^\\s*,]*)'\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f77_switches = ' -pic'\n self.f77_opt = ' -fast -dalign -xtarget=generic -R/opt/SUNWspro/lib'\n\n self.f90_compiler = f90c\n # -fixed specifies fixed-format instead of free-format F90/95 code\n self.f90_switches = ' -fixed -pic'\n self.f90_opt = ' -fast -dalign -xtarget=generic -R/opt/SUNWspro/lib'\n\n self.ver_cmd = self.f90_compiler + ' -V'\n\n self.libraries = ['fsu', 'F77', 'M77', 'sunmath',\n 'mvec', 'f77compat', 'm']\n \n #threaded\n #self.libraries = ['f90', 'F77_mt', 'sunmath_mt', 'm', 'thread']\n #self.libraries = []\n self.library_dirs = self.find_lib_dir()\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -M' + mod\n return res\n\n def find_lib_dir(self):\n library_dirs = [\"/opt/SUNWspro/prod/lib\"]\n lib_match = r'### f90: Note: LD_RUN_PATH\\s*= '\\\n '(?P[^\\s.]*).*'\n cmd = self.f90_compiler + ' -dryrun dummy.f'\n self.announce(yellow_text(cmd))\n exit_status, output = run_command(cmd)\n if not exit_status:\n libs = re.findall(lib_match,output)\n if libs[0] == \"(null)\":\n del libs[0]\n if libs:\n library_dirs = string.split(libs[0],':')\n self.get_version() # force version calculation\n compiler_home = os.path.dirname(library_dirs[0])\n library_dirs.append(os.path.join(compiler_home,\n self.version,'lib'))\n return library_dirs\n\n def get_runtime_library_dirs(self):\n return self.find_lib_dir()\n\n def get_extra_link_args(self):\n return [\"-Bdynamic\", \"-G\"]\n\n def get_linker_so(self):\n return [self.f77_compiler]\n\n\nclass mips_fortran_compiler(fortran_compiler_base):\n\n vendor = 'SGI'\n ver_match = r'MIPSpro Compilers: Version (?P[^\\s*,]*)'\n lib_ranlib = '' # XXX: should we use `ar -s' here?\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f77_switches = ' -n32 -KPIC '\n self.f77_opt = ' -O3 '\n\n self.f90_compiler = f90c\n self.f90_switches = ' -n32 -KPIC -fixedform ' # why fixed ???\n self.f90_opt = ' ' \n\n self.ver_cmd = self.f77_compiler + ' -version '\n\n #self.libraries = ['fortran', 'ftn', 'm']\n # -lfortran is redundant with MIPSPro 7.30\n self.libraries = ['ftn', 'm']\n self.library_dirs = self.find_lib_dir()\n\n\n def build_module_switch(self,module_dirs):\n res = ''\n return res \n def find_lib_dir(self):\n library_dirs = []\n return library_dirs\n def get_runtime_library_dirs(self):\n\treturn self.find_lib_dir() \n def get_extra_link_args(self):\n\treturn []\n\nclass hpux_fortran_compiler(fortran_compiler_base):\n\n vendor = 'HP'\n ver_match = r'HP F90 (?P[^\\s*,]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f90'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f77_switches = ' +pic=long '\n self.f77_opt = ' -O3 '\n\n self.f90_compiler = f90c\n self.f90_switches = ' +pic=long '\n self.f90_opt = ' -O3 '\n\n self.ver_cmd = self.f77_compiler + ' +version '\n\n self.libraries = ['m']\n self.library_dirs = []\n\n def get_version(self):\n if self.version is not None:\n return self.version\n self.version = ''\n self.announce(yellow_text(self.ver_cmd))\n exit_status, out_text = run_command(self.ver_cmd)\n if self.verbose:\n out_text = out_text.split('\\n')[0]\n if exit_status in [0,256]:\n # 256 seems to indicate success on HP-UX but keeping\n # also 0. Or does 0 exit status mean something different\n # in this platform?\n self.announce('found: '+green_text(out_text))\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\n else:\n self.announce('%s: %s' % (exit_status,red_text(out_text)))\n return self.version\n\nclass gnu_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Gnu'\n ver_match = r'GNU Fortran (?P[^\\s*]*)'\n gcc_lib_dir = None\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n\n gcc_lib_dir = self.find_lib_directories()\n if gcc_lib_dir and \\\n os.path.isfile(os.path.join(gcc_lib_dir[0],'libg2c-pic.a')):\n g2c = 'g2c-pic'\n else:\n g2c = 'g2c'\n if sys.platform == 'win32':\n self.libraries = ['gcc',g2c]\n self.library_dirs = gcc_lib_dir\n else:\n # On linux g77 does not need lib_directories to be specified.\n self.libraries = [g2c]\n\n switches = ' -Wall -fno-second-underscore '\n\n if os.name != 'nt':\n switches = switches + ' -fPIC '\n\n self.f77_switches = switches\n self.ver_cmd = self.f77_compiler + ' --version '\n\n self.f77_opt = self.get_opt()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 -funroll-loops '\n \n # only check for more optimization if g77 can handle it.\n if self.get_version():\n if self.version >= '0.5.26': # is gcc >= 3.x.x\n if cpu.is_AthlonK6():\n opt = opt + ' -march=k6 '\n elif cpu.is_AthlonK7():\n opt = opt + ' -march=athlon '\n if cpu.is_i686():\n opt = opt + ' -march=i686 '\n elif cpu.is_i586():\n opt = opt + ' -march=i586 '\n elif cpu.is_i486():\n opt = opt + ' -march=i486 '\n elif cpu.is_i386():\n opt = opt + ' -march=i386 '\n if cpu.is_Intel():\n opt = opt + ' -malign-double -fomit-frame-pointer ' \n return opt\n \n def find_lib_directories(self):\n if self.gcc_lib_dir is not None:\n return self.gcc_lib_dir\n self.announce('running gnu_fortran_compiler.find_lib_directories')\n self.gcc_lib_dir = []\n lib_dir = []\n match = r'Reading specs from (.*)/specs'\n\n # works I think only for unix...\n cmd = '%s -v' % self.f77_compiler\n self.announce(yellow_text(cmd))\n exit_status, out_text = run_command(cmd)\n if not exit_status:\n m = re.findall(match,out_text)\n if m:\n assert len(m)==1,`m`\n self.gcc_lib_dir = m\n return self.gcc_lib_dir\n\n def get_linker_so(self):\n lnk = None\n # win32 linking should be handled by standard linker\n if ((sys.platform != 'win32') and\n (sys.platform != 'cygwin') and\n (os.uname()[0] != 'Darwin')):\n lnk = [self.f77_compiler,'-shared']\n return lnk\n\n def get_extra_link_args(self):\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work.\n args = [] \n if (hasattr(os,'uname') and (os.uname()[0] == 'SunOS')):\n args = ['-mimpure-text']\n return args\n\n def f90_compile(self,source_files,module_files,temp_dir=''):\n raise DistutilsExecError, 'f90 not supported by Gnu'\n\n\n#http://developer.intel.com/software/products/compilers/f50/linux/\nclass intel_ia32_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Intel' # Intel(R) Corporation \n ver_match = r'Intel\\(R\\) Fortran Compiler for 32-bit applications, '\\\n 'Version (?P[^\\s*]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'ifc'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -KPIC '\n\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n if cpu.has_fdiv_bug():\n switches = switches + ' -fdiv_check '\n if cpu.has_f00f_bug():\n switches = switches + ' -0f_check '\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -FI -w90 -w95 '\n\n self.f77_opt = self.f90_opt = self.get_opt()\n \n debug = ' -g -C '\n self.f77_debug = self.f90_debug = debug\n\n self.ver_cmd = self.f77_compiler+' -FI -V -c %s -o %s' %\\\n self.dummy_fortran_files()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 '\n if cpu.is_PentiumPro() or cpu.is_PentiumII():\n opt = opt + ' -tpp6 -xi '\n elif cpu.is_PentiumIII():\n opt = opt + ' -tpp6 '\n elif cpu.is_Pentium():\n opt = opt + ' -tpp5 '\n elif cpu.is_PentiumIV():\n opt = opt + ' -tpp7 -xW '\n elif cpu.has_mmx():\n opt = opt + ' -xM '\n return opt\n \n\n def get_linker_so(self):\n return [self.f77_compiler,'-shared']\n\n\nclass intel_itanium_fortran_compiler(intel_ia32_fortran_compiler):\n\n vendor = 'Itanium'\n ver_match = r'Intel\\(R\\) Fortran 90 Compiler Itanium\\(TM\\) Compiler'\\\n ' for the Itanium\\(TM\\)-based applications,'\\\n ' Version (?P[^\\s*]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n if fc is None:\n fc = 'efc'\n intel_ia32_fortran_compiler.__init__(self, fc, f90c, verbose=verbose)\n\n\nclass nag_fortran_compiler(fortran_compiler_base):\n\n vendor = 'NAG'\n ver_match = r'NAGWare Fortran 95 compiler Release (?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f95'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ''\n debug = ' -g -gline -g90 -nan -C '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -fixed '\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -target=native '\n return opt\n\n def get_linker_so(self):\n return [self.f77_compiler,'-Wl,-shared']\n\n\n# http://www.fortran.com/F/compilers.html\n#\n# We define F compiler here but it is quite useless\n# because it does not support external procedures\n# which are needed for calling F90 module routines\n# through f2py generated wrappers.\nclass f_fortran_compiler(fortran_compiler_base):\n\n vendor = 'F'\n ver_match = r'Fortran Company/NAG F compiler Release (?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'F'\n if f90c is None:\n f90c = 'F'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n self.ver_cmd = self.f90_compiler+' -V '\n\n gnu = gnu_fortran_compiler('g77')\n if not gnu.is_available(): # F compiler requires gcc.\n self.version = ''\n return\n if not self.is_available():\n return\n\n if self.verbose:\n print red_text(\"\"\"\nWARNING: F compiler is unsupported due to its incompleteness.\n Send complaints to its vendor. For adding its support\n to scipy_distutils, it must support external procedures.\n\"\"\")\n\n self.f90_switches = ''\n self.f90_debug = ' -g -gline -g90 -C '\n self.f90_opt = ' -O '\n\n #self.f77_switches = gnu.f77_switches\n #self.f77_debug = gnu.f77_debug\n #self.f77_opt = gnu.f77_opt\n\n def get_linker_so(self):\n return ['gcc','-shared']\n\n\nclass vast_fortran_compiler(fortran_compiler_base):\n\n vendor = 'VAST'\n ver_match = r'\\s*Pacific-Sierra Research vf90 (Personal|Professional)'\\\n '\\s+(?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n d,b = os.path.split(f90c)\n vf90 = os.path.join(d,'v'+b)\n self.ver_cmd = vf90+' -v '\n\n gnu = gnu_fortran_compiler(fc)\n if not gnu.is_available(): # VAST compiler requires g77.\n self.version = ''\n return\n if not self.is_available():\n return\n\n self.f77_switches = gnu.f77_switches\n self.f77_debug = gnu.f77_debug\n self.f77_opt = gnu.f77_opt \n\n # XXX: need f90 switches, debug, opt\n\n def get_linker_so(self):\n return [self.f90_compiler,'-shared']\n\n\nclass compaq_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Compaq'\n ver_match = r'Compaq Fortran (?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'fort'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -assume no2underscore -nomixed_str_len_arg '\n debug = ' -g -check_bounds '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n # XXX: uncomment if required\n #self.libraries = ' -lUfor -lfor -lFutil -lcpml -lots -lc '\n\n # XXX: fix the version showing flag\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -align dcommons -arch host -assume bigarrays'\\\n ' -assume nozsize -math_library fast -tune host '\n return opt\n\n def get_linker_so(self):\n return [self.f77_compiler,'-shared']\n\n\n#http://www.compaq.com/fortran\nclass digital_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Digital'\n ver_match = r'DIGITAL Visual Fortran Optimizing Compiler'\\\n ' Version (?P[^\\s]*).*'\n\n compile_switch = ' /c '\n object_switch = ' /object:'\n lib_prefix = ''\n lib_suffix = '.lib'\n lib_ar = 'lib.exe /OUT:'\n lib_ranlib = ''\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'DF'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n self.ver_cmd = self.f77_compiler+' /what '\n\n if self.is_available():\n #XXX: is this really necessary???\n from distutils.msvccompiler import find_exe\n self.lib_ar = find_exe(\"lib.exe\", self.version) + ' /OUT:'\n\n switches = ' /nologo /MD /W1 /iface:cref /iface=nomixed_str_len_arg '\n debug = ' '\n\n self.f77_switches = ' /f77rtl /fixed ' + switches\n self.f90_switches = switches\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n def get_opt(self):\n # XXX: use also /architecture, see gnu_fortran_compiler\n return ' /Ox '\n\n\ndef match_extension(files,ext):\n match = re.compile(r'.*[.]('+ext+r')\\Z',re.I).match\n return filter(lambda x,match = match: match(x),files)\n\ndef get_f77_files(files):\n return match_extension(files,'for|f77|ftn|f')\n\ndef get_f90_files(files):\n return match_extension(files,'f90|f95')\n\ndef get_fortran_files(files):\n return match_extension(files,'f90|f95|for|f77|ftn|f')\n\ndef find_fortran_compiler(vendor=None, fc=None, f90c=None, verbose=0):\n for compiler_class in all_compilers:\n if vendor is not None and vendor != compiler_class.vendor:\n continue\n #print compiler_class\n compiler = compiler_class(fc,f90c,verbose = verbose)\n if compiler.is_available():\n return compiler\n return None\n\nall_compilers = [absoft_fortran_compiler,\n mips_fortran_compiler,\n sun_fortran_compiler,\n intel_ia32_fortran_compiler,\n intel_itanium_fortran_compiler,\n nag_fortran_compiler,\n compaq_fortran_compiler,\n digital_fortran_compiler,\n vast_fortran_compiler,\n hpux_fortran_compiler,\n f_fortran_compiler,\n gnu_fortran_compiler,\n ]\n\nif __name__ == \"__main__\":\n show_compilers()\n", "source_code_before": "\"\"\" Implements the build_flib command which should go into Distutils\n at some point.\n \n Note:\n Right now, we're dynamically linking to the Fortran libraries on \n some platforms (Sun for sure). This is fine for local installations\n but a bad thing for redistribution because these libraries won't\n live on any machine that doesn't have a fortran compiler installed.\n It is pretty hard (impossible?) to get gcc to pass the right compiler\n flags on Sun to get the linker to use static libs for the fortran\n stuff. Investigate further...\n\nBugs:\n *** Options -e and -x have no effect when used with --help-compiler\n options. E.g. \n ./setup.py build_flib --help-compiler -e g77-3.0\n finds g77-2.95.\n How to extract these options inside the show_compilers function?\n *** compiler.is_available() method may not work correctly on nt\n because of lack of knowledge how to get exit status in\n run_command function. However, it may give reasonable results\n based on a version string.\n *** Some vendors provide different compilers for F77 and F90\n compilations. Currently, checking the availability of these\n compilers is based on only checking the availability of the\n corresponding F77 compiler. If it exists, then F90 is assumed\n to exist also.\n *** F compiler from Fortran Compiler is _not_ supported, though it\n is defined below. The reasons is that this F95 compiler is\n incomplete: it does not support external procedures\n that are needed to facilitate calling F90 module routines\n from C and subsequently from Python. See also\n http://cens.ioc.ee/pipermail/f2py-users/2002-May/000265.html\n\nOpen issues:\n *** User-defined compiler flags. Do we need --fflags?\n\nFortran compilers (as to be used with --fcompiler= option):\n Absoft\n Sun\n SGI\n Intel\n Itanium\n NAG\n Compaq\n Digital\n Gnu\n VAST\n F [unsupported]\n\"\"\"\n\nimport distutils\nimport distutils.dep_util, distutils.dir_util\nimport os,sys,string\nimport commands,re\nfrom types import *\nfrom distutils.ccompiler import CCompiler,gen_preprocess_options\nfrom distutils.command.build_clib import build_clib\nfrom distutils.errors import *\nfrom scipy_distutils.misc_util import red_text,green_text,yellow_text,\\\n cyan_text\n\nclass FortranCompilerError (CCompilerError):\n \"\"\"Some compile/link operation failed.\"\"\"\nclass FortranCompileError (FortranCompilerError):\n \"\"\"Failure to compile one or more Fortran source files.\"\"\"\nclass FortranBuildError (FortranCompilerError):\n \"\"\"Failure to build Fortran library.\"\"\"\n\nif os.name == 'nt':\n def run_command(command):\n \"\"\" not sure how to get exit status on nt. \"\"\"\n in_pipe,out_pipe = os.popen4(command)\n in_pipe.close()\n text = out_pipe.read()\n return 0, text\nelse:\n run_command = commands.getstatusoutput\n\ndef show_compilers():\n for compiler_class in all_compilers:\n compiler = compiler_class()\n if compiler.is_available():\n print cyan_text(compiler)\n\nclass build_flib (build_clib):\n\n description = \"build f77/f90 libraries used by Python extensions\"\n\n user_options = [\n ('build-flib', 'b',\n \"directory to build f77/f90 libraries to\"),\n ('build-temp', 't',\n \"directory to put temporary build by-products\"),\n ('debug', 'g',\n \"compile with debugging information\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ('fcompiler=', 'c',\n \"specify the compiler type\"),\n ('fcompiler-exec=', 'e',\n \"specify the path to F77 compiler\"),\n ('f90compiler-exec=', 'x',\n \"specify the path to F90 compiler\"),\n ]\n\n boolean_options = ['debug', 'force']\n\n help_options = [\n ('help-compiler', None,\n \"list available compilers\", show_compilers),\n ]\n\n def initialize_options (self):\n\n self.build_flib = None\n self.build_temp = None\n\n self.fortran_libraries = None\n self.define = None\n self.undef = None\n self.debug = None\n self.force = 0\n self.fcompiler = None\n self.fcompiler_exec = None\n self.f90compiler_exec = None\n\n # initialize_options()\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_flib'),\n ('build_temp', 'build_temp'),\n ('debug', 'debug'),\n ('force', 'force'))\n\n self.announce('running find_fortran_compiler')\n fc = find_fortran_compiler(self.fcompiler,\n self.fcompiler_exec,\n self.f90compiler_exec,\n verbose = self.verbose)\n if not fc:\n raise DistutilsOptionError, 'Fortran compiler not available: %s'\\\n % (self.fcompiler)\n else:\n self.announce('using '+cyan_text('%s Fortran compiler' % fc))\n self.fcompiler = fc\n if self.has_f_libraries():\n self.fortran_libraries = self.distribution.fortran_libraries\n self.check_library_list(self.fortran_libraries)\n \n # finalize_options()\n\n def has_f_libraries(self):\n return self.distribution.fortran_libraries \\\n and len(self.distribution.fortran_libraries) > 0\n\n def run (self):\n if not self.has_f_libraries():\n return\n self.build_libraries(self.fortran_libraries)\n\n # run ()\n\n def has_f_library(self,name):\n if self.has_f_libraries():\n # If self.fortran_libraries is None at this point\n # then it means that build_flib was called before\n # build. Always call build before build_flib.\n for (lib_name, build_info) in self.fortran_libraries:\n if lib_name == name:\n return 1\n \n def get_library_names(self, name=None):\n if not self.has_f_libraries():\n return None\n\n lib_names = []\n\n if name is None:\n for (lib_name, build_info) in self.fortran_libraries:\n lib_names.append(lib_name)\n\n if self.fcompiler is not None:\n lib_names.extend(self.fcompiler.get_libraries())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n for n in build_info.get('libraries',[]):\n lib_names.append(n)\n #XXX: how to catch recursive calls here?\n lib_names.extend(self.get_library_names(n))\n break\n return lib_names\n\n def get_fcompiler_library_names(self):\n #if not self.has_f_libraries():\n # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_libraries()\n return []\n\n def get_fcompiler_library_dirs(self):\n #if not self.has_f_libraries():\n # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_library_dirs()\n return []\n\n # get_library_names ()\n\n def get_library_dirs(self, name=None):\n if not self.has_f_libraries():\n return []\n\n lib_dirs = [] \n\n if name is None:\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_library_dirs())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n lib_dirs.extend(build_info.get('library_dirs',[]))\n for n in build_info.get('libraries',[]):\n lib_dirs.extend(self.get_library_dirs(n))\n break\n\n return lib_dirs\n\n # get_library_dirs ()\n\n def get_runtime_library_dirs(self):\n #if not self.has_f_libraries():\n # return []\n\n lib_dirs = []\n\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_runtime_library_dirs())\n \n return lib_dirs\n\n # get_library_dirs ()\n\n def get_source_files (self):\n if not self.has_f_libraries():\n return []\n\n self.check_library_list(self.fortran_libraries)\n filenames = []\n\n # Gets source files specified \n for ext in self.fortran_libraries:\n filenames.extend(ext[1]['sources'])\n\n return filenames \n \n def build_libraries (self, fortran_libraries):\n \n fcompiler = self.fcompiler\n \n for (lib_name, build_info) in fortran_libraries:\n self.announce(\" building '%s' library\" % lib_name)\n\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'fortran_libraries' option (library '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % lib_name\n sources = list(sources)\n module_dirs = build_info.get('module_dirs')\n module_files = build_info.get('module_files')\n\n\n include_dirs = build_info.get('include_dirs')\n\n if include_dirs:\n fcompiler.set_include_dirs(include_dirs)\n for n,v in build_info.get('define_macros') or []:\n fcompiler.define_macro(n,v)\n for n in build_info.get('undef_macros') or []:\n fcompiler.undefine_macro(n)\n\n if module_files:\n fcompiler.build_library(lib_name, module_files,\n temp_dir=self.build_temp)\n \n fcompiler.build_library(lib_name, sources,\n module_dirs, temp_dir=self.build_temp)\n\n # for loop\n\n # build_libraries ()\n\nclass fortran_compiler_base(CCompiler):\n\n vendor = None\n ver_match = None\n\n compiler_type = 'fortran'\n executables = {}\n\n compile_switch = ' -c '\n object_switch = ' -o '\n lib_prefix = 'lib'\n lib_suffix = '.a'\n lib_ar = 'ar -cur '\n lib_ranlib = 'ranlib '\n\n def __init__(self,verbose=0,dry_run=0,force=0):\n # Default initialization. Constructors of derived classes MUST\n # call this function.\n CCompiler.__init__(self,verbose,dry_run,force)\n\n self.version = None\n \n self.f77_switches = ''\n self.f77_opt = ''\n self.f77_debug = ''\n \n self.f90_switches = ''\n self.f90_opt = ''\n self.f90_debug = ''\n \n #self.libraries = []\n #self.library_dirs = []\n\n if self.vendor is None:\n raise DistutilsInternalError,\\\n '%s must define vendor attribute'%(self.__class__)\n if self.ver_match is None:\n raise DistutilsInternalError,\\\n '%s must define ver_match attribute'%(self.__class__)\n\n def to_object(self,\n dirty_files,\n module_dirs=None,\n temp_dir=''):\n files = string.join(dirty_files)\n f90_files = get_f90_files(dirty_files)\n f77_files = get_f77_files(dirty_files)\n if f90_files != []:\n obj1 = self.f90_compile(f90_files,module_dirs,temp_dir = temp_dir)\n else:\n obj1 = []\n if f77_files != []:\n obj2 = self.f77_compile(f77_files, temp_dir = temp_dir)\n else:\n obj2 = []\n return obj1 + obj2\n\n def source_to_object_names(self,source_files, temp_dir=''):\n file_list = map(lambda x: os.path.basename(x),source_files)\n file_base_ext = map(lambda x: os.path.splitext(x),file_list)\n object_list = map(lambda x: x[0] +'.o',file_base_ext)\n object_files = map(lambda x,td=temp_dir: os.path.join(td,x),object_list)\n return object_files\n \n def source_and_object_pairs(self,source_files, temp_dir=''):\n object_files = self.source_to_object_names(source_files,temp_dir)\n file_pairs = zip(source_files,object_files)\n return file_pairs\n \n def f_compile(self,compiler,switches, source_files,\n module_dirs=None, temp_dir=''):\n\n pp_opts = gen_preprocess_options(self.macros,self.include_dirs)\n\n switches = switches + ' ' + string.join(pp_opts,' ')\n\n module_switch = self.build_module_switch(module_dirs)\n file_pairs = self.source_and_object_pairs(source_files,temp_dir)\n object_files = []\n for source,object in file_pairs:\n if distutils.dep_util.newer(source,object):\n cmd = compiler + ' ' + switches + ' '+\\\n module_switch + \\\n self.compile_switch + source + \\\n self.object_switch + object\n self.announce(yellow_text(cmd))\n failure = os.system(cmd)\n if failure:\n raise FortranCompileError,\\\n 'failure during compile (exit status = %s)' % failure\n object_files.append(object)\n return object_files\n #return all object files to make sure everything is archived \n #return map(lambda x: x[1], file_pairs)\n\n def f90_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f90_switches, self.f90_opt))\n return self.f_compile(self.f90_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n def f77_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f77_switches, self.f77_opt))\n return self.f_compile(self.f77_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n def build_module_switch(self, module_dirs):\n return ''\n\n def create_static_lib(self, object_files, library_name,\n output_dir='', debug=None, skip_ranlib=0):\n lib_file = os.path.join(output_dir,\n self.lib_prefix+library_name+self.lib_suffix)\n objects = string.join(object_files)\n if objects:\n cmd = '%s%s %s' % (self.lib_ar,lib_file,objects)\n self.announce(yellow_text(cmd))\n failure = os.system(cmd)\n if failure:\n raise FortranBuildError,\\\n 'failure during build (exit status = %s)'%failure \n if self.lib_ranlib and not skip_ranlib:\n # Digital,MIPSPro compilers do not have ranlib.\n cmd = '%s %s' %(self.lib_ranlib,lib_file)\n self.announce(yellow_text(cmd))\n failure = os.system(cmd)\n if failure:\n raise FortranBuildError,\\\n 'failure during build (exit status = %s)'%failure \n\n def build_library(self,library_name,source_list,module_dirs=None,\n temp_dir = ''):\n #make sure the temp directory exists before trying to build files\n import distutils.dir_util\n distutils.dir_util.mkpath(temp_dir)\n\n #this compiles the files\n object_list = self.to_object(source_list,\n module_dirs,\n temp_dir)\n\n # actually we need to use all the object file names here to\n # make sure the library is always built. It could occur that an\n # object file exists but hasn't been put in the archive. (happens\n # a lot when builds fail once and are restarted).\n object_list = self.source_to_object_names(source_list, temp_dir)\n\n if os.name == 'nt' or sys.platform[:4] == 'irix':\n # I (pearu) had the same problem on irix646 ...\n # I think we can make this \"bunk\" default as skip_ranlib\n # feature speeds things up.\n # XXX:Need to check if Digital compiler works here.\n\n # This is pure bunk...\n # Windows fails for long argument strings on the command line.\n # if objects is real long (> 2048 chars or so on my machine),\n # the command fails (cmd.exe /e:2048 on w2k).\n # for now we'll split linking into to steps which should work for\n objects = object_list[:]\n while objects:\n #obj,objects = objects[:20],objects[20:]\n i = 0\n obj = []\n while i<1900 and objects:\n i = i + len(objects[0]) + 1\n obj.append(objects[0])\n objects = objects[1:]\n self.create_static_lib(obj,library_name,temp_dir,\n skip_ranlib = len(objects))\n else:\n self.create_static_lib(object_list,library_name,temp_dir)\n\n def dummy_fortran_files(self):\n import tempfile \n d = tempfile.gettempdir()\n dummy_name = os.path.join(d,'__dummy.f')\n dummy = open(dummy_name,'w')\n dummy.write(\" subroutine dummy()\\n end\\n\")\n dummy.close()\n return (os.path.join(d,'__dummy.f'),os.path.join(d,'__dummy.o'))\n \n def is_available(self):\n return self.get_version()\n \n def get_version(self):\n \"\"\"Return the compiler version. If compiler is not available,\n return empty string.\"\"\"\n # XXX: Is there compilers that have no version? If yes,\n # this test will fail even if the compiler is available.\n if self.version is not None:\n # Finding version is expensive, so return previously found\n # version string.\n return self.version\n self.version = ''\n # works I think only for unix...\n #if self.verbose:\n self.announce('detecting %s Fortran compiler...'%(self.vendor))\n self.announce(yellow_text(self.ver_cmd))\n exit_status, out_text = run_command(self.ver_cmd)\n out_text2 = out_text.split('\\n')[0]\n if not exit_status:\n self.announce('found %s' %(green_text(out_text2)))\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\n else:\n self.announce('%s: %s' % (exit_status,red_text(out_text2)))\n return self.version\n\n def get_libraries(self):\n return self.libraries\n def get_library_dirs(self):\n return self.library_dirs\n def get_extra_link_args(self):\n return []\n def get_runtime_library_dirs(self):\n return []\n def get_linker_so(self):\n \"\"\"\n If a compiler requires specific linker then return a list\n containing a linker executable name and linker options.\n Otherwise, return None.\n \"\"\"\n\n def __str__(self):\n return \"%s %s\" % (self.vendor, self.get_version())\n\n\nclass absoft_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Absoft'\n ver_match = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n # got rid of -B108 cause it was generating 2 underscores instead\n # of one on the newest version. Now we use -YEXT_SFX=_ to \n # specify the output format\n if os.name == 'nt':\n self.f90_switches = '-f fixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -Q100'\n self.f77_switches = '-N22 -N90 -N110'\n self.f77_opt = '-O -Q100'\n self.libraries = ['fio', 'fmath', 'f90math', 'COMDLG32']\n else:\n self.f90_switches = '-ffixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -B101' \n self.f77_switches = '-N22 -N90 -N110 -B108'\n self.f77_opt = '-O -B101'\n\n self.libraries = ['fio', 'f77math', 'f90math']\n \n try:\n dir = os.environ['ABSOFT'] \n self.library_dirs = [os.path.join(dir,'lib')]\n except KeyError:\n self.library_dirs = []\n\n self.ver_cmd = self.f77_compiler + ' -V -c %s -o %s' % \\\n self.dummy_fortran_files()\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -p' + mod\n return res\n\n def get_extra_link_args(self):\n return []\n # Couldn't get this to link for anything using gcc.\n #dr = \"c:\\\\Absoft62\\\\lib\"\n #libs = ['fio.lib', 'COMDLG32.lib','fmath.lib', 'f90math.lib','libcomdlg32.a' ] \n #libs = map(lambda x,dr=dr:os.path.join(dr,x),libs)\n #return libs\n\n\nclass sun_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Sun'\n #ver_match = r'f77: (?P[^\\s*,]*)'\n ver_match = r'f90: (Forte Developer 7 Fortran 95|Sun) (?P[^\\s*,]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc # not tested\n self.f77_switches = ' -pic'\n self.f77_opt = ' -fast -dalign -xtarget=generic -R/opt/SUNWspro/lib'\n\n self.f90_compiler = f90c\n self.f90_switches = ' -fixed ' # ??? why fixed?\n self.f90_opt = ' -fast -dalign -xtarget=generic -R/opt/SUNWspro/lib'\n\n self.ver_cmd = self.f90_compiler + ' -V'\n\n #self.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\n self.libraries = ['fsu', 'F77', 'M77', 'sunmath',\n 'mvec', 'f77compat', 'm']\n \n #threaded\n #self.libraries = ['f90', 'F77_mt', 'sunmath_mt', 'm', 'thread']\n #self.libraries = []\n self.library_dirs = self.find_lib_dir()\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -M' + mod\n return res\n\n def find_lib_dir(self):\n library_dirs = [\"/opt/SUNWspro/prod/lib\"]\n lib_match = r'### f90: Note: LD_RUN_PATH\\s*= '\\\n '(?P[^\\s.]*).*'\n cmd = self.f90_compiler + ' -dryrun dummy.f'\n self.announce(yellow_text(cmd))\n exit_status, output = run_command(cmd)\n if not exit_status:\n libs = re.findall(lib_match,output)\n if libs[0] == \"(null)\":\n del libs[0]\n if libs:\n library_dirs = string.split(libs[0],':')\n self.get_version() # force version calculation\n compiler_home = os.path.dirname(library_dirs[0])\n library_dirs.append(os.path.join(compiler_home,\n self.version,'lib'))\n return library_dirs\n\n def get_runtime_library_dirs(self):\n return self.find_lib_dir()\n\n def get_extra_link_args(self):\n return [\"-Bdynamic\", \"-G\"]\n\n def get_linker_so(self):\n return [self.f77_compiler]\n\n\nclass mips_fortran_compiler(fortran_compiler_base):\n\n vendor = 'SGI'\n ver_match = r'MIPSpro Compilers: Version (?P[^\\s*,]*)'\n lib_ranlib = '' # XXX: should we use `ar -s' here?\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f77_switches = ' -n32 -KPIC '\n self.f77_opt = ' -O3 '\n\n self.f90_compiler = f90c\n self.f90_switches = ' -n32 -KPIC -fixedform ' # why fixed ???\n self.f90_opt = ' ' \n\n self.ver_cmd = self.f77_compiler + ' -version '\n\n #self.libraries = ['fortran', 'ftn', 'm']\n # -lfortran is redundant with MIPSPro 7.30\n self.libraries = ['ftn', 'm']\n self.library_dirs = self.find_lib_dir()\n\n\n def build_module_switch(self,module_dirs):\n res = ''\n return res \n def find_lib_dir(self):\n library_dirs = []\n return library_dirs\n def get_runtime_library_dirs(self):\n\treturn self.find_lib_dir() \n def get_extra_link_args(self):\n\treturn []\n\nclass hpux_fortran_compiler(fortran_compiler_base):\n\n vendor = 'HP'\n ver_match = r'HP F90 (?P[^\\s*,]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f90'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f77_switches = ' +pic=long '\n self.f77_opt = ' -O3 '\n\n self.f90_compiler = f90c\n self.f90_switches = ' +pic=long '\n self.f90_opt = ' -O3 '\n\n self.ver_cmd = self.f77_compiler + ' +version '\n\n self.libraries = ['m']\n self.library_dirs = []\n\n def get_version(self):\n if self.version is not None:\n return self.version\n self.version = ''\n self.announce(yellow_text(self.ver_cmd))\n exit_status, out_text = run_command(self.ver_cmd)\n if self.verbose:\n out_text = out_text.split('\\n')[0]\n if exit_status in [0,256]:\n # 256 seems to indicate success on HP-UX but keeping\n # also 0. Or does 0 exit status mean something different\n # in this platform?\n self.announce('found: '+green_text(out_text))\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\n else:\n self.announce('%s: %s' % (exit_status,red_text(out_text)))\n return self.version\n\nclass gnu_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Gnu'\n ver_match = r'GNU Fortran (?P[^\\s*]*)'\n gcc_lib_dir = None\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n\n gcc_lib_dir = self.find_lib_directories()\n if gcc_lib_dir and \\\n os.path.isfile(os.path.join(gcc_lib_dir[0],'libg2c-pic.a')):\n g2c = 'g2c-pic'\n else:\n g2c = 'g2c'\n if sys.platform == 'win32':\n self.libraries = ['gcc',g2c]\n self.library_dirs = gcc_lib_dir\n else:\n # On linux g77 does not need lib_directories to be specified.\n self.libraries = [g2c]\n\n switches = ' -Wall -fno-second-underscore '\n\n if os.name != 'nt':\n switches = switches + ' -fPIC '\n\n self.f77_switches = switches\n self.ver_cmd = self.f77_compiler + ' --version '\n\n self.f77_opt = self.get_opt()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 -funroll-loops '\n \n # only check for more optimization if g77 can handle it.\n if self.get_version():\n if self.version >= '0.5.26': # is gcc >= 3.x.x\n if cpu.is_AthlonK6():\n opt = opt + ' -march=k6 '\n elif cpu.is_AthlonK7():\n opt = opt + ' -march=athlon '\n if cpu.is_i686():\n opt = opt + ' -march=i686 '\n elif cpu.is_i586():\n opt = opt + ' -march=i586 '\n elif cpu.is_i486():\n opt = opt + ' -march=i486 '\n elif cpu.is_i386():\n opt = opt + ' -march=i386 '\n if cpu.is_Intel():\n opt = opt + ' -malign-double -fomit-frame-pointer ' \n return opt\n \n def find_lib_directories(self):\n if self.gcc_lib_dir is not None:\n return self.gcc_lib_dir\n self.announce('running gnu_fortran_compiler.find_lib_directories')\n self.gcc_lib_dir = []\n lib_dir = []\n match = r'Reading specs from (.*)/specs'\n\n # works I think only for unix...\n cmd = '%s -v' % self.f77_compiler\n self.announce(yellow_text(cmd))\n exit_status, out_text = run_command(cmd)\n if not exit_status:\n m = re.findall(match,out_text)\n if m:\n assert len(m)==1,`m`\n self.gcc_lib_dir = m\n return self.gcc_lib_dir\n\n def get_linker_so(self):\n lnk = None\n # win32 linking should be handled by standard linker\n if ((sys.platform != 'win32') and\n (sys.platform != 'cygwin') and\n (os.uname()[0] != 'Darwin')):\n lnk = [self.f77_compiler,'-shared']\n return lnk\n\n def get_extra_link_args(self):\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work.\n args = [] \n if (hasattr(os,'uname') and (os.uname()[0] == 'SunOS')):\n args = ['-mimpure-text']\n return args\n\n def f90_compile(self,source_files,module_files,temp_dir=''):\n raise DistutilsExecError, 'f90 not supported by Gnu'\n\n\n#http://developer.intel.com/software/products/compilers/f50/linux/\nclass intel_ia32_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Intel' # Intel(R) Corporation \n ver_match = r'Intel\\(R\\) Fortran Compiler for 32-bit applications, '\\\n 'Version (?P[^\\s*]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'ifc'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -KPIC '\n\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n if cpu.has_fdiv_bug():\n switches = switches + ' -fdiv_check '\n if cpu.has_f00f_bug():\n switches = switches + ' -0f_check '\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -FI -w90 -w95 '\n\n self.f77_opt = self.f90_opt = self.get_opt()\n \n debug = ' -g -C '\n self.f77_debug = self.f90_debug = debug\n\n self.ver_cmd = self.f77_compiler+' -FI -V -c %s -o %s' %\\\n self.dummy_fortran_files()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 '\n if cpu.is_PentiumPro() or cpu.is_PentiumII():\n opt = opt + ' -tpp6 -xi '\n elif cpu.is_PentiumIII():\n opt = opt + ' -tpp6 '\n elif cpu.is_Pentium():\n opt = opt + ' -tpp5 '\n elif cpu.is_PentiumIV():\n opt = opt + ' -tpp7 -xW '\n elif cpu.has_mmx():\n opt = opt + ' -xM '\n return opt\n \n\n def get_linker_so(self):\n return [self.f77_compiler,'-shared']\n\n\nclass intel_itanium_fortran_compiler(intel_ia32_fortran_compiler):\n\n vendor = 'Itanium'\n ver_match = r'Intel\\(R\\) Fortran 90 Compiler Itanium\\(TM\\) Compiler'\\\n ' for the Itanium\\(TM\\)-based applications,'\\\n ' Version (?P[^\\s*]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n if fc is None:\n fc = 'efc'\n intel_ia32_fortran_compiler.__init__(self, fc, f90c, verbose=verbose)\n\n\nclass nag_fortran_compiler(fortran_compiler_base):\n\n vendor = 'NAG'\n ver_match = r'NAGWare Fortran 95 compiler Release (?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'f95'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ''\n debug = ' -g -gline -g90 -nan -C '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -fixed '\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -target=native '\n return opt\n\n def get_linker_so(self):\n return [self.f77_compiler,'-Wl,-shared']\n\n\n# http://www.fortran.com/F/compilers.html\n#\n# We define F compiler here but it is quite useless\n# because it does not support external procedures\n# which are needed for calling F90 module routines\n# through f2py generated wrappers.\nclass f_fortran_compiler(fortran_compiler_base):\n\n vendor = 'F'\n ver_match = r'Fortran Company/NAG F compiler Release (?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'F'\n if f90c is None:\n f90c = 'F'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n self.ver_cmd = self.f90_compiler+' -V '\n\n gnu = gnu_fortran_compiler('g77')\n if not gnu.is_available(): # F compiler requires gcc.\n self.version = ''\n return\n if not self.is_available():\n return\n\n if self.verbose:\n print red_text(\"\"\"\nWARNING: F compiler is unsupported due to its incompleteness.\n Send complaints to its vendor. For adding its support\n to scipy_distutils, it must support external procedures.\n\"\"\")\n\n self.f90_switches = ''\n self.f90_debug = ' -g -gline -g90 -C '\n self.f90_opt = ' -O '\n\n #self.f77_switches = gnu.f77_switches\n #self.f77_debug = gnu.f77_debug\n #self.f77_opt = gnu.f77_opt\n\n def get_linker_so(self):\n return ['gcc','-shared']\n\n\nclass vast_fortran_compiler(fortran_compiler_base):\n\n vendor = 'VAST'\n ver_match = r'\\s*Pacific-Sierra Research vf90 (Personal|Professional)'\\\n '\\s+(?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n d,b = os.path.split(f90c)\n vf90 = os.path.join(d,'v'+b)\n self.ver_cmd = vf90+' -v '\n\n gnu = gnu_fortran_compiler(fc)\n if not gnu.is_available(): # VAST compiler requires g77.\n self.version = ''\n return\n if not self.is_available():\n return\n\n self.f77_switches = gnu.f77_switches\n self.f77_debug = gnu.f77_debug\n self.f77_opt = gnu.f77_opt \n\n # XXX: need f90 switches, debug, opt\n\n def get_linker_so(self):\n return [self.f90_compiler,'-shared']\n\n\nclass compaq_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Compaq'\n ver_match = r'Compaq Fortran (?P[^\\s]*)'\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'fort'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -assume no2underscore -nomixed_str_len_arg '\n debug = ' -g -check_bounds '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n # XXX: uncomment if required\n #self.libraries = ' -lUfor -lfor -lFutil -lcpml -lots -lc '\n\n # XXX: fix the version showing flag\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -align dcommons -arch host -assume bigarrays'\\\n ' -assume nozsize -math_library fast -tune host '\n return opt\n\n def get_linker_so(self):\n return [self.f77_compiler,'-shared']\n\n\n#http://www.compaq.com/fortran\nclass digital_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Digital'\n ver_match = r'DIGITAL Visual Fortran Optimizing Compiler'\\\n ' Version (?P[^\\s]*).*'\n\n compile_switch = ' /c '\n object_switch = ' /object:'\n lib_prefix = ''\n lib_suffix = '.lib'\n lib_ar = 'lib.exe /OUT:'\n lib_ranlib = ''\n\n def __init__(self, fc=None, f90c=None, verbose=0):\n fortran_compiler_base.__init__(self, verbose=verbose)\n\n if fc is None:\n fc = 'DF'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n self.ver_cmd = self.f77_compiler+' /what '\n\n if self.is_available():\n #XXX: is this really necessary???\n from distutils.msvccompiler import find_exe\n self.lib_ar = find_exe(\"lib.exe\", self.version) + ' /OUT:'\n\n switches = ' /nologo /MD /W1 /iface:cref /iface=nomixed_str_len_arg '\n debug = ' '\n\n self.f77_switches = ' /f77rtl /fixed ' + switches\n self.f90_switches = switches\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n def get_opt(self):\n # XXX: use also /architecture, see gnu_fortran_compiler\n return ' /Ox '\n\n\ndef match_extension(files,ext):\n match = re.compile(r'.*[.]('+ext+r')\\Z',re.I).match\n return filter(lambda x,match = match: match(x),files)\n\ndef get_f77_files(files):\n return match_extension(files,'for|f77|ftn|f')\n\ndef get_f90_files(files):\n return match_extension(files,'f90|f95')\n\ndef get_fortran_files(files):\n return match_extension(files,'f90|f95|for|f77|ftn|f')\n\ndef find_fortran_compiler(vendor=None, fc=None, f90c=None, verbose=0):\n for compiler_class in all_compilers:\n if vendor is not None and vendor != compiler_class.vendor:\n continue\n #print compiler_class\n compiler = compiler_class(fc,f90c,verbose = verbose)\n if compiler.is_available():\n return compiler\n return None\n\nall_compilers = [absoft_fortran_compiler,\n mips_fortran_compiler,\n sun_fortran_compiler,\n intel_ia32_fortran_compiler,\n intel_itanium_fortran_compiler,\n nag_fortran_compiler,\n compaq_fortran_compiler,\n digital_fortran_compiler,\n vast_fortran_compiler,\n hpux_fortran_compiler,\n f_fortran_compiler,\n gnu_fortran_compiler,\n ]\n\nif __name__ == \"__main__\":\n show_compilers()\n", "methods": [ { "name": "run_command", "long_name": "run_command( command )", "filename": "build_flib.py", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "command" ], "start_line": 71, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "show_compilers", "long_name": "show_compilers( )", "filename": "build_flib.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [], "start_line": 80, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_flib.py", "nloc": 11, "complexity": 1, "token_count": 55, "parameters": [ "self" ], "start_line": 114, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "build_flib.py", "nloc": 20, "complexity": 3, "token_count": 122, "parameters": [ "self" ], "start_line": 130, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "has_f_libraries", "long_name": "has_f_libraries( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 2, "token_count": 23, "parameters": [ "self" ], "start_line": 154, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 22, "parameters": [ "self" ], "start_line": 158, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "has_f_library", "long_name": "has_f_library( self , name )", "filename": "build_flib.py", "nloc": 5, "complexity": 4, "token_count": 32, "parameters": [ "self", "name" ], "start_line": 165, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "get_library_names", "long_name": "get_library_names( self , name = None )", "filename": "build_flib.py", "nloc": 17, "complexity": 8, "token_count": 117, "parameters": [ "self", "name" ], "start_line": 174, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_fcompiler_library_names", "long_name": "get_fcompiler_library_names( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 24, "parameters": [ "self" ], "start_line": 196, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_fcompiler_library_dirs", "long_name": "get_fcompiler_library_dirs( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 24, "parameters": [ "self" ], "start_line": 203, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self , name = None )", "filename": "build_flib.py", "nloc": 15, "complexity": 7, "token_count": 109, "parameters": [ "self", "name" ], "start_line": 212, "end_line": 229, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 5, "complexity": 2, "token_count": 31, "parameters": [ "self" ], "start_line": 233, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_flib.py", "nloc": 8, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 246, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , fortran_libraries )", "filename": "build_flib.py", "nloc": 25, "complexity": 10, "token_count": 181, "parameters": [ "self", "fortran_libraries" ], "start_line": 259, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 100, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 312, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "to_object", "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 89, "parameters": [ "self", "dirty_files", "module_dirs", "temp_dir" ], "start_line": 337, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "source_to_object_names", "long_name": "source_to_object_names( self , source_files , temp_dir = '' )", "filename": "build_flib.py", "nloc": 6, "complexity": 1, "token_count": 89, "parameters": [ "self", "source_files", "temp_dir" ], "start_line": 354, "end_line": 359, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "source_and_object_pairs", "long_name": "source_and_object_pairs( self , source_files , temp_dir = '' )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "self", "source_files", "temp_dir" ], "start_line": 361, "end_line": 364, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f_compile", "long_name": "f_compile( self , compiler , switches , source_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 20, "complexity": 4, "token_count": 147, "parameters": [ "self", "compiler", "switches", "source_files", "module_dirs", "temp_dir" ], "start_line": 366, "end_line": 388, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "f90_compile", "long_name": "f90_compile( self , source_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self", "source_files", "module_dirs", "temp_dir" ], "start_line": 392, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f77_compile", "long_name": "f77_compile( self , source_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self", "source_files", "module_dirs", "temp_dir" ], "start_line": 397, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "module_dirs" ], "start_line": 402, "end_line": 403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "create_static_lib", "long_name": "create_static_lib( self , object_files , library_name , output_dir = '' , debug = None , skip_ranlib = 0 )", "filename": "build_flib.py", "nloc": 19, "complexity": 6, "token_count": 138, "parameters": [ "self", "object_files", "library_name", "output_dir", "debug", "skip_ranlib" ], "start_line": 405, "end_line": 424, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "build_library", "long_name": "build_library( self , library_name , source_list , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 21, "complexity": 6, "token_count": 149, "parameters": [ "self", "library_name", "source_list", "module_dirs", "temp_dir" ], "start_line": 426, "end_line": 466, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "dummy_fortran_files", "long_name": "dummy_fortran_files( self )", "filename": "build_flib.py", "nloc": 8, "complexity": 1, "token_count": 69, "parameters": [ "self" ], "start_line": 468, "end_line": 475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "is_available", "long_name": "is_available( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 477, "end_line": 478, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_version", "long_name": "get_version( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 4, "token_count": 130, "parameters": [ "self" ], "start_line": 480, "end_line": 503, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 505, "end_line": 506, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 507, "end_line": 508, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 509, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 511, "end_line": 512, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 1, "complexity": 1, "token_count": 6, "parameters": [ "self" ], "start_line": 513, "end_line": 518, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 520, "end_line": 521, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 31, "complexity": 5, "token_count": 185, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 529, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 6, "complexity": 3, "token_count": 27, "parameters": [ "self", "module_dirs" ], "start_line": 570, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 577, "end_line": 578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 110, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 608, "end_line": 633, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 6, "complexity": 3, "token_count": 27, "parameters": [ "self", "module_dirs" ], "start_line": 635, "end_line": 640, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "find_lib_dir", "long_name": "find_lib_dir( self )", "filename": "build_flib.py", "nloc": 18, "complexity": 4, "token_count": 122, "parameters": [ "self" ], "start_line": 642, "end_line": 659, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 661, "end_line": 662, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 664, "end_line": 665, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 667, "end_line": 668, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 100, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 677, "end_line": 698, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "module_dirs" ], "start_line": 701, "end_line": 703, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "find_lib_dir", "long_name": "find_lib_dir( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 704, "end_line": 706, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 707, "end_line": 708, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 709, "end_line": 710, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 95, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 717, "end_line": 736, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "get_version", "long_name": "get_version( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 5, "token_count": 125, "parameters": [ "self" ], "start_line": 738, "end_line": 756, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 24, "complexity": 7, "token_count": 156, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 764, "end_line": 795, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 21, "complexity": 10, "token_count": 117, "parameters": [ "self" ], "start_line": 797, "end_line": 819, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "find_lib_directories", "long_name": "find_lib_directories( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 4, "token_count": 98, "parameters": [ "self" ], "start_line": 821, "end_line": 838, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 7, "complexity": 4, "token_count": 51, "parameters": [ "self" ], "start_line": 840, "end_line": 847, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 5, "complexity": 3, "token_count": 39, "parameters": [ "self" ], "start_line": 849, "end_line": 857, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "f90_compile", "long_name": "f90_compile( self , source_files , module_files , temp_dir = '' )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "source_files", "module_files", "temp_dir" ], "start_line": 859, "end_line": 860, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 22, "complexity": 5, "token_count": 148, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 870, "end_line": 898, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 15, "complexity": 7, "token_count": 85, "parameters": [ "self" ], "start_line": 900, "end_line": 914, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 917, "end_line": 918, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 39, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 928, "end_line": 931, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 108, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 939, "end_line": 958, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 960, "end_line": 962, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 964, "end_line": 965, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 24, "complexity": 6, "token_count": 116, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 979, "end_line": 1007, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 1013, "end_line": 1014, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 20, "complexity": 5, "token_count": 136, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 1023, "end_line": 1047, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 1051, "end_line": 1052, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 14, "complexity": 3, "token_count": 99, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 1060, "end_line": 1082, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 1084, "end_line": 1087, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 1089, "end_line": 1090, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 18, "complexity": 4, "token_count": 129, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 1107, "end_line": 1130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 1132, "end_line": 1134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "match_extension", "long_name": "match_extension( files , ext )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 44, "parameters": [ "files", "ext" ], "start_line": 1137, "end_line": 1139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "get_f77_files", "long_name": "get_f77_files( files )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "files" ], "start_line": 1141, "end_line": 1142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "get_f90_files", "long_name": "get_f90_files( files )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "files" ], "start_line": 1144, "end_line": 1145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "get_fortran_files", "long_name": "get_fortran_files( files )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "files" ], "start_line": 1147, "end_line": 1148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "find_fortran_compiler", "long_name": "find_fortran_compiler( vendor = None , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 8, "complexity": 5, "token_count": 60, "parameters": [ "vendor", "fc", "f90c", "verbose" ], "start_line": 1150, "end_line": 1158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "methods_before": [ { "name": "run_command", "long_name": "run_command( command )", "filename": "build_flib.py", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "command" ], "start_line": 71, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "show_compilers", "long_name": "show_compilers( )", "filename": "build_flib.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [], "start_line": 80, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_flib.py", "nloc": 11, "complexity": 1, "token_count": 55, "parameters": [ "self" ], "start_line": 114, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "build_flib.py", "nloc": 20, "complexity": 3, "token_count": 122, "parameters": [ "self" ], "start_line": 130, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "has_f_libraries", "long_name": "has_f_libraries( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 2, "token_count": 23, "parameters": [ "self" ], "start_line": 154, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 22, "parameters": [ "self" ], "start_line": 158, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "has_f_library", "long_name": "has_f_library( self , name )", "filename": "build_flib.py", "nloc": 5, "complexity": 4, "token_count": 32, "parameters": [ "self", "name" ], "start_line": 165, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "get_library_names", "long_name": "get_library_names( self , name = None )", "filename": "build_flib.py", "nloc": 17, "complexity": 8, "token_count": 117, "parameters": [ "self", "name" ], "start_line": 174, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_fcompiler_library_names", "long_name": "get_fcompiler_library_names( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 24, "parameters": [ "self" ], "start_line": 196, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_fcompiler_library_dirs", "long_name": "get_fcompiler_library_dirs( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 24, "parameters": [ "self" ], "start_line": 203, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self , name = None )", "filename": "build_flib.py", "nloc": 15, "complexity": 7, "token_count": 109, "parameters": [ "self", "name" ], "start_line": 212, "end_line": 229, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 5, "complexity": 2, "token_count": 31, "parameters": [ "self" ], "start_line": 233, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_flib.py", "nloc": 8, "complexity": 3, "token_count": 49, "parameters": [ "self" ], "start_line": 246, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , fortran_libraries )", "filename": "build_flib.py", "nloc": 25, "complexity": 10, "token_count": 181, "parameters": [ "self", "fortran_libraries" ], "start_line": 259, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 100, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 312, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "to_object", "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 89, "parameters": [ "self", "dirty_files", "module_dirs", "temp_dir" ], "start_line": 337, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "source_to_object_names", "long_name": "source_to_object_names( self , source_files , temp_dir = '' )", "filename": "build_flib.py", "nloc": 6, "complexity": 1, "token_count": 89, "parameters": [ "self", "source_files", "temp_dir" ], "start_line": 354, "end_line": 359, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "source_and_object_pairs", "long_name": "source_and_object_pairs( self , source_files , temp_dir = '' )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 31, "parameters": [ "self", "source_files", "temp_dir" ], "start_line": 361, "end_line": 364, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f_compile", "long_name": "f_compile( self , compiler , switches , source_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 20, "complexity": 4, "token_count": 147, "parameters": [ "self", "compiler", "switches", "source_files", "module_dirs", "temp_dir" ], "start_line": 366, "end_line": 388, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "f90_compile", "long_name": "f90_compile( self , source_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self", "source_files", "module_dirs", "temp_dir" ], "start_line": 392, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "f77_compile", "long_name": "f77_compile( self , source_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self", "source_files", "module_dirs", "temp_dir" ], "start_line": 397, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "module_dirs" ], "start_line": 402, "end_line": 403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "create_static_lib", "long_name": "create_static_lib( self , object_files , library_name , output_dir = '' , debug = None , skip_ranlib = 0 )", "filename": "build_flib.py", "nloc": 19, "complexity": 6, "token_count": 138, "parameters": [ "self", "object_files", "library_name", "output_dir", "debug", "skip_ranlib" ], "start_line": 405, "end_line": 424, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "build_library", "long_name": "build_library( self , library_name , source_list , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 21, "complexity": 6, "token_count": 149, "parameters": [ "self", "library_name", "source_list", "module_dirs", "temp_dir" ], "start_line": 426, "end_line": 466, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "dummy_fortran_files", "long_name": "dummy_fortran_files( self )", "filename": "build_flib.py", "nloc": 8, "complexity": 1, "token_count": 69, "parameters": [ "self" ], "start_line": 468, "end_line": 475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "is_available", "long_name": "is_available( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 477, "end_line": 478, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_version", "long_name": "get_version( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 4, "token_count": 130, "parameters": [ "self" ], "start_line": 480, "end_line": 503, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 505, "end_line": 506, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 507, "end_line": 508, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 509, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 511, "end_line": 512, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 1, "complexity": 1, "token_count": 6, "parameters": [ "self" ], "start_line": 513, "end_line": 518, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 520, "end_line": 521, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 31, "complexity": 5, "token_count": 185, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 529, "end_line": 568, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 6, "complexity": 3, "token_count": 27, "parameters": [ "self", "module_dirs" ], "start_line": 570, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 577, "end_line": 578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 110, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 592, "end_line": 617, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 6, "complexity": 3, "token_count": 27, "parameters": [ "self", "module_dirs" ], "start_line": 619, "end_line": 624, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "find_lib_dir", "long_name": "find_lib_dir( self )", "filename": "build_flib.py", "nloc": 18, "complexity": 4, "token_count": 122, "parameters": [ "self" ], "start_line": 626, "end_line": 643, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 645, "end_line": 646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 648, "end_line": 649, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 651, "end_line": 652, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 100, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 661, "end_line": 682, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "build_module_switch", "long_name": "build_module_switch( self , module_dirs )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "module_dirs" ], "start_line": 685, "end_line": 687, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "find_lib_dir", "long_name": "find_lib_dir( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 688, "end_line": 690, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 691, "end_line": 692, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 693, "end_line": 694, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 95, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 701, "end_line": 720, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "get_version", "long_name": "get_version( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 5, "token_count": 125, "parameters": [ "self" ], "start_line": 722, "end_line": 740, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 24, "complexity": 7, "token_count": 156, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 748, "end_line": 779, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 21, "complexity": 10, "token_count": 117, "parameters": [ "self" ], "start_line": 781, "end_line": 803, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "find_lib_directories", "long_name": "find_lib_directories( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 4, "token_count": 98, "parameters": [ "self" ], "start_line": 805, "end_line": 822, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 7, "complexity": 4, "token_count": 51, "parameters": [ "self" ], "start_line": 824, "end_line": 831, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "get_extra_link_args", "long_name": "get_extra_link_args( self )", "filename": "build_flib.py", "nloc": 5, "complexity": 3, "token_count": 39, "parameters": [ "self" ], "start_line": 833, "end_line": 841, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "f90_compile", "long_name": "f90_compile( self , source_files , module_files , temp_dir = '' )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "source_files", "module_files", "temp_dir" ], "start_line": 843, "end_line": 844, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 22, "complexity": 5, "token_count": 148, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 854, "end_line": 882, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 15, "complexity": 7, "token_count": 85, "parameters": [ "self" ], "start_line": 884, "end_line": 898, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 901, "end_line": 902, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 39, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 912, "end_line": 915, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 108, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 923, "end_line": 942, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 944, "end_line": 946, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 948, "end_line": 949, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 24, "complexity": 6, "token_count": 116, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 963, "end_line": 991, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 997, "end_line": 998, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 20, "complexity": 5, "token_count": 136, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 1007, "end_line": 1031, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 1035, "end_line": 1036, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 14, "complexity": 3, "token_count": 99, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 1044, "end_line": 1066, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 4, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 1068, "end_line": 1071, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 1073, "end_line": 1074, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 18, "complexity": 4, "token_count": 129, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 1091, "end_line": 1114, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 1116, "end_line": 1118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "match_extension", "long_name": "match_extension( files , ext )", "filename": "build_flib.py", "nloc": 3, "complexity": 1, "token_count": 44, "parameters": [ "files", "ext" ], "start_line": 1121, "end_line": 1123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "get_f77_files", "long_name": "get_f77_files( files )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "files" ], "start_line": 1125, "end_line": 1126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "get_f90_files", "long_name": "get_f90_files( files )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "files" ], "start_line": 1128, "end_line": 1129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "get_fortran_files", "long_name": "get_fortran_files( files )", "filename": "build_flib.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "files" ], "start_line": 1131, "end_line": 1132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "find_fortran_compiler", "long_name": "find_fortran_compiler( vendor = None , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 8, "complexity": 5, "token_count": 60, "parameters": [ "vendor", "fc", "f90c", "verbose" ], "start_line": 1134, "end_line": 1142, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "__init__", "long_name": "__init__( self , fc = None , f90c = None , verbose = 0 )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 110, "parameters": [ "self", "fc", "f90c", "verbose" ], "start_line": 608, "end_line": 633, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 } ], "nloc": 844, "complexity": 207, "token_count": 4933, "diff_parsed": { "added": [ " \"\"\"specify/detect settings for Sun's Forte compiler", "", " Recent Sun Fortran compilers are FORTRAN 90/95 beasts. F77 support is", " handled by the same compiler, so even if you are asking for F77 you're", " getting a FORTRAN 95 compiler. Since most (all?) the code currently", " being compiled for SciPy is FORTRAN 77 code, the list of libraries", " contains various F77-related libraries. Not sure what would happen if", " you tried to actually compile and link FORTRAN 95 code with these", " settings.", "", " Note also that the 'Forte' name is passe. Sun's latest compiler is", " named 'Sun ONE Studio 7, Compiler Collection'. Heaven only knows what", " the version string for that baby will be.", " \"\"\"", "", "", " # old compiler - any idea what the proper flags would be?", " ver_match = r'f90: (Forte Developer 7 Fortran 95|Sun) (?P[^\\s*,]*)'", " self.f77_compiler = fc", " # -fixed specifies fixed-format instead of free-format F90/95 code", " self.f90_switches = ' -fixed -pic'" ], "deleted": [ "", " ver_match = r'f90: (Forte Developer 7 Fortran 95|Sun) (?P[^\\s*,]*)'", " self.f77_compiler = fc # not tested", " self.f90_switches = ' -fixed ' # ??? why fixed?", " #self.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']" ] } } ] }, { "hash": "3b2b316874ef01a39fbd86f51494bd2c2a847558", "msg": "NEW: Added a VTK type converter for weave.", "author": { "name": "prabhu", "email": "prabhu@localhost" }, "committer": { "name": "prabhu", "email": "prabhu@localhost" }, "author_date": "2002-09-17T16:14:47+00:00", "author_timezone": 0, "committer_date": "2002-09-17T16:14:47+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "3bfc473f92dbf3827c02d0e0950658dc95ee19e6" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 0, "insertions": 142, "lines": 142, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 0.8936170212765957, "modified_files": [ { "old_path": null, "new_path": "weave/vtk_spec.py", "filename": "vtk_spec.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,142 @@\n+\"\"\"\n+VTK type converter.\n+\n+This module handles conversion between VTK C++ and VTK Python objects\n+so that one can write inline C++ code to manipulate VTK Python\n+objects. It requires that you have VTK and the VTK-Python wrappers\n+installed. It has been tested with VTK 4.0 and above. The code is\n+based on wx_spec.py. You will need to call inline with include_dirs,\n+library_dirs and often even libraries appropriately set for this to\n+work without errors. Sometimes you might need to include additional\n+headers.\n+\n+Distributed under the SciPy License.\n+\n+Authors:\n+ Prabhu Ramachandran \n+ Eric Jones \n+\"\"\"\n+\n+import common_info\n+from c_spec import common_base_converter\n+\n+\n+vtk_py_to_c_template = \\\n+\"\"\"\n+class %(type_name)s_handler\n+{\n+public:\n+ %(c_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n+ {\n+ %(c_type)s vtk_ptr = (%(c_type)s) vtkPythonGetPointerFromObject(py_obj, \"%(type_name)s\");\n+ if (!vtk_ptr)\n+ handle_conversion_error(py_obj,\"%(type_name)s\", name);\n+ %(inc_ref_count)s\n+ return vtk_ptr;\n+ }\n+\n+ %(c_type)s py_to_%(type_name)s(PyObject* py_obj, const char* name)\n+ {\n+ %(c_type)s vtk_ptr = (%(c_type)s) vtkPythonGetPointerFromObject(py_obj, \"%(type_name)s\");\n+ if (!vtk_ptr)\n+ handle_bad_type(py_obj,\"%(type_name)s\", name);\n+ %(inc_ref_count)s\n+ return vtk_ptr;\n+ }\n+};\n+\n+%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n+#define convert_to_%(type_name)s(py_obj,name) \\\\\n+ x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n+#define py_to_%(type_name)s(py_obj,name) \\\\\n+ x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n+\n+\"\"\"\n+\n+vtk_c_to_py_template = \\\n+\"\"\"\n+PyObject* %(type_name)s_to_py(vtkObjectBase* obj)\n+{\n+ return vtkPythonGetObjectFromPointer(obj);\n+}\n+\"\"\"\n+ \n+\n+class vtk_converter(common_base_converter):\n+ def __init__(self,class_name=\"undefined\"):\n+ self.class_name = class_name\n+ common_base_converter.__init__(self)\n+\n+ def init_info(self):\n+ common_base_converter.init_info(self)\n+ # These are generated on the fly instead of defined at \n+ # the class level.\n+ self.type_name = self.class_name\n+ self.c_type = self.class_name + \"*\"\n+ self.to_c_return = None # not used\n+ self.check_func = None # not used\n+ hdr = self.class_name + \".h\"\n+ # Remember that you need both the quotes!\n+ self.headers.extend(['\"vtkPythonUtil.h\"', '\"vtkObject.h\"',\n+ '\"%s\"'%hdr])\n+ #self.include_dirs.extend(vtk_inc)\n+ #self.define_macros.append(('SOME_VARIABLE', '1'))\n+ #self.library_dirs.extend(vtk_lib)\n+ self.libraries.extend(['vtkCommonPython', 'vtkCommon'])\n+ #self.support_code.append(common_info.swig_support_code)\n+ \n+ def type_match(self,value):\n+ is_match = 0\n+ try:\n+ if value.IsA('vtkObject'):\n+ is_match = 1\n+ except AttributeError:\n+ pass\n+ return is_match\n+\n+ def generate_build_info(self):\n+ if self.class_name != \"undefined\":\n+ res = common_base_converter.generate_build_info(self)\n+ else:\n+ # if there isn't a class_name, we don't want the\n+ # we don't want the support_code to be included\n+ import base_info\n+ res = base_info.base_info()\n+ return res\n+ \n+ def py_to_c_code(self):\n+ return vtk_py_to_c_template % self.template_vars()\n+\n+ def c_to_py_code(self):\n+ return vtk_c_to_py_template % self.template_vars()\n+ \n+ def type_spec(self,name,value):\n+ # factory\n+ class_name = value.__class__.__name__\n+ new_spec = self.__class__(class_name)\n+ new_spec.name = name \n+ return new_spec\n+\n+ def __cmp__(self,other):\n+ #only works for equal\n+ res = -1\n+ try:\n+ res = cmp(self.name,other.name) or \\\n+ cmp(self.__class__, other.__class__) or \\\n+ cmp(self.class_name, other.class_name) or \\\n+ cmp(self.type_name,other.type_name)\n+ except:\n+ pass\n+ return res\n+\n+\"\"\"\n+# this should only be enabled on machines with access to a display device\n+# It'll cause problems otherwise.\n+def test(level=10):\n+ from scipy_base.testing import module_test\n+ module_test(__name__,__file__,level=level)\n+\n+def test_suite(level=1):\n+ from scipy_base.testing import module_test_suite\n+ return module_test_suite(__name__,__file__,level=level)\n+\"\"\"\n", "added_lines": 142, "deleted_lines": 0, "source_code": "\"\"\"\nVTK type converter.\n\nThis module handles conversion between VTK C++ and VTK Python objects\nso that one can write inline C++ code to manipulate VTK Python\nobjects. It requires that you have VTK and the VTK-Python wrappers\ninstalled. It has been tested with VTK 4.0 and above. The code is\nbased on wx_spec.py. You will need to call inline with include_dirs,\nlibrary_dirs and often even libraries appropriately set for this to\nwork without errors. Sometimes you might need to include additional\nheaders.\n\nDistributed under the SciPy License.\n\nAuthors:\n Prabhu Ramachandran \n Eric Jones \n\"\"\"\n\nimport common_info\nfrom c_spec import common_base_converter\n\n\nvtk_py_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic:\n %(c_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n %(c_type)s vtk_ptr = (%(c_type)s) vtkPythonGetPointerFromObject(py_obj, \"%(type_name)s\");\n if (!vtk_ptr)\n handle_conversion_error(py_obj,\"%(type_name)s\", name);\n %(inc_ref_count)s\n return vtk_ptr;\n }\n\n %(c_type)s py_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n %(c_type)s vtk_ptr = (%(c_type)s) vtkPythonGetPointerFromObject(py_obj, \"%(type_name)s\");\n if (!vtk_ptr)\n handle_bad_type(py_obj,\"%(type_name)s\", name);\n %(inc_ref_count)s\n return vtk_ptr;\n }\n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\nvtk_c_to_py_template = \\\n\"\"\"\nPyObject* %(type_name)s_to_py(vtkObjectBase* obj)\n{\n return vtkPythonGetObjectFromPointer(obj);\n}\n\"\"\"\n \n\nclass vtk_converter(common_base_converter):\n def __init__(self,class_name=\"undefined\"):\n self.class_name = class_name\n common_base_converter.__init__(self)\n\n def init_info(self):\n common_base_converter.init_info(self)\n # These are generated on the fly instead of defined at \n # the class level.\n self.type_name = self.class_name\n self.c_type = self.class_name + \"*\"\n self.to_c_return = None # not used\n self.check_func = None # not used\n hdr = self.class_name + \".h\"\n # Remember that you need both the quotes!\n self.headers.extend(['\"vtkPythonUtil.h\"', '\"vtkObject.h\"',\n '\"%s\"'%hdr])\n #self.include_dirs.extend(vtk_inc)\n #self.define_macros.append(('SOME_VARIABLE', '1'))\n #self.library_dirs.extend(vtk_lib)\n self.libraries.extend(['vtkCommonPython', 'vtkCommon'])\n #self.support_code.append(common_info.swig_support_code)\n \n def type_match(self,value):\n is_match = 0\n try:\n if value.IsA('vtkObject'):\n is_match = 1\n except AttributeError:\n pass\n return is_match\n\n def generate_build_info(self):\n if self.class_name != \"undefined\":\n res = common_base_converter.generate_build_info(self)\n else:\n # if there isn't a class_name, we don't want the\n # we don't want the support_code to be included\n import base_info\n res = base_info.base_info()\n return res\n \n def py_to_c_code(self):\n return vtk_py_to_c_template % self.template_vars()\n\n def c_to_py_code(self):\n return vtk_c_to_py_template % self.template_vars()\n \n def type_spec(self,name,value):\n # factory\n class_name = value.__class__.__name__\n new_spec = self.__class__(class_name)\n new_spec.name = name \n return new_spec\n\n def __cmp__(self,other):\n #only works for equal\n res = -1\n try:\n res = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__) or \\\n cmp(self.class_name, other.class_name) or \\\n cmp(self.type_name,other.type_name)\n except:\n pass\n return res\n\n\"\"\"\n# this should only be enabled on machines with access to a display device\n# It'll cause problems otherwise.\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\"\"\"\n", "source_code_before": null, "methods": [ { "name": "__init__", "long_name": "__init__( self , class_name = \"undefined\" )", "filename": "vtk_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self", "class_name" ], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "vtk_spec.py", "nloc": 10, "complexity": 1, "token_count": 72, "parameters": [ "self" ], "start_line": 70, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "vtk_spec.py", "nloc": 8, "complexity": 3, "token_count": 29, "parameters": [ "self", "value" ], "start_line": 88, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "vtk_spec.py", "nloc": 7, "complexity": 2, "token_count": 33, "parameters": [ "self" ], "start_line": 97, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "vtk_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 107, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "vtk_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "vtk_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self", "name", "value" ], "start_line": 113, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "vtk_spec.py", "nloc": 10, "complexity": 5, "token_count": 66, "parameters": [ "self", "other" ], "start_line": 120, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 } ], "methods_before": [], "changed_methods": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "vtk_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self", "name", "value" ], "start_line": 113, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "vtk_spec.py", "nloc": 8, "complexity": 3, "token_count": 29, "parameters": [ "self", "value" ], "start_line": 88, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "vtk_spec.py", "nloc": 10, "complexity": 1, "token_count": 72, "parameters": [ "self" ], "start_line": 70, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , class_name = \"undefined\" )", "filename": "vtk_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self", "class_name" ], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "vtk_spec.py", "nloc": 7, "complexity": 2, "token_count": 33, "parameters": [ "self" ], "start_line": 97, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "vtk_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 107, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "vtk_spec.py", "nloc": 10, "complexity": 5, "token_count": 66, "parameters": [ "self", "other" ], "start_line": 120, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "vtk_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "nloc": 117, "complexity": 15, "token_count": 307, "diff_parsed": { "added": [ "\"\"\"", "VTK type converter.", "", "This module handles conversion between VTK C++ and VTK Python objects", "so that one can write inline C++ code to manipulate VTK Python", "objects. It requires that you have VTK and the VTK-Python wrappers", "installed. It has been tested with VTK 4.0 and above. The code is", "based on wx_spec.py. You will need to call inline with include_dirs,", "library_dirs and often even libraries appropriately set for this to", "work without errors. Sometimes you might need to include additional", "headers.", "", "Distributed under the SciPy License.", "", "Authors:", " Prabhu Ramachandran ", " Eric Jones ", "\"\"\"", "", "import common_info", "from c_spec import common_base_converter", "", "", "vtk_py_to_c_template = \\", "\"\"\"", "class %(type_name)s_handler", "{", "public:", " %(c_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)", " {", " %(c_type)s vtk_ptr = (%(c_type)s) vtkPythonGetPointerFromObject(py_obj, \"%(type_name)s\");", " if (!vtk_ptr)", " handle_conversion_error(py_obj,\"%(type_name)s\", name);", " %(inc_ref_count)s", " return vtk_ptr;", " }", "", " %(c_type)s py_to_%(type_name)s(PyObject* py_obj, const char* name)", " {", " %(c_type)s vtk_ptr = (%(c_type)s) vtkPythonGetPointerFromObject(py_obj, \"%(type_name)s\");", " if (!vtk_ptr)", " handle_bad_type(py_obj,\"%(type_name)s\", name);", " %(inc_ref_count)s", " return vtk_ptr;", " }", "};", "", "%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();", "#define convert_to_%(type_name)s(py_obj,name) \\\\", " x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)", "#define py_to_%(type_name)s(py_obj,name) \\\\", " x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)", "", "\"\"\"", "", "vtk_c_to_py_template = \\", "\"\"\"", "PyObject* %(type_name)s_to_py(vtkObjectBase* obj)", "{", " return vtkPythonGetObjectFromPointer(obj);", "}", "\"\"\"", "", "", "class vtk_converter(common_base_converter):", " def __init__(self,class_name=\"undefined\"):", " self.class_name = class_name", " common_base_converter.__init__(self)", "", " def init_info(self):", " common_base_converter.init_info(self)", " # These are generated on the fly instead of defined at", " # the class level.", " self.type_name = self.class_name", " self.c_type = self.class_name + \"*\"", " self.to_c_return = None # not used", " self.check_func = None # not used", " hdr = self.class_name + \".h\"", " # Remember that you need both the quotes!", " self.headers.extend(['\"vtkPythonUtil.h\"', '\"vtkObject.h\"',", " '\"%s\"'%hdr])", " #self.include_dirs.extend(vtk_inc)", " #self.define_macros.append(('SOME_VARIABLE', '1'))", " #self.library_dirs.extend(vtk_lib)", " self.libraries.extend(['vtkCommonPython', 'vtkCommon'])", " #self.support_code.append(common_info.swig_support_code)", "", " def type_match(self,value):", " is_match = 0", " try:", " if value.IsA('vtkObject'):", " is_match = 1", " except AttributeError:", " pass", " return is_match", "", " def generate_build_info(self):", " if self.class_name != \"undefined\":", " res = common_base_converter.generate_build_info(self)", " else:", " # if there isn't a class_name, we don't want the", " # we don't want the support_code to be included", " import base_info", " res = base_info.base_info()", " return res", "", " def py_to_c_code(self):", " return vtk_py_to_c_template % self.template_vars()", "", " def c_to_py_code(self):", " return vtk_c_to_py_template % self.template_vars()", "", " def type_spec(self,name,value):", " # factory", " class_name = value.__class__.__name__", " new_spec = self.__class__(class_name)", " new_spec.name = name", " return new_spec", "", " def __cmp__(self,other):", " #only works for equal", " res = -1", " try:", " res = cmp(self.name,other.name) or \\", " cmp(self.__class__, other.__class__) or \\", " cmp(self.class_name, other.class_name) or \\", " cmp(self.type_name,other.type_name)", " except:", " pass", " return res", "", "\"\"\"", "# this should only be enabled on machines with access to a display device", "# It'll cause problems otherwise.", "def test(level=10):", " from scipy_base.testing import module_test", " module_test(__name__,__file__,level=level)", "", "def test_suite(level=1):", " from scipy_base.testing import module_test_suite", " return module_test_suite(__name__,__file__,level=level)", "\"\"\"" ], "deleted": [] } } ] }, { "hash": "5d7c9032c020020ad71a846e311f12b63480f614", "msg": "ENH: Updated to add the new VTK converter.", "author": { "name": "prabhu", "email": "prabhu@localhost" }, "committer": { "name": "prabhu", "email": "prabhu@localhost" }, "author_date": "2002-09-17T16:21:17+00:00", "author_timezone": 0, "committer_date": "2002-09-17T16:21:17+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "3b2b316874ef01a39fbd86f51494bd2c2a847558" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 0, "insertions": 11, "lines": 11, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "weave/converters.py", "new_path": "weave/converters.py", "filename": "converters.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -42,6 +42,17 @@\n except IndexError: \n pass \n \n+#------------------------------------------------------------------------\n+# Add VTK support\n+#-----------------------------------------------------------------------\n+\n+try: \n+ import vtk_spec\n+ default.insert(0,vtk_spec.vtk_converter())\n+except IndexError: \n+ pass\n+\n+\n standard_info = [common_info.basic_module_info()]\n standard_info += [x.generate_build_info() for x in default]\n \n", "added_lines": 11, "deleted_lines": 0, "source_code": "\"\"\" converters.py\n\"\"\"\n\nimport common_info\nimport c_spec\n\n#----------------------------------------------------------------------------\n# The \"standard\" conversion classes\n#----------------------------------------------------------------------------\n\ndefault = [c_spec.int_converter(),\n c_spec.float_converter(),\n c_spec.complex_converter(),\n c_spec.unicode_converter(),\n c_spec.string_converter(),\n c_spec.list_converter(),\n c_spec.dict_converter(),\n c_spec.tuple_converter(),\n c_spec.file_converter(),\n c_spec.callable_converter(),\n c_spec.instance_converter(),] \n #common_spec.module_converter()]\n\n#----------------------------------------------------------------------------\n# If Numeric is installed, add numeric array converters to the default\n# converter list.\n#----------------------------------------------------------------------------\ntry: \n import standard_array_spec\n default.append(standard_array_spec.array_converter())\nexcept ImportError: \n pass \n\n#----------------------------------------------------------------------------\n# Add wxPython support\n#----------------------------------------------------------------------------\n\ntry: \n # this is currently safe because it doesn't import wxPython.\n import wx_spec\n default.insert(0,wx_spec.wx_converter())\nexcept IndexError: \n pass \n\n#------------------------------------------------------------------------\n# Add VTK support\n#-----------------------------------------------------------------------\n\ntry: \n import vtk_spec\n default.insert(0,vtk_spec.vtk_converter())\nexcept IndexError: \n pass\n\n\nstandard_info = [common_info.basic_module_info()]\nstandard_info += [x.generate_build_info() for x in default]\n\n#----------------------------------------------------------------------------\n# Blitz conversion classes\n#\n# same as default, but will convert Numeric arrays to blitz C++ classes \n#----------------------------------------------------------------------------\nimport blitz_spec\nblitz = [blitz_spec.array_converter()] + default\n\n", "source_code_before": "\"\"\" converters.py\n\"\"\"\n\nimport common_info\nimport c_spec\n\n#----------------------------------------------------------------------------\n# The \"standard\" conversion classes\n#----------------------------------------------------------------------------\n\ndefault = [c_spec.int_converter(),\n c_spec.float_converter(),\n c_spec.complex_converter(),\n c_spec.unicode_converter(),\n c_spec.string_converter(),\n c_spec.list_converter(),\n c_spec.dict_converter(),\n c_spec.tuple_converter(),\n c_spec.file_converter(),\n c_spec.callable_converter(),\n c_spec.instance_converter(),] \n #common_spec.module_converter()]\n\n#----------------------------------------------------------------------------\n# If Numeric is installed, add numeric array converters to the default\n# converter list.\n#----------------------------------------------------------------------------\ntry: \n import standard_array_spec\n default.append(standard_array_spec.array_converter())\nexcept ImportError: \n pass \n\n#----------------------------------------------------------------------------\n# Add wxPython support\n#----------------------------------------------------------------------------\n\ntry: \n # this is currently safe because it doesn't import wxPython.\n import wx_spec\n default.insert(0,wx_spec.wx_converter())\nexcept IndexError: \n pass \n\nstandard_info = [common_info.basic_module_info()]\nstandard_info += [x.generate_build_info() for x in default]\n\n#----------------------------------------------------------------------------\n# Blitz conversion classes\n#\n# same as default, but will convert Numeric arrays to blitz C++ classes \n#----------------------------------------------------------------------------\nimport blitz_spec\nblitz = [blitz_spec.array_converter()] + default\n\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 34, "complexity": 0, "token_count": 168, "diff_parsed": { "added": [ "#------------------------------------------------------------------------", "# Add VTK support", "#-----------------------------------------------------------------------", "", "try:", " import vtk_spec", " default.insert(0,vtk_spec.vtk_converter())", "except IndexError:", " pass", "", "" ], "deleted": [] } } ] }, { "hash": "0b94f013bfb5e2efb891f1c82390912276e0d7fb", "msg": "This fixes infinite loop when testing weave", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-09-17T18:38:05+00:00", "author_timezone": 0, "committer_date": "2002-09-17T18:38:05+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "5d7c9032c020020ad71a846e311f12b63480f614" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 1, "insertions": 1, "lines": 2, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "weave/__init__.py", "new_path": "weave/__init__.py", "filename": "__init__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -30,7 +30,7 @@ def test(level=10):\n def test_suite(level=1):\n import scipy_base.testing\n try:\n- this_mod = __import__(__name__)\n+ import scipy.weave as this_mod\n except ImportError:\n # punt -- assume we're a stand alone package\n this_mod = weave\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\"\"\" compiler provides several tools:\n\n 1. inline() -- a function for including C/C++ code within Python\n 2. blitz() -- a function for compiling Numeric expressions to C++\n 3. ext_tools-- a module that helps construct C/C++ extension modules.\n 4. accelerate -- a module that inline accelerates Python functions\n\"\"\"\n\ntry:\n from blitz_tools import blitz\nexcept ImportError:\n pass # Numeric wasn't available \n \nfrom inline_tools import inline\nimport ext_tools\nfrom ext_tools import ext_module, ext_function\ntry:\n from accelerate_tools import accelerate\nexcept:\n pass\n\n#---- testing ----#\n\ndef test(level=10):\n import unittest\n runner = unittest.TextTestRunner()\n runner.run(test_suite(level))\n return runner\n\ndef test_suite(level=1):\n import scipy_base.testing\n try:\n import scipy.weave as this_mod\n except ImportError:\n # punt -- assume we're a stand alone package\n this_mod = weave\n return scipy_base.testing.harvest_test_suites(this_mod,level=level)\n", "source_code_before": "\"\"\" compiler provides several tools:\n\n 1. inline() -- a function for including C/C++ code within Python\n 2. blitz() -- a function for compiling Numeric expressions to C++\n 3. ext_tools-- a module that helps construct C/C++ extension modules.\n 4. accelerate -- a module that inline accelerates Python functions\n\"\"\"\n\ntry:\n from blitz_tools import blitz\nexcept ImportError:\n pass # Numeric wasn't available \n \nfrom inline_tools import inline\nimport ext_tools\nfrom ext_tools import ext_module, ext_function\ntry:\n from accelerate_tools import accelerate\nexcept:\n pass\n\n#---- testing ----#\n\ndef test(level=10):\n import unittest\n runner = unittest.TextTestRunner()\n runner.run(test_suite(level))\n return runner\n\ndef test_suite(level=1):\n import scipy_base.testing\n try:\n this_mod = __import__(__name__)\n except ImportError:\n # punt -- assume we're a stand alone package\n this_mod = weave\n return scipy_base.testing.harvest_test_suites(this_mod,level=level)\n", "methods": [ { "name": "test", "long_name": "test( level = 10 )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "level" ], "start_line": 24, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "__init__.py", "nloc": 7, "complexity": 2, "token_count": 38, "parameters": [ "level" ], "start_line": 30, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "methods_before": [ { "name": "test", "long_name": "test( level = 10 )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "level" ], "start_line": 24, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "__init__.py", "nloc": 7, "complexity": 2, "token_count": 38, "parameters": [ "level" ], "start_line": 30, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "__init__.py", "nloc": 7, "complexity": 2, "token_count": 38, "parameters": [ "level" ], "start_line": 30, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "nloc": 30, "complexity": 3, "token_count": 99, "diff_parsed": { "added": [ " import scipy.weave as this_mod" ], "deleted": [ " this_mod = __import__(__name__)" ] } } ] }, { "hash": "f8fc8923f2ed8d4da323558092b1307383aa5685", "msg": "Fixed unique function for Python 2.1", "author": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "committer": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "author_date": "2002-09-17T21:49:39+00:00", "author_timezone": 0, "committer_date": "2002-09-17T21:49:39+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "0b94f013bfb5e2efb891f1c82390912276e0d7fb" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 1, "insertions": 2, "lines": 3, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_base/function_base.py", "new_path": "scipy_base/function_base.py", "filename": "function_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -260,7 +260,8 @@ def unique(inseq):\n \"\"\"Returns unique items in 1-dimensional sequence.\n \"\"\"\n set = {}\n- map(set.__setitem__, inseq, [])\n+ for item in inseq:\n+ set[item] = None\n return asarray(set.keys())\n \n import sys\n", "added_lines": 2, "deleted_lines": 1, "source_code": "import types\nimport Numeric\nN = Numeric\nfrom Numeric import *\nfrom scipy_base.fastumath import *\nimport _compiled_base\nfrom type_check import ScalarType, isscalar\n\n__all__ = ['round','any','all','logspace','linspace','fix','mod',\n 'select','trim_zeros','amax','amin','ptp','cumsum',\n 'prod','cumprod','diff','angle','unwrap','sort_complex',\n 'disp','unique']\n\nround = Numeric.around\nany = Numeric.sometrue\nall = Numeric.alltrue\n\n\ndef logspace(start,stop,num=50,endpoint=1):\n \"\"\" Evenly spaced samples on a logarithmic scale.\n\n Return num evenly spaced samples from 10**start to 10**stop. If\n endpoint=1 then last sample is 10**stop.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = Numeric.arange(0,num) * step + start\n else:\n step = (stop-start)/float(num)\n y = Numeric.arange(0,num) * step + start\n return Numeric.power(10.0,y)\n\ndef linspace(start,stop,num=50,endpoint=1,retstep=0):\n \"\"\" Evenly spaced samples.\n \n Return num evenly spaced samples from start to stop. If endpoint=1 then\n last sample is stop. If retstep is 1 then return the step value used.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = Numeric.arange(0,num) * step + start \n else:\n step = (stop-start)/float(num)\n y = Numeric.arange(0,num) * step + start\n if retstep:\n return y, step\n else:\n return y\n\ndef fix(x):\n \"\"\" Round x to nearest integer towards zero.\n \"\"\"\n x = Numeric.asarray(x)\n y = Numeric.floor(x)\n return Numeric.where(x<0,y+1,y)\n\ndef mod(x,y):\n \"\"\" x - y*floor(x/y)\n \n For numeric arrays, x % y has the same sign as x while\n mod(x,y) has the same sign as y.\n \"\"\"\n return x - y*Numeric.floor(x*1.0/y)\n\ndef select(condlist, choicelist, default=0):\n \"\"\" Returns an array comprised from different elements of choicelist\n depending on the list of conditions.\n\n condlist is a list of condition arrays containing ones or zeros\n \n choicelist is a list of choice matrices (of the \"same\" size as the\n arrays in condlist). The result array has the \"same\" size as the\n arrays in choicelist. If condlist is [c0,...,cN-1] then choicelist\n must be of length N. The elements of the choicelist can then be\n represented as [v0,...,vN-1]. The default choice if none of the\n conditions are met is given as the default argument. \n \n The conditions are tested in order and the first one statisfied is\n used to select the choice. In other words, the elements of the\n output array are found from the following tree (notice the order of\n the conditions matters):\n \n if c0: v0\n elif c1: v1\n elif c2: v2\n ...\n elif cN-1: vN-1\n else: default\n \n Note, that one of the condition arrays must be large enough to handle\n the largest array in the choice list.\n \"\"\"\n n = len(condlist)\n n2 = len(choicelist)\n if n2 != n:\n raise ValueError, \"List of cases, must be same length as the list of conditions.\"\n choicelist.insert(0,default) \n S = 0\n pfac = 1\n for k in range(1,n+1):\n S += k * pfac * asarray(condlist[k-1])\n if k < n:\n pfac *= (1-asarray(condlist[k-1]))\n # handle special case of a 1-element condition but\n # a multi-element choice\n if type(S) in ScalarType or max(asarray(S).shape)==1:\n pfac = asarray(1)\n for k in range(n2+1):\n pfac = pfac + asarray(choicelist[k]) \n S = S*ones(asarray(pfac).shape)\n return choose(S, tuple(choicelist))\n\n# Basic operations\ndef amax(m,axis=-1):\n \"\"\"Returns the maximum of m along dimension axis. \n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return maximum.reduce(m,axis)\n\ndef amin(m,axis=-1):\n \"\"\"Returns the minimum of m along dimension axis.\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else: \n m = asarray(m)\n return minimum.reduce(m,axis)\n\n# Actually from Basis, but it fits in so naturally here...\n\ndef ptp(m,axis=-1):\n \"\"\"Returns the maximum - minimum along the the given dimension\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return amax(m,axis)-amin(m,axis)\n\ndef cumsum(m,axis=-1):\n \"\"\"Returns the cumulative sum of the elements along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return add.accumulate(m,axis)\n\ndef prod(m,axis=-1):\n \"\"\"Returns the product of the elements along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return multiply.reduce(m,axis)\n\ndef cumprod(m,axis=-1):\n \"\"\"Returns the cumulative product of the elments along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return multiply.accumulate(m,axis)\n\ndef diff(x, n=1,axis=-1):\n \"\"\"Calculates the nth order, discrete difference along given axis.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n if n > 1:\n return diff(x[slice1]-x[slice2], n-1, axis=axis)\n else:\n return x[slice1]-x[slice2]\n\n \ndef angle(z,deg=0):\n \"\"\"Return the angle of complex argument z.\"\"\"\n if deg:\n fact = 180/pi\n else:\n fact = 1.0\n z = asarray(z)\n if z.typecode() in ['D','F']:\n zimag = z.imag\n zreal = z.real\n else:\n zimag = 0\n zreal = z\n return arctan2(zimag,zreal) * fact\n\ndef unwrap(p,discont=pi,axis=-1):\n \"\"\"unwraps radian phase p by changing absolute jumps greater than\n discont to their 2*pi complement along the given axis.\n \"\"\"\n p = asarray(p)\n nd = len(p.shape)\n dd = diff(p,axis=axis)\n slice1 = [slice(None,None)]*nd # full slices\n slice1[axis] = slice(1,None)\n ddmod = mod(dd+pi,2*pi)-pi\n putmask(ddmod,(ddmod==-pi) & (dd > 0),pi)\n ph_correct = ddmod - dd;\n putmask(ph_correct,abs(dd)>> import scipy\n >>> a = array((0,0,0,1,2,3,2,1,0))\n >>> scipy.trim_zeros(a)\n array([1, 2, 3, 2, 1])\n \"\"\"\n first = 0\n if 'f' in trim or 'F' in trim:\n for i in filt:\n if i != 0.: break\n else: first = first + 1\n last = len(filt)\n if 'b' in trim or 'B' in trim:\n for i in filt[::-1]:\n if i != 0.: break\n else: last = last - 1\n return filt[first:last]\n\ndef unique(inseq):\n \"\"\"Returns unique items in 1-dimensional sequence.\n \"\"\"\n set = {}\n for item in inseq:\n set[item] = None\n return asarray(set.keys())\n\nimport sys\ndef disp(mesg, device=None, linefeed=1):\n \"\"\"Display a message to device (default is sys.stdout) with(out) linefeed.\n \"\"\"\n if device is None:\n device = sys.stdout\n if linefeed:\n device.write('%s\\n' % mesg)\n else:\n device.write('%s' % mesg)\n device.flush()\n return\n\n \n\n#-----------------------------------------------------------------------------\n# Test Routines\n#-----------------------------------------------------------------------------\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == '__main__':\n test()\n", "source_code_before": "import types\nimport Numeric\nN = Numeric\nfrom Numeric import *\nfrom scipy_base.fastumath import *\nimport _compiled_base\nfrom type_check import ScalarType, isscalar\n\n__all__ = ['round','any','all','logspace','linspace','fix','mod',\n 'select','trim_zeros','amax','amin','ptp','cumsum',\n 'prod','cumprod','diff','angle','unwrap','sort_complex',\n 'disp','unique']\n\nround = Numeric.around\nany = Numeric.sometrue\nall = Numeric.alltrue\n\n\ndef logspace(start,stop,num=50,endpoint=1):\n \"\"\" Evenly spaced samples on a logarithmic scale.\n\n Return num evenly spaced samples from 10**start to 10**stop. If\n endpoint=1 then last sample is 10**stop.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = Numeric.arange(0,num) * step + start\n else:\n step = (stop-start)/float(num)\n y = Numeric.arange(0,num) * step + start\n return Numeric.power(10.0,y)\n\ndef linspace(start,stop,num=50,endpoint=1,retstep=0):\n \"\"\" Evenly spaced samples.\n \n Return num evenly spaced samples from start to stop. If endpoint=1 then\n last sample is stop. If retstep is 1 then return the step value used.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = Numeric.arange(0,num) * step + start \n else:\n step = (stop-start)/float(num)\n y = Numeric.arange(0,num) * step + start\n if retstep:\n return y, step\n else:\n return y\n\ndef fix(x):\n \"\"\" Round x to nearest integer towards zero.\n \"\"\"\n x = Numeric.asarray(x)\n y = Numeric.floor(x)\n return Numeric.where(x<0,y+1,y)\n\ndef mod(x,y):\n \"\"\" x - y*floor(x/y)\n \n For numeric arrays, x % y has the same sign as x while\n mod(x,y) has the same sign as y.\n \"\"\"\n return x - y*Numeric.floor(x*1.0/y)\n\ndef select(condlist, choicelist, default=0):\n \"\"\" Returns an array comprised from different elements of choicelist\n depending on the list of conditions.\n\n condlist is a list of condition arrays containing ones or zeros\n \n choicelist is a list of choice matrices (of the \"same\" size as the\n arrays in condlist). The result array has the \"same\" size as the\n arrays in choicelist. If condlist is [c0,...,cN-1] then choicelist\n must be of length N. The elements of the choicelist can then be\n represented as [v0,...,vN-1]. The default choice if none of the\n conditions are met is given as the default argument. \n \n The conditions are tested in order and the first one statisfied is\n used to select the choice. In other words, the elements of the\n output array are found from the following tree (notice the order of\n the conditions matters):\n \n if c0: v0\n elif c1: v1\n elif c2: v2\n ...\n elif cN-1: vN-1\n else: default\n \n Note, that one of the condition arrays must be large enough to handle\n the largest array in the choice list.\n \"\"\"\n n = len(condlist)\n n2 = len(choicelist)\n if n2 != n:\n raise ValueError, \"List of cases, must be same length as the list of conditions.\"\n choicelist.insert(0,default) \n S = 0\n pfac = 1\n for k in range(1,n+1):\n S += k * pfac * asarray(condlist[k-1])\n if k < n:\n pfac *= (1-asarray(condlist[k-1]))\n # handle special case of a 1-element condition but\n # a multi-element choice\n if type(S) in ScalarType or max(asarray(S).shape)==1:\n pfac = asarray(1)\n for k in range(n2+1):\n pfac = pfac + asarray(choicelist[k]) \n S = S*ones(asarray(pfac).shape)\n return choose(S, tuple(choicelist))\n\n# Basic operations\ndef amax(m,axis=-1):\n \"\"\"Returns the maximum of m along dimension axis. \n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return maximum.reduce(m,axis)\n\ndef amin(m,axis=-1):\n \"\"\"Returns the minimum of m along dimension axis.\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else: \n m = asarray(m)\n return minimum.reduce(m,axis)\n\n# Actually from Basis, but it fits in so naturally here...\n\ndef ptp(m,axis=-1):\n \"\"\"Returns the maximum - minimum along the the given dimension\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return amax(m,axis)-amin(m,axis)\n\ndef cumsum(m,axis=-1):\n \"\"\"Returns the cumulative sum of the elements along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return add.accumulate(m,axis)\n\ndef prod(m,axis=-1):\n \"\"\"Returns the product of the elements along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return multiply.reduce(m,axis)\n\ndef cumprod(m,axis=-1):\n \"\"\"Returns the cumulative product of the elments along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return multiply.accumulate(m,axis)\n\ndef diff(x, n=1,axis=-1):\n \"\"\"Calculates the nth order, discrete difference along given axis.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n if n > 1:\n return diff(x[slice1]-x[slice2], n-1, axis=axis)\n else:\n return x[slice1]-x[slice2]\n\n \ndef angle(z,deg=0):\n \"\"\"Return the angle of complex argument z.\"\"\"\n if deg:\n fact = 180/pi\n else:\n fact = 1.0\n z = asarray(z)\n if z.typecode() in ['D','F']:\n zimag = z.imag\n zreal = z.real\n else:\n zimag = 0\n zreal = z\n return arctan2(zimag,zreal) * fact\n\ndef unwrap(p,discont=pi,axis=-1):\n \"\"\"unwraps radian phase p by changing absolute jumps greater than\n discont to their 2*pi complement along the given axis.\n \"\"\"\n p = asarray(p)\n nd = len(p.shape)\n dd = diff(p,axis=axis)\n slice1 = [slice(None,None)]*nd # full slices\n slice1[axis] = slice(1,None)\n ddmod = mod(dd+pi,2*pi)-pi\n putmask(ddmod,(ddmod==-pi) & (dd > 0),pi)\n ph_correct = ddmod - dd;\n putmask(ph_correct,abs(dd)>> import scipy\n >>> a = array((0,0,0,1,2,3,2,1,0))\n >>> scipy.trim_zeros(a)\n array([1, 2, 3, 2, 1])\n \"\"\"\n first = 0\n if 'f' in trim or 'F' in trim:\n for i in filt:\n if i != 0.: break\n else: first = first + 1\n last = len(filt)\n if 'b' in trim or 'B' in trim:\n for i in filt[::-1]:\n if i != 0.: break\n else: last = last - 1\n return filt[first:last]\n\ndef unique(inseq):\n \"\"\"Returns unique items in 1-dimensional sequence.\n \"\"\"\n set = {}\n map(set.__setitem__, inseq, [])\n return asarray(set.keys())\n\nimport sys\ndef disp(mesg, device=None, linefeed=1):\n \"\"\"Display a message to device (default is sys.stdout) with(out) linefeed.\n \"\"\"\n if device is None:\n device = sys.stdout\n if linefeed:\n device.write('%s\\n' % mesg)\n else:\n device.write('%s' % mesg)\n device.flush()\n return\n\n \n\n#-----------------------------------------------------------------------------\n# Test Routines\n#-----------------------------------------------------------------------------\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == '__main__':\n test()\n", "methods": [ { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 19, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = 1 , retstep = 0 )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 34, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "fix", "long_name": "fix( x )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "x" ], "start_line": 52, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "mod", "long_name": "mod( x , y )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "x", "y" ], "start_line": 59, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "select", "long_name": "select( condlist , choicelist , default = 0 )", "filename": "function_base.py", "nloc": 18, "complexity": 7, "token_count": 165, "parameters": [ "condlist", "choicelist", "default" ], "start_line": 67, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 116, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 126, "end_line": 134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 47, "parameters": [ "m", "axis" ], "start_line": 138, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "cumsum", "long_name": "cumsum( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 148, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "prod", "long_name": "prod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 158, "end_line": 166, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 168, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "diff", "long_name": "diff( x , n = 1 , axis = - 1 )", "filename": "function_base.py", "nloc": 11, "complexity": 2, "token_count": 110, "parameters": [ "x", "n", "axis" ], "start_line": 178, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "angle", "long_name": "angle( z , deg = 0 )", "filename": "function_base.py", "nloc": 13, "complexity": 3, "token_count": 71, "parameters": [ "z", "deg" ], "start_line": 193, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "unwrap", "long_name": "unwrap( p , discont = pi , axis = - 1 )", "filename": "function_base.py", "nloc": 13, "complexity": 1, "token_count": 146, "parameters": [ "p", "discont", "axis" ], "start_line": 208, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "sort_complex.complex_cmp", "long_name": "sort_complex.complex_cmp( x , y )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "x", "y" ], "start_line": 229, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "sort_complex", "long_name": "sort_complex( a )", "filename": "function_base.py", "nloc": 6, "complexity": 1, "token_count": 44, "parameters": [ "a" ], "start_line": 225, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "trim_zeros", "long_name": "trim_zeros( filt , trim = 'fb' )", "filename": "function_base.py", "nloc": 12, "complexity": 9, "token_count": 87, "parameters": [ "filt", "trim" ], "start_line": 238, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "unique", "long_name": "unique( inseq )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "inseq" ], "start_line": 259, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "disp", "long_name": "disp( mesg , device = None , linefeed = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 51, "parameters": [ "mesg", "device", "linefeed" ], "start_line": 268, "end_line": 278, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 286, "end_line": 288, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 290, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 19, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = 1 , retstep = 0 )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 34, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "fix", "long_name": "fix( x )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "x" ], "start_line": 52, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "mod", "long_name": "mod( x , y )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "x", "y" ], "start_line": 59, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "select", "long_name": "select( condlist , choicelist , default = 0 )", "filename": "function_base.py", "nloc": 18, "complexity": 7, "token_count": 165, "parameters": [ "condlist", "choicelist", "default" ], "start_line": 67, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 116, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 126, "end_line": 134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 47, "parameters": [ "m", "axis" ], "start_line": 138, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "cumsum", "long_name": "cumsum( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 148, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "prod", "long_name": "prod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 158, "end_line": 166, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 168, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "diff", "long_name": "diff( x , n = 1 , axis = - 1 )", "filename": "function_base.py", "nloc": 11, "complexity": 2, "token_count": 110, "parameters": [ "x", "n", "axis" ], "start_line": 178, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "angle", "long_name": "angle( z , deg = 0 )", "filename": "function_base.py", "nloc": 13, "complexity": 3, "token_count": 71, "parameters": [ "z", "deg" ], "start_line": 193, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "unwrap", "long_name": "unwrap( p , discont = pi , axis = - 1 )", "filename": "function_base.py", "nloc": 13, "complexity": 1, "token_count": 146, "parameters": [ "p", "discont", "axis" ], "start_line": 208, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "sort_complex.complex_cmp", "long_name": "sort_complex.complex_cmp( x , y )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "x", "y" ], "start_line": 229, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "sort_complex", "long_name": "sort_complex( a )", "filename": "function_base.py", "nloc": 6, "complexity": 1, "token_count": 44, "parameters": [ "a" ], "start_line": 225, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "trim_zeros", "long_name": "trim_zeros( filt , trim = 'fb' )", "filename": "function_base.py", "nloc": 12, "complexity": 9, "token_count": 87, "parameters": [ "filt", "trim" ], "start_line": 238, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "unique", "long_name": "unique( inseq )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "inseq" ], "start_line": 259, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "disp", "long_name": "disp( mesg , device = None , linefeed = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 51, "parameters": [ "mesg", "device", "linefeed" ], "start_line": 267, "end_line": 277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 285, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 289, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "unique", "long_name": "unique( inseq )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "inseq" ], "start_line": 259, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 } ], "nloc": 183, "complexity": 53, "token_count": 1424, "diff_parsed": { "added": [ " for item in inseq:", " set[item] = None" ], "deleted": [ " map(set.__setitem__, inseq, [])" ] } } ] }, { "hash": "8b32c6733a6ab787db59097d63c457c4f01f342e", "msg": "merging differences between support for \"catchall\" converters and the vtk converter.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-09-17T22:59:14+00:00", "author_timezone": 0, "committer_date": "2002-09-17T22:59:14+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "f8fc8923f2ed8d4da323558092b1307383aa5685" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 0, "insertions": 14, "lines": 14, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "weave/converters.py", "new_path": "weave/converters.py", "filename": "converters.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -52,6 +52,13 @@\n except IndexError: \n pass\n \n+#------------------------------------------------------------------------\n+# Add \"sentinal\" catchall converter\n+#\n+# if everything else fails, this one is the last hope (it always works)\n+#-----------------------------------------------------------------------\n+\n+default.append(c_spec.catchall_converter())\n \n standard_info = [common_info.basic_module_info()]\n standard_info += [x.generate_build_info() for x in default]\n@@ -64,3 +71,10 @@\n import blitz_spec\n blitz = [blitz_spec.array_converter()] + default\n \n+#------------------------------------------------------------------------\n+# Add \"sentinal\" catchall converter\n+#\n+# if everything else fails, this one is the last hope (it always works)\n+#-----------------------------------------------------------------------\n+\n+blitz.append(c_spec.catchall_converter())\n", "added_lines": 14, "deleted_lines": 0, "source_code": "\"\"\" converters.py\n\"\"\"\n\nimport common_info\nimport c_spec\n\n#----------------------------------------------------------------------------\n# The \"standard\" conversion classes\n#----------------------------------------------------------------------------\n\ndefault = [c_spec.int_converter(),\n c_spec.float_converter(),\n c_spec.complex_converter(),\n c_spec.unicode_converter(),\n c_spec.string_converter(),\n c_spec.list_converter(),\n c_spec.dict_converter(),\n c_spec.tuple_converter(),\n c_spec.file_converter(),\n c_spec.callable_converter(),\n c_spec.instance_converter(),] \n #common_spec.module_converter()]\n\n#----------------------------------------------------------------------------\n# If Numeric is installed, add numeric array converters to the default\n# converter list.\n#----------------------------------------------------------------------------\ntry: \n import standard_array_spec\n default.append(standard_array_spec.array_converter())\nexcept ImportError: \n pass \n\n#----------------------------------------------------------------------------\n# Add wxPython support\n#----------------------------------------------------------------------------\n\ntry: \n # this is currently safe because it doesn't import wxPython.\n import wx_spec\n default.insert(0,wx_spec.wx_converter())\nexcept IndexError: \n pass \n\n#------------------------------------------------------------------------\n# Add VTK support\n#-----------------------------------------------------------------------\n\ntry: \n import vtk_spec\n default.insert(0,vtk_spec.vtk_converter())\nexcept IndexError: \n pass\n\n#------------------------------------------------------------------------\n# Add \"sentinal\" catchall converter\n#\n# if everything else fails, this one is the last hope (it always works)\n#-----------------------------------------------------------------------\n\ndefault.append(c_spec.catchall_converter())\n\nstandard_info = [common_info.basic_module_info()]\nstandard_info += [x.generate_build_info() for x in default]\n\n#----------------------------------------------------------------------------\n# Blitz conversion classes\n#\n# same as default, but will convert Numeric arrays to blitz C++ classes \n#----------------------------------------------------------------------------\nimport blitz_spec\nblitz = [blitz_spec.array_converter()] + default\n\n#------------------------------------------------------------------------\n# Add \"sentinal\" catchall converter\n#\n# if everything else fails, this one is the last hope (it always works)\n#-----------------------------------------------------------------------\n\nblitz.append(c_spec.catchall_converter())\n", "source_code_before": "\"\"\" converters.py\n\"\"\"\n\nimport common_info\nimport c_spec\n\n#----------------------------------------------------------------------------\n# The \"standard\" conversion classes\n#----------------------------------------------------------------------------\n\ndefault = [c_spec.int_converter(),\n c_spec.float_converter(),\n c_spec.complex_converter(),\n c_spec.unicode_converter(),\n c_spec.string_converter(),\n c_spec.list_converter(),\n c_spec.dict_converter(),\n c_spec.tuple_converter(),\n c_spec.file_converter(),\n c_spec.callable_converter(),\n c_spec.instance_converter(),] \n #common_spec.module_converter()]\n\n#----------------------------------------------------------------------------\n# If Numeric is installed, add numeric array converters to the default\n# converter list.\n#----------------------------------------------------------------------------\ntry: \n import standard_array_spec\n default.append(standard_array_spec.array_converter())\nexcept ImportError: \n pass \n\n#----------------------------------------------------------------------------\n# Add wxPython support\n#----------------------------------------------------------------------------\n\ntry: \n # this is currently safe because it doesn't import wxPython.\n import wx_spec\n default.insert(0,wx_spec.wx_converter())\nexcept IndexError: \n pass \n\n#------------------------------------------------------------------------\n# Add VTK support\n#-----------------------------------------------------------------------\n\ntry: \n import vtk_spec\n default.insert(0,vtk_spec.vtk_converter())\nexcept IndexError: \n pass\n\n\nstandard_info = [common_info.basic_module_info()]\nstandard_info += [x.generate_build_info() for x in default]\n\n#----------------------------------------------------------------------------\n# Blitz conversion classes\n#\n# same as default, but will convert Numeric arrays to blitz C++ classes \n#----------------------------------------------------------------------------\nimport blitz_spec\nblitz = [blitz_spec.array_converter()] + default\n\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 36, "complexity": 0, "token_count": 188, "diff_parsed": { "added": [ "#------------------------------------------------------------------------", "# Add \"sentinal\" catchall converter", "#", "# if everything else fails, this one is the last hope (it always works)", "#-----------------------------------------------------------------------", "", "default.append(c_spec.catchall_converter())", "#------------------------------------------------------------------------", "# Add \"sentinal\" catchall converter", "#", "# if everything else fails, this one is the last hope (it always works)", "#-----------------------------------------------------------------------", "", "blitz.append(c_spec.catchall_converter())" ], "deleted": [] } } ] }, { "hash": "70c9caef428752d7fff46c747f114303dc079800", "msg": "added scipy_test (actually reinstated it) to the repository. It now holds auto_test.py testing.py and logging.py\n\nIn the long run, logging.py is going to be part of python, so it will disappear. auto_test.py isn't getting used directly either, so its presence isn't absolutely necessary. For now, we'll leave it.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-09-18T03:34:40+00:00", "author_timezone": 0, "committer_date": "2002-09-18T03:34:40+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "8b32c6733a6ab787db59097d63c457c4f01f342e" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 0, "insertions": 2905, "lines": 2905, "files": 3, "dmm_unit_size": 0.6424831712789828, "dmm_unit_complexity": 0.8399401645474944, "dmm_unit_interfacing": 0.5721765145848915, "modified_files": [ { "old_path": null, "new_path": "scipy_test/auto_test.py", "filename": "auto_test.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,810 @@\n+\"\"\" Auto test tools for SciPy\n+\n+ Do not run this as root! If you enter something\n+ like /usr as your test directory, it'll delete\n+ /usr/bin, usr/lib, etc. So don't do it!!!\n+ \n+ \n+ Author: Eric Jones (eric@enthought.com)\n+\"\"\"\n+from distutils import file_util\n+from distutils import dir_util\n+from distutils.errors import DistutilsFileError\n+#import tarfile\n+import sys, os, stat, time\n+import gzip\n+import tempfile, cStringIO\n+import urllib\n+import logging\n+\n+if sys.platform == 'cygwin':\n+ local_repository = \"/cygdrive/i/tarballs\"\n+elif sys.platform == 'win32': \n+ local_repository = \"i:\\tarballs\"\n+else:\n+ local_repository = \"/home/shared/tarballs\"\n+\n+local_mail_server = \"enthought.com\"\n+\n+python_ftp_url = \"ftp://ftp.python.org/pub/python\"\n+numeric_url = \"http://prdownloads.sourceforge.net/numpy\"\n+f2py_url = \"http://cens.ioc.ee/projects/f2py2e/2.x\"\n+scipy_url = \"ftp://www.scipy.org/pub\"\n+blas_url = \"http://www.netlib.org/blas\"\n+lapack_url = \"http://www.netlib.org/lapack\"\n+#atlas_url = \"http://prdownloads.sourceforge.net/math-atlas\"\n+atlas_url = \"http://www.scipy.org/Members/eric\"\n+\n+\n+#-----------------------------------------------------------------------------\n+# Generic installation class. \n+# built to handle downloading/untarring/building/installing arbitrary software\n+#-----------------------------------------------------------------------------\n+\n+class package_installation: \n+ def __init__(self,version='', dst_dir = '.',\n+ logger = None, python_exe='python'):\n+ #---------------------------------------------------------------------\n+ # These should be defined in sub-class before calling this\n+ # constructor\n+ #---------------------------------------------------------------------\n+ # \n+ #self.package_url -- The name of the url where tarball can be found.\n+ #self.package_base_name -- The base name of the source tarball.\n+ #self.package_dir_name -- Top level directory of unpacked tarball\n+ #self.tarball_suffix -- usually tar.gz or .tgz\n+ #self.build_type -- 'make' or 'setup' for makefile or python setup file\n+ \n+ # Version of the software package.\n+ self.version = version\n+\n+ # Only used by packages built with setup.py\n+ self.python_exe = python_exe\n+ \n+ # Directory where package is unpacked/built/installed\n+ self.dst_dir = os.path.abspath(dst_dir) \n+ \n+ if not logger:\n+ self.logger = logging\n+ else:\n+ self.logger = logger \n+\n+ # make sure the destination exists\n+ make_dir(self.dst_dir,logger=self.logger)\n+\n+ # Construct any derived names built from the above names.\n+ self.init_names()\n+ \n+ def init_names(self): \n+ self.package_dir = os.path.join(self.dst_dir,self.package_dir_name)\n+ self.tarball = self.package_base_name + '.' + self.tarball_suffix\n+\n+ def get_source(self):\n+ \"\"\" Grab the source tarball from a repository.\n+ \n+ Try a local repository first. If the file isn't found,\n+ grab it from an ftp site.\n+ \"\"\"\n+ local_found = 0\n+ if self.local_source_up_to_date():\n+ try:\n+ self.get_source_local()\n+ local_found = 1 \n+ except DistutilsFileError:\n+ pass\n+ \n+ if not local_found:\n+ self.get_source_ftp()\n+ \n+ def local_source_up_to_date(self):\n+ \"\"\" Hook to test whether a file found in the repository is current\n+ \"\"\"\n+ return 1\n+ \n+ def get_source_local(self):\n+ \"\"\" Grab the requested tarball from a local repository of source\n+ tarballs. If it doesn't exist, an error is raised.\n+ \"\"\"\n+ file = os.path.join(local_repository,self.tarball) \n+ dst_file = os.path.join(self.dst_dir,self.tarball)\n+ self.logger.info(\"Searching local repository for %s\" % file)\n+ try:\n+ copy_file(file,dst_file,self.logger)\n+ except DistutilsFileError, msg:\n+ self.logger.info(\"Not found:\",msg)\n+ raise\n+ \n+ def get_source_ftp(self):\n+ \"\"\" Grab requested tarball from a ftp site specified as a url. \n+ \"\"\"\n+ url = '/'.join([self.package_url,self.tarball])\n+ \n+ self.logger.info('Opening: %s' % url)\n+ f = urllib.urlopen(url)\n+ self.logger.info('Downloading: this may take a while')\n+ contents = f.read(-1)\n+ f.close()\n+ self.logger.info('Finished download (size=%d)' % len(contents))\n+ \n+ output_file = os.path.join(self.dst_dir,self.tarball)\n+ write_file(output_file,contents,self.logger)\n+\n+ # Put file in local repository so we don't have to download it again.\n+ self.logger.info(\"Caching file in repository\" )\n+ src_file = output_file\n+ repos_file = os.path.join(local_repository,self.tarball) \n+ copy_file(src_file,repos_file,self.logger)\n+\n+ def unpack_source(self,sub_dir = None):\n+ \"\"\" equivalent to 'tar -xzvf file' in the given sub_dir\n+ \"\"\" \n+ tarfile = os.path.join(self.dst_dir,self.tarball)\n+ old_dir = None\n+ \n+ # copy and move into sub directory if it is specified.\n+ if sub_dir:\n+ dst_dir = os.path.join(self.dst_dir,sub_dir)\n+ dst_file = os.path.join(dst_dir,self.tarball)\n+ copy_file(tarfile,dst_file)\n+ change_dir(dst_dir,self.logger)\n+ try:\n+ try:\n+ # occasionally the tarball is not zipped, try this first.\n+ untar_file(self.tarball,self.dst_dir,\n+ self.logger,silent_failure=1)\n+ except:\n+ # otherwise, handle the fact that it is zipped \n+ dst = os.path.join(self.dst_dir,'tmp.tar') \n+ decompress_file(tarfile,dst,self.logger) \n+ untar_file(dst,self.dst_dir,self.logger)\n+ remove_file(dst,self.logger)\n+ finally:\n+ if old_dir:\n+ unchange_dir(self.logger)\n+\n+ #def auto_configure(self):\n+ # cmd = os.path.join('.','configure')\n+ # try:\n+ # text = run_command(cmd,self.package_dir,self.logger,log_output=0)\n+ # except ValueError, e:\n+ # status, text = e\n+ # self.logger.exception('Configuration Error:\\n'+text)\n+ def auto_configure(self):\n+ cmd = os.path.join('.','configure')\n+ text = run_command(cmd,self.package_dir,self.logger)\n+ \n+ def build_with_make(self):\n+ cmd = 'make'\n+ text = run_command(cmd,self.package_dir,self.logger)\n+ \n+ def install_with_make(self, prefix = None):\n+ if prefix is None:\n+ prefix = os.path.abspath(self.dst_dir)\n+ cmd = 'make install prefix=%s' % prefix\n+ text = run_command(cmd,self.package_dir,self.logger)\n+ \n+ def python_setup(self):\n+ cmd = self.python_exe + ' setup.py install'\n+ text = run_command(cmd,self.package_dir,self.logger)\n+ \n+ def _make(self,**kw):\n+ \"\"\" This generally needs to be overrridden in the derived class,\n+ but this will suffice for the standard configure/make process. \n+ \"\"\"\n+ self.logger.info(\"### Begin Configure: %s\" % self.package_base_name)\n+ self.auto_configure()\n+ self.logger.info(\"### Finished Configure: %s\" % self.package_base_name)\n+ self.logger.info(\"### Begin Build: %s\" % self.package_base_name)\n+ self.build_with_make()\n+ self.logger.info(\"### Finished Build: %s\" % self.package_base_name)\n+ self.logger.info(\"### Begin Install: %s\" % self.package_base_name)\n+ self.install_with_make()\n+ self.logger.info(\"### Finished Install: %s\" % self.package_base_name)\n+\n+ def install(self):\n+ self.logger.info('####### Building: %s' % self.package_base_name)\n+ self.logger.info(' Version: %s' % self.version)\n+ self.logger.info(' Url: %s' % self.package_url)\n+ self.logger.info(' Install dir: %s' % self.dst_dir)\n+ self.logger.info(' Package dir: %s' % self.package_dir)\n+ self.logger.info(' Suffix: %s' % self.tarball_suffix)\n+ self.logger.info(' Build type: %s' % self.build_type)\n+\n+ self.logger.info(\"### Begin Get Source: %s\" % self.package_base_name)\n+ self.get_source()\n+ self.unpack_source()\n+ self.logger.info(\"### Finished Get Source: %s\" % self.package_base_name)\n+\n+ if self.build_type == 'setup':\n+ self.python_setup()\n+ else: \n+ self._make()\n+ self.logger.info('####### Finished Building: %s' % self.package_base_name) \n+ \n+#-----------------------------------------------------------------------------\n+# Installation class for Python itself.\n+#-----------------------------------------------------------------------------\n+ \n+class python_installation(package_installation):\n+ \n+ def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n+ \n+ # Specialization for Python. \n+ self.package_base_name = 'Python-'+version\n+ self.package_dir_name = self.package_base_name\n+ self.package_url = '/'.join([python_ftp_url,version])\n+ self.tarball_suffix = 'tgz'\n+ self.build_type = 'make'\n+ \n+ package_installation.__init__(self,version,dst_dir,logger,python_exe)\n+\n+ def write_install_config(self): \n+ \"\"\" Make doesn't seem to install scripts in the correct places.\n+ \n+ Writing this to the python directory will solve the problem.\n+ [install_script]\n+ install-dir= \n+ \"\"\"\n+ self.logger.info('### Writing Install Script Hack')\n+ text = \"[install_scripts]\\n\"\\\n+ \"install-dir='%s'\" % os.path.join(self.dst_dir,'bin')\n+ file = os.path.join(self.package_dir,'setup.cfg') \n+ write_file(file,text,self.logger,mode='w')\n+ self.logger.info('### Finished writing Install Script Hack')\n+\n+ def install_with_make(self):\n+ \"\"\" Scripts were failing to install correctly, so a setuo.cfg\n+ file is written to force installation in the correct place.\n+ \"\"\" \n+ self.write_install_config()\n+ package_installation.install_with_make(self)\n+\n+ def get_exe_name(self):\n+ pyname = os.path.join('.','python')\n+ cmd = pyname + \"\"\" -c \"import sys;print '%d.%d' % sys.version_info[:2]\" \"\"\"\n+ text = run_command(cmd,self.package_dir,self.logger)\n+ exe = os.path.join(self.dst_dir,'bin','python'+text)\n+ return exe\n+\n+#-----------------------------------------------------------------------------\n+# Installation class for Blas.\n+#-----------------------------------------------------------------------------\n+\n+class blas_installation(package_installation):\n+ \n+ def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n+ \n+ # Specialization for for \"slow\" blas\n+ self.package_base_name = 'blas'\n+ self.package_dir_name = 'BLAS'\n+ self.package_url = blas_url\n+ self.tarball_suffix = 'tgz'\n+ self.build_type = 'make'\n+ \n+ self.platform = 'LINUX'\n+ package_installation.__init__(self,version,dst_dir,logger,python_exe)\n+\n+ def unpack_source(self,subdir=None):\n+ \"\"\" Dag. blas.tgz doesn't have directory information -- its\n+ just a tar ball of fortran source code. untar it in the\n+ BLAS directory\n+ \"\"\"\n+ package_installation.unpack_source(self,self.package_dir_name)\n+ \n+ def auto_configure(self):\n+ # nothing to do.\n+ pass\n+ def build_with_make(self, **kw):\n+ libname = 'blas_LINUX.a'\n+ cmd = 'g77 -funroll-all-loops -fno-f2c -O3 -c *.f;ar -cru %s' % libname\n+ text = run_command(cmd,self.package_dir,self.logger)\n+ \n+ def install_with_make(self, **kw):\n+ # not really using make -- we'll just copy the file over. \n+ src_file = os.path.join(self.package_dir,'blas_%s.a' % self.platform)\n+ dst_file = os.path.join(self.dst_dir,'lib','libblas.a')\n+ self.logger.info(\"Installing blas\")\n+ copy_file(src_file,dst_file,self.logger)\n+ \n+#-----------------------------------------------------------------------------\n+# Installation class for Lapack.\n+#-----------------------------------------------------------------------------\n+\n+class lapack_installation(package_installation):\n+ \n+ def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n+ \n+ # Specialization for Lapack 3.0 + updates \n+ self.package_base_name = 'lapack'\n+ self.package_dir_name = 'LAPACK'\n+ self.package_url = lapack_url\n+ self.tarball_suffix = 'tgz'\n+ self.build_type = 'make'\n+ \n+ self.platform = 'LINUX'\n+ package_installation.__init__(self,version,dst_dir,logger,python_exe)\n+\n+ def auto_configure(self):\n+ # perhaps this should actually override auto_conifgure\n+ # before make, we need to copy the appropriate setup file in.\n+ # should work anywhere g77 works...\n+ make_inc = 'make.inc.' + self.platform\n+ src_file = os.path.join(self.package_dir,'INSTALL',make_inc)\n+ dst_file = os.path.join(self.package_dir,'make.inc')\n+ copy_file(src_file,dst_file,self.logger)\n+ \n+ def build_with_make(self, **kw):\n+ cmd = 'make install lapacklib'\n+ text = run_command(cmd,self.package_dir,self.logger)\n+ \n+ def install_with_make(self, **kw):\n+ # not really using make -- we'll just copy the file over.\n+ src_file = os.path.join(self.package_dir,'lapack_%s.a' % self.platform)\n+ dst_file = os.path.join(self.dst_dir,'lib','liblapack.a') \n+ copy_file(src_file,dst_file,self.logger)\n+\n+#-----------------------------------------------------------------------------\n+# Installation class for Numeric\n+#-----------------------------------------------------------------------------\n+\n+class numeric_installation(package_installation):\n+ \n+ def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n+ \n+ self.package_base_name = 'Numeric-'+version\n+ self.package_dir_name = self.package_base_name\n+ self.package_url = numeric_url\n+ self.tarball_suffix = 'tar.gz'\n+ self.build_type = 'setup' \n+\n+ package_installation.__init__(self,version,dst_dir,logger,python_exe)\n+\n+\n+#-----------------------------------------------------------------------------\n+# Installation class for f2py\n+#-----------------------------------------------------------------------------\n+\n+class f2py_installation(package_installation):\n+ \n+ def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n+ \n+ # Typical file format: F2PY-2.13.175-1250.tar.gz\n+ self.package_base_name = 'F2PY-'+version\n+ self.package_dir_name = self.package_base_name\n+ self.package_url = f2py_url\n+ self.tarball_suffix = 'tar.gz'\n+ self.build_type = 'setup' \n+ \n+ package_installation.__init__(self,version,dst_dir,logger,python_exe)\n+\n+\n+#-----------------------------------------------------------------------------\n+# Installation class for Atlas.\n+# This is a binary install *NOT* a source install.\n+# The source install is a pain to automate.\n+#-----------------------------------------------------------------------------\n+\n+class atlas_installation(package_installation):\n+ \n+ def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n+ \n+ #self.package_base_name = 'atlas' + version\n+ #self.package_dir_name = 'ATLAS'\n+ self.package_base_name = 'atlas-RH7.1-PIII'\n+ self.package_dir_name = 'atlas'\n+ self.package_url = atlas_url\n+ self.tarball_suffix = 'tgz'\n+ self.build_type = 'make' \n+ \n+ package_installation.__init__(self,version,dst_dir,logger,python_exe)\n+\n+ def auto_configure(self,**kw):\n+ pass\n+ def build_with_make(self,**kw):\n+ pass\n+ def install_with_make(self, **kw):\n+ # just copy the tree over.\n+ dst = os.path.join(self.dst_dir,'lib','atlas')\n+ self.logger.info(\"Installing Atlas\")\n+ copy_tree(self.package_dir,dst,self.logger)\n+\n+#-----------------------------------------------------------------------------\n+# Installation class for scipy\n+#-----------------------------------------------------------------------------\n+\n+class scipy_installation(package_installation):\n+ \n+ def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n+ \n+ self.package_base_name = 'scipy_snapshot'\n+ self.package_dir_name = 'scipy'\n+ self.package_url = scipy_url\n+ self.tarball_suffix = 'tgz'\n+ self.build_type = 'setup'\n+ \n+ package_installation.__init__(self,version,dst_dir,logger,python_exe)\n+ \n+ def local_source_up_to_date(self):\n+ \"\"\" Hook to test whether a file found in the repository is current\n+ \"\"\"\n+ file = os.path.join(local_repository,self.tarball)\n+ up_to_date = 0\n+ try:\n+ file_time = os.stat(file)[stat.ST_MTIME] \n+ fyear,fmonth,fday = time.localtime(file_time)[:3]\n+ year,month,day = time.localtime()[:3]\n+ if fyear == year and fmonth == month and fday == day:\n+ up_to_date = 1\n+ self.logger.info(\"Repository file up to date: %s\" % file)\n+ except OSError, msg:\n+ pass\n+ return up_to_date\n+ \n+#-----------------------------------------------------------------------------\n+# Utilities\n+#-----------------------------------------------------------------------------\n+\n+\n+#if os.name == 'nt':\n+# def exec_command(command):\n+# \"\"\" not sure how to get exit status on nt. \"\"\"\n+# in_pipe,out_pipe = os.popen4(command)\n+# in_pipe.close()\n+# text = out_pipe.read()\n+# return 0, text\n+#else:\n+# import commands\n+# exec_command = commands.getstatusoutput\n+ \n+# This may not work on Win98... The above stuff was to handle these machines.\n+import commands\n+exec_command = commands.getstatusoutput\n+\n+def copy_file(src,dst,logger=None):\n+ if not logger:\n+ logger = logging\n+ logger.info(\"Copying %s->%s\" % (src,dst)) \n+ try:\n+ file_util.copy_file(src,dst)\n+ except Exception, e: \n+ logger.exception(\"Copy Failed\") \n+ raise\n+\n+def copy_tree(src,dst,logger=None):\n+ if not logger:\n+ logger = logging\n+ logger.info(\"Copying directory tree %s->%s\" % (src,dst)) \n+ try:\n+ dir_util.copy_tree(src,dst)\n+ except Exception, e: \n+ logger.exception(\"Copy Failed\") \n+ raise\n+\n+def remove_tree(directory,logger=None):\n+ if not logger:\n+ logger = logging\n+ logger.info(\"Removing directory tree %s\" % directory) \n+ try:\n+ dir_util.remove_tree(directory)\n+ except Exception, e: \n+ logger.exception(\"Remove failed: %s\" % e) \n+ raise\n+\n+def remove_file(file,logger=None):\n+ if not logger:\n+ logger = logging\n+ logger.info(\"Remove file %s\" % file) \n+ try:\n+ os.remove(file)\n+ except Exception, e: \n+ logger.exception(\"Remove failed\") \n+ raise\n+\n+def write_file(file,contents,logger=None,mode='wb'):\n+ if not logger:\n+ logger = logging\n+ logger.info('Write file: %s' % file)\n+ try:\n+ new_file = open(file,mode)\n+ new_file.write(contents)\n+ new_file.close()\n+ except Exception, e: \n+ logger.exception(\"Write failed\") \n+ raise\n+\n+def make_dir(name,logger=None):\n+ if not logger:\n+ logger = logging\n+ logger.info('Make directory: %s' % name)\n+ try: \n+ dir_util.mkpath(os.path.abspath(name))\n+ except Exception, e: \n+ logger.exception(\"Make Directory failed\") \n+ raise\n+\n+# I know, I know...\n+old_dir = []\n+\n+def change_dir(d, logger = None):\n+ if not logger:\n+ logger = logging\n+ global old_dir \n+ cwd = os.getcwd() \n+ old_dir.append(cwd)\n+ d = os.path.abspath(d)\n+ if d != old_dir[-1]:\n+ logger.info(\"Change directory: %s\" % d) \n+ try:\n+ os.chdir(d)\n+ except Exception, e: \n+ logger.exception(\"Change directory failed\")\n+ raise \n+ #if d == '.':\n+ # import sys,traceback\n+ # f = sys._getframe()\n+ # traceback.print_stack(f)\n+\n+def unchange_dir(logger=None):\n+ if not logger:\n+ logger = logging \n+ global old_dir\n+ try:\n+ cwd = os.getcwd()\n+ d = old_dir.pop(-1) \n+ try:\n+ if d != cwd:\n+ logger.info(\"Change directory : %s\" % d)\n+ os.chdir(d)\n+ except Exception, e: \n+ logger.exception(\"Change directory failed\")\n+ raise \n+ except IndexError:\n+ logger.exception(\"Change directory failed\")\n+ \n+def decompress_file(src,dst,logger = None):\n+ if not logger:\n+ logger = logging\n+ logger.info(\"Upacking %s->%s\" % (src,dst))\n+ try:\n+ f = gzip.open(src,'rb')\n+ contents = f.read(-1)\n+ f = open(dst, 'wb')\n+ f.write(contents)\n+ except Exception, e: \n+ logger.exception(\"Unpack failed\")\n+ raise \n+\n+ \n+def untar_file(file,dst_dir='.',logger = None,silent_failure = 0): \n+ if not logger:\n+ logger = logging\n+ logger.info(\"Untarring file: %s\" % (file))\n+ try:\n+ run_command('tar -xf ' + file,directory = dst_dir,\n+ logger=logger, silent_failure = silent_failure)\n+ except Exception, e:\n+ if not silent_failure: \n+ logger.exception(\"Untar failed\")\n+ raise \n+\n+def unpack_file(file,logger = None):\n+ \"\"\" equivalent to 'tar -xzvf file'\n+ \"\"\"\n+ dst = 'tmp.tar'\n+ decompress_file(file,dst,logger) \n+ untar_file(dst.logger)\n+ remove_file(dst,logger) \n+\n+\n+def run_command(cmd,directory='.',logger=None,silent_failure = 0):\n+ if not logger:\n+ logger = logging\n+ change_dir(directory,logger) \n+ try: \n+ msg = 'Running: %s' % cmd\n+ logger.info(msg) \n+ status,text = exec_command(cmd)\n+ if status and silent_failure:\n+ msg = '(failed silently)'\n+ logger.info(msg) \n+ if status and text and not silent_failure:\n+ logger.error('Command Failed (status=%d)\\n'% status +text)\n+ finally:\n+ unchange_dir(logger)\n+ if status:\n+ raise ValueError, (status,text)\n+ return text \n+\n+def mail_report(from_addr,to_addr,subject,mail_server,\n+ build_log, test_results,info):\n+ \n+ msg = ''\n+ msg = msg + 'To: %s\\n' % to_addr\n+ msg = msg + 'Subject: %s\\n' % subject\n+ msg = msg + '\\r\\n\\r\\n'\n+\n+ for k,v in info.items(): \n+ msg = msg + '%s: %s\\n' % (k,v)\n+ msg = msg + test_results + '\\n'\n+ msg = msg + '-----------------------------\\n' \n+ msg = msg + '-------- BUILD LOG -------\\n' \n+ msg = msg + '-----------------------------\\n' \n+ msg = msg + build_log\n+ print msg\n+ \n+ # mail results\n+ import smtplib \n+ server = smtplib.SMTP(mail_server) \n+ server.sendmail(from_addr, to_addr, msg)\n+ server.quit()\n+ \n+\n+def full_scipy_build(build_dir = '.',\n+ test_level = 10,\n+ python_version = '2.2.1',\n+ numeric_version = '21.0',\n+ f2py_version = '2.13.175-1250',\n+ atlas_version = '3.3.14',\n+ scipy_version = 'snapshot'):\n+ \n+ # for now the atlas version is ignored. Only the \n+ # binaries for RH are supported at the moment.\n+\n+ build_info = {'python_version' : python_version,\n+ 'test_level' : test_level,\n+ 'numeric_version': numeric_version,\n+ 'f2py_version' : f2py_version,\n+ 'atlas_version' : atlas_version,\n+ 'scipy_version' : scipy_version}\n+ \n+ dst_dir = os.path.join(build_dir,sys.platform)\n+\n+ logger = logging.Logger(\"SciPy Test\")\n+ fmt = logging.Formatter(logging.BASIC_FORMAT)\n+ log_stream = cStringIO.StringIO()\n+ stream_handler = logging.StreamHandler(log_stream)\n+ stream_handler.setFormatter(fmt)\n+ logger.addHandler(stream_handler)\n+ # also write to stderr\n+ stderr = logging.StreamHandler()\n+ stderr.setFormatter(fmt)\n+ logger.addHandler(stderr)\n+\n+ try:\n+ try: \n+ \n+ # before doing anything, we need to wipe the \n+ # /bin, /lib, /man, and /include directories\n+ # in dst_dir. Don't run as root. \n+ make_dir(dst_dir,logger=logger) \n+ change_dir(dst_dir , logger)\n+ for d in ['bin','lib','man','include']:\n+ try: remove_tree(d, logger)\n+ except OSError: pass \n+ unchange_dir(logger)\n+ \n+ python = python_installation(version=python_version,\n+ logger = logger,\n+ dst_dir = dst_dir)\n+ python.install()\n+ \n+ python_name = python.get_exe_name()\n+ \n+ numeric = numeric_installation(version=numeric_version,\n+ dst_dir = dst_dir,\n+ logger = logger,\n+ python_exe=python_name)\n+ numeric.install()\n+ \n+ f2py = f2py_installation(version=f2py_version,\n+ logger = logger,\n+ dst_dir = dst_dir,\n+ python_exe=python_name)\n+ f2py.install() \n+ \n+ # download files don't have a version specified \n+ #lapack = lapack_installation(version='',\n+ # dst_dir = dst_dir\n+ # python_exe=python_name)\n+ #lapack.install() \n+ \n+ # download files don't have a version specified \n+ #blas = blas_installation(version='',\n+ # logger = logger,\n+ # dst_dir = dst_dir,\n+ # python_exe=python_name)\n+ #blas.install() \n+ \n+ # ATLAS\n+ atlas = atlas_installation(version=atlas_version,\n+ logger = logger,\n+ dst_dir = dst_dir,\n+ python_exe=python_name)\n+ atlas.install()\n+ \n+ # version not currently used -- need to fix this.\n+ scipy = scipy_installation(version=scipy_version,\n+ logger = logger,\n+ dst_dir = dst_dir,\n+ python_exe=python_name)\n+ scipy.install() \n+ \n+ # The change to tmp makes sure there isn't a scipy directory in \n+ # the local scope.\n+ # All tests are run.\n+ logger.info('Beginning Test')\n+ cmd = python_name +' -c \"import sys,scipy;suite=scipy.test(%d);\"'\\\n+ % test_level\n+ test_results = run_command(cmd, logger=logger,\n+ directory = tempfile.gettempdir())\n+ build_info['results'] = 'test completed (check below for pass/fail)'\n+ except Exception, msg:\n+ test_results = ''\n+ build_info['results'] = 'build failed: %s' % msg\n+ logger.exception('Build failed')\n+ finally: \n+ to_addr = \"scipy-testlog@scipy.org\"\n+ from_addr = \"scipy-test@enthought.com\"\n+ subject = '%s,py%s,num%s,scipy%s' % (sys.platform,python_version,\n+ numeric_version,scipy_version) \n+ build_log = log_stream.getvalue()\n+ mail_report(from_addr,to_addr,subject,local_mail_server,\n+ build_log,test_results,build_info)\n+\n+if __name__ == '__main__':\n+ build_dir = '/tmp/scipy_test'\n+ level = 10\n+\n+ full_scipy_build(build_dir = build_dir,\n+ test_level = level,\n+ python_version = '2.2.1',\n+ numeric_version = '21.0',\n+ f2py_version = '2.13.175-1250',\n+ atlas_version = '3.3.14',\n+ scipy_version = 'snapshot')\n+\n+ # an older python\n+ full_scipy_build(build_dir = build_dir,\n+ test_level = level,\n+ python_version = '2.1.3',\n+ numeric_version = '21.0',\n+ f2py_version = '2.13.175-1250',\n+ atlas_version = '3.3.14',\n+ scipy_version = 'snapshot')\n+\n+ # an older numeric\n+ full_scipy_build(build_dir = build_dir,\n+ test_level = level,\n+ python_version = '2.1.3',\n+ numeric_version = '20.3',\n+ f2py_version = '2.13.175-1250',\n+ atlas_version = '3.3.14',\n+ scipy_version = 'snapshot')\n+\n+ # This fails because multiarray doesn't have \n+ # arange defined.\n+ \"\"\"\n+ full_scipy_build(build_dir = build_dir,\n+ test_level = level,\n+ python_version = '2.1.3',\n+ numeric_version = '20.0.0',\n+ f2py_version = '2.13.175-1250',\n+ atlas_version = '3.3.14',\n+ scipy_version = 'snapshot')\n+\n+ full_scipy_build(build_dir = build_dir,\n+ test_level = level,\n+ python_version = '2.1.3',\n+ numeric_version = '19.0.0',\n+ f2py_version = '2.13.175-1250',\n+ atlas_version = '3.3.14',\n+ scipy_version = 'snapshot')\n+\n+ full_scipy_build(build_dir = build_dir,\n+ test_level = level,\n+ python_version = '2.1.3',\n+ numeric_version = '18.4.1',\n+ f2py_version = '2.13.175-1250',\n+ atlas_version = '3.3.14',\n+ scipy_version = 'snapshot')\n+ \"\"\"\n", "added_lines": 810, "deleted_lines": 0, "source_code": "\"\"\" Auto test tools for SciPy\n\n Do not run this as root! If you enter something\n like /usr as your test directory, it'll delete\n /usr/bin, usr/lib, etc. So don't do it!!!\n \n \n Author: Eric Jones (eric@enthought.com)\n\"\"\"\nfrom distutils import file_util\nfrom distutils import dir_util\nfrom distutils.errors import DistutilsFileError\n#import tarfile\nimport sys, os, stat, time\nimport gzip\nimport tempfile, cStringIO\nimport urllib\nimport logging\n\nif sys.platform == 'cygwin':\n local_repository = \"/cygdrive/i/tarballs\"\nelif sys.platform == 'win32': \n local_repository = \"i:\\tarballs\"\nelse:\n local_repository = \"/home/shared/tarballs\"\n\nlocal_mail_server = \"enthought.com\"\n\npython_ftp_url = \"ftp://ftp.python.org/pub/python\"\nnumeric_url = \"http://prdownloads.sourceforge.net/numpy\"\nf2py_url = \"http://cens.ioc.ee/projects/f2py2e/2.x\"\nscipy_url = \"ftp://www.scipy.org/pub\"\nblas_url = \"http://www.netlib.org/blas\"\nlapack_url = \"http://www.netlib.org/lapack\"\n#atlas_url = \"http://prdownloads.sourceforge.net/math-atlas\"\natlas_url = \"http://www.scipy.org/Members/eric\"\n\n\n#-----------------------------------------------------------------------------\n# Generic installation class. \n# built to handle downloading/untarring/building/installing arbitrary software\n#-----------------------------------------------------------------------------\n\nclass package_installation: \n def __init__(self,version='', dst_dir = '.',\n logger = None, python_exe='python'):\n #---------------------------------------------------------------------\n # These should be defined in sub-class before calling this\n # constructor\n #---------------------------------------------------------------------\n # \n #self.package_url -- The name of the url where tarball can be found.\n #self.package_base_name -- The base name of the source tarball.\n #self.package_dir_name -- Top level directory of unpacked tarball\n #self.tarball_suffix -- usually tar.gz or .tgz\n #self.build_type -- 'make' or 'setup' for makefile or python setup file\n \n # Version of the software package.\n self.version = version\n\n # Only used by packages built with setup.py\n self.python_exe = python_exe\n \n # Directory where package is unpacked/built/installed\n self.dst_dir = os.path.abspath(dst_dir) \n \n if not logger:\n self.logger = logging\n else:\n self.logger = logger \n\n # make sure the destination exists\n make_dir(self.dst_dir,logger=self.logger)\n\n # Construct any derived names built from the above names.\n self.init_names()\n \n def init_names(self): \n self.package_dir = os.path.join(self.dst_dir,self.package_dir_name)\n self.tarball = self.package_base_name + '.' + self.tarball_suffix\n\n def get_source(self):\n \"\"\" Grab the source tarball from a repository.\n \n Try a local repository first. If the file isn't found,\n grab it from an ftp site.\n \"\"\"\n local_found = 0\n if self.local_source_up_to_date():\n try:\n self.get_source_local()\n local_found = 1 \n except DistutilsFileError:\n pass\n \n if not local_found:\n self.get_source_ftp()\n \n def local_source_up_to_date(self):\n \"\"\" Hook to test whether a file found in the repository is current\n \"\"\"\n return 1\n \n def get_source_local(self):\n \"\"\" Grab the requested tarball from a local repository of source\n tarballs. If it doesn't exist, an error is raised.\n \"\"\"\n file = os.path.join(local_repository,self.tarball) \n dst_file = os.path.join(self.dst_dir,self.tarball)\n self.logger.info(\"Searching local repository for %s\" % file)\n try:\n copy_file(file,dst_file,self.logger)\n except DistutilsFileError, msg:\n self.logger.info(\"Not found:\",msg)\n raise\n \n def get_source_ftp(self):\n \"\"\" Grab requested tarball from a ftp site specified as a url. \n \"\"\"\n url = '/'.join([self.package_url,self.tarball])\n \n self.logger.info('Opening: %s' % url)\n f = urllib.urlopen(url)\n self.logger.info('Downloading: this may take a while')\n contents = f.read(-1)\n f.close()\n self.logger.info('Finished download (size=%d)' % len(contents))\n \n output_file = os.path.join(self.dst_dir,self.tarball)\n write_file(output_file,contents,self.logger)\n\n # Put file in local repository so we don't have to download it again.\n self.logger.info(\"Caching file in repository\" )\n src_file = output_file\n repos_file = os.path.join(local_repository,self.tarball) \n copy_file(src_file,repos_file,self.logger)\n\n def unpack_source(self,sub_dir = None):\n \"\"\" equivalent to 'tar -xzvf file' in the given sub_dir\n \"\"\" \n tarfile = os.path.join(self.dst_dir,self.tarball)\n old_dir = None\n \n # copy and move into sub directory if it is specified.\n if sub_dir:\n dst_dir = os.path.join(self.dst_dir,sub_dir)\n dst_file = os.path.join(dst_dir,self.tarball)\n copy_file(tarfile,dst_file)\n change_dir(dst_dir,self.logger)\n try:\n try:\n # occasionally the tarball is not zipped, try this first.\n untar_file(self.tarball,self.dst_dir,\n self.logger,silent_failure=1)\n except:\n # otherwise, handle the fact that it is zipped \n dst = os.path.join(self.dst_dir,'tmp.tar') \n decompress_file(tarfile,dst,self.logger) \n untar_file(dst,self.dst_dir,self.logger)\n remove_file(dst,self.logger)\n finally:\n if old_dir:\n unchange_dir(self.logger)\n\n #def auto_configure(self):\n # cmd = os.path.join('.','configure')\n # try:\n # text = run_command(cmd,self.package_dir,self.logger,log_output=0)\n # except ValueError, e:\n # status, text = e\n # self.logger.exception('Configuration Error:\\n'+text)\n def auto_configure(self):\n cmd = os.path.join('.','configure')\n text = run_command(cmd,self.package_dir,self.logger)\n \n def build_with_make(self):\n cmd = 'make'\n text = run_command(cmd,self.package_dir,self.logger)\n \n def install_with_make(self, prefix = None):\n if prefix is None:\n prefix = os.path.abspath(self.dst_dir)\n cmd = 'make install prefix=%s' % prefix\n text = run_command(cmd,self.package_dir,self.logger)\n \n def python_setup(self):\n cmd = self.python_exe + ' setup.py install'\n text = run_command(cmd,self.package_dir,self.logger)\n \n def _make(self,**kw):\n \"\"\" This generally needs to be overrridden in the derived class,\n but this will suffice for the standard configure/make process. \n \"\"\"\n self.logger.info(\"### Begin Configure: %s\" % self.package_base_name)\n self.auto_configure()\n self.logger.info(\"### Finished Configure: %s\" % self.package_base_name)\n self.logger.info(\"### Begin Build: %s\" % self.package_base_name)\n self.build_with_make()\n self.logger.info(\"### Finished Build: %s\" % self.package_base_name)\n self.logger.info(\"### Begin Install: %s\" % self.package_base_name)\n self.install_with_make()\n self.logger.info(\"### Finished Install: %s\" % self.package_base_name)\n\n def install(self):\n self.logger.info('####### Building: %s' % self.package_base_name)\n self.logger.info(' Version: %s' % self.version)\n self.logger.info(' Url: %s' % self.package_url)\n self.logger.info(' Install dir: %s' % self.dst_dir)\n self.logger.info(' Package dir: %s' % self.package_dir)\n self.logger.info(' Suffix: %s' % self.tarball_suffix)\n self.logger.info(' Build type: %s' % self.build_type)\n\n self.logger.info(\"### Begin Get Source: %s\" % self.package_base_name)\n self.get_source()\n self.unpack_source()\n self.logger.info(\"### Finished Get Source: %s\" % self.package_base_name)\n\n if self.build_type == 'setup':\n self.python_setup()\n else: \n self._make()\n self.logger.info('####### Finished Building: %s' % self.package_base_name) \n \n#-----------------------------------------------------------------------------\n# Installation class for Python itself.\n#-----------------------------------------------------------------------------\n \nclass python_installation(package_installation):\n \n def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n \n # Specialization for Python. \n self.package_base_name = 'Python-'+version\n self.package_dir_name = self.package_base_name\n self.package_url = '/'.join([python_ftp_url,version])\n self.tarball_suffix = 'tgz'\n self.build_type = 'make'\n \n package_installation.__init__(self,version,dst_dir,logger,python_exe)\n\n def write_install_config(self): \n \"\"\" Make doesn't seem to install scripts in the correct places.\n \n Writing this to the python directory will solve the problem.\n [install_script]\n install-dir= \n \"\"\"\n self.logger.info('### Writing Install Script Hack')\n text = \"[install_scripts]\\n\"\\\n \"install-dir='%s'\" % os.path.join(self.dst_dir,'bin')\n file = os.path.join(self.package_dir,'setup.cfg') \n write_file(file,text,self.logger,mode='w')\n self.logger.info('### Finished writing Install Script Hack')\n\n def install_with_make(self):\n \"\"\" Scripts were failing to install correctly, so a setuo.cfg\n file is written to force installation in the correct place.\n \"\"\" \n self.write_install_config()\n package_installation.install_with_make(self)\n\n def get_exe_name(self):\n pyname = os.path.join('.','python')\n cmd = pyname + \"\"\" -c \"import sys;print '%d.%d' % sys.version_info[:2]\" \"\"\"\n text = run_command(cmd,self.package_dir,self.logger)\n exe = os.path.join(self.dst_dir,'bin','python'+text)\n return exe\n\n#-----------------------------------------------------------------------------\n# Installation class for Blas.\n#-----------------------------------------------------------------------------\n\nclass blas_installation(package_installation):\n \n def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n \n # Specialization for for \"slow\" blas\n self.package_base_name = 'blas'\n self.package_dir_name = 'BLAS'\n self.package_url = blas_url\n self.tarball_suffix = 'tgz'\n self.build_type = 'make'\n \n self.platform = 'LINUX'\n package_installation.__init__(self,version,dst_dir,logger,python_exe)\n\n def unpack_source(self,subdir=None):\n \"\"\" Dag. blas.tgz doesn't have directory information -- its\n just a tar ball of fortran source code. untar it in the\n BLAS directory\n \"\"\"\n package_installation.unpack_source(self,self.package_dir_name)\n \n def auto_configure(self):\n # nothing to do.\n pass\n def build_with_make(self, **kw):\n libname = 'blas_LINUX.a'\n cmd = 'g77 -funroll-all-loops -fno-f2c -O3 -c *.f;ar -cru %s' % libname\n text = run_command(cmd,self.package_dir,self.logger)\n \n def install_with_make(self, **kw):\n # not really using make -- we'll just copy the file over. \n src_file = os.path.join(self.package_dir,'blas_%s.a' % self.platform)\n dst_file = os.path.join(self.dst_dir,'lib','libblas.a')\n self.logger.info(\"Installing blas\")\n copy_file(src_file,dst_file,self.logger)\n \n#-----------------------------------------------------------------------------\n# Installation class for Lapack.\n#-----------------------------------------------------------------------------\n\nclass lapack_installation(package_installation):\n \n def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n \n # Specialization for Lapack 3.0 + updates \n self.package_base_name = 'lapack'\n self.package_dir_name = 'LAPACK'\n self.package_url = lapack_url\n self.tarball_suffix = 'tgz'\n self.build_type = 'make'\n \n self.platform = 'LINUX'\n package_installation.__init__(self,version,dst_dir,logger,python_exe)\n\n def auto_configure(self):\n # perhaps this should actually override auto_conifgure\n # before make, we need to copy the appropriate setup file in.\n # should work anywhere g77 works...\n make_inc = 'make.inc.' + self.platform\n src_file = os.path.join(self.package_dir,'INSTALL',make_inc)\n dst_file = os.path.join(self.package_dir,'make.inc')\n copy_file(src_file,dst_file,self.logger)\n \n def build_with_make(self, **kw):\n cmd = 'make install lapacklib'\n text = run_command(cmd,self.package_dir,self.logger)\n \n def install_with_make(self, **kw):\n # not really using make -- we'll just copy the file over.\n src_file = os.path.join(self.package_dir,'lapack_%s.a' % self.platform)\n dst_file = os.path.join(self.dst_dir,'lib','liblapack.a') \n copy_file(src_file,dst_file,self.logger)\n\n#-----------------------------------------------------------------------------\n# Installation class for Numeric\n#-----------------------------------------------------------------------------\n\nclass numeric_installation(package_installation):\n \n def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n \n self.package_base_name = 'Numeric-'+version\n self.package_dir_name = self.package_base_name\n self.package_url = numeric_url\n self.tarball_suffix = 'tar.gz'\n self.build_type = 'setup' \n\n package_installation.__init__(self,version,dst_dir,logger,python_exe)\n\n\n#-----------------------------------------------------------------------------\n# Installation class for f2py\n#-----------------------------------------------------------------------------\n\nclass f2py_installation(package_installation):\n \n def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n \n # Typical file format: F2PY-2.13.175-1250.tar.gz\n self.package_base_name = 'F2PY-'+version\n self.package_dir_name = self.package_base_name\n self.package_url = f2py_url\n self.tarball_suffix = 'tar.gz'\n self.build_type = 'setup' \n \n package_installation.__init__(self,version,dst_dir,logger,python_exe)\n\n\n#-----------------------------------------------------------------------------\n# Installation class for Atlas.\n# This is a binary install *NOT* a source install.\n# The source install is a pain to automate.\n#-----------------------------------------------------------------------------\n\nclass atlas_installation(package_installation):\n \n def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n \n #self.package_base_name = 'atlas' + version\n #self.package_dir_name = 'ATLAS'\n self.package_base_name = 'atlas-RH7.1-PIII'\n self.package_dir_name = 'atlas'\n self.package_url = atlas_url\n self.tarball_suffix = 'tgz'\n self.build_type = 'make' \n \n package_installation.__init__(self,version,dst_dir,logger,python_exe)\n\n def auto_configure(self,**kw):\n pass\n def build_with_make(self,**kw):\n pass\n def install_with_make(self, **kw):\n # just copy the tree over.\n dst = os.path.join(self.dst_dir,'lib','atlas')\n self.logger.info(\"Installing Atlas\")\n copy_tree(self.package_dir,dst,self.logger)\n\n#-----------------------------------------------------------------------------\n# Installation class for scipy\n#-----------------------------------------------------------------------------\n\nclass scipy_installation(package_installation):\n \n def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n \n self.package_base_name = 'scipy_snapshot'\n self.package_dir_name = 'scipy'\n self.package_url = scipy_url\n self.tarball_suffix = 'tgz'\n self.build_type = 'setup'\n \n package_installation.__init__(self,version,dst_dir,logger,python_exe)\n \n def local_source_up_to_date(self):\n \"\"\" Hook to test whether a file found in the repository is current\n \"\"\"\n file = os.path.join(local_repository,self.tarball)\n up_to_date = 0\n try:\n file_time = os.stat(file)[stat.ST_MTIME] \n fyear,fmonth,fday = time.localtime(file_time)[:3]\n year,month,day = time.localtime()[:3]\n if fyear == year and fmonth == month and fday == day:\n up_to_date = 1\n self.logger.info(\"Repository file up to date: %s\" % file)\n except OSError, msg:\n pass\n return up_to_date\n \n#-----------------------------------------------------------------------------\n# Utilities\n#-----------------------------------------------------------------------------\n\n\n#if os.name == 'nt':\n# def exec_command(command):\n# \"\"\" not sure how to get exit status on nt. \"\"\"\n# in_pipe,out_pipe = os.popen4(command)\n# in_pipe.close()\n# text = out_pipe.read()\n# return 0, text\n#else:\n# import commands\n# exec_command = commands.getstatusoutput\n \n# This may not work on Win98... The above stuff was to handle these machines.\nimport commands\nexec_command = commands.getstatusoutput\n\ndef copy_file(src,dst,logger=None):\n if not logger:\n logger = logging\n logger.info(\"Copying %s->%s\" % (src,dst)) \n try:\n file_util.copy_file(src,dst)\n except Exception, e: \n logger.exception(\"Copy Failed\") \n raise\n\ndef copy_tree(src,dst,logger=None):\n if not logger:\n logger = logging\n logger.info(\"Copying directory tree %s->%s\" % (src,dst)) \n try:\n dir_util.copy_tree(src,dst)\n except Exception, e: \n logger.exception(\"Copy Failed\") \n raise\n\ndef remove_tree(directory,logger=None):\n if not logger:\n logger = logging\n logger.info(\"Removing directory tree %s\" % directory) \n try:\n dir_util.remove_tree(directory)\n except Exception, e: \n logger.exception(\"Remove failed: %s\" % e) \n raise\n\ndef remove_file(file,logger=None):\n if not logger:\n logger = logging\n logger.info(\"Remove file %s\" % file) \n try:\n os.remove(file)\n except Exception, e: \n logger.exception(\"Remove failed\") \n raise\n\ndef write_file(file,contents,logger=None,mode='wb'):\n if not logger:\n logger = logging\n logger.info('Write file: %s' % file)\n try:\n new_file = open(file,mode)\n new_file.write(contents)\n new_file.close()\n except Exception, e: \n logger.exception(\"Write failed\") \n raise\n\ndef make_dir(name,logger=None):\n if not logger:\n logger = logging\n logger.info('Make directory: %s' % name)\n try: \n dir_util.mkpath(os.path.abspath(name))\n except Exception, e: \n logger.exception(\"Make Directory failed\") \n raise\n\n# I know, I know...\nold_dir = []\n\ndef change_dir(d, logger = None):\n if not logger:\n logger = logging\n global old_dir \n cwd = os.getcwd() \n old_dir.append(cwd)\n d = os.path.abspath(d)\n if d != old_dir[-1]:\n logger.info(\"Change directory: %s\" % d) \n try:\n os.chdir(d)\n except Exception, e: \n logger.exception(\"Change directory failed\")\n raise \n #if d == '.':\n # import sys,traceback\n # f = sys._getframe()\n # traceback.print_stack(f)\n\ndef unchange_dir(logger=None):\n if not logger:\n logger = logging \n global old_dir\n try:\n cwd = os.getcwd()\n d = old_dir.pop(-1) \n try:\n if d != cwd:\n logger.info(\"Change directory : %s\" % d)\n os.chdir(d)\n except Exception, e: \n logger.exception(\"Change directory failed\")\n raise \n except IndexError:\n logger.exception(\"Change directory failed\")\n \ndef decompress_file(src,dst,logger = None):\n if not logger:\n logger = logging\n logger.info(\"Upacking %s->%s\" % (src,dst))\n try:\n f = gzip.open(src,'rb')\n contents = f.read(-1)\n f = open(dst, 'wb')\n f.write(contents)\n except Exception, e: \n logger.exception(\"Unpack failed\")\n raise \n\n \ndef untar_file(file,dst_dir='.',logger = None,silent_failure = 0): \n if not logger:\n logger = logging\n logger.info(\"Untarring file: %s\" % (file))\n try:\n run_command('tar -xf ' + file,directory = dst_dir,\n logger=logger, silent_failure = silent_failure)\n except Exception, e:\n if not silent_failure: \n logger.exception(\"Untar failed\")\n raise \n\ndef unpack_file(file,logger = None):\n \"\"\" equivalent to 'tar -xzvf file'\n \"\"\"\n dst = 'tmp.tar'\n decompress_file(file,dst,logger) \n untar_file(dst.logger)\n remove_file(dst,logger) \n\n\ndef run_command(cmd,directory='.',logger=None,silent_failure = 0):\n if not logger:\n logger = logging\n change_dir(directory,logger) \n try: \n msg = 'Running: %s' % cmd\n logger.info(msg) \n status,text = exec_command(cmd)\n if status and silent_failure:\n msg = '(failed silently)'\n logger.info(msg) \n if status and text and not silent_failure:\n logger.error('Command Failed (status=%d)\\n'% status +text)\n finally:\n unchange_dir(logger)\n if status:\n raise ValueError, (status,text)\n return text \n\ndef mail_report(from_addr,to_addr,subject,mail_server,\n build_log, test_results,info):\n \n msg = ''\n msg = msg + 'To: %s\\n' % to_addr\n msg = msg + 'Subject: %s\\n' % subject\n msg = msg + '\\r\\n\\r\\n'\n\n for k,v in info.items(): \n msg = msg + '%s: %s\\n' % (k,v)\n msg = msg + test_results + '\\n'\n msg = msg + '-----------------------------\\n' \n msg = msg + '-------- BUILD LOG -------\\n' \n msg = msg + '-----------------------------\\n' \n msg = msg + build_log\n print msg\n \n # mail results\n import smtplib \n server = smtplib.SMTP(mail_server) \n server.sendmail(from_addr, to_addr, msg)\n server.quit()\n \n\ndef full_scipy_build(build_dir = '.',\n test_level = 10,\n python_version = '2.2.1',\n numeric_version = '21.0',\n f2py_version = '2.13.175-1250',\n atlas_version = '3.3.14',\n scipy_version = 'snapshot'):\n \n # for now the atlas version is ignored. Only the \n # binaries for RH are supported at the moment.\n\n build_info = {'python_version' : python_version,\n 'test_level' : test_level,\n 'numeric_version': numeric_version,\n 'f2py_version' : f2py_version,\n 'atlas_version' : atlas_version,\n 'scipy_version' : scipy_version}\n \n dst_dir = os.path.join(build_dir,sys.platform)\n\n logger = logging.Logger(\"SciPy Test\")\n fmt = logging.Formatter(logging.BASIC_FORMAT)\n log_stream = cStringIO.StringIO()\n stream_handler = logging.StreamHandler(log_stream)\n stream_handler.setFormatter(fmt)\n logger.addHandler(stream_handler)\n # also write to stderr\n stderr = logging.StreamHandler()\n stderr.setFormatter(fmt)\n logger.addHandler(stderr)\n\n try:\n try: \n \n # before doing anything, we need to wipe the \n # /bin, /lib, /man, and /include directories\n # in dst_dir. Don't run as root. \n make_dir(dst_dir,logger=logger) \n change_dir(dst_dir , logger)\n for d in ['bin','lib','man','include']:\n try: remove_tree(d, logger)\n except OSError: pass \n unchange_dir(logger)\n \n python = python_installation(version=python_version,\n logger = logger,\n dst_dir = dst_dir)\n python.install()\n \n python_name = python.get_exe_name()\n \n numeric = numeric_installation(version=numeric_version,\n dst_dir = dst_dir,\n logger = logger,\n python_exe=python_name)\n numeric.install()\n \n f2py = f2py_installation(version=f2py_version,\n logger = logger,\n dst_dir = dst_dir,\n python_exe=python_name)\n f2py.install() \n \n # download files don't have a version specified \n #lapack = lapack_installation(version='',\n # dst_dir = dst_dir\n # python_exe=python_name)\n #lapack.install() \n \n # download files don't have a version specified \n #blas = blas_installation(version='',\n # logger = logger,\n # dst_dir = dst_dir,\n # python_exe=python_name)\n #blas.install() \n \n # ATLAS\n atlas = atlas_installation(version=atlas_version,\n logger = logger,\n dst_dir = dst_dir,\n python_exe=python_name)\n atlas.install()\n \n # version not currently used -- need to fix this.\n scipy = scipy_installation(version=scipy_version,\n logger = logger,\n dst_dir = dst_dir,\n python_exe=python_name)\n scipy.install() \n \n # The change to tmp makes sure there isn't a scipy directory in \n # the local scope.\n # All tests are run.\n logger.info('Beginning Test')\n cmd = python_name +' -c \"import sys,scipy;suite=scipy.test(%d);\"'\\\n % test_level\n test_results = run_command(cmd, logger=logger,\n directory = tempfile.gettempdir())\n build_info['results'] = 'test completed (check below for pass/fail)'\n except Exception, msg:\n test_results = ''\n build_info['results'] = 'build failed: %s' % msg\n logger.exception('Build failed')\n finally: \n to_addr = \"scipy-testlog@scipy.org\"\n from_addr = \"scipy-test@enthought.com\"\n subject = '%s,py%s,num%s,scipy%s' % (sys.platform,python_version,\n numeric_version,scipy_version) \n build_log = log_stream.getvalue()\n mail_report(from_addr,to_addr,subject,local_mail_server,\n build_log,test_results,build_info)\n\nif __name__ == '__main__':\n build_dir = '/tmp/scipy_test'\n level = 10\n\n full_scipy_build(build_dir = build_dir,\n test_level = level,\n python_version = '2.2.1',\n numeric_version = '21.0',\n f2py_version = '2.13.175-1250',\n atlas_version = '3.3.14',\n scipy_version = 'snapshot')\n\n # an older python\n full_scipy_build(build_dir = build_dir,\n test_level = level,\n python_version = '2.1.3',\n numeric_version = '21.0',\n f2py_version = '2.13.175-1250',\n atlas_version = '3.3.14',\n scipy_version = 'snapshot')\n\n # an older numeric\n full_scipy_build(build_dir = build_dir,\n test_level = level,\n python_version = '2.1.3',\n numeric_version = '20.3',\n f2py_version = '2.13.175-1250',\n atlas_version = '3.3.14',\n scipy_version = 'snapshot')\n\n # This fails because multiarray doesn't have \n # arange defined.\n \"\"\"\n full_scipy_build(build_dir = build_dir,\n test_level = level,\n python_version = '2.1.3',\n numeric_version = '20.0.0',\n f2py_version = '2.13.175-1250',\n atlas_version = '3.3.14',\n scipy_version = 'snapshot')\n\n full_scipy_build(build_dir = build_dir,\n test_level = level,\n python_version = '2.1.3',\n numeric_version = '19.0.0',\n f2py_version = '2.13.175-1250',\n atlas_version = '3.3.14',\n scipy_version = 'snapshot')\n\n full_scipy_build(build_dir = build_dir,\n test_level = level,\n python_version = '2.1.3',\n numeric_version = '18.4.1',\n f2py_version = '2.13.175-1250',\n atlas_version = '3.3.14',\n scipy_version = 'snapshot')\n \"\"\"\n", "source_code_before": null, "methods": [ { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 11, "complexity": 2, "token_count": 76, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 45, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "init_names", "long_name": "init_names( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 78, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_source", "long_name": "get_source( self )", "filename": "auto_test.py", "nloc": 10, "complexity": 4, "token_count": 39, "parameters": [ "self" ], "start_line": 82, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "local_source_up_to_date", "long_name": "local_source_up_to_date( self )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 99, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_source_local", "long_name": "get_source_local( self )", "filename": "auto_test.py", "nloc": 9, "complexity": 2, "token_count": 74, "parameters": [ "self" ], "start_line": 104, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "get_source_ftp", "long_name": "get_source_ftp( self )", "filename": "auto_test.py", "nloc": 14, "complexity": 1, "token_count": 136, "parameters": [ "self" ], "start_line": 117, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "unpack_source", "long_name": "unpack_source( self , sub_dir = None )", "filename": "auto_test.py", "nloc": 20, "complexity": 5, "token_count": 153, "parameters": [ "self", "sub_dir" ], "start_line": 138, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "auto_configure", "long_name": "auto_configure( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 172, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "build_with_make", "long_name": "build_with_make( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 176, "end_line": 178, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "install_with_make", "long_name": "install_with_make( self , prefix = None )", "filename": "auto_test.py", "nloc": 5, "complexity": 2, "token_count": 45, "parameters": [ "self", "prefix" ], "start_line": 180, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "python_setup", "long_name": "python_setup( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "self" ], "start_line": 186, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_make", "long_name": "_make( self , ** kw )", "filename": "auto_test.py", "nloc": 10, "complexity": 1, "token_count": 96, "parameters": [ "self", "kw" ], "start_line": 190, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "install", "long_name": "install( self )", "filename": "auto_test.py", "nloc": 17, "complexity": 2, "token_count": 154, "parameters": [ "self" ], "start_line": 204, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 7, "complexity": 1, "token_count": 73, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 230, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "write_install_config", "long_name": "write_install_config( self )", "filename": "auto_test.py", "nloc": 7, "complexity": 1, "token_count": 68, "parameters": [ "self" ], "start_line": 241, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "install_with_make", "long_name": "install_with_make( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 255, "end_line": 260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_exe_name", "long_name": "get_exe_name( self )", "filename": "auto_test.py", "nloc": 6, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 262, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 8, "complexity": 1, "token_count": 65, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 275, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "unpack_source", "long_name": "unpack_source( self , subdir = None )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "subdir" ], "start_line": 287, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "auto_configure", "long_name": "auto_configure( self )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [ "self" ], "start_line": 294, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "build_with_make", "long_name": "build_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "self", "kw" ], "start_line": 297, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "install_with_make", "long_name": "install_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 5, "complexity": 1, "token_count": 60, "parameters": [ "self", "kw" ], "start_line": 302, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 8, "complexity": 1, "token_count": 65, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 315, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "auto_configure", "long_name": "auto_configure( self )", "filename": "auto_test.py", "nloc": 5, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 327, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "build_with_make", "long_name": "build_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "kw" ], "start_line": 336, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "install_with_make", "long_name": "install_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 4, "complexity": 1, "token_count": 52, "parameters": [ "self", "kw" ], "start_line": 340, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 7, "complexity": 1, "token_count": 64, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 352, "end_line": 360, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 7, "complexity": 1, "token_count": 64, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 369, "end_line": 378, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 7, "complexity": 1, "token_count": 60, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 389, "end_line": 399, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "auto_configure", "long_name": "auto_configure( self , ** kw )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "kw" ], "start_line": 401, "end_line": 402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "build_with_make", "long_name": "build_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "kw" ], "start_line": 403, "end_line": 404, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "install_with_make", "long_name": "install_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 4, "complexity": 1, "token_count": 44, "parameters": [ "self", "kw" ], "start_line": 405, "end_line": 409, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 7, "complexity": 1, "token_count": 60, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 417, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "local_source_up_to_date", "long_name": "local_source_up_to_date( self )", "filename": "auto_test.py", "nloc": 13, "complexity": 5, "token_count": 103, "parameters": [ "self" ], "start_line": 427, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "copy_file", "long_name": "copy_file( src , dst , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 52, "parameters": [ "src", "dst", "logger" ], "start_line": 463, "end_line": 471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "copy_tree", "long_name": "copy_tree( src , dst , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 52, "parameters": [ "src", "dst", "logger" ], "start_line": 473, "end_line": 481, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "remove_tree", "long_name": "remove_tree( directory , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 46, "parameters": [ "directory", "logger" ], "start_line": 483, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "remove_file", "long_name": "remove_file( file , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 44, "parameters": [ "file", "logger" ], "start_line": 493, "end_line": 501, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "write_file", "long_name": "write_file( file , contents , logger = None , mode = 'wb' )", "filename": "auto_test.py", "nloc": 11, "complexity": 3, "token_count": 63, "parameters": [ "file", "contents", "logger", "mode" ], "start_line": 503, "end_line": 513, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "make_dir", "long_name": "make_dir( name , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 51, "parameters": [ "name", "logger" ], "start_line": 515, "end_line": 523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "change_dir", "long_name": "change_dir( d , logger = None )", "filename": "auto_test.py", "nloc": 14, "complexity": 4, "token_count": 78, "parameters": [ "d", "logger" ], "start_line": 528, "end_line": 541, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "unchange_dir", "long_name": "unchange_dir( logger = None )", "filename": "auto_test.py", "nloc": 16, "complexity": 5, "token_count": 76, "parameters": [ "logger" ], "start_line": 547, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "decompress_file", "long_name": "decompress_file( src , dst , logger = None )", "filename": "auto_test.py", "nloc": 12, "complexity": 3, "token_count": 77, "parameters": [ "src", "dst", "logger" ], "start_line": 564, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "untar_file", "long_name": "untar_file( file , dst_dir = '.' , logger = None , silent_failure = 0 )", "filename": "auto_test.py", "nloc": 11, "complexity": 4, "token_count": 70, "parameters": [ "file", "dst_dir", "logger", "silent_failure" ], "start_line": 578, "end_line": 588, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "unpack_file", "long_name": "unpack_file( file , logger = None )", "filename": "auto_test.py", "nloc": 5, "complexity": 1, "token_count": 33, "parameters": [ "file", "logger" ], "start_line": 590, "end_line": 596, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "run_command", "long_name": "run_command( cmd , directory = '.' , logger = None , silent_failure = 0 )", "filename": "auto_test.py", "nloc": 18, "complexity": 9, "token_count": 102, "parameters": [ "cmd", "directory", "logger", "silent_failure" ], "start_line": 599, "end_line": 616, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "mail_report", "long_name": "mail_report( from_addr , to_addr , subject , mail_server , build_log , test_results , info )", "filename": "auto_test.py", "nloc": 18, "complexity": 2, "token_count": 115, "parameters": [ "from_addr", "to_addr", "subject", "mail_server", "build_log", "test_results", "info" ], "start_line": 618, "end_line": 639, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "full_scipy_build", "long_name": "full_scipy_build( build_dir = '.' , test_level = 10 , python_version = '2.2.1' , numeric_version = '21.0' , f2py_version = '2.13.175-1250' , atlas_version = '3.3.14' , scipy_version = 'snapshot' )", "filename": "auto_test.py", "nloc": 74, "complexity": 5, "token_count": 417, "parameters": [ "build_dir", "test_level", "python_version", "numeric_version", "f2py_version", "atlas_version", "scipy_version" ], "start_line": 642, "end_line": 752, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 111, "top_nesting_level": 0 } ], "methods_before": [], "changed_methods": [ { "name": "get_source", "long_name": "get_source( self )", "filename": "auto_test.py", "nloc": 10, "complexity": 4, "token_count": 39, "parameters": [ "self" ], "start_line": 82, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "unpack_source", "long_name": "unpack_source( self , subdir = None )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "subdir" ], "start_line": 287, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "install_with_make", "long_name": "install_with_make( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 255, "end_line": 260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "build_with_make", "long_name": "build_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "self", "kw" ], "start_line": 297, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "unpack_source", "long_name": "unpack_source( self , sub_dir = None )", "filename": "auto_test.py", "nloc": 20, "complexity": 5, "token_count": 153, "parameters": [ "self", "sub_dir" ], "start_line": 138, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "remove_file", "long_name": "remove_file( file , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 44, "parameters": [ "file", "logger" ], "start_line": 493, "end_line": 501, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "write_file", "long_name": "write_file( file , contents , logger = None , mode = 'wb' )", "filename": "auto_test.py", "nloc": 11, "complexity": 3, "token_count": 63, "parameters": [ "file", "contents", "logger", "mode" ], "start_line": 503, "end_line": 513, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "unchange_dir", "long_name": "unchange_dir( logger = None )", "filename": "auto_test.py", "nloc": 16, "complexity": 5, "token_count": 76, "parameters": [ "logger" ], "start_line": 547, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "untar_file", "long_name": "untar_file( file , dst_dir = '.' , logger = None , silent_failure = 0 )", "filename": "auto_test.py", "nloc": 11, "complexity": 4, "token_count": 70, "parameters": [ "file", "dst_dir", "logger", "silent_failure" ], "start_line": 578, "end_line": 588, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "install", "long_name": "install( self )", "filename": "auto_test.py", "nloc": 17, "complexity": 2, "token_count": 154, "parameters": [ "self" ], "start_line": 204, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "init_names", "long_name": "init_names( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 78, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "install_with_make", "long_name": "install_with_make( self , prefix = None )", "filename": "auto_test.py", "nloc": 5, "complexity": 2, "token_count": 45, "parameters": [ "self", "prefix" ], "start_line": 180, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_source_local", "long_name": "get_source_local( self )", "filename": "auto_test.py", "nloc": 9, "complexity": 2, "token_count": 74, "parameters": [ "self" ], "start_line": 104, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "change_dir", "long_name": "change_dir( d , logger = None )", "filename": "auto_test.py", "nloc": 14, "complexity": 4, "token_count": 78, "parameters": [ "d", "logger" ], "start_line": 528, "end_line": 541, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_exe_name", "long_name": "get_exe_name( self )", "filename": "auto_test.py", "nloc": 6, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 262, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "build_with_make", "long_name": "build_with_make( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 176, "end_line": 178, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "decompress_file", "long_name": "decompress_file( src , dst , logger = None )", "filename": "auto_test.py", "nloc": 12, "complexity": 3, "token_count": 77, "parameters": [ "src", "dst", "logger" ], "start_line": 564, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "full_scipy_build", "long_name": "full_scipy_build( build_dir = '.' , test_level = 10 , python_version = '2.2.1' , numeric_version = '21.0' , f2py_version = '2.13.175-1250' , atlas_version = '3.3.14' , scipy_version = 'snapshot' )", "filename": "auto_test.py", "nloc": 74, "complexity": 5, "token_count": 417, "parameters": [ "build_dir", "test_level", "python_version", "numeric_version", "f2py_version", "atlas_version", "scipy_version" ], "start_line": 642, "end_line": 752, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 111, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 11, "complexity": 2, "token_count": 76, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 45, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "remove_tree", "long_name": "remove_tree( directory , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 46, "parameters": [ "directory", "logger" ], "start_line": 483, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "copy_tree", "long_name": "copy_tree( src , dst , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 52, "parameters": [ "src", "dst", "logger" ], "start_line": 473, "end_line": 481, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "auto_configure", "long_name": "auto_configure( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 172, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write_install_config", "long_name": "write_install_config( self )", "filename": "auto_test.py", "nloc": 7, "complexity": 1, "token_count": 68, "parameters": [ "self" ], "start_line": 241, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "auto_configure", "long_name": "auto_configure( self , ** kw )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "kw" ], "start_line": 401, "end_line": 402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "mail_report", "long_name": "mail_report( from_addr , to_addr , subject , mail_server , build_log , test_results , info )", "filename": "auto_test.py", "nloc": 18, "complexity": 2, "token_count": 115, "parameters": [ "from_addr", "to_addr", "subject", "mail_server", "build_log", "test_results", "info" ], "start_line": 618, "end_line": 639, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "_make", "long_name": "_make( self , ** kw )", "filename": "auto_test.py", "nloc": 10, "complexity": 1, "token_count": 96, "parameters": [ "self", "kw" ], "start_line": 190, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "make_dir", "long_name": "make_dir( name , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 51, "parameters": [ "name", "logger" ], "start_line": 515, "end_line": 523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "install_with_make", "long_name": "install_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 5, "complexity": 1, "token_count": 60, "parameters": [ "self", "kw" ], "start_line": 302, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_source_ftp", "long_name": "get_source_ftp( self )", "filename": "auto_test.py", "nloc": 14, "complexity": 1, "token_count": 136, "parameters": [ "self" ], "start_line": 117, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "unpack_file", "long_name": "unpack_file( file , logger = None )", "filename": "auto_test.py", "nloc": 5, "complexity": 1, "token_count": 33, "parameters": [ "file", "logger" ], "start_line": 590, "end_line": 596, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "local_source_up_to_date", "long_name": "local_source_up_to_date( self )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 99, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "run_command", "long_name": "run_command( cmd , directory = '.' , logger = None , silent_failure = 0 )", "filename": "auto_test.py", "nloc": 18, "complexity": 9, "token_count": 102, "parameters": [ "cmd", "directory", "logger", "silent_failure" ], "start_line": 599, "end_line": 616, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "copy_file", "long_name": "copy_file( src , dst , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 52, "parameters": [ "src", "dst", "logger" ], "start_line": 463, "end_line": 471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "python_setup", "long_name": "python_setup( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "self" ], "start_line": 186, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 } ], "nloc": 538, "complexity": 100, "token_count": 3462, "diff_parsed": { "added": [ "\"\"\" Auto test tools for SciPy", "", " Do not run this as root! If you enter something", " like /usr as your test directory, it'll delete", " /usr/bin, usr/lib, etc. So don't do it!!!", "", "", " Author: Eric Jones (eric@enthought.com)", "\"\"\"", "from distutils import file_util", "from distutils import dir_util", "from distutils.errors import DistutilsFileError", "#import tarfile", "import sys, os, stat, time", "import gzip", "import tempfile, cStringIO", "import urllib", "import logging", "", "if sys.platform == 'cygwin':", " local_repository = \"/cygdrive/i/tarballs\"", "elif sys.platform == 'win32':", " local_repository = \"i:\\tarballs\"", "else:", " local_repository = \"/home/shared/tarballs\"", "", "local_mail_server = \"enthought.com\"", "", "python_ftp_url = \"ftp://ftp.python.org/pub/python\"", "numeric_url = \"http://prdownloads.sourceforge.net/numpy\"", "f2py_url = \"http://cens.ioc.ee/projects/f2py2e/2.x\"", "scipy_url = \"ftp://www.scipy.org/pub\"", "blas_url = \"http://www.netlib.org/blas\"", "lapack_url = \"http://www.netlib.org/lapack\"", "#atlas_url = \"http://prdownloads.sourceforge.net/math-atlas\"", "atlas_url = \"http://www.scipy.org/Members/eric\"", "", "", "#-----------------------------------------------------------------------------", "# Generic installation class.", "# built to handle downloading/untarring/building/installing arbitrary software", "#-----------------------------------------------------------------------------", "", "class package_installation:", " def __init__(self,version='', dst_dir = '.',", " logger = None, python_exe='python'):", " #---------------------------------------------------------------------", " # These should be defined in sub-class before calling this", " # constructor", " #---------------------------------------------------------------------", " #", " #self.package_url -- The name of the url where tarball can be found.", " #self.package_base_name -- The base name of the source tarball.", " #self.package_dir_name -- Top level directory of unpacked tarball", " #self.tarball_suffix -- usually tar.gz or .tgz", " #self.build_type -- 'make' or 'setup' for makefile or python setup file", "", " # Version of the software package.", " self.version = version", "", " # Only used by packages built with setup.py", " self.python_exe = python_exe", "", " # Directory where package is unpacked/built/installed", " self.dst_dir = os.path.abspath(dst_dir)", "", " if not logger:", " self.logger = logging", " else:", " self.logger = logger", "", " # make sure the destination exists", " make_dir(self.dst_dir,logger=self.logger)", "", " # Construct any derived names built from the above names.", " self.init_names()", "", " def init_names(self):", " self.package_dir = os.path.join(self.dst_dir,self.package_dir_name)", " self.tarball = self.package_base_name + '.' + self.tarball_suffix", "", " def get_source(self):", " \"\"\" Grab the source tarball from a repository.", "", " Try a local repository first. If the file isn't found,", " grab it from an ftp site.", " \"\"\"", " local_found = 0", " if self.local_source_up_to_date():", " try:", " self.get_source_local()", " local_found = 1", " except DistutilsFileError:", " pass", "", " if not local_found:", " self.get_source_ftp()", "", " def local_source_up_to_date(self):", " \"\"\" Hook to test whether a file found in the repository is current", " \"\"\"", " return 1", "", " def get_source_local(self):", " \"\"\" Grab the requested tarball from a local repository of source", " tarballs. If it doesn't exist, an error is raised.", " \"\"\"", " file = os.path.join(local_repository,self.tarball)", " dst_file = os.path.join(self.dst_dir,self.tarball)", " self.logger.info(\"Searching local repository for %s\" % file)", " try:", " copy_file(file,dst_file,self.logger)", " except DistutilsFileError, msg:", " self.logger.info(\"Not found:\",msg)", " raise", "", " def get_source_ftp(self):", " \"\"\" Grab requested tarball from a ftp site specified as a url.", " \"\"\"", " url = '/'.join([self.package_url,self.tarball])", "", " self.logger.info('Opening: %s' % url)", " f = urllib.urlopen(url)", " self.logger.info('Downloading: this may take a while')", " contents = f.read(-1)", " f.close()", " self.logger.info('Finished download (size=%d)' % len(contents))", "", " output_file = os.path.join(self.dst_dir,self.tarball)", " write_file(output_file,contents,self.logger)", "", " # Put file in local repository so we don't have to download it again.", " self.logger.info(\"Caching file in repository\" )", " src_file = output_file", " repos_file = os.path.join(local_repository,self.tarball)", " copy_file(src_file,repos_file,self.logger)", "", " def unpack_source(self,sub_dir = None):", " \"\"\" equivalent to 'tar -xzvf file' in the given sub_dir", " \"\"\"", " tarfile = os.path.join(self.dst_dir,self.tarball)", " old_dir = None", "", " # copy and move into sub directory if it is specified.", " if sub_dir:", " dst_dir = os.path.join(self.dst_dir,sub_dir)", " dst_file = os.path.join(dst_dir,self.tarball)", " copy_file(tarfile,dst_file)", " change_dir(dst_dir,self.logger)", " try:", " try:", " # occasionally the tarball is not zipped, try this first.", " untar_file(self.tarball,self.dst_dir,", " self.logger,silent_failure=1)", " except:", " # otherwise, handle the fact that it is zipped", " dst = os.path.join(self.dst_dir,'tmp.tar')", " decompress_file(tarfile,dst,self.logger)", " untar_file(dst,self.dst_dir,self.logger)", " remove_file(dst,self.logger)", " finally:", " if old_dir:", " unchange_dir(self.logger)", "", " #def auto_configure(self):", " # cmd = os.path.join('.','configure')", " # try:", " # text = run_command(cmd,self.package_dir,self.logger,log_output=0)", " # except ValueError, e:", " # status, text = e", " # self.logger.exception('Configuration Error:\\n'+text)", " def auto_configure(self):", " cmd = os.path.join('.','configure')", " text = run_command(cmd,self.package_dir,self.logger)", "", " def build_with_make(self):", " cmd = 'make'", " text = run_command(cmd,self.package_dir,self.logger)", "", " def install_with_make(self, prefix = None):", " if prefix is None:", " prefix = os.path.abspath(self.dst_dir)", " cmd = 'make install prefix=%s' % prefix", " text = run_command(cmd,self.package_dir,self.logger)", "", " def python_setup(self):", " cmd = self.python_exe + ' setup.py install'", " text = run_command(cmd,self.package_dir,self.logger)", "", " def _make(self,**kw):", " \"\"\" This generally needs to be overrridden in the derived class,", " but this will suffice for the standard configure/make process.", " \"\"\"", " self.logger.info(\"### Begin Configure: %s\" % self.package_base_name)", " self.auto_configure()", " self.logger.info(\"### Finished Configure: %s\" % self.package_base_name)", " self.logger.info(\"### Begin Build: %s\" % self.package_base_name)", " self.build_with_make()", " self.logger.info(\"### Finished Build: %s\" % self.package_base_name)", " self.logger.info(\"### Begin Install: %s\" % self.package_base_name)", " self.install_with_make()", " self.logger.info(\"### Finished Install: %s\" % self.package_base_name)", "", " def install(self):", " self.logger.info('####### Building: %s' % self.package_base_name)", " self.logger.info(' Version: %s' % self.version)", " self.logger.info(' Url: %s' % self.package_url)", " self.logger.info(' Install dir: %s' % self.dst_dir)", " self.logger.info(' Package dir: %s' % self.package_dir)", " self.logger.info(' Suffix: %s' % self.tarball_suffix)", " self.logger.info(' Build type: %s' % self.build_type)", "", " self.logger.info(\"### Begin Get Source: %s\" % self.package_base_name)", " self.get_source()", " self.unpack_source()", " self.logger.info(\"### Finished Get Source: %s\" % self.package_base_name)", "", " if self.build_type == 'setup':", " self.python_setup()", " else:", " self._make()", " self.logger.info('####### Finished Building: %s' % self.package_base_name)", "", "#-----------------------------------------------------------------------------", "# Installation class for Python itself.", "#-----------------------------------------------------------------------------", "", "class python_installation(package_installation):", "", " def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):", "", " # Specialization for Python.", " self.package_base_name = 'Python-'+version", " self.package_dir_name = self.package_base_name", " self.package_url = '/'.join([python_ftp_url,version])", " self.tarball_suffix = 'tgz'", " self.build_type = 'make'", "", " package_installation.__init__(self,version,dst_dir,logger,python_exe)", "", " def write_install_config(self):", " \"\"\" Make doesn't seem to install scripts in the correct places.", "", " Writing this to the python directory will solve the problem.", " [install_script]", " install-dir=", " \"\"\"", " self.logger.info('### Writing Install Script Hack')", " text = \"[install_scripts]\\n\"\\", " \"install-dir='%s'\" % os.path.join(self.dst_dir,'bin')", " file = os.path.join(self.package_dir,'setup.cfg')", " write_file(file,text,self.logger,mode='w')", " self.logger.info('### Finished writing Install Script Hack')", "", " def install_with_make(self):", " \"\"\" Scripts were failing to install correctly, so a setuo.cfg", " file is written to force installation in the correct place.", " \"\"\"", " self.write_install_config()", " package_installation.install_with_make(self)", "", " def get_exe_name(self):", " pyname = os.path.join('.','python')", " cmd = pyname + \"\"\" -c \"import sys;print '%d.%d' % sys.version_info[:2]\" \"\"\"", " text = run_command(cmd,self.package_dir,self.logger)", " exe = os.path.join(self.dst_dir,'bin','python'+text)", " return exe", "", "#-----------------------------------------------------------------------------", "# Installation class for Blas.", "#-----------------------------------------------------------------------------", "", "class blas_installation(package_installation):", "", " def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):", "", " # Specialization for for \"slow\" blas", " self.package_base_name = 'blas'", " self.package_dir_name = 'BLAS'", " self.package_url = blas_url", " self.tarball_suffix = 'tgz'", " self.build_type = 'make'", "", " self.platform = 'LINUX'", " package_installation.__init__(self,version,dst_dir,logger,python_exe)", "", " def unpack_source(self,subdir=None):", " \"\"\" Dag. blas.tgz doesn't have directory information -- its", " just a tar ball of fortran source code. untar it in the", " BLAS directory", " \"\"\"", " package_installation.unpack_source(self,self.package_dir_name)", "", " def auto_configure(self):", " # nothing to do.", " pass", " def build_with_make(self, **kw):", " libname = 'blas_LINUX.a'", " cmd = 'g77 -funroll-all-loops -fno-f2c -O3 -c *.f;ar -cru %s' % libname", " text = run_command(cmd,self.package_dir,self.logger)", "", " def install_with_make(self, **kw):", " # not really using make -- we'll just copy the file over.", " src_file = os.path.join(self.package_dir,'blas_%s.a' % self.platform)", " dst_file = os.path.join(self.dst_dir,'lib','libblas.a')", " self.logger.info(\"Installing blas\")", " copy_file(src_file,dst_file,self.logger)", "", "#-----------------------------------------------------------------------------", "# Installation class for Lapack.", "#-----------------------------------------------------------------------------", "", "class lapack_installation(package_installation):", "", " def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):", "", " # Specialization for Lapack 3.0 + updates", " self.package_base_name = 'lapack'", " self.package_dir_name = 'LAPACK'", " self.package_url = lapack_url", " self.tarball_suffix = 'tgz'", " self.build_type = 'make'", "", " self.platform = 'LINUX'", " package_installation.__init__(self,version,dst_dir,logger,python_exe)", "", " def auto_configure(self):", " # perhaps this should actually override auto_conifgure", " # before make, we need to copy the appropriate setup file in.", " # should work anywhere g77 works...", " make_inc = 'make.inc.' + self.platform", " src_file = os.path.join(self.package_dir,'INSTALL',make_inc)", " dst_file = os.path.join(self.package_dir,'make.inc')", " copy_file(src_file,dst_file,self.logger)", "", " def build_with_make(self, **kw):", " cmd = 'make install lapacklib'", " text = run_command(cmd,self.package_dir,self.logger)", "", " def install_with_make(self, **kw):", " # not really using make -- we'll just copy the file over.", " src_file = os.path.join(self.package_dir,'lapack_%s.a' % self.platform)", " dst_file = os.path.join(self.dst_dir,'lib','liblapack.a')", " copy_file(src_file,dst_file,self.logger)", "", "#-----------------------------------------------------------------------------", "# Installation class for Numeric", "#-----------------------------------------------------------------------------", "", "class numeric_installation(package_installation):", "", " def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):", "", " self.package_base_name = 'Numeric-'+version", " self.package_dir_name = self.package_base_name", " self.package_url = numeric_url", " self.tarball_suffix = 'tar.gz'", " self.build_type = 'setup'", "", " package_installation.__init__(self,version,dst_dir,logger,python_exe)", "", "", "#-----------------------------------------------------------------------------", "# Installation class for f2py", "#-----------------------------------------------------------------------------", "", "class f2py_installation(package_installation):", "", " def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):", "", " # Typical file format: F2PY-2.13.175-1250.tar.gz", " self.package_base_name = 'F2PY-'+version", " self.package_dir_name = self.package_base_name", " self.package_url = f2py_url", " self.tarball_suffix = 'tar.gz'", " self.build_type = 'setup'", "", " package_installation.__init__(self,version,dst_dir,logger,python_exe)", "", "", "#-----------------------------------------------------------------------------", "# Installation class for Atlas.", "# This is a binary install *NOT* a source install.", "# The source install is a pain to automate.", "#-----------------------------------------------------------------------------", "", "class atlas_installation(package_installation):", "", " def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):", "", " #self.package_base_name = 'atlas' + version", " #self.package_dir_name = 'ATLAS'", " self.package_base_name = 'atlas-RH7.1-PIII'", " self.package_dir_name = 'atlas'", " self.package_url = atlas_url", " self.tarball_suffix = 'tgz'", " self.build_type = 'make'", "", " package_installation.__init__(self,version,dst_dir,logger,python_exe)", "", " def auto_configure(self,**kw):", " pass", " def build_with_make(self,**kw):", " pass", " def install_with_make(self, **kw):", " # just copy the tree over.", " dst = os.path.join(self.dst_dir,'lib','atlas')", " self.logger.info(\"Installing Atlas\")", " copy_tree(self.package_dir,dst,self.logger)", "", "#-----------------------------------------------------------------------------", "# Installation class for scipy", "#-----------------------------------------------------------------------------", "", "class scipy_installation(package_installation):", "", " def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):", "", " self.package_base_name = 'scipy_snapshot'", " self.package_dir_name = 'scipy'", " self.package_url = scipy_url", " self.tarball_suffix = 'tgz'", " self.build_type = 'setup'", "", " package_installation.__init__(self,version,dst_dir,logger,python_exe)", "", " def local_source_up_to_date(self):", " \"\"\" Hook to test whether a file found in the repository is current", " \"\"\"", " file = os.path.join(local_repository,self.tarball)", " up_to_date = 0", " try:", " file_time = os.stat(file)[stat.ST_MTIME]", " fyear,fmonth,fday = time.localtime(file_time)[:3]", " year,month,day = time.localtime()[:3]", " if fyear == year and fmonth == month and fday == day:", " up_to_date = 1", " self.logger.info(\"Repository file up to date: %s\" % file)", " except OSError, msg:", " pass", " return up_to_date", "", "#-----------------------------------------------------------------------------", "# Utilities", "#-----------------------------------------------------------------------------", "", "", "#if os.name == 'nt':", "# def exec_command(command):", "# \"\"\" not sure how to get exit status on nt. \"\"\"", "# in_pipe,out_pipe = os.popen4(command)", "# in_pipe.close()", "# text = out_pipe.read()", "# return 0, text", "#else:", "# import commands", "# exec_command = commands.getstatusoutput", "", "# This may not work on Win98... The above stuff was to handle these machines.", "import commands", "exec_command = commands.getstatusoutput", "", "def copy_file(src,dst,logger=None):", " if not logger:", " logger = logging", " logger.info(\"Copying %s->%s\" % (src,dst))", " try:", " file_util.copy_file(src,dst)", " except Exception, e:", " logger.exception(\"Copy Failed\")", " raise", "", "def copy_tree(src,dst,logger=None):", " if not logger:", " logger = logging", " logger.info(\"Copying directory tree %s->%s\" % (src,dst))", " try:", " dir_util.copy_tree(src,dst)", " except Exception, e:", " logger.exception(\"Copy Failed\")", " raise", "", "def remove_tree(directory,logger=None):", " if not logger:", " logger = logging", " logger.info(\"Removing directory tree %s\" % directory)", " try:", " dir_util.remove_tree(directory)", " except Exception, e:", " logger.exception(\"Remove failed: %s\" % e)", " raise", "", "def remove_file(file,logger=None):", " if not logger:", " logger = logging", " logger.info(\"Remove file %s\" % file)", " try:", " os.remove(file)", " except Exception, e:", " logger.exception(\"Remove failed\")", " raise", "", "def write_file(file,contents,logger=None,mode='wb'):", " if not logger:", " logger = logging", " logger.info('Write file: %s' % file)", " try:", " new_file = open(file,mode)", " new_file.write(contents)", " new_file.close()", " except Exception, e:", " logger.exception(\"Write failed\")", " raise", "", "def make_dir(name,logger=None):", " if not logger:", " logger = logging", " logger.info('Make directory: %s' % name)", " try:", " dir_util.mkpath(os.path.abspath(name))", " except Exception, e:", " logger.exception(\"Make Directory failed\")", " raise", "", "# I know, I know...", "old_dir = []", "", "def change_dir(d, logger = None):", " if not logger:", " logger = logging", " global old_dir", " cwd = os.getcwd()", " old_dir.append(cwd)", " d = os.path.abspath(d)", " if d != old_dir[-1]:", " logger.info(\"Change directory: %s\" % d)", " try:", " os.chdir(d)", " except Exception, e:", " logger.exception(\"Change directory failed\")", " raise", " #if d == '.':", " # import sys,traceback", " # f = sys._getframe()", " # traceback.print_stack(f)", "", "def unchange_dir(logger=None):", " if not logger:", " logger = logging", " global old_dir", " try:", " cwd = os.getcwd()", " d = old_dir.pop(-1)", " try:", " if d != cwd:", " logger.info(\"Change directory : %s\" % d)", " os.chdir(d)", " except Exception, e:", " logger.exception(\"Change directory failed\")", " raise", " except IndexError:", " logger.exception(\"Change directory failed\")", "", "def decompress_file(src,dst,logger = None):", " if not logger:", " logger = logging", " logger.info(\"Upacking %s->%s\" % (src,dst))", " try:", " f = gzip.open(src,'rb')", " contents = f.read(-1)", " f = open(dst, 'wb')", " f.write(contents)", " except Exception, e:", " logger.exception(\"Unpack failed\")", " raise", "", "", "def untar_file(file,dst_dir='.',logger = None,silent_failure = 0):", " if not logger:", " logger = logging", " logger.info(\"Untarring file: %s\" % (file))", " try:", " run_command('tar -xf ' + file,directory = dst_dir,", " logger=logger, silent_failure = silent_failure)", " except Exception, e:", " if not silent_failure:", " logger.exception(\"Untar failed\")", " raise", "", "def unpack_file(file,logger = None):", " \"\"\" equivalent to 'tar -xzvf file'", " \"\"\"", " dst = 'tmp.tar'", " decompress_file(file,dst,logger)", " untar_file(dst.logger)", " remove_file(dst,logger)", "", "", "def run_command(cmd,directory='.',logger=None,silent_failure = 0):", " if not logger:", " logger = logging", " change_dir(directory,logger)", " try:", " msg = 'Running: %s' % cmd", " logger.info(msg)", " status,text = exec_command(cmd)", " if status and silent_failure:", " msg = '(failed silently)'", " logger.info(msg)", " if status and text and not silent_failure:", " logger.error('Command Failed (status=%d)\\n'% status +text)", " finally:", " unchange_dir(logger)", " if status:", " raise ValueError, (status,text)", " return text", "", "def mail_report(from_addr,to_addr,subject,mail_server,", " build_log, test_results,info):", "", " msg = ''", " msg = msg + 'To: %s\\n' % to_addr", " msg = msg + 'Subject: %s\\n' % subject", " msg = msg + '\\r\\n\\r\\n'", "", " for k,v in info.items():", " msg = msg + '%s: %s\\n' % (k,v)", " msg = msg + test_results + '\\n'", " msg = msg + '-----------------------------\\n'", " msg = msg + '-------- BUILD LOG -------\\n'", " msg = msg + '-----------------------------\\n'", " msg = msg + build_log", " print msg", "", " # mail results", " import smtplib", " server = smtplib.SMTP(mail_server)", " server.sendmail(from_addr, to_addr, msg)", " server.quit()", "", "", "def full_scipy_build(build_dir = '.',", " test_level = 10,", " python_version = '2.2.1',", " numeric_version = '21.0',", " f2py_version = '2.13.175-1250',", " atlas_version = '3.3.14',", " scipy_version = 'snapshot'):", "", " # for now the atlas version is ignored. Only the", " # binaries for RH are supported at the moment.", "", " build_info = {'python_version' : python_version,", " 'test_level' : test_level,", " 'numeric_version': numeric_version,", " 'f2py_version' : f2py_version,", " 'atlas_version' : atlas_version,", " 'scipy_version' : scipy_version}", "", " dst_dir = os.path.join(build_dir,sys.platform)", "", " logger = logging.Logger(\"SciPy Test\")", " fmt = logging.Formatter(logging.BASIC_FORMAT)", " log_stream = cStringIO.StringIO()", " stream_handler = logging.StreamHandler(log_stream)", " stream_handler.setFormatter(fmt)", " logger.addHandler(stream_handler)", " # also write to stderr", " stderr = logging.StreamHandler()", " stderr.setFormatter(fmt)", " logger.addHandler(stderr)", "", " try:", " try:", "", " # before doing anything, we need to wipe the", " # /bin, /lib, /man, and /include directories", " # in dst_dir. Don't run as root.", " make_dir(dst_dir,logger=logger)", " change_dir(dst_dir , logger)", " for d in ['bin','lib','man','include']:", " try: remove_tree(d, logger)", " except OSError: pass", " unchange_dir(logger)", "", " python = python_installation(version=python_version,", " logger = logger,", " dst_dir = dst_dir)", " python.install()", "", " python_name = python.get_exe_name()", "", " numeric = numeric_installation(version=numeric_version,", " dst_dir = dst_dir,", " logger = logger,", " python_exe=python_name)", " numeric.install()", "", " f2py = f2py_installation(version=f2py_version,", " logger = logger,", " dst_dir = dst_dir,", " python_exe=python_name)", " f2py.install()", "", " # download files don't have a version specified", " #lapack = lapack_installation(version='',", " # dst_dir = dst_dir", " # python_exe=python_name)", " #lapack.install()", "", " # download files don't have a version specified", " #blas = blas_installation(version='',", " # logger = logger,", " # dst_dir = dst_dir,", " # python_exe=python_name)", " #blas.install()", "", " # ATLAS", " atlas = atlas_installation(version=atlas_version,", " logger = logger,", " dst_dir = dst_dir,", " python_exe=python_name)", " atlas.install()", "", " # version not currently used -- need to fix this.", " scipy = scipy_installation(version=scipy_version,", " logger = logger,", " dst_dir = dst_dir,", " python_exe=python_name)", " scipy.install()", "", " # The change to tmp makes sure there isn't a scipy directory in", " # the local scope.", " # All tests are run.", " logger.info('Beginning Test')", " cmd = python_name +' -c \"import sys,scipy;suite=scipy.test(%d);\"'\\", " % test_level", " test_results = run_command(cmd, logger=logger,", " directory = tempfile.gettempdir())", " build_info['results'] = 'test completed (check below for pass/fail)'", " except Exception, msg:", " test_results = ''", " build_info['results'] = 'build failed: %s' % msg", " logger.exception('Build failed')", " finally:", " to_addr = \"scipy-testlog@scipy.org\"", " from_addr = \"scipy-test@enthought.com\"", " subject = '%s,py%s,num%s,scipy%s' % (sys.platform,python_version,", " numeric_version,scipy_version)", " build_log = log_stream.getvalue()", " mail_report(from_addr,to_addr,subject,local_mail_server,", " build_log,test_results,build_info)", "", "if __name__ == '__main__':", " build_dir = '/tmp/scipy_test'", " level = 10", "", " full_scipy_build(build_dir = build_dir,", " test_level = level,", " python_version = '2.2.1',", " numeric_version = '21.0',", " f2py_version = '2.13.175-1250',", " atlas_version = '3.3.14',", " scipy_version = 'snapshot')", "", " # an older python", " full_scipy_build(build_dir = build_dir,", " test_level = level,", " python_version = '2.1.3',", " numeric_version = '21.0',", " f2py_version = '2.13.175-1250',", " atlas_version = '3.3.14',", " scipy_version = 'snapshot')", "", " # an older numeric", " full_scipy_build(build_dir = build_dir,", " test_level = level,", " python_version = '2.1.3',", " numeric_version = '20.3',", " f2py_version = '2.13.175-1250',", " atlas_version = '3.3.14',", " scipy_version = 'snapshot')", "", " # This fails because multiarray doesn't have", " # arange defined.", " \"\"\"", " full_scipy_build(build_dir = build_dir,", " test_level = level,", " python_version = '2.1.3',", " numeric_version = '20.0.0',", " f2py_version = '2.13.175-1250',", " atlas_version = '3.3.14',", " scipy_version = 'snapshot')", "", " full_scipy_build(build_dir = build_dir,", " test_level = level,", " python_version = '2.1.3',", " numeric_version = '19.0.0',", " f2py_version = '2.13.175-1250',", " atlas_version = '3.3.14',", " scipy_version = 'snapshot')", "", " full_scipy_build(build_dir = build_dir,", " test_level = level,", " python_version = '2.1.3',", " numeric_version = '18.4.1',", " f2py_version = '2.13.175-1250',", " atlas_version = '3.3.14',", " scipy_version = 'snapshot')", " \"\"\"" ], "deleted": [] } }, { "old_path": null, "new_path": "scipy_test/logging.py", "filename": "logging.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,1737 @@\n+#! /usr/bin/env python\n+#\n+# Copyright 2001-2002 by Vinay Sajip. All Rights Reserved.\n+#\n+# Permission to use, copy, modify, and distribute this software and its\n+# documentation for any purpose and without fee is hereby granted,\n+# provided that the above copyright notice appear in all copies and that\n+# both that copyright notice and this permission notice appear in\n+# supporting documentation, and that the name of Vinay Sajip\n+# not be used in advertising or publicity pertaining to distribution\n+# of the software without specific, written prior permission.\n+# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING\n+# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL\n+# VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR\n+# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\n+# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT\n+# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n+#\n+# For the change history, see README.txt in the distribution.\n+#\n+# This file is part of the Python logging distribution. See\n+# http://www.red-dove.com/python_logging.html\n+#\n+\n+\"\"\"\n+Logging module for Python. Based on PEP 282 and comments thereto in\n+comp.lang.python, and influenced by Apache's log4j system.\n+\n+Should work under Python versions >= 1.5.2, except that source line\n+information is not available unless 'inspect' is.\n+\n+Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.\n+\n+To use, simply 'import logging' and log away!\n+\"\"\"\n+\n+import sys, os, types, time, string, socket, cPickle, cStringIO\n+\n+try:\n+ import thread\n+except ImportError:\n+ thread = None\n+try:\n+ import inspect\n+except ImportError:\n+ inspect = None\n+\n+__author__ = \"Vinay Sajip \"\n+__status__ = \"alpha\"\n+__version__ = \"0.4.1\"\n+__date__ = \"03 April 2002\"\n+\n+#---------------------------------------------------------------------------\n+# Module data\n+#---------------------------------------------------------------------------\n+\n+#\n+#_srcfile is used when walking the stack to check when we've got the first\n+# caller stack frame.\n+#If run as a script, __file__ is not bound.\n+#\n+if __name__ == \"__main__\":\n+ _srcFile = None\n+else:\n+ _srcfile = os.path.splitext(__file__)\n+ if _srcfile[1] in [\".pyc\", \".pyo\"]:\n+ _srcfile = _srcfile[0] + \".py\"\n+ else:\n+ _srcfile = __file__\n+\n+#\n+#_start_time is used as the base when calculating the relative time of events\n+#\n+_start_time = time.time()\n+\n+DEFAULT_TCP_LOGGING_PORT = 9020\n+DEFAULT_UDP_LOGGING_PORT = 9021\n+DEFAULT_HTTP_LOGGING_PORT = 9022\n+SYSLOG_UDP_PORT = 514\n+\n+#\n+# Default levels and level names, these can be replaced with any positive set\n+# of values having corresponding names. There is a pseudo-level, ALL, which\n+# is only really there as a lower limit for user-defined levels. Handlers and\n+# loggers are initialized with ALL so that they will log all messages, even\n+# at user-defined levels.\n+#\n+CRITICAL = 50\n+FATAL = CRITICAL\n+ERROR = 40\n+WARN = 30\n+INFO = 20\n+DEBUG = 10\n+ALL = 0\n+\n+_levelNames = {\n+ CRITICAL : 'CRITICAL',\n+ ERROR : 'ERROR',\n+ WARN : 'WARN',\n+ INFO : 'INFO',\n+ DEBUG : 'DEBUG',\n+ ALL : 'ALL',\n+}\n+\n+def getLevelName(lvl):\n+ \"\"\"\n+ Return the textual representation of logging level 'lvl'. If the level is\n+ one of the predefined levels (CRITICAL, ERROR, WARN, INFO, DEBUG) then you\n+ get the corresponding string. If you have associated levels with names\n+ using addLevelName then the name you have associated with 'lvl' is\n+ returned. Otherwise, the string \"Level %s\" % lvl is returned.\n+ \"\"\"\n+ return _levelNames.get(lvl, (\"Level %s\" % lvl))\n+\n+def addLevelName(lvl, levelName):\n+ \"\"\"\n+ Associate 'levelName' with 'lvl'. This is used when converting levels\n+ to text during message formatting.\n+ \"\"\"\n+ _levelNames[lvl] = levelName\n+\n+#---------------------------------------------------------------------------\n+# The logging record\n+#---------------------------------------------------------------------------\n+\n+class LogRecord:\n+ \"\"\"\n+ LogRecord instances are created every time something is logged. They\n+ contain all the information pertinent to the event being logged. The\n+ main information passed in is in msg and args, which are combined\n+ using msg % args to create the message field of the record. The record\n+ also includes information such as when the record was created, the\n+ source line where the logging call was made, and any exception\n+ information to be logged.\n+ \"\"\"\n+ def __init__(self, name, lvl, pathname, lineno, msg, args, exc_info):\n+ \"\"\"\n+ Initialize a logging record with interesting information.\n+ \"\"\"\n+ ct = time.time()\n+ self.name = name\n+ self.msg = msg\n+ self.args = args\n+ self.level = getLevelName(lvl)\n+ self.lvl = lvl\n+ self.pathname = pathname\n+ try:\n+ self.filename = os.path.basename(pathname)\n+ except:\n+ self.filename = pathname\n+ self.exc_info = exc_info\n+ self.lineno = lineno\n+ self.created = ct\n+ self.msecs = (ct - long(ct)) * 1000\n+ self.relativeCreated = (self.created - _start_time) * 1000\n+ if thread:\n+ self.thread = thread.get_ident()\n+ else:\n+ self.thread = None\n+\n+ def __str__(self):\n+ return ''%(self.name, self.lvl,\n+ self.pathname, self.lineno, self.msg)\n+\n+#---------------------------------------------------------------------------\n+# Formatter classes and functions\n+#---------------------------------------------------------------------------\n+\n+class Formatter:\n+ \"\"\"\n+ Formatters need to know how a LogRecord is constructed. They are\n+ responsible for converting a LogRecord to (usually) a string which can\n+ be interpreted by either a human or an external system. The base Formatter\n+ allows a formatting string to be specified. If none is supplied, the\n+ default value of \"%s(message)\\\\n\" is used.\n+\n+ The Formatter can be initialized with a format string which makes use of\n+ knowledge of the LogRecord attributes - e.g. the default value mentioned\n+ above makes use of the fact that the user's message and arguments are pre-\n+ formatted into a LogRecord's message attribute. Currently, the useful\n+ attributes in a LogRecord are described by:\n+\n+ %(name)s Name of the logger (logging channel)\n+ %(lvl)s Numeric logging level for the message (DEBUG, INFO,\n+ WARN, ERROR, CRITICAL)\n+ %(level)s Text logging level for the message (\"DEBUG\", \"INFO\",\n+ \"WARN\", \"ERROR\", \"CRITICAL\")\n+ %(pathname)s Full pathname of the source file where the logging\n+ call was issued (if available)\n+ %(filename)s Filename portion of pathname\n+ %(lineno)d Source line number where the logging call was issued\n+ (if available)\n+ %(created)f Time when the LogRecord was created (time.time()\n+ return value)\n+ %(asctime)s textual time when the LogRecord was created\n+ %(msecs)d Millisecond portion of the creation time\n+ %(relativeCreated)d Time in milliseconds when the LogRecord was created,\n+ relative to the time the logging module was loaded\n+ (typically at application startup time)\n+ %(thread)d Thread ID (if available)\n+ %(message)s The result of msg % args, computed just as the\n+ record is emitted\n+ %(msg)s The raw formatting string provided by the user\n+ %(args)r The argument tuple which goes with the formatting\n+ string in the msg attribute\n+ \"\"\"\n+ def __init__(self, fmt=None, datefmt=None):\n+ \"\"\"\n+ Initialize the formatter either with the specified format string, or a\n+ default as described above. Allow for specialized date formatting with\n+ the optional datefmt argument (if omitted, you get the ISO8601 format).\n+ \"\"\"\n+ if fmt:\n+ self._fmt = fmt\n+ else:\n+ self._fmt = \"%(message)s\"\n+ self.datefmt = datefmt\n+\n+ def formatTime(self, record, datefmt=None):\n+ \"\"\"\n+ This method should be called from format() by a formatter which\n+ wants to make use of a formatted time. This method can be overridden\n+ in formatters to provide for any specific requirement, but the\n+ basic behaviour is as follows: if datefmt (a string) is specfied,\n+ it is used with time.strftime to format the creation time of the\n+ record. Otherwise, the ISO8601 format is used. The resulting\n+ string is written to the asctime attribute of the record.\n+ \"\"\"\n+ ct = record.created\n+ if datefmt:\n+ s = time.strftime(datefmt, time.localtime(ct))\n+ else:\n+ t = time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime(ct))\n+ s = \"%s,%03d\" % (t, record.msecs)\n+ record.asctime = s\n+\n+ def formatException(self, ei):\n+ \"\"\"\n+ Format the specified exception information as a string. This\n+ default implementation just uses traceback.print_exception()\n+ \"\"\"\n+ import traceback\n+ sio = cStringIO.StringIO()\n+ traceback.print_exception(ei[0], ei[1], ei[2], None, sio)\n+ s = sio.getvalue()\n+ sio.close()\n+ return s\n+\n+ def format(self, record):\n+ \"\"\"\n+ The record's attribute dictionary is used as the operand to a\n+ string formatting operation which yields the returned string.\n+ Before formatting the dictionary, a couple of preparatory steps\n+ are carried out. The message attribute of the record is computed\n+ using msg % args. If the formatting string contains \"(asctime)\",\n+ formatTime() is called to format the event time. If there is\n+ exception information, it is formatted using formatException()\n+ and appended to the message.\n+ \"\"\"\n+ record.message = record.msg % record.args\n+ if string.find(self._fmt,\"(asctime)\") > 0:\n+ self.formatTime(record, self.datefmt)\n+ s = self._fmt % record.__dict__\n+ if record.exc_info:\n+ if s[-1] != \"\\n\":\n+ s = s + \"\\n\"\n+ s = s + self.formatException(record.exc_info)\n+ return s\n+\n+#\n+# The default formatter to use when no other is specified\n+#\n+_defaultFormatter = Formatter()\n+\n+class BufferingFormatter:\n+ \"\"\"\n+ A formatter suitable for formatting a number of records.\n+ \"\"\"\n+ def __init__(self, linefmt=None):\n+ \"\"\"\n+ Optionally specify a formatter which will be used to format each\n+ individual record.\n+ \"\"\"\n+ if linefmt:\n+ self.linefmt = linefmt\n+ else:\n+ self.linefmt = _defaultFormatter\n+\n+ def formatHeader(self, records):\n+ \"\"\"\n+ Return the header string for the specified records.\n+ \"\"\"\n+ return \"\"\n+\n+ def formatFooter(self, records):\n+ \"\"\"\n+ Return the footer string for the specified records.\n+ \"\"\"\n+ return \"\"\n+\n+ def format(self, records):\n+ \"\"\"\n+ Format the specified records and return the result as a string.\n+ \"\"\"\n+ rv = \"\"\n+ if len(records) > 0:\n+ rv = rv + self.formatHeader(records)\n+ for record in records:\n+ rv = rv + self.linefmt.format(record)\n+ rv = rv + self.formatFooter(records)\n+ return rv\n+\n+#---------------------------------------------------------------------------\n+# Filter classes and functions\n+#---------------------------------------------------------------------------\n+\n+class Filter:\n+ \"\"\"\n+ The base filter class. This class never filters anything, acting as\n+ a placeholder which defines the Filter interface. Loggers and Handlers\n+ can optionally use Filter instances to filter records as desired.\n+ \"\"\"\n+ def filter(self, record):\n+ \"\"\"\n+ Is the specified record to be logged? Returns a boolean value.\n+ \"\"\"\n+ return 1\n+\n+class Filterer:\n+ \"\"\"\n+ A base class for loggers and handlers which allows them to share\n+ common code.\n+ \"\"\"\n+ def __init__(self):\n+ self.filters = []\n+\n+ def addFilter(self, filter):\n+ \"\"\"\n+ Add the specified filter to this handler.\n+ \"\"\"\n+ if not (filter in self.filters):\n+ self.filters.append(filter)\n+\n+ def removeFilter(self, filter):\n+ \"\"\"\n+ Remove the specified filter from this handler.\n+ \"\"\"\n+ if filter in self.filters:\n+ self.filters.remove(filter)\n+\n+ def filter(self, record):\n+ \"\"\"\n+ Determine if a record is loggable by consulting all the filters. The\n+ default is to allow the record to be logged; any filter can veto this\n+ and the record is then dropped. Returns a boolean value.\n+ \"\"\"\n+ rv = 1\n+ for f in self.filters:\n+ if not f.filter(record):\n+ rv = 0\n+ break\n+ return rv\n+\n+#---------------------------------------------------------------------------\n+# Handler classes and functions\n+#---------------------------------------------------------------------------\n+\n+_handlers = {} #repository of handlers (for flushing when shutdown called)\n+\n+class Handler(Filterer):\n+ \"\"\"\n+ The base handler class. Acts as a placeholder which defines the Handler\n+ interface. Handlers can optionally use Formatter instances to format\n+ records as desired. By default, no formatter is specified; in this case,\n+ the 'raw' message as determined by record.message is logged.\n+ \"\"\"\n+ def __init__(self, level=0):\n+ \"\"\"\n+ Initializes the instance - basically setting the formatter to None\n+ and the filter list to empty.\n+ \"\"\"\n+ Filterer.__init__(self)\n+ self.level = level\n+ self.formatter = None\n+ _handlers[self] = 1\n+\n+ def setLevel(self, lvl):\n+ \"\"\"\n+ Set the logging level of this handler.\n+ \"\"\"\n+ self.level = lvl\n+\n+ def format(self, record):\n+ \"\"\"\n+ Do formatting for a record - if a formatter is set, use it.\n+ Otherwise, use the default formatter for the module.\n+ \"\"\"\n+ if self.formatter:\n+ fmt = self.formatter\n+ else:\n+ fmt = _defaultFormatter\n+ return fmt.format(record)\n+\n+ def emit(self, record):\n+ \"\"\"\n+ Do whatever it takes to actually log the specified logging record.\n+ This version is intended to be implemented by subclasses and so\n+ raises a NotImplementedError.\n+ \"\"\"\n+ raise NotImplementedError, 'emit must be implemented '\\\n+ 'by Handler subclasses'\n+\n+ def handle(self, record):\n+ \"\"\"\n+ Conditionally handle the specified logging record, depending on\n+ filters which may have been added to the handler.\n+ \"\"\"\n+ if self.filter(record):\n+ self.emit(record)\n+\n+ def setFormatter(self, fmt):\n+ \"\"\"\n+ Set the formatter for this handler.\n+ \"\"\"\n+ self.formatter = fmt\n+\n+ def flush(self):\n+ \"\"\"\n+ Ensure all logging output has been flushed. This version does\n+ nothing and is intended to be implemented by subclasses.\n+ \"\"\"\n+ pass\n+\n+ def close(self):\n+ \"\"\"\n+ Tidy up any resources used by the handler. This version does\n+ nothing and is intended to be implemented by subclasses.\n+ \"\"\"\n+ pass\n+\n+ def handleError(self):\n+ \"\"\"\n+ This method should be called from handlers when an exception is\n+ encountered during an emit() call. By default it does nothing,\n+ which means that exceptions get silently ignored. This is what is\n+ mostly wanted for a logging system - most users will not care\n+ about errors in the logging system, they are more interested in\n+ application errors. You could, however, replace this with a custom\n+ handler if you wish.\n+ \"\"\"\n+ #import traceback\n+ #ei = sys.exc_info()\n+ #traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr)\n+ #del ei\n+ pass\n+\n+class StreamHandler(Handler):\n+ \"\"\"\n+ A handler class which writes logging records, appropriately formatted,\n+ to a stream. Note that this class does not close the stream, as\n+ sys.stdout or sys.stderr may be used.\n+ \"\"\"\n+ def __init__(self, strm=None):\n+ \"\"\"\n+ If strm is not specified, sys.stderr is used.\n+ \"\"\"\n+ Handler.__init__(self)\n+ if not strm:\n+ strm = sys.stderr\n+ self.stream = strm\n+ self.formatter = None\n+\n+ def flush(self):\n+ \"\"\"\n+ Flushes the stream.\n+ \"\"\"\n+ self.stream.flush()\n+\n+ def emit(self, record):\n+ \"\"\"\n+ If a formatter is specified, it is used to format the record.\n+ The record is then written to the stream with a trailing newline\n+ [N.B. this may be removed depending on feedback]. If exception\n+ information is present, it is formatted using\n+ traceback.print_exception and appended to the stream.\n+ \"\"\"\n+ try:\n+ msg = self.format(record)\n+ self.stream.write(\"%s\\n\" % msg)\n+ self.flush()\n+ except:\n+ self.handleError()\n+\n+class FileHandler(StreamHandler):\n+ \"\"\"\n+ A handler class which writes formatted logging records to disk files.\n+ \"\"\"\n+ def __init__(self, filename, mode=\"a+\"):\n+ \"\"\"\n+ Open the specified file and use it as the stream for logging.\n+ By default, the file grows indefinitely. You can call setRollover()\n+ to allow the file to rollover at a predetermined size.\n+ \"\"\"\n+ StreamHandler.__init__(self, open(filename, mode))\n+ self.max_size = 0\n+ self.backup_count = 0\n+ self.basefilename = filename\n+ self.backup_index = 0\n+ self.mode = mode\n+\n+ def setRollover(self, max_size, backup_count):\n+ \"\"\"\n+ Set the rollover parameters so that rollover occurs whenever the\n+ current log file is nearly max_size in length. If backup_count\n+ is >= 1, the system will successively create new files with the\n+ same pathname as the base file, but with extensions \".1\", \".2\"\n+ etc. appended to it. For example, with a backup_count of 5 and a\n+ base file name of \"app.log\", you would get \"app.log\", \"app.log.1\",\n+ \"app.log.2\", ... through to \"app.log.5\". When the last file reaches\n+ its size limit, the logging reverts to \"app.log\" which is truncated\n+ to zero length. If max_size is zero, rollover never occurs.\n+ \"\"\"\n+ self.max_size = max_size\n+ self.backup_count = backup_count\n+ if max_size > 0:\n+ self.mode = \"a+\"\n+\n+ def doRollover(self):\n+ \"\"\"\n+ Do a rollover, as described in setRollover().\n+ \"\"\"\n+ if self.backup_index >= self.backup_count:\n+ self.backup_index = 0\n+ fn = self.basefilename\n+ else:\n+ self.backup_index = self.backup_index + 1\n+ fn = \"%s.%d\" % (self.basefilename, self.backup_index)\n+ self.stream.close()\n+ self.stream = open(fn, \"w+\")\n+\n+ def emit(self, record):\n+ \"\"\"\n+ Output the record to the file, catering for rollover as described\n+ in setRollover().\n+ \"\"\"\n+ if self.max_size > 0: # are we rolling over?\n+ msg = \"%s\\n\" % self.format(record)\n+ if self.stream.tell() + len(msg) >= self.max_size:\n+ self.doRollover()\n+ StreamHandler.emit(self, record)\n+\n+ def close(self):\n+ \"\"\"\n+ Closes the stream.\n+ \"\"\"\n+ self.stream.close()\n+\n+class SocketHandler(StreamHandler):\n+ \"\"\"\n+ A handler class which writes logging records, in pickle format, to\n+ a streaming socket. The socket is kept open across logging calls.\n+ If the peer resets it, an attempt is made to reconnect on the next call.\n+ \"\"\"\n+\n+ def __init__(self, host, port):\n+ \"\"\"\n+ Initializes the handler with a specific host address and port.\n+ \"\"\"\n+ StreamHandler.__init__(self)\n+ self.host = host\n+ self.port = port\n+ self.sock = None\n+ self.closeOnError = 1\n+\n+ def makeSocket(self):\n+ \"\"\"\n+ A factory method which allows subclasses to define the precise\n+ type of socket they want.\n+ \"\"\"\n+ s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n+ s.connect((self.host, self.port))\n+ return s\n+\n+ def send(self, s):\n+ \"\"\"\n+ Send a pickled string to the socket. This function allows for\n+ partial sends which can happen when the network is busy.\n+ \"\"\"\n+ sentsofar = 0\n+ left = len(s)\n+ while left > 0:\n+ sent = self.sock.send(s[sentsofar:])\n+ sentsofar = sentsofar + sent\n+ left = left - sent\n+\n+ def makePickle(self, record):\n+ \"\"\"\n+ Pickle the record in binary format with a length prefix.\n+ \"\"\"\n+ s = cPickle.dumps(record.__dict__, 1)\n+ n = len(s)\n+ slen = \"%c%c\" % ((n >> 8) & 0xFF, n & 0xFF)\n+ return slen + s\n+\n+ def handleError(self):\n+ \"\"\"\n+ An error has occurred during logging. Most likely cause -\n+ connection lost. Close the socket so that we can retry on the\n+ next event.\n+ \"\"\"\n+ if self.closeOnError and self.sock:\n+ self.sock.close()\n+ self.sock = None #try to reconnect next time\n+\n+ def emit(self, record):\n+ \"\"\"\n+ Pickles the record and writes it to the socket in binary format.\n+ If there is an error with the socket, silently drop the packet.\n+ \"\"\"\n+ try:\n+ s = self.makePickle(record)\n+ if not self.sock:\n+ self.sock = self.makeSocket()\n+ self.send(s)\n+ except:\n+ self.handleError()\n+\n+ def close(self):\n+ \"\"\"\n+ Closes the socket.\n+ \"\"\"\n+ if self.sock:\n+ self.sock.close()\n+ self.sock = None\n+\n+class DatagramHandler(SocketHandler):\n+ \"\"\"\n+ A handler class which writes logging records, in pickle format, to\n+ a datagram socket.\n+ \"\"\"\n+ def __init__(self, host, port):\n+ \"\"\"\n+ Initializes the handler with a specific host address and port.\n+ \"\"\"\n+ SocketHandler.__init__(self, host, port)\n+ self.closeOnError = 0\n+\n+ def makeSocket(self):\n+ \"\"\"\n+ The factory method of SocketHandler is here overridden to create\n+ a UDP socket (SOCK_DGRAM).\n+ \"\"\"\n+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n+ return s\n+\n+ def sendto(self, s, addr):\n+ \"\"\"\n+ Send a pickled string to a socket. This function allows for\n+ partial sends which can happen when the network is busy.\n+ \"\"\"\n+ sentsofar = 0\n+ left = len(s)\n+ while left > 0:\n+ sent = self.sock.sendto(s[sentsofar:], addr)\n+ sentsofar = sentsofar + sent\n+ left = left - sent\n+\n+ def emit(self, record):\n+ \"\"\"\n+ Pickles the record and writes it to the socket in binary format.\n+ \"\"\"\n+ try:\n+ s = self.makePickle(record)\n+ if not self.sock:\n+ self.sock = self.makeSocket()\n+ self.sendto(s, (self.host, self.port))\n+ except:\n+ self.handleError()\n+\n+class SysLogHandler(Handler):\n+ \"\"\"\n+ A handler class which sends formatted logging records to a syslog\n+ server. Based on Sam Rushing's syslog module:\n+ http://www.nightmare.com/squirl/python-ext/misc/syslog.py\n+ Contributed by Nicolas Untz (after which minor refactoring changes\n+ have been made).\n+ \"\"\"\n+\n+ # from :\n+ # ======================================================================\n+ # priorities/facilities are encoded into a single 32-bit quantity, where\n+ # the bottom 3 bits are the priority (0-7) and the top 28 bits are the\n+ # facility (0-big number). Both the priorities and the facilities map\n+ # roughly one-to-one to strings in the syslogd(8) source code. This\n+ # mapping is included in this file.\n+ #\n+ # priorities (these are ordered)\n+\n+ LOG_EMERG = 0 # system is unusable\n+ LOG_ALERT = 1 # action must be taken immediately\n+ LOG_CRIT = 2 # critical conditions\n+ LOG_ERR = 3 # error conditions\n+ LOG_WARNING = 4 # warning conditions\n+ LOG_NOTICE = 5 # normal but significant condition\n+ LOG_INFO = 6 # informational\n+ LOG_DEBUG = 7 # debug-level messages\n+\n+ # facility codes\n+ LOG_KERN = 0 # kernel messages\n+ LOG_USER = 1 # random user-level messages\n+ LOG_MAIL = 2 # mail system\n+ LOG_DAEMON = 3 # system daemons\n+ LOG_AUTH = 4 # security/authorization messages\n+ LOG_SYSLOG = 5 # messages generated internally by syslogd\n+ LOG_LPR = 6 # line printer subsystem\n+ LOG_NEWS = 7 # network news subsystem\n+ LOG_UUCP = 8 # UUCP subsystem\n+ LOG_CRON = 9 # clock daemon\n+ LOG_AUTHPRIV = 10 # security/authorization messages (private)\n+\n+ # other codes through 15 reserved for system use\n+ LOG_LOCAL0 = 16 # reserved for local use\n+ LOG_LOCAL1 = 17 # reserved for local use\n+ LOG_LOCAL2 = 18 # reserved for local use\n+ LOG_LOCAL3 = 19 # reserved for local use\n+ LOG_LOCAL4 = 20 # reserved for local use\n+ LOG_LOCAL5 = 21 # reserved for local use\n+ LOG_LOCAL6 = 22 # reserved for local use\n+ LOG_LOCAL7 = 23 # reserved for local use\n+\n+ priority_names = {\n+ \"alert\": LOG_ALERT,\n+ \"crit\": LOG_CRIT,\n+ \"critical\": LOG_CRIT,\n+ \"debug\": LOG_DEBUG,\n+ \"emerg\": LOG_EMERG,\n+ \"err\": LOG_ERR,\n+ \"error\": LOG_ERR, # DEPRECATED\n+ \"info\": LOG_INFO,\n+ \"notice\": LOG_NOTICE,\n+ \"panic\": LOG_EMERG, # DEPRECATED\n+ \"warn\": LOG_WARNING, # DEPRECATED\n+ \"warning\": LOG_WARNING,\n+ }\n+\n+ facility_names = {\n+ \"auth\": LOG_AUTH,\n+ \"authpriv\": LOG_AUTHPRIV,\n+ \"cron\": LOG_CRON,\n+ \"daemon\": LOG_DAEMON,\n+ \"kern\": LOG_KERN,\n+ \"lpr\": LOG_LPR,\n+ \"mail\": LOG_MAIL,\n+ \"news\": LOG_NEWS,\n+ \"security\": LOG_AUTH, # DEPRECATED\n+ \"syslog\": LOG_SYSLOG,\n+ \"user\": LOG_USER,\n+ \"uucp\": LOG_UUCP,\n+ \"local0\": LOG_LOCAL0,\n+ \"local1\": LOG_LOCAL1,\n+ \"local2\": LOG_LOCAL2,\n+ \"local3\": LOG_LOCAL3,\n+ \"local4\": LOG_LOCAL4,\n+ \"local5\": LOG_LOCAL5,\n+ \"local6\": LOG_LOCAL6,\n+ \"local7\": LOG_LOCAL7,\n+ }\n+\n+ def __init__(self, address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER):\n+ \"\"\"\n+ If address is not specified, UNIX socket is used.\n+ If facility is not specified, LOG_USER is used.\n+ \"\"\"\n+ Handler.__init__(self)\n+\n+ self.address = address\n+ self.facility = facility\n+ if type(address) == types.StringType:\n+ self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)\n+ self.socket.connect(address)\n+ self.unixsocket = 1\n+ else:\n+ self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n+ self.unixsocket = 0\n+\n+ self.formatter = None\n+\n+ # curious: when talking to the unix-domain '/dev/log' socket, a\n+ # zero-terminator seems to be required. this string is placed\n+ # into a class variable so that it can be overridden if\n+ # necessary.\n+ log_format_string = '<%d>%s\\000'\n+\n+ def encodePriority (self, facility, priority):\n+ \"\"\"\n+ Encode the facility and priority. You can pass in strings or\n+ integers - if strings are passed, the facility_names and\n+ priority_names mapping dictionaries are used to convert them to\n+ integers.\n+ \"\"\"\n+ if type(facility) == types.StringType:\n+ facility = self.facility_names[facility]\n+ if type(priority) == types.StringType:\n+ priority = self.priority_names[priority]\n+ return (facility << 3) | priority\n+\n+ def close (self):\n+ \"\"\"\n+ Closes the socket.\n+ \"\"\"\n+ if self.unixsocket:\n+ self.socket.close()\n+\n+ def emit(self, record):\n+ \"\"\"\n+ The record is formatted, and then sent to the syslog server. If\n+ exception information is present, it is NOT sent to the server.\n+ \"\"\"\n+ msg = self.format(record)\n+ \"\"\"\n+ We need to convert record level to lowercase, maybe this will\n+ change in the future.\n+ \"\"\"\n+ msg = self.log_format_string % (\n+ self.encodePriority(self.facility, string.lower(record.level)),\n+ msg)\n+ try:\n+ if self.unixsocket:\n+ self.socket.send(msg)\n+ else:\n+ self.socket.sendto(msg, self.address)\n+ except:\n+ self.handleError()\n+\n+class SMTPHandler(Handler):\n+ \"\"\"\n+ A handler class which sends an SMTP email for each logging event.\n+ \"\"\"\n+ def __init__(self, mailhost, fromaddr, toaddrs, subject):\n+ \"\"\"\n+ Initialize the instance with the from and to addresses and subject\n+ line of the email. To specify a non-standard SMTP port, use the\n+ (host, port) tuple format for the mailhost argument.\n+ \"\"\"\n+ Handler.__init__(self)\n+ if type(mailhost) == types.TupleType:\n+ host, port = mailhost\n+ self.mailhost = host\n+ self.mailport = port\n+ else:\n+ self.mailhost = mailhost\n+ self.mailport = None\n+ self.fromaddr = fromaddr\n+ self.toaddrs = toaddrs\n+ self.subject = subject\n+\n+ def getSubject(self, record):\n+ \"\"\"\n+ If you want to specify a subject line which is record-dependent,\n+ override this method.\n+ \"\"\"\n+ return self.subject\n+\n+ def emit(self, record):\n+ \"\"\"\n+ Format the record and send it to the specified addressees.\n+ \"\"\"\n+ try:\n+ import smtplib\n+ port = self.mailport\n+ if not port:\n+ port = smtplib.SMTP_PORT\n+ smtp = smtplib.SMTP(self.mailhost, port)\n+ msg = self.format(record)\n+ msg = \"From: %s\\r\\nTo: %s\\r\\nSubject: %s\\r\\n\\r\\n%s\" % (\n+ self.fromaddr,\n+ string.join(self.toaddrs, \",\"),\n+ self.getSubject(record), msg\n+ )\n+ smtp.sendmail(self.fromaddr, self.toaddrs, msg)\n+ smtp.quit()\n+ except:\n+ self.handleError()\n+\n+class BufferingHandler(Handler):\n+ \"\"\"\n+ A handler class which buffers logging records in memory. Whenever each\n+ record is added to the buffer, a check is made to see if the buffer should\n+ be flushed. If it should, then flush() is expected to do the needful.\n+ \"\"\"\n+ def __init__(self, capacity):\n+ \"\"\"\n+ Initialize the handler with the buffer size.\n+ \"\"\"\n+ Handler.__init__(self)\n+ self.capacity = capacity\n+ self.buffer = []\n+\n+ def shouldFlush(self, record):\n+ \"\"\"\n+ Returns true if the buffer is up to capacity. This method can be\n+ overridden to implement custom flushing strategies.\n+ \"\"\"\n+ return (len(self.buffer) >= self.capacity)\n+\n+ def emit(self, record):\n+ \"\"\"\n+ Append the record. If shouldFlush() tells us to, call flush() to process\n+ the buffer.\n+ \"\"\"\n+ self.buffer.append(record)\n+ if self.shouldFlush(record):\n+ self.flush()\n+\n+ def flush(self):\n+ \"\"\"\n+ Override to implement custom flushing behaviour. This version just zaps\n+ the buffer to empty.\n+ \"\"\"\n+ self.buffer = []\n+\n+class MemoryHandler(BufferingHandler):\n+ \"\"\"\n+ A handler class which buffers logging records in memory, periodically\n+ flushing them to a target handler. Flushing occurs whenever the buffer\n+ is full, or when an event of a certain severity or greater is seen.\n+ \"\"\"\n+ def __init__(self, capacity, flushLevel=ERROR, target=None):\n+ \"\"\"\n+ Initialize the handler with the buffer size, the level at which\n+ flushing should occur and an optional target. Note that without a\n+ target being set either here or via setTarget(), a MemoryHandler\n+ is no use to anyone!\n+ \"\"\"\n+ BufferingHandler.__init__(self, capacity)\n+ self.flushLevel = flushLevel\n+ self.target = target\n+\n+ def shouldFlush(self, record):\n+ \"\"\"\n+ Check for buffer full or a record at the flushLevel or higher.\n+ \"\"\"\n+ return (len(self.buffer) >= self.capacity) or \\\n+ (record.lvl >= self.flushLevel)\n+\n+ def setTarget(self, target):\n+ \"\"\"\n+ Set the target handler for this handler.\n+ \"\"\"\n+ self.target = target\n+\n+ def flush(self):\n+ \"\"\"\n+ For a MemoryHandler, flushing means just sending the buffered\n+ records to the target, if there is one. Override if you want\n+ different behaviour.\n+ \"\"\"\n+ if self.target:\n+ for record in self.buffer:\n+ self.target.handle(record)\n+ self.buffer = []\n+\n+class NTEventLogHandler(Handler):\n+ \"\"\"\n+ A handler class which sends events to the NT Event Log. Adds a\n+ registry entry for the specified application name. If no dllname is\n+ provided, win32service.pyd (which contains some basic message\n+ placeholders) is used. Note that use of these placeholders will make\n+ your event logs big, as the entire message source is held in the log.\n+ If you want slimmer logs, you have to pass in the name of your own DLL\n+ which contains the message definitions you want to use in the event log.\n+ \"\"\"\n+ def __init__(self, appname, dllname=None, logtype=\"Application\"):\n+ Handler.__init__(self)\n+ try:\n+ import win32evtlogutil, win32evtlog\n+ self.appname = appname\n+ self._welu = win32evtlogutil\n+ if not dllname:\n+ import os\n+ dllname = os.path.split(self._welu.__file__)\n+ dllname = os.path.split(dllname[0])\n+ dllname = os.path.join(dllname[0], r'win32service.pyd')\n+ self.dllname = dllname\n+ self.logtype = logtype\n+ self._welu.AddSourceToRegistry(appname, dllname, logtype)\n+ self.deftype = win32evtlog.EVENTLOG_ERROR_TYPE\n+ self.typemap = {\n+ DEBUG : win32evtlog.EVENTLOG_INFORMATION_TYPE,\n+ INFO : win32evtlog.EVENTLOG_INFORMATION_TYPE,\n+ WARN : win32evtlog.EVENTLOG_WARNING_TYPE,\n+ ERROR : win32evtlog.EVENTLOG_ERROR_TYPE,\n+ CRITICAL: win32evtlog.EVENTLOG_ERROR_TYPE,\n+ }\n+ except ImportError:\n+ print \"The Python Win32 extensions for NT (service, event \"\\\n+ \"logging) appear not to be available.\"\n+ self._welu = None\n+\n+ def getMessageID(self, record):\n+ \"\"\"\n+ Return the message ID for the event record. If you are using your\n+ own messages, you could do this by having the msg passed to the\n+ logger being an ID rather than a formatting string. Then, in here,\n+ you could use a dictionary lookup to get the message ID. This\n+ version returns 1, which is the base message ID in win32service.pyd.\n+ \"\"\"\n+ return 1\n+\n+ def getEventCategory(self, record):\n+ \"\"\"\n+ Return the event category for the record. Override this if you\n+ want to specify your own categories. This version returns 0.\n+ \"\"\"\n+ return 0\n+\n+ def getEventType(self, record):\n+ \"\"\"\n+ Return the event type for the record. Override this if you want\n+ to specify your own types. This version does a mapping using the\n+ handler's typemap attribute, which is set up in __init__() to a\n+ dictionary which contains mappings for DEBUG, INFO, WARN, ERROR\n+ and CRITICAL. If you are using your own levels you will either need\n+ to override this method or place a suitable dictionary in the\n+ handler's typemap attribute.\n+ \"\"\"\n+ return self.typemap.get(record.lvl, self.deftype)\n+\n+ def emit(self, record):\n+ \"\"\"\n+ Determine the message ID, event category and event type. Then\n+ log the message in the NT event log.\n+ \"\"\"\n+ if self._welu:\n+ try:\n+ id = self.getMessageID(record)\n+ cat = self.getEventCategory(record)\n+ type = self.getEventType(record)\n+ msg = self.format(record)\n+ self._welu.ReportEvent(self.appname, id, cat, type, [msg])\n+ except:\n+ self.handleError()\n+\n+ def close(self):\n+ \"\"\"\n+ You can remove the application name from the registry as a\n+ source of event log entries. However, if you do this, you will\n+ not be able to see the events as you intended in the Event Log\n+ Viewer - it needs to be able to access the registry to get the\n+ DLL name.\n+ \"\"\"\n+ #self._welu.RemoveSourceFromRegistry(self.appname, self.logtype)\n+ pass\n+\n+class HTTPHandler(Handler):\n+ \"\"\"\n+ A class which sends records to a Web server, using either GET or\n+ POST semantics.\n+ \"\"\"\n+ def __init__(self, host, url, method=\"GET\"):\n+ \"\"\"\n+ Initialize the instance with the host, the request URL, and the method\n+ (\"GET\" or \"POST\")\n+ \"\"\"\n+ Handler.__init__(self)\n+ method = string.upper(method)\n+ if method not in [\"GET\", \"POST\"]:\n+ raise ValueError, \"method must be GET or POST\"\n+ self.host = host\n+ self.url = url\n+ self.method = method\n+\n+ def emit(self, record):\n+ \"\"\"\n+ Send the record to the Web server as an URL-encoded dictionary\n+ \"\"\"\n+ try:\n+ import httplib, urllib\n+ h = httplib.HTTP(self.host)\n+ url = self.url\n+ data = urllib.urlencode(record.__dict__)\n+ if self.method == \"GET\":\n+ if (string.find(url, '?') >= 0):\n+ sep = '&'\n+ else:\n+ sep = '?'\n+ url = url + \"%c%s\" % (sep, data)\n+ h.putrequest(self.method, url)\n+ if self.method == \"POST\":\n+ h.putheader(\"Content-length\", str(len(data)))\n+ h.endheaders()\n+ if self.method == \"POST\":\n+ h.send(data)\n+ h.getreply() #can't do anything with the result\n+ except:\n+ self.handleError()\n+\n+SOAP_MESSAGE = \"\"\"\n+ \n+ \n+%s\n+ \n+ \n+\n+\"\"\"\n+\n+class SOAPHandler(Handler):\n+ \"\"\"\n+ A class which sends records to a SOAP server.\n+ \"\"\"\n+ def __init__(self, host, url):\n+ \"\"\"\n+ Initialize the instance with the host and the request URL\n+ \"\"\"\n+ Handler.__init__(self)\n+ self.host = host\n+ self.url = url\n+\n+ def emit(self, record):\n+ \"\"\"\n+ Send the record to the Web server as a SOAP message\n+ \"\"\"\n+ try:\n+ import httplib, urllib\n+ h = httplib.HTTP(self.host)\n+ h.putrequest(\"POST\", self.url)\n+ keys = record.__dict__.keys()\n+ keys.sort()\n+ args = \"\"\n+ for key in keys:\n+ v = record.__dict__[key]\n+ if type(v) == types.StringType:\n+ t = \"string\"\n+ elif (type(v) == types.IntType) or (type(v) == types.LongType):\n+ t = \"integer\"\n+ elif type(v) == types.FloatType:\n+ t = \"float\"\n+ else:\n+ t = \"string\"\n+ args = args + \"%12s%s\\n\" % (\"\",\n+ key, t, str(v), key)\n+ data = SOAP_MESSAGE % args[:-1]\n+ #print data\n+ h.putheader(\"Content-type\", \"text/plain; charset=\\\"utf-8\\\"\")\n+ h.putheader(\"Content-length\", str(len(data)))\n+ h.endheaders()\n+ h.send(data)\n+ r = h.getreply() #can't do anything with the result\n+ #print r\n+ f = h.getfile()\n+ #print f.read()\n+ f.close()\n+ except:\n+ self.handleError()\n+\n+#---------------------------------------------------------------------------\n+# Manager classes and functions\n+#---------------------------------------------------------------------------\n+\n+class PlaceHolder:\n+ \"\"\"\n+ PlaceHolder instances are used in the Manager logger hierarchy to take\n+ the place of nodes for which no loggers have been defined [FIXME add\n+ example].\n+ \"\"\"\n+ def __init__(self, alogger):\n+ \"\"\"\n+ Initialize with the specified logger being a child of this placeholder.\n+ \"\"\"\n+ self.loggers = [alogger]\n+\n+ def append(self, alogger):\n+ \"\"\"\n+ Add the specified logger as a child of this placeholder.\n+ \"\"\"\n+ if alogger not in self.loggers:\n+ self.loggers.append(alogger)\n+\n+#\n+# Determine which class to use when instantiating loggers.\n+#\n+_loggerClass = None\n+\n+def setLoggerClass(klass):\n+ \"\"\"\n+ Set the class to be used when instantiating a logger. The class should\n+ define __init__() such that only a name argument is required, and the\n+ __init__() should call Logger.__init__()\n+ \"\"\"\n+ if klass != Logger:\n+ if type(klass) != types.ClassType:\n+ raise TypeError, \"setLoggerClass is expecting a class\"\n+ if not (Logger in klass.__bases__):\n+ raise TypeError, \"logger not derived from logging.Logger: \" + \\\n+ klass.__name__\n+ global _loggerClass\n+ _loggerClass = klass\n+\n+class Manager:\n+ \"\"\"\n+ There is [under normal circumstances] just one Manager instance, which\n+ holds the hierarchy of loggers.\n+ \"\"\"\n+ def __init__(self, root):\n+ \"\"\"\n+ Initialize the manager with the root node of the logger hierarchy.\n+ \"\"\"\n+ self.root = root\n+ self.disable = 0\n+ self.emittedNoHandlerWarning = 0\n+ self.loggerDict = {}\n+\n+ def getLogger(self, name):\n+ \"\"\"\n+ Get a logger with the specified name, creating it if it doesn't\n+ yet exist. If a PlaceHolder existed for the specified name [i.e.\n+ the logger didn't exist but a child of it did], replace it with\n+ the created logger and fix up the parent/child references which\n+ pointed to the placeholder to now point to the logger.\n+ \"\"\"\n+ rv = None\n+ if self.loggerDict.has_key(name):\n+ rv = self.loggerDict[name]\n+ if isinstance(rv, PlaceHolder):\n+ ph = rv\n+ rv = _loggerClass(name)\n+ rv.manager = self\n+ self.loggerDict[name] = rv\n+ self._fixupChildren(ph, rv)\n+ self._fixupParents(rv)\n+ else:\n+ rv = _loggerClass(name)\n+ rv.manager = self\n+ self.loggerDict[name] = rv\n+ self._fixupParents(rv)\n+ return rv\n+\n+ def _fixupParents(self, alogger):\n+ \"\"\"\n+ Ensure that there are either loggers or placeholders all the way\n+ from the specified logger to the root of the logger hierarchy.\n+ \"\"\"\n+ name = alogger.name\n+ i = string.rfind(name, \".\")\n+ rv = None\n+ while (i > 0) and not rv:\n+ substr = name[:i]\n+ if not self.loggerDict.has_key(substr):\n+ self.loggerDict[name] = PlaceHolder(alogger)\n+ else:\n+ obj = self.loggerDict[substr]\n+ if isinstance(obj, Logger):\n+ rv = obj\n+ else:\n+ assert isinstance(obj, PlaceHolder)\n+ obj.append(alogger)\n+ i = string.rfind(name, \".\", 0, i - 1)\n+ if not rv:\n+ rv = self.root\n+ alogger.parent = rv\n+\n+ def _fixupChildren(self, ph, alogger):\n+ \"\"\"\n+ Ensure that children of the placeholder ph are connected to the\n+ specified logger.\n+ \"\"\"\n+ for c in ph.loggers:\n+ if string.find(c.parent.name, alogger.name) <> 0:\n+ alogger.parent = c.parent\n+ c.parent = alogger\n+\n+#---------------------------------------------------------------------------\n+# Logger classes and functions\n+#---------------------------------------------------------------------------\n+\n+class Logger(Filterer):\n+ \"\"\"\n+ Instances of the Logger class represent a single logging channel.\n+ \"\"\"\n+ def __init__(self, name, level=0):\n+ \"\"\"\n+ Initialize the logger with a name and an optional level.\n+ \"\"\"\n+ Filterer.__init__(self)\n+ self.name = name\n+ self.level = level\n+ self.parent = None\n+ self.propagate = 1\n+ self.handlers = []\n+\n+ def setLevel(self, lvl):\n+ \"\"\"\n+ Set the logging level of this logger.\n+ \"\"\"\n+ self.level = lvl\n+\n+# def getRoot(self):\n+# \"\"\"\n+# Get the root of the logger hierarchy.\n+# \"\"\"\n+# return Logger.root\n+\n+ def debug(self, msg, *args, **kwargs):\n+ \"\"\"\n+ Log 'msg % args' with severity 'DEBUG'. To pass exception information,\n+ use the keyword argument exc_info with a true value, e.g.\n+\n+ logger.debug(\"Houston, we have a %s\", \"thorny problem\", exc_info=1)\n+ \"\"\"\n+ if self.manager.disable >= DEBUG:\n+ return\n+ if DEBUG >= self.getEffectiveLevel():\n+ apply(self._log, (DEBUG, msg, args), kwargs)\n+\n+ def info(self, msg, *args, **kwargs):\n+ \"\"\"\n+ Log 'msg % args' with severity 'INFO'. To pass exception information,\n+ use the keyword argument exc_info with a true value, e.g.\n+\n+ logger.info(\"Houston, we have a %s\", \"interesting problem\", exc_info=1)\n+ \"\"\"\n+ if self.manager.disable >= INFO:\n+ return\n+ if INFO >= self.getEffectiveLevel():\n+ apply(self._log, (INFO, msg, args), kwargs)\n+\n+ def warn(self, msg, *args, **kwargs):\n+ \"\"\"\n+ Log 'msg % args' with severity 'WARN'. To pass exception information,\n+ use the keyword argument exc_info with a true value, e.g.\n+\n+ logger.warn(\"Houston, we have a %s\", \"bit of a problem\", exc_info=1)\n+ \"\"\"\n+ if self.manager.disable >= WARN:\n+ return\n+ if self.isEnabledFor(WARN):\n+ apply(self._log, (WARN, msg, args), kwargs)\n+\n+ def error(self, msg, *args, **kwargs):\n+ \"\"\"\n+ Log 'msg % args' with severity 'ERROR'. To pass exception information,\n+ use the keyword argument exc_info with a true value, e.g.\n+\n+ logger.error(\"Houston, we have a %s\", \"major problem\", exc_info=1)\n+ \"\"\"\n+ if self.manager.disable >= ERROR:\n+ return\n+ if self.isEnabledFor(ERROR):\n+ apply(self._log, (ERROR, msg, args), kwargs)\n+\n+ def exception(self, msg, *args):\n+ \"\"\"\n+ Convenience method for logging an ERROR with exception information\n+ \"\"\"\n+ apply(self.error, (msg,) + args, {'exc_info': 1})\n+\n+ def critical(self, msg, *args, **kwargs):\n+ \"\"\"\n+ Log 'msg % args' with severity 'CRITICAL'. To pass exception\n+ information, use the keyword argument exc_info with a true value, e.g.\n+\n+ logger.critical(\"Houston, we have a %s\", \"major disaster\", exc_info=1)\n+ \"\"\"\n+ if self.manager.disable >= CRITICAL:\n+ return\n+ if CRITICAL >= self.getEffectiveLevel():\n+ apply(self._log, (CRITICAL, msg, args), kwargs)\n+\n+ fatal = critical\n+\n+ def log(self, lvl, msg, *args, **kwargs):\n+ \"\"\"\n+ Log 'msg % args' with the severity 'lvl'. To pass exception\n+ information, use the keyword argument exc_info with a true value, e.g.\n+ logger.log(lvl, \"We have a %s\", \"mysterious problem\", exc_info=1)\n+ \"\"\"\n+ if self.manager.disable >= lvl:\n+ return\n+ if self.isEnabledFor(lvl):\n+ apply(self._log, (lvl, msg, args), kwargs)\n+\n+ def findCaller(self):\n+ \"\"\"\n+ Find the stack frame of the caller so that we can note the source\n+ file name and line number.\n+ \"\"\"\n+ frames = inspect.stack()[1:]\n+ for f in frames:\n+ if _srcfile != f[1]:\n+ return (f[1], f[2])\n+ return (None, None)\n+\n+ def makeRecord(self, name, lvl, fn, lno, msg, args, exc_info):\n+ \"\"\"\n+ A factory method which can be overridden in subclasses to create\n+ specialized LogRecords.\n+ \"\"\"\n+ return LogRecord(name, lvl, fn, lno, msg, args, exc_info)\n+\n+ def _log(self, lvl, msg, args, exc_info=None):\n+ \"\"\"\n+ Low-level logging routine which creates a LogRecord and then calls\n+ all the handlers of this logger to handle the record.\n+ \"\"\"\n+ if inspect:\n+ fn, lno = self.findCaller()\n+ else:\n+ fn, lno = \"\", 0\n+ if exc_info:\n+ exc_info = sys.exc_info()\n+ record = self.makeRecord(self.name, lvl, fn, lno, msg, args, exc_info)\n+ self.handle(record)\n+\n+ def handle(self, record):\n+ \"\"\"\n+ Call the handlers for the specified record. This method is used for\n+ unpickled records received from a socket, as well as those created\n+ locally. Logger-level filtering is applied.\n+ \"\"\"\n+ if self.filter(record):\n+ self.callHandlers(record)\n+\n+ def addHandler(self, hdlr):\n+ \"\"\"\n+ Add the specified handler to this logger.\n+ \"\"\"\n+ if not (hdlr in self.handlers):\n+ self.handlers.append(hdlr)\n+\n+ def removeHandler(self, hdlr):\n+ \"\"\"\n+ Remove the specified handler from this logger.\n+ \"\"\"\n+ if hdlr in self.handlers:\n+ self.handlers.remove(hdlr)\n+\n+ def callHandlers(self, record):\n+ \"\"\"\n+ Loop through all handlers for this logger and its parents in the\n+ logger hierarchy. If no handler was found, output a one-off error\n+ message. Stop searching up the hierarchy whenever a logger with the\n+ \"propagate\" attribute set to zero is found - that will be the last\n+ logger whose handlers are called.\n+ \"\"\"\n+ c = self\n+ found = 0\n+ while c:\n+ for hdlr in c.handlers:\n+ found = found + 1\n+ if record.lvl >= hdlr.level:\n+ hdlr.handle(record)\n+ if not c.propagate:\n+ c = None #break out\n+ else:\n+ c = c.parent\n+ if (found == 0) and not self.manager.emittedNoHandlerWarning:\n+ print \"No handlers could be found for logger \\\"%s\\\"\" % self.name\n+ self.manager.emittedNoHandlerWarning = 1\n+\n+ def getEffectiveLevel(self):\n+ \"\"\"\n+ Loop through this logger and its parents in the logger hierarchy,\n+ looking for a non-zero logging level. Return the first one found.\n+ \"\"\"\n+ c = self\n+ while c:\n+ if c.level:\n+ return c.level\n+ c = c.parent\n+ #print \"NCP\", self.parent\n+\n+ def isEnabledFor(self, lvl):\n+ \"\"\"\n+ Is this logger enabled for level lvl?\n+ \"\"\"\n+ if self.manager.disable >= lvl:\n+ return 0\n+ return lvl >= self.getEffectiveLevel()\n+\n+class RootLogger(Logger):\n+ \"\"\"\n+ A root logger is not that different to any other logger, except that\n+ it must have a logging level and there is only one instance of it in\n+ the hierarchy.\n+ \"\"\"\n+ def __init__(self, lvl):\n+ \"\"\"\n+ Initialize the logger with the name \"root\".\n+ \"\"\"\n+ Logger.__init__(self, \"root\", lvl)\n+\n+_loggerClass = Logger\n+\n+root = RootLogger(DEBUG)\n+Logger.root = root\n+Logger.manager = Manager(Logger.root)\n+\n+#---------------------------------------------------------------------------\n+# Configuration classes and functions\n+#---------------------------------------------------------------------------\n+\n+BASIC_FORMAT = \"%(asctime)s %(name)-19s %(level)-5s - %(message)s\"\n+\n+def basicConfig():\n+ \"\"\"\n+ Do basic configuration for the logging system by creating a\n+ StreamHandler with a default Formatter and adding it to the\n+ root logger.\n+ \"\"\"\n+ hdlr = StreamHandler()\n+ fmt = Formatter(BASIC_FORMAT)\n+ hdlr.setFormatter(fmt)\n+ root.addHandler(hdlr)\n+\n+#def fileConfig(fname):\n+# \"\"\"\n+# The old implementation - using dict-based configuration files.\n+# Read the logging configuration from a file. Keep it simple for now.\n+# \"\"\"\n+# file = open(fname, \"r\")\n+# data = file.read()\n+# file.close()\n+# dict = eval(data)\n+# handlers = dict.get(\"handlers\", [])\n+# loggers = dict.get(\"loggers\", [])\n+# formatters = dict.get(\"formatters\", [])\n+# for f in formatters:\n+# fd = dict[f]\n+# fc = fd.get(\"class\", \"logging.Formatter\")\n+# args = fd.get(\"args\", ())\n+# fc = eval(fc)\n+# try:\n+# fmt = apply(fc, args)\n+# except:\n+# print fc, args\n+# raise\n+# dict[f] = fmt\n+#\n+# for h in handlers:\n+# hd = dict[h]\n+# hc = hd.get(\"class\", \"logging.StreamHandler\")\n+# args = hd.get(\"args\", ())\n+# hc = eval(hc)\n+# fmt = hd.get(\"formatter\", None)\n+# if fmt:\n+# fmt = dict.get(fmt, None)\n+# try:\n+# hdlr = apply(hc, args)\n+# except:\n+# print hc, args\n+# raise\n+# if fmt:\n+# hdlr.setFormatter(fmt)\n+# dict[h] = hdlr\n+#\n+# for ln in loggers:\n+# ld = dict[ln]\n+# name = ld.get(\"name\", None)\n+# if name:\n+# logger = getLogger(name)\n+# else:\n+# logger = getRootLogger()\n+# logger.propagate = ld.get(\"propagate\", 1)\n+# hdlrs = ld.get(\"handlers\", [])\n+# for h in hdlrs:\n+# hdlr = dict.get(h, None)\n+# if hdlr:\n+# logger.addHandler(hdlr)\n+\n+def fileConfig(fname):\n+ \"\"\"\n+ Read the logging configuration from a ConfigParser-format file.\n+ \"\"\"\n+ import ConfigParser\n+\n+ cp = ConfigParser.ConfigParser()\n+ cp.read(fname)\n+ #first, do the formatters...\n+ flist = cp.get(\"formatters\", \"keys\")\n+ flist = string.split(flist, \",\")\n+ formatters = {}\n+ for form in flist:\n+ sectname = \"formatter_%s\" % form\n+ fs = cp.get(sectname, \"format\", 1)\n+ dfs = cp.get(sectname, \"datefmt\", 1)\n+ f = Formatter(fs, dfs)\n+ formatters[form] = f\n+ #next, do the handlers...\n+ hlist = cp.get(\"handlers\", \"keys\")\n+ hlist = string.split(hlist, \",\")\n+ handlers = {}\n+ for hand in hlist:\n+ sectname = \"handler_%s\" % hand\n+ klass = cp.get(sectname, \"class\")\n+ fmt = cp.get(sectname, \"formatter\")\n+ lvl = cp.get(sectname, \"level\")\n+ klass = eval(klass)\n+ args = cp.get(sectname, \"args\")\n+ args = eval(args)\n+ h = apply(klass, args)\n+ h.setLevel(eval(lvl))\n+ h.setFormatter(formatters[fmt])\n+ #temporary hack for FileHandler.\n+ if klass == FileHandler:\n+ maxsize = cp.get(sectname, \"maxsize\")\n+ if maxsize:\n+ maxsize = eval(maxsize)\n+ else:\n+ maxsize = 0\n+ if maxsize:\n+ backcount = cp.get(sectname, \"backcount\")\n+ if backcount:\n+ backcount = eval(backcount)\n+ else:\n+ backcount = 0\n+ h.setRollover(maxsize, backcount)\n+ handlers[hand] = h\n+ #at last, the loggers...first the root...\n+ llist = cp.get(\"loggers\", \"keys\")\n+ llist = string.split(llist, \",\")\n+ llist.remove(\"root\")\n+ sectname = \"logger_root\"\n+ log = root\n+ lvl = cp.get(sectname, \"level\")\n+ log.setLevel(eval(lvl))\n+ hlist = cp.get(sectname, \"handlers\")\n+ hlist = string.split(hlist, \",\")\n+ for hand in hlist:\n+ log.addHandler(handlers[hand])\n+ #and now the others...\n+ for log in llist:\n+ sectname = \"logger_%s\" % log\n+ qn = cp.get(sectname, \"qualname\")\n+ lvl = cp.get(sectname, \"level\")\n+ propagate = cp.get(sectname, \"propagate\")\n+ logger = getLogger(qn)\n+ logger.setLevel(eval(lvl))\n+ logger.propagate = eval(propagate)\n+ hlist = cp.get(sectname, \"handlers\")\n+ hlist = string.split(hlist, \",\")\n+ for hand in hlist:\n+ logger.addHandler(handlers[hand])\n+\n+\n+#---------------------------------------------------------------------------\n+# Utility functions at module level.\n+# Basically delegate everything to the root logger.\n+#---------------------------------------------------------------------------\n+\n+def getLogger(name):\n+ \"\"\"\n+ Return a logger with the specified name, creating it if necessary.\n+ If no name is specified, return the root logger.\n+ \"\"\"\n+ if name:\n+ return Logger.manager.getLogger(name)\n+ else:\n+ return root\n+\n+def getRootLogger():\n+ \"\"\"\n+ Return the root logger.\n+ \"\"\"\n+ return root\n+\n+def critical(msg, *args, **kwargs):\n+ \"\"\"\n+ Log a message with severity 'CRITICAL' on the root logger.\n+ \"\"\"\n+ if len(root.handlers) == 0:\n+ basicConfig()\n+ apply(root.critical, (msg,)+args, kwargs)\n+\n+fatal = critical\n+\n+def error(msg, *args, **kwargs):\n+ \"\"\"\n+ Log a message with severity 'ERROR' on the root logger.\n+ \"\"\"\n+ if len(root.handlers) == 0:\n+ basicConfig()\n+ apply(root.error, (msg,)+args, kwargs)\n+\n+def exception(msg, *args):\n+ \"\"\"\n+ Log a message with severity 'ERROR' on the root logger,\n+ with exception information.\n+ \"\"\"\n+ apply(error, (msg,)+args, {'exc_info': 1})\n+\n+def warn(msg, *args, **kwargs):\n+ \"\"\"\n+ Log a message with severity 'WARN' on the root logger.\n+ \"\"\"\n+ if len(root.handlers) == 0:\n+ basicConfig()\n+ apply(root.warn, (msg,)+args, kwargs)\n+\n+def info(msg, *args, **kwargs):\n+ \"\"\"\n+ Log a message with severity 'INFO' on the root logger.\n+ \"\"\"\n+ if len(root.handlers) == 0:\n+ basicConfig()\n+ apply(root.info, (msg,)+args, kwargs)\n+\n+def debug(msg, *args, **kwargs):\n+ \"\"\"\n+ Log a message with severity 'DEBUG' on the root logger.\n+ \"\"\"\n+ if len(root.handlers) == 0:\n+ basicConfig()\n+ apply(root.debug, (msg,)+args, kwargs)\n+\n+def disable(level):\n+ \"\"\"\n+ Disable all logging calls less severe than 'level'.\n+ \"\"\"\n+ root.manager.disable = level\n+\n+def shutdown():\n+ \"\"\"\n+ Perform any cleanup actions in the logging system (e.g. flushing\n+ buffers). Should be called at application exit.\n+ \"\"\"\n+ for h in _handlers.keys():\n+ h.flush()\n+ h.close()\n+\n+if __name__ == \"__main__\":\n+ print __doc__\n", "added_lines": 1737, "deleted_lines": 0, "source_code": "#! /usr/bin/env python\n#\n# Copyright 2001-2002 by Vinay Sajip. All Rights Reserved.\n#\n# Permission to use, copy, modify, and distribute this software and its\n# documentation for any purpose and without fee is hereby granted,\n# provided that the above copyright notice appear in all copies and that\n# both that copyright notice and this permission notice appear in\n# supporting documentation, and that the name of Vinay Sajip\n# not be used in advertising or publicity pertaining to distribution\n# of the software without specific, written prior permission.\n# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING\n# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL\n# VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR\n# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\n# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT\n# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n#\n# For the change history, see README.txt in the distribution.\n#\n# This file is part of the Python logging distribution. See\n# http://www.red-dove.com/python_logging.html\n#\n\n\"\"\"\nLogging module for Python. Based on PEP 282 and comments thereto in\ncomp.lang.python, and influenced by Apache's log4j system.\n\nShould work under Python versions >= 1.5.2, except that source line\ninformation is not available unless 'inspect' is.\n\nCopyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.\n\nTo use, simply 'import logging' and log away!\n\"\"\"\n\nimport sys, os, types, time, string, socket, cPickle, cStringIO\n\ntry:\n import thread\nexcept ImportError:\n thread = None\ntry:\n import inspect\nexcept ImportError:\n inspect = None\n\n__author__ = \"Vinay Sajip \"\n__status__ = \"alpha\"\n__version__ = \"0.4.1\"\n__date__ = \"03 April 2002\"\n\n#---------------------------------------------------------------------------\n# Module data\n#---------------------------------------------------------------------------\n\n#\n#_srcfile is used when walking the stack to check when we've got the first\n# caller stack frame.\n#If run as a script, __file__ is not bound.\n#\nif __name__ == \"__main__\":\n _srcFile = None\nelse:\n _srcfile = os.path.splitext(__file__)\n if _srcfile[1] in [\".pyc\", \".pyo\"]:\n _srcfile = _srcfile[0] + \".py\"\n else:\n _srcfile = __file__\n\n#\n#_start_time is used as the base when calculating the relative time of events\n#\n_start_time = time.time()\n\nDEFAULT_TCP_LOGGING_PORT = 9020\nDEFAULT_UDP_LOGGING_PORT = 9021\nDEFAULT_HTTP_LOGGING_PORT = 9022\nSYSLOG_UDP_PORT = 514\n\n#\n# Default levels and level names, these can be replaced with any positive set\n# of values having corresponding names. There is a pseudo-level, ALL, which\n# is only really there as a lower limit for user-defined levels. Handlers and\n# loggers are initialized with ALL so that they will log all messages, even\n# at user-defined levels.\n#\nCRITICAL = 50\nFATAL = CRITICAL\nERROR = 40\nWARN = 30\nINFO = 20\nDEBUG = 10\nALL = 0\n\n_levelNames = {\n CRITICAL : 'CRITICAL',\n ERROR : 'ERROR',\n WARN : 'WARN',\n INFO : 'INFO',\n DEBUG : 'DEBUG',\n ALL : 'ALL',\n}\n\ndef getLevelName(lvl):\n \"\"\"\n Return the textual representation of logging level 'lvl'. If the level is\n one of the predefined levels (CRITICAL, ERROR, WARN, INFO, DEBUG) then you\n get the corresponding string. If you have associated levels with names\n using addLevelName then the name you have associated with 'lvl' is\n returned. Otherwise, the string \"Level %s\" % lvl is returned.\n \"\"\"\n return _levelNames.get(lvl, (\"Level %s\" % lvl))\n\ndef addLevelName(lvl, levelName):\n \"\"\"\n Associate 'levelName' with 'lvl'. This is used when converting levels\n to text during message formatting.\n \"\"\"\n _levelNames[lvl] = levelName\n\n#---------------------------------------------------------------------------\n# The logging record\n#---------------------------------------------------------------------------\n\nclass LogRecord:\n \"\"\"\n LogRecord instances are created every time something is logged. They\n contain all the information pertinent to the event being logged. The\n main information passed in is in msg and args, which are combined\n using msg % args to create the message field of the record. The record\n also includes information such as when the record was created, the\n source line where the logging call was made, and any exception\n information to be logged.\n \"\"\"\n def __init__(self, name, lvl, pathname, lineno, msg, args, exc_info):\n \"\"\"\n Initialize a logging record with interesting information.\n \"\"\"\n ct = time.time()\n self.name = name\n self.msg = msg\n self.args = args\n self.level = getLevelName(lvl)\n self.lvl = lvl\n self.pathname = pathname\n try:\n self.filename = os.path.basename(pathname)\n except:\n self.filename = pathname\n self.exc_info = exc_info\n self.lineno = lineno\n self.created = ct\n self.msecs = (ct - long(ct)) * 1000\n self.relativeCreated = (self.created - _start_time) * 1000\n if thread:\n self.thread = thread.get_ident()\n else:\n self.thread = None\n\n def __str__(self):\n return ''%(self.name, self.lvl,\n self.pathname, self.lineno, self.msg)\n\n#---------------------------------------------------------------------------\n# Formatter classes and functions\n#---------------------------------------------------------------------------\n\nclass Formatter:\n \"\"\"\n Formatters need to know how a LogRecord is constructed. They are\n responsible for converting a LogRecord to (usually) a string which can\n be interpreted by either a human or an external system. The base Formatter\n allows a formatting string to be specified. If none is supplied, the\n default value of \"%s(message)\\\\n\" is used.\n\n The Formatter can be initialized with a format string which makes use of\n knowledge of the LogRecord attributes - e.g. the default value mentioned\n above makes use of the fact that the user's message and arguments are pre-\n formatted into a LogRecord's message attribute. Currently, the useful\n attributes in a LogRecord are described by:\n\n %(name)s Name of the logger (logging channel)\n %(lvl)s Numeric logging level for the message (DEBUG, INFO,\n WARN, ERROR, CRITICAL)\n %(level)s Text logging level for the message (\"DEBUG\", \"INFO\",\n \"WARN\", \"ERROR\", \"CRITICAL\")\n %(pathname)s Full pathname of the source file where the logging\n call was issued (if available)\n %(filename)s Filename portion of pathname\n %(lineno)d Source line number where the logging call was issued\n (if available)\n %(created)f Time when the LogRecord was created (time.time()\n return value)\n %(asctime)s textual time when the LogRecord was created\n %(msecs)d Millisecond portion of the creation time\n %(relativeCreated)d Time in milliseconds when the LogRecord was created,\n relative to the time the logging module was loaded\n (typically at application startup time)\n %(thread)d Thread ID (if available)\n %(message)s The result of msg % args, computed just as the\n record is emitted\n %(msg)s The raw formatting string provided by the user\n %(args)r The argument tuple which goes with the formatting\n string in the msg attribute\n \"\"\"\n def __init__(self, fmt=None, datefmt=None):\n \"\"\"\n Initialize the formatter either with the specified format string, or a\n default as described above. Allow for specialized date formatting with\n the optional datefmt argument (if omitted, you get the ISO8601 format).\n \"\"\"\n if fmt:\n self._fmt = fmt\n else:\n self._fmt = \"%(message)s\"\n self.datefmt = datefmt\n\n def formatTime(self, record, datefmt=None):\n \"\"\"\n This method should be called from format() by a formatter which\n wants to make use of a formatted time. This method can be overridden\n in formatters to provide for any specific requirement, but the\n basic behaviour is as follows: if datefmt (a string) is specfied,\n it is used with time.strftime to format the creation time of the\n record. Otherwise, the ISO8601 format is used. The resulting\n string is written to the asctime attribute of the record.\n \"\"\"\n ct = record.created\n if datefmt:\n s = time.strftime(datefmt, time.localtime(ct))\n else:\n t = time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime(ct))\n s = \"%s,%03d\" % (t, record.msecs)\n record.asctime = s\n\n def formatException(self, ei):\n \"\"\"\n Format the specified exception information as a string. This\n default implementation just uses traceback.print_exception()\n \"\"\"\n import traceback\n sio = cStringIO.StringIO()\n traceback.print_exception(ei[0], ei[1], ei[2], None, sio)\n s = sio.getvalue()\n sio.close()\n return s\n\n def format(self, record):\n \"\"\"\n The record's attribute dictionary is used as the operand to a\n string formatting operation which yields the returned string.\n Before formatting the dictionary, a couple of preparatory steps\n are carried out. The message attribute of the record is computed\n using msg % args. If the formatting string contains \"(asctime)\",\n formatTime() is called to format the event time. If there is\n exception information, it is formatted using formatException()\n and appended to the message.\n \"\"\"\n record.message = record.msg % record.args\n if string.find(self._fmt,\"(asctime)\") > 0:\n self.formatTime(record, self.datefmt)\n s = self._fmt % record.__dict__\n if record.exc_info:\n if s[-1] != \"\\n\":\n s = s + \"\\n\"\n s = s + self.formatException(record.exc_info)\n return s\n\n#\n# The default formatter to use when no other is specified\n#\n_defaultFormatter = Formatter()\n\nclass BufferingFormatter:\n \"\"\"\n A formatter suitable for formatting a number of records.\n \"\"\"\n def __init__(self, linefmt=None):\n \"\"\"\n Optionally specify a formatter which will be used to format each\n individual record.\n \"\"\"\n if linefmt:\n self.linefmt = linefmt\n else:\n self.linefmt = _defaultFormatter\n\n def formatHeader(self, records):\n \"\"\"\n Return the header string for the specified records.\n \"\"\"\n return \"\"\n\n def formatFooter(self, records):\n \"\"\"\n Return the footer string for the specified records.\n \"\"\"\n return \"\"\n\n def format(self, records):\n \"\"\"\n Format the specified records and return the result as a string.\n \"\"\"\n rv = \"\"\n if len(records) > 0:\n rv = rv + self.formatHeader(records)\n for record in records:\n rv = rv + self.linefmt.format(record)\n rv = rv + self.formatFooter(records)\n return rv\n\n#---------------------------------------------------------------------------\n# Filter classes and functions\n#---------------------------------------------------------------------------\n\nclass Filter:\n \"\"\"\n The base filter class. This class never filters anything, acting as\n a placeholder which defines the Filter interface. Loggers and Handlers\n can optionally use Filter instances to filter records as desired.\n \"\"\"\n def filter(self, record):\n \"\"\"\n Is the specified record to be logged? Returns a boolean value.\n \"\"\"\n return 1\n\nclass Filterer:\n \"\"\"\n A base class for loggers and handlers which allows them to share\n common code.\n \"\"\"\n def __init__(self):\n self.filters = []\n\n def addFilter(self, filter):\n \"\"\"\n Add the specified filter to this handler.\n \"\"\"\n if not (filter in self.filters):\n self.filters.append(filter)\n\n def removeFilter(self, filter):\n \"\"\"\n Remove the specified filter from this handler.\n \"\"\"\n if filter in self.filters:\n self.filters.remove(filter)\n\n def filter(self, record):\n \"\"\"\n Determine if a record is loggable by consulting all the filters. The\n default is to allow the record to be logged; any filter can veto this\n and the record is then dropped. Returns a boolean value.\n \"\"\"\n rv = 1\n for f in self.filters:\n if not f.filter(record):\n rv = 0\n break\n return rv\n\n#---------------------------------------------------------------------------\n# Handler classes and functions\n#---------------------------------------------------------------------------\n\n_handlers = {} #repository of handlers (for flushing when shutdown called)\n\nclass Handler(Filterer):\n \"\"\"\n The base handler class. Acts as a placeholder which defines the Handler\n interface. Handlers can optionally use Formatter instances to format\n records as desired. By default, no formatter is specified; in this case,\n the 'raw' message as determined by record.message is logged.\n \"\"\"\n def __init__(self, level=0):\n \"\"\"\n Initializes the instance - basically setting the formatter to None\n and the filter list to empty.\n \"\"\"\n Filterer.__init__(self)\n self.level = level\n self.formatter = None\n _handlers[self] = 1\n\n def setLevel(self, lvl):\n \"\"\"\n Set the logging level of this handler.\n \"\"\"\n self.level = lvl\n\n def format(self, record):\n \"\"\"\n Do formatting for a record - if a formatter is set, use it.\n Otherwise, use the default formatter for the module.\n \"\"\"\n if self.formatter:\n fmt = self.formatter\n else:\n fmt = _defaultFormatter\n return fmt.format(record)\n\n def emit(self, record):\n \"\"\"\n Do whatever it takes to actually log the specified logging record.\n This version is intended to be implemented by subclasses and so\n raises a NotImplementedError.\n \"\"\"\n raise NotImplementedError, 'emit must be implemented '\\\n 'by Handler subclasses'\n\n def handle(self, record):\n \"\"\"\n Conditionally handle the specified logging record, depending on\n filters which may have been added to the handler.\n \"\"\"\n if self.filter(record):\n self.emit(record)\n\n def setFormatter(self, fmt):\n \"\"\"\n Set the formatter for this handler.\n \"\"\"\n self.formatter = fmt\n\n def flush(self):\n \"\"\"\n Ensure all logging output has been flushed. This version does\n nothing and is intended to be implemented by subclasses.\n \"\"\"\n pass\n\n def close(self):\n \"\"\"\n Tidy up any resources used by the handler. This version does\n nothing and is intended to be implemented by subclasses.\n \"\"\"\n pass\n\n def handleError(self):\n \"\"\"\n This method should be called from handlers when an exception is\n encountered during an emit() call. By default it does nothing,\n which means that exceptions get silently ignored. This is what is\n mostly wanted for a logging system - most users will not care\n about errors in the logging system, they are more interested in\n application errors. You could, however, replace this with a custom\n handler if you wish.\n \"\"\"\n #import traceback\n #ei = sys.exc_info()\n #traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr)\n #del ei\n pass\n\nclass StreamHandler(Handler):\n \"\"\"\n A handler class which writes logging records, appropriately formatted,\n to a stream. Note that this class does not close the stream, as\n sys.stdout or sys.stderr may be used.\n \"\"\"\n def __init__(self, strm=None):\n \"\"\"\n If strm is not specified, sys.stderr is used.\n \"\"\"\n Handler.__init__(self)\n if not strm:\n strm = sys.stderr\n self.stream = strm\n self.formatter = None\n\n def flush(self):\n \"\"\"\n Flushes the stream.\n \"\"\"\n self.stream.flush()\n\n def emit(self, record):\n \"\"\"\n If a formatter is specified, it is used to format the record.\n The record is then written to the stream with a trailing newline\n [N.B. this may be removed depending on feedback]. If exception\n information is present, it is formatted using\n traceback.print_exception and appended to the stream.\n \"\"\"\n try:\n msg = self.format(record)\n self.stream.write(\"%s\\n\" % msg)\n self.flush()\n except:\n self.handleError()\n\nclass FileHandler(StreamHandler):\n \"\"\"\n A handler class which writes formatted logging records to disk files.\n \"\"\"\n def __init__(self, filename, mode=\"a+\"):\n \"\"\"\n Open the specified file and use it as the stream for logging.\n By default, the file grows indefinitely. You can call setRollover()\n to allow the file to rollover at a predetermined size.\n \"\"\"\n StreamHandler.__init__(self, open(filename, mode))\n self.max_size = 0\n self.backup_count = 0\n self.basefilename = filename\n self.backup_index = 0\n self.mode = mode\n\n def setRollover(self, max_size, backup_count):\n \"\"\"\n Set the rollover parameters so that rollover occurs whenever the\n current log file is nearly max_size in length. If backup_count\n is >= 1, the system will successively create new files with the\n same pathname as the base file, but with extensions \".1\", \".2\"\n etc. appended to it. For example, with a backup_count of 5 and a\n base file name of \"app.log\", you would get \"app.log\", \"app.log.1\",\n \"app.log.2\", ... through to \"app.log.5\". When the last file reaches\n its size limit, the logging reverts to \"app.log\" which is truncated\n to zero length. If max_size is zero, rollover never occurs.\n \"\"\"\n self.max_size = max_size\n self.backup_count = backup_count\n if max_size > 0:\n self.mode = \"a+\"\n\n def doRollover(self):\n \"\"\"\n Do a rollover, as described in setRollover().\n \"\"\"\n if self.backup_index >= self.backup_count:\n self.backup_index = 0\n fn = self.basefilename\n else:\n self.backup_index = self.backup_index + 1\n fn = \"%s.%d\" % (self.basefilename, self.backup_index)\n self.stream.close()\n self.stream = open(fn, \"w+\")\n\n def emit(self, record):\n \"\"\"\n Output the record to the file, catering for rollover as described\n in setRollover().\n \"\"\"\n if self.max_size > 0: # are we rolling over?\n msg = \"%s\\n\" % self.format(record)\n if self.stream.tell() + len(msg) >= self.max_size:\n self.doRollover()\n StreamHandler.emit(self, record)\n\n def close(self):\n \"\"\"\n Closes the stream.\n \"\"\"\n self.stream.close()\n\nclass SocketHandler(StreamHandler):\n \"\"\"\n A handler class which writes logging records, in pickle format, to\n a streaming socket. The socket is kept open across logging calls.\n If the peer resets it, an attempt is made to reconnect on the next call.\n \"\"\"\n\n def __init__(self, host, port):\n \"\"\"\n Initializes the handler with a specific host address and port.\n \"\"\"\n StreamHandler.__init__(self)\n self.host = host\n self.port = port\n self.sock = None\n self.closeOnError = 1\n\n def makeSocket(self):\n \"\"\"\n A factory method which allows subclasses to define the precise\n type of socket they want.\n \"\"\"\n s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n s.connect((self.host, self.port))\n return s\n\n def send(self, s):\n \"\"\"\n Send a pickled string to the socket. This function allows for\n partial sends which can happen when the network is busy.\n \"\"\"\n sentsofar = 0\n left = len(s)\n while left > 0:\n sent = self.sock.send(s[sentsofar:])\n sentsofar = sentsofar + sent\n left = left - sent\n\n def makePickle(self, record):\n \"\"\"\n Pickle the record in binary format with a length prefix.\n \"\"\"\n s = cPickle.dumps(record.__dict__, 1)\n n = len(s)\n slen = \"%c%c\" % ((n >> 8) & 0xFF, n & 0xFF)\n return slen + s\n\n def handleError(self):\n \"\"\"\n An error has occurred during logging. Most likely cause -\n connection lost. Close the socket so that we can retry on the\n next event.\n \"\"\"\n if self.closeOnError and self.sock:\n self.sock.close()\n self.sock = None #try to reconnect next time\n\n def emit(self, record):\n \"\"\"\n Pickles the record and writes it to the socket in binary format.\n If there is an error with the socket, silently drop the packet.\n \"\"\"\n try:\n s = self.makePickle(record)\n if not self.sock:\n self.sock = self.makeSocket()\n self.send(s)\n except:\n self.handleError()\n\n def close(self):\n \"\"\"\n Closes the socket.\n \"\"\"\n if self.sock:\n self.sock.close()\n self.sock = None\n\nclass DatagramHandler(SocketHandler):\n \"\"\"\n A handler class which writes logging records, in pickle format, to\n a datagram socket.\n \"\"\"\n def __init__(self, host, port):\n \"\"\"\n Initializes the handler with a specific host address and port.\n \"\"\"\n SocketHandler.__init__(self, host, port)\n self.closeOnError = 0\n\n def makeSocket(self):\n \"\"\"\n The factory method of SocketHandler is here overridden to create\n a UDP socket (SOCK_DGRAM).\n \"\"\"\n s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n return s\n\n def sendto(self, s, addr):\n \"\"\"\n Send a pickled string to a socket. This function allows for\n partial sends which can happen when the network is busy.\n \"\"\"\n sentsofar = 0\n left = len(s)\n while left > 0:\n sent = self.sock.sendto(s[sentsofar:], addr)\n sentsofar = sentsofar + sent\n left = left - sent\n\n def emit(self, record):\n \"\"\"\n Pickles the record and writes it to the socket in binary format.\n \"\"\"\n try:\n s = self.makePickle(record)\n if not self.sock:\n self.sock = self.makeSocket()\n self.sendto(s, (self.host, self.port))\n except:\n self.handleError()\n\nclass SysLogHandler(Handler):\n \"\"\"\n A handler class which sends formatted logging records to a syslog\n server. Based on Sam Rushing's syslog module:\n http://www.nightmare.com/squirl/python-ext/misc/syslog.py\n Contributed by Nicolas Untz (after which minor refactoring changes\n have been made).\n \"\"\"\n\n # from :\n # ======================================================================\n # priorities/facilities are encoded into a single 32-bit quantity, where\n # the bottom 3 bits are the priority (0-7) and the top 28 bits are the\n # facility (0-big number). Both the priorities and the facilities map\n # roughly one-to-one to strings in the syslogd(8) source code. This\n # mapping is included in this file.\n #\n # priorities (these are ordered)\n\n LOG_EMERG = 0 # system is unusable\n LOG_ALERT = 1 # action must be taken immediately\n LOG_CRIT = 2 # critical conditions\n LOG_ERR = 3 # error conditions\n LOG_WARNING = 4 # warning conditions\n LOG_NOTICE = 5 # normal but significant condition\n LOG_INFO = 6 # informational\n LOG_DEBUG = 7 # debug-level messages\n\n # facility codes\n LOG_KERN = 0 # kernel messages\n LOG_USER = 1 # random user-level messages\n LOG_MAIL = 2 # mail system\n LOG_DAEMON = 3 # system daemons\n LOG_AUTH = 4 # security/authorization messages\n LOG_SYSLOG = 5 # messages generated internally by syslogd\n LOG_LPR = 6 # line printer subsystem\n LOG_NEWS = 7 # network news subsystem\n LOG_UUCP = 8 # UUCP subsystem\n LOG_CRON = 9 # clock daemon\n LOG_AUTHPRIV = 10 # security/authorization messages (private)\n\n # other codes through 15 reserved for system use\n LOG_LOCAL0 = 16 # reserved for local use\n LOG_LOCAL1 = 17 # reserved for local use\n LOG_LOCAL2 = 18 # reserved for local use\n LOG_LOCAL3 = 19 # reserved for local use\n LOG_LOCAL4 = 20 # reserved for local use\n LOG_LOCAL5 = 21 # reserved for local use\n LOG_LOCAL6 = 22 # reserved for local use\n LOG_LOCAL7 = 23 # reserved for local use\n\n priority_names = {\n \"alert\": LOG_ALERT,\n \"crit\": LOG_CRIT,\n \"critical\": LOG_CRIT,\n \"debug\": LOG_DEBUG,\n \"emerg\": LOG_EMERG,\n \"err\": LOG_ERR,\n \"error\": LOG_ERR, # DEPRECATED\n \"info\": LOG_INFO,\n \"notice\": LOG_NOTICE,\n \"panic\": LOG_EMERG, # DEPRECATED\n \"warn\": LOG_WARNING, # DEPRECATED\n \"warning\": LOG_WARNING,\n }\n\n facility_names = {\n \"auth\": LOG_AUTH,\n \"authpriv\": LOG_AUTHPRIV,\n \"cron\": LOG_CRON,\n \"daemon\": LOG_DAEMON,\n \"kern\": LOG_KERN,\n \"lpr\": LOG_LPR,\n \"mail\": LOG_MAIL,\n \"news\": LOG_NEWS,\n \"security\": LOG_AUTH, # DEPRECATED\n \"syslog\": LOG_SYSLOG,\n \"user\": LOG_USER,\n \"uucp\": LOG_UUCP,\n \"local0\": LOG_LOCAL0,\n \"local1\": LOG_LOCAL1,\n \"local2\": LOG_LOCAL2,\n \"local3\": LOG_LOCAL3,\n \"local4\": LOG_LOCAL4,\n \"local5\": LOG_LOCAL5,\n \"local6\": LOG_LOCAL6,\n \"local7\": LOG_LOCAL7,\n }\n\n def __init__(self, address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER):\n \"\"\"\n If address is not specified, UNIX socket is used.\n If facility is not specified, LOG_USER is used.\n \"\"\"\n Handler.__init__(self)\n\n self.address = address\n self.facility = facility\n if type(address) == types.StringType:\n self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)\n self.socket.connect(address)\n self.unixsocket = 1\n else:\n self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n self.unixsocket = 0\n\n self.formatter = None\n\n # curious: when talking to the unix-domain '/dev/log' socket, a\n # zero-terminator seems to be required. this string is placed\n # into a class variable so that it can be overridden if\n # necessary.\n log_format_string = '<%d>%s\\000'\n\n def encodePriority (self, facility, priority):\n \"\"\"\n Encode the facility and priority. You can pass in strings or\n integers - if strings are passed, the facility_names and\n priority_names mapping dictionaries are used to convert them to\n integers.\n \"\"\"\n if type(facility) == types.StringType:\n facility = self.facility_names[facility]\n if type(priority) == types.StringType:\n priority = self.priority_names[priority]\n return (facility << 3) | priority\n\n def close (self):\n \"\"\"\n Closes the socket.\n \"\"\"\n if self.unixsocket:\n self.socket.close()\n\n def emit(self, record):\n \"\"\"\n The record is formatted, and then sent to the syslog server. If\n exception information is present, it is NOT sent to the server.\n \"\"\"\n msg = self.format(record)\n \"\"\"\n We need to convert record level to lowercase, maybe this will\n change in the future.\n \"\"\"\n msg = self.log_format_string % (\n self.encodePriority(self.facility, string.lower(record.level)),\n msg)\n try:\n if self.unixsocket:\n self.socket.send(msg)\n else:\n self.socket.sendto(msg, self.address)\n except:\n self.handleError()\n\nclass SMTPHandler(Handler):\n \"\"\"\n A handler class which sends an SMTP email for each logging event.\n \"\"\"\n def __init__(self, mailhost, fromaddr, toaddrs, subject):\n \"\"\"\n Initialize the instance with the from and to addresses and subject\n line of the email. To specify a non-standard SMTP port, use the\n (host, port) tuple format for the mailhost argument.\n \"\"\"\n Handler.__init__(self)\n if type(mailhost) == types.TupleType:\n host, port = mailhost\n self.mailhost = host\n self.mailport = port\n else:\n self.mailhost = mailhost\n self.mailport = None\n self.fromaddr = fromaddr\n self.toaddrs = toaddrs\n self.subject = subject\n\n def getSubject(self, record):\n \"\"\"\n If you want to specify a subject line which is record-dependent,\n override this method.\n \"\"\"\n return self.subject\n\n def emit(self, record):\n \"\"\"\n Format the record and send it to the specified addressees.\n \"\"\"\n try:\n import smtplib\n port = self.mailport\n if not port:\n port = smtplib.SMTP_PORT\n smtp = smtplib.SMTP(self.mailhost, port)\n msg = self.format(record)\n msg = \"From: %s\\r\\nTo: %s\\r\\nSubject: %s\\r\\n\\r\\n%s\" % (\n self.fromaddr,\n string.join(self.toaddrs, \",\"),\n self.getSubject(record), msg\n )\n smtp.sendmail(self.fromaddr, self.toaddrs, msg)\n smtp.quit()\n except:\n self.handleError()\n\nclass BufferingHandler(Handler):\n \"\"\"\n A handler class which buffers logging records in memory. Whenever each\n record is added to the buffer, a check is made to see if the buffer should\n be flushed. If it should, then flush() is expected to do the needful.\n \"\"\"\n def __init__(self, capacity):\n \"\"\"\n Initialize the handler with the buffer size.\n \"\"\"\n Handler.__init__(self)\n self.capacity = capacity\n self.buffer = []\n\n def shouldFlush(self, record):\n \"\"\"\n Returns true if the buffer is up to capacity. This method can be\n overridden to implement custom flushing strategies.\n \"\"\"\n return (len(self.buffer) >= self.capacity)\n\n def emit(self, record):\n \"\"\"\n Append the record. If shouldFlush() tells us to, call flush() to process\n the buffer.\n \"\"\"\n self.buffer.append(record)\n if self.shouldFlush(record):\n self.flush()\n\n def flush(self):\n \"\"\"\n Override to implement custom flushing behaviour. This version just zaps\n the buffer to empty.\n \"\"\"\n self.buffer = []\n\nclass MemoryHandler(BufferingHandler):\n \"\"\"\n A handler class which buffers logging records in memory, periodically\n flushing them to a target handler. Flushing occurs whenever the buffer\n is full, or when an event of a certain severity or greater is seen.\n \"\"\"\n def __init__(self, capacity, flushLevel=ERROR, target=None):\n \"\"\"\n Initialize the handler with the buffer size, the level at which\n flushing should occur and an optional target. Note that without a\n target being set either here or via setTarget(), a MemoryHandler\n is no use to anyone!\n \"\"\"\n BufferingHandler.__init__(self, capacity)\n self.flushLevel = flushLevel\n self.target = target\n\n def shouldFlush(self, record):\n \"\"\"\n Check for buffer full or a record at the flushLevel or higher.\n \"\"\"\n return (len(self.buffer) >= self.capacity) or \\\n (record.lvl >= self.flushLevel)\n\n def setTarget(self, target):\n \"\"\"\n Set the target handler for this handler.\n \"\"\"\n self.target = target\n\n def flush(self):\n \"\"\"\n For a MemoryHandler, flushing means just sending the buffered\n records to the target, if there is one. Override if you want\n different behaviour.\n \"\"\"\n if self.target:\n for record in self.buffer:\n self.target.handle(record)\n self.buffer = []\n\nclass NTEventLogHandler(Handler):\n \"\"\"\n A handler class which sends events to the NT Event Log. Adds a\n registry entry for the specified application name. If no dllname is\n provided, win32service.pyd (which contains some basic message\n placeholders) is used. Note that use of these placeholders will make\n your event logs big, as the entire message source is held in the log.\n If you want slimmer logs, you have to pass in the name of your own DLL\n which contains the message definitions you want to use in the event log.\n \"\"\"\n def __init__(self, appname, dllname=None, logtype=\"Application\"):\n Handler.__init__(self)\n try:\n import win32evtlogutil, win32evtlog\n self.appname = appname\n self._welu = win32evtlogutil\n if not dllname:\n import os\n dllname = os.path.split(self._welu.__file__)\n dllname = os.path.split(dllname[0])\n dllname = os.path.join(dllname[0], r'win32service.pyd')\n self.dllname = dllname\n self.logtype = logtype\n self._welu.AddSourceToRegistry(appname, dllname, logtype)\n self.deftype = win32evtlog.EVENTLOG_ERROR_TYPE\n self.typemap = {\n DEBUG : win32evtlog.EVENTLOG_INFORMATION_TYPE,\n INFO : win32evtlog.EVENTLOG_INFORMATION_TYPE,\n WARN : win32evtlog.EVENTLOG_WARNING_TYPE,\n ERROR : win32evtlog.EVENTLOG_ERROR_TYPE,\n CRITICAL: win32evtlog.EVENTLOG_ERROR_TYPE,\n }\n except ImportError:\n print \"The Python Win32 extensions for NT (service, event \"\\\n \"logging) appear not to be available.\"\n self._welu = None\n\n def getMessageID(self, record):\n \"\"\"\n Return the message ID for the event record. If you are using your\n own messages, you could do this by having the msg passed to the\n logger being an ID rather than a formatting string. Then, in here,\n you could use a dictionary lookup to get the message ID. This\n version returns 1, which is the base message ID in win32service.pyd.\n \"\"\"\n return 1\n\n def getEventCategory(self, record):\n \"\"\"\n Return the event category for the record. Override this if you\n want to specify your own categories. This version returns 0.\n \"\"\"\n return 0\n\n def getEventType(self, record):\n \"\"\"\n Return the event type for the record. Override this if you want\n to specify your own types. This version does a mapping using the\n handler's typemap attribute, which is set up in __init__() to a\n dictionary which contains mappings for DEBUG, INFO, WARN, ERROR\n and CRITICAL. If you are using your own levels you will either need\n to override this method or place a suitable dictionary in the\n handler's typemap attribute.\n \"\"\"\n return self.typemap.get(record.lvl, self.deftype)\n\n def emit(self, record):\n \"\"\"\n Determine the message ID, event category and event type. Then\n log the message in the NT event log.\n \"\"\"\n if self._welu:\n try:\n id = self.getMessageID(record)\n cat = self.getEventCategory(record)\n type = self.getEventType(record)\n msg = self.format(record)\n self._welu.ReportEvent(self.appname, id, cat, type, [msg])\n except:\n self.handleError()\n\n def close(self):\n \"\"\"\n You can remove the application name from the registry as a\n source of event log entries. However, if you do this, you will\n not be able to see the events as you intended in the Event Log\n Viewer - it needs to be able to access the registry to get the\n DLL name.\n \"\"\"\n #self._welu.RemoveSourceFromRegistry(self.appname, self.logtype)\n pass\n\nclass HTTPHandler(Handler):\n \"\"\"\n A class which sends records to a Web server, using either GET or\n POST semantics.\n \"\"\"\n def __init__(self, host, url, method=\"GET\"):\n \"\"\"\n Initialize the instance with the host, the request URL, and the method\n (\"GET\" or \"POST\")\n \"\"\"\n Handler.__init__(self)\n method = string.upper(method)\n if method not in [\"GET\", \"POST\"]:\n raise ValueError, \"method must be GET or POST\"\n self.host = host\n self.url = url\n self.method = method\n\n def emit(self, record):\n \"\"\"\n Send the record to the Web server as an URL-encoded dictionary\n \"\"\"\n try:\n import httplib, urllib\n h = httplib.HTTP(self.host)\n url = self.url\n data = urllib.urlencode(record.__dict__)\n if self.method == \"GET\":\n if (string.find(url, '?') >= 0):\n sep = '&'\n else:\n sep = '?'\n url = url + \"%c%s\" % (sep, data)\n h.putrequest(self.method, url)\n if self.method == \"POST\":\n h.putheader(\"Content-length\", str(len(data)))\n h.endheaders()\n if self.method == \"POST\":\n h.send(data)\n h.getreply() #can't do anything with the result\n except:\n self.handleError()\n\nSOAP_MESSAGE = \"\"\"\n \n \n%s\n \n \n\n\"\"\"\n\nclass SOAPHandler(Handler):\n \"\"\"\n A class which sends records to a SOAP server.\n \"\"\"\n def __init__(self, host, url):\n \"\"\"\n Initialize the instance with the host and the request URL\n \"\"\"\n Handler.__init__(self)\n self.host = host\n self.url = url\n\n def emit(self, record):\n \"\"\"\n Send the record to the Web server as a SOAP message\n \"\"\"\n try:\n import httplib, urllib\n h = httplib.HTTP(self.host)\n h.putrequest(\"POST\", self.url)\n keys = record.__dict__.keys()\n keys.sort()\n args = \"\"\n for key in keys:\n v = record.__dict__[key]\n if type(v) == types.StringType:\n t = \"string\"\n elif (type(v) == types.IntType) or (type(v) == types.LongType):\n t = \"integer\"\n elif type(v) == types.FloatType:\n t = \"float\"\n else:\n t = \"string\"\n args = args + \"%12s%s\\n\" % (\"\",\n key, t, str(v), key)\n data = SOAP_MESSAGE % args[:-1]\n #print data\n h.putheader(\"Content-type\", \"text/plain; charset=\\\"utf-8\\\"\")\n h.putheader(\"Content-length\", str(len(data)))\n h.endheaders()\n h.send(data)\n r = h.getreply() #can't do anything with the result\n #print r\n f = h.getfile()\n #print f.read()\n f.close()\n except:\n self.handleError()\n\n#---------------------------------------------------------------------------\n# Manager classes and functions\n#---------------------------------------------------------------------------\n\nclass PlaceHolder:\n \"\"\"\n PlaceHolder instances are used in the Manager logger hierarchy to take\n the place of nodes for which no loggers have been defined [FIXME add\n example].\n \"\"\"\n def __init__(self, alogger):\n \"\"\"\n Initialize with the specified logger being a child of this placeholder.\n \"\"\"\n self.loggers = [alogger]\n\n def append(self, alogger):\n \"\"\"\n Add the specified logger as a child of this placeholder.\n \"\"\"\n if alogger not in self.loggers:\n self.loggers.append(alogger)\n\n#\n# Determine which class to use when instantiating loggers.\n#\n_loggerClass = None\n\ndef setLoggerClass(klass):\n \"\"\"\n Set the class to be used when instantiating a logger. The class should\n define __init__() such that only a name argument is required, and the\n __init__() should call Logger.__init__()\n \"\"\"\n if klass != Logger:\n if type(klass) != types.ClassType:\n raise TypeError, \"setLoggerClass is expecting a class\"\n if not (Logger in klass.__bases__):\n raise TypeError, \"logger not derived from logging.Logger: \" + \\\n klass.__name__\n global _loggerClass\n _loggerClass = klass\n\nclass Manager:\n \"\"\"\n There is [under normal circumstances] just one Manager instance, which\n holds the hierarchy of loggers.\n \"\"\"\n def __init__(self, root):\n \"\"\"\n Initialize the manager with the root node of the logger hierarchy.\n \"\"\"\n self.root = root\n self.disable = 0\n self.emittedNoHandlerWarning = 0\n self.loggerDict = {}\n\n def getLogger(self, name):\n \"\"\"\n Get a logger with the specified name, creating it if it doesn't\n yet exist. If a PlaceHolder existed for the specified name [i.e.\n the logger didn't exist but a child of it did], replace it with\n the created logger and fix up the parent/child references which\n pointed to the placeholder to now point to the logger.\n \"\"\"\n rv = None\n if self.loggerDict.has_key(name):\n rv = self.loggerDict[name]\n if isinstance(rv, PlaceHolder):\n ph = rv\n rv = _loggerClass(name)\n rv.manager = self\n self.loggerDict[name] = rv\n self._fixupChildren(ph, rv)\n self._fixupParents(rv)\n else:\n rv = _loggerClass(name)\n rv.manager = self\n self.loggerDict[name] = rv\n self._fixupParents(rv)\n return rv\n\n def _fixupParents(self, alogger):\n \"\"\"\n Ensure that there are either loggers or placeholders all the way\n from the specified logger to the root of the logger hierarchy.\n \"\"\"\n name = alogger.name\n i = string.rfind(name, \".\")\n rv = None\n while (i > 0) and not rv:\n substr = name[:i]\n if not self.loggerDict.has_key(substr):\n self.loggerDict[name] = PlaceHolder(alogger)\n else:\n obj = self.loggerDict[substr]\n if isinstance(obj, Logger):\n rv = obj\n else:\n assert isinstance(obj, PlaceHolder)\n obj.append(alogger)\n i = string.rfind(name, \".\", 0, i - 1)\n if not rv:\n rv = self.root\n alogger.parent = rv\n\n def _fixupChildren(self, ph, alogger):\n \"\"\"\n Ensure that children of the placeholder ph are connected to the\n specified logger.\n \"\"\"\n for c in ph.loggers:\n if string.find(c.parent.name, alogger.name) <> 0:\n alogger.parent = c.parent\n c.parent = alogger\n\n#---------------------------------------------------------------------------\n# Logger classes and functions\n#---------------------------------------------------------------------------\n\nclass Logger(Filterer):\n \"\"\"\n Instances of the Logger class represent a single logging channel.\n \"\"\"\n def __init__(self, name, level=0):\n \"\"\"\n Initialize the logger with a name and an optional level.\n \"\"\"\n Filterer.__init__(self)\n self.name = name\n self.level = level\n self.parent = None\n self.propagate = 1\n self.handlers = []\n\n def setLevel(self, lvl):\n \"\"\"\n Set the logging level of this logger.\n \"\"\"\n self.level = lvl\n\n# def getRoot(self):\n# \"\"\"\n# Get the root of the logger hierarchy.\n# \"\"\"\n# return Logger.root\n\n def debug(self, msg, *args, **kwargs):\n \"\"\"\n Log 'msg % args' with severity 'DEBUG'. To pass exception information,\n use the keyword argument exc_info with a true value, e.g.\n\n logger.debug(\"Houston, we have a %s\", \"thorny problem\", exc_info=1)\n \"\"\"\n if self.manager.disable >= DEBUG:\n return\n if DEBUG >= self.getEffectiveLevel():\n apply(self._log, (DEBUG, msg, args), kwargs)\n\n def info(self, msg, *args, **kwargs):\n \"\"\"\n Log 'msg % args' with severity 'INFO'. To pass exception information,\n use the keyword argument exc_info with a true value, e.g.\n\n logger.info(\"Houston, we have a %s\", \"interesting problem\", exc_info=1)\n \"\"\"\n if self.manager.disable >= INFO:\n return\n if INFO >= self.getEffectiveLevel():\n apply(self._log, (INFO, msg, args), kwargs)\n\n def warn(self, msg, *args, **kwargs):\n \"\"\"\n Log 'msg % args' with severity 'WARN'. To pass exception information,\n use the keyword argument exc_info with a true value, e.g.\n\n logger.warn(\"Houston, we have a %s\", \"bit of a problem\", exc_info=1)\n \"\"\"\n if self.manager.disable >= WARN:\n return\n if self.isEnabledFor(WARN):\n apply(self._log, (WARN, msg, args), kwargs)\n\n def error(self, msg, *args, **kwargs):\n \"\"\"\n Log 'msg % args' with severity 'ERROR'. To pass exception information,\n use the keyword argument exc_info with a true value, e.g.\n\n logger.error(\"Houston, we have a %s\", \"major problem\", exc_info=1)\n \"\"\"\n if self.manager.disable >= ERROR:\n return\n if self.isEnabledFor(ERROR):\n apply(self._log, (ERROR, msg, args), kwargs)\n\n def exception(self, msg, *args):\n \"\"\"\n Convenience method for logging an ERROR with exception information\n \"\"\"\n apply(self.error, (msg,) + args, {'exc_info': 1})\n\n def critical(self, msg, *args, **kwargs):\n \"\"\"\n Log 'msg % args' with severity 'CRITICAL'. To pass exception\n information, use the keyword argument exc_info with a true value, e.g.\n\n logger.critical(\"Houston, we have a %s\", \"major disaster\", exc_info=1)\n \"\"\"\n if self.manager.disable >= CRITICAL:\n return\n if CRITICAL >= self.getEffectiveLevel():\n apply(self._log, (CRITICAL, msg, args), kwargs)\n\n fatal = critical\n\n def log(self, lvl, msg, *args, **kwargs):\n \"\"\"\n Log 'msg % args' with the severity 'lvl'. To pass exception\n information, use the keyword argument exc_info with a true value, e.g.\n logger.log(lvl, \"We have a %s\", \"mysterious problem\", exc_info=1)\n \"\"\"\n if self.manager.disable >= lvl:\n return\n if self.isEnabledFor(lvl):\n apply(self._log, (lvl, msg, args), kwargs)\n\n def findCaller(self):\n \"\"\"\n Find the stack frame of the caller so that we can note the source\n file name and line number.\n \"\"\"\n frames = inspect.stack()[1:]\n for f in frames:\n if _srcfile != f[1]:\n return (f[1], f[2])\n return (None, None)\n\n def makeRecord(self, name, lvl, fn, lno, msg, args, exc_info):\n \"\"\"\n A factory method which can be overridden in subclasses to create\n specialized LogRecords.\n \"\"\"\n return LogRecord(name, lvl, fn, lno, msg, args, exc_info)\n\n def _log(self, lvl, msg, args, exc_info=None):\n \"\"\"\n Low-level logging routine which creates a LogRecord and then calls\n all the handlers of this logger to handle the record.\n \"\"\"\n if inspect:\n fn, lno = self.findCaller()\n else:\n fn, lno = \"\", 0\n if exc_info:\n exc_info = sys.exc_info()\n record = self.makeRecord(self.name, lvl, fn, lno, msg, args, exc_info)\n self.handle(record)\n\n def handle(self, record):\n \"\"\"\n Call the handlers for the specified record. This method is used for\n unpickled records received from a socket, as well as those created\n locally. Logger-level filtering is applied.\n \"\"\"\n if self.filter(record):\n self.callHandlers(record)\n\n def addHandler(self, hdlr):\n \"\"\"\n Add the specified handler to this logger.\n \"\"\"\n if not (hdlr in self.handlers):\n self.handlers.append(hdlr)\n\n def removeHandler(self, hdlr):\n \"\"\"\n Remove the specified handler from this logger.\n \"\"\"\n if hdlr in self.handlers:\n self.handlers.remove(hdlr)\n\n def callHandlers(self, record):\n \"\"\"\n Loop through all handlers for this logger and its parents in the\n logger hierarchy. If no handler was found, output a one-off error\n message. Stop searching up the hierarchy whenever a logger with the\n \"propagate\" attribute set to zero is found - that will be the last\n logger whose handlers are called.\n \"\"\"\n c = self\n found = 0\n while c:\n for hdlr in c.handlers:\n found = found + 1\n if record.lvl >= hdlr.level:\n hdlr.handle(record)\n if not c.propagate:\n c = None #break out\n else:\n c = c.parent\n if (found == 0) and not self.manager.emittedNoHandlerWarning:\n print \"No handlers could be found for logger \\\"%s\\\"\" % self.name\n self.manager.emittedNoHandlerWarning = 1\n\n def getEffectiveLevel(self):\n \"\"\"\n Loop through this logger and its parents in the logger hierarchy,\n looking for a non-zero logging level. Return the first one found.\n \"\"\"\n c = self\n while c:\n if c.level:\n return c.level\n c = c.parent\n #print \"NCP\", self.parent\n\n def isEnabledFor(self, lvl):\n \"\"\"\n Is this logger enabled for level lvl?\n \"\"\"\n if self.manager.disable >= lvl:\n return 0\n return lvl >= self.getEffectiveLevel()\n\nclass RootLogger(Logger):\n \"\"\"\n A root logger is not that different to any other logger, except that\n it must have a logging level and there is only one instance of it in\n the hierarchy.\n \"\"\"\n def __init__(self, lvl):\n \"\"\"\n Initialize the logger with the name \"root\".\n \"\"\"\n Logger.__init__(self, \"root\", lvl)\n\n_loggerClass = Logger\n\nroot = RootLogger(DEBUG)\nLogger.root = root\nLogger.manager = Manager(Logger.root)\n\n#---------------------------------------------------------------------------\n# Configuration classes and functions\n#---------------------------------------------------------------------------\n\nBASIC_FORMAT = \"%(asctime)s %(name)-19s %(level)-5s - %(message)s\"\n\ndef basicConfig():\n \"\"\"\n Do basic configuration for the logging system by creating a\n StreamHandler with a default Formatter and adding it to the\n root logger.\n \"\"\"\n hdlr = StreamHandler()\n fmt = Formatter(BASIC_FORMAT)\n hdlr.setFormatter(fmt)\n root.addHandler(hdlr)\n\n#def fileConfig(fname):\n# \"\"\"\n# The old implementation - using dict-based configuration files.\n# Read the logging configuration from a file. Keep it simple for now.\n# \"\"\"\n# file = open(fname, \"r\")\n# data = file.read()\n# file.close()\n# dict = eval(data)\n# handlers = dict.get(\"handlers\", [])\n# loggers = dict.get(\"loggers\", [])\n# formatters = dict.get(\"formatters\", [])\n# for f in formatters:\n# fd = dict[f]\n# fc = fd.get(\"class\", \"logging.Formatter\")\n# args = fd.get(\"args\", ())\n# fc = eval(fc)\n# try:\n# fmt = apply(fc, args)\n# except:\n# print fc, args\n# raise\n# dict[f] = fmt\n#\n# for h in handlers:\n# hd = dict[h]\n# hc = hd.get(\"class\", \"logging.StreamHandler\")\n# args = hd.get(\"args\", ())\n# hc = eval(hc)\n# fmt = hd.get(\"formatter\", None)\n# if fmt:\n# fmt = dict.get(fmt, None)\n# try:\n# hdlr = apply(hc, args)\n# except:\n# print hc, args\n# raise\n# if fmt:\n# hdlr.setFormatter(fmt)\n# dict[h] = hdlr\n#\n# for ln in loggers:\n# ld = dict[ln]\n# name = ld.get(\"name\", None)\n# if name:\n# logger = getLogger(name)\n# else:\n# logger = getRootLogger()\n# logger.propagate = ld.get(\"propagate\", 1)\n# hdlrs = ld.get(\"handlers\", [])\n# for h in hdlrs:\n# hdlr = dict.get(h, None)\n# if hdlr:\n# logger.addHandler(hdlr)\n\ndef fileConfig(fname):\n \"\"\"\n Read the logging configuration from a ConfigParser-format file.\n \"\"\"\n import ConfigParser\n\n cp = ConfigParser.ConfigParser()\n cp.read(fname)\n #first, do the formatters...\n flist = cp.get(\"formatters\", \"keys\")\n flist = string.split(flist, \",\")\n formatters = {}\n for form in flist:\n sectname = \"formatter_%s\" % form\n fs = cp.get(sectname, \"format\", 1)\n dfs = cp.get(sectname, \"datefmt\", 1)\n f = Formatter(fs, dfs)\n formatters[form] = f\n #next, do the handlers...\n hlist = cp.get(\"handlers\", \"keys\")\n hlist = string.split(hlist, \",\")\n handlers = {}\n for hand in hlist:\n sectname = \"handler_%s\" % hand\n klass = cp.get(sectname, \"class\")\n fmt = cp.get(sectname, \"formatter\")\n lvl = cp.get(sectname, \"level\")\n klass = eval(klass)\n args = cp.get(sectname, \"args\")\n args = eval(args)\n h = apply(klass, args)\n h.setLevel(eval(lvl))\n h.setFormatter(formatters[fmt])\n #temporary hack for FileHandler.\n if klass == FileHandler:\n maxsize = cp.get(sectname, \"maxsize\")\n if maxsize:\n maxsize = eval(maxsize)\n else:\n maxsize = 0\n if maxsize:\n backcount = cp.get(sectname, \"backcount\")\n if backcount:\n backcount = eval(backcount)\n else:\n backcount = 0\n h.setRollover(maxsize, backcount)\n handlers[hand] = h\n #at last, the loggers...first the root...\n llist = cp.get(\"loggers\", \"keys\")\n llist = string.split(llist, \",\")\n llist.remove(\"root\")\n sectname = \"logger_root\"\n log = root\n lvl = cp.get(sectname, \"level\")\n log.setLevel(eval(lvl))\n hlist = cp.get(sectname, \"handlers\")\n hlist = string.split(hlist, \",\")\n for hand in hlist:\n log.addHandler(handlers[hand])\n #and now the others...\n for log in llist:\n sectname = \"logger_%s\" % log\n qn = cp.get(sectname, \"qualname\")\n lvl = cp.get(sectname, \"level\")\n propagate = cp.get(sectname, \"propagate\")\n logger = getLogger(qn)\n logger.setLevel(eval(lvl))\n logger.propagate = eval(propagate)\n hlist = cp.get(sectname, \"handlers\")\n hlist = string.split(hlist, \",\")\n for hand in hlist:\n logger.addHandler(handlers[hand])\n\n\n#---------------------------------------------------------------------------\n# Utility functions at module level.\n# Basically delegate everything to the root logger.\n#---------------------------------------------------------------------------\n\ndef getLogger(name):\n \"\"\"\n Return a logger with the specified name, creating it if necessary.\n If no name is specified, return the root logger.\n \"\"\"\n if name:\n return Logger.manager.getLogger(name)\n else:\n return root\n\ndef getRootLogger():\n \"\"\"\n Return the root logger.\n \"\"\"\n return root\n\ndef critical(msg, *args, **kwargs):\n \"\"\"\n Log a message with severity 'CRITICAL' on the root logger.\n \"\"\"\n if len(root.handlers) == 0:\n basicConfig()\n apply(root.critical, (msg,)+args, kwargs)\n\nfatal = critical\n\ndef error(msg, *args, **kwargs):\n \"\"\"\n Log a message with severity 'ERROR' on the root logger.\n \"\"\"\n if len(root.handlers) == 0:\n basicConfig()\n apply(root.error, (msg,)+args, kwargs)\n\ndef exception(msg, *args):\n \"\"\"\n Log a message with severity 'ERROR' on the root logger,\n with exception information.\n \"\"\"\n apply(error, (msg,)+args, {'exc_info': 1})\n\ndef warn(msg, *args, **kwargs):\n \"\"\"\n Log a message with severity 'WARN' on the root logger.\n \"\"\"\n if len(root.handlers) == 0:\n basicConfig()\n apply(root.warn, (msg,)+args, kwargs)\n\ndef info(msg, *args, **kwargs):\n \"\"\"\n Log a message with severity 'INFO' on the root logger.\n \"\"\"\n if len(root.handlers) == 0:\n basicConfig()\n apply(root.info, (msg,)+args, kwargs)\n\ndef debug(msg, *args, **kwargs):\n \"\"\"\n Log a message with severity 'DEBUG' on the root logger.\n \"\"\"\n if len(root.handlers) == 0:\n basicConfig()\n apply(root.debug, (msg,)+args, kwargs)\n\ndef disable(level):\n \"\"\"\n Disable all logging calls less severe than 'level'.\n \"\"\"\n root.manager.disable = level\n\ndef shutdown():\n \"\"\"\n Perform any cleanup actions in the logging system (e.g. flushing\n buffers). Should be called at application exit.\n \"\"\"\n for h in _handlers.keys():\n h.flush()\n h.close()\n\nif __name__ == \"__main__\":\n print __doc__\n", "source_code_before": null, "methods": [ { "name": "getLevelName", "long_name": "getLevelName( lvl )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "lvl" ], "start_line": 105, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "addLevelName", "long_name": "addLevelName( lvl , levelName )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "lvl", "levelName" ], "start_line": 115, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , lvl , pathname , lineno , msg , args , exc_info )", "filename": "logging.py", "nloc": 21, "complexity": 3, "token_count": 142, "parameters": [ "self", "name", "lvl", "pathname", "lineno", "msg", "args", "exc_info" ], "start_line": 136, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "logging.py", "nloc": 3, "complexity": 1, "token_count": 29, "parameters": [ "self" ], "start_line": 161, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fmt = None , datefmt = None )", "filename": "logging.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "fmt", "datefmt" ], "start_line": 207, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "formatTime", "long_name": "formatTime( self , record , datefmt = None )", "filename": "logging.py", "nloc": 8, "complexity": 2, "token_count": 68, "parameters": [ "self", "record", "datefmt" ], "start_line": 219, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "formatException", "long_name": "formatException( self , ei )", "filename": "logging.py", "nloc": 7, "complexity": 1, "token_count": 54, "parameters": [ "self", "ei" ], "start_line": 237, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "format", "long_name": "format( self , record )", "filename": "logging.py", "nloc": 10, "complexity": 4, "token_count": 85, "parameters": [ "self", "record" ], "start_line": 249, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , linefmt = None )", "filename": "logging.py", "nloc": 5, "complexity": 2, "token_count": 25, "parameters": [ "self", "linefmt" ], "start_line": 279, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "formatHeader", "long_name": "formatHeader( self , records )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "records" ], "start_line": 289, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "formatFooter", "long_name": "formatFooter( self , records )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "records" ], "start_line": 295, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "format", "long_name": "format( self , records )", "filename": "logging.py", "nloc": 8, "complexity": 3, "token_count": 58, "parameters": [ "self", "records" ], "start_line": 301, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "record" ], "start_line": 323, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 334, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "addFilter", "long_name": "addFilter( self , filter )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 26, "parameters": [ "self", "filter" ], "start_line": 337, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "removeFilter", "long_name": "removeFilter( self , filter )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 23, "parameters": [ "self", "filter" ], "start_line": 344, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self , record )", "filename": "logging.py", "nloc": 7, "complexity": 3, "token_count": 33, "parameters": [ "self", "record" ], "start_line": 351, "end_line": 362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , level = 0 )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "self", "level" ], "start_line": 377, "end_line": 385, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "setLevel", "long_name": "setLevel( self , lvl )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "lvl" ], "start_line": 387, "end_line": 391, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "format", "long_name": "format( self , record )", "filename": "logging.py", "nloc": 6, "complexity": 2, "token_count": 30, "parameters": [ "self", "record" ], "start_line": 393, "end_line": 402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self", "record" ], "start_line": 404, "end_line": 411, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "handle", "long_name": "handle( self , record )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 22, "parameters": [ "self", "record" ], "start_line": 413, "end_line": 419, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "setFormatter", "long_name": "setFormatter( self , fmt )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "fmt" ], "start_line": 421, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "flush", "long_name": "flush( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 427, "end_line": 432, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "close", "long_name": "close( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 434, "end_line": 439, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "handleError", "long_name": "handleError( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 441, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , strm = None )", "filename": "logging.py", "nloc": 6, "complexity": 2, "token_count": 35, "parameters": [ "self", "strm" ], "start_line": 463, "end_line": 471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "flush", "long_name": "flush( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 473, "end_line": 477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 7, "complexity": 2, "token_count": 40, "parameters": [ "self", "record" ], "start_line": 479, "end_line": 492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , filename , mode = \"a+\" )", "filename": "logging.py", "nloc": 7, "complexity": 1, "token_count": 50, "parameters": [ "self", "filename", "mode" ], "start_line": 498, "end_line": 509, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "setRollover", "long_name": "setRollover( self , max_size , backup_count )", "filename": "logging.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "self", "max_size", "backup_count" ], "start_line": 511, "end_line": 526, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "doRollover", "long_name": "doRollover( self )", "filename": "logging.py", "nloc": 9, "complexity": 2, "token_count": 66, "parameters": [ "self" ], "start_line": 528, "end_line": 539, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 6, "complexity": 3, "token_count": 56, "parameters": [ "self", "record" ], "start_line": 541, "end_line": 550, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "close", "long_name": "close( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 552, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , host , port )", "filename": "logging.py", "nloc": 6, "complexity": 1, "token_count": 36, "parameters": [ "self", "host", "port" ], "start_line": 565, "end_line": 573, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "makeSocket", "long_name": "makeSocket( self )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 575, "end_line": 582, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "send", "long_name": "send( self , s )", "filename": "logging.py", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "s" ], "start_line": 584, "end_line": 594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "makePickle", "long_name": "makePickle( self , record )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 48, "parameters": [ "self", "record" ], "start_line": 596, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "handleError", "long_name": "handleError( self )", "filename": "logging.py", "nloc": 4, "complexity": 3, "token_count": 27, "parameters": [ "self" ], "start_line": 605, "end_line": 613, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 8, "complexity": 3, "token_count": 46, "parameters": [ "self", "record" ], "start_line": 615, "end_line": 626, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "close", "long_name": "close( self )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 23, "parameters": [ "self" ], "start_line": 628, "end_line": 634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , host , port )", "filename": "logging.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "host", "port" ], "start_line": 641, "end_line": 646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "makeSocket", "long_name": "makeSocket( self )", "filename": "logging.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 648, "end_line": 654, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "sendto", "long_name": "sendto( self , s , addr )", "filename": "logging.py", "nloc": 7, "complexity": 2, "token_count": 50, "parameters": [ "self", "s", "addr" ], "start_line": 656, "end_line": 666, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 8, "complexity": 3, "token_count": 56, "parameters": [ "self", "record" ], "start_line": 668, "end_line": 678, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , address = ( 'localhost' , SYSLOG_UDP_PORT )", "filename": "logging.py", "nloc": 16, "complexity": 2, "token_count": 101, "parameters": [ "self", "address", "SYSLOG_UDP_PORT" ], "start_line": 769, "end_line": 786, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "encodePriority", "long_name": "encodePriority( self , facility , priority )", "filename": "logging.py", "nloc": 6, "complexity": 3, "token_count": 55, "parameters": [ "self", "facility", "priority" ], "start_line": 794, "end_line": 805, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "close", "long_name": "close( self )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 18, "parameters": [ "self" ], "start_line": 807, "end_line": 812, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 16, "complexity": 3, "token_count": 80, "parameters": [ "self", "record" ], "start_line": 814, "end_line": 833, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , mailhost , fromaddr , toaddrs , subject )", "filename": "logging.py", "nloc": 12, "complexity": 2, "token_count": 72, "parameters": [ "self", "mailhost", "fromaddr", "toaddrs", "subject" ], "start_line": 839, "end_line": 855, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "getSubject", "long_name": "getSubject( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "record" ], "start_line": 857, "end_line": 862, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 17, "complexity": 3, "token_count": 101, "parameters": [ "self", "record" ], "start_line": 864, "end_line": 883, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , capacity )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self", "capacity" ], "start_line": 891, "end_line": 897, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "shouldFlush", "long_name": "shouldFlush( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "self", "record" ], "start_line": 899, "end_line": 904, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 29, "parameters": [ "self", "record" ], "start_line": 906, "end_line": 913, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "flush", "long_name": "flush( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 915, "end_line": 920, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , capacity , flushLevel = ERROR , target = None )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "self", "capacity", "flushLevel", "target" ], "start_line": 928, "end_line": 937, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "shouldFlush", "long_name": "shouldFlush( self , record )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 32, "parameters": [ "self", "record" ], "start_line": 939, "end_line": 944, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "setTarget", "long_name": "setTarget( self , target )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "target" ], "start_line": 946, "end_line": 950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "flush", "long_name": "flush( self )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 32, "parameters": [ "self" ], "start_line": 952, "end_line": 961, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , appname , dllname = None , logtype = \"Application\" )", "filename": "logging.py", "nloc": 26, "complexity": 3, "token_count": 163, "parameters": [ "self", "appname", "dllname", "logtype" ], "start_line": 973, "end_line": 998, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "getMessageID", "long_name": "getMessageID( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "record" ], "start_line": 1000, "end_line": 1008, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "getEventCategory", "long_name": "getEventCategory( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "record" ], "start_line": 1010, "end_line": 1015, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "getEventType", "long_name": "getEventType( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "record" ], "start_line": 1017, "end_line": 1027, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "self", "record" ], "start_line": 1029, "end_line": 1042, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "close", "long_name": "close( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 1044, "end_line": 1053, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , host , url , method = \"GET\" )", "filename": "logging.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [ "self", "host", "url", "method" ], "start_line": 1060, "end_line": 1071, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 21, "complexity": 6, "token_count": 140, "parameters": [ "self", "record" ], "start_line": 1073, "end_line": 1096, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , host , url )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "host", "url" ], "start_line": 1117, "end_line": 1123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 30, "complexity": 7, "token_count": 210, "parameters": [ "self", "record" ], "start_line": 1125, "end_line": 1160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , alogger )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "alogger" ], "start_line": 1172, "end_line": 1176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "append", "long_name": "append( self , alogger )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 24, "parameters": [ "self", "alogger" ], "start_line": 1178, "end_line": 1183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "setLoggerClass", "long_name": "setLoggerClass( klass )", "filename": "logging.py", "nloc": 9, "complexity": 4, "token_count": 49, "parameters": [ "klass" ], "start_line": 1190, "end_line": 1203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , root )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 29, "parameters": [ "self", "root" ], "start_line": 1210, "end_line": 1217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "getLogger", "long_name": "getLogger( self , name )", "filename": "logging.py", "nloc": 17, "complexity": 3, "token_count": 102, "parameters": [ "self", "name" ], "start_line": 1219, "end_line": 1242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "_fixupParents", "long_name": "_fixupParents( self , alogger )", "filename": "logging.py", "nloc": 19, "complexity": 6, "token_count": 131, "parameters": [ "self", "alogger" ], "start_line": 1244, "end_line": 1266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "_fixupChildren", "long_name": "_fixupChildren( self , ph , alogger )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 48, "parameters": [ "self", "ph", "alogger" ], "start_line": 1268, "end_line": 1276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , level = 0 )", "filename": "logging.py", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [ "self", "name", "level" ], "start_line": 1286, "end_line": 1295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "setLevel", "long_name": "setLevel( self , lvl )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "lvl" ], "start_line": 1297, "end_line": 1301, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "debug", "long_name": "debug( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 49, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1309, "end_line": 1319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "info", "long_name": "info( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 49, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1321, "end_line": 1331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "warn", "long_name": "warn( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 48, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1333, "end_line": 1343, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "error", "long_name": "error( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 48, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1345, "end_line": 1355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "exception", "long_name": "exception( self , msg , * args )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 30, "parameters": [ "self", "msg", "args" ], "start_line": 1357, "end_line": 1361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "critical", "long_name": "critical( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 49, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1363, "end_line": 1373, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "log", "long_name": "log( self , lvl , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 50, "parameters": [ "self", "lvl", "msg", "args", "kwargs" ], "start_line": 1377, "end_line": 1386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "findCaller", "long_name": "findCaller( self )", "filename": "logging.py", "nloc": 6, "complexity": 3, "token_count": 48, "parameters": [ "self" ], "start_line": 1388, "end_line": 1397, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "makeRecord", "long_name": "makeRecord( self , name , lvl , fn , lno , msg , args , exc_info )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 37, "parameters": [ "self", "name", "lvl", "fn", "lno", "msg", "args", "exc_info" ], "start_line": 1399, "end_line": 1404, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "_log", "long_name": "_log( self , lvl , msg , args , exc_info = None )", "filename": "logging.py", "nloc": 9, "complexity": 3, "token_count": 75, "parameters": [ "self", "lvl", "msg", "args", "exc_info" ], "start_line": 1406, "end_line": 1418, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "handle", "long_name": "handle( self , record )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 22, "parameters": [ "self", "record" ], "start_line": 1420, "end_line": 1427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "addHandler", "long_name": "addHandler( self , hdlr )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 26, "parameters": [ "self", "hdlr" ], "start_line": 1429, "end_line": 1434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "removeHandler", "long_name": "removeHandler( self , hdlr )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 23, "parameters": [ "self", "hdlr" ], "start_line": 1436, "end_line": 1441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "callHandlers", "long_name": "callHandlers( self , record )", "filename": "logging.py", "nloc": 15, "complexity": 7, "token_count": 87, "parameters": [ "self", "record" ], "start_line": 1443, "end_line": 1464, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "getEffectiveLevel", "long_name": "getEffectiveLevel( self )", "filename": "logging.py", "nloc": 6, "complexity": 3, "token_count": 26, "parameters": [ "self" ], "start_line": 1466, "end_line": 1475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "isEnabledFor", "long_name": "isEnabledFor( self , lvl )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 27, "parameters": [ "self", "lvl" ], "start_line": 1478, "end_line": 1484, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , lvl )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "lvl" ], "start_line": 1492, "end_line": 1496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "basicConfig", "long_name": "basicConfig( )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [], "start_line": 1510, "end_line": 1519, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "fileConfig", "long_name": "fileConfig( fname )", "filename": "logging.py", "nloc": 64, "complexity": 10, "token_count": 457, "parameters": [ "fname" ], "start_line": 1576, "end_line": 1648, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "getLogger", "long_name": "getLogger( name )", "filename": "logging.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "name" ], "start_line": 1656, "end_line": 1664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "getRootLogger", "long_name": "getRootLogger( )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [], "start_line": 1666, "end_line": 1670, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "critical", "long_name": "critical( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1672, "end_line": 1678, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "error", "long_name": "error( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1682, "end_line": 1688, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "exception", "long_name": "exception( msg , * args )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "msg", "args" ], "start_line": 1690, "end_line": 1695, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "warn", "long_name": "warn( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1697, "end_line": 1703, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "info", "long_name": "info( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1705, "end_line": 1711, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "debug", "long_name": "debug( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1713, "end_line": 1719, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( level )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "level" ], "start_line": 1721, "end_line": 1725, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "shutdown", "long_name": "shutdown( )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 24, "parameters": [], "start_line": 1727, "end_line": 1734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "methods_before": [], "changed_methods": [ { "name": "flush", "long_name": "flush( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 427, "end_line": 432, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "getEffectiveLevel", "long_name": "getEffectiveLevel( self )", "filename": "logging.py", "nloc": 6, "complexity": 3, "token_count": 26, "parameters": [ "self" ], "start_line": 1466, "end_line": 1475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "close", "long_name": "close( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 434, "end_line": 439, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "handle", "long_name": "handle( self , record )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 22, "parameters": [ "self", "record" ], "start_line": 413, "end_line": 419, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , address = ( 'localhost' , SYSLOG_UDP_PORT )", "filename": "logging.py", "nloc": 16, "complexity": 2, "token_count": 101, "parameters": [ "self", "address", "SYSLOG_UDP_PORT" ], "start_line": 769, "end_line": 786, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "error", "long_name": "error( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1682, "end_line": 1688, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "formatFooter", "long_name": "formatFooter( self , records )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "records" ], "start_line": 295, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "addFilter", "long_name": "addFilter( self , filter )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 26, "parameters": [ "self", "filter" ], "start_line": 337, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "error", "long_name": "error( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 48, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1345, "end_line": 1355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "findCaller", "long_name": "findCaller( self )", "filename": "logging.py", "nloc": 6, "complexity": 3, "token_count": 48, "parameters": [ "self" ], "start_line": 1388, "end_line": 1397, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , host , port )", "filename": "logging.py", "nloc": 6, "complexity": 1, "token_count": 36, "parameters": [ "self", "host", "port" ], "start_line": 565, "end_line": 573, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "setTarget", "long_name": "setTarget( self , target )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "target" ], "start_line": 946, "end_line": 950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "encodePriority", "long_name": "encodePriority( self , facility , priority )", "filename": "logging.py", "nloc": 6, "complexity": 3, "token_count": 55, "parameters": [ "self", "facility", "priority" ], "start_line": 794, "end_line": 805, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "setRollover", "long_name": "setRollover( self , max_size , backup_count )", "filename": "logging.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "self", "max_size", "backup_count" ], "start_line": 511, "end_line": 526, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "setLoggerClass", "long_name": "setLoggerClass( klass )", "filename": "logging.py", "nloc": 9, "complexity": 4, "token_count": 49, "parameters": [ "klass" ], "start_line": 1190, "end_line": 1203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , linefmt = None )", "filename": "logging.py", "nloc": 5, "complexity": 2, "token_count": 25, "parameters": [ "self", "linefmt" ], "start_line": 279, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , filename , mode = \"a+\" )", "filename": "logging.py", "nloc": 7, "complexity": 1, "token_count": 50, "parameters": [ "self", "filename", "mode" ], "start_line": 498, "end_line": 509, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , capacity , flushLevel = ERROR , target = None )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "self", "capacity", "flushLevel", "target" ], "start_line": 928, "end_line": 937, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "doRollover", "long_name": "doRollover( self )", "filename": "logging.py", "nloc": 9, "complexity": 2, "token_count": 66, "parameters": [ "self" ], "start_line": 528, "end_line": 539, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "_fixupChildren", "long_name": "_fixupChildren( self , ph , alogger )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 48, "parameters": [ "self", "ph", "alogger" ], "start_line": 1268, "end_line": 1276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "makeRecord", "long_name": "makeRecord( self , name , lvl , fn , lno , msg , args , exc_info )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 37, "parameters": [ "self", "name", "lvl", "fn", "lno", "msg", "args", "exc_info" ], "start_line": 1399, "end_line": 1404, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "handleError", "long_name": "handleError( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 441, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "shutdown", "long_name": "shutdown( )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 24, "parameters": [], "start_line": 1727, "end_line": 1734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , strm = None )", "filename": "logging.py", "nloc": 6, "complexity": 2, "token_count": 35, "parameters": [ "self", "strm" ], "start_line": 463, "end_line": 471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "setLevel", "long_name": "setLevel( self , lvl )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "lvl" ], "start_line": 387, "end_line": 391, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , level = 0 )", "filename": "logging.py", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [ "self", "name", "level" ], "start_line": 1286, "end_line": 1295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "disable", "long_name": "disable( level )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "level" ], "start_line": 1721, "end_line": 1725, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "makePickle", "long_name": "makePickle( self , record )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 48, "parameters": [ "self", "record" ], "start_line": 596, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , appname , dllname = None , logtype = \"Application\" )", "filename": "logging.py", "nloc": 26, "complexity": 3, "token_count": 163, "parameters": [ "self", "appname", "dllname", "logtype" ], "start_line": 973, "end_line": 998, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self", "record" ], "start_line": 404, "end_line": 411, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "exception", "long_name": "exception( self , msg , * args )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 30, "parameters": [ "self", "msg", "args" ], "start_line": 1357, "end_line": 1361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "record" ], "start_line": 323, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "log", "long_name": "log( self , lvl , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 50, "parameters": [ "self", "lvl", "msg", "args", "kwargs" ], "start_line": 1377, "end_line": 1386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "getLogger", "long_name": "getLogger( self , name )", "filename": "logging.py", "nloc": 17, "complexity": 3, "token_count": 102, "parameters": [ "self", "name" ], "start_line": 1219, "end_line": 1242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "_fixupParents", "long_name": "_fixupParents( self , alogger )", "filename": "logging.py", "nloc": 19, "complexity": 6, "token_count": 131, "parameters": [ "self", "alogger" ], "start_line": 1244, "end_line": 1266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , alogger )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "alogger" ], "start_line": 1172, "end_line": 1176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , mailhost , fromaddr , toaddrs , subject )", "filename": "logging.py", "nloc": 12, "complexity": 2, "token_count": 72, "parameters": [ "self", "mailhost", "fromaddr", "toaddrs", "subject" ], "start_line": 839, "end_line": 855, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "isEnabledFor", "long_name": "isEnabledFor( self , lvl )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 27, "parameters": [ "self", "lvl" ], "start_line": 1478, "end_line": 1484, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "append", "long_name": "append( self , alogger )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 24, "parameters": [ "self", "alogger" ], "start_line": 1178, "end_line": 1183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "format", "long_name": "format( self , records )", "filename": "logging.py", "nloc": 8, "complexity": 3, "token_count": 58, "parameters": [ "self", "records" ], "start_line": 301, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "critical", "long_name": "critical( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1672, "end_line": 1678, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "addHandler", "long_name": "addHandler( self , hdlr )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 26, "parameters": [ "self", "hdlr" ], "start_line": 1429, "end_line": 1434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "getSubject", "long_name": "getSubject( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "record" ], "start_line": 857, "end_line": 862, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "send", "long_name": "send( self , s )", "filename": "logging.py", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "s" ], "start_line": 584, "end_line": 594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "getLevelName", "long_name": "getLevelName( lvl )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "lvl" ], "start_line": 105, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , host , url , method = \"GET\" )", "filename": "logging.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [ "self", "host", "url", "method" ], "start_line": 1060, "end_line": 1071, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "shouldFlush", "long_name": "shouldFlush( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "self", "record" ], "start_line": 899, "end_line": 904, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "format", "long_name": "format( self , record )", "filename": "logging.py", "nloc": 10, "complexity": 4, "token_count": 85, "parameters": [ "self", "record" ], "start_line": 249, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "getRootLogger", "long_name": "getRootLogger( )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [], "start_line": 1666, "end_line": 1670, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "warn", "long_name": "warn( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 48, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1333, "end_line": 1343, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "debug", "long_name": "debug( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 49, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1309, "end_line": 1319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "setFormatter", "long_name": "setFormatter( self , fmt )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "fmt" ], "start_line": 421, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_log", "long_name": "_log( self , lvl , msg , args , exc_info = None )", "filename": "logging.py", "nloc": 9, "complexity": 3, "token_count": 75, "parameters": [ "self", "lvl", "msg", "args", "exc_info" ], "start_line": 1406, "end_line": 1418, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "addLevelName", "long_name": "addLevelName( lvl , levelName )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "lvl", "levelName" ], "start_line": 115, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "logging.py", "nloc": 3, "complexity": 1, "token_count": 29, "parameters": [ "self" ], "start_line": 161, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "formatTime", "long_name": "formatTime( self , record , datefmt = None )", "filename": "logging.py", "nloc": 8, "complexity": 2, "token_count": 68, "parameters": [ "self", "record", "datefmt" ], "start_line": 219, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "debug", "long_name": "debug( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1713, "end_line": 1719, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , lvl , pathname , lineno , msg , args , exc_info )", "filename": "logging.py", "nloc": 21, "complexity": 3, "token_count": 142, "parameters": [ "self", "name", "lvl", "pathname", "lineno", "msg", "args", "exc_info" ], "start_line": 136, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "info", "long_name": "info( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 49, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1321, "end_line": 1331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fmt = None , datefmt = None )", "filename": "logging.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "fmt", "datefmt" ], "start_line": 207, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "getEventCategory", "long_name": "getEventCategory( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "record" ], "start_line": 1010, "end_line": 1015, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , capacity )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self", "capacity" ], "start_line": 891, "end_line": 897, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "warn", "long_name": "warn( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1697, "end_line": 1703, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "getMessageID", "long_name": "getMessageID( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "record" ], "start_line": 1000, "end_line": 1008, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , lvl )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "lvl" ], "start_line": 1492, "end_line": 1496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "makeSocket", "long_name": "makeSocket( self )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 575, "end_line": 582, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "removeFilter", "long_name": "removeFilter( self , filter )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 23, "parameters": [ "self", "filter" ], "start_line": 344, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "critical", "long_name": "critical( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 49, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1363, "end_line": 1373, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "formatHeader", "long_name": "formatHeader( self , records )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "records" ], "start_line": 289, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , host , url )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "host", "url" ], "start_line": 1117, "end_line": 1123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , root )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 29, "parameters": [ "self", "root" ], "start_line": 1210, "end_line": 1217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , level = 0 )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "self", "level" ], "start_line": 377, "end_line": 385, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "exception", "long_name": "exception( msg , * args )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "msg", "args" ], "start_line": 1690, "end_line": 1695, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "callHandlers", "long_name": "callHandlers( self , record )", "filename": "logging.py", "nloc": 15, "complexity": 7, "token_count": 87, "parameters": [ "self", "record" ], "start_line": 1443, "end_line": 1464, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "sendto", "long_name": "sendto( self , s , addr )", "filename": "logging.py", "nloc": 7, "complexity": 2, "token_count": 50, "parameters": [ "self", "s", "addr" ], "start_line": 656, "end_line": 666, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "info", "long_name": "info( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1705, "end_line": 1711, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "fileConfig", "long_name": "fileConfig( fname )", "filename": "logging.py", "nloc": 64, "complexity": 10, "token_count": 457, "parameters": [ "fname" ], "start_line": 1576, "end_line": 1648, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "getEventType", "long_name": "getEventType( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "record" ], "start_line": 1017, "end_line": 1027, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 334, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "basicConfig", "long_name": "basicConfig( )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [], "start_line": 1510, "end_line": 1519, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "formatException", "long_name": "formatException( self , ei )", "filename": "logging.py", "nloc": 7, "complexity": 1, "token_count": 54, "parameters": [ "self", "ei" ], "start_line": 237, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "getLogger", "long_name": "getLogger( name )", "filename": "logging.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "name" ], "start_line": 1656, "end_line": 1664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "removeHandler", "long_name": "removeHandler( self , hdlr )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 23, "parameters": [ "self", "hdlr" ], "start_line": 1436, "end_line": 1441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "nloc": 983, "complexity": 225, "token_count": 5486, "diff_parsed": { "added": [ "#! /usr/bin/env python", "#", "# Copyright 2001-2002 by Vinay Sajip. All Rights Reserved.", "#", "# Permission to use, copy, modify, and distribute this software and its", "# documentation for any purpose and without fee is hereby granted,", "# provided that the above copyright notice appear in all copies and that", "# both that copyright notice and this permission notice appear in", "# supporting documentation, and that the name of Vinay Sajip", "# not be used in advertising or publicity pertaining to distribution", "# of the software without specific, written prior permission.", "# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING", "# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL", "# VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR", "# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER", "# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT", "# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.", "#", "# For the change history, see README.txt in the distribution.", "#", "# This file is part of the Python logging distribution. See", "# http://www.red-dove.com/python_logging.html", "#", "", "\"\"\"", "Logging module for Python. Based on PEP 282 and comments thereto in", "comp.lang.python, and influenced by Apache's log4j system.", "", "Should work under Python versions >= 1.5.2, except that source line", "information is not available unless 'inspect' is.", "", "Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.", "", "To use, simply 'import logging' and log away!", "\"\"\"", "", "import sys, os, types, time, string, socket, cPickle, cStringIO", "", "try:", " import thread", "except ImportError:", " thread = None", "try:", " import inspect", "except ImportError:", " inspect = None", "", "__author__ = \"Vinay Sajip \"", "__status__ = \"alpha\"", "__version__ = \"0.4.1\"", "__date__ = \"03 April 2002\"", "", "#---------------------------------------------------------------------------", "# Module data", "#---------------------------------------------------------------------------", "", "#", "#_srcfile is used when walking the stack to check when we've got the first", "# caller stack frame.", "#If run as a script, __file__ is not bound.", "#", "if __name__ == \"__main__\":", " _srcFile = None", "else:", " _srcfile = os.path.splitext(__file__)", " if _srcfile[1] in [\".pyc\", \".pyo\"]:", " _srcfile = _srcfile[0] + \".py\"", " else:", " _srcfile = __file__", "", "#", "#_start_time is used as the base when calculating the relative time of events", "#", "_start_time = time.time()", "", "DEFAULT_TCP_LOGGING_PORT = 9020", "DEFAULT_UDP_LOGGING_PORT = 9021", "DEFAULT_HTTP_LOGGING_PORT = 9022", "SYSLOG_UDP_PORT = 514", "", "#", "# Default levels and level names, these can be replaced with any positive set", "# of values having corresponding names. There is a pseudo-level, ALL, which", "# is only really there as a lower limit for user-defined levels. Handlers and", "# loggers are initialized with ALL so that they will log all messages, even", "# at user-defined levels.", "#", "CRITICAL = 50", "FATAL = CRITICAL", "ERROR = 40", "WARN = 30", "INFO = 20", "DEBUG = 10", "ALL = 0", "", "_levelNames = {", " CRITICAL : 'CRITICAL',", " ERROR : 'ERROR',", " WARN : 'WARN',", " INFO : 'INFO',", " DEBUG : 'DEBUG',", " ALL : 'ALL',", "}", "", "def getLevelName(lvl):", " \"\"\"", " Return the textual representation of logging level 'lvl'. If the level is", " one of the predefined levels (CRITICAL, ERROR, WARN, INFO, DEBUG) then you", " get the corresponding string. If you have associated levels with names", " using addLevelName then the name you have associated with 'lvl' is", " returned. Otherwise, the string \"Level %s\" % lvl is returned.", " \"\"\"", " return _levelNames.get(lvl, (\"Level %s\" % lvl))", "", "def addLevelName(lvl, levelName):", " \"\"\"", " Associate 'levelName' with 'lvl'. This is used when converting levels", " to text during message formatting.", " \"\"\"", " _levelNames[lvl] = levelName", "", "#---------------------------------------------------------------------------", "# The logging record", "#---------------------------------------------------------------------------", "", "class LogRecord:", " \"\"\"", " LogRecord instances are created every time something is logged. They", " contain all the information pertinent to the event being logged. The", " main information passed in is in msg and args, which are combined", " using msg % args to create the message field of the record. The record", " also includes information such as when the record was created, the", " source line where the logging call was made, and any exception", " information to be logged.", " \"\"\"", " def __init__(self, name, lvl, pathname, lineno, msg, args, exc_info):", " \"\"\"", " Initialize a logging record with interesting information.", " \"\"\"", " ct = time.time()", " self.name = name", " self.msg = msg", " self.args = args", " self.level = getLevelName(lvl)", " self.lvl = lvl", " self.pathname = pathname", " try:", " self.filename = os.path.basename(pathname)", " except:", " self.filename = pathname", " self.exc_info = exc_info", " self.lineno = lineno", " self.created = ct", " self.msecs = (ct - long(ct)) * 1000", " self.relativeCreated = (self.created - _start_time) * 1000", " if thread:", " self.thread = thread.get_ident()", " else:", " self.thread = None", "", " def __str__(self):", " return ''%(self.name, self.lvl,", " self.pathname, self.lineno, self.msg)", "", "#---------------------------------------------------------------------------", "# Formatter classes and functions", "#---------------------------------------------------------------------------", "", "class Formatter:", " \"\"\"", " Formatters need to know how a LogRecord is constructed. They are", " responsible for converting a LogRecord to (usually) a string which can", " be interpreted by either a human or an external system. The base Formatter", " allows a formatting string to be specified. If none is supplied, the", " default value of \"%s(message)\\\\n\" is used.", "", " The Formatter can be initialized with a format string which makes use of", " knowledge of the LogRecord attributes - e.g. the default value mentioned", " above makes use of the fact that the user's message and arguments are pre-", " formatted into a LogRecord's message attribute. Currently, the useful", " attributes in a LogRecord are described by:", "", " %(name)s Name of the logger (logging channel)", " %(lvl)s Numeric logging level for the message (DEBUG, INFO,", " WARN, ERROR, CRITICAL)", " %(level)s Text logging level for the message (\"DEBUG\", \"INFO\",", " \"WARN\", \"ERROR\", \"CRITICAL\")", " %(pathname)s Full pathname of the source file where the logging", " call was issued (if available)", " %(filename)s Filename portion of pathname", " %(lineno)d Source line number where the logging call was issued", " (if available)", " %(created)f Time when the LogRecord was created (time.time()", " return value)", " %(asctime)s textual time when the LogRecord was created", " %(msecs)d Millisecond portion of the creation time", " %(relativeCreated)d Time in milliseconds when the LogRecord was created,", " relative to the time the logging module was loaded", " (typically at application startup time)", " %(thread)d Thread ID (if available)", " %(message)s The result of msg % args, computed just as the", " record is emitted", " %(msg)s The raw formatting string provided by the user", " %(args)r The argument tuple which goes with the formatting", " string in the msg attribute", " \"\"\"", " def __init__(self, fmt=None, datefmt=None):", " \"\"\"", " Initialize the formatter either with the specified format string, or a", " default as described above. Allow for specialized date formatting with", " the optional datefmt argument (if omitted, you get the ISO8601 format).", " \"\"\"", " if fmt:", " self._fmt = fmt", " else:", " self._fmt = \"%(message)s\"", " self.datefmt = datefmt", "", " def formatTime(self, record, datefmt=None):", " \"\"\"", " This method should be called from format() by a formatter which", " wants to make use of a formatted time. This method can be overridden", " in formatters to provide for any specific requirement, but the", " basic behaviour is as follows: if datefmt (a string) is specfied,", " it is used with time.strftime to format the creation time of the", " record. Otherwise, the ISO8601 format is used. The resulting", " string is written to the asctime attribute of the record.", " \"\"\"", " ct = record.created", " if datefmt:", " s = time.strftime(datefmt, time.localtime(ct))", " else:", " t = time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime(ct))", " s = \"%s,%03d\" % (t, record.msecs)", " record.asctime = s", "", " def formatException(self, ei):", " \"\"\"", " Format the specified exception information as a string. This", " default implementation just uses traceback.print_exception()", " \"\"\"", " import traceback", " sio = cStringIO.StringIO()", " traceback.print_exception(ei[0], ei[1], ei[2], None, sio)", " s = sio.getvalue()", " sio.close()", " return s", "", " def format(self, record):", " \"\"\"", " The record's attribute dictionary is used as the operand to a", " string formatting operation which yields the returned string.", " Before formatting the dictionary, a couple of preparatory steps", " are carried out. The message attribute of the record is computed", " using msg % args. If the formatting string contains \"(asctime)\",", " formatTime() is called to format the event time. If there is", " exception information, it is formatted using formatException()", " and appended to the message.", " \"\"\"", " record.message = record.msg % record.args", " if string.find(self._fmt,\"(asctime)\") > 0:", " self.formatTime(record, self.datefmt)", " s = self._fmt % record.__dict__", " if record.exc_info:", " if s[-1] != \"\\n\":", " s = s + \"\\n\"", " s = s + self.formatException(record.exc_info)", " return s", "", "#", "# The default formatter to use when no other is specified", "#", "_defaultFormatter = Formatter()", "", "class BufferingFormatter:", " \"\"\"", " A formatter suitable for formatting a number of records.", " \"\"\"", " def __init__(self, linefmt=None):", " \"\"\"", " Optionally specify a formatter which will be used to format each", " individual record.", " \"\"\"", " if linefmt:", " self.linefmt = linefmt", " else:", " self.linefmt = _defaultFormatter", "", " def formatHeader(self, records):", " \"\"\"", " Return the header string for the specified records.", " \"\"\"", " return \"\"", "", " def formatFooter(self, records):", " \"\"\"", " Return the footer string for the specified records.", " \"\"\"", " return \"\"", "", " def format(self, records):", " \"\"\"", " Format the specified records and return the result as a string.", " \"\"\"", " rv = \"\"", " if len(records) > 0:", " rv = rv + self.formatHeader(records)", " for record in records:", " rv = rv + self.linefmt.format(record)", " rv = rv + self.formatFooter(records)", " return rv", "", "#---------------------------------------------------------------------------", "# Filter classes and functions", "#---------------------------------------------------------------------------", "", "class Filter:", " \"\"\"", " The base filter class. This class never filters anything, acting as", " a placeholder which defines the Filter interface. Loggers and Handlers", " can optionally use Filter instances to filter records as desired.", " \"\"\"", " def filter(self, record):", " \"\"\"", " Is the specified record to be logged? Returns a boolean value.", " \"\"\"", " return 1", "", "class Filterer:", " \"\"\"", " A base class for loggers and handlers which allows them to share", " common code.", " \"\"\"", " def __init__(self):", " self.filters = []", "", " def addFilter(self, filter):", " \"\"\"", " Add the specified filter to this handler.", " \"\"\"", " if not (filter in self.filters):", " self.filters.append(filter)", "", " def removeFilter(self, filter):", " \"\"\"", " Remove the specified filter from this handler.", " \"\"\"", " if filter in self.filters:", " self.filters.remove(filter)", "", " def filter(self, record):", " \"\"\"", " Determine if a record is loggable by consulting all the filters. The", " default is to allow the record to be logged; any filter can veto this", " and the record is then dropped. Returns a boolean value.", " \"\"\"", " rv = 1", " for f in self.filters:", " if not f.filter(record):", " rv = 0", " break", " return rv", "", "#---------------------------------------------------------------------------", "# Handler classes and functions", "#---------------------------------------------------------------------------", "", "_handlers = {} #repository of handlers (for flushing when shutdown called)", "", "class Handler(Filterer):", " \"\"\"", " The base handler class. Acts as a placeholder which defines the Handler", " interface. Handlers can optionally use Formatter instances to format", " records as desired. By default, no formatter is specified; in this case,", " the 'raw' message as determined by record.message is logged.", " \"\"\"", " def __init__(self, level=0):", " \"\"\"", " Initializes the instance - basically setting the formatter to None", " and the filter list to empty.", " \"\"\"", " Filterer.__init__(self)", " self.level = level", " self.formatter = None", " _handlers[self] = 1", "", " def setLevel(self, lvl):", " \"\"\"", " Set the logging level of this handler.", " \"\"\"", " self.level = lvl", "", " def format(self, record):", " \"\"\"", " Do formatting for a record - if a formatter is set, use it.", " Otherwise, use the default formatter for the module.", " \"\"\"", " if self.formatter:", " fmt = self.formatter", " else:", " fmt = _defaultFormatter", " return fmt.format(record)", "", " def emit(self, record):", " \"\"\"", " Do whatever it takes to actually log the specified logging record.", " This version is intended to be implemented by subclasses and so", " raises a NotImplementedError.", " \"\"\"", " raise NotImplementedError, 'emit must be implemented '\\", " 'by Handler subclasses'", "", " def handle(self, record):", " \"\"\"", " Conditionally handle the specified logging record, depending on", " filters which may have been added to the handler.", " \"\"\"", " if self.filter(record):", " self.emit(record)", "", " def setFormatter(self, fmt):", " \"\"\"", " Set the formatter for this handler.", " \"\"\"", " self.formatter = fmt", "", " def flush(self):", " \"\"\"", " Ensure all logging output has been flushed. This version does", " nothing and is intended to be implemented by subclasses.", " \"\"\"", " pass", "", " def close(self):", " \"\"\"", " Tidy up any resources used by the handler. This version does", " nothing and is intended to be implemented by subclasses.", " \"\"\"", " pass", "", " def handleError(self):", " \"\"\"", " This method should be called from handlers when an exception is", " encountered during an emit() call. By default it does nothing,", " which means that exceptions get silently ignored. This is what is", " mostly wanted for a logging system - most users will not care", " about errors in the logging system, they are more interested in", " application errors. You could, however, replace this with a custom", " handler if you wish.", " \"\"\"", " #import traceback", " #ei = sys.exc_info()", " #traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr)", " #del ei", " pass", "", "class StreamHandler(Handler):", " \"\"\"", " A handler class which writes logging records, appropriately formatted,", " to a stream. Note that this class does not close the stream, as", " sys.stdout or sys.stderr may be used.", " \"\"\"", " def __init__(self, strm=None):", " \"\"\"", " If strm is not specified, sys.stderr is used.", " \"\"\"", " Handler.__init__(self)", " if not strm:", " strm = sys.stderr", " self.stream = strm", " self.formatter = None", "", " def flush(self):", " \"\"\"", " Flushes the stream.", " \"\"\"", " self.stream.flush()", "", " def emit(self, record):", " \"\"\"", " If a formatter is specified, it is used to format the record.", " The record is then written to the stream with a trailing newline", " [N.B. this may be removed depending on feedback]. If exception", " information is present, it is formatted using", " traceback.print_exception and appended to the stream.", " \"\"\"", " try:", " msg = self.format(record)", " self.stream.write(\"%s\\n\" % msg)", " self.flush()", " except:", " self.handleError()", "", "class FileHandler(StreamHandler):", " \"\"\"", " A handler class which writes formatted logging records to disk files.", " \"\"\"", " def __init__(self, filename, mode=\"a+\"):", " \"\"\"", " Open the specified file and use it as the stream for logging.", " By default, the file grows indefinitely. You can call setRollover()", " to allow the file to rollover at a predetermined size.", " \"\"\"", " StreamHandler.__init__(self, open(filename, mode))", " self.max_size = 0", " self.backup_count = 0", " self.basefilename = filename", " self.backup_index = 0", " self.mode = mode", "", " def setRollover(self, max_size, backup_count):", " \"\"\"", " Set the rollover parameters so that rollover occurs whenever the", " current log file is nearly max_size in length. If backup_count", " is >= 1, the system will successively create new files with the", " same pathname as the base file, but with extensions \".1\", \".2\"", " etc. appended to it. For example, with a backup_count of 5 and a", " base file name of \"app.log\", you would get \"app.log\", \"app.log.1\",", " \"app.log.2\", ... through to \"app.log.5\". When the last file reaches", " its size limit, the logging reverts to \"app.log\" which is truncated", " to zero length. If max_size is zero, rollover never occurs.", " \"\"\"", " self.max_size = max_size", " self.backup_count = backup_count", " if max_size > 0:", " self.mode = \"a+\"", "", " def doRollover(self):", " \"\"\"", " Do a rollover, as described in setRollover().", " \"\"\"", " if self.backup_index >= self.backup_count:", " self.backup_index = 0", " fn = self.basefilename", " else:", " self.backup_index = self.backup_index + 1", " fn = \"%s.%d\" % (self.basefilename, self.backup_index)", " self.stream.close()", " self.stream = open(fn, \"w+\")", "", " def emit(self, record):", " \"\"\"", " Output the record to the file, catering for rollover as described", " in setRollover().", " \"\"\"", " if self.max_size > 0: # are we rolling over?", " msg = \"%s\\n\" % self.format(record)", " if self.stream.tell() + len(msg) >= self.max_size:", " self.doRollover()", " StreamHandler.emit(self, record)", "", " def close(self):", " \"\"\"", " Closes the stream.", " \"\"\"", " self.stream.close()", "", "class SocketHandler(StreamHandler):", " \"\"\"", " A handler class which writes logging records, in pickle format, to", " a streaming socket. The socket is kept open across logging calls.", " If the peer resets it, an attempt is made to reconnect on the next call.", " \"\"\"", "", " def __init__(self, host, port):", " \"\"\"", " Initializes the handler with a specific host address and port.", " \"\"\"", " StreamHandler.__init__(self)", " self.host = host", " self.port = port", " self.sock = None", " self.closeOnError = 1", "", " def makeSocket(self):", " \"\"\"", " A factory method which allows subclasses to define the precise", " type of socket they want.", " \"\"\"", " s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)", " s.connect((self.host, self.port))", " return s", "", " def send(self, s):", " \"\"\"", " Send a pickled string to the socket. This function allows for", " partial sends which can happen when the network is busy.", " \"\"\"", " sentsofar = 0", " left = len(s)", " while left > 0:", " sent = self.sock.send(s[sentsofar:])", " sentsofar = sentsofar + sent", " left = left - sent", "", " def makePickle(self, record):", " \"\"\"", " Pickle the record in binary format with a length prefix.", " \"\"\"", " s = cPickle.dumps(record.__dict__, 1)", " n = len(s)", " slen = \"%c%c\" % ((n >> 8) & 0xFF, n & 0xFF)", " return slen + s", "", " def handleError(self):", " \"\"\"", " An error has occurred during logging. Most likely cause -", " connection lost. Close the socket so that we can retry on the", " next event.", " \"\"\"", " if self.closeOnError and self.sock:", " self.sock.close()", " self.sock = None #try to reconnect next time", "", " def emit(self, record):", " \"\"\"", " Pickles the record and writes it to the socket in binary format.", " If there is an error with the socket, silently drop the packet.", " \"\"\"", " try:", " s = self.makePickle(record)", " if not self.sock:", " self.sock = self.makeSocket()", " self.send(s)", " except:", " self.handleError()", "", " def close(self):", " \"\"\"", " Closes the socket.", " \"\"\"", " if self.sock:", " self.sock.close()", " self.sock = None", "", "class DatagramHandler(SocketHandler):", " \"\"\"", " A handler class which writes logging records, in pickle format, to", " a datagram socket.", " \"\"\"", " def __init__(self, host, port):", " \"\"\"", " Initializes the handler with a specific host address and port.", " \"\"\"", " SocketHandler.__init__(self, host, port)", " self.closeOnError = 0", "", " def makeSocket(self):", " \"\"\"", " The factory method of SocketHandler is here overridden to create", " a UDP socket (SOCK_DGRAM).", " \"\"\"", " s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)", " return s", "", " def sendto(self, s, addr):", " \"\"\"", " Send a pickled string to a socket. This function allows for", " partial sends which can happen when the network is busy.", " \"\"\"", " sentsofar = 0", " left = len(s)", " while left > 0:", " sent = self.sock.sendto(s[sentsofar:], addr)", " sentsofar = sentsofar + sent", " left = left - sent", "", " def emit(self, record):", " \"\"\"", " Pickles the record and writes it to the socket in binary format.", " \"\"\"", " try:", " s = self.makePickle(record)", " if not self.sock:", " self.sock = self.makeSocket()", " self.sendto(s, (self.host, self.port))", " except:", " self.handleError()", "", "class SysLogHandler(Handler):", " \"\"\"", " A handler class which sends formatted logging records to a syslog", " server. Based on Sam Rushing's syslog module:", " http://www.nightmare.com/squirl/python-ext/misc/syslog.py", " Contributed by Nicolas Untz (after which minor refactoring changes", " have been made).", " \"\"\"", "", " # from :", " # ======================================================================", " # priorities/facilities are encoded into a single 32-bit quantity, where", " # the bottom 3 bits are the priority (0-7) and the top 28 bits are the", " # facility (0-big number). Both the priorities and the facilities map", " # roughly one-to-one to strings in the syslogd(8) source code. This", " # mapping is included in this file.", " #", " # priorities (these are ordered)", "", " LOG_EMERG = 0 # system is unusable", " LOG_ALERT = 1 # action must be taken immediately", " LOG_CRIT = 2 # critical conditions", " LOG_ERR = 3 # error conditions", " LOG_WARNING = 4 # warning conditions", " LOG_NOTICE = 5 # normal but significant condition", " LOG_INFO = 6 # informational", " LOG_DEBUG = 7 # debug-level messages", "", " # facility codes", " LOG_KERN = 0 # kernel messages", " LOG_USER = 1 # random user-level messages", " LOG_MAIL = 2 # mail system", " LOG_DAEMON = 3 # system daemons", " LOG_AUTH = 4 # security/authorization messages", " LOG_SYSLOG = 5 # messages generated internally by syslogd", " LOG_LPR = 6 # line printer subsystem", " LOG_NEWS = 7 # network news subsystem", " LOG_UUCP = 8 # UUCP subsystem", " LOG_CRON = 9 # clock daemon", " LOG_AUTHPRIV = 10 # security/authorization messages (private)", "", " # other codes through 15 reserved for system use", " LOG_LOCAL0 = 16 # reserved for local use", " LOG_LOCAL1 = 17 # reserved for local use", " LOG_LOCAL2 = 18 # reserved for local use", " LOG_LOCAL3 = 19 # reserved for local use", " LOG_LOCAL4 = 20 # reserved for local use", " LOG_LOCAL5 = 21 # reserved for local use", " LOG_LOCAL6 = 22 # reserved for local use", " LOG_LOCAL7 = 23 # reserved for local use", "", " priority_names = {", " \"alert\": LOG_ALERT,", " \"crit\": LOG_CRIT,", " \"critical\": LOG_CRIT,", " \"debug\": LOG_DEBUG,", " \"emerg\": LOG_EMERG,", " \"err\": LOG_ERR,", " \"error\": LOG_ERR, # DEPRECATED", " \"info\": LOG_INFO,", " \"notice\": LOG_NOTICE,", " \"panic\": LOG_EMERG, # DEPRECATED", " \"warn\": LOG_WARNING, # DEPRECATED", " \"warning\": LOG_WARNING,", " }", "", " facility_names = {", " \"auth\": LOG_AUTH,", " \"authpriv\": LOG_AUTHPRIV,", " \"cron\": LOG_CRON,", " \"daemon\": LOG_DAEMON,", " \"kern\": LOG_KERN,", " \"lpr\": LOG_LPR,", " \"mail\": LOG_MAIL,", " \"news\": LOG_NEWS,", " \"security\": LOG_AUTH, # DEPRECATED", " \"syslog\": LOG_SYSLOG,", " \"user\": LOG_USER,", " \"uucp\": LOG_UUCP,", " \"local0\": LOG_LOCAL0,", " \"local1\": LOG_LOCAL1,", " \"local2\": LOG_LOCAL2,", " \"local3\": LOG_LOCAL3,", " \"local4\": LOG_LOCAL4,", " \"local5\": LOG_LOCAL5,", " \"local6\": LOG_LOCAL6,", " \"local7\": LOG_LOCAL7,", " }", "", " def __init__(self, address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER):", " \"\"\"", " If address is not specified, UNIX socket is used.", " If facility is not specified, LOG_USER is used.", " \"\"\"", " Handler.__init__(self)", "", " self.address = address", " self.facility = facility", " if type(address) == types.StringType:", " self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)", " self.socket.connect(address)", " self.unixsocket = 1", " else:", " self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)", " self.unixsocket = 0", "", " self.formatter = None", "", " # curious: when talking to the unix-domain '/dev/log' socket, a", " # zero-terminator seems to be required. this string is placed", " # into a class variable so that it can be overridden if", " # necessary.", " log_format_string = '<%d>%s\\000'", "", " def encodePriority (self, facility, priority):", " \"\"\"", " Encode the facility and priority. You can pass in strings or", " integers - if strings are passed, the facility_names and", " priority_names mapping dictionaries are used to convert them to", " integers.", " \"\"\"", " if type(facility) == types.StringType:", " facility = self.facility_names[facility]", " if type(priority) == types.StringType:", " priority = self.priority_names[priority]", " return (facility << 3) | priority", "", " def close (self):", " \"\"\"", " Closes the socket.", " \"\"\"", " if self.unixsocket:", " self.socket.close()", "", " def emit(self, record):", " \"\"\"", " The record is formatted, and then sent to the syslog server. If", " exception information is present, it is NOT sent to the server.", " \"\"\"", " msg = self.format(record)", " \"\"\"", " We need to convert record level to lowercase, maybe this will", " change in the future.", " \"\"\"", " msg = self.log_format_string % (", " self.encodePriority(self.facility, string.lower(record.level)),", " msg)", " try:", " if self.unixsocket:", " self.socket.send(msg)", " else:", " self.socket.sendto(msg, self.address)", " except:", " self.handleError()", "", "class SMTPHandler(Handler):", " \"\"\"", " A handler class which sends an SMTP email for each logging event.", " \"\"\"", " def __init__(self, mailhost, fromaddr, toaddrs, subject):", " \"\"\"", " Initialize the instance with the from and to addresses and subject", " line of the email. To specify a non-standard SMTP port, use the", " (host, port) tuple format for the mailhost argument.", " \"\"\"", " Handler.__init__(self)", " if type(mailhost) == types.TupleType:", " host, port = mailhost", " self.mailhost = host", " self.mailport = port", " else:", " self.mailhost = mailhost", " self.mailport = None", " self.fromaddr = fromaddr", " self.toaddrs = toaddrs", " self.subject = subject", "", " def getSubject(self, record):", " \"\"\"", " If you want to specify a subject line which is record-dependent,", " override this method.", " \"\"\"", " return self.subject", "", " def emit(self, record):", " \"\"\"", " Format the record and send it to the specified addressees.", " \"\"\"", " try:", " import smtplib", " port = self.mailport", " if not port:", " port = smtplib.SMTP_PORT", " smtp = smtplib.SMTP(self.mailhost, port)", " msg = self.format(record)", " msg = \"From: %s\\r\\nTo: %s\\r\\nSubject: %s\\r\\n\\r\\n%s\" % (", " self.fromaddr,", " string.join(self.toaddrs, \",\"),", " self.getSubject(record), msg", " )", " smtp.sendmail(self.fromaddr, self.toaddrs, msg)", " smtp.quit()", " except:", " self.handleError()", "", "class BufferingHandler(Handler):", " \"\"\"", " A handler class which buffers logging records in memory. Whenever each", " record is added to the buffer, a check is made to see if the buffer should", " be flushed. If it should, then flush() is expected to do the needful.", " \"\"\"", " def __init__(self, capacity):", " \"\"\"", " Initialize the handler with the buffer size.", " \"\"\"", " Handler.__init__(self)", " self.capacity = capacity", " self.buffer = []", "", " def shouldFlush(self, record):", " \"\"\"", " Returns true if the buffer is up to capacity. This method can be", " overridden to implement custom flushing strategies.", " \"\"\"", " return (len(self.buffer) >= self.capacity)", "", " def emit(self, record):", " \"\"\"", " Append the record. If shouldFlush() tells us to, call flush() to process", " the buffer.", " \"\"\"", " self.buffer.append(record)", " if self.shouldFlush(record):", " self.flush()", "", " def flush(self):", " \"\"\"", " Override to implement custom flushing behaviour. This version just zaps", " the buffer to empty.", " \"\"\"", " self.buffer = []", "", "class MemoryHandler(BufferingHandler):", " \"\"\"", " A handler class which buffers logging records in memory, periodically", " flushing them to a target handler. Flushing occurs whenever the buffer", " is full, or when an event of a certain severity or greater is seen.", " \"\"\"", " def __init__(self, capacity, flushLevel=ERROR, target=None):", " \"\"\"", " Initialize the handler with the buffer size, the level at which", " flushing should occur and an optional target. Note that without a", " target being set either here or via setTarget(), a MemoryHandler", " is no use to anyone!", " \"\"\"", " BufferingHandler.__init__(self, capacity)", " self.flushLevel = flushLevel", " self.target = target", "", " def shouldFlush(self, record):", " \"\"\"", " Check for buffer full or a record at the flushLevel or higher.", " \"\"\"", " return (len(self.buffer) >= self.capacity) or \\", " (record.lvl >= self.flushLevel)", "", " def setTarget(self, target):", " \"\"\"", " Set the target handler for this handler.", " \"\"\"", " self.target = target", "", " def flush(self):", " \"\"\"", " For a MemoryHandler, flushing means just sending the buffered", " records to the target, if there is one. Override if you want", " different behaviour.", " \"\"\"", " if self.target:", " for record in self.buffer:", " self.target.handle(record)", " self.buffer = []", "", "class NTEventLogHandler(Handler):", " \"\"\"", " A handler class which sends events to the NT Event Log. Adds a", " registry entry for the specified application name. If no dllname is", " provided, win32service.pyd (which contains some basic message", " placeholders) is used. Note that use of these placeholders will make", " your event logs big, as the entire message source is held in the log.", " If you want slimmer logs, you have to pass in the name of your own DLL", " which contains the message definitions you want to use in the event log.", " \"\"\"", " def __init__(self, appname, dllname=None, logtype=\"Application\"):", " Handler.__init__(self)", " try:", " import win32evtlogutil, win32evtlog", " self.appname = appname", " self._welu = win32evtlogutil", " if not dllname:", " import os", " dllname = os.path.split(self._welu.__file__)", " dllname = os.path.split(dllname[0])", " dllname = os.path.join(dllname[0], r'win32service.pyd')", " self.dllname = dllname", " self.logtype = logtype", " self._welu.AddSourceToRegistry(appname, dllname, logtype)", " self.deftype = win32evtlog.EVENTLOG_ERROR_TYPE", " self.typemap = {", " DEBUG : win32evtlog.EVENTLOG_INFORMATION_TYPE,", " INFO : win32evtlog.EVENTLOG_INFORMATION_TYPE,", " WARN : win32evtlog.EVENTLOG_WARNING_TYPE,", " ERROR : win32evtlog.EVENTLOG_ERROR_TYPE,", " CRITICAL: win32evtlog.EVENTLOG_ERROR_TYPE,", " }", " except ImportError:", " print \"The Python Win32 extensions for NT (service, event \"\\", " \"logging) appear not to be available.\"", " self._welu = None", "", " def getMessageID(self, record):", " \"\"\"", " Return the message ID for the event record. If you are using your", " own messages, you could do this by having the msg passed to the", " logger being an ID rather than a formatting string. Then, in here,", " you could use a dictionary lookup to get the message ID. This", " version returns 1, which is the base message ID in win32service.pyd.", " \"\"\"", " return 1", "", " def getEventCategory(self, record):", " \"\"\"", " Return the event category for the record. Override this if you", " want to specify your own categories. This version returns 0.", " \"\"\"", " return 0", "", " def getEventType(self, record):", " \"\"\"", " Return the event type for the record. Override this if you want", " to specify your own types. This version does a mapping using the", " handler's typemap attribute, which is set up in __init__() to a", " dictionary which contains mappings for DEBUG, INFO, WARN, ERROR", " and CRITICAL. If you are using your own levels you will either need", " to override this method or place a suitable dictionary in the", " handler's typemap attribute.", " \"\"\"", " return self.typemap.get(record.lvl, self.deftype)", "", " def emit(self, record):", " \"\"\"", " Determine the message ID, event category and event type. Then", " log the message in the NT event log.", " \"\"\"", " if self._welu:", " try:", " id = self.getMessageID(record)", " cat = self.getEventCategory(record)", " type = self.getEventType(record)", " msg = self.format(record)", " self._welu.ReportEvent(self.appname, id, cat, type, [msg])", " except:", " self.handleError()", "", " def close(self):", " \"\"\"", " You can remove the application name from the registry as a", " source of event log entries. However, if you do this, you will", " not be able to see the events as you intended in the Event Log", " Viewer - it needs to be able to access the registry to get the", " DLL name.", " \"\"\"", " #self._welu.RemoveSourceFromRegistry(self.appname, self.logtype)", " pass", "", "class HTTPHandler(Handler):", " \"\"\"", " A class which sends records to a Web server, using either GET or", " POST semantics.", " \"\"\"", " def __init__(self, host, url, method=\"GET\"):", " \"\"\"", " Initialize the instance with the host, the request URL, and the method", " (\"GET\" or \"POST\")", " \"\"\"", " Handler.__init__(self)", " method = string.upper(method)", " if method not in [\"GET\", \"POST\"]:", " raise ValueError, \"method must be GET or POST\"", " self.host = host", " self.url = url", " self.method = method", "", " def emit(self, record):", " \"\"\"", " Send the record to the Web server as an URL-encoded dictionary", " \"\"\"", " try:", " import httplib, urllib", " h = httplib.HTTP(self.host)", " url = self.url", " data = urllib.urlencode(record.__dict__)", " if self.method == \"GET\":", " if (string.find(url, '?') >= 0):", " sep = '&'", " else:", " sep = '?'", " url = url + \"%c%s\" % (sep, data)", " h.putrequest(self.method, url)", " if self.method == \"POST\":", " h.putheader(\"Content-length\", str(len(data)))", " h.endheaders()", " if self.method == \"POST\":", " h.send(data)", " h.getreply() #can't do anything with the result", " except:", " self.handleError()", "", "SOAP_MESSAGE = \"\"\"", " ", " ", "%s", " ", " ", "", "\"\"\"", "", "class SOAPHandler(Handler):", " \"\"\"", " A class which sends records to a SOAP server.", " \"\"\"", " def __init__(self, host, url):", " \"\"\"", " Initialize the instance with the host and the request URL", " \"\"\"", " Handler.__init__(self)", " self.host = host", " self.url = url", "", " def emit(self, record):", " \"\"\"", " Send the record to the Web server as a SOAP message", " \"\"\"", " try:", " import httplib, urllib", " h = httplib.HTTP(self.host)", " h.putrequest(\"POST\", self.url)", " keys = record.__dict__.keys()", " keys.sort()", " args = \"\"", " for key in keys:", " v = record.__dict__[key]", " if type(v) == types.StringType:", " t = \"string\"", " elif (type(v) == types.IntType) or (type(v) == types.LongType):", " t = \"integer\"", " elif type(v) == types.FloatType:", " t = \"float\"", " else:", " t = \"string\"", " args = args + \"%12s%s\\n\" % (\"\",", " key, t, str(v), key)", " data = SOAP_MESSAGE % args[:-1]", " #print data", " h.putheader(\"Content-type\", \"text/plain; charset=\\\"utf-8\\\"\")", " h.putheader(\"Content-length\", str(len(data)))", " h.endheaders()", " h.send(data)", " r = h.getreply() #can't do anything with the result", " #print r", " f = h.getfile()", " #print f.read()", " f.close()", " except:", " self.handleError()", "", "#---------------------------------------------------------------------------", "# Manager classes and functions", "#---------------------------------------------------------------------------", "", "class PlaceHolder:", " \"\"\"", " PlaceHolder instances are used in the Manager logger hierarchy to take", " the place of nodes for which no loggers have been defined [FIXME add", " example].", " \"\"\"", " def __init__(self, alogger):", " \"\"\"", " Initialize with the specified logger being a child of this placeholder.", " \"\"\"", " self.loggers = [alogger]", "", " def append(self, alogger):", " \"\"\"", " Add the specified logger as a child of this placeholder.", " \"\"\"", " if alogger not in self.loggers:", " self.loggers.append(alogger)", "", "#", "# Determine which class to use when instantiating loggers.", "#", "_loggerClass = None", "", "def setLoggerClass(klass):", " \"\"\"", " Set the class to be used when instantiating a logger. The class should", " define __init__() such that only a name argument is required, and the", " __init__() should call Logger.__init__()", " \"\"\"", " if klass != Logger:", " if type(klass) != types.ClassType:", " raise TypeError, \"setLoggerClass is expecting a class\"", " if not (Logger in klass.__bases__):", " raise TypeError, \"logger not derived from logging.Logger: \" + \\", " klass.__name__", " global _loggerClass", " _loggerClass = klass", "", "class Manager:", " \"\"\"", " There is [under normal circumstances] just one Manager instance, which", " holds the hierarchy of loggers.", " \"\"\"", " def __init__(self, root):", " \"\"\"", " Initialize the manager with the root node of the logger hierarchy.", " \"\"\"", " self.root = root", " self.disable = 0", " self.emittedNoHandlerWarning = 0", " self.loggerDict = {}", "", " def getLogger(self, name):", " \"\"\"", " Get a logger with the specified name, creating it if it doesn't", " yet exist. If a PlaceHolder existed for the specified name [i.e.", " the logger didn't exist but a child of it did], replace it with", " the created logger and fix up the parent/child references which", " pointed to the placeholder to now point to the logger.", " \"\"\"", " rv = None", " if self.loggerDict.has_key(name):", " rv = self.loggerDict[name]", " if isinstance(rv, PlaceHolder):", " ph = rv", " rv = _loggerClass(name)", " rv.manager = self", " self.loggerDict[name] = rv", " self._fixupChildren(ph, rv)", " self._fixupParents(rv)", " else:", " rv = _loggerClass(name)", " rv.manager = self", " self.loggerDict[name] = rv", " self._fixupParents(rv)", " return rv", "", " def _fixupParents(self, alogger):", " \"\"\"", " Ensure that there are either loggers or placeholders all the way", " from the specified logger to the root of the logger hierarchy.", " \"\"\"", " name = alogger.name", " i = string.rfind(name, \".\")", " rv = None", " while (i > 0) and not rv:", " substr = name[:i]", " if not self.loggerDict.has_key(substr):", " self.loggerDict[name] = PlaceHolder(alogger)", " else:", " obj = self.loggerDict[substr]", " if isinstance(obj, Logger):", " rv = obj", " else:", " assert isinstance(obj, PlaceHolder)", " obj.append(alogger)", " i = string.rfind(name, \".\", 0, i - 1)", " if not rv:", " rv = self.root", " alogger.parent = rv", "", " def _fixupChildren(self, ph, alogger):", " \"\"\"", " Ensure that children of the placeholder ph are connected to the", " specified logger.", " \"\"\"", " for c in ph.loggers:", " if string.find(c.parent.name, alogger.name) <> 0:", " alogger.parent = c.parent", " c.parent = alogger", "", "#---------------------------------------------------------------------------", "# Logger classes and functions", "#---------------------------------------------------------------------------", "", "class Logger(Filterer):", " \"\"\"", " Instances of the Logger class represent a single logging channel.", " \"\"\"", " def __init__(self, name, level=0):", " \"\"\"", " Initialize the logger with a name and an optional level.", " \"\"\"", " Filterer.__init__(self)", " self.name = name", " self.level = level", " self.parent = None", " self.propagate = 1", " self.handlers = []", "", " def setLevel(self, lvl):", " \"\"\"", " Set the logging level of this logger.", " \"\"\"", " self.level = lvl", "", "# def getRoot(self):", "# \"\"\"", "# Get the root of the logger hierarchy.", "# \"\"\"", "# return Logger.root", "", " def debug(self, msg, *args, **kwargs):", " \"\"\"", " Log 'msg % args' with severity 'DEBUG'. To pass exception information,", " use the keyword argument exc_info with a true value, e.g.", "", " logger.debug(\"Houston, we have a %s\", \"thorny problem\", exc_info=1)", " \"\"\"", " if self.manager.disable >= DEBUG:", " return", " if DEBUG >= self.getEffectiveLevel():", " apply(self._log, (DEBUG, msg, args), kwargs)", "", " def info(self, msg, *args, **kwargs):", " \"\"\"", " Log 'msg % args' with severity 'INFO'. To pass exception information,", " use the keyword argument exc_info with a true value, e.g.", "", " logger.info(\"Houston, we have a %s\", \"interesting problem\", exc_info=1)", " \"\"\"", " if self.manager.disable >= INFO:", " return", " if INFO >= self.getEffectiveLevel():", " apply(self._log, (INFO, msg, args), kwargs)", "", " def warn(self, msg, *args, **kwargs):", " \"\"\"", " Log 'msg % args' with severity 'WARN'. To pass exception information,", " use the keyword argument exc_info with a true value, e.g.", "", " logger.warn(\"Houston, we have a %s\", \"bit of a problem\", exc_info=1)", " \"\"\"", " if self.manager.disable >= WARN:", " return", " if self.isEnabledFor(WARN):", " apply(self._log, (WARN, msg, args), kwargs)", "", " def error(self, msg, *args, **kwargs):", " \"\"\"", " Log 'msg % args' with severity 'ERROR'. To pass exception information,", " use the keyword argument exc_info with a true value, e.g.", "", " logger.error(\"Houston, we have a %s\", \"major problem\", exc_info=1)", " \"\"\"", " if self.manager.disable >= ERROR:", " return", " if self.isEnabledFor(ERROR):", " apply(self._log, (ERROR, msg, args), kwargs)", "", " def exception(self, msg, *args):", " \"\"\"", " Convenience method for logging an ERROR with exception information", " \"\"\"", " apply(self.error, (msg,) + args, {'exc_info': 1})", "", " def critical(self, msg, *args, **kwargs):", " \"\"\"", " Log 'msg % args' with severity 'CRITICAL'. To pass exception", " information, use the keyword argument exc_info with a true value, e.g.", "", " logger.critical(\"Houston, we have a %s\", \"major disaster\", exc_info=1)", " \"\"\"", " if self.manager.disable >= CRITICAL:", " return", " if CRITICAL >= self.getEffectiveLevel():", " apply(self._log, (CRITICAL, msg, args), kwargs)", "", " fatal = critical", "", " def log(self, lvl, msg, *args, **kwargs):", " \"\"\"", " Log 'msg % args' with the severity 'lvl'. To pass exception", " information, use the keyword argument exc_info with a true value, e.g.", " logger.log(lvl, \"We have a %s\", \"mysterious problem\", exc_info=1)", " \"\"\"", " if self.manager.disable >= lvl:", " return", " if self.isEnabledFor(lvl):", " apply(self._log, (lvl, msg, args), kwargs)", "", " def findCaller(self):", " \"\"\"", " Find the stack frame of the caller so that we can note the source", " file name and line number.", " \"\"\"", " frames = inspect.stack()[1:]", " for f in frames:", " if _srcfile != f[1]:", " return (f[1], f[2])", " return (None, None)", "", " def makeRecord(self, name, lvl, fn, lno, msg, args, exc_info):", " \"\"\"", " A factory method which can be overridden in subclasses to create", " specialized LogRecords.", " \"\"\"", " return LogRecord(name, lvl, fn, lno, msg, args, exc_info)", "", " def _log(self, lvl, msg, args, exc_info=None):", " \"\"\"", " Low-level logging routine which creates a LogRecord and then calls", " all the handlers of this logger to handle the record.", " \"\"\"", " if inspect:", " fn, lno = self.findCaller()", " else:", " fn, lno = \"\", 0", " if exc_info:", " exc_info = sys.exc_info()", " record = self.makeRecord(self.name, lvl, fn, lno, msg, args, exc_info)", " self.handle(record)", "", " def handle(self, record):", " \"\"\"", " Call the handlers for the specified record. This method is used for", " unpickled records received from a socket, as well as those created", " locally. Logger-level filtering is applied.", " \"\"\"", " if self.filter(record):", " self.callHandlers(record)", "", " def addHandler(self, hdlr):", " \"\"\"", " Add the specified handler to this logger.", " \"\"\"", " if not (hdlr in self.handlers):", " self.handlers.append(hdlr)", "", " def removeHandler(self, hdlr):", " \"\"\"", " Remove the specified handler from this logger.", " \"\"\"", " if hdlr in self.handlers:", " self.handlers.remove(hdlr)", "", " def callHandlers(self, record):", " \"\"\"", " Loop through all handlers for this logger and its parents in the", " logger hierarchy. If no handler was found, output a one-off error", " message. Stop searching up the hierarchy whenever a logger with the", " \"propagate\" attribute set to zero is found - that will be the last", " logger whose handlers are called.", " \"\"\"", " c = self", " found = 0", " while c:", " for hdlr in c.handlers:", " found = found + 1", " if record.lvl >= hdlr.level:", " hdlr.handle(record)", " if not c.propagate:", " c = None #break out", " else:", " c = c.parent", " if (found == 0) and not self.manager.emittedNoHandlerWarning:", " print \"No handlers could be found for logger \\\"%s\\\"\" % self.name", " self.manager.emittedNoHandlerWarning = 1", "", " def getEffectiveLevel(self):", " \"\"\"", " Loop through this logger and its parents in the logger hierarchy,", " looking for a non-zero logging level. Return the first one found.", " \"\"\"", " c = self", " while c:", " if c.level:", " return c.level", " c = c.parent", " #print \"NCP\", self.parent", "", " def isEnabledFor(self, lvl):", " \"\"\"", " Is this logger enabled for level lvl?", " \"\"\"", " if self.manager.disable >= lvl:", " return 0", " return lvl >= self.getEffectiveLevel()", "", "class RootLogger(Logger):", " \"\"\"", " A root logger is not that different to any other logger, except that", " it must have a logging level and there is only one instance of it in", " the hierarchy.", " \"\"\"", " def __init__(self, lvl):", " \"\"\"", " Initialize the logger with the name \"root\".", " \"\"\"", " Logger.__init__(self, \"root\", lvl)", "", "_loggerClass = Logger", "", "root = RootLogger(DEBUG)", "Logger.root = root", "Logger.manager = Manager(Logger.root)", "", "#---------------------------------------------------------------------------", "# Configuration classes and functions", "#---------------------------------------------------------------------------", "", "BASIC_FORMAT = \"%(asctime)s %(name)-19s %(level)-5s - %(message)s\"", "", "def basicConfig():", " \"\"\"", " Do basic configuration for the logging system by creating a", " StreamHandler with a default Formatter and adding it to the", " root logger.", " \"\"\"", " hdlr = StreamHandler()", " fmt = Formatter(BASIC_FORMAT)", " hdlr.setFormatter(fmt)", " root.addHandler(hdlr)", "", "#def fileConfig(fname):", "# \"\"\"", "# The old implementation - using dict-based configuration files.", "# Read the logging configuration from a file. Keep it simple for now.", "# \"\"\"", "# file = open(fname, \"r\")", "# data = file.read()", "# file.close()", "# dict = eval(data)", "# handlers = dict.get(\"handlers\", [])", "# loggers = dict.get(\"loggers\", [])", "# formatters = dict.get(\"formatters\", [])", "# for f in formatters:", "# fd = dict[f]", "# fc = fd.get(\"class\", \"logging.Formatter\")", "# args = fd.get(\"args\", ())", "# fc = eval(fc)", "# try:", "# fmt = apply(fc, args)", "# except:", "# print fc, args", "# raise", "# dict[f] = fmt", "#", "# for h in handlers:", "# hd = dict[h]", "# hc = hd.get(\"class\", \"logging.StreamHandler\")", "# args = hd.get(\"args\", ())", "# hc = eval(hc)", "# fmt = hd.get(\"formatter\", None)", "# if fmt:", "# fmt = dict.get(fmt, None)", "# try:", "# hdlr = apply(hc, args)", "# except:", "# print hc, args", "# raise", "# if fmt:", "# hdlr.setFormatter(fmt)", "# dict[h] = hdlr", "#", "# for ln in loggers:", "# ld = dict[ln]", "# name = ld.get(\"name\", None)", "# if name:", "# logger = getLogger(name)", "# else:", "# logger = getRootLogger()", "# logger.propagate = ld.get(\"propagate\", 1)", "# hdlrs = ld.get(\"handlers\", [])", "# for h in hdlrs:", "# hdlr = dict.get(h, None)", "# if hdlr:", "# logger.addHandler(hdlr)", "", "def fileConfig(fname):", " \"\"\"", " Read the logging configuration from a ConfigParser-format file.", " \"\"\"", " import ConfigParser", "", " cp = ConfigParser.ConfigParser()", " cp.read(fname)", " #first, do the formatters...", " flist = cp.get(\"formatters\", \"keys\")", " flist = string.split(flist, \",\")", " formatters = {}", " for form in flist:", " sectname = \"formatter_%s\" % form", " fs = cp.get(sectname, \"format\", 1)", " dfs = cp.get(sectname, \"datefmt\", 1)", " f = Formatter(fs, dfs)", " formatters[form] = f", " #next, do the handlers...", " hlist = cp.get(\"handlers\", \"keys\")", " hlist = string.split(hlist, \",\")", " handlers = {}", " for hand in hlist:", " sectname = \"handler_%s\" % hand", " klass = cp.get(sectname, \"class\")", " fmt = cp.get(sectname, \"formatter\")", " lvl = cp.get(sectname, \"level\")", " klass = eval(klass)", " args = cp.get(sectname, \"args\")", " args = eval(args)", " h = apply(klass, args)", " h.setLevel(eval(lvl))", " h.setFormatter(formatters[fmt])", " #temporary hack for FileHandler.", " if klass == FileHandler:", " maxsize = cp.get(sectname, \"maxsize\")", " if maxsize:", " maxsize = eval(maxsize)", " else:", " maxsize = 0", " if maxsize:", " backcount = cp.get(sectname, \"backcount\")", " if backcount:", " backcount = eval(backcount)", " else:", " backcount = 0", " h.setRollover(maxsize, backcount)", " handlers[hand] = h", " #at last, the loggers...first the root...", " llist = cp.get(\"loggers\", \"keys\")", " llist = string.split(llist, \",\")", " llist.remove(\"root\")", " sectname = \"logger_root\"", " log = root", " lvl = cp.get(sectname, \"level\")", " log.setLevel(eval(lvl))", " hlist = cp.get(sectname, \"handlers\")", " hlist = string.split(hlist, \",\")", " for hand in hlist:", " log.addHandler(handlers[hand])", " #and now the others...", " for log in llist:", " sectname = \"logger_%s\" % log", " qn = cp.get(sectname, \"qualname\")", " lvl = cp.get(sectname, \"level\")", " propagate = cp.get(sectname, \"propagate\")", " logger = getLogger(qn)", " logger.setLevel(eval(lvl))", " logger.propagate = eval(propagate)", " hlist = cp.get(sectname, \"handlers\")", " hlist = string.split(hlist, \",\")", " for hand in hlist:", " logger.addHandler(handlers[hand])", "", "", "#---------------------------------------------------------------------------", "# Utility functions at module level.", "# Basically delegate everything to the root logger.", "#---------------------------------------------------------------------------", "", "def getLogger(name):", " \"\"\"", " Return a logger with the specified name, creating it if necessary.", " If no name is specified, return the root logger.", " \"\"\"", " if name:", " return Logger.manager.getLogger(name)", " else:", " return root", "", "def getRootLogger():", " \"\"\"", " Return the root logger.", " \"\"\"", " return root", "", "def critical(msg, *args, **kwargs):", " \"\"\"", " Log a message with severity 'CRITICAL' on the root logger.", " \"\"\"", " if len(root.handlers) == 0:", " basicConfig()", " apply(root.critical, (msg,)+args, kwargs)", "", "fatal = critical", "", "def error(msg, *args, **kwargs):", " \"\"\"", " Log a message with severity 'ERROR' on the root logger.", " \"\"\"", " if len(root.handlers) == 0:", " basicConfig()", " apply(root.error, (msg,)+args, kwargs)", "", "def exception(msg, *args):", " \"\"\"", " Log a message with severity 'ERROR' on the root logger,", " with exception information.", " \"\"\"", " apply(error, (msg,)+args, {'exc_info': 1})", "", "def warn(msg, *args, **kwargs):", " \"\"\"", " Log a message with severity 'WARN' on the root logger.", " \"\"\"", " if len(root.handlers) == 0:", " basicConfig()", " apply(root.warn, (msg,)+args, kwargs)", "", "def info(msg, *args, **kwargs):", " \"\"\"", " Log a message with severity 'INFO' on the root logger.", " \"\"\"", " if len(root.handlers) == 0:", " basicConfig()", " apply(root.info, (msg,)+args, kwargs)", "", "def debug(msg, *args, **kwargs):", " \"\"\"", " Log a message with severity 'DEBUG' on the root logger.", " \"\"\"", " if len(root.handlers) == 0:", " basicConfig()", " apply(root.debug, (msg,)+args, kwargs)", "", "def disable(level):", " \"\"\"", " Disable all logging calls less severe than 'level'.", " \"\"\"", " root.manager.disable = level", "", "def shutdown():", " \"\"\"", " Perform any cleanup actions in the logging system (e.g. flushing", " buffers). Should be called at application exit.", " \"\"\"", " for h in _handlers.keys():", " h.flush()", " h.close()", "", "if __name__ == \"__main__\":", " print __doc__" ], "deleted": [] } }, { "old_path": null, "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,358 @@\n+\n+__all__ = []\n+\n+import os,sys,time,glob,string,traceback,unittest\n+import fastumath as math\n+\n+try:\n+ # These are used by Numeric tests.\n+ # If Numeric and scipy_base are not available, then some of the\n+ # functions below will not be available.\n+ from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64\n+ import scipy_base.fastumath\n+except ImportError:\n+ pass\n+ \n+__all__.append('ScipyTestCase')\n+class ScipyTestCase (unittest.TestCase):\n+\n+ def measure(self,code_str,times=1):\n+ \"\"\" Return elapsed time for executing code_str in the\n+ namespace of the caller for given times.\n+ \"\"\"\n+ frame = sys._getframe(1)\n+ locs,globs = frame.f_locals,frame.f_globals\n+ code = compile(code_str,\n+ 'ScipyTestCase runner for '+self.__class__.__name__,\n+ 'exec')\n+ i = 0\n+ elapsed = time.time()\n+ while i test_list -> test ...\n # I'm considering test to be the root of atom symbols.\n # It might be a better idea to move down a little in the\n # parse tree. Any benefits? Right now, this works fine. \n if type(expr_string) == StringType:\n ast = parser.expr(expr_string).totuple()[1][1]\n else:\n ast = parser.expr(`expr_string`).totuple()[1][1]\n return ast\n\ndef atom_tuple(expr_string):\n return build_atom(expr_string)\n\ndef atom_list(expr_string):\n return tuples_to_lists(build_atom(expr_string))\n \ndef find_first_pattern(ast_tuple,pattern_list):\n \"\"\"* Find the first occurence of a pattern one of a list of patterns \n in ast_tuple.\n \n Used for testing at the moment.\n \n ast_tuple -- tuple or list created by ast.totuple() or ast.tolist().\n pattern_list -- A single pattern or list of patterns to search\n for in the ast_tuple. If a single pattern is \n used, it MUST BE A IN A TUPLE format.\n Returns:\n found -- true/false indicating whether pattern was found\n data -- dictionary of data from first matching pattern in tree.\n (see match function by Jeremy Hylton). \n *\"\"\"\n found,data = 0,{}\n \n # convert to a list if input wasn't a list\n if type(pattern_list) != ListType:\n pattern_list = [pattern_list]\n\n # look for any of the patterns in a list of patterns \n for pattern in pattern_list:\n found,data = match(pattern,ast_tuple)\n if found: \n break \n \n # if we didn't find the pattern, search sub-trees of the parse tree\n if not found: \n for item in ast_tuple: \n if type(item) in [TupleType,ListType]:\n # only search sub items if they are a list or tuple.\n found, data = find_first_pattern(item,pattern_list)\n if found: \n break \n return found,data\n\nname_pattern = (token.NAME, ['var'])\n\ndef remove_duplicates(lst):\n output = []\n for item in lst:\n if item not in output:\n output.append(item)\n return output\n\nreserved_names = ['sin']\n\ndef remove_reserved_names(lst):\n \"\"\" These are functions names -- don't create variables for them\n There is a more reobust approach, but this ought to work pretty\n well.\n \"\"\"\n output = []\n for item in lst:\n if item not in reserved_names:\n output.append(item)\n return output\n\ndef harvest_variables(ast_list): \n \"\"\" Retreive all the variables that need to be defined.\n \"\"\" \n variables = []\n if type(ast_list) in (ListType,TupleType):\n found,data = match(name_pattern,ast_list)\n if found:\n variables.append(data['var'])\n for item in ast_list:\n if type(item) in (ListType,TupleType):\n variables.extend(harvest_variables(item))\n variables = remove_duplicates(variables) \n variables = remove_reserved_names(variables) \n return variables\n\ndef match(pattern, data, vars=None):\n \"\"\"match `data' to `pattern', with variable extraction.\n\n pattern\n Pattern to match against, possibly containing variables.\n\n data\n Data to be checked and against which variables are extracted.\n\n vars\n Dictionary of variables which have already been found. If not\n provided, an empty dictionary is created.\n\n The `pattern' value may contain variables of the form ['varname'] which\n are allowed to match anything. The value that is matched is returned as\n part of a dictionary which maps 'varname' to the matched value. 'varname'\n is not required to be a string object, but using strings makes patterns\n and the code which uses them more readable.\n\n This function returns two values: a boolean indicating whether a match\n was found and a dictionary mapping variable names to their associated\n values.\n \n From the Demo/Parser/example.py file\n \"\"\"\n if vars is None:\n vars = {}\n if type(pattern) is ListType: # 'variables' are ['varname']\n vars[pattern[0]] = data\n return 1, vars\n if type(pattern) is not TupleType:\n return (pattern == data), vars\n if len(data) != len(pattern):\n return 0, vars\n for pattern, data in map(None, pattern, data):\n same, vars = match(pattern, data, vars)\n if not same:\n break\n return same, vars\n\n\ndef tuples_to_lists(ast_tuple):\n \"\"\" Convert an ast object tree in tuple form to list form.\n \"\"\"\n if type(ast_tuple) not in [ListType,TupleType]:\n return ast_tuple\n \n new_list = []\n for item in ast_tuple:\n new_list.append(tuples_to_lists(item))\n return new_list\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n\"\"\"\nA little tree I built to help me understand the parse trees.\n -----------303------------------------------\n | | \n 304 -------------------------307-------------------------\n | | | | | |\n 1 'result' 9 '[' 308 12 ',' 308 10 ']'\n | |\n ---------309-------- -----309-------- \n | | | | \n 291|304 291|304 291|304 |\n | | | |\n 1 'a1' 11 ':' 1 'a2' 2 '10' 11 ':' \n\"\"\"\n", "source_code_before": "import token\nimport symbol\nimport parser\n\nfrom types import ListType, TupleType, StringType, IntType\n\ndef int_to_symbol(i):\n \"\"\" Convert numeric symbol or token to a desriptive name.\n \"\"\"\n try: \n return symbol.sym_name[i]\n except KeyError:\n return token.tok_name[i]\n \ndef translate_symbols(ast_tuple):\n \"\"\" Translate numeric grammar symbols in an ast_tuple descriptive names.\n \n This simply traverses the tree converting any integer value to values\n found in symbol.sym_name or token.tok_name.\n \"\"\" \n new_list = []\n for item in ast_tuple:\n if type(item) == IntType:\n new_list.append(int_to_symbol(item))\n elif type(item) in [TupleType,ListType]:\n new_list.append(translate_symbols(item))\n else: \n new_list.append(item)\n if type(ast_tuple) == TupleType:\n return tuple(new_list)\n else:\n return new_list\n\ndef ast_to_string(ast_seq):\n \"\"\"* Traverse an ast tree sequence, printing out all leaf nodes.\n \n This effectively rebuilds the expression the tree was built\n from. I guess its probably missing whitespace. How bout\n indent stuff and new lines? Haven't checked this since we're\n currently only dealing with simple expressions.\n *\"\"\"\n output = ''\n for item in ast_seq:\n if type(item) is StringType:\n output = output + item\n elif type(item) in [ListType,TupleType]:\n output = output + ast_to_string(item)\n return output \n\ndef build_atom(expr_string):\n \"\"\" Build an ast for an atom from the given expr string.\n \n If expr_string is not a string, it is converted to a string\n before parsing to an ast_tuple.\n \"\"\"\n # the [1][1] indexing below starts atoms at the third level\n # deep in the resulting parse tree. parser.expr will return\n # a tree rooted with eval_input -> test_list -> test ...\n # I'm considering test to be the root of atom symbols.\n # It might be a better idea to move down a little in the\n # parse tree. Any benefits? Right now, this works fine. \n if type(expr_string) == StringType:\n ast = parser.expr(expr_string).totuple()[1][1]\n else:\n ast = parser.expr(`expr_string`).totuple()[1][1]\n return ast\n\ndef atom_tuple(expr_string):\n return build_atom(expr_string)\n\ndef atom_list(expr_string):\n return tuples_to_lists(build_atom(expr_string))\n \ndef find_first_pattern(ast_tuple,pattern_list):\n \"\"\"* Find the first occurence of a pattern one of a list of patterns \n in ast_tuple.\n \n Used for testing at the moment.\n \n ast_tuple -- tuple or list created by ast.totuple() or ast.tolist().\n pattern_list -- A single pattern or list of patterns to search\n for in the ast_tuple. If a single pattern is \n used, it MUST BE A IN A TUPLE format.\n Returns:\n found -- true/false indicating whether pattern was found\n data -- dictionary of data from first matching pattern in tree.\n (see match function by Jeremy Hylton). \n *\"\"\"\n found,data = 0,{}\n \n # convert to a list if input wasn't a list\n if type(pattern_list) != ListType:\n pattern_list = [pattern_list]\n\n # look for any of the patterns in a list of patterns \n for pattern in pattern_list:\n found,data = match(pattern,ast_tuple)\n if found: \n break \n \n # if we didn't find the pattern, search sub-trees of the parse tree\n if not found: \n for item in ast_tuple: \n if type(item) in [TupleType,ListType]:\n # only search sub items if they are a list or tuple.\n found, data = find_first_pattern(item,pattern_list)\n if found: \n break \n return found,data\n\nname_pattern = (token.NAME, ['var'])\n\ndef remove_duplicates(lst):\n output = []\n for item in lst:\n if item not in output:\n output.append(item)\n return output\n\nreserved_names = ['sin']\n\ndef remove_reserved_names(lst):\n \"\"\" These are functions names -- don't create variables for them\n There is a more reobust approach, but this ought to work pretty\n well.\n \"\"\"\n output = []\n for item in lst:\n if item not in reserved_names:\n output.append(item)\n return output\n\ndef harvest_variables(ast_list): \n \"\"\" Retreive all the variables that need to be defined.\n \"\"\" \n variables = []\n if type(ast_list) in (ListType,TupleType):\n found,data = match(name_pattern,ast_list)\n if found:\n variables.append(data['var'])\n for item in ast_list:\n if type(item) in (ListType,TupleType):\n variables.extend(harvest_variables(item))\n variables = remove_duplicates(variables) \n variables = remove_reserved_names(variables) \n return variables\n\ndef match(pattern, data, vars=None):\n \"\"\"match `data' to `pattern', with variable extraction.\n\n pattern\n Pattern to match against, possibly containing variables.\n\n data\n Data to be checked and against which variables are extracted.\n\n vars\n Dictionary of variables which have already been found. If not\n provided, an empty dictionary is created.\n\n The `pattern' value may contain variables of the form ['varname'] which\n are allowed to match anything. The value that is matched is returned as\n part of a dictionary which maps 'varname' to the matched value. 'varname'\n is not required to be a string object, but using strings makes patterns\n and the code which uses them more readable.\n\n This function returns two values: a boolean indicating whether a match\n was found and a dictionary mapping variable names to their associated\n values.\n \n From the Demo/Parser/example.py file\n \"\"\"\n if vars is None:\n vars = {}\n if type(pattern) is ListType: # 'variables' are ['varname']\n vars[pattern[0]] = data\n return 1, vars\n if type(pattern) is not TupleType:\n return (pattern == data), vars\n if len(data) != len(pattern):\n return 0, vars\n for pattern, data in map(None, pattern, data):\n same, vars = match(pattern, data, vars)\n if not same:\n break\n return same, vars\n\n\ndef tuples_to_lists(ast_tuple):\n \"\"\" Convert an ast object tree in tuple form to list form.\n \"\"\"\n if type(ast_tuple) not in [ListType,TupleType]:\n return ast_tuple\n \n new_list = []\n for item in ast_tuple:\n new_list.append(tuples_to_lists(item))\n return new_list\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n\"\"\"\nA little tree I built to help me understand the parse trees.\n -----------303------------------------------\n | | \n 304 -------------------------307-------------------------\n | | | | | |\n 1 'result' 9 '[' 308 12 ',' 308 10 ']'\n | |\n ---------309-------- -----309-------- \n | | | | \n 291|304 291|304 291|304 |\n | | | |\n 1 'a1' 11 ':' 1 'a2' 2 '10' 11 ':' \n\"\"\"\n", "methods": [ { "name": "int_to_symbol", "long_name": "int_to_symbol( i )", "filename": "ast_tools.py", "nloc": 5, "complexity": 2, "token_count": 25, "parameters": [ "i" ], "start_line": 7, "end_line": 13, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "translate_symbols", "long_name": "translate_symbols( ast_tuple )", "filename": "ast_tools.py", "nloc": 13, "complexity": 5, "token_count": 78, "parameters": [ "ast_tuple" ], "start_line": 15, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "ast_to_string", "long_name": "ast_to_string( ast_seq )", "filename": "ast_tools.py", "nloc": 8, "complexity": 4, "token_count": 49, "parameters": [ "ast_seq" ], "start_line": 34, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "build_atom", "long_name": "build_atom( expr_string )", "filename": "ast_tools.py", "nloc": 6, "complexity": 2, "token_count": 56, "parameters": [ "expr_string" ], "start_line": 50, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "atom_tuple", "long_name": "atom_tuple( expr_string )", "filename": "ast_tools.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "expr_string" ], "start_line": 68, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "atom_list", "long_name": "atom_list( expr_string )", "filename": "ast_tools.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "expr_string" ], "start_line": 71, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "find_first_pattern", "long_name": "find_first_pattern( ast_tuple , pattern_list )", "filename": "ast_tools.py", "nloc": 15, "complexity": 8, "token_count": 87, "parameters": [ "ast_tuple", "pattern_list" ], "start_line": 74, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "remove_duplicates", "long_name": "remove_duplicates( lst )", "filename": "ast_tools.py", "nloc": 6, "complexity": 3, "token_count": 28, "parameters": [ "lst" ], "start_line": 113, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "remove_reserved_names", "long_name": "remove_reserved_names( lst )", "filename": "ast_tools.py", "nloc": 6, "complexity": 3, "token_count": 29, "parameters": [ "lst" ], "start_line": 122, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "harvest_variables", "long_name": "harvest_variables( ast_list )", "filename": "ast_tools.py", "nloc": 12, "complexity": 5, "token_count": 84, "parameters": [ "ast_list" ], "start_line": 133, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "match", "long_name": "match( pattern , data , vars = None )", "filename": "ast_tools.py", "nloc": 15, "complexity": 7, "token_count": 109, "parameters": [ "pattern", "data", "vars" ], "start_line": 148, "end_line": 186, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 }, { "name": "tuples_to_lists", "long_name": "tuples_to_lists( ast_tuple )", "filename": "ast_tools.py", "nloc": 7, "complexity": 3, "token_count": 41, "parameters": [ "ast_tuple" ], "start_line": 189, "end_line": 198, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "ast_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 200, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "ast_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 204, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "int_to_symbol", "long_name": "int_to_symbol( i )", "filename": "ast_tools.py", "nloc": 5, "complexity": 2, "token_count": 25, "parameters": [ "i" ], "start_line": 7, "end_line": 13, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "translate_symbols", "long_name": "translate_symbols( ast_tuple )", "filename": "ast_tools.py", "nloc": 13, "complexity": 5, "token_count": 78, "parameters": [ "ast_tuple" ], "start_line": 15, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "ast_to_string", "long_name": "ast_to_string( ast_seq )", "filename": "ast_tools.py", "nloc": 8, "complexity": 4, "token_count": 49, "parameters": [ "ast_seq" ], "start_line": 34, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "build_atom", "long_name": "build_atom( expr_string )", "filename": "ast_tools.py", "nloc": 6, "complexity": 2, "token_count": 56, "parameters": [ "expr_string" ], "start_line": 50, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "atom_tuple", "long_name": "atom_tuple( expr_string )", "filename": "ast_tools.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "expr_string" ], "start_line": 68, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "atom_list", "long_name": "atom_list( expr_string )", "filename": "ast_tools.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "expr_string" ], "start_line": 71, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "find_first_pattern", "long_name": "find_first_pattern( ast_tuple , pattern_list )", "filename": "ast_tools.py", "nloc": 15, "complexity": 8, "token_count": 87, "parameters": [ "ast_tuple", "pattern_list" ], "start_line": 74, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "remove_duplicates", "long_name": "remove_duplicates( lst )", "filename": "ast_tools.py", "nloc": 6, "complexity": 3, "token_count": 28, "parameters": [ "lst" ], "start_line": 113, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "remove_reserved_names", "long_name": "remove_reserved_names( lst )", "filename": "ast_tools.py", "nloc": 6, "complexity": 3, "token_count": 29, "parameters": [ "lst" ], "start_line": 122, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "harvest_variables", "long_name": "harvest_variables( ast_list )", "filename": "ast_tools.py", "nloc": 12, "complexity": 5, "token_count": 84, "parameters": [ "ast_list" ], "start_line": 133, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "match", "long_name": "match( pattern , data , vars = None )", "filename": "ast_tools.py", "nloc": 15, "complexity": 7, "token_count": 109, "parameters": [ "pattern", "data", "vars" ], "start_line": 148, "end_line": 186, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 }, { "name": "tuples_to_lists", "long_name": "tuples_to_lists( ast_tuple )", "filename": "ast_tools.py", "nloc": 7, "complexity": 3, "token_count": 41, "parameters": [ "ast_tuple" ], "start_line": 189, "end_line": 198, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "ast_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 200, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "ast_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 204, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "ast_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 204, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "ast_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 200, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 123, "complexity": 46, "token_count": 703, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "weave/blitz_tools.py", "new_path": "weave/blitz_tools.py", "filename": "blitz_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -132,11 +132,11 @@ def test_function():\n blitz(expr)\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n if __name__ == \"__main__\":\n", "added_lines": 2, "deleted_lines": 2, "source_code": "import parser\nimport string\nimport copy\nimport os,sys\nimport ast_tools\nimport token,symbol\nimport slice_handler\nimport size_check\nimport converters\n\nfrom ast_tools import *\n\nfrom Numeric import *\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from scipy_base.fastumath import *\nexcept:\n pass # scipy_base.fastumath not available \n \nfrom types import *\n\nimport inline_tools\nfrom inline_tools import attempt_function_call\nfunction_catalog = inline_tools.function_catalog\nfunction_cache = inline_tools.function_cache\n \ndef blitz(expr,local_dict=None, global_dict=None,check_size=1,verbose=0,**kw):\n # this could call inline, but making a copy of the\n # code here is more efficient for several reasons.\n global function_catalog\n \n # this grabs the local variables from the *previous* call\n # frame -- that is the locals from the function that called\n # inline.\n call_frame = sys._getframe().f_back\n if local_dict is None:\n local_dict = call_frame.f_locals\n if global_dict is None:\n global_dict = call_frame.f_globals\n\n # 1. Check the sizes of the arrays and make sure they are compatible.\n # This is expensive, so unsetting the check_size flag can save a lot\n # of time. It also can cause core-dumps if the sizes of the inputs \n # aren't compatible. \n if check_size and not size_check.check_expr(expr,local_dict,global_dict):\n raise 'inputs failed to pass size check.'\n \n # 2. try local cache \n try:\n results = apply(function_cache[expr],(local_dict,global_dict))\n return results\n except: \n pass\n try:\n results = attempt_function_call(expr,local_dict,global_dict)\n # 3. build the function \n except ValueError:\n # This section is pretty much the only difference \n # between blitz and inline\n ast = parser.suite(expr)\n ast_list = ast.tolist()\n expr_code = ast_to_blitz_expr(ast_list)\n arg_names = harvest_variables(ast_list)\n module_dir = global_dict.get('__file__',None)\n #func = inline_tools.compile_function(expr_code,arg_names,\n # local_dict,global_dict,\n # module_dir,auto_downcast = 1)\n func = inline_tools.compile_function(expr_code,arg_names,local_dict, \n global_dict,module_dir,\n compiler='gcc',auto_downcast=1,\n verbose = verbose,\n type_converters = converters.blitz,\n **kw)\n function_catalog.add_function(expr,func,module_dir)\n try: \n results = attempt_function_call(expr,local_dict,global_dict)\n except ValueError: \n print 'warning: compilation failed. Executing as python code'\n exec expr in global_dict, local_dict\n \ndef ast_to_blitz_expr(ast_seq):\n \"\"\" Convert an ast_sequence to a blitz expression.\n \"\"\"\n \n # Don't overwrite orignal sequence in call to transform slices.\n ast_seq = copy.deepcopy(ast_seq) \n slice_handler.transform_slices(ast_seq)\n \n # Build the actual program statement from ast_seq\n expr = ast_tools.ast_to_string(ast_seq)\n \n # Now find and replace specific symbols to convert this to\n # a blitz++ compatible statement.\n # I'm doing this with string replacement here. It could\n # also be done on the actual ast tree (and probably should from\n # a purest standpoint...).\n \n # this one isn't necessary but it helps code readability\n # and compactness. It requires that \n # Range _all = blitz::Range::all();\n # be included in the generated code. \n # These could all alternatively be done to the ast in\n # build_slice_atom()\n expr = string.replace(expr,'slice(_beg,_end)', '_all' ) \n expr = string.replace(expr,'slice', 'blitz::Range' )\n expr = string.replace(expr,'[','(')\n expr = string.replace(expr,']', ')' )\n expr = string.replace(expr,'_stp', '1' )\n \n # Instead of blitz::fromStart and blitz::toEnd. This requires\n # the following in the generated code.\n # Range _beg = blitz::fromStart;\n # Range _end = blitz::toEnd;\n #expr = string.replace(expr,'_beg', 'blitz::fromStart' )\n #expr = string.replace(expr,'_end', 'blitz::toEnd' )\n \n return expr + ';\\n'\n\ndef test_function():\n expr = \"ex[:,1:,1:] = k + ca_x[:,1:,1:] * ex[:,1:,1:]\" \\\n \"+ cb_y_x[:,1:,1:] * (hz[:,1:,1:] - hz[:,:-1,1:])\"\\\n \"- cb_z_x[:,1:,1:] * (hy[:,1:,1:] - hy[:,1:,:-1])\" \n #ast = parser.suite('a = (b + c) * sin(d)')\n ast = parser.suite(expr)\n k = 1.\n ex = ones((1,1,1),typecode=Float32)\n ca_x = ones((1,1,1),typecode=Float32)\n cb_y_x = ones((1,1,1),typecode=Float32)\n cb_z_x = ones((1,1,1),typecode=Float32)\n hz = ones((1,1,1),typecode=Float32)\n hy = ones((1,1,1),typecode=Float32)\n blitz(expr)\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == \"__main__\":\n test_function()\n", "source_code_before": "import parser\nimport string\nimport copy\nimport os,sys\nimport ast_tools\nimport token,symbol\nimport slice_handler\nimport size_check\nimport converters\n\nfrom ast_tools import *\n\nfrom Numeric import *\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from scipy_base.fastumath import *\nexcept:\n pass # scipy_base.fastumath not available \n \nfrom types import *\n\nimport inline_tools\nfrom inline_tools import attempt_function_call\nfunction_catalog = inline_tools.function_catalog\nfunction_cache = inline_tools.function_cache\n \ndef blitz(expr,local_dict=None, global_dict=None,check_size=1,verbose=0,**kw):\n # this could call inline, but making a copy of the\n # code here is more efficient for several reasons.\n global function_catalog\n \n # this grabs the local variables from the *previous* call\n # frame -- that is the locals from the function that called\n # inline.\n call_frame = sys._getframe().f_back\n if local_dict is None:\n local_dict = call_frame.f_locals\n if global_dict is None:\n global_dict = call_frame.f_globals\n\n # 1. Check the sizes of the arrays and make sure they are compatible.\n # This is expensive, so unsetting the check_size flag can save a lot\n # of time. It also can cause core-dumps if the sizes of the inputs \n # aren't compatible. \n if check_size and not size_check.check_expr(expr,local_dict,global_dict):\n raise 'inputs failed to pass size check.'\n \n # 2. try local cache \n try:\n results = apply(function_cache[expr],(local_dict,global_dict))\n return results\n except: \n pass\n try:\n results = attempt_function_call(expr,local_dict,global_dict)\n # 3. build the function \n except ValueError:\n # This section is pretty much the only difference \n # between blitz and inline\n ast = parser.suite(expr)\n ast_list = ast.tolist()\n expr_code = ast_to_blitz_expr(ast_list)\n arg_names = harvest_variables(ast_list)\n module_dir = global_dict.get('__file__',None)\n #func = inline_tools.compile_function(expr_code,arg_names,\n # local_dict,global_dict,\n # module_dir,auto_downcast = 1)\n func = inline_tools.compile_function(expr_code,arg_names,local_dict, \n global_dict,module_dir,\n compiler='gcc',auto_downcast=1,\n verbose = verbose,\n type_converters = converters.blitz,\n **kw)\n function_catalog.add_function(expr,func,module_dir)\n try: \n results = attempt_function_call(expr,local_dict,global_dict)\n except ValueError: \n print 'warning: compilation failed. Executing as python code'\n exec expr in global_dict, local_dict\n \ndef ast_to_blitz_expr(ast_seq):\n \"\"\" Convert an ast_sequence to a blitz expression.\n \"\"\"\n \n # Don't overwrite orignal sequence in call to transform slices.\n ast_seq = copy.deepcopy(ast_seq) \n slice_handler.transform_slices(ast_seq)\n \n # Build the actual program statement from ast_seq\n expr = ast_tools.ast_to_string(ast_seq)\n \n # Now find and replace specific symbols to convert this to\n # a blitz++ compatible statement.\n # I'm doing this with string replacement here. It could\n # also be done on the actual ast tree (and probably should from\n # a purest standpoint...).\n \n # this one isn't necessary but it helps code readability\n # and compactness. It requires that \n # Range _all = blitz::Range::all();\n # be included in the generated code. \n # These could all alternatively be done to the ast in\n # build_slice_atom()\n expr = string.replace(expr,'slice(_beg,_end)', '_all' ) \n expr = string.replace(expr,'slice', 'blitz::Range' )\n expr = string.replace(expr,'[','(')\n expr = string.replace(expr,']', ')' )\n expr = string.replace(expr,'_stp', '1' )\n \n # Instead of blitz::fromStart and blitz::toEnd. This requires\n # the following in the generated code.\n # Range _beg = blitz::fromStart;\n # Range _end = blitz::toEnd;\n #expr = string.replace(expr,'_beg', 'blitz::fromStart' )\n #expr = string.replace(expr,'_end', 'blitz::toEnd' )\n \n return expr + ';\\n'\n\ndef test_function():\n expr = \"ex[:,1:,1:] = k + ca_x[:,1:,1:] * ex[:,1:,1:]\" \\\n \"+ cb_y_x[:,1:,1:] * (hz[:,1:,1:] - hz[:,:-1,1:])\"\\\n \"- cb_z_x[:,1:,1:] * (hy[:,1:,1:] - hy[:,1:,:-1])\" \n #ast = parser.suite('a = (b + c) * sin(d)')\n ast = parser.suite(expr)\n k = 1.\n ex = ones((1,1,1),typecode=Float32)\n ca_x = ones((1,1,1),typecode=Float32)\n cb_y_x = ones((1,1,1),typecode=Float32)\n cb_z_x = ones((1,1,1),typecode=Float32)\n hz = ones((1,1,1),typecode=Float32)\n hy = ones((1,1,1),typecode=Float32)\n blitz(expr)\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == \"__main__\":\n test_function()\n", "methods": [ { "name": "blitz", "long_name": "blitz( expr , local_dict = None , global_dict = None , check_size = 1 , verbose = 0 , ** kw )", "filename": "blitz_tools.py", "nloc": 34, "complexity": 8, "token_count": 216, "parameters": [ "expr", "local_dict", "global_dict", "check_size", "verbose", "kw" ], "start_line": 27, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "ast_to_blitz_expr", "long_name": "ast_to_blitz_expr( ast_seq )", "filename": "blitz_tools.py", "nloc": 10, "complexity": 1, "token_count": 92, "parameters": [ "ast_seq" ], "start_line": 81, "end_line": 117, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "test_function", "long_name": "test_function( )", "filename": "blitz_tools.py", "nloc": 13, "complexity": 1, "token_count": 123, "parameters": [], "start_line": 119, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 134, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 138, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "blitz", "long_name": "blitz( expr , local_dict = None , global_dict = None , check_size = 1 , verbose = 0 , ** kw )", "filename": "blitz_tools.py", "nloc": 34, "complexity": 8, "token_count": 216, "parameters": [ "expr", "local_dict", "global_dict", "check_size", "verbose", "kw" ], "start_line": 27, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 }, { "name": "ast_to_blitz_expr", "long_name": "ast_to_blitz_expr( ast_seq )", "filename": "blitz_tools.py", "nloc": 10, "complexity": 1, "token_count": 92, "parameters": [ "ast_seq" ], "start_line": 81, "end_line": 117, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "test_function", "long_name": "test_function( )", "filename": "blitz_tools.py", "nloc": 13, "complexity": 1, "token_count": 123, "parameters": [], "start_line": 119, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 134, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 138, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 138, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 134, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 85, "complexity": 12, "token_count": 552, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "weave/build_tools.py", "new_path": "weave/build_tools.py", "filename": "build_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -457,11 +457,11 @@ def build_import_library():\n # raise DistutilsPlatformError, msg\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n \n", "added_lines": 2, "deleted_lines": 2, "source_code": "\"\"\" Tools for compiling C/C++ code to extension modules\n\n The main function, build_extension(), takes the C/C++ file\n along with some other options and builds a Python extension.\n It uses distutils for most of the heavy lifting.\n \n choose_compiler() is also useful (mainly on windows anyway)\n for trying to determine whether MSVC++ or gcc is available.\n MSVC doesn't handle templates as well, so some of the code emitted\n by the python->C conversions need this info to choose what kind\n of code to create.\n \n The other main thing here is an alternative version of the MingW32\n compiler class. The class makes it possible to build libraries with\n gcc even if the original version of python was built using MSVC. It\n does this by converting a pythonxx.lib file to a libpythonxx.a file.\n Note that you need write access to the pythonxx/lib directory to do this.\n\"\"\"\n\nimport sys,os,string,time\nimport tempfile\nimport exceptions\n\n# If linker is 'gcc', this will convert it to 'g++'\n# necessary to make sure stdc++ is linked in cross-platform way.\nimport distutils.sysconfig\n\nold_init_posix = distutils.sysconfig._init_posix\n\ndef _init_posix():\n old_init_posix()\n ld = distutils.sysconfig._config_vars['LDSHARED']\n #distutils.sysconfig._config_vars['LDSHARED'] = ld.replace('gcc','g++')\n # FreeBSD names gcc as cc, so the above find and replace doesn't work. \n # So, assume first entry in ld is the name of the linker -- gcc or cc or \n # whatever. This is a sane assumption, correct?\n # If the linker is gcc, set it to g++\n link_cmds = ld.split() \n if gcc_exists(link_cmds[0]):\n link_cmds[0] = 'g++'\n ld = ' '.join(link_cmds)\n distutils.sysconfig._config_vars['LDSHARED'] = ld \n\ndistutils.sysconfig._init_posix = _init_posix \n# end force g++\n\n\nclass CompileError(exceptions.Exception):\n pass\n \ndef build_extension(module_path,compiler_name = '',build_dir = None,\n temp_dir = None, verbose = 0, **kw):\n \"\"\" Build the file given by module_path into a Python extension module.\n \n build_extensions uses distutils to build Python extension modules.\n kw arguments not used are passed on to the distutils extension\n module. Directory settings can handle absoulte settings, but don't\n currently expand '~' or environment variables.\n \n module_path -- the full path name to the c file to compile. \n Something like: /full/path/name/module_name.c \n The name of the c/c++ file should be the same as the\n name of the module (i.e. the initmodule() routine)\n compiler_name -- The name of the compiler to use. On Windows if it \n isn't given, MSVC is used if it exists (is found).\n gcc is used as a second choice. If neither are found, \n the default distutils compiler is used. Acceptable \n names are 'gcc', 'msvc' or any of the compiler names \n shown by distutils.ccompiler.show_compilers()\n build_dir -- The location where the resulting extension module \n should be placed. This location must be writable. If\n it isn't, several default locations are tried. If the \n build_dir is not in the current python path, a warning\n is emitted, and it is added to the end of the path.\n build_dir defaults to the current directory.\n temp_dir -- The location where temporary files (*.o or *.obj)\n from the build are placed. This location must be \n writable. If it isn't, several default locations are \n tried. It defaults to tempfile.gettempdir()\n verbose -- 0, 1, or 2. 0 is as quiet as possible. 1 prints\n minimal information. 2 is noisy. \n **kw -- keyword arguments. These are passed on to the \n distutils extension module. Most of the keywords\n are listed below.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n \n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list \n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability) \n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line) \n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n success = 0\n from distutils.core import setup, Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n compiler_name = choose_compiler(compiler_name)\n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n try:\n if verbose == 1:\n print 'Compiling code...'\n \n # set compiler verboseness 2 or more makes it output results\n if verbose > 1: verb = 1 \n else: verb = 0\n \n t1 = time.time() \n # add module to the needed source code files and build extension\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n \n # ! This was fixed at beginning of file by using g++ on most \n # !machines. We'll have to check how to handle it on non-gcc machines \n ## add module to the needed source code files and build extension\n ## FIX this is g++ specific. It probably should be fixed for other\n ## Unices/compilers. Find a generic solution\n #if compiler_name != 'msvc':\n # libraries = kw.get('libraries',[])\n # kw['libraries'] = ['stdc++'] + libraries \n # !\n \n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n platform = sys.platform\n version = sys.version.lower()\n if platform[:5] == 'sunos' and version.find('gcc') != -1:\n extra_link_args = kw.get('extra_link_args',[])\n kw['extra_link_args'] = ['-mimpure-text'] + extra_link_args\n \n ext = Extension(module_name, **kw)\n \n # the switcheroo on SystemExit here is meant to keep command line\n # sessions from exiting when compiles fail.\n builtin = sys.modules['__builtin__']\n old_SysExit = builtin.__dict__['SystemExit']\n builtin.__dict__['SystemExit'] = CompileError\n \n # distutils for MSVC messes with the environment, so we save the\n # current state and restore them afterward.\n import copy\n environ = copy.deepcopy(os.environ)\n try:\n setup(name = module_name, ext_modules = [ext],verbose=verb)\n finally:\n # restore state\n os.environ = environ \n # restore SystemExit\n builtin.__dict__['SystemExit'] = old_SysExit\n t2 = time.time()\n \n if verbose == 1:\n print 'finished compiling (sec): ', t2 - t1 \n success = 1\n configure_python_path(build_dir)\n except SyntaxError: #TypeError:\n success = 0 \n \n # restore argv after our trick... \n restore_sys_argv()\n \n return success\n\nold_argv = []\ndef configure_sys_argv(compiler_name,temp_dir,build_dir):\n # We're gonna play some tricks with argv here to pass info to distutils \n # which is really built for command line use. better way??\n global old_argv\n old_argv = sys.argv[:] \n sys.argv = ['','build_ext','--build-lib', build_dir,\n '--build-temp',temp_dir] \n if compiler_name == 'gcc':\n sys.argv.insert(2,'--compiler='+compiler_name)\n elif compiler_name:\n sys.argv.insert(2,'--compiler='+compiler_name)\n\ndef restore_sys_argv():\n sys.argv = old_argv\n \ndef configure_python_path(build_dir): \n #make sure the module lives in a directory on the python path.\n python_paths = [os.path.abspath(x) for x in sys.path]\n if os.path.abspath(build_dir) not in python_paths:\n #print \"warning: build directory was not part of python path.\"\\\n # \" It has been appended to the path.\"\n sys.path.append(os.path.abspath(build_dir))\n\ndef choose_compiler(compiler_name=''):\n \"\"\" Try and figure out which compiler is gonna be used on windows.\n On other platforms, it just returns whatever value it is given.\n \n converts 'gcc' to 'mingw32' on win32\n \"\"\"\n if sys.platform == 'win32': \n if not compiler_name:\n # On Windows, default to MSVC and use gcc if it wasn't found\n # wasn't found. If neither are found, go with whatever\n # the default is for distutils -- and probably fail...\n if msvc_exists():\n compiler_name = 'msvc'\n elif gcc_exists():\n compiler_name = 'mingw32'\n elif compiler_name == 'gcc':\n compiler_name = 'mingw32'\n else:\n # don't know how to force gcc -- look into this.\n if compiler_name == 'gcc':\n compiler_name = 'unix' \n return compiler_name\n \ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n version = distutils.msvccompiler.get_devstudio_version()\n if version:\n result = 1\n return result\n\ndef configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n print \"warning: specified temp_dir '%s' does not exist \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n\n # final check that that directories are writable. \n if not os.access(temp_dir,os.W_OK):\n msg = \"Either the temp or build directory wasn't writable. Check\" \\\n \" these locations: '%s'\" % temp_dir \n raise ValueError, msg\n return temp_dir\n\ndef configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n print \"warning: specified build_dir '%s' does not exist \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n if build_dir is None:\n #default to building in the home directory of the given module. \n build_dir = os.curdir\n # if it doesn't work use the current directory. This should always\n # be writable. \n if not os.access(build_dir,os.W_OK):\n print \"warning:, neither the module's directory nor the \"\\\n \"current directory are writable. Using the temporary\"\\\n \"directory.\"\n build_dir = tempfile.gettempdir()\n\n # final check that that directories are writable.\n if not os.access(build_dir,os.W_OK):\n msg = \"The build directory wasn't writable. Check\" \\\n \" this location: '%s'\" % build_dir\n raise ValueError, msg\n \n return os.path.abspath(build_dir) \n \nif sys.platform == 'win32':\n import distutils.cygwinccompiler\n # the same as cygwin plus some additional parameters\n class Mingw32CCompiler (distutils.cygwinccompiler.CygwinCCompiler):\n \"\"\" A modified MingW32 compiler compatible with an MSVC built Python.\n \n \"\"\"\n \n compiler_type = 'mingw32'\n \n def __init__ (self,\n verbose=0,\n dry_run=0,\n force=0):\n \n distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose, \n dry_run, force)\n \n # A real mingw32 doesn't need to specify a different entry point,\n # but cygwin 2.91.57 in no-cygwin-mode needs it.\n if self.gcc_version <= \"2.91.57\":\n entry_point = '--entry _DllMain@12'\n else:\n entry_point = ''\n if self.linker_dll == 'dllwrap':\n self.linker = 'dllwrap' + ' --driver-name g++'\n elif self.linker_dll == 'gcc':\n self.linker = 'g++' \n # **changes: eric jones 4/11/01\n # 1. Check for import library on Windows. Build if it doesn't exist.\n if not import_library_exists():\n build_import_library()\n \n # **changes: eric jones 4/11/01\n # 2. increased optimization and turned off all warnings\n # 3. also added --driver-name g++\n #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n # compiler_so='gcc -mno-cygwin -mdll -O2 -w',\n # linker_exe='gcc -mno-cygwin',\n # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' \n # % (self.linker, entry_point))\n self.set_executables(compiler='g++ -mno-cygwin -O2 -w',\n compiler_so='g++ -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',\n linker_exe='g++ -mno-cygwin',\n linker_so='%s -mno-cygwin -mdll -static %s' \n % (self.linker, entry_point))\n \n # Maybe we should also append -mthreads, but then the finished\n # dlls need another dll (mingwm10.dll see Mingw32 docs)\n # (-mthreads: Support thread-safe exception handling on `Mingw32') \n \n # no additional libraries needed \n self.dll_libraries=[]\n \n # __init__ ()\n \n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n # We should also check the version of gcc available...\n #distutils.ccompiler._default_compilers['nt'] = 'mingw32'\n #distutils.ccompiler._default_compilers = (('nt', 'mingw32'))\n # reset the Mingw32 compiler in distutils to the one defined above\n distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler\n \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if os.name == 'nt':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n import lib2def as lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print 'WARNING: failed to build import library for gcc. Linking will fail.'\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\n\n\n", "source_code_before": "\"\"\" Tools for compiling C/C++ code to extension modules\n\n The main function, build_extension(), takes the C/C++ file\n along with some other options and builds a Python extension.\n It uses distutils for most of the heavy lifting.\n \n choose_compiler() is also useful (mainly on windows anyway)\n for trying to determine whether MSVC++ or gcc is available.\n MSVC doesn't handle templates as well, so some of the code emitted\n by the python->C conversions need this info to choose what kind\n of code to create.\n \n The other main thing here is an alternative version of the MingW32\n compiler class. The class makes it possible to build libraries with\n gcc even if the original version of python was built using MSVC. It\n does this by converting a pythonxx.lib file to a libpythonxx.a file.\n Note that you need write access to the pythonxx/lib directory to do this.\n\"\"\"\n\nimport sys,os,string,time\nimport tempfile\nimport exceptions\n\n# If linker is 'gcc', this will convert it to 'g++'\n# necessary to make sure stdc++ is linked in cross-platform way.\nimport distutils.sysconfig\n\nold_init_posix = distutils.sysconfig._init_posix\n\ndef _init_posix():\n old_init_posix()\n ld = distutils.sysconfig._config_vars['LDSHARED']\n #distutils.sysconfig._config_vars['LDSHARED'] = ld.replace('gcc','g++')\n # FreeBSD names gcc as cc, so the above find and replace doesn't work. \n # So, assume first entry in ld is the name of the linker -- gcc or cc or \n # whatever. This is a sane assumption, correct?\n # If the linker is gcc, set it to g++\n link_cmds = ld.split() \n if gcc_exists(link_cmds[0]):\n link_cmds[0] = 'g++'\n ld = ' '.join(link_cmds)\n distutils.sysconfig._config_vars['LDSHARED'] = ld \n\ndistutils.sysconfig._init_posix = _init_posix \n# end force g++\n\n\nclass CompileError(exceptions.Exception):\n pass\n \ndef build_extension(module_path,compiler_name = '',build_dir = None,\n temp_dir = None, verbose = 0, **kw):\n \"\"\" Build the file given by module_path into a Python extension module.\n \n build_extensions uses distutils to build Python extension modules.\n kw arguments not used are passed on to the distutils extension\n module. Directory settings can handle absoulte settings, but don't\n currently expand '~' or environment variables.\n \n module_path -- the full path name to the c file to compile. \n Something like: /full/path/name/module_name.c \n The name of the c/c++ file should be the same as the\n name of the module (i.e. the initmodule() routine)\n compiler_name -- The name of the compiler to use. On Windows if it \n isn't given, MSVC is used if it exists (is found).\n gcc is used as a second choice. If neither are found, \n the default distutils compiler is used. Acceptable \n names are 'gcc', 'msvc' or any of the compiler names \n shown by distutils.ccompiler.show_compilers()\n build_dir -- The location where the resulting extension module \n should be placed. This location must be writable. If\n it isn't, several default locations are tried. If the \n build_dir is not in the current python path, a warning\n is emitted, and it is added to the end of the path.\n build_dir defaults to the current directory.\n temp_dir -- The location where temporary files (*.o or *.obj)\n from the build are placed. This location must be \n writable. If it isn't, several default locations are \n tried. It defaults to tempfile.gettempdir()\n verbose -- 0, 1, or 2. 0 is as quiet as possible. 1 prints\n minimal information. 2 is noisy. \n **kw -- keyword arguments. These are passed on to the \n distutils extension module. Most of the keywords\n are listed below.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n \n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list \n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability) \n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line) \n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n success = 0\n from distutils.core import setup, Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n compiler_name = choose_compiler(compiler_name)\n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n try:\n if verbose == 1:\n print 'Compiling code...'\n \n # set compiler verboseness 2 or more makes it output results\n if verbose > 1: verb = 1 \n else: verb = 0\n \n t1 = time.time() \n # add module to the needed source code files and build extension\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n \n # ! This was fixed at beginning of file by using g++ on most \n # !machines. We'll have to check how to handle it on non-gcc machines \n ## add module to the needed source code files and build extension\n ## FIX this is g++ specific. It probably should be fixed for other\n ## Unices/compilers. Find a generic solution\n #if compiler_name != 'msvc':\n # libraries = kw.get('libraries',[])\n # kw['libraries'] = ['stdc++'] + libraries \n # !\n \n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n platform = sys.platform\n version = sys.version.lower()\n if platform[:5] == 'sunos' and version.find('gcc') != -1:\n extra_link_args = kw.get('extra_link_args',[])\n kw['extra_link_args'] = ['-mimpure-text'] + extra_link_args\n \n ext = Extension(module_name, **kw)\n \n # the switcheroo on SystemExit here is meant to keep command line\n # sessions from exiting when compiles fail.\n builtin = sys.modules['__builtin__']\n old_SysExit = builtin.__dict__['SystemExit']\n builtin.__dict__['SystemExit'] = CompileError\n \n # distutils for MSVC messes with the environment, so we save the\n # current state and restore them afterward.\n import copy\n environ = copy.deepcopy(os.environ)\n try:\n setup(name = module_name, ext_modules = [ext],verbose=verb)\n finally:\n # restore state\n os.environ = environ \n # restore SystemExit\n builtin.__dict__['SystemExit'] = old_SysExit\n t2 = time.time()\n \n if verbose == 1:\n print 'finished compiling (sec): ', t2 - t1 \n success = 1\n configure_python_path(build_dir)\n except SyntaxError: #TypeError:\n success = 0 \n \n # restore argv after our trick... \n restore_sys_argv()\n \n return success\n\nold_argv = []\ndef configure_sys_argv(compiler_name,temp_dir,build_dir):\n # We're gonna play some tricks with argv here to pass info to distutils \n # which is really built for command line use. better way??\n global old_argv\n old_argv = sys.argv[:] \n sys.argv = ['','build_ext','--build-lib', build_dir,\n '--build-temp',temp_dir] \n if compiler_name == 'gcc':\n sys.argv.insert(2,'--compiler='+compiler_name)\n elif compiler_name:\n sys.argv.insert(2,'--compiler='+compiler_name)\n\ndef restore_sys_argv():\n sys.argv = old_argv\n \ndef configure_python_path(build_dir): \n #make sure the module lives in a directory on the python path.\n python_paths = [os.path.abspath(x) for x in sys.path]\n if os.path.abspath(build_dir) not in python_paths:\n #print \"warning: build directory was not part of python path.\"\\\n # \" It has been appended to the path.\"\n sys.path.append(os.path.abspath(build_dir))\n\ndef choose_compiler(compiler_name=''):\n \"\"\" Try and figure out which compiler is gonna be used on windows.\n On other platforms, it just returns whatever value it is given.\n \n converts 'gcc' to 'mingw32' on win32\n \"\"\"\n if sys.platform == 'win32': \n if not compiler_name:\n # On Windows, default to MSVC and use gcc if it wasn't found\n # wasn't found. If neither are found, go with whatever\n # the default is for distutils -- and probably fail...\n if msvc_exists():\n compiler_name = 'msvc'\n elif gcc_exists():\n compiler_name = 'mingw32'\n elif compiler_name == 'gcc':\n compiler_name = 'mingw32'\n else:\n # don't know how to force gcc -- look into this.\n if compiler_name == 'gcc':\n compiler_name = 'unix' \n return compiler_name\n \ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n version = distutils.msvccompiler.get_devstudio_version()\n if version:\n result = 1\n return result\n\ndef configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n print \"warning: specified temp_dir '%s' does not exist \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n\n # final check that that directories are writable. \n if not os.access(temp_dir,os.W_OK):\n msg = \"Either the temp or build directory wasn't writable. Check\" \\\n \" these locations: '%s'\" % temp_dir \n raise ValueError, msg\n return temp_dir\n\ndef configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n print \"warning: specified build_dir '%s' does not exist \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n if build_dir is None:\n #default to building in the home directory of the given module. \n build_dir = os.curdir\n # if it doesn't work use the current directory. This should always\n # be writable. \n if not os.access(build_dir,os.W_OK):\n print \"warning:, neither the module's directory nor the \"\\\n \"current directory are writable. Using the temporary\"\\\n \"directory.\"\n build_dir = tempfile.gettempdir()\n\n # final check that that directories are writable.\n if not os.access(build_dir,os.W_OK):\n msg = \"The build directory wasn't writable. Check\" \\\n \" this location: '%s'\" % build_dir\n raise ValueError, msg\n \n return os.path.abspath(build_dir) \n \nif sys.platform == 'win32':\n import distutils.cygwinccompiler\n # the same as cygwin plus some additional parameters\n class Mingw32CCompiler (distutils.cygwinccompiler.CygwinCCompiler):\n \"\"\" A modified MingW32 compiler compatible with an MSVC built Python.\n \n \"\"\"\n \n compiler_type = 'mingw32'\n \n def __init__ (self,\n verbose=0,\n dry_run=0,\n force=0):\n \n distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose, \n dry_run, force)\n \n # A real mingw32 doesn't need to specify a different entry point,\n # but cygwin 2.91.57 in no-cygwin-mode needs it.\n if self.gcc_version <= \"2.91.57\":\n entry_point = '--entry _DllMain@12'\n else:\n entry_point = ''\n if self.linker_dll == 'dllwrap':\n self.linker = 'dllwrap' + ' --driver-name g++'\n elif self.linker_dll == 'gcc':\n self.linker = 'g++' \n # **changes: eric jones 4/11/01\n # 1. Check for import library on Windows. Build if it doesn't exist.\n if not import_library_exists():\n build_import_library()\n \n # **changes: eric jones 4/11/01\n # 2. increased optimization and turned off all warnings\n # 3. also added --driver-name g++\n #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n # compiler_so='gcc -mno-cygwin -mdll -O2 -w',\n # linker_exe='gcc -mno-cygwin',\n # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' \n # % (self.linker, entry_point))\n self.set_executables(compiler='g++ -mno-cygwin -O2 -w',\n compiler_so='g++ -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',\n linker_exe='g++ -mno-cygwin',\n linker_so='%s -mno-cygwin -mdll -static %s' \n % (self.linker, entry_point))\n \n # Maybe we should also append -mthreads, but then the finished\n # dlls need another dll (mingwm10.dll see Mingw32 docs)\n # (-mthreads: Support thread-safe exception handling on `Mingw32') \n \n # no additional libraries needed \n self.dll_libraries=[]\n \n # __init__ ()\n \n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n # We should also check the version of gcc available...\n #distutils.ccompiler._default_compilers['nt'] = 'mingw32'\n #distutils.ccompiler._default_compilers = (('nt', 'mingw32'))\n # reset the Mingw32 compiler in distutils to the one defined above\n distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler\n \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if os.name == 'nt':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n import lib2def as lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print 'WARNING: failed to build import library for gcc. Linking will fail.'\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\n\n\n", "methods": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [], "start_line": 30, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 49, "complexity": 9, "token_count": 364, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 51, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 171, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name , temp_dir , build_dir )", "filename": "build_tools.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [ "compiler_name", "temp_dir", "build_dir" ], "start_line": 224, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "build_tools.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 236, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "configure_python_path", "long_name": "configure_python_path( build_dir )", "filename": "build_tools.py", "nloc": 4, "complexity": 3, "token_count": 51, "parameters": [ "build_dir" ], "start_line": 239, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "build_tools.py", "nloc": 13, "complexity": 7, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 247, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 270, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "build_tools.py", "nloc": 14, "complexity": 4, "token_count": 71, "parameters": [], "start_line": 292, "end_line": 309, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 311, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 327, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_tools.py", "nloc": 22, "complexity": 5, "token_count": 117, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 364, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 2 }, { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "build_tools.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 418, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 428, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 459, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 463, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [], "start_line": 30, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 49, "complexity": 9, "token_count": 364, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 51, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 171, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name , temp_dir , build_dir )", "filename": "build_tools.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [ "compiler_name", "temp_dir", "build_dir" ], "start_line": 224, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "build_tools.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 236, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "configure_python_path", "long_name": "configure_python_path( build_dir )", "filename": "build_tools.py", "nloc": 4, "complexity": 3, "token_count": 51, "parameters": [ "build_dir" ], "start_line": 239, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "build_tools.py", "nloc": 13, "complexity": 7, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 247, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 270, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "build_tools.py", "nloc": 14, "complexity": 4, "token_count": 71, "parameters": [], "start_line": 292, "end_line": 309, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 311, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 327, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_tools.py", "nloc": 22, "complexity": 5, "token_count": 117, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 364, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 2 }, { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "build_tools.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 418, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 428, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 459, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 463, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 463, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 459, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 230, "complexity": 56, "token_count": 1440, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "weave/c_spec.py", "new_path": "weave/c_spec.py", "filename": "c_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -193,6 +193,17 @@ def init_info(self):\n self.check_func = 'PyInstance_Check' \n self.matching_types = [InstanceType]\n \n+#----------------------------------------------------------------------------\n+# Catchall Converter\n+#----------------------------------------------------------------------------\n+class catchall_converter(common_base_converter):\n+ def init_info(self):\n+ common_base_converter.init_info(self)\n+ self.type_name = 'catchall'\n+ self.check_func = '' \n+ def type_match(self,value):\n+ return 1\n+\n #----------------------------------------------------------------------------\n # String Converter\n #----------------------------------------------------------------------------\n@@ -407,11 +418,11 @@ def init_info(self):\n self.use_ref_count = 0\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n if __name__ == \"__main__\":\n", "added_lines": 13, "deleted_lines": 2, "source_code": "from types import *\nfrom base_spec import base_converter\nimport base_info\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from python objects to C++ objects\n#\n# This is silly code. There is absolutely no reason why these simple\n# conversion functions should be classes. However, some versions of \n# Mandrake Linux ship with broken C++ compilers (or libraries) that do not\n# handle exceptions correctly when they are thrown from functions. However,\n# exceptions thrown from class methods always work, so we make everything\n# a class method to solve this error.\n#----------------------------------------------------------------------------\n\npy_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic: \n %(c_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // Incref occurs even if conversion fails so that\n // the decref in cleanup_code has a matching incref.\n %(inc_ref_count)s\n if (!py_obj || !%(check_func)s(py_obj))\n handle_conversion_error(py_obj,\"%(type_name)s\", name); \n return %(to_c_return)s;\n }\n \n %(c_type)s py_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // !! Pretty sure INCREF should only be called on success since\n // !! py_to_xxx is used by the user -- not the code generator.\n if (!py_obj || !%(check_func)s(py_obj))\n handle_bad_type(py_obj,\"%(type_name)s\", name); \n %(inc_ref_count)s\n return %(to_c_return)s;\n }\n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from C++ objects to Python objects\n#\n#----------------------------------------------------------------------------\n\nsimple_c_to_py_template = \\\n\"\"\"\nPyObject* %(type_name)s_to_py(PyObject* obj)\n{\n return (PyObject*) obj;\n}\n\n\"\"\"\n\nclass common_base_converter(base_converter):\n \n def __init__(self):\n self.init_info()\n self._build_information = [self.generate_build_info()]\n \n def init_info(self):\n self.matching_types = []\n self.headers = []\n self.include_dirs = []\n self.libraries = []\n self.library_dirs = []\n self.sources = []\n self.support_code = []\n self.module_init_code = []\n self.warnings = []\n self.define_macros = []\n self.use_ref_count = 1\n self.name = \"no_name\"\n self.c_type = 'PyObject*'\n self.to_c_return = 'py_obj'\n \n def info_object(self):\n return base_info.custom_info()\n \n def generate_build_info(self):\n info = self.info_object()\n for header in self.headers:\n info.add_header(header)\n for d in self.include_dirs:\n info.add_include_dir(d)\n for lib in self.libraries:\n info.add_library(lib)\n for d in self.library_dirs:\n info.add_library_dir(d)\n for source in self.sources:\n info.add_source(source)\n for code in self.support_code:\n info.add_support_code(code)\n info.add_support_code(self.py_to_c_code())\n info.add_support_code(self.c_to_py_code())\n for init_code in self.module_init_code:\n info.add_module_init_code(init_code)\n for macro in self.define_macros:\n info.add_define_macro(macro)\n for warning in self.warnings:\n info.add_warning(warning)\n return info\n\n def type_match(self,value):\n return type(value) in self.matching_types\n\n def get_var_type(self,value):\n return type(value)\n \n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n new_spec.var_type = self.get_var_type(value)\n return new_spec\n\n def template_vars(self,inline=0):\n d = {}\n d['type_name'] = self.type_name\n d['check_func'] = self.check_func\n d['c_type'] = self.c_type\n d['to_c_return'] = self.to_c_return\n d['name'] = self.name\n d['py_var'] = self.py_variable()\n d['var_lookup'] = self.retrieve_py_variable(inline)\n code = 'convert_to_%(type_name)s(%(py_var)s,\"%(name)s\")' % d\n d['var_convert'] = code\n if self.use_ref_count:\n d['inc_ref_count'] = \"Py_INCREF(py_obj);\"\n else:\n d['inc_ref_count'] = \"\"\n return d\n\n def py_to_c_code(self):\n return py_to_c_template % self.template_vars()\n\n def c_to_py_code(self):\n return simple_c_to_py_template % self.template_vars()\n \n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(name)s = %(var_convert)s;\\n' % \\\n self.template_vars(inline=inline)\n return code \n\n def cleanup_code(self):\n if self.use_ref_count:\n code = \"Py_XDECREF(%(py_var)s);\\n\" % self.template_vars()\n else:\n code = \"\" \n return code\n \n def __repr__(self):\n msg = \"(file:: name: %s)\" % self.name\n return msg\n def __cmp__(self,other):\n #only works for equal\n result = -1\n try:\n result = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n except AttributeError:\n pass\n return result \n\n#----------------------------------------------------------------------------\n# Module Converter\n#----------------------------------------------------------------------------\nclass module_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'module'\n self.check_func = 'PyModule_Check' \n # probably should test for callable classes here also.\n self.matching_types = [ModuleType]\n\n#----------------------------------------------------------------------------\n# Instance Converter\n#----------------------------------------------------------------------------\nclass instance_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'instance'\n self.check_func = 'PyInstance_Check' \n self.matching_types = [InstanceType]\n\n#----------------------------------------------------------------------------\n# Catchall Converter\n#----------------------------------------------------------------------------\nclass catchall_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'catchall'\n self.check_func = '' \n def type_match(self,value):\n return 1\n\n#----------------------------------------------------------------------------\n# String Converter\n#----------------------------------------------------------------------------\nclass string_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'string'\n self.check_func = 'PyString_Check' \n self.c_type = 'std::string'\n self.to_c_return = \"std::string(PyString_AsString(py_obj))\"\n self.matching_types = [StringType]\n self.headers.append('')\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* string_to_py(std::string s)\n {\n return PyString_FromString(s.c_str());\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n# Unicode Converter\n#----------------------------------------------------------------------------\nclass unicode_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'unicode'\n self.check_func = 'PyUnicode_Check'\n # This isn't supported by gcc 2.95.3 -- MSVC works fine with it. \n #self.c_type = 'std::wstring'\n #self.to_c_return = \"std::wstring(PyUnicode_AS_UNICODE(py_obj))\"\n self.c_type = 'Py_UNICODE*'\n self.to_c_return = \"PyUnicode_AS_UNICODE(py_obj)\"\n self.matching_types = [UnicodeType]\n #self.headers.append('')\n#----------------------------------------------------------------------------\n# File Converter\n#----------------------------------------------------------------------------\nclass file_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'file'\n self.check_func = 'PyFile_Check' \n self.c_type = 'FILE*'\n self.to_c_return = \"PyFile_AsFile(py_obj)\"\n self.headers = ['']\n self.matching_types = [FileType]\n\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* file_to_py(FILE* file, char* name, char* mode)\n {\n PyObject* py_obj = NULL;\n //extern int fclose(FILE *);\n return (PyObject*) PyFile_FromFile(file, name, mode, fclose);\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n#\n# Scalar Number Conversions\n#\n#----------------------------------------------------------------------------\n\n# the following typemaps are for 32 bit platforms. A way to do this\n# general case? maybe ask numeric types how long they are and base\n# the decisions on that.\n\n#----------------------------------------------------------------------------\n# Standard Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types = {}\nnum_to_c_types[type(1)] = 'int'\nnum_to_c_types[type(1.)] = 'double'\nnum_to_c_types[type(1.+1.j)] = 'std::complex '\n# !! hmmm. The following is likely unsafe...\nnum_to_c_types[type(1L)] = 'int'\n\n#----------------------------------------------------------------------------\n# Numeric array Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types['T'] = 'T' # for templates\nnum_to_c_types['F'] = 'std::complex '\nnum_to_c_types['D'] = 'std::complex '\nnum_to_c_types['f'] = 'float'\nnum_to_c_types['d'] = 'double'\nnum_to_c_types['1'] = 'char'\nnum_to_c_types['b'] = 'unsigned char'\nnum_to_c_types['s'] = 'short'\nnum_to_c_types['i'] = 'int'\n# not strictly correct, but shoulld be fine fo numeric work.\n# add test somewhere to make sure long can be cast to int before using.\nnum_to_c_types['l'] = 'int'\n\nclass scalar_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.warnings = ['disable: 4275', 'disable: 4101']\n self.headers = ['','']\n self.use_ref_count = 0\n\nclass int_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'int'\n self.check_func = 'PyInt_Check' \n self.c_type = 'int'\n self.to_c_return = \"(int) PyInt_AsLong(py_obj)\"\n self.matching_types = [IntType]\n\nclass long_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # !! long to int conversion isn't safe!\n self.type_name = 'long'\n self.check_func = 'PyLong_Check' \n self.c_type = 'int'\n self.to_c_return = \"(int) PyLong_AsLong(py_obj)\"\n self.matching_types = [LongType]\n\nclass float_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # Not sure this is really that safe...\n self.type_name = 'float'\n self.check_func = 'PyFloat_Check' \n self.c_type = 'double'\n self.to_c_return = \"PyFloat_AsDouble(py_obj)\"\n self.matching_types = [FloatType]\n\nclass complex_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'complex'\n self.check_func = 'PyComplex_Check' \n self.c_type = 'std::complex'\n self.to_c_return = \"std::complex(PyComplex_RealAsDouble(py_obj),\"\\\n \"PyComplex_ImagAsDouble(py_obj))\"\n self.matching_types = [ComplexType]\n\n#----------------------------------------------------------------------------\n#\n# List, Tuple, and Dict converters.\n#\n# Based on SCXX by Gordon McMillan\n#----------------------------------------------------------------------------\nimport os, c_spec # yes, I import myself to find out my __file__ location.\nlocal_dir,junk = os.path.split(os.path.abspath(c_spec.__file__)) \nscxx_dir = os.path.join(local_dir,'scxx')\n\nclass scxx_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.headers = ['\"scxx/PWOBase.h\"','\"scxx/PWOSequence.h\"',\n '\"scxx/PWOCallable.h\"','\"scxx/PWOMapping.h\"',\n '\"scxx/PWOSequence.h\"','\"scxx/PWOMSequence.h\"',\n '\"scxx/PWONumber.h\"','']\n self.include_dirs = [local_dir,scxx_dir]\n self.sources = [os.path.join(scxx_dir,'PWOImp.cpp'),]\n\nclass list_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'list'\n self.check_func = 'PyList_Check' \n self.c_type = 'PWOList'\n self.to_c_return = 'PWOList(py_obj)'\n self.matching_types = [ListType]\n # ref counting handled by PWOList\n self.use_ref_count = 0\n\nclass tuple_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'tuple'\n self.check_func = 'PyTuple_Check' \n self.c_type = 'PWOTuple'\n self.to_c_return = 'PWOTuple(py_obj)'\n self.matching_types = [TupleType]\n # ref counting handled by PWOTuple\n self.use_ref_count = 0\n\nclass dict_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.support_code.append(\"#define PWODict PWOMapping\")\n self.type_name = 'dict'\n self.check_func = 'PyDict_Check' \n self.c_type = 'PWODict'\n self.to_c_return = 'PWODict(py_obj)'\n self.matching_types = [DictType]\n # ref counting handled by PWODict\n self.use_ref_count = 0\n\n#----------------------------------------------------------------------------\n# Callable Converter\n#----------------------------------------------------------------------------\nclass callable_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'callable'\n self.check_func = 'PyCallable_Check' \n # probably should test for callable classes here also.\n self.matching_types = [FunctionType,MethodType,type(len)]\n self.c_type = 'PWOCallable'\n self.to_c_return = 'PWOCallable(py_obj)'\n # ref counting handled by PWOCallable\n self.use_ref_count = 0\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == \"__main__\":\n x = list_converter().type_spec(\"x\",1)\n print x.py_to_c_code()\n print\n print x.c_to_py_code()\n print\n print x.declaration_code(inline=1)\n print\n print x.cleanup_code()", "source_code_before": "from types import *\nfrom base_spec import base_converter\nimport base_info\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from python objects to C++ objects\n#\n# This is silly code. There is absolutely no reason why these simple\n# conversion functions should be classes. However, some versions of \n# Mandrake Linux ship with broken C++ compilers (or libraries) that do not\n# handle exceptions correctly when they are thrown from functions. However,\n# exceptions thrown from class methods always work, so we make everything\n# a class method to solve this error.\n#----------------------------------------------------------------------------\n\npy_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic: \n %(c_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // Incref occurs even if conversion fails so that\n // the decref in cleanup_code has a matching incref.\n %(inc_ref_count)s\n if (!py_obj || !%(check_func)s(py_obj))\n handle_conversion_error(py_obj,\"%(type_name)s\", name); \n return %(to_c_return)s;\n }\n \n %(c_type)s py_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // !! Pretty sure INCREF should only be called on success since\n // !! py_to_xxx is used by the user -- not the code generator.\n if (!py_obj || !%(check_func)s(py_obj))\n handle_bad_type(py_obj,\"%(type_name)s\", name); \n %(inc_ref_count)s\n return %(to_c_return)s;\n }\n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from C++ objects to Python objects\n#\n#----------------------------------------------------------------------------\n\nsimple_c_to_py_template = \\\n\"\"\"\nPyObject* %(type_name)s_to_py(PyObject* obj)\n{\n return (PyObject*) obj;\n}\n\n\"\"\"\n\nclass common_base_converter(base_converter):\n \n def __init__(self):\n self.init_info()\n self._build_information = [self.generate_build_info()]\n \n def init_info(self):\n self.matching_types = []\n self.headers = []\n self.include_dirs = []\n self.libraries = []\n self.library_dirs = []\n self.sources = []\n self.support_code = []\n self.module_init_code = []\n self.warnings = []\n self.define_macros = []\n self.use_ref_count = 1\n self.name = \"no_name\"\n self.c_type = 'PyObject*'\n self.to_c_return = 'py_obj'\n \n def info_object(self):\n return base_info.custom_info()\n \n def generate_build_info(self):\n info = self.info_object()\n for header in self.headers:\n info.add_header(header)\n for d in self.include_dirs:\n info.add_include_dir(d)\n for lib in self.libraries:\n info.add_library(lib)\n for d in self.library_dirs:\n info.add_library_dir(d)\n for source in self.sources:\n info.add_source(source)\n for code in self.support_code:\n info.add_support_code(code)\n info.add_support_code(self.py_to_c_code())\n info.add_support_code(self.c_to_py_code())\n for init_code in self.module_init_code:\n info.add_module_init_code(init_code)\n for macro in self.define_macros:\n info.add_define_macro(macro)\n for warning in self.warnings:\n info.add_warning(warning)\n return info\n\n def type_match(self,value):\n return type(value) in self.matching_types\n\n def get_var_type(self,value):\n return type(value)\n \n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n new_spec.var_type = self.get_var_type(value)\n return new_spec\n\n def template_vars(self,inline=0):\n d = {}\n d['type_name'] = self.type_name\n d['check_func'] = self.check_func\n d['c_type'] = self.c_type\n d['to_c_return'] = self.to_c_return\n d['name'] = self.name\n d['py_var'] = self.py_variable()\n d['var_lookup'] = self.retrieve_py_variable(inline)\n code = 'convert_to_%(type_name)s(%(py_var)s,\"%(name)s\")' % d\n d['var_convert'] = code\n if self.use_ref_count:\n d['inc_ref_count'] = \"Py_INCREF(py_obj);\"\n else:\n d['inc_ref_count'] = \"\"\n return d\n\n def py_to_c_code(self):\n return py_to_c_template % self.template_vars()\n\n def c_to_py_code(self):\n return simple_c_to_py_template % self.template_vars()\n \n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(name)s = %(var_convert)s;\\n' % \\\n self.template_vars(inline=inline)\n return code \n\n def cleanup_code(self):\n if self.use_ref_count:\n code = \"Py_XDECREF(%(py_var)s);\\n\" % self.template_vars()\n else:\n code = \"\" \n return code\n \n def __repr__(self):\n msg = \"(file:: name: %s)\" % self.name\n return msg\n def __cmp__(self,other):\n #only works for equal\n result = -1\n try:\n result = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n except AttributeError:\n pass\n return result \n\n#----------------------------------------------------------------------------\n# Module Converter\n#----------------------------------------------------------------------------\nclass module_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'module'\n self.check_func = 'PyModule_Check' \n # probably should test for callable classes here also.\n self.matching_types = [ModuleType]\n\n#----------------------------------------------------------------------------\n# Instance Converter\n#----------------------------------------------------------------------------\nclass instance_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'instance'\n self.check_func = 'PyInstance_Check' \n self.matching_types = [InstanceType]\n\n#----------------------------------------------------------------------------\n# String Converter\n#----------------------------------------------------------------------------\nclass string_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'string'\n self.check_func = 'PyString_Check' \n self.c_type = 'std::string'\n self.to_c_return = \"std::string(PyString_AsString(py_obj))\"\n self.matching_types = [StringType]\n self.headers.append('')\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* string_to_py(std::string s)\n {\n return PyString_FromString(s.c_str());\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n# Unicode Converter\n#----------------------------------------------------------------------------\nclass unicode_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'unicode'\n self.check_func = 'PyUnicode_Check'\n # This isn't supported by gcc 2.95.3 -- MSVC works fine with it. \n #self.c_type = 'std::wstring'\n #self.to_c_return = \"std::wstring(PyUnicode_AS_UNICODE(py_obj))\"\n self.c_type = 'Py_UNICODE*'\n self.to_c_return = \"PyUnicode_AS_UNICODE(py_obj)\"\n self.matching_types = [UnicodeType]\n #self.headers.append('')\n#----------------------------------------------------------------------------\n# File Converter\n#----------------------------------------------------------------------------\nclass file_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'file'\n self.check_func = 'PyFile_Check' \n self.c_type = 'FILE*'\n self.to_c_return = \"PyFile_AsFile(py_obj)\"\n self.headers = ['']\n self.matching_types = [FileType]\n\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* file_to_py(FILE* file, char* name, char* mode)\n {\n PyObject* py_obj = NULL;\n //extern int fclose(FILE *);\n return (PyObject*) PyFile_FromFile(file, name, mode, fclose);\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n#\n# Scalar Number Conversions\n#\n#----------------------------------------------------------------------------\n\n# the following typemaps are for 32 bit platforms. A way to do this\n# general case? maybe ask numeric types how long they are and base\n# the decisions on that.\n\n#----------------------------------------------------------------------------\n# Standard Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types = {}\nnum_to_c_types[type(1)] = 'int'\nnum_to_c_types[type(1.)] = 'double'\nnum_to_c_types[type(1.+1.j)] = 'std::complex '\n# !! hmmm. The following is likely unsafe...\nnum_to_c_types[type(1L)] = 'int'\n\n#----------------------------------------------------------------------------\n# Numeric array Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types['T'] = 'T' # for templates\nnum_to_c_types['F'] = 'std::complex '\nnum_to_c_types['D'] = 'std::complex '\nnum_to_c_types['f'] = 'float'\nnum_to_c_types['d'] = 'double'\nnum_to_c_types['1'] = 'char'\nnum_to_c_types['b'] = 'unsigned char'\nnum_to_c_types['s'] = 'short'\nnum_to_c_types['i'] = 'int'\n# not strictly correct, but shoulld be fine fo numeric work.\n# add test somewhere to make sure long can be cast to int before using.\nnum_to_c_types['l'] = 'int'\n\nclass scalar_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.warnings = ['disable: 4275', 'disable: 4101']\n self.headers = ['','']\n self.use_ref_count = 0\n\nclass int_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'int'\n self.check_func = 'PyInt_Check' \n self.c_type = 'int'\n self.to_c_return = \"(int) PyInt_AsLong(py_obj)\"\n self.matching_types = [IntType]\n\nclass long_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # !! long to int conversion isn't safe!\n self.type_name = 'long'\n self.check_func = 'PyLong_Check' \n self.c_type = 'int'\n self.to_c_return = \"(int) PyLong_AsLong(py_obj)\"\n self.matching_types = [LongType]\n\nclass float_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # Not sure this is really that safe...\n self.type_name = 'float'\n self.check_func = 'PyFloat_Check' \n self.c_type = 'double'\n self.to_c_return = \"PyFloat_AsDouble(py_obj)\"\n self.matching_types = [FloatType]\n\nclass complex_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'complex'\n self.check_func = 'PyComplex_Check' \n self.c_type = 'std::complex'\n self.to_c_return = \"std::complex(PyComplex_RealAsDouble(py_obj),\"\\\n \"PyComplex_ImagAsDouble(py_obj))\"\n self.matching_types = [ComplexType]\n\n#----------------------------------------------------------------------------\n#\n# List, Tuple, and Dict converters.\n#\n# Based on SCXX by Gordon McMillan\n#----------------------------------------------------------------------------\nimport os, c_spec # yes, I import myself to find out my __file__ location.\nlocal_dir,junk = os.path.split(os.path.abspath(c_spec.__file__)) \nscxx_dir = os.path.join(local_dir,'scxx')\n\nclass scxx_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.headers = ['\"scxx/PWOBase.h\"','\"scxx/PWOSequence.h\"',\n '\"scxx/PWOCallable.h\"','\"scxx/PWOMapping.h\"',\n '\"scxx/PWOSequence.h\"','\"scxx/PWOMSequence.h\"',\n '\"scxx/PWONumber.h\"','']\n self.include_dirs = [local_dir,scxx_dir]\n self.sources = [os.path.join(scxx_dir,'PWOImp.cpp'),]\n\nclass list_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'list'\n self.check_func = 'PyList_Check' \n self.c_type = 'PWOList'\n self.to_c_return = 'PWOList(py_obj)'\n self.matching_types = [ListType]\n # ref counting handled by PWOList\n self.use_ref_count = 0\n\nclass tuple_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'tuple'\n self.check_func = 'PyTuple_Check' \n self.c_type = 'PWOTuple'\n self.to_c_return = 'PWOTuple(py_obj)'\n self.matching_types = [TupleType]\n # ref counting handled by PWOTuple\n self.use_ref_count = 0\n\nclass dict_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.support_code.append(\"#define PWODict PWOMapping\")\n self.type_name = 'dict'\n self.check_func = 'PyDict_Check' \n self.c_type = 'PWODict'\n self.to_c_return = 'PWODict(py_obj)'\n self.matching_types = [DictType]\n # ref counting handled by PWODict\n self.use_ref_count = 0\n\n#----------------------------------------------------------------------------\n# Callable Converter\n#----------------------------------------------------------------------------\nclass callable_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'callable'\n self.check_func = 'PyCallable_Check' \n # probably should test for callable classes here also.\n self.matching_types = [FunctionType,MethodType,type(len)]\n self.c_type = 'PWOCallable'\n self.to_c_return = 'PWOCallable(py_obj)'\n # ref counting handled by PWOCallable\n self.use_ref_count = 0\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == \"__main__\":\n x = list_converter().type_spec(\"x\",1)\n print x.py_to_c_code()\n print\n print x.c_to_py_code()\n print\n print x.declaration_code(inline=1)\n print\n print x.cleanup_code()", "methods": [ { "name": "__init__", "long_name": "__init__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 15, "complexity": 1, "token_count": 85, "parameters": [ "self" ], "start_line": 70, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "info_object", "long_name": "info_object( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 86, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "c_spec.py", "nloc": 23, "complexity": 10, "token_count": 151, "parameters": [ "self" ], "start_line": 89, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 113, "end_line": 114, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_var_type", "long_name": "get_var_type( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "value" ], "start_line": 116, "end_line": 117, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 33, "parameters": [ "self", "name", "value" ], "start_line": 119, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "c_spec.py", "nloc": 16, "complexity": 2, "token_count": 106, "parameters": [ "self", "inline" ], "start_line": 126, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 143, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 146, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "self", "templatize", "inline" ], "start_line": 149, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "c_spec.py", "nloc": 6, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 155, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 162, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "c_spec.py", "nloc": 8, "complexity": 3, "token_count": 43, "parameters": [ "self", "other" ], "start_line": 165, "end_line": 173, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "self" ], "start_line": 179, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "self" ], "start_line": 190, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 4, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 200, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "value" ], "start_line": 204, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 46, "parameters": [ "self" ], "start_line": 211, "end_line": 218, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 219, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 233, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 248, "end_line": 255, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 10, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 257, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 306, "end_line": 310, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 313, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 322, "end_line": 329, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 332, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 342, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 362, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 372, "end_line": 380, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 383, "end_line": 391, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 394, "end_line": 403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 50, "parameters": [ "self" ], "start_line": 409, "end_line": 418, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 420, "end_line": 422, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 424, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 15, "complexity": 1, "token_count": 85, "parameters": [ "self" ], "start_line": 70, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "info_object", "long_name": "info_object( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 86, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "c_spec.py", "nloc": 23, "complexity": 10, "token_count": 151, "parameters": [ "self" ], "start_line": 89, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 113, "end_line": 114, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_var_type", "long_name": "get_var_type( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "value" ], "start_line": 116, "end_line": 117, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 33, "parameters": [ "self", "name", "value" ], "start_line": 119, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "c_spec.py", "nloc": 16, "complexity": 2, "token_count": 106, "parameters": [ "self", "inline" ], "start_line": 126, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 143, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 146, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "self", "templatize", "inline" ], "start_line": 149, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "c_spec.py", "nloc": 6, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 155, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 162, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "c_spec.py", "nloc": 8, "complexity": 3, "token_count": 43, "parameters": [ "self", "other" ], "start_line": 165, "end_line": 173, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "self" ], "start_line": 179, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "self" ], "start_line": 190, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 46, "parameters": [ "self" ], "start_line": 200, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 208, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 222, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 237, "end_line": 244, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 10, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 246, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 295, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 302, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 311, "end_line": 318, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 321, "end_line": 328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 331, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 351, "end_line": 358, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 361, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 372, "end_line": 380, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 383, "end_line": 392, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 50, "parameters": [ "self" ], "start_line": 398, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 409, "end_line": 411, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 413, "end_line": 415, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 4, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 200, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 424, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "value" ], "start_line": 204, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 420, "end_line": 422, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 320, "complexity": 48, "token_count": 1634, "diff_parsed": { "added": [ "#----------------------------------------------------------------------------", "# Catchall Converter", "#----------------------------------------------------------------------------", "class catchall_converter(common_base_converter):", " def init_info(self):", " common_base_converter.init_info(self)", " self.type_name = 'catchall'", " self.check_func = ''", " def type_match(self,value):", " return 1", "", " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "weave/catalog.py", "new_path": "weave/catalog.py", "filename": "catalog.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -674,9 +674,9 @@ def fast_cache(self,code,function):\n self.cache[code].insert(0,function)\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "added_lines": 2, "deleted_lines": 2, "source_code": "\"\"\" Track relationships between compiled extension functions & code fragments\n\n catalog keeps track of which compiled(or even standard) functions are \n related to which code fragments. It also stores these relationships\n to disk so they are remembered between Python sessions. When \n \n a = 1\n compiler.inline('printf(\"printed from C: %d\",a);',['a'] )\n \n is called, inline() first looks to see if it has seen the code \n 'printf(\"printed from C\");' before. If not, it calls \n \n catalog.get_functions('printf(\"printed from C: %d\", a);')\n \n which returns a list of all the function objects that have been compiled\n for the code fragment. Multiple functions can occur because the code\n could be compiled for different types for 'a' (although not likely in\n this case). The catalog first looks in its cache and quickly returns\n a list of the functions if possible. If the cache lookup fails, it then\n looks through possibly multiple catalog files on disk and fills its\n cache with all the functions that match the code fragment. \n \n In case where the code fragment hasn't been compiled, inline() compiles\n the code and then adds it to the catalog:\n \n function = \n catalog.add_function('printf(\"printed from C: %d\", a);',function)\n \n add_function() adds function to the front of the cache. function,\n along with the path information to its module, are also stored in a\n persistent catalog for future use by python sessions. \n\"\"\" \n\nimport os,sys,string\nimport pickle\nimport tempfile\n\ntry:\n import dbhash\n import shelve\n dumb = 0\nexcept ImportError:\n import dumb_shelve as shelve\n dumb = 1\n\n#For testing...\n#import dumb_shelve as shelve\n#dumb = 1\n\n#import shelve\n#dumb = 0\n \ndef getmodule(object):\n \"\"\" Discover the name of the module where object was defined.\n \n This is an augmented version of inspect.getmodule that can discover \n the parent module for extension functions.\n \"\"\"\n import inspect\n value = inspect.getmodule(object)\n if value is None:\n #walk trough all modules looking for function\n for name,mod in sys.modules.items():\n # try except used because of some comparison failures\n # in wxPoint code. Need to review this\n try:\n if mod and object in mod.__dict__.values():\n value = mod\n # if it is a built-in module, keep looking to see\n # if a non-builtin also has it. Otherwise quit and\n # consider the module found. (ain't perfect, but will \n # have to do for now).\n if string.find('(built-in)',str(mod)) is -1:\n break\n \n except (TypeError, KeyError):\n pass \n return value\n\ndef expr_to_filename(expr):\n \"\"\" Convert an arbitrary expr string to a valid file name.\n \n The name is based on the md5 check sum for the string and\n Something that was a little more human readable would be \n nice, but the computer doesn't seem to care.\n \"\"\"\n import md5\n base = 'sc_'\n return base + md5.new(expr).hexdigest()\n\ndef unique_file(d,expr):\n \"\"\" Generate a unqiue file name based on expr in directory d\n \n This is meant for use with building extension modules, so\n a file name is considered unique if none of the following\n extension '.cpp','.o','.so','module.so','.py', or '.pyd'\n exists in directory d. The fully qualified path to the\n new name is returned. You'll need to append your own\n extension to it before creating files.\n \"\"\"\n files = os.listdir(d)\n #base = 'scipy_compile'\n base = expr_to_filename(expr)\n for i in range(1000000):\n fname = base + `i`\n if not (fname+'.cpp' in files or\n fname+'.o' in files or\n fname+'.so' in files or\n fname+'module.so' in files or\n fname+'.py' in files or\n fname+'.pyd' in files):\n break\n return os.path.join(d,fname)\n\ndef create_dir(p):\n \"\"\" Create a directory and any necessary intermediate directories.\"\"\"\n if not os.path.exists(p):\n try:\n os.mkdir(p)\n except OSError:\n # perhaps one or more intermediate path components don't exist\n # try to create them\n base,dir = os.path.split(p)\n create_dir(base)\n # don't enclose this one in try/except - we want the user to\n # get failure info\n os.mkdir(p)\n\ndef is_writable(dir):\n dummy = os.path.join(dir, \"dummy\")\n try:\n open(dummy, 'w')\n except IOError:\n return 0\n os.unlink(dummy)\n return 1\n\ndef whoami():\n \"\"\"return a string identifying the user.\"\"\"\n return os.environ.get(\"USER\") or os.environ.get(\"USERNAME\") or \"unknown\"\n\ndef default_dir():\n \"\"\" Return a default location to store compiled files and catalogs.\n \n XX is the Python version number in all paths listed below\n On windows, the default location is the temporary directory\n returned by gettempdir()/pythonXX.\n \n On Unix, ~/.pythonXX_compiled is the default location. If it doesn't\n exist, it is created. The directory is marked rwx------.\n \n If for some reason it isn't possible to build a default directory\n in the user's home, /tmp/_pythonXX_compiled is used. If it \n doesn't exist, it is created. The directory is marked rwx------\n to try and keep people from being able to sneak a bad module\n in on you. \n \"\"\"\n python_name = \"python%d%d_compiled\" % tuple(sys.version_info[:2]) \n if sys.platform != 'win32':\n try:\n path = os.path.join(os.environ['HOME'],'.' + python_name)\n except KeyError:\n temp_dir = `os.getuid()` + '_' + python_name\n path = os.path.join(tempfile.gettempdir(),temp_dir) \n else:\n path = os.path.join(tempfile.gettempdir(),\"%s\"%whoami(),python_name)\n \n if not os.path.exists(path):\n create_dir(path)\n os.chmod(path,0700) # make it only accessible by this user.\n if not is_writable(path):\n print 'warning: default directory is not write accessible.'\n print 'default:', path\n return path\n\ndef intermediate_dir():\n \"\"\" Location in temp dir for storing .cpp and .o files during\n builds.\n \"\"\"\n python_name = \"python%d%d_intermediate\" % tuple(sys.version_info[:2]) \n path = os.path.join(tempfile.gettempdir(),\"%s\"%whoami(),python_name)\n if not os.path.exists(path):\n create_dir(path)\n return path\n \ndef default_temp_dir():\n path = os.path.join(default_dir(),'temp')\n if not os.path.exists(path):\n create_dir(path)\n os.chmod(path,0700) # make it only accessible by this user.\n if not is_writable(path):\n print 'warning: default directory is not write accessible.'\n print 'default:', path\n return path\n\n \ndef os_dependent_catalog_name():\n \"\"\" Generate catalog name dependent on OS and Python version being used.\n \n This allows multiple platforms to have catalog files in the\n same directory without stepping on each other. For now, it \n bases the name of the value returned by sys.platform and the\n version of python being run. If this isn't enough to descriminate\n on some platforms, we can try to add other info. It has \n occured to me that if we get fancy enough to optimize for different\n architectures, then chip type might be added to the catalog name also.\n \"\"\"\n version = '%d%d' % sys.version_info[:2]\n return sys.platform+version+'compiled_catalog'\n \ndef catalog_path(module_path):\n \"\"\" Return the full path name for the catalog file in the given directory.\n \n module_path can either be a file name or a path name. If it is a \n file name, the catalog file name in its parent directory is returned.\n If it is a directory, the catalog file in that directory is returned.\n\n If module_path doesn't exist, None is returned. Note though, that the\n catalog file does *not* have to exist, only its parent. '~', shell\n variables, and relative ('.' and '..') paths are all acceptable.\n \n catalog file names are os dependent (based on sys.platform), so this \n should support multiple platforms sharing the same disk space \n (NFS mounts). See os_dependent_catalog_name() for more info.\n \"\"\"\n module_path = os.path.expanduser(module_path)\n module_path = os.path.expandvars(module_path)\n module_path = os.path.abspath(module_path)\n if not os.path.exists(module_path):\n catalog_file = None\n elif not os.path.isdir(module_path):\n module_path,dummy = os.path.split(module_path)\n catalog_file = os.path.join(module_path,os_dependent_catalog_name())\n else: \n catalog_file = os.path.join(module_path,os_dependent_catalog_name())\n return catalog_file\n\ndef get_catalog(module_path,mode='r'):\n \"\"\" Return a function catalog (shelve object) from the path module_path\n\n If module_path is a directory, the function catalog returned is\n from that directory. If module_path is an actual module_name,\n then the function catalog returned is from its parent directory.\n mode uses the standard 'c' = create, 'n' = new, 'r' = read, \n 'w' = write file open modes available for anydbm databases.\n \n Well... it should be. Stuck with dumbdbm for now and the modes\n almost don't matter. We do some checking for 'r' mode, but that\n is about it.\n \n See catalog_path() for more information on module_path.\n \"\"\"\n if mode not in ['c','r','w','n']:\n msg = \" mode must be 'c', 'n', 'r', or 'w'. See anydbm for more info\"\n raise ValueError, msg\n catalog_file = catalog_path(module_path)\n try:\n # code reliant on the fact that we are using dumbdbm\n if dumb and mode == 'r' and not os.path.exists(catalog_file+'.dat'):\n sh = None\n else:\n sh = shelve.open(catalog_file,mode)\n except: # not sure how to pin down which error to catch yet\n sh = None\n return sh\n\nclass catalog:\n \"\"\" Stores information about compiled functions both in cache and on disk.\n \n catalog stores (code, list_of_function) pairs so that all the functions\n that have been compiled for code are available for calling (usually in\n inline or blitz).\n \n catalog keeps a dictionary of previously accessed code values cached \n for quick access. It also handles the looking up of functions compiled \n in previously called Python sessions on disk in function catalogs. \n catalog searches the directories in the PYTHONCOMPILED environment \n variable in order loading functions that correspond to the given code \n fragment. A default directory is also searched for catalog functions. \n On unix, the default directory is usually '~/.pythonxx_compiled' where \n xx is the version of Python used. On windows, it is the directory \n returned by temfile.gettempdir(). Functions closer to the front are of \n the variable list are guaranteed to be closer to the front of the \n function list so that they will be called first. See \n get_cataloged_functions() for more info on how the search order is \n traversed.\n \n Catalog also handles storing information about compiled functions to\n a catalog. When writing this information, the first writable catalog\n file in PYTHONCOMPILED path is used. If a writable catalog is not\n found, it is written to the catalog in the default directory. This\n directory should always be writable.\n \"\"\"\n def __init__(self,user_path_list=None):\n \"\"\" Create a catalog for storing/searching for compiled functions. \n \n user_path_list contains directories that should be searched \n first for function catalogs. They will come before the path\n entries in the PYTHONCOMPILED environment varilable.\n \"\"\"\n if type(user_path_list) == type('string'):\n self.user_path_list = [user_path_list]\n elif user_path_list:\n self.user_path_list = user_path_list\n else:\n self.user_path_list = []\n self.cache = {}\n self.module_dir = None\n self.paths_added = 0\n \n def set_module_directory(self,module_dir):\n \"\"\" Set the path that will replace 'MODULE' in catalog searches.\n \n You should call clear_module_directory() when your finished\n working with it.\n \"\"\"\n self.module_dir = module_dir\n def get_module_directory(self):\n \"\"\" Return the path used to replace the 'MODULE' in searches.\n \"\"\"\n return self.module_dir\n def clear_module_directory(self):\n \"\"\" Reset 'MODULE' path to None so that it is ignored in searches. \n \"\"\"\n self.module_dir = None\n \n def get_environ_path(self):\n \"\"\" Return list of paths from 'PYTHONCOMPILED' environment variable.\n \n On Unix the path in PYTHONCOMPILED is a ':' separated list of\n directories. On Windows, a ';' separated list is used. \n \"\"\"\n paths = []\n if os.environ.has_key('PYTHONCOMPILED'):\n path_string = os.environ['PYTHONCOMPILED'] \n if sys.platform == 'win32':\n #probably should also look in registry\n paths = path_string.split(';')\n else: \n paths = path_string.split(':')\n return paths \n\n def build_search_order(self):\n \"\"\" Returns a list of paths that are searched for catalogs. \n \n Values specified in the catalog constructor are searched first,\n then values found in the PYTHONCOMPILED environment variable.\n The directory returned by default_dir() is always returned at\n the end of the list.\n \n There is a 'magic' path name called 'MODULE' that is replaced\n by the directory defined by set_module_directory(). If the\n module directory hasn't been set, 'MODULE' is ignored.\n \"\"\"\n \n paths = self.user_path_list + self.get_environ_path()\n search_order = []\n for path in paths:\n if path == 'MODULE':\n if self.module_dir:\n search_order.append(self.module_dir)\n else:\n search_order.append(path)\n search_order.append(default_dir())\n return search_order\n\n def get_catalog_files(self):\n \"\"\" Returns catalog file list in correct search order.\n \n Some of the catalog files may not currently exists.\n However, all will be valid locations for a catalog\n to be created (if you have write permission).\n \"\"\"\n files = map(catalog_path,self.build_search_order())\n files = filter(lambda x: x is not None,files)\n return files\n\n def get_existing_files(self):\n \"\"\" Returns all existing catalog file list in correct search order.\n \"\"\"\n files = self.get_catalog_files()\n # open every stinking file to check if it exists.\n # This is because anydbm doesn't provide a consistent naming \n # convention across platforms for its files \n existing_files = []\n for file in files:\n if get_catalog(os.path.dirname(file),'r') is not None:\n existing_files.append(file)\n # This is the non-portable (and much faster) old code\n #existing_files = filter(os.path.exists,files)\n return existing_files\n\n def get_writable_file(self,existing_only=0):\n \"\"\" Return the name of the first writable catalog file.\n \n Its parent directory must also be writable. This is so that\n compiled modules can be written to the same directory.\n \"\"\"\n # note: both file and its parent directory must be writeable\n if existing_only:\n files = self.get_existing_files()\n else:\n files = self.get_catalog_files()\n # filter for (file exists and is writable) OR directory is writable\n def file_test(x):\n from os import access, F_OK, W_OK\n return (access(x,F_OK) and access(x,W_OK) or\n access(os.path.dirname(x),W_OK))\n writable = filter(file_test,files)\n if writable:\n file = writable[0]\n else:\n file = None\n return file\n \n def get_writable_dir(self):\n \"\"\" Return the parent directory of first writable catalog file.\n \n The returned directory has write access.\n \"\"\"\n return os.path.dirname(self.get_writable_file())\n \n def unique_module_name(self,code,module_dir=None):\n \"\"\" Return full path to unique file name that in writable location.\n \n The directory for the file is the first writable directory in \n the catalog search path. The unique file name is derived from\n the code fragment. If, module_dir is specified, it is used\n to replace 'MODULE' in the search path.\n \"\"\"\n if module_dir is not None:\n self.set_module_directory(module_dir)\n try:\n d = self.get_writable_dir()\n finally:\n if module_dir is not None:\n self.clear_module_directory()\n return unique_file(d,code)\n\n def path_key(self,code):\n \"\"\" Return key for path information for functions associated with code.\n \"\"\"\n return '__path__' + code\n \n def configure_path(self,cat,code):\n \"\"\" Add the python path for the given code to the sys.path\n \n unconfigure_path() should be called as soon as possible after\n imports associated with code are finished so that sys.path \n is restored to normal.\n \"\"\"\n try:\n paths = cat[self.path_key(code)]\n self.paths_added = len(paths)\n sys.path = paths + sys.path\n except:\n self.paths_added = 0 \n \n def unconfigure_path(self):\n \"\"\" Restores sys.path to normal after calls to configure_path()\n \n Remove the previously added paths from sys.path\n \"\"\"\n sys.path = sys.path[self.paths_added:]\n self.paths_added = 0\n\n def get_cataloged_functions(self,code):\n \"\"\" Load all functions associated with code from catalog search path.\n \n Sometimes there can be trouble loading a function listed in a\n catalog file because the actual module that holds the function \n has been moved or deleted. When this happens, that catalog file\n is \"repaired\", meaning the entire entry for this function is \n removed from the file. This only affects the catalog file that\n has problems -- not the others in the search path.\n \n The \"repair\" behavior may not be needed, but I'll keep it for now.\n \"\"\"\n mode = 'r'\n cat = None\n function_list = []\n for path in self.build_search_order():\n cat = get_catalog(path,mode)\n if cat is not None and cat.has_key(code):\n # set up the python path so that modules for this\n # function can be loaded.\n self.configure_path(cat,code)\n try: \n function_list += cat[code]\n except: #SystemError and ImportError so far seen \n # problems loading a function from the catalog. Try to\n # repair the cause.\n cat.close()\n self.repair_catalog(path,code)\n self.unconfigure_path() \n return function_list\n\n\n def repair_catalog(self,catalog_path,code):\n \"\"\" Remove entry for code from catalog_path\n \n Occasionally catalog entries could get corrupted. An example\n would be when a module that had functions in the catalog was\n deleted or moved on the disk. The best current repair method is \n just to trash the entire catalog entry for this piece of code. \n This may loose function entries that are valid, but thats life.\n \n catalog_path must be writable for repair. If it isn't, the\n function exists with a warning. \n \"\"\"\n writable_cat = None\n if not os.path.exists(catalog_path):\n return\n try:\n writable_cat = get_catalog(catalog_path,'w')\n except:\n print 'warning: unable to repair catalog entry\\n %s\\n in\\n %s' % \\\n (code,catalog_path)\n return \n if writable_cat.has_key(code):\n print 'repairing catalog by removing key'\n del writable_cat[code]\n \n # it is possible that the path key doesn't exist (if the function registered\n # was a built-in function), so we have to check if the path exists before\n # arbitrarily deleting it.\n path_key = self.path_key(code) \n if writable_cat.has_key(path_key):\n del writable_cat[path_key] \n \n def get_functions_fast(self,code):\n \"\"\" Return list of functions for code from the cache.\n \n Return an empty list if the code entry is not found.\n \"\"\"\n return self.cache.get(code,[])\n \n def get_functions(self,code,module_dir=None):\n \"\"\" Return the list of functions associated with this code fragment.\n \n The cache is first searched for the function. If an entry\n in the cache is not found, then catalog files on disk are \n searched for the entry. This is slooooow, but only happens\n once per code object. All the functions found in catalog files\n on a cache miss are loaded into the cache to speed up future calls.\n The search order is as follows:\n \n 1. user specified path (from catalog initialization)\n 2. directories from the PYTHONCOMPILED environment variable\n 3. The temporary directory on your platform.\n\n The path specified by module_dir will replace the 'MODULE' \n place holder in the catalog search path. See build_search_order()\n for more info on the search path. \n \"\"\" \n # Fast!! try cache first.\n if self.cache.has_key(code):\n return self.cache[code]\n \n # 2. Slow!! read previously compiled functions from disk.\n try:\n self.set_module_directory(module_dir)\n function_list = self.get_cataloged_functions(code)\n # put function_list in cache to save future lookups.\n if function_list:\n self.cache[code] = function_list\n # return function_list, empty or otherwise.\n finally:\n self.clear_module_directory()\n return function_list\n\n def add_function(self,code,function,module_dir=None):\n \"\"\" Adds a function to the catalog.\n \n The function is added to the cache as well as the first\n writable file catalog found in the search path. If no\n code entry exists in the cache, the on disk catalogs\n are loaded into the cache and function is added to the\n beginning of the function list.\n \n The path specified by module_dir will replace the 'MODULE' \n place holder in the catalog search path. See build_search_order()\n for more info on the search path. \n \"\"\" \n\n # 1. put it in the cache.\n if self.cache.has_key(code):\n if function not in self.cache[code]:\n self.cache[code].insert(0,function)\n else:\n # if it is in the cache, then it is also\n # been persisted \n return\n else: \n # Load functions and put this one up front\n self.cache[code] = self.get_functions(code) \n self.fast_cache(code,function)\n # 2. Store the function entry to disk. \n try:\n self.set_module_directory(module_dir)\n self.add_function_persistent(code,function)\n finally:\n self.clear_module_directory()\n \n def add_function_persistent(self,code,function):\n \"\"\" Store the code->function relationship to disk.\n \n Two pieces of information are needed for loading functions\n from disk -- the function pickle (which conveniently stores\n the module name, etc.) and the path to its module's directory.\n The latter is needed so that the function can be loaded no\n matter what the user's Python path is.\n \"\"\" \n # add function to data in first writable catalog\n mode = 'c' # create if doesn't exist, otherwise, use existing\n cat_dir = self.get_writable_dir()\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n cat_dir = default_dir()\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n cat_dir = default_dir() \n cat_file = catalog_path(cat_dir)\n print 'problems with default catalog -- removing'\n import glob\n files = glob.glob(cat_file+'*')\n for f in files:\n os.remove(f)\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n raise ValueError, 'Failed to access a catalog for storing functions' \n # Prabhu was getting some corrupt catalog errors. I'll put a try/except\n # to protect against this, but should really try and track down the issue.\n function_list = [function]\n try:\n function_list = function_list + cat.get(code,[])\n except pickle.UnpicklingError:\n pass\n cat[code] = function_list\n # now add needed path information for loading function\n module = getmodule(function)\n try:\n # built in modules don't have the __file__ extension, so this\n # will fail. Just pass in this case since path additions aren't\n # needed for built-in modules.\n mod_path,f=os.path.split(os.path.abspath(module.__file__))\n pkey = self.path_key(code)\n cat[pkey] = [mod_path] + cat.get(pkey,[])\n except:\n pass\n\n def fast_cache(self,code,function):\n \"\"\" Move function to the front of the cache entry for code\n \n If future calls to the function have the same type signature,\n this will speed up access significantly because the first\n function call is correct.\n \n Note: The cache added to the inline_tools module is significantly\n faster than always calling get_functions, so this isn't\n as necessary as it used to be. Still, it's probably worth\n doing. \n \"\"\"\n try:\n if self.cache[code][0] == function:\n return\n except: # KeyError, IndexError \n pass\n try:\n self.cache[code].remove(function)\n except ValueError:\n pass\n # put new function at the beginning of the list to search.\n self.cache[code].insert(0,function)\n \ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "source_code_before": "\"\"\" Track relationships between compiled extension functions & code fragments\n\n catalog keeps track of which compiled(or even standard) functions are \n related to which code fragments. It also stores these relationships\n to disk so they are remembered between Python sessions. When \n \n a = 1\n compiler.inline('printf(\"printed from C: %d\",a);',['a'] )\n \n is called, inline() first looks to see if it has seen the code \n 'printf(\"printed from C\");' before. If not, it calls \n \n catalog.get_functions('printf(\"printed from C: %d\", a);')\n \n which returns a list of all the function objects that have been compiled\n for the code fragment. Multiple functions can occur because the code\n could be compiled for different types for 'a' (although not likely in\n this case). The catalog first looks in its cache and quickly returns\n a list of the functions if possible. If the cache lookup fails, it then\n looks through possibly multiple catalog files on disk and fills its\n cache with all the functions that match the code fragment. \n \n In case where the code fragment hasn't been compiled, inline() compiles\n the code and then adds it to the catalog:\n \n function = \n catalog.add_function('printf(\"printed from C: %d\", a);',function)\n \n add_function() adds function to the front of the cache. function,\n along with the path information to its module, are also stored in a\n persistent catalog for future use by python sessions. \n\"\"\" \n\nimport os,sys,string\nimport pickle\nimport tempfile\n\ntry:\n import dbhash\n import shelve\n dumb = 0\nexcept ImportError:\n import dumb_shelve as shelve\n dumb = 1\n\n#For testing...\n#import dumb_shelve as shelve\n#dumb = 1\n\n#import shelve\n#dumb = 0\n \ndef getmodule(object):\n \"\"\" Discover the name of the module where object was defined.\n \n This is an augmented version of inspect.getmodule that can discover \n the parent module for extension functions.\n \"\"\"\n import inspect\n value = inspect.getmodule(object)\n if value is None:\n #walk trough all modules looking for function\n for name,mod in sys.modules.items():\n # try except used because of some comparison failures\n # in wxPoint code. Need to review this\n try:\n if mod and object in mod.__dict__.values():\n value = mod\n # if it is a built-in module, keep looking to see\n # if a non-builtin also has it. Otherwise quit and\n # consider the module found. (ain't perfect, but will \n # have to do for now).\n if string.find('(built-in)',str(mod)) is -1:\n break\n \n except (TypeError, KeyError):\n pass \n return value\n\ndef expr_to_filename(expr):\n \"\"\" Convert an arbitrary expr string to a valid file name.\n \n The name is based on the md5 check sum for the string and\n Something that was a little more human readable would be \n nice, but the computer doesn't seem to care.\n \"\"\"\n import md5\n base = 'sc_'\n return base + md5.new(expr).hexdigest()\n\ndef unique_file(d,expr):\n \"\"\" Generate a unqiue file name based on expr in directory d\n \n This is meant for use with building extension modules, so\n a file name is considered unique if none of the following\n extension '.cpp','.o','.so','module.so','.py', or '.pyd'\n exists in directory d. The fully qualified path to the\n new name is returned. You'll need to append your own\n extension to it before creating files.\n \"\"\"\n files = os.listdir(d)\n #base = 'scipy_compile'\n base = expr_to_filename(expr)\n for i in range(1000000):\n fname = base + `i`\n if not (fname+'.cpp' in files or\n fname+'.o' in files or\n fname+'.so' in files or\n fname+'module.so' in files or\n fname+'.py' in files or\n fname+'.pyd' in files):\n break\n return os.path.join(d,fname)\n\ndef create_dir(p):\n \"\"\" Create a directory and any necessary intermediate directories.\"\"\"\n if not os.path.exists(p):\n try:\n os.mkdir(p)\n except OSError:\n # perhaps one or more intermediate path components don't exist\n # try to create them\n base,dir = os.path.split(p)\n create_dir(base)\n # don't enclose this one in try/except - we want the user to\n # get failure info\n os.mkdir(p)\n\ndef is_writable(dir):\n dummy = os.path.join(dir, \"dummy\")\n try:\n open(dummy, 'w')\n except IOError:\n return 0\n os.unlink(dummy)\n return 1\n\ndef whoami():\n \"\"\"return a string identifying the user.\"\"\"\n return os.environ.get(\"USER\") or os.environ.get(\"USERNAME\") or \"unknown\"\n\ndef default_dir():\n \"\"\" Return a default location to store compiled files and catalogs.\n \n XX is the Python version number in all paths listed below\n On windows, the default location is the temporary directory\n returned by gettempdir()/pythonXX.\n \n On Unix, ~/.pythonXX_compiled is the default location. If it doesn't\n exist, it is created. The directory is marked rwx------.\n \n If for some reason it isn't possible to build a default directory\n in the user's home, /tmp/_pythonXX_compiled is used. If it \n doesn't exist, it is created. The directory is marked rwx------\n to try and keep people from being able to sneak a bad module\n in on you. \n \"\"\"\n python_name = \"python%d%d_compiled\" % tuple(sys.version_info[:2]) \n if sys.platform != 'win32':\n try:\n path = os.path.join(os.environ['HOME'],'.' + python_name)\n except KeyError:\n temp_dir = `os.getuid()` + '_' + python_name\n path = os.path.join(tempfile.gettempdir(),temp_dir) \n else:\n path = os.path.join(tempfile.gettempdir(),\"%s\"%whoami(),python_name)\n \n if not os.path.exists(path):\n create_dir(path)\n os.chmod(path,0700) # make it only accessible by this user.\n if not is_writable(path):\n print 'warning: default directory is not write accessible.'\n print 'default:', path\n return path\n\ndef intermediate_dir():\n \"\"\" Location in temp dir for storing .cpp and .o files during\n builds.\n \"\"\"\n python_name = \"python%d%d_intermediate\" % tuple(sys.version_info[:2]) \n path = os.path.join(tempfile.gettempdir(),\"%s\"%whoami(),python_name)\n if not os.path.exists(path):\n create_dir(path)\n return path\n \ndef default_temp_dir():\n path = os.path.join(default_dir(),'temp')\n if not os.path.exists(path):\n create_dir(path)\n os.chmod(path,0700) # make it only accessible by this user.\n if not is_writable(path):\n print 'warning: default directory is not write accessible.'\n print 'default:', path\n return path\n\n \ndef os_dependent_catalog_name():\n \"\"\" Generate catalog name dependent on OS and Python version being used.\n \n This allows multiple platforms to have catalog files in the\n same directory without stepping on each other. For now, it \n bases the name of the value returned by sys.platform and the\n version of python being run. If this isn't enough to descriminate\n on some platforms, we can try to add other info. It has \n occured to me that if we get fancy enough to optimize for different\n architectures, then chip type might be added to the catalog name also.\n \"\"\"\n version = '%d%d' % sys.version_info[:2]\n return sys.platform+version+'compiled_catalog'\n \ndef catalog_path(module_path):\n \"\"\" Return the full path name for the catalog file in the given directory.\n \n module_path can either be a file name or a path name. If it is a \n file name, the catalog file name in its parent directory is returned.\n If it is a directory, the catalog file in that directory is returned.\n\n If module_path doesn't exist, None is returned. Note though, that the\n catalog file does *not* have to exist, only its parent. '~', shell\n variables, and relative ('.' and '..') paths are all acceptable.\n \n catalog file names are os dependent (based on sys.platform), so this \n should support multiple platforms sharing the same disk space \n (NFS mounts). See os_dependent_catalog_name() for more info.\n \"\"\"\n module_path = os.path.expanduser(module_path)\n module_path = os.path.expandvars(module_path)\n module_path = os.path.abspath(module_path)\n if not os.path.exists(module_path):\n catalog_file = None\n elif not os.path.isdir(module_path):\n module_path,dummy = os.path.split(module_path)\n catalog_file = os.path.join(module_path,os_dependent_catalog_name())\n else: \n catalog_file = os.path.join(module_path,os_dependent_catalog_name())\n return catalog_file\n\ndef get_catalog(module_path,mode='r'):\n \"\"\" Return a function catalog (shelve object) from the path module_path\n\n If module_path is a directory, the function catalog returned is\n from that directory. If module_path is an actual module_name,\n then the function catalog returned is from its parent directory.\n mode uses the standard 'c' = create, 'n' = new, 'r' = read, \n 'w' = write file open modes available for anydbm databases.\n \n Well... it should be. Stuck with dumbdbm for now and the modes\n almost don't matter. We do some checking for 'r' mode, but that\n is about it.\n \n See catalog_path() for more information on module_path.\n \"\"\"\n if mode not in ['c','r','w','n']:\n msg = \" mode must be 'c', 'n', 'r', or 'w'. See anydbm for more info\"\n raise ValueError, msg\n catalog_file = catalog_path(module_path)\n try:\n # code reliant on the fact that we are using dumbdbm\n if dumb and mode == 'r' and not os.path.exists(catalog_file+'.dat'):\n sh = None\n else:\n sh = shelve.open(catalog_file,mode)\n except: # not sure how to pin down which error to catch yet\n sh = None\n return sh\n\nclass catalog:\n \"\"\" Stores information about compiled functions both in cache and on disk.\n \n catalog stores (code, list_of_function) pairs so that all the functions\n that have been compiled for code are available for calling (usually in\n inline or blitz).\n \n catalog keeps a dictionary of previously accessed code values cached \n for quick access. It also handles the looking up of functions compiled \n in previously called Python sessions on disk in function catalogs. \n catalog searches the directories in the PYTHONCOMPILED environment \n variable in order loading functions that correspond to the given code \n fragment. A default directory is also searched for catalog functions. \n On unix, the default directory is usually '~/.pythonxx_compiled' where \n xx is the version of Python used. On windows, it is the directory \n returned by temfile.gettempdir(). Functions closer to the front are of \n the variable list are guaranteed to be closer to the front of the \n function list so that they will be called first. See \n get_cataloged_functions() for more info on how the search order is \n traversed.\n \n Catalog also handles storing information about compiled functions to\n a catalog. When writing this information, the first writable catalog\n file in PYTHONCOMPILED path is used. If a writable catalog is not\n found, it is written to the catalog in the default directory. This\n directory should always be writable.\n \"\"\"\n def __init__(self,user_path_list=None):\n \"\"\" Create a catalog for storing/searching for compiled functions. \n \n user_path_list contains directories that should be searched \n first for function catalogs. They will come before the path\n entries in the PYTHONCOMPILED environment varilable.\n \"\"\"\n if type(user_path_list) == type('string'):\n self.user_path_list = [user_path_list]\n elif user_path_list:\n self.user_path_list = user_path_list\n else:\n self.user_path_list = []\n self.cache = {}\n self.module_dir = None\n self.paths_added = 0\n \n def set_module_directory(self,module_dir):\n \"\"\" Set the path that will replace 'MODULE' in catalog searches.\n \n You should call clear_module_directory() when your finished\n working with it.\n \"\"\"\n self.module_dir = module_dir\n def get_module_directory(self):\n \"\"\" Return the path used to replace the 'MODULE' in searches.\n \"\"\"\n return self.module_dir\n def clear_module_directory(self):\n \"\"\" Reset 'MODULE' path to None so that it is ignored in searches. \n \"\"\"\n self.module_dir = None\n \n def get_environ_path(self):\n \"\"\" Return list of paths from 'PYTHONCOMPILED' environment variable.\n \n On Unix the path in PYTHONCOMPILED is a ':' separated list of\n directories. On Windows, a ';' separated list is used. \n \"\"\"\n paths = []\n if os.environ.has_key('PYTHONCOMPILED'):\n path_string = os.environ['PYTHONCOMPILED'] \n if sys.platform == 'win32':\n #probably should also look in registry\n paths = path_string.split(';')\n else: \n paths = path_string.split(':')\n return paths \n\n def build_search_order(self):\n \"\"\" Returns a list of paths that are searched for catalogs. \n \n Values specified in the catalog constructor are searched first,\n then values found in the PYTHONCOMPILED environment variable.\n The directory returned by default_dir() is always returned at\n the end of the list.\n \n There is a 'magic' path name called 'MODULE' that is replaced\n by the directory defined by set_module_directory(). If the\n module directory hasn't been set, 'MODULE' is ignored.\n \"\"\"\n \n paths = self.user_path_list + self.get_environ_path()\n search_order = []\n for path in paths:\n if path == 'MODULE':\n if self.module_dir:\n search_order.append(self.module_dir)\n else:\n search_order.append(path)\n search_order.append(default_dir())\n return search_order\n\n def get_catalog_files(self):\n \"\"\" Returns catalog file list in correct search order.\n \n Some of the catalog files may not currently exists.\n However, all will be valid locations for a catalog\n to be created (if you have write permission).\n \"\"\"\n files = map(catalog_path,self.build_search_order())\n files = filter(lambda x: x is not None,files)\n return files\n\n def get_existing_files(self):\n \"\"\" Returns all existing catalog file list in correct search order.\n \"\"\"\n files = self.get_catalog_files()\n # open every stinking file to check if it exists.\n # This is because anydbm doesn't provide a consistent naming \n # convention across platforms for its files \n existing_files = []\n for file in files:\n if get_catalog(os.path.dirname(file),'r') is not None:\n existing_files.append(file)\n # This is the non-portable (and much faster) old code\n #existing_files = filter(os.path.exists,files)\n return existing_files\n\n def get_writable_file(self,existing_only=0):\n \"\"\" Return the name of the first writable catalog file.\n \n Its parent directory must also be writable. This is so that\n compiled modules can be written to the same directory.\n \"\"\"\n # note: both file and its parent directory must be writeable\n if existing_only:\n files = self.get_existing_files()\n else:\n files = self.get_catalog_files()\n # filter for (file exists and is writable) OR directory is writable\n def file_test(x):\n from os import access, F_OK, W_OK\n return (access(x,F_OK) and access(x,W_OK) or\n access(os.path.dirname(x),W_OK))\n writable = filter(file_test,files)\n if writable:\n file = writable[0]\n else:\n file = None\n return file\n \n def get_writable_dir(self):\n \"\"\" Return the parent directory of first writable catalog file.\n \n The returned directory has write access.\n \"\"\"\n return os.path.dirname(self.get_writable_file())\n \n def unique_module_name(self,code,module_dir=None):\n \"\"\" Return full path to unique file name that in writable location.\n \n The directory for the file is the first writable directory in \n the catalog search path. The unique file name is derived from\n the code fragment. If, module_dir is specified, it is used\n to replace 'MODULE' in the search path.\n \"\"\"\n if module_dir is not None:\n self.set_module_directory(module_dir)\n try:\n d = self.get_writable_dir()\n finally:\n if module_dir is not None:\n self.clear_module_directory()\n return unique_file(d,code)\n\n def path_key(self,code):\n \"\"\" Return key for path information for functions associated with code.\n \"\"\"\n return '__path__' + code\n \n def configure_path(self,cat,code):\n \"\"\" Add the python path for the given code to the sys.path\n \n unconfigure_path() should be called as soon as possible after\n imports associated with code are finished so that sys.path \n is restored to normal.\n \"\"\"\n try:\n paths = cat[self.path_key(code)]\n self.paths_added = len(paths)\n sys.path = paths + sys.path\n except:\n self.paths_added = 0 \n \n def unconfigure_path(self):\n \"\"\" Restores sys.path to normal after calls to configure_path()\n \n Remove the previously added paths from sys.path\n \"\"\"\n sys.path = sys.path[self.paths_added:]\n self.paths_added = 0\n\n def get_cataloged_functions(self,code):\n \"\"\" Load all functions associated with code from catalog search path.\n \n Sometimes there can be trouble loading a function listed in a\n catalog file because the actual module that holds the function \n has been moved or deleted. When this happens, that catalog file\n is \"repaired\", meaning the entire entry for this function is \n removed from the file. This only affects the catalog file that\n has problems -- not the others in the search path.\n \n The \"repair\" behavior may not be needed, but I'll keep it for now.\n \"\"\"\n mode = 'r'\n cat = None\n function_list = []\n for path in self.build_search_order():\n cat = get_catalog(path,mode)\n if cat is not None and cat.has_key(code):\n # set up the python path so that modules for this\n # function can be loaded.\n self.configure_path(cat,code)\n try: \n function_list += cat[code]\n except: #SystemError and ImportError so far seen \n # problems loading a function from the catalog. Try to\n # repair the cause.\n cat.close()\n self.repair_catalog(path,code)\n self.unconfigure_path() \n return function_list\n\n\n def repair_catalog(self,catalog_path,code):\n \"\"\" Remove entry for code from catalog_path\n \n Occasionally catalog entries could get corrupted. An example\n would be when a module that had functions in the catalog was\n deleted or moved on the disk. The best current repair method is \n just to trash the entire catalog entry for this piece of code. \n This may loose function entries that are valid, but thats life.\n \n catalog_path must be writable for repair. If it isn't, the\n function exists with a warning. \n \"\"\"\n writable_cat = None\n if not os.path.exists(catalog_path):\n return\n try:\n writable_cat = get_catalog(catalog_path,'w')\n except:\n print 'warning: unable to repair catalog entry\\n %s\\n in\\n %s' % \\\n (code,catalog_path)\n return \n if writable_cat.has_key(code):\n print 'repairing catalog by removing key'\n del writable_cat[code]\n \n # it is possible that the path key doesn't exist (if the function registered\n # was a built-in function), so we have to check if the path exists before\n # arbitrarily deleting it.\n path_key = self.path_key(code) \n if writable_cat.has_key(path_key):\n del writable_cat[path_key] \n \n def get_functions_fast(self,code):\n \"\"\" Return list of functions for code from the cache.\n \n Return an empty list if the code entry is not found.\n \"\"\"\n return self.cache.get(code,[])\n \n def get_functions(self,code,module_dir=None):\n \"\"\" Return the list of functions associated with this code fragment.\n \n The cache is first searched for the function. If an entry\n in the cache is not found, then catalog files on disk are \n searched for the entry. This is slooooow, but only happens\n once per code object. All the functions found in catalog files\n on a cache miss are loaded into the cache to speed up future calls.\n The search order is as follows:\n \n 1. user specified path (from catalog initialization)\n 2. directories from the PYTHONCOMPILED environment variable\n 3. The temporary directory on your platform.\n\n The path specified by module_dir will replace the 'MODULE' \n place holder in the catalog search path. See build_search_order()\n for more info on the search path. \n \"\"\" \n # Fast!! try cache first.\n if self.cache.has_key(code):\n return self.cache[code]\n \n # 2. Slow!! read previously compiled functions from disk.\n try:\n self.set_module_directory(module_dir)\n function_list = self.get_cataloged_functions(code)\n # put function_list in cache to save future lookups.\n if function_list:\n self.cache[code] = function_list\n # return function_list, empty or otherwise.\n finally:\n self.clear_module_directory()\n return function_list\n\n def add_function(self,code,function,module_dir=None):\n \"\"\" Adds a function to the catalog.\n \n The function is added to the cache as well as the first\n writable file catalog found in the search path. If no\n code entry exists in the cache, the on disk catalogs\n are loaded into the cache and function is added to the\n beginning of the function list.\n \n The path specified by module_dir will replace the 'MODULE' \n place holder in the catalog search path. See build_search_order()\n for more info on the search path. \n \"\"\" \n\n # 1. put it in the cache.\n if self.cache.has_key(code):\n if function not in self.cache[code]:\n self.cache[code].insert(0,function)\n else:\n # if it is in the cache, then it is also\n # been persisted \n return\n else: \n # Load functions and put this one up front\n self.cache[code] = self.get_functions(code) \n self.fast_cache(code,function)\n # 2. Store the function entry to disk. \n try:\n self.set_module_directory(module_dir)\n self.add_function_persistent(code,function)\n finally:\n self.clear_module_directory()\n \n def add_function_persistent(self,code,function):\n \"\"\" Store the code->function relationship to disk.\n \n Two pieces of information are needed for loading functions\n from disk -- the function pickle (which conveniently stores\n the module name, etc.) and the path to its module's directory.\n The latter is needed so that the function can be loaded no\n matter what the user's Python path is.\n \"\"\" \n # add function to data in first writable catalog\n mode = 'c' # create if doesn't exist, otherwise, use existing\n cat_dir = self.get_writable_dir()\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n cat_dir = default_dir()\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n cat_dir = default_dir() \n cat_file = catalog_path(cat_dir)\n print 'problems with default catalog -- removing'\n import glob\n files = glob.glob(cat_file+'*')\n for f in files:\n os.remove(f)\n cat = get_catalog(cat_dir,mode)\n if cat is None:\n raise ValueError, 'Failed to access a catalog for storing functions' \n # Prabhu was getting some corrupt catalog errors. I'll put a try/except\n # to protect against this, but should really try and track down the issue.\n function_list = [function]\n try:\n function_list = function_list + cat.get(code,[])\n except pickle.UnpicklingError:\n pass\n cat[code] = function_list\n # now add needed path information for loading function\n module = getmodule(function)\n try:\n # built in modules don't have the __file__ extension, so this\n # will fail. Just pass in this case since path additions aren't\n # needed for built-in modules.\n mod_path,f=os.path.split(os.path.abspath(module.__file__))\n pkey = self.path_key(code)\n cat[pkey] = [mod_path] + cat.get(pkey,[])\n except:\n pass\n\n def fast_cache(self,code,function):\n \"\"\" Move function to the front of the cache entry for code\n \n If future calls to the function have the same type signature,\n this will speed up access significantly because the first\n function call is correct.\n \n Note: The cache added to the inline_tools module is significantly\n faster than always calling get_functions, so this isn't\n as necessary as it used to be. Still, it's probably worth\n doing. \n \"\"\"\n try:\n if self.cache[code][0] == function:\n return\n except: # KeyError, IndexError \n pass\n try:\n self.cache[code].remove(function)\n except ValueError:\n pass\n # put new function at the beginning of the list to search.\n self.cache[code].insert(0,function)\n \ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "methods": [ { "name": "getmodule", "long_name": "getmodule( object )", "filename": "catalog.py", "nloc": 13, "complexity": 7, "token_count": 79, "parameters": [ "object" ], "start_line": 53, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "expr_to_filename", "long_name": "expr_to_filename( expr )", "filename": "catalog.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "expr" ], "start_line": 80, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "unique_file", "long_name": "unique_file( d , expr )", "filename": "catalog.py", "nloc": 13, "complexity": 8, "token_count": 89, "parameters": [ "d", "expr" ], "start_line": 91, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "create_dir", "long_name": "create_dir( p )", "filename": "catalog.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "p" ], "start_line": 115, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "is_writable", "long_name": "is_writable( dir )", "filename": "catalog.py", "nloc": 8, "complexity": 2, "token_count": 38, "parameters": [ "dir" ], "start_line": 129, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "whoami", "long_name": "whoami( )", "filename": "catalog.py", "nloc": 2, "complexity": 3, "token_count": 25, "parameters": [], "start_line": 138, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "default_dir", "long_name": "default_dir( )", "filename": "catalog.py", "nloc": 17, "complexity": 5, "token_count": 141, "parameters": [], "start_line": 142, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "intermediate_dir", "long_name": "intermediate_dir( )", "filename": "catalog.py", "nloc": 6, "complexity": 2, "token_count": 58, "parameters": [], "start_line": 176, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "default_temp_dir", "long_name": "default_temp_dir( )", "filename": "catalog.py", "nloc": 9, "complexity": 3, "token_count": 56, "parameters": [], "start_line": 186, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "os_dependent_catalog_name", "long_name": "os_dependent_catalog_name( )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 197, "end_line": 209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "catalog_path", "long_name": "catalog_path( module_path )", "filename": "catalog.py", "nloc": 12, "complexity": 3, "token_count": 105, "parameters": [ "module_path" ], "start_line": 211, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "get_catalog", "long_name": "get_catalog( module_path , mode = 'r' )", "filename": "catalog.py", "nloc": 13, "complexity": 6, "token_count": 80, "parameters": [ "module_path", "mode" ], "start_line": 238, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , user_path_list = None )", "filename": "catalog.py", "nloc": 10, "complexity": 3, "token_count": 60, "parameters": [ "self", "user_path_list" ], "start_line": 294, "end_line": 309, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "set_module_directory", "long_name": "set_module_directory( self , module_dir )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "module_dir" ], "start_line": 311, "end_line": 317, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_module_directory", "long_name": "get_module_directory( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 318, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "clear_module_directory", "long_name": "clear_module_directory( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 322, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_environ_path", "long_name": "get_environ_path( self )", "filename": "catalog.py", "nloc": 9, "complexity": 3, "token_count": 55, "parameters": [ "self" ], "start_line": 327, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "build_search_order", "long_name": "build_search_order( self )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 62, "parameters": [ "self" ], "start_line": 343, "end_line": 365, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_catalog_files", "long_name": "get_catalog_files( self )", "filename": "catalog.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 367, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_existing_files", "long_name": "get_existing_files( self )", "filename": "catalog.py", "nloc": 7, "complexity": 3, "token_count": 48, "parameters": [ "self" ], "start_line": 378, "end_line": 391, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "get_writable_file.file_test", "long_name": "get_writable_file.file_test( x )", "filename": "catalog.py", "nloc": 4, "complexity": 3, "token_count": 43, "parameters": [ "x" ], "start_line": 405, "end_line": 408, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 2 }, { "name": "get_writable_file", "long_name": "get_writable_file( self , existing_only = 0 )", "filename": "catalog.py", "nloc": 12, "complexity": 3, "token_count": 55, "parameters": [ "self", "existing_only" ], "start_line": 393, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "get_writable_dir", "long_name": "get_writable_dir( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 416, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "unique_module_name", "long_name": "unique_module_name( self , code , module_dir = None )", "filename": "catalog.py", "nloc": 9, "complexity": 4, "token_count": 53, "parameters": [ "self", "code", "module_dir" ], "start_line": 423, "end_line": 438, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "path_key", "long_name": "path_key( self , code )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "code" ], "start_line": 440, "end_line": 443, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "configure_path", "long_name": "configure_path( self , cat , code )", "filename": "catalog.py", "nloc": 7, "complexity": 2, "token_count": 47, "parameters": [ "self", "cat", "code" ], "start_line": 445, "end_line": 457, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "unconfigure_path", "long_name": "unconfigure_path( self )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 459, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_cataloged_functions", "long_name": "get_cataloged_functions( self , code )", "filename": "catalog.py", "nloc": 15, "complexity": 5, "token_count": 86, "parameters": [ "self", "code" ], "start_line": 467, "end_line": 496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 1 }, { "name": "repair_catalog", "long_name": "repair_catalog( self , catalog_path , code )", "filename": "catalog.py", "nloc": 16, "complexity": 5, "token_count": 83, "parameters": [ "self", "catalog_path", "code" ], "start_line": 499, "end_line": 529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "get_functions_fast", "long_name": "get_functions_fast( self , code )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "code" ], "start_line": 531, "end_line": 536, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_functions", "long_name": "get_functions( self , code , module_dir = None )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 65, "parameters": [ "self", "code", "module_dir" ], "start_line": 538, "end_line": 570, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 1 }, { "name": "add_function", "long_name": "add_function( self , code , function , module_dir = None )", "filename": "catalog.py", "nloc": 14, "complexity": 4, "token_count": 97, "parameters": [ "self", "code", "function", "module_dir" ], "start_line": 572, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "add_function_persistent", "long_name": "add_function_persistent( self , code , function )", "filename": "catalog.py", "nloc": 31, "complexity": 7, "token_count": 194, "parameters": [ "self", "code", "function" ], "start_line": 605, "end_line": 650, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "fast_cache", "long_name": "fast_cache( self , code , function )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 59, "parameters": [ "self", "code", "function" ], "start_line": 652, "end_line": 674, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 676, "end_line": 678, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 680, "end_line": 682, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "getmodule", "long_name": "getmodule( object )", "filename": "catalog.py", "nloc": 13, "complexity": 7, "token_count": 79, "parameters": [ "object" ], "start_line": 53, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "expr_to_filename", "long_name": "expr_to_filename( expr )", "filename": "catalog.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "expr" ], "start_line": 80, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "unique_file", "long_name": "unique_file( d , expr )", "filename": "catalog.py", "nloc": 13, "complexity": 8, "token_count": 89, "parameters": [ "d", "expr" ], "start_line": 91, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "create_dir", "long_name": "create_dir( p )", "filename": "catalog.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "p" ], "start_line": 115, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "is_writable", "long_name": "is_writable( dir )", "filename": "catalog.py", "nloc": 8, "complexity": 2, "token_count": 38, "parameters": [ "dir" ], "start_line": 129, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "whoami", "long_name": "whoami( )", "filename": "catalog.py", "nloc": 2, "complexity": 3, "token_count": 25, "parameters": [], "start_line": 138, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "default_dir", "long_name": "default_dir( )", "filename": "catalog.py", "nloc": 17, "complexity": 5, "token_count": 141, "parameters": [], "start_line": 142, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "intermediate_dir", "long_name": "intermediate_dir( )", "filename": "catalog.py", "nloc": 6, "complexity": 2, "token_count": 58, "parameters": [], "start_line": 176, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "default_temp_dir", "long_name": "default_temp_dir( )", "filename": "catalog.py", "nloc": 9, "complexity": 3, "token_count": 56, "parameters": [], "start_line": 186, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "os_dependent_catalog_name", "long_name": "os_dependent_catalog_name( )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 197, "end_line": 209, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "catalog_path", "long_name": "catalog_path( module_path )", "filename": "catalog.py", "nloc": 12, "complexity": 3, "token_count": 105, "parameters": [ "module_path" ], "start_line": 211, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "get_catalog", "long_name": "get_catalog( module_path , mode = 'r' )", "filename": "catalog.py", "nloc": 13, "complexity": 6, "token_count": 80, "parameters": [ "module_path", "mode" ], "start_line": 238, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , user_path_list = None )", "filename": "catalog.py", "nloc": 10, "complexity": 3, "token_count": 60, "parameters": [ "self", "user_path_list" ], "start_line": 294, "end_line": 309, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "set_module_directory", "long_name": "set_module_directory( self , module_dir )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "module_dir" ], "start_line": 311, "end_line": 317, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_module_directory", "long_name": "get_module_directory( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 318, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "clear_module_directory", "long_name": "clear_module_directory( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 322, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_environ_path", "long_name": "get_environ_path( self )", "filename": "catalog.py", "nloc": 9, "complexity": 3, "token_count": 55, "parameters": [ "self" ], "start_line": 327, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "build_search_order", "long_name": "build_search_order( self )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 62, "parameters": [ "self" ], "start_line": 343, "end_line": 365, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_catalog_files", "long_name": "get_catalog_files( self )", "filename": "catalog.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 367, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_existing_files", "long_name": "get_existing_files( self )", "filename": "catalog.py", "nloc": 7, "complexity": 3, "token_count": 48, "parameters": [ "self" ], "start_line": 378, "end_line": 391, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "get_writable_file.file_test", "long_name": "get_writable_file.file_test( x )", "filename": "catalog.py", "nloc": 4, "complexity": 3, "token_count": 43, "parameters": [ "x" ], "start_line": 405, "end_line": 408, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 2 }, { "name": "get_writable_file", "long_name": "get_writable_file( self , existing_only = 0 )", "filename": "catalog.py", "nloc": 12, "complexity": 3, "token_count": 55, "parameters": [ "self", "existing_only" ], "start_line": 393, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "get_writable_dir", "long_name": "get_writable_dir( self )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 416, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "unique_module_name", "long_name": "unique_module_name( self , code , module_dir = None )", "filename": "catalog.py", "nloc": 9, "complexity": 4, "token_count": 53, "parameters": [ "self", "code", "module_dir" ], "start_line": 423, "end_line": 438, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "path_key", "long_name": "path_key( self , code )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "code" ], "start_line": 440, "end_line": 443, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "configure_path", "long_name": "configure_path( self , cat , code )", "filename": "catalog.py", "nloc": 7, "complexity": 2, "token_count": 47, "parameters": [ "self", "cat", "code" ], "start_line": 445, "end_line": 457, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "unconfigure_path", "long_name": "unconfigure_path( self )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 459, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_cataloged_functions", "long_name": "get_cataloged_functions( self , code )", "filename": "catalog.py", "nloc": 15, "complexity": 5, "token_count": 86, "parameters": [ "self", "code" ], "start_line": 467, "end_line": 496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 1 }, { "name": "repair_catalog", "long_name": "repair_catalog( self , catalog_path , code )", "filename": "catalog.py", "nloc": 16, "complexity": 5, "token_count": 83, "parameters": [ "self", "catalog_path", "code" ], "start_line": 499, "end_line": 529, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "get_functions_fast", "long_name": "get_functions_fast( self , code )", "filename": "catalog.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "code" ], "start_line": 531, "end_line": 536, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_functions", "long_name": "get_functions( self , code , module_dir = None )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 65, "parameters": [ "self", "code", "module_dir" ], "start_line": 538, "end_line": 570, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 1 }, { "name": "add_function", "long_name": "add_function( self , code , function , module_dir = None )", "filename": "catalog.py", "nloc": 14, "complexity": 4, "token_count": 97, "parameters": [ "self", "code", "function", "module_dir" ], "start_line": 572, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "add_function_persistent", "long_name": "add_function_persistent( self , code , function )", "filename": "catalog.py", "nloc": 31, "complexity": 7, "token_count": 194, "parameters": [ "self", "code", "function" ], "start_line": 605, "end_line": 650, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "fast_cache", "long_name": "fast_cache( self , code , function )", "filename": "catalog.py", "nloc": 11, "complexity": 4, "token_count": 59, "parameters": [ "self", "code", "function" ], "start_line": 652, "end_line": 674, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 676, "end_line": 678, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 680, "end_line": 682, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 680, "end_line": 682, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 676, "end_line": 678, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 368, "complexity": 108, "token_count": 2034, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "weave/ext_tools.py", "new_path": "weave/ext_tools.py", "filename": "ext_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -414,9 +414,9 @@ def format_error_msg(errors):\n return msg.getvalue()\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "added_lines": 2, "deleted_lines": 2, "source_code": "import os, sys\nimport string, re\n\nimport catalog \nimport build_tools\nimport converters\nimport base_spec\n\nclass ext_function_from_specs:\n def __init__(self,name,code_block,arg_specs):\n self.name = name\n self.arg_specs = base_spec.arg_spec_list(arg_specs)\n self.code_block = code_block\n self.compiler = ''\n self.customize = base_info.custom_info()\n \n def header_code(self):\n pass\n\n def function_declaration_code(self):\n code = 'static PyObject* %s(PyObject*self, PyObject* args,' \\\n ' PyObject* kywds)\\n{\\n'\n return code % self.name\n\n def template_declaration_code(self):\n code = 'template\\n' \\\n 'static PyObject* %s(PyObject*self, PyObject* args,' \\\n ' PyObject* kywds)\\n{\\n'\n return code % self.name\n\n #def cpp_function_declaration_code(self):\n # pass\n #def cpp_function_call_code(self):\n #s pass\n \n def parse_tuple_code(self):\n \"\"\" Create code block for PyArg_ParseTuple. Variable declarations\n for all PyObjects are done also.\n \n This code got a lot uglier when I added local_dict...\n \"\"\"\n join = string.join\n\n declare_return = 'PyObject *return_val = NULL;\\n' \\\n 'int exception_occured = 0;\\n' \\\n 'PyObject *py_local_dict = NULL;\\n'\n arg_string_list = self.arg_specs.variable_as_strings() + ['\"local_dict\"']\n arg_strings = join(arg_string_list,',')\n if arg_strings: arg_strings += ','\n declare_kwlist = 'static char *kwlist[] = {%s NULL};\\n' % arg_strings\n\n py_objects = join(self.arg_specs.py_pointers(),', ')\n init_flags = join(self.arg_specs.init_flags(),', ')\n init_flags_init = join(self.arg_specs.init_flags(),'= ')\n py_vars = join(self.arg_specs.py_variables(),' = ')\n if py_objects:\n declare_py_objects = 'PyObject ' + py_objects +';\\n'\n declare_py_objects += 'int '+ init_flags + ';\\n' \n init_values = py_vars + ' = NULL;\\n'\n init_values += init_flags_init + ' = 0;\\n\\n'\n else:\n declare_py_objects = ''\n init_values = '' \n\n #Each variable is in charge of its own cleanup now.\n #cnt = len(arg_list)\n #declare_cleanup = \"blitz::TinyVector clean_up(0);\\n\" % cnt\n\n ref_string = join(self.arg_specs.py_references(),', ')\n if ref_string:\n ref_string += ', &py_local_dict'\n else:\n ref_string = '&py_local_dict'\n \n format = \"O\"* len(self.arg_specs) + \"|O\" + ':' + self.name\n parse_tuple = 'if(!PyArg_ParseTupleAndKeywords(args,' \\\n 'kywds,\"%s\",kwlist,%s))\\n' % (format,ref_string)\n parse_tuple += ' return NULL;\\n'\n\n return declare_return + declare_kwlist + declare_py_objects \\\n + init_values + parse_tuple\n\n def arg_declaration_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.declaration_code())\n arg_strings.append(arg.init_flag() +\" = 1;\\n\")\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_cleanup_code(self):\n arg_strings = []\n have_cleanup = filter(lambda x:x.cleanup_code(),self.arg_specs)\n for arg in have_cleanup:\n code = \"if(%s)\\n\" % arg.init_flag()\n code += \"{\\n\"\n code += indent(arg.cleanup_code(),4)\n code += \"}\\n\"\n arg_strings.append(code)\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_local_dict_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.local_dict_code())\n code = string.join(arg_strings,\"\")\n return code\n \n def function_code(self):\n decl_code = indent(self.arg_declaration_code(),4)\n cleanup_code = indent(self.arg_cleanup_code(),4)\n function_code = indent(self.code_block,4)\n local_dict_code = indent(self.arg_local_dict_code(),4)\n\n dict_code = \"if(py_local_dict) \\n\" \\\n \"{ \\n\" \\\n \" PWODict local_dict = PWODict(py_local_dict); \\n\" + \\\n local_dict_code + \\\n \"} \\n\"\n\n try_code = \"try \\n\" \\\n \"{ \\n\" + \\\n decl_code + \\\n \" /**/ \\n\" + \\\n function_code + \\\n indent(dict_code,4) + \\\n \"\\n} \\n\"\n catch_code = \"catch(...) \\n\" \\\n \"{ \\n\" + \\\n \" return_val = NULL; \\n\" \\\n \" exception_occured = 1; \\n\" \\\n \"} \\n\"\n\n return_code = \" /*cleanup code*/ \\n\" + \\\n cleanup_code + \\\n \" if(!return_val && !exception_occured)\\n\" \\\n \" {\\n \\n\" \\\n \" Py_INCREF(Py_None); \\n\" \\\n \" return_val = Py_None; \\n\" \\\n \" }\\n \\n\" \\\n \" return return_val; \\n\" \\\n \"} \\n\"\n\n all_code = self.function_declaration_code() + \\\n indent(self.parse_tuple_code(),4) + \\\n indent(try_code,4) + \\\n indent(catch_code,4) + \\\n return_code\n\n return all_code\n\n def python_function_definition_code(self):\n args = (self.name, self.name)\n function_decls = '{\"%s\",(PyCFunction)%s , METH_VARARGS|' \\\n 'METH_KEYWORDS},\\n' % args\n return function_decls\n\n def set_compiler(self,compiler):\n self.compiler = compiler\n for arg in self.arg_specs:\n arg.set_compiler(compiler)\n\n\nclass ext_function(ext_function_from_specs):\n def __init__(self,name,code_block, args, local_dict=None, global_dict=None,\n auto_downcast=1, type_converters=None):\n \n call_frame = sys._getframe().f_back\n if local_dict is None:\n local_dict = call_frame.f_locals\n if global_dict is None:\n global_dict = call_frame.f_globals\n if type_converters is None:\n type_converters = converters.default\n arg_specs = assign_variable_types(args,local_dict, global_dict,\n auto_downcast, type_converters)\n ext_function_from_specs.__init__(self,name,code_block,arg_specs)\n \n \nimport base_info\n\nclass ext_module:\n def __init__(self,name,compiler=''):\n standard_info = converters.standard_info\n self.name = name\n self.functions = []\n self.compiler = compiler\n self.customize = base_info.custom_info()\n self._build_information = base_info.info_list(standard_info)\n \n def add_function(self,func):\n self.functions.append(func)\n def module_code(self):\n code = self.warning_code() + \\\n self.header_code() + \\\n self.support_code() + \\\n self.function_code() + \\\n self.python_function_definition_code() + \\\n self.module_init_code()\n return code\n\n def arg_specs(self):\n all_arg_specs = base_spec.arg_spec_list()\n for func in self.functions:\n all_arg_specs += func.arg_specs\n return all_arg_specs\n\n def build_information(self):\n info = [self.customize] + self._build_information + \\\n self.arg_specs().build_information()\n for func in self.functions:\n info.append(func.customize)\n #redundant, but easiest place to make sure compiler is set\n for i in info:\n i.set_compiler(self.compiler)\n return info\n \n def get_headers(self):\n all_headers = self.build_information().headers()\n\n # blitz/array.h always needs to be first so we hack that here...\n if '\"blitz/array.h\"' in all_headers:\n all_headers.remove('\"blitz/array.h\"')\n all_headers.insert(0,'\"blitz/array.h\"')\n return all_headers\n\n def warning_code(self):\n all_warnings = self.build_information().warnings()\n w=map(lambda x: \"#pragma warning(%s)\\n\" % x,all_warnings)\n return ''.join(w)\n \n def header_code(self):\n h = self.get_headers()\n h= map(lambda x: '#include ' + x + '\\n',h)\n return ''.join(h)\n\n def support_code(self):\n code = self.build_information().support_code()\n return ''.join(code)\n\n def function_code(self):\n all_function_code = \"\"\n for func in self.functions:\n all_function_code += func.function_code()\n return ''.join(all_function_code)\n\n def python_function_definition_code(self):\n all_definition_code = \"\"\n for func in self.functions:\n all_definition_code += func.python_function_definition_code()\n all_definition_code = indent(''.join(all_definition_code),4)\n code = 'static PyMethodDef compiled_methods[] = \\n' \\\n '{\\n' \\\n '%s' \\\n ' {NULL, NULL} /* Sentinel */\\n' \\\n '};\\n'\n return code % (all_definition_code)\n\n def module_init_code(self):\n init_code_list = self.build_information().module_init_code()\n init_code = indent(''.join(init_code_list),4)\n code = 'extern \"C\" void init%s()\\n' \\\n '{\\n' \\\n '%s' \\\n ' (void) Py_InitModule(\"%s\", compiled_methods);\\n' \\\n '}\\n' % (self.name,init_code,self.name)\n return code\n\n def generate_file(self,file_name=\"\",location='.'):\n code = self.module_code()\n if not file_name:\n file_name = self.name + '.cpp'\n name = generate_file_name(file_name,location)\n #return name\n return generate_module(code,name)\n\n def set_compiler(self,compiler):\n #for i in self.arg_specs()\n # i.set_compiler(compiler)\n for i in self.build_information():\n i.set_compiler(compiler) \n for i in self.functions:\n i.set_compiler(compiler)\n self.compiler = compiler \n \n def compile(self,location='.',compiler=None, verbose = 0, **kw):\n \n if compiler is not None:\n self.compiler = compiler\n # hmm. Is there a cleaner way to do this? Seems like\n # choosing the compiler spagettis around a little.\n compiler = build_tools.choose_compiler(self.compiler) \n self.set_compiler(compiler)\n arg_specs = self.arg_specs()\n info = self.build_information()\n _source_files = info.sources()\n # remove duplicates\n source_files = {}\n for i in _source_files:\n source_files[i] = None\n source_files = source_files.keys()\n \n # add internally specified macros, includes, etc. to the key words\n # values of the same names so that distutils will use them.\n kw['define_macros'] = kw.get('define_macros',[]) + info.define_macros()\n kw['include_dirs'] = kw.get('include_dirs',[]) + info.include_dirs()\n kw['libraries'] = kw.get('libraries',[]) + info.libraries()\n kw['library_dirs'] = kw.get('library_dirs',[]) + info.library_dirs()\n \n file = self.generate_file(location=location)\n # This is needed so that files build correctly even when different\n # versions of Python are running around.\n # Imported at beginning of file now to help with test paths.\n # import catalog \n #temp = catalog.default_temp_dir()\n # for speed, build in the machines temp directory\n temp = catalog.intermediate_dir()\n success = build_tools.build_extension(file, temp_dir = temp,\n sources = source_files, \n compiler_name = compiler,\n verbose = verbose, **kw)\n if not success:\n raise SystemError, 'Compilation failed'\n\ndef generate_file_name(module_name,module_location):\n module_file = os.path.join(module_location,module_name)\n return os.path.abspath(module_file)\n\ndef generate_module(module_string, module_file):\n f =open(module_file,'w')\n f.write(module_string)\n f.close()\n return module_file\n\ndef assign_variable_types(variables,local_dict = {}, global_dict = {},\n auto_downcast = 1,\n type_converters = converters.default):\n incoming_vars = {}\n incoming_vars.update(global_dict)\n incoming_vars.update(local_dict)\n variable_specs = []\n errors={}\n for var in variables:\n try:\n example_type = incoming_vars[var]\n\n # look through possible type specs to find which one\n # should be used to for example_type\n spec = None\n for factory in type_converters:\n if factory.type_match(example_type):\n spec = factory.type_spec(var,example_type)\n break \n if not spec:\n # should really define our own type.\n raise IndexError\n else:\n variable_specs.append(spec)\n except KeyError:\n errors[var] = (\"The type and dimensionality specifications\" +\n \"for variable '\" + var + \"' are missing.\")\n except IndexError:\n errors[var] = (\"Unable to convert variable '\"+ var +\n \"' to a C++ type.\")\n if errors:\n raise TypeError, format_error_msg(errors)\n\n if auto_downcast:\n variable_specs = downcast(variable_specs)\n return variable_specs\n\ndef downcast(var_specs):\n \"\"\" Cast python scalars down to most common type of\n arrays used.\n\n Right now, focus on complex and float types. Ignore int types.\n Require all arrays to have same type before forcing downcasts.\n\n Note: var_specs are currently altered in place (horrors...!)\n \"\"\"\n numeric_types = []\n\n #grab all the numeric types associated with a variables.\n for var in var_specs:\n if hasattr(var,'numeric_type'):\n numeric_types.append(var.numeric_type)\n\n # if arrays are present, but none of them are double precision,\n # make all numeric types float or complex(float)\n if ( ('f' in numeric_types or 'F' in numeric_types) and\n not ('d' in numeric_types or 'D' in numeric_types) ):\n for var in var_specs:\n if hasattr(var,'numeric_type'):\n # really should do this some other way...\n if var.numeric_type == type(1+1j):\n var.numeric_type = 'F'\n elif var.numeric_type == type(1.):\n var.numeric_type = 'f'\n return var_specs\n\ndef indent(st,spaces):\n indention = ' '*spaces\n indented = indention + string.replace(st,'\\n','\\n'+indention)\n # trim off any trailing spaces\n indented = re.sub(r' +$',r'',indented)\n return indented\n\ndef format_error_msg(errors):\n #minimum effort right now...\n import pprint,cStringIO\n msg = cStringIO.StringIO()\n pprint.pprint(errors,msg)\n return msg.getvalue()\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "source_code_before": "import os, sys\nimport string, re\n\nimport catalog \nimport build_tools\nimport converters\nimport base_spec\n\nclass ext_function_from_specs:\n def __init__(self,name,code_block,arg_specs):\n self.name = name\n self.arg_specs = base_spec.arg_spec_list(arg_specs)\n self.code_block = code_block\n self.compiler = ''\n self.customize = base_info.custom_info()\n \n def header_code(self):\n pass\n\n def function_declaration_code(self):\n code = 'static PyObject* %s(PyObject*self, PyObject* args,' \\\n ' PyObject* kywds)\\n{\\n'\n return code % self.name\n\n def template_declaration_code(self):\n code = 'template\\n' \\\n 'static PyObject* %s(PyObject*self, PyObject* args,' \\\n ' PyObject* kywds)\\n{\\n'\n return code % self.name\n\n #def cpp_function_declaration_code(self):\n # pass\n #def cpp_function_call_code(self):\n #s pass\n \n def parse_tuple_code(self):\n \"\"\" Create code block for PyArg_ParseTuple. Variable declarations\n for all PyObjects are done also.\n \n This code got a lot uglier when I added local_dict...\n \"\"\"\n join = string.join\n\n declare_return = 'PyObject *return_val = NULL;\\n' \\\n 'int exception_occured = 0;\\n' \\\n 'PyObject *py_local_dict = NULL;\\n'\n arg_string_list = self.arg_specs.variable_as_strings() + ['\"local_dict\"']\n arg_strings = join(arg_string_list,',')\n if arg_strings: arg_strings += ','\n declare_kwlist = 'static char *kwlist[] = {%s NULL};\\n' % arg_strings\n\n py_objects = join(self.arg_specs.py_pointers(),', ')\n init_flags = join(self.arg_specs.init_flags(),', ')\n init_flags_init = join(self.arg_specs.init_flags(),'= ')\n py_vars = join(self.arg_specs.py_variables(),' = ')\n if py_objects:\n declare_py_objects = 'PyObject ' + py_objects +';\\n'\n declare_py_objects += 'int '+ init_flags + ';\\n' \n init_values = py_vars + ' = NULL;\\n'\n init_values += init_flags_init + ' = 0;\\n\\n'\n else:\n declare_py_objects = ''\n init_values = '' \n\n #Each variable is in charge of its own cleanup now.\n #cnt = len(arg_list)\n #declare_cleanup = \"blitz::TinyVector clean_up(0);\\n\" % cnt\n\n ref_string = join(self.arg_specs.py_references(),', ')\n if ref_string:\n ref_string += ', &py_local_dict'\n else:\n ref_string = '&py_local_dict'\n \n format = \"O\"* len(self.arg_specs) + \"|O\" + ':' + self.name\n parse_tuple = 'if(!PyArg_ParseTupleAndKeywords(args,' \\\n 'kywds,\"%s\",kwlist,%s))\\n' % (format,ref_string)\n parse_tuple += ' return NULL;\\n'\n\n return declare_return + declare_kwlist + declare_py_objects \\\n + init_values + parse_tuple\n\n def arg_declaration_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.declaration_code())\n arg_strings.append(arg.init_flag() +\" = 1;\\n\")\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_cleanup_code(self):\n arg_strings = []\n have_cleanup = filter(lambda x:x.cleanup_code(),self.arg_specs)\n for arg in have_cleanup:\n code = \"if(%s)\\n\" % arg.init_flag()\n code += \"{\\n\"\n code += indent(arg.cleanup_code(),4)\n code += \"}\\n\"\n arg_strings.append(code)\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_local_dict_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.local_dict_code())\n code = string.join(arg_strings,\"\")\n return code\n \n def function_code(self):\n decl_code = indent(self.arg_declaration_code(),4)\n cleanup_code = indent(self.arg_cleanup_code(),4)\n function_code = indent(self.code_block,4)\n local_dict_code = indent(self.arg_local_dict_code(),4)\n\n dict_code = \"if(py_local_dict) \\n\" \\\n \"{ \\n\" \\\n \" PWODict local_dict = PWODict(py_local_dict); \\n\" + \\\n local_dict_code + \\\n \"} \\n\"\n\n try_code = \"try \\n\" \\\n \"{ \\n\" + \\\n decl_code + \\\n \" /**/ \\n\" + \\\n function_code + \\\n indent(dict_code,4) + \\\n \"\\n} \\n\"\n catch_code = \"catch(...) \\n\" \\\n \"{ \\n\" + \\\n \" return_val = NULL; \\n\" \\\n \" exception_occured = 1; \\n\" \\\n \"} \\n\"\n\n return_code = \" /*cleanup code*/ \\n\" + \\\n cleanup_code + \\\n \" if(!return_val && !exception_occured)\\n\" \\\n \" {\\n \\n\" \\\n \" Py_INCREF(Py_None); \\n\" \\\n \" return_val = Py_None; \\n\" \\\n \" }\\n \\n\" \\\n \" return return_val; \\n\" \\\n \"} \\n\"\n\n all_code = self.function_declaration_code() + \\\n indent(self.parse_tuple_code(),4) + \\\n indent(try_code,4) + \\\n indent(catch_code,4) + \\\n return_code\n\n return all_code\n\n def python_function_definition_code(self):\n args = (self.name, self.name)\n function_decls = '{\"%s\",(PyCFunction)%s , METH_VARARGS|' \\\n 'METH_KEYWORDS},\\n' % args\n return function_decls\n\n def set_compiler(self,compiler):\n self.compiler = compiler\n for arg in self.arg_specs:\n arg.set_compiler(compiler)\n\n\nclass ext_function(ext_function_from_specs):\n def __init__(self,name,code_block, args, local_dict=None, global_dict=None,\n auto_downcast=1, type_converters=None):\n \n call_frame = sys._getframe().f_back\n if local_dict is None:\n local_dict = call_frame.f_locals\n if global_dict is None:\n global_dict = call_frame.f_globals\n if type_converters is None:\n type_converters = converters.default\n arg_specs = assign_variable_types(args,local_dict, global_dict,\n auto_downcast, type_converters)\n ext_function_from_specs.__init__(self,name,code_block,arg_specs)\n \n \nimport base_info\n\nclass ext_module:\n def __init__(self,name,compiler=''):\n standard_info = converters.standard_info\n self.name = name\n self.functions = []\n self.compiler = compiler\n self.customize = base_info.custom_info()\n self._build_information = base_info.info_list(standard_info)\n \n def add_function(self,func):\n self.functions.append(func)\n def module_code(self):\n code = self.warning_code() + \\\n self.header_code() + \\\n self.support_code() + \\\n self.function_code() + \\\n self.python_function_definition_code() + \\\n self.module_init_code()\n return code\n\n def arg_specs(self):\n all_arg_specs = base_spec.arg_spec_list()\n for func in self.functions:\n all_arg_specs += func.arg_specs\n return all_arg_specs\n\n def build_information(self):\n info = [self.customize] + self._build_information + \\\n self.arg_specs().build_information()\n for func in self.functions:\n info.append(func.customize)\n #redundant, but easiest place to make sure compiler is set\n for i in info:\n i.set_compiler(self.compiler)\n return info\n \n def get_headers(self):\n all_headers = self.build_information().headers()\n\n # blitz/array.h always needs to be first so we hack that here...\n if '\"blitz/array.h\"' in all_headers:\n all_headers.remove('\"blitz/array.h\"')\n all_headers.insert(0,'\"blitz/array.h\"')\n return all_headers\n\n def warning_code(self):\n all_warnings = self.build_information().warnings()\n w=map(lambda x: \"#pragma warning(%s)\\n\" % x,all_warnings)\n return ''.join(w)\n \n def header_code(self):\n h = self.get_headers()\n h= map(lambda x: '#include ' + x + '\\n',h)\n return ''.join(h)\n\n def support_code(self):\n code = self.build_information().support_code()\n return ''.join(code)\n\n def function_code(self):\n all_function_code = \"\"\n for func in self.functions:\n all_function_code += func.function_code()\n return ''.join(all_function_code)\n\n def python_function_definition_code(self):\n all_definition_code = \"\"\n for func in self.functions:\n all_definition_code += func.python_function_definition_code()\n all_definition_code = indent(''.join(all_definition_code),4)\n code = 'static PyMethodDef compiled_methods[] = \\n' \\\n '{\\n' \\\n '%s' \\\n ' {NULL, NULL} /* Sentinel */\\n' \\\n '};\\n'\n return code % (all_definition_code)\n\n def module_init_code(self):\n init_code_list = self.build_information().module_init_code()\n init_code = indent(''.join(init_code_list),4)\n code = 'extern \"C\" void init%s()\\n' \\\n '{\\n' \\\n '%s' \\\n ' (void) Py_InitModule(\"%s\", compiled_methods);\\n' \\\n '}\\n' % (self.name,init_code,self.name)\n return code\n\n def generate_file(self,file_name=\"\",location='.'):\n code = self.module_code()\n if not file_name:\n file_name = self.name + '.cpp'\n name = generate_file_name(file_name,location)\n #return name\n return generate_module(code,name)\n\n def set_compiler(self,compiler):\n #for i in self.arg_specs()\n # i.set_compiler(compiler)\n for i in self.build_information():\n i.set_compiler(compiler) \n for i in self.functions:\n i.set_compiler(compiler)\n self.compiler = compiler \n \n def compile(self,location='.',compiler=None, verbose = 0, **kw):\n \n if compiler is not None:\n self.compiler = compiler\n # hmm. Is there a cleaner way to do this? Seems like\n # choosing the compiler spagettis around a little.\n compiler = build_tools.choose_compiler(self.compiler) \n self.set_compiler(compiler)\n arg_specs = self.arg_specs()\n info = self.build_information()\n _source_files = info.sources()\n # remove duplicates\n source_files = {}\n for i in _source_files:\n source_files[i] = None\n source_files = source_files.keys()\n \n # add internally specified macros, includes, etc. to the key words\n # values of the same names so that distutils will use them.\n kw['define_macros'] = kw.get('define_macros',[]) + info.define_macros()\n kw['include_dirs'] = kw.get('include_dirs',[]) + info.include_dirs()\n kw['libraries'] = kw.get('libraries',[]) + info.libraries()\n kw['library_dirs'] = kw.get('library_dirs',[]) + info.library_dirs()\n \n file = self.generate_file(location=location)\n # This is needed so that files build correctly even when different\n # versions of Python are running around.\n # Imported at beginning of file now to help with test paths.\n # import catalog \n #temp = catalog.default_temp_dir()\n # for speed, build in the machines temp directory\n temp = catalog.intermediate_dir()\n success = build_tools.build_extension(file, temp_dir = temp,\n sources = source_files, \n compiler_name = compiler,\n verbose = verbose, **kw)\n if not success:\n raise SystemError, 'Compilation failed'\n\ndef generate_file_name(module_name,module_location):\n module_file = os.path.join(module_location,module_name)\n return os.path.abspath(module_file)\n\ndef generate_module(module_string, module_file):\n f =open(module_file,'w')\n f.write(module_string)\n f.close()\n return module_file\n\ndef assign_variable_types(variables,local_dict = {}, global_dict = {},\n auto_downcast = 1,\n type_converters = converters.default):\n incoming_vars = {}\n incoming_vars.update(global_dict)\n incoming_vars.update(local_dict)\n variable_specs = []\n errors={}\n for var in variables:\n try:\n example_type = incoming_vars[var]\n\n # look through possible type specs to find which one\n # should be used to for example_type\n spec = None\n for factory in type_converters:\n if factory.type_match(example_type):\n spec = factory.type_spec(var,example_type)\n break \n if not spec:\n # should really define our own type.\n raise IndexError\n else:\n variable_specs.append(spec)\n except KeyError:\n errors[var] = (\"The type and dimensionality specifications\" +\n \"for variable '\" + var + \"' are missing.\")\n except IndexError:\n errors[var] = (\"Unable to convert variable '\"+ var +\n \"' to a C++ type.\")\n if errors:\n raise TypeError, format_error_msg(errors)\n\n if auto_downcast:\n variable_specs = downcast(variable_specs)\n return variable_specs\n\ndef downcast(var_specs):\n \"\"\" Cast python scalars down to most common type of\n arrays used.\n\n Right now, focus on complex and float types. Ignore int types.\n Require all arrays to have same type before forcing downcasts.\n\n Note: var_specs are currently altered in place (horrors...!)\n \"\"\"\n numeric_types = []\n\n #grab all the numeric types associated with a variables.\n for var in var_specs:\n if hasattr(var,'numeric_type'):\n numeric_types.append(var.numeric_type)\n\n # if arrays are present, but none of them are double precision,\n # make all numeric types float or complex(float)\n if ( ('f' in numeric_types or 'F' in numeric_types) and\n not ('d' in numeric_types or 'D' in numeric_types) ):\n for var in var_specs:\n if hasattr(var,'numeric_type'):\n # really should do this some other way...\n if var.numeric_type == type(1+1j):\n var.numeric_type = 'F'\n elif var.numeric_type == type(1.):\n var.numeric_type = 'f'\n return var_specs\n\ndef indent(st,spaces):\n indention = ' '*spaces\n indented = indention + string.replace(st,'\\n','\\n'+indention)\n # trim off any trailing spaces\n indented = re.sub(r' +$',r'',indented)\n return indented\n\ndef format_error_msg(errors):\n #minimum effort right now...\n import pprint,cStringIO\n msg = cStringIO.StringIO()\n pprint.pprint(errors,msg)\n return msg.getvalue()\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "methods": [ { "name": "__init__", "long_name": "__init__( self , name , code_block , arg_specs )", "filename": "ext_tools.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "self", "name", "code_block", "arg_specs" ], "start_line": 10, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "header_code", "long_name": "header_code( self )", "filename": "ext_tools.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [ "self" ], "start_line": 17, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "function_declaration_code", "long_name": "function_declaration_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 20, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "template_declaration_code", "long_name": "template_declaration_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 25, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "parse_tuple_code", "long_name": "parse_tuple_code( self )", "filename": "ext_tools.py", "nloc": 32, "complexity": 4, "token_count": 209, "parameters": [ "self" ], "start_line": 36, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "arg_declaration_code", "long_name": "arg_declaration_code( self )", "filename": "ext_tools.py", "nloc": 7, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 83, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "arg_cleanup_code", "long_name": "arg_cleanup_code( self )", "filename": "ext_tools.py", "nloc": 11, "complexity": 2, "token_count": 76, "parameters": [ "self" ], "start_line": 91, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "arg_local_dict_code", "long_name": "arg_local_dict_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 103, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 37, "complexity": 1, "token_count": 162, "parameters": [ "self" ], "start_line": 110, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 153, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "ext_tools.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [ "self", "compiler" ], "start_line": 159, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , code_block , args , local_dict = None , global_dict = None , auto_downcast = 1 , type_converters = None )", "filename": "ext_tools.py", "nloc": 12, "complexity": 4, "token_count": 92, "parameters": [ "self", "name", "code_block", "args", "local_dict", "global_dict", "auto_downcast", "type_converters" ], "start_line": 166, "end_line": 178, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , compiler = '' )", "filename": "ext_tools.py", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "self", "name", "compiler" ], "start_line": 184, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "add_function", "long_name": "add_function( self , func )", "filename": "ext_tools.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "func" ], "start_line": 192, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "module_code", "long_name": "module_code( self )", "filename": "ext_tools.py", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "self" ], "start_line": 194, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "arg_specs", "long_name": "arg_specs( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 203, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "build_information", "long_name": "build_information( self )", "filename": "ext_tools.py", "nloc": 8, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 209, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "get_headers", "long_name": "get_headers( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "self" ], "start_line": 219, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "warning_code", "long_name": "warning_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 228, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "header_code", "long_name": "header_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 233, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "support_code", "long_name": "support_code( self )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 238, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 2, "token_count": 29, "parameters": [ "self" ], "start_line": 242, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "ext_tools.py", "nloc": 11, "complexity": 2, "token_count": 52, "parameters": [ "self" ], "start_line": 248, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "module_init_code", "long_name": "module_init_code( self )", "filename": "ext_tools.py", "nloc": 9, "complexity": 1, "token_count": 54, "parameters": [ "self" ], "start_line": 260, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "generate_file", "long_name": "generate_file( self , file_name = \"\" , location = '.' )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 46, "parameters": [ "self", "file_name", "location" ], "start_line": 270, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "ext_tools.py", "nloc": 6, "complexity": 3, "token_count": 40, "parameters": [ "self", "compiler" ], "start_line": 278, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "compile", "long_name": "compile( self , location = '.' , compiler = None , verbose = 0 , ** kw )", "filename": "ext_tools.py", "nloc": 24, "complexity": 4, "token_count": 222, "parameters": [ "self", "location", "compiler", "verbose", "kw" ], "start_line": 287, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 1 }, { "name": "generate_file_name", "long_name": "generate_file_name( module_name , module_location )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 28, "parameters": [ "module_name", "module_location" ], "start_line": 326, "end_line": 328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "generate_module", "long_name": "generate_module( module_string , module_file )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "module_string", "module_file" ], "start_line": 330, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "assign_variable_types", "long_name": "assign_variable_types( variables , local_dict = { } , global_dict = { } , auto_downcast = 1 , type_converters = converters . default )", "filename": "ext_tools.py", "nloc": 31, "complexity": 9, "token_count": 156, "parameters": [ "variables", "local_dict", "global_dict", "auto_downcast", "type_converters" ], "start_line": 336, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "downcast", "long_name": "downcast( var_specs )", "filename": "ext_tools.py", "nloc": 14, "complexity": 11, "token_count": 103, "parameters": [ "var_specs" ], "start_line": 373, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "indent", "long_name": "indent( st , spaces )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 44, "parameters": [ "st", "spaces" ], "start_line": 402, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "format_error_msg", "long_name": "format_error_msg( errors )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "errors" ], "start_line": 409, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 416, "end_line": 418, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 420, "end_line": 422, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self , name , code_block , arg_specs )", "filename": "ext_tools.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "self", "name", "code_block", "arg_specs" ], "start_line": 10, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "header_code", "long_name": "header_code( self )", "filename": "ext_tools.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [ "self" ], "start_line": 17, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "function_declaration_code", "long_name": "function_declaration_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 20, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "template_declaration_code", "long_name": "template_declaration_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 25, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "parse_tuple_code", "long_name": "parse_tuple_code( self )", "filename": "ext_tools.py", "nloc": 32, "complexity": 4, "token_count": 209, "parameters": [ "self" ], "start_line": 36, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "arg_declaration_code", "long_name": "arg_declaration_code( self )", "filename": "ext_tools.py", "nloc": 7, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 83, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "arg_cleanup_code", "long_name": "arg_cleanup_code( self )", "filename": "ext_tools.py", "nloc": 11, "complexity": 2, "token_count": 76, "parameters": [ "self" ], "start_line": 91, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "arg_local_dict_code", "long_name": "arg_local_dict_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 103, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 37, "complexity": 1, "token_count": 162, "parameters": [ "self" ], "start_line": 110, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 153, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "ext_tools.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [ "self", "compiler" ], "start_line": 159, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , code_block , args , local_dict = None , global_dict = None , auto_downcast = 1 , type_converters = None )", "filename": "ext_tools.py", "nloc": 12, "complexity": 4, "token_count": 92, "parameters": [ "self", "name", "code_block", "args", "local_dict", "global_dict", "auto_downcast", "type_converters" ], "start_line": 166, "end_line": 178, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , compiler = '' )", "filename": "ext_tools.py", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "self", "name", "compiler" ], "start_line": 184, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "add_function", "long_name": "add_function( self , func )", "filename": "ext_tools.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "func" ], "start_line": 192, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "module_code", "long_name": "module_code( self )", "filename": "ext_tools.py", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "self" ], "start_line": 194, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "arg_specs", "long_name": "arg_specs( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 203, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "build_information", "long_name": "build_information( self )", "filename": "ext_tools.py", "nloc": 8, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 209, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "get_headers", "long_name": "get_headers( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "self" ], "start_line": 219, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "warning_code", "long_name": "warning_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 228, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "header_code", "long_name": "header_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 233, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "support_code", "long_name": "support_code( self )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 238, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 2, "token_count": 29, "parameters": [ "self" ], "start_line": 242, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "ext_tools.py", "nloc": 11, "complexity": 2, "token_count": 52, "parameters": [ "self" ], "start_line": 248, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "module_init_code", "long_name": "module_init_code( self )", "filename": "ext_tools.py", "nloc": 9, "complexity": 1, "token_count": 54, "parameters": [ "self" ], "start_line": 260, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "generate_file", "long_name": "generate_file( self , file_name = \"\" , location = '.' )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 46, "parameters": [ "self", "file_name", "location" ], "start_line": 270, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "ext_tools.py", "nloc": 6, "complexity": 3, "token_count": 40, "parameters": [ "self", "compiler" ], "start_line": 278, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "compile", "long_name": "compile( self , location = '.' , compiler = None , verbose = 0 , ** kw )", "filename": "ext_tools.py", "nloc": 24, "complexity": 4, "token_count": 222, "parameters": [ "self", "location", "compiler", "verbose", "kw" ], "start_line": 287, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 1 }, { "name": "generate_file_name", "long_name": "generate_file_name( module_name , module_location )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 28, "parameters": [ "module_name", "module_location" ], "start_line": 326, "end_line": 328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "generate_module", "long_name": "generate_module( module_string , module_file )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "module_string", "module_file" ], "start_line": 330, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "assign_variable_types", "long_name": "assign_variable_types( variables , local_dict = { } , global_dict = { } , auto_downcast = 1 , type_converters = converters . default )", "filename": "ext_tools.py", "nloc": 31, "complexity": 9, "token_count": 156, "parameters": [ "variables", "local_dict", "global_dict", "auto_downcast", "type_converters" ], "start_line": 336, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "downcast", "long_name": "downcast( var_specs )", "filename": "ext_tools.py", "nloc": 14, "complexity": 11, "token_count": 103, "parameters": [ "var_specs" ], "start_line": 373, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "indent", "long_name": "indent( st , spaces )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 44, "parameters": [ "st", "spaces" ], "start_line": 402, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "format_error_msg", "long_name": "format_error_msg( errors )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "errors" ], "start_line": 409, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 416, "end_line": 418, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 420, "end_line": 422, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 420, "end_line": 422, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 416, "end_line": 418, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 318, "complexity": 75, "token_count": 2034, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "weave/inline_tools.py", "new_path": "weave/inline_tools.py", "filename": "inline_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -436,11 +436,11 @@ def compile_function(code,arg_names,local_dict,global_dict,\n return func\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n if __name__ == \"__main__\":\n", "added_lines": 2, "deleted_lines": 2, "source_code": "# should re-write compiled functions to take a local and global dict\n# as input.\nimport sys,os\nimport ext_tools\nimport string\nimport catalog\nimport common_info\n\n# not an easy way for the user_path_list to come in here.\n# the PYTHONCOMPILED environment variable offers the most hope.\n\nfunction_catalog = catalog.catalog()\n\n\nclass inline_ext_function(ext_tools.ext_function):\n # Some specialization is needed for inline extension functions\n def function_declaration_code(self):\n code = 'static PyObject* %s(PyObject*self, PyObject* args)\\n{\\n'\n return code % self.name\n\n def template_declaration_code(self):\n code = 'template\\n' \\\n 'static PyObject* %s(PyObject*self, PyObject* args)\\n{\\n'\n return code % self.name\n\n def parse_tuple_code(self):\n \"\"\" Create code block for PyArg_ParseTuple. Variable declarations\n for all PyObjects are done also.\n\n This code got a lot uglier when I added local_dict...\n \"\"\"\n declare_return = 'PyObject *return_val = NULL;\\n' \\\n 'int exception_occured = 0;\\n' \\\n 'PyObject *py__locals = NULL;\\n' \\\n 'PyObject *py__globals = NULL;\\n'\n\n py_objects = ', '.join(self.arg_specs.py_pointers())\n if py_objects:\n declare_py_objects = 'PyObject ' + py_objects +';\\n'\n else:\n declare_py_objects = ''\n\n py_vars = ' = '.join(self.arg_specs.py_variables())\n if py_vars:\n init_values = py_vars + ' = NULL;\\n\\n'\n else:\n init_values = ''\n\n parse_tuple = 'if(!PyArg_ParseTuple(args,\"OO:compiled_func\",'\\\n '&py__locals,'\\\n '&py__globals))\\n'\\\n ' return NULL;\\n'\n\n return declare_return + declare_py_objects + \\\n init_values + parse_tuple\n\n def arg_declaration_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.declaration_code(inline=1))\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_cleanup_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.cleanup_code())\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_local_dict_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.local_dict_code())\n code = string.join(arg_strings,\"\")\n return code\n\n\n def function_code(self):\n from ext_tools import indent\n decl_code = indent(self.arg_declaration_code(),4)\n cleanup_code = indent(self.arg_cleanup_code(),4)\n function_code = indent(self.code_block,4)\n #local_dict_code = indent(self.arg_local_dict_code(),4)\n\n try_code = 'try \\n' \\\n '{ \\n' \\\n ' PyObject* raw_locals = py_to_raw_dict(' \\\n 'py__locals,\"_locals\");\\n' \\\n ' PyObject* raw_globals = py_to_raw_dict(' \\\n 'py__globals,\"_globals\");\\n' + \\\n ' /* argument conversion code */ \\n' + \\\n decl_code + \\\n ' /* inline code */ \\n' + \\\n function_code + \\\n ' /*I would like to fill in changed ' \\\n 'locals and globals here...*/ \\n' \\\n '\\n} \\n'\n catch_code = \"catch(...) \\n\" \\\n \"{ \\n\" + \\\n \" return_val = NULL; \\n\" \\\n \" exception_occured = 1; \\n\" \\\n \"} \\n\" \n return_code = \" /* cleanup code */ \\n\" + \\\n cleanup_code + \\\n \" if(!return_val && !exception_occured)\\n\" \\\n \" {\\n \\n\" \\\n \" Py_INCREF(Py_None); \\n\" \\\n \" return_val = Py_None; \\n\" \\\n \" }\\n \\n\" \\\n \" return return_val; \\n\" \\\n \"} \\n\"\n\n all_code = self.function_declaration_code() + \\\n indent(self.parse_tuple_code(),4) + \\\n indent(try_code,4) + \\\n indent(catch_code,4) + \\\n return_code\n\n return all_code\n\n def python_function_definition_code(self):\n args = (self.name, self.name)\n function_decls = '{\"%s\",(PyCFunction)%s , METH_VARARGS},\\n' % args\n return function_decls\n\nclass inline_ext_module(ext_tools.ext_module):\n def __init__(self,name,compiler=''):\n ext_tools.ext_module.__init__(self,name,compiler)\n self._build_information.append(common_info.inline_info())\n\nfunction_cache = {}\ndef inline(code,arg_names=[],local_dict = None, global_dict = None,\n force = 0,\n compiler='',\n verbose = 0,\n support_code = None,\n customize=None,\n type_converters = None,\n auto_downcast=1,\n **kw):\n \"\"\" Inline C/C++ code within Python scripts.\n\n inline() compiles and executes C/C++ code on the fly. Variables\n in the local and global Python scope are also available in the\n C/C++ code. Values are passed to the C/C++ code by assignment\n much like variables passed are passed into a standard Python\n function. Values are returned from the C/C++ code through a\n special argument called return_val. Also, the contents of\n mutable objects can be changed within the C/C++ code and the\n changes remain after the C code exits and returns to Python.\n\n inline has quite a few options as listed below. Also, the keyword\n arguments for distutils extension modules are accepted to\n specify extra information needed for compiling.\n\n code -- string. A string of valid C++ code. It should not specify a\n return statement. Instead it should assign results that\n need to be returned to Python in the return_val.\n arg_names -- optional. list of strings. A list of Python variable names \n that should be transferred from Python into the C/C++ \n code. It defaults to an empty string.\n local_dict -- optional. dictionary. If specified, it is a dictionary\n of values that should be used as the local scope for the\n C/C++ code. If local_dict is not specified the local\n dictionary of the calling function is used.\n global_dict -- optional. dictionary. If specified, it is a dictionary\n of values that should be used as the global scope for\n the C/C++ code. If global_dict is not specified the\n global dictionary of the calling function is used.\n force -- optional. 0 or 1. default 0. If 1, the C++ code is\n compiled every time inline is called. This is really\n only useful for debugging, and probably only useful if\n your editing support_code a lot.\n compiler -- optional. string. The name of compiler to use when\n compiling. On windows, it understands 'msvc' and 'gcc'\n as well as all the compiler names understood by\n distutils. On Unix, it'll only understand the values\n understoof by distutils. ( I should add 'gcc' though\n to this).\n\n On windows, the compiler defaults to the Microsoft C++\n compiler. If this isn't available, it looks for mingw32\n (the gcc compiler).\n\n On Unix, it'll probably use the same compiler that was\n used when compiling Python. Cygwin's behavior should be\n similar.\n verbose -- optional. 0,1, or 2. defualt 0. Speficies how much\n much information is printed during the compile phase\n of inlining code. 0 is silent (except on windows with\n msvc where it still prints some garbage). 1 informs\n you when compiling starts, finishes, and how long it\n took. 2 prints out the command lines for the compilation\n process and can be useful if your having problems\n getting code to work. Its handy for finding the name\n of the .cpp file if you need to examine it. verbose has\n no affect if the compilation isn't necessary.\n support_code -- optional. string. A string of valid C++ code declaring\n extra code that might be needed by your compiled\n function. This could be declarations of functions,\n classes, or structures.\n customize -- optional. base_info.custom_info object. An alternative\n way to specifiy support_code, headers, etc. needed by\n the function see the compiler.base_info module for more\n details. (not sure this'll be used much).\n type_converters -- optional. list of type converters. These\n guys are what convert Python data types to C/C++ data\n types. If you'd like to use a different set of type\n conversions than the default, specify them here. Look\n in the type conversions section of the main\n documentation for examples.\n auto_downcast -- optional. 0 or 1. default 1. This only affects\n functions that have Numeric arrays as input variables.\n Setting this to 1 will cause all floating point values\n to be cast as float instead of double if all the\n Numeric arrays are of type float. If even one of the\n arrays has type double or double complex, all\n variables maintain there standard types.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n\n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list\n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability)\n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line)\n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n # this grabs the local variables from the *previous* call\n # frame -- that is the locals from the function that called\n # inline.\n global function_catalog\n\n call_frame = sys._getframe().f_back\n if local_dict is None:\n local_dict = call_frame.f_locals\n if global_dict is None:\n global_dict = call_frame.f_globals\n if force:\n module_dir = global_dict.get('__file__',None)\n func = compile_function(code,arg_names,local_dict,\n global_dict,module_dir,\n compiler=compiler,\n verbose=verbose,\n support_code = support_code,\n customize=customize,\n type_converters = type_converters,\n auto_downcast = auto_downcast,\n **kw)\n\n function_catalog.add_function(code,func,module_dir)\n results = attempt_function_call(code,local_dict,global_dict)\n else:\n # 1. try local cache\n try:\n results = apply(function_cache[code],(local_dict,global_dict))\n return results\n except TypeError, msg: \n msg = str(msg).strip()\n if msg[:16] == \"Conversion Error\":\n pass\n else:\n raise TypeError, msg\n except NameError, msg: \n msg = str(msg).strip()\n if msg[:16] == \"Conversion Error\":\n pass\n else:\n raise NameError, msg\n except KeyError:\n pass\n # 2. try function catalog\n try:\n results = attempt_function_call(code,local_dict,global_dict)\n # 3. build the function\n except ValueError:\n # compile the library\n module_dir = global_dict.get('__file__',None)\n func = compile_function(code,arg_names,local_dict,\n global_dict,module_dir,\n compiler=compiler,\n verbose=verbose,\n support_code = support_code,\n customize=customize,\n type_converters = type_converters,\n auto_downcast = auto_downcast,\n **kw)\n\n function_catalog.add_function(code,func,module_dir)\n results = attempt_function_call(code,local_dict,global_dict)\n return results\n\ndef attempt_function_call(code,local_dict,global_dict):\n # we try 3 levels here -- a local cache first, then the\n # catalog cache, and then persistent catalog.\n #\n global function_cache\n # 2. try catalog cache.\n function_list = function_catalog.get_functions_fast(code)\n for func in function_list:\n try:\n results = apply(func,(local_dict,global_dict))\n function_catalog.fast_cache(code,func)\n function_cache[code] = func\n return results\n except TypeError, msg: # should specify argument types here.\n # This should really have its own error type, instead of\n # checking the beginning of the message, but I don't know\n # how to define that yet.\n msg = str(msg)\n if msg[:16] == \"Conversion Error\":\n pass\n else:\n raise TypeError, msg\n except NameError, msg: \n msg = str(msg).strip()\n if msg[:16] == \"Conversion Error\":\n pass\n else:\n raise NameError, msg \n # 3. try persistent catalog\n module_dir = global_dict.get('__file__',None)\n function_list = function_catalog.get_functions(code,module_dir)\n for func in function_list:\n try:\n results = apply(func,(local_dict,global_dict))\n function_catalog.fast_cache(code,func)\n function_cache[code] = func\n return results\n except: # should specify argument types here.\n pass\n # if we get here, the function wasn't found\n raise ValueError, 'function with correct signature not found'\n\ndef inline_function_code(code,arg_names,local_dict=None,\n global_dict=None,auto_downcast = 1,\n type_converters=None,compiler=''):\n call_frame = sys._getframe().f_back\n if local_dict is None:\n local_dict = call_frame.f_locals\n if global_dict is None:\n global_dict = call_frame.f_globals\n ext_func = inline_ext_function('compiled_func',code,arg_names,\n local_dict,global_dict,auto_downcast,\n type_converters = type_converters)\n import build_tools\n compiler = build_tools.choose_compiler(compiler)\n ext_func.set_compiler(compiler)\n return ext_func.function_code()\n\ndef compile_function(code,arg_names,local_dict,global_dict,\n module_dir,\n compiler='',\n verbose = 0,\n support_code = None,\n customize = None,\n type_converters = None,\n auto_downcast=1,\n **kw):\n # figure out where to store and what to name the extension module\n # that will contain the function.\n #storage_dir = catalog.intermediate_dir()\n module_path = function_catalog.unique_module_name(code,module_dir)\n storage_dir, module_name = os.path.split(module_path)\n mod = inline_ext_module(module_name,compiler)\n\n # create the function. This relies on the auto_downcast and\n # type factories setting\n ext_func = inline_ext_function('compiled_func',code,arg_names,\n local_dict,global_dict,auto_downcast,\n type_converters = type_converters)\n mod.add_function(ext_func)\n\n # if customize (a custom_info object), then set the module customization.\n if customize:\n mod.customize = customize\n\n # add the extra \"support code\" needed by the function to the module.\n if support_code:\n mod.customize.add_support_code(support_code)\n \n # compile code in correct location, with the given compiler and verbosity\n # setting. All input keywords are passed through to distutils\n mod.compile(location=storage_dir,compiler=compiler,\n verbose=verbose, **kw)\n\n # import the module and return the function. Make sure\n # the directory where it lives is in the python path.\n try:\n sys.path.insert(0,storage_dir)\n exec 'import ' + module_name\n func = eval(module_name+'.compiled_func')\n finally:\n del sys.path[0]\n return func\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == \"__main__\":\n test_function()\n\n", "source_code_before": "# should re-write compiled functions to take a local and global dict\n# as input.\nimport sys,os\nimport ext_tools\nimport string\nimport catalog\nimport common_info\n\n# not an easy way for the user_path_list to come in here.\n# the PYTHONCOMPILED environment variable offers the most hope.\n\nfunction_catalog = catalog.catalog()\n\n\nclass inline_ext_function(ext_tools.ext_function):\n # Some specialization is needed for inline extension functions\n def function_declaration_code(self):\n code = 'static PyObject* %s(PyObject*self, PyObject* args)\\n{\\n'\n return code % self.name\n\n def template_declaration_code(self):\n code = 'template\\n' \\\n 'static PyObject* %s(PyObject*self, PyObject* args)\\n{\\n'\n return code % self.name\n\n def parse_tuple_code(self):\n \"\"\" Create code block for PyArg_ParseTuple. Variable declarations\n for all PyObjects are done also.\n\n This code got a lot uglier when I added local_dict...\n \"\"\"\n declare_return = 'PyObject *return_val = NULL;\\n' \\\n 'int exception_occured = 0;\\n' \\\n 'PyObject *py__locals = NULL;\\n' \\\n 'PyObject *py__globals = NULL;\\n'\n\n py_objects = ', '.join(self.arg_specs.py_pointers())\n if py_objects:\n declare_py_objects = 'PyObject ' + py_objects +';\\n'\n else:\n declare_py_objects = ''\n\n py_vars = ' = '.join(self.arg_specs.py_variables())\n if py_vars:\n init_values = py_vars + ' = NULL;\\n\\n'\n else:\n init_values = ''\n\n parse_tuple = 'if(!PyArg_ParseTuple(args,\"OO:compiled_func\",'\\\n '&py__locals,'\\\n '&py__globals))\\n'\\\n ' return NULL;\\n'\n\n return declare_return + declare_py_objects + \\\n init_values + parse_tuple\n\n def arg_declaration_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.declaration_code(inline=1))\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_cleanup_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.cleanup_code())\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_local_dict_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.local_dict_code())\n code = string.join(arg_strings,\"\")\n return code\n\n\n def function_code(self):\n from ext_tools import indent\n decl_code = indent(self.arg_declaration_code(),4)\n cleanup_code = indent(self.arg_cleanup_code(),4)\n function_code = indent(self.code_block,4)\n #local_dict_code = indent(self.arg_local_dict_code(),4)\n\n try_code = 'try \\n' \\\n '{ \\n' \\\n ' PyObject* raw_locals = py_to_raw_dict(' \\\n 'py__locals,\"_locals\");\\n' \\\n ' PyObject* raw_globals = py_to_raw_dict(' \\\n 'py__globals,\"_globals\");\\n' + \\\n ' /* argument conversion code */ \\n' + \\\n decl_code + \\\n ' /* inline code */ \\n' + \\\n function_code + \\\n ' /*I would like to fill in changed ' \\\n 'locals and globals here...*/ \\n' \\\n '\\n} \\n'\n catch_code = \"catch(...) \\n\" \\\n \"{ \\n\" + \\\n \" return_val = NULL; \\n\" \\\n \" exception_occured = 1; \\n\" \\\n \"} \\n\" \n return_code = \" /* cleanup code */ \\n\" + \\\n cleanup_code + \\\n \" if(!return_val && !exception_occured)\\n\" \\\n \" {\\n \\n\" \\\n \" Py_INCREF(Py_None); \\n\" \\\n \" return_val = Py_None; \\n\" \\\n \" }\\n \\n\" \\\n \" return return_val; \\n\" \\\n \"} \\n\"\n\n all_code = self.function_declaration_code() + \\\n indent(self.parse_tuple_code(),4) + \\\n indent(try_code,4) + \\\n indent(catch_code,4) + \\\n return_code\n\n return all_code\n\n def python_function_definition_code(self):\n args = (self.name, self.name)\n function_decls = '{\"%s\",(PyCFunction)%s , METH_VARARGS},\\n' % args\n return function_decls\n\nclass inline_ext_module(ext_tools.ext_module):\n def __init__(self,name,compiler=''):\n ext_tools.ext_module.__init__(self,name,compiler)\n self._build_information.append(common_info.inline_info())\n\nfunction_cache = {}\ndef inline(code,arg_names=[],local_dict = None, global_dict = None,\n force = 0,\n compiler='',\n verbose = 0,\n support_code = None,\n customize=None,\n type_converters = None,\n auto_downcast=1,\n **kw):\n \"\"\" Inline C/C++ code within Python scripts.\n\n inline() compiles and executes C/C++ code on the fly. Variables\n in the local and global Python scope are also available in the\n C/C++ code. Values are passed to the C/C++ code by assignment\n much like variables passed are passed into a standard Python\n function. Values are returned from the C/C++ code through a\n special argument called return_val. Also, the contents of\n mutable objects can be changed within the C/C++ code and the\n changes remain after the C code exits and returns to Python.\n\n inline has quite a few options as listed below. Also, the keyword\n arguments for distutils extension modules are accepted to\n specify extra information needed for compiling.\n\n code -- string. A string of valid C++ code. It should not specify a\n return statement. Instead it should assign results that\n need to be returned to Python in the return_val.\n arg_names -- optional. list of strings. A list of Python variable names \n that should be transferred from Python into the C/C++ \n code. It defaults to an empty string.\n local_dict -- optional. dictionary. If specified, it is a dictionary\n of values that should be used as the local scope for the\n C/C++ code. If local_dict is not specified the local\n dictionary of the calling function is used.\n global_dict -- optional. dictionary. If specified, it is a dictionary\n of values that should be used as the global scope for\n the C/C++ code. If global_dict is not specified the\n global dictionary of the calling function is used.\n force -- optional. 0 or 1. default 0. If 1, the C++ code is\n compiled every time inline is called. This is really\n only useful for debugging, and probably only useful if\n your editing support_code a lot.\n compiler -- optional. string. The name of compiler to use when\n compiling. On windows, it understands 'msvc' and 'gcc'\n as well as all the compiler names understood by\n distutils. On Unix, it'll only understand the values\n understoof by distutils. ( I should add 'gcc' though\n to this).\n\n On windows, the compiler defaults to the Microsoft C++\n compiler. If this isn't available, it looks for mingw32\n (the gcc compiler).\n\n On Unix, it'll probably use the same compiler that was\n used when compiling Python. Cygwin's behavior should be\n similar.\n verbose -- optional. 0,1, or 2. defualt 0. Speficies how much\n much information is printed during the compile phase\n of inlining code. 0 is silent (except on windows with\n msvc where it still prints some garbage). 1 informs\n you when compiling starts, finishes, and how long it\n took. 2 prints out the command lines for the compilation\n process and can be useful if your having problems\n getting code to work. Its handy for finding the name\n of the .cpp file if you need to examine it. verbose has\n no affect if the compilation isn't necessary.\n support_code -- optional. string. A string of valid C++ code declaring\n extra code that might be needed by your compiled\n function. This could be declarations of functions,\n classes, or structures.\n customize -- optional. base_info.custom_info object. An alternative\n way to specifiy support_code, headers, etc. needed by\n the function see the compiler.base_info module for more\n details. (not sure this'll be used much).\n type_converters -- optional. list of type converters. These\n guys are what convert Python data types to C/C++ data\n types. If you'd like to use a different set of type\n conversions than the default, specify them here. Look\n in the type conversions section of the main\n documentation for examples.\n auto_downcast -- optional. 0 or 1. default 1. This only affects\n functions that have Numeric arrays as input variables.\n Setting this to 1 will cause all floating point values\n to be cast as float instead of double if all the\n Numeric arrays are of type float. If even one of the\n arrays has type double or double complex, all\n variables maintain there standard types.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n\n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list\n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability)\n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line)\n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n # this grabs the local variables from the *previous* call\n # frame -- that is the locals from the function that called\n # inline.\n global function_catalog\n\n call_frame = sys._getframe().f_back\n if local_dict is None:\n local_dict = call_frame.f_locals\n if global_dict is None:\n global_dict = call_frame.f_globals\n if force:\n module_dir = global_dict.get('__file__',None)\n func = compile_function(code,arg_names,local_dict,\n global_dict,module_dir,\n compiler=compiler,\n verbose=verbose,\n support_code = support_code,\n customize=customize,\n type_converters = type_converters,\n auto_downcast = auto_downcast,\n **kw)\n\n function_catalog.add_function(code,func,module_dir)\n results = attempt_function_call(code,local_dict,global_dict)\n else:\n # 1. try local cache\n try:\n results = apply(function_cache[code],(local_dict,global_dict))\n return results\n except TypeError, msg: \n msg = str(msg).strip()\n if msg[:16] == \"Conversion Error\":\n pass\n else:\n raise TypeError, msg\n except NameError, msg: \n msg = str(msg).strip()\n if msg[:16] == \"Conversion Error\":\n pass\n else:\n raise NameError, msg\n except KeyError:\n pass\n # 2. try function catalog\n try:\n results = attempt_function_call(code,local_dict,global_dict)\n # 3. build the function\n except ValueError:\n # compile the library\n module_dir = global_dict.get('__file__',None)\n func = compile_function(code,arg_names,local_dict,\n global_dict,module_dir,\n compiler=compiler,\n verbose=verbose,\n support_code = support_code,\n customize=customize,\n type_converters = type_converters,\n auto_downcast = auto_downcast,\n **kw)\n\n function_catalog.add_function(code,func,module_dir)\n results = attempt_function_call(code,local_dict,global_dict)\n return results\n\ndef attempt_function_call(code,local_dict,global_dict):\n # we try 3 levels here -- a local cache first, then the\n # catalog cache, and then persistent catalog.\n #\n global function_cache\n # 2. try catalog cache.\n function_list = function_catalog.get_functions_fast(code)\n for func in function_list:\n try:\n results = apply(func,(local_dict,global_dict))\n function_catalog.fast_cache(code,func)\n function_cache[code] = func\n return results\n except TypeError, msg: # should specify argument types here.\n # This should really have its own error type, instead of\n # checking the beginning of the message, but I don't know\n # how to define that yet.\n msg = str(msg)\n if msg[:16] == \"Conversion Error\":\n pass\n else:\n raise TypeError, msg\n except NameError, msg: \n msg = str(msg).strip()\n if msg[:16] == \"Conversion Error\":\n pass\n else:\n raise NameError, msg \n # 3. try persistent catalog\n module_dir = global_dict.get('__file__',None)\n function_list = function_catalog.get_functions(code,module_dir)\n for func in function_list:\n try:\n results = apply(func,(local_dict,global_dict))\n function_catalog.fast_cache(code,func)\n function_cache[code] = func\n return results\n except: # should specify argument types here.\n pass\n # if we get here, the function wasn't found\n raise ValueError, 'function with correct signature not found'\n\ndef inline_function_code(code,arg_names,local_dict=None,\n global_dict=None,auto_downcast = 1,\n type_converters=None,compiler=''):\n call_frame = sys._getframe().f_back\n if local_dict is None:\n local_dict = call_frame.f_locals\n if global_dict is None:\n global_dict = call_frame.f_globals\n ext_func = inline_ext_function('compiled_func',code,arg_names,\n local_dict,global_dict,auto_downcast,\n type_converters = type_converters)\n import build_tools\n compiler = build_tools.choose_compiler(compiler)\n ext_func.set_compiler(compiler)\n return ext_func.function_code()\n\ndef compile_function(code,arg_names,local_dict,global_dict,\n module_dir,\n compiler='',\n verbose = 0,\n support_code = None,\n customize = None,\n type_converters = None,\n auto_downcast=1,\n **kw):\n # figure out where to store and what to name the extension module\n # that will contain the function.\n #storage_dir = catalog.intermediate_dir()\n module_path = function_catalog.unique_module_name(code,module_dir)\n storage_dir, module_name = os.path.split(module_path)\n mod = inline_ext_module(module_name,compiler)\n\n # create the function. This relies on the auto_downcast and\n # type factories setting\n ext_func = inline_ext_function('compiled_func',code,arg_names,\n local_dict,global_dict,auto_downcast,\n type_converters = type_converters)\n mod.add_function(ext_func)\n\n # if customize (a custom_info object), then set the module customization.\n if customize:\n mod.customize = customize\n\n # add the extra \"support code\" needed by the function to the module.\n if support_code:\n mod.customize.add_support_code(support_code)\n \n # compile code in correct location, with the given compiler and verbosity\n # setting. All input keywords are passed through to distutils\n mod.compile(location=storage_dir,compiler=compiler,\n verbose=verbose, **kw)\n\n # import the module and return the function. Make sure\n # the directory where it lives is in the python path.\n try:\n sys.path.insert(0,storage_dir)\n exec 'import ' + module_name\n func = eval(module_name+'.compiled_func')\n finally:\n del sys.path[0]\n return func\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == \"__main__\":\n test_function()\n\n", "methods": [ { "name": "function_declaration_code", "long_name": "function_declaration_code( self )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 17, "end_line": 19, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "template_declaration_code", "long_name": "template_declaration_code( self )", "filename": "inline_tools.py", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 21, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "parse_tuple_code", "long_name": "parse_tuple_code( self )", "filename": "inline_tools.py", "nloc": 21, "complexity": 3, "token_count": 89, "parameters": [ "self" ], "start_line": 26, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 1 }, { "name": "arg_declaration_code", "long_name": "arg_declaration_code( self )", "filename": "inline_tools.py", "nloc": 6, "complexity": 2, "token_count": 41, "parameters": [ "self" ], "start_line": 57, "end_line": 62, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "arg_cleanup_code", "long_name": "arg_cleanup_code( self )", "filename": "inline_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 64, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "arg_local_dict_code", "long_name": "arg_local_dict_code( self )", "filename": "inline_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 71, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "inline_tools.py", "nloc": 38, "complexity": 1, "token_count": 148, "parameters": [ "self" ], "start_line": 79, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "inline_tools.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 122, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , compiler = '' )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 35, "parameters": [ "self", "name", "compiler" ], "start_line": 128, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "inline", "long_name": "inline( code , arg_names = [ ] , local_dict = None , global_dict = None , force = 0 , compiler = '' , verbose = 0 , support_code = None , customize = None , type_converters = None , auto_downcast = 1 , ** kw )", "filename": "inline_tools.py", "nloc": 62, "complexity": 10, "token_count": 330, "parameters": [ "code", "arg_names", "local_dict", "global_dict", "force", "compiler", "verbose", "support_code", "customize", "type_converters", "auto_downcast", "kw" ], "start_line": 133, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 200, "top_nesting_level": 0 }, { "name": "attempt_function_call", "long_name": "attempt_function_call( code , local_dict , global_dict )", "filename": "inline_tools.py", "nloc": 32, "complexity": 8, "token_count": 174, "parameters": [ "code", "local_dict", "global_dict" ], "start_line": 334, "end_line": 374, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 0 }, { "name": "inline_function_code", "long_name": "inline_function_code( code , arg_names , local_dict = None , global_dict = None , auto_downcast = 1 , type_converters = None , compiler = '' )", "filename": "inline_tools.py", "nloc": 15, "complexity": 3, "token_count": 98, "parameters": [ "code", "arg_names", "local_dict", "global_dict", "auto_downcast", "type_converters", "compiler" ], "start_line": 376, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "compile_function", "long_name": "compile_function( code , arg_names , local_dict , global_dict , module_dir , compiler = '' , verbose = 0 , support_code = None , customize = None , type_converters = None , auto_downcast = 1 , ** kw )", "filename": "inline_tools.py", "nloc": 29, "complexity": 4, "token_count": 169, "parameters": [ "code", "arg_names", "local_dict", "global_dict", "module_dir", "compiler", "verbose", "support_code", "customize", "type_converters", "auto_downcast", "kw" ], "start_line": 392, "end_line": 436, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 438, "end_line": 440, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 442, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "function_declaration_code", "long_name": "function_declaration_code( self )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 17, "end_line": 19, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "template_declaration_code", "long_name": "template_declaration_code( self )", "filename": "inline_tools.py", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 21, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "parse_tuple_code", "long_name": "parse_tuple_code( self )", "filename": "inline_tools.py", "nloc": 21, "complexity": 3, "token_count": 89, "parameters": [ "self" ], "start_line": 26, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 1 }, { "name": "arg_declaration_code", "long_name": "arg_declaration_code( self )", "filename": "inline_tools.py", "nloc": 6, "complexity": 2, "token_count": 41, "parameters": [ "self" ], "start_line": 57, "end_line": 62, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "arg_cleanup_code", "long_name": "arg_cleanup_code( self )", "filename": "inline_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 64, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "arg_local_dict_code", "long_name": "arg_local_dict_code( self )", "filename": "inline_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 71, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "inline_tools.py", "nloc": 38, "complexity": 1, "token_count": 148, "parameters": [ "self" ], "start_line": 79, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "inline_tools.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 122, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , compiler = '' )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 35, "parameters": [ "self", "name", "compiler" ], "start_line": 128, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "inline", "long_name": "inline( code , arg_names = [ ] , local_dict = None , global_dict = None , force = 0 , compiler = '' , verbose = 0 , support_code = None , customize = None , type_converters = None , auto_downcast = 1 , ** kw )", "filename": "inline_tools.py", "nloc": 62, "complexity": 10, "token_count": 330, "parameters": [ "code", "arg_names", "local_dict", "global_dict", "force", "compiler", "verbose", "support_code", "customize", "type_converters", "auto_downcast", "kw" ], "start_line": 133, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 200, "top_nesting_level": 0 }, { "name": "attempt_function_call", "long_name": "attempt_function_call( code , local_dict , global_dict )", "filename": "inline_tools.py", "nloc": 32, "complexity": 8, "token_count": 174, "parameters": [ "code", "local_dict", "global_dict" ], "start_line": 334, "end_line": 374, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 0 }, { "name": "inline_function_code", "long_name": "inline_function_code( code , arg_names , local_dict = None , global_dict = None , auto_downcast = 1 , type_converters = None , compiler = '' )", "filename": "inline_tools.py", "nloc": 15, "complexity": 3, "token_count": 98, "parameters": [ "code", "arg_names", "local_dict", "global_dict", "auto_downcast", "type_converters", "compiler" ], "start_line": 376, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "compile_function", "long_name": "compile_function( code , arg_names , local_dict , global_dict , module_dir , compiler = '' , verbose = 0 , support_code = None , customize = None , type_converters = None , auto_downcast = 1 , ** kw )", "filename": "inline_tools.py", "nloc": 29, "complexity": 4, "token_count": 169, "parameters": [ "code", "arg_names", "local_dict", "global_dict", "module_dir", "compiler", "verbose", "support_code", "customize", "type_converters", "auto_downcast", "kw" ], "start_line": 392, "end_line": 436, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 438, "end_line": 440, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 442, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 442, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 438, "end_line": 440, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 246, "complexity": 41, "token_count": 1322, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "weave/setup.py", "new_path": "weave/setup.py", "filename": "setup.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -6,7 +6,7 @@\n \n # Enough changes to bump the number. We need a global method for\n # versioning\n-version = \"0.2.3\"\n+version = \"0.3.0.alpha\"\n \n def stand_alone_package(with_dependencies = 0):\n path = get_path(__name__)\n@@ -15,7 +15,7 @@ def stand_alone_package(with_dependencies = 0):\n try:\n primary = ['weave']\n if with_dependencies:\n- dependencies= ['scipy_distutils', 'scipy_base.testing'] \n+ dependencies= ['scipy_distutils','scipy_test'] \n else:\n dependencies = [] \n \n", "added_lines": 2, "deleted_lines": 2, "source_code": "#!/usr/bin/env python\nimport os,sys\nfrom scipy_distutils.core import setup\nfrom scipy_distutils.misc_util import get_path, merge_config_dicts\nfrom scipy_distutils.misc_util import package_config\n\n# Enough changes to bump the number. We need a global method for\n# versioning\nversion = \"0.3.0.alpha\"\n \ndef stand_alone_package(with_dependencies = 0):\n path = get_path(__name__)\n old_path = os.getcwd()\n os.chdir(path)\n try:\n primary = ['weave']\n if with_dependencies:\n dependencies= ['scipy_distutils','scipy_test'] \n else:\n dependencies = [] \n \n print 'dep:', dependencies\n config_dict = package_config(primary,dependencies)\n\n setup (name = \"weave\",\n version = version,\n description = \"Tools for inlining C/C++ in Python\",\n author = \"Eric Jones\",\n author_email = \"eric@enthought.com\",\n licence = \"SciPy License (BSD Style)\",\n url = 'http://www.scipy.org',\n **config_dict\n ) \n finally:\n os.chdir(old_path)\n\nif __name__ == '__main__':\n import sys\n if '--without-dependencies' in sys.argv:\n with_dependencies = 0\n sys.argv.remove('--without-dependencies')\n else:\n with_dependencies = 1 \n stand_alone_package(with_dependencies)\n \n", "source_code_before": "#!/usr/bin/env python\nimport os,sys\nfrom scipy_distutils.core import setup\nfrom scipy_distutils.misc_util import get_path, merge_config_dicts\nfrom scipy_distutils.misc_util import package_config\n\n# Enough changes to bump the number. We need a global method for\n# versioning\nversion = \"0.2.3\"\n \ndef stand_alone_package(with_dependencies = 0):\n path = get_path(__name__)\n old_path = os.getcwd()\n os.chdir(path)\n try:\n primary = ['weave']\n if with_dependencies:\n dependencies= ['scipy_distutils', 'scipy_base.testing'] \n else:\n dependencies = [] \n \n print 'dep:', dependencies\n config_dict = package_config(primary,dependencies)\n\n setup (name = \"weave\",\n version = version,\n description = \"Tools for inlining C/C++ in Python\",\n author = \"Eric Jones\",\n author_email = \"eric@enthought.com\",\n licence = \"SciPy License (BSD Style)\",\n url = 'http://www.scipy.org',\n **config_dict\n ) \n finally:\n os.chdir(old_path)\n\nif __name__ == '__main__':\n import sys\n if '--without-dependencies' in sys.argv:\n with_dependencies = 0\n sys.argv.remove('--without-dependencies')\n else:\n with_dependencies = 1 \n stand_alone_package(with_dependencies)\n \n", "methods": [ { "name": "stand_alone_package", "long_name": "stand_alone_package( with_dependencies = 0 )", "filename": "setup.py", "nloc": 23, "complexity": 3, "token_count": 102, "parameters": [ "with_dependencies" ], "start_line": 11, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 } ], "methods_before": [ { "name": "stand_alone_package", "long_name": "stand_alone_package( with_dependencies = 0 )", "filename": "setup.py", "nloc": 23, "complexity": 3, "token_count": 102, "parameters": [ "with_dependencies" ], "start_line": 11, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "stand_alone_package", "long_name": "stand_alone_package( with_dependencies = 0 )", "filename": "setup.py", "nloc": 23, "complexity": 3, "token_count": 102, "parameters": [ "with_dependencies" ], "start_line": 11, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 } ], "nloc": 36, "complexity": 3, "token_count": 164, "diff_parsed": { "added": [ "version = \"0.3.0.alpha\"", " dependencies= ['scipy_distutils','scipy_test']" ], "deleted": [ "version = \"0.2.3\"", " dependencies= ['scipy_distutils', 'scipy_base.testing']" ] } }, { "old_path": "weave/size_check.py", "new_path": "weave/size_check.py", "filename": "size_check.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -284,10 +284,10 @@ def take(ary,axis=0): raise NotImplemented\n # and all the rest\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n", "added_lines": 2, "deleted_lines": 2, "source_code": "from Numeric import *\n\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from scipy_base.fastumath import *\nexcept:\n pass # scipy_base.fastumath not available \n\nfrom ast_tools import *\nfrom types import *\nimport sys\n\ndef time_it():\n import time\n \n expr = \"ex[:,1:,1:] = ca_x[:,1:,1:] * ex[:,1:,1:]\" \\\n \"+ cb_y_x[:,1:,1:] * (hz[:,1:,1:] - hz[:,:-1,1:])\" \\\n \"- cb_z_x[:,1:,1:] * (hy[:,1:,1:] - hy[:,1:,:-1])\" \n ex = ones((10,10,10),typecode=Float32)\n ca_x = ones((10,10,10),typecode=Float32)\n cb_y_x = ones((10,10,10),typecode=Float32)\n cb_z_x = ones((10,10,10),typecode=Float32)\n hz = ones((10,10,10),typecode=Float32)\n hy = ones((10,10,10),typecode=Float32)\n \n N = 1\n t1 = time.time()\n for i in range(N):\n passed = check_expr(expr,locals())\n t2 = time.time()\n print 'time per call:', (t2 - t1)/N\n print 'passed:', passed\n \ndef check_expr(expr,local_vars,global_vars={}):\n \"\"\" Currently only checks expressions (not suites).\n Doesn't check that lhs = rhs. checked by compiled func though\n \"\"\"\n values ={}\n \n #first handle the globals\n for var,val in global_vars.items():\n if type(val) in [ArrayType]: \n values[var] = dummy_array(val,name=var)\n elif type(val) in [IntType,LongType,FloatType,ComplexType]: \n values[var] = val\n #now handle the locals \n for var,val in local_vars.items():\n if type(val) in [ArrayType]: \n values[var] = dummy_array(val,name=var)\n elif type(val) in [IntType,LongType,FloatType,ComplexType]: \n values[var] = val\n exec(expr,values)\n try:\n exec(expr,values)\n except:\n try:\n eval(expr,values)\n except:\n return 0 \n return 1 \n \nempty = array(())\nempty_slice = slice(None)\n\ndef make_same_length(x,y):\n try:\n Nx = len(x)\n except:\n Nx = 0\n try:\n Ny = len(y)\n except:\n Ny = 0\n if Nx == Ny == 0:\n return empty,empty\n elif Nx == Ny:\n return asarray(x),asarray(y)\n else: \n diff = abs(Nx - Ny)\n front = ones(diff,Int)\n if Nx > Ny:\n return asarray(x), concatenate((front,y))\n elif Ny > Nx:\n return concatenate((front,x)),asarray(y) \n\ndef binary_op_size(xx,yy):\n \"\"\" This returns the resulting size from operating on xx, and yy\n with a binary operator. It accounts for broadcasting, and\n throws errors if the array sizes are incompatible.\n \"\"\"\n x,y = make_same_length(xx,yy)\n res = zeros(len(x))\n for i in range(len(x)):\n if x[i] == y[i]:\n res[i] = x[i]\n elif x[i] == 1:\n res[i] = y[i]\n elif y[i] == 1:\n res[i] = x[i]\n else:\n # offer more information here about which variables.\n raise ValueError, \"frames are not aligned\"\n return res \nclass dummy_array:\n def __init__(self,ary,ary_is_shape = 0,name=None):\n self.name = name\n if ary_is_shape:\n self.shape = ary\n #self.shape = asarray(ary)\n else:\n try:\n self.shape = shape(ary)\n except:\n self.shape = empty\n #self.value = ary \n def binary_op(self,other):\n try: \n x = other.shape\n except AttributeError:\n x = empty \n new_shape = binary_op_size(self.shape,x)\n return dummy_array(new_shape,1)\n def __cmp__(self,other):\n # This isn't an exact compare, but does work for == \n # cluge for Numeric\n if type(other) in [IntType,LongType,FloatType,ComplexType]:\n return 0\n if len(self.shape) == len(other.shape) == 0:\n return 0\n return not alltrue(equal(self.shape,other.shape))\n\n def __add__(self,other): return self.binary_op(other)\n def __radd__(self,other): return self.binary_op(other)\n def __sub__(self,other): return self.binary_op(other)\n def __rsub__(self,other): return self.binary_op(other)\n def __mul__(self,other): return self.binary_op(other)\n def __rmul__(self,other): return self.binary_op(other)\n def __div__(self,other): return self.binary_op(other)\n def __rdiv__(self,other): return self.binary_op(other)\n def __mod__(self,other): return self.binary_op(other)\n def __rmod__(self,other): return self.binary_op(other)\n def __lshift__(self,other): return self.binary_op(other)\n def __rshift__(self,other): return self.binary_op(other)\n # unary ops\n def __neg__(self,other): return self\n def __pos__(self,other): return self\n def __abs__(self,other): return self\n def __invert__(self,other): return self \n # Not sure what to do with coersion ops. Ignore for now.\n #\n # not currently supported by compiler.\n # __divmod__\n # __pow__\n # __rpow__\n # __and__\n # __or__\n # __xor__\n # item access and slicing \n def __setitem__(self,indices,val):\n #ignore for now\n pass\n def __len__(self):\n return self.shape[0]\n def __getslice__(self,i,j):\n # enabling the following would make class compatible with\n # lists. Its current incarnation is compatible with arrays.\n # Both this and Numeric should have this FIXED to correspond\n # to lists.\n #i = max(i, 0); j = max(j, 0)\n return self.__getitem__((slice(i,j),))\n def __getitem__(self,indices):\n # ayeyaya this is a mess\n #print indices, type(indices), indices.shape \n if type(indices) is not TupleType:\n indices = (indices,)\n if Ellipsis in indices:\n raise IndexError, \"Ellipsis not currently supported\"\n new_dims = [] \n dim = 0 \n for index in indices:\n try:\n dim_len = self.shape[dim]\n except IndexError:\n raise IndexError, \"To many indices specified\"\n \n #if (type(index) is SliceType and index.start == index.stop == index.step):\n if (index is empty_slice):\n slc_len = dim_len\n elif type(index) is SliceType:\n beg,end,step = index.start,index.stop,index.step \n # handle if they are dummy arrays\n #if hasattr(beg,'value') and type(beg.value) != ArrayType:\n # beg = beg.value\n #if hasattr(end,'value') and type(end.value) != ArrayType:\n # end = end.value\n #if hasattr(step,'value') and type(step.value) != ArrayType:\n # step = step.value \n if beg is None: beg = 0\n if end == sys.maxint or end is None:\n end = dim_len\n if step is None: \n step = 1\n \n if beg < 0: beg += dim_len\n if end < 0: end += dim_len\n # the following is list like behavior,\n # which isn't adhered to by arrays. \n # FIX THIS ANOMOLY IN NUMERIC!\n if beg < 0: beg = 0\n if beg > dim_len: beg = dim_len\n if end < 0: end = 0\n if end > dim_len: end = dim_len\n # This is rubbish. \n if beg == end:\n beg,end,step = 0,0,1\n elif beg >= dim_len and step > 0:\n beg,end,step = 0,0,1\n #elif index.step > 0 and beg <= end:\n elif step > 0 and beg <= end:\n pass #slc_len = abs(divide(end-beg-1,step)+1) \n # handle [::-1] and [-1::-1] correctly \n #elif index.step > 0 and beg > end:\n elif step > 0 and beg > end:\n beg,end,step = 0,0,1\n elif(step < 0 and index.start is None and index.stop is None):\n beg,end,step = 0,dim_len,-step\n elif(step < 0 and index.start is None):\n # +1 because negative stepping is inclusive\n beg,end,step = end+1,dim_len,-step \n elif(step < 0 and index.stop is None):\n beg,end,step = 0,beg+1,-step\n elif(step < 0 and beg > end): \n beg,end,step = end,beg,-step\n elif(step < 0 and beg < end): \n beg,end,step = 0,0,-step\n slc_len = abs(divide(end-beg-1,step)+1)\n new_dims.append(slc_len)\n else:\n if index < 0: index += dim_len\n if index >=0 and index < dim_len:\n #this reduces the array dimensions by one\n pass\n else:\n raise IndexError, \"Index out of range\" \n dim += 1 \n new_dims.extend(self.shape[dim:])\n if 0 in new_dims:\n raise IndexError, \"Zero length slices not currently supported\"\n return dummy_array(new_dims,1)\n def __repr__(self):\n val = str((self.name, str(self.shape)))\n return val \n\ndef unary(ary):\n return ary\n\ndef not_implemented(ary):\n return ary\n \n#all imported from Numeric and need to be reassigned.\nunary_op = [arccos, arcsin, arctan, cos, cosh, sin, sinh, \n exp,ceil,floor,fabs,log,log10,sqrt]\n\nunsupported = [argmin,argmax, argsort,around, absolute,sign,negative,floor]\n\nfor func in unary_op:\n func = unary\n \nfor func in unsupported:\n func = not_implemented\n \ndef reduction(ary,axis=0):\n if axis < 0:\n axis += len(ary.shape) \n if axis < 0 or axis >= len(ary.shape):\n raise ValueError, \"Dimension not in array\" \n new_dims = list(ary.shape[:axis]) + list(ary.shape[axis+1:])\n return dummy_array(new_dims,1) \n\n# functions currently not supported by compiler\n# reductions are gonna take some array reordering for the general case,\n# so this is gonna take some thought (probably some tree manipulation).\ndef take(ary,axis=0): raise NotImplemented\n# and all the rest\n \ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n", "source_code_before": "from Numeric import *\n\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from scipy_base.fastumath import *\nexcept:\n pass # scipy_base.fastumath not available \n\nfrom ast_tools import *\nfrom types import *\nimport sys\n\ndef time_it():\n import time\n \n expr = \"ex[:,1:,1:] = ca_x[:,1:,1:] * ex[:,1:,1:]\" \\\n \"+ cb_y_x[:,1:,1:] * (hz[:,1:,1:] - hz[:,:-1,1:])\" \\\n \"- cb_z_x[:,1:,1:] * (hy[:,1:,1:] - hy[:,1:,:-1])\" \n ex = ones((10,10,10),typecode=Float32)\n ca_x = ones((10,10,10),typecode=Float32)\n cb_y_x = ones((10,10,10),typecode=Float32)\n cb_z_x = ones((10,10,10),typecode=Float32)\n hz = ones((10,10,10),typecode=Float32)\n hy = ones((10,10,10),typecode=Float32)\n \n N = 1\n t1 = time.time()\n for i in range(N):\n passed = check_expr(expr,locals())\n t2 = time.time()\n print 'time per call:', (t2 - t1)/N\n print 'passed:', passed\n \ndef check_expr(expr,local_vars,global_vars={}):\n \"\"\" Currently only checks expressions (not suites).\n Doesn't check that lhs = rhs. checked by compiled func though\n \"\"\"\n values ={}\n \n #first handle the globals\n for var,val in global_vars.items():\n if type(val) in [ArrayType]: \n values[var] = dummy_array(val,name=var)\n elif type(val) in [IntType,LongType,FloatType,ComplexType]: \n values[var] = val\n #now handle the locals \n for var,val in local_vars.items():\n if type(val) in [ArrayType]: \n values[var] = dummy_array(val,name=var)\n elif type(val) in [IntType,LongType,FloatType,ComplexType]: \n values[var] = val\n exec(expr,values)\n try:\n exec(expr,values)\n except:\n try:\n eval(expr,values)\n except:\n return 0 \n return 1 \n \nempty = array(())\nempty_slice = slice(None)\n\ndef make_same_length(x,y):\n try:\n Nx = len(x)\n except:\n Nx = 0\n try:\n Ny = len(y)\n except:\n Ny = 0\n if Nx == Ny == 0:\n return empty,empty\n elif Nx == Ny:\n return asarray(x),asarray(y)\n else: \n diff = abs(Nx - Ny)\n front = ones(diff,Int)\n if Nx > Ny:\n return asarray(x), concatenate((front,y))\n elif Ny > Nx:\n return concatenate((front,x)),asarray(y) \n\ndef binary_op_size(xx,yy):\n \"\"\" This returns the resulting size from operating on xx, and yy\n with a binary operator. It accounts for broadcasting, and\n throws errors if the array sizes are incompatible.\n \"\"\"\n x,y = make_same_length(xx,yy)\n res = zeros(len(x))\n for i in range(len(x)):\n if x[i] == y[i]:\n res[i] = x[i]\n elif x[i] == 1:\n res[i] = y[i]\n elif y[i] == 1:\n res[i] = x[i]\n else:\n # offer more information here about which variables.\n raise ValueError, \"frames are not aligned\"\n return res \nclass dummy_array:\n def __init__(self,ary,ary_is_shape = 0,name=None):\n self.name = name\n if ary_is_shape:\n self.shape = ary\n #self.shape = asarray(ary)\n else:\n try:\n self.shape = shape(ary)\n except:\n self.shape = empty\n #self.value = ary \n def binary_op(self,other):\n try: \n x = other.shape\n except AttributeError:\n x = empty \n new_shape = binary_op_size(self.shape,x)\n return dummy_array(new_shape,1)\n def __cmp__(self,other):\n # This isn't an exact compare, but does work for == \n # cluge for Numeric\n if type(other) in [IntType,LongType,FloatType,ComplexType]:\n return 0\n if len(self.shape) == len(other.shape) == 0:\n return 0\n return not alltrue(equal(self.shape,other.shape))\n\n def __add__(self,other): return self.binary_op(other)\n def __radd__(self,other): return self.binary_op(other)\n def __sub__(self,other): return self.binary_op(other)\n def __rsub__(self,other): return self.binary_op(other)\n def __mul__(self,other): return self.binary_op(other)\n def __rmul__(self,other): return self.binary_op(other)\n def __div__(self,other): return self.binary_op(other)\n def __rdiv__(self,other): return self.binary_op(other)\n def __mod__(self,other): return self.binary_op(other)\n def __rmod__(self,other): return self.binary_op(other)\n def __lshift__(self,other): return self.binary_op(other)\n def __rshift__(self,other): return self.binary_op(other)\n # unary ops\n def __neg__(self,other): return self\n def __pos__(self,other): return self\n def __abs__(self,other): return self\n def __invert__(self,other): return self \n # Not sure what to do with coersion ops. Ignore for now.\n #\n # not currently supported by compiler.\n # __divmod__\n # __pow__\n # __rpow__\n # __and__\n # __or__\n # __xor__\n # item access and slicing \n def __setitem__(self,indices,val):\n #ignore for now\n pass\n def __len__(self):\n return self.shape[0]\n def __getslice__(self,i,j):\n # enabling the following would make class compatible with\n # lists. Its current incarnation is compatible with arrays.\n # Both this and Numeric should have this FIXED to correspond\n # to lists.\n #i = max(i, 0); j = max(j, 0)\n return self.__getitem__((slice(i,j),))\n def __getitem__(self,indices):\n # ayeyaya this is a mess\n #print indices, type(indices), indices.shape \n if type(indices) is not TupleType:\n indices = (indices,)\n if Ellipsis in indices:\n raise IndexError, \"Ellipsis not currently supported\"\n new_dims = [] \n dim = 0 \n for index in indices:\n try:\n dim_len = self.shape[dim]\n except IndexError:\n raise IndexError, \"To many indices specified\"\n \n #if (type(index) is SliceType and index.start == index.stop == index.step):\n if (index is empty_slice):\n slc_len = dim_len\n elif type(index) is SliceType:\n beg,end,step = index.start,index.stop,index.step \n # handle if they are dummy arrays\n #if hasattr(beg,'value') and type(beg.value) != ArrayType:\n # beg = beg.value\n #if hasattr(end,'value') and type(end.value) != ArrayType:\n # end = end.value\n #if hasattr(step,'value') and type(step.value) != ArrayType:\n # step = step.value \n if beg is None: beg = 0\n if end == sys.maxint or end is None:\n end = dim_len\n if step is None: \n step = 1\n \n if beg < 0: beg += dim_len\n if end < 0: end += dim_len\n # the following is list like behavior,\n # which isn't adhered to by arrays. \n # FIX THIS ANOMOLY IN NUMERIC!\n if beg < 0: beg = 0\n if beg > dim_len: beg = dim_len\n if end < 0: end = 0\n if end > dim_len: end = dim_len\n # This is rubbish. \n if beg == end:\n beg,end,step = 0,0,1\n elif beg >= dim_len and step > 0:\n beg,end,step = 0,0,1\n #elif index.step > 0 and beg <= end:\n elif step > 0 and beg <= end:\n pass #slc_len = abs(divide(end-beg-1,step)+1) \n # handle [::-1] and [-1::-1] correctly \n #elif index.step > 0 and beg > end:\n elif step > 0 and beg > end:\n beg,end,step = 0,0,1\n elif(step < 0 and index.start is None and index.stop is None):\n beg,end,step = 0,dim_len,-step\n elif(step < 0 and index.start is None):\n # +1 because negative stepping is inclusive\n beg,end,step = end+1,dim_len,-step \n elif(step < 0 and index.stop is None):\n beg,end,step = 0,beg+1,-step\n elif(step < 0 and beg > end): \n beg,end,step = end,beg,-step\n elif(step < 0 and beg < end): \n beg,end,step = 0,0,-step\n slc_len = abs(divide(end-beg-1,step)+1)\n new_dims.append(slc_len)\n else:\n if index < 0: index += dim_len\n if index >=0 and index < dim_len:\n #this reduces the array dimensions by one\n pass\n else:\n raise IndexError, \"Index out of range\" \n dim += 1 \n new_dims.extend(self.shape[dim:])\n if 0 in new_dims:\n raise IndexError, \"Zero length slices not currently supported\"\n return dummy_array(new_dims,1)\n def __repr__(self):\n val = str((self.name, str(self.shape)))\n return val \n\ndef unary(ary):\n return ary\n\ndef not_implemented(ary):\n return ary\n \n#all imported from Numeric and need to be reassigned.\nunary_op = [arccos, arcsin, arctan, cos, cosh, sin, sinh, \n exp,ceil,floor,fabs,log,log10,sqrt]\n\nunsupported = [argmin,argmax, argsort,around, absolute,sign,negative,floor]\n\nfor func in unary_op:\n func = unary\n \nfor func in unsupported:\n func = not_implemented\n \ndef reduction(ary,axis=0):\n if axis < 0:\n axis += len(ary.shape) \n if axis < 0 or axis >= len(ary.shape):\n raise ValueError, \"Dimension not in array\" \n new_dims = list(ary.shape[:axis]) + list(ary.shape[axis+1:])\n return dummy_array(new_dims,1) \n\n# functions currently not supported by compiler\n# reductions are gonna take some array reordering for the general case,\n# so this is gonna take some thought (probably some tree manipulation).\ndef take(ary,axis=0): raise NotImplemented\n# and all the rest\n \ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n", "methods": [ { "name": "time_it", "long_name": "time_it( )", "filename": "size_check.py", "nloc": 18, "complexity": 2, "token_count": 158, "parameters": [], "start_line": 13, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "check_expr", "long_name": "check_expr( expr , local_vars , global_vars = { } )", "filename": "size_check.py", "nloc": 21, "complexity": 9, "token_count": 159, "parameters": [ "expr", "local_vars", "global_vars" ], "start_line": 34, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 }, { "name": "make_same_length", "long_name": "make_same_length( x , y )", "filename": "size_check.py", "nloc": 20, "complexity": 7, "token_count": 115, "parameters": [ "x", "y" ], "start_line": 65, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "binary_op_size", "long_name": "binary_op_size( xx , yy )", "filename": "size_check.py", "nloc": 13, "complexity": 5, "token_count": 100, "parameters": [ "xx", "yy" ], "start_line": 86, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , ary , ary_is_shape = 0 , name = None )", "filename": "size_check.py", "nloc": 9, "complexity": 3, "token_count": 47, "parameters": [ "self", "ary", "ary_is_shape", "name" ], "start_line": 105, "end_line": 114, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "binary_op", "long_name": "binary_op( self , other )", "filename": "size_check.py", "nloc": 7, "complexity": 2, "token_count": 37, "parameters": [ "self", "other" ], "start_line": 116, "end_line": 122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "size_check.py", "nloc": 6, "complexity": 3, "token_count": 59, "parameters": [ "self", "other" ], "start_line": 123, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__setitem__", "long_name": "__setitem__( self , indices , val )", "filename": "size_check.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "indices", "val" ], "start_line": 159, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__len__", "long_name": "__len__( self )", "filename": "size_check.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 162, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getslice__", "long_name": "__getslice__( self , i , j )", "filename": "size_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self", "i", "j" ], "start_line": 164, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__getitem__", "long_name": "__getitem__( self , indices )", "filename": "size_check.py", "nloc": 58, "complexity": 39, "token_count": 450, "parameters": [ "self", "indices" ], "start_line": 171, "end_line": 249, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 79, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "size_check.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 250, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "unary", "long_name": "unary( ary )", "filename": "size_check.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "ary" ], "start_line": 254, "end_line": 255, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "not_implemented", "long_name": "not_implemented( ary )", "filename": "size_check.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "ary" ], "start_line": 257, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "reduction", "long_name": "reduction( ary , axis = 0 )", "filename": "size_check.py", "nloc": 7, "complexity": 4, "token_count": 72, "parameters": [ "ary", "axis" ], "start_line": 272, "end_line": 278, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "size_check.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 286, "end_line": 288, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "size_check.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 290, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "time_it", "long_name": "time_it( )", "filename": "size_check.py", "nloc": 18, "complexity": 2, "token_count": 158, "parameters": [], "start_line": 13, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "check_expr", "long_name": "check_expr( expr , local_vars , global_vars = { } )", "filename": "size_check.py", "nloc": 21, "complexity": 9, "token_count": 159, "parameters": [ "expr", "local_vars", "global_vars" ], "start_line": 34, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 0 }, { "name": "make_same_length", "long_name": "make_same_length( x , y )", "filename": "size_check.py", "nloc": 20, "complexity": 7, "token_count": 115, "parameters": [ "x", "y" ], "start_line": 65, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "binary_op_size", "long_name": "binary_op_size( xx , yy )", "filename": "size_check.py", "nloc": 13, "complexity": 5, "token_count": 100, "parameters": [ "xx", "yy" ], "start_line": 86, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , ary , ary_is_shape = 0 , name = None )", "filename": "size_check.py", "nloc": 9, "complexity": 3, "token_count": 47, "parameters": [ "self", "ary", "ary_is_shape", "name" ], "start_line": 105, "end_line": 114, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "binary_op", "long_name": "binary_op( self , other )", "filename": "size_check.py", "nloc": 7, "complexity": 2, "token_count": 37, "parameters": [ "self", "other" ], "start_line": 116, "end_line": 122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "size_check.py", "nloc": 6, "complexity": 3, "token_count": 59, "parameters": [ "self", "other" ], "start_line": 123, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__setitem__", "long_name": "__setitem__( self , indices , val )", "filename": "size_check.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "indices", "val" ], "start_line": 159, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__len__", "long_name": "__len__( self )", "filename": "size_check.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 162, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getslice__", "long_name": "__getslice__( self , i , j )", "filename": "size_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self", "i", "j" ], "start_line": 164, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__getitem__", "long_name": "__getitem__( self , indices )", "filename": "size_check.py", "nloc": 58, "complexity": 39, "token_count": 450, "parameters": [ "self", "indices" ], "start_line": 171, "end_line": 249, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 79, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "size_check.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 250, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "unary", "long_name": "unary( ary )", "filename": "size_check.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "ary" ], "start_line": 254, "end_line": 255, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "not_implemented", "long_name": "not_implemented( ary )", "filename": "size_check.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "ary" ], "start_line": 257, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "reduction", "long_name": "reduction( ary , axis = 0 )", "filename": "size_check.py", "nloc": 7, "complexity": 4, "token_count": 72, "parameters": [ "ary", "axis" ], "start_line": 272, "end_line": 278, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "size_check.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 286, "end_line": 288, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "size_check.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 290, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "size_check.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 290, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "size_check.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 286, "end_line": 288, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 213, "complexity": 82, "token_count": 1684, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "weave/slice_handler.py", "new_path": "weave/slice_handler.py", "filename": "slice_handler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -155,11 +155,11 @@ def transform_slices(ast_list):\n )\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n if __name__ == \"__main__\": \n", "added_lines": 2, "deleted_lines": 2, "source_code": "import pprint\nimport string\nfrom ast_tools import * \n\ndef slice_ast_to_dict(ast_seq):\n sl_vars = {}\n if type(ast_seq) in (ListType,TupleType):\n for pattern in slice_patterns:\n found,data = match(pattern,ast_seq)\n if found: \n sl_vars = {'begin':'_beg',\n 'end':'_end', \n 'step':'_stp',\n 'single_index':'_index'}\n for key in data.keys():\n data[key] = ast_to_string(data[key])\n sl_vars.update(data)\n break; \n return sl_vars\n \ndef build_slice_atom(slice_vars, position):\n # Note: This produces slices that are incorrect for Python\n # evaluation because of slicing being exclusive in Python\n # and inclusive for blitz on the top end of the range.\n # This difference should really be handle in a blitz specific transform,\n # but I've put it here for convenience. This doesn't cause any\n # problems in code, its just a maintance hassle (I'll forget I did it here)\n # and inelegant. *FIX ME*.\n \n \n ###########################################################################\n # Handling negative indices.\n #\n # Range indices that begin with a negative sign, '-', are assumed to be\n # negative. Blitz++ interprets negative indices differently than \n # Python. To correct this, we subtract negative indices from the length\n # of the array (at run-time). If indices do not start with a negative \n # sign, they are assumed to be positive.\n #\n # This scheme doesn't work in the general case. For example, if you\n # are calculating negative indices from a math expression that doesn't\n # start with the negative sign, then it will be assumed positive and\n # hence generate wrong results (and maybe a seg-fault).\n # \n # I think this case can might be remedied by calculating all ranges on\n # the fly, and then subtracting them from the length of the array in \n # that dimension if they are negative. This is major code bloat in the\n # funcitons and more work. Save till later...\n ###########################################################################\n # I don't think the strip is necessary, but it insures\n # that '-' is the first sign for negative indices.\n if slice_vars['single_index'] != '_index':\n expr = '%(single_index)s' % slice_vars \n else: \n begin = string.strip(slice_vars['begin'])\n if begin[0] == '-':\n slice_vars['begin'] = 'N' + slice_vars['var']+`position`+begin;\n \n end = string.strip(slice_vars['end'])\n if end != '_end' and end[0] != '-':\n #compensate for blitz using inclusive indexing on top end \n #of slice for positive indices.\n slice_vars['end'] = end + '-1'\n if end[0] == '-':\n slice_vars['end'] = 'N%s[%d]%s-1' % (slice_vars['var'],position,end)\n \n if slice_vars['step'] == '_stp':\n # this if/then isn't strictly necessary, it'll\n # just keep the output code a little cleaner\n expr = 'slice(%(begin)s,%(end)s)' % slice_vars \n else: \n expr = 'slice(%(begin)s,%(end)s,%(step)s)' % slice_vars \n val = atom_list(expr)\n return val\n\ndef transform_subscript_list(subscript_dict):\n # this is gonna edit the ast_list... \n subscript_list = subscript_dict['subscript_list']\n\n var = subscript_dict['var']\n #skip the first entry (the subscript_list symbol)\n slice_position = -1\n for i in range(1,len(subscript_list)):\n #skip commas...\n if subscript_list[i][0] != token.COMMA:\n slice_position += 1\n slice_vars = slice_ast_to_dict(subscript_list[i])\n\n slice_vars['var'] = var\n # create a slice(b,e,s) atom and insert in \n # place of the x:y:z atom in the tree. \n subscript_list[i] = build_slice_atom(slice_vars, slice_position)\n \ndef harvest_subscript_dicts(ast_list):\n \"\"\" Needs Tests!\n \"\"\"\n subscript_lists = []\n if type(ast_list) == ListType:\n found,data = match(indexed_array_pattern,ast_list)\n # data is a dict with 'var' = variable name\n # and 'subscript_list' = to the ast_seq for the subscript list\n if found:\n subscript_lists.append(data)\n for item in ast_list:\n if type(item) == ListType:\n subscript_lists.extend(harvest_subscript_dicts(item))\n return subscript_lists\n\ndef transform_slices(ast_list):\n \"\"\" Walk through an ast_list converting all x:y:z subscripts\n to slice(x,y,z) subscripts.\n \"\"\"\n all_dicts = harvest_subscript_dicts(ast_list)\n for subscript_dict in all_dicts:\n transform_subscript_list(subscript_dict)\n\nslice_patterns = []\nCLN = (token.COLON,':')\nCLN2= (symbol.sliceop, (token.COLON, ':'))\nCLN2_STEP = (symbol.sliceop, (token.COLON, ':'),['step'])\n# [begin:end:step]\nslice_patterns.append((symbol.subscript, ['begin'],CLN,['end'], CLN2_STEP ))\n# [:end:step]\nslice_patterns.append((symbol.subscript, CLN,['end'], CLN2_STEP ))\n# [begin::step]\nslice_patterns.append((symbol.subscript, ['begin'],CLN, CLN2_STEP ))\n# [begin:end:]\nslice_patterns.append((symbol.subscript, ['begin'],CLN,['end'], CLN2 ))\n# [begin::]\nslice_patterns.append((symbol.subscript, ['begin'],CLN, CLN2 ))\n# [:end:]\nslice_patterns.append((symbol.subscript, CLN,['end'], CLN2, ))\n# [::step]\nslice_patterns.append((symbol.subscript, CLN, CLN2_STEP ))\n# [::]\nslice_patterns.append((symbol.subscript, CLN, CLN2 ))\n\n# begin:end variants\nslice_patterns.append((symbol.subscript, ['begin'],CLN,['end']))\nslice_patterns.append((symbol.subscript, CLN,['end']))\nslice_patterns.append((symbol.subscript, ['begin'],CLN))\nslice_patterns.append((symbol.subscript, CLN)) \n\n# a[0] variant -- can't believe I left this out...\nslice_patterns.append((symbol.subscript,['single_index'])) \n\nindexed_array_pattern = \\\n (symbol.power,\n (symbol.atom,(token.NAME, ['var'])),\n (symbol.trailer,\n (token.LSQB, '['),\n ['subscript_list'],\n (token.RSQB, ']')\n )\n )\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == \"__main__\": \n test()", "source_code_before": "import pprint\nimport string\nfrom ast_tools import * \n\ndef slice_ast_to_dict(ast_seq):\n sl_vars = {}\n if type(ast_seq) in (ListType,TupleType):\n for pattern in slice_patterns:\n found,data = match(pattern,ast_seq)\n if found: \n sl_vars = {'begin':'_beg',\n 'end':'_end', \n 'step':'_stp',\n 'single_index':'_index'}\n for key in data.keys():\n data[key] = ast_to_string(data[key])\n sl_vars.update(data)\n break; \n return sl_vars\n \ndef build_slice_atom(slice_vars, position):\n # Note: This produces slices that are incorrect for Python\n # evaluation because of slicing being exclusive in Python\n # and inclusive for blitz on the top end of the range.\n # This difference should really be handle in a blitz specific transform,\n # but I've put it here for convenience. This doesn't cause any\n # problems in code, its just a maintance hassle (I'll forget I did it here)\n # and inelegant. *FIX ME*.\n \n \n ###########################################################################\n # Handling negative indices.\n #\n # Range indices that begin with a negative sign, '-', are assumed to be\n # negative. Blitz++ interprets negative indices differently than \n # Python. To correct this, we subtract negative indices from the length\n # of the array (at run-time). If indices do not start with a negative \n # sign, they are assumed to be positive.\n #\n # This scheme doesn't work in the general case. For example, if you\n # are calculating negative indices from a math expression that doesn't\n # start with the negative sign, then it will be assumed positive and\n # hence generate wrong results (and maybe a seg-fault).\n # \n # I think this case can might be remedied by calculating all ranges on\n # the fly, and then subtracting them from the length of the array in \n # that dimension if they are negative. This is major code bloat in the\n # funcitons and more work. Save till later...\n ###########################################################################\n # I don't think the strip is necessary, but it insures\n # that '-' is the first sign for negative indices.\n if slice_vars['single_index'] != '_index':\n expr = '%(single_index)s' % slice_vars \n else: \n begin = string.strip(slice_vars['begin'])\n if begin[0] == '-':\n slice_vars['begin'] = 'N' + slice_vars['var']+`position`+begin;\n \n end = string.strip(slice_vars['end'])\n if end != '_end' and end[0] != '-':\n #compensate for blitz using inclusive indexing on top end \n #of slice for positive indices.\n slice_vars['end'] = end + '-1'\n if end[0] == '-':\n slice_vars['end'] = 'N%s[%d]%s-1' % (slice_vars['var'],position,end)\n \n if slice_vars['step'] == '_stp':\n # this if/then isn't strictly necessary, it'll\n # just keep the output code a little cleaner\n expr = 'slice(%(begin)s,%(end)s)' % slice_vars \n else: \n expr = 'slice(%(begin)s,%(end)s,%(step)s)' % slice_vars \n val = atom_list(expr)\n return val\n\ndef transform_subscript_list(subscript_dict):\n # this is gonna edit the ast_list... \n subscript_list = subscript_dict['subscript_list']\n\n var = subscript_dict['var']\n #skip the first entry (the subscript_list symbol)\n slice_position = -1\n for i in range(1,len(subscript_list)):\n #skip commas...\n if subscript_list[i][0] != token.COMMA:\n slice_position += 1\n slice_vars = slice_ast_to_dict(subscript_list[i])\n\n slice_vars['var'] = var\n # create a slice(b,e,s) atom and insert in \n # place of the x:y:z atom in the tree. \n subscript_list[i] = build_slice_atom(slice_vars, slice_position)\n \ndef harvest_subscript_dicts(ast_list):\n \"\"\" Needs Tests!\n \"\"\"\n subscript_lists = []\n if type(ast_list) == ListType:\n found,data = match(indexed_array_pattern,ast_list)\n # data is a dict with 'var' = variable name\n # and 'subscript_list' = to the ast_seq for the subscript list\n if found:\n subscript_lists.append(data)\n for item in ast_list:\n if type(item) == ListType:\n subscript_lists.extend(harvest_subscript_dicts(item))\n return subscript_lists\n\ndef transform_slices(ast_list):\n \"\"\" Walk through an ast_list converting all x:y:z subscripts\n to slice(x,y,z) subscripts.\n \"\"\"\n all_dicts = harvest_subscript_dicts(ast_list)\n for subscript_dict in all_dicts:\n transform_subscript_list(subscript_dict)\n\nslice_patterns = []\nCLN = (token.COLON,':')\nCLN2= (symbol.sliceop, (token.COLON, ':'))\nCLN2_STEP = (symbol.sliceop, (token.COLON, ':'),['step'])\n# [begin:end:step]\nslice_patterns.append((symbol.subscript, ['begin'],CLN,['end'], CLN2_STEP ))\n# [:end:step]\nslice_patterns.append((symbol.subscript, CLN,['end'], CLN2_STEP ))\n# [begin::step]\nslice_patterns.append((symbol.subscript, ['begin'],CLN, CLN2_STEP ))\n# [begin:end:]\nslice_patterns.append((symbol.subscript, ['begin'],CLN,['end'], CLN2 ))\n# [begin::]\nslice_patterns.append((symbol.subscript, ['begin'],CLN, CLN2 ))\n# [:end:]\nslice_patterns.append((symbol.subscript, CLN,['end'], CLN2, ))\n# [::step]\nslice_patterns.append((symbol.subscript, CLN, CLN2_STEP ))\n# [::]\nslice_patterns.append((symbol.subscript, CLN, CLN2 ))\n\n# begin:end variants\nslice_patterns.append((symbol.subscript, ['begin'],CLN,['end']))\nslice_patterns.append((symbol.subscript, CLN,['end']))\nslice_patterns.append((symbol.subscript, ['begin'],CLN))\nslice_patterns.append((symbol.subscript, CLN)) \n\n# a[0] variant -- can't believe I left this out...\nslice_patterns.append((symbol.subscript,['single_index'])) \n\nindexed_array_pattern = \\\n (symbol.power,\n (symbol.atom,(token.NAME, ['var'])),\n (symbol.trailer,\n (token.LSQB, '['),\n ['subscript_list'],\n (token.RSQB, ']')\n )\n )\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == \"__main__\": \n test()", "methods": [ { "name": "slice_ast_to_dict", "long_name": "slice_ast_to_dict( ast_seq )", "filename": "slice_handler.py", "nloc": 15, "complexity": 5, "token_count": 89, "parameters": [ "ast_seq" ], "start_line": 5, "end_line": 19, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "build_slice_atom", "long_name": "build_slice_atom( slice_vars , position )", "filename": "slice_handler.py", "nloc": 18, "complexity": 7, "token_count": 143, "parameters": [ "slice_vars", "position" ], "start_line": 21, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "transform_subscript_list", "long_name": "transform_subscript_list( subscript_dict )", "filename": "slice_handler.py", "nloc": 10, "complexity": 3, "token_count": 76, "parameters": [ "subscript_dict" ], "start_line": 76, "end_line": 92, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "harvest_subscript_dicts", "long_name": "harvest_subscript_dicts( ast_list )", "filename": "slice_handler.py", "nloc": 10, "complexity": 5, "token_count": 61, "parameters": [ "ast_list" ], "start_line": 94, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "transform_slices", "long_name": "transform_slices( ast_list )", "filename": "slice_handler.py", "nloc": 4, "complexity": 2, "token_count": 21, "parameters": [ "ast_list" ], "start_line": 109, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "slice_handler.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 157, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "slice_handler.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 161, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "slice_ast_to_dict", "long_name": "slice_ast_to_dict( ast_seq )", "filename": "slice_handler.py", "nloc": 15, "complexity": 5, "token_count": 89, "parameters": [ "ast_seq" ], "start_line": 5, "end_line": 19, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "build_slice_atom", "long_name": "build_slice_atom( slice_vars , position )", "filename": "slice_handler.py", "nloc": 18, "complexity": 7, "token_count": 143, "parameters": [ "slice_vars", "position" ], "start_line": 21, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "transform_subscript_list", "long_name": "transform_subscript_list( subscript_dict )", "filename": "slice_handler.py", "nloc": 10, "complexity": 3, "token_count": 76, "parameters": [ "subscript_dict" ], "start_line": 76, "end_line": 92, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "harvest_subscript_dicts", "long_name": "harvest_subscript_dicts( ast_list )", "filename": "slice_handler.py", "nloc": 10, "complexity": 5, "token_count": 61, "parameters": [ "ast_list" ], "start_line": 94, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "transform_slices", "long_name": "transform_slices( ast_list )", "filename": "slice_handler.py", "nloc": 4, "complexity": 2, "token_count": 21, "parameters": [ "ast_list" ], "start_line": 109, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "slice_handler.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 157, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "slice_handler.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 161, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "slice_handler.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 161, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "slice_handler.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 157, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 94, "complexity": 24, "token_count": 780, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "weave/standard_array_spec.py", "new_path": "weave/standard_array_spec.py", "filename": "standard_array_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -149,9 +149,9 @@ def declaration_code(self,templatize = 0,inline=0):\n return code\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "added_lines": 2, "deleted_lines": 2, "source_code": "from c_spec import common_base_converter\nfrom c_spec import num_to_c_types\nfrom Numeric import *\nfrom types import *\nimport os\n\nnum_typecode = {}\nnum_typecode['c'] = 'PyArray_CHAR'\nnum_typecode['1'] = 'PyArray_SBYTE'\nnum_typecode['b'] = 'PyArray_UBYTE'\nnum_typecode['s'] = 'PyArray_SHORT'\nnum_typecode['i'] = 'PyArray_INT' # PyArray_INT has troubles ?? What does this note mean ??\nnum_typecode['l'] = 'PyArray_LONG'\nnum_typecode['f'] = 'PyArray_FLOAT'\nnum_typecode['d'] = 'PyArray_DOUBLE'\nnum_typecode['F'] = 'PyArray_CFLOAT'\nnum_typecode['D'] = 'PyArray_CDOUBLE'\n\ntype_check_code = \\\n\"\"\"\nclass numpy_type_handler\n{\npublic:\n void conversion_numpy_check_type(PyArrayObject* arr_obj, int numeric_type,\n const char* name)\n {\n // Make sure input has correct numeric type.\n // allow character and byte to match\n // also allow int and long to match\n int arr_type = arr_obj->descr->type_num;\n if ( arr_type != numeric_type &&\n !(numeric_type == PyArray_CHAR && arr_type == PyArray_SBYTE) &&\n !(numeric_type == PyArray_SBYTE && arr_type == PyArray_CHAR) &&\n !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&\n !(numeric_type == PyArray_LONG && arr_type == PyArray_INT)) \n {\n char* type_names[13] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"int\", \n \"long\", \"float\", \"double\", \"complex float\",\n \"complex double\", \"object\",\"ntype\",\"unkown\"};\n char msg[500];\n sprintf(msg,\"Conversion Error: received '%s' typed array instead of '%s' typed array for variable '%s'\",\n type_names[arr_type],type_names[numeric_type],name);\n throw_error(PyExc_TypeError,msg); \n }\n }\n \n void numpy_check_type(PyArrayObject* arr_obj, int numeric_type, const char* name)\n {\n // Make sure input has correct numeric type.\n int arr_type = arr_obj->descr->type_num;\n if ( arr_type != numeric_type &&\n !(numeric_type == PyArray_CHAR && arr_type == PyArray_SBYTE) &&\n !(numeric_type == PyArray_SBYTE && arr_type == PyArray_CHAR) &&\n !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&\n !(numeric_type == PyArray_LONG && arr_type == PyArray_INT)) \n {\n char* type_names[13] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"int\", \n \"long\", \"float\", \"double\", \"complex float\",\n \"complex double\", \"object\",\"ntype\",\"unkown\"};\n char msg[500];\n sprintf(msg,\"received '%s' typed array instead of '%s' typed array for variable '%s'\",\n type_names[arr_type],type_names[numeric_type],name);\n throw_error(PyExc_TypeError,msg); \n }\n }\n};\n\nnumpy_type_handler x__numpy_type_handler = numpy_type_handler();\n#define conversion_numpy_check_type x__numpy_type_handler.conversion_numpy_check_type\n#define numpy_check_type x__numpy_type_handler.numpy_check_type\n\n\"\"\"\n\nsize_check_code = \\\n\"\"\"\nclass numpy_size_handler\n{\npublic:\n void conversion_numpy_check_size(PyArrayObject* arr_obj, int Ndims, \n const char* name)\n {\n if (arr_obj->nd != Ndims)\n {\n char msg[500];\n sprintf(msg,\"Conversion Error: received '%d' dimensional array instead of '%d' dimensional array for variable '%s'\",\n arr_obj->nd,Ndims,name);\n throw_error(PyExc_TypeError,msg);\n } \n }\n \n void numpy_check_size(PyArrayObject* arr_obj, int Ndims, const char* name)\n {\n if (arr_obj->nd != Ndims)\n {\n char msg[500];\n sprintf(msg,\"received '%d' dimensional array instead of '%d' dimensional array for variable '%s'\",\n arr_obj->nd,Ndims,name);\n throw_error(PyExc_TypeError,msg);\n } \n }\n};\n\nnumpy_size_handler x__numpy_size_handler = numpy_size_handler();\n#define conversion_numpy_check_size x__numpy_size_handler.conversion_numpy_check_size\n#define numpy_check_size x__numpy_size_handler.numpy_check_size\n\n\"\"\"\n\nnumeric_init_code = \\\n\"\"\"\nPy_Initialize();\nimport_array();\nPyImport_ImportModule(\"Numeric\");\n\"\"\"\n \nclass array_converter(common_base_converter):\n\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'numpy'\n self.check_func = 'PyArray_Check' \n self.c_type = 'PyArrayObject*'\n self.to_c_return = '(PyArrayObject*) py_obj'\n self.matching_types = [ArrayType]\n self.headers = ['\"Numeric/arrayobject.h\"','','']\n self.support_code = [size_check_code, type_check_code]\n self.module_init_code = [numeric_init_code] \n \n def get_var_type(self,value):\n return value.typecode()\n \n def template_vars(self,inline=0):\n res = common_base_converter.template_vars(self,inline) \n if hasattr(self,'var_type'):\n res['num_type'] = num_to_c_types[self.var_type]\n res['num_typecode'] = num_typecode[self.var_type]\n res['array_name'] = self.name + \"_array\"\n return res\n \n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(array_name)s = %(var_convert)s;\\n' \\\n 'conversion_numpy_check_type(%(array_name)s,%(num_typecode)s,\"%(name)s\");\\n' \\\n 'int* N%(name)s = %(array_name)s->dimensions;\\n' \\\n 'int* S%(name)s = %(array_name)s->strides;\\n' \\\n 'int D%(name)s = %(array_name)s->nd;\\n' \\\n '%(num_type)s* %(name)s = (%(num_type)s*) %(array_name)s->data;\\n' \n code = code % self.template_vars(inline=inline)\n return code\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "source_code_before": "from c_spec import common_base_converter\nfrom c_spec import num_to_c_types\nfrom Numeric import *\nfrom types import *\nimport os\n\nnum_typecode = {}\nnum_typecode['c'] = 'PyArray_CHAR'\nnum_typecode['1'] = 'PyArray_SBYTE'\nnum_typecode['b'] = 'PyArray_UBYTE'\nnum_typecode['s'] = 'PyArray_SHORT'\nnum_typecode['i'] = 'PyArray_INT' # PyArray_INT has troubles ?? What does this note mean ??\nnum_typecode['l'] = 'PyArray_LONG'\nnum_typecode['f'] = 'PyArray_FLOAT'\nnum_typecode['d'] = 'PyArray_DOUBLE'\nnum_typecode['F'] = 'PyArray_CFLOAT'\nnum_typecode['D'] = 'PyArray_CDOUBLE'\n\ntype_check_code = \\\n\"\"\"\nclass numpy_type_handler\n{\npublic:\n void conversion_numpy_check_type(PyArrayObject* arr_obj, int numeric_type,\n const char* name)\n {\n // Make sure input has correct numeric type.\n // allow character and byte to match\n // also allow int and long to match\n int arr_type = arr_obj->descr->type_num;\n if ( arr_type != numeric_type &&\n !(numeric_type == PyArray_CHAR && arr_type == PyArray_SBYTE) &&\n !(numeric_type == PyArray_SBYTE && arr_type == PyArray_CHAR) &&\n !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&\n !(numeric_type == PyArray_LONG && arr_type == PyArray_INT)) \n {\n char* type_names[13] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"int\", \n \"long\", \"float\", \"double\", \"complex float\",\n \"complex double\", \"object\",\"ntype\",\"unkown\"};\n char msg[500];\n sprintf(msg,\"Conversion Error: received '%s' typed array instead of '%s' typed array for variable '%s'\",\n type_names[arr_type],type_names[numeric_type],name);\n throw_error(PyExc_TypeError,msg); \n }\n }\n \n void numpy_check_type(PyArrayObject* arr_obj, int numeric_type, const char* name)\n {\n // Make sure input has correct numeric type.\n int arr_type = arr_obj->descr->type_num;\n if ( arr_type != numeric_type &&\n !(numeric_type == PyArray_CHAR && arr_type == PyArray_SBYTE) &&\n !(numeric_type == PyArray_SBYTE && arr_type == PyArray_CHAR) &&\n !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&\n !(numeric_type == PyArray_LONG && arr_type == PyArray_INT)) \n {\n char* type_names[13] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"int\", \n \"long\", \"float\", \"double\", \"complex float\",\n \"complex double\", \"object\",\"ntype\",\"unkown\"};\n char msg[500];\n sprintf(msg,\"received '%s' typed array instead of '%s' typed array for variable '%s'\",\n type_names[arr_type],type_names[numeric_type],name);\n throw_error(PyExc_TypeError,msg); \n }\n }\n};\n\nnumpy_type_handler x__numpy_type_handler = numpy_type_handler();\n#define conversion_numpy_check_type x__numpy_type_handler.conversion_numpy_check_type\n#define numpy_check_type x__numpy_type_handler.numpy_check_type\n\n\"\"\"\n\nsize_check_code = \\\n\"\"\"\nclass numpy_size_handler\n{\npublic:\n void conversion_numpy_check_size(PyArrayObject* arr_obj, int Ndims, \n const char* name)\n {\n if (arr_obj->nd != Ndims)\n {\n char msg[500];\n sprintf(msg,\"Conversion Error: received '%d' dimensional array instead of '%d' dimensional array for variable '%s'\",\n arr_obj->nd,Ndims,name);\n throw_error(PyExc_TypeError,msg);\n } \n }\n \n void numpy_check_size(PyArrayObject* arr_obj, int Ndims, const char* name)\n {\n if (arr_obj->nd != Ndims)\n {\n char msg[500];\n sprintf(msg,\"received '%d' dimensional array instead of '%d' dimensional array for variable '%s'\",\n arr_obj->nd,Ndims,name);\n throw_error(PyExc_TypeError,msg);\n } \n }\n};\n\nnumpy_size_handler x__numpy_size_handler = numpy_size_handler();\n#define conversion_numpy_check_size x__numpy_size_handler.conversion_numpy_check_size\n#define numpy_check_size x__numpy_size_handler.numpy_check_size\n\n\"\"\"\n\nnumeric_init_code = \\\n\"\"\"\nPy_Initialize();\nimport_array();\nPyImport_ImportModule(\"Numeric\");\n\"\"\"\n \nclass array_converter(common_base_converter):\n\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'numpy'\n self.check_func = 'PyArray_Check' \n self.c_type = 'PyArrayObject*'\n self.to_c_return = '(PyArrayObject*) py_obj'\n self.matching_types = [ArrayType]\n self.headers = ['\"Numeric/arrayobject.h\"','','']\n self.support_code = [size_check_code, type_check_code]\n self.module_init_code = [numeric_init_code] \n \n def get_var_type(self,value):\n return value.typecode()\n \n def template_vars(self,inline=0):\n res = common_base_converter.template_vars(self,inline) \n if hasattr(self,'var_type'):\n res['num_type'] = num_to_c_types[self.var_type]\n res['num_typecode'] = num_typecode[self.var_type]\n res['array_name'] = self.name + \"_array\"\n return res\n \n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(array_name)s = %(var_convert)s;\\n' \\\n 'conversion_numpy_check_type(%(array_name)s,%(num_typecode)s,\"%(name)s\");\\n' \\\n 'int* N%(name)s = %(array_name)s->dimensions;\\n' \\\n 'int* S%(name)s = %(array_name)s->strides;\\n' \\\n 'int D%(name)s = %(array_name)s->nd;\\n' \\\n '%(num_type)s* %(name)s = (%(num_type)s*) %(array_name)s->data;\\n' \n code = code % self.template_vars(inline=inline)\n return code\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "methods": [ { "name": "init_info", "long_name": "init_info( self )", "filename": "standard_array_spec.py", "nloc": 10, "complexity": 1, "token_count": 65, "parameters": [ "self" ], "start_line": 118, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_var_type", "long_name": "get_var_type( self , value )", "filename": "standard_array_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "value" ], "start_line": 129, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 7, "complexity": 2, "token_count": 61, "parameters": [ "self", "inline" ], "start_line": 132, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 10, "complexity": 1, "token_count": 42, "parameters": [ "self", "templatize", "inline" ], "start_line": 140, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 151, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 155, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "init_info", "long_name": "init_info( self )", "filename": "standard_array_spec.py", "nloc": 10, "complexity": 1, "token_count": 65, "parameters": [ "self" ], "start_line": 118, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_var_type", "long_name": "get_var_type( self , value )", "filename": "standard_array_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "value" ], "start_line": 129, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 7, "complexity": 2, "token_count": 61, "parameters": [ "self", "inline" ], "start_line": 132, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 10, "complexity": 1, "token_count": 42, "parameters": [ "self", "templatize", "inline" ], "start_line": 140, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 151, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 155, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 155, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 151, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 146, "complexity": 7, "token_count": 334, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "weave/tests/test_c_spec.py", "new_path": "weave/tests/test_c_spec.py", "filename": "test_c_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -25,7 +25,7 @@ def remove_whitespace(in_str):\n return out\n \n def print_assert_equal(test_string,actual,desired):\n- \"\"\"this should probably be in scipy_base.testing\n+ \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n import pprint\n try:\n", "added_lines": 1, "deleted_lines": 1, "source_code": "import unittest\nimport time\nimport os,sys\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport inline_tools\nimport ext_tools\nfrom catalog import unique_file\nfrom build_tools import msvc_exists, gcc_exists\nimport c_spec\nrestore_path()\n\ndef unique_mod(d,file_name):\n f = os.path.basename(unique_file(d,file_name))\n m = os.path.splitext(f)[0]\n return m\n \ndef remove_whitespace(in_str):\n import string\n out = string.replace(in_str,\" \",\"\")\n out = string.replace(out,\"\\t\",\"\")\n out = string.replace(out,\"\\n\",\"\")\n return out\n \ndef print_assert_equal(test_string,actual,desired):\n \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n import pprint\n try:\n assert(actual == desired)\n except AssertionError:\n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n\n#----------------------------------------------------------------------------\n# Scalar conversion test classes\n# int, float, complex\n#----------------------------------------------------------------------------\nclass test_int_converter(unittest.TestCase):\n compiler = '' \n def check_type_match_string(self):\n s = c_spec.int_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = c_spec.int_converter() \n assert(s.type_match(5))\n def check_type_match_float(self):\n s = c_spec.int_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = c_spec.int_converter() \n assert(not s.type_match(5.+1j))\n def check_var_in(self):\n test_dir = setup_test_location()\n mod_name = 'int_var_in' + self.compiler\n mod_name = unique_mod(test_dir,mod_name)\n mod = ext_tools.ext_module(mod_name)\n a = 1\n code = \"a=2;\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = test_dir, compiler = self.compiler)\n exec 'from ' + mod_name + ' import test'\n b=1\n test(b)\n try:\n b = 1.\n test(b)\n except TypeError:\n pass\n try:\n b = 'abc'\n test(b)\n except TypeError:\n pass\n teardown_test_location()\n \n def check_int_return(self):\n test_dir = setup_test_location() \n mod_name = sys._getframe().f_code.co_name + self.compiler\n mod_name = unique_mod(test_dir,mod_name)\n mod = ext_tools.ext_module(mod_name)\n a = 1\n code = \"\"\"\n a=a+2;\n return_val = PyInt_FromLong(a);\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = test_dir, compiler = self.compiler)\n exec 'from ' + mod_name + ' import test'\n b=1\n c = test(b)\n teardown_test_location()\n assert( c == 3)\n\nclass test_float_converter(unittest.TestCase): \n compiler = ''\n def check_type_match_string(self):\n s = c_spec.float_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = c_spec.float_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = c_spec.float_converter() \n assert(s.type_match(5.))\n def check_type_match_complex(self):\n s = c_spec.float_converter() \n assert(not s.type_match(5.+1j))\n def check_float_var_in(self):\n test_dir = setup_test_location() \n mod_name = sys._getframe().f_code.co_name + self.compiler\n mod_name = unique_mod(test_dir,mod_name)\n mod = ext_tools.ext_module(mod_name)\n\n a = 1.\n code = \"a=2.;\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = test_dir, compiler = self.compiler)\n exec 'from ' + mod_name + ' import test'\n b=1.\n test(b)\n try:\n b = 1.\n test(b)\n except TypeError:\n pass\n try:\n b = 'abc'\n test(b)\n except TypeError:\n pass\n teardown_test_location()\n\n def check_float_return(self):\n test_dir = setup_test_location() \n mod_name = sys._getframe().f_code.co_name + self.compiler\n mod_name = unique_mod(test_dir,mod_name)\n mod = ext_tools.ext_module(mod_name)\n a = 1.\n code = \"\"\"\n a=a+2.;\n return_val = PyFloat_FromDouble(a);\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = test_dir, compiler = self.compiler)\n exec 'from ' + mod_name + ' import test'\n b=1.\n c = test(b)\n teardown_test_location()\n assert( c == 3.)\n \nclass test_complex_converter(unittest.TestCase): \n compiler = ''\n def check_type_match_string(self):\n s = c_spec.complex_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = c_spec.complex_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = c_spec.complex_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = c_spec.complex_converter() \n assert(s.type_match(5.+1j))\n def check_complex_var_in(self):\n test_dir = setup_test_location() \n mod_name = sys._getframe().f_code.co_name + self.compiler\n mod_name = unique_mod(test_dir,mod_name)\n mod = ext_tools.ext_module(mod_name)\n a = 1.+1j\n code = \"a=std::complex(2.,2.);\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = test_dir, compiler = self.compiler)\n exec 'from ' + mod_name + ' import test'\n b=1.+1j\n test(b)\n try:\n b = 1.\n test(b)\n except TypeError:\n pass\n try:\n b = 'abc'\n test(b)\n except TypeError:\n pass\n teardown_test_location()\n\n def check_complex_return(self):\n test_dir = setup_test_location() \n mod_name = sys._getframe().f_code.co_name + self.compiler\n mod_name = unique_mod(test_dir,mod_name)\n mod = ext_tools.ext_module(mod_name)\n a = 1.+1j\n code = \"\"\"\n a= a + std::complex(2.,2.);\n return_val = PyComplex_FromDoubles(a.real(),a.imag());\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = test_dir, compiler = self.compiler)\n exec 'from ' + mod_name + ' import test'\n b=1.+1j\n c = test(b)\n teardown_test_location() \n assert( c == 3.+3j)\n\nclass test_msvc_int_converter(test_int_converter): \n compiler = 'msvc'\nclass test_msvc_float_converter(test_float_converter): \n compiler = 'msvc'\nclass test_msvc_complex_converter(test_complex_converter): \n compiler = 'msvc'\n\nclass test_unix_int_converter(test_int_converter): \n compiler = ''\nclass test_unix_float_converter(test_float_converter): \n compiler = ''\nclass test_unix_complex_converter(test_complex_converter): \n compiler = ''\n\nclass test_gcc_int_converter(test_int_converter): \n compiler = 'gcc'\nclass test_gcc_float_converter(test_float_converter): \n compiler = 'gcc'\nclass test_gcc_complex_converter(test_complex_converter): \n compiler = 'gcc'\n \ndef setup_test_location():\n import tempfile\n test_dir = os.path.join(tempfile.gettempdir(),'test_files')\n if not os.path.exists(test_dir):\n os.mkdir(test_dir)\n sys.path.insert(0,test_dir) \n return test_dir\n\ndef teardown_test_location():\n import tempfile\n test_dir = os.path.join(tempfile.gettempdir(),'test_files')\n if sys.path[0] == test_dir:\n sys.path = sys.path[1:]\n return test_dir\n\ndef remove_file(name):\n test_dir = os.path.abspath(name)\n\n#----------------------------------------------------------------------------\n# File conversion tests\n#----------------------------------------------------------------------------\n\nclass test_file_converter(unittest.TestCase): \n def check_py_to_file(self):\n import tempfile\n file_name = tempfile.mktemp() \n file = open(file_name,'w')\n code = \"\"\"\n fprintf(file,\"hello bob\");\n \"\"\"\n inline_tools.inline(code,['file']) \n file.close()\n file = open(file_name,'r')\n assert(file.read() == \"hello bob\")\n def check_file_to_py(self):\n import tempfile\n file_name = tempfile.mktemp() \n # not sure I like Py::String as default -- might move to std::sting\n # or just plain char*\n code = \"\"\"\n char* _file_name = (char*) file_name.c_str();\n FILE* file = fopen(_file_name,\"w\");\n return_val = file_to_py(file,_file_name,\"w\");\n Py_XINCREF(return_val);\n \"\"\"\n file = inline_tools.inline(code,['file_name'])\n file.write(\"hello fred\") \n file.close()\n file = open(file_name,'r')\n assert(file.read() == \"hello fred\")\n\n#----------------------------------------------------------------------------\n# Instance conversion tests\n#----------------------------------------------------------------------------\n\nclass test_instance_converter(unittest.TestCase): \n pass\n\n#----------------------------------------------------------------------------\n# Callable object conversion tests\n#----------------------------------------------------------------------------\n \nclass test_callable_converter(unittest.TestCase): \n def check_call_function(self):\n import string\n func = string.find\n search_str = \"hello world hello\"\n sub_str = \"world\"\n # * Not sure about ref counts on search_str and sub_str.\n # * Is the Py::String necessary? (it works anyways...)\n code = \"\"\"\n PWOTuple args(2);\n args.setItem(0,PWOString(search_str.c_str()));\n args.setItem(1,PWOString(sub_str.c_str()));\n return_val = PyObject_CallObject(func,args);\n \"\"\"\n actual = inline_tools.inline(code,['func','search_str','sub_str'])\n desired = func(search_str,sub_str) \n assert(desired == actual)\n\n\nclass test_sequence_converter(unittest.TestCase): \n def check_convert_to_dict(self):\n d = {}\n inline_tools.inline(\"\",['d']) \n def check_convert_to_list(self): \n l = []\n inline_tools.inline(\"\",['l']) \n def check_convert_to_string(self): \n s = 'hello'\n inline_tools.inline(\"\",['s']) \n def check_convert_to_tuple(self): \n t = ()\n inline_tools.inline(\"\",['t']) \n\nclass test_string_converter(unittest.TestCase): \n def check_type_match_string(self):\n s = c_spec.string_converter()\n assert( s.type_match('string') )\n def check_type_match_int(self):\n s = c_spec.string_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = c_spec.string_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = c_spec.string_converter() \n assert(not s.type_match(5.+1j))\n def check_var_in(self):\n mod = ext_tools.ext_module('string_var_in')\n a = 'string'\n code = 'a=std::string(\"hello\");'\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import string_var_in\n b='bub'\n string_var_in.test(b)\n try:\n b = 1.\n string_var_in.test(b)\n except TypeError:\n pass\n try:\n b = 1\n string_var_in.test(b)\n except TypeError:\n pass\n \n def check_return(self):\n mod = ext_tools.ext_module('string_return')\n a = 'string'\n code = \"\"\"\n a= std::string(\"hello\");\n return_val = PyString_FromString(a.c_str());\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import string_return\n b='bub'\n c = string_return.test(b)\n assert( c == 'hello')\n\nclass test_list_converter(unittest.TestCase): \n def check_type_match_bad(self):\n s = c_spec.list_converter()\n objs = [{},(),'',1,1.,1+1j]\n for i in objs:\n assert( not s.type_match(i) )\n def check_type_match_good(self):\n s = c_spec.list_converter() \n assert(s.type_match([]))\n def check_var_in(self):\n mod = ext_tools.ext_module('list_var_in')\n a = [1]\n code = 'a=PWOList();'\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import list_var_in\n b=[1,2]\n list_var_in.test(b)\n try:\n b = 1.\n list_var_in.test(b)\n except TypeError:\n pass\n try:\n b = 'string'\n list_var_in.test(b)\n except TypeError:\n pass\n \n def check_return(self):\n mod = ext_tools.ext_module('list_return')\n a = [1]\n code = \"\"\"\n a=PWOList();\n a.append(PWOString(\"hello\"));\n return_val = a.disOwn();\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import list_return\n b=[1,2]\n c = list_return.test(b)\n assert( c == ['hello'])\n \n def check_speed(self):\n mod = ext_tools.ext_module('list_speed')\n a = range(1e6);\n code = \"\"\"\n PWONumber v = PWONumber();\n int vv, sum = 0; \n for(int i = 0; i < a.len(); i++)\n {\n v = a[i];\n vv = (int)v;\n if (vv % 2)\n sum += vv;\n else\n sum -= vv; \n }\n return_val = PyInt_FromLong(sum);\n \"\"\"\n with_cxx = ext_tools.ext_function('with_cxx',code,['a'])\n mod.add_function(with_cxx)\n code = \"\"\"\n int vv, sum = 0;\n PyObject *v; \n for(int i = 0; i < a.len(); i++)\n {\n v = PyList_GetItem(py_a,i);\n //didn't set error here -- just speed test\n vv = py_to_int(v,\"list item\");\n if (vv % 2)\n sum += vv;\n else\n sum -= vv; \n }\n return_val = PyInt_FromLong(sum);\n \"\"\"\n no_checking = ext_tools.ext_function('no_checking',code,['a'])\n mod.add_function(no_checking)\n mod.compile()\n import list_speed\n import time\n t1 = time.time()\n sum1 = list_speed.with_cxx(a)\n t2 = time.time()\n print 'scxx:', t2 - t1\n t1 = time.time()\n sum2 = list_speed.no_checking(a)\n t2 = time.time()\n print 'C, no checking:', t2 - t1\n sum3 = 0\n t1 = time.time()\n for i in a:\n if i % 2:\n sum3 += i\n else:\n sum3 -= i\n t2 = time.time()\n print 'python:', t2 - t1 \n assert( sum1 == sum2 and sum1 == sum3)\n\nclass test_tuple_converter(unittest.TestCase): \n def check_type_match_bad(self):\n s = c_spec.tuple_converter()\n objs = [{},[],'',1,1.,1+1j]\n for i in objs:\n assert( not s.type_match(i) )\n def check_type_match_good(self):\n s = c_spec.tuple_converter() \n assert(s.type_match((1,)))\n def check_var_in(self):\n mod = ext_tools.ext_module('tuple_var_in')\n a = (1,)\n code = 'a=PWOTuple();'\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import tuple_var_in\n b=(1,2)\n tuple_var_in.test(b)\n try:\n b = 1.\n tuple_var_in.test(b)\n except TypeError:\n pass\n try:\n b = 'string'\n tuple_var_in.test(b)\n except TypeError:\n pass\n \n def check_return(self):\n mod = ext_tools.ext_module('tuple_return')\n a = (1,)\n code = \"\"\"\n a=PWOTuple(2);\n a.setItem(0,PWOString(\"hello\"));\n a.setItem(1,PWOBase(Py_None));\n return_val = a.disOwn();\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import tuple_return\n b=(1,2)\n c = tuple_return.test(b)\n assert( c == ('hello',None))\n\n\nclass test_dict_converter(unittest.TestCase): \n def check_type_match_bad(self):\n s = c_spec.dict_converter()\n objs = [[],(),'',1,1.,1+1j]\n for i in objs:\n assert( not s.type_match(i) )\n def check_type_match_good(self):\n s = c_spec.dict_converter() \n assert(s.type_match({}))\n def check_var_in(self):\n mod = ext_tools.ext_module('dict_var_in')\n a = {'z':1}\n code = 'a=PWODict();' # This just checks to make sure the type is correct\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import dict_var_in\n b={'y':2}\n dict_var_in.test(b)\n try:\n b = 1.\n dict_var_in.test(b)\n except TypeError:\n pass\n try:\n b = 'string'\n dict_var_in.test(b)\n except TypeError:\n pass\n \n def check_return(self):\n mod = ext_tools.ext_module('dict_return')\n a = {'z':1}\n code = \"\"\"\n a=PWODict();\n a[\"hello\"] = PWONumber(5);\n return_val = a.disOwn();\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import dict_return\n b = {'z':2}\n c = dict_return.test(b)\n assert( c['hello'] == 5)\n \ndef test_suite(level=1):\n suites = [] \n if level >= 5:\n \"\"\"\n if msvc_exists():\n suites.append( unittest.makeSuite(test_msvc_int_converter,\n 'check_'))\n suites.append( unittest.makeSuite(test_msvc_float_converter,\n 'check_')) \n suites.append( unittest.makeSuite(test_msvc_complex_converter,\n 'check_'))\n pass\n else: # unix\n suites.append( unittest.makeSuite(test_unix_int_converter,\n 'check_'))\n suites.append( unittest.makeSuite(test_unix_float_converter,\n 'check_')) \n suites.append( unittest.makeSuite(test_unix_complex_converter,\n 'check_'))\n \n if gcc_exists(): \n suites.append( unittest.makeSuite(test_gcc_int_converter,\n 'check_'))\n suites.append( unittest.makeSuite(test_gcc_float_converter,\n 'check_'))\n suites.append( unittest.makeSuite(test_gcc_complex_converter,\n 'check_'))\n\n # file, instance, callable object tests\n suites.append( unittest.makeSuite(test_file_converter,'check_'))\n suites.append( unittest.makeSuite(test_instance_converter,'check_'))\n suites.append( unittest.makeSuite(test_callable_converter,'check_'))\n \"\"\"\n # sequenc conversion tests\n suites.append( unittest.makeSuite(test_sequence_converter,'check_'))\n suites.append( unittest.makeSuite(test_string_converter,'check_'))\n suites.append( unittest.makeSuite(test_list_converter,'check_'))\n suites.append( unittest.makeSuite(test_tuple_converter,'check_'))\n suites.append( unittest.makeSuite(test_dict_converter,'check_'))\n \n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "source_code_before": "import unittest\nimport time\nimport os,sys\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport inline_tools\nimport ext_tools\nfrom catalog import unique_file\nfrom build_tools import msvc_exists, gcc_exists\nimport c_spec\nrestore_path()\n\ndef unique_mod(d,file_name):\n f = os.path.basename(unique_file(d,file_name))\n m = os.path.splitext(f)[0]\n return m\n \ndef remove_whitespace(in_str):\n import string\n out = string.replace(in_str,\" \",\"\")\n out = string.replace(out,\"\\t\",\"\")\n out = string.replace(out,\"\\n\",\"\")\n return out\n \ndef print_assert_equal(test_string,actual,desired):\n \"\"\"this should probably be in scipy_base.testing\n \"\"\"\n import pprint\n try:\n assert(actual == desired)\n except AssertionError:\n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n\n#----------------------------------------------------------------------------\n# Scalar conversion test classes\n# int, float, complex\n#----------------------------------------------------------------------------\nclass test_int_converter(unittest.TestCase):\n compiler = '' \n def check_type_match_string(self):\n s = c_spec.int_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = c_spec.int_converter() \n assert(s.type_match(5))\n def check_type_match_float(self):\n s = c_spec.int_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = c_spec.int_converter() \n assert(not s.type_match(5.+1j))\n def check_var_in(self):\n test_dir = setup_test_location()\n mod_name = 'int_var_in' + self.compiler\n mod_name = unique_mod(test_dir,mod_name)\n mod = ext_tools.ext_module(mod_name)\n a = 1\n code = \"a=2;\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = test_dir, compiler = self.compiler)\n exec 'from ' + mod_name + ' import test'\n b=1\n test(b)\n try:\n b = 1.\n test(b)\n except TypeError:\n pass\n try:\n b = 'abc'\n test(b)\n except TypeError:\n pass\n teardown_test_location()\n \n def check_int_return(self):\n test_dir = setup_test_location() \n mod_name = sys._getframe().f_code.co_name + self.compiler\n mod_name = unique_mod(test_dir,mod_name)\n mod = ext_tools.ext_module(mod_name)\n a = 1\n code = \"\"\"\n a=a+2;\n return_val = PyInt_FromLong(a);\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = test_dir, compiler = self.compiler)\n exec 'from ' + mod_name + ' import test'\n b=1\n c = test(b)\n teardown_test_location()\n assert( c == 3)\n\nclass test_float_converter(unittest.TestCase): \n compiler = ''\n def check_type_match_string(self):\n s = c_spec.float_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = c_spec.float_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = c_spec.float_converter() \n assert(s.type_match(5.))\n def check_type_match_complex(self):\n s = c_spec.float_converter() \n assert(not s.type_match(5.+1j))\n def check_float_var_in(self):\n test_dir = setup_test_location() \n mod_name = sys._getframe().f_code.co_name + self.compiler\n mod_name = unique_mod(test_dir,mod_name)\n mod = ext_tools.ext_module(mod_name)\n\n a = 1.\n code = \"a=2.;\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = test_dir, compiler = self.compiler)\n exec 'from ' + mod_name + ' import test'\n b=1.\n test(b)\n try:\n b = 1.\n test(b)\n except TypeError:\n pass\n try:\n b = 'abc'\n test(b)\n except TypeError:\n pass\n teardown_test_location()\n\n def check_float_return(self):\n test_dir = setup_test_location() \n mod_name = sys._getframe().f_code.co_name + self.compiler\n mod_name = unique_mod(test_dir,mod_name)\n mod = ext_tools.ext_module(mod_name)\n a = 1.\n code = \"\"\"\n a=a+2.;\n return_val = PyFloat_FromDouble(a);\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = test_dir, compiler = self.compiler)\n exec 'from ' + mod_name + ' import test'\n b=1.\n c = test(b)\n teardown_test_location()\n assert( c == 3.)\n \nclass test_complex_converter(unittest.TestCase): \n compiler = ''\n def check_type_match_string(self):\n s = c_spec.complex_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = c_spec.complex_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = c_spec.complex_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = c_spec.complex_converter() \n assert(s.type_match(5.+1j))\n def check_complex_var_in(self):\n test_dir = setup_test_location() \n mod_name = sys._getframe().f_code.co_name + self.compiler\n mod_name = unique_mod(test_dir,mod_name)\n mod = ext_tools.ext_module(mod_name)\n a = 1.+1j\n code = \"a=std::complex(2.,2.);\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = test_dir, compiler = self.compiler)\n exec 'from ' + mod_name + ' import test'\n b=1.+1j\n test(b)\n try:\n b = 1.\n test(b)\n except TypeError:\n pass\n try:\n b = 'abc'\n test(b)\n except TypeError:\n pass\n teardown_test_location()\n\n def check_complex_return(self):\n test_dir = setup_test_location() \n mod_name = sys._getframe().f_code.co_name + self.compiler\n mod_name = unique_mod(test_dir,mod_name)\n mod = ext_tools.ext_module(mod_name)\n a = 1.+1j\n code = \"\"\"\n a= a + std::complex(2.,2.);\n return_val = PyComplex_FromDoubles(a.real(),a.imag());\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = test_dir, compiler = self.compiler)\n exec 'from ' + mod_name + ' import test'\n b=1.+1j\n c = test(b)\n teardown_test_location() \n assert( c == 3.+3j)\n\nclass test_msvc_int_converter(test_int_converter): \n compiler = 'msvc'\nclass test_msvc_float_converter(test_float_converter): \n compiler = 'msvc'\nclass test_msvc_complex_converter(test_complex_converter): \n compiler = 'msvc'\n\nclass test_unix_int_converter(test_int_converter): \n compiler = ''\nclass test_unix_float_converter(test_float_converter): \n compiler = ''\nclass test_unix_complex_converter(test_complex_converter): \n compiler = ''\n\nclass test_gcc_int_converter(test_int_converter): \n compiler = 'gcc'\nclass test_gcc_float_converter(test_float_converter): \n compiler = 'gcc'\nclass test_gcc_complex_converter(test_complex_converter): \n compiler = 'gcc'\n \ndef setup_test_location():\n import tempfile\n test_dir = os.path.join(tempfile.gettempdir(),'test_files')\n if not os.path.exists(test_dir):\n os.mkdir(test_dir)\n sys.path.insert(0,test_dir) \n return test_dir\n\ndef teardown_test_location():\n import tempfile\n test_dir = os.path.join(tempfile.gettempdir(),'test_files')\n if sys.path[0] == test_dir:\n sys.path = sys.path[1:]\n return test_dir\n\ndef remove_file(name):\n test_dir = os.path.abspath(name)\n\n#----------------------------------------------------------------------------\n# File conversion tests\n#----------------------------------------------------------------------------\n\nclass test_file_converter(unittest.TestCase): \n def check_py_to_file(self):\n import tempfile\n file_name = tempfile.mktemp() \n file = open(file_name,'w')\n code = \"\"\"\n fprintf(file,\"hello bob\");\n \"\"\"\n inline_tools.inline(code,['file']) \n file.close()\n file = open(file_name,'r')\n assert(file.read() == \"hello bob\")\n def check_file_to_py(self):\n import tempfile\n file_name = tempfile.mktemp() \n # not sure I like Py::String as default -- might move to std::sting\n # or just plain char*\n code = \"\"\"\n char* _file_name = (char*) file_name.c_str();\n FILE* file = fopen(_file_name,\"w\");\n return_val = file_to_py(file,_file_name,\"w\");\n Py_XINCREF(return_val);\n \"\"\"\n file = inline_tools.inline(code,['file_name'])\n file.write(\"hello fred\") \n file.close()\n file = open(file_name,'r')\n assert(file.read() == \"hello fred\")\n\n#----------------------------------------------------------------------------\n# Instance conversion tests\n#----------------------------------------------------------------------------\n\nclass test_instance_converter(unittest.TestCase): \n pass\n\n#----------------------------------------------------------------------------\n# Callable object conversion tests\n#----------------------------------------------------------------------------\n \nclass test_callable_converter(unittest.TestCase): \n def check_call_function(self):\n import string\n func = string.find\n search_str = \"hello world hello\"\n sub_str = \"world\"\n # * Not sure about ref counts on search_str and sub_str.\n # * Is the Py::String necessary? (it works anyways...)\n code = \"\"\"\n PWOTuple args(2);\n args.setItem(0,PWOString(search_str.c_str()));\n args.setItem(1,PWOString(sub_str.c_str()));\n return_val = PyObject_CallObject(func,args);\n \"\"\"\n actual = inline_tools.inline(code,['func','search_str','sub_str'])\n desired = func(search_str,sub_str) \n assert(desired == actual)\n\n\nclass test_sequence_converter(unittest.TestCase): \n def check_convert_to_dict(self):\n d = {}\n inline_tools.inline(\"\",['d']) \n def check_convert_to_list(self): \n l = []\n inline_tools.inline(\"\",['l']) \n def check_convert_to_string(self): \n s = 'hello'\n inline_tools.inline(\"\",['s']) \n def check_convert_to_tuple(self): \n t = ()\n inline_tools.inline(\"\",['t']) \n\nclass test_string_converter(unittest.TestCase): \n def check_type_match_string(self):\n s = c_spec.string_converter()\n assert( s.type_match('string') )\n def check_type_match_int(self):\n s = c_spec.string_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = c_spec.string_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = c_spec.string_converter() \n assert(not s.type_match(5.+1j))\n def check_var_in(self):\n mod = ext_tools.ext_module('string_var_in')\n a = 'string'\n code = 'a=std::string(\"hello\");'\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import string_var_in\n b='bub'\n string_var_in.test(b)\n try:\n b = 1.\n string_var_in.test(b)\n except TypeError:\n pass\n try:\n b = 1\n string_var_in.test(b)\n except TypeError:\n pass\n \n def check_return(self):\n mod = ext_tools.ext_module('string_return')\n a = 'string'\n code = \"\"\"\n a= std::string(\"hello\");\n return_val = PyString_FromString(a.c_str());\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import string_return\n b='bub'\n c = string_return.test(b)\n assert( c == 'hello')\n\nclass test_list_converter(unittest.TestCase): \n def check_type_match_bad(self):\n s = c_spec.list_converter()\n objs = [{},(),'',1,1.,1+1j]\n for i in objs:\n assert( not s.type_match(i) )\n def check_type_match_good(self):\n s = c_spec.list_converter() \n assert(s.type_match([]))\n def check_var_in(self):\n mod = ext_tools.ext_module('list_var_in')\n a = [1]\n code = 'a=PWOList();'\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import list_var_in\n b=[1,2]\n list_var_in.test(b)\n try:\n b = 1.\n list_var_in.test(b)\n except TypeError:\n pass\n try:\n b = 'string'\n list_var_in.test(b)\n except TypeError:\n pass\n \n def check_return(self):\n mod = ext_tools.ext_module('list_return')\n a = [1]\n code = \"\"\"\n a=PWOList();\n a.append(PWOString(\"hello\"));\n return_val = a.disOwn();\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import list_return\n b=[1,2]\n c = list_return.test(b)\n assert( c == ['hello'])\n \n def check_speed(self):\n mod = ext_tools.ext_module('list_speed')\n a = range(1e6);\n code = \"\"\"\n PWONumber v = PWONumber();\n int vv, sum = 0; \n for(int i = 0; i < a.len(); i++)\n {\n v = a[i];\n vv = (int)v;\n if (vv % 2)\n sum += vv;\n else\n sum -= vv; \n }\n return_val = PyInt_FromLong(sum);\n \"\"\"\n with_cxx = ext_tools.ext_function('with_cxx',code,['a'])\n mod.add_function(with_cxx)\n code = \"\"\"\n int vv, sum = 0;\n PyObject *v; \n for(int i = 0; i < a.len(); i++)\n {\n v = PyList_GetItem(py_a,i);\n //didn't set error here -- just speed test\n vv = py_to_int(v,\"list item\");\n if (vv % 2)\n sum += vv;\n else\n sum -= vv; \n }\n return_val = PyInt_FromLong(sum);\n \"\"\"\n no_checking = ext_tools.ext_function('no_checking',code,['a'])\n mod.add_function(no_checking)\n mod.compile()\n import list_speed\n import time\n t1 = time.time()\n sum1 = list_speed.with_cxx(a)\n t2 = time.time()\n print 'scxx:', t2 - t1\n t1 = time.time()\n sum2 = list_speed.no_checking(a)\n t2 = time.time()\n print 'C, no checking:', t2 - t1\n sum3 = 0\n t1 = time.time()\n for i in a:\n if i % 2:\n sum3 += i\n else:\n sum3 -= i\n t2 = time.time()\n print 'python:', t2 - t1 \n assert( sum1 == sum2 and sum1 == sum3)\n\nclass test_tuple_converter(unittest.TestCase): \n def check_type_match_bad(self):\n s = c_spec.tuple_converter()\n objs = [{},[],'',1,1.,1+1j]\n for i in objs:\n assert( not s.type_match(i) )\n def check_type_match_good(self):\n s = c_spec.tuple_converter() \n assert(s.type_match((1,)))\n def check_var_in(self):\n mod = ext_tools.ext_module('tuple_var_in')\n a = (1,)\n code = 'a=PWOTuple();'\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import tuple_var_in\n b=(1,2)\n tuple_var_in.test(b)\n try:\n b = 1.\n tuple_var_in.test(b)\n except TypeError:\n pass\n try:\n b = 'string'\n tuple_var_in.test(b)\n except TypeError:\n pass\n \n def check_return(self):\n mod = ext_tools.ext_module('tuple_return')\n a = (1,)\n code = \"\"\"\n a=PWOTuple(2);\n a.setItem(0,PWOString(\"hello\"));\n a.setItem(1,PWOBase(Py_None));\n return_val = a.disOwn();\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import tuple_return\n b=(1,2)\n c = tuple_return.test(b)\n assert( c == ('hello',None))\n\n\nclass test_dict_converter(unittest.TestCase): \n def check_type_match_bad(self):\n s = c_spec.dict_converter()\n objs = [[],(),'',1,1.,1+1j]\n for i in objs:\n assert( not s.type_match(i) )\n def check_type_match_good(self):\n s = c_spec.dict_converter() \n assert(s.type_match({}))\n def check_var_in(self):\n mod = ext_tools.ext_module('dict_var_in')\n a = {'z':1}\n code = 'a=PWODict();' # This just checks to make sure the type is correct\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import dict_var_in\n b={'y':2}\n dict_var_in.test(b)\n try:\n b = 1.\n dict_var_in.test(b)\n except TypeError:\n pass\n try:\n b = 'string'\n dict_var_in.test(b)\n except TypeError:\n pass\n \n def check_return(self):\n mod = ext_tools.ext_module('dict_return')\n a = {'z':1}\n code = \"\"\"\n a=PWODict();\n a[\"hello\"] = PWONumber(5);\n return_val = a.disOwn();\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile()\n import dict_return\n b = {'z':2}\n c = dict_return.test(b)\n assert( c['hello'] == 5)\n \ndef test_suite(level=1):\n suites = [] \n if level >= 5:\n \"\"\"\n if msvc_exists():\n suites.append( unittest.makeSuite(test_msvc_int_converter,\n 'check_'))\n suites.append( unittest.makeSuite(test_msvc_float_converter,\n 'check_')) \n suites.append( unittest.makeSuite(test_msvc_complex_converter,\n 'check_'))\n pass\n else: # unix\n suites.append( unittest.makeSuite(test_unix_int_converter,\n 'check_'))\n suites.append( unittest.makeSuite(test_unix_float_converter,\n 'check_')) \n suites.append( unittest.makeSuite(test_unix_complex_converter,\n 'check_'))\n \n if gcc_exists(): \n suites.append( unittest.makeSuite(test_gcc_int_converter,\n 'check_'))\n suites.append( unittest.makeSuite(test_gcc_float_converter,\n 'check_'))\n suites.append( unittest.makeSuite(test_gcc_complex_converter,\n 'check_'))\n\n # file, instance, callable object tests\n suites.append( unittest.makeSuite(test_file_converter,'check_'))\n suites.append( unittest.makeSuite(test_instance_converter,'check_'))\n suites.append( unittest.makeSuite(test_callable_converter,'check_'))\n \"\"\"\n # sequenc conversion tests\n suites.append( unittest.makeSuite(test_sequence_converter,'check_'))\n suites.append( unittest.makeSuite(test_string_converter,'check_'))\n suites.append( unittest.makeSuite(test_list_converter,'check_'))\n suites.append( unittest.makeSuite(test_tuple_converter,'check_'))\n suites.append( unittest.makeSuite(test_dict_converter,'check_'))\n \n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "unique_mod", "long_name": "unique_mod( d , file_name )", "filename": "test_c_spec.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "d", "file_name" ], "start_line": 15, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "remove_whitespace", "long_name": "remove_whitespace( in_str )", "filename": "test_c_spec.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "in_str" ], "start_line": 20, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "print_assert_equal", "long_name": "print_assert_equal( test_string , actual , desired )", "filename": "test_c_spec.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 27, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 49, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 52, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 55, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_complex", "long_name": "check_type_match_complex( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 58, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_var_in", "long_name": "check_var_in( self )", "filename": "test_c_spec.py", "nloc": 24, "complexity": 3, "token_count": 116, "parameters": [ "self" ], "start_line": 61, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_int_return", "long_name": "check_int_return( self )", "filename": "test_c_spec.py", "nloc": 18, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 86, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 107, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 110, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 113, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_complex", "long_name": "check_type_match_complex( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 116, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_float_var_in", "long_name": "check_float_var_in( self )", "filename": "test_c_spec.py", "nloc": 24, "complexity": 3, "token_count": 126, "parameters": [ "self" ], "start_line": 119, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "check_float_return", "long_name": "check_float_return( self )", "filename": "test_c_spec.py", "nloc": 18, "complexity": 1, "token_count": 108, "parameters": [ "self" ], "start_line": 145, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 166, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 169, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 172, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_complex", "long_name": "check_type_match_complex( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 175, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_complex_var_in", "long_name": "check_complex_var_in( self )", "filename": "test_c_spec.py", "nloc": 24, "complexity": 3, "token_count": 130, "parameters": [ "self" ], "start_line": 178, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_complex_return", "long_name": "check_complex_return( self )", "filename": "test_c_spec.py", "nloc": 18, "complexity": 1, "token_count": 114, "parameters": [ "self" ], "start_line": 203, "end_line": 220, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "setup_test_location", "long_name": "setup_test_location( )", "filename": "test_c_spec.py", "nloc": 7, "complexity": 2, "token_count": 51, "parameters": [], "start_line": 243, "end_line": 249, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "teardown_test_location", "long_name": "teardown_test_location( )", "filename": "test_c_spec.py", "nloc": 6, "complexity": 2, "token_count": 45, "parameters": [], "start_line": 251, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "remove_file", "long_name": "remove_file( name )", "filename": "test_c_spec.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "name" ], "start_line": 258, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "check_py_to_file", "long_name": "check_py_to_file( self )", "filename": "test_c_spec.py", "nloc": 11, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 266, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_file_to_py", "long_name": "check_file_to_py( self )", "filename": "test_c_spec.py", "nloc": 14, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 277, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_call_function", "long_name": "check_call_function( self )", "filename": "test_c_spec.py", "nloc": 14, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 306, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_convert_to_dict", "long_name": "check_convert_to_dict( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 325, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_convert_to_list", "long_name": "check_convert_to_list( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 328, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_convert_to_string", "long_name": "check_convert_to_string( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 331, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_convert_to_tuple", "long_name": "check_convert_to_tuple( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 334, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 339, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 342, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 345, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_complex", "long_name": "check_type_match_complex( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 348, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_var_in", "long_name": "check_var_in( self )", "filename": "test_c_spec.py", "nloc": 20, "complexity": 3, "token_count": 86, "parameters": [ "self" ], "start_line": 351, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_c_spec.py", "nloc": 14, "complexity": 1, "token_count": 63, "parameters": [ "self" ], "start_line": 372, "end_line": 385, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_c_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 388, "end_line": 392, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_type_match_good", "long_name": "check_type_match_good( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 393, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_var_in", "long_name": "check_var_in( self )", "filename": "test_c_spec.py", "nloc": 20, "complexity": 3, "token_count": 92, "parameters": [ "self" ], "start_line": 396, "end_line": 415, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_c_spec.py", "nloc": 15, "complexity": 1, "token_count": 71, "parameters": [ "self" ], "start_line": 417, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_speed", "long_name": "check_speed( self )", "filename": "test_c_spec.py", "nloc": 57, "complexity": 4, "token_count": 182, "parameters": [ "self" ], "start_line": 433, "end_line": 489, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 57, "top_nesting_level": 1 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_c_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 492, "end_line": 496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_type_match_good", "long_name": "check_type_match_good( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 497, "end_line": 499, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_var_in", "long_name": "check_var_in( self )", "filename": "test_c_spec.py", "nloc": 20, "complexity": 3, "token_count": 93, "parameters": [ "self" ], "start_line": 500, "end_line": 519, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_c_spec.py", "nloc": 16, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 521, "end_line": 536, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_c_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 540, "end_line": 544, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_type_match_good", "long_name": "check_type_match_good( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 545, "end_line": 547, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_var_in", "long_name": "check_var_in( self )", "filename": "test_c_spec.py", "nloc": 20, "complexity": 3, "token_count": 94, "parameters": [ "self" ], "start_line": 548, "end_line": 567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_c_spec.py", "nloc": 15, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 569, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_c_spec.py", "nloc": 40, "complexity": 2, "token_count": 92, "parameters": [ "level" ], "start_line": 585, "end_line": 626, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_c_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 628, "end_line": 632, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "unique_mod", "long_name": "unique_mod( d , file_name )", "filename": "test_c_spec.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "d", "file_name" ], "start_line": 15, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "remove_whitespace", "long_name": "remove_whitespace( in_str )", "filename": "test_c_spec.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "in_str" ], "start_line": 20, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "print_assert_equal", "long_name": "print_assert_equal( test_string , actual , desired )", "filename": "test_c_spec.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 27, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 49, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 52, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 55, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_complex", "long_name": "check_type_match_complex( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 58, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_var_in", "long_name": "check_var_in( self )", "filename": "test_c_spec.py", "nloc": 24, "complexity": 3, "token_count": 116, "parameters": [ "self" ], "start_line": 61, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_int_return", "long_name": "check_int_return( self )", "filename": "test_c_spec.py", "nloc": 18, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 86, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 107, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 110, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 113, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_complex", "long_name": "check_type_match_complex( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 116, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_float_var_in", "long_name": "check_float_var_in( self )", "filename": "test_c_spec.py", "nloc": 24, "complexity": 3, "token_count": 126, "parameters": [ "self" ], "start_line": 119, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "check_float_return", "long_name": "check_float_return( self )", "filename": "test_c_spec.py", "nloc": 18, "complexity": 1, "token_count": 108, "parameters": [ "self" ], "start_line": 145, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 166, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 169, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 172, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_complex", "long_name": "check_type_match_complex( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 175, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_complex_var_in", "long_name": "check_complex_var_in( self )", "filename": "test_c_spec.py", "nloc": 24, "complexity": 3, "token_count": 130, "parameters": [ "self" ], "start_line": 178, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_complex_return", "long_name": "check_complex_return( self )", "filename": "test_c_spec.py", "nloc": 18, "complexity": 1, "token_count": 114, "parameters": [ "self" ], "start_line": 203, "end_line": 220, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "setup_test_location", "long_name": "setup_test_location( )", "filename": "test_c_spec.py", "nloc": 7, "complexity": 2, "token_count": 51, "parameters": [], "start_line": 243, "end_line": 249, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "teardown_test_location", "long_name": "teardown_test_location( )", "filename": "test_c_spec.py", "nloc": 6, "complexity": 2, "token_count": 45, "parameters": [], "start_line": 251, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "remove_file", "long_name": "remove_file( name )", "filename": "test_c_spec.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "name" ], "start_line": 258, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "check_py_to_file", "long_name": "check_py_to_file( self )", "filename": "test_c_spec.py", "nloc": 11, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 266, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_file_to_py", "long_name": "check_file_to_py( self )", "filename": "test_c_spec.py", "nloc": 14, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 277, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_call_function", "long_name": "check_call_function( self )", "filename": "test_c_spec.py", "nloc": 14, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 306, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_convert_to_dict", "long_name": "check_convert_to_dict( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 325, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_convert_to_list", "long_name": "check_convert_to_list( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 328, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_convert_to_string", "long_name": "check_convert_to_string( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 331, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_convert_to_tuple", "long_name": "check_convert_to_tuple( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 334, "end_line": 336, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 339, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 342, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 345, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_complex", "long_name": "check_type_match_complex( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 348, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_var_in", "long_name": "check_var_in( self )", "filename": "test_c_spec.py", "nloc": 20, "complexity": 3, "token_count": 86, "parameters": [ "self" ], "start_line": 351, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_c_spec.py", "nloc": 14, "complexity": 1, "token_count": 63, "parameters": [ "self" ], "start_line": 372, "end_line": 385, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_c_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 388, "end_line": 392, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_type_match_good", "long_name": "check_type_match_good( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 393, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_var_in", "long_name": "check_var_in( self )", "filename": "test_c_spec.py", "nloc": 20, "complexity": 3, "token_count": 92, "parameters": [ "self" ], "start_line": 396, "end_line": 415, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_c_spec.py", "nloc": 15, "complexity": 1, "token_count": 71, "parameters": [ "self" ], "start_line": 417, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_speed", "long_name": "check_speed( self )", "filename": "test_c_spec.py", "nloc": 57, "complexity": 4, "token_count": 182, "parameters": [ "self" ], "start_line": 433, "end_line": 489, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 57, "top_nesting_level": 1 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_c_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 492, "end_line": 496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_type_match_good", "long_name": "check_type_match_good( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 497, "end_line": 499, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_var_in", "long_name": "check_var_in( self )", "filename": "test_c_spec.py", "nloc": 20, "complexity": 3, "token_count": 93, "parameters": [ "self" ], "start_line": 500, "end_line": 519, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_c_spec.py", "nloc": 16, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 521, "end_line": 536, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_c_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 540, "end_line": 544, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_type_match_good", "long_name": "check_type_match_good( self )", "filename": "test_c_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 545, "end_line": 547, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_var_in", "long_name": "check_var_in( self )", "filename": "test_c_spec.py", "nloc": 20, "complexity": 3, "token_count": 94, "parameters": [ "self" ], "start_line": 548, "end_line": 567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_c_spec.py", "nloc": 15, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 569, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_c_spec.py", "nloc": 40, "complexity": 2, "token_count": 92, "parameters": [ "level" ], "start_line": 585, "end_line": 626, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_c_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 628, "end_line": 632, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "print_assert_equal", "long_name": "print_assert_equal( test_string , actual , desired )", "filename": "test_c_spec.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 27, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 } ], "nloc": 575, "complexity": 76, "token_count": 3008, "diff_parsed": { "added": [ " \"\"\"this should probably be in scipy_test.testing" ], "deleted": [ " \"\"\"this should probably be in scipy_base.testing" ] } }, { "old_path": "weave/tests/test_size_check.py", "new_path": "weave/tests/test_size_check.py", "filename": "test_size_check.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -16,7 +16,7 @@\n empty = array(())\n \n def array_assert_equal(test_string,actual,desired):\n- \"\"\"this should probably be in scipy_base.testing\n+ \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n import pprint \n try:\n@@ -128,7 +128,7 @@ def check_error2(self):\n \n class test_dummy_array(test_binary_op_size):\n def array_assert_equal(self,test_string,actual,desired):\n- \"\"\"this should probably be in scipy_base.testing\n+ \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n import pprint \n try:\n@@ -165,7 +165,7 @@ def desired_type(self,val):\n \n class test_dummy_array_indexing(unittest.TestCase):\n def array_assert_equal(self,test_string,actual,desired):\n- \"\"\"this should probably be in scipy_base.testing\n+ \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n import pprint \n try:\n@@ -363,7 +363,7 @@ def check_error1(self):\n \n class test_expressions(unittest.TestCase): \n def array_assert_equal(self,test_string,actual,desired):\n- \"\"\"this should probably be in scipy_base.testing\n+ \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n import pprint \n try:\n", "added_lines": 4, "deleted_lines": 4, "source_code": "import unittest, os\nfrom Numeric import *\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from scipy_base.fastumath import *\nexcept:\n pass # scipy_base.fastumath not available \n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport size_check\nfrom ast_tools import *\nrestore_path()\n\nempty = array(())\n \ndef array_assert_equal(test_string,actual,desired):\n \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n import pprint \n try:\n assert(alltrue(equal(actual,desired)))\n except AssertionError:\n try:\n # kluge for bug in Numeric\n assert (len(actual[0]) == len(actual[1]) == \n len(desired[0]) == len(desired[1]) == 0)\n except: \n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n\nclass test_make_same_length(unittest.TestCase):\n\n def generic_test(self,x,y,desired):\n actual = size_check.make_same_length(x,y)\n desired = desired\n array_assert_equal('',actual,desired)\n\n def check_scalar(self):\n x,y = (),()\n desired = empty,empty \n self.generic_test(x,y,desired)\n def check_x_scalar(self):\n x,y = (),(1,2)\n desired = array((1,1)),array((1,2))\n self.generic_test(x,y,desired)\n def check_y_scalar(self):\n x,y = (1,2),()\n desired = array((1,2)),array((1,1))\n self.generic_test(x,y,desired)\n def check_x_short(self):\n x,y = (1,2),(1,2,3)\n desired = array((1,1,2)),array((1,2,3))\n self.generic_test(x,y,desired)\n def check_y_short(self):\n x,y = (1,2,3),(1,2)\n desired = array((1,2,3)),array((1,1,2))\n self.generic_test(x,y,desired)\n\nclass test_binary_op_size(unittest.TestCase):\n def generic_test(self,x,y,desired):\n actual = size_check.binary_op_size(x,y)\n desired = desired\n array_assert_equal('',actual,desired)\n def generic_error_test(self,x,y):\n try:\n actual = size_check.binary_op_size(x,y)\n #print actual\n raise AttributeError, \"Should have raised ValueError\"\n except ValueError:\n pass \n def desired_type(self,val):\n return array(val) \n def check_scalar(self):\n x,y = (),()\n desired = self.desired_type(())\n self.generic_test(x,y,desired)\n def check_x1(self):\n x,y = (1,),()\n desired = self.desired_type((1,))\n self.generic_test(x,y,desired)\n def check_y1(self):\n x,y = (),(1,)\n desired = self.desired_type((1,))\n self.generic_test(x,y,desired)\n def check_x_y(self):\n x,y = (5,),(5,)\n desired = self.desired_type((5,))\n self.generic_test(x,y,desired)\n def check_x_y2(self):\n x,y = (5,10),(5,10)\n desired = self.desired_type((5,10))\n self.generic_test(x,y,desired)\n def check_x_y3(self):\n x,y = (5,10),(1,10)\n desired = self.desired_type((5,10))\n self.generic_test(x,y,desired)\n def check_x_y4(self):\n x,y = (1,10),(5,10)\n desired = self.desired_type((5,10))\n self.generic_test(x,y,desired)\n def check_x_y5(self):\n x,y = (5,1),(1,10)\n desired = self.desired_type((5,10))\n self.generic_test(x,y,desired)\n def check_x_y6(self):\n x,y = (1,10),(5,1)\n desired = self.desired_type((5,10))\n self.generic_test(x,y,desired)\n def check_x_y7(self):\n x,y = (5,4,3,2,1),(3,2,1)\n desired = self.desired_type((5,4,3,2,1))\n self.generic_test(x,y,desired)\n \n def check_error1(self):\n x,y = (5,),(4,)\n self.generic_error_test(x,y)\n def check_error2(self):\n x,y = (5,5),(4,5)\n self.generic_error_test(x,y)\n\nclass test_dummy_array(test_binary_op_size):\n def array_assert_equal(self,test_string,actual,desired):\n \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n import pprint \n try:\n assert(actual == desired)\n except AssertionError:\n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue() \n def generic_test(self,x,y,desired):\n if type(x) is type(()):\n x = ones(x)\n if type(y) is type(()):\n y = ones(y)\n xx = size_check.dummy_array(x)\n yy = size_check.dummy_array(y)\n ops = ['+', '-', '/', '*', '<<', '>>']\n for op in ops:\n actual = eval('xx' + op + 'yy')\n desired = desired\n self.array_assert_equal('',actual,desired)\n def generic_error_test(self,x,y):\n try:\n self.generic_test('',x,y)\n raise AttributeError, \"Should have raised ValueError\"\n except ValueError:\n pass \n def desired_type(self,val):\n return size_check.dummy_array(array(val),1)\n\nclass test_dummy_array_indexing(unittest.TestCase):\n def array_assert_equal(self,test_string,actual,desired):\n \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n import pprint \n try:\n assert(alltrue(equal(actual,desired))) \n except AssertionError:\n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n def generic_test(self,ary,expr,desired):\n a = size_check.dummy_array(ary)\n actual = eval(expr).shape \n #print desired, actual\n self.array_assert_equal(expr,actual,desired)\n def generic_wrap(self,a,expr):\n #print expr ,eval(expr)\n desired = array(eval(expr).shape)\n try:\n self.generic_test(a,expr,desired)\n except IndexError:\n if 0 not in desired:\n msg = '%s raised IndexError in dummy_array, but forms\\n' \\\n 'valid array shape -> %s' % (expr, str(desired))\n raise AttributeError, msg \n def generic_1d(self,expr):\n a = arange(10)\n self.generic_wrap(a,expr)\n def generic_2d(self,expr):\n a = ones((10,20))\n self.generic_wrap(a,expr)\n def generic_3d(self,expr):\n a = ones((10,20,1))\n self.generic_wrap(a,expr)\n \n def generic_1d_index(self,expr):\n a = arange(10)\n #print expr ,eval(expr)\n desired = array(())\n self.generic_test(a,expr,desired)\n def check_1d_index_0(self):\n self.generic_1d_index('a[0]')\n def check_1d_index_1(self):\n self.generic_1d_index('a[4]')\n def check_1d_index_2(self):\n self.generic_1d_index('a[-4]')\n def check_1d_index_3(self):\n try: self.generic_1d('a[12]')\n except IndexError: pass \n def check_1d_index_calculated(self):\n self.generic_1d_index('a[0+1]')\n def check_1d_0(self):\n self.generic_1d('a[:]')\n def check_1d_1(self): \n self.generic_1d('a[1:]')\n def check_1d_2(self): \n self.generic_1d('a[-1:]')\n def check_1d_3(self):\n # dummy_array is \"bug for bug\" equiv to Numeric.array\n # on wrapping of indices.\n self.generic_1d('a[-11:]')\n def check_1d_4(self): \n self.generic_1d('a[:1]')\n def check_1d_5(self): \n self.generic_1d('a[:-1]')\n def check_1d_6(self): \n self.generic_1d('a[:-11]')\n def check_1d_7(self): \n self.generic_1d('a[1:5]')\n def check_1d_8(self): \n self.generic_1d('a[1:-5]')\n def check_1d_9(self):\n # don't support zero length slicing at the moment.\n try: self.generic_1d('a[-1:-5]')\n except IndexError: pass \n def check_1d_10(self): \n self.generic_1d('a[-5:-1]')\n \n def check_1d_stride_0(self): \n self.generic_1d('a[::1]') \n def check_1d_stride_1(self): \n self.generic_1d('a[::-1]') \n def check_1d_stride_2(self): \n self.generic_1d('a[1::1]') \n def check_1d_stride_3(self): \n self.generic_1d('a[1::-1]') \n def check_1d_stride_4(self): \n # don't support zero length slicing at the moment.\n try: self.generic_1d('a[1:5:-1]') \n except IndexError: pass \n def check_1d_stride_5(self): \n self.generic_1d('a[5:1:-1]') \n def check_1d_stride_6(self): \n self.generic_1d('a[:4:1]') \n def check_1d_stride_7(self): \n self.generic_1d('a[:4:-1]') \n def check_1d_stride_8(self): \n self.generic_1d('a[:-4:1]') \n def check_1d_stride_9(self): \n self.generic_1d('a[:-4:-1]') \n def check_1d_stride_10(self): \n self.generic_1d('a[:-3:2]') \n def check_1d_stride_11(self): \n self.generic_1d('a[:-3:-2]') \n def check_1d_stride_12(self): \n self.generic_1d('a[:-3:-7]') \n def check_1d_random(self):\n \"\"\" through a bunch of different indexes at it for good measure.\n \"\"\"\n import whrandom\n choices = map(lambda x: `x`,range(50)) + range(50) + ['']*50\n for i in range(100):\n try:\n beg = whrandom.choice(choices)\n end = whrandom.choice(choices)\n step = whrandom.choice(choices) \n self.generic_1d('a[%s:%s:%s]' %(beg,end,step)) \n except IndexError:\n pass\n\n def check_2d_0(self):\n self.generic_2d('a[:]')\n def check_2d_1(self):\n self.generic_2d('a[:2]')\n def check_2d_2(self):\n self.generic_2d('a[:,:]')\n def check_2d_random(self):\n \"\"\" through a bunch of different indexes at it for good measure.\n \"\"\"\n import whrandom\n choices = map(lambda x: `x`,range(50)) + range(50) + ['']*50 \n for i in range(100):\n try:\n beg = whrandom.choice(choices)\n end = whrandom.choice(choices)\n step = whrandom.choice(choices) \n beg2 = whrandom.choice(choices)\n end2 = whrandom.choice(choices)\n step2 = whrandom.choice(choices) \n expr = 'a[%s:%s:%s,%s:%s:%s]' %(beg,end,step,beg2,end2,step2)\n self.generic_2d(expr) \n except IndexError:\n pass\n def check_3d_random(self):\n \"\"\" through a bunch of different indexes at it for good measure.\n \"\"\"\n import whrandom\n choices = map(lambda x: `x`,range(50)) + range(50) + ['']*50 \n for i in range(100):\n try:\n idx = []\n for i in range(9):\n idx.append(whrandom.choice(choices))\n expr = 'a[%s:%s:%s,%s:%s:%s,%s:%s:%s]' % tuple(idx)\n self.generic_3d(expr) \n except IndexError:\n pass\n\nclass test_reduction(unittest.TestCase):\n def check_1d_0(self):\n a = ones((5,))\n actual = size_check.reduction(a,0)\n desired = size_check.dummy_array((),1)\n array_assert_equal('',actual.shape,desired.shape) \n def check_2d_0(self):\n a = ones((5,10))\n actual = size_check.reduction(a,0)\n desired = size_check.dummy_array((10,),1)\n array_assert_equal('',actual.shape,desired.shape) \n def check_2d_1(self):\n a = ones((5,10))\n actual = size_check.reduction(a,1)\n desired = size_check.dummy_array((5,),1)\n array_assert_equal('',actual.shape,desired.shape) \n def check_3d_0(self):\n a = ones((5,6,7))\n actual = size_check.reduction(a,1)\n desired = size_check.dummy_array((5,7),1)\n array_assert_equal('',actual.shape,desired.shape) \n def check_error0(self):\n a = ones((5,))\n try:\n actual = size_check.reduction(a,-2)\n except ValueError:\n pass \n def check_error1(self):\n a = ones((5,))\n try:\n actual = size_check.reduction(a,1)\n except ValueError:\n pass \n\nclass test_expressions(unittest.TestCase): \n def array_assert_equal(self,test_string,actual,desired):\n \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n import pprint \n try:\n assert(alltrue(equal(actual,desired))) \n except AssertionError:\n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n def generic_test(self,expr,desired,**kw):\n import parser\n ast_list = parser.expr(expr).tolist()\n args = harvest_variables(ast_list)\n loc = locals().update(kw)\n for var in args:\n s='%s = size_check.dummy_array(%s)'% (var,var)\n exec(s,loc)\n try: \n actual = eval(expr,locals()).shape \n except:\n actual = 'failed' \n if actual is 'failed' and desired is 'failed':\n return\n try: \n self.array_assert_equal(expr,actual,desired)\n except:\n print 'EXPR:',expr\n print 'ACTUAL:',actual\n print 'DEISRED:',desired\n def generic_wrap(self,expr,**kw):\n try:\n x = array(eval(expr,kw))\n try:\n desired = x.shape\n except:\n desired = zeros(())\n except:\n desired = 'failed'\n self.generic_test(expr,desired,**kw)\n def check_generic_1d(self):\n a = arange(10) \n expr = 'a[:]' \n self.generic_wrap(expr,a=a)\n expr = 'a[:] + a' \n self.generic_wrap(expr,a=a)\n bad_expr = 'a[4:] + a' \n self.generic_wrap(bad_expr,a=a)\n a = arange(10) \n b = ones((1,10))\n expr = 'a + b' \n self.generic_wrap(expr,a=a,b=b)\n bad_expr = 'a[:5] + b' \n self.generic_wrap(bad_expr,a=a,b=b)\n def check_single_index(self): \n a = arange(10) \n expr = 'a[5] + a[3]' \n self.generic_wrap(expr,a=a)\n \n def check_calculated_index(self): \n a = arange(10) \n nx = 0\n expr = 'a[5] + a[nx+3]' \n size_check.check_expr(expr,locals())\n def check_calculated_index2(self): \n a = arange(10) \n nx = 0\n expr = 'a[1:5] + a[nx+1:5+nx]' \n size_check.check_expr(expr,locals())\n def generic_2d(self,expr):\n a = ones((10,20))\n self.generic_wrap(a,expr)\n def generic_3d(self,expr):\n a = ones((10,20,1))\n self.generic_wrap(a,expr)\n \ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_make_same_length,'check_') )\n suites.append( unittest.makeSuite(test_binary_op_size,'check_') )\n suites.append( unittest.makeSuite(test_dummy_array,'check_') )\n suites.append( unittest.makeSuite(test_dummy_array_indexing,'check_') )\n suites.append( unittest.makeSuite(test_reduction,'check_') )\n suites.append( unittest.makeSuite(test_expressions,'check_') )\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "source_code_before": "import unittest, os\nfrom Numeric import *\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from scipy_base.fastumath import *\nexcept:\n pass # scipy_base.fastumath not available \n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport size_check\nfrom ast_tools import *\nrestore_path()\n\nempty = array(())\n \ndef array_assert_equal(test_string,actual,desired):\n \"\"\"this should probably be in scipy_base.testing\n \"\"\"\n import pprint \n try:\n assert(alltrue(equal(actual,desired)))\n except AssertionError:\n try:\n # kluge for bug in Numeric\n assert (len(actual[0]) == len(actual[1]) == \n len(desired[0]) == len(desired[1]) == 0)\n except: \n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n\nclass test_make_same_length(unittest.TestCase):\n\n def generic_test(self,x,y,desired):\n actual = size_check.make_same_length(x,y)\n desired = desired\n array_assert_equal('',actual,desired)\n\n def check_scalar(self):\n x,y = (),()\n desired = empty,empty \n self.generic_test(x,y,desired)\n def check_x_scalar(self):\n x,y = (),(1,2)\n desired = array((1,1)),array((1,2))\n self.generic_test(x,y,desired)\n def check_y_scalar(self):\n x,y = (1,2),()\n desired = array((1,2)),array((1,1))\n self.generic_test(x,y,desired)\n def check_x_short(self):\n x,y = (1,2),(1,2,3)\n desired = array((1,1,2)),array((1,2,3))\n self.generic_test(x,y,desired)\n def check_y_short(self):\n x,y = (1,2,3),(1,2)\n desired = array((1,2,3)),array((1,1,2))\n self.generic_test(x,y,desired)\n\nclass test_binary_op_size(unittest.TestCase):\n def generic_test(self,x,y,desired):\n actual = size_check.binary_op_size(x,y)\n desired = desired\n array_assert_equal('',actual,desired)\n def generic_error_test(self,x,y):\n try:\n actual = size_check.binary_op_size(x,y)\n #print actual\n raise AttributeError, \"Should have raised ValueError\"\n except ValueError:\n pass \n def desired_type(self,val):\n return array(val) \n def check_scalar(self):\n x,y = (),()\n desired = self.desired_type(())\n self.generic_test(x,y,desired)\n def check_x1(self):\n x,y = (1,),()\n desired = self.desired_type((1,))\n self.generic_test(x,y,desired)\n def check_y1(self):\n x,y = (),(1,)\n desired = self.desired_type((1,))\n self.generic_test(x,y,desired)\n def check_x_y(self):\n x,y = (5,),(5,)\n desired = self.desired_type((5,))\n self.generic_test(x,y,desired)\n def check_x_y2(self):\n x,y = (5,10),(5,10)\n desired = self.desired_type((5,10))\n self.generic_test(x,y,desired)\n def check_x_y3(self):\n x,y = (5,10),(1,10)\n desired = self.desired_type((5,10))\n self.generic_test(x,y,desired)\n def check_x_y4(self):\n x,y = (1,10),(5,10)\n desired = self.desired_type((5,10))\n self.generic_test(x,y,desired)\n def check_x_y5(self):\n x,y = (5,1),(1,10)\n desired = self.desired_type((5,10))\n self.generic_test(x,y,desired)\n def check_x_y6(self):\n x,y = (1,10),(5,1)\n desired = self.desired_type((5,10))\n self.generic_test(x,y,desired)\n def check_x_y7(self):\n x,y = (5,4,3,2,1),(3,2,1)\n desired = self.desired_type((5,4,3,2,1))\n self.generic_test(x,y,desired)\n \n def check_error1(self):\n x,y = (5,),(4,)\n self.generic_error_test(x,y)\n def check_error2(self):\n x,y = (5,5),(4,5)\n self.generic_error_test(x,y)\n\nclass test_dummy_array(test_binary_op_size):\n def array_assert_equal(self,test_string,actual,desired):\n \"\"\"this should probably be in scipy_base.testing\n \"\"\"\n import pprint \n try:\n assert(actual == desired)\n except AssertionError:\n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue() \n def generic_test(self,x,y,desired):\n if type(x) is type(()):\n x = ones(x)\n if type(y) is type(()):\n y = ones(y)\n xx = size_check.dummy_array(x)\n yy = size_check.dummy_array(y)\n ops = ['+', '-', '/', '*', '<<', '>>']\n for op in ops:\n actual = eval('xx' + op + 'yy')\n desired = desired\n self.array_assert_equal('',actual,desired)\n def generic_error_test(self,x,y):\n try:\n self.generic_test('',x,y)\n raise AttributeError, \"Should have raised ValueError\"\n except ValueError:\n pass \n def desired_type(self,val):\n return size_check.dummy_array(array(val),1)\n\nclass test_dummy_array_indexing(unittest.TestCase):\n def array_assert_equal(self,test_string,actual,desired):\n \"\"\"this should probably be in scipy_base.testing\n \"\"\"\n import pprint \n try:\n assert(alltrue(equal(actual,desired))) \n except AssertionError:\n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n def generic_test(self,ary,expr,desired):\n a = size_check.dummy_array(ary)\n actual = eval(expr).shape \n #print desired, actual\n self.array_assert_equal(expr,actual,desired)\n def generic_wrap(self,a,expr):\n #print expr ,eval(expr)\n desired = array(eval(expr).shape)\n try:\n self.generic_test(a,expr,desired)\n except IndexError:\n if 0 not in desired:\n msg = '%s raised IndexError in dummy_array, but forms\\n' \\\n 'valid array shape -> %s' % (expr, str(desired))\n raise AttributeError, msg \n def generic_1d(self,expr):\n a = arange(10)\n self.generic_wrap(a,expr)\n def generic_2d(self,expr):\n a = ones((10,20))\n self.generic_wrap(a,expr)\n def generic_3d(self,expr):\n a = ones((10,20,1))\n self.generic_wrap(a,expr)\n \n def generic_1d_index(self,expr):\n a = arange(10)\n #print expr ,eval(expr)\n desired = array(())\n self.generic_test(a,expr,desired)\n def check_1d_index_0(self):\n self.generic_1d_index('a[0]')\n def check_1d_index_1(self):\n self.generic_1d_index('a[4]')\n def check_1d_index_2(self):\n self.generic_1d_index('a[-4]')\n def check_1d_index_3(self):\n try: self.generic_1d('a[12]')\n except IndexError: pass \n def check_1d_index_calculated(self):\n self.generic_1d_index('a[0+1]')\n def check_1d_0(self):\n self.generic_1d('a[:]')\n def check_1d_1(self): \n self.generic_1d('a[1:]')\n def check_1d_2(self): \n self.generic_1d('a[-1:]')\n def check_1d_3(self):\n # dummy_array is \"bug for bug\" equiv to Numeric.array\n # on wrapping of indices.\n self.generic_1d('a[-11:]')\n def check_1d_4(self): \n self.generic_1d('a[:1]')\n def check_1d_5(self): \n self.generic_1d('a[:-1]')\n def check_1d_6(self): \n self.generic_1d('a[:-11]')\n def check_1d_7(self): \n self.generic_1d('a[1:5]')\n def check_1d_8(self): \n self.generic_1d('a[1:-5]')\n def check_1d_9(self):\n # don't support zero length slicing at the moment.\n try: self.generic_1d('a[-1:-5]')\n except IndexError: pass \n def check_1d_10(self): \n self.generic_1d('a[-5:-1]')\n \n def check_1d_stride_0(self): \n self.generic_1d('a[::1]') \n def check_1d_stride_1(self): \n self.generic_1d('a[::-1]') \n def check_1d_stride_2(self): \n self.generic_1d('a[1::1]') \n def check_1d_stride_3(self): \n self.generic_1d('a[1::-1]') \n def check_1d_stride_4(self): \n # don't support zero length slicing at the moment.\n try: self.generic_1d('a[1:5:-1]') \n except IndexError: pass \n def check_1d_stride_5(self): \n self.generic_1d('a[5:1:-1]') \n def check_1d_stride_6(self): \n self.generic_1d('a[:4:1]') \n def check_1d_stride_7(self): \n self.generic_1d('a[:4:-1]') \n def check_1d_stride_8(self): \n self.generic_1d('a[:-4:1]') \n def check_1d_stride_9(self): \n self.generic_1d('a[:-4:-1]') \n def check_1d_stride_10(self): \n self.generic_1d('a[:-3:2]') \n def check_1d_stride_11(self): \n self.generic_1d('a[:-3:-2]') \n def check_1d_stride_12(self): \n self.generic_1d('a[:-3:-7]') \n def check_1d_random(self):\n \"\"\" through a bunch of different indexes at it for good measure.\n \"\"\"\n import whrandom\n choices = map(lambda x: `x`,range(50)) + range(50) + ['']*50\n for i in range(100):\n try:\n beg = whrandom.choice(choices)\n end = whrandom.choice(choices)\n step = whrandom.choice(choices) \n self.generic_1d('a[%s:%s:%s]' %(beg,end,step)) \n except IndexError:\n pass\n\n def check_2d_0(self):\n self.generic_2d('a[:]')\n def check_2d_1(self):\n self.generic_2d('a[:2]')\n def check_2d_2(self):\n self.generic_2d('a[:,:]')\n def check_2d_random(self):\n \"\"\" through a bunch of different indexes at it for good measure.\n \"\"\"\n import whrandom\n choices = map(lambda x: `x`,range(50)) + range(50) + ['']*50 \n for i in range(100):\n try:\n beg = whrandom.choice(choices)\n end = whrandom.choice(choices)\n step = whrandom.choice(choices) \n beg2 = whrandom.choice(choices)\n end2 = whrandom.choice(choices)\n step2 = whrandom.choice(choices) \n expr = 'a[%s:%s:%s,%s:%s:%s]' %(beg,end,step,beg2,end2,step2)\n self.generic_2d(expr) \n except IndexError:\n pass\n def check_3d_random(self):\n \"\"\" through a bunch of different indexes at it for good measure.\n \"\"\"\n import whrandom\n choices = map(lambda x: `x`,range(50)) + range(50) + ['']*50 \n for i in range(100):\n try:\n idx = []\n for i in range(9):\n idx.append(whrandom.choice(choices))\n expr = 'a[%s:%s:%s,%s:%s:%s,%s:%s:%s]' % tuple(idx)\n self.generic_3d(expr) \n except IndexError:\n pass\n\nclass test_reduction(unittest.TestCase):\n def check_1d_0(self):\n a = ones((5,))\n actual = size_check.reduction(a,0)\n desired = size_check.dummy_array((),1)\n array_assert_equal('',actual.shape,desired.shape) \n def check_2d_0(self):\n a = ones((5,10))\n actual = size_check.reduction(a,0)\n desired = size_check.dummy_array((10,),1)\n array_assert_equal('',actual.shape,desired.shape) \n def check_2d_1(self):\n a = ones((5,10))\n actual = size_check.reduction(a,1)\n desired = size_check.dummy_array((5,),1)\n array_assert_equal('',actual.shape,desired.shape) \n def check_3d_0(self):\n a = ones((5,6,7))\n actual = size_check.reduction(a,1)\n desired = size_check.dummy_array((5,7),1)\n array_assert_equal('',actual.shape,desired.shape) \n def check_error0(self):\n a = ones((5,))\n try:\n actual = size_check.reduction(a,-2)\n except ValueError:\n pass \n def check_error1(self):\n a = ones((5,))\n try:\n actual = size_check.reduction(a,1)\n except ValueError:\n pass \n\nclass test_expressions(unittest.TestCase): \n def array_assert_equal(self,test_string,actual,desired):\n \"\"\"this should probably be in scipy_base.testing\n \"\"\"\n import pprint \n try:\n assert(alltrue(equal(actual,desired))) \n except AssertionError:\n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n def generic_test(self,expr,desired,**kw):\n import parser\n ast_list = parser.expr(expr).tolist()\n args = harvest_variables(ast_list)\n loc = locals().update(kw)\n for var in args:\n s='%s = size_check.dummy_array(%s)'% (var,var)\n exec(s,loc)\n try: \n actual = eval(expr,locals()).shape \n except:\n actual = 'failed' \n if actual is 'failed' and desired is 'failed':\n return\n try: \n self.array_assert_equal(expr,actual,desired)\n except:\n print 'EXPR:',expr\n print 'ACTUAL:',actual\n print 'DEISRED:',desired\n def generic_wrap(self,expr,**kw):\n try:\n x = array(eval(expr,kw))\n try:\n desired = x.shape\n except:\n desired = zeros(())\n except:\n desired = 'failed'\n self.generic_test(expr,desired,**kw)\n def check_generic_1d(self):\n a = arange(10) \n expr = 'a[:]' \n self.generic_wrap(expr,a=a)\n expr = 'a[:] + a' \n self.generic_wrap(expr,a=a)\n bad_expr = 'a[4:] + a' \n self.generic_wrap(bad_expr,a=a)\n a = arange(10) \n b = ones((1,10))\n expr = 'a + b' \n self.generic_wrap(expr,a=a,b=b)\n bad_expr = 'a[:5] + b' \n self.generic_wrap(bad_expr,a=a,b=b)\n def check_single_index(self): \n a = arange(10) \n expr = 'a[5] + a[3]' \n self.generic_wrap(expr,a=a)\n \n def check_calculated_index(self): \n a = arange(10) \n nx = 0\n expr = 'a[5] + a[nx+3]' \n size_check.check_expr(expr,locals())\n def check_calculated_index2(self): \n a = arange(10) \n nx = 0\n expr = 'a[1:5] + a[nx+1:5+nx]' \n size_check.check_expr(expr,locals())\n def generic_2d(self,expr):\n a = ones((10,20))\n self.generic_wrap(a,expr)\n def generic_3d(self,expr):\n a = ones((10,20,1))\n self.generic_wrap(a,expr)\n \ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_make_same_length,'check_') )\n suites.append( unittest.makeSuite(test_binary_op_size,'check_') )\n suites.append( unittest.makeSuite(test_dummy_array,'check_') )\n suites.append( unittest.makeSuite(test_dummy_array_indexing,'check_') )\n suites.append( unittest.makeSuite(test_reduction,'check_') )\n suites.append( unittest.makeSuite(test_expressions,'check_') )\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "array_assert_equal", "long_name": "array_assert_equal( test_string , actual , desired )", "filename": "test_size_check.py", "nloc": 17, "complexity": 3, "token_count": 120, "parameters": [ "test_string", "actual", "desired" ], "start_line": 18, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "generic_test", "long_name": "generic_test( self , x , y , desired )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 32, "parameters": [ "self", "x", "y", "desired" ], "start_line": 41, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_scalar", "long_name": "check_scalar( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 29, "parameters": [ "self" ], "start_line": 46, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_scalar", "long_name": "check_x_scalar( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 46, "parameters": [ "self" ], "start_line": 50, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_y_scalar", "long_name": "check_y_scalar( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 46, "parameters": [ "self" ], "start_line": 54, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_short", "long_name": "check_x_short( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 55, "parameters": [ "self" ], "start_line": 58, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_y_short", "long_name": "check_y_short( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 55, "parameters": [ "self" ], "start_line": 62, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "generic_test", "long_name": "generic_test( self , x , y , desired )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 32, "parameters": [ "self", "x", "y", "desired" ], "start_line": 68, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "generic_error_test", "long_name": "generic_error_test( self , x , y )", "filename": "test_size_check.py", "nloc": 6, "complexity": 2, "token_count": 29, "parameters": [ "self", "x", "y" ], "start_line": 72, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "desired_type", "long_name": "desired_type( self , val )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "val" ], "start_line": 79, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_scalar", "long_name": "check_scalar( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 33, "parameters": [ "self" ], "start_line": 81, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x1", "long_name": "check_x1( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "self" ], "start_line": 85, "end_line": 88, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_y1", "long_name": "check_y1( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "self" ], "start_line": 89, "end_line": 92, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_y", "long_name": "check_x_y( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 39, "parameters": [ "self" ], "start_line": 93, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_y2", "long_name": "check_x_y2( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "self" ], "start_line": 97, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_y3", "long_name": "check_x_y3( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "self" ], "start_line": 101, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_y4", "long_name": "check_x_y4( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "self" ], "start_line": 105, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_y5", "long_name": "check_x_y5( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "self" ], "start_line": 109, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_y6", "long_name": "check_x_y6( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "self" ], "start_line": 113, "end_line": 116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_y7", "long_name": "check_x_y7( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 117, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_error1", "long_name": "check_error1( self )", "filename": "test_size_check.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "self" ], "start_line": 122, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_error2", "long_name": "check_error2( self )", "filename": "test_size_check.py", "nloc": 3, "complexity": 1, "token_count": 28, "parameters": [ "self" ], "start_line": 125, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "array_assert_equal", "long_name": "array_assert_equal( self , test_string , actual , desired )", "filename": "test_size_check.py", "nloc": 13, "complexity": 2, "token_count": 76, "parameters": [ "self", "test_string", "actual", "desired" ], "start_line": 130, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "generic_test", "long_name": "generic_test( self , x , y , desired )", "filename": "test_size_check.py", "nloc": 12, "complexity": 4, "token_count": 106, "parameters": [ "self", "x", "y", "desired" ], "start_line": 145, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "generic_error_test", "long_name": "generic_error_test( self , x , y )", "filename": "test_size_check.py", "nloc": 6, "complexity": 2, "token_count": 29, "parameters": [ "self", "x", "y" ], "start_line": 157, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "desired_type", "long_name": "desired_type( self , val )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self", "val" ], "start_line": 163, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "array_assert_equal", "long_name": "array_assert_equal( self , test_string , actual , desired )", "filename": "test_size_check.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "test_string", "actual", "desired" ], "start_line": 167, "end_line": 181, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "generic_test", "long_name": "generic_test( self , ary , expr , desired )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "self", "ary", "expr", "desired" ], "start_line": 182, "end_line": 186, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "generic_wrap", "long_name": "generic_wrap( self , a , expr )", "filename": "test_size_check.py", "nloc": 9, "complexity": 3, "token_count": 59, "parameters": [ "self", "a", "expr" ], "start_line": 187, "end_line": 196, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "generic_1d", "long_name": "generic_1d( self , expr )", "filename": "test_size_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self", "expr" ], "start_line": 197, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "generic_2d", "long_name": "generic_2d( self , expr )", "filename": "test_size_check.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "expr" ], "start_line": 200, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "generic_3d", "long_name": "generic_3d( self , expr )", "filename": "test_size_check.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "expr" ], "start_line": 203, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "generic_1d_index", "long_name": "generic_1d_index( self , expr )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "self", "expr" ], "start_line": 207, "end_line": 211, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_1d_index_0", "long_name": "check_1d_index_0( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 212, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_index_1", "long_name": "check_1d_index_1( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 214, "end_line": 215, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_index_2", "long_name": "check_1d_index_2( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 216, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_index_3", "long_name": "check_1d_index_3( self )", "filename": "test_size_check.py", "nloc": 3, "complexity": 2, "token_count": 17, "parameters": [ "self" ], "start_line": 218, "end_line": 220, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_1d_index_calculated", "long_name": "check_1d_index_calculated( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 221, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_0", "long_name": "check_1d_0( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 223, "end_line": 224, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_1", "long_name": "check_1d_1( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 225, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_2", "long_name": "check_1d_2( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 227, "end_line": 228, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_3", "long_name": "check_1d_3( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 229, "end_line": 232, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_1d_4", "long_name": "check_1d_4( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 233, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_5", "long_name": "check_1d_5( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 235, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_6", "long_name": "check_1d_6( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 237, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_7", "long_name": "check_1d_7( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 239, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_8", "long_name": "check_1d_8( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 241, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_9", "long_name": "check_1d_9( self )", "filename": "test_size_check.py", "nloc": 3, "complexity": 2, "token_count": 17, "parameters": [ "self" ], "start_line": 243, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_1d_10", "long_name": "check_1d_10( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 247, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_0", "long_name": "check_1d_stride_0( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 250, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_1", "long_name": "check_1d_stride_1( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 252, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_2", "long_name": "check_1d_stride_2( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 254, "end_line": 255, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_3", "long_name": "check_1d_stride_3( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 256, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_4", "long_name": "check_1d_stride_4( self )", "filename": "test_size_check.py", "nloc": 3, "complexity": 2, "token_count": 17, "parameters": [ "self" ], "start_line": 258, "end_line": 261, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_1d_stride_5", "long_name": "check_1d_stride_5( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 262, "end_line": 263, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_6", "long_name": "check_1d_stride_6( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 264, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_7", "long_name": "check_1d_stride_7( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 266, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_8", "long_name": "check_1d_stride_8( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 268, "end_line": 269, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_9", "long_name": "check_1d_stride_9( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 270, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_10", "long_name": "check_1d_stride_10( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_11", "long_name": "check_1d_stride_11( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 274, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_12", "long_name": "check_1d_stride_12( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 276, "end_line": 277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_random", "long_name": "check_1d_random( self )", "filename": "test_size_check.py", "nloc": 11, "complexity": 3, "token_count": 87, "parameters": [ "self" ], "start_line": 278, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_2d_0", "long_name": "check_2d_0( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 292, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_2d_1", "long_name": "check_2d_1( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 294, "end_line": 295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_2d_2", "long_name": "check_2d_2( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 296, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_2d_random", "long_name": "check_2d_random( self )", "filename": "test_size_check.py", "nloc": 15, "complexity": 3, "token_count": 120, "parameters": [ "self" ], "start_line": 298, "end_line": 314, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "check_3d_random", "long_name": "check_3d_random( self )", "filename": "test_size_check.py", "nloc": 12, "complexity": 4, "token_count": 86, "parameters": [ "self" ], "start_line": 315, "end_line": 328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "check_1d_0", "long_name": "check_1d_0( self )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 47, "parameters": [ "self" ], "start_line": 331, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2d_0", "long_name": "check_2d_0( self )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 50, "parameters": [ "self" ], "start_line": 336, "end_line": 340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2d_1", "long_name": "check_2d_1( self )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 50, "parameters": [ "self" ], "start_line": 341, "end_line": 345, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_3d_0", "long_name": "check_3d_0( self )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 53, "parameters": [ "self" ], "start_line": 346, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_error0", "long_name": "check_error0( self )", "filename": "test_size_check.py", "nloc": 6, "complexity": 2, "token_count": 31, "parameters": [ "self" ], "start_line": 351, "end_line": 356, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_error1", "long_name": "check_error1( self )", "filename": "test_size_check.py", "nloc": 6, "complexity": 2, "token_count": 30, "parameters": [ "self" ], "start_line": 357, "end_line": 362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "array_assert_equal", "long_name": "array_assert_equal( self , test_string , actual , desired )", "filename": "test_size_check.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "test_string", "actual", "desired" ], "start_line": 365, "end_line": 379, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "generic_test", "long_name": "generic_test( self , expr , desired , ** kw )", "filename": "test_size_check.py", "nloc": 20, "complexity": 6, "token_count": 117, "parameters": [ "self", "expr", "desired", "kw" ], "start_line": 380, "end_line": 399, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "generic_wrap", "long_name": "generic_wrap( self , expr , ** kw )", "filename": "test_size_check.py", "nloc": 10, "complexity": 3, "token_count": 55, "parameters": [ "self", "expr", "kw" ], "start_line": 400, "end_line": 409, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_generic_1d", "long_name": "check_generic_1d( self )", "filename": "test_size_check.py", "nloc": 14, "complexity": 1, "token_count": 100, "parameters": [ "self" ], "start_line": 410, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "check_single_index", "long_name": "check_single_index( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 424, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_calculated_index", "long_name": "check_calculated_index( self )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "self" ], "start_line": 429, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_calculated_index2", "long_name": "check_calculated_index2( self )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "self" ], "start_line": 434, "end_line": 438, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "generic_2d", "long_name": "generic_2d( self , expr )", "filename": "test_size_check.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "expr" ], "start_line": 439, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "generic_3d", "long_name": "generic_3d( self , expr )", "filename": "test_size_check.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "expr" ], "start_line": 442, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_size_check.py", "nloc": 11, "complexity": 2, "token_count": 104, "parameters": [ "level" ], "start_line": 446, "end_line": 456, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 458, "end_line": 462, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "array_assert_equal", "long_name": "array_assert_equal( test_string , actual , desired )", "filename": "test_size_check.py", "nloc": 17, "complexity": 3, "token_count": 120, "parameters": [ "test_string", "actual", "desired" ], "start_line": 18, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "generic_test", "long_name": "generic_test( self , x , y , desired )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 32, "parameters": [ "self", "x", "y", "desired" ], "start_line": 41, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_scalar", "long_name": "check_scalar( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 29, "parameters": [ "self" ], "start_line": 46, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_scalar", "long_name": "check_x_scalar( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 46, "parameters": [ "self" ], "start_line": 50, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_y_scalar", "long_name": "check_y_scalar( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 46, "parameters": [ "self" ], "start_line": 54, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_short", "long_name": "check_x_short( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 55, "parameters": [ "self" ], "start_line": 58, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_y_short", "long_name": "check_y_short( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 55, "parameters": [ "self" ], "start_line": 62, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "generic_test", "long_name": "generic_test( self , x , y , desired )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 32, "parameters": [ "self", "x", "y", "desired" ], "start_line": 68, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "generic_error_test", "long_name": "generic_error_test( self , x , y )", "filename": "test_size_check.py", "nloc": 6, "complexity": 2, "token_count": 29, "parameters": [ "self", "x", "y" ], "start_line": 72, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "desired_type", "long_name": "desired_type( self , val )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "val" ], "start_line": 79, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_scalar", "long_name": "check_scalar( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 33, "parameters": [ "self" ], "start_line": 81, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x1", "long_name": "check_x1( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "self" ], "start_line": 85, "end_line": 88, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_y1", "long_name": "check_y1( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "self" ], "start_line": 89, "end_line": 92, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_y", "long_name": "check_x_y( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 39, "parameters": [ "self" ], "start_line": 93, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_y2", "long_name": "check_x_y2( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "self" ], "start_line": 97, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_y3", "long_name": "check_x_y3( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "self" ], "start_line": 101, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_y4", "long_name": "check_x_y4( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "self" ], "start_line": 105, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_y5", "long_name": "check_x_y5( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "self" ], "start_line": 109, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_y6", "long_name": "check_x_y6( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 42, "parameters": [ "self" ], "start_line": 113, "end_line": 116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_x_y7", "long_name": "check_x_y7( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 117, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_error1", "long_name": "check_error1( self )", "filename": "test_size_check.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "self" ], "start_line": 122, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_error2", "long_name": "check_error2( self )", "filename": "test_size_check.py", "nloc": 3, "complexity": 1, "token_count": 28, "parameters": [ "self" ], "start_line": 125, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "array_assert_equal", "long_name": "array_assert_equal( self , test_string , actual , desired )", "filename": "test_size_check.py", "nloc": 13, "complexity": 2, "token_count": 76, "parameters": [ "self", "test_string", "actual", "desired" ], "start_line": 130, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "generic_test", "long_name": "generic_test( self , x , y , desired )", "filename": "test_size_check.py", "nloc": 12, "complexity": 4, "token_count": 106, "parameters": [ "self", "x", "y", "desired" ], "start_line": 145, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "generic_error_test", "long_name": "generic_error_test( self , x , y )", "filename": "test_size_check.py", "nloc": 6, "complexity": 2, "token_count": 29, "parameters": [ "self", "x", "y" ], "start_line": 157, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "desired_type", "long_name": "desired_type( self , val )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self", "val" ], "start_line": 163, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "array_assert_equal", "long_name": "array_assert_equal( self , test_string , actual , desired )", "filename": "test_size_check.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "test_string", "actual", "desired" ], "start_line": 167, "end_line": 181, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "generic_test", "long_name": "generic_test( self , ary , expr , desired )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "self", "ary", "expr", "desired" ], "start_line": 182, "end_line": 186, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "generic_wrap", "long_name": "generic_wrap( self , a , expr )", "filename": "test_size_check.py", "nloc": 9, "complexity": 3, "token_count": 59, "parameters": [ "self", "a", "expr" ], "start_line": 187, "end_line": 196, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "generic_1d", "long_name": "generic_1d( self , expr )", "filename": "test_size_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self", "expr" ], "start_line": 197, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "generic_2d", "long_name": "generic_2d( self , expr )", "filename": "test_size_check.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "expr" ], "start_line": 200, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "generic_3d", "long_name": "generic_3d( self , expr )", "filename": "test_size_check.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "expr" ], "start_line": 203, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "generic_1d_index", "long_name": "generic_1d_index( self , expr )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "self", "expr" ], "start_line": 207, "end_line": 211, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_1d_index_0", "long_name": "check_1d_index_0( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 212, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_index_1", "long_name": "check_1d_index_1( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 214, "end_line": 215, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_index_2", "long_name": "check_1d_index_2( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 216, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_index_3", "long_name": "check_1d_index_3( self )", "filename": "test_size_check.py", "nloc": 3, "complexity": 2, "token_count": 17, "parameters": [ "self" ], "start_line": 218, "end_line": 220, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_1d_index_calculated", "long_name": "check_1d_index_calculated( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 221, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_0", "long_name": "check_1d_0( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 223, "end_line": 224, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_1", "long_name": "check_1d_1( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 225, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_2", "long_name": "check_1d_2( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 227, "end_line": 228, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_3", "long_name": "check_1d_3( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 229, "end_line": 232, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_1d_4", "long_name": "check_1d_4( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 233, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_5", "long_name": "check_1d_5( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 235, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_6", "long_name": "check_1d_6( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 237, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_7", "long_name": "check_1d_7( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 239, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_8", "long_name": "check_1d_8( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 241, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_9", "long_name": "check_1d_9( self )", "filename": "test_size_check.py", "nloc": 3, "complexity": 2, "token_count": 17, "parameters": [ "self" ], "start_line": 243, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_1d_10", "long_name": "check_1d_10( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 247, "end_line": 248, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_0", "long_name": "check_1d_stride_0( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 250, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_1", "long_name": "check_1d_stride_1( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 252, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_2", "long_name": "check_1d_stride_2( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 254, "end_line": 255, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_3", "long_name": "check_1d_stride_3( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 256, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_4", "long_name": "check_1d_stride_4( self )", "filename": "test_size_check.py", "nloc": 3, "complexity": 2, "token_count": 17, "parameters": [ "self" ], "start_line": 258, "end_line": 261, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_1d_stride_5", "long_name": "check_1d_stride_5( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 262, "end_line": 263, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_6", "long_name": "check_1d_stride_6( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 264, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_7", "long_name": "check_1d_stride_7( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 266, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_8", "long_name": "check_1d_stride_8( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 268, "end_line": 269, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_9", "long_name": "check_1d_stride_9( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 270, "end_line": 271, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_10", "long_name": "check_1d_stride_10( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 272, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_11", "long_name": "check_1d_stride_11( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 274, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_stride_12", "long_name": "check_1d_stride_12( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 276, "end_line": 277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_1d_random", "long_name": "check_1d_random( self )", "filename": "test_size_check.py", "nloc": 11, "complexity": 3, "token_count": 87, "parameters": [ "self" ], "start_line": 278, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_2d_0", "long_name": "check_2d_0( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 292, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_2d_1", "long_name": "check_2d_1( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 294, "end_line": 295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_2d_2", "long_name": "check_2d_2( self )", "filename": "test_size_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 296, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_2d_random", "long_name": "check_2d_random( self )", "filename": "test_size_check.py", "nloc": 15, "complexity": 3, "token_count": 120, "parameters": [ "self" ], "start_line": 298, "end_line": 314, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "check_3d_random", "long_name": "check_3d_random( self )", "filename": "test_size_check.py", "nloc": 12, "complexity": 4, "token_count": 86, "parameters": [ "self" ], "start_line": 315, "end_line": 328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "check_1d_0", "long_name": "check_1d_0( self )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 47, "parameters": [ "self" ], "start_line": 331, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2d_0", "long_name": "check_2d_0( self )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 50, "parameters": [ "self" ], "start_line": 336, "end_line": 340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2d_1", "long_name": "check_2d_1( self )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 50, "parameters": [ "self" ], "start_line": 341, "end_line": 345, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_3d_0", "long_name": "check_3d_0( self )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 53, "parameters": [ "self" ], "start_line": 346, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_error0", "long_name": "check_error0( self )", "filename": "test_size_check.py", "nloc": 6, "complexity": 2, "token_count": 31, "parameters": [ "self" ], "start_line": 351, "end_line": 356, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_error1", "long_name": "check_error1( self )", "filename": "test_size_check.py", "nloc": 6, "complexity": 2, "token_count": 30, "parameters": [ "self" ], "start_line": 357, "end_line": 362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "array_assert_equal", "long_name": "array_assert_equal( self , test_string , actual , desired )", "filename": "test_size_check.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "test_string", "actual", "desired" ], "start_line": 365, "end_line": 379, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "generic_test", "long_name": "generic_test( self , expr , desired , ** kw )", "filename": "test_size_check.py", "nloc": 20, "complexity": 6, "token_count": 117, "parameters": [ "self", "expr", "desired", "kw" ], "start_line": 380, "end_line": 399, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "generic_wrap", "long_name": "generic_wrap( self , expr , ** kw )", "filename": "test_size_check.py", "nloc": 10, "complexity": 3, "token_count": 55, "parameters": [ "self", "expr", "kw" ], "start_line": 400, "end_line": 409, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_generic_1d", "long_name": "check_generic_1d( self )", "filename": "test_size_check.py", "nloc": 14, "complexity": 1, "token_count": 100, "parameters": [ "self" ], "start_line": 410, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "check_single_index", "long_name": "check_single_index( self )", "filename": "test_size_check.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 424, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_calculated_index", "long_name": "check_calculated_index( self )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "self" ], "start_line": 429, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_calculated_index2", "long_name": "check_calculated_index2( self )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "self" ], "start_line": 434, "end_line": 438, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "generic_2d", "long_name": "generic_2d( self , expr )", "filename": "test_size_check.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "expr" ], "start_line": 439, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "generic_3d", "long_name": "generic_3d( self , expr )", "filename": "test_size_check.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "self", "expr" ], "start_line": 442, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_size_check.py", "nloc": 11, "complexity": 2, "token_count": 104, "parameters": [ "level" ], "start_line": 446, "end_line": 456, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 458, "end_line": 462, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "array_assert_equal", "long_name": "array_assert_equal( test_string , actual , desired )", "filename": "test_size_check.py", "nloc": 17, "complexity": 3, "token_count": 120, "parameters": [ "test_string", "actual", "desired" ], "start_line": 18, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "array_assert_equal", "long_name": "array_assert_equal( self , test_string , actual , desired )", "filename": "test_size_check.py", "nloc": 13, "complexity": 2, "token_count": 76, "parameters": [ "self", "test_string", "actual", "desired" ], "start_line": 130, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 } ], "nloc": 421, "complexity": 117, "token_count": 3159, "diff_parsed": { "added": [ " \"\"\"this should probably be in scipy_test.testing", " \"\"\"this should probably be in scipy_test.testing", " \"\"\"this should probably be in scipy_test.testing", " \"\"\"this should probably be in scipy_test.testing" ], "deleted": [ " \"\"\"this should probably be in scipy_base.testing", " \"\"\"this should probably be in scipy_base.testing", " \"\"\"this should probably be in scipy_base.testing", " \"\"\"this should probably be in scipy_base.testing" ] } }, { "old_path": "weave/tests/test_slice_handler.py", "new_path": "weave/tests/test_slice_handler.py", "filename": "test_slice_handler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -10,7 +10,7 @@\n restore_path()\n \n def print_assert_equal(test_string,actual,desired):\n- \"\"\"this should probably be in scipy_base.testing\n+ \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n import pprint\n try:\n", "added_lines": 1, "deleted_lines": 1, "source_code": "import unittest\n# Was getting a weird \"no module named slice_handler error with this.\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport slice_handler\nfrom slice_handler import indexed_array_pattern\nfrom ast_tools import *\nrestore_path()\n\ndef print_assert_equal(test_string,actual,desired):\n \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n import pprint\n try:\n assert(actual == desired)\n except AssertionError:\n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n\nclass test_build_slice_atom(unittest.TestCase):\n def generic_test(self,slice_vars,desired):\n pos = slice_vars['pos']\n ast_list = slice_handler.build_slice_atom(slice_vars,pos)\n actual = ast_to_string(ast_list)\n print_assert_equal('',actual,desired)\n def check_exclusive_end(self):\n slice_vars = {'begin':'1', 'end':'2', 'step':'_stp',\n 'single_index':'_index','pos':0}\n desired = 'slice(1,2-1)'\n self.generic_test(slice_vars,desired)\n \nclass test_slice(unittest.TestCase):\n\n def generic_test(self,suite_string,desired):\n import parser\n ast_tuple = parser.suite(suite_string).totuple()\n found, data = find_first_pattern(ast_tuple,indexed_array_pattern)\n subscript = data['subscript_list'][1] #[0] is symbol, [1] is the supscript\n actual = slice_handler.slice_ast_to_dict(subscript)\n print_assert_equal(suite_string,actual,desired)\n\n def check_empty_2_slice(self):\n \"\"\"match slice from a[:]\"\"\"\n test =\"a[:]\"\n desired = {'begin':'_beg', 'end':'_end', 'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_begin_2_slice(self):\n \"\"\"match slice from a[1:]\"\"\"\n test =\"a[1:]\"\n desired = {'begin':'1', 'end':'_end', 'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_end_2_slice(self):\n \"\"\"match slice from a[:2]\"\"\"\n test =\"a[:2]\"\n desired = {'begin':'_beg', 'end':'2', 'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_begin_end_2_slice(self):\n \"\"\"match slice from a[1:2]\"\"\"\n test =\"a[1:2]\"\n desired = {'begin':'1', 'end':'2', 'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_empty_3_slice(self):\n \"\"\"match slice from a[::]\"\"\"\n test =\"a[::]\"\n desired = {'begin':'_beg', 'end':'_end', 'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_begin_3_slice(self):\n \"\"\"match slice from a[1::]\"\"\"\n test =\"a[1::]\"\n desired = {'begin':'1', 'end':'_end', 'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_end_3_slice(self):\n \"\"\"match slice from a[:2:]\"\"\"\n test =\"a[:2:]\"\n desired = {'begin':'_beg', 'end':'2', 'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_stp3_slice(self):\n \"\"\"match slice from a[::3]\"\"\"\n test =\"a[::3]\"\n desired = {'begin':'_beg', 'end':'_end', 'step':'3',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_begin_end_3_slice(self):\n \"\"\"match slice from a[1:2:]\"\"\"\n test =\"a[1:2:]\"\n desired = {'begin':'1', 'end':'2','step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_begin_step_3_slice(self):\n \"\"\"match slice from a[1::3]\"\"\"\n test =\"a[1::3]\"\n desired = {'begin':'1', 'end':'_end','step':'3',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_end_step_3_slice(self):\n \"\"\"match slice from a[:2:3]\"\"\"\n test =\"a[:2:3]\"\n desired = {'begin':'_beg', 'end':'2', 'step':'3',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_begin_end_stp3_slice(self):\n \"\"\"match slice from a[1:2:3]\"\"\"\n test =\"a[1:2:3]\"\n desired = {'begin':'1', 'end':'2', 'step':'3','single_index':'_index'}\n self.generic_test(test,desired)\n def check_expr_3_slice(self):\n \"\"\"match slice from a[:1+i+2:]\"\"\"\n test =\"a[:1+i+2:]\"\n desired = {'begin':'_beg', 'end':\"1+i+2\",'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_single_index(self):\n \"\"\"match slice from a[0]\"\"\"\n test =\"a[0]\"\n desired = {'begin':'_beg', 'end':\"_end\",'step':'_stp',\n 'single_index':'0'}\n self.generic_test(test,desired)\n\ndef replace_whitespace(in_str):\n import string\n out = string.replace(in_str,\" \",\"\")\n out = string.replace(out,\"\\t\",\"\")\n out = string.replace(out,\"\\n\",\"\")\n return out\n \nclass test_transform_slices(unittest.TestCase):\n def generic_test(self,suite_string,desired):\n import parser\n ast_list = parser.suite(suite_string).tolist()\n slice_handler.transform_slices(ast_list)\n actual = ast_to_string(ast_list)\n # Remove white space from expressions so that equivelant \n # but differently formatted string will compare equally\n import string\n actual = replace_whitespace(actual)\n desired = replace_whitespace(desired)\n print_assert_equal(suite_string,actual,desired)\n\n def check_simple_expr(self):\n \"\"\"transform a[:] to slice notation\"\"\"\n test =\"a[:]\"\n desired = 'a[slice(_beg,_end,_stp)]'\n self.generic_test(test,desired)\n def check_simple_expr(self):\n \"\"\"transform a[:,:] = b[:,1:1+2:3] *(c[1-2+i:,:] - c[:,:])\"\"\"\n test =\"a[:,:] = b[:,1:1+2:3] *(c[1-2+i:,:] - c[:,:])\"\n desired = \" a[slice(_beg,_end),slice(_beg,_end)] = \"\\\n \" b[slice(_beg,_end), slice(1,1+2-1,3)] *\"\\\n \" (c[slice(1-2+i,_end), slice(_beg,_end)] -\"\\\n \" c[slice(_beg,_end), slice(_beg,_end)])\"\n self.generic_test(test,desired)\n\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_slice,'check_') )\n suites.append( unittest.makeSuite(test_transform_slices,'check_') )\n suites.append( unittest.makeSuite(test_build_slice_atom,'check_') )\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()", "source_code_before": "import unittest\n# Was getting a weird \"no module named slice_handler error with this.\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport slice_handler\nfrom slice_handler import indexed_array_pattern\nfrom ast_tools import *\nrestore_path()\n\ndef print_assert_equal(test_string,actual,desired):\n \"\"\"this should probably be in scipy_base.testing\n \"\"\"\n import pprint\n try:\n assert(actual == desired)\n except AssertionError:\n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n\nclass test_build_slice_atom(unittest.TestCase):\n def generic_test(self,slice_vars,desired):\n pos = slice_vars['pos']\n ast_list = slice_handler.build_slice_atom(slice_vars,pos)\n actual = ast_to_string(ast_list)\n print_assert_equal('',actual,desired)\n def check_exclusive_end(self):\n slice_vars = {'begin':'1', 'end':'2', 'step':'_stp',\n 'single_index':'_index','pos':0}\n desired = 'slice(1,2-1)'\n self.generic_test(slice_vars,desired)\n \nclass test_slice(unittest.TestCase):\n\n def generic_test(self,suite_string,desired):\n import parser\n ast_tuple = parser.suite(suite_string).totuple()\n found, data = find_first_pattern(ast_tuple,indexed_array_pattern)\n subscript = data['subscript_list'][1] #[0] is symbol, [1] is the supscript\n actual = slice_handler.slice_ast_to_dict(subscript)\n print_assert_equal(suite_string,actual,desired)\n\n def check_empty_2_slice(self):\n \"\"\"match slice from a[:]\"\"\"\n test =\"a[:]\"\n desired = {'begin':'_beg', 'end':'_end', 'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_begin_2_slice(self):\n \"\"\"match slice from a[1:]\"\"\"\n test =\"a[1:]\"\n desired = {'begin':'1', 'end':'_end', 'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_end_2_slice(self):\n \"\"\"match slice from a[:2]\"\"\"\n test =\"a[:2]\"\n desired = {'begin':'_beg', 'end':'2', 'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_begin_end_2_slice(self):\n \"\"\"match slice from a[1:2]\"\"\"\n test =\"a[1:2]\"\n desired = {'begin':'1', 'end':'2', 'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_empty_3_slice(self):\n \"\"\"match slice from a[::]\"\"\"\n test =\"a[::]\"\n desired = {'begin':'_beg', 'end':'_end', 'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_begin_3_slice(self):\n \"\"\"match slice from a[1::]\"\"\"\n test =\"a[1::]\"\n desired = {'begin':'1', 'end':'_end', 'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_end_3_slice(self):\n \"\"\"match slice from a[:2:]\"\"\"\n test =\"a[:2:]\"\n desired = {'begin':'_beg', 'end':'2', 'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_stp3_slice(self):\n \"\"\"match slice from a[::3]\"\"\"\n test =\"a[::3]\"\n desired = {'begin':'_beg', 'end':'_end', 'step':'3',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_begin_end_3_slice(self):\n \"\"\"match slice from a[1:2:]\"\"\"\n test =\"a[1:2:]\"\n desired = {'begin':'1', 'end':'2','step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_begin_step_3_slice(self):\n \"\"\"match slice from a[1::3]\"\"\"\n test =\"a[1::3]\"\n desired = {'begin':'1', 'end':'_end','step':'3',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_end_step_3_slice(self):\n \"\"\"match slice from a[:2:3]\"\"\"\n test =\"a[:2:3]\"\n desired = {'begin':'_beg', 'end':'2', 'step':'3',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_begin_end_stp3_slice(self):\n \"\"\"match slice from a[1:2:3]\"\"\"\n test =\"a[1:2:3]\"\n desired = {'begin':'1', 'end':'2', 'step':'3','single_index':'_index'}\n self.generic_test(test,desired)\n def check_expr_3_slice(self):\n \"\"\"match slice from a[:1+i+2:]\"\"\"\n test =\"a[:1+i+2:]\"\n desired = {'begin':'_beg', 'end':\"1+i+2\",'step':'_stp',\n 'single_index':'_index'}\n self.generic_test(test,desired)\n def check_single_index(self):\n \"\"\"match slice from a[0]\"\"\"\n test =\"a[0]\"\n desired = {'begin':'_beg', 'end':\"_end\",'step':'_stp',\n 'single_index':'0'}\n self.generic_test(test,desired)\n\ndef replace_whitespace(in_str):\n import string\n out = string.replace(in_str,\" \",\"\")\n out = string.replace(out,\"\\t\",\"\")\n out = string.replace(out,\"\\n\",\"\")\n return out\n \nclass test_transform_slices(unittest.TestCase):\n def generic_test(self,suite_string,desired):\n import parser\n ast_list = parser.suite(suite_string).tolist()\n slice_handler.transform_slices(ast_list)\n actual = ast_to_string(ast_list)\n # Remove white space from expressions so that equivelant \n # but differently formatted string will compare equally\n import string\n actual = replace_whitespace(actual)\n desired = replace_whitespace(desired)\n print_assert_equal(suite_string,actual,desired)\n\n def check_simple_expr(self):\n \"\"\"transform a[:] to slice notation\"\"\"\n test =\"a[:]\"\n desired = 'a[slice(_beg,_end,_stp)]'\n self.generic_test(test,desired)\n def check_simple_expr(self):\n \"\"\"transform a[:,:] = b[:,1:1+2:3] *(c[1-2+i:,:] - c[:,:])\"\"\"\n test =\"a[:,:] = b[:,1:1+2:3] *(c[1-2+i:,:] - c[:,:])\"\n desired = \" a[slice(_beg,_end),slice(_beg,_end)] = \"\\\n \" b[slice(_beg,_end), slice(1,1+2-1,3)] *\"\\\n \" (c[slice(1-2+i,_end), slice(_beg,_end)] -\"\\\n \" c[slice(_beg,_end), slice(_beg,_end)])\"\n self.generic_test(test,desired)\n\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_slice,'check_') )\n suites.append( unittest.makeSuite(test_transform_slices,'check_') )\n suites.append( unittest.makeSuite(test_build_slice_atom,'check_') )\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()", "methods": [ { "name": "print_assert_equal", "long_name": "print_assert_equal( test_string , actual , desired )", "filename": "test_slice_handler.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 12, "end_line": 26, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "generic_test", "long_name": "generic_test( self , slice_vars , desired )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "slice_vars", "desired" ], "start_line": 29, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_exclusive_end", "long_name": "check_exclusive_end( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self" ], "start_line": 34, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "generic_test", "long_name": "generic_test( self , suite_string , desired )", "filename": "test_slice_handler.py", "nloc": 7, "complexity": 1, "token_count": 58, "parameters": [ "self", "suite_string", "desired" ], "start_line": 42, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_empty_2_slice", "long_name": "check_empty_2_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 50, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_begin_2_slice", "long_name": "check_begin_2_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 56, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_end_2_slice", "long_name": "check_end_2_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 62, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_begin_end_2_slice", "long_name": "check_begin_end_2_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 68, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_empty_3_slice", "long_name": "check_empty_3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 74, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_begin_3_slice", "long_name": "check_begin_3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 80, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_end_3_slice", "long_name": "check_end_3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 86, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_stp3_slice", "long_name": "check_stp3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 92, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_begin_end_3_slice", "long_name": "check_begin_end_3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 98, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_begin_step_3_slice", "long_name": "check_begin_step_3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 104, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_end_step_3_slice", "long_name": "check_end_step_3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 110, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_begin_end_stp3_slice", "long_name": "check_begin_end_stp3_slice( self )", "filename": "test_slice_handler.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 116, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_expr_3_slice", "long_name": "check_expr_3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 121, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_single_index", "long_name": "check_single_index( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 127, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "replace_whitespace", "long_name": "replace_whitespace( in_str )", "filename": "test_slice_handler.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "in_str" ], "start_line": 134, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "generic_test", "long_name": "generic_test( self , suite_string , desired )", "filename": "test_slice_handler.py", "nloc": 9, "complexity": 1, "token_count": 57, "parameters": [ "self", "suite_string", "desired" ], "start_line": 142, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_simple_expr", "long_name": "check_simple_expr( self )", "filename": "test_slice_handler.py", "nloc": 4, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 154, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_simple_expr", "long_name": "check_simple_expr( self )", "filename": "test_slice_handler.py", "nloc": 7, "complexity": 1, "token_count": 26, "parameters": [ "self" ], "start_line": 159, "end_line": 166, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_slice_handler.py", "nloc": 8, "complexity": 2, "token_count": 65, "parameters": [ "level" ], "start_line": 169, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 178, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "print_assert_equal", "long_name": "print_assert_equal( test_string , actual , desired )", "filename": "test_slice_handler.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 12, "end_line": 26, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "generic_test", "long_name": "generic_test( self , slice_vars , desired )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "slice_vars", "desired" ], "start_line": 29, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_exclusive_end", "long_name": "check_exclusive_end( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self" ], "start_line": 34, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "generic_test", "long_name": "generic_test( self , suite_string , desired )", "filename": "test_slice_handler.py", "nloc": 7, "complexity": 1, "token_count": 58, "parameters": [ "self", "suite_string", "desired" ], "start_line": 42, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_empty_2_slice", "long_name": "check_empty_2_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 50, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_begin_2_slice", "long_name": "check_begin_2_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 56, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_end_2_slice", "long_name": "check_end_2_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 62, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_begin_end_2_slice", "long_name": "check_begin_end_2_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 68, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_empty_3_slice", "long_name": "check_empty_3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 74, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_begin_3_slice", "long_name": "check_begin_3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 80, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_end_3_slice", "long_name": "check_end_3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 86, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_stp3_slice", "long_name": "check_stp3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 92, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_begin_end_3_slice", "long_name": "check_begin_end_3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 98, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_begin_step_3_slice", "long_name": "check_begin_step_3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 104, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_end_step_3_slice", "long_name": "check_end_step_3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 110, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_begin_end_stp3_slice", "long_name": "check_begin_end_stp3_slice( self )", "filename": "test_slice_handler.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 116, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_expr_3_slice", "long_name": "check_expr_3_slice( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 121, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_single_index", "long_name": "check_single_index( self )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 127, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "replace_whitespace", "long_name": "replace_whitespace( in_str )", "filename": "test_slice_handler.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "in_str" ], "start_line": 134, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "generic_test", "long_name": "generic_test( self , suite_string , desired )", "filename": "test_slice_handler.py", "nloc": 9, "complexity": 1, "token_count": 57, "parameters": [ "self", "suite_string", "desired" ], "start_line": 142, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_simple_expr", "long_name": "check_simple_expr( self )", "filename": "test_slice_handler.py", "nloc": 4, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 154, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_simple_expr", "long_name": "check_simple_expr( self )", "filename": "test_slice_handler.py", "nloc": 7, "complexity": 1, "token_count": 26, "parameters": [ "self" ], "start_line": 159, "end_line": 166, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_slice_handler.py", "nloc": 8, "complexity": 2, "token_count": 65, "parameters": [ "level" ], "start_line": 169, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 178, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "print_assert_equal", "long_name": "print_assert_equal( test_string , actual , desired )", "filename": "test_slice_handler.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 12, "end_line": 26, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 } ], "nloc": 150, "complexity": 26, "token_count": 1038, "diff_parsed": { "added": [ " \"\"\"this should probably be in scipy_test.testing" ], "deleted": [ " \"\"\"this should probably be in scipy_base.testing" ] } }, { "old_path": "weave/tests/test_standard_array_spec.py", "new_path": "weave/tests/test_standard_array_spec.py", "filename": "test_standard_array_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -22,7 +22,7 @@ def remove_whitespace(in_str):\n return out\n \n def print_assert_equal(test_string,actual,desired):\n- \"\"\"this should probably be in scipy_base.testing\n+ \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n import pprint\n try:\n", "added_lines": 1, "deleted_lines": 1, "source_code": "import unittest\nfrom Numeric import *\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from scipy_base.fastumath import *\nexcept:\n pass # scipy_base.fastumath not available \nimport RandomArray\nimport time\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport standard_array_spec\nrestore_path()\n\ndef remove_whitespace(in_str):\n import string\n out = string.replace(in_str,\" \",\"\")\n out = string.replace(out,\"\\t\",\"\")\n out = string.replace(out,\"\\n\",\"\")\n return out\n \ndef print_assert_equal(test_string,actual,desired):\n \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n import pprint\n try:\n assert(actual == desired)\n except AssertionError:\n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n\nclass test_array_converter(unittest.TestCase): \n def check_type_match_string(self):\n s = standard_array_spec.array_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = standard_array_spec.array_converter() \n assert(not s.type_match(5))\n def check_type_match_array(self):\n s = standard_array_spec.array_converter() \n assert(s.type_match(arange(4)))\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_array_converter,'check_'))\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "source_code_before": "import unittest\nfrom Numeric import *\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from scipy_base.fastumath import *\nexcept:\n pass # scipy_base.fastumath not available \nimport RandomArray\nimport time\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport standard_array_spec\nrestore_path()\n\ndef remove_whitespace(in_str):\n import string\n out = string.replace(in_str,\" \",\"\")\n out = string.replace(out,\"\\t\",\"\")\n out = string.replace(out,\"\\n\",\"\")\n return out\n \ndef print_assert_equal(test_string,actual,desired):\n \"\"\"this should probably be in scipy_base.testing\n \"\"\"\n import pprint\n try:\n assert(actual == desired)\n except AssertionError:\n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n\nclass test_array_converter(unittest.TestCase): \n def check_type_match_string(self):\n s = standard_array_spec.array_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = standard_array_spec.array_converter() \n assert(not s.type_match(5))\n def check_type_match_array(self):\n s = standard_array_spec.array_converter() \n assert(s.type_match(arange(4)))\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_array_converter,'check_'))\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "remove_whitespace", "long_name": "remove_whitespace( in_str )", "filename": "test_standard_array_spec.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "in_str" ], "start_line": 17, "end_line": 22, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "print_assert_equal", "long_name": "print_assert_equal( test_string , actual , desired )", "filename": "test_standard_array_spec.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 24, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 41, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 44, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_array", "long_name": "check_type_match_array( self )", "filename": "test_standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 47, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_standard_array_spec.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "level" ], "start_line": 51, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 59, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "remove_whitespace", "long_name": "remove_whitespace( in_str )", "filename": "test_standard_array_spec.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "in_str" ], "start_line": 17, "end_line": 22, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "print_assert_equal", "long_name": "print_assert_equal( test_string , actual , desired )", "filename": "test_standard_array_spec.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 24, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 41, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 44, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_array", "long_name": "check_type_match_array( self )", "filename": "test_standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 47, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_standard_array_spec.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "level" ], "start_line": 51, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 59, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "print_assert_equal", "long_name": "print_assert_equal( test_string , actual , desired )", "filename": "test_standard_array_spec.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 24, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 } ], "nloc": 54, "complexity": 9, "token_count": 315, "diff_parsed": { "added": [ " \"\"\"this should probably be in scipy_test.testing" ], "deleted": [ " \"\"\"this should probably be in scipy_base.testing" ] } }, { "old_path": "weave/tests/weave_test_utils.py", "new_path": "weave/tests/weave_test_utils.py", "filename": "weave_test_utils.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -9,7 +9,7 @@ def remove_whitespace(in_str):\n return out\n \n def print_assert_equal(test_string,actual,desired):\n- \"\"\"this should probably be in scipy_base.testing\n+ \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n try:\n assert(actual == desired)\n", "added_lines": 1, "deleted_lines": 1, "source_code": "import os,sys,string\nimport pprint \n\ndef remove_whitespace(in_str):\n import string\n out = string.replace(in_str,\" \",\"\")\n out = string.replace(out,\"\\t\",\"\")\n out = string.replace(out,\"\\n\",\"\")\n return out\n \ndef print_assert_equal(test_string,actual,desired):\n \"\"\"this should probably be in scipy_test.testing\n \"\"\"\n try:\n assert(actual == desired)\n except AssertionError:\n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n\n###################################################\n# mainly used by catalog tests \n###################################################\nfrom scipy_distutils.misc_util import add_grandparent_to_path,restore_path\n\nadd_grandparent_to_path(__name__)\nimport catalog\nrestore_path()\n\nimport glob\n\ndef temp_catalog_files(prefix=''):\n # might need to add some more platform specific catalog file\n # suffixes to remove. The .pag was recently added for SunOS\n d = catalog.default_dir()\n f = catalog.os_dependent_catalog_name()\n return glob.glob(os.path.join(d,prefix+f+'*'))\n\nimport tempfile\n\ndef clear_temp_catalog():\n \"\"\" Remove any catalog from the temp dir\n \"\"\"\n global backup_dir \n backup_dir =tempfile.mktemp()\n os.mkdir(backup_dir)\n for file in temp_catalog_files():\n move_file(file,backup_dir)\n #d,f = os.path.split(file)\n #backup = os.path.join(backup_dir,f)\n #os.rename(file,backup)\n\ndef restore_temp_catalog():\n \"\"\" Remove any catalog from the temp dir\n \"\"\"\n global backup_dir\n cat_dir = catalog.default_dir()\n for file in os.listdir(backup_dir):\n file = os.path.join(backup_dir,file)\n d,f = os.path.split(file)\n dst_file = os.path.join(cat_dir, f)\n if os.path.exists(dst_file):\n os.remove(dst_file)\n #os.rename(file,dst_file)\n move_file(file,dst_file)\n os.rmdir(backup_dir)\n backup_dir = None\n \ndef empty_temp_dir():\n \"\"\" Create a sub directory in the temp directory for use in tests\n \"\"\"\n import tempfile\n d = catalog.default_dir()\n for i in range(10000):\n new_d = os.path.join(d,tempfile.gettempprefix()[1:-1]+`i`)\n if not os.path.exists(new_d):\n os.mkdir(new_d)\n break\n return new_d\n\ndef cleanup_temp_dir(d):\n \"\"\" Remove a directory created by empty_temp_dir\n should probably catch errors\n \"\"\"\n files = map(lambda x,d=d: os.path.join(d,x),os.listdir(d))\n for i in files:\n try:\n if os.path.isdir(i):\n cleanup_temp_dir(i)\n else:\n os.remove(i)\n except OSError:\n pass # failed to remove file for whatever reason \n # (maybe it is a DLL Python is currently using) \n try:\n os.rmdir(d)\n except OSError:\n pass \n \n\n# from distutils -- old versions had bug, so copying here to make sure \n# a working version is available.\nfrom distutils.errors import DistutilsFileError\nimport distutils.file_util\ndef move_file (src, dst,\n verbose=0,\n dry_run=0):\n\n \"\"\"Move a file 'src' to 'dst'. If 'dst' is a directory, the file will\n be moved into it with the same name; otherwise, 'src' is just renamed\n to 'dst'. Return the new full name of the file.\n\n Handles cross-device moves on Unix using 'copy_file()'. What about\n other systems???\n \"\"\"\n from os.path import exists, isfile, isdir, basename, dirname\n import errno\n\n if verbose:\n print \"moving %s -> %s\" % (src, dst)\n\n if dry_run:\n return dst\n\n if not isfile(src):\n raise DistutilsFileError, \\\n \"can't move '%s': not a regular file\" % src\n\n if isdir(dst):\n dst = os.path.join(dst, basename(src))\n elif exists(dst):\n raise DistutilsFileError, \\\n \"can't move '%s': destination '%s' already exists\" % \\\n (src, dst)\n\n if not isdir(dirname(dst)):\n raise DistutilsFileError, \\\n \"can't move '%s': destination '%s' not a valid path\" % \\\n (src, dst)\n\n copy_it = 0\n try:\n os.rename(src, dst)\n except os.error, (num, msg):\n if num == errno.EXDEV:\n copy_it = 1\n else:\n raise DistutilsFileError, \\\n \"couldn't move '%s' to '%s': %s\" % (src, dst, msg)\n\n if copy_it:\n distutils.file_util.copy_file(src, dst)\n try:\n os.unlink(src)\n except os.error, (num, msg):\n try:\n os.unlink(dst)\n except os.error:\n pass\n raise DistutilsFileError, \\\n (\"couldn't move '%s' to '%s' by copy/delete: \" +\n \"delete '%s' failed: %s\") % \\\n (src, dst, src, msg)\n\n return dst\n\n ", "source_code_before": "import os,sys,string\nimport pprint \n\ndef remove_whitespace(in_str):\n import string\n out = string.replace(in_str,\" \",\"\")\n out = string.replace(out,\"\\t\",\"\")\n out = string.replace(out,\"\\n\",\"\")\n return out\n \ndef print_assert_equal(test_string,actual,desired):\n \"\"\"this should probably be in scipy_base.testing\n \"\"\"\n try:\n assert(actual == desired)\n except AssertionError:\n import cStringIO\n msg = cStringIO.StringIO()\n msg.write(test_string)\n msg.write(' failed\\nACTUAL: \\n')\n pprint.pprint(actual,msg)\n msg.write('DESIRED: \\n')\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n\n###################################################\n# mainly used by catalog tests \n###################################################\nfrom scipy_distutils.misc_util import add_grandparent_to_path,restore_path\n\nadd_grandparent_to_path(__name__)\nimport catalog\nrestore_path()\n\nimport glob\n\ndef temp_catalog_files(prefix=''):\n # might need to add some more platform specific catalog file\n # suffixes to remove. The .pag was recently added for SunOS\n d = catalog.default_dir()\n f = catalog.os_dependent_catalog_name()\n return glob.glob(os.path.join(d,prefix+f+'*'))\n\nimport tempfile\n\ndef clear_temp_catalog():\n \"\"\" Remove any catalog from the temp dir\n \"\"\"\n global backup_dir \n backup_dir =tempfile.mktemp()\n os.mkdir(backup_dir)\n for file in temp_catalog_files():\n move_file(file,backup_dir)\n #d,f = os.path.split(file)\n #backup = os.path.join(backup_dir,f)\n #os.rename(file,backup)\n\ndef restore_temp_catalog():\n \"\"\" Remove any catalog from the temp dir\n \"\"\"\n global backup_dir\n cat_dir = catalog.default_dir()\n for file in os.listdir(backup_dir):\n file = os.path.join(backup_dir,file)\n d,f = os.path.split(file)\n dst_file = os.path.join(cat_dir, f)\n if os.path.exists(dst_file):\n os.remove(dst_file)\n #os.rename(file,dst_file)\n move_file(file,dst_file)\n os.rmdir(backup_dir)\n backup_dir = None\n \ndef empty_temp_dir():\n \"\"\" Create a sub directory in the temp directory for use in tests\n \"\"\"\n import tempfile\n d = catalog.default_dir()\n for i in range(10000):\n new_d = os.path.join(d,tempfile.gettempprefix()[1:-1]+`i`)\n if not os.path.exists(new_d):\n os.mkdir(new_d)\n break\n return new_d\n\ndef cleanup_temp_dir(d):\n \"\"\" Remove a directory created by empty_temp_dir\n should probably catch errors\n \"\"\"\n files = map(lambda x,d=d: os.path.join(d,x),os.listdir(d))\n for i in files:\n try:\n if os.path.isdir(i):\n cleanup_temp_dir(i)\n else:\n os.remove(i)\n except OSError:\n pass # failed to remove file for whatever reason \n # (maybe it is a DLL Python is currently using) \n try:\n os.rmdir(d)\n except OSError:\n pass \n \n\n# from distutils -- old versions had bug, so copying here to make sure \n# a working version is available.\nfrom distutils.errors import DistutilsFileError\nimport distutils.file_util\ndef move_file (src, dst,\n verbose=0,\n dry_run=0):\n\n \"\"\"Move a file 'src' to 'dst'. If 'dst' is a directory, the file will\n be moved into it with the same name; otherwise, 'src' is just renamed\n to 'dst'. Return the new full name of the file.\n\n Handles cross-device moves on Unix using 'copy_file()'. What about\n other systems???\n \"\"\"\n from os.path import exists, isfile, isdir, basename, dirname\n import errno\n\n if verbose:\n print \"moving %s -> %s\" % (src, dst)\n\n if dry_run:\n return dst\n\n if not isfile(src):\n raise DistutilsFileError, \\\n \"can't move '%s': not a regular file\" % src\n\n if isdir(dst):\n dst = os.path.join(dst, basename(src))\n elif exists(dst):\n raise DistutilsFileError, \\\n \"can't move '%s': destination '%s' already exists\" % \\\n (src, dst)\n\n if not isdir(dirname(dst)):\n raise DistutilsFileError, \\\n \"can't move '%s': destination '%s' not a valid path\" % \\\n (src, dst)\n\n copy_it = 0\n try:\n os.rename(src, dst)\n except os.error, (num, msg):\n if num == errno.EXDEV:\n copy_it = 1\n else:\n raise DistutilsFileError, \\\n \"couldn't move '%s' to '%s': %s\" % (src, dst, msg)\n\n if copy_it:\n distutils.file_util.copy_file(src, dst)\n try:\n os.unlink(src)\n except os.error, (num, msg):\n try:\n os.unlink(dst)\n except os.error:\n pass\n raise DistutilsFileError, \\\n (\"couldn't move '%s' to '%s' by copy/delete: \" +\n \"delete '%s' failed: %s\") % \\\n (src, dst, src, msg)\n\n return dst\n\n ", "methods": [ { "name": "remove_whitespace", "long_name": "remove_whitespace( in_str )", "filename": "weave_test_utils.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "in_str" ], "start_line": 4, "end_line": 9, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "print_assert_equal", "long_name": "print_assert_equal( test_string , actual , desired )", "filename": "weave_test_utils.py", "nloc": 12, "complexity": 2, "token_count": 72, "parameters": [ "test_string", "actual", "desired" ], "start_line": 11, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "temp_catalog_files", "long_name": "temp_catalog_files( prefix = '' )", "filename": "weave_test_utils.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [ "prefix" ], "start_line": 37, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "clear_temp_catalog", "long_name": "clear_temp_catalog( )", "filename": "weave_test_utils.py", "nloc": 6, "complexity": 2, "token_count": 33, "parameters": [], "start_line": 46, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "restore_temp_catalog", "long_name": "restore_temp_catalog( )", "filename": "weave_test_utils.py", "nloc": 12, "complexity": 3, "token_count": 91, "parameters": [], "start_line": 58, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "empty_temp_dir", "long_name": "empty_temp_dir( )", "filename": "weave_test_utils.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [], "start_line": 74, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "cleanup_temp_dir", "long_name": "cleanup_temp_dir( d )", "filename": "weave_test_utils.py", "nloc": 14, "complexity": 5, "token_count": 80, "parameters": [ "d" ], "start_line": 86, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "move_file", "long_name": "move_file( src , dst , verbose = 0 , dry_run = 0 )", "filename": "weave_test_utils.py", "nloc": 45, "complexity": 12, "token_count": 240, "parameters": [ "src", "dst", "verbose", "dry_run" ], "start_line": 110, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 0 } ], "methods_before": [ { "name": "remove_whitespace", "long_name": "remove_whitespace( in_str )", "filename": "weave_test_utils.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "in_str" ], "start_line": 4, "end_line": 9, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "print_assert_equal", "long_name": "print_assert_equal( test_string , actual , desired )", "filename": "weave_test_utils.py", "nloc": 12, "complexity": 2, "token_count": 72, "parameters": [ "test_string", "actual", "desired" ], "start_line": 11, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "temp_catalog_files", "long_name": "temp_catalog_files( prefix = '' )", "filename": "weave_test_utils.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [ "prefix" ], "start_line": 37, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "clear_temp_catalog", "long_name": "clear_temp_catalog( )", "filename": "weave_test_utils.py", "nloc": 6, "complexity": 2, "token_count": 33, "parameters": [], "start_line": 46, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "restore_temp_catalog", "long_name": "restore_temp_catalog( )", "filename": "weave_test_utils.py", "nloc": 12, "complexity": 3, "token_count": 91, "parameters": [], "start_line": 58, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "empty_temp_dir", "long_name": "empty_temp_dir( )", "filename": "weave_test_utils.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [], "start_line": 74, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "cleanup_temp_dir", "long_name": "cleanup_temp_dir( d )", "filename": "weave_test_utils.py", "nloc": 14, "complexity": 5, "token_count": 80, "parameters": [ "d" ], "start_line": 86, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "move_file", "long_name": "move_file( src , dst , verbose = 0 , dry_run = 0 )", "filename": "weave_test_utils.py", "nloc": 45, "complexity": 12, "token_count": 240, "parameters": [ "src", "dst", "verbose", "dry_run" ], "start_line": 110, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "print_assert_equal", "long_name": "print_assert_equal( test_string , actual , desired )", "filename": "weave_test_utils.py", "nloc": 12, "complexity": 2, "token_count": 72, "parameters": [ "test_string", "actual", "desired" ], "start_line": 11, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 } ], "nloc": 118, "complexity": 29, "token_count": 717, "diff_parsed": { "added": [ " \"\"\"this should probably be in scipy_test.testing" ], "deleted": [ " \"\"\"this should probably be in scipy_base.testing" ] } }, { "old_path": "weave/wx_spec.py", "new_path": "weave/wx_spec.py", "filename": "wx_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -106,10 +106,10 @@ def __cmp__(self,other):\n # this should only be enabled on machines with access to a display device\n # It'll cause problems otherwise.\n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \"\"\" \n\\ No newline at end of file\n", "added_lines": 2, "deleted_lines": 2, "source_code": "import common_info\nfrom c_spec import common_base_converter\n\nwx_dir = 'C:\\\\wx232\\\\include'\n\nwx_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic: \n %(c_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n %(c_type)s wx_ptr; \n // work on this error reporting...\n if (SWIG_GetPtrObj(py_obj,(void **) &wx_ptr,\"_%(type_name)s_p\"))\n handle_conversion_error(py_obj,\"%(type_name)s\", name);\n %(inc_ref_count)s\n return wx_ptr;\n }\n \n %(c_type)s py_to_%(type_name)s(PyObject* py_obj,const char* name)\n {\n %(c_type)s wx_ptr; \n // work on this error reporting...\n if (SWIG_GetPtrObj(py_obj,(void **) &wx_ptr,\"_%(type_name)s_p\"))\n handle_bad_type(py_obj,\"%(type_name)s\", name);\n %(inc_ref_count)s\n return wx_ptr;\n } \n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\nclass wx_converter(common_base_converter):\n def __init__(self,class_name=\"undefined\"):\n self.class_name = class_name\n common_base_converter.__init__(self)\n\n def init_info(self):\n common_base_converter.init_info(self)\n # These are generated on the fly instead of defined at \n # the class level.\n self.type_name = self.class_name\n self.c_type = self.class_name + \"*\"\n self.to_c_return = None # not used\n self.check_func = None # not used\n self.headers.extend(['\"wx/wx.h\"',''])\n self.include_dirs.append(wx_dir)\n self.define_macros.append(('wxUSE_GUI', '1'))\n self.library_dirs.append('c:\\wx232\\lib')\n self.libraries.append('gdi32')\n self.libraries.append('wxmsw232')\n self.support_code.append(common_info.swig_support_code)\n \n def type_match(self,value):\n is_match = 0\n try:\n wx_class = value.this.split('_')[-2]\n if wx_class[:2] == 'wx':\n is_match = 1\n except AttributeError:\n pass\n return is_match\n\n def generate_build_info(self):\n if self.class_name != \"undefined\":\n res = common_base_converter.generate_build_info(self)\n else:\n # if there isn't a class_name, we don't want the\n # we don't want the support_code to be included\n import base_info\n res = base_info.base_info()\n return res\n \n def py_to_c_code(self):\n return wx_to_c_template % self.template_vars()\n\n #def c_to_py_code(self):\n # return simple_c_to_py_template % self.template_vars()\n \n def type_spec(self,name,value):\n # factory\n class_name = value.this.split('_')[-2]\n new_spec = self.__class__(class_name)\n new_spec.name = name \n return new_spec\n\n def __cmp__(self,other):\n #only works for equal\n res = -1\n try:\n res = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__) or \\\n cmp(self.class_name, other.class_name) or \\\n cmp(self.type_name,other.type_name)\n except:\n pass\n return res\n\"\"\"\n# this should only be enabled on machines with access to a display device\n# It'll cause problems otherwise.\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\"\"\" ", "source_code_before": "import common_info\nfrom c_spec import common_base_converter\n\nwx_dir = 'C:\\\\wx232\\\\include'\n\nwx_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic: \n %(c_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n %(c_type)s wx_ptr; \n // work on this error reporting...\n if (SWIG_GetPtrObj(py_obj,(void **) &wx_ptr,\"_%(type_name)s_p\"))\n handle_conversion_error(py_obj,\"%(type_name)s\", name);\n %(inc_ref_count)s\n return wx_ptr;\n }\n \n %(c_type)s py_to_%(type_name)s(PyObject* py_obj,const char* name)\n {\n %(c_type)s wx_ptr; \n // work on this error reporting...\n if (SWIG_GetPtrObj(py_obj,(void **) &wx_ptr,\"_%(type_name)s_p\"))\n handle_bad_type(py_obj,\"%(type_name)s\", name);\n %(inc_ref_count)s\n return wx_ptr;\n } \n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\nclass wx_converter(common_base_converter):\n def __init__(self,class_name=\"undefined\"):\n self.class_name = class_name\n common_base_converter.__init__(self)\n\n def init_info(self):\n common_base_converter.init_info(self)\n # These are generated on the fly instead of defined at \n # the class level.\n self.type_name = self.class_name\n self.c_type = self.class_name + \"*\"\n self.to_c_return = None # not used\n self.check_func = None # not used\n self.headers.extend(['\"wx/wx.h\"',''])\n self.include_dirs.append(wx_dir)\n self.define_macros.append(('wxUSE_GUI', '1'))\n self.library_dirs.append('c:\\wx232\\lib')\n self.libraries.append('gdi32')\n self.libraries.append('wxmsw232')\n self.support_code.append(common_info.swig_support_code)\n \n def type_match(self,value):\n is_match = 0\n try:\n wx_class = value.this.split('_')[-2]\n if wx_class[:2] == 'wx':\n is_match = 1\n except AttributeError:\n pass\n return is_match\n\n def generate_build_info(self):\n if self.class_name != \"undefined\":\n res = common_base_converter.generate_build_info(self)\n else:\n # if there isn't a class_name, we don't want the\n # we don't want the support_code to be included\n import base_info\n res = base_info.base_info()\n return res\n \n def py_to_c_code(self):\n return wx_to_c_template % self.template_vars()\n\n #def c_to_py_code(self):\n # return simple_c_to_py_template % self.template_vars()\n \n def type_spec(self,name,value):\n # factory\n class_name = value.this.split('_')[-2]\n new_spec = self.__class__(class_name)\n new_spec.name = name \n return new_spec\n\n def __cmp__(self,other):\n #only works for equal\n res = -1\n try:\n res = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__) or \\\n cmp(self.class_name, other.class_name) or \\\n cmp(self.type_name,other.type_name)\n except:\n pass\n return res\n\"\"\"\n# this should only be enabled on machines with access to a display device\n# It'll cause problems otherwise.\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\"\"\" ", "methods": [ { "name": "__init__", "long_name": "__init__( self , class_name = \"undefined\" )", "filename": "wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self", "class_name" ], "start_line": 41, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "wx_spec.py", "nloc": 13, "complexity": 1, "token_count": 103, "parameters": [ "self" ], "start_line": 45, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "wx_spec.py", "nloc": 9, "complexity": 3, "token_count": 44, "parameters": [ "self", "value" ], "start_line": 61, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "wx_spec.py", "nloc": 7, "complexity": 2, "token_count": 33, "parameters": [ "self" ], "start_line": 71, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "wx_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 81, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "wx_spec.py", "nloc": 5, "complexity": 1, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 87, "end_line": 92, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "wx_spec.py", "nloc": 10, "complexity": 5, "token_count": 66, "parameters": [ "self", "other" ], "start_line": 94, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self , class_name = \"undefined\" )", "filename": "wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self", "class_name" ], "start_line": 41, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "wx_spec.py", "nloc": 13, "complexity": 1, "token_count": 103, "parameters": [ "self" ], "start_line": 45, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "wx_spec.py", "nloc": 9, "complexity": 3, "token_count": 44, "parameters": [ "self", "value" ], "start_line": 61, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "wx_spec.py", "nloc": 7, "complexity": 2, "token_count": 33, "parameters": [ "self" ], "start_line": 71, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "wx_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 81, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "wx_spec.py", "nloc": 5, "complexity": 1, "token_count": 38, "parameters": [ "self", "name", "value" ], "start_line": 87, "end_line": 92, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "wx_spec.py", "nloc": 10, "complexity": 5, "token_count": 66, "parameters": [ "self", "other" ], "start_line": 94, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 97, "complexity": 14, "token_count": 344, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } } ] }, { "hash": "819731acb7ab212c74a850239cc2188d51a4ed03", "msg": "changed testing module from scipy_base to scipy_test", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-09-18T06:55:07+00:00", "author_timezone": 0, "committer_date": "2002-09-18T06:55:07+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "e7e3556b1a532a82c363625265f444e21d1a5048" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 26, "insertions": 26, "lines": 52, "files": 13, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_base/__init__.py", "new_path": "scipy_base/__init__.py", "filename": "__init__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -123,12 +123,12 @@ def test(level=10):\n return runner\n \n def test_suite(level=1):\n- import scipy_base.testing\n+ import scipy_test.testing\n import scipy_base\n this_mod = scipy_base\n # testing is the module that actually does all the testing...\n ignore = ['testing']\n- return scipy_base.testing.harvest_test_suites(this_mod,ignore = ignore,\n+ return scipy_test.testing.harvest_test_suites(this_mod,ignore = ignore,\n level=level)\n \n \n", "added_lines": 2, "deleted_lines": 2, "source_code": "\"\"\"Basic functions used by several sub-packages and useful to have in the\nmain name-space\n\nType handling\n==============\niscomplexobj -- Test for complex object, scalar result\nisrealobj -- Test for real object, scalar result\niscomplex -- Test for complex elements, array result\nisreal -- Test for real elements, array result\nimag -- Imaginary part\nreal -- Real part\nreal_if_close -- Turns complex number with tiny imaginary part to real\nisneginf -- Tests for negative infinity ---|\nisposinf -- Tests for positive infinity |\nisnan -- Tests for nans |---- array results\nisinf -- Tests for infinity |\nisfinite -- Tests for finite numbers ---| \nisscalar -- True if argument is a scalar\nnan_to_num -- Replaces NaN's with 0 and infinities with large numbers\ntypename -- Return english name for given typecode character\ncast -- Dictionary of functions to force cast to each type\ncommon_type -- Determine the 'minimum common type code' for a group\n of arrays\n\nIndex tricks\n==================\nmgrid -- Method which allows easy construction of N-d 'mesh-grids'\nr_ -- Append and construct arrays -- turns slice objects into\n ranges and concatenates them, for 2d arrays appends\n rows.\nc_ -- Append and construct arrays -- for 2d arrays appends\n columns.\n\nindex_exp -- Konrad Hinsen's index_expression class instance which\n can be useful for building complicated slicing syntax.\n\nUseful functions\n==================\nselect -- Extension of where to multiple conditions and choices\nlinspace -- Evenly spaced samples in linear space\nlogspace -- Evenly spaced samples in logarithmic space\nfix -- Round x to nearest integer towards zero\nmod -- Modulo mod(x,y) = x % y except keeps sign of y\namax -- Array maximum along axis\namin -- Array minimum along axis\nptp -- Array max-min along axis\ncumsum -- Cumulative sum along axis\nprod -- Product of elements along axis\ncumprod -- Cumluative product along axis\ndiff -- Discrete differences along axis\nangle -- Returns angle of complex argument\nunwrap -- Unwrap phase along given axis (1-d algorithm)\nsort_complex -- Sort a complex-array (based on real, then imaginary)\ntrim_zeros -- trim the leading and trailing zeros from 1D array.\n\nShape manipulation\n===================\nsqueeze -- Return a with length-one dimensions removed.\natleast_1d -- Force arrays to be > 1D\natleast_2d -- Force arrays to be > 2D\natleast_3d -- Force arrays to be > 3D\nvstack -- Stack arrays vertically (row on row)\nhstack -- Stack arrays horizontally (column on column)\ncolumn_stack -- Stack 1D arrays as columns into 2D array\ndstack -- Stack arrays depthwise (along third dimension)\nsplit -- Divide array into a list of sub-arrays\nhsplit -- Split into columns\nvsplit -- Split into rows\ndsplit -- Split along third dimension\n\nMatrix (2d array) manipluations\n===============================\nfliplr -- 2D array with columns flipped\nflipud -- 2D array with rows flipped\nrot90 -- Rotate a 2D array a multiple of 90 degrees\neye -- Return a 2D array with ones down a given diagonal\ndiag -- Construct a 2D array from a vector, or return a given\n diagonal from a 2D array. \n\nPolynomials\n============\npoly1d -- A one-dimensional polynomial class\n\npoly -- Return polynomial coefficients from roots\nroots -- Find roots of polynomial given coefficients\npolyint -- Integrate polynomial\npolyder -- Differentiate polynomial\npolyadd -- Add polynomials\npolysub -- Substract polynomials\npolymul -- Multiply polynomials\npolydiv -- Divide polynomials\npolyval -- Evaluate polynomial at given argument\n\"\"\"\n\nimport Numeric\nfrom Numeric import *\nimport fastumath\nimport limits\n\nfrom type_check import *\nfrom index_tricks import *\nfrom function_base import *\nfrom shape_base import *\nfrom matrix_base import *\n\nfrom polynomial import *\nfrom scimath import *\n\n# needs scipy_base.fastumath\nInf = inf = fastumath.PINF\ntry:\n NAN = NaN = nan = fastumath.NAN\nexcept AttributeError:\n NaN = NAN = nan = fastumath.PINF - fastumath.PINF\n\n\n#---- testing ----#\n\ndef test(level=10):\n import unittest\n runner = unittest.TextTestRunner()\n runner.run(test_suite())\n return runner\n\ndef test_suite(level=1):\n import scipy_test.testing\n import scipy_base\n this_mod = scipy_base\n # testing is the module that actually does all the testing...\n ignore = ['testing']\n return scipy_test.testing.harvest_test_suites(this_mod,ignore = ignore,\n level=level)\n\n\n", "source_code_before": "\"\"\"Basic functions used by several sub-packages and useful to have in the\nmain name-space\n\nType handling\n==============\niscomplexobj -- Test for complex object, scalar result\nisrealobj -- Test for real object, scalar result\niscomplex -- Test for complex elements, array result\nisreal -- Test for real elements, array result\nimag -- Imaginary part\nreal -- Real part\nreal_if_close -- Turns complex number with tiny imaginary part to real\nisneginf -- Tests for negative infinity ---|\nisposinf -- Tests for positive infinity |\nisnan -- Tests for nans |---- array results\nisinf -- Tests for infinity |\nisfinite -- Tests for finite numbers ---| \nisscalar -- True if argument is a scalar\nnan_to_num -- Replaces NaN's with 0 and infinities with large numbers\ntypename -- Return english name for given typecode character\ncast -- Dictionary of functions to force cast to each type\ncommon_type -- Determine the 'minimum common type code' for a group\n of arrays\n\nIndex tricks\n==================\nmgrid -- Method which allows easy construction of N-d 'mesh-grids'\nr_ -- Append and construct arrays -- turns slice objects into\n ranges and concatenates them, for 2d arrays appends\n rows.\nc_ -- Append and construct arrays -- for 2d arrays appends\n columns.\n\nindex_exp -- Konrad Hinsen's index_expression class instance which\n can be useful for building complicated slicing syntax.\n\nUseful functions\n==================\nselect -- Extension of where to multiple conditions and choices\nlinspace -- Evenly spaced samples in linear space\nlogspace -- Evenly spaced samples in logarithmic space\nfix -- Round x to nearest integer towards zero\nmod -- Modulo mod(x,y) = x % y except keeps sign of y\namax -- Array maximum along axis\namin -- Array minimum along axis\nptp -- Array max-min along axis\ncumsum -- Cumulative sum along axis\nprod -- Product of elements along axis\ncumprod -- Cumluative product along axis\ndiff -- Discrete differences along axis\nangle -- Returns angle of complex argument\nunwrap -- Unwrap phase along given axis (1-d algorithm)\nsort_complex -- Sort a complex-array (based on real, then imaginary)\ntrim_zeros -- trim the leading and trailing zeros from 1D array.\n\nShape manipulation\n===================\nsqueeze -- Return a with length-one dimensions removed.\natleast_1d -- Force arrays to be > 1D\natleast_2d -- Force arrays to be > 2D\natleast_3d -- Force arrays to be > 3D\nvstack -- Stack arrays vertically (row on row)\nhstack -- Stack arrays horizontally (column on column)\ncolumn_stack -- Stack 1D arrays as columns into 2D array\ndstack -- Stack arrays depthwise (along third dimension)\nsplit -- Divide array into a list of sub-arrays\nhsplit -- Split into columns\nvsplit -- Split into rows\ndsplit -- Split along third dimension\n\nMatrix (2d array) manipluations\n===============================\nfliplr -- 2D array with columns flipped\nflipud -- 2D array with rows flipped\nrot90 -- Rotate a 2D array a multiple of 90 degrees\neye -- Return a 2D array with ones down a given diagonal\ndiag -- Construct a 2D array from a vector, or return a given\n diagonal from a 2D array. \n\nPolynomials\n============\npoly1d -- A one-dimensional polynomial class\n\npoly -- Return polynomial coefficients from roots\nroots -- Find roots of polynomial given coefficients\npolyint -- Integrate polynomial\npolyder -- Differentiate polynomial\npolyadd -- Add polynomials\npolysub -- Substract polynomials\npolymul -- Multiply polynomials\npolydiv -- Divide polynomials\npolyval -- Evaluate polynomial at given argument\n\"\"\"\n\nimport Numeric\nfrom Numeric import *\nimport fastumath\nimport limits\n\nfrom type_check import *\nfrom index_tricks import *\nfrom function_base import *\nfrom shape_base import *\nfrom matrix_base import *\n\nfrom polynomial import *\nfrom scimath import *\n\n# needs scipy_base.fastumath\nInf = inf = fastumath.PINF\ntry:\n NAN = NaN = nan = fastumath.NAN\nexcept AttributeError:\n NaN = NAN = nan = fastumath.PINF - fastumath.PINF\n\n\n#---- testing ----#\n\ndef test(level=10):\n import unittest\n runner = unittest.TextTestRunner()\n runner.run(test_suite())\n return runner\n\ndef test_suite(level=1):\n import scipy_base.testing\n import scipy_base\n this_mod = scipy_base\n # testing is the module that actually does all the testing...\n ignore = ['testing']\n return scipy_base.testing.harvest_test_suites(this_mod,ignore = ignore,\n level=level)\n\n\n", "methods": [ { "name": "test", "long_name": "test( level = 10 )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 26, "parameters": [ "level" ], "start_line": 119, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "__init__.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "level" ], "start_line": 125, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "methods_before": [ { "name": "test", "long_name": "test( level = 10 )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 26, "parameters": [ "level" ], "start_line": 119, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "__init__.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "level" ], "start_line": 125, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "__init__.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "level" ], "start_line": 125, "end_line": 132, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "nloc": 121, "complexity": 2, "token_count": 139, "diff_parsed": { "added": [ " import scipy_test.testing", " return scipy_test.testing.harvest_test_suites(this_mod,ignore = ignore," ], "deleted": [ " import scipy_base.testing", " return scipy_base.testing.harvest_test_suites(this_mod,ignore = ignore," ] } }, { "old_path": "scipy_base/function_base.py", "new_path": "scipy_base/function_base.py", "filename": "function_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -284,11 +284,11 @@ def disp(mesg, device=None, linefeed=1):\n #-----------------------------------------------------------------------------\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n if __name__ == '__main__':\n", "added_lines": 2, "deleted_lines": 2, "source_code": "import types\nimport Numeric\nN = Numeric\nfrom Numeric import *\nfrom scipy_base.fastumath import *\nimport _compiled_base\nfrom type_check import ScalarType, isscalar\n\n__all__ = ['round','any','all','logspace','linspace','fix','mod',\n 'select','trim_zeros','amax','amin','ptp','cumsum',\n 'prod','cumprod','diff','angle','unwrap','sort_complex',\n 'disp','unique']\n\nround = Numeric.around\nany = Numeric.sometrue\nall = Numeric.alltrue\n\n\ndef logspace(start,stop,num=50,endpoint=1):\n \"\"\" Evenly spaced samples on a logarithmic scale.\n\n Return num evenly spaced samples from 10**start to 10**stop. If\n endpoint=1 then last sample is 10**stop.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = Numeric.arange(0,num) * step + start\n else:\n step = (stop-start)/float(num)\n y = Numeric.arange(0,num) * step + start\n return Numeric.power(10.0,y)\n\ndef linspace(start,stop,num=50,endpoint=1,retstep=0):\n \"\"\" Evenly spaced samples.\n \n Return num evenly spaced samples from start to stop. If endpoint=1 then\n last sample is stop. If retstep is 1 then return the step value used.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = Numeric.arange(0,num) * step + start \n else:\n step = (stop-start)/float(num)\n y = Numeric.arange(0,num) * step + start\n if retstep:\n return y, step\n else:\n return y\n\ndef fix(x):\n \"\"\" Round x to nearest integer towards zero.\n \"\"\"\n x = Numeric.asarray(x)\n y = Numeric.floor(x)\n return Numeric.where(x<0,y+1,y)\n\ndef mod(x,y):\n \"\"\" x - y*floor(x/y)\n \n For numeric arrays, x % y has the same sign as x while\n mod(x,y) has the same sign as y.\n \"\"\"\n return x - y*Numeric.floor(x*1.0/y)\n\ndef select(condlist, choicelist, default=0):\n \"\"\" Returns an array comprised from different elements of choicelist\n depending on the list of conditions.\n\n condlist is a list of condition arrays containing ones or zeros\n \n choicelist is a list of choice matrices (of the \"same\" size as the\n arrays in condlist). The result array has the \"same\" size as the\n arrays in choicelist. If condlist is [c0,...,cN-1] then choicelist\n must be of length N. The elements of the choicelist can then be\n represented as [v0,...,vN-1]. The default choice if none of the\n conditions are met is given as the default argument. \n \n The conditions are tested in order and the first one statisfied is\n used to select the choice. In other words, the elements of the\n output array are found from the following tree (notice the order of\n the conditions matters):\n \n if c0: v0\n elif c1: v1\n elif c2: v2\n ...\n elif cN-1: vN-1\n else: default\n \n Note, that one of the condition arrays must be large enough to handle\n the largest array in the choice list.\n \"\"\"\n n = len(condlist)\n n2 = len(choicelist)\n if n2 != n:\n raise ValueError, \"List of cases, must be same length as the list of conditions.\"\n choicelist.insert(0,default) \n S = 0\n pfac = 1\n for k in range(1,n+1):\n S += k * pfac * asarray(condlist[k-1])\n if k < n:\n pfac *= (1-asarray(condlist[k-1]))\n # handle special case of a 1-element condition but\n # a multi-element choice\n if type(S) in ScalarType or max(asarray(S).shape)==1:\n pfac = asarray(1)\n for k in range(n2+1):\n pfac = pfac + asarray(choicelist[k]) \n S = S*ones(asarray(pfac).shape)\n return choose(S, tuple(choicelist))\n\n# Basic operations\ndef amax(m,axis=-1):\n \"\"\"Returns the maximum of m along dimension axis. \n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return maximum.reduce(m,axis)\n\ndef amin(m,axis=-1):\n \"\"\"Returns the minimum of m along dimension axis.\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else: \n m = asarray(m)\n return minimum.reduce(m,axis)\n\n# Actually from Basis, but it fits in so naturally here...\n\ndef ptp(m,axis=-1):\n \"\"\"Returns the maximum - minimum along the the given dimension\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return amax(m,axis)-amin(m,axis)\n\ndef cumsum(m,axis=-1):\n \"\"\"Returns the cumulative sum of the elements along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return add.accumulate(m,axis)\n\ndef prod(m,axis=-1):\n \"\"\"Returns the product of the elements along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return multiply.reduce(m,axis)\n\ndef cumprod(m,axis=-1):\n \"\"\"Returns the cumulative product of the elments along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return multiply.accumulate(m,axis)\n\ndef diff(x, n=1,axis=-1):\n \"\"\"Calculates the nth order, discrete difference along given axis.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n if n > 1:\n return diff(x[slice1]-x[slice2], n-1, axis=axis)\n else:\n return x[slice1]-x[slice2]\n\n \ndef angle(z,deg=0):\n \"\"\"Return the angle of complex argument z.\"\"\"\n if deg:\n fact = 180/pi\n else:\n fact = 1.0\n z = asarray(z)\n if z.typecode() in ['D','F']:\n zimag = z.imag\n zreal = z.real\n else:\n zimag = 0\n zreal = z\n return arctan2(zimag,zreal) * fact\n\ndef unwrap(p,discont=pi,axis=-1):\n \"\"\"unwraps radian phase p by changing absolute jumps greater than\n discont to their 2*pi complement along the given axis.\n \"\"\"\n p = asarray(p)\n nd = len(p.shape)\n dd = diff(p,axis=axis)\n slice1 = [slice(None,None)]*nd # full slices\n slice1[axis] = slice(1,None)\n ddmod = mod(dd+pi,2*pi)-pi\n putmask(ddmod,(ddmod==-pi) & (dd > 0),pi)\n ph_correct = ddmod - dd;\n putmask(ph_correct,abs(dd)>> import scipy\n >>> a = array((0,0,0,1,2,3,2,1,0))\n >>> scipy.trim_zeros(a)\n array([1, 2, 3, 2, 1])\n \"\"\"\n first = 0\n if 'f' in trim or 'F' in trim:\n for i in filt:\n if i != 0.: break\n else: first = first + 1\n last = len(filt)\n if 'b' in trim or 'B' in trim:\n for i in filt[::-1]:\n if i != 0.: break\n else: last = last - 1\n return filt[first:last]\n\ndef unique(inseq):\n \"\"\"Returns unique items in 1-dimensional sequence.\n \"\"\"\n set = {}\n for item in inseq:\n set[item] = None\n return asarray(set.keys())\n\nimport sys\ndef disp(mesg, device=None, linefeed=1):\n \"\"\"Display a message to device (default is sys.stdout) with(out) linefeed.\n \"\"\"\n if device is None:\n device = sys.stdout\n if linefeed:\n device.write('%s\\n' % mesg)\n else:\n device.write('%s' % mesg)\n device.flush()\n return\n\n \n\n#-----------------------------------------------------------------------------\n# Test Routines\n#-----------------------------------------------------------------------------\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == '__main__':\n test()\n", "source_code_before": "import types\nimport Numeric\nN = Numeric\nfrom Numeric import *\nfrom scipy_base.fastumath import *\nimport _compiled_base\nfrom type_check import ScalarType, isscalar\n\n__all__ = ['round','any','all','logspace','linspace','fix','mod',\n 'select','trim_zeros','amax','amin','ptp','cumsum',\n 'prod','cumprod','diff','angle','unwrap','sort_complex',\n 'disp','unique']\n\nround = Numeric.around\nany = Numeric.sometrue\nall = Numeric.alltrue\n\n\ndef logspace(start,stop,num=50,endpoint=1):\n \"\"\" Evenly spaced samples on a logarithmic scale.\n\n Return num evenly spaced samples from 10**start to 10**stop. If\n endpoint=1 then last sample is 10**stop.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = Numeric.arange(0,num) * step + start\n else:\n step = (stop-start)/float(num)\n y = Numeric.arange(0,num) * step + start\n return Numeric.power(10.0,y)\n\ndef linspace(start,stop,num=50,endpoint=1,retstep=0):\n \"\"\" Evenly spaced samples.\n \n Return num evenly spaced samples from start to stop. If endpoint=1 then\n last sample is stop. If retstep is 1 then return the step value used.\n \"\"\"\n if num <= 0: return array([])\n if endpoint:\n step = (stop-start)/float((num-1))\n y = Numeric.arange(0,num) * step + start \n else:\n step = (stop-start)/float(num)\n y = Numeric.arange(0,num) * step + start\n if retstep:\n return y, step\n else:\n return y\n\ndef fix(x):\n \"\"\" Round x to nearest integer towards zero.\n \"\"\"\n x = Numeric.asarray(x)\n y = Numeric.floor(x)\n return Numeric.where(x<0,y+1,y)\n\ndef mod(x,y):\n \"\"\" x - y*floor(x/y)\n \n For numeric arrays, x % y has the same sign as x while\n mod(x,y) has the same sign as y.\n \"\"\"\n return x - y*Numeric.floor(x*1.0/y)\n\ndef select(condlist, choicelist, default=0):\n \"\"\" Returns an array comprised from different elements of choicelist\n depending on the list of conditions.\n\n condlist is a list of condition arrays containing ones or zeros\n \n choicelist is a list of choice matrices (of the \"same\" size as the\n arrays in condlist). The result array has the \"same\" size as the\n arrays in choicelist. If condlist is [c0,...,cN-1] then choicelist\n must be of length N. The elements of the choicelist can then be\n represented as [v0,...,vN-1]. The default choice if none of the\n conditions are met is given as the default argument. \n \n The conditions are tested in order and the first one statisfied is\n used to select the choice. In other words, the elements of the\n output array are found from the following tree (notice the order of\n the conditions matters):\n \n if c0: v0\n elif c1: v1\n elif c2: v2\n ...\n elif cN-1: vN-1\n else: default\n \n Note, that one of the condition arrays must be large enough to handle\n the largest array in the choice list.\n \"\"\"\n n = len(condlist)\n n2 = len(choicelist)\n if n2 != n:\n raise ValueError, \"List of cases, must be same length as the list of conditions.\"\n choicelist.insert(0,default) \n S = 0\n pfac = 1\n for k in range(1,n+1):\n S += k * pfac * asarray(condlist[k-1])\n if k < n:\n pfac *= (1-asarray(condlist[k-1]))\n # handle special case of a 1-element condition but\n # a multi-element choice\n if type(S) in ScalarType or max(asarray(S).shape)==1:\n pfac = asarray(1)\n for k in range(n2+1):\n pfac = pfac + asarray(choicelist[k]) \n S = S*ones(asarray(pfac).shape)\n return choose(S, tuple(choicelist))\n\n# Basic operations\ndef amax(m,axis=-1):\n \"\"\"Returns the maximum of m along dimension axis. \n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return maximum.reduce(m,axis)\n\ndef amin(m,axis=-1):\n \"\"\"Returns the minimum of m along dimension axis.\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else: \n m = asarray(m)\n return minimum.reduce(m,axis)\n\n# Actually from Basis, but it fits in so naturally here...\n\ndef ptp(m,axis=-1):\n \"\"\"Returns the maximum - minimum along the the given dimension\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return amax(m,axis)-amin(m,axis)\n\ndef cumsum(m,axis=-1):\n \"\"\"Returns the cumulative sum of the elements along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return add.accumulate(m,axis)\n\ndef prod(m,axis=-1):\n \"\"\"Returns the product of the elements along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return multiply.reduce(m,axis)\n\ndef cumprod(m,axis=-1):\n \"\"\"Returns the cumulative product of the elments along the given axis\n \"\"\"\n if axis is None:\n m = ravel(m)\n axis = 0\n else:\n m = asarray(m)\n return multiply.accumulate(m,axis)\n\ndef diff(x, n=1,axis=-1):\n \"\"\"Calculates the nth order, discrete difference along given axis.\n \"\"\"\n x = asarray(x)\n nd = len(x.shape)\n slice1 = [slice(None)]*nd\n slice2 = [slice(None)]*nd\n slice1[axis] = slice(1,None)\n slice2[axis] = slice(None,-1)\n if n > 1:\n return diff(x[slice1]-x[slice2], n-1, axis=axis)\n else:\n return x[slice1]-x[slice2]\n\n \ndef angle(z,deg=0):\n \"\"\"Return the angle of complex argument z.\"\"\"\n if deg:\n fact = 180/pi\n else:\n fact = 1.0\n z = asarray(z)\n if z.typecode() in ['D','F']:\n zimag = z.imag\n zreal = z.real\n else:\n zimag = 0\n zreal = z\n return arctan2(zimag,zreal) * fact\n\ndef unwrap(p,discont=pi,axis=-1):\n \"\"\"unwraps radian phase p by changing absolute jumps greater than\n discont to their 2*pi complement along the given axis.\n \"\"\"\n p = asarray(p)\n nd = len(p.shape)\n dd = diff(p,axis=axis)\n slice1 = [slice(None,None)]*nd # full slices\n slice1[axis] = slice(1,None)\n ddmod = mod(dd+pi,2*pi)-pi\n putmask(ddmod,(ddmod==-pi) & (dd > 0),pi)\n ph_correct = ddmod - dd;\n putmask(ph_correct,abs(dd)>> import scipy\n >>> a = array((0,0,0,1,2,3,2,1,0))\n >>> scipy.trim_zeros(a)\n array([1, 2, 3, 2, 1])\n \"\"\"\n first = 0\n if 'f' in trim or 'F' in trim:\n for i in filt:\n if i != 0.: break\n else: first = first + 1\n last = len(filt)\n if 'b' in trim or 'B' in trim:\n for i in filt[::-1]:\n if i != 0.: break\n else: last = last - 1\n return filt[first:last]\n\ndef unique(inseq):\n \"\"\"Returns unique items in 1-dimensional sequence.\n \"\"\"\n set = {}\n for item in inseq:\n set[item] = None\n return asarray(set.keys())\n\nimport sys\ndef disp(mesg, device=None, linefeed=1):\n \"\"\"Display a message to device (default is sys.stdout) with(out) linefeed.\n \"\"\"\n if device is None:\n device = sys.stdout\n if linefeed:\n device.write('%s\\n' % mesg)\n else:\n device.write('%s' % mesg)\n device.flush()\n return\n\n \n\n#-----------------------------------------------------------------------------\n# Test Routines\n#-----------------------------------------------------------------------------\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == '__main__':\n test()\n", "methods": [ { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 19, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = 1 , retstep = 0 )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 34, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "fix", "long_name": "fix( x )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "x" ], "start_line": 52, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "mod", "long_name": "mod( x , y )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "x", "y" ], "start_line": 59, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "select", "long_name": "select( condlist , choicelist , default = 0 )", "filename": "function_base.py", "nloc": 18, "complexity": 7, "token_count": 165, "parameters": [ "condlist", "choicelist", "default" ], "start_line": 67, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 116, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 126, "end_line": 134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 47, "parameters": [ "m", "axis" ], "start_line": 138, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "cumsum", "long_name": "cumsum( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 148, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "prod", "long_name": "prod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 158, "end_line": 166, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 168, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "diff", "long_name": "diff( x , n = 1 , axis = - 1 )", "filename": "function_base.py", "nloc": 11, "complexity": 2, "token_count": 110, "parameters": [ "x", "n", "axis" ], "start_line": 178, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "angle", "long_name": "angle( z , deg = 0 )", "filename": "function_base.py", "nloc": 13, "complexity": 3, "token_count": 71, "parameters": [ "z", "deg" ], "start_line": 193, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "unwrap", "long_name": "unwrap( p , discont = pi , axis = - 1 )", "filename": "function_base.py", "nloc": 13, "complexity": 1, "token_count": 146, "parameters": [ "p", "discont", "axis" ], "start_line": 208, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "sort_complex.complex_cmp", "long_name": "sort_complex.complex_cmp( x , y )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "x", "y" ], "start_line": 229, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "sort_complex", "long_name": "sort_complex( a )", "filename": "function_base.py", "nloc": 6, "complexity": 1, "token_count": 44, "parameters": [ "a" ], "start_line": 225, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "trim_zeros", "long_name": "trim_zeros( filt , trim = 'fb' )", "filename": "function_base.py", "nloc": 12, "complexity": 9, "token_count": 87, "parameters": [ "filt", "trim" ], "start_line": 238, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "unique", "long_name": "unique( inseq )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "inseq" ], "start_line": 259, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "disp", "long_name": "disp( mesg , device = None , linefeed = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 51, "parameters": [ "mesg", "device", "linefeed" ], "start_line": 268, "end_line": 278, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 286, "end_line": 288, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 290, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "logspace", "long_name": "logspace( start , stop , num = 50 , endpoint = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 99, "parameters": [ "start", "stop", "num", "endpoint" ], "start_line": 19, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "linspace", "long_name": "linspace( start , stop , num = 50 , endpoint = 1 , retstep = 0 )", "filename": "function_base.py", "nloc": 12, "complexity": 4, "token_count": 103, "parameters": [ "start", "stop", "num", "endpoint", "retstep" ], "start_line": 34, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "fix", "long_name": "fix( x )", "filename": "function_base.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "x" ], "start_line": 52, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "mod", "long_name": "mod( x , y )", "filename": "function_base.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "x", "y" ], "start_line": 59, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "select", "long_name": "select( condlist , choicelist , default = 0 )", "filename": "function_base.py", "nloc": 18, "complexity": 7, "token_count": 165, "parameters": [ "condlist", "choicelist", "default" ], "start_line": 67, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "amax", "long_name": "amax( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 116, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "amin", "long_name": "amin( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 126, "end_line": 134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "ptp", "long_name": "ptp( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 47, "parameters": [ "m", "axis" ], "start_line": 138, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "cumsum", "long_name": "cumsum( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 148, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "prod", "long_name": "prod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 158, "end_line": 166, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "cumprod", "long_name": "cumprod( m , axis = - 1 )", "filename": "function_base.py", "nloc": 7, "complexity": 2, "token_count": 42, "parameters": [ "m", "axis" ], "start_line": 168, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "diff", "long_name": "diff( x , n = 1 , axis = - 1 )", "filename": "function_base.py", "nloc": 11, "complexity": 2, "token_count": 110, "parameters": [ "x", "n", "axis" ], "start_line": 178, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "angle", "long_name": "angle( z , deg = 0 )", "filename": "function_base.py", "nloc": 13, "complexity": 3, "token_count": 71, "parameters": [ "z", "deg" ], "start_line": 193, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "unwrap", "long_name": "unwrap( p , discont = pi , axis = - 1 )", "filename": "function_base.py", "nloc": 13, "complexity": 1, "token_count": 146, "parameters": [ "p", "discont", "axis" ], "start_line": 208, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "sort_complex.complex_cmp", "long_name": "sort_complex.complex_cmp( x , y )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 38, "parameters": [ "x", "y" ], "start_line": 229, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "sort_complex", "long_name": "sort_complex( a )", "filename": "function_base.py", "nloc": 6, "complexity": 1, "token_count": 44, "parameters": [ "a" ], "start_line": 225, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "trim_zeros", "long_name": "trim_zeros( filt , trim = 'fb' )", "filename": "function_base.py", "nloc": 12, "complexity": 9, "token_count": 87, "parameters": [ "filt", "trim" ], "start_line": 238, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "unique", "long_name": "unique( inseq )", "filename": "function_base.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "inseq" ], "start_line": 259, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "disp", "long_name": "disp( mesg , device = None , linefeed = 1 )", "filename": "function_base.py", "nloc": 9, "complexity": 3, "token_count": 51, "parameters": [ "mesg", "device", "linefeed" ], "start_line": 268, "end_line": 278, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 286, "end_line": 288, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 290, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 290, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "function_base.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 286, "end_line": 288, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 183, "complexity": 53, "token_count": 1424, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "scipy_base/index_tricks.py", "new_path": "scipy_base/index_tricks.py", "filename": "index_tricks.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -199,9 +199,9 @@ def __getslice__(self, start, stop):\n #-----------------------------------------------------------------------------\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "added_lines": 2, "deleted_lines": 2, "source_code": "import types\nimport Numeric\n__all__ = ['mgrid','ogrid','r_','c_','index_exp']\n\nfrom type_check import ScalarType\nimport function_base\n\nclass nd_grid:\n \"\"\" Construct a \"meshgrid\" in N-dimensions.\n\n grid = nd_grid() creates an instance which will return a mesh-grid\n when indexed. The dimension and number of the output arrays are equal\n to the number of indexing dimensions. If the step length is not a\n complex number, then the stop is not inclusive.\n \n However, if the step length is a COMPLEX NUMBER (e.g. 5j), then the\n integer part of it's magnitude is interpreted as specifying the\n number of points to create between the start and stop values, where\n the stop value IS INCLUSIVE.\n\n If instantiated with an argument of 1, the mesh-grid is open or not\n fleshed out so that only one-dimension of each returned argument is\n greater than 1\n \n Example:\n \n >>> mgrid = nd_grid()\n >>> mgrid[0:5,0:5]\n array([[[0, 0, 0, 0, 0],\n [1, 1, 1, 1, 1],\n [2, 2, 2, 2, 2],\n [3, 3, 3, 3, 3],\n [4, 4, 4, 4, 4]],\n [[0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4]]])\n >>> mgrid[-1:1:5j]\n array([-1. , -0.5, 0. , 0.5, 1. ])\n\n >>> ogrid = nd_grid(1)\n >>> ogrid[0:5,0:5]\n [array([[0],[1],[2],[3],[4]]), array([[0, 1, 2, 3, 4]])] \n \"\"\"\n def __init__(self, sparse=0):\n self.sparse = sparse\n def __getitem__(self,key):\n try:\n\t size = []\n typecode = Numeric.Int\n\t for k in range(len(key)):\n\t step = key[k].step\n start = key[k].start\n if start is None: start = 0\n if step is None:\n step = 1\n if type(step) is type(1j):\n size.append(int(abs(step)))\n typecode = Numeric.Float\n else:\n size.append(int((key[k].stop - start)/(step*1.0)))\n if isinstance(step,types.FloatType) or \\\n isinstance(start, types.FloatType) or \\\n isinstance(key[k].stop, types.FloatType):\n typecode = Numeric.Float\n if self.sparse:\n nn = map(lambda x,t: Numeric.arange(x,typecode=t),size,(typecode,)*len(size))\n else:\n nn = Numeric.indices(size,typecode)\n\t for k in range(len(size)):\n step = key[k].step\n if step is None:\n step = 1\n if type(step) is type(1j):\n step = int(abs(step))\n step = (key[k].stop - key[k].start)/float(step-1)\n nn[k] = (nn[k]*step+key[k].start)\n if self.sparse:\n slobj = [Numeric.NewAxis]*len(size)\n for k in range(len(size)):\n slobj[k] = slice(None,None)\n nn[k] = nn[k][slobj]\n slobj[k] = Numeric.NewAxis\n\t return nn\n except (IndexError, TypeError):\n step = key.step\n stop = key.stop\n start = key.start\n if start is None: start = 0\n if type(step) is type(1j):\n step = abs(step)\n length = int(step)\n step = (key.stop-start)/float(step-1)\n stop = key.stop+step\n return Numeric.arange(0,length,1,Numeric.Float)*step + start\n else:\n return Numeric.arange(start, stop, step)\n\t \n def __getslice__(self,i,j):\n return Numeric.arange(i,j)\n\n def __len__(self):\n return 0\n\nmgrid = nd_grid()\nogrid = nd_grid(1)\n\nclass concatenator:\n \"\"\" Translates slice objects to concatenation along an axis.\n \"\"\"\n def __init__(self, axis=0):\n self.axis = axis\n def __getitem__(self,key):\n if type(key) is not types.TupleType:\n key = (key,)\n objs = []\n for k in range(len(key)):\n if type(key[k]) is types.SliceType:\n typecode = Numeric.Int\n\t step = key[k].step\n start = key[k].start\n stop = key[k].stop\n if start is None: start = 0\n if step is None:\n step = 1\n if type(step) is type(1j):\n size = int(abs(step))\n typecode = Numeric.Float\n endpoint = 1\n else:\n size = int((stop - start)/(step*1.0))\n endpoint = 0\n if isinstance(step,types.FloatType) or \\\n isinstance(start, types.FloatType) or \\\n isinstance(stop, types.FloatType):\n typecode = Numeric.Float\n newobj = function_base.linspace(start, stop, num=size, endpoint=endpoint)\n elif type(key[k]) in ScalarType:\n newobj = Numeric.asarray([key[k]])\n else:\n newobj = key[k]\n objs.append(newobj)\n return Numeric.concatenate(tuple(objs),axis=self.axis)\n \n def __getslice__(self,i,j):\n return Numeric.arange(i,j)\n\n def __len__(self):\n return 0\n\nr_=concatenator(0)\nc_=concatenator(-1)\n\n# A nicer way to build up index tuples for arrays.\n#\n# You can do all this with slice() plus a few special objects,\n# but there's a lot to remember. This version is simpler because\n# it uses the standard array indexing syntax.\n#\n# Written by Konrad Hinsen \n# last revision: 1999-7-23\n#\n# Cosmetic changes by T. Oliphant 2001\n#\n#\n# This module provides a convenient method for constructing\n# array indices algorithmically. It provides one importable object,\n# 'index_expression'.\n#\n# For any index combination, including slicing and axis insertion,\n# 'a[indices]' is the same as 'a[index_expression[indices]]' for any\n# array 'a'. However, 'index_expression[indices]' can be used anywhere\n# in Python code and returns a tuple of slice objects that can be\n# used in the construction of complex index expressions.\n\nclass _index_expression_class:\n import sys\n maxint = sys.maxint\n\n def __getitem__(self, item):\n if type(item) != type(()):\n return (item,)\n else:\n return item\n\n def __len__(self):\n return self.maxint\n\n def __getslice__(self, start, stop):\n if stop == self.maxint:\n stop = None\n return self[start:stop:None]\n\nindex_exp = _index_expression_class()\n\n# End contribution from Konrad.\n\n#-----------------------------------------------------------------------------\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "source_code_before": "import types\nimport Numeric\n__all__ = ['mgrid','ogrid','r_','c_','index_exp']\n\nfrom type_check import ScalarType\nimport function_base\n\nclass nd_grid:\n \"\"\" Construct a \"meshgrid\" in N-dimensions.\n\n grid = nd_grid() creates an instance which will return a mesh-grid\n when indexed. The dimension and number of the output arrays are equal\n to the number of indexing dimensions. If the step length is not a\n complex number, then the stop is not inclusive.\n \n However, if the step length is a COMPLEX NUMBER (e.g. 5j), then the\n integer part of it's magnitude is interpreted as specifying the\n number of points to create between the start and stop values, where\n the stop value IS INCLUSIVE.\n\n If instantiated with an argument of 1, the mesh-grid is open or not\n fleshed out so that only one-dimension of each returned argument is\n greater than 1\n \n Example:\n \n >>> mgrid = nd_grid()\n >>> mgrid[0:5,0:5]\n array([[[0, 0, 0, 0, 0],\n [1, 1, 1, 1, 1],\n [2, 2, 2, 2, 2],\n [3, 3, 3, 3, 3],\n [4, 4, 4, 4, 4]],\n [[0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4],\n [0, 1, 2, 3, 4]]])\n >>> mgrid[-1:1:5j]\n array([-1. , -0.5, 0. , 0.5, 1. ])\n\n >>> ogrid = nd_grid(1)\n >>> ogrid[0:5,0:5]\n [array([[0],[1],[2],[3],[4]]), array([[0, 1, 2, 3, 4]])] \n \"\"\"\n def __init__(self, sparse=0):\n self.sparse = sparse\n def __getitem__(self,key):\n try:\n\t size = []\n typecode = Numeric.Int\n\t for k in range(len(key)):\n\t step = key[k].step\n start = key[k].start\n if start is None: start = 0\n if step is None:\n step = 1\n if type(step) is type(1j):\n size.append(int(abs(step)))\n typecode = Numeric.Float\n else:\n size.append(int((key[k].stop - start)/(step*1.0)))\n if isinstance(step,types.FloatType) or \\\n isinstance(start, types.FloatType) or \\\n isinstance(key[k].stop, types.FloatType):\n typecode = Numeric.Float\n if self.sparse:\n nn = map(lambda x,t: Numeric.arange(x,typecode=t),size,(typecode,)*len(size))\n else:\n nn = Numeric.indices(size,typecode)\n\t for k in range(len(size)):\n step = key[k].step\n if step is None:\n step = 1\n if type(step) is type(1j):\n step = int(abs(step))\n step = (key[k].stop - key[k].start)/float(step-1)\n nn[k] = (nn[k]*step+key[k].start)\n if self.sparse:\n slobj = [Numeric.NewAxis]*len(size)\n for k in range(len(size)):\n slobj[k] = slice(None,None)\n nn[k] = nn[k][slobj]\n slobj[k] = Numeric.NewAxis\n\t return nn\n except (IndexError, TypeError):\n step = key.step\n stop = key.stop\n start = key.start\n if start is None: start = 0\n if type(step) is type(1j):\n step = abs(step)\n length = int(step)\n step = (key.stop-start)/float(step-1)\n stop = key.stop+step\n return Numeric.arange(0,length,1,Numeric.Float)*step + start\n else:\n return Numeric.arange(start, stop, step)\n\t \n def __getslice__(self,i,j):\n return Numeric.arange(i,j)\n\n def __len__(self):\n return 0\n\nmgrid = nd_grid()\nogrid = nd_grid(1)\n\nclass concatenator:\n \"\"\" Translates slice objects to concatenation along an axis.\n \"\"\"\n def __init__(self, axis=0):\n self.axis = axis\n def __getitem__(self,key):\n if type(key) is not types.TupleType:\n key = (key,)\n objs = []\n for k in range(len(key)):\n if type(key[k]) is types.SliceType:\n typecode = Numeric.Int\n\t step = key[k].step\n start = key[k].start\n stop = key[k].stop\n if start is None: start = 0\n if step is None:\n step = 1\n if type(step) is type(1j):\n size = int(abs(step))\n typecode = Numeric.Float\n endpoint = 1\n else:\n size = int((stop - start)/(step*1.0))\n endpoint = 0\n if isinstance(step,types.FloatType) or \\\n isinstance(start, types.FloatType) or \\\n isinstance(stop, types.FloatType):\n typecode = Numeric.Float\n newobj = function_base.linspace(start, stop, num=size, endpoint=endpoint)\n elif type(key[k]) in ScalarType:\n newobj = Numeric.asarray([key[k]])\n else:\n newobj = key[k]\n objs.append(newobj)\n return Numeric.concatenate(tuple(objs),axis=self.axis)\n \n def __getslice__(self,i,j):\n return Numeric.arange(i,j)\n\n def __len__(self):\n return 0\n\nr_=concatenator(0)\nc_=concatenator(-1)\n\n# A nicer way to build up index tuples for arrays.\n#\n# You can do all this with slice() plus a few special objects,\n# but there's a lot to remember. This version is simpler because\n# it uses the standard array indexing syntax.\n#\n# Written by Konrad Hinsen \n# last revision: 1999-7-23\n#\n# Cosmetic changes by T. Oliphant 2001\n#\n#\n# This module provides a convenient method for constructing\n# array indices algorithmically. It provides one importable object,\n# 'index_expression'.\n#\n# For any index combination, including slicing and axis insertion,\n# 'a[indices]' is the same as 'a[index_expression[indices]]' for any\n# array 'a'. However, 'index_expression[indices]' can be used anywhere\n# in Python code and returns a tuple of slice objects that can be\n# used in the construction of complex index expressions.\n\nclass _index_expression_class:\n import sys\n maxint = sys.maxint\n\n def __getitem__(self, item):\n if type(item) != type(()):\n return (item,)\n else:\n return item\n\n def __len__(self):\n return self.maxint\n\n def __getslice__(self, start, stop):\n if stop == self.maxint:\n stop = None\n return self[start:stop:None]\n\nindex_exp = _index_expression_class()\n\n# End contribution from Konrad.\n\n#-----------------------------------------------------------------------------\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "methods": [ { "name": "__init__", "long_name": "__init__( self , sparse = 0 )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "sparse" ], "start_line": 46, "end_line": 47, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getitem__", "long_name": "__getitem__( self , key )", "filename": "index_tricks.py", "nloc": 51, "complexity": 17, "token_count": 466, "parameters": [ "self", "key" ], "start_line": 48, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "top_nesting_level": 1 }, { "name": "__getslice__", "long_name": "__getslice__( self , i , j )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "i", "j" ], "start_line": 100, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__len__", "long_name": "__len__( self )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 103, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , axis = 0 )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "axis" ], "start_line": 112, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getitem__", "long_name": "__getitem__( self , key )", "filename": "index_tricks.py", "nloc": 31, "complexity": 11, "token_count": 255, "parameters": [ "self", "key" ], "start_line": 114, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "__getslice__", "long_name": "__getslice__( self , i , j )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "i", "j" ], "start_line": 146, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__len__", "long_name": "__len__( self )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 149, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getitem__", "long_name": "__getitem__( self , item )", "filename": "index_tricks.py", "nloc": 5, "complexity": 2, "token_count": 28, "parameters": [ "self", "item" ], "start_line": 181, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__len__", "long_name": "__len__( self )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 187, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getslice__", "long_name": "__getslice__( self , start , stop )", "filename": "index_tricks.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self", "start", "stop" ], "start_line": 190, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "index_tricks.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 201, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "index_tricks.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 205, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self , sparse = 0 )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "sparse" ], "start_line": 46, "end_line": 47, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getitem__", "long_name": "__getitem__( self , key )", "filename": "index_tricks.py", "nloc": 51, "complexity": 17, "token_count": 466, "parameters": [ "self", "key" ], "start_line": 48, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "top_nesting_level": 1 }, { "name": "__getslice__", "long_name": "__getslice__( self , i , j )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "i", "j" ], "start_line": 100, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__len__", "long_name": "__len__( self )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 103, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , axis = 0 )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "axis" ], "start_line": 112, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getitem__", "long_name": "__getitem__( self , key )", "filename": "index_tricks.py", "nloc": 31, "complexity": 11, "token_count": 255, "parameters": [ "self", "key" ], "start_line": 114, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "__getslice__", "long_name": "__getslice__( self , i , j )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "i", "j" ], "start_line": 146, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__len__", "long_name": "__len__( self )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 149, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getitem__", "long_name": "__getitem__( self , item )", "filename": "index_tricks.py", "nloc": 5, "complexity": 2, "token_count": 28, "parameters": [ "self", "item" ], "start_line": 181, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__len__", "long_name": "__len__( self )", "filename": "index_tricks.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 187, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__getslice__", "long_name": "__getslice__( self , start , stop )", "filename": "index_tricks.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self", "start", "stop" ], "start_line": 190, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "index_tricks.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 201, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "index_tricks.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 205, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "index_tricks.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 205, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "index_tricks.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 201, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 165, "complexity": 41, "token_count": 994, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "scipy_base/limits.py", "new_path": "scipy_base/limits.py", "filename": "limits.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -67,11 +67,11 @@ def tiny(typecode):\n double_resolution = 10.0**(-double_precision)\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n if __name__ == '__main__':\n", "added_lines": 2, "deleted_lines": 2, "source_code": "\"\"\" This really needs some work...\n\n Calculate machine limits for Float32 and Float64.\n Actually, max and min are hard coded - and wrong!\n They are close, however.\n\n\"\"\"\n\nimport Numeric\nimport scipy_base.fastumath\nreload(scipy_base.fastumath)\nfrom type_check import cast\ntoFloat32=cast['f']\ntoFloat64=cast['d']\n\n__all__ = ['epsilon','tiny','float_epsilon','float_tiny','float_min',\n 'float_max','float_precision','float_resolution',\n 'double_epsilon','double_tiny','double_min','double_max',\n 'double_precision','double_resolution']\n\n\ndef epsilon(typecode):\n if typecode == Numeric.Float32: cast = toFloat32\n elif typecode == Numeric.Float64: cast = toFloat64\n one = cast(1.0)\n x = cast(1.0)\n while one+x > one:\n x = x * cast(.5)\n x = x * cast(2.0)\n return x\n\ndef tiny(typecode):\n if typecode == Numeric.Float32: cast = toFloat32\n if typecode == Numeric.Float64: cast = toFloat64\n zero = cast(0.0)\n d1 = cast(1.0)\n d2 = cast(1.0)\n while d1 > zero:\n d2 = d1\n d1 = d1 * cast(.5)\n return d2\n\n \n\nfloat_epsilon = epsilon(Numeric.Float32)\nfloat_tiny = tiny(Numeric.Float32)\n#not correct\nfloat_min = -3.402823e38\nfloat_max = 3.402823e38\nfloat_precision = 6\nfloat_resolution = 10.0**(-float_precision)\n\n# hard coded - taken from Norbert's Fortran code.\n# INTEGER, PARAMETER :: kind_DBLE = KIND(0D0) ! 8 (HP-UX)\n# INTEGER, PARAMETER :: prec_DBLE = PRECISION(0D0) ! 15\n# INTEGER, PARAMETER :: range_DBLE = RANGE(0D0) ! 307\n# REAL(kind_DBLE), PARAMETER :: eps_DBLE = EPSILON(0D0) ! 2.22e-16\n# REAL(kind_DBLE), PARAMETER :: tiny_DBLE = TINY(0D0) ! 2.23e-308\n# REAL(kind_DBLE), PARAMETER :: huge_DBLE = HUGE(0D0) ! 1.80e+308\ndouble_epsilon = epsilon(Numeric.Float64)\ndouble_tiny = tiny(Numeric.Float64)\n\n# not quite right...\ndouble_min = -1.797683134862318e308\ndouble_max = 1.797683134862318e308\ndouble_precision = 15\ndouble_resolution = 10.0**(-double_precision)\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == '__main__':\n print 'float epsilon:',float_epsilon\n print 'float tiny:',float_tiny\n print 'double epsilon:',double_epsilon\n print 'double tiny:',double_tiny\n", "source_code_before": "\"\"\" This really needs some work...\n\n Calculate machine limits for Float32 and Float64.\n Actually, max and min are hard coded - and wrong!\n They are close, however.\n\n\"\"\"\n\nimport Numeric\nimport scipy_base.fastumath\nreload(scipy_base.fastumath)\nfrom type_check import cast\ntoFloat32=cast['f']\ntoFloat64=cast['d']\n\n__all__ = ['epsilon','tiny','float_epsilon','float_tiny','float_min',\n 'float_max','float_precision','float_resolution',\n 'double_epsilon','double_tiny','double_min','double_max',\n 'double_precision','double_resolution']\n\n\ndef epsilon(typecode):\n if typecode == Numeric.Float32: cast = toFloat32\n elif typecode == Numeric.Float64: cast = toFloat64\n one = cast(1.0)\n x = cast(1.0)\n while one+x > one:\n x = x * cast(.5)\n x = x * cast(2.0)\n return x\n\ndef tiny(typecode):\n if typecode == Numeric.Float32: cast = toFloat32\n if typecode == Numeric.Float64: cast = toFloat64\n zero = cast(0.0)\n d1 = cast(1.0)\n d2 = cast(1.0)\n while d1 > zero:\n d2 = d1\n d1 = d1 * cast(.5)\n return d2\n\n \n\nfloat_epsilon = epsilon(Numeric.Float32)\nfloat_tiny = tiny(Numeric.Float32)\n#not correct\nfloat_min = -3.402823e38\nfloat_max = 3.402823e38\nfloat_precision = 6\nfloat_resolution = 10.0**(-float_precision)\n\n# hard coded - taken from Norbert's Fortran code.\n# INTEGER, PARAMETER :: kind_DBLE = KIND(0D0) ! 8 (HP-UX)\n# INTEGER, PARAMETER :: prec_DBLE = PRECISION(0D0) ! 15\n# INTEGER, PARAMETER :: range_DBLE = RANGE(0D0) ! 307\n# REAL(kind_DBLE), PARAMETER :: eps_DBLE = EPSILON(0D0) ! 2.22e-16\n# REAL(kind_DBLE), PARAMETER :: tiny_DBLE = TINY(0D0) ! 2.23e-308\n# REAL(kind_DBLE), PARAMETER :: huge_DBLE = HUGE(0D0) ! 1.80e+308\ndouble_epsilon = epsilon(Numeric.Float64)\ndouble_tiny = tiny(Numeric.Float64)\n\n# not quite right...\ndouble_min = -1.797683134862318e308\ndouble_max = 1.797683134862318e308\ndouble_precision = 15\ndouble_resolution = 10.0**(-double_precision)\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == '__main__':\n print 'float epsilon:',float_epsilon\n print 'float tiny:',float_tiny\n print 'double epsilon:',double_epsilon\n print 'double tiny:',double_tiny\n", "methods": [ { "name": "epsilon", "long_name": "epsilon( typecode )", "filename": "limits.py", "nloc": 9, "complexity": 4, "token_count": 69, "parameters": [ "typecode" ], "start_line": 22, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "tiny", "long_name": "tiny( typecode )", "filename": "limits.py", "nloc": 10, "complexity": 4, "token_count": 68, "parameters": [ "typecode" ], "start_line": 32, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "limits.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 69, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "limits.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 73, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "epsilon", "long_name": "epsilon( typecode )", "filename": "limits.py", "nloc": 9, "complexity": 4, "token_count": 69, "parameters": [ "typecode" ], "start_line": 22, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "tiny", "long_name": "tiny( typecode )", "filename": "limits.py", "nloc": 10, "complexity": 4, "token_count": 68, "parameters": [ "typecode" ], "start_line": 32, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "limits.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 69, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "limits.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 73, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "limits.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 73, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "limits.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 69, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 59, "complexity": 10, "token_count": 349, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "scipy_base/matrix_base.py", "new_path": "scipy_base/matrix_base.py", "filename": "matrix_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -90,11 +90,11 @@ def diag(v, k=0):\n #-----------------------------------------------------------------------------\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n if __name__ == '__main__':\n", "added_lines": 2, "deleted_lines": 2, "source_code": "\"\"\" Basic functions for manipulating 2d arrays\n\n\"\"\"\n\n__all__ = ['diag','eye','fliplr','flipud','rot90']\n \n# These are from Numeric\nimport Matrix\nfrom Numeric import *\nfrom scipy_base.fastumath import *\nfrom type_check import isscalar\nfrom index_tricks import mgrid,r_,c_\n# Elementary matrices\n\n# zeros is from matrixmodule in C\n# ones is from Numeric.py\n\n \ndef fliplr(m):\n \"\"\" returns a 2-D matrix m with the rows preserved and columns flipped \n in the left/right direction. Only works with 2-D arrays.\n \"\"\"\n m = asarray(m)\n if len(m.shape) != 2:\n raise ValueError, \"Input must be 2-D.\"\n return m[:, ::-1]\n\ndef flipud(m):\n \"\"\" returns a 2-D matrix with the columns preserved and rows flipped in\n the up/down direction. Only works with 2-D arrays.\n \"\"\"\n m = asarray(m)\n if len(m.shape) != 2:\n raise ValueError, \"Input must be 2-D.\"\n return m[::-1]\n \n# reshape(x, m, n) is not used, instead use reshape(x, (m, n))\n\ndef rot90(m, k=1):\n \"\"\" returns the matrix found by rotating m by k*90 degrees in the \n counterclockwise direction.\n \"\"\"\n m = asarray(m)\n if len(m.shape) != 2:\n raise ValueError, \"Input must be 2-D.\"\n k = k % 4\n if k == 0: return m\n elif k == 1: return transpose(fliplr(m))\n elif k == 2: return fliplr(flipud(m))\n else: return fliplr(transpose(m)) # k==3\n \ndef eye(N, M=None, k=0, typecode=None):\n \"\"\" eye returns a N-by-M matrix where the k-th diagonal is all ones, \n and everything else is zeros.\n \"\"\"\n if M is None: M = N\n if type(M) == type('d'): \n typecode = M\n M = N\n m = equal(subtract.outer(arange(N), arange(M)),-k)\n if typecode is None:\n return m\n else:\n return m.astype(typecode)\n\ndef diag(v, k=0):\n \"\"\" returns the k-th diagonal if v is a matrix or returns a matrix \n with v as the k-th diagonal if v is a vector.\n \"\"\"\n v = asarray(v)\n s = v.shape\n if len(s)==1:\n n = s[0]+abs(k)\n if k > 0:\n v = concatenate((zeros(k, v.typecode()),v))\n elif k < 0:\n v = concatenate((v,zeros(-k, v.typecode())))\n return eye(n, k=k)*v\n elif len(s)==2:\n v = add.reduce(eye(s[0], s[1], k=k)*v)\n if k > 0: return v[k:]\n elif k < 0: return v[:k]\n else: return v\n else:\n raise ValueError, \"Input must be 1- or 2-D.\"\n\n\n#-----------------------------------------------------------------------------\n# Test Routines\n#-----------------------------------------------------------------------------\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == '__main__':\n print 'float epsilon:',float_epsilon\n print 'float tiny:',float_tiny\n print 'double epsilon:',double_epsilon\n print 'double tiny:',double_tiny\n", "source_code_before": "\"\"\" Basic functions for manipulating 2d arrays\n\n\"\"\"\n\n__all__ = ['diag','eye','fliplr','flipud','rot90']\n \n# These are from Numeric\nimport Matrix\nfrom Numeric import *\nfrom scipy_base.fastumath import *\nfrom type_check import isscalar\nfrom index_tricks import mgrid,r_,c_\n# Elementary matrices\n\n# zeros is from matrixmodule in C\n# ones is from Numeric.py\n\n \ndef fliplr(m):\n \"\"\" returns a 2-D matrix m with the rows preserved and columns flipped \n in the left/right direction. Only works with 2-D arrays.\n \"\"\"\n m = asarray(m)\n if len(m.shape) != 2:\n raise ValueError, \"Input must be 2-D.\"\n return m[:, ::-1]\n\ndef flipud(m):\n \"\"\" returns a 2-D matrix with the columns preserved and rows flipped in\n the up/down direction. Only works with 2-D arrays.\n \"\"\"\n m = asarray(m)\n if len(m.shape) != 2:\n raise ValueError, \"Input must be 2-D.\"\n return m[::-1]\n \n# reshape(x, m, n) is not used, instead use reshape(x, (m, n))\n\ndef rot90(m, k=1):\n \"\"\" returns the matrix found by rotating m by k*90 degrees in the \n counterclockwise direction.\n \"\"\"\n m = asarray(m)\n if len(m.shape) != 2:\n raise ValueError, \"Input must be 2-D.\"\n k = k % 4\n if k == 0: return m\n elif k == 1: return transpose(fliplr(m))\n elif k == 2: return fliplr(flipud(m))\n else: return fliplr(transpose(m)) # k==3\n \ndef eye(N, M=None, k=0, typecode=None):\n \"\"\" eye returns a N-by-M matrix where the k-th diagonal is all ones, \n and everything else is zeros.\n \"\"\"\n if M is None: M = N\n if type(M) == type('d'): \n typecode = M\n M = N\n m = equal(subtract.outer(arange(N), arange(M)),-k)\n if typecode is None:\n return m\n else:\n return m.astype(typecode)\n\ndef diag(v, k=0):\n \"\"\" returns the k-th diagonal if v is a matrix or returns a matrix \n with v as the k-th diagonal if v is a vector.\n \"\"\"\n v = asarray(v)\n s = v.shape\n if len(s)==1:\n n = s[0]+abs(k)\n if k > 0:\n v = concatenate((zeros(k, v.typecode()),v))\n elif k < 0:\n v = concatenate((v,zeros(-k, v.typecode())))\n return eye(n, k=k)*v\n elif len(s)==2:\n v = add.reduce(eye(s[0], s[1], k=k)*v)\n if k > 0: return v[k:]\n elif k < 0: return v[:k]\n else: return v\n else:\n raise ValueError, \"Input must be 1- or 2-D.\"\n\n\n#-----------------------------------------------------------------------------\n# Test Routines\n#-----------------------------------------------------------------------------\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == '__main__':\n print 'float epsilon:',float_epsilon\n print 'float tiny:',float_tiny\n print 'double epsilon:',double_epsilon\n print 'double tiny:',double_tiny\n", "methods": [ { "name": "fliplr", "long_name": "fliplr( m )", "filename": "matrix_base.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [ "m" ], "start_line": 19, "end_line": 26, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "flipud", "long_name": "flipud( m )", "filename": "matrix_base.py", "nloc": 5, "complexity": 2, "token_count": 33, "parameters": [ "m" ], "start_line": 28, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "rot90", "long_name": "rot90( m , k = 1 )", "filename": "matrix_base.py", "nloc": 9, "complexity": 5, "token_count": 78, "parameters": [ "m", "k" ], "start_line": 39, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "eye", "long_name": "eye( N , M = None , k = 0 , typecode = None )", "filename": "matrix_base.py", "nloc": 10, "complexity": 4, "token_count": 81, "parameters": [ "N", "M", "k", "typecode" ], "start_line": 52, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "diag", "long_name": "diag( v , k = 0 )", "filename": "matrix_base.py", "nloc": 17, "complexity": 7, "token_count": 165, "parameters": [ "v", "k" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "matrix_base.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 92, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "matrix_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 96, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "fliplr", "long_name": "fliplr( m )", "filename": "matrix_base.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [ "m" ], "start_line": 19, "end_line": 26, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "flipud", "long_name": "flipud( m )", "filename": "matrix_base.py", "nloc": 5, "complexity": 2, "token_count": 33, "parameters": [ "m" ], "start_line": 28, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "rot90", "long_name": "rot90( m , k = 1 )", "filename": "matrix_base.py", "nloc": 9, "complexity": 5, "token_count": 78, "parameters": [ "m", "k" ], "start_line": 39, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "eye", "long_name": "eye( N , M = None , k = 0 , typecode = None )", "filename": "matrix_base.py", "nloc": 10, "complexity": 4, "token_count": 81, "parameters": [ "N", "M", "k", "typecode" ], "start_line": 52, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "diag", "long_name": "diag( v , k = 0 )", "filename": "matrix_base.py", "nloc": 17, "complexity": 7, "token_count": 165, "parameters": [ "v", "k" ], "start_line": 66, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "matrix_base.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 92, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "matrix_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 96, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "matrix_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 96, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "matrix_base.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 92, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 66, "complexity": 22, "token_count": 505, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "scipy_base/shape_base.py", "new_path": "scipy_base/shape_base.py", "filename": "shape_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -473,11 +473,11 @@ def dsplit(ary,indices_or_sections):\n #-----------------------------------------------------------------------------\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n if __name__ == '__main__':\n", "added_lines": 2, "deleted_lines": 2, "source_code": "import Numeric\nfrom Numeric import *\n\n__all__ = ['atleast_1d','atleast_2d','atleast_3d','vstack','hstack',\n 'column_stack','dstack','array_split','split','hsplit',\n 'vsplit','dsplit','squeeze','apply_over_axes','expand_dims']\n\n\ndef apply_over_axes(func, a, axes):\n \"\"\"Apply a function over multiple axes, keeping the same shape\n for the resulting array.\n \"\"\"\n val = asarray(a)\n N = len(val.shape)\n if not type(axes) in SequenceType:\n axes = (axes,)\n for axis in axes:\n if axis < 0: axis = N + axis\n args = (val, axis)\n val = expand_dims(func(*args),axis)\n return val\n\ndef expand_dims(a, axis):\n \"\"\"Expand the shape of a to include a length 1 dimension before the given\n axis.\n \"\"\"\n a = asarray(a)\n shape = a.shape\n if axis < 0:\n axis = axis + len(shape) + 1\n a.shape = shape[:axis] + (1,) + shape[axis:]\n return a\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n a = asarray(a)\n b = asarray(a.shape)\n return reshape (a, tuple (compress (not_equal (b, 1), b)))\n\ndef atleast_1d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 1D.\n\n Description:\n Force an array to be at least 1D. If an array is 0D, the \n array is converted to a single row of values. Otherwise,\n the array is unaltered.\n Arguments:\n *arys -- arrays to be converted to 1 or more dimensional array.\n Returns:\n input array converted to at least 1D array.\n \"\"\"\n res = []\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0: \n result = Numeric.array([ary[0]])\n else:\n result = ary\n res.append(result)\n if len(res) == 1:\n return res[0]\n else:\n return res\n\ndef atleast_2d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 2D.\n\n Description:\n Force an array to each be at least 2D. If the array\n is 0D or 1D, the array is converted to a single\n row of values. Otherwise, the array is unaltered.\n Arguments:\n arys -- arrays to be converted to 2 or more dimensional array.\n Returns:\n input array converted to at least 2D array.\n \"\"\"\n res = []\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0: \n ary = Numeric.array([ary[0]])\n if len(ary.shape) == 1: \n result = ary[NewAxis,:]\n else: \n result = ary\n res.append(result)\n if len(res) == 1:\n return res[0]\n else:\n return res\n \ndef atleast_3d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 3D.\n\n Description:\n Force an array each be at least 3D. If the array is 0D or 1D, \n the array is converted to a single 1xNx1 array of values where \n N is the orginal length of the array. If the array is 2D, the \n array is converted to a single MxNx1 array of values where MxN\n is the orginal shape of the array. Otherwise, the array is \n unaltered.\n Arguments:\n arys -- arrays to be converted to 3 or more dimensional array.\n Returns:\n input array converted to at least 3D array.\n \"\"\"\n res = []\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0:\n ary = Numeric.array([ary[0]])\n if len(ary.shape) == 1:\n result = ary[NewAxis,:,NewAxis]\n elif len(ary.shape) == 2:\n result = ary[:,:,NewAxis]\n else: \n result = ary\n res.append(result)\n if len(res) == 1:\n return res[0]\n else:\n return res\n\n\ndef vstack(tup):\n \"\"\" Stack arrays in sequence vertically (row wise)\n\n Description:\n Take a sequence of arrays and stack them veritcally\n to make a single array. All arrays in the sequence\n must have the same shape along all but the first axis. \n vstack will rebuild arrays divided by vsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same \n shape.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.vstack((a,b))\n array([[1, 2, 3],\n [2, 3, 4]])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> scipy.vstack((a,b))\n array([[1],\n [2],\n [3],\n [2],\n [3],\n [4]])\n\n \"\"\"\n return Numeric.concatenate(map(atleast_2d,tup),0)\n\ndef hstack(tup):\n \"\"\" Stack arrays in sequence horizontally (column wise)\n\n Description:\n Take a sequence of arrays and stack them horizontally\n to make a single array. All arrays in the sequence\n must have the same shape along all but the second axis.\n hstack will rebuild arrays divided by hsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same \n shape.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.hstack((a,b))\n array([1, 2, 3, 2, 3, 4])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> scipy.hstack((a,b))\n array([[1, 2],\n [2, 3],\n [3, 4]])\n\n \"\"\"\n return Numeric.concatenate(map(atleast_1d,tup),1)\n\ndef column_stack(tup):\n \"\"\" Stack 1D arrays as columns into a 2D array\n\n Description:\n Take a sequence of 1D arrays and stack them as columns\n to make a single 2D array. All arrays in the sequence\n must have the same length.\n Arguments:\n tup -- sequence of 1D arrays. All arrays must have the same \n length.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.vstack((a,b))\n array([[1, 2],\n [2, 3],\n [3, 4]])\n\n \"\"\"\n arrays = map(Numeric.transpose,map(atleast_2d,tup))\n return Numeric.concatenate(arrays,1)\n \ndef dstack(tup):\n \"\"\" Stack arrays in sequence depth wise (along third dimension)\n\n Description:\n Take a sequence of arrays and stack them along the third axis.\n All arrays in the sequence must have the same shape along all \n but the third axis. This is a simple way to stack 2D arrays \n (images) into a single 3D array for processing.\n dstack will rebuild arrays divided by dsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same \n shape.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.dstack((a,b))\n array([ [[1, 2],\n [2, 3],\n [3, 4]]])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> scipy.dstack((a,b))\n array([[ [1, 2]],\n [ [2, 3]],\n [ [3, 4]]])\n \"\"\"\n return Numeric.concatenate(map(atleast_3d,tup),2)\n\ndef _replace_zero_by_x_arrays(sub_arys):\n for i in range(len(sub_arys)):\n if len(Numeric.shape(sub_arys[i])) == 0:\n sub_arys[i] = Numeric.array([])\n elif Numeric.sometrue(Numeric.equal(Numeric.shape(sub_arys[i]),0)):\n sub_arys[i] = Numeric.array([]) \n return sub_arys\n \ndef array_split(ary,indices_or_sections,axis = 0):\n \"\"\" Divide an array into a list of sub-arrays.\n\n Description:\n Divide ary into a list of sub-arrays along the\n specified axis. If indices_or_sections is an integer,\n ary is divided into that many equally sized arrays.\n If it is impossible to make an equal split, each of the\n leading arrays in the list have one additional member. If\n indices_or_sections is a list of sorted integers, its\n entries define the indexes where ary is split.\n\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n axis -- integer. default=0.\n Specifies the axis along which to split ary.\n Caveats:\n Currently, the default for axis is 0. This\n means a 2D array is divided into multiple groups\n of rows. This seems like the appropriate default, but\n we've agreed most other functions should default to\n axis=-1. Perhaps we should use axis=-1 for consistency.\n However, we could also make the argument that SciPy\n works on \"rows\" by default. sum() sums up rows of\n values. split() will split data into rows. Opinions?\n \"\"\"\n try:\n Ntotal = ary.shape[axis]\n except AttributeError:\n Ntotal = len(ary)\n try: # handle scalar case.\n Nsections = len(indices_or_sections) + 1\n div_points = [0] + list(indices_or_sections) + [Ntotal]\n except TypeError: #indices_or_sections is a scalar, not an array.\n Nsections = int(indices_or_sections)\n if Nsections <= 0:\n raise ValueError, 'number sections must be larger than 0.'\n Neach_section,extras = divmod(Ntotal,Nsections)\n section_sizes = [0] + \\\n extras * [Neach_section+1] + \\\n (Nsections-extras) * [Neach_section]\n div_points = Numeric.add.accumulate(Numeric.array(section_sizes))\n\n sub_arys = []\n sary = Numeric.swapaxes(ary,axis,0)\n for i in range(Nsections):\n st = div_points[i]; end = div_points[i+1]\n sub_arys.append(Numeric.swapaxes(sary[st:end],axis,0))\n\n # there is a wierd issue with array slicing that allows\n # 0x10 arrays and other such things. The following cluge is needed\n # to get around this issue.\n sub_arys = _replace_zero_by_x_arrays(sub_arys)\n # end cluge.\n\n return sub_arys\n\ndef split(ary,indices_or_sections,axis=0):\n \"\"\" Divide an array into a list of sub-arrays.\n\n Description:\n Divide ary into a list of sub-arrays along the\n specified axis. If indices_or_sections is an integer,\n ary is divided into that many equally sized arrays.\n If it is impossible to make an equal split, an error is \n raised. This is the only way this function differs from\n the array_split() function. If indices_or_sections is a \n list of sorted integers, its entries define the indexes\n where ary is split.\n\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n axis -- integer. default=0.\n Specifies the axis along which to split ary.\n Caveats:\n Currently, the default for axis is 0. This\n means a 2D array is divided into multiple groups\n of rows. This seems like the appropriate default, but\n we've agreed most other functions should default to\n axis=-1. Perhaps we should use axis=-1 for consistency.\n However, we could also make the argument that SciPy\n works on \"rows\" by default. sum() sums up rows of\n values. split() will split data into rows. Opinions?\n \"\"\"\n try: len(indices_or_sections)\n except TypeError:\n sections = indices_or_sections\n N = ary.shape[axis]\n if N % sections:\n raise ValueError, 'array split does not result in an equal division'\n res = array_split(ary,indices_or_sections,axis)\n return res\n\ndef hsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple columns of sub-arrays\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups of columns. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections. \n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same \n number of dimensions as the input array.\n Related:\n hstack, split, array_split, vsplit, dsplit. \n Examples:\n >>> import scipy\n >>> a= array((1,2,3,4))\n >>> scipy.hsplit(a,2)\n [array([1, 2]), array([3, 4])]\n >>> a = array([[1,2,3,4],[1,2,3,4]])\n [array([[1, 2],\n [1, 2]]), array([[3, 4],\n [3, 4]])]\n \n \"\"\"\n if len(Numeric.shape(ary)) == 0:\n raise ValueError, 'hsplit only works on arrays of 1 or more dimensions'\n if len(ary.shape) > 1:\n return split(ary,indices_or_sections,1)\n else:\n return split(ary,indices_or_sections,0)\n \ndef vsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple rows of sub-arrays\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups of rows. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections.\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same \n number of dimensions as the input array. \n Caveats:\n How should we handle 1D arrays here? I am currently raising\n an error when I encounter them. Any better approach? \n \n Should we reduce the returned array to their minium dimensions\n by getting rid of any dimensions that are 1?\n Related:\n vstack, split, array_split, hsplit, dsplit.\n Examples:\n import scipy\n >>> a = array([[1,2,3,4],\n ... [1,2,3,4]])\n >>> scipy.vsplit(a)\n [array([ [1, 2, 3, 4]]), array([ [1, 2, 3, 4]])]\n \n \"\"\"\n if len(Numeric.shape(ary)) < 2:\n raise ValueError, 'vsplit only works on arrays of 2 or more dimensions'\n return split(ary,indices_or_sections,0)\n\ndef dsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple sub-arrays along the 3rd axis (depth)\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups along the 3rd axis. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections. \n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same \n number of dimensions as the input array.\n Caveats:\n See vsplit caveats. \n Related:\n dstack, split, array_split, hsplit, vsplit.\n Examples:\n >>> a = array([[[1,2,3,4],[1,2,3,4]]])\n [array([ [[1, 2],\n [1, 2]]]), array([ [[3, 4],\n [3, 4]]])]\n \n \"\"\"\n if len(Numeric.shape(ary)) < 3:\n raise ValueError, 'vsplit only works on arrays of 3 or more dimensions'\n return split(ary,indices_or_sections,2)\n\n#-----------------------------------------------------------------------------\n# Test Routines\n#-----------------------------------------------------------------------------\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == '__main__':\n test()\n", "source_code_before": "import Numeric\nfrom Numeric import *\n\n__all__ = ['atleast_1d','atleast_2d','atleast_3d','vstack','hstack',\n 'column_stack','dstack','array_split','split','hsplit',\n 'vsplit','dsplit','squeeze','apply_over_axes','expand_dims']\n\n\ndef apply_over_axes(func, a, axes):\n \"\"\"Apply a function over multiple axes, keeping the same shape\n for the resulting array.\n \"\"\"\n val = asarray(a)\n N = len(val.shape)\n if not type(axes) in SequenceType:\n axes = (axes,)\n for axis in axes:\n if axis < 0: axis = N + axis\n args = (val, axis)\n val = expand_dims(func(*args),axis)\n return val\n\ndef expand_dims(a, axis):\n \"\"\"Expand the shape of a to include a length 1 dimension before the given\n axis.\n \"\"\"\n a = asarray(a)\n shape = a.shape\n if axis < 0:\n axis = axis + len(shape) + 1\n a.shape = shape[:axis] + (1,) + shape[axis:]\n return a\n\ndef squeeze(a):\n \"Returns a with any ones from the shape of a removed\"\n a = asarray(a)\n b = asarray(a.shape)\n return reshape (a, tuple (compress (not_equal (b, 1), b)))\n\ndef atleast_1d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 1D.\n\n Description:\n Force an array to be at least 1D. If an array is 0D, the \n array is converted to a single row of values. Otherwise,\n the array is unaltered.\n Arguments:\n *arys -- arrays to be converted to 1 or more dimensional array.\n Returns:\n input array converted to at least 1D array.\n \"\"\"\n res = []\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0: \n result = Numeric.array([ary[0]])\n else:\n result = ary\n res.append(result)\n if len(res) == 1:\n return res[0]\n else:\n return res\n\ndef atleast_2d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 2D.\n\n Description:\n Force an array to each be at least 2D. If the array\n is 0D or 1D, the array is converted to a single\n row of values. Otherwise, the array is unaltered.\n Arguments:\n arys -- arrays to be converted to 2 or more dimensional array.\n Returns:\n input array converted to at least 2D array.\n \"\"\"\n res = []\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0: \n ary = Numeric.array([ary[0]])\n if len(ary.shape) == 1: \n result = ary[NewAxis,:]\n else: \n result = ary\n res.append(result)\n if len(res) == 1:\n return res[0]\n else:\n return res\n \ndef atleast_3d(*arys):\n \"\"\" Force a sequence of arrays to each be at least 3D.\n\n Description:\n Force an array each be at least 3D. If the array is 0D or 1D, \n the array is converted to a single 1xNx1 array of values where \n N is the orginal length of the array. If the array is 2D, the \n array is converted to a single MxNx1 array of values where MxN\n is the orginal shape of the array. Otherwise, the array is \n unaltered.\n Arguments:\n arys -- arrays to be converted to 3 or more dimensional array.\n Returns:\n input array converted to at least 3D array.\n \"\"\"\n res = []\n for ary in arys:\n ary = asarray(ary)\n if len(ary.shape) == 0:\n ary = Numeric.array([ary[0]])\n if len(ary.shape) == 1:\n result = ary[NewAxis,:,NewAxis]\n elif len(ary.shape) == 2:\n result = ary[:,:,NewAxis]\n else: \n result = ary\n res.append(result)\n if len(res) == 1:\n return res[0]\n else:\n return res\n\n\ndef vstack(tup):\n \"\"\" Stack arrays in sequence vertically (row wise)\n\n Description:\n Take a sequence of arrays and stack them veritcally\n to make a single array. All arrays in the sequence\n must have the same shape along all but the first axis. \n vstack will rebuild arrays divided by vsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same \n shape.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.vstack((a,b))\n array([[1, 2, 3],\n [2, 3, 4]])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> scipy.vstack((a,b))\n array([[1],\n [2],\n [3],\n [2],\n [3],\n [4]])\n\n \"\"\"\n return Numeric.concatenate(map(atleast_2d,tup),0)\n\ndef hstack(tup):\n \"\"\" Stack arrays in sequence horizontally (column wise)\n\n Description:\n Take a sequence of arrays and stack them horizontally\n to make a single array. All arrays in the sequence\n must have the same shape along all but the second axis.\n hstack will rebuild arrays divided by hsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same \n shape.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.hstack((a,b))\n array([1, 2, 3, 2, 3, 4])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> scipy.hstack((a,b))\n array([[1, 2],\n [2, 3],\n [3, 4]])\n\n \"\"\"\n return Numeric.concatenate(map(atleast_1d,tup),1)\n\ndef column_stack(tup):\n \"\"\" Stack 1D arrays as columns into a 2D array\n\n Description:\n Take a sequence of 1D arrays and stack them as columns\n to make a single 2D array. All arrays in the sequence\n must have the same length.\n Arguments:\n tup -- sequence of 1D arrays. All arrays must have the same \n length.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.vstack((a,b))\n array([[1, 2],\n [2, 3],\n [3, 4]])\n\n \"\"\"\n arrays = map(Numeric.transpose,map(atleast_2d,tup))\n return Numeric.concatenate(arrays,1)\n \ndef dstack(tup):\n \"\"\" Stack arrays in sequence depth wise (along third dimension)\n\n Description:\n Take a sequence of arrays and stack them along the third axis.\n All arrays in the sequence must have the same shape along all \n but the third axis. This is a simple way to stack 2D arrays \n (images) into a single 3D array for processing.\n dstack will rebuild arrays divided by dsplit.\n Arguments:\n tup -- sequence of arrays. All arrays must have the same \n shape.\n Examples:\n >>> import scipy\n >>> a = array((1,2,3))\n >>> b = array((2,3,4))\n >>> scipy.dstack((a,b))\n array([ [[1, 2],\n [2, 3],\n [3, 4]]])\n >>> a = array([[1],[2],[3]])\n >>> b = array([[2],[3],[4]])\n >>> scipy.dstack((a,b))\n array([[ [1, 2]],\n [ [2, 3]],\n [ [3, 4]]])\n \"\"\"\n return Numeric.concatenate(map(atleast_3d,tup),2)\n\ndef _replace_zero_by_x_arrays(sub_arys):\n for i in range(len(sub_arys)):\n if len(Numeric.shape(sub_arys[i])) == 0:\n sub_arys[i] = Numeric.array([])\n elif Numeric.sometrue(Numeric.equal(Numeric.shape(sub_arys[i]),0)):\n sub_arys[i] = Numeric.array([]) \n return sub_arys\n \ndef array_split(ary,indices_or_sections,axis = 0):\n \"\"\" Divide an array into a list of sub-arrays.\n\n Description:\n Divide ary into a list of sub-arrays along the\n specified axis. If indices_or_sections is an integer,\n ary is divided into that many equally sized arrays.\n If it is impossible to make an equal split, each of the\n leading arrays in the list have one additional member. If\n indices_or_sections is a list of sorted integers, its\n entries define the indexes where ary is split.\n\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n axis -- integer. default=0.\n Specifies the axis along which to split ary.\n Caveats:\n Currently, the default for axis is 0. This\n means a 2D array is divided into multiple groups\n of rows. This seems like the appropriate default, but\n we've agreed most other functions should default to\n axis=-1. Perhaps we should use axis=-1 for consistency.\n However, we could also make the argument that SciPy\n works on \"rows\" by default. sum() sums up rows of\n values. split() will split data into rows. Opinions?\n \"\"\"\n try:\n Ntotal = ary.shape[axis]\n except AttributeError:\n Ntotal = len(ary)\n try: # handle scalar case.\n Nsections = len(indices_or_sections) + 1\n div_points = [0] + list(indices_or_sections) + [Ntotal]\n except TypeError: #indices_or_sections is a scalar, not an array.\n Nsections = int(indices_or_sections)\n if Nsections <= 0:\n raise ValueError, 'number sections must be larger than 0.'\n Neach_section,extras = divmod(Ntotal,Nsections)\n section_sizes = [0] + \\\n extras * [Neach_section+1] + \\\n (Nsections-extras) * [Neach_section]\n div_points = Numeric.add.accumulate(Numeric.array(section_sizes))\n\n sub_arys = []\n sary = Numeric.swapaxes(ary,axis,0)\n for i in range(Nsections):\n st = div_points[i]; end = div_points[i+1]\n sub_arys.append(Numeric.swapaxes(sary[st:end],axis,0))\n\n # there is a wierd issue with array slicing that allows\n # 0x10 arrays and other such things. The following cluge is needed\n # to get around this issue.\n sub_arys = _replace_zero_by_x_arrays(sub_arys)\n # end cluge.\n\n return sub_arys\n\ndef split(ary,indices_or_sections,axis=0):\n \"\"\" Divide an array into a list of sub-arrays.\n\n Description:\n Divide ary into a list of sub-arrays along the\n specified axis. If indices_or_sections is an integer,\n ary is divided into that many equally sized arrays.\n If it is impossible to make an equal split, an error is \n raised. This is the only way this function differs from\n the array_split() function. If indices_or_sections is a \n list of sorted integers, its entries define the indexes\n where ary is split.\n\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n axis -- integer. default=0.\n Specifies the axis along which to split ary.\n Caveats:\n Currently, the default for axis is 0. This\n means a 2D array is divided into multiple groups\n of rows. This seems like the appropriate default, but\n we've agreed most other functions should default to\n axis=-1. Perhaps we should use axis=-1 for consistency.\n However, we could also make the argument that SciPy\n works on \"rows\" by default. sum() sums up rows of\n values. split() will split data into rows. Opinions?\n \"\"\"\n try: len(indices_or_sections)\n except TypeError:\n sections = indices_or_sections\n N = ary.shape[axis]\n if N % sections:\n raise ValueError, 'array split does not result in an equal division'\n res = array_split(ary,indices_or_sections,axis)\n return res\n\ndef hsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple columns of sub-arrays\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups of columns. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections. \n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same \n number of dimensions as the input array.\n Related:\n hstack, split, array_split, vsplit, dsplit. \n Examples:\n >>> import scipy\n >>> a= array((1,2,3,4))\n >>> scipy.hsplit(a,2)\n [array([1, 2]), array([3, 4])]\n >>> a = array([[1,2,3,4],[1,2,3,4]])\n [array([[1, 2],\n [1, 2]]), array([[3, 4],\n [3, 4]])]\n \n \"\"\"\n if len(Numeric.shape(ary)) == 0:\n raise ValueError, 'hsplit only works on arrays of 1 or more dimensions'\n if len(ary.shape) > 1:\n return split(ary,indices_or_sections,1)\n else:\n return split(ary,indices_or_sections,0)\n \ndef vsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple rows of sub-arrays\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups of rows. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections.\n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same \n number of dimensions as the input array. \n Caveats:\n How should we handle 1D arrays here? I am currently raising\n an error when I encounter them. Any better approach? \n \n Should we reduce the returned array to their minium dimensions\n by getting rid of any dimensions that are 1?\n Related:\n vstack, split, array_split, hsplit, dsplit.\n Examples:\n import scipy\n >>> a = array([[1,2,3,4],\n ... [1,2,3,4]])\n >>> scipy.vsplit(a)\n [array([ [1, 2, 3, 4]]), array([ [1, 2, 3, 4]])]\n \n \"\"\"\n if len(Numeric.shape(ary)) < 2:\n raise ValueError, 'vsplit only works on arrays of 2 or more dimensions'\n return split(ary,indices_or_sections,0)\n\ndef dsplit(ary,indices_or_sections):\n \"\"\" Split ary into multiple sub-arrays along the 3rd axis (depth)\n\n Description:\n Split a single array into multiple sub arrays. The array is\n divided into groups along the 3rd axis. If indices_or_sections is\n an integer, ary is divided into that many equally sized sub arrays.\n If it is impossible to make the sub-arrays equally sized, the\n operation throws a ValueError exception. See array_split and\n split for other options on indices_or_sections. \n Arguments:\n ary -- N-D array.\n Array to be divided into sub-arrays.\n indices_or_sections -- integer or 1D array.\n If integer, defines the number of (close to) equal sized\n sub-arrays. If it is a 1D array of sorted indices, it\n defines the indexes at which ary is divided. Any empty\n list results in a single sub-array equal to the original\n array.\n Returns:\n sequence of sub-arrays. The returned arrays have the same \n number of dimensions as the input array.\n Caveats:\n See vsplit caveats. \n Related:\n dstack, split, array_split, hsplit, vsplit.\n Examples:\n >>> a = array([[[1,2,3,4],[1,2,3,4]]])\n [array([ [[1, 2],\n [1, 2]]]), array([ [[3, 4],\n [3, 4]]])]\n \n \"\"\"\n if len(Numeric.shape(ary)) < 3:\n raise ValueError, 'vsplit only works on arrays of 3 or more dimensions'\n return split(ary,indices_or_sections,2)\n\n#-----------------------------------------------------------------------------\n# Test Routines\n#-----------------------------------------------------------------------------\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == '__main__':\n test()\n", "methods": [ { "name": "apply_over_axes", "long_name": "apply_over_axes( func , a , axes )", "filename": "shape_base.py", "nloc": 10, "complexity": 4, "token_count": 75, "parameters": [ "func", "a", "axes" ], "start_line": 9, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "expand_dims", "long_name": "expand_dims( a , axis )", "filename": "shape_base.py", "nloc": 7, "complexity": 2, "token_count": 56, "parameters": [ "a", "axis" ], "start_line": 23, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "squeeze", "long_name": "squeeze( a )", "filename": "shape_base.py", "nloc": 5, "complexity": 1, "token_count": 40, "parameters": [ "a" ], "start_line": 34, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "atleast_1d", "long_name": "atleast_1d( * arys )", "filename": "shape_base.py", "nloc": 13, "complexity": 4, "token_count": 73, "parameters": [ "arys" ], "start_line": 40, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "atleast_2d", "long_name": "atleast_2d( * arys )", "filename": "shape_base.py", "nloc": 15, "complexity": 5, "token_count": 91, "parameters": [ "arys" ], "start_line": 65, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "atleast_3d", "long_name": "atleast_3d( * arys )", "filename": "shape_base.py", "nloc": 17, "complexity": 6, "token_count": 113, "parameters": [ "arys" ], "start_line": 92, "end_line": 122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "vstack", "long_name": "vstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 125, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 0 }, { "name": "hstack", "long_name": "hstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 156, "end_line": 181, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "column_stack", "long_name": "column_stack( tup )", "filename": "shape_base.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "tup" ], "start_line": 183, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "dstack", "long_name": "dstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 206, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_replace_zero_by_x_arrays", "long_name": "_replace_zero_by_x_arrays( sub_arys )", "filename": "shape_base.py", "nloc": 7, "complexity": 4, "token_count": 81, "parameters": [ "sub_arys" ], "start_line": 235, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "array_split", "long_name": "array_split( ary , indices_or_sections , axis = 0 )", "filename": "shape_base.py", "nloc": 24, "complexity": 5, "token_count": 190, "parameters": [ "ary", "indices_or_sections", "axis" ], "start_line": 243, "end_line": 305, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 63, "top_nesting_level": 0 }, { "name": "split", "long_name": "split( ary , indices_or_sections , axis = 0 )", "filename": "shape_base.py", "nloc": 9, "complexity": 3, "token_count": 53, "parameters": [ "ary", "indices_or_sections", "axis" ], "start_line": 307, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 0 }, { "name": "hsplit", "long_name": "hsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 7, "complexity": 3, "token_count": 55, "parameters": [ "ary", "indices_or_sections" ], "start_line": 350, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 0 }, { "name": "vsplit", "long_name": "vsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 4, "complexity": 2, "token_count": 34, "parameters": [ "ary", "indices_or_sections" ], "start_line": 392, "end_line": 432, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 0 }, { "name": "dsplit", "long_name": "dsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 4, "complexity": 2, "token_count": 34, "parameters": [ "ary", "indices_or_sections" ], "start_line": 434, "end_line": 469, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "shape_base.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 475, "end_line": 477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "shape_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 479, "end_line": 481, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "apply_over_axes", "long_name": "apply_over_axes( func , a , axes )", "filename": "shape_base.py", "nloc": 10, "complexity": 4, "token_count": 75, "parameters": [ "func", "a", "axes" ], "start_line": 9, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "expand_dims", "long_name": "expand_dims( a , axis )", "filename": "shape_base.py", "nloc": 7, "complexity": 2, "token_count": 56, "parameters": [ "a", "axis" ], "start_line": 23, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "squeeze", "long_name": "squeeze( a )", "filename": "shape_base.py", "nloc": 5, "complexity": 1, "token_count": 40, "parameters": [ "a" ], "start_line": 34, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "atleast_1d", "long_name": "atleast_1d( * arys )", "filename": "shape_base.py", "nloc": 13, "complexity": 4, "token_count": 73, "parameters": [ "arys" ], "start_line": 40, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "atleast_2d", "long_name": "atleast_2d( * arys )", "filename": "shape_base.py", "nloc": 15, "complexity": 5, "token_count": 91, "parameters": [ "arys" ], "start_line": 65, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "atleast_3d", "long_name": "atleast_3d( * arys )", "filename": "shape_base.py", "nloc": 17, "complexity": 6, "token_count": 113, "parameters": [ "arys" ], "start_line": 92, "end_line": 122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "vstack", "long_name": "vstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 125, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 30, "top_nesting_level": 0 }, { "name": "hstack", "long_name": "hstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 156, "end_line": 181, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "column_stack", "long_name": "column_stack( tup )", "filename": "shape_base.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "tup" ], "start_line": 183, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "dstack", "long_name": "dstack( tup )", "filename": "shape_base.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "tup" ], "start_line": 206, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "_replace_zero_by_x_arrays", "long_name": "_replace_zero_by_x_arrays( sub_arys )", "filename": "shape_base.py", "nloc": 7, "complexity": 4, "token_count": 81, "parameters": [ "sub_arys" ], "start_line": 235, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "array_split", "long_name": "array_split( ary , indices_or_sections , axis = 0 )", "filename": "shape_base.py", "nloc": 24, "complexity": 5, "token_count": 190, "parameters": [ "ary", "indices_or_sections", "axis" ], "start_line": 243, "end_line": 305, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 63, "top_nesting_level": 0 }, { "name": "split", "long_name": "split( ary , indices_or_sections , axis = 0 )", "filename": "shape_base.py", "nloc": 9, "complexity": 3, "token_count": 53, "parameters": [ "ary", "indices_or_sections", "axis" ], "start_line": 307, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 0 }, { "name": "hsplit", "long_name": "hsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 7, "complexity": 3, "token_count": 55, "parameters": [ "ary", "indices_or_sections" ], "start_line": 350, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 0 }, { "name": "vsplit", "long_name": "vsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 4, "complexity": 2, "token_count": 34, "parameters": [ "ary", "indices_or_sections" ], "start_line": 392, "end_line": 432, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 0 }, { "name": "dsplit", "long_name": "dsplit( ary , indices_or_sections )", "filename": "shape_base.py", "nloc": 4, "complexity": 2, "token_count": 34, "parameters": [ "ary", "indices_or_sections" ], "start_line": 434, "end_line": 469, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "shape_base.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 475, "end_line": 477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "shape_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 479, "end_line": 481, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "shape_base.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 479, "end_line": 481, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "shape_base.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 475, "end_line": 477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 144, "complexity": 47, "token_count": 1097, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "scipy_base/tests/test_function_base.py", "new_path": "scipy_base/tests/test_function_base.py", "filename": "test_function_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -3,8 +3,8 @@\n sys.path.insert(0,'../..')\n \n import unittest\n-from scipy_base.testing import assert_array_equal, assert_equal, rand\n-from scipy_base.testing import assert_almost_equal, assert_array_almost_equal \n+from scipy_test.testing import assert_array_equal, assert_equal, rand\n+from scipy_test.testing import assert_almost_equal, assert_array_almost_equal \n \n from scipy_base import *\n # This won't be needed when we get scipy_base finished.\n", "added_lines": 2, "deleted_lines": 2, "source_code": "# only for short term testing\nimport sys\nsys.path.insert(0,'../..')\n\nimport unittest\nfrom scipy_test.testing import assert_array_equal, assert_equal, rand\nfrom scipy_test.testing import assert_almost_equal, assert_array_almost_equal \n\nfrom scipy_base import *\n# This won't be needed when we get scipy_base finished.\nfrom scipy_base.index_tricks import *\nfrom scipy_base.function_base import *\n\n\nclass test_any(unittest.TestCase):\n def check_basic(self):\n y1 = [0,0,1,0]\n y2 = [0,0,0,0]\n y3 = [1,0,1,0]\n assert(any(y1))\n assert(any(y3))\n assert(not any(y2))\n\n def check_nd(self):\n y1 = [[0,0,0],[0,1,0],[1,1,0]]\n assert_array_equal(any(y1),[1,1,0])\n assert_array_equal(any(y1,axis=1),[0,1,1])\n \nclass test_all(unittest.TestCase):\n def check_basic(self):\n y1 = [0,1,1,0]\n y2 = [0,0,0,0]\n y3 = [1,1,1,1]\n assert(not all(y1))\n assert(all(y3))\n assert(not all(y2))\n assert(all(~array(y2)))\n\n def check_nd(self):\n y1 = [[0,0,1],[0,1,1],[1,1,1]]\n assert_array_equal(all(y1),[0,0,1])\n assert_array_equal(all(y1,axis=1),[0,0,1])\n\nclass test_logspace(unittest.TestCase):\n def check_basic(self):\n y = logspace(0,6)\n assert(len(y)==50)\n y = logspace(0,6,num=100)\n assert(y[-1] == 10**6)\n y = logspace(0,6,endpoint=0)\n assert(y[-1] < 10**6)\n y = logspace(0,6,num=7)\n assert_array_equal(y,[1,10,100,1e3,1e4,1e5,1e6])\n\nclass test_linspace(unittest.TestCase):\n def check_basic(self):\n y = linspace(0,10)\n assert(len(y)==50)\n y = linspace(2,10,num=100)\n assert(y[-1] == 10)\n y = linspace(2,10,endpoint=0)\n assert(y[-1] < 10)\n y,st = linspace(2,10,retstep=1)\n assert_almost_equal(st,8/49.0)\n assert_array_almost_equal(y,mgrid[2:10:50j],13)\n\nclass test_amax(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amax(a),10.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amax(b),[8.0,10.0,9.0])\n assert_equal(amax(b,axis=1),[9.0,10.0,8.0])\n \nclass test_amin(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amin(a),-5.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amin(b),[3.0,3.0,2.0])\n assert_equal(amin(b,axis=1),[3.0,4.0,2.0])\n\nclass test_ptp(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(ptp(a),15.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(ptp(b,axis=0),[5.0,7.0,7.0])\n assert_equal(ptp(b),[6.0,6.0,6.0])\n\nclass test_cumsum(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n assert_array_equal(cumsum(a), array([1,3,13,24,30,35,39],ctype))\n assert_array_equal(cumsum(a2,axis=0), array([[1,2,3,4],[6,8,10,13],\n [16,11,14,18]],ctype))\n assert_array_equal(cumsum(a2,axis=1),\n array([[1,3,6,10],\n [5,11,18,27],\n [10,13,17,22]],ctype))\n\nclass test_prod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, prod, a)\n self.failUnlessRaises(ArithmeticError, prod, a2, 1)\n self.failUnlessRaises(ArithmeticError, prod, a)\n else: \n assert_equal(prod(a),26400)\n assert_array_equal(prod(a2,axis=0), \n array([50,36,84,180],ctype))\n assert_array_equal(prod(a2),array([24, 1890, 600],ctype))\n\nclass test_cumprod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n self.failUnlessRaises(ArithmeticError, cumprod, a2, 1)\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n else: \n assert_array_equal(cumprod(a),\n array([1, 2, 20, 220,\n 1320, 6600, 26400],ctype))\n assert_array_equal(cumprod(a2,axis=0),\n array([[ 1, 2, 3, 4],\n [ 5, 12, 21, 36],\n [50, 36, 84, 180]],ctype))\n assert_array_equal(cumprod(a2),\n array([[ 1, 2, 6, 24],\n [ 5, 30, 210, 1890],\n [10, 30, 120, 600]],ctype))\n\nclass test_diff(unittest.TestCase):\n def check_basic(self):\n x = [1,4,6,7,12]\n out = array([3,2,1,5])\n out2 = array([-1,-1,4])\n out3 = array([0,5])\n assert_array_equal(diff(x),out)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,n=3),out3)\n\n def check_nd(self):\n x = 20*rand(10,20,30)\n out1 = x[:,:,1:] - x[:,:,:-1]\n out2 = out1[:,:,1:] - out1[:,:,:-1]\n out3 = x[1:,:,:] - x[:-1,:,:]\n out4 = out3[1:,:,:] - out3[:-1,:,:]\n assert_array_equal(diff(x),out1)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,axis=0),out3)\n assert_array_equal(diff(x,n=2,axis=0),out4)\n\nclass test_angle(unittest.TestCase):\n def check_basic(self):\n x = [1+3j,sqrt(2)/2.0+1j*sqrt(2)/2,1,1j,-1,-1j,1-3j,-1+3j]\n y = angle(x)\n yo = [arctan(3.0/1.0),arctan(1.0),0,pi/2,pi,-pi/2.0,\n -arctan(3.0/1.0),pi-arctan(3.0/1.0)]\n z = angle(x,deg=1)\n zo = array(yo)*180/pi\n assert_array_almost_equal(y,yo,11)\n assert_array_almost_equal(z,zo,11)\n\nclass test_trim_zeros(unittest.TestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_basic(self):\n a= array([0,0,1,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,2,3,4]))\n def check_leading_skip(self):\n a= array([0,0,1,0,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,4]))\n def check_trailing_skip(self):\n a= array([0,0,1,0,2,3,0,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,0,4]))\n \n# Utility\n\ndef compare_results(res,desired):\n for i in range(len(desired)):\n assert_array_equal(res[i],desired[i])\n\n\n#-----------------------------------------------------------------------------\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_linspace,'check_') )\n suites.append( unittest.makeSuite(test_logspace,'check_') )\n suites.append( unittest.makeSuite(test_all,'check_') )\n suites.append( unittest.makeSuite(test_any,'check_') )\n\n suites.append( unittest.makeSuite(test_amax,'check_') )\n suites.append( unittest.makeSuite(test_amin,'check_') )\n suites.append( unittest.makeSuite(test_ptp,'check_') ) \n\n suites.append( unittest.makeSuite(test_cumsum,'check_') )\n suites.append( unittest.makeSuite(test_prod,'check_') )\n suites.append( unittest.makeSuite(test_cumprod,'check_') )\n suites.append( unittest.makeSuite(test_diff,'check_') )\n\n suites.append( unittest.makeSuite(test_angle,'check_') )\n \n suites.append( unittest.makeSuite(test_trim_zeros,'check_') )\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\n\nif __name__ == \"__main__\":\n test()\n", "source_code_before": "# only for short term testing\nimport sys\nsys.path.insert(0,'../..')\n\nimport unittest\nfrom scipy_base.testing import assert_array_equal, assert_equal, rand\nfrom scipy_base.testing import assert_almost_equal, assert_array_almost_equal \n\nfrom scipy_base import *\n# This won't be needed when we get scipy_base finished.\nfrom scipy_base.index_tricks import *\nfrom scipy_base.function_base import *\n\n\nclass test_any(unittest.TestCase):\n def check_basic(self):\n y1 = [0,0,1,0]\n y2 = [0,0,0,0]\n y3 = [1,0,1,0]\n assert(any(y1))\n assert(any(y3))\n assert(not any(y2))\n\n def check_nd(self):\n y1 = [[0,0,0],[0,1,0],[1,1,0]]\n assert_array_equal(any(y1),[1,1,0])\n assert_array_equal(any(y1,axis=1),[0,1,1])\n \nclass test_all(unittest.TestCase):\n def check_basic(self):\n y1 = [0,1,1,0]\n y2 = [0,0,0,0]\n y3 = [1,1,1,1]\n assert(not all(y1))\n assert(all(y3))\n assert(not all(y2))\n assert(all(~array(y2)))\n\n def check_nd(self):\n y1 = [[0,0,1],[0,1,1],[1,1,1]]\n assert_array_equal(all(y1),[0,0,1])\n assert_array_equal(all(y1,axis=1),[0,0,1])\n\nclass test_logspace(unittest.TestCase):\n def check_basic(self):\n y = logspace(0,6)\n assert(len(y)==50)\n y = logspace(0,6,num=100)\n assert(y[-1] == 10**6)\n y = logspace(0,6,endpoint=0)\n assert(y[-1] < 10**6)\n y = logspace(0,6,num=7)\n assert_array_equal(y,[1,10,100,1e3,1e4,1e5,1e6])\n\nclass test_linspace(unittest.TestCase):\n def check_basic(self):\n y = linspace(0,10)\n assert(len(y)==50)\n y = linspace(2,10,num=100)\n assert(y[-1] == 10)\n y = linspace(2,10,endpoint=0)\n assert(y[-1] < 10)\n y,st = linspace(2,10,retstep=1)\n assert_almost_equal(st,8/49.0)\n assert_array_almost_equal(y,mgrid[2:10:50j],13)\n\nclass test_amax(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amax(a),10.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amax(b),[8.0,10.0,9.0])\n assert_equal(amax(b,axis=1),[9.0,10.0,8.0])\n \nclass test_amin(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(amin(a),-5.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(amin(b),[3.0,3.0,2.0])\n assert_equal(amin(b,axis=1),[3.0,4.0,2.0])\n\nclass test_ptp(unittest.TestCase):\n def check_basic(self):\n a = [3,4,5,10,-3,-5,6.0]\n assert_equal(ptp(a),15.0)\n b = [[3,6.0, 9.0],\n [4,10.0,5.0],\n [8,3.0,2.0]]\n assert_equal(ptp(b,axis=0),[5.0,7.0,7.0])\n assert_equal(ptp(b),[6.0,6.0,6.0])\n\nclass test_cumsum(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n assert_array_equal(cumsum(a), array([1,3,13,24,30,35,39],ctype))\n assert_array_equal(cumsum(a2,axis=0), array([[1,2,3,4],[6,8,10,13],\n [16,11,14,18]],ctype))\n assert_array_equal(cumsum(a2,axis=1),\n array([[1,3,6,10],\n [5,11,18,27],\n [10,13,17,22]],ctype))\n\nclass test_prod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, prod, a)\n self.failUnlessRaises(ArithmeticError, prod, a2, 1)\n self.failUnlessRaises(ArithmeticError, prod, a)\n else: \n assert_equal(prod(a),26400)\n assert_array_equal(prod(a2,axis=0), \n array([50,36,84,180],ctype))\n assert_array_equal(prod(a2),array([24, 1890, 600],ctype))\n\nclass test_cumprod(unittest.TestCase):\n def check_basic(self):\n ba = [1,2,10,11,6,5,4]\n ba2 = [[1,2,3,4],[5,6,7,9],[10,3,4,5]]\n for ctype in ['1','b','s','i','l','f','d','F','D']:\n a = array(ba,ctype)\n a2 = array(ba2,ctype)\n if ctype in ['1', 'b']:\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n self.failUnlessRaises(ArithmeticError, cumprod, a2, 1)\n self.failUnlessRaises(ArithmeticError, cumprod, a)\n else: \n assert_array_equal(cumprod(a),\n array([1, 2, 20, 220,\n 1320, 6600, 26400],ctype))\n assert_array_equal(cumprod(a2,axis=0),\n array([[ 1, 2, 3, 4],\n [ 5, 12, 21, 36],\n [50, 36, 84, 180]],ctype))\n assert_array_equal(cumprod(a2),\n array([[ 1, 2, 6, 24],\n [ 5, 30, 210, 1890],\n [10, 30, 120, 600]],ctype))\n\nclass test_diff(unittest.TestCase):\n def check_basic(self):\n x = [1,4,6,7,12]\n out = array([3,2,1,5])\n out2 = array([-1,-1,4])\n out3 = array([0,5])\n assert_array_equal(diff(x),out)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,n=3),out3)\n\n def check_nd(self):\n x = 20*rand(10,20,30)\n out1 = x[:,:,1:] - x[:,:,:-1]\n out2 = out1[:,:,1:] - out1[:,:,:-1]\n out3 = x[1:,:,:] - x[:-1,:,:]\n out4 = out3[1:,:,:] - out3[:-1,:,:]\n assert_array_equal(diff(x),out1)\n assert_array_equal(diff(x,n=2),out2)\n assert_array_equal(diff(x,axis=0),out3)\n assert_array_equal(diff(x,n=2,axis=0),out4)\n\nclass test_angle(unittest.TestCase):\n def check_basic(self):\n x = [1+3j,sqrt(2)/2.0+1j*sqrt(2)/2,1,1j,-1,-1j,1-3j,-1+3j]\n y = angle(x)\n yo = [arctan(3.0/1.0),arctan(1.0),0,pi/2,pi,-pi/2.0,\n -arctan(3.0/1.0),pi-arctan(3.0/1.0)]\n z = angle(x,deg=1)\n zo = array(yo)*180/pi\n assert_array_almost_equal(y,yo,11)\n assert_array_almost_equal(z,zo,11)\n\nclass test_trim_zeros(unittest.TestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_basic(self):\n a= array([0,0,1,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,2,3,4]))\n def check_leading_skip(self):\n a= array([0,0,1,0,2,3,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,4]))\n def check_trailing_skip(self):\n a= array([0,0,1,0,2,3,0,4,0])\n res = trim_zeros(a)\n assert_array_equal(res,array([1,0,2,3,0,4]))\n \n# Utility\n\ndef compare_results(res,desired):\n for i in range(len(desired)):\n assert_array_equal(res[i],desired[i])\n\n\n#-----------------------------------------------------------------------------\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_linspace,'check_') )\n suites.append( unittest.makeSuite(test_logspace,'check_') )\n suites.append( unittest.makeSuite(test_all,'check_') )\n suites.append( unittest.makeSuite(test_any,'check_') )\n\n suites.append( unittest.makeSuite(test_amax,'check_') )\n suites.append( unittest.makeSuite(test_amin,'check_') )\n suites.append( unittest.makeSuite(test_ptp,'check_') ) \n\n suites.append( unittest.makeSuite(test_cumsum,'check_') )\n suites.append( unittest.makeSuite(test_prod,'check_') )\n suites.append( unittest.makeSuite(test_cumprod,'check_') )\n suites.append( unittest.makeSuite(test_diff,'check_') )\n\n suites.append( unittest.makeSuite(test_angle,'check_') )\n \n suites.append( unittest.makeSuite(test_trim_zeros,'check_') )\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 7, "complexity": 1, "token_count": 60, "parameters": [ "self" ], "start_line": 16, "end_line": 22, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 66, "parameters": [ "self" ], "start_line": 24, "end_line": 27, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 72, "parameters": [ "self" ], "start_line": 30, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 66, "parameters": [ "self" ], "start_line": 39, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 102, "parameters": [ "self" ], "start_line": 45, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 56, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 122, "parameters": [ "self" ], "start_line": 68, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 123, "parameters": [ "self" ], "start_line": 78, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 122, "parameters": [ "self" ], "start_line": 88, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 13, "complexity": 2, "token_count": 218, "parameters": [ "self" ], "start_line": 98, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 15, "complexity": 3, "token_count": 192, "parameters": [ "self" ], "start_line": 113, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 22, "complexity": 3, "token_count": 257, "parameters": [ "self" ], "start_line": 130, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 91, "parameters": [ "self" ], "start_line": 154, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 157, "parameters": [ "self" ], "start_line": 163, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 152, "parameters": [ "self" ], "start_line": 175, "end_line": 183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 188, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_leading_skip", "long_name": "check_leading_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 192, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_trailing_skip", "long_name": "check_trailing_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 196, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "compare_results", "long_name": "compare_results( res , desired )", "filename": "test_function_base.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "res", "desired" ], "start_line": 203, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_function_base.py", "nloc": 18, "complexity": 2, "token_count": 195, "parameters": [ "level" ], "start_line": 210, "end_line": 232, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 234, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 7, "complexity": 1, "token_count": 60, "parameters": [ "self" ], "start_line": 16, "end_line": 22, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 66, "parameters": [ "self" ], "start_line": 24, "end_line": 27, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 72, "parameters": [ "self" ], "start_line": 30, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 66, "parameters": [ "self" ], "start_line": 39, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 102, "parameters": [ "self" ], "start_line": 45, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 56, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 122, "parameters": [ "self" ], "start_line": 68, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 123, "parameters": [ "self" ], "start_line": 78, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 122, "parameters": [ "self" ], "start_line": 88, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 13, "complexity": 2, "token_count": 218, "parameters": [ "self" ], "start_line": 98, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 15, "complexity": 3, "token_count": 192, "parameters": [ "self" ], "start_line": 113, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 22, "complexity": 3, "token_count": 257, "parameters": [ "self" ], "start_line": 130, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 8, "complexity": 1, "token_count": 91, "parameters": [ "self" ], "start_line": 154, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_function_base.py", "nloc": 10, "complexity": 1, "token_count": 157, "parameters": [ "self" ], "start_line": 163, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 9, "complexity": 1, "token_count": 152, "parameters": [ "self" ], "start_line": 175, "end_line": 183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 188, "end_line": 191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_leading_skip", "long_name": "check_leading_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 192, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_trailing_skip", "long_name": "check_trailing_skip( self )", "filename": "test_function_base.py", "nloc": 4, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 196, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "compare_results", "long_name": "compare_results( res , desired )", "filename": "test_function_base.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "res", "desired" ], "start_line": 203, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_function_base.py", "nloc": 18, "complexity": 2, "token_count": 195, "parameters": [ "level" ], "start_line": 210, "end_line": 232, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_function_base.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 234, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 206, "complexity": 28, "token_count": 2496, "diff_parsed": { "added": [ "from scipy_test.testing import assert_array_equal, assert_equal, rand", "from scipy_test.testing import assert_almost_equal, assert_array_almost_equal" ], "deleted": [ "from scipy_base.testing import assert_array_equal, assert_equal, rand", "from scipy_base.testing import assert_almost_equal, assert_array_almost_equal" ] } }, { "old_path": "scipy_base/tests/test_index_tricks.py", "new_path": "scipy_base/tests/test_index_tricks.py", "filename": "test_index_tricks.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,6 +1,6 @@\n import unittest\n-from scipy_base.testing import assert_array_equal, assert_equal, rand\n-from scipy_base.testing import assert_almost_equal, assert_array_almost_equal\n+from scipy_test.testing import assert_array_equal, assert_equal, rand\n+from scipy_test.testing import assert_almost_equal, assert_array_almost_equal\n from scipy_base import *\n \n class test_grid(unittest.TestCase):\n", "added_lines": 2, "deleted_lines": 2, "source_code": "import unittest\nfrom scipy_test.testing import assert_array_equal, assert_equal, rand\nfrom scipy_test.testing import assert_almost_equal, assert_array_almost_equal\nfrom scipy_base import *\n\nclass test_grid(unittest.TestCase):\n def check_basic(self):\n a = mgrid[-1:1:10j]\n b = mgrid[-1:1:0.1]\n assert(a.shape == (10,))\n assert(b.shape == (20,))\n assert(a[0] == -1)\n assert_almost_equal(a[-1],1)\n assert(b[0] == -1)\n assert_almost_equal(b[1]-b[0],0.1,11)\n assert_almost_equal(b[-1],b[0]+19*0.1,11)\n assert_almost_equal(a[1]-a[0],2.0/9.0,11)\n\n def check_nd(self):\n c = mgrid[-1:1:10j,-2:2:10j]\n d = mgrid[-1:1:0.1,-2:2:0.2]\n assert(c.shape == (2,10,10))\n assert(d.shape == (2,20,20))\n assert_array_equal(c[0][0,:],-ones(10,'d'))\n assert_array_equal(c[1][:,0],-2*ones(10,'d'))\n assert_array_almost_equal(c[0][-1,:],ones(10,'d'),11)\n assert_array_almost_equal(c[1][:,-1],2*ones(10,'d'),11)\n assert_array_almost_equal(d[0,1,:]-d[0,0,:], 0.1*ones(20,'d'),11)\n assert_array_almost_equal(d[1,:,1]-d[1,:,0], 0.2*ones(20,'d'),11)\n\nclass test_concatenator(unittest.TestCase):\n def check_1d(self):\n assert_array_equal(r_[1,2,3,4,5,6],array([1,2,3,4,5,6]))\n b = ones(5)\n c = r_[b,0,0,b]\n assert_array_equal(c,[1,1,1,1,1,0,0,1,1,1,1,1])\n c = c_[b,0,0,b]\n assert_array_equal(c,[1,1,1,1,1,0,0,1,1,1,1,1])\n\n def check_2d(self):\n b = rand(5,5)\n c = rand(5,5)\n d = c_[b,c] # append columns\n assert(d.shape == (5,10))\n assert_array_equal(d[:,:5],b)\n assert_array_equal(d[:,5:],c)\n d = r_[b,c]\n assert(d.shape == (10,5))\n assert_array_equal(d[:5,:],b)\n assert_array_equal(d[5:,:],c)\n\n#-----------------------------------------------------------------------------\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_grid,'check_') )\n suites.append( unittest.makeSuite(test_concatenator,'check_') )\n \n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\n\nif __name__ == \"__main__\":\n test()", "source_code_before": "import unittest\nfrom scipy_base.testing import assert_array_equal, assert_equal, rand\nfrom scipy_base.testing import assert_almost_equal, assert_array_almost_equal\nfrom scipy_base import *\n\nclass test_grid(unittest.TestCase):\n def check_basic(self):\n a = mgrid[-1:1:10j]\n b = mgrid[-1:1:0.1]\n assert(a.shape == (10,))\n assert(b.shape == (20,))\n assert(a[0] == -1)\n assert_almost_equal(a[-1],1)\n assert(b[0] == -1)\n assert_almost_equal(b[1]-b[0],0.1,11)\n assert_almost_equal(b[-1],b[0]+19*0.1,11)\n assert_almost_equal(a[1]-a[0],2.0/9.0,11)\n\n def check_nd(self):\n c = mgrid[-1:1:10j,-2:2:10j]\n d = mgrid[-1:1:0.1,-2:2:0.2]\n assert(c.shape == (2,10,10))\n assert(d.shape == (2,20,20))\n assert_array_equal(c[0][0,:],-ones(10,'d'))\n assert_array_equal(c[1][:,0],-2*ones(10,'d'))\n assert_array_almost_equal(c[0][-1,:],ones(10,'d'),11)\n assert_array_almost_equal(c[1][:,-1],2*ones(10,'d'),11)\n assert_array_almost_equal(d[0,1,:]-d[0,0,:], 0.1*ones(20,'d'),11)\n assert_array_almost_equal(d[1,:,1]-d[1,:,0], 0.2*ones(20,'d'),11)\n\nclass test_concatenator(unittest.TestCase):\n def check_1d(self):\n assert_array_equal(r_[1,2,3,4,5,6],array([1,2,3,4,5,6]))\n b = ones(5)\n c = r_[b,0,0,b]\n assert_array_equal(c,[1,1,1,1,1,0,0,1,1,1,1,1])\n c = c_[b,0,0,b]\n assert_array_equal(c,[1,1,1,1,1,0,0,1,1,1,1,1])\n\n def check_2d(self):\n b = rand(5,5)\n c = rand(5,5)\n d = c_[b,c] # append columns\n assert(d.shape == (5,10))\n assert_array_equal(d[:,:5],b)\n assert_array_equal(d[:,5:],c)\n d = r_[b,c]\n assert(d.shape == (10,5))\n assert_array_equal(d[:5,:],b)\n assert_array_equal(d[5:,:],c)\n\n#-----------------------------------------------------------------------------\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_grid,'check_') )\n suites.append( unittest.makeSuite(test_concatenator,'check_') )\n \n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\n\nif __name__ == \"__main__\":\n test()", "methods": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_index_tricks.py", "nloc": 11, "complexity": 1, "token_count": 142, "parameters": [ "self" ], "start_line": 7, "end_line": 17, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_index_tricks.py", "nloc": 11, "complexity": 1, "token_count": 227, "parameters": [ "self" ], "start_line": 19, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_1d", "long_name": "check_1d( self )", "filename": "test_index_tricks.py", "nloc": 7, "complexity": 1, "token_count": 129, "parameters": [ "self" ], "start_line": 32, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_2d", "long_name": "check_2d( self )", "filename": "test_index_tricks.py", "nloc": 11, "complexity": 1, "token_count": 109, "parameters": [ "self" ], "start_line": 40, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_index_tricks.py", "nloc": 7, "complexity": 2, "token_count": 52, "parameters": [ "level" ], "start_line": 54, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_index_tricks.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 63, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_index_tricks.py", "nloc": 11, "complexity": 1, "token_count": 142, "parameters": [ "self" ], "start_line": 7, "end_line": 17, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_nd", "long_name": "check_nd( self )", "filename": "test_index_tricks.py", "nloc": 11, "complexity": 1, "token_count": 227, "parameters": [ "self" ], "start_line": 19, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_1d", "long_name": "check_1d( self )", "filename": "test_index_tricks.py", "nloc": 7, "complexity": 1, "token_count": 129, "parameters": [ "self" ], "start_line": 32, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_2d", "long_name": "check_2d( self )", "filename": "test_index_tricks.py", "nloc": 11, "complexity": 1, "token_count": 109, "parameters": [ "self" ], "start_line": 40, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_index_tricks.py", "nloc": 7, "complexity": 2, "token_count": 52, "parameters": [ "level" ], "start_line": 54, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_index_tricks.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 63, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 60, "complexity": 7, "token_count": 741, "diff_parsed": { "added": [ "from scipy_test.testing import assert_array_equal, assert_equal, rand", "from scipy_test.testing import assert_almost_equal, assert_array_almost_equal" ], "deleted": [ "from scipy_base.testing import assert_array_equal, assert_equal, rand", "from scipy_base.testing import assert_almost_equal, assert_array_almost_equal" ] } }, { "old_path": "scipy_base/tests/test_matrix_base.py", "new_path": "scipy_base/tests/test_matrix_base.py", "filename": "test_matrix_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -7,8 +7,8 @@\n sys.path.insert(0,'../..')\n \n import unittest\n-from scipy_base.testing import assert_array_equal, assert_equal\n-from scipy_base.testing import assert_almost_equal, assert_array_almost_equal\n+from scipy_test.testing import assert_array_equal, assert_equal\n+from scipy_test.testing import assert_almost_equal, assert_array_almost_equal\n \n \n from scipy_base import *\n", "added_lines": 2, "deleted_lines": 2, "source_code": "\"\"\" Test functions for basic module\n\n\"\"\"\n\n# only for short term testing\nimport sys\nsys.path.insert(0,'../..')\n\nimport unittest\nfrom scipy_test.testing import assert_array_equal, assert_equal\nfrom scipy_test.testing import assert_almost_equal, assert_array_almost_equal\n\n\nfrom scipy_base import *\n# This won't be needed when we get scipy_base finished.\nfrom scipy_base.type_check import isscalar \nfrom scipy_base import limits\nfrom scipy_base.matrix_base import *\n\n##################################################\n\nval = limits.double_resolution\n\n\ndef get_mat(n):\n data = arange(n)\n data = add.outer(data,data)\n return data\n\nclass test_eye(unittest.TestCase):\n def check_basic(self):\n assert_equal(eye(4),array([[1,0,0,0],\n [0,1,0,0],\n [0,0,1,0],\n [0,0,0,1]]))\n assert_equal(eye(4,typecode='f'),array([[1,0,0,0],\n [0,1,0,0],\n [0,0,1,0],\n [0,0,0,1]],'f'))\n def check_diag(self):\n assert_equal(eye(4,k=1),array([[0,1,0,0],\n [0,0,1,0],\n [0,0,0,1],\n [0,0,0,0]]))\n assert_equal(eye(4,k=-1),array([[0,0,0,0],\n [1,0,0,0],\n [0,1,0,0],\n [0,0,1,0]]))\n def check_2d(self):\n assert_equal(eye(4,3),array([[1,0,0],\n [0,1,0],\n [0,0,1],\n [0,0,0]]))\n assert_equal(eye(3,4),array([[1,0,0,0],\n [0,1,0,0],\n [0,0,1,0]])) \n def check_diag2d(self):\n assert_equal(eye(3,4,k=2),array([[0,0,1,0],\n [0,0,0,1],\n [0,0,0,0]]))\n assert_equal(eye(4,3,k=-2),array([[0,0,0],\n [0,0,0],\n [1,0,0],\n [0,1,0]]))\n\nclass test_diag(unittest.TestCase):\n def check_vector(self):\n vals = (100*arange(5)).astype('l')\n b = zeros((5,5))\n for k in range(5):\n b[k,k] = vals[k]\n assert_equal(diag(vals),b)\n b = zeros((7,7))\n c = b.copy()\n for k in range(5):\n b[k,k+2] = vals[k]\n c[k+2,k] = vals[k]\n assert_equal(diag(vals,k=2), b)\n assert_equal(diag(vals,k=-2), c)\n\n def check_matrix(self):\n vals = (100*get_mat(5)+1).astype('l')\n b = zeros((5,))\n for k in range(5):\n b[k] = vals[k,k]\n assert_equal(diag(vals),b)\n b = b*0\n for k in range(3):\n b[k] = vals[k,k+2]\n assert_equal(diag(vals,2),b[:3])\n for k in range(3):\n b[k] = vals[k+2,k]\n assert_equal(diag(vals,-2),b[:3])\n\nclass test_fliplr(unittest.TestCase):\n def check_basic(self):\n self.failUnlessRaises(ValueError, fliplr, ones(4)) \n self.failUnlessRaises(ValueError, fliplr, ones((4,3,2)))\n a = get_mat(4)\n b = a[:,::-1]\n assert_equal(fliplr(a),b)\n a = [[0,1,2],\n [3,4,5]]\n b = [[2,1,0],\n [5,4,3]]\n assert_equal(fliplr(a),b)\n\nclass test_flipud(unittest.TestCase):\n def check_basic(self):\n self.failUnlessRaises(ValueError, flipud, ones(4))\n self.failUnlessRaises(ValueError, flipud, ones((4,3,2)))\n a = get_mat(4)\n b = a[::-1,:]\n assert_equal(flipud(a),b)\n a = [[0,1,2],\n [3,4,5]]\n b = [[3,4,5],\n [0,1,2]]\n assert_equal(flipud(a),b)\n\nclass test_rot90(unittest.TestCase):\n def check_basic(self):\n self.failUnlessRaises(ValueError, rot90, ones(4))\n self.failUnlessRaises(ValueError, rot90, ones((4,3,2)))\n\n a = [[0,1,2],\n [3,4,5]]\n b1 = [[2,5],\n [1,4],\n [0,3]]\n b2 = [[5,4,3],\n [2,1,0]]\n b3 = [[3,0],\n [4,1],\n [5,2]]\n b4 = [[0,1,2],\n [3,4,5]]\n\n for k in range(-3,13,4):\n assert_equal(rot90(a,k=k),b1)\n for k in range(-2,13,4):\n assert_equal(rot90(a,k=k),b2)\n for k in range(-1,13,4):\n assert_equal(rot90(a,k=k),b3)\n for k in range(0,13,4):\n assert_equal(rot90(a,k=k),b4)\n\n \n#-----------------------------------------------------------------------------\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_eye,'check_') )\n suites.append( unittest.makeSuite(test_diag,'check_') )\n suites.append( unittest.makeSuite(test_fliplr,'check_') )\n suites.append( unittest.makeSuite(test_flipud,'check_') )\n suites.append( unittest.makeSuite(test_rot90,'check_') )\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\n\nif __name__ == \"__main__\":\n test()\n", "source_code_before": "\"\"\" Test functions for basic module\n\n\"\"\"\n\n# only for short term testing\nimport sys\nsys.path.insert(0,'../..')\n\nimport unittest\nfrom scipy_base.testing import assert_array_equal, assert_equal\nfrom scipy_base.testing import assert_almost_equal, assert_array_almost_equal\n\n\nfrom scipy_base import *\n# This won't be needed when we get scipy_base finished.\nfrom scipy_base.type_check import isscalar \nfrom scipy_base import limits\nfrom scipy_base.matrix_base import *\n\n##################################################\n\nval = limits.double_resolution\n\n\ndef get_mat(n):\n data = arange(n)\n data = add.outer(data,data)\n return data\n\nclass test_eye(unittest.TestCase):\n def check_basic(self):\n assert_equal(eye(4),array([[1,0,0,0],\n [0,1,0,0],\n [0,0,1,0],\n [0,0,0,1]]))\n assert_equal(eye(4,typecode='f'),array([[1,0,0,0],\n [0,1,0,0],\n [0,0,1,0],\n [0,0,0,1]],'f'))\n def check_diag(self):\n assert_equal(eye(4,k=1),array([[0,1,0,0],\n [0,0,1,0],\n [0,0,0,1],\n [0,0,0,0]]))\n assert_equal(eye(4,k=-1),array([[0,0,0,0],\n [1,0,0,0],\n [0,1,0,0],\n [0,0,1,0]]))\n def check_2d(self):\n assert_equal(eye(4,3),array([[1,0,0],\n [0,1,0],\n [0,0,1],\n [0,0,0]]))\n assert_equal(eye(3,4),array([[1,0,0,0],\n [0,1,0,0],\n [0,0,1,0]])) \n def check_diag2d(self):\n assert_equal(eye(3,4,k=2),array([[0,0,1,0],\n [0,0,0,1],\n [0,0,0,0]]))\n assert_equal(eye(4,3,k=-2),array([[0,0,0],\n [0,0,0],\n [1,0,0],\n [0,1,0]]))\n\nclass test_diag(unittest.TestCase):\n def check_vector(self):\n vals = (100*arange(5)).astype('l')\n b = zeros((5,5))\n for k in range(5):\n b[k,k] = vals[k]\n assert_equal(diag(vals),b)\n b = zeros((7,7))\n c = b.copy()\n for k in range(5):\n b[k,k+2] = vals[k]\n c[k+2,k] = vals[k]\n assert_equal(diag(vals,k=2), b)\n assert_equal(diag(vals,k=-2), c)\n\n def check_matrix(self):\n vals = (100*get_mat(5)+1).astype('l')\n b = zeros((5,))\n for k in range(5):\n b[k] = vals[k,k]\n assert_equal(diag(vals),b)\n b = b*0\n for k in range(3):\n b[k] = vals[k,k+2]\n assert_equal(diag(vals,2),b[:3])\n for k in range(3):\n b[k] = vals[k+2,k]\n assert_equal(diag(vals,-2),b[:3])\n\nclass test_fliplr(unittest.TestCase):\n def check_basic(self):\n self.failUnlessRaises(ValueError, fliplr, ones(4)) \n self.failUnlessRaises(ValueError, fliplr, ones((4,3,2)))\n a = get_mat(4)\n b = a[:,::-1]\n assert_equal(fliplr(a),b)\n a = [[0,1,2],\n [3,4,5]]\n b = [[2,1,0],\n [5,4,3]]\n assert_equal(fliplr(a),b)\n\nclass test_flipud(unittest.TestCase):\n def check_basic(self):\n self.failUnlessRaises(ValueError, flipud, ones(4))\n self.failUnlessRaises(ValueError, flipud, ones((4,3,2)))\n a = get_mat(4)\n b = a[::-1,:]\n assert_equal(flipud(a),b)\n a = [[0,1,2],\n [3,4,5]]\n b = [[3,4,5],\n [0,1,2]]\n assert_equal(flipud(a),b)\n\nclass test_rot90(unittest.TestCase):\n def check_basic(self):\n self.failUnlessRaises(ValueError, rot90, ones(4))\n self.failUnlessRaises(ValueError, rot90, ones((4,3,2)))\n\n a = [[0,1,2],\n [3,4,5]]\n b1 = [[2,5],\n [1,4],\n [0,3]]\n b2 = [[5,4,3],\n [2,1,0]]\n b3 = [[3,0],\n [4,1],\n [5,2]]\n b4 = [[0,1,2],\n [3,4,5]]\n\n for k in range(-3,13,4):\n assert_equal(rot90(a,k=k),b1)\n for k in range(-2,13,4):\n assert_equal(rot90(a,k=k),b2)\n for k in range(-1,13,4):\n assert_equal(rot90(a,k=k),b3)\n for k in range(0,13,4):\n assert_equal(rot90(a,k=k),b4)\n\n \n#-----------------------------------------------------------------------------\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_eye,'check_') )\n suites.append( unittest.makeSuite(test_diag,'check_') )\n suites.append( unittest.makeSuite(test_fliplr,'check_') )\n suites.append( unittest.makeSuite(test_flipud,'check_') )\n suites.append( unittest.makeSuite(test_rot90,'check_') )\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "get_mat", "long_name": "get_mat( n )", "filename": "test_matrix_base.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "n" ], "start_line": 25, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_matrix_base.py", "nloc": 9, "complexity": 1, "token_count": 115, "parameters": [ "self" ], "start_line": 31, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_diag", "long_name": "check_diag( self )", "filename": "test_matrix_base.py", "nloc": 9, "complexity": 1, "token_count": 118, "parameters": [ "self" ], "start_line": 40, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_2d", "long_name": "check_2d( self )", "filename": "test_matrix_base.py", "nloc": 8, "complexity": 1, "token_count": 95, "parameters": [ "self" ], "start_line": 49, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_diag2d", "long_name": "check_diag2d( self )", "filename": "test_matrix_base.py", "nloc": 8, "complexity": 1, "token_count": 104, "parameters": [ "self" ], "start_line": 57, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_vector", "long_name": "check_vector( self )", "filename": "test_matrix_base.py", "nloc": 13, "complexity": 3, "token_count": 136, "parameters": [ "self" ], "start_line": 67, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_matrix", "long_name": "check_matrix( self )", "filename": "test_matrix_base.py", "nloc": 13, "complexity": 4, "token_count": 137, "parameters": [ "self" ], "start_line": 81, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_matrix_base.py", "nloc": 11, "complexity": 1, "token_count": 109, "parameters": [ "self" ], "start_line": 96, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_matrix_base.py", "nloc": 11, "complexity": 1, "token_count": 109, "parameters": [ "self" ], "start_line": 109, "end_line": 119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_matrix_base.py", "nloc": 23, "complexity": 5, "token_count": 239, "parameters": [ "self" ], "start_line": 122, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_matrix_base.py", "nloc": 10, "complexity": 2, "token_count": 91, "parameters": [ "level" ], "start_line": 151, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_matrix_base.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 163, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_mat", "long_name": "get_mat( n )", "filename": "test_matrix_base.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "n" ], "start_line": 25, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_matrix_base.py", "nloc": 9, "complexity": 1, "token_count": 115, "parameters": [ "self" ], "start_line": 31, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_diag", "long_name": "check_diag( self )", "filename": "test_matrix_base.py", "nloc": 9, "complexity": 1, "token_count": 118, "parameters": [ "self" ], "start_line": 40, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_2d", "long_name": "check_2d( self )", "filename": "test_matrix_base.py", "nloc": 8, "complexity": 1, "token_count": 95, "parameters": [ "self" ], "start_line": 49, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_diag2d", "long_name": "check_diag2d( self )", "filename": "test_matrix_base.py", "nloc": 8, "complexity": 1, "token_count": 104, "parameters": [ "self" ], "start_line": 57, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_vector", "long_name": "check_vector( self )", "filename": "test_matrix_base.py", "nloc": 13, "complexity": 3, "token_count": 136, "parameters": [ "self" ], "start_line": 67, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_matrix", "long_name": "check_matrix( self )", "filename": "test_matrix_base.py", "nloc": 13, "complexity": 4, "token_count": 137, "parameters": [ "self" ], "start_line": 81, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_matrix_base.py", "nloc": 11, "complexity": 1, "token_count": 109, "parameters": [ "self" ], "start_line": 96, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_matrix_base.py", "nloc": 11, "complexity": 1, "token_count": 109, "parameters": [ "self" ], "start_line": 109, "end_line": 119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_matrix_base.py", "nloc": 23, "complexity": 5, "token_count": 239, "parameters": [ "self" ], "start_line": 122, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_matrix_base.py", "nloc": 10, "complexity": 2, "token_count": 91, "parameters": [ "level" ], "start_line": 151, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_matrix_base.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 163, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 144, "complexity": 22, "token_count": 1420, "diff_parsed": { "added": [ "from scipy_test.testing import assert_array_equal, assert_equal", "from scipy_test.testing import assert_almost_equal, assert_array_almost_equal" ], "deleted": [ "from scipy_base.testing import assert_array_equal, assert_equal", "from scipy_base.testing import assert_almost_equal, assert_array_almost_equal" ] } }, { "old_path": "scipy_base/tests/test_shape_base.py", "new_path": "scipy_base/tests/test_shape_base.py", "filename": "test_shape_base.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -3,8 +3,8 @@\n sys.path.insert(0,'../..')\n \n import unittest\n-from scipy_base.testing import assert_array_equal, assert_equal, rand\n-from scipy_base.testing import assert_almost_equal, assert_array_almost_equal \n+from scipy_test.testing import assert_array_equal, assert_equal, rand\n+from scipy_test.testing import assert_almost_equal, assert_array_almost_equal \n \n from scipy_base import *\n # This won't be needed when we get scipy_base finished.\n", "added_lines": 2, "deleted_lines": 2, "source_code": "# only for short term testing\nimport sys\nsys.path.insert(0,'../..')\n\nimport unittest\nfrom scipy_test.testing import assert_array_equal, assert_equal, rand\nfrom scipy_test.testing import assert_almost_equal, assert_array_almost_equal \n\nfrom scipy_base import *\n# This won't be needed when we get scipy_base finished.\nfrom scipy_base.shape_base import *\n\n\nclass test_array_split(unittest.TestCase):\n def check_integer_0_split(self):\n a = arange(10)\n try:\n res = array_split(a,0)\n assert(0) # it should have thrown a value error\n except ValueError:\n pass\n def check_integer_split(self):\n a = arange(10)\n res = array_split(a,1)\n desired = [arange(10)]\n compare_results(res,desired)\n\n res = array_split(a,2)\n desired = [arange(5),arange(5,10)]\n compare_results(res,desired)\n\n res = array_split(a,3)\n desired = [arange(4),arange(4,7),arange(7,10)]\n compare_results(res,desired)\n\n res = array_split(a,4)\n desired = [arange(3),arange(3,6),arange(6,8),arange(8,10)]\n compare_results(res,desired)\n\n res = array_split(a,5)\n desired = [arange(2),arange(2,4),arange(4,6),arange(6,8),arange(8,10)]\n compare_results(res,desired)\n\n res = array_split(a,6)\n desired = [arange(2),arange(2,4),arange(4,6),arange(6,8),arange(8,9),\n arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,7)\n desired = [arange(2),arange(2,4),arange(4,6),arange(6,7),arange(7,8),\n arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,8)\n desired = [arange(2),arange(2,4),arange(4,5),arange(5,6),arange(6,7),\n arange(7,8), arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,9)\n desired = [arange(2),arange(2,3),arange(3,4),arange(4,5),arange(5,6),\n arange(6,7), arange(7,8), arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,10)\n desired = [arange(1),arange(1,2),arange(2,3),arange(3,4),\n arange(4,5),arange(5,6), arange(6,7), arange(7,8),\n arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,11)\n desired = [arange(1),arange(1,2),arange(2,3),arange(3,4),\n arange(4,5),arange(5,6), arange(6,7), arange(7,8),\n arange(8,9), arange(9,10),array([])]\n compare_results(res,desired)\n def check_integer_split_2D_rows(self):\n a = array([arange(10),arange(10)])\n res = array_split(a,3,axis=0)\n desired = [array([arange(10)]),array([arange(10)]),array([])]\n compare_results(res,desired)\n def check_integer_split_2D_cols(self):\n a = array([arange(10),arange(10)])\n res = array_split(a,3,axis=-1)\n desired = [array([arange(4),arange(4)]),\n array([arange(4,7),arange(4,7)]),\n array([arange(7,10),arange(7,10)])]\n compare_results(res,desired)\n def check_integer_split_2D_default(self):\n \"\"\" This will fail if we change default axis\n \"\"\"\n a = array([arange(10),arange(10)])\n res = array_split(a,3)\n desired = [array([arange(10)]),array([arange(10)]),array([])]\n compare_results(res,desired)\n #perhaps should check higher dimensions\n\n def check_index_split_simple(self):\n a = arange(10)\n indices = [1,5,7]\n res = array_split(a,indices,axis=-1)\n desired = [arange(0,1),arange(1,5),arange(5,7),arange(7,10)]\n compare_results(res,desired)\n\n def check_index_split_low_bound(self):\n a = arange(10)\n indices = [0,5,7]\n res = array_split(a,indices,axis=-1)\n desired = [array([]),arange(0,5),arange(5,7),arange(7,10)]\n compare_results(res,desired)\n def check_index_split_high_bound(self):\n a = arange(10)\n indices = [0,5,7,10,12]\n res = array_split(a,indices,axis=-1)\n desired = [array([]),arange(0,5),arange(5,7),arange(7,10),\n array([]),array([])]\n compare_results(res,desired)\n \nclass test_split(unittest.TestCase):\n \"\"\"* This function is essentially the same as array_split,\n except that it test if splitting will result in an\n equal split. Only test for this case.\n *\"\"\"\n def check_equal_split(self):\n a = arange(10)\n res = split(a,2)\n desired = [arange(5),arange(5,10)]\n compare_results(res,desired)\n\n def check_unequal_split(self):\n a = arange(10) \n try:\n res = split(a,3)\n assert(0) # should raise an error\n except ValueError:\n pass\n\nclass test_atleast_1d(unittest.TestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=map(atleast_1d,[a,b])\n desired = [array([1]),array([2])]\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1,2]); b = array([2,3]);\n res=map(atleast_1d,[a,b])\n desired = [array([1,2]),array([2,3])]\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n res=map(atleast_1d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_3D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n a = array([a,a]);b = array([b,b]);\n res=map(atleast_1d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_r1array(self):\n \"\"\" Test to make sure equivalent Travis O's r1array function\n \"\"\"\n assert(atleast_1d(3).shape == (1,))\n assert(atleast_1d(3j).shape == (1,))\n assert(atleast_1d(3L).shape == (1,))\n assert(atleast_1d(3.0).shape == (1,))\n assert(atleast_1d([[2,3],[4,5]]).shape == (2,2))\n\nclass test_atleast_2d(unittest.TestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=map(atleast_2d,[a,b])\n desired = [array([[1]]),array([[2]])]\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1,2]); b = array([2,3]);\n res=map(atleast_2d,[a,b])\n desired = [array([[1,2]]),array([[2,3]])]\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n res=map(atleast_2d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_3D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n a = array([a,a]);b = array([b,b]);\n res=map(atleast_2d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_r2array(self):\n \"\"\" Test to make sure equivalent Travis O's r2array function\n \"\"\"\n assert(atleast_2d(3).shape == (1,1))\n assert(atleast_2d([3j,1]).shape == (1,2))\n assert(atleast_2d([[[3,1],[4,5]],[[3,5],[1,2]]]).shape == (2,2,2))\n\nclass test_atleast_3d(unittest.TestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=map(atleast_3d,[a,b])\n desired = [array([[[1]]]),array([[[2]]])]\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1,2]); b = array([2,3]);\n res=map(atleast_3d,[a,b])\n desired = [array([[[1],[2]]]),array([[[2],[3]]])]\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n res=map(atleast_3d,[a,b])\n desired = [a[:,:,NewAxis],b[:,:,NewAxis]]\n assert_array_equal(res,desired)\n def check_3D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n a = array([a,a]);b = array([b,b]);\n res=map(atleast_3d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n\nclass test_hstack(unittest.TestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=hstack([a,b])\n desired = array([1,2])\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1]); b = array([2]);\n res=hstack([a,b])\n desired = array([1,2])\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1],[2]]); b = array([[1],[2]]);\n res=hstack([a,b])\n desired = array([[1,1],[2,2]])\n assert_array_equal(res,desired)\n\nclass test_vstack(unittest.TestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=vstack([a,b])\n desired = array([[1],[2]])\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1]); b = array([2]);\n res=vstack([a,b])\n desired = array([[1],[2]])\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1],[2]]); b = array([[1],[2]]);\n res=vstack([a,b])\n desired = array([[1],[2],[1],[2]])\n assert_array_equal(res,desired)\n def check_2D_array2(self):\n a = array([1,2]); b = array([1,2]);\n res=vstack([a,b])\n desired = array([[1,2],[1,2]])\n assert_array_equal(res,desired)\n\nclass test_dstack(unittest.TestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=dstack([a,b])\n desired = array([[[1,2]]])\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1]); b = array([2]);\n res=dstack([a,b])\n desired = array([[[1,2]]])\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1],[2]]); b = array([[1],[2]]);\n res=dstack([a,b])\n desired = array([[[1,1]],[[2,2,]]])\n assert_array_equal(res,desired)\n def check_2D_array2(self):\n a = array([1,2]); b = array([1,2]);\n res=dstack([a,b])\n desired = array([[[1,1],[2,2]]])\n assert_array_equal(res,desired)\n\n\"\"\" array_split has more comprehensive test of splitting.\n only do simple test on hsplit, vsplit, and dsplit\n\"\"\"\nclass test_hsplit(unittest.TestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_0D_array(self):\n a= array(1)\n try:\n hsplit(a,2)\n assert(0)\n except ValueError:\n pass\n def check_1D_array(self):\n a= array([1,2,3,4])\n res = hsplit(a,2)\n desired = [array([1,2]),array([3,4])]\n compare_results(res,desired)\n def check_2D_array(self):\n a= array([[1,2,3,4],\n [1,2,3,4]])\n res = hsplit(a,2)\n desired = [array([[1,2],[1,2]]),array([[3,4],[3,4]])]\n compare_results(res,desired)\n\nclass test_vsplit(unittest.TestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_1D_array(self):\n a= array([1,2,3,4])\n try:\n vsplit(a,2)\n assert(0)\n except ValueError:\n pass\n def check_2D_array(self):\n a= array([[1,2,3,4],\n [1,2,3,4]])\n res = vsplit(a,2)\n desired = [array([[1,2,3,4]]),array([[1,2,3,4]])]\n compare_results(res,desired)\n\nclass test_dsplit(unittest.TestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_2D_array(self):\n a= array([[1,2,3,4],\n [1,2,3,4]])\n try:\n dsplit(a,2)\n assert(0)\n except ValueError:\n pass\n def check_3D_array(self):\n a= array([[[1,2,3,4],\n [1,2,3,4]],\n [[1,2,3,4],\n [1,2,3,4]]])\n res = dsplit(a,2)\n desired = [array([[[1,2],[1,2]],[[1,2],[1,2]]]),\n array([[[3,4],[3,4]],[[3,4],[3,4]]])]\n compare_results(res,desired)\n\nclass test_squeeze(unittest.TestCase):\n def check_basic(self):\n a = rand(20,10,10,1,1)\n b = rand(20,1,10,1,20)\n c = rand(1,1,20,10)\n assert_array_equal(squeeze(a),reshape(a,(20,10,10)))\n assert_array_equal(squeeze(b),reshape(b,(20,10,20)))\n assert_array_equal(squeeze(c),reshape(c,(20,10)))\n \n# Utility\n\ndef compare_results(res,desired):\n for i in range(len(desired)):\n assert_array_equal(res[i],desired[i])\n\n\n#-----------------------------------------------------------------------------\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_array_split,'check_') )\n suites.append( unittest.makeSuite(test_split,'check_') )\n suites.append( unittest.makeSuite(test_atleast_1d,'check_') )\n suites.append( unittest.makeSuite(test_atleast_2d,'check_') )\n suites.append( unittest.makeSuite(test_atleast_3d,'check_') )\n suites.append( unittest.makeSuite(test_hstack,'check_') )\n suites.append( unittest.makeSuite(test_vstack,'check_') )\n suites.append( unittest.makeSuite(test_dstack,'check_') )\n suites.append( unittest.makeSuite(test_hsplit,'check_') ) \n suites.append( unittest.makeSuite(test_vsplit,'check_') )\n suites.append( unittest.makeSuite(test_dsplit,'check_') )\n suites.append( unittest.makeSuite(test_squeeze,'check_') )\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\n\nif __name__ == \"__main__\":\n test()\n", "source_code_before": "# only for short term testing\nimport sys\nsys.path.insert(0,'../..')\n\nimport unittest\nfrom scipy_base.testing import assert_array_equal, assert_equal, rand\nfrom scipy_base.testing import assert_almost_equal, assert_array_almost_equal \n\nfrom scipy_base import *\n# This won't be needed when we get scipy_base finished.\nfrom scipy_base.shape_base import *\n\n\nclass test_array_split(unittest.TestCase):\n def check_integer_0_split(self):\n a = arange(10)\n try:\n res = array_split(a,0)\n assert(0) # it should have thrown a value error\n except ValueError:\n pass\n def check_integer_split(self):\n a = arange(10)\n res = array_split(a,1)\n desired = [arange(10)]\n compare_results(res,desired)\n\n res = array_split(a,2)\n desired = [arange(5),arange(5,10)]\n compare_results(res,desired)\n\n res = array_split(a,3)\n desired = [arange(4),arange(4,7),arange(7,10)]\n compare_results(res,desired)\n\n res = array_split(a,4)\n desired = [arange(3),arange(3,6),arange(6,8),arange(8,10)]\n compare_results(res,desired)\n\n res = array_split(a,5)\n desired = [arange(2),arange(2,4),arange(4,6),arange(6,8),arange(8,10)]\n compare_results(res,desired)\n\n res = array_split(a,6)\n desired = [arange(2),arange(2,4),arange(4,6),arange(6,8),arange(8,9),\n arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,7)\n desired = [arange(2),arange(2,4),arange(4,6),arange(6,7),arange(7,8),\n arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,8)\n desired = [arange(2),arange(2,4),arange(4,5),arange(5,6),arange(6,7),\n arange(7,8), arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,9)\n desired = [arange(2),arange(2,3),arange(3,4),arange(4,5),arange(5,6),\n arange(6,7), arange(7,8), arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,10)\n desired = [arange(1),arange(1,2),arange(2,3),arange(3,4),\n arange(4,5),arange(5,6), arange(6,7), arange(7,8),\n arange(8,9), arange(9,10)]\n compare_results(res,desired)\n\n res = array_split(a,11)\n desired = [arange(1),arange(1,2),arange(2,3),arange(3,4),\n arange(4,5),arange(5,6), arange(6,7), arange(7,8),\n arange(8,9), arange(9,10),array([])]\n compare_results(res,desired)\n def check_integer_split_2D_rows(self):\n a = array([arange(10),arange(10)])\n res = array_split(a,3,axis=0)\n desired = [array([arange(10)]),array([arange(10)]),array([])]\n compare_results(res,desired)\n def check_integer_split_2D_cols(self):\n a = array([arange(10),arange(10)])\n res = array_split(a,3,axis=-1)\n desired = [array([arange(4),arange(4)]),\n array([arange(4,7),arange(4,7)]),\n array([arange(7,10),arange(7,10)])]\n compare_results(res,desired)\n def check_integer_split_2D_default(self):\n \"\"\" This will fail if we change default axis\n \"\"\"\n a = array([arange(10),arange(10)])\n res = array_split(a,3)\n desired = [array([arange(10)]),array([arange(10)]),array([])]\n compare_results(res,desired)\n #perhaps should check higher dimensions\n\n def check_index_split_simple(self):\n a = arange(10)\n indices = [1,5,7]\n res = array_split(a,indices,axis=-1)\n desired = [arange(0,1),arange(1,5),arange(5,7),arange(7,10)]\n compare_results(res,desired)\n\n def check_index_split_low_bound(self):\n a = arange(10)\n indices = [0,5,7]\n res = array_split(a,indices,axis=-1)\n desired = [array([]),arange(0,5),arange(5,7),arange(7,10)]\n compare_results(res,desired)\n def check_index_split_high_bound(self):\n a = arange(10)\n indices = [0,5,7,10,12]\n res = array_split(a,indices,axis=-1)\n desired = [array([]),arange(0,5),arange(5,7),arange(7,10),\n array([]),array([])]\n compare_results(res,desired)\n \nclass test_split(unittest.TestCase):\n \"\"\"* This function is essentially the same as array_split,\n except that it test if splitting will result in an\n equal split. Only test for this case.\n *\"\"\"\n def check_equal_split(self):\n a = arange(10)\n res = split(a,2)\n desired = [arange(5),arange(5,10)]\n compare_results(res,desired)\n\n def check_unequal_split(self):\n a = arange(10) \n try:\n res = split(a,3)\n assert(0) # should raise an error\n except ValueError:\n pass\n\nclass test_atleast_1d(unittest.TestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=map(atleast_1d,[a,b])\n desired = [array([1]),array([2])]\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1,2]); b = array([2,3]);\n res=map(atleast_1d,[a,b])\n desired = [array([1,2]),array([2,3])]\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n res=map(atleast_1d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_3D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n a = array([a,a]);b = array([b,b]);\n res=map(atleast_1d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_r1array(self):\n \"\"\" Test to make sure equivalent Travis O's r1array function\n \"\"\"\n assert(atleast_1d(3).shape == (1,))\n assert(atleast_1d(3j).shape == (1,))\n assert(atleast_1d(3L).shape == (1,))\n assert(atleast_1d(3.0).shape == (1,))\n assert(atleast_1d([[2,3],[4,5]]).shape == (2,2))\n\nclass test_atleast_2d(unittest.TestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=map(atleast_2d,[a,b])\n desired = [array([[1]]),array([[2]])]\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1,2]); b = array([2,3]);\n res=map(atleast_2d,[a,b])\n desired = [array([[1,2]]),array([[2,3]])]\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n res=map(atleast_2d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_3D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n a = array([a,a]);b = array([b,b]);\n res=map(atleast_2d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n def check_r2array(self):\n \"\"\" Test to make sure equivalent Travis O's r2array function\n \"\"\"\n assert(atleast_2d(3).shape == (1,1))\n assert(atleast_2d([3j,1]).shape == (1,2))\n assert(atleast_2d([[[3,1],[4,5]],[[3,5],[1,2]]]).shape == (2,2,2))\n\nclass test_atleast_3d(unittest.TestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=map(atleast_3d,[a,b])\n desired = [array([[[1]]]),array([[[2]]])]\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1,2]); b = array([2,3]);\n res=map(atleast_3d,[a,b])\n desired = [array([[[1],[2]]]),array([[[2],[3]]])]\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n res=map(atleast_3d,[a,b])\n desired = [a[:,:,NewAxis],b[:,:,NewAxis]]\n assert_array_equal(res,desired)\n def check_3D_array(self):\n a = array([[1,2],[1,2]]); b = array([[2,3],[2,3]]);\n a = array([a,a]);b = array([b,b]);\n res=map(atleast_3d,[a,b])\n desired = [a,b]\n assert_array_equal(res,desired)\n\nclass test_hstack(unittest.TestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=hstack([a,b])\n desired = array([1,2])\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1]); b = array([2]);\n res=hstack([a,b])\n desired = array([1,2])\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1],[2]]); b = array([[1],[2]]);\n res=hstack([a,b])\n desired = array([[1,1],[2,2]])\n assert_array_equal(res,desired)\n\nclass test_vstack(unittest.TestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=vstack([a,b])\n desired = array([[1],[2]])\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1]); b = array([2]);\n res=vstack([a,b])\n desired = array([[1],[2]])\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1],[2]]); b = array([[1],[2]]);\n res=vstack([a,b])\n desired = array([[1],[2],[1],[2]])\n assert_array_equal(res,desired)\n def check_2D_array2(self):\n a = array([1,2]); b = array([1,2]);\n res=vstack([a,b])\n desired = array([[1,2],[1,2]])\n assert_array_equal(res,desired)\n\nclass test_dstack(unittest.TestCase):\n def check_0D_array(self):\n a = array(1); b = array(2);\n res=dstack([a,b])\n desired = array([[[1,2]]])\n assert_array_equal(res,desired)\n def check_1D_array(self):\n a = array([1]); b = array([2]);\n res=dstack([a,b])\n desired = array([[[1,2]]])\n assert_array_equal(res,desired)\n def check_2D_array(self):\n a = array([[1],[2]]); b = array([[1],[2]]);\n res=dstack([a,b])\n desired = array([[[1,1]],[[2,2,]]])\n assert_array_equal(res,desired)\n def check_2D_array2(self):\n a = array([1,2]); b = array([1,2]);\n res=dstack([a,b])\n desired = array([[[1,1],[2,2]]])\n assert_array_equal(res,desired)\n\n\"\"\" array_split has more comprehensive test of splitting.\n only do simple test on hsplit, vsplit, and dsplit\n\"\"\"\nclass test_hsplit(unittest.TestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_0D_array(self):\n a= array(1)\n try:\n hsplit(a,2)\n assert(0)\n except ValueError:\n pass\n def check_1D_array(self):\n a= array([1,2,3,4])\n res = hsplit(a,2)\n desired = [array([1,2]),array([3,4])]\n compare_results(res,desired)\n def check_2D_array(self):\n a= array([[1,2,3,4],\n [1,2,3,4]])\n res = hsplit(a,2)\n desired = [array([[1,2],[1,2]]),array([[3,4],[3,4]])]\n compare_results(res,desired)\n\nclass test_vsplit(unittest.TestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_1D_array(self):\n a= array([1,2,3,4])\n try:\n vsplit(a,2)\n assert(0)\n except ValueError:\n pass\n def check_2D_array(self):\n a= array([[1,2,3,4],\n [1,2,3,4]])\n res = vsplit(a,2)\n desired = [array([[1,2,3,4]]),array([[1,2,3,4]])]\n compare_results(res,desired)\n\nclass test_dsplit(unittest.TestCase):\n \"\"\" only testing for integer splits.\n \"\"\"\n def check_2D_array(self):\n a= array([[1,2,3,4],\n [1,2,3,4]])\n try:\n dsplit(a,2)\n assert(0)\n except ValueError:\n pass\n def check_3D_array(self):\n a= array([[[1,2,3,4],\n [1,2,3,4]],\n [[1,2,3,4],\n [1,2,3,4]]])\n res = dsplit(a,2)\n desired = [array([[[1,2],[1,2]],[[1,2],[1,2]]]),\n array([[[3,4],[3,4]],[[3,4],[3,4]]])]\n compare_results(res,desired)\n\nclass test_squeeze(unittest.TestCase):\n def check_basic(self):\n a = rand(20,10,10,1,1)\n b = rand(20,1,10,1,20)\n c = rand(1,1,20,10)\n assert_array_equal(squeeze(a),reshape(a,(20,10,10)))\n assert_array_equal(squeeze(b),reshape(b,(20,10,20)))\n assert_array_equal(squeeze(c),reshape(c,(20,10)))\n \n# Utility\n\ndef compare_results(res,desired):\n for i in range(len(desired)):\n assert_array_equal(res[i],desired[i])\n\n\n#-----------------------------------------------------------------------------\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_array_split,'check_') )\n suites.append( unittest.makeSuite(test_split,'check_') )\n suites.append( unittest.makeSuite(test_atleast_1d,'check_') )\n suites.append( unittest.makeSuite(test_atleast_2d,'check_') )\n suites.append( unittest.makeSuite(test_atleast_3d,'check_') )\n suites.append( unittest.makeSuite(test_hstack,'check_') )\n suites.append( unittest.makeSuite(test_vstack,'check_') )\n suites.append( unittest.makeSuite(test_dstack,'check_') )\n suites.append( unittest.makeSuite(test_hsplit,'check_') ) \n suites.append( unittest.makeSuite(test_vsplit,'check_') )\n suites.append( unittest.makeSuite(test_dsplit,'check_') )\n suites.append( unittest.makeSuite(test_squeeze,'check_') )\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "check_integer_0_split", "long_name": "check_integer_0_split( self )", "filename": "test_shape_base.py", "nloc": 7, "complexity": 2, "token_count": 29, "parameters": [ "self" ], "start_line": 15, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_integer_split", "long_name": "check_integer_split( self )", "filename": "test_shape_base.py", "nloc": 43, "complexity": 1, "token_count": 637, "parameters": [ "self" ], "start_line": 22, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 1 }, { "name": "check_integer_split_2D_rows", "long_name": "check_integer_split_2D_rows( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 68, "parameters": [ "self" ], "start_line": 75, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_integer_split_2D_cols", "long_name": "check_integer_split_2D_cols( self )", "filename": "test_shape_base.py", "nloc": 7, "complexity": 1, "token_count": 96, "parameters": [ "self" ], "start_line": 80, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_integer_split_2D_default", "long_name": "check_integer_split_2D_default( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 65, "parameters": [ "self" ], "start_line": 87, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_index_split_simple", "long_name": "check_index_split_simple( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 70, "parameters": [ "self" ], "start_line": 96, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_index_split_low_bound", "long_name": "check_index_split_low_bound( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 69, "parameters": [ "self" ], "start_line": 103, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_index_split_high_bound", "long_name": "check_index_split_high_bound( self )", "filename": "test_shape_base.py", "nloc": 7, "complexity": 1, "token_count": 85, "parameters": [ "self" ], "start_line": 109, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_equal_split", "long_name": "check_equal_split( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 122, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_unequal_split", "long_name": "check_unequal_split( self )", "filename": "test_shape_base.py", "nloc": 7, "complexity": 2, "token_count": 29, "parameters": [ "self" ], "start_line": 128, "end_line": 134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_0D_array", "long_name": "check_0D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 54, "parameters": [ "self" ], "start_line": 137, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 66, "parameters": [ "self" ], "start_line": 142, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 68, "parameters": [ "self" ], "start_line": 147, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_3D_array", "long_name": "check_3D_array( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 90, "parameters": [ "self" ], "start_line": 152, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_r1array", "long_name": "check_r1array( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 91, "parameters": [ "self" ], "start_line": 158, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_0D_array", "long_name": "check_0D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 168, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 70, "parameters": [ "self" ], "start_line": 173, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 68, "parameters": [ "self" ], "start_line": 178, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_3D_array", "long_name": "check_3D_array( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 90, "parameters": [ "self" ], "start_line": 183, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_r2array", "long_name": "check_r2array( self )", "filename": "test_shape_base.py", "nloc": 4, "complexity": 1, "token_count": 85, "parameters": [ "self" ], "start_line": 189, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_0D_array", "long_name": "check_0D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 62, "parameters": [ "self" ], "start_line": 197, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 78, "parameters": [ "self" ], "start_line": 202, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 82, "parameters": [ "self" ], "start_line": 207, "end_line": 211, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_3D_array", "long_name": "check_3D_array( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 90, "parameters": [ "self" ], "start_line": 212, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_0D_array", "long_name": "check_0D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 220, "end_line": 224, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 49, "parameters": [ "self" ], "start_line": 225, "end_line": 229, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 69, "parameters": [ "self" ], "start_line": 230, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_0D_array", "long_name": "check_0D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 49, "parameters": [ "self" ], "start_line": 237, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 53, "parameters": [ "self" ], "start_line": 242, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 73, "parameters": [ "self" ], "start_line": 247, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array2", "long_name": "check_2D_array2( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 61, "parameters": [ "self" ], "start_line": 252, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_0D_array", "long_name": "check_0D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 49, "parameters": [ "self" ], "start_line": 259, "end_line": 263, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 53, "parameters": [ "self" ], "start_line": 264, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 269, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array2", "long_name": "check_2D_array2( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 63, "parameters": [ "self" ], "start_line": 274, "end_line": 278, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_0D_array", "long_name": "check_0D_array( self )", "filename": "test_shape_base.py", "nloc": 7, "complexity": 2, "token_count": 27, "parameters": [ "self" ], "start_line": 286, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 54, "parameters": [ "self" ], "start_line": 293, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 82, "parameters": [ "self" ], "start_line": 298, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 7, "complexity": 2, "token_count": 35, "parameters": [ "self" ], "start_line": 308, "end_line": 314, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 78, "parameters": [ "self" ], "start_line": 315, "end_line": 320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 8, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 325, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_3D_array", "long_name": "check_3D_array( self )", "filename": "test_shape_base.py", "nloc": 9, "complexity": 1, "token_count": 138, "parameters": [ "self" ], "start_line": 333, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_shape_base.py", "nloc": 7, "complexity": 1, "token_count": 103, "parameters": [ "self" ], "start_line": 344, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "compare_results", "long_name": "compare_results( res , desired )", "filename": "test_shape_base.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "res", "desired" ], "start_line": 354, "end_line": 356, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_shape_base.py", "nloc": 17, "complexity": 2, "token_count": 182, "parameters": [ "level" ], "start_line": 361, "end_line": 378, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 380, "end_line": 384, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_integer_0_split", "long_name": "check_integer_0_split( self )", "filename": "test_shape_base.py", "nloc": 7, "complexity": 2, "token_count": 29, "parameters": [ "self" ], "start_line": 15, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_integer_split", "long_name": "check_integer_split( self )", "filename": "test_shape_base.py", "nloc": 43, "complexity": 1, "token_count": 637, "parameters": [ "self" ], "start_line": 22, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 1 }, { "name": "check_integer_split_2D_rows", "long_name": "check_integer_split_2D_rows( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 68, "parameters": [ "self" ], "start_line": 75, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_integer_split_2D_cols", "long_name": "check_integer_split_2D_cols( self )", "filename": "test_shape_base.py", "nloc": 7, "complexity": 1, "token_count": 96, "parameters": [ "self" ], "start_line": 80, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_integer_split_2D_default", "long_name": "check_integer_split_2D_default( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 65, "parameters": [ "self" ], "start_line": 87, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_index_split_simple", "long_name": "check_index_split_simple( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 70, "parameters": [ "self" ], "start_line": 96, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_index_split_low_bound", "long_name": "check_index_split_low_bound( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 69, "parameters": [ "self" ], "start_line": 103, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_index_split_high_bound", "long_name": "check_index_split_high_bound( self )", "filename": "test_shape_base.py", "nloc": 7, "complexity": 1, "token_count": 85, "parameters": [ "self" ], "start_line": 109, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_equal_split", "long_name": "check_equal_split( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 122, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_unequal_split", "long_name": "check_unequal_split( self )", "filename": "test_shape_base.py", "nloc": 7, "complexity": 2, "token_count": 29, "parameters": [ "self" ], "start_line": 128, "end_line": 134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_0D_array", "long_name": "check_0D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 54, "parameters": [ "self" ], "start_line": 137, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 66, "parameters": [ "self" ], "start_line": 142, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 68, "parameters": [ "self" ], "start_line": 147, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_3D_array", "long_name": "check_3D_array( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 90, "parameters": [ "self" ], "start_line": 152, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_r1array", "long_name": "check_r1array( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 91, "parameters": [ "self" ], "start_line": 158, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_0D_array", "long_name": "check_0D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 168, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 70, "parameters": [ "self" ], "start_line": 173, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 68, "parameters": [ "self" ], "start_line": 178, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_3D_array", "long_name": "check_3D_array( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 90, "parameters": [ "self" ], "start_line": 183, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_r2array", "long_name": "check_r2array( self )", "filename": "test_shape_base.py", "nloc": 4, "complexity": 1, "token_count": 85, "parameters": [ "self" ], "start_line": 189, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_0D_array", "long_name": "check_0D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 62, "parameters": [ "self" ], "start_line": 197, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 78, "parameters": [ "self" ], "start_line": 202, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 82, "parameters": [ "self" ], "start_line": 207, "end_line": 211, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_3D_array", "long_name": "check_3D_array( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 90, "parameters": [ "self" ], "start_line": 212, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_0D_array", "long_name": "check_0D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 220, "end_line": 224, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 49, "parameters": [ "self" ], "start_line": 225, "end_line": 229, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 69, "parameters": [ "self" ], "start_line": 230, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_0D_array", "long_name": "check_0D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 49, "parameters": [ "self" ], "start_line": 237, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 53, "parameters": [ "self" ], "start_line": 242, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 73, "parameters": [ "self" ], "start_line": 247, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array2", "long_name": "check_2D_array2( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 61, "parameters": [ "self" ], "start_line": 252, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_0D_array", "long_name": "check_0D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 49, "parameters": [ "self" ], "start_line": 259, "end_line": 263, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 53, "parameters": [ "self" ], "start_line": 264, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 269, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array2", "long_name": "check_2D_array2( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 63, "parameters": [ "self" ], "start_line": 274, "end_line": 278, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_0D_array", "long_name": "check_0D_array( self )", "filename": "test_shape_base.py", "nloc": 7, "complexity": 2, "token_count": 27, "parameters": [ "self" ], "start_line": 286, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 54, "parameters": [ "self" ], "start_line": 293, "end_line": 297, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 82, "parameters": [ "self" ], "start_line": 298, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_1D_array", "long_name": "check_1D_array( self )", "filename": "test_shape_base.py", "nloc": 7, "complexity": 2, "token_count": 35, "parameters": [ "self" ], "start_line": 308, "end_line": 314, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 6, "complexity": 1, "token_count": 78, "parameters": [ "self" ], "start_line": 315, "end_line": 320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_2D_array", "long_name": "check_2D_array( self )", "filename": "test_shape_base.py", "nloc": 8, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 325, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_3D_array", "long_name": "check_3D_array( self )", "filename": "test_shape_base.py", "nloc": 9, "complexity": 1, "token_count": 138, "parameters": [ "self" ], "start_line": 333, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_shape_base.py", "nloc": 7, "complexity": 1, "token_count": 103, "parameters": [ "self" ], "start_line": 344, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "compare_results", "long_name": "compare_results( res , desired )", "filename": "test_shape_base.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "res", "desired" ], "start_line": 354, "end_line": 356, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_shape_base.py", "nloc": 17, "complexity": 2, "token_count": 182, "parameters": [ "level" ], "start_line": 361, "end_line": 378, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_shape_base.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 380, "end_line": 384, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 340, "complexity": 53, "token_count": 3879, "diff_parsed": { "added": [ "from scipy_test.testing import assert_array_equal, assert_equal, rand", "from scipy_test.testing import assert_almost_equal, assert_array_almost_equal" ], "deleted": [ "from scipy_base.testing import assert_array_equal, assert_equal, rand", "from scipy_base.testing import assert_almost_equal, assert_array_almost_equal" ] } }, { "old_path": "scipy_base/tests/test_type_check.py", "new_path": "scipy_base/tests/test_type_check.py", "filename": "test_type_check.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -3,8 +3,8 @@\n sys.path.insert(0,'../..')\n \n import unittest\n-from scipy_base.testing import assert_array_equal, assert_equal, rand\n-from scipy_base.testing import assert_almost_equal, assert_array_almost_equal \n+from scipy_test.testing import assert_array_equal, assert_equal, rand\n+from scipy_test.testing import assert_almost_equal, assert_array_almost_equal \n \n from scipy_base import *\n # This won't be needed when we get scipy_base finished.\n", "added_lines": 2, "deleted_lines": 2, "source_code": "# only for short term testing\nimport sys\nsys.path.insert(0,'../..')\n\nimport unittest\nfrom scipy_test.testing import assert_array_equal, assert_equal, rand\nfrom scipy_test.testing import assert_almost_equal, assert_array_almost_equal \n\nfrom scipy_base import *\n# This won't be needed when we get scipy_base finished.\nfrom scipy_base.type_check import *\n \nclass test_isscalar(unittest.TestCase):\n def check_basic(self):\n assert(isscalar(3))\n assert(not isscalar([3]))\n assert(not isscalar((3,)))\n assert(isscalar(3j))\n assert(isscalar(10L))\n assert(isscalar(4.0))\n\nclass test_real(unittest.TestCase):\n def check_real(self):\n y = rand(10,)\n assert_array_equal(y,real(y))\n\n def check_cmplx(self):\n y = rand(10,)+1j*rand(10,)\n assert_array_equal(y.real,real(y))\n\nclass test_imag(unittest.TestCase):\n def check_real(self):\n y = rand(10,)\n assert_array_equal(0,imag(y))\n\n def check_cmplx(self):\n y = rand(10,)+1j*rand(10,)\n assert_array_equal(y.imag,imag(y))\n\nclass test_iscomplex(unittest.TestCase):\n def check_fail(self):\n z = array([-1,0,1])\n res = iscomplex(z)\n assert(not sometrue(res))\n def check_pass(self):\n z = array([-1j,1,0])\n res = iscomplex(z)\n assert_array_equal(res,[1,0,0])\n\nclass test_isreal(unittest.TestCase):\n def check_pass(self):\n z = array([-1,0,1j])\n res = isreal(z)\n assert_array_equal(res,[1,1,0])\n def check_fail(self):\n z = array([-1j,1,0])\n res = isreal(z)\n assert_array_equal(res,[0,1,1])\n\nclass test_iscomplexobj(unittest.TestCase):\n def check_basic(self):\n z = array([-1,0,1])\n assert(not iscomplexobj(z))\n z = array([-1j,0,-1])\n assert(iscomplexobj(z))\n\nclass test_isrealobj(unittest.TestCase):\n def check_basic(self):\n z = array([-1,0,1])\n assert(isrealobj(z))\n z = array([-1j,0,-1])\n assert(not isrealobj(z))\n\nclass test_isnan(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isnan(z) == 0\n assert(alltrue(res)) \n def check_posinf(self): \n assert(isnan(array((1.,))/0.) == 0)\n def check_neginf(self): \n assert(isnan(array((-1.,))/0.) == 0)\n def check_ind(self): \n assert(isnan(array((0.,))/0.) == 1)\n #def check_qnan(self): log(-1) return pi*j now\n # assert(isnan(log(-1.)) == 1)\n def check_integer(self):\n assert(isnan(1) == 0)\n def check_complex(self):\n assert(isnan(1+1j) == 0)\n def check_complex1(self):\n assert(isnan(array(0+0j)/0.) == 1)\n \nclass test_isfinite(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isfinite(z) == 1\n assert(alltrue(res)) \n def check_posinf(self): \n assert(isfinite(array((1.,))/0.) == 0)\n def check_neginf(self): \n assert(isfinite(array((-1.,))/0.) == 0)\n def check_ind(self): \n assert(isfinite(array((0.,))/0.) == 0)\n #def check_qnan(self): \n # assert(isfinite(log(-1.)) == 0)\n def check_integer(self):\n assert(isfinite(1) == 1)\n def check_complex(self):\n assert(isfinite(1+1j) == 1)\n def check_complex1(self):\n assert(isfinite(array(1+1j)/0.) == 0)\n \nclass test_isinf(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isinf(z) == 0\n assert(alltrue(res)) \n def check_posinf(self): \n assert(isinf(array((1.,))/0.) == 1)\n def check_posinf_scalar(self): \n assert(isinf(array(1.,)/0.) == 1)\n def check_neginf(self): \n assert(isinf(array((-1.,))/0.) == 1)\n def check_neginf_scalar(self): \n assert(isinf(array(-1.)/0.) == 1)\n def check_ind(self): \n assert(isinf(array((0.,))/0.) == 0)\n #def check_qnan(self): \n # assert(isinf(log(-1.)) == 0)\n # assert(isnan(log(-1.)) == 1)\n\nclass test_isposinf(unittest.TestCase):\n def check_generic(self):\n vals = isposinf(array((-1.,0,1))/0.)\n assert(vals[0] == 0)\n assert(vals[1] == 0)\n assert(vals[2] == 1)\n\nclass test_isneginf(unittest.TestCase):\n def check_generic(self):\n vals = isneginf(array((-1.,0,1))/0.)\n assert(vals[0] == 1)\n assert(vals[1] == 0)\n assert(vals[2] == 0)\n\nclass test_nan_to_num(unittest.TestCase):\n def check_generic(self):\n vals = nan_to_num(array((-1.,0,1))/0.)\n assert(vals[0] < -1e10 and isfinite(vals[0]))\n assert(vals[1] == 0)\n assert(vals[2] > 1e10 and isfinite(vals[2]))\n def check_integer(self):\n vals = nan_to_num(1)\n assert(vals == 1)\n def check_complex_good(self):\n vals = nan_to_num(1+1j)\n assert(vals == 1+1j)\n def check_complex_bad(self):\n v = 1+1j\n v += array(0+1.j)/0.\n vals = nan_to_num(v)\n # !! This is actually (unexpectedly) zero\n assert(vals.imag > 1e10 and isfinite(vals))\n def check_complex_bad2(self):\n v = 1+1j\n v += array(-1+1.j)/0.\n vals = nan_to_num(v)\n assert(isfinite(vals)) \n #assert(vals.imag > 1e10 and isfinite(vals)) \n # !! This is actually (unexpectedly) positive\n # !! inf. Comment out for now, and see if it\n # !! changes\n #assert(vals.real < -1e10 and isfinite(vals)) \n\n\nclass test_real_if_close(unittest.TestCase):\n def check_basic(self):\n a = rand(10)\n b = real_if_close(a+1e-15j)\n assert(isrealobj(b))\n assert_array_equal(a,b)\n b = real_if_close(a+1e-7j)\n assert(iscomplexobj(b))\n b = real_if_close(a+1e-7j,tol=1e-6)\n assert(isrealobj(b))\n\n\n#-----------------------------------------------------------------------------\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_isscalar,'check_') )\n suites.append( unittest.makeSuite(test_real_if_close,'check_') )\n suites.append( unittest.makeSuite(test_real,'check_') )\n suites.append( unittest.makeSuite(test_imag,'check_') )\n suites.append( unittest.makeSuite(test_iscomplexobj,'check_') )\n suites.append( unittest.makeSuite(test_isrealobj,'check_') ) \n suites.append( unittest.makeSuite(test_iscomplex,'check_') )\n suites.append( unittest.makeSuite(test_isreal,'check_') ) \n suites.append( unittest.makeSuite(test_isnan,'check_') )\n suites.append( unittest.makeSuite(test_isfinite,'check_') )\n suites.append( unittest.makeSuite(test_isinf,'check_') )\n suites.append( unittest.makeSuite(test_isposinf,'check_') ) \n suites.append( unittest.makeSuite(test_isneginf,'check_') )\n suites.append( unittest.makeSuite(test_nan_to_num,'check_') )\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\n\nif __name__ == \"__main__\":\n test()\n", "source_code_before": "# only for short term testing\nimport sys\nsys.path.insert(0,'../..')\n\nimport unittest\nfrom scipy_base.testing import assert_array_equal, assert_equal, rand\nfrom scipy_base.testing import assert_almost_equal, assert_array_almost_equal \n\nfrom scipy_base import *\n# This won't be needed when we get scipy_base finished.\nfrom scipy_base.type_check import *\n \nclass test_isscalar(unittest.TestCase):\n def check_basic(self):\n assert(isscalar(3))\n assert(not isscalar([3]))\n assert(not isscalar((3,)))\n assert(isscalar(3j))\n assert(isscalar(10L))\n assert(isscalar(4.0))\n\nclass test_real(unittest.TestCase):\n def check_real(self):\n y = rand(10,)\n assert_array_equal(y,real(y))\n\n def check_cmplx(self):\n y = rand(10,)+1j*rand(10,)\n assert_array_equal(y.real,real(y))\n\nclass test_imag(unittest.TestCase):\n def check_real(self):\n y = rand(10,)\n assert_array_equal(0,imag(y))\n\n def check_cmplx(self):\n y = rand(10,)+1j*rand(10,)\n assert_array_equal(y.imag,imag(y))\n\nclass test_iscomplex(unittest.TestCase):\n def check_fail(self):\n z = array([-1,0,1])\n res = iscomplex(z)\n assert(not sometrue(res))\n def check_pass(self):\n z = array([-1j,1,0])\n res = iscomplex(z)\n assert_array_equal(res,[1,0,0])\n\nclass test_isreal(unittest.TestCase):\n def check_pass(self):\n z = array([-1,0,1j])\n res = isreal(z)\n assert_array_equal(res,[1,1,0])\n def check_fail(self):\n z = array([-1j,1,0])\n res = isreal(z)\n assert_array_equal(res,[0,1,1])\n\nclass test_iscomplexobj(unittest.TestCase):\n def check_basic(self):\n z = array([-1,0,1])\n assert(not iscomplexobj(z))\n z = array([-1j,0,-1])\n assert(iscomplexobj(z))\n\nclass test_isrealobj(unittest.TestCase):\n def check_basic(self):\n z = array([-1,0,1])\n assert(isrealobj(z))\n z = array([-1j,0,-1])\n assert(not isrealobj(z))\n\nclass test_isnan(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isnan(z) == 0\n assert(alltrue(res)) \n def check_posinf(self): \n assert(isnan(array((1.,))/0.) == 0)\n def check_neginf(self): \n assert(isnan(array((-1.,))/0.) == 0)\n def check_ind(self): \n assert(isnan(array((0.,))/0.) == 1)\n #def check_qnan(self): log(-1) return pi*j now\n # assert(isnan(log(-1.)) == 1)\n def check_integer(self):\n assert(isnan(1) == 0)\n def check_complex(self):\n assert(isnan(1+1j) == 0)\n def check_complex1(self):\n assert(isnan(array(0+0j)/0.) == 1)\n \nclass test_isfinite(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isfinite(z) == 1\n assert(alltrue(res)) \n def check_posinf(self): \n assert(isfinite(array((1.,))/0.) == 0)\n def check_neginf(self): \n assert(isfinite(array((-1.,))/0.) == 0)\n def check_ind(self): \n assert(isfinite(array((0.,))/0.) == 0)\n #def check_qnan(self): \n # assert(isfinite(log(-1.)) == 0)\n def check_integer(self):\n assert(isfinite(1) == 1)\n def check_complex(self):\n assert(isfinite(1+1j) == 1)\n def check_complex1(self):\n assert(isfinite(array(1+1j)/0.) == 0)\n \nclass test_isinf(unittest.TestCase):\n def check_goodvalues(self):\n z = array((-1.,0.,1.))\n res = isinf(z) == 0\n assert(alltrue(res)) \n def check_posinf(self): \n assert(isinf(array((1.,))/0.) == 1)\n def check_posinf_scalar(self): \n assert(isinf(array(1.,)/0.) == 1)\n def check_neginf(self): \n assert(isinf(array((-1.,))/0.) == 1)\n def check_neginf_scalar(self): \n assert(isinf(array(-1.)/0.) == 1)\n def check_ind(self): \n assert(isinf(array((0.,))/0.) == 0)\n #def check_qnan(self): \n # assert(isinf(log(-1.)) == 0)\n # assert(isnan(log(-1.)) == 1)\n\nclass test_isposinf(unittest.TestCase):\n def check_generic(self):\n vals = isposinf(array((-1.,0,1))/0.)\n assert(vals[0] == 0)\n assert(vals[1] == 0)\n assert(vals[2] == 1)\n\nclass test_isneginf(unittest.TestCase):\n def check_generic(self):\n vals = isneginf(array((-1.,0,1))/0.)\n assert(vals[0] == 1)\n assert(vals[1] == 0)\n assert(vals[2] == 0)\n\nclass test_nan_to_num(unittest.TestCase):\n def check_generic(self):\n vals = nan_to_num(array((-1.,0,1))/0.)\n assert(vals[0] < -1e10 and isfinite(vals[0]))\n assert(vals[1] == 0)\n assert(vals[2] > 1e10 and isfinite(vals[2]))\n def check_integer(self):\n vals = nan_to_num(1)\n assert(vals == 1)\n def check_complex_good(self):\n vals = nan_to_num(1+1j)\n assert(vals == 1+1j)\n def check_complex_bad(self):\n v = 1+1j\n v += array(0+1.j)/0.\n vals = nan_to_num(v)\n # !! This is actually (unexpectedly) zero\n assert(vals.imag > 1e10 and isfinite(vals))\n def check_complex_bad2(self):\n v = 1+1j\n v += array(-1+1.j)/0.\n vals = nan_to_num(v)\n assert(isfinite(vals)) \n #assert(vals.imag > 1e10 and isfinite(vals)) \n # !! This is actually (unexpectedly) positive\n # !! inf. Comment out for now, and see if it\n # !! changes\n #assert(vals.real < -1e10 and isfinite(vals)) \n\n\nclass test_real_if_close(unittest.TestCase):\n def check_basic(self):\n a = rand(10)\n b = real_if_close(a+1e-15j)\n assert(isrealobj(b))\n assert_array_equal(a,b)\n b = real_if_close(a+1e-7j)\n assert(iscomplexobj(b))\n b = real_if_close(a+1e-7j,tol=1e-6)\n assert(isrealobj(b))\n\n\n#-----------------------------------------------------------------------------\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_isscalar,'check_') )\n suites.append( unittest.makeSuite(test_real_if_close,'check_') )\n suites.append( unittest.makeSuite(test_real,'check_') )\n suites.append( unittest.makeSuite(test_imag,'check_') )\n suites.append( unittest.makeSuite(test_iscomplexobj,'check_') )\n suites.append( unittest.makeSuite(test_isrealobj,'check_') ) \n suites.append( unittest.makeSuite(test_iscomplex,'check_') )\n suites.append( unittest.makeSuite(test_isreal,'check_') ) \n suites.append( unittest.makeSuite(test_isnan,'check_') )\n suites.append( unittest.makeSuite(test_isfinite,'check_') )\n suites.append( unittest.makeSuite(test_isinf,'check_') )\n suites.append( unittest.makeSuite(test_isposinf,'check_') ) \n suites.append( unittest.makeSuite(test_isneginf,'check_') )\n suites.append( unittest.makeSuite(test_nan_to_num,'check_') )\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test(level=10):\n all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 7, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 14, "end_line": 20, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_real", "long_name": "check_real( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 23, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_cmplx", "long_name": "check_cmplx( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 27, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_real", "long_name": "check_real( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 32, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_cmplx", "long_name": "check_cmplx( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 36, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_fail", "long_name": "check_fail( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 32, "parameters": [ "self" ], "start_line": 41, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_pass", "long_name": "check_pass( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 45, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_pass", "long_name": "check_pass( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 51, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_fail", "long_name": "check_fail( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 55, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 47, "parameters": [ "self" ], "start_line": 61, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 47, "parameters": [ "self" ], "start_line": 68, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_goodvalues", "long_name": "check_goodvalues( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 75, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_posinf", "long_name": "check_posinf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 79, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf", "long_name": "check_neginf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 81, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_ind", "long_name": "check_ind( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 83, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_integer", "long_name": "check_integer( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 87, "end_line": 88, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex", "long_name": "check_complex( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 89, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex1", "long_name": "check_complex1( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 91, "end_line": 92, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_goodvalues", "long_name": "check_goodvalues( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 95, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_posinf", "long_name": "check_posinf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 99, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf", "long_name": "check_neginf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 101, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_ind", "long_name": "check_ind( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 103, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_integer", "long_name": "check_integer( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 107, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex", "long_name": "check_complex( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 109, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex1", "long_name": "check_complex1( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 111, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_goodvalues", "long_name": "check_goodvalues( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 115, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_posinf", "long_name": "check_posinf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 119, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_posinf_scalar", "long_name": "check_posinf_scalar( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 121, "end_line": 122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf", "long_name": "check_neginf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 123, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf_scalar", "long_name": "check_neginf_scalar( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 125, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_ind", "long_name": "check_ind( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 127, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_generic", "long_name": "check_generic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 134, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_generic", "long_name": "check_generic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 141, "end_line": 145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_generic", "long_name": "check_generic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 3, "token_count": 69, "parameters": [ "self" ], "start_line": 148, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_integer", "long_name": "check_integer( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 153, "end_line": 155, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_complex_good", "long_name": "check_complex_good( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 156, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_complex_bad", "long_name": "check_complex_bad( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 2, "token_count": 42, "parameters": [ "self" ], "start_line": 159, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_complex_bad2", "long_name": "check_complex_bad2( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 37, "parameters": [ "self" ], "start_line": 165, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 9, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 178, "end_line": 186, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_type_check.py", "nloc": 19, "complexity": 2, "token_count": 208, "parameters": [ "level" ], "start_line": 191, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 212, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 7, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 14, "end_line": 20, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_real", "long_name": "check_real( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 23, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_cmplx", "long_name": "check_cmplx( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 27, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_real", "long_name": "check_real( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 32, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_cmplx", "long_name": "check_cmplx( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 36, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_fail", "long_name": "check_fail( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 32, "parameters": [ "self" ], "start_line": 41, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_pass", "long_name": "check_pass( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 45, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_pass", "long_name": "check_pass( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 51, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_fail", "long_name": "check_fail( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 55, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 47, "parameters": [ "self" ], "start_line": 61, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 47, "parameters": [ "self" ], "start_line": 68, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_goodvalues", "long_name": "check_goodvalues( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 75, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_posinf", "long_name": "check_posinf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 79, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf", "long_name": "check_neginf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 81, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_ind", "long_name": "check_ind( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 83, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_integer", "long_name": "check_integer( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 87, "end_line": 88, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex", "long_name": "check_complex( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 89, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex1", "long_name": "check_complex1( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 91, "end_line": 92, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_goodvalues", "long_name": "check_goodvalues( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 95, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_posinf", "long_name": "check_posinf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 99, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf", "long_name": "check_neginf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 101, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_ind", "long_name": "check_ind( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 103, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_integer", "long_name": "check_integer( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 107, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex", "long_name": "check_complex( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 109, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_complex1", "long_name": "check_complex1( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 111, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_goodvalues", "long_name": "check_goodvalues( self )", "filename": "test_type_check.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 115, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_posinf", "long_name": "check_posinf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 119, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_posinf_scalar", "long_name": "check_posinf_scalar( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 121, "end_line": 122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf", "long_name": "check_neginf( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 123, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_neginf_scalar", "long_name": "check_neginf_scalar( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 125, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_ind", "long_name": "check_ind( self )", "filename": "test_type_check.py", "nloc": 2, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 127, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check_generic", "long_name": "check_generic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 134, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_generic", "long_name": "check_generic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 141, "end_line": 145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_generic", "long_name": "check_generic( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 3, "token_count": 69, "parameters": [ "self" ], "start_line": 148, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_integer", "long_name": "check_integer( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 153, "end_line": 155, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_complex_good", "long_name": "check_complex_good( self )", "filename": "test_type_check.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 156, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_complex_bad", "long_name": "check_complex_bad( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 2, "token_count": 42, "parameters": [ "self" ], "start_line": 159, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_complex_bad2", "long_name": "check_complex_bad2( self )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 37, "parameters": [ "self" ], "start_line": 165, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_basic", "long_name": "check_basic( self )", "filename": "test_type_check.py", "nloc": 9, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 178, "end_line": 186, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_type_check.py", "nloc": 19, "complexity": 2, "token_count": 208, "parameters": [ "level" ], "start_line": 191, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_type_check.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 212, "end_line": 216, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 178, "complexity": 45, "token_count": 1672, "diff_parsed": { "added": [ "from scipy_test.testing import assert_array_equal, assert_equal, rand", "from scipy_test.testing import assert_almost_equal, assert_array_almost_equal" ], "deleted": [ "from scipy_base.testing import assert_array_equal, assert_equal, rand", "from scipy_base.testing import assert_almost_equal, assert_array_almost_equal" ] } }, { "old_path": "scipy_base/type_check.py", "new_path": "scipy_base/type_check.py", "filename": "type_check.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -198,11 +198,11 @@ def common_type(*arrays):\n #-----------------------------------------------------------------------------\n \n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \n if __name__ == '__main__':\n", "added_lines": 2, "deleted_lines": 2, "source_code": "import types\nimport Numeric\nfrom Numeric import *\nfrom scipy_base.fastumath import *\n\nimport limits\n\n__all__ = ['ScalarType','iscomplexobj','isrealobj','imag','iscomplex',\n 'isscalar','isneginf','isposinf','isnan','isinf','isfinite',\n 'isreal','nan_to_num','real','real_if_close',\n 'typename','cast','common_type']\n\nScalarType = [types.IntType, types.LongType, types.FloatType, types.ComplexType]\n\ntry:\n Char = Numeric.Character\nexcept AttributeError:\n Char = 'c'\n\ntoChar = lambda x: Numeric.asarray(x).astype(Char)\ntoInt8 = lambda x: Numeric.asarray(x).astype(Numeric.Int8)# or use variable names such as Byte\ntoUInt8 = lambda x: Numeric.asarray(x).astype(Numeric.UnsignedInt8)\n_unsigned = 0\nif hasattr(Numeric,'UnsignedInt16'):\n toUInt16 = lambda x: Numeric.asarray(x).astype(Numeric.UnsignedInt16)\n toUInt32 = lambda x: Numeric.asarray(x).astype(Numeric.UnsignedInt32)\n _unsigned = 1\n \ntoInt16 = lambda x: Numeric.asarray(x).astype(Numeric.Int16)\ntoInt32 = lambda x: Numeric.asarray(x).astype(Numeric.Int32)\ntoInt = lambda x: Numeric.asarray(x).astype(Numeric.Int)\ntoFloat32 = lambda x: Numeric.asarray(x).astype(Numeric.Float32)\ntoFloat64 = lambda x: Numeric.asarray(x).astype(Numeric.Float64)\ntoComplex32 = lambda x: Numeric.asarray(x).astype(Numeric.Complex32)\ntoComplex64 = lambda x: Numeric.asarray(x).astype(Numeric.Complex64)\n\n# This is for pre Numeric 21.x compatiblity. Adding it is harmless.\nif not hasattr(Numeric,'Character'):\n Numeric.Character = 'c'\n \ncast = {Numeric.Character: toChar,\n Numeric.UnsignedInt8: toUInt8,\n Numeric.Int8: toInt8,\n Numeric.Int16: toInt16,\n Numeric.Int32: toInt32,\n Numeric.Int: toInt,\n Numeric.Float32: toFloat32,\n Numeric.Float64: toFloat64,\n Numeric.Complex32: toComplex32,\n Numeric.Complex64: toComplex64}\n\nif _unsigned:\n cast[Numeric.UnsignedInt16] = toUInt16\n cast[Numeric.UnsignedInt32] = toUInt32\n \n\ndef isscalar(num):\n if isinstance(num, ArrayType):\n return len(num.shape) == 0 and num.typecode() != 'O'\n return type(num) in ScalarType\n\ndef real(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.real\n else:\n return aval\n\ndef imag(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.imag\n else:\n return array(0,aval.typecode())*aval\n\ndef iscomplex(x):\n return imag(x) != Numeric.zeros(asarray(x).shape)\n\ndef isreal(x):\n return imag(x) == Numeric.zeros(asarray(x).shape)\n\ndef iscomplexobj(x):\n return asarray(x).typecode() in ['F', 'D']\n\ndef isrealobj(x):\n return not asarray(x).typecode() in ['F', 'D']\n\n#-----------------------------------------------------------------------------\n\n##def isnan(val):\n## # fast, but apparently not portable (according to notes by Tim Peters)\n## #return val != val\n## # very slow -- should really use cephes methods or *something* different\n## import ieee_754\n## vals = ravel(val)\n## if array_iscomplex(vals):\n## r = array(map(ieee_754.isnan,real(vals))) \n## i = array(map(ieee_754.isnan,imag(vals)))\n## results = Numeric.logical_or(r,i)\n## else: \n## results = array(map(ieee_754.isnan,vals))\n## if isscalar(val):\n## results = results[0]\n## return results\n\ndef isposinf(val):\n return isinf(val) & (val > 0)\n \ndef isneginf(val):\n return isinf(val) & (val < 0)\n \n##def isinf(val):\n## return Numeric.logical_or(isposinf(val),isneginf(val))\n\n##def isfinite(val):\n## vals = asarray(val)\n## if iscomplexobj(vals):\n## r = isfinite(real(vals))\n## i = isfinite(imag(vals))\n## results = Numeric.logical_and(r,i)\n## else: \n## fin = Numeric.logical_not(isinf(val))\n## an = Numeric.logical_not(isnan(val))\n## results = Numeric.logical_and(fin,an)\n## return results \n\ndef nan_to_num(x):\n # mapping:\n # NaN -> 0\n # Inf -> limits.double_max\n # -Inf -> limits.double_min\n # complex not handled currently\n import limits\n try:\n t = x.typecode()\n except AttributeError:\n t = type(x)\n if t in [types.ComplexType,'F','D']: \n y = nan_to_num(x.real) + 1j * nan_to_num(x.imag)\n else: \n x = Numeric.asarray(x)\n are_inf = isposinf(x)\n are_neg_inf = isneginf(x)\n are_nan = isnan(x)\n choose_array = are_neg_inf + are_nan * 2 + are_inf * 3\n y = Numeric.choose(choose_array,\n (x,limits.double_min, 0., limits.double_max))\n return y\n\n#-----------------------------------------------------------------------------\n\ndef real_if_close(a,tol=1e-13):\n a = Numeric.asarray(a)\n if a.typecode() in ['F','D'] and Numeric.allclose(a.imag, 0, atol=tol):\n a = a.real\n return a\n\n\n#-----------------------------------------------------------------------------\n\n_namefromtype = {'c' : 'character',\n '1' : 'signed char',\n 'b' : 'unsigned char',\n 's' : 'short',\n 'w' : 'unsigned short',\n 'i' : 'integer',\n 'u' : 'unsigned integer',\n 'l' : 'long integer',\n 'f' : 'float',\n 'd' : 'double',\n 'F' : 'complex float',\n 'D' : 'complex double',\n 'O' : 'object'\n }\n\ndef typename(char):\n \"\"\"Return an english name for the given typecode character.\n \"\"\"\n return _namefromtype[char]\n\n#-----------------------------------------------------------------------------\n\n#determine the \"minimum common type code\" for a group of arrays.\narray_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\narray_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\narray_type = [['f', 'd'], ['F', 'D']]\ndef common_type(*arrays):\n kind = 0\n precision = 0\n for a in arrays:\n t = a.typecode()\n kind = max(kind, array_kind[t])\n precision = max(precision, array_precision[t])\n return array_type[kind][precision]\n\n#-----------------------------------------------------------------------------\n# Test Routines\n#-----------------------------------------------------------------------------\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == '__main__':\n print 'float epsilon:',float_epsilon\n print 'float tiny:',float_tiny\n print 'double epsilon:',double_epsilon\n print 'double tiny:',double_tiny\n", "source_code_before": "import types\nimport Numeric\nfrom Numeric import *\nfrom scipy_base.fastumath import *\n\nimport limits\n\n__all__ = ['ScalarType','iscomplexobj','isrealobj','imag','iscomplex',\n 'isscalar','isneginf','isposinf','isnan','isinf','isfinite',\n 'isreal','nan_to_num','real','real_if_close',\n 'typename','cast','common_type']\n\nScalarType = [types.IntType, types.LongType, types.FloatType, types.ComplexType]\n\ntry:\n Char = Numeric.Character\nexcept AttributeError:\n Char = 'c'\n\ntoChar = lambda x: Numeric.asarray(x).astype(Char)\ntoInt8 = lambda x: Numeric.asarray(x).astype(Numeric.Int8)# or use variable names such as Byte\ntoUInt8 = lambda x: Numeric.asarray(x).astype(Numeric.UnsignedInt8)\n_unsigned = 0\nif hasattr(Numeric,'UnsignedInt16'):\n toUInt16 = lambda x: Numeric.asarray(x).astype(Numeric.UnsignedInt16)\n toUInt32 = lambda x: Numeric.asarray(x).astype(Numeric.UnsignedInt32)\n _unsigned = 1\n \ntoInt16 = lambda x: Numeric.asarray(x).astype(Numeric.Int16)\ntoInt32 = lambda x: Numeric.asarray(x).astype(Numeric.Int32)\ntoInt = lambda x: Numeric.asarray(x).astype(Numeric.Int)\ntoFloat32 = lambda x: Numeric.asarray(x).astype(Numeric.Float32)\ntoFloat64 = lambda x: Numeric.asarray(x).astype(Numeric.Float64)\ntoComplex32 = lambda x: Numeric.asarray(x).astype(Numeric.Complex32)\ntoComplex64 = lambda x: Numeric.asarray(x).astype(Numeric.Complex64)\n\n# This is for pre Numeric 21.x compatiblity. Adding it is harmless.\nif not hasattr(Numeric,'Character'):\n Numeric.Character = 'c'\n \ncast = {Numeric.Character: toChar,\n Numeric.UnsignedInt8: toUInt8,\n Numeric.Int8: toInt8,\n Numeric.Int16: toInt16,\n Numeric.Int32: toInt32,\n Numeric.Int: toInt,\n Numeric.Float32: toFloat32,\n Numeric.Float64: toFloat64,\n Numeric.Complex32: toComplex32,\n Numeric.Complex64: toComplex64}\n\nif _unsigned:\n cast[Numeric.UnsignedInt16] = toUInt16\n cast[Numeric.UnsignedInt32] = toUInt32\n \n\ndef isscalar(num):\n if isinstance(num, ArrayType):\n return len(num.shape) == 0 and num.typecode() != 'O'\n return type(num) in ScalarType\n\ndef real(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.real\n else:\n return aval\n\ndef imag(val):\n aval = asarray(val)\n if aval.typecode() in ['F', 'D']:\n return aval.imag\n else:\n return array(0,aval.typecode())*aval\n\ndef iscomplex(x):\n return imag(x) != Numeric.zeros(asarray(x).shape)\n\ndef isreal(x):\n return imag(x) == Numeric.zeros(asarray(x).shape)\n\ndef iscomplexobj(x):\n return asarray(x).typecode() in ['F', 'D']\n\ndef isrealobj(x):\n return not asarray(x).typecode() in ['F', 'D']\n\n#-----------------------------------------------------------------------------\n\n##def isnan(val):\n## # fast, but apparently not portable (according to notes by Tim Peters)\n## #return val != val\n## # very slow -- should really use cephes methods or *something* different\n## import ieee_754\n## vals = ravel(val)\n## if array_iscomplex(vals):\n## r = array(map(ieee_754.isnan,real(vals))) \n## i = array(map(ieee_754.isnan,imag(vals)))\n## results = Numeric.logical_or(r,i)\n## else: \n## results = array(map(ieee_754.isnan,vals))\n## if isscalar(val):\n## results = results[0]\n## return results\n\ndef isposinf(val):\n return isinf(val) & (val > 0)\n \ndef isneginf(val):\n return isinf(val) & (val < 0)\n \n##def isinf(val):\n## return Numeric.logical_or(isposinf(val),isneginf(val))\n\n##def isfinite(val):\n## vals = asarray(val)\n## if iscomplexobj(vals):\n## r = isfinite(real(vals))\n## i = isfinite(imag(vals))\n## results = Numeric.logical_and(r,i)\n## else: \n## fin = Numeric.logical_not(isinf(val))\n## an = Numeric.logical_not(isnan(val))\n## results = Numeric.logical_and(fin,an)\n## return results \n\ndef nan_to_num(x):\n # mapping:\n # NaN -> 0\n # Inf -> limits.double_max\n # -Inf -> limits.double_min\n # complex not handled currently\n import limits\n try:\n t = x.typecode()\n except AttributeError:\n t = type(x)\n if t in [types.ComplexType,'F','D']: \n y = nan_to_num(x.real) + 1j * nan_to_num(x.imag)\n else: \n x = Numeric.asarray(x)\n are_inf = isposinf(x)\n are_neg_inf = isneginf(x)\n are_nan = isnan(x)\n choose_array = are_neg_inf + are_nan * 2 + are_inf * 3\n y = Numeric.choose(choose_array,\n (x,limits.double_min, 0., limits.double_max))\n return y\n\n#-----------------------------------------------------------------------------\n\ndef real_if_close(a,tol=1e-13):\n a = Numeric.asarray(a)\n if a.typecode() in ['F','D'] and Numeric.allclose(a.imag, 0, atol=tol):\n a = a.real\n return a\n\n\n#-----------------------------------------------------------------------------\n\n_namefromtype = {'c' : 'character',\n '1' : 'signed char',\n 'b' : 'unsigned char',\n 's' : 'short',\n 'w' : 'unsigned short',\n 'i' : 'integer',\n 'u' : 'unsigned integer',\n 'l' : 'long integer',\n 'f' : 'float',\n 'd' : 'double',\n 'F' : 'complex float',\n 'D' : 'complex double',\n 'O' : 'object'\n }\n\ndef typename(char):\n \"\"\"Return an english name for the given typecode character.\n \"\"\"\n return _namefromtype[char]\n\n#-----------------------------------------------------------------------------\n\n#determine the \"minimum common type code\" for a group of arrays.\narray_kind = {'i':0, 'l': 0, 'f': 0, 'd': 0, 'F': 1, 'D': 1}\narray_precision = {'i': 1, 'l': 1, 'f': 0, 'd': 1, 'F': 0, 'D': 1}\narray_type = [['f', 'd'], ['F', 'D']]\ndef common_type(*arrays):\n kind = 0\n precision = 0\n for a in arrays:\n t = a.typecode()\n kind = max(kind, array_kind[t])\n precision = max(precision, array_precision[t])\n return array_type[kind][precision]\n\n#-----------------------------------------------------------------------------\n# Test Routines\n#-----------------------------------------------------------------------------\n\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == '__main__':\n print 'float epsilon:',float_epsilon\n print 'float tiny:',float_tiny\n print 'double epsilon:',double_epsilon\n print 'double tiny:',double_tiny\n", "methods": [ { "name": "isscalar", "long_name": "isscalar( num )", "filename": "type_check.py", "nloc": 4, "complexity": 3, "token_count": 37, "parameters": [ "num" ], "start_line": 57, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "real", "long_name": "real( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "val" ], "start_line": 62, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "imag", "long_name": "imag( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "val" ], "start_line": 69, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "iscomplex", "long_name": "iscomplex( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 76, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isreal", "long_name": "isreal( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 79, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "iscomplexobj", "long_name": "iscomplexobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "x" ], "start_line": 82, "end_line": 83, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isrealobj", "long_name": "isrealobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "x" ], "start_line": 85, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isposinf", "long_name": "isposinf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 106, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isneginf", "long_name": "isneginf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 109, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "nan_to_num", "long_name": "nan_to_num( x )", "filename": "type_check.py", "nloc": 17, "complexity": 3, "token_count": 119, "parameters": [ "x" ], "start_line": 127, "end_line": 148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "real_if_close", "long_name": "real_if_close( a , tol = 1e - 13 )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 54, "parameters": [ "a", "tol" ], "start_line": 152, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "typename", "long_name": "typename( char )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "char" ], "start_line": 176, "end_line": 179, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "common_type", "long_name": "common_type( * arrays )", "filename": "type_check.py", "nloc": 8, "complexity": 2, "token_count": 54, "parameters": [ "arrays" ], "start_line": 187, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "type_check.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 200, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "type_check.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 204, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "isscalar", "long_name": "isscalar( num )", "filename": "type_check.py", "nloc": 4, "complexity": 3, "token_count": 37, "parameters": [ "num" ], "start_line": 57, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "real", "long_name": "real( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 32, "parameters": [ "val" ], "start_line": 62, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "imag", "long_name": "imag( val )", "filename": "type_check.py", "nloc": 6, "complexity": 2, "token_count": 43, "parameters": [ "val" ], "start_line": 69, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "iscomplex", "long_name": "iscomplex( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 76, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isreal", "long_name": "isreal( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 22, "parameters": [ "x" ], "start_line": 79, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "iscomplexobj", "long_name": "iscomplexobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "x" ], "start_line": 82, "end_line": 83, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isrealobj", "long_name": "isrealobj( x )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "x" ], "start_line": 85, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isposinf", "long_name": "isposinf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 106, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "isneginf", "long_name": "isneginf( val )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 109, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "nan_to_num", "long_name": "nan_to_num( x )", "filename": "type_check.py", "nloc": 17, "complexity": 3, "token_count": 119, "parameters": [ "x" ], "start_line": 127, "end_line": 148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "real_if_close", "long_name": "real_if_close( a , tol = 1e - 13 )", "filename": "type_check.py", "nloc": 5, "complexity": 3, "token_count": 54, "parameters": [ "a", "tol" ], "start_line": 152, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "typename", "long_name": "typename( char )", "filename": "type_check.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "char" ], "start_line": 176, "end_line": 179, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "common_type", "long_name": "common_type( * arrays )", "filename": "type_check.py", "nloc": 8, "complexity": 2, "token_count": 54, "parameters": [ "arrays" ], "start_line": 187, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "type_check.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 200, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "type_check.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 204, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "type_check.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 204, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "type_check.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 200, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 132, "complexity": 24, "token_count": 1085, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } }, { "old_path": "weave/vtk_spec.py", "new_path": "weave/vtk_spec.py", "filename": "vtk_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -133,10 +133,10 @@ def __cmp__(self,other):\n # this should only be enabled on machines with access to a display device\n # It'll cause problems otherwise.\n def test(level=10):\n- from scipy_base.testing import module_test\n+ from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n \n def test_suite(level=1):\n- from scipy_base.testing import module_test_suite\n+ from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n \"\"\"\n", "added_lines": 2, "deleted_lines": 2, "source_code": "\"\"\"\nVTK type converter.\n\nThis module handles conversion between VTK C++ and VTK Python objects\nso that one can write inline C++ code to manipulate VTK Python\nobjects. It requires that you have VTK and the VTK-Python wrappers\ninstalled. It has been tested with VTK 4.0 and above. The code is\nbased on wx_spec.py. You will need to call inline with include_dirs,\nlibrary_dirs and often even libraries appropriately set for this to\nwork without errors. Sometimes you might need to include additional\nheaders.\n\nDistributed under the SciPy License.\n\nAuthors:\n Prabhu Ramachandran \n Eric Jones \n\"\"\"\n\nimport common_info\nfrom c_spec import common_base_converter\n\n\nvtk_py_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic:\n %(c_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n %(c_type)s vtk_ptr = (%(c_type)s) vtkPythonGetPointerFromObject(py_obj, \"%(type_name)s\");\n if (!vtk_ptr)\n handle_conversion_error(py_obj,\"%(type_name)s\", name);\n %(inc_ref_count)s\n return vtk_ptr;\n }\n\n %(c_type)s py_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n %(c_type)s vtk_ptr = (%(c_type)s) vtkPythonGetPointerFromObject(py_obj, \"%(type_name)s\");\n if (!vtk_ptr)\n handle_bad_type(py_obj,\"%(type_name)s\", name);\n %(inc_ref_count)s\n return vtk_ptr;\n }\n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\nvtk_c_to_py_template = \\\n\"\"\"\nPyObject* %(type_name)s_to_py(vtkObjectBase* obj)\n{\n return vtkPythonGetObjectFromPointer(obj);\n}\n\"\"\"\n \n\nclass vtk_converter(common_base_converter):\n def __init__(self,class_name=\"undefined\"):\n self.class_name = class_name\n common_base_converter.__init__(self)\n\n def init_info(self):\n common_base_converter.init_info(self)\n # These are generated on the fly instead of defined at \n # the class level.\n self.type_name = self.class_name\n self.c_type = self.class_name + \"*\"\n self.to_c_return = None # not used\n self.check_func = None # not used\n hdr = self.class_name + \".h\"\n # Remember that you need both the quotes!\n self.headers.extend(['\"vtkPythonUtil.h\"', '\"vtkObject.h\"',\n '\"%s\"'%hdr])\n #self.include_dirs.extend(vtk_inc)\n #self.define_macros.append(('SOME_VARIABLE', '1'))\n #self.library_dirs.extend(vtk_lib)\n self.libraries.extend(['vtkCommonPython', 'vtkCommon'])\n #self.support_code.append(common_info.swig_support_code)\n \n def type_match(self,value):\n is_match = 0\n try:\n if value.IsA('vtkObject'):\n is_match = 1\n except AttributeError:\n pass\n return is_match\n\n def generate_build_info(self):\n if self.class_name != \"undefined\":\n res = common_base_converter.generate_build_info(self)\n else:\n # if there isn't a class_name, we don't want the\n # we don't want the support_code to be included\n import base_info\n res = base_info.base_info()\n return res\n \n def py_to_c_code(self):\n return vtk_py_to_c_template % self.template_vars()\n\n def c_to_py_code(self):\n return vtk_c_to_py_template % self.template_vars()\n \n def type_spec(self,name,value):\n # factory\n class_name = value.__class__.__name__\n new_spec = self.__class__(class_name)\n new_spec.name = name \n return new_spec\n\n def __cmp__(self,other):\n #only works for equal\n res = -1\n try:\n res = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__) or \\\n cmp(self.class_name, other.class_name) or \\\n cmp(self.type_name,other.type_name)\n except:\n pass\n return res\n\n\"\"\"\n# this should only be enabled on machines with access to a display device\n# It'll cause problems otherwise.\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\"\"\"\n", "source_code_before": "\"\"\"\nVTK type converter.\n\nThis module handles conversion between VTK C++ and VTK Python objects\nso that one can write inline C++ code to manipulate VTK Python\nobjects. It requires that you have VTK and the VTK-Python wrappers\ninstalled. It has been tested with VTK 4.0 and above. The code is\nbased on wx_spec.py. You will need to call inline with include_dirs,\nlibrary_dirs and often even libraries appropriately set for this to\nwork without errors. Sometimes you might need to include additional\nheaders.\n\nDistributed under the SciPy License.\n\nAuthors:\n Prabhu Ramachandran \n Eric Jones \n\"\"\"\n\nimport common_info\nfrom c_spec import common_base_converter\n\n\nvtk_py_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic:\n %(c_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n %(c_type)s vtk_ptr = (%(c_type)s) vtkPythonGetPointerFromObject(py_obj, \"%(type_name)s\");\n if (!vtk_ptr)\n handle_conversion_error(py_obj,\"%(type_name)s\", name);\n %(inc_ref_count)s\n return vtk_ptr;\n }\n\n %(c_type)s py_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n %(c_type)s vtk_ptr = (%(c_type)s) vtkPythonGetPointerFromObject(py_obj, \"%(type_name)s\");\n if (!vtk_ptr)\n handle_bad_type(py_obj,\"%(type_name)s\", name);\n %(inc_ref_count)s\n return vtk_ptr;\n }\n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\nvtk_c_to_py_template = \\\n\"\"\"\nPyObject* %(type_name)s_to_py(vtkObjectBase* obj)\n{\n return vtkPythonGetObjectFromPointer(obj);\n}\n\"\"\"\n \n\nclass vtk_converter(common_base_converter):\n def __init__(self,class_name=\"undefined\"):\n self.class_name = class_name\n common_base_converter.__init__(self)\n\n def init_info(self):\n common_base_converter.init_info(self)\n # These are generated on the fly instead of defined at \n # the class level.\n self.type_name = self.class_name\n self.c_type = self.class_name + \"*\"\n self.to_c_return = None # not used\n self.check_func = None # not used\n hdr = self.class_name + \".h\"\n # Remember that you need both the quotes!\n self.headers.extend(['\"vtkPythonUtil.h\"', '\"vtkObject.h\"',\n '\"%s\"'%hdr])\n #self.include_dirs.extend(vtk_inc)\n #self.define_macros.append(('SOME_VARIABLE', '1'))\n #self.library_dirs.extend(vtk_lib)\n self.libraries.extend(['vtkCommonPython', 'vtkCommon'])\n #self.support_code.append(common_info.swig_support_code)\n \n def type_match(self,value):\n is_match = 0\n try:\n if value.IsA('vtkObject'):\n is_match = 1\n except AttributeError:\n pass\n return is_match\n\n def generate_build_info(self):\n if self.class_name != \"undefined\":\n res = common_base_converter.generate_build_info(self)\n else:\n # if there isn't a class_name, we don't want the\n # we don't want the support_code to be included\n import base_info\n res = base_info.base_info()\n return res\n \n def py_to_c_code(self):\n return vtk_py_to_c_template % self.template_vars()\n\n def c_to_py_code(self):\n return vtk_c_to_py_template % self.template_vars()\n \n def type_spec(self,name,value):\n # factory\n class_name = value.__class__.__name__\n new_spec = self.__class__(class_name)\n new_spec.name = name \n return new_spec\n\n def __cmp__(self,other):\n #only works for equal\n res = -1\n try:\n res = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__) or \\\n cmp(self.class_name, other.class_name) or \\\n cmp(self.type_name,other.type_name)\n except:\n pass\n return res\n\n\"\"\"\n# this should only be enabled on machines with access to a display device\n# It'll cause problems otherwise.\ndef test(level=10):\n from scipy_base.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_base.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\"\"\"\n", "methods": [ { "name": "__init__", "long_name": "__init__( self , class_name = \"undefined\" )", "filename": "vtk_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self", "class_name" ], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "vtk_spec.py", "nloc": 10, "complexity": 1, "token_count": 72, "parameters": [ "self" ], "start_line": 70, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "vtk_spec.py", "nloc": 8, "complexity": 3, "token_count": 29, "parameters": [ "self", "value" ], "start_line": 88, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "vtk_spec.py", "nloc": 7, "complexity": 2, "token_count": 33, "parameters": [ "self" ], "start_line": 97, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "vtk_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 107, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "vtk_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "vtk_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self", "name", "value" ], "start_line": 113, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "vtk_spec.py", "nloc": 10, "complexity": 5, "token_count": 66, "parameters": [ "self", "other" ], "start_line": 120, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self , class_name = \"undefined\" )", "filename": "vtk_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self", "class_name" ], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "vtk_spec.py", "nloc": 10, "complexity": 1, "token_count": 72, "parameters": [ "self" ], "start_line": 70, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "vtk_spec.py", "nloc": 8, "complexity": 3, "token_count": 29, "parameters": [ "self", "value" ], "start_line": 88, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "vtk_spec.py", "nloc": 7, "complexity": 2, "token_count": 33, "parameters": [ "self" ], "start_line": 97, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "vtk_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 107, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "vtk_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 110, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "vtk_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self", "name", "value" ], "start_line": 113, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "vtk_spec.py", "nloc": 10, "complexity": 5, "token_count": 66, "parameters": [ "self", "other" ], "start_line": 120, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 117, "complexity": 15, "token_count": 307, "diff_parsed": { "added": [ " from scipy_test.testing import module_test", " from scipy_test.testing import module_test_suite" ], "deleted": [ " from scipy_base.testing import module_test", " from scipy_base.testing import module_test_suite" ] } } ] }, { "hash": "6cdc5475289cd2d0ec41d793aa979d91ea965be2", "msg": "MSVC complained about 1.0/0.0 as a divide by 0 error. The error went away if I\nmade a variable named zero=0.0 and did 1/zero.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-09-18T21:16:17+00:00", "author_timezone": 0, "committer_date": "2002-09-18T21:16:17+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "819731acb7ab212c74a850239cc2188d51a4ed03" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 4, "insertions": 7, "lines": 11, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_base/fastumathmodule.c", "new_path": "scipy_base/fastumathmodule.c", "filename": "fastumathmodule.c", "extension": "c", "change_type": "MODIFY", "diff": "@@ -36,7 +36,10 @@ static struct PyMethodDef methods[] = {\n \n DL_EXPORT(void) initfastumath(void) {\n PyObject *m, *d, *s, *f1;\n- \n+ /* MSVC compiler complained about divide by 0 when 1/0.0\n+ was used. changing it to 1.0/0.0 fixed the compile error. */ \n+ double zero = 0.0;\n+ \n /* Create the module and add the functions */\n m = Py_InitModule(\"fastumath\", methods); \n \n@@ -53,14 +56,14 @@ DL_EXPORT(void) initfastumath(void) {\n \n /* Load the ufunc operators into the array module's namespace */\n InitOperators(d); \n-\n+ \n PyDict_SetItemString(d, \"pi\", s = PyFloat_FromDouble(atan(1.0) * 4.0));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"e\", s = PyFloat_FromDouble(exp(1.0)));\n Py_DECREF(s);\n- PyDict_SetItemString(d, \"PINF\", s = PyFloat_FromDouble(1.0/0.0));\n+ PyDict_SetItemString(d, \"PINF\", s = PyFloat_FromDouble(1.0/zero));\n Py_DECREF(s);\n- PyDict_SetItemString(d, \"NINF\", s = PyFloat_FromDouble(-1.0/0.0));\n+ PyDict_SetItemString(d, \"NINF\", s = PyFloat_FromDouble(-1.0/zero));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"PZERO\", s = PyFloat_FromDouble(0.0));\n Py_DECREF(s);\n", "added_lines": 7, "deleted_lines": 4, "source_code": "#include \"Python.h\"\n#include \"Numeric/arrayobject.h\"\n#include \"Numeric/ufuncobject.h\"\n#include \"abstract.h\"\n#include \n#include \"mconf_lite.h\"\n\n/* Fast umath module whose functions do not check for range and domain\n errors.\n\n Replacement for umath + additions for isnan, isfinite, and isinf\n Also allows comparison operations on complex numbers (just compares\n the real part) and logical operations.\n\n All logical operations return UBYTE arrays.\n*/\n\n#if defined _ISOC99_SOURCE || defined _XOPEN_SOURCE_EXTENDED \\\n || defined _BSD_SOURCE || defined _SVID_SOURCE\n#define HAVE_INVERSE_HYPERBOLIC 1\n#endif\n\n/* Wrapper to include the correct version */\n\n#ifdef PyArray_UNSIGNED_TYPES\n#include \"fastumath_unsigned.inc\"\n#else\n#include \"fastumath_nounsigned.inc\"\n#endif\n\n/* Initialization function for the module (*must* be called initArray) */\n\nstatic struct PyMethodDef methods[] = {\n {NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\nDL_EXPORT(void) initfastumath(void) {\n PyObject *m, *d, *s, *f1;\n /* MSVC compiler complained about divide by 0 when 1/0.0\n was used. changing it to 1.0/0.0 fixed the compile error. */ \n double zero = 0.0;\n \n /* Create the module and add the functions */\n m = Py_InitModule(\"fastumath\", methods); \n\n /* Import the array and ufunc objects */\n import_array();\n import_ufunc();\n\n /* Add some symbolic constants to the module */\n d = PyModule_GetDict(m);\n\n s = PyString_FromString(\"2.2\");\n PyDict_SetItemString(d, \"__version__\", s);\n Py_DECREF(s);\n\n /* Load the ufunc operators into the array module's namespace */\n InitOperators(d); \n \n PyDict_SetItemString(d, \"pi\", s = PyFloat_FromDouble(atan(1.0) * 4.0));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"e\", s = PyFloat_FromDouble(exp(1.0)));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"PINF\", s = PyFloat_FromDouble(1.0/zero));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"NINF\", s = PyFloat_FromDouble(-1.0/zero));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"PZERO\", s = PyFloat_FromDouble(0.0));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"NZERO\", s = PyFloat_FromDouble(-0.0));\n Py_DECREF(s);\n#if defined(NAN) \n PyDict_SetItemString(d, \"NAN\", s = PyFloat_FromDouble(NAN));\n Py_DECREF(s);\n#endif\n\n\n f1 = PyDict_GetItemString(d, \"conjugate\"); /* Borrowed reference */\n\n /* Setup the array object's numerical structures */\n PyArray_SetNumericOps(d);\n\n PyDict_SetItemString(d, \"conj\", f1); /* shorthand for conjugate */\n \n /* Check for errors */\n if (PyErr_Occurred())\n\tPy_FatalError(\"can't initialize module fastumath\");\n}\n\n", "source_code_before": "#include \"Python.h\"\n#include \"Numeric/arrayobject.h\"\n#include \"Numeric/ufuncobject.h\"\n#include \"abstract.h\"\n#include \n#include \"mconf_lite.h\"\n\n/* Fast umath module whose functions do not check for range and domain\n errors.\n\n Replacement for umath + additions for isnan, isfinite, and isinf\n Also allows comparison operations on complex numbers (just compares\n the real part) and logical operations.\n\n All logical operations return UBYTE arrays.\n*/\n\n#if defined _ISOC99_SOURCE || defined _XOPEN_SOURCE_EXTENDED \\\n || defined _BSD_SOURCE || defined _SVID_SOURCE\n#define HAVE_INVERSE_HYPERBOLIC 1\n#endif\n\n/* Wrapper to include the correct version */\n\n#ifdef PyArray_UNSIGNED_TYPES\n#include \"fastumath_unsigned.inc\"\n#else\n#include \"fastumath_nounsigned.inc\"\n#endif\n\n/* Initialization function for the module (*must* be called initArray) */\n\nstatic struct PyMethodDef methods[] = {\n {NULL,\t\tNULL, 0}\t\t/* sentinel */\n};\n\nDL_EXPORT(void) initfastumath(void) {\n PyObject *m, *d, *s, *f1;\n \n /* Create the module and add the functions */\n m = Py_InitModule(\"fastumath\", methods); \n\n /* Import the array and ufunc objects */\n import_array();\n import_ufunc();\n\n /* Add some symbolic constants to the module */\n d = PyModule_GetDict(m);\n\n s = PyString_FromString(\"2.2\");\n PyDict_SetItemString(d, \"__version__\", s);\n Py_DECREF(s);\n\n /* Load the ufunc operators into the array module's namespace */\n InitOperators(d); \n\n PyDict_SetItemString(d, \"pi\", s = PyFloat_FromDouble(atan(1.0) * 4.0));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"e\", s = PyFloat_FromDouble(exp(1.0)));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"PINF\", s = PyFloat_FromDouble(1.0/0.0));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"NINF\", s = PyFloat_FromDouble(-1.0/0.0));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"PZERO\", s = PyFloat_FromDouble(0.0));\n Py_DECREF(s);\n PyDict_SetItemString(d, \"NZERO\", s = PyFloat_FromDouble(-0.0));\n Py_DECREF(s);\n#if defined(NAN) \n PyDict_SetItemString(d, \"NAN\", s = PyFloat_FromDouble(NAN));\n Py_DECREF(s);\n#endif\n\n\n f1 = PyDict_GetItemString(d, \"conjugate\"); /* Borrowed reference */\n\n /* Setup the array object's numerical structures */\n PyArray_SetNumericOps(d);\n\n PyDict_SetItemString(d, \"conj\", f1); /* shorthand for conjugate */\n \n /* Check for errors */\n if (PyErr_Occurred())\n\tPy_FatalError(\"can't initialize module fastumath\");\n}\n\n", "methods": [ { "name": "initfastumath", "long_name": "initfastumath()", "filename": "fastumathmodule.c", "nloc": 31, "complexity": 3, "token_count": 254, "parameters": [], "start_line": 37, "end_line": 88, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 } ], "methods_before": [ { "name": "initfastumath", "long_name": "initfastumath()", "filename": "fastumathmodule.c", "nloc": 30, "complexity": 3, "token_count": 249, "parameters": [], "start_line": 37, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "initfastumath", "long_name": "initfastumath()", "filename": "fastumathmodule.c", "nloc": 31, "complexity": 3, "token_count": 254, "parameters": [], "start_line": 37, "end_line": 88, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 } ], "nloc": 42, "complexity": 3, "token_count": 292, "diff_parsed": { "added": [ " /* MSVC compiler complained about divide by 0 when 1/0.0", " was used. changing it to 1.0/0.0 fixed the compile error. */", " double zero = 0.0;", "", "", " PyDict_SetItemString(d, \"PINF\", s = PyFloat_FromDouble(1.0/zero));", " PyDict_SetItemString(d, \"NINF\", s = PyFloat_FromDouble(-1.0/zero));" ], "deleted": [ "", "", " PyDict_SetItemString(d, \"PINF\", s = PyFloat_FromDouble(1.0/0.0));", " PyDict_SetItemString(d, \"NINF\", s = PyFloat_FromDouble(-1.0/0.0));" ] } } ] }, { "hash": "f3e6c3774bf4cb7103391826f27fe5a849fa856b", "msg": "MSVC did not have a linker_so variable defined. This defines a dummy value for it (set to None) so that scipy_base can be built and used with MSVC. Other pure C modules will also work with MSVC. C/Fortran will have to wait so that we can work out any linker issues.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-09-18T21:17:46+00:00", "author_timezone": 0, "committer_date": "2002-09-18T21:17:46+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "6cdc5475289cd2d0ec41d793aa979d91ea965be2" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 0, "insertions": 6, "lines": 6, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/command/build_ext.py", "new_path": "scipy_distutils/command/build_ext.py", "filename": "build_ext.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -12,6 +12,12 @@\n class build_ext (old_build_ext):\n \n def build_extension(self, ext):\n+ \n+ # The MSVC compiler doesn't have a linker_so attribute.\n+ # Giving it a dummy one of None seems to do the trick.\n+ if not hasattr(self.compiler,'linker_so'):\n+ self.compiler.linker_so = None\n+ \n #XXX: anything else we need to save?\n save_linker_so = self.compiler.linker_so\n save_compiler_libs = self.compiler.libraries\n", "added_lines": 6, "deleted_lines": 0, "source_code": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os, string\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n \n # The MSVC compiler doesn't have a linker_so attribute.\n # Giving it a dummy one of None seems to do the trick.\n if not hasattr(self.compiler,'linker_so'):\n self.compiler.linker_so = None\n \n #XXX: anything else we need to save?\n save_linker_so = self.compiler.linker_so\n save_compiler_libs = self.compiler.libraries\n save_compiler_libs_dirs = self.compiler.library_dirs\n \n # support for building static fortran libraries\n need_f_libs = 0\n need_f_opts = getattr(ext,'need_fcompiler_opts',0)\n ext_name = string.split(ext.name,'.')[-1]\n\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n if build_flib.has_f_library(ext_name):\n need_f_libs = 1\n else:\n for lib_name in ext.libraries:\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n elif need_f_opts:\n build_flib = self.get_finalized_command('build_flib')\n\n #self.announce('%s %s needs fortran libraries %s %s'%(\\\n # ext.name,ext_name,need_f_libs,need_f_opts))\n \n if need_f_libs:\n if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.insert(0,ext_name)\n for lib_name in ext.libraries[:]:\n ext.libraries.extend(build_flib.get_library_names(lib_name))\n ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))\n ext.library_dirs.append(build_flib.build_flib)\n\n if need_f_libs or need_f_opts:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n if moreargs != []:\n if ext.extra_link_args is None:\n ext.extra_link_args = moreargs\n else:\n ext.extra_link_args += moreargs\n\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n\n linker_so = build_flib.fcompiler.get_linker_so()\n\n if linker_so is not None:\n if linker_so is not save_linker_so:\n self.announce('replacing linker_so %r with %r' %(\\\n ' '.join(save_linker_so),\n ' '.join(linker_so)))\n self.compiler.linker_so = linker_so\n l = build_flib.get_fcompiler_library_names()\n #l = self.compiler.libraries + l\n self.compiler.libraries = l\n l = ( self.compiler.library_dirs +\n build_flib.get_fcompiler_library_dirs() )\n self.compiler.library_dirs = l\n else:\n libs = build_flib.get_fcompiler_library_names()\n for lib in libs:\n if lib not in self.compiler.libraries:\n self.compiler.libraries.append(lib)\n\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n if lib_dir not in self.compiler.library_dirs:\n self.compiler.library_dirs.append(lib_dir)\n\n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n\n if save_linker_so is not self.compiler.linker_so:\n self.announce('restoring linker_so %r' % ' '.join(save_linker_so))\n self.compiler.linker_so = save_linker_so\n self.compiler.libraries = save_compiler_libs\n self.compiler.library_dirs = save_compiler_libs_dirs\n\n return res\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n filenames.extend(ext.sources)\n filenames.extend(get_headers(get_directories(ext.sources)))\n\n return filenames\n\n \n", "source_code_before": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os, string\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n #XXX: anything else we need to save?\n save_linker_so = self.compiler.linker_so\n save_compiler_libs = self.compiler.libraries\n save_compiler_libs_dirs = self.compiler.library_dirs\n \n # support for building static fortran libraries\n need_f_libs = 0\n need_f_opts = getattr(ext,'need_fcompiler_opts',0)\n ext_name = string.split(ext.name,'.')[-1]\n\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n if build_flib.has_f_library(ext_name):\n need_f_libs = 1\n else:\n for lib_name in ext.libraries:\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n elif need_f_opts:\n build_flib = self.get_finalized_command('build_flib')\n\n #self.announce('%s %s needs fortran libraries %s %s'%(\\\n # ext.name,ext_name,need_f_libs,need_f_opts))\n \n if need_f_libs:\n if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.insert(0,ext_name)\n for lib_name in ext.libraries[:]:\n ext.libraries.extend(build_flib.get_library_names(lib_name))\n ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))\n ext.library_dirs.append(build_flib.build_flib)\n\n if need_f_libs or need_f_opts:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n if moreargs != []:\n if ext.extra_link_args is None:\n ext.extra_link_args = moreargs\n else:\n ext.extra_link_args += moreargs\n\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n\n linker_so = build_flib.fcompiler.get_linker_so()\n\n if linker_so is not None:\n if linker_so is not save_linker_so:\n self.announce('replacing linker_so %r with %r' %(\\\n ' '.join(save_linker_so),\n ' '.join(linker_so)))\n self.compiler.linker_so = linker_so\n l = build_flib.get_fcompiler_library_names()\n #l = self.compiler.libraries + l\n self.compiler.libraries = l\n l = ( self.compiler.library_dirs +\n build_flib.get_fcompiler_library_dirs() )\n self.compiler.library_dirs = l\n else:\n libs = build_flib.get_fcompiler_library_names()\n for lib in libs:\n if lib not in self.compiler.libraries:\n self.compiler.libraries.append(lib)\n\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n if lib_dir not in self.compiler.library_dirs:\n self.compiler.library_dirs.append(lib_dir)\n\n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n\n if save_linker_so is not self.compiler.linker_so:\n self.announce('restoring linker_so %r' % ' '.join(save_linker_so))\n self.compiler.linker_so = save_linker_so\n self.compiler.libraries = save_compiler_libs\n self.compiler.library_dirs = save_compiler_libs_dirs\n\n return res\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n filenames.extend(ext.sources)\n filenames.extend(get_headers(get_directories(ext.sources)))\n\n return filenames\n\n \n", "methods": [ { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 65, "complexity": 23, "token_count": 476, "parameters": [ "self", "ext" ], "start_line": 14, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 87, "top_nesting_level": 1 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_ext.py", "nloc": 7, "complexity": 2, "token_count": 48, "parameters": [ "self" ], "start_line": 102, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 } ], "methods_before": [ { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 63, "complexity": 22, "token_count": 458, "parameters": [ "self", "ext" ], "start_line": 14, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 81, "top_nesting_level": 1 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_ext.py", "nloc": 7, "complexity": 2, "token_count": 48, "parameters": [ "self" ], "start_line": 96, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 65, "complexity": 23, "token_count": 476, "parameters": [ "self", "ext" ], "start_line": 14, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 87, "top_nesting_level": 1 } ], "nloc": 80, "complexity": 25, "token_count": 569, "diff_parsed": { "added": [ "", " # The MSVC compiler doesn't have a linker_so attribute.", " # Giving it a dummy one of None seems to do the trick.", " if not hasattr(self.compiler,'linker_so'):", " self.compiler.linker_so = None", "" ], "deleted": [] } } ] }, { "hash": "09d3a0753f3b1f03c5990084c152af06775536f5", "msg": "Fixed problem with unix2dos file conversion routine", "author": { "name": "dmorrill", "email": "dmorrill@localhost" }, "committer": { "name": "dmorrill", "email": "dmorrill@localhost" }, "author_date": "2002-09-18T22:44:33+00:00", "author_timezone": 0, "committer_date": "2002-09-18T22:44:33+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "f3e6c3774bf4cb7103391826f27fe5a849fa856b" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 1, "insertions": 2, "lines": 3, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/line_endings.py", "new_path": "scipy_distutils/line_endings.py", "filename": "line_endings.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -44,7 +44,8 @@ def unix2dos(file):\n print file, \"Binary!\"\n return\n \n- newdata = re.sub(\"\\n\", \"\\r\\n\", data)\n+ newdata = re.sub(\"\\r\\n\", \"\\n\", data)\n+ newdata = re.sub(\"\\n\", \"\\r\\n\", newdata)\n if newdata != data:\n print 'unix2dos:', file\n f = open(file, \"wb\")\n", "added_lines": 2, "deleted_lines": 1, "source_code": "\"\"\" Functions for converting from DOS to UNIX line endings\n\"\"\"\n\nimport sys, re, os\n\ndef dos2unix(file):\n \"Replace CRLF with LF in argument files. Print names of changed files.\" \n if os.path.isdir(file):\n print file, \"Directory!\"\n return\n \n data = open(file, \"rb\").read()\n if '\\0' in data:\n print file, \"Binary!\"\n return\n \n newdata = re.sub(\"\\r\\n\", \"\\n\", data)\n if newdata != data:\n print 'dos2unix:', file\n f = open(file, \"wb\")\n f.write(newdata)\n f.close()\n else:\n print file, 'ok' \n\ndef dos2unix_one_dir(args,dir_name,file_names):\n for file in file_names:\n full_path = os.path.join(dir_name,file)\n dos2unix(full_path)\n \ndef dos2unix_dir(dir_name):\n os.path.walk(dir_name,dos2unix_one_dir,[])\n\n#----------------------------------\n\ndef unix2dos(file):\n \"Replace LF with CRLF in argument files. Print names of changed files.\" \n if os.path.isdir(file):\n print file, \"Directory!\"\n return\n \n data = open(file, \"rb\").read()\n if '\\0' in data:\n print file, \"Binary!\"\n return\n \n newdata = re.sub(\"\\r\\n\", \"\\n\", data)\n newdata = re.sub(\"\\n\", \"\\r\\n\", newdata)\n if newdata != data:\n print 'unix2dos:', file\n f = open(file, \"wb\")\n f.write(newdata)\n f.close()\n else:\n print file, 'ok' \n\ndef unix2dos_one_dir(args,dir_name,file_names):\n for file in file_names:\n full_path = os.path.join(dir_name,file)\n unix2dos(full_path)\n \ndef unix2dos_dir(dir_name):\n os.path.walk(dir_name,unix2dos_one_dir,[])\n \nif __name__ == \"__main__\":\n import sys\n dos2unix_dir(sys.argv[1])\n", "source_code_before": "\"\"\" Functions for converting from DOS to UNIX line endings\n\"\"\"\n\nimport sys, re, os\n\ndef dos2unix(file):\n \"Replace CRLF with LF in argument files. Print names of changed files.\" \n if os.path.isdir(file):\n print file, \"Directory!\"\n return\n \n data = open(file, \"rb\").read()\n if '\\0' in data:\n print file, \"Binary!\"\n return\n \n newdata = re.sub(\"\\r\\n\", \"\\n\", data)\n if newdata != data:\n print 'dos2unix:', file\n f = open(file, \"wb\")\n f.write(newdata)\n f.close()\n else:\n print file, 'ok' \n\ndef dos2unix_one_dir(args,dir_name,file_names):\n for file in file_names:\n full_path = os.path.join(dir_name,file)\n dos2unix(full_path)\n \ndef dos2unix_dir(dir_name):\n os.path.walk(dir_name,dos2unix_one_dir,[])\n\n#----------------------------------\n\ndef unix2dos(file):\n \"Replace LF with CRLF in argument files. Print names of changed files.\" \n if os.path.isdir(file):\n print file, \"Directory!\"\n return\n \n data = open(file, \"rb\").read()\n if '\\0' in data:\n print file, \"Binary!\"\n return\n \n newdata = re.sub(\"\\n\", \"\\r\\n\", data)\n if newdata != data:\n print 'unix2dos:', file\n f = open(file, \"wb\")\n f.write(newdata)\n f.close()\n else:\n print file, 'ok' \n\ndef unix2dos_one_dir(args,dir_name,file_names):\n for file in file_names:\n full_path = os.path.join(dir_name,file)\n unix2dos(full_path)\n \ndef unix2dos_dir(dir_name):\n os.path.walk(dir_name,unix2dos_one_dir,[])\n \nif __name__ == \"__main__\":\n import sys\n dos2unix_dir(sys.argv[1])\n", "methods": [ { "name": "dos2unix", "long_name": "dos2unix( file )", "filename": "line_endings.py", "nloc": 17, "complexity": 4, "token_count": 89, "parameters": [ "file" ], "start_line": 6, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "dos2unix_one_dir", "long_name": "dos2unix_one_dir( args , dir_name , file_names )", "filename": "line_endings.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "args", "dir_name", "file_names" ], "start_line": 26, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "dos2unix_dir", "long_name": "dos2unix_dir( dir_name )", "filename": "line_endings.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "dir_name" ], "start_line": 31, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "unix2dos", "long_name": "unix2dos( file )", "filename": "line_endings.py", "nloc": 18, "complexity": 4, "token_count": 101, "parameters": [ "file" ], "start_line": 36, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "unix2dos_one_dir", "long_name": "unix2dos_one_dir( args , dir_name , file_names )", "filename": "line_endings.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "args", "dir_name", "file_names" ], "start_line": 57, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "unix2dos_dir", "long_name": "unix2dos_dir( dir_name )", "filename": "line_endings.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "dir_name" ], "start_line": 62, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 } ], "methods_before": [ { "name": "dos2unix", "long_name": "dos2unix( file )", "filename": "line_endings.py", "nloc": 17, "complexity": 4, "token_count": 89, "parameters": [ "file" ], "start_line": 6, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "dos2unix_one_dir", "long_name": "dos2unix_one_dir( args , dir_name , file_names )", "filename": "line_endings.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "args", "dir_name", "file_names" ], "start_line": 26, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "dos2unix_dir", "long_name": "dos2unix_dir( dir_name )", "filename": "line_endings.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "dir_name" ], "start_line": 31, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "unix2dos", "long_name": "unix2dos( file )", "filename": "line_endings.py", "nloc": 17, "complexity": 4, "token_count": 89, "parameters": [ "file" ], "start_line": 36, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "unix2dos_one_dir", "long_name": "unix2dos_one_dir( args , dir_name , file_names )", "filename": "line_endings.py", "nloc": 4, "complexity": 2, "token_count": 30, "parameters": [ "args", "dir_name", "file_names" ], "start_line": 56, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "unix2dos_dir", "long_name": "unix2dos_dir( dir_name )", "filename": "line_endings.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "dir_name" ], "start_line": 61, "end_line": 62, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "unix2dos", "long_name": "unix2dos( file )", "filename": "line_endings.py", "nloc": 18, "complexity": 4, "token_count": 101, "parameters": [ "file" ], "start_line": 36, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 } ], "nloc": 53, "complexity": 14, "token_count": 315, "diff_parsed": { "added": [ " newdata = re.sub(\"\\r\\n\", \"\\n\", data)", " newdata = re.sub(\"\\n\", \"\\r\\n\", newdata)" ], "deleted": [ " newdata = re.sub(\"\\n\", \"\\r\\n\", data)" ] } } ] }, { "hash": "a2d92aaca3cd2e897b080867623c7802e7970da0", "msg": "changed config.h defines to check for gcc3 and set definitions appropriately.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-09-19T03:05:17+00:00", "author_timezone": 0, "committer_date": "2002-09-19T03:05:17+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "09d3a0753f3b1f03c5990084c152af06775536f5" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 1, "insertions": 7, "lines": 8, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "weave/blitz-20001213/blitz/config.h", "new_path": "weave/blitz-20001213/blitz/config.h", "filename": "config.h", "extension": "h", "change_type": "MODIFY", "diff": "@@ -51,7 +51,13 @@\n #define BZ_ENUM_COMPUTATIONS\n #define BZ_ENUM_COMPUTATIONS_WITH_CAST\n #define BZ_HAVE_COMPLEX\n-#undef BZ_HAVE_NUMERIC_LIMITS\n+\n+#ifdef __GNUC__ && __GNUC__==3\n+ #define BZ_HAVE_NUMERIC_LIMITS\n+#else\n+ #undef BZ_HAVE_NUMERIC_LIMITS\n+#endif\n+\n #define BZ_HAVE_CLIMITS\n #define BZ_HAVE_VALARRAY\n #undef BZ_HAVE_COMPLEX_MATH\n", "added_lines": 7, "deleted_lines": 1, "source_code": "/******************************************************************************\n * config.h Compiler language support flags\n *\n * This file was generated automatically by the script bzconfig.\n * You should rerun bzconfig each time you switch compilers, install new\n * standard libraries, or change compiler versions.\n *\n */\n\n \n#ifndef BZ_CONFIG_H\n#define BZ_CONFIG_H\n \n#define BZ_COMPILER_NAME \"g++\"\n#define BZ_COMPILER_OPTIONS \"-ftemplate-depth-30\"\n#define BZ_OS_NAME \"Linux 2.2.14-5.0\"\n#define BZ_BZCONFIG_DATE \"Tue Apr 10 21:43:49 EDT 2001\"\n#define BZ_PLATFORM \"i686-pc-linux-gnu\"\n \n#define BZ_NAMESPACES\n#define BZ_EXCEPTIONS\n#define BZ_RTTI\n#define BZ_MEMBER_CONSTANTS\n#undef BZ_OLD_FOR_SCOPING\n#define BZ_EXPLICIT\n#define BZ_MUTABLE\n#define BZ_TYPENAME\n#undef BZ_NCEG_RESTRICT\n#define BZ_NCEG_RESTRICT_EGCS\n#define BZ_BOOL\n#define BZ_CONST_CAST\n#define BZ_STATIC_CAST\n#define BZ_REINTERPRET_CAST\n#define BZ_DYNAMIC_CAST\n#define BZ_TEMPLATES\n#define BZ_PARTIAL_SPECIALIZATION\n#define BZ_PARTIAL_ORDERING\n#define BZ_DEFAULT_TEMPLATE_PARAMETERS\n#define BZ_MEMBER_TEMPLATES\n#define BZ_MEMBER_TEMPLATES_OUTSIDE_CLASS\n#define BZ_FULL_SPECIALIZATION_SYNTAX\n#define BZ_FUNCTION_NONTYPE_PARAMETERS\n#define BZ_TEMPLATE_QUALIFIED_BASE_CLASS\n#define BZ_TEMPLATE_QUALIFIED_RETURN_TYPE\n#define BZ_EXPLICIT_TEMPLATE_FUNCTION_QUALIFICATION\n#define BZ_TEMPLATES_AS_TEMPLATE_ARGUMENTS\n#define BZ_TEMPLATE_KEYWORD_QUALIFIER\n#define BZ_TEMPLATE_SCOPED_ARGUMENT_MATCHING\n#define BZ_TYPE_PROMOTION\n#define BZ_USE_NUMTRAIT\n#define BZ_ENUM_COMPUTATIONS\n#define BZ_ENUM_COMPUTATIONS_WITH_CAST\n#define BZ_HAVE_COMPLEX\n\n#ifdef __GNUC__ && __GNUC__==3\n #define BZ_HAVE_NUMERIC_LIMITS\n#else\n #undef BZ_HAVE_NUMERIC_LIMITS\n#endif\n\n#define BZ_HAVE_CLIMITS\n#define BZ_HAVE_VALARRAY\n#undef BZ_HAVE_COMPLEX_MATH\n#define BZ_HAVE_IEEE_MATH\n#undef BZ_HAVE_SYSTEM_V_MATH\n#define BZ_MATH_FN_IN_NAMESPACE_STD\n#define BZ_COMPLEX_MATH_IN_NAMESPACE_STD\n#define BZ_HAVE_STD\n#define BZ_HAVE_STL\n#define BZ_HAVE_RUSAGE\n \n#endif // BZ_CONFIG_H\n", "source_code_before": "/******************************************************************************\n * config.h Compiler language support flags\n *\n * This file was generated automatically by the script bzconfig.\n * You should rerun bzconfig each time you switch compilers, install new\n * standard libraries, or change compiler versions.\n *\n */\n\n \n#ifndef BZ_CONFIG_H\n#define BZ_CONFIG_H\n \n#define BZ_COMPILER_NAME \"g++\"\n#define BZ_COMPILER_OPTIONS \"-ftemplate-depth-30\"\n#define BZ_OS_NAME \"Linux 2.2.14-5.0\"\n#define BZ_BZCONFIG_DATE \"Tue Apr 10 21:43:49 EDT 2001\"\n#define BZ_PLATFORM \"i686-pc-linux-gnu\"\n \n#define BZ_NAMESPACES\n#define BZ_EXCEPTIONS\n#define BZ_RTTI\n#define BZ_MEMBER_CONSTANTS\n#undef BZ_OLD_FOR_SCOPING\n#define BZ_EXPLICIT\n#define BZ_MUTABLE\n#define BZ_TYPENAME\n#undef BZ_NCEG_RESTRICT\n#define BZ_NCEG_RESTRICT_EGCS\n#define BZ_BOOL\n#define BZ_CONST_CAST\n#define BZ_STATIC_CAST\n#define BZ_REINTERPRET_CAST\n#define BZ_DYNAMIC_CAST\n#define BZ_TEMPLATES\n#define BZ_PARTIAL_SPECIALIZATION\n#define BZ_PARTIAL_ORDERING\n#define BZ_DEFAULT_TEMPLATE_PARAMETERS\n#define BZ_MEMBER_TEMPLATES\n#define BZ_MEMBER_TEMPLATES_OUTSIDE_CLASS\n#define BZ_FULL_SPECIALIZATION_SYNTAX\n#define BZ_FUNCTION_NONTYPE_PARAMETERS\n#define BZ_TEMPLATE_QUALIFIED_BASE_CLASS\n#define BZ_TEMPLATE_QUALIFIED_RETURN_TYPE\n#define BZ_EXPLICIT_TEMPLATE_FUNCTION_QUALIFICATION\n#define BZ_TEMPLATES_AS_TEMPLATE_ARGUMENTS\n#define BZ_TEMPLATE_KEYWORD_QUALIFIER\n#define BZ_TEMPLATE_SCOPED_ARGUMENT_MATCHING\n#define BZ_TYPE_PROMOTION\n#define BZ_USE_NUMTRAIT\n#define BZ_ENUM_COMPUTATIONS\n#define BZ_ENUM_COMPUTATIONS_WITH_CAST\n#define BZ_HAVE_COMPLEX\n#undef BZ_HAVE_NUMERIC_LIMITS\n#define BZ_HAVE_CLIMITS\n#define BZ_HAVE_VALARRAY\n#undef BZ_HAVE_COMPLEX_MATH\n#define BZ_HAVE_IEEE_MATH\n#undef BZ_HAVE_SYSTEM_V_MATH\n#define BZ_MATH_FN_IN_NAMESPACE_STD\n#define BZ_COMPLEX_MATH_IN_NAMESPACE_STD\n#define BZ_HAVE_STD\n#define BZ_HAVE_STL\n#define BZ_HAVE_RUSAGE\n \n#endif // BZ_CONFIG_H\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 0, "complexity": 0, "token_count": 0, "diff_parsed": { "added": [ "", "#ifdef __GNUC__ && __GNUC__==3", " #define BZ_HAVE_NUMERIC_LIMITS", "#else", " #undef BZ_HAVE_NUMERIC_LIMITS", "#endif", "" ], "deleted": [ "#undef BZ_HAVE_NUMERIC_LIMITS" ] } } ] }, { "hash": "9d56fb08134529c827b9bbcf0854d43cf7898d9f", "msg": "moved lib2def.py from weave to scipy_distutils\n\nremoved lib2def and logging from scipy_distutils as they now live in scipy_test", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-09-19T03:13:24+00:00", "author_timezone": 0, "committer_date": "2002-09-19T03:13:24+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "a2d92aaca3cd2e897b080867623c7802e7970da0" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 2555, "insertions": 4, "lines": 2559, "files": 6, "dmm_unit_size": 0.3609154929577465, "dmm_unit_complexity": 0.14700704225352113, "dmm_unit_interfacing": 0.3855633802816901, "modified_files": [ { "old_path": "scipy_distutils/auto_test.py", "new_path": null, "filename": "auto_test.py", "extension": "py", "change_type": "DELETE", "diff": "@@ -1,810 +0,0 @@\n-\"\"\" Auto test tools for SciPy\n-\n- Do not run this as root! If you enter something\n- like /usr as your test directory, it'll delete\n- /usr/bin, usr/lib, etc. So don't do it!!!\n- \n- \n- Author: Eric Jones (eric@enthought.com)\n-\"\"\"\n-from distutils import file_util\n-from distutils import dir_util\n-from distutils.errors import DistutilsFileError\n-#import tarfile\n-import sys, os, stat, time\n-import gzip\n-import tempfile, cStringIO\n-import urllib\n-import logging\n-\n-if sys.platform == 'cygwin':\n- local_repository = \"/cygdrive/i/tarballs\"\n-elif sys.platform == 'win32': \n- local_repository = \"i:\\tarballs\"\n-else:\n- local_repository = \"/home/shared/tarballs\"\n-\n-local_mail_server = \"enthought.com\"\n-\n-python_ftp_url = \"ftp://ftp.python.org/pub/python\"\n-numeric_url = \"http://prdownloads.sourceforge.net/numpy\"\n-f2py_url = \"http://cens.ioc.ee/projects/f2py2e/2.x\"\n-scipy_url = \"ftp://www.scipy.org/pub\"\n-blas_url = \"http://www.netlib.org/blas\"\n-lapack_url = \"http://www.netlib.org/lapack\"\n-#atlas_url = \"http://prdownloads.sourceforge.net/math-atlas\"\n-atlas_url = \"http://www.scipy.org/Members/eric\"\n-\n-\n-#-----------------------------------------------------------------------------\n-# Generic installation class. \n-# built to handle downloading/untarring/building/installing arbitrary software\n-#-----------------------------------------------------------------------------\n-\n-class package_installation: \n- def __init__(self,version='', dst_dir = '.',\n- logger = None, python_exe='python'):\n- #---------------------------------------------------------------------\n- # These should be defined in sub-class before calling this\n- # constructor\n- #---------------------------------------------------------------------\n- # \n- #self.package_url -- The name of the url where tarball can be found.\n- #self.package_base_name -- The base name of the source tarball.\n- #self.package_dir_name -- Top level directory of unpacked tarball\n- #self.tarball_suffix -- usually tar.gz or .tgz\n- #self.build_type -- 'make' or 'setup' for makefile or python setup file\n- \n- # Version of the software package.\n- self.version = version\n-\n- # Only used by packages built with setup.py\n- self.python_exe = python_exe\n- \n- # Directory where package is unpacked/built/installed\n- self.dst_dir = os.path.abspath(dst_dir) \n- \n- if not logger:\n- self.logger = logging\n- else:\n- self.logger = logger \n-\n- # make sure the destination exists\n- make_dir(self.dst_dir,logger=self.logger)\n-\n- # Construct any derived names built from the above names.\n- self.init_names()\n- \n- def init_names(self): \n- self.package_dir = os.path.join(self.dst_dir,self.package_dir_name)\n- self.tarball = self.package_base_name + '.' + self.tarball_suffix\n-\n- def get_source(self):\n- \"\"\" Grab the source tarball from a repository.\n- \n- Try a local repository first. If the file isn't found,\n- grab it from an ftp site.\n- \"\"\"\n- local_found = 0\n- if self.local_source_up_to_date():\n- try:\n- self.get_source_local()\n- local_found = 1 \n- except DistutilsFileError:\n- pass\n- \n- if not local_found:\n- self.get_source_ftp()\n- \n- def local_source_up_to_date(self):\n- \"\"\" Hook to test whether a file found in the repository is current\n- \"\"\"\n- return 1\n- \n- def get_source_local(self):\n- \"\"\" Grab the requested tarball from a local repository of source\n- tarballs. If it doesn't exist, an error is raised.\n- \"\"\"\n- file = os.path.join(local_repository,self.tarball) \n- dst_file = os.path.join(self.dst_dir,self.tarball)\n- self.logger.info(\"Searching local repository for %s\" % file)\n- try:\n- copy_file(file,dst_file,self.logger)\n- except DistutilsFileError, msg:\n- self.logger.info(\"Not found:\",msg)\n- raise\n- \n- def get_source_ftp(self):\n- \"\"\" Grab requested tarball from a ftp site specified as a url. \n- \"\"\"\n- url = '/'.join([self.package_url,self.tarball])\n- \n- self.logger.info('Opening: %s' % url)\n- f = urllib.urlopen(url)\n- self.logger.info('Downloading: this may take a while')\n- contents = f.read(-1)\n- f.close()\n- self.logger.info('Finished download (size=%d)' % len(contents))\n- \n- output_file = os.path.join(self.dst_dir,self.tarball)\n- write_file(output_file,contents,self.logger)\n-\n- # Put file in local repository so we don't have to download it again.\n- self.logger.info(\"Caching file in repository\" )\n- src_file = output_file\n- repos_file = os.path.join(local_repository,self.tarball) \n- copy_file(src_file,repos_file,self.logger)\n-\n- def unpack_source(self,sub_dir = None):\n- \"\"\" equivalent to 'tar -xzvf file' in the given sub_dir\n- \"\"\" \n- tarfile = os.path.join(self.dst_dir,self.tarball)\n- old_dir = None\n- \n- # copy and move into sub directory if it is specified.\n- if sub_dir:\n- dst_dir = os.path.join(self.dst_dir,sub_dir)\n- dst_file = os.path.join(dst_dir,self.tarball)\n- copy_file(tarfile,dst_file)\n- change_dir(dst_dir,self.logger)\n- try:\n- try:\n- # occasionally the tarball is not zipped, try this first.\n- untar_file(self.tarball,self.dst_dir,\n- self.logger,silent_failure=1)\n- except:\n- # otherwise, handle the fact that it is zipped \n- dst = os.path.join(self.dst_dir,'tmp.tar') \n- decompress_file(tarfile,dst,self.logger) \n- untar_file(dst,self.dst_dir,self.logger)\n- remove_file(dst,self.logger)\n- finally:\n- if old_dir:\n- unchange_dir(self.logger)\n-\n- #def auto_configure(self):\n- # cmd = os.path.join('.','configure')\n- # try:\n- # text = run_command(cmd,self.package_dir,self.logger,log_output=0)\n- # except ValueError, e:\n- # status, text = e\n- # self.logger.exception('Configuration Error:\\n'+text)\n- def auto_configure(self):\n- cmd = os.path.join('.','configure')\n- text = run_command(cmd,self.package_dir,self.logger)\n- \n- def build_with_make(self):\n- cmd = 'make'\n- text = run_command(cmd,self.package_dir,self.logger)\n- \n- def install_with_make(self, prefix = None):\n- if prefix is None:\n- prefix = os.path.abspath(self.dst_dir)\n- cmd = 'make install prefix=%s' % prefix\n- text = run_command(cmd,self.package_dir,self.logger)\n- \n- def python_setup(self):\n- cmd = self.python_exe + ' setup.py install'\n- text = run_command(cmd,self.package_dir,self.logger)\n- \n- def _make(self,**kw):\n- \"\"\" This generally needs to be overrridden in the derived class,\n- but this will suffice for the standard configure/make process. \n- \"\"\"\n- self.logger.info(\"### Begin Configure: %s\" % self.package_base_name)\n- self.auto_configure()\n- self.logger.info(\"### Finished Configure: %s\" % self.package_base_name)\n- self.logger.info(\"### Begin Build: %s\" % self.package_base_name)\n- self.build_with_make()\n- self.logger.info(\"### Finished Build: %s\" % self.package_base_name)\n- self.logger.info(\"### Begin Install: %s\" % self.package_base_name)\n- self.install_with_make()\n- self.logger.info(\"### Finished Install: %s\" % self.package_base_name)\n-\n- def install(self):\n- self.logger.info('####### Building: %s' % self.package_base_name)\n- self.logger.info(' Version: %s' % self.version)\n- self.logger.info(' Url: %s' % self.package_url)\n- self.logger.info(' Install dir: %s' % self.dst_dir)\n- self.logger.info(' Package dir: %s' % self.package_dir)\n- self.logger.info(' Suffix: %s' % self.tarball_suffix)\n- self.logger.info(' Build type: %s' % self.build_type)\n-\n- self.logger.info(\"### Begin Get Source: %s\" % self.package_base_name)\n- self.get_source()\n- self.unpack_source()\n- self.logger.info(\"### Finished Get Source: %s\" % self.package_base_name)\n-\n- if self.build_type == 'setup':\n- self.python_setup()\n- else: \n- self._make()\n- self.logger.info('####### Finished Building: %s' % self.package_base_name) \n- \n-#-----------------------------------------------------------------------------\n-# Installation class for Python itself.\n-#-----------------------------------------------------------------------------\n- \n-class python_installation(package_installation):\n- \n- def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n- \n- # Specialization for Python. \n- self.package_base_name = 'Python-'+version\n- self.package_dir_name = self.package_base_name\n- self.package_url = '/'.join([python_ftp_url,version])\n- self.tarball_suffix = 'tgz'\n- self.build_type = 'make'\n- \n- package_installation.__init__(self,version,dst_dir,logger,python_exe)\n-\n- def write_install_config(self): \n- \"\"\" Make doesn't seem to install scripts in the correct places.\n- \n- Writing this to the python directory will solve the problem.\n- [install_script]\n- install-dir= \n- \"\"\"\n- self.logger.info('### Writing Install Script Hack')\n- text = \"[install_scripts]\\n\"\\\n- \"install-dir='%s'\" % os.path.join(self.dst_dir,'bin')\n- file = os.path.join(self.package_dir,'setup.cfg') \n- write_file(file,text,self.logger,mode='w')\n- self.logger.info('### Finished writing Install Script Hack')\n-\n- def install_with_make(self):\n- \"\"\" Scripts were failing to install correctly, so a setuo.cfg\n- file is written to force installation in the correct place.\n- \"\"\" \n- self.write_install_config()\n- package_installation.install_with_make(self)\n-\n- def get_exe_name(self):\n- pyname = os.path.join('.','python')\n- cmd = pyname + \"\"\" -c \"import sys;print '%d.%d' % sys.version_info[:2]\" \"\"\"\n- text = run_command(cmd,self.package_dir,self.logger)\n- exe = os.path.join(self.dst_dir,'bin','python'+text)\n- return exe\n-\n-#-----------------------------------------------------------------------------\n-# Installation class for Blas.\n-#-----------------------------------------------------------------------------\n-\n-class blas_installation(package_installation):\n- \n- def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n- \n- # Specialization for for \"slow\" blas\n- self.package_base_name = 'blas'\n- self.package_dir_name = 'BLAS'\n- self.package_url = blas_url\n- self.tarball_suffix = 'tgz'\n- self.build_type = 'make'\n- \n- self.platform = 'LINUX'\n- package_installation.__init__(self,version,dst_dir,logger,python_exe)\n-\n- def unpack_source(self,subdir=None):\n- \"\"\" Dag. blas.tgz doesn't have directory information -- its\n- just a tar ball of fortran source code. untar it in the\n- BLAS directory\n- \"\"\"\n- package_installation.unpack_source(self,self.package_dir_name)\n- \n- def auto_configure(self):\n- # nothing to do.\n- pass\n- def build_with_make(self, **kw):\n- libname = 'blas_LINUX.a'\n- cmd = 'g77 -funroll-all-loops -fno-f2c -O3 -c *.f;ar -cru %s' % libname\n- text = run_command(cmd,self.package_dir,self.logger)\n- \n- def install_with_make(self, **kw):\n- # not really using make -- we'll just copy the file over. \n- src_file = os.path.join(self.package_dir,'blas_%s.a' % self.platform)\n- dst_file = os.path.join(self.dst_dir,'lib','libblas.a')\n- self.logger.info(\"Installing blas\")\n- copy_file(src_file,dst_file,self.logger)\n- \n-#-----------------------------------------------------------------------------\n-# Installation class for Lapack.\n-#-----------------------------------------------------------------------------\n-\n-class lapack_installation(package_installation):\n- \n- def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n- \n- # Specialization for Lapack 3.0 + updates \n- self.package_base_name = 'lapack'\n- self.package_dir_name = 'LAPACK'\n- self.package_url = lapack_url\n- self.tarball_suffix = 'tgz'\n- self.build_type = 'make'\n- \n- self.platform = 'LINUX'\n- package_installation.__init__(self,version,dst_dir,logger,python_exe)\n-\n- def auto_configure(self):\n- # perhaps this should actually override auto_conifgure\n- # before make, we need to copy the appropriate setup file in.\n- # should work anywhere g77 works...\n- make_inc = 'make.inc.' + self.platform\n- src_file = os.path.join(self.package_dir,'INSTALL',make_inc)\n- dst_file = os.path.join(self.package_dir,'make.inc')\n- copy_file(src_file,dst_file,self.logger)\n- \n- def build_with_make(self, **kw):\n- cmd = 'make install lapacklib'\n- text = run_command(cmd,self.package_dir,self.logger)\n- \n- def install_with_make(self, **kw):\n- # not really using make -- we'll just copy the file over.\n- src_file = os.path.join(self.package_dir,'lapack_%s.a' % self.platform)\n- dst_file = os.path.join(self.dst_dir,'lib','liblapack.a') \n- copy_file(src_file,dst_file,self.logger)\n-\n-#-----------------------------------------------------------------------------\n-# Installation class for Numeric\n-#-----------------------------------------------------------------------------\n-\n-class numeric_installation(package_installation):\n- \n- def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n- \n- self.package_base_name = 'Numeric-'+version\n- self.package_dir_name = self.package_base_name\n- self.package_url = numeric_url\n- self.tarball_suffix = 'tar.gz'\n- self.build_type = 'setup' \n-\n- package_installation.__init__(self,version,dst_dir,logger,python_exe)\n-\n-\n-#-----------------------------------------------------------------------------\n-# Installation class for f2py\n-#-----------------------------------------------------------------------------\n-\n-class f2py_installation(package_installation):\n- \n- def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n- \n- # Typical file format: F2PY-2.13.175-1250.tar.gz\n- self.package_base_name = 'F2PY-'+version\n- self.package_dir_name = self.package_base_name\n- self.package_url = f2py_url\n- self.tarball_suffix = 'tar.gz'\n- self.build_type = 'setup' \n- \n- package_installation.__init__(self,version,dst_dir,logger,python_exe)\n-\n-\n-#-----------------------------------------------------------------------------\n-# Installation class for Atlas.\n-# This is a binary install *NOT* a source install.\n-# The source install is a pain to automate.\n-#-----------------------------------------------------------------------------\n-\n-class atlas_installation(package_installation):\n- \n- def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n- \n- #self.package_base_name = 'atlas' + version\n- #self.package_dir_name = 'ATLAS'\n- self.package_base_name = 'atlas-RH7.1-PIII'\n- self.package_dir_name = 'atlas'\n- self.package_url = atlas_url\n- self.tarball_suffix = 'tgz'\n- self.build_type = 'make' \n- \n- package_installation.__init__(self,version,dst_dir,logger,python_exe)\n-\n- def auto_configure(self,**kw):\n- pass\n- def build_with_make(self,**kw):\n- pass\n- def install_with_make(self, **kw):\n- # just copy the tree over.\n- dst = os.path.join(self.dst_dir,'lib','atlas')\n- self.logger.info(\"Installing Atlas\")\n- copy_tree(self.package_dir,dst,self.logger)\n-\n-#-----------------------------------------------------------------------------\n-# Installation class for scipy\n-#-----------------------------------------------------------------------------\n-\n-class scipy_installation(package_installation):\n- \n- def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n- \n- self.package_base_name = 'scipy_snapshot'\n- self.package_dir_name = 'scipy'\n- self.package_url = scipy_url\n- self.tarball_suffix = 'tgz'\n- self.build_type = 'setup'\n- \n- package_installation.__init__(self,version,dst_dir,logger,python_exe)\n- \n- def local_source_up_to_date(self):\n- \"\"\" Hook to test whether a file found in the repository is current\n- \"\"\"\n- file = os.path.join(local_repository,self.tarball)\n- up_to_date = 0\n- try:\n- file_time = os.stat(file)[stat.ST_MTIME] \n- fyear,fmonth,fday = time.localtime(file_time)[:3]\n- year,month,day = time.localtime()[:3]\n- if fyear == year and fmonth == month and fday == day:\n- up_to_date = 1\n- self.logger.info(\"Repository file up to date: %s\" % file)\n- except OSError, msg:\n- pass\n- return up_to_date\n- \n-#-----------------------------------------------------------------------------\n-# Utilities\n-#-----------------------------------------------------------------------------\n-\n-\n-#if os.name == 'nt':\n-# def exec_command(command):\n-# \"\"\" not sure how to get exit status on nt. \"\"\"\n-# in_pipe,out_pipe = os.popen4(command)\n-# in_pipe.close()\n-# text = out_pipe.read()\n-# return 0, text\n-#else:\n-# import commands\n-# exec_command = commands.getstatusoutput\n- \n-# This may not work on Win98... The above stuff was to handle these machines.\n-import commands\n-exec_command = commands.getstatusoutput\n-\n-def copy_file(src,dst,logger=None):\n- if not logger:\n- logger = logging\n- logger.info(\"Copying %s->%s\" % (src,dst)) \n- try:\n- file_util.copy_file(src,dst)\n- except Exception, e: \n- logger.exception(\"Copy Failed\") \n- raise\n-\n-def copy_tree(src,dst,logger=None):\n- if not logger:\n- logger = logging\n- logger.info(\"Copying directory tree %s->%s\" % (src,dst)) \n- try:\n- dir_util.copy_tree(src,dst)\n- except Exception, e: \n- logger.exception(\"Copy Failed\") \n- raise\n-\n-def remove_tree(directory,logger=None):\n- if not logger:\n- logger = logging\n- logger.info(\"Removing directory tree %s\" % directory) \n- try:\n- dir_util.remove_tree(directory)\n- except Exception, e: \n- logger.exception(\"Remove failed: %s\" % e) \n- raise\n-\n-def remove_file(file,logger=None):\n- if not logger:\n- logger = logging\n- logger.info(\"Remove file %s\" % file) \n- try:\n- os.remove(file)\n- except Exception, e: \n- logger.exception(\"Remove failed\") \n- raise\n-\n-def write_file(file,contents,logger=None,mode='wb'):\n- if not logger:\n- logger = logging\n- logger.info('Write file: %s' % file)\n- try:\n- new_file = open(file,mode)\n- new_file.write(contents)\n- new_file.close()\n- except Exception, e: \n- logger.exception(\"Write failed\") \n- raise\n-\n-def make_dir(name,logger=None):\n- if not logger:\n- logger = logging\n- logger.info('Make directory: %s' % name)\n- try: \n- dir_util.mkpath(os.path.abspath(name))\n- except Exception, e: \n- logger.exception(\"Make Directory failed\") \n- raise\n-\n-# I know, I know...\n-old_dir = []\n-\n-def change_dir(d, logger = None):\n- if not logger:\n- logger = logging\n- global old_dir \n- cwd = os.getcwd() \n- old_dir.append(cwd)\n- d = os.path.abspath(d)\n- if d != old_dir[-1]:\n- logger.info(\"Change directory: %s\" % d) \n- try:\n- os.chdir(d)\n- except Exception, e: \n- logger.exception(\"Change directory failed\")\n- raise \n- #if d == '.':\n- # import sys,traceback\n- # f = sys._getframe()\n- # traceback.print_stack(f)\n-\n-def unchange_dir(logger=None):\n- if not logger:\n- logger = logging \n- global old_dir\n- try:\n- cwd = os.getcwd()\n- d = old_dir.pop(-1) \n- try:\n- if d != cwd:\n- logger.info(\"Change directory : %s\" % d)\n- os.chdir(d)\n- except Exception, e: \n- logger.exception(\"Change directory failed\")\n- raise \n- except IndexError:\n- logger.exception(\"Change directory failed\")\n- \n-def decompress_file(src,dst,logger = None):\n- if not logger:\n- logger = logging\n- logger.info(\"Upacking %s->%s\" % (src,dst))\n- try:\n- f = gzip.open(src,'rb')\n- contents = f.read(-1)\n- f = open(dst, 'wb')\n- f.write(contents)\n- except Exception, e: \n- logger.exception(\"Unpack failed\")\n- raise \n-\n- \n-def untar_file(file,dst_dir='.',logger = None,silent_failure = 0): \n- if not logger:\n- logger = logging\n- logger.info(\"Untarring file: %s\" % (file))\n- try:\n- run_command('tar -xf ' + file,directory = dst_dir,\n- logger=logger, silent_failure = silent_failure)\n- except Exception, e:\n- if not silent_failure: \n- logger.exception(\"Untar failed\")\n- raise \n-\n-def unpack_file(file,logger = None):\n- \"\"\" equivalent to 'tar -xzvf file'\n- \"\"\"\n- dst = 'tmp.tar'\n- decompress_file(file,dst,logger) \n- untar_file(dst.logger)\n- remove_file(dst,logger) \n-\n-\n-def run_command(cmd,directory='.',logger=None,silent_failure = 0):\n- if not logger:\n- logger = logging\n- change_dir(directory,logger) \n- try: \n- msg = 'Running: %s' % cmd\n- logger.info(msg) \n- status,text = exec_command(cmd)\n- if status and silent_failure:\n- msg = '(failed silently)'\n- logger.info(msg) \n- if status and text and not silent_failure:\n- logger.error('Command Failed (status=%d)\\n'% status +text)\n- finally:\n- unchange_dir(logger)\n- if status:\n- raise ValueError, (status,text)\n- return text \n-\n-def mail_report(from_addr,to_addr,subject,mail_server,\n- build_log, test_results,info):\n- \n- msg = ''\n- msg = msg + 'To: %s\\n' % to_addr\n- msg = msg + 'Subject: %s\\n' % subject\n- msg = msg + '\\r\\n\\r\\n'\n-\n- for k,v in info.items(): \n- msg = msg + '%s: %s\\n' % (k,v)\n- msg = msg + test_results + '\\n'\n- msg = msg + '-----------------------------\\n' \n- msg = msg + '-------- BUILD LOG -------\\n' \n- msg = msg + '-----------------------------\\n' \n- msg = msg + build_log\n- print msg\n- \n- # mail results\n- import smtplib \n- server = smtplib.SMTP(mail_server) \n- server.sendmail(from_addr, to_addr, msg)\n- server.quit()\n- \n-\n-def full_scipy_build(build_dir = '.',\n- test_level = 10,\n- python_version = '2.2.1',\n- numeric_version = '21.0',\n- f2py_version = '2.13.175-1250',\n- atlas_version = '3.3.14',\n- scipy_version = 'snapshot'):\n- \n- # for now the atlas version is ignored. Only the \n- # binaries for RH are supported at the moment.\n-\n- build_info = {'python_version' : python_version,\n- 'test_level' : test_level,\n- 'numeric_version': numeric_version,\n- 'f2py_version' : f2py_version,\n- 'atlas_version' : atlas_version,\n- 'scipy_version' : scipy_version}\n- \n- dst_dir = os.path.join(build_dir,sys.platform)\n-\n- logger = logging.Logger(\"SciPy Test\")\n- fmt = logging.Formatter(logging.BASIC_FORMAT)\n- log_stream = cStringIO.StringIO()\n- stream_handler = logging.StreamHandler(log_stream)\n- stream_handler.setFormatter(fmt)\n- logger.addHandler(stream_handler)\n- # also write to stderr\n- stderr = logging.StreamHandler()\n- stderr.setFormatter(fmt)\n- logger.addHandler(stderr)\n-\n- try:\n- try: \n- \n- # before doing anything, we need to wipe the \n- # /bin, /lib, /man, and /include directories\n- # in dst_dir. Don't run as root. \n- make_dir(dst_dir,logger=logger) \n- change_dir(dst_dir , logger)\n- for d in ['bin','lib','man','include']:\n- try: remove_tree(d, logger)\n- except OSError: pass \n- unchange_dir(logger)\n- \n- python = python_installation(version=python_version,\n- logger = logger,\n- dst_dir = dst_dir)\n- python.install()\n- \n- python_name = python.get_exe_name()\n- \n- numeric = numeric_installation(version=numeric_version,\n- dst_dir = dst_dir,\n- logger = logger,\n- python_exe=python_name)\n- numeric.install()\n- \n- f2py = f2py_installation(version=f2py_version,\n- logger = logger,\n- dst_dir = dst_dir,\n- python_exe=python_name)\n- f2py.install() \n- \n- # download files don't have a version specified \n- #lapack = lapack_installation(version='',\n- # dst_dir = dst_dir\n- # python_exe=python_name)\n- #lapack.install() \n- \n- # download files don't have a version specified \n- #blas = blas_installation(version='',\n- # logger = logger,\n- # dst_dir = dst_dir,\n- # python_exe=python_name)\n- #blas.install() \n- \n- # ATLAS\n- atlas = atlas_installation(version=atlas_version,\n- logger = logger,\n- dst_dir = dst_dir,\n- python_exe=python_name)\n- atlas.install()\n- \n- # version not currently used -- need to fix this.\n- scipy = scipy_installation(version=scipy_version,\n- logger = logger,\n- dst_dir = dst_dir,\n- python_exe=python_name)\n- scipy.install() \n- \n- # The change to tmp makes sure there isn't a scipy directory in \n- # the local scope.\n- # All tests are run.\n- logger.info('Beginning Test')\n- cmd = python_name +' -c \"import sys,scipy;suite=scipy.test(%d);\"'\\\n- % test_level\n- test_results = run_command(cmd, logger=logger,\n- directory = tempfile.gettempdir())\n- build_info['results'] = 'test completed (check below for pass/fail)'\n- except Exception, msg:\n- test_results = ''\n- build_info['results'] = 'build failed: %s' % msg\n- logger.exception('Build failed')\n- finally: \n- to_addr = \"scipy-testlog@scipy.org\"\n- from_addr = \"scipy-test@enthought.com\"\n- subject = '%s,py%s,num%s,scipy%s' % (sys.platform,python_version,\n- numeric_version,scipy_version) \n- build_log = log_stream.getvalue()\n- mail_report(from_addr,to_addr,subject,local_mail_server,\n- build_log,test_results,build_info)\n-\n-if __name__ == '__main__':\n- build_dir = '/tmp/scipy_test'\n- level = 10\n-\n- full_scipy_build(build_dir = build_dir,\n- test_level = level,\n- python_version = '2.2.1',\n- numeric_version = '21.0',\n- f2py_version = '2.13.175-1250',\n- atlas_version = '3.3.14',\n- scipy_version = 'snapshot')\n-\n- # an older python\n- full_scipy_build(build_dir = build_dir,\n- test_level = level,\n- python_version = '2.1.3',\n- numeric_version = '21.0',\n- f2py_version = '2.13.175-1250',\n- atlas_version = '3.3.14',\n- scipy_version = 'snapshot')\n-\n- # an older numeric\n- full_scipy_build(build_dir = build_dir,\n- test_level = level,\n- python_version = '2.1.3',\n- numeric_version = '20.3',\n- f2py_version = '2.13.175-1250',\n- atlas_version = '3.3.14',\n- scipy_version = 'snapshot')\n-\n- # This fails because multiarray doesn't have \n- # arange defined.\n- \"\"\"\n- full_scipy_build(build_dir = build_dir,\n- test_level = level,\n- python_version = '2.1.3',\n- numeric_version = '20.0.0',\n- f2py_version = '2.13.175-1250',\n- atlas_version = '3.3.14',\n- scipy_version = 'snapshot')\n-\n- full_scipy_build(build_dir = build_dir,\n- test_level = level,\n- python_version = '2.1.3',\n- numeric_version = '19.0.0',\n- f2py_version = '2.13.175-1250',\n- atlas_version = '3.3.14',\n- scipy_version = 'snapshot')\n-\n- full_scipy_build(build_dir = build_dir,\n- test_level = level,\n- python_version = '2.1.3',\n- numeric_version = '18.4.1',\n- f2py_version = '2.13.175-1250',\n- atlas_version = '3.3.14',\n- scipy_version = 'snapshot')\n- \"\"\"\n", "added_lines": 0, "deleted_lines": 810, "source_code": null, "source_code_before": "\"\"\" Auto test tools for SciPy\n\n Do not run this as root! If you enter something\n like /usr as your test directory, it'll delete\n /usr/bin, usr/lib, etc. So don't do it!!!\n \n \n Author: Eric Jones (eric@enthought.com)\n\"\"\"\nfrom distutils import file_util\nfrom distutils import dir_util\nfrom distutils.errors import DistutilsFileError\n#import tarfile\nimport sys, os, stat, time\nimport gzip\nimport tempfile, cStringIO\nimport urllib\nimport logging\n\nif sys.platform == 'cygwin':\n local_repository = \"/cygdrive/i/tarballs\"\nelif sys.platform == 'win32': \n local_repository = \"i:\\tarballs\"\nelse:\n local_repository = \"/home/shared/tarballs\"\n\nlocal_mail_server = \"enthought.com\"\n\npython_ftp_url = \"ftp://ftp.python.org/pub/python\"\nnumeric_url = \"http://prdownloads.sourceforge.net/numpy\"\nf2py_url = \"http://cens.ioc.ee/projects/f2py2e/2.x\"\nscipy_url = \"ftp://www.scipy.org/pub\"\nblas_url = \"http://www.netlib.org/blas\"\nlapack_url = \"http://www.netlib.org/lapack\"\n#atlas_url = \"http://prdownloads.sourceforge.net/math-atlas\"\natlas_url = \"http://www.scipy.org/Members/eric\"\n\n\n#-----------------------------------------------------------------------------\n# Generic installation class. \n# built to handle downloading/untarring/building/installing arbitrary software\n#-----------------------------------------------------------------------------\n\nclass package_installation: \n def __init__(self,version='', dst_dir = '.',\n logger = None, python_exe='python'):\n #---------------------------------------------------------------------\n # These should be defined in sub-class before calling this\n # constructor\n #---------------------------------------------------------------------\n # \n #self.package_url -- The name of the url where tarball can be found.\n #self.package_base_name -- The base name of the source tarball.\n #self.package_dir_name -- Top level directory of unpacked tarball\n #self.tarball_suffix -- usually tar.gz or .tgz\n #self.build_type -- 'make' or 'setup' for makefile or python setup file\n \n # Version of the software package.\n self.version = version\n\n # Only used by packages built with setup.py\n self.python_exe = python_exe\n \n # Directory where package is unpacked/built/installed\n self.dst_dir = os.path.abspath(dst_dir) \n \n if not logger:\n self.logger = logging\n else:\n self.logger = logger \n\n # make sure the destination exists\n make_dir(self.dst_dir,logger=self.logger)\n\n # Construct any derived names built from the above names.\n self.init_names()\n \n def init_names(self): \n self.package_dir = os.path.join(self.dst_dir,self.package_dir_name)\n self.tarball = self.package_base_name + '.' + self.tarball_suffix\n\n def get_source(self):\n \"\"\" Grab the source tarball from a repository.\n \n Try a local repository first. If the file isn't found,\n grab it from an ftp site.\n \"\"\"\n local_found = 0\n if self.local_source_up_to_date():\n try:\n self.get_source_local()\n local_found = 1 \n except DistutilsFileError:\n pass\n \n if not local_found:\n self.get_source_ftp()\n \n def local_source_up_to_date(self):\n \"\"\" Hook to test whether a file found in the repository is current\n \"\"\"\n return 1\n \n def get_source_local(self):\n \"\"\" Grab the requested tarball from a local repository of source\n tarballs. If it doesn't exist, an error is raised.\n \"\"\"\n file = os.path.join(local_repository,self.tarball) \n dst_file = os.path.join(self.dst_dir,self.tarball)\n self.logger.info(\"Searching local repository for %s\" % file)\n try:\n copy_file(file,dst_file,self.logger)\n except DistutilsFileError, msg:\n self.logger.info(\"Not found:\",msg)\n raise\n \n def get_source_ftp(self):\n \"\"\" Grab requested tarball from a ftp site specified as a url. \n \"\"\"\n url = '/'.join([self.package_url,self.tarball])\n \n self.logger.info('Opening: %s' % url)\n f = urllib.urlopen(url)\n self.logger.info('Downloading: this may take a while')\n contents = f.read(-1)\n f.close()\n self.logger.info('Finished download (size=%d)' % len(contents))\n \n output_file = os.path.join(self.dst_dir,self.tarball)\n write_file(output_file,contents,self.logger)\n\n # Put file in local repository so we don't have to download it again.\n self.logger.info(\"Caching file in repository\" )\n src_file = output_file\n repos_file = os.path.join(local_repository,self.tarball) \n copy_file(src_file,repos_file,self.logger)\n\n def unpack_source(self,sub_dir = None):\n \"\"\" equivalent to 'tar -xzvf file' in the given sub_dir\n \"\"\" \n tarfile = os.path.join(self.dst_dir,self.tarball)\n old_dir = None\n \n # copy and move into sub directory if it is specified.\n if sub_dir:\n dst_dir = os.path.join(self.dst_dir,sub_dir)\n dst_file = os.path.join(dst_dir,self.tarball)\n copy_file(tarfile,dst_file)\n change_dir(dst_dir,self.logger)\n try:\n try:\n # occasionally the tarball is not zipped, try this first.\n untar_file(self.tarball,self.dst_dir,\n self.logger,silent_failure=1)\n except:\n # otherwise, handle the fact that it is zipped \n dst = os.path.join(self.dst_dir,'tmp.tar') \n decompress_file(tarfile,dst,self.logger) \n untar_file(dst,self.dst_dir,self.logger)\n remove_file(dst,self.logger)\n finally:\n if old_dir:\n unchange_dir(self.logger)\n\n #def auto_configure(self):\n # cmd = os.path.join('.','configure')\n # try:\n # text = run_command(cmd,self.package_dir,self.logger,log_output=0)\n # except ValueError, e:\n # status, text = e\n # self.logger.exception('Configuration Error:\\n'+text)\n def auto_configure(self):\n cmd = os.path.join('.','configure')\n text = run_command(cmd,self.package_dir,self.logger)\n \n def build_with_make(self):\n cmd = 'make'\n text = run_command(cmd,self.package_dir,self.logger)\n \n def install_with_make(self, prefix = None):\n if prefix is None:\n prefix = os.path.abspath(self.dst_dir)\n cmd = 'make install prefix=%s' % prefix\n text = run_command(cmd,self.package_dir,self.logger)\n \n def python_setup(self):\n cmd = self.python_exe + ' setup.py install'\n text = run_command(cmd,self.package_dir,self.logger)\n \n def _make(self,**kw):\n \"\"\" This generally needs to be overrridden in the derived class,\n but this will suffice for the standard configure/make process. \n \"\"\"\n self.logger.info(\"### Begin Configure: %s\" % self.package_base_name)\n self.auto_configure()\n self.logger.info(\"### Finished Configure: %s\" % self.package_base_name)\n self.logger.info(\"### Begin Build: %s\" % self.package_base_name)\n self.build_with_make()\n self.logger.info(\"### Finished Build: %s\" % self.package_base_name)\n self.logger.info(\"### Begin Install: %s\" % self.package_base_name)\n self.install_with_make()\n self.logger.info(\"### Finished Install: %s\" % self.package_base_name)\n\n def install(self):\n self.logger.info('####### Building: %s' % self.package_base_name)\n self.logger.info(' Version: %s' % self.version)\n self.logger.info(' Url: %s' % self.package_url)\n self.logger.info(' Install dir: %s' % self.dst_dir)\n self.logger.info(' Package dir: %s' % self.package_dir)\n self.logger.info(' Suffix: %s' % self.tarball_suffix)\n self.logger.info(' Build type: %s' % self.build_type)\n\n self.logger.info(\"### Begin Get Source: %s\" % self.package_base_name)\n self.get_source()\n self.unpack_source()\n self.logger.info(\"### Finished Get Source: %s\" % self.package_base_name)\n\n if self.build_type == 'setup':\n self.python_setup()\n else: \n self._make()\n self.logger.info('####### Finished Building: %s' % self.package_base_name) \n \n#-----------------------------------------------------------------------------\n# Installation class for Python itself.\n#-----------------------------------------------------------------------------\n \nclass python_installation(package_installation):\n \n def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n \n # Specialization for Python. \n self.package_base_name = 'Python-'+version\n self.package_dir_name = self.package_base_name\n self.package_url = '/'.join([python_ftp_url,version])\n self.tarball_suffix = 'tgz'\n self.build_type = 'make'\n \n package_installation.__init__(self,version,dst_dir,logger,python_exe)\n\n def write_install_config(self): \n \"\"\" Make doesn't seem to install scripts in the correct places.\n \n Writing this to the python directory will solve the problem.\n [install_script]\n install-dir= \n \"\"\"\n self.logger.info('### Writing Install Script Hack')\n text = \"[install_scripts]\\n\"\\\n \"install-dir='%s'\" % os.path.join(self.dst_dir,'bin')\n file = os.path.join(self.package_dir,'setup.cfg') \n write_file(file,text,self.logger,mode='w')\n self.logger.info('### Finished writing Install Script Hack')\n\n def install_with_make(self):\n \"\"\" Scripts were failing to install correctly, so a setuo.cfg\n file is written to force installation in the correct place.\n \"\"\" \n self.write_install_config()\n package_installation.install_with_make(self)\n\n def get_exe_name(self):\n pyname = os.path.join('.','python')\n cmd = pyname + \"\"\" -c \"import sys;print '%d.%d' % sys.version_info[:2]\" \"\"\"\n text = run_command(cmd,self.package_dir,self.logger)\n exe = os.path.join(self.dst_dir,'bin','python'+text)\n return exe\n\n#-----------------------------------------------------------------------------\n# Installation class for Blas.\n#-----------------------------------------------------------------------------\n\nclass blas_installation(package_installation):\n \n def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n \n # Specialization for for \"slow\" blas\n self.package_base_name = 'blas'\n self.package_dir_name = 'BLAS'\n self.package_url = blas_url\n self.tarball_suffix = 'tgz'\n self.build_type = 'make'\n \n self.platform = 'LINUX'\n package_installation.__init__(self,version,dst_dir,logger,python_exe)\n\n def unpack_source(self,subdir=None):\n \"\"\" Dag. blas.tgz doesn't have directory information -- its\n just a tar ball of fortran source code. untar it in the\n BLAS directory\n \"\"\"\n package_installation.unpack_source(self,self.package_dir_name)\n \n def auto_configure(self):\n # nothing to do.\n pass\n def build_with_make(self, **kw):\n libname = 'blas_LINUX.a'\n cmd = 'g77 -funroll-all-loops -fno-f2c -O3 -c *.f;ar -cru %s' % libname\n text = run_command(cmd,self.package_dir,self.logger)\n \n def install_with_make(self, **kw):\n # not really using make -- we'll just copy the file over. \n src_file = os.path.join(self.package_dir,'blas_%s.a' % self.platform)\n dst_file = os.path.join(self.dst_dir,'lib','libblas.a')\n self.logger.info(\"Installing blas\")\n copy_file(src_file,dst_file,self.logger)\n \n#-----------------------------------------------------------------------------\n# Installation class for Lapack.\n#-----------------------------------------------------------------------------\n\nclass lapack_installation(package_installation):\n \n def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n \n # Specialization for Lapack 3.0 + updates \n self.package_base_name = 'lapack'\n self.package_dir_name = 'LAPACK'\n self.package_url = lapack_url\n self.tarball_suffix = 'tgz'\n self.build_type = 'make'\n \n self.platform = 'LINUX'\n package_installation.__init__(self,version,dst_dir,logger,python_exe)\n\n def auto_configure(self):\n # perhaps this should actually override auto_conifgure\n # before make, we need to copy the appropriate setup file in.\n # should work anywhere g77 works...\n make_inc = 'make.inc.' + self.platform\n src_file = os.path.join(self.package_dir,'INSTALL',make_inc)\n dst_file = os.path.join(self.package_dir,'make.inc')\n copy_file(src_file,dst_file,self.logger)\n \n def build_with_make(self, **kw):\n cmd = 'make install lapacklib'\n text = run_command(cmd,self.package_dir,self.logger)\n \n def install_with_make(self, **kw):\n # not really using make -- we'll just copy the file over.\n src_file = os.path.join(self.package_dir,'lapack_%s.a' % self.platform)\n dst_file = os.path.join(self.dst_dir,'lib','liblapack.a') \n copy_file(src_file,dst_file,self.logger)\n\n#-----------------------------------------------------------------------------\n# Installation class for Numeric\n#-----------------------------------------------------------------------------\n\nclass numeric_installation(package_installation):\n \n def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n \n self.package_base_name = 'Numeric-'+version\n self.package_dir_name = self.package_base_name\n self.package_url = numeric_url\n self.tarball_suffix = 'tar.gz'\n self.build_type = 'setup' \n\n package_installation.__init__(self,version,dst_dir,logger,python_exe)\n\n\n#-----------------------------------------------------------------------------\n# Installation class for f2py\n#-----------------------------------------------------------------------------\n\nclass f2py_installation(package_installation):\n \n def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n \n # Typical file format: F2PY-2.13.175-1250.tar.gz\n self.package_base_name = 'F2PY-'+version\n self.package_dir_name = self.package_base_name\n self.package_url = f2py_url\n self.tarball_suffix = 'tar.gz'\n self.build_type = 'setup' \n \n package_installation.__init__(self,version,dst_dir,logger,python_exe)\n\n\n#-----------------------------------------------------------------------------\n# Installation class for Atlas.\n# This is a binary install *NOT* a source install.\n# The source install is a pain to automate.\n#-----------------------------------------------------------------------------\n\nclass atlas_installation(package_installation):\n \n def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n \n #self.package_base_name = 'atlas' + version\n #self.package_dir_name = 'ATLAS'\n self.package_base_name = 'atlas-RH7.1-PIII'\n self.package_dir_name = 'atlas'\n self.package_url = atlas_url\n self.tarball_suffix = 'tgz'\n self.build_type = 'make' \n \n package_installation.__init__(self,version,dst_dir,logger,python_exe)\n\n def auto_configure(self,**kw):\n pass\n def build_with_make(self,**kw):\n pass\n def install_with_make(self, **kw):\n # just copy the tree over.\n dst = os.path.join(self.dst_dir,'lib','atlas')\n self.logger.info(\"Installing Atlas\")\n copy_tree(self.package_dir,dst,self.logger)\n\n#-----------------------------------------------------------------------------\n# Installation class for scipy\n#-----------------------------------------------------------------------------\n\nclass scipy_installation(package_installation):\n \n def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):\n \n self.package_base_name = 'scipy_snapshot'\n self.package_dir_name = 'scipy'\n self.package_url = scipy_url\n self.tarball_suffix = 'tgz'\n self.build_type = 'setup'\n \n package_installation.__init__(self,version,dst_dir,logger,python_exe)\n \n def local_source_up_to_date(self):\n \"\"\" Hook to test whether a file found in the repository is current\n \"\"\"\n file = os.path.join(local_repository,self.tarball)\n up_to_date = 0\n try:\n file_time = os.stat(file)[stat.ST_MTIME] \n fyear,fmonth,fday = time.localtime(file_time)[:3]\n year,month,day = time.localtime()[:3]\n if fyear == year and fmonth == month and fday == day:\n up_to_date = 1\n self.logger.info(\"Repository file up to date: %s\" % file)\n except OSError, msg:\n pass\n return up_to_date\n \n#-----------------------------------------------------------------------------\n# Utilities\n#-----------------------------------------------------------------------------\n\n\n#if os.name == 'nt':\n# def exec_command(command):\n# \"\"\" not sure how to get exit status on nt. \"\"\"\n# in_pipe,out_pipe = os.popen4(command)\n# in_pipe.close()\n# text = out_pipe.read()\n# return 0, text\n#else:\n# import commands\n# exec_command = commands.getstatusoutput\n \n# This may not work on Win98... The above stuff was to handle these machines.\nimport commands\nexec_command = commands.getstatusoutput\n\ndef copy_file(src,dst,logger=None):\n if not logger:\n logger = logging\n logger.info(\"Copying %s->%s\" % (src,dst)) \n try:\n file_util.copy_file(src,dst)\n except Exception, e: \n logger.exception(\"Copy Failed\") \n raise\n\ndef copy_tree(src,dst,logger=None):\n if not logger:\n logger = logging\n logger.info(\"Copying directory tree %s->%s\" % (src,dst)) \n try:\n dir_util.copy_tree(src,dst)\n except Exception, e: \n logger.exception(\"Copy Failed\") \n raise\n\ndef remove_tree(directory,logger=None):\n if not logger:\n logger = logging\n logger.info(\"Removing directory tree %s\" % directory) \n try:\n dir_util.remove_tree(directory)\n except Exception, e: \n logger.exception(\"Remove failed: %s\" % e) \n raise\n\ndef remove_file(file,logger=None):\n if not logger:\n logger = logging\n logger.info(\"Remove file %s\" % file) \n try:\n os.remove(file)\n except Exception, e: \n logger.exception(\"Remove failed\") \n raise\n\ndef write_file(file,contents,logger=None,mode='wb'):\n if not logger:\n logger = logging\n logger.info('Write file: %s' % file)\n try:\n new_file = open(file,mode)\n new_file.write(contents)\n new_file.close()\n except Exception, e: \n logger.exception(\"Write failed\") \n raise\n\ndef make_dir(name,logger=None):\n if not logger:\n logger = logging\n logger.info('Make directory: %s' % name)\n try: \n dir_util.mkpath(os.path.abspath(name))\n except Exception, e: \n logger.exception(\"Make Directory failed\") \n raise\n\n# I know, I know...\nold_dir = []\n\ndef change_dir(d, logger = None):\n if not logger:\n logger = logging\n global old_dir \n cwd = os.getcwd() \n old_dir.append(cwd)\n d = os.path.abspath(d)\n if d != old_dir[-1]:\n logger.info(\"Change directory: %s\" % d) \n try:\n os.chdir(d)\n except Exception, e: \n logger.exception(\"Change directory failed\")\n raise \n #if d == '.':\n # import sys,traceback\n # f = sys._getframe()\n # traceback.print_stack(f)\n\ndef unchange_dir(logger=None):\n if not logger:\n logger = logging \n global old_dir\n try:\n cwd = os.getcwd()\n d = old_dir.pop(-1) \n try:\n if d != cwd:\n logger.info(\"Change directory : %s\" % d)\n os.chdir(d)\n except Exception, e: \n logger.exception(\"Change directory failed\")\n raise \n except IndexError:\n logger.exception(\"Change directory failed\")\n \ndef decompress_file(src,dst,logger = None):\n if not logger:\n logger = logging\n logger.info(\"Upacking %s->%s\" % (src,dst))\n try:\n f = gzip.open(src,'rb')\n contents = f.read(-1)\n f = open(dst, 'wb')\n f.write(contents)\n except Exception, e: \n logger.exception(\"Unpack failed\")\n raise \n\n \ndef untar_file(file,dst_dir='.',logger = None,silent_failure = 0): \n if not logger:\n logger = logging\n logger.info(\"Untarring file: %s\" % (file))\n try:\n run_command('tar -xf ' + file,directory = dst_dir,\n logger=logger, silent_failure = silent_failure)\n except Exception, e:\n if not silent_failure: \n logger.exception(\"Untar failed\")\n raise \n\ndef unpack_file(file,logger = None):\n \"\"\" equivalent to 'tar -xzvf file'\n \"\"\"\n dst = 'tmp.tar'\n decompress_file(file,dst,logger) \n untar_file(dst.logger)\n remove_file(dst,logger) \n\n\ndef run_command(cmd,directory='.',logger=None,silent_failure = 0):\n if not logger:\n logger = logging\n change_dir(directory,logger) \n try: \n msg = 'Running: %s' % cmd\n logger.info(msg) \n status,text = exec_command(cmd)\n if status and silent_failure:\n msg = '(failed silently)'\n logger.info(msg) \n if status and text and not silent_failure:\n logger.error('Command Failed (status=%d)\\n'% status +text)\n finally:\n unchange_dir(logger)\n if status:\n raise ValueError, (status,text)\n return text \n\ndef mail_report(from_addr,to_addr,subject,mail_server,\n build_log, test_results,info):\n \n msg = ''\n msg = msg + 'To: %s\\n' % to_addr\n msg = msg + 'Subject: %s\\n' % subject\n msg = msg + '\\r\\n\\r\\n'\n\n for k,v in info.items(): \n msg = msg + '%s: %s\\n' % (k,v)\n msg = msg + test_results + '\\n'\n msg = msg + '-----------------------------\\n' \n msg = msg + '-------- BUILD LOG -------\\n' \n msg = msg + '-----------------------------\\n' \n msg = msg + build_log\n print msg\n \n # mail results\n import smtplib \n server = smtplib.SMTP(mail_server) \n server.sendmail(from_addr, to_addr, msg)\n server.quit()\n \n\ndef full_scipy_build(build_dir = '.',\n test_level = 10,\n python_version = '2.2.1',\n numeric_version = '21.0',\n f2py_version = '2.13.175-1250',\n atlas_version = '3.3.14',\n scipy_version = 'snapshot'):\n \n # for now the atlas version is ignored. Only the \n # binaries for RH are supported at the moment.\n\n build_info = {'python_version' : python_version,\n 'test_level' : test_level,\n 'numeric_version': numeric_version,\n 'f2py_version' : f2py_version,\n 'atlas_version' : atlas_version,\n 'scipy_version' : scipy_version}\n \n dst_dir = os.path.join(build_dir,sys.platform)\n\n logger = logging.Logger(\"SciPy Test\")\n fmt = logging.Formatter(logging.BASIC_FORMAT)\n log_stream = cStringIO.StringIO()\n stream_handler = logging.StreamHandler(log_stream)\n stream_handler.setFormatter(fmt)\n logger.addHandler(stream_handler)\n # also write to stderr\n stderr = logging.StreamHandler()\n stderr.setFormatter(fmt)\n logger.addHandler(stderr)\n\n try:\n try: \n \n # before doing anything, we need to wipe the \n # /bin, /lib, /man, and /include directories\n # in dst_dir. Don't run as root. \n make_dir(dst_dir,logger=logger) \n change_dir(dst_dir , logger)\n for d in ['bin','lib','man','include']:\n try: remove_tree(d, logger)\n except OSError: pass \n unchange_dir(logger)\n \n python = python_installation(version=python_version,\n logger = logger,\n dst_dir = dst_dir)\n python.install()\n \n python_name = python.get_exe_name()\n \n numeric = numeric_installation(version=numeric_version,\n dst_dir = dst_dir,\n logger = logger,\n python_exe=python_name)\n numeric.install()\n \n f2py = f2py_installation(version=f2py_version,\n logger = logger,\n dst_dir = dst_dir,\n python_exe=python_name)\n f2py.install() \n \n # download files don't have a version specified \n #lapack = lapack_installation(version='',\n # dst_dir = dst_dir\n # python_exe=python_name)\n #lapack.install() \n \n # download files don't have a version specified \n #blas = blas_installation(version='',\n # logger = logger,\n # dst_dir = dst_dir,\n # python_exe=python_name)\n #blas.install() \n \n # ATLAS\n atlas = atlas_installation(version=atlas_version,\n logger = logger,\n dst_dir = dst_dir,\n python_exe=python_name)\n atlas.install()\n \n # version not currently used -- need to fix this.\n scipy = scipy_installation(version=scipy_version,\n logger = logger,\n dst_dir = dst_dir,\n python_exe=python_name)\n scipy.install() \n \n # The change to tmp makes sure there isn't a scipy directory in \n # the local scope.\n # All tests are run.\n logger.info('Beginning Test')\n cmd = python_name +' -c \"import sys,scipy;suite=scipy.test(%d);\"'\\\n % test_level\n test_results = run_command(cmd, logger=logger,\n directory = tempfile.gettempdir())\n build_info['results'] = 'test completed (check below for pass/fail)'\n except Exception, msg:\n test_results = ''\n build_info['results'] = 'build failed: %s' % msg\n logger.exception('Build failed')\n finally: \n to_addr = \"scipy-testlog@scipy.org\"\n from_addr = \"scipy-test@enthought.com\"\n subject = '%s,py%s,num%s,scipy%s' % (sys.platform,python_version,\n numeric_version,scipy_version) \n build_log = log_stream.getvalue()\n mail_report(from_addr,to_addr,subject,local_mail_server,\n build_log,test_results,build_info)\n\nif __name__ == '__main__':\n build_dir = '/tmp/scipy_test'\n level = 10\n\n full_scipy_build(build_dir = build_dir,\n test_level = level,\n python_version = '2.2.1',\n numeric_version = '21.0',\n f2py_version = '2.13.175-1250',\n atlas_version = '3.3.14',\n scipy_version = 'snapshot')\n\n # an older python\n full_scipy_build(build_dir = build_dir,\n test_level = level,\n python_version = '2.1.3',\n numeric_version = '21.0',\n f2py_version = '2.13.175-1250',\n atlas_version = '3.3.14',\n scipy_version = 'snapshot')\n\n # an older numeric\n full_scipy_build(build_dir = build_dir,\n test_level = level,\n python_version = '2.1.3',\n numeric_version = '20.3',\n f2py_version = '2.13.175-1250',\n atlas_version = '3.3.14',\n scipy_version = 'snapshot')\n\n # This fails because multiarray doesn't have \n # arange defined.\n \"\"\"\n full_scipy_build(build_dir = build_dir,\n test_level = level,\n python_version = '2.1.3',\n numeric_version = '20.0.0',\n f2py_version = '2.13.175-1250',\n atlas_version = '3.3.14',\n scipy_version = 'snapshot')\n\n full_scipy_build(build_dir = build_dir,\n test_level = level,\n python_version = '2.1.3',\n numeric_version = '19.0.0',\n f2py_version = '2.13.175-1250',\n atlas_version = '3.3.14',\n scipy_version = 'snapshot')\n\n full_scipy_build(build_dir = build_dir,\n test_level = level,\n python_version = '2.1.3',\n numeric_version = '18.4.1',\n f2py_version = '2.13.175-1250',\n atlas_version = '3.3.14',\n scipy_version = 'snapshot')\n \"\"\"\n", "methods": [], "methods_before": [ { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 11, "complexity": 2, "token_count": 76, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 45, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "init_names", "long_name": "init_names( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 78, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_source", "long_name": "get_source( self )", "filename": "auto_test.py", "nloc": 10, "complexity": 4, "token_count": 39, "parameters": [ "self" ], "start_line": 82, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "local_source_up_to_date", "long_name": "local_source_up_to_date( self )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 99, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_source_local", "long_name": "get_source_local( self )", "filename": "auto_test.py", "nloc": 9, "complexity": 2, "token_count": 74, "parameters": [ "self" ], "start_line": 104, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "get_source_ftp", "long_name": "get_source_ftp( self )", "filename": "auto_test.py", "nloc": 14, "complexity": 1, "token_count": 136, "parameters": [ "self" ], "start_line": 117, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "unpack_source", "long_name": "unpack_source( self , sub_dir = None )", "filename": "auto_test.py", "nloc": 20, "complexity": 5, "token_count": 153, "parameters": [ "self", "sub_dir" ], "start_line": 138, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "auto_configure", "long_name": "auto_configure( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 172, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "build_with_make", "long_name": "build_with_make( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 176, "end_line": 178, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "install_with_make", "long_name": "install_with_make( self , prefix = None )", "filename": "auto_test.py", "nloc": 5, "complexity": 2, "token_count": 45, "parameters": [ "self", "prefix" ], "start_line": 180, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "python_setup", "long_name": "python_setup( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "self" ], "start_line": 186, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_make", "long_name": "_make( self , ** kw )", "filename": "auto_test.py", "nloc": 10, "complexity": 1, "token_count": 96, "parameters": [ "self", "kw" ], "start_line": 190, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "install", "long_name": "install( self )", "filename": "auto_test.py", "nloc": 17, "complexity": 2, "token_count": 154, "parameters": [ "self" ], "start_line": 204, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 7, "complexity": 1, "token_count": 73, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 230, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "write_install_config", "long_name": "write_install_config( self )", "filename": "auto_test.py", "nloc": 7, "complexity": 1, "token_count": 68, "parameters": [ "self" ], "start_line": 241, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "install_with_make", "long_name": "install_with_make( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 255, "end_line": 260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_exe_name", "long_name": "get_exe_name( self )", "filename": "auto_test.py", "nloc": 6, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 262, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 8, "complexity": 1, "token_count": 65, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 275, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "unpack_source", "long_name": "unpack_source( self , subdir = None )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "subdir" ], "start_line": 287, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "auto_configure", "long_name": "auto_configure( self )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [ "self" ], "start_line": 294, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "build_with_make", "long_name": "build_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "self", "kw" ], "start_line": 297, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "install_with_make", "long_name": "install_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 5, "complexity": 1, "token_count": 60, "parameters": [ "self", "kw" ], "start_line": 302, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 8, "complexity": 1, "token_count": 65, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 315, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "auto_configure", "long_name": "auto_configure( self )", "filename": "auto_test.py", "nloc": 5, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 327, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "build_with_make", "long_name": "build_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "kw" ], "start_line": 336, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "install_with_make", "long_name": "install_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 4, "complexity": 1, "token_count": 52, "parameters": [ "self", "kw" ], "start_line": 340, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 7, "complexity": 1, "token_count": 64, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 352, "end_line": 360, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 7, "complexity": 1, "token_count": 64, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 369, "end_line": 378, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 7, "complexity": 1, "token_count": 60, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 389, "end_line": 399, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "auto_configure", "long_name": "auto_configure( self , ** kw )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "kw" ], "start_line": 401, "end_line": 402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "build_with_make", "long_name": "build_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "kw" ], "start_line": 403, "end_line": 404, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "install_with_make", "long_name": "install_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 4, "complexity": 1, "token_count": 44, "parameters": [ "self", "kw" ], "start_line": 405, "end_line": 409, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 7, "complexity": 1, "token_count": 60, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 417, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "local_source_up_to_date", "long_name": "local_source_up_to_date( self )", "filename": "auto_test.py", "nloc": 13, "complexity": 5, "token_count": 103, "parameters": [ "self" ], "start_line": 427, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "copy_file", "long_name": "copy_file( src , dst , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 52, "parameters": [ "src", "dst", "logger" ], "start_line": 463, "end_line": 471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "copy_tree", "long_name": "copy_tree( src , dst , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 52, "parameters": [ "src", "dst", "logger" ], "start_line": 473, "end_line": 481, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "remove_tree", "long_name": "remove_tree( directory , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 46, "parameters": [ "directory", "logger" ], "start_line": 483, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "remove_file", "long_name": "remove_file( file , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 44, "parameters": [ "file", "logger" ], "start_line": 493, "end_line": 501, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "write_file", "long_name": "write_file( file , contents , logger = None , mode = 'wb' )", "filename": "auto_test.py", "nloc": 11, "complexity": 3, "token_count": 63, "parameters": [ "file", "contents", "logger", "mode" ], "start_line": 503, "end_line": 513, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "make_dir", "long_name": "make_dir( name , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 51, "parameters": [ "name", "logger" ], "start_line": 515, "end_line": 523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "change_dir", "long_name": "change_dir( d , logger = None )", "filename": "auto_test.py", "nloc": 14, "complexity": 4, "token_count": 78, "parameters": [ "d", "logger" ], "start_line": 528, "end_line": 541, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "unchange_dir", "long_name": "unchange_dir( logger = None )", "filename": "auto_test.py", "nloc": 16, "complexity": 5, "token_count": 76, "parameters": [ "logger" ], "start_line": 547, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "decompress_file", "long_name": "decompress_file( src , dst , logger = None )", "filename": "auto_test.py", "nloc": 12, "complexity": 3, "token_count": 77, "parameters": [ "src", "dst", "logger" ], "start_line": 564, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "untar_file", "long_name": "untar_file( file , dst_dir = '.' , logger = None , silent_failure = 0 )", "filename": "auto_test.py", "nloc": 11, "complexity": 4, "token_count": 70, "parameters": [ "file", "dst_dir", "logger", "silent_failure" ], "start_line": 578, "end_line": 588, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "unpack_file", "long_name": "unpack_file( file , logger = None )", "filename": "auto_test.py", "nloc": 5, "complexity": 1, "token_count": 33, "parameters": [ "file", "logger" ], "start_line": 590, "end_line": 596, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "run_command", "long_name": "run_command( cmd , directory = '.' , logger = None , silent_failure = 0 )", "filename": "auto_test.py", "nloc": 18, "complexity": 9, "token_count": 102, "parameters": [ "cmd", "directory", "logger", "silent_failure" ], "start_line": 599, "end_line": 616, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "mail_report", "long_name": "mail_report( from_addr , to_addr , subject , mail_server , build_log , test_results , info )", "filename": "auto_test.py", "nloc": 18, "complexity": 2, "token_count": 115, "parameters": [ "from_addr", "to_addr", "subject", "mail_server", "build_log", "test_results", "info" ], "start_line": 618, "end_line": 639, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "full_scipy_build", "long_name": "full_scipy_build( build_dir = '.' , test_level = 10 , python_version = '2.2.1' , numeric_version = '21.0' , f2py_version = '2.13.175-1250' , atlas_version = '3.3.14' , scipy_version = 'snapshot' )", "filename": "auto_test.py", "nloc": 74, "complexity": 5, "token_count": 417, "parameters": [ "build_dir", "test_level", "python_version", "numeric_version", "f2py_version", "atlas_version", "scipy_version" ], "start_line": 642, "end_line": 752, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 111, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_source", "long_name": "get_source( self )", "filename": "auto_test.py", "nloc": 10, "complexity": 4, "token_count": 39, "parameters": [ "self" ], "start_line": 82, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "unpack_source", "long_name": "unpack_source( self , subdir = None )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "subdir" ], "start_line": 287, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "install_with_make", "long_name": "install_with_make( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 255, "end_line": 260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "build_with_make", "long_name": "build_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 4, "complexity": 1, "token_count": 30, "parameters": [ "self", "kw" ], "start_line": 297, "end_line": 300, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "unpack_source", "long_name": "unpack_source( self , sub_dir = None )", "filename": "auto_test.py", "nloc": 20, "complexity": 5, "token_count": 153, "parameters": [ "self", "sub_dir" ], "start_line": 138, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "remove_file", "long_name": "remove_file( file , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 44, "parameters": [ "file", "logger" ], "start_line": 493, "end_line": 501, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "write_file", "long_name": "write_file( file , contents , logger = None , mode = 'wb' )", "filename": "auto_test.py", "nloc": 11, "complexity": 3, "token_count": 63, "parameters": [ "file", "contents", "logger", "mode" ], "start_line": 503, "end_line": 513, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "unchange_dir", "long_name": "unchange_dir( logger = None )", "filename": "auto_test.py", "nloc": 16, "complexity": 5, "token_count": 76, "parameters": [ "logger" ], "start_line": 547, "end_line": 562, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "untar_file", "long_name": "untar_file( file , dst_dir = '.' , logger = None , silent_failure = 0 )", "filename": "auto_test.py", "nloc": 11, "complexity": 4, "token_count": 70, "parameters": [ "file", "dst_dir", "logger", "silent_failure" ], "start_line": 578, "end_line": 588, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "install", "long_name": "install( self )", "filename": "auto_test.py", "nloc": 17, "complexity": 2, "token_count": 154, "parameters": [ "self" ], "start_line": 204, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "init_names", "long_name": "init_names( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 78, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "install_with_make", "long_name": "install_with_make( self , prefix = None )", "filename": "auto_test.py", "nloc": 5, "complexity": 2, "token_count": 45, "parameters": [ "self", "prefix" ], "start_line": 180, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_source_local", "long_name": "get_source_local( self )", "filename": "auto_test.py", "nloc": 9, "complexity": 2, "token_count": 74, "parameters": [ "self" ], "start_line": 104, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "change_dir", "long_name": "change_dir( d , logger = None )", "filename": "auto_test.py", "nloc": 14, "complexity": 4, "token_count": 78, "parameters": [ "d", "logger" ], "start_line": 528, "end_line": 541, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_exe_name", "long_name": "get_exe_name( self )", "filename": "auto_test.py", "nloc": 6, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 262, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "build_with_make", "long_name": "build_with_make( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 176, "end_line": 178, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "decompress_file", "long_name": "decompress_file( src , dst , logger = None )", "filename": "auto_test.py", "nloc": 12, "complexity": 3, "token_count": 77, "parameters": [ "src", "dst", "logger" ], "start_line": 564, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "full_scipy_build", "long_name": "full_scipy_build( build_dir = '.' , test_level = 10 , python_version = '2.2.1' , numeric_version = '21.0' , f2py_version = '2.13.175-1250' , atlas_version = '3.3.14' , scipy_version = 'snapshot' )", "filename": "auto_test.py", "nloc": 74, "complexity": 5, "token_count": 417, "parameters": [ "build_dir", "test_level", "python_version", "numeric_version", "f2py_version", "atlas_version", "scipy_version" ], "start_line": 642, "end_line": 752, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 111, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , version = '' , dst_dir = '.' , logger = None , python_exe = 'python' )", "filename": "auto_test.py", "nloc": 11, "complexity": 2, "token_count": 76, "parameters": [ "self", "version", "dst_dir", "logger", "python_exe" ], "start_line": 45, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "remove_tree", "long_name": "remove_tree( directory , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 46, "parameters": [ "directory", "logger" ], "start_line": 483, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "copy_tree", "long_name": "copy_tree( src , dst , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 52, "parameters": [ "src", "dst", "logger" ], "start_line": 473, "end_line": 481, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "auto_configure", "long_name": "auto_configure( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 172, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "write_install_config", "long_name": "write_install_config( self )", "filename": "auto_test.py", "nloc": 7, "complexity": 1, "token_count": 68, "parameters": [ "self" ], "start_line": 241, "end_line": 253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "auto_configure", "long_name": "auto_configure( self , ** kw )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "kw" ], "start_line": 401, "end_line": 402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "mail_report", "long_name": "mail_report( from_addr , to_addr , subject , mail_server , build_log , test_results , info )", "filename": "auto_test.py", "nloc": 18, "complexity": 2, "token_count": 115, "parameters": [ "from_addr", "to_addr", "subject", "mail_server", "build_log", "test_results", "info" ], "start_line": 618, "end_line": 639, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "_make", "long_name": "_make( self , ** kw )", "filename": "auto_test.py", "nloc": 10, "complexity": 1, "token_count": 96, "parameters": [ "self", "kw" ], "start_line": 190, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "make_dir", "long_name": "make_dir( name , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 51, "parameters": [ "name", "logger" ], "start_line": 515, "end_line": 523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "install_with_make", "long_name": "install_with_make( self , ** kw )", "filename": "auto_test.py", "nloc": 5, "complexity": 1, "token_count": 60, "parameters": [ "self", "kw" ], "start_line": 302, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_source_ftp", "long_name": "get_source_ftp( self )", "filename": "auto_test.py", "nloc": 14, "complexity": 1, "token_count": 136, "parameters": [ "self" ], "start_line": 117, "end_line": 136, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "unpack_file", "long_name": "unpack_file( file , logger = None )", "filename": "auto_test.py", "nloc": 5, "complexity": 1, "token_count": 33, "parameters": [ "file", "logger" ], "start_line": 590, "end_line": 596, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "local_source_up_to_date", "long_name": "local_source_up_to_date( self )", "filename": "auto_test.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self" ], "start_line": 99, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "run_command", "long_name": "run_command( cmd , directory = '.' , logger = None , silent_failure = 0 )", "filename": "auto_test.py", "nloc": 18, "complexity": 9, "token_count": 102, "parameters": [ "cmd", "directory", "logger", "silent_failure" ], "start_line": 599, "end_line": 616, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "copy_file", "long_name": "copy_file( src , dst , logger = None )", "filename": "auto_test.py", "nloc": 9, "complexity": 3, "token_count": 52, "parameters": [ "src", "dst", "logger" ], "start_line": 463, "end_line": 471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "python_setup", "long_name": "python_setup( self )", "filename": "auto_test.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "self" ], "start_line": 186, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 } ], "nloc": null, "complexity": null, "token_count": null, "diff_parsed": { "added": [], "deleted": [ "\"\"\" Auto test tools for SciPy", "", " Do not run this as root! If you enter something", " like /usr as your test directory, it'll delete", " /usr/bin, usr/lib, etc. So don't do it!!!", "", "", " Author: Eric Jones (eric@enthought.com)", "\"\"\"", "from distutils import file_util", "from distutils import dir_util", "from distutils.errors import DistutilsFileError", "#import tarfile", "import sys, os, stat, time", "import gzip", "import tempfile, cStringIO", "import urllib", "import logging", "", "if sys.platform == 'cygwin':", " local_repository = \"/cygdrive/i/tarballs\"", "elif sys.platform == 'win32':", " local_repository = \"i:\\tarballs\"", "else:", " local_repository = \"/home/shared/tarballs\"", "", "local_mail_server = \"enthought.com\"", "", "python_ftp_url = \"ftp://ftp.python.org/pub/python\"", "numeric_url = \"http://prdownloads.sourceforge.net/numpy\"", "f2py_url = \"http://cens.ioc.ee/projects/f2py2e/2.x\"", "scipy_url = \"ftp://www.scipy.org/pub\"", "blas_url = \"http://www.netlib.org/blas\"", "lapack_url = \"http://www.netlib.org/lapack\"", "#atlas_url = \"http://prdownloads.sourceforge.net/math-atlas\"", "atlas_url = \"http://www.scipy.org/Members/eric\"", "", "", "#-----------------------------------------------------------------------------", "# Generic installation class.", "# built to handle downloading/untarring/building/installing arbitrary software", "#-----------------------------------------------------------------------------", "", "class package_installation:", " def __init__(self,version='', dst_dir = '.',", " logger = None, python_exe='python'):", " #---------------------------------------------------------------------", " # These should be defined in sub-class before calling this", " # constructor", " #---------------------------------------------------------------------", " #", " #self.package_url -- The name of the url where tarball can be found.", " #self.package_base_name -- The base name of the source tarball.", " #self.package_dir_name -- Top level directory of unpacked tarball", " #self.tarball_suffix -- usually tar.gz or .tgz", " #self.build_type -- 'make' or 'setup' for makefile or python setup file", "", " # Version of the software package.", " self.version = version", "", " # Only used by packages built with setup.py", " self.python_exe = python_exe", "", " # Directory where package is unpacked/built/installed", " self.dst_dir = os.path.abspath(dst_dir)", "", " if not logger:", " self.logger = logging", " else:", " self.logger = logger", "", " # make sure the destination exists", " make_dir(self.dst_dir,logger=self.logger)", "", " # Construct any derived names built from the above names.", " self.init_names()", "", " def init_names(self):", " self.package_dir = os.path.join(self.dst_dir,self.package_dir_name)", " self.tarball = self.package_base_name + '.' + self.tarball_suffix", "", " def get_source(self):", " \"\"\" Grab the source tarball from a repository.", "", " Try a local repository first. If the file isn't found,", " grab it from an ftp site.", " \"\"\"", " local_found = 0", " if self.local_source_up_to_date():", " try:", " self.get_source_local()", " local_found = 1", " except DistutilsFileError:", " pass", "", " if not local_found:", " self.get_source_ftp()", "", " def local_source_up_to_date(self):", " \"\"\" Hook to test whether a file found in the repository is current", " \"\"\"", " return 1", "", " def get_source_local(self):", " \"\"\" Grab the requested tarball from a local repository of source", " tarballs. If it doesn't exist, an error is raised.", " \"\"\"", " file = os.path.join(local_repository,self.tarball)", " dst_file = os.path.join(self.dst_dir,self.tarball)", " self.logger.info(\"Searching local repository for %s\" % file)", " try:", " copy_file(file,dst_file,self.logger)", " except DistutilsFileError, msg:", " self.logger.info(\"Not found:\",msg)", " raise", "", " def get_source_ftp(self):", " \"\"\" Grab requested tarball from a ftp site specified as a url.", " \"\"\"", " url = '/'.join([self.package_url,self.tarball])", "", " self.logger.info('Opening: %s' % url)", " f = urllib.urlopen(url)", " self.logger.info('Downloading: this may take a while')", " contents = f.read(-1)", " f.close()", " self.logger.info('Finished download (size=%d)' % len(contents))", "", " output_file = os.path.join(self.dst_dir,self.tarball)", " write_file(output_file,contents,self.logger)", "", " # Put file in local repository so we don't have to download it again.", " self.logger.info(\"Caching file in repository\" )", " src_file = output_file", " repos_file = os.path.join(local_repository,self.tarball)", " copy_file(src_file,repos_file,self.logger)", "", " def unpack_source(self,sub_dir = None):", " \"\"\" equivalent to 'tar -xzvf file' in the given sub_dir", " \"\"\"", " tarfile = os.path.join(self.dst_dir,self.tarball)", " old_dir = None", "", " # copy and move into sub directory if it is specified.", " if sub_dir:", " dst_dir = os.path.join(self.dst_dir,sub_dir)", " dst_file = os.path.join(dst_dir,self.tarball)", " copy_file(tarfile,dst_file)", " change_dir(dst_dir,self.logger)", " try:", " try:", " # occasionally the tarball is not zipped, try this first.", " untar_file(self.tarball,self.dst_dir,", " self.logger,silent_failure=1)", " except:", " # otherwise, handle the fact that it is zipped", " dst = os.path.join(self.dst_dir,'tmp.tar')", " decompress_file(tarfile,dst,self.logger)", " untar_file(dst,self.dst_dir,self.logger)", " remove_file(dst,self.logger)", " finally:", " if old_dir:", " unchange_dir(self.logger)", "", " #def auto_configure(self):", " # cmd = os.path.join('.','configure')", " # try:", " # text = run_command(cmd,self.package_dir,self.logger,log_output=0)", " # except ValueError, e:", " # status, text = e", " # self.logger.exception('Configuration Error:\\n'+text)", " def auto_configure(self):", " cmd = os.path.join('.','configure')", " text = run_command(cmd,self.package_dir,self.logger)", "", " def build_with_make(self):", " cmd = 'make'", " text = run_command(cmd,self.package_dir,self.logger)", "", " def install_with_make(self, prefix = None):", " if prefix is None:", " prefix = os.path.abspath(self.dst_dir)", " cmd = 'make install prefix=%s' % prefix", " text = run_command(cmd,self.package_dir,self.logger)", "", " def python_setup(self):", " cmd = self.python_exe + ' setup.py install'", " text = run_command(cmd,self.package_dir,self.logger)", "", " def _make(self,**kw):", " \"\"\" This generally needs to be overrridden in the derived class,", " but this will suffice for the standard configure/make process.", " \"\"\"", " self.logger.info(\"### Begin Configure: %s\" % self.package_base_name)", " self.auto_configure()", " self.logger.info(\"### Finished Configure: %s\" % self.package_base_name)", " self.logger.info(\"### Begin Build: %s\" % self.package_base_name)", " self.build_with_make()", " self.logger.info(\"### Finished Build: %s\" % self.package_base_name)", " self.logger.info(\"### Begin Install: %s\" % self.package_base_name)", " self.install_with_make()", " self.logger.info(\"### Finished Install: %s\" % self.package_base_name)", "", " def install(self):", " self.logger.info('####### Building: %s' % self.package_base_name)", " self.logger.info(' Version: %s' % self.version)", " self.logger.info(' Url: %s' % self.package_url)", " self.logger.info(' Install dir: %s' % self.dst_dir)", " self.logger.info(' Package dir: %s' % self.package_dir)", " self.logger.info(' Suffix: %s' % self.tarball_suffix)", " self.logger.info(' Build type: %s' % self.build_type)", "", " self.logger.info(\"### Begin Get Source: %s\" % self.package_base_name)", " self.get_source()", " self.unpack_source()", " self.logger.info(\"### Finished Get Source: %s\" % self.package_base_name)", "", " if self.build_type == 'setup':", " self.python_setup()", " else:", " self._make()", " self.logger.info('####### Finished Building: %s' % self.package_base_name)", "", "#-----------------------------------------------------------------------------", "# Installation class for Python itself.", "#-----------------------------------------------------------------------------", "", "class python_installation(package_installation):", "", " def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):", "", " # Specialization for Python.", " self.package_base_name = 'Python-'+version", " self.package_dir_name = self.package_base_name", " self.package_url = '/'.join([python_ftp_url,version])", " self.tarball_suffix = 'tgz'", " self.build_type = 'make'", "", " package_installation.__init__(self,version,dst_dir,logger,python_exe)", "", " def write_install_config(self):", " \"\"\" Make doesn't seem to install scripts in the correct places.", "", " Writing this to the python directory will solve the problem.", " [install_script]", " install-dir=", " \"\"\"", " self.logger.info('### Writing Install Script Hack')", " text = \"[install_scripts]\\n\"\\", " \"install-dir='%s'\" % os.path.join(self.dst_dir,'bin')", " file = os.path.join(self.package_dir,'setup.cfg')", " write_file(file,text,self.logger,mode='w')", " self.logger.info('### Finished writing Install Script Hack')", "", " def install_with_make(self):", " \"\"\" Scripts were failing to install correctly, so a setuo.cfg", " file is written to force installation in the correct place.", " \"\"\"", " self.write_install_config()", " package_installation.install_with_make(self)", "", " def get_exe_name(self):", " pyname = os.path.join('.','python')", " cmd = pyname + \"\"\" -c \"import sys;print '%d.%d' % sys.version_info[:2]\" \"\"\"", " text = run_command(cmd,self.package_dir,self.logger)", " exe = os.path.join(self.dst_dir,'bin','python'+text)", " return exe", "", "#-----------------------------------------------------------------------------", "# Installation class for Blas.", "#-----------------------------------------------------------------------------", "", "class blas_installation(package_installation):", "", " def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):", "", " # Specialization for for \"slow\" blas", " self.package_base_name = 'blas'", " self.package_dir_name = 'BLAS'", " self.package_url = blas_url", " self.tarball_suffix = 'tgz'", " self.build_type = 'make'", "", " self.platform = 'LINUX'", " package_installation.__init__(self,version,dst_dir,logger,python_exe)", "", " def unpack_source(self,subdir=None):", " \"\"\" Dag. blas.tgz doesn't have directory information -- its", " just a tar ball of fortran source code. untar it in the", " BLAS directory", " \"\"\"", " package_installation.unpack_source(self,self.package_dir_name)", "", " def auto_configure(self):", " # nothing to do.", " pass", " def build_with_make(self, **kw):", " libname = 'blas_LINUX.a'", " cmd = 'g77 -funroll-all-loops -fno-f2c -O3 -c *.f;ar -cru %s' % libname", " text = run_command(cmd,self.package_dir,self.logger)", "", " def install_with_make(self, **kw):", " # not really using make -- we'll just copy the file over.", " src_file = os.path.join(self.package_dir,'blas_%s.a' % self.platform)", " dst_file = os.path.join(self.dst_dir,'lib','libblas.a')", " self.logger.info(\"Installing blas\")", " copy_file(src_file,dst_file,self.logger)", "", "#-----------------------------------------------------------------------------", "# Installation class for Lapack.", "#-----------------------------------------------------------------------------", "", "class lapack_installation(package_installation):", "", " def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):", "", " # Specialization for Lapack 3.0 + updates", " self.package_base_name = 'lapack'", " self.package_dir_name = 'LAPACK'", " self.package_url = lapack_url", " self.tarball_suffix = 'tgz'", " self.build_type = 'make'", "", " self.platform = 'LINUX'", " package_installation.__init__(self,version,dst_dir,logger,python_exe)", "", " def auto_configure(self):", " # perhaps this should actually override auto_conifgure", " # before make, we need to copy the appropriate setup file in.", " # should work anywhere g77 works...", " make_inc = 'make.inc.' + self.platform", " src_file = os.path.join(self.package_dir,'INSTALL',make_inc)", " dst_file = os.path.join(self.package_dir,'make.inc')", " copy_file(src_file,dst_file,self.logger)", "", " def build_with_make(self, **kw):", " cmd = 'make install lapacklib'", " text = run_command(cmd,self.package_dir,self.logger)", "", " def install_with_make(self, **kw):", " # not really using make -- we'll just copy the file over.", " src_file = os.path.join(self.package_dir,'lapack_%s.a' % self.platform)", " dst_file = os.path.join(self.dst_dir,'lib','liblapack.a')", " copy_file(src_file,dst_file,self.logger)", "", "#-----------------------------------------------------------------------------", "# Installation class for Numeric", "#-----------------------------------------------------------------------------", "", "class numeric_installation(package_installation):", "", " def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):", "", " self.package_base_name = 'Numeric-'+version", " self.package_dir_name = self.package_base_name", " self.package_url = numeric_url", " self.tarball_suffix = 'tar.gz'", " self.build_type = 'setup'", "", " package_installation.__init__(self,version,dst_dir,logger,python_exe)", "", "", "#-----------------------------------------------------------------------------", "# Installation class for f2py", "#-----------------------------------------------------------------------------", "", "class f2py_installation(package_installation):", "", " def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):", "", " # Typical file format: F2PY-2.13.175-1250.tar.gz", " self.package_base_name = 'F2PY-'+version", " self.package_dir_name = self.package_base_name", " self.package_url = f2py_url", " self.tarball_suffix = 'tar.gz'", " self.build_type = 'setup'", "", " package_installation.__init__(self,version,dst_dir,logger,python_exe)", "", "", "#-----------------------------------------------------------------------------", "# Installation class for Atlas.", "# This is a binary install *NOT* a source install.", "# The source install is a pain to automate.", "#-----------------------------------------------------------------------------", "", "class atlas_installation(package_installation):", "", " def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):", "", " #self.package_base_name = 'atlas' + version", " #self.package_dir_name = 'ATLAS'", " self.package_base_name = 'atlas-RH7.1-PIII'", " self.package_dir_name = 'atlas'", " self.package_url = atlas_url", " self.tarball_suffix = 'tgz'", " self.build_type = 'make'", "", " package_installation.__init__(self,version,dst_dir,logger,python_exe)", "", " def auto_configure(self,**kw):", " pass", " def build_with_make(self,**kw):", " pass", " def install_with_make(self, **kw):", " # just copy the tree over.", " dst = os.path.join(self.dst_dir,'lib','atlas')", " self.logger.info(\"Installing Atlas\")", " copy_tree(self.package_dir,dst,self.logger)", "", "#-----------------------------------------------------------------------------", "# Installation class for scipy", "#-----------------------------------------------------------------------------", "", "class scipy_installation(package_installation):", "", " def __init__(self,version='', dst_dir = '.',logger=None,python_exe='python'):", "", " self.package_base_name = 'scipy_snapshot'", " self.package_dir_name = 'scipy'", " self.package_url = scipy_url", " self.tarball_suffix = 'tgz'", " self.build_type = 'setup'", "", " package_installation.__init__(self,version,dst_dir,logger,python_exe)", "", " def local_source_up_to_date(self):", " \"\"\" Hook to test whether a file found in the repository is current", " \"\"\"", " file = os.path.join(local_repository,self.tarball)", " up_to_date = 0", " try:", " file_time = os.stat(file)[stat.ST_MTIME]", " fyear,fmonth,fday = time.localtime(file_time)[:3]", " year,month,day = time.localtime()[:3]", " if fyear == year and fmonth == month and fday == day:", " up_to_date = 1", " self.logger.info(\"Repository file up to date: %s\" % file)", " except OSError, msg:", " pass", " return up_to_date", "", "#-----------------------------------------------------------------------------", "# Utilities", "#-----------------------------------------------------------------------------", "", "", "#if os.name == 'nt':", "# def exec_command(command):", "# \"\"\" not sure how to get exit status on nt. \"\"\"", "# in_pipe,out_pipe = os.popen4(command)", "# in_pipe.close()", "# text = out_pipe.read()", "# return 0, text", "#else:", "# import commands", "# exec_command = commands.getstatusoutput", "", "# This may not work on Win98... The above stuff was to handle these machines.", "import commands", "exec_command = commands.getstatusoutput", "", "def copy_file(src,dst,logger=None):", " if not logger:", " logger = logging", " logger.info(\"Copying %s->%s\" % (src,dst))", " try:", " file_util.copy_file(src,dst)", " except Exception, e:", " logger.exception(\"Copy Failed\")", " raise", "", "def copy_tree(src,dst,logger=None):", " if not logger:", " logger = logging", " logger.info(\"Copying directory tree %s->%s\" % (src,dst))", " try:", " dir_util.copy_tree(src,dst)", " except Exception, e:", " logger.exception(\"Copy Failed\")", " raise", "", "def remove_tree(directory,logger=None):", " if not logger:", " logger = logging", " logger.info(\"Removing directory tree %s\" % directory)", " try:", " dir_util.remove_tree(directory)", " except Exception, e:", " logger.exception(\"Remove failed: %s\" % e)", " raise", "", "def remove_file(file,logger=None):", " if not logger:", " logger = logging", " logger.info(\"Remove file %s\" % file)", " try:", " os.remove(file)", " except Exception, e:", " logger.exception(\"Remove failed\")", " raise", "", "def write_file(file,contents,logger=None,mode='wb'):", " if not logger:", " logger = logging", " logger.info('Write file: %s' % file)", " try:", " new_file = open(file,mode)", " new_file.write(contents)", " new_file.close()", " except Exception, e:", " logger.exception(\"Write failed\")", " raise", "", "def make_dir(name,logger=None):", " if not logger:", " logger = logging", " logger.info('Make directory: %s' % name)", " try:", " dir_util.mkpath(os.path.abspath(name))", " except Exception, e:", " logger.exception(\"Make Directory failed\")", " raise", "", "# I know, I know...", "old_dir = []", "", "def change_dir(d, logger = None):", " if not logger:", " logger = logging", " global old_dir", " cwd = os.getcwd()", " old_dir.append(cwd)", " d = os.path.abspath(d)", " if d != old_dir[-1]:", " logger.info(\"Change directory: %s\" % d)", " try:", " os.chdir(d)", " except Exception, e:", " logger.exception(\"Change directory failed\")", " raise", " #if d == '.':", " # import sys,traceback", " # f = sys._getframe()", " # traceback.print_stack(f)", "", "def unchange_dir(logger=None):", " if not logger:", " logger = logging", " global old_dir", " try:", " cwd = os.getcwd()", " d = old_dir.pop(-1)", " try:", " if d != cwd:", " logger.info(\"Change directory : %s\" % d)", " os.chdir(d)", " except Exception, e:", " logger.exception(\"Change directory failed\")", " raise", " except IndexError:", " logger.exception(\"Change directory failed\")", "", "def decompress_file(src,dst,logger = None):", " if not logger:", " logger = logging", " logger.info(\"Upacking %s->%s\" % (src,dst))", " try:", " f = gzip.open(src,'rb')", " contents = f.read(-1)", " f = open(dst, 'wb')", " f.write(contents)", " except Exception, e:", " logger.exception(\"Unpack failed\")", " raise", "", "", "def untar_file(file,dst_dir='.',logger = None,silent_failure = 0):", " if not logger:", " logger = logging", " logger.info(\"Untarring file: %s\" % (file))", " try:", " run_command('tar -xf ' + file,directory = dst_dir,", " logger=logger, silent_failure = silent_failure)", " except Exception, e:", " if not silent_failure:", " logger.exception(\"Untar failed\")", " raise", "", "def unpack_file(file,logger = None):", " \"\"\" equivalent to 'tar -xzvf file'", " \"\"\"", " dst = 'tmp.tar'", " decompress_file(file,dst,logger)", " untar_file(dst.logger)", " remove_file(dst,logger)", "", "", "def run_command(cmd,directory='.',logger=None,silent_failure = 0):", " if not logger:", " logger = logging", " change_dir(directory,logger)", " try:", " msg = 'Running: %s' % cmd", " logger.info(msg)", " status,text = exec_command(cmd)", " if status and silent_failure:", " msg = '(failed silently)'", " logger.info(msg)", " if status and text and not silent_failure:", " logger.error('Command Failed (status=%d)\\n'% status +text)", " finally:", " unchange_dir(logger)", " if status:", " raise ValueError, (status,text)", " return text", "", "def mail_report(from_addr,to_addr,subject,mail_server,", " build_log, test_results,info):", "", " msg = ''", " msg = msg + 'To: %s\\n' % to_addr", " msg = msg + 'Subject: %s\\n' % subject", " msg = msg + '\\r\\n\\r\\n'", "", " for k,v in info.items():", " msg = msg + '%s: %s\\n' % (k,v)", " msg = msg + test_results + '\\n'", " msg = msg + '-----------------------------\\n'", " msg = msg + '-------- BUILD LOG -------\\n'", " msg = msg + '-----------------------------\\n'", " msg = msg + build_log", " print msg", "", " # mail results", " import smtplib", " server = smtplib.SMTP(mail_server)", " server.sendmail(from_addr, to_addr, msg)", " server.quit()", "", "", "def full_scipy_build(build_dir = '.',", " test_level = 10,", " python_version = '2.2.1',", " numeric_version = '21.0',", " f2py_version = '2.13.175-1250',", " atlas_version = '3.3.14',", " scipy_version = 'snapshot'):", "", " # for now the atlas version is ignored. Only the", " # binaries for RH are supported at the moment.", "", " build_info = {'python_version' : python_version,", " 'test_level' : test_level,", " 'numeric_version': numeric_version,", " 'f2py_version' : f2py_version,", " 'atlas_version' : atlas_version,", " 'scipy_version' : scipy_version}", "", " dst_dir = os.path.join(build_dir,sys.platform)", "", " logger = logging.Logger(\"SciPy Test\")", " fmt = logging.Formatter(logging.BASIC_FORMAT)", " log_stream = cStringIO.StringIO()", " stream_handler = logging.StreamHandler(log_stream)", " stream_handler.setFormatter(fmt)", " logger.addHandler(stream_handler)", " # also write to stderr", " stderr = logging.StreamHandler()", " stderr.setFormatter(fmt)", " logger.addHandler(stderr)", "", " try:", " try:", "", " # before doing anything, we need to wipe the", " # /bin, /lib, /man, and /include directories", " # in dst_dir. Don't run as root.", " make_dir(dst_dir,logger=logger)", " change_dir(dst_dir , logger)", " for d in ['bin','lib','man','include']:", " try: remove_tree(d, logger)", " except OSError: pass", " unchange_dir(logger)", "", " python = python_installation(version=python_version,", " logger = logger,", " dst_dir = dst_dir)", " python.install()", "", " python_name = python.get_exe_name()", "", " numeric = numeric_installation(version=numeric_version,", " dst_dir = dst_dir,", " logger = logger,", " python_exe=python_name)", " numeric.install()", "", " f2py = f2py_installation(version=f2py_version,", " logger = logger,", " dst_dir = dst_dir,", " python_exe=python_name)", " f2py.install()", "", " # download files don't have a version specified", " #lapack = lapack_installation(version='',", " # dst_dir = dst_dir", " # python_exe=python_name)", " #lapack.install()", "", " # download files don't have a version specified", " #blas = blas_installation(version='',", " # logger = logger,", " # dst_dir = dst_dir,", " # python_exe=python_name)", " #blas.install()", "", " # ATLAS", " atlas = atlas_installation(version=atlas_version,", " logger = logger,", " dst_dir = dst_dir,", " python_exe=python_name)", " atlas.install()", "", " # version not currently used -- need to fix this.", " scipy = scipy_installation(version=scipy_version,", " logger = logger,", " dst_dir = dst_dir,", " python_exe=python_name)", " scipy.install()", "", " # The change to tmp makes sure there isn't a scipy directory in", " # the local scope.", " # All tests are run.", " logger.info('Beginning Test')", " cmd = python_name +' -c \"import sys,scipy;suite=scipy.test(%d);\"'\\", " % test_level", " test_results = run_command(cmd, logger=logger,", " directory = tempfile.gettempdir())", " build_info['results'] = 'test completed (check below for pass/fail)'", " except Exception, msg:", " test_results = ''", " build_info['results'] = 'build failed: %s' % msg", " logger.exception('Build failed')", " finally:", " to_addr = \"scipy-testlog@scipy.org\"", " from_addr = \"scipy-test@enthought.com\"", " subject = '%s,py%s,num%s,scipy%s' % (sys.platform,python_version,", " numeric_version,scipy_version)", " build_log = log_stream.getvalue()", " mail_report(from_addr,to_addr,subject,local_mail_server,", " build_log,test_results,build_info)", "", "if __name__ == '__main__':", " build_dir = '/tmp/scipy_test'", " level = 10", "", " full_scipy_build(build_dir = build_dir,", " test_level = level,", " python_version = '2.2.1',", " numeric_version = '21.0',", " f2py_version = '2.13.175-1250',", " atlas_version = '3.3.14',", " scipy_version = 'snapshot')", "", " # an older python", " full_scipy_build(build_dir = build_dir,", " test_level = level,", " python_version = '2.1.3',", " numeric_version = '21.0',", " f2py_version = '2.13.175-1250',", " atlas_version = '3.3.14',", " scipy_version = 'snapshot')", "", " # an older numeric", " full_scipy_build(build_dir = build_dir,", " test_level = level,", " python_version = '2.1.3',", " numeric_version = '20.3',", " f2py_version = '2.13.175-1250',", " atlas_version = '3.3.14',", " scipy_version = 'snapshot')", "", " # This fails because multiarray doesn't have", " # arange defined.", " \"\"\"", " full_scipy_build(build_dir = build_dir,", " test_level = level,", " python_version = '2.1.3',", " numeric_version = '20.0.0',", " f2py_version = '2.13.175-1250',", " atlas_version = '3.3.14',", " scipy_version = 'snapshot')", "", " full_scipy_build(build_dir = build_dir,", " test_level = level,", " python_version = '2.1.3',", " numeric_version = '19.0.0',", " f2py_version = '2.13.175-1250',", " atlas_version = '3.3.14',", " scipy_version = 'snapshot')", "", " full_scipy_build(build_dir = build_dir,", " test_level = level,", " python_version = '2.1.3',", " numeric_version = '18.4.1',", " f2py_version = '2.13.175-1250',", " atlas_version = '3.3.14',", " scipy_version = 'snapshot')", " \"\"\"" ] } }, { "old_path": "weave/lib2def.py", "new_path": "scipy_distutils/lib2def.py", "filename": "lib2def.py", "extension": "py", "change_type": "RENAME", "diff": "", "added_lines": 0, "deleted_lines": 0, "source_code": null, "source_code_before": null, "methods": [], "methods_before": [], "changed_methods": [], "nloc": null, "complexity": null, "token_count": null, "diff_parsed": { "added": [], "deleted": [] } }, { "old_path": "scipy_distutils/logging.py", "new_path": null, "filename": "logging.py", "extension": "py", "change_type": "DELETE", "diff": "@@ -1,1737 +0,0 @@\n-#! /usr/bin/env python\n-#\n-# Copyright 2001-2002 by Vinay Sajip. All Rights Reserved.\n-#\n-# Permission to use, copy, modify, and distribute this software and its\n-# documentation for any purpose and without fee is hereby granted,\n-# provided that the above copyright notice appear in all copies and that\n-# both that copyright notice and this permission notice appear in\n-# supporting documentation, and that the name of Vinay Sajip\n-# not be used in advertising or publicity pertaining to distribution\n-# of the software without specific, written prior permission.\n-# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING\n-# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL\n-# VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR\n-# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\n-# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT\n-# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n-#\n-# For the change history, see README.txt in the distribution.\n-#\n-# This file is part of the Python logging distribution. See\n-# http://www.red-dove.com/python_logging.html\n-#\n-\n-\"\"\"\n-Logging module for Python. Based on PEP 282 and comments thereto in\n-comp.lang.python, and influenced by Apache's log4j system.\n-\n-Should work under Python versions >= 1.5.2, except that source line\n-information is not available unless 'inspect' is.\n-\n-Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.\n-\n-To use, simply 'import logging' and log away!\n-\"\"\"\n-\n-import sys, os, types, time, string, socket, cPickle, cStringIO\n-\n-try:\n- import thread\n-except ImportError:\n- thread = None\n-try:\n- import inspect\n-except ImportError:\n- inspect = None\n-\n-__author__ = \"Vinay Sajip \"\n-__status__ = \"alpha\"\n-__version__ = \"0.4.1\"\n-__date__ = \"03 April 2002\"\n-\n-#---------------------------------------------------------------------------\n-# Module data\n-#---------------------------------------------------------------------------\n-\n-#\n-#_srcfile is used when walking the stack to check when we've got the first\n-# caller stack frame.\n-#If run as a script, __file__ is not bound.\n-#\n-if __name__ == \"__main__\":\n- _srcFile = None\n-else:\n- _srcfile = os.path.splitext(__file__)\n- if _srcfile[1] in [\".pyc\", \".pyo\"]:\n- _srcfile = _srcfile[0] + \".py\"\n- else:\n- _srcfile = __file__\n-\n-#\n-#_start_time is used as the base when calculating the relative time of events\n-#\n-_start_time = time.time()\n-\n-DEFAULT_TCP_LOGGING_PORT = 9020\n-DEFAULT_UDP_LOGGING_PORT = 9021\n-DEFAULT_HTTP_LOGGING_PORT = 9022\n-SYSLOG_UDP_PORT = 514\n-\n-#\n-# Default levels and level names, these can be replaced with any positive set\n-# of values having corresponding names. There is a pseudo-level, ALL, which\n-# is only really there as a lower limit for user-defined levels. Handlers and\n-# loggers are initialized with ALL so that they will log all messages, even\n-# at user-defined levels.\n-#\n-CRITICAL = 50\n-FATAL = CRITICAL\n-ERROR = 40\n-WARN = 30\n-INFO = 20\n-DEBUG = 10\n-ALL = 0\n-\n-_levelNames = {\n- CRITICAL : 'CRITICAL',\n- ERROR : 'ERROR',\n- WARN : 'WARN',\n- INFO : 'INFO',\n- DEBUG : 'DEBUG',\n- ALL : 'ALL',\n-}\n-\n-def getLevelName(lvl):\n- \"\"\"\n- Return the textual representation of logging level 'lvl'. If the level is\n- one of the predefined levels (CRITICAL, ERROR, WARN, INFO, DEBUG) then you\n- get the corresponding string. If you have associated levels with names\n- using addLevelName then the name you have associated with 'lvl' is\n- returned. Otherwise, the string \"Level %s\" % lvl is returned.\n- \"\"\"\n- return _levelNames.get(lvl, (\"Level %s\" % lvl))\n-\n-def addLevelName(lvl, levelName):\n- \"\"\"\n- Associate 'levelName' with 'lvl'. This is used when converting levels\n- to text during message formatting.\n- \"\"\"\n- _levelNames[lvl] = levelName\n-\n-#---------------------------------------------------------------------------\n-# The logging record\n-#---------------------------------------------------------------------------\n-\n-class LogRecord:\n- \"\"\"\n- LogRecord instances are created every time something is logged. They\n- contain all the information pertinent to the event being logged. The\n- main information passed in is in msg and args, which are combined\n- using msg % args to create the message field of the record. The record\n- also includes information such as when the record was created, the\n- source line where the logging call was made, and any exception\n- information to be logged.\n- \"\"\"\n- def __init__(self, name, lvl, pathname, lineno, msg, args, exc_info):\n- \"\"\"\n- Initialize a logging record with interesting information.\n- \"\"\"\n- ct = time.time()\n- self.name = name\n- self.msg = msg\n- self.args = args\n- self.level = getLevelName(lvl)\n- self.lvl = lvl\n- self.pathname = pathname\n- try:\n- self.filename = os.path.basename(pathname)\n- except:\n- self.filename = pathname\n- self.exc_info = exc_info\n- self.lineno = lineno\n- self.created = ct\n- self.msecs = (ct - long(ct)) * 1000\n- self.relativeCreated = (self.created - _start_time) * 1000\n- if thread:\n- self.thread = thread.get_ident()\n- else:\n- self.thread = None\n-\n- def __str__(self):\n- return ''%(self.name, self.lvl,\n- self.pathname, self.lineno, self.msg)\n-\n-#---------------------------------------------------------------------------\n-# Formatter classes and functions\n-#---------------------------------------------------------------------------\n-\n-class Formatter:\n- \"\"\"\n- Formatters need to know how a LogRecord is constructed. They are\n- responsible for converting a LogRecord to (usually) a string which can\n- be interpreted by either a human or an external system. The base Formatter\n- allows a formatting string to be specified. If none is supplied, the\n- default value of \"%s(message)\\\\n\" is used.\n-\n- The Formatter can be initialized with a format string which makes use of\n- knowledge of the LogRecord attributes - e.g. the default value mentioned\n- above makes use of the fact that the user's message and arguments are pre-\n- formatted into a LogRecord's message attribute. Currently, the useful\n- attributes in a LogRecord are described by:\n-\n- %(name)s Name of the logger (logging channel)\n- %(lvl)s Numeric logging level for the message (DEBUG, INFO,\n- WARN, ERROR, CRITICAL)\n- %(level)s Text logging level for the message (\"DEBUG\", \"INFO\",\n- \"WARN\", \"ERROR\", \"CRITICAL\")\n- %(pathname)s Full pathname of the source file where the logging\n- call was issued (if available)\n- %(filename)s Filename portion of pathname\n- %(lineno)d Source line number where the logging call was issued\n- (if available)\n- %(created)f Time when the LogRecord was created (time.time()\n- return value)\n- %(asctime)s textual time when the LogRecord was created\n- %(msecs)d Millisecond portion of the creation time\n- %(relativeCreated)d Time in milliseconds when the LogRecord was created,\n- relative to the time the logging module was loaded\n- (typically at application startup time)\n- %(thread)d Thread ID (if available)\n- %(message)s The result of msg % args, computed just as the\n- record is emitted\n- %(msg)s The raw formatting string provided by the user\n- %(args)r The argument tuple which goes with the formatting\n- string in the msg attribute\n- \"\"\"\n- def __init__(self, fmt=None, datefmt=None):\n- \"\"\"\n- Initialize the formatter either with the specified format string, or a\n- default as described above. Allow for specialized date formatting with\n- the optional datefmt argument (if omitted, you get the ISO8601 format).\n- \"\"\"\n- if fmt:\n- self._fmt = fmt\n- else:\n- self._fmt = \"%(message)s\"\n- self.datefmt = datefmt\n-\n- def formatTime(self, record, datefmt=None):\n- \"\"\"\n- This method should be called from format() by a formatter which\n- wants to make use of a formatted time. This method can be overridden\n- in formatters to provide for any specific requirement, but the\n- basic behaviour is as follows: if datefmt (a string) is specfied,\n- it is used with time.strftime to format the creation time of the\n- record. Otherwise, the ISO8601 format is used. The resulting\n- string is written to the asctime attribute of the record.\n- \"\"\"\n- ct = record.created\n- if datefmt:\n- s = time.strftime(datefmt, time.localtime(ct))\n- else:\n- t = time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime(ct))\n- s = \"%s,%03d\" % (t, record.msecs)\n- record.asctime = s\n-\n- def formatException(self, ei):\n- \"\"\"\n- Format the specified exception information as a string. This\n- default implementation just uses traceback.print_exception()\n- \"\"\"\n- import traceback\n- sio = cStringIO.StringIO()\n- traceback.print_exception(ei[0], ei[1], ei[2], None, sio)\n- s = sio.getvalue()\n- sio.close()\n- return s\n-\n- def format(self, record):\n- \"\"\"\n- The record's attribute dictionary is used as the operand to a\n- string formatting operation which yields the returned string.\n- Before formatting the dictionary, a couple of preparatory steps\n- are carried out. The message attribute of the record is computed\n- using msg % args. If the formatting string contains \"(asctime)\",\n- formatTime() is called to format the event time. If there is\n- exception information, it is formatted using formatException()\n- and appended to the message.\n- \"\"\"\n- record.message = record.msg % record.args\n- if string.find(self._fmt,\"(asctime)\") > 0:\n- self.formatTime(record, self.datefmt)\n- s = self._fmt % record.__dict__\n- if record.exc_info:\n- if s[-1] != \"\\n\":\n- s = s + \"\\n\"\n- s = s + self.formatException(record.exc_info)\n- return s\n-\n-#\n-# The default formatter to use when no other is specified\n-#\n-_defaultFormatter = Formatter()\n-\n-class BufferingFormatter:\n- \"\"\"\n- A formatter suitable for formatting a number of records.\n- \"\"\"\n- def __init__(self, linefmt=None):\n- \"\"\"\n- Optionally specify a formatter which will be used to format each\n- individual record.\n- \"\"\"\n- if linefmt:\n- self.linefmt = linefmt\n- else:\n- self.linefmt = _defaultFormatter\n-\n- def formatHeader(self, records):\n- \"\"\"\n- Return the header string for the specified records.\n- \"\"\"\n- return \"\"\n-\n- def formatFooter(self, records):\n- \"\"\"\n- Return the footer string for the specified records.\n- \"\"\"\n- return \"\"\n-\n- def format(self, records):\n- \"\"\"\n- Format the specified records and return the result as a string.\n- \"\"\"\n- rv = \"\"\n- if len(records) > 0:\n- rv = rv + self.formatHeader(records)\n- for record in records:\n- rv = rv + self.linefmt.format(record)\n- rv = rv + self.formatFooter(records)\n- return rv\n-\n-#---------------------------------------------------------------------------\n-# Filter classes and functions\n-#---------------------------------------------------------------------------\n-\n-class Filter:\n- \"\"\"\n- The base filter class. This class never filters anything, acting as\n- a placeholder which defines the Filter interface. Loggers and Handlers\n- can optionally use Filter instances to filter records as desired.\n- \"\"\"\n- def filter(self, record):\n- \"\"\"\n- Is the specified record to be logged? Returns a boolean value.\n- \"\"\"\n- return 1\n-\n-class Filterer:\n- \"\"\"\n- A base class for loggers and handlers which allows them to share\n- common code.\n- \"\"\"\n- def __init__(self):\n- self.filters = []\n-\n- def addFilter(self, filter):\n- \"\"\"\n- Add the specified filter to this handler.\n- \"\"\"\n- if not (filter in self.filters):\n- self.filters.append(filter)\n-\n- def removeFilter(self, filter):\n- \"\"\"\n- Remove the specified filter from this handler.\n- \"\"\"\n- if filter in self.filters:\n- self.filters.remove(filter)\n-\n- def filter(self, record):\n- \"\"\"\n- Determine if a record is loggable by consulting all the filters. The\n- default is to allow the record to be logged; any filter can veto this\n- and the record is then dropped. Returns a boolean value.\n- \"\"\"\n- rv = 1\n- for f in self.filters:\n- if not f.filter(record):\n- rv = 0\n- break\n- return rv\n-\n-#---------------------------------------------------------------------------\n-# Handler classes and functions\n-#---------------------------------------------------------------------------\n-\n-_handlers = {} #repository of handlers (for flushing when shutdown called)\n-\n-class Handler(Filterer):\n- \"\"\"\n- The base handler class. Acts as a placeholder which defines the Handler\n- interface. Handlers can optionally use Formatter instances to format\n- records as desired. By default, no formatter is specified; in this case,\n- the 'raw' message as determined by record.message is logged.\n- \"\"\"\n- def __init__(self, level=0):\n- \"\"\"\n- Initializes the instance - basically setting the formatter to None\n- and the filter list to empty.\n- \"\"\"\n- Filterer.__init__(self)\n- self.level = level\n- self.formatter = None\n- _handlers[self] = 1\n-\n- def setLevel(self, lvl):\n- \"\"\"\n- Set the logging level of this handler.\n- \"\"\"\n- self.level = lvl\n-\n- def format(self, record):\n- \"\"\"\n- Do formatting for a record - if a formatter is set, use it.\n- Otherwise, use the default formatter for the module.\n- \"\"\"\n- if self.formatter:\n- fmt = self.formatter\n- else:\n- fmt = _defaultFormatter\n- return fmt.format(record)\n-\n- def emit(self, record):\n- \"\"\"\n- Do whatever it takes to actually log the specified logging record.\n- This version is intended to be implemented by subclasses and so\n- raises a NotImplementedError.\n- \"\"\"\n- raise NotImplementedError, 'emit must be implemented '\\\n- 'by Handler subclasses'\n-\n- def handle(self, record):\n- \"\"\"\n- Conditionally handle the specified logging record, depending on\n- filters which may have been added to the handler.\n- \"\"\"\n- if self.filter(record):\n- self.emit(record)\n-\n- def setFormatter(self, fmt):\n- \"\"\"\n- Set the formatter for this handler.\n- \"\"\"\n- self.formatter = fmt\n-\n- def flush(self):\n- \"\"\"\n- Ensure all logging output has been flushed. This version does\n- nothing and is intended to be implemented by subclasses.\n- \"\"\"\n- pass\n-\n- def close(self):\n- \"\"\"\n- Tidy up any resources used by the handler. This version does\n- nothing and is intended to be implemented by subclasses.\n- \"\"\"\n- pass\n-\n- def handleError(self):\n- \"\"\"\n- This method should be called from handlers when an exception is\n- encountered during an emit() call. By default it does nothing,\n- which means that exceptions get silently ignored. This is what is\n- mostly wanted for a logging system - most users will not care\n- about errors in the logging system, they are more interested in\n- application errors. You could, however, replace this with a custom\n- handler if you wish.\n- \"\"\"\n- #import traceback\n- #ei = sys.exc_info()\n- #traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr)\n- #del ei\n- pass\n-\n-class StreamHandler(Handler):\n- \"\"\"\n- A handler class which writes logging records, appropriately formatted,\n- to a stream. Note that this class does not close the stream, as\n- sys.stdout or sys.stderr may be used.\n- \"\"\"\n- def __init__(self, strm=None):\n- \"\"\"\n- If strm is not specified, sys.stderr is used.\n- \"\"\"\n- Handler.__init__(self)\n- if not strm:\n- strm = sys.stderr\n- self.stream = strm\n- self.formatter = None\n-\n- def flush(self):\n- \"\"\"\n- Flushes the stream.\n- \"\"\"\n- self.stream.flush()\n-\n- def emit(self, record):\n- \"\"\"\n- If a formatter is specified, it is used to format the record.\n- The record is then written to the stream with a trailing newline\n- [N.B. this may be removed depending on feedback]. If exception\n- information is present, it is formatted using\n- traceback.print_exception and appended to the stream.\n- \"\"\"\n- try:\n- msg = self.format(record)\n- self.stream.write(\"%s\\n\" % msg)\n- self.flush()\n- except:\n- self.handleError()\n-\n-class FileHandler(StreamHandler):\n- \"\"\"\n- A handler class which writes formatted logging records to disk files.\n- \"\"\"\n- def __init__(self, filename, mode=\"a+\"):\n- \"\"\"\n- Open the specified file and use it as the stream for logging.\n- By default, the file grows indefinitely. You can call setRollover()\n- to allow the file to rollover at a predetermined size.\n- \"\"\"\n- StreamHandler.__init__(self, open(filename, mode))\n- self.max_size = 0\n- self.backup_count = 0\n- self.basefilename = filename\n- self.backup_index = 0\n- self.mode = mode\n-\n- def setRollover(self, max_size, backup_count):\n- \"\"\"\n- Set the rollover parameters so that rollover occurs whenever the\n- current log file is nearly max_size in length. If backup_count\n- is >= 1, the system will successively create new files with the\n- same pathname as the base file, but with extensions \".1\", \".2\"\n- etc. appended to it. For example, with a backup_count of 5 and a\n- base file name of \"app.log\", you would get \"app.log\", \"app.log.1\",\n- \"app.log.2\", ... through to \"app.log.5\". When the last file reaches\n- its size limit, the logging reverts to \"app.log\" which is truncated\n- to zero length. If max_size is zero, rollover never occurs.\n- \"\"\"\n- self.max_size = max_size\n- self.backup_count = backup_count\n- if max_size > 0:\n- self.mode = \"a+\"\n-\n- def doRollover(self):\n- \"\"\"\n- Do a rollover, as described in setRollover().\n- \"\"\"\n- if self.backup_index >= self.backup_count:\n- self.backup_index = 0\n- fn = self.basefilename\n- else:\n- self.backup_index = self.backup_index + 1\n- fn = \"%s.%d\" % (self.basefilename, self.backup_index)\n- self.stream.close()\n- self.stream = open(fn, \"w+\")\n-\n- def emit(self, record):\n- \"\"\"\n- Output the record to the file, catering for rollover as described\n- in setRollover().\n- \"\"\"\n- if self.max_size > 0: # are we rolling over?\n- msg = \"%s\\n\" % self.format(record)\n- if self.stream.tell() + len(msg) >= self.max_size:\n- self.doRollover()\n- StreamHandler.emit(self, record)\n-\n- def close(self):\n- \"\"\"\n- Closes the stream.\n- \"\"\"\n- self.stream.close()\n-\n-class SocketHandler(StreamHandler):\n- \"\"\"\n- A handler class which writes logging records, in pickle format, to\n- a streaming socket. The socket is kept open across logging calls.\n- If the peer resets it, an attempt is made to reconnect on the next call.\n- \"\"\"\n-\n- def __init__(self, host, port):\n- \"\"\"\n- Initializes the handler with a specific host address and port.\n- \"\"\"\n- StreamHandler.__init__(self)\n- self.host = host\n- self.port = port\n- self.sock = None\n- self.closeOnError = 1\n-\n- def makeSocket(self):\n- \"\"\"\n- A factory method which allows subclasses to define the precise\n- type of socket they want.\n- \"\"\"\n- s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n- s.connect((self.host, self.port))\n- return s\n-\n- def send(self, s):\n- \"\"\"\n- Send a pickled string to the socket. This function allows for\n- partial sends which can happen when the network is busy.\n- \"\"\"\n- sentsofar = 0\n- left = len(s)\n- while left > 0:\n- sent = self.sock.send(s[sentsofar:])\n- sentsofar = sentsofar + sent\n- left = left - sent\n-\n- def makePickle(self, record):\n- \"\"\"\n- Pickle the record in binary format with a length prefix.\n- \"\"\"\n- s = cPickle.dumps(record.__dict__, 1)\n- n = len(s)\n- slen = \"%c%c\" % ((n >> 8) & 0xFF, n & 0xFF)\n- return slen + s\n-\n- def handleError(self):\n- \"\"\"\n- An error has occurred during logging. Most likely cause -\n- connection lost. Close the socket so that we can retry on the\n- next event.\n- \"\"\"\n- if self.closeOnError and self.sock:\n- self.sock.close()\n- self.sock = None #try to reconnect next time\n-\n- def emit(self, record):\n- \"\"\"\n- Pickles the record and writes it to the socket in binary format.\n- If there is an error with the socket, silently drop the packet.\n- \"\"\"\n- try:\n- s = self.makePickle(record)\n- if not self.sock:\n- self.sock = self.makeSocket()\n- self.send(s)\n- except:\n- self.handleError()\n-\n- def close(self):\n- \"\"\"\n- Closes the socket.\n- \"\"\"\n- if self.sock:\n- self.sock.close()\n- self.sock = None\n-\n-class DatagramHandler(SocketHandler):\n- \"\"\"\n- A handler class which writes logging records, in pickle format, to\n- a datagram socket.\n- \"\"\"\n- def __init__(self, host, port):\n- \"\"\"\n- Initializes the handler with a specific host address and port.\n- \"\"\"\n- SocketHandler.__init__(self, host, port)\n- self.closeOnError = 0\n-\n- def makeSocket(self):\n- \"\"\"\n- The factory method of SocketHandler is here overridden to create\n- a UDP socket (SOCK_DGRAM).\n- \"\"\"\n- s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n- return s\n-\n- def sendto(self, s, addr):\n- \"\"\"\n- Send a pickled string to a socket. This function allows for\n- partial sends which can happen when the network is busy.\n- \"\"\"\n- sentsofar = 0\n- left = len(s)\n- while left > 0:\n- sent = self.sock.sendto(s[sentsofar:], addr)\n- sentsofar = sentsofar + sent\n- left = left - sent\n-\n- def emit(self, record):\n- \"\"\"\n- Pickles the record and writes it to the socket in binary format.\n- \"\"\"\n- try:\n- s = self.makePickle(record)\n- if not self.sock:\n- self.sock = self.makeSocket()\n- self.sendto(s, (self.host, self.port))\n- except:\n- self.handleError()\n-\n-class SysLogHandler(Handler):\n- \"\"\"\n- A handler class which sends formatted logging records to a syslog\n- server. Based on Sam Rushing's syslog module:\n- http://www.nightmare.com/squirl/python-ext/misc/syslog.py\n- Contributed by Nicolas Untz (after which minor refactoring changes\n- have been made).\n- \"\"\"\n-\n- # from :\n- # ======================================================================\n- # priorities/facilities are encoded into a single 32-bit quantity, where\n- # the bottom 3 bits are the priority (0-7) and the top 28 bits are the\n- # facility (0-big number). Both the priorities and the facilities map\n- # roughly one-to-one to strings in the syslogd(8) source code. This\n- # mapping is included in this file.\n- #\n- # priorities (these are ordered)\n-\n- LOG_EMERG = 0 # system is unusable\n- LOG_ALERT = 1 # action must be taken immediately\n- LOG_CRIT = 2 # critical conditions\n- LOG_ERR = 3 # error conditions\n- LOG_WARNING = 4 # warning conditions\n- LOG_NOTICE = 5 # normal but significant condition\n- LOG_INFO = 6 # informational\n- LOG_DEBUG = 7 # debug-level messages\n-\n- # facility codes\n- LOG_KERN = 0 # kernel messages\n- LOG_USER = 1 # random user-level messages\n- LOG_MAIL = 2 # mail system\n- LOG_DAEMON = 3 # system daemons\n- LOG_AUTH = 4 # security/authorization messages\n- LOG_SYSLOG = 5 # messages generated internally by syslogd\n- LOG_LPR = 6 # line printer subsystem\n- LOG_NEWS = 7 # network news subsystem\n- LOG_UUCP = 8 # UUCP subsystem\n- LOG_CRON = 9 # clock daemon\n- LOG_AUTHPRIV = 10 # security/authorization messages (private)\n-\n- # other codes through 15 reserved for system use\n- LOG_LOCAL0 = 16 # reserved for local use\n- LOG_LOCAL1 = 17 # reserved for local use\n- LOG_LOCAL2 = 18 # reserved for local use\n- LOG_LOCAL3 = 19 # reserved for local use\n- LOG_LOCAL4 = 20 # reserved for local use\n- LOG_LOCAL5 = 21 # reserved for local use\n- LOG_LOCAL6 = 22 # reserved for local use\n- LOG_LOCAL7 = 23 # reserved for local use\n-\n- priority_names = {\n- \"alert\": LOG_ALERT,\n- \"crit\": LOG_CRIT,\n- \"critical\": LOG_CRIT,\n- \"debug\": LOG_DEBUG,\n- \"emerg\": LOG_EMERG,\n- \"err\": LOG_ERR,\n- \"error\": LOG_ERR, # DEPRECATED\n- \"info\": LOG_INFO,\n- \"notice\": LOG_NOTICE,\n- \"panic\": LOG_EMERG, # DEPRECATED\n- \"warn\": LOG_WARNING, # DEPRECATED\n- \"warning\": LOG_WARNING,\n- }\n-\n- facility_names = {\n- \"auth\": LOG_AUTH,\n- \"authpriv\": LOG_AUTHPRIV,\n- \"cron\": LOG_CRON,\n- \"daemon\": LOG_DAEMON,\n- \"kern\": LOG_KERN,\n- \"lpr\": LOG_LPR,\n- \"mail\": LOG_MAIL,\n- \"news\": LOG_NEWS,\n- \"security\": LOG_AUTH, # DEPRECATED\n- \"syslog\": LOG_SYSLOG,\n- \"user\": LOG_USER,\n- \"uucp\": LOG_UUCP,\n- \"local0\": LOG_LOCAL0,\n- \"local1\": LOG_LOCAL1,\n- \"local2\": LOG_LOCAL2,\n- \"local3\": LOG_LOCAL3,\n- \"local4\": LOG_LOCAL4,\n- \"local5\": LOG_LOCAL5,\n- \"local6\": LOG_LOCAL6,\n- \"local7\": LOG_LOCAL7,\n- }\n-\n- def __init__(self, address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER):\n- \"\"\"\n- If address is not specified, UNIX socket is used.\n- If facility is not specified, LOG_USER is used.\n- \"\"\"\n- Handler.__init__(self)\n-\n- self.address = address\n- self.facility = facility\n- if type(address) == types.StringType:\n- self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)\n- self.socket.connect(address)\n- self.unixsocket = 1\n- else:\n- self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n- self.unixsocket = 0\n-\n- self.formatter = None\n-\n- # curious: when talking to the unix-domain '/dev/log' socket, a\n- # zero-terminator seems to be required. this string is placed\n- # into a class variable so that it can be overridden if\n- # necessary.\n- log_format_string = '<%d>%s\\000'\n-\n- def encodePriority (self, facility, priority):\n- \"\"\"\n- Encode the facility and priority. You can pass in strings or\n- integers - if strings are passed, the facility_names and\n- priority_names mapping dictionaries are used to convert them to\n- integers.\n- \"\"\"\n- if type(facility) == types.StringType:\n- facility = self.facility_names[facility]\n- if type(priority) == types.StringType:\n- priority = self.priority_names[priority]\n- return (facility << 3) | priority\n-\n- def close (self):\n- \"\"\"\n- Closes the socket.\n- \"\"\"\n- if self.unixsocket:\n- self.socket.close()\n-\n- def emit(self, record):\n- \"\"\"\n- The record is formatted, and then sent to the syslog server. If\n- exception information is present, it is NOT sent to the server.\n- \"\"\"\n- msg = self.format(record)\n- \"\"\"\n- We need to convert record level to lowercase, maybe this will\n- change in the future.\n- \"\"\"\n- msg = self.log_format_string % (\n- self.encodePriority(self.facility, string.lower(record.level)),\n- msg)\n- try:\n- if self.unixsocket:\n- self.socket.send(msg)\n- else:\n- self.socket.sendto(msg, self.address)\n- except:\n- self.handleError()\n-\n-class SMTPHandler(Handler):\n- \"\"\"\n- A handler class which sends an SMTP email for each logging event.\n- \"\"\"\n- def __init__(self, mailhost, fromaddr, toaddrs, subject):\n- \"\"\"\n- Initialize the instance with the from and to addresses and subject\n- line of the email. To specify a non-standard SMTP port, use the\n- (host, port) tuple format for the mailhost argument.\n- \"\"\"\n- Handler.__init__(self)\n- if type(mailhost) == types.TupleType:\n- host, port = mailhost\n- self.mailhost = host\n- self.mailport = port\n- else:\n- self.mailhost = mailhost\n- self.mailport = None\n- self.fromaddr = fromaddr\n- self.toaddrs = toaddrs\n- self.subject = subject\n-\n- def getSubject(self, record):\n- \"\"\"\n- If you want to specify a subject line which is record-dependent,\n- override this method.\n- \"\"\"\n- return self.subject\n-\n- def emit(self, record):\n- \"\"\"\n- Format the record and send it to the specified addressees.\n- \"\"\"\n- try:\n- import smtplib\n- port = self.mailport\n- if not port:\n- port = smtplib.SMTP_PORT\n- smtp = smtplib.SMTP(self.mailhost, port)\n- msg = self.format(record)\n- msg = \"From: %s\\r\\nTo: %s\\r\\nSubject: %s\\r\\n\\r\\n%s\" % (\n- self.fromaddr,\n- string.join(self.toaddrs, \",\"),\n- self.getSubject(record), msg\n- )\n- smtp.sendmail(self.fromaddr, self.toaddrs, msg)\n- smtp.quit()\n- except:\n- self.handleError()\n-\n-class BufferingHandler(Handler):\n- \"\"\"\n- A handler class which buffers logging records in memory. Whenever each\n- record is added to the buffer, a check is made to see if the buffer should\n- be flushed. If it should, then flush() is expected to do the needful.\n- \"\"\"\n- def __init__(self, capacity):\n- \"\"\"\n- Initialize the handler with the buffer size.\n- \"\"\"\n- Handler.__init__(self)\n- self.capacity = capacity\n- self.buffer = []\n-\n- def shouldFlush(self, record):\n- \"\"\"\n- Returns true if the buffer is up to capacity. This method can be\n- overridden to implement custom flushing strategies.\n- \"\"\"\n- return (len(self.buffer) >= self.capacity)\n-\n- def emit(self, record):\n- \"\"\"\n- Append the record. If shouldFlush() tells us to, call flush() to process\n- the buffer.\n- \"\"\"\n- self.buffer.append(record)\n- if self.shouldFlush(record):\n- self.flush()\n-\n- def flush(self):\n- \"\"\"\n- Override to implement custom flushing behaviour. This version just zaps\n- the buffer to empty.\n- \"\"\"\n- self.buffer = []\n-\n-class MemoryHandler(BufferingHandler):\n- \"\"\"\n- A handler class which buffers logging records in memory, periodically\n- flushing them to a target handler. Flushing occurs whenever the buffer\n- is full, or when an event of a certain severity or greater is seen.\n- \"\"\"\n- def __init__(self, capacity, flushLevel=ERROR, target=None):\n- \"\"\"\n- Initialize the handler with the buffer size, the level at which\n- flushing should occur and an optional target. Note that without a\n- target being set either here or via setTarget(), a MemoryHandler\n- is no use to anyone!\n- \"\"\"\n- BufferingHandler.__init__(self, capacity)\n- self.flushLevel = flushLevel\n- self.target = target\n-\n- def shouldFlush(self, record):\n- \"\"\"\n- Check for buffer full or a record at the flushLevel or higher.\n- \"\"\"\n- return (len(self.buffer) >= self.capacity) or \\\n- (record.lvl >= self.flushLevel)\n-\n- def setTarget(self, target):\n- \"\"\"\n- Set the target handler for this handler.\n- \"\"\"\n- self.target = target\n-\n- def flush(self):\n- \"\"\"\n- For a MemoryHandler, flushing means just sending the buffered\n- records to the target, if there is one. Override if you want\n- different behaviour.\n- \"\"\"\n- if self.target:\n- for record in self.buffer:\n- self.target.handle(record)\n- self.buffer = []\n-\n-class NTEventLogHandler(Handler):\n- \"\"\"\n- A handler class which sends events to the NT Event Log. Adds a\n- registry entry for the specified application name. If no dllname is\n- provided, win32service.pyd (which contains some basic message\n- placeholders) is used. Note that use of these placeholders will make\n- your event logs big, as the entire message source is held in the log.\n- If you want slimmer logs, you have to pass in the name of your own DLL\n- which contains the message definitions you want to use in the event log.\n- \"\"\"\n- def __init__(self, appname, dllname=None, logtype=\"Application\"):\n- Handler.__init__(self)\n- try:\n- import win32evtlogutil, win32evtlog\n- self.appname = appname\n- self._welu = win32evtlogutil\n- if not dllname:\n- import os\n- dllname = os.path.split(self._welu.__file__)\n- dllname = os.path.split(dllname[0])\n- dllname = os.path.join(dllname[0], r'win32service.pyd')\n- self.dllname = dllname\n- self.logtype = logtype\n- self._welu.AddSourceToRegistry(appname, dllname, logtype)\n- self.deftype = win32evtlog.EVENTLOG_ERROR_TYPE\n- self.typemap = {\n- DEBUG : win32evtlog.EVENTLOG_INFORMATION_TYPE,\n- INFO : win32evtlog.EVENTLOG_INFORMATION_TYPE,\n- WARN : win32evtlog.EVENTLOG_WARNING_TYPE,\n- ERROR : win32evtlog.EVENTLOG_ERROR_TYPE,\n- CRITICAL: win32evtlog.EVENTLOG_ERROR_TYPE,\n- }\n- except ImportError:\n- print \"The Python Win32 extensions for NT (service, event \"\\\n- \"logging) appear not to be available.\"\n- self._welu = None\n-\n- def getMessageID(self, record):\n- \"\"\"\n- Return the message ID for the event record. If you are using your\n- own messages, you could do this by having the msg passed to the\n- logger being an ID rather than a formatting string. Then, in here,\n- you could use a dictionary lookup to get the message ID. This\n- version returns 1, which is the base message ID in win32service.pyd.\n- \"\"\"\n- return 1\n-\n- def getEventCategory(self, record):\n- \"\"\"\n- Return the event category for the record. Override this if you\n- want to specify your own categories. This version returns 0.\n- \"\"\"\n- return 0\n-\n- def getEventType(self, record):\n- \"\"\"\n- Return the event type for the record. Override this if you want\n- to specify your own types. This version does a mapping using the\n- handler's typemap attribute, which is set up in __init__() to a\n- dictionary which contains mappings for DEBUG, INFO, WARN, ERROR\n- and CRITICAL. If you are using your own levels you will either need\n- to override this method or place a suitable dictionary in the\n- handler's typemap attribute.\n- \"\"\"\n- return self.typemap.get(record.lvl, self.deftype)\n-\n- def emit(self, record):\n- \"\"\"\n- Determine the message ID, event category and event type. Then\n- log the message in the NT event log.\n- \"\"\"\n- if self._welu:\n- try:\n- id = self.getMessageID(record)\n- cat = self.getEventCategory(record)\n- type = self.getEventType(record)\n- msg = self.format(record)\n- self._welu.ReportEvent(self.appname, id, cat, type, [msg])\n- except:\n- self.handleError()\n-\n- def close(self):\n- \"\"\"\n- You can remove the application name from the registry as a\n- source of event log entries. However, if you do this, you will\n- not be able to see the events as you intended in the Event Log\n- Viewer - it needs to be able to access the registry to get the\n- DLL name.\n- \"\"\"\n- #self._welu.RemoveSourceFromRegistry(self.appname, self.logtype)\n- pass\n-\n-class HTTPHandler(Handler):\n- \"\"\"\n- A class which sends records to a Web server, using either GET or\n- POST semantics.\n- \"\"\"\n- def __init__(self, host, url, method=\"GET\"):\n- \"\"\"\n- Initialize the instance with the host, the request URL, and the method\n- (\"GET\" or \"POST\")\n- \"\"\"\n- Handler.__init__(self)\n- method = string.upper(method)\n- if method not in [\"GET\", \"POST\"]:\n- raise ValueError, \"method must be GET or POST\"\n- self.host = host\n- self.url = url\n- self.method = method\n-\n- def emit(self, record):\n- \"\"\"\n- Send the record to the Web server as an URL-encoded dictionary\n- \"\"\"\n- try:\n- import httplib, urllib\n- h = httplib.HTTP(self.host)\n- url = self.url\n- data = urllib.urlencode(record.__dict__)\n- if self.method == \"GET\":\n- if (string.find(url, '?') >= 0):\n- sep = '&'\n- else:\n- sep = '?'\n- url = url + \"%c%s\" % (sep, data)\n- h.putrequest(self.method, url)\n- if self.method == \"POST\":\n- h.putheader(\"Content-length\", str(len(data)))\n- h.endheaders()\n- if self.method == \"POST\":\n- h.send(data)\n- h.getreply() #can't do anything with the result\n- except:\n- self.handleError()\n-\n-SOAP_MESSAGE = \"\"\"\n- \n- \n-%s\n- \n- \n-\n-\"\"\"\n-\n-class SOAPHandler(Handler):\n- \"\"\"\n- A class which sends records to a SOAP server.\n- \"\"\"\n- def __init__(self, host, url):\n- \"\"\"\n- Initialize the instance with the host and the request URL\n- \"\"\"\n- Handler.__init__(self)\n- self.host = host\n- self.url = url\n-\n- def emit(self, record):\n- \"\"\"\n- Send the record to the Web server as a SOAP message\n- \"\"\"\n- try:\n- import httplib, urllib\n- h = httplib.HTTP(self.host)\n- h.putrequest(\"POST\", self.url)\n- keys = record.__dict__.keys()\n- keys.sort()\n- args = \"\"\n- for key in keys:\n- v = record.__dict__[key]\n- if type(v) == types.StringType:\n- t = \"string\"\n- elif (type(v) == types.IntType) or (type(v) == types.LongType):\n- t = \"integer\"\n- elif type(v) == types.FloatType:\n- t = \"float\"\n- else:\n- t = \"string\"\n- args = args + \"%12s%s\\n\" % (\"\",\n- key, t, str(v), key)\n- data = SOAP_MESSAGE % args[:-1]\n- #print data\n- h.putheader(\"Content-type\", \"text/plain; charset=\\\"utf-8\\\"\")\n- h.putheader(\"Content-length\", str(len(data)))\n- h.endheaders()\n- h.send(data)\n- r = h.getreply() #can't do anything with the result\n- #print r\n- f = h.getfile()\n- #print f.read()\n- f.close()\n- except:\n- self.handleError()\n-\n-#---------------------------------------------------------------------------\n-# Manager classes and functions\n-#---------------------------------------------------------------------------\n-\n-class PlaceHolder:\n- \"\"\"\n- PlaceHolder instances are used in the Manager logger hierarchy to take\n- the place of nodes for which no loggers have been defined [FIXME add\n- example].\n- \"\"\"\n- def __init__(self, alogger):\n- \"\"\"\n- Initialize with the specified logger being a child of this placeholder.\n- \"\"\"\n- self.loggers = [alogger]\n-\n- def append(self, alogger):\n- \"\"\"\n- Add the specified logger as a child of this placeholder.\n- \"\"\"\n- if alogger not in self.loggers:\n- self.loggers.append(alogger)\n-\n-#\n-# Determine which class to use when instantiating loggers.\n-#\n-_loggerClass = None\n-\n-def setLoggerClass(klass):\n- \"\"\"\n- Set the class to be used when instantiating a logger. The class should\n- define __init__() such that only a name argument is required, and the\n- __init__() should call Logger.__init__()\n- \"\"\"\n- if klass != Logger:\n- if type(klass) != types.ClassType:\n- raise TypeError, \"setLoggerClass is expecting a class\"\n- if not (Logger in klass.__bases__):\n- raise TypeError, \"logger not derived from logging.Logger: \" + \\\n- klass.__name__\n- global _loggerClass\n- _loggerClass = klass\n-\n-class Manager:\n- \"\"\"\n- There is [under normal circumstances] just one Manager instance, which\n- holds the hierarchy of loggers.\n- \"\"\"\n- def __init__(self, root):\n- \"\"\"\n- Initialize the manager with the root node of the logger hierarchy.\n- \"\"\"\n- self.root = root\n- self.disable = 0\n- self.emittedNoHandlerWarning = 0\n- self.loggerDict = {}\n-\n- def getLogger(self, name):\n- \"\"\"\n- Get a logger with the specified name, creating it if it doesn't\n- yet exist. If a PlaceHolder existed for the specified name [i.e.\n- the logger didn't exist but a child of it did], replace it with\n- the created logger and fix up the parent/child references which\n- pointed to the placeholder to now point to the logger.\n- \"\"\"\n- rv = None\n- if self.loggerDict.has_key(name):\n- rv = self.loggerDict[name]\n- if isinstance(rv, PlaceHolder):\n- ph = rv\n- rv = _loggerClass(name)\n- rv.manager = self\n- self.loggerDict[name] = rv\n- self._fixupChildren(ph, rv)\n- self._fixupParents(rv)\n- else:\n- rv = _loggerClass(name)\n- rv.manager = self\n- self.loggerDict[name] = rv\n- self._fixupParents(rv)\n- return rv\n-\n- def _fixupParents(self, alogger):\n- \"\"\"\n- Ensure that there are either loggers or placeholders all the way\n- from the specified logger to the root of the logger hierarchy.\n- \"\"\"\n- name = alogger.name\n- i = string.rfind(name, \".\")\n- rv = None\n- while (i > 0) and not rv:\n- substr = name[:i]\n- if not self.loggerDict.has_key(substr):\n- self.loggerDict[name] = PlaceHolder(alogger)\n- else:\n- obj = self.loggerDict[substr]\n- if isinstance(obj, Logger):\n- rv = obj\n- else:\n- assert isinstance(obj, PlaceHolder)\n- obj.append(alogger)\n- i = string.rfind(name, \".\", 0, i - 1)\n- if not rv:\n- rv = self.root\n- alogger.parent = rv\n-\n- def _fixupChildren(self, ph, alogger):\n- \"\"\"\n- Ensure that children of the placeholder ph are connected to the\n- specified logger.\n- \"\"\"\n- for c in ph.loggers:\n- if string.find(c.parent.name, alogger.name) <> 0:\n- alogger.parent = c.parent\n- c.parent = alogger\n-\n-#---------------------------------------------------------------------------\n-# Logger classes and functions\n-#---------------------------------------------------------------------------\n-\n-class Logger(Filterer):\n- \"\"\"\n- Instances of the Logger class represent a single logging channel.\n- \"\"\"\n- def __init__(self, name, level=0):\n- \"\"\"\n- Initialize the logger with a name and an optional level.\n- \"\"\"\n- Filterer.__init__(self)\n- self.name = name\n- self.level = level\n- self.parent = None\n- self.propagate = 1\n- self.handlers = []\n-\n- def setLevel(self, lvl):\n- \"\"\"\n- Set the logging level of this logger.\n- \"\"\"\n- self.level = lvl\n-\n-# def getRoot(self):\n-# \"\"\"\n-# Get the root of the logger hierarchy.\n-# \"\"\"\n-# return Logger.root\n-\n- def debug(self, msg, *args, **kwargs):\n- \"\"\"\n- Log 'msg % args' with severity 'DEBUG'. To pass exception information,\n- use the keyword argument exc_info with a true value, e.g.\n-\n- logger.debug(\"Houston, we have a %s\", \"thorny problem\", exc_info=1)\n- \"\"\"\n- if self.manager.disable >= DEBUG:\n- return\n- if DEBUG >= self.getEffectiveLevel():\n- apply(self._log, (DEBUG, msg, args), kwargs)\n-\n- def info(self, msg, *args, **kwargs):\n- \"\"\"\n- Log 'msg % args' with severity 'INFO'. To pass exception information,\n- use the keyword argument exc_info with a true value, e.g.\n-\n- logger.info(\"Houston, we have a %s\", \"interesting problem\", exc_info=1)\n- \"\"\"\n- if self.manager.disable >= INFO:\n- return\n- if INFO >= self.getEffectiveLevel():\n- apply(self._log, (INFO, msg, args), kwargs)\n-\n- def warn(self, msg, *args, **kwargs):\n- \"\"\"\n- Log 'msg % args' with severity 'WARN'. To pass exception information,\n- use the keyword argument exc_info with a true value, e.g.\n-\n- logger.warn(\"Houston, we have a %s\", \"bit of a problem\", exc_info=1)\n- \"\"\"\n- if self.manager.disable >= WARN:\n- return\n- if self.isEnabledFor(WARN):\n- apply(self._log, (WARN, msg, args), kwargs)\n-\n- def error(self, msg, *args, **kwargs):\n- \"\"\"\n- Log 'msg % args' with severity 'ERROR'. To pass exception information,\n- use the keyword argument exc_info with a true value, e.g.\n-\n- logger.error(\"Houston, we have a %s\", \"major problem\", exc_info=1)\n- \"\"\"\n- if self.manager.disable >= ERROR:\n- return\n- if self.isEnabledFor(ERROR):\n- apply(self._log, (ERROR, msg, args), kwargs)\n-\n- def exception(self, msg, *args):\n- \"\"\"\n- Convenience method for logging an ERROR with exception information\n- \"\"\"\n- apply(self.error, (msg,) + args, {'exc_info': 1})\n-\n- def critical(self, msg, *args, **kwargs):\n- \"\"\"\n- Log 'msg % args' with severity 'CRITICAL'. To pass exception\n- information, use the keyword argument exc_info with a true value, e.g.\n-\n- logger.critical(\"Houston, we have a %s\", \"major disaster\", exc_info=1)\n- \"\"\"\n- if self.manager.disable >= CRITICAL:\n- return\n- if CRITICAL >= self.getEffectiveLevel():\n- apply(self._log, (CRITICAL, msg, args), kwargs)\n-\n- fatal = critical\n-\n- def log(self, lvl, msg, *args, **kwargs):\n- \"\"\"\n- Log 'msg % args' with the severity 'lvl'. To pass exception\n- information, use the keyword argument exc_info with a true value, e.g.\n- logger.log(lvl, \"We have a %s\", \"mysterious problem\", exc_info=1)\n- \"\"\"\n- if self.manager.disable >= lvl:\n- return\n- if self.isEnabledFor(lvl):\n- apply(self._log, (lvl, msg, args), kwargs)\n-\n- def findCaller(self):\n- \"\"\"\n- Find the stack frame of the caller so that we can note the source\n- file name and line number.\n- \"\"\"\n- frames = inspect.stack()[1:]\n- for f in frames:\n- if _srcfile != f[1]:\n- return (f[1], f[2])\n- return (None, None)\n-\n- def makeRecord(self, name, lvl, fn, lno, msg, args, exc_info):\n- \"\"\"\n- A factory method which can be overridden in subclasses to create\n- specialized LogRecords.\n- \"\"\"\n- return LogRecord(name, lvl, fn, lno, msg, args, exc_info)\n-\n- def _log(self, lvl, msg, args, exc_info=None):\n- \"\"\"\n- Low-level logging routine which creates a LogRecord and then calls\n- all the handlers of this logger to handle the record.\n- \"\"\"\n- if inspect:\n- fn, lno = self.findCaller()\n- else:\n- fn, lno = \"\", 0\n- if exc_info:\n- exc_info = sys.exc_info()\n- record = self.makeRecord(self.name, lvl, fn, lno, msg, args, exc_info)\n- self.handle(record)\n-\n- def handle(self, record):\n- \"\"\"\n- Call the handlers for the specified record. This method is used for\n- unpickled records received from a socket, as well as those created\n- locally. Logger-level filtering is applied.\n- \"\"\"\n- if self.filter(record):\n- self.callHandlers(record)\n-\n- def addHandler(self, hdlr):\n- \"\"\"\n- Add the specified handler to this logger.\n- \"\"\"\n- if not (hdlr in self.handlers):\n- self.handlers.append(hdlr)\n-\n- def removeHandler(self, hdlr):\n- \"\"\"\n- Remove the specified handler from this logger.\n- \"\"\"\n- if hdlr in self.handlers:\n- self.handlers.remove(hdlr)\n-\n- def callHandlers(self, record):\n- \"\"\"\n- Loop through all handlers for this logger and its parents in the\n- logger hierarchy. If no handler was found, output a one-off error\n- message. Stop searching up the hierarchy whenever a logger with the\n- \"propagate\" attribute set to zero is found - that will be the last\n- logger whose handlers are called.\n- \"\"\"\n- c = self\n- found = 0\n- while c:\n- for hdlr in c.handlers:\n- found = found + 1\n- if record.lvl >= hdlr.level:\n- hdlr.handle(record)\n- if not c.propagate:\n- c = None #break out\n- else:\n- c = c.parent\n- if (found == 0) and not self.manager.emittedNoHandlerWarning:\n- print \"No handlers could be found for logger \\\"%s\\\"\" % self.name\n- self.manager.emittedNoHandlerWarning = 1\n-\n- def getEffectiveLevel(self):\n- \"\"\"\n- Loop through this logger and its parents in the logger hierarchy,\n- looking for a non-zero logging level. Return the first one found.\n- \"\"\"\n- c = self\n- while c:\n- if c.level:\n- return c.level\n- c = c.parent\n- #print \"NCP\", self.parent\n-\n- def isEnabledFor(self, lvl):\n- \"\"\"\n- Is this logger enabled for level lvl?\n- \"\"\"\n- if self.manager.disable >= lvl:\n- return 0\n- return lvl >= self.getEffectiveLevel()\n-\n-class RootLogger(Logger):\n- \"\"\"\n- A root logger is not that different to any other logger, except that\n- it must have a logging level and there is only one instance of it in\n- the hierarchy.\n- \"\"\"\n- def __init__(self, lvl):\n- \"\"\"\n- Initialize the logger with the name \"root\".\n- \"\"\"\n- Logger.__init__(self, \"root\", lvl)\n-\n-_loggerClass = Logger\n-\n-root = RootLogger(DEBUG)\n-Logger.root = root\n-Logger.manager = Manager(Logger.root)\n-\n-#---------------------------------------------------------------------------\n-# Configuration classes and functions\n-#---------------------------------------------------------------------------\n-\n-BASIC_FORMAT = \"%(asctime)s %(name)-19s %(level)-5s - %(message)s\"\n-\n-def basicConfig():\n- \"\"\"\n- Do basic configuration for the logging system by creating a\n- StreamHandler with a default Formatter and adding it to the\n- root logger.\n- \"\"\"\n- hdlr = StreamHandler()\n- fmt = Formatter(BASIC_FORMAT)\n- hdlr.setFormatter(fmt)\n- root.addHandler(hdlr)\n-\n-#def fileConfig(fname):\n-# \"\"\"\n-# The old implementation - using dict-based configuration files.\n-# Read the logging configuration from a file. Keep it simple for now.\n-# \"\"\"\n-# file = open(fname, \"r\")\n-# data = file.read()\n-# file.close()\n-# dict = eval(data)\n-# handlers = dict.get(\"handlers\", [])\n-# loggers = dict.get(\"loggers\", [])\n-# formatters = dict.get(\"formatters\", [])\n-# for f in formatters:\n-# fd = dict[f]\n-# fc = fd.get(\"class\", \"logging.Formatter\")\n-# args = fd.get(\"args\", ())\n-# fc = eval(fc)\n-# try:\n-# fmt = apply(fc, args)\n-# except:\n-# print fc, args\n-# raise\n-# dict[f] = fmt\n-#\n-# for h in handlers:\n-# hd = dict[h]\n-# hc = hd.get(\"class\", \"logging.StreamHandler\")\n-# args = hd.get(\"args\", ())\n-# hc = eval(hc)\n-# fmt = hd.get(\"formatter\", None)\n-# if fmt:\n-# fmt = dict.get(fmt, None)\n-# try:\n-# hdlr = apply(hc, args)\n-# except:\n-# print hc, args\n-# raise\n-# if fmt:\n-# hdlr.setFormatter(fmt)\n-# dict[h] = hdlr\n-#\n-# for ln in loggers:\n-# ld = dict[ln]\n-# name = ld.get(\"name\", None)\n-# if name:\n-# logger = getLogger(name)\n-# else:\n-# logger = getRootLogger()\n-# logger.propagate = ld.get(\"propagate\", 1)\n-# hdlrs = ld.get(\"handlers\", [])\n-# for h in hdlrs:\n-# hdlr = dict.get(h, None)\n-# if hdlr:\n-# logger.addHandler(hdlr)\n-\n-def fileConfig(fname):\n- \"\"\"\n- Read the logging configuration from a ConfigParser-format file.\n- \"\"\"\n- import ConfigParser\n-\n- cp = ConfigParser.ConfigParser()\n- cp.read(fname)\n- #first, do the formatters...\n- flist = cp.get(\"formatters\", \"keys\")\n- flist = string.split(flist, \",\")\n- formatters = {}\n- for form in flist:\n- sectname = \"formatter_%s\" % form\n- fs = cp.get(sectname, \"format\", 1)\n- dfs = cp.get(sectname, \"datefmt\", 1)\n- f = Formatter(fs, dfs)\n- formatters[form] = f\n- #next, do the handlers...\n- hlist = cp.get(\"handlers\", \"keys\")\n- hlist = string.split(hlist, \",\")\n- handlers = {}\n- for hand in hlist:\n- sectname = \"handler_%s\" % hand\n- klass = cp.get(sectname, \"class\")\n- fmt = cp.get(sectname, \"formatter\")\n- lvl = cp.get(sectname, \"level\")\n- klass = eval(klass)\n- args = cp.get(sectname, \"args\")\n- args = eval(args)\n- h = apply(klass, args)\n- h.setLevel(eval(lvl))\n- h.setFormatter(formatters[fmt])\n- #temporary hack for FileHandler.\n- if klass == FileHandler:\n- maxsize = cp.get(sectname, \"maxsize\")\n- if maxsize:\n- maxsize = eval(maxsize)\n- else:\n- maxsize = 0\n- if maxsize:\n- backcount = cp.get(sectname, \"backcount\")\n- if backcount:\n- backcount = eval(backcount)\n- else:\n- backcount = 0\n- h.setRollover(maxsize, backcount)\n- handlers[hand] = h\n- #at last, the loggers...first the root...\n- llist = cp.get(\"loggers\", \"keys\")\n- llist = string.split(llist, \",\")\n- llist.remove(\"root\")\n- sectname = \"logger_root\"\n- log = root\n- lvl = cp.get(sectname, \"level\")\n- log.setLevel(eval(lvl))\n- hlist = cp.get(sectname, \"handlers\")\n- hlist = string.split(hlist, \",\")\n- for hand in hlist:\n- log.addHandler(handlers[hand])\n- #and now the others...\n- for log in llist:\n- sectname = \"logger_%s\" % log\n- qn = cp.get(sectname, \"qualname\")\n- lvl = cp.get(sectname, \"level\")\n- propagate = cp.get(sectname, \"propagate\")\n- logger = getLogger(qn)\n- logger.setLevel(eval(lvl))\n- logger.propagate = eval(propagate)\n- hlist = cp.get(sectname, \"handlers\")\n- hlist = string.split(hlist, \",\")\n- for hand in hlist:\n- logger.addHandler(handlers[hand])\n-\n-\n-#---------------------------------------------------------------------------\n-# Utility functions at module level.\n-# Basically delegate everything to the root logger.\n-#---------------------------------------------------------------------------\n-\n-def getLogger(name):\n- \"\"\"\n- Return a logger with the specified name, creating it if necessary.\n- If no name is specified, return the root logger.\n- \"\"\"\n- if name:\n- return Logger.manager.getLogger(name)\n- else:\n- return root\n-\n-def getRootLogger():\n- \"\"\"\n- Return the root logger.\n- \"\"\"\n- return root\n-\n-def critical(msg, *args, **kwargs):\n- \"\"\"\n- Log a message with severity 'CRITICAL' on the root logger.\n- \"\"\"\n- if len(root.handlers) == 0:\n- basicConfig()\n- apply(root.critical, (msg,)+args, kwargs)\n-\n-fatal = critical\n-\n-def error(msg, *args, **kwargs):\n- \"\"\"\n- Log a message with severity 'ERROR' on the root logger.\n- \"\"\"\n- if len(root.handlers) == 0:\n- basicConfig()\n- apply(root.error, (msg,)+args, kwargs)\n-\n-def exception(msg, *args):\n- \"\"\"\n- Log a message with severity 'ERROR' on the root logger,\n- with exception information.\n- \"\"\"\n- apply(error, (msg,)+args, {'exc_info': 1})\n-\n-def warn(msg, *args, **kwargs):\n- \"\"\"\n- Log a message with severity 'WARN' on the root logger.\n- \"\"\"\n- if len(root.handlers) == 0:\n- basicConfig()\n- apply(root.warn, (msg,)+args, kwargs)\n-\n-def info(msg, *args, **kwargs):\n- \"\"\"\n- Log a message with severity 'INFO' on the root logger.\n- \"\"\"\n- if len(root.handlers) == 0:\n- basicConfig()\n- apply(root.info, (msg,)+args, kwargs)\n-\n-def debug(msg, *args, **kwargs):\n- \"\"\"\n- Log a message with severity 'DEBUG' on the root logger.\n- \"\"\"\n- if len(root.handlers) == 0:\n- basicConfig()\n- apply(root.debug, (msg,)+args, kwargs)\n-\n-def disable(level):\n- \"\"\"\n- Disable all logging calls less severe than 'level'.\n- \"\"\"\n- root.manager.disable = level\n-\n-def shutdown():\n- \"\"\"\n- Perform any cleanup actions in the logging system (e.g. flushing\n- buffers). Should be called at application exit.\n- \"\"\"\n- for h in _handlers.keys():\n- h.flush()\n- h.close()\n-\n-if __name__ == \"__main__\":\n- print __doc__\n", "added_lines": 0, "deleted_lines": 1737, "source_code": null, "source_code_before": "#! /usr/bin/env python\n#\n# Copyright 2001-2002 by Vinay Sajip. All Rights Reserved.\n#\n# Permission to use, copy, modify, and distribute this software and its\n# documentation for any purpose and without fee is hereby granted,\n# provided that the above copyright notice appear in all copies and that\n# both that copyright notice and this permission notice appear in\n# supporting documentation, and that the name of Vinay Sajip\n# not be used in advertising or publicity pertaining to distribution\n# of the software without specific, written prior permission.\n# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING\n# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL\n# VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR\n# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER\n# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT\n# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.\n#\n# For the change history, see README.txt in the distribution.\n#\n# This file is part of the Python logging distribution. See\n# http://www.red-dove.com/python_logging.html\n#\n\n\"\"\"\nLogging module for Python. Based on PEP 282 and comments thereto in\ncomp.lang.python, and influenced by Apache's log4j system.\n\nShould work under Python versions >= 1.5.2, except that source line\ninformation is not available unless 'inspect' is.\n\nCopyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.\n\nTo use, simply 'import logging' and log away!\n\"\"\"\n\nimport sys, os, types, time, string, socket, cPickle, cStringIO\n\ntry:\n import thread\nexcept ImportError:\n thread = None\ntry:\n import inspect\nexcept ImportError:\n inspect = None\n\n__author__ = \"Vinay Sajip \"\n__status__ = \"alpha\"\n__version__ = \"0.4.1\"\n__date__ = \"03 April 2002\"\n\n#---------------------------------------------------------------------------\n# Module data\n#---------------------------------------------------------------------------\n\n#\n#_srcfile is used when walking the stack to check when we've got the first\n# caller stack frame.\n#If run as a script, __file__ is not bound.\n#\nif __name__ == \"__main__\":\n _srcFile = None\nelse:\n _srcfile = os.path.splitext(__file__)\n if _srcfile[1] in [\".pyc\", \".pyo\"]:\n _srcfile = _srcfile[0] + \".py\"\n else:\n _srcfile = __file__\n\n#\n#_start_time is used as the base when calculating the relative time of events\n#\n_start_time = time.time()\n\nDEFAULT_TCP_LOGGING_PORT = 9020\nDEFAULT_UDP_LOGGING_PORT = 9021\nDEFAULT_HTTP_LOGGING_PORT = 9022\nSYSLOG_UDP_PORT = 514\n\n#\n# Default levels and level names, these can be replaced with any positive set\n# of values having corresponding names. There is a pseudo-level, ALL, which\n# is only really there as a lower limit for user-defined levels. Handlers and\n# loggers are initialized with ALL so that they will log all messages, even\n# at user-defined levels.\n#\nCRITICAL = 50\nFATAL = CRITICAL\nERROR = 40\nWARN = 30\nINFO = 20\nDEBUG = 10\nALL = 0\n\n_levelNames = {\n CRITICAL : 'CRITICAL',\n ERROR : 'ERROR',\n WARN : 'WARN',\n INFO : 'INFO',\n DEBUG : 'DEBUG',\n ALL : 'ALL',\n}\n\ndef getLevelName(lvl):\n \"\"\"\n Return the textual representation of logging level 'lvl'. If the level is\n one of the predefined levels (CRITICAL, ERROR, WARN, INFO, DEBUG) then you\n get the corresponding string. If you have associated levels with names\n using addLevelName then the name you have associated with 'lvl' is\n returned. Otherwise, the string \"Level %s\" % lvl is returned.\n \"\"\"\n return _levelNames.get(lvl, (\"Level %s\" % lvl))\n\ndef addLevelName(lvl, levelName):\n \"\"\"\n Associate 'levelName' with 'lvl'. This is used when converting levels\n to text during message formatting.\n \"\"\"\n _levelNames[lvl] = levelName\n\n#---------------------------------------------------------------------------\n# The logging record\n#---------------------------------------------------------------------------\n\nclass LogRecord:\n \"\"\"\n LogRecord instances are created every time something is logged. They\n contain all the information pertinent to the event being logged. The\n main information passed in is in msg and args, which are combined\n using msg % args to create the message field of the record. The record\n also includes information such as when the record was created, the\n source line where the logging call was made, and any exception\n information to be logged.\n \"\"\"\n def __init__(self, name, lvl, pathname, lineno, msg, args, exc_info):\n \"\"\"\n Initialize a logging record with interesting information.\n \"\"\"\n ct = time.time()\n self.name = name\n self.msg = msg\n self.args = args\n self.level = getLevelName(lvl)\n self.lvl = lvl\n self.pathname = pathname\n try:\n self.filename = os.path.basename(pathname)\n except:\n self.filename = pathname\n self.exc_info = exc_info\n self.lineno = lineno\n self.created = ct\n self.msecs = (ct - long(ct)) * 1000\n self.relativeCreated = (self.created - _start_time) * 1000\n if thread:\n self.thread = thread.get_ident()\n else:\n self.thread = None\n\n def __str__(self):\n return ''%(self.name, self.lvl,\n self.pathname, self.lineno, self.msg)\n\n#---------------------------------------------------------------------------\n# Formatter classes and functions\n#---------------------------------------------------------------------------\n\nclass Formatter:\n \"\"\"\n Formatters need to know how a LogRecord is constructed. They are\n responsible for converting a LogRecord to (usually) a string which can\n be interpreted by either a human or an external system. The base Formatter\n allows a formatting string to be specified. If none is supplied, the\n default value of \"%s(message)\\\\n\" is used.\n\n The Formatter can be initialized with a format string which makes use of\n knowledge of the LogRecord attributes - e.g. the default value mentioned\n above makes use of the fact that the user's message and arguments are pre-\n formatted into a LogRecord's message attribute. Currently, the useful\n attributes in a LogRecord are described by:\n\n %(name)s Name of the logger (logging channel)\n %(lvl)s Numeric logging level for the message (DEBUG, INFO,\n WARN, ERROR, CRITICAL)\n %(level)s Text logging level for the message (\"DEBUG\", \"INFO\",\n \"WARN\", \"ERROR\", \"CRITICAL\")\n %(pathname)s Full pathname of the source file where the logging\n call was issued (if available)\n %(filename)s Filename portion of pathname\n %(lineno)d Source line number where the logging call was issued\n (if available)\n %(created)f Time when the LogRecord was created (time.time()\n return value)\n %(asctime)s textual time when the LogRecord was created\n %(msecs)d Millisecond portion of the creation time\n %(relativeCreated)d Time in milliseconds when the LogRecord was created,\n relative to the time the logging module was loaded\n (typically at application startup time)\n %(thread)d Thread ID (if available)\n %(message)s The result of msg % args, computed just as the\n record is emitted\n %(msg)s The raw formatting string provided by the user\n %(args)r The argument tuple which goes with the formatting\n string in the msg attribute\n \"\"\"\n def __init__(self, fmt=None, datefmt=None):\n \"\"\"\n Initialize the formatter either with the specified format string, or a\n default as described above. Allow for specialized date formatting with\n the optional datefmt argument (if omitted, you get the ISO8601 format).\n \"\"\"\n if fmt:\n self._fmt = fmt\n else:\n self._fmt = \"%(message)s\"\n self.datefmt = datefmt\n\n def formatTime(self, record, datefmt=None):\n \"\"\"\n This method should be called from format() by a formatter which\n wants to make use of a formatted time. This method can be overridden\n in formatters to provide for any specific requirement, but the\n basic behaviour is as follows: if datefmt (a string) is specfied,\n it is used with time.strftime to format the creation time of the\n record. Otherwise, the ISO8601 format is used. The resulting\n string is written to the asctime attribute of the record.\n \"\"\"\n ct = record.created\n if datefmt:\n s = time.strftime(datefmt, time.localtime(ct))\n else:\n t = time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime(ct))\n s = \"%s,%03d\" % (t, record.msecs)\n record.asctime = s\n\n def formatException(self, ei):\n \"\"\"\n Format the specified exception information as a string. This\n default implementation just uses traceback.print_exception()\n \"\"\"\n import traceback\n sio = cStringIO.StringIO()\n traceback.print_exception(ei[0], ei[1], ei[2], None, sio)\n s = sio.getvalue()\n sio.close()\n return s\n\n def format(self, record):\n \"\"\"\n The record's attribute dictionary is used as the operand to a\n string formatting operation which yields the returned string.\n Before formatting the dictionary, a couple of preparatory steps\n are carried out. The message attribute of the record is computed\n using msg % args. If the formatting string contains \"(asctime)\",\n formatTime() is called to format the event time. If there is\n exception information, it is formatted using formatException()\n and appended to the message.\n \"\"\"\n record.message = record.msg % record.args\n if string.find(self._fmt,\"(asctime)\") > 0:\n self.formatTime(record, self.datefmt)\n s = self._fmt % record.__dict__\n if record.exc_info:\n if s[-1] != \"\\n\":\n s = s + \"\\n\"\n s = s + self.formatException(record.exc_info)\n return s\n\n#\n# The default formatter to use when no other is specified\n#\n_defaultFormatter = Formatter()\n\nclass BufferingFormatter:\n \"\"\"\n A formatter suitable for formatting a number of records.\n \"\"\"\n def __init__(self, linefmt=None):\n \"\"\"\n Optionally specify a formatter which will be used to format each\n individual record.\n \"\"\"\n if linefmt:\n self.linefmt = linefmt\n else:\n self.linefmt = _defaultFormatter\n\n def formatHeader(self, records):\n \"\"\"\n Return the header string for the specified records.\n \"\"\"\n return \"\"\n\n def formatFooter(self, records):\n \"\"\"\n Return the footer string for the specified records.\n \"\"\"\n return \"\"\n\n def format(self, records):\n \"\"\"\n Format the specified records and return the result as a string.\n \"\"\"\n rv = \"\"\n if len(records) > 0:\n rv = rv + self.formatHeader(records)\n for record in records:\n rv = rv + self.linefmt.format(record)\n rv = rv + self.formatFooter(records)\n return rv\n\n#---------------------------------------------------------------------------\n# Filter classes and functions\n#---------------------------------------------------------------------------\n\nclass Filter:\n \"\"\"\n The base filter class. This class never filters anything, acting as\n a placeholder which defines the Filter interface. Loggers and Handlers\n can optionally use Filter instances to filter records as desired.\n \"\"\"\n def filter(self, record):\n \"\"\"\n Is the specified record to be logged? Returns a boolean value.\n \"\"\"\n return 1\n\nclass Filterer:\n \"\"\"\n A base class for loggers and handlers which allows them to share\n common code.\n \"\"\"\n def __init__(self):\n self.filters = []\n\n def addFilter(self, filter):\n \"\"\"\n Add the specified filter to this handler.\n \"\"\"\n if not (filter in self.filters):\n self.filters.append(filter)\n\n def removeFilter(self, filter):\n \"\"\"\n Remove the specified filter from this handler.\n \"\"\"\n if filter in self.filters:\n self.filters.remove(filter)\n\n def filter(self, record):\n \"\"\"\n Determine if a record is loggable by consulting all the filters. The\n default is to allow the record to be logged; any filter can veto this\n and the record is then dropped. Returns a boolean value.\n \"\"\"\n rv = 1\n for f in self.filters:\n if not f.filter(record):\n rv = 0\n break\n return rv\n\n#---------------------------------------------------------------------------\n# Handler classes and functions\n#---------------------------------------------------------------------------\n\n_handlers = {} #repository of handlers (for flushing when shutdown called)\n\nclass Handler(Filterer):\n \"\"\"\n The base handler class. Acts as a placeholder which defines the Handler\n interface. Handlers can optionally use Formatter instances to format\n records as desired. By default, no formatter is specified; in this case,\n the 'raw' message as determined by record.message is logged.\n \"\"\"\n def __init__(self, level=0):\n \"\"\"\n Initializes the instance - basically setting the formatter to None\n and the filter list to empty.\n \"\"\"\n Filterer.__init__(self)\n self.level = level\n self.formatter = None\n _handlers[self] = 1\n\n def setLevel(self, lvl):\n \"\"\"\n Set the logging level of this handler.\n \"\"\"\n self.level = lvl\n\n def format(self, record):\n \"\"\"\n Do formatting for a record - if a formatter is set, use it.\n Otherwise, use the default formatter for the module.\n \"\"\"\n if self.formatter:\n fmt = self.formatter\n else:\n fmt = _defaultFormatter\n return fmt.format(record)\n\n def emit(self, record):\n \"\"\"\n Do whatever it takes to actually log the specified logging record.\n This version is intended to be implemented by subclasses and so\n raises a NotImplementedError.\n \"\"\"\n raise NotImplementedError, 'emit must be implemented '\\\n 'by Handler subclasses'\n\n def handle(self, record):\n \"\"\"\n Conditionally handle the specified logging record, depending on\n filters which may have been added to the handler.\n \"\"\"\n if self.filter(record):\n self.emit(record)\n\n def setFormatter(self, fmt):\n \"\"\"\n Set the formatter for this handler.\n \"\"\"\n self.formatter = fmt\n\n def flush(self):\n \"\"\"\n Ensure all logging output has been flushed. This version does\n nothing and is intended to be implemented by subclasses.\n \"\"\"\n pass\n\n def close(self):\n \"\"\"\n Tidy up any resources used by the handler. This version does\n nothing and is intended to be implemented by subclasses.\n \"\"\"\n pass\n\n def handleError(self):\n \"\"\"\n This method should be called from handlers when an exception is\n encountered during an emit() call. By default it does nothing,\n which means that exceptions get silently ignored. This is what is\n mostly wanted for a logging system - most users will not care\n about errors in the logging system, they are more interested in\n application errors. You could, however, replace this with a custom\n handler if you wish.\n \"\"\"\n #import traceback\n #ei = sys.exc_info()\n #traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr)\n #del ei\n pass\n\nclass StreamHandler(Handler):\n \"\"\"\n A handler class which writes logging records, appropriately formatted,\n to a stream. Note that this class does not close the stream, as\n sys.stdout or sys.stderr may be used.\n \"\"\"\n def __init__(self, strm=None):\n \"\"\"\n If strm is not specified, sys.stderr is used.\n \"\"\"\n Handler.__init__(self)\n if not strm:\n strm = sys.stderr\n self.stream = strm\n self.formatter = None\n\n def flush(self):\n \"\"\"\n Flushes the stream.\n \"\"\"\n self.stream.flush()\n\n def emit(self, record):\n \"\"\"\n If a formatter is specified, it is used to format the record.\n The record is then written to the stream with a trailing newline\n [N.B. this may be removed depending on feedback]. If exception\n information is present, it is formatted using\n traceback.print_exception and appended to the stream.\n \"\"\"\n try:\n msg = self.format(record)\n self.stream.write(\"%s\\n\" % msg)\n self.flush()\n except:\n self.handleError()\n\nclass FileHandler(StreamHandler):\n \"\"\"\n A handler class which writes formatted logging records to disk files.\n \"\"\"\n def __init__(self, filename, mode=\"a+\"):\n \"\"\"\n Open the specified file and use it as the stream for logging.\n By default, the file grows indefinitely. You can call setRollover()\n to allow the file to rollover at a predetermined size.\n \"\"\"\n StreamHandler.__init__(self, open(filename, mode))\n self.max_size = 0\n self.backup_count = 0\n self.basefilename = filename\n self.backup_index = 0\n self.mode = mode\n\n def setRollover(self, max_size, backup_count):\n \"\"\"\n Set the rollover parameters so that rollover occurs whenever the\n current log file is nearly max_size in length. If backup_count\n is >= 1, the system will successively create new files with the\n same pathname as the base file, but with extensions \".1\", \".2\"\n etc. appended to it. For example, with a backup_count of 5 and a\n base file name of \"app.log\", you would get \"app.log\", \"app.log.1\",\n \"app.log.2\", ... through to \"app.log.5\". When the last file reaches\n its size limit, the logging reverts to \"app.log\" which is truncated\n to zero length. If max_size is zero, rollover never occurs.\n \"\"\"\n self.max_size = max_size\n self.backup_count = backup_count\n if max_size > 0:\n self.mode = \"a+\"\n\n def doRollover(self):\n \"\"\"\n Do a rollover, as described in setRollover().\n \"\"\"\n if self.backup_index >= self.backup_count:\n self.backup_index = 0\n fn = self.basefilename\n else:\n self.backup_index = self.backup_index + 1\n fn = \"%s.%d\" % (self.basefilename, self.backup_index)\n self.stream.close()\n self.stream = open(fn, \"w+\")\n\n def emit(self, record):\n \"\"\"\n Output the record to the file, catering for rollover as described\n in setRollover().\n \"\"\"\n if self.max_size > 0: # are we rolling over?\n msg = \"%s\\n\" % self.format(record)\n if self.stream.tell() + len(msg) >= self.max_size:\n self.doRollover()\n StreamHandler.emit(self, record)\n\n def close(self):\n \"\"\"\n Closes the stream.\n \"\"\"\n self.stream.close()\n\nclass SocketHandler(StreamHandler):\n \"\"\"\n A handler class which writes logging records, in pickle format, to\n a streaming socket. The socket is kept open across logging calls.\n If the peer resets it, an attempt is made to reconnect on the next call.\n \"\"\"\n\n def __init__(self, host, port):\n \"\"\"\n Initializes the handler with a specific host address and port.\n \"\"\"\n StreamHandler.__init__(self)\n self.host = host\n self.port = port\n self.sock = None\n self.closeOnError = 1\n\n def makeSocket(self):\n \"\"\"\n A factory method which allows subclasses to define the precise\n type of socket they want.\n \"\"\"\n s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n s.connect((self.host, self.port))\n return s\n\n def send(self, s):\n \"\"\"\n Send a pickled string to the socket. This function allows for\n partial sends which can happen when the network is busy.\n \"\"\"\n sentsofar = 0\n left = len(s)\n while left > 0:\n sent = self.sock.send(s[sentsofar:])\n sentsofar = sentsofar + sent\n left = left - sent\n\n def makePickle(self, record):\n \"\"\"\n Pickle the record in binary format with a length prefix.\n \"\"\"\n s = cPickle.dumps(record.__dict__, 1)\n n = len(s)\n slen = \"%c%c\" % ((n >> 8) & 0xFF, n & 0xFF)\n return slen + s\n\n def handleError(self):\n \"\"\"\n An error has occurred during logging. Most likely cause -\n connection lost. Close the socket so that we can retry on the\n next event.\n \"\"\"\n if self.closeOnError and self.sock:\n self.sock.close()\n self.sock = None #try to reconnect next time\n\n def emit(self, record):\n \"\"\"\n Pickles the record and writes it to the socket in binary format.\n If there is an error with the socket, silently drop the packet.\n \"\"\"\n try:\n s = self.makePickle(record)\n if not self.sock:\n self.sock = self.makeSocket()\n self.send(s)\n except:\n self.handleError()\n\n def close(self):\n \"\"\"\n Closes the socket.\n \"\"\"\n if self.sock:\n self.sock.close()\n self.sock = None\n\nclass DatagramHandler(SocketHandler):\n \"\"\"\n A handler class which writes logging records, in pickle format, to\n a datagram socket.\n \"\"\"\n def __init__(self, host, port):\n \"\"\"\n Initializes the handler with a specific host address and port.\n \"\"\"\n SocketHandler.__init__(self, host, port)\n self.closeOnError = 0\n\n def makeSocket(self):\n \"\"\"\n The factory method of SocketHandler is here overridden to create\n a UDP socket (SOCK_DGRAM).\n \"\"\"\n s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n return s\n\n def sendto(self, s, addr):\n \"\"\"\n Send a pickled string to a socket. This function allows for\n partial sends which can happen when the network is busy.\n \"\"\"\n sentsofar = 0\n left = len(s)\n while left > 0:\n sent = self.sock.sendto(s[sentsofar:], addr)\n sentsofar = sentsofar + sent\n left = left - sent\n\n def emit(self, record):\n \"\"\"\n Pickles the record and writes it to the socket in binary format.\n \"\"\"\n try:\n s = self.makePickle(record)\n if not self.sock:\n self.sock = self.makeSocket()\n self.sendto(s, (self.host, self.port))\n except:\n self.handleError()\n\nclass SysLogHandler(Handler):\n \"\"\"\n A handler class which sends formatted logging records to a syslog\n server. Based on Sam Rushing's syslog module:\n http://www.nightmare.com/squirl/python-ext/misc/syslog.py\n Contributed by Nicolas Untz (after which minor refactoring changes\n have been made).\n \"\"\"\n\n # from :\n # ======================================================================\n # priorities/facilities are encoded into a single 32-bit quantity, where\n # the bottom 3 bits are the priority (0-7) and the top 28 bits are the\n # facility (0-big number). Both the priorities and the facilities map\n # roughly one-to-one to strings in the syslogd(8) source code. This\n # mapping is included in this file.\n #\n # priorities (these are ordered)\n\n LOG_EMERG = 0 # system is unusable\n LOG_ALERT = 1 # action must be taken immediately\n LOG_CRIT = 2 # critical conditions\n LOG_ERR = 3 # error conditions\n LOG_WARNING = 4 # warning conditions\n LOG_NOTICE = 5 # normal but significant condition\n LOG_INFO = 6 # informational\n LOG_DEBUG = 7 # debug-level messages\n\n # facility codes\n LOG_KERN = 0 # kernel messages\n LOG_USER = 1 # random user-level messages\n LOG_MAIL = 2 # mail system\n LOG_DAEMON = 3 # system daemons\n LOG_AUTH = 4 # security/authorization messages\n LOG_SYSLOG = 5 # messages generated internally by syslogd\n LOG_LPR = 6 # line printer subsystem\n LOG_NEWS = 7 # network news subsystem\n LOG_UUCP = 8 # UUCP subsystem\n LOG_CRON = 9 # clock daemon\n LOG_AUTHPRIV = 10 # security/authorization messages (private)\n\n # other codes through 15 reserved for system use\n LOG_LOCAL0 = 16 # reserved for local use\n LOG_LOCAL1 = 17 # reserved for local use\n LOG_LOCAL2 = 18 # reserved for local use\n LOG_LOCAL3 = 19 # reserved for local use\n LOG_LOCAL4 = 20 # reserved for local use\n LOG_LOCAL5 = 21 # reserved for local use\n LOG_LOCAL6 = 22 # reserved for local use\n LOG_LOCAL7 = 23 # reserved for local use\n\n priority_names = {\n \"alert\": LOG_ALERT,\n \"crit\": LOG_CRIT,\n \"critical\": LOG_CRIT,\n \"debug\": LOG_DEBUG,\n \"emerg\": LOG_EMERG,\n \"err\": LOG_ERR,\n \"error\": LOG_ERR, # DEPRECATED\n \"info\": LOG_INFO,\n \"notice\": LOG_NOTICE,\n \"panic\": LOG_EMERG, # DEPRECATED\n \"warn\": LOG_WARNING, # DEPRECATED\n \"warning\": LOG_WARNING,\n }\n\n facility_names = {\n \"auth\": LOG_AUTH,\n \"authpriv\": LOG_AUTHPRIV,\n \"cron\": LOG_CRON,\n \"daemon\": LOG_DAEMON,\n \"kern\": LOG_KERN,\n \"lpr\": LOG_LPR,\n \"mail\": LOG_MAIL,\n \"news\": LOG_NEWS,\n \"security\": LOG_AUTH, # DEPRECATED\n \"syslog\": LOG_SYSLOG,\n \"user\": LOG_USER,\n \"uucp\": LOG_UUCP,\n \"local0\": LOG_LOCAL0,\n \"local1\": LOG_LOCAL1,\n \"local2\": LOG_LOCAL2,\n \"local3\": LOG_LOCAL3,\n \"local4\": LOG_LOCAL4,\n \"local5\": LOG_LOCAL5,\n \"local6\": LOG_LOCAL6,\n \"local7\": LOG_LOCAL7,\n }\n\n def __init__(self, address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER):\n \"\"\"\n If address is not specified, UNIX socket is used.\n If facility is not specified, LOG_USER is used.\n \"\"\"\n Handler.__init__(self)\n\n self.address = address\n self.facility = facility\n if type(address) == types.StringType:\n self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)\n self.socket.connect(address)\n self.unixsocket = 1\n else:\n self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)\n self.unixsocket = 0\n\n self.formatter = None\n\n # curious: when talking to the unix-domain '/dev/log' socket, a\n # zero-terminator seems to be required. this string is placed\n # into a class variable so that it can be overridden if\n # necessary.\n log_format_string = '<%d>%s\\000'\n\n def encodePriority (self, facility, priority):\n \"\"\"\n Encode the facility and priority. You can pass in strings or\n integers - if strings are passed, the facility_names and\n priority_names mapping dictionaries are used to convert them to\n integers.\n \"\"\"\n if type(facility) == types.StringType:\n facility = self.facility_names[facility]\n if type(priority) == types.StringType:\n priority = self.priority_names[priority]\n return (facility << 3) | priority\n\n def close (self):\n \"\"\"\n Closes the socket.\n \"\"\"\n if self.unixsocket:\n self.socket.close()\n\n def emit(self, record):\n \"\"\"\n The record is formatted, and then sent to the syslog server. If\n exception information is present, it is NOT sent to the server.\n \"\"\"\n msg = self.format(record)\n \"\"\"\n We need to convert record level to lowercase, maybe this will\n change in the future.\n \"\"\"\n msg = self.log_format_string % (\n self.encodePriority(self.facility, string.lower(record.level)),\n msg)\n try:\n if self.unixsocket:\n self.socket.send(msg)\n else:\n self.socket.sendto(msg, self.address)\n except:\n self.handleError()\n\nclass SMTPHandler(Handler):\n \"\"\"\n A handler class which sends an SMTP email for each logging event.\n \"\"\"\n def __init__(self, mailhost, fromaddr, toaddrs, subject):\n \"\"\"\n Initialize the instance with the from and to addresses and subject\n line of the email. To specify a non-standard SMTP port, use the\n (host, port) tuple format for the mailhost argument.\n \"\"\"\n Handler.__init__(self)\n if type(mailhost) == types.TupleType:\n host, port = mailhost\n self.mailhost = host\n self.mailport = port\n else:\n self.mailhost = mailhost\n self.mailport = None\n self.fromaddr = fromaddr\n self.toaddrs = toaddrs\n self.subject = subject\n\n def getSubject(self, record):\n \"\"\"\n If you want to specify a subject line which is record-dependent,\n override this method.\n \"\"\"\n return self.subject\n\n def emit(self, record):\n \"\"\"\n Format the record and send it to the specified addressees.\n \"\"\"\n try:\n import smtplib\n port = self.mailport\n if not port:\n port = smtplib.SMTP_PORT\n smtp = smtplib.SMTP(self.mailhost, port)\n msg = self.format(record)\n msg = \"From: %s\\r\\nTo: %s\\r\\nSubject: %s\\r\\n\\r\\n%s\" % (\n self.fromaddr,\n string.join(self.toaddrs, \",\"),\n self.getSubject(record), msg\n )\n smtp.sendmail(self.fromaddr, self.toaddrs, msg)\n smtp.quit()\n except:\n self.handleError()\n\nclass BufferingHandler(Handler):\n \"\"\"\n A handler class which buffers logging records in memory. Whenever each\n record is added to the buffer, a check is made to see if the buffer should\n be flushed. If it should, then flush() is expected to do the needful.\n \"\"\"\n def __init__(self, capacity):\n \"\"\"\n Initialize the handler with the buffer size.\n \"\"\"\n Handler.__init__(self)\n self.capacity = capacity\n self.buffer = []\n\n def shouldFlush(self, record):\n \"\"\"\n Returns true if the buffer is up to capacity. This method can be\n overridden to implement custom flushing strategies.\n \"\"\"\n return (len(self.buffer) >= self.capacity)\n\n def emit(self, record):\n \"\"\"\n Append the record. If shouldFlush() tells us to, call flush() to process\n the buffer.\n \"\"\"\n self.buffer.append(record)\n if self.shouldFlush(record):\n self.flush()\n\n def flush(self):\n \"\"\"\n Override to implement custom flushing behaviour. This version just zaps\n the buffer to empty.\n \"\"\"\n self.buffer = []\n\nclass MemoryHandler(BufferingHandler):\n \"\"\"\n A handler class which buffers logging records in memory, periodically\n flushing them to a target handler. Flushing occurs whenever the buffer\n is full, or when an event of a certain severity or greater is seen.\n \"\"\"\n def __init__(self, capacity, flushLevel=ERROR, target=None):\n \"\"\"\n Initialize the handler with the buffer size, the level at which\n flushing should occur and an optional target. Note that without a\n target being set either here or via setTarget(), a MemoryHandler\n is no use to anyone!\n \"\"\"\n BufferingHandler.__init__(self, capacity)\n self.flushLevel = flushLevel\n self.target = target\n\n def shouldFlush(self, record):\n \"\"\"\n Check for buffer full or a record at the flushLevel or higher.\n \"\"\"\n return (len(self.buffer) >= self.capacity) or \\\n (record.lvl >= self.flushLevel)\n\n def setTarget(self, target):\n \"\"\"\n Set the target handler for this handler.\n \"\"\"\n self.target = target\n\n def flush(self):\n \"\"\"\n For a MemoryHandler, flushing means just sending the buffered\n records to the target, if there is one. Override if you want\n different behaviour.\n \"\"\"\n if self.target:\n for record in self.buffer:\n self.target.handle(record)\n self.buffer = []\n\nclass NTEventLogHandler(Handler):\n \"\"\"\n A handler class which sends events to the NT Event Log. Adds a\n registry entry for the specified application name. If no dllname is\n provided, win32service.pyd (which contains some basic message\n placeholders) is used. Note that use of these placeholders will make\n your event logs big, as the entire message source is held in the log.\n If you want slimmer logs, you have to pass in the name of your own DLL\n which contains the message definitions you want to use in the event log.\n \"\"\"\n def __init__(self, appname, dllname=None, logtype=\"Application\"):\n Handler.__init__(self)\n try:\n import win32evtlogutil, win32evtlog\n self.appname = appname\n self._welu = win32evtlogutil\n if not dllname:\n import os\n dllname = os.path.split(self._welu.__file__)\n dllname = os.path.split(dllname[0])\n dllname = os.path.join(dllname[0], r'win32service.pyd')\n self.dllname = dllname\n self.logtype = logtype\n self._welu.AddSourceToRegistry(appname, dllname, logtype)\n self.deftype = win32evtlog.EVENTLOG_ERROR_TYPE\n self.typemap = {\n DEBUG : win32evtlog.EVENTLOG_INFORMATION_TYPE,\n INFO : win32evtlog.EVENTLOG_INFORMATION_TYPE,\n WARN : win32evtlog.EVENTLOG_WARNING_TYPE,\n ERROR : win32evtlog.EVENTLOG_ERROR_TYPE,\n CRITICAL: win32evtlog.EVENTLOG_ERROR_TYPE,\n }\n except ImportError:\n print \"The Python Win32 extensions for NT (service, event \"\\\n \"logging) appear not to be available.\"\n self._welu = None\n\n def getMessageID(self, record):\n \"\"\"\n Return the message ID for the event record. If you are using your\n own messages, you could do this by having the msg passed to the\n logger being an ID rather than a formatting string. Then, in here,\n you could use a dictionary lookup to get the message ID. This\n version returns 1, which is the base message ID in win32service.pyd.\n \"\"\"\n return 1\n\n def getEventCategory(self, record):\n \"\"\"\n Return the event category for the record. Override this if you\n want to specify your own categories. This version returns 0.\n \"\"\"\n return 0\n\n def getEventType(self, record):\n \"\"\"\n Return the event type for the record. Override this if you want\n to specify your own types. This version does a mapping using the\n handler's typemap attribute, which is set up in __init__() to a\n dictionary which contains mappings for DEBUG, INFO, WARN, ERROR\n and CRITICAL. If you are using your own levels you will either need\n to override this method or place a suitable dictionary in the\n handler's typemap attribute.\n \"\"\"\n return self.typemap.get(record.lvl, self.deftype)\n\n def emit(self, record):\n \"\"\"\n Determine the message ID, event category and event type. Then\n log the message in the NT event log.\n \"\"\"\n if self._welu:\n try:\n id = self.getMessageID(record)\n cat = self.getEventCategory(record)\n type = self.getEventType(record)\n msg = self.format(record)\n self._welu.ReportEvent(self.appname, id, cat, type, [msg])\n except:\n self.handleError()\n\n def close(self):\n \"\"\"\n You can remove the application name from the registry as a\n source of event log entries. However, if you do this, you will\n not be able to see the events as you intended in the Event Log\n Viewer - it needs to be able to access the registry to get the\n DLL name.\n \"\"\"\n #self._welu.RemoveSourceFromRegistry(self.appname, self.logtype)\n pass\n\nclass HTTPHandler(Handler):\n \"\"\"\n A class which sends records to a Web server, using either GET or\n POST semantics.\n \"\"\"\n def __init__(self, host, url, method=\"GET\"):\n \"\"\"\n Initialize the instance with the host, the request URL, and the method\n (\"GET\" or \"POST\")\n \"\"\"\n Handler.__init__(self)\n method = string.upper(method)\n if method not in [\"GET\", \"POST\"]:\n raise ValueError, \"method must be GET or POST\"\n self.host = host\n self.url = url\n self.method = method\n\n def emit(self, record):\n \"\"\"\n Send the record to the Web server as an URL-encoded dictionary\n \"\"\"\n try:\n import httplib, urllib\n h = httplib.HTTP(self.host)\n url = self.url\n data = urllib.urlencode(record.__dict__)\n if self.method == \"GET\":\n if (string.find(url, '?') >= 0):\n sep = '&'\n else:\n sep = '?'\n url = url + \"%c%s\" % (sep, data)\n h.putrequest(self.method, url)\n if self.method == \"POST\":\n h.putheader(\"Content-length\", str(len(data)))\n h.endheaders()\n if self.method == \"POST\":\n h.send(data)\n h.getreply() #can't do anything with the result\n except:\n self.handleError()\n\nSOAP_MESSAGE = \"\"\"\n \n \n%s\n \n \n\n\"\"\"\n\nclass SOAPHandler(Handler):\n \"\"\"\n A class which sends records to a SOAP server.\n \"\"\"\n def __init__(self, host, url):\n \"\"\"\n Initialize the instance with the host and the request URL\n \"\"\"\n Handler.__init__(self)\n self.host = host\n self.url = url\n\n def emit(self, record):\n \"\"\"\n Send the record to the Web server as a SOAP message\n \"\"\"\n try:\n import httplib, urllib\n h = httplib.HTTP(self.host)\n h.putrequest(\"POST\", self.url)\n keys = record.__dict__.keys()\n keys.sort()\n args = \"\"\n for key in keys:\n v = record.__dict__[key]\n if type(v) == types.StringType:\n t = \"string\"\n elif (type(v) == types.IntType) or (type(v) == types.LongType):\n t = \"integer\"\n elif type(v) == types.FloatType:\n t = \"float\"\n else:\n t = \"string\"\n args = args + \"%12s%s\\n\" % (\"\",\n key, t, str(v), key)\n data = SOAP_MESSAGE % args[:-1]\n #print data\n h.putheader(\"Content-type\", \"text/plain; charset=\\\"utf-8\\\"\")\n h.putheader(\"Content-length\", str(len(data)))\n h.endheaders()\n h.send(data)\n r = h.getreply() #can't do anything with the result\n #print r\n f = h.getfile()\n #print f.read()\n f.close()\n except:\n self.handleError()\n\n#---------------------------------------------------------------------------\n# Manager classes and functions\n#---------------------------------------------------------------------------\n\nclass PlaceHolder:\n \"\"\"\n PlaceHolder instances are used in the Manager logger hierarchy to take\n the place of nodes for which no loggers have been defined [FIXME add\n example].\n \"\"\"\n def __init__(self, alogger):\n \"\"\"\n Initialize with the specified logger being a child of this placeholder.\n \"\"\"\n self.loggers = [alogger]\n\n def append(self, alogger):\n \"\"\"\n Add the specified logger as a child of this placeholder.\n \"\"\"\n if alogger not in self.loggers:\n self.loggers.append(alogger)\n\n#\n# Determine which class to use when instantiating loggers.\n#\n_loggerClass = None\n\ndef setLoggerClass(klass):\n \"\"\"\n Set the class to be used when instantiating a logger. The class should\n define __init__() such that only a name argument is required, and the\n __init__() should call Logger.__init__()\n \"\"\"\n if klass != Logger:\n if type(klass) != types.ClassType:\n raise TypeError, \"setLoggerClass is expecting a class\"\n if not (Logger in klass.__bases__):\n raise TypeError, \"logger not derived from logging.Logger: \" + \\\n klass.__name__\n global _loggerClass\n _loggerClass = klass\n\nclass Manager:\n \"\"\"\n There is [under normal circumstances] just one Manager instance, which\n holds the hierarchy of loggers.\n \"\"\"\n def __init__(self, root):\n \"\"\"\n Initialize the manager with the root node of the logger hierarchy.\n \"\"\"\n self.root = root\n self.disable = 0\n self.emittedNoHandlerWarning = 0\n self.loggerDict = {}\n\n def getLogger(self, name):\n \"\"\"\n Get a logger with the specified name, creating it if it doesn't\n yet exist. If a PlaceHolder existed for the specified name [i.e.\n the logger didn't exist but a child of it did], replace it with\n the created logger and fix up the parent/child references which\n pointed to the placeholder to now point to the logger.\n \"\"\"\n rv = None\n if self.loggerDict.has_key(name):\n rv = self.loggerDict[name]\n if isinstance(rv, PlaceHolder):\n ph = rv\n rv = _loggerClass(name)\n rv.manager = self\n self.loggerDict[name] = rv\n self._fixupChildren(ph, rv)\n self._fixupParents(rv)\n else:\n rv = _loggerClass(name)\n rv.manager = self\n self.loggerDict[name] = rv\n self._fixupParents(rv)\n return rv\n\n def _fixupParents(self, alogger):\n \"\"\"\n Ensure that there are either loggers or placeholders all the way\n from the specified logger to the root of the logger hierarchy.\n \"\"\"\n name = alogger.name\n i = string.rfind(name, \".\")\n rv = None\n while (i > 0) and not rv:\n substr = name[:i]\n if not self.loggerDict.has_key(substr):\n self.loggerDict[name] = PlaceHolder(alogger)\n else:\n obj = self.loggerDict[substr]\n if isinstance(obj, Logger):\n rv = obj\n else:\n assert isinstance(obj, PlaceHolder)\n obj.append(alogger)\n i = string.rfind(name, \".\", 0, i - 1)\n if not rv:\n rv = self.root\n alogger.parent = rv\n\n def _fixupChildren(self, ph, alogger):\n \"\"\"\n Ensure that children of the placeholder ph are connected to the\n specified logger.\n \"\"\"\n for c in ph.loggers:\n if string.find(c.parent.name, alogger.name) <> 0:\n alogger.parent = c.parent\n c.parent = alogger\n\n#---------------------------------------------------------------------------\n# Logger classes and functions\n#---------------------------------------------------------------------------\n\nclass Logger(Filterer):\n \"\"\"\n Instances of the Logger class represent a single logging channel.\n \"\"\"\n def __init__(self, name, level=0):\n \"\"\"\n Initialize the logger with a name and an optional level.\n \"\"\"\n Filterer.__init__(self)\n self.name = name\n self.level = level\n self.parent = None\n self.propagate = 1\n self.handlers = []\n\n def setLevel(self, lvl):\n \"\"\"\n Set the logging level of this logger.\n \"\"\"\n self.level = lvl\n\n# def getRoot(self):\n# \"\"\"\n# Get the root of the logger hierarchy.\n# \"\"\"\n# return Logger.root\n\n def debug(self, msg, *args, **kwargs):\n \"\"\"\n Log 'msg % args' with severity 'DEBUG'. To pass exception information,\n use the keyword argument exc_info with a true value, e.g.\n\n logger.debug(\"Houston, we have a %s\", \"thorny problem\", exc_info=1)\n \"\"\"\n if self.manager.disable >= DEBUG:\n return\n if DEBUG >= self.getEffectiveLevel():\n apply(self._log, (DEBUG, msg, args), kwargs)\n\n def info(self, msg, *args, **kwargs):\n \"\"\"\n Log 'msg % args' with severity 'INFO'. To pass exception information,\n use the keyword argument exc_info with a true value, e.g.\n\n logger.info(\"Houston, we have a %s\", \"interesting problem\", exc_info=1)\n \"\"\"\n if self.manager.disable >= INFO:\n return\n if INFO >= self.getEffectiveLevel():\n apply(self._log, (INFO, msg, args), kwargs)\n\n def warn(self, msg, *args, **kwargs):\n \"\"\"\n Log 'msg % args' with severity 'WARN'. To pass exception information,\n use the keyword argument exc_info with a true value, e.g.\n\n logger.warn(\"Houston, we have a %s\", \"bit of a problem\", exc_info=1)\n \"\"\"\n if self.manager.disable >= WARN:\n return\n if self.isEnabledFor(WARN):\n apply(self._log, (WARN, msg, args), kwargs)\n\n def error(self, msg, *args, **kwargs):\n \"\"\"\n Log 'msg % args' with severity 'ERROR'. To pass exception information,\n use the keyword argument exc_info with a true value, e.g.\n\n logger.error(\"Houston, we have a %s\", \"major problem\", exc_info=1)\n \"\"\"\n if self.manager.disable >= ERROR:\n return\n if self.isEnabledFor(ERROR):\n apply(self._log, (ERROR, msg, args), kwargs)\n\n def exception(self, msg, *args):\n \"\"\"\n Convenience method for logging an ERROR with exception information\n \"\"\"\n apply(self.error, (msg,) + args, {'exc_info': 1})\n\n def critical(self, msg, *args, **kwargs):\n \"\"\"\n Log 'msg % args' with severity 'CRITICAL'. To pass exception\n information, use the keyword argument exc_info with a true value, e.g.\n\n logger.critical(\"Houston, we have a %s\", \"major disaster\", exc_info=1)\n \"\"\"\n if self.manager.disable >= CRITICAL:\n return\n if CRITICAL >= self.getEffectiveLevel():\n apply(self._log, (CRITICAL, msg, args), kwargs)\n\n fatal = critical\n\n def log(self, lvl, msg, *args, **kwargs):\n \"\"\"\n Log 'msg % args' with the severity 'lvl'. To pass exception\n information, use the keyword argument exc_info with a true value, e.g.\n logger.log(lvl, \"We have a %s\", \"mysterious problem\", exc_info=1)\n \"\"\"\n if self.manager.disable >= lvl:\n return\n if self.isEnabledFor(lvl):\n apply(self._log, (lvl, msg, args), kwargs)\n\n def findCaller(self):\n \"\"\"\n Find the stack frame of the caller so that we can note the source\n file name and line number.\n \"\"\"\n frames = inspect.stack()[1:]\n for f in frames:\n if _srcfile != f[1]:\n return (f[1], f[2])\n return (None, None)\n\n def makeRecord(self, name, lvl, fn, lno, msg, args, exc_info):\n \"\"\"\n A factory method which can be overridden in subclasses to create\n specialized LogRecords.\n \"\"\"\n return LogRecord(name, lvl, fn, lno, msg, args, exc_info)\n\n def _log(self, lvl, msg, args, exc_info=None):\n \"\"\"\n Low-level logging routine which creates a LogRecord and then calls\n all the handlers of this logger to handle the record.\n \"\"\"\n if inspect:\n fn, lno = self.findCaller()\n else:\n fn, lno = \"\", 0\n if exc_info:\n exc_info = sys.exc_info()\n record = self.makeRecord(self.name, lvl, fn, lno, msg, args, exc_info)\n self.handle(record)\n\n def handle(self, record):\n \"\"\"\n Call the handlers for the specified record. This method is used for\n unpickled records received from a socket, as well as those created\n locally. Logger-level filtering is applied.\n \"\"\"\n if self.filter(record):\n self.callHandlers(record)\n\n def addHandler(self, hdlr):\n \"\"\"\n Add the specified handler to this logger.\n \"\"\"\n if not (hdlr in self.handlers):\n self.handlers.append(hdlr)\n\n def removeHandler(self, hdlr):\n \"\"\"\n Remove the specified handler from this logger.\n \"\"\"\n if hdlr in self.handlers:\n self.handlers.remove(hdlr)\n\n def callHandlers(self, record):\n \"\"\"\n Loop through all handlers for this logger and its parents in the\n logger hierarchy. If no handler was found, output a one-off error\n message. Stop searching up the hierarchy whenever a logger with the\n \"propagate\" attribute set to zero is found - that will be the last\n logger whose handlers are called.\n \"\"\"\n c = self\n found = 0\n while c:\n for hdlr in c.handlers:\n found = found + 1\n if record.lvl >= hdlr.level:\n hdlr.handle(record)\n if not c.propagate:\n c = None #break out\n else:\n c = c.parent\n if (found == 0) and not self.manager.emittedNoHandlerWarning:\n print \"No handlers could be found for logger \\\"%s\\\"\" % self.name\n self.manager.emittedNoHandlerWarning = 1\n\n def getEffectiveLevel(self):\n \"\"\"\n Loop through this logger and its parents in the logger hierarchy,\n looking for a non-zero logging level. Return the first one found.\n \"\"\"\n c = self\n while c:\n if c.level:\n return c.level\n c = c.parent\n #print \"NCP\", self.parent\n\n def isEnabledFor(self, lvl):\n \"\"\"\n Is this logger enabled for level lvl?\n \"\"\"\n if self.manager.disable >= lvl:\n return 0\n return lvl >= self.getEffectiveLevel()\n\nclass RootLogger(Logger):\n \"\"\"\n A root logger is not that different to any other logger, except that\n it must have a logging level and there is only one instance of it in\n the hierarchy.\n \"\"\"\n def __init__(self, lvl):\n \"\"\"\n Initialize the logger with the name \"root\".\n \"\"\"\n Logger.__init__(self, \"root\", lvl)\n\n_loggerClass = Logger\n\nroot = RootLogger(DEBUG)\nLogger.root = root\nLogger.manager = Manager(Logger.root)\n\n#---------------------------------------------------------------------------\n# Configuration classes and functions\n#---------------------------------------------------------------------------\n\nBASIC_FORMAT = \"%(asctime)s %(name)-19s %(level)-5s - %(message)s\"\n\ndef basicConfig():\n \"\"\"\n Do basic configuration for the logging system by creating a\n StreamHandler with a default Formatter and adding it to the\n root logger.\n \"\"\"\n hdlr = StreamHandler()\n fmt = Formatter(BASIC_FORMAT)\n hdlr.setFormatter(fmt)\n root.addHandler(hdlr)\n\n#def fileConfig(fname):\n# \"\"\"\n# The old implementation - using dict-based configuration files.\n# Read the logging configuration from a file. Keep it simple for now.\n# \"\"\"\n# file = open(fname, \"r\")\n# data = file.read()\n# file.close()\n# dict = eval(data)\n# handlers = dict.get(\"handlers\", [])\n# loggers = dict.get(\"loggers\", [])\n# formatters = dict.get(\"formatters\", [])\n# for f in formatters:\n# fd = dict[f]\n# fc = fd.get(\"class\", \"logging.Formatter\")\n# args = fd.get(\"args\", ())\n# fc = eval(fc)\n# try:\n# fmt = apply(fc, args)\n# except:\n# print fc, args\n# raise\n# dict[f] = fmt\n#\n# for h in handlers:\n# hd = dict[h]\n# hc = hd.get(\"class\", \"logging.StreamHandler\")\n# args = hd.get(\"args\", ())\n# hc = eval(hc)\n# fmt = hd.get(\"formatter\", None)\n# if fmt:\n# fmt = dict.get(fmt, None)\n# try:\n# hdlr = apply(hc, args)\n# except:\n# print hc, args\n# raise\n# if fmt:\n# hdlr.setFormatter(fmt)\n# dict[h] = hdlr\n#\n# for ln in loggers:\n# ld = dict[ln]\n# name = ld.get(\"name\", None)\n# if name:\n# logger = getLogger(name)\n# else:\n# logger = getRootLogger()\n# logger.propagate = ld.get(\"propagate\", 1)\n# hdlrs = ld.get(\"handlers\", [])\n# for h in hdlrs:\n# hdlr = dict.get(h, None)\n# if hdlr:\n# logger.addHandler(hdlr)\n\ndef fileConfig(fname):\n \"\"\"\n Read the logging configuration from a ConfigParser-format file.\n \"\"\"\n import ConfigParser\n\n cp = ConfigParser.ConfigParser()\n cp.read(fname)\n #first, do the formatters...\n flist = cp.get(\"formatters\", \"keys\")\n flist = string.split(flist, \",\")\n formatters = {}\n for form in flist:\n sectname = \"formatter_%s\" % form\n fs = cp.get(sectname, \"format\", 1)\n dfs = cp.get(sectname, \"datefmt\", 1)\n f = Formatter(fs, dfs)\n formatters[form] = f\n #next, do the handlers...\n hlist = cp.get(\"handlers\", \"keys\")\n hlist = string.split(hlist, \",\")\n handlers = {}\n for hand in hlist:\n sectname = \"handler_%s\" % hand\n klass = cp.get(sectname, \"class\")\n fmt = cp.get(sectname, \"formatter\")\n lvl = cp.get(sectname, \"level\")\n klass = eval(klass)\n args = cp.get(sectname, \"args\")\n args = eval(args)\n h = apply(klass, args)\n h.setLevel(eval(lvl))\n h.setFormatter(formatters[fmt])\n #temporary hack for FileHandler.\n if klass == FileHandler:\n maxsize = cp.get(sectname, \"maxsize\")\n if maxsize:\n maxsize = eval(maxsize)\n else:\n maxsize = 0\n if maxsize:\n backcount = cp.get(sectname, \"backcount\")\n if backcount:\n backcount = eval(backcount)\n else:\n backcount = 0\n h.setRollover(maxsize, backcount)\n handlers[hand] = h\n #at last, the loggers...first the root...\n llist = cp.get(\"loggers\", \"keys\")\n llist = string.split(llist, \",\")\n llist.remove(\"root\")\n sectname = \"logger_root\"\n log = root\n lvl = cp.get(sectname, \"level\")\n log.setLevel(eval(lvl))\n hlist = cp.get(sectname, \"handlers\")\n hlist = string.split(hlist, \",\")\n for hand in hlist:\n log.addHandler(handlers[hand])\n #and now the others...\n for log in llist:\n sectname = \"logger_%s\" % log\n qn = cp.get(sectname, \"qualname\")\n lvl = cp.get(sectname, \"level\")\n propagate = cp.get(sectname, \"propagate\")\n logger = getLogger(qn)\n logger.setLevel(eval(lvl))\n logger.propagate = eval(propagate)\n hlist = cp.get(sectname, \"handlers\")\n hlist = string.split(hlist, \",\")\n for hand in hlist:\n logger.addHandler(handlers[hand])\n\n\n#---------------------------------------------------------------------------\n# Utility functions at module level.\n# Basically delegate everything to the root logger.\n#---------------------------------------------------------------------------\n\ndef getLogger(name):\n \"\"\"\n Return a logger with the specified name, creating it if necessary.\n If no name is specified, return the root logger.\n \"\"\"\n if name:\n return Logger.manager.getLogger(name)\n else:\n return root\n\ndef getRootLogger():\n \"\"\"\n Return the root logger.\n \"\"\"\n return root\n\ndef critical(msg, *args, **kwargs):\n \"\"\"\n Log a message with severity 'CRITICAL' on the root logger.\n \"\"\"\n if len(root.handlers) == 0:\n basicConfig()\n apply(root.critical, (msg,)+args, kwargs)\n\nfatal = critical\n\ndef error(msg, *args, **kwargs):\n \"\"\"\n Log a message with severity 'ERROR' on the root logger.\n \"\"\"\n if len(root.handlers) == 0:\n basicConfig()\n apply(root.error, (msg,)+args, kwargs)\n\ndef exception(msg, *args):\n \"\"\"\n Log a message with severity 'ERROR' on the root logger,\n with exception information.\n \"\"\"\n apply(error, (msg,)+args, {'exc_info': 1})\n\ndef warn(msg, *args, **kwargs):\n \"\"\"\n Log a message with severity 'WARN' on the root logger.\n \"\"\"\n if len(root.handlers) == 0:\n basicConfig()\n apply(root.warn, (msg,)+args, kwargs)\n\ndef info(msg, *args, **kwargs):\n \"\"\"\n Log a message with severity 'INFO' on the root logger.\n \"\"\"\n if len(root.handlers) == 0:\n basicConfig()\n apply(root.info, (msg,)+args, kwargs)\n\ndef debug(msg, *args, **kwargs):\n \"\"\"\n Log a message with severity 'DEBUG' on the root logger.\n \"\"\"\n if len(root.handlers) == 0:\n basicConfig()\n apply(root.debug, (msg,)+args, kwargs)\n\ndef disable(level):\n \"\"\"\n Disable all logging calls less severe than 'level'.\n \"\"\"\n root.manager.disable = level\n\ndef shutdown():\n \"\"\"\n Perform any cleanup actions in the logging system (e.g. flushing\n buffers). Should be called at application exit.\n \"\"\"\n for h in _handlers.keys():\n h.flush()\n h.close()\n\nif __name__ == \"__main__\":\n print __doc__\n", "methods": [], "methods_before": [ { "name": "getLevelName", "long_name": "getLevelName( lvl )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "lvl" ], "start_line": 105, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "addLevelName", "long_name": "addLevelName( lvl , levelName )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "lvl", "levelName" ], "start_line": 115, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , lvl , pathname , lineno , msg , args , exc_info )", "filename": "logging.py", "nloc": 21, "complexity": 3, "token_count": 142, "parameters": [ "self", "name", "lvl", "pathname", "lineno", "msg", "args", "exc_info" ], "start_line": 136, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "logging.py", "nloc": 3, "complexity": 1, "token_count": 29, "parameters": [ "self" ], "start_line": 161, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fmt = None , datefmt = None )", "filename": "logging.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "fmt", "datefmt" ], "start_line": 207, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "formatTime", "long_name": "formatTime( self , record , datefmt = None )", "filename": "logging.py", "nloc": 8, "complexity": 2, "token_count": 68, "parameters": [ "self", "record", "datefmt" ], "start_line": 219, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "formatException", "long_name": "formatException( self , ei )", "filename": "logging.py", "nloc": 7, "complexity": 1, "token_count": 54, "parameters": [ "self", "ei" ], "start_line": 237, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "format", "long_name": "format( self , record )", "filename": "logging.py", "nloc": 10, "complexity": 4, "token_count": 85, "parameters": [ "self", "record" ], "start_line": 249, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , linefmt = None )", "filename": "logging.py", "nloc": 5, "complexity": 2, "token_count": 25, "parameters": [ "self", "linefmt" ], "start_line": 279, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "formatHeader", "long_name": "formatHeader( self , records )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "records" ], "start_line": 289, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "formatFooter", "long_name": "formatFooter( self , records )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "records" ], "start_line": 295, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "format", "long_name": "format( self , records )", "filename": "logging.py", "nloc": 8, "complexity": 3, "token_count": 58, "parameters": [ "self", "records" ], "start_line": 301, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "record" ], "start_line": 323, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 334, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "addFilter", "long_name": "addFilter( self , filter )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 26, "parameters": [ "self", "filter" ], "start_line": 337, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "removeFilter", "long_name": "removeFilter( self , filter )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 23, "parameters": [ "self", "filter" ], "start_line": 344, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self , record )", "filename": "logging.py", "nloc": 7, "complexity": 3, "token_count": 33, "parameters": [ "self", "record" ], "start_line": 351, "end_line": 362, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , level = 0 )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "self", "level" ], "start_line": 377, "end_line": 385, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "setLevel", "long_name": "setLevel( self , lvl )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "lvl" ], "start_line": 387, "end_line": 391, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "format", "long_name": "format( self , record )", "filename": "logging.py", "nloc": 6, "complexity": 2, "token_count": 30, "parameters": [ "self", "record" ], "start_line": 393, "end_line": 402, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self", "record" ], "start_line": 404, "end_line": 411, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "handle", "long_name": "handle( self , record )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 22, "parameters": [ "self", "record" ], "start_line": 413, "end_line": 419, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "setFormatter", "long_name": "setFormatter( self , fmt )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "fmt" ], "start_line": 421, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "flush", "long_name": "flush( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 427, "end_line": 432, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "close", "long_name": "close( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 434, "end_line": 439, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "handleError", "long_name": "handleError( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 441, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , strm = None )", "filename": "logging.py", "nloc": 6, "complexity": 2, "token_count": 35, "parameters": [ "self", "strm" ], "start_line": 463, "end_line": 471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "flush", "long_name": "flush( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 473, "end_line": 477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 7, "complexity": 2, "token_count": 40, "parameters": [ "self", "record" ], "start_line": 479, "end_line": 492, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , filename , mode = \"a+\" )", "filename": "logging.py", "nloc": 7, "complexity": 1, "token_count": 50, "parameters": [ "self", "filename", "mode" ], "start_line": 498, "end_line": 509, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "setRollover", "long_name": "setRollover( self , max_size , backup_count )", "filename": "logging.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "self", "max_size", "backup_count" ], "start_line": 511, "end_line": 526, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "doRollover", "long_name": "doRollover( self )", "filename": "logging.py", "nloc": 9, "complexity": 2, "token_count": 66, "parameters": [ "self" ], "start_line": 528, "end_line": 539, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 6, "complexity": 3, "token_count": 56, "parameters": [ "self", "record" ], "start_line": 541, "end_line": 550, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "close", "long_name": "close( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 552, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , host , port )", "filename": "logging.py", "nloc": 6, "complexity": 1, "token_count": 36, "parameters": [ "self", "host", "port" ], "start_line": 565, "end_line": 573, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "makeSocket", "long_name": "makeSocket( self )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 575, "end_line": 582, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "send", "long_name": "send( self , s )", "filename": "logging.py", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "s" ], "start_line": 584, "end_line": 594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "makePickle", "long_name": "makePickle( self , record )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 48, "parameters": [ "self", "record" ], "start_line": 596, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "handleError", "long_name": "handleError( self )", "filename": "logging.py", "nloc": 4, "complexity": 3, "token_count": 27, "parameters": [ "self" ], "start_line": 605, "end_line": 613, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 8, "complexity": 3, "token_count": 46, "parameters": [ "self", "record" ], "start_line": 615, "end_line": 626, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "close", "long_name": "close( self )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 23, "parameters": [ "self" ], "start_line": 628, "end_line": 634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , host , port )", "filename": "logging.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "host", "port" ], "start_line": 641, "end_line": 646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "makeSocket", "long_name": "makeSocket( self )", "filename": "logging.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 648, "end_line": 654, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "sendto", "long_name": "sendto( self , s , addr )", "filename": "logging.py", "nloc": 7, "complexity": 2, "token_count": 50, "parameters": [ "self", "s", "addr" ], "start_line": 656, "end_line": 666, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 8, "complexity": 3, "token_count": 56, "parameters": [ "self", "record" ], "start_line": 668, "end_line": 678, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , address = ( 'localhost' , SYSLOG_UDP_PORT )", "filename": "logging.py", "nloc": 16, "complexity": 2, "token_count": 101, "parameters": [ "self", "address", "SYSLOG_UDP_PORT" ], "start_line": 769, "end_line": 786, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "encodePriority", "long_name": "encodePriority( self , facility , priority )", "filename": "logging.py", "nloc": 6, "complexity": 3, "token_count": 55, "parameters": [ "self", "facility", "priority" ], "start_line": 794, "end_line": 805, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "close", "long_name": "close( self )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 18, "parameters": [ "self" ], "start_line": 807, "end_line": 812, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 16, "complexity": 3, "token_count": 80, "parameters": [ "self", "record" ], "start_line": 814, "end_line": 833, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , mailhost , fromaddr , toaddrs , subject )", "filename": "logging.py", "nloc": 12, "complexity": 2, "token_count": 72, "parameters": [ "self", "mailhost", "fromaddr", "toaddrs", "subject" ], "start_line": 839, "end_line": 855, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "getSubject", "long_name": "getSubject( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "record" ], "start_line": 857, "end_line": 862, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 17, "complexity": 3, "token_count": 101, "parameters": [ "self", "record" ], "start_line": 864, "end_line": 883, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , capacity )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self", "capacity" ], "start_line": 891, "end_line": 897, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "shouldFlush", "long_name": "shouldFlush( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "self", "record" ], "start_line": 899, "end_line": 904, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 29, "parameters": [ "self", "record" ], "start_line": 906, "end_line": 913, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "flush", "long_name": "flush( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 915, "end_line": 920, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , capacity , flushLevel = ERROR , target = None )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "self", "capacity", "flushLevel", "target" ], "start_line": 928, "end_line": 937, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "shouldFlush", "long_name": "shouldFlush( self , record )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 32, "parameters": [ "self", "record" ], "start_line": 939, "end_line": 944, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "setTarget", "long_name": "setTarget( self , target )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "target" ], "start_line": 946, "end_line": 950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "flush", "long_name": "flush( self )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 32, "parameters": [ "self" ], "start_line": 952, "end_line": 961, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , appname , dllname = None , logtype = \"Application\" )", "filename": "logging.py", "nloc": 26, "complexity": 3, "token_count": 163, "parameters": [ "self", "appname", "dllname", "logtype" ], "start_line": 973, "end_line": 998, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "getMessageID", "long_name": "getMessageID( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "record" ], "start_line": 1000, "end_line": 1008, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "getEventCategory", "long_name": "getEventCategory( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "record" ], "start_line": 1010, "end_line": 1015, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "getEventType", "long_name": "getEventType( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "record" ], "start_line": 1017, "end_line": 1027, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "self", "record" ], "start_line": 1029, "end_line": 1042, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "close", "long_name": "close( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 1044, "end_line": 1053, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , host , url , method = \"GET\" )", "filename": "logging.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [ "self", "host", "url", "method" ], "start_line": 1060, "end_line": 1071, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 21, "complexity": 6, "token_count": 140, "parameters": [ "self", "record" ], "start_line": 1073, "end_line": 1096, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , host , url )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "host", "url" ], "start_line": 1117, "end_line": 1123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 30, "complexity": 7, "token_count": 210, "parameters": [ "self", "record" ], "start_line": 1125, "end_line": 1160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , alogger )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "alogger" ], "start_line": 1172, "end_line": 1176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "append", "long_name": "append( self , alogger )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 24, "parameters": [ "self", "alogger" ], "start_line": 1178, "end_line": 1183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "setLoggerClass", "long_name": "setLoggerClass( klass )", "filename": "logging.py", "nloc": 9, "complexity": 4, "token_count": 49, "parameters": [ "klass" ], "start_line": 1190, "end_line": 1203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , root )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 29, "parameters": [ "self", "root" ], "start_line": 1210, "end_line": 1217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "getLogger", "long_name": "getLogger( self , name )", "filename": "logging.py", "nloc": 17, "complexity": 3, "token_count": 102, "parameters": [ "self", "name" ], "start_line": 1219, "end_line": 1242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "_fixupParents", "long_name": "_fixupParents( self , alogger )", "filename": "logging.py", "nloc": 19, "complexity": 6, "token_count": 131, "parameters": [ "self", "alogger" ], "start_line": 1244, "end_line": 1266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "_fixupChildren", "long_name": "_fixupChildren( self , ph , alogger )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 48, "parameters": [ "self", "ph", "alogger" ], "start_line": 1268, "end_line": 1276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , level = 0 )", "filename": "logging.py", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [ "self", "name", "level" ], "start_line": 1286, "end_line": 1295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "setLevel", "long_name": "setLevel( self , lvl )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "lvl" ], "start_line": 1297, "end_line": 1301, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "debug", "long_name": "debug( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 49, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1309, "end_line": 1319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "info", "long_name": "info( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 49, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1321, "end_line": 1331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "warn", "long_name": "warn( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 48, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1333, "end_line": 1343, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "error", "long_name": "error( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 48, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1345, "end_line": 1355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "exception", "long_name": "exception( self , msg , * args )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 30, "parameters": [ "self", "msg", "args" ], "start_line": 1357, "end_line": 1361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "critical", "long_name": "critical( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 49, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1363, "end_line": 1373, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "log", "long_name": "log( self , lvl , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 50, "parameters": [ "self", "lvl", "msg", "args", "kwargs" ], "start_line": 1377, "end_line": 1386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "findCaller", "long_name": "findCaller( self )", "filename": "logging.py", "nloc": 6, "complexity": 3, "token_count": 48, "parameters": [ "self" ], "start_line": 1388, "end_line": 1397, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "makeRecord", "long_name": "makeRecord( self , name , lvl , fn , lno , msg , args , exc_info )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 37, "parameters": [ "self", "name", "lvl", "fn", "lno", "msg", "args", "exc_info" ], "start_line": 1399, "end_line": 1404, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "_log", "long_name": "_log( self , lvl , msg , args , exc_info = None )", "filename": "logging.py", "nloc": 9, "complexity": 3, "token_count": 75, "parameters": [ "self", "lvl", "msg", "args", "exc_info" ], "start_line": 1406, "end_line": 1418, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "handle", "long_name": "handle( self , record )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 22, "parameters": [ "self", "record" ], "start_line": 1420, "end_line": 1427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "addHandler", "long_name": "addHandler( self , hdlr )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 26, "parameters": [ "self", "hdlr" ], "start_line": 1429, "end_line": 1434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "removeHandler", "long_name": "removeHandler( self , hdlr )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 23, "parameters": [ "self", "hdlr" ], "start_line": 1436, "end_line": 1441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "callHandlers", "long_name": "callHandlers( self , record )", "filename": "logging.py", "nloc": 15, "complexity": 7, "token_count": 87, "parameters": [ "self", "record" ], "start_line": 1443, "end_line": 1464, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "getEffectiveLevel", "long_name": "getEffectiveLevel( self )", "filename": "logging.py", "nloc": 6, "complexity": 3, "token_count": 26, "parameters": [ "self" ], "start_line": 1466, "end_line": 1475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "isEnabledFor", "long_name": "isEnabledFor( self , lvl )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 27, "parameters": [ "self", "lvl" ], "start_line": 1478, "end_line": 1484, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , lvl )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "lvl" ], "start_line": 1492, "end_line": 1496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "basicConfig", "long_name": "basicConfig( )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [], "start_line": 1510, "end_line": 1519, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "fileConfig", "long_name": "fileConfig( fname )", "filename": "logging.py", "nloc": 64, "complexity": 10, "token_count": 457, "parameters": [ "fname" ], "start_line": 1576, "end_line": 1648, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "getLogger", "long_name": "getLogger( name )", "filename": "logging.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "name" ], "start_line": 1656, "end_line": 1664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "getRootLogger", "long_name": "getRootLogger( )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [], "start_line": 1666, "end_line": 1670, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "critical", "long_name": "critical( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1672, "end_line": 1678, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "error", "long_name": "error( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1682, "end_line": 1688, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "exception", "long_name": "exception( msg , * args )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "msg", "args" ], "start_line": 1690, "end_line": 1695, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "warn", "long_name": "warn( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1697, "end_line": 1703, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "info", "long_name": "info( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1705, "end_line": 1711, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "debug", "long_name": "debug( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1713, "end_line": 1719, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "disable", "long_name": "disable( level )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "level" ], "start_line": 1721, "end_line": 1725, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "shutdown", "long_name": "shutdown( )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 24, "parameters": [], "start_line": 1727, "end_line": 1734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "flush", "long_name": "flush( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 427, "end_line": 432, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "getEffectiveLevel", "long_name": "getEffectiveLevel( self )", "filename": "logging.py", "nloc": 6, "complexity": 3, "token_count": 26, "parameters": [ "self" ], "start_line": 1466, "end_line": 1475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "close", "long_name": "close( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 434, "end_line": 439, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "handle", "long_name": "handle( self , record )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 22, "parameters": [ "self", "record" ], "start_line": 413, "end_line": 419, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , address = ( 'localhost' , SYSLOG_UDP_PORT )", "filename": "logging.py", "nloc": 16, "complexity": 2, "token_count": 101, "parameters": [ "self", "address", "SYSLOG_UDP_PORT" ], "start_line": 769, "end_line": 786, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "error", "long_name": "error( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1682, "end_line": 1688, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "formatFooter", "long_name": "formatFooter( self , records )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "records" ], "start_line": 295, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "addFilter", "long_name": "addFilter( self , filter )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 26, "parameters": [ "self", "filter" ], "start_line": 337, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "error", "long_name": "error( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 48, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1345, "end_line": 1355, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "findCaller", "long_name": "findCaller( self )", "filename": "logging.py", "nloc": 6, "complexity": 3, "token_count": 48, "parameters": [ "self" ], "start_line": 1388, "end_line": 1397, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , host , port )", "filename": "logging.py", "nloc": 6, "complexity": 1, "token_count": 36, "parameters": [ "self", "host", "port" ], "start_line": 565, "end_line": 573, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "setTarget", "long_name": "setTarget( self , target )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "target" ], "start_line": 946, "end_line": 950, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "encodePriority", "long_name": "encodePriority( self , facility , priority )", "filename": "logging.py", "nloc": 6, "complexity": 3, "token_count": 55, "parameters": [ "self", "facility", "priority" ], "start_line": 794, "end_line": 805, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "setRollover", "long_name": "setRollover( self , max_size , backup_count )", "filename": "logging.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "self", "max_size", "backup_count" ], "start_line": 511, "end_line": 526, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "setLoggerClass", "long_name": "setLoggerClass( klass )", "filename": "logging.py", "nloc": 9, "complexity": 4, "token_count": 49, "parameters": [ "klass" ], "start_line": 1190, "end_line": 1203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , linefmt = None )", "filename": "logging.py", "nloc": 5, "complexity": 2, "token_count": 25, "parameters": [ "self", "linefmt" ], "start_line": 279, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , filename , mode = \"a+\" )", "filename": "logging.py", "nloc": 7, "complexity": 1, "token_count": 50, "parameters": [ "self", "filename", "mode" ], "start_line": 498, "end_line": 509, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , capacity , flushLevel = ERROR , target = None )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "self", "capacity", "flushLevel", "target" ], "start_line": 928, "end_line": 937, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "doRollover", "long_name": "doRollover( self )", "filename": "logging.py", "nloc": 9, "complexity": 2, "token_count": 66, "parameters": [ "self" ], "start_line": 528, "end_line": 539, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "_fixupChildren", "long_name": "_fixupChildren( self , ph , alogger )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 48, "parameters": [ "self", "ph", "alogger" ], "start_line": 1268, "end_line": 1276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "makeRecord", "long_name": "makeRecord( self , name , lvl , fn , lno , msg , args , exc_info )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 37, "parameters": [ "self", "name", "lvl", "fn", "lno", "msg", "args", "exc_info" ], "start_line": 1399, "end_line": 1404, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "handleError", "long_name": "handleError( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [ "self" ], "start_line": 441, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "shutdown", "long_name": "shutdown( )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 24, "parameters": [], "start_line": 1727, "end_line": 1734, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , strm = None )", "filename": "logging.py", "nloc": 6, "complexity": 2, "token_count": 35, "parameters": [ "self", "strm" ], "start_line": 463, "end_line": 471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "setLevel", "long_name": "setLevel( self , lvl )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "lvl" ], "start_line": 387, "end_line": 391, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , level = 0 )", "filename": "logging.py", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [ "self", "name", "level" ], "start_line": 1286, "end_line": 1295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "disable", "long_name": "disable( level )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "level" ], "start_line": 1721, "end_line": 1725, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "makePickle", "long_name": "makePickle( self , record )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 48, "parameters": [ "self", "record" ], "start_line": 596, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , appname , dllname = None , logtype = \"Application\" )", "filename": "logging.py", "nloc": 26, "complexity": 3, "token_count": 163, "parameters": [ "self", "appname", "dllname", "logtype" ], "start_line": 973, "end_line": 998, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , record )", "filename": "logging.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self", "record" ], "start_line": 404, "end_line": 411, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "exception", "long_name": "exception( self , msg , * args )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 30, "parameters": [ "self", "msg", "args" ], "start_line": 1357, "end_line": 1361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "record" ], "start_line": 323, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "log", "long_name": "log( self , lvl , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 50, "parameters": [ "self", "lvl", "msg", "args", "kwargs" ], "start_line": 1377, "end_line": 1386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "getLogger", "long_name": "getLogger( self , name )", "filename": "logging.py", "nloc": 17, "complexity": 3, "token_count": 102, "parameters": [ "self", "name" ], "start_line": 1219, "end_line": 1242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "_fixupParents", "long_name": "_fixupParents( self , alogger )", "filename": "logging.py", "nloc": 19, "complexity": 6, "token_count": 131, "parameters": [ "self", "alogger" ], "start_line": 1244, "end_line": 1266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , alogger )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "alogger" ], "start_line": 1172, "end_line": 1176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , mailhost , fromaddr , toaddrs , subject )", "filename": "logging.py", "nloc": 12, "complexity": 2, "token_count": 72, "parameters": [ "self", "mailhost", "fromaddr", "toaddrs", "subject" ], "start_line": 839, "end_line": 855, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "isEnabledFor", "long_name": "isEnabledFor( self , lvl )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 27, "parameters": [ "self", "lvl" ], "start_line": 1478, "end_line": 1484, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "append", "long_name": "append( self , alogger )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 24, "parameters": [ "self", "alogger" ], "start_line": 1178, "end_line": 1183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "format", "long_name": "format( self , records )", "filename": "logging.py", "nloc": 8, "complexity": 3, "token_count": 58, "parameters": [ "self", "records" ], "start_line": 301, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "critical", "long_name": "critical( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1672, "end_line": 1678, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "addHandler", "long_name": "addHandler( self , hdlr )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 26, "parameters": [ "self", "hdlr" ], "start_line": 1429, "end_line": 1434, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "getSubject", "long_name": "getSubject( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "record" ], "start_line": 857, "end_line": 862, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "send", "long_name": "send( self , s )", "filename": "logging.py", "nloc": 7, "complexity": 2, "token_count": 46, "parameters": [ "self", "s" ], "start_line": 584, "end_line": 594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "getLevelName", "long_name": "getLevelName( lvl )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "lvl" ], "start_line": 105, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , host , url , method = \"GET\" )", "filename": "logging.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [ "self", "host", "url", "method" ], "start_line": 1060, "end_line": 1071, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "shouldFlush", "long_name": "shouldFlush( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "self", "record" ], "start_line": 899, "end_line": 904, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "format", "long_name": "format( self , record )", "filename": "logging.py", "nloc": 10, "complexity": 4, "token_count": 85, "parameters": [ "self", "record" ], "start_line": 249, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "getRootLogger", "long_name": "getRootLogger( )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 7, "parameters": [], "start_line": 1666, "end_line": 1670, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "warn", "long_name": "warn( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 48, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1333, "end_line": 1343, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "debug", "long_name": "debug( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 49, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1309, "end_line": 1319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "setFormatter", "long_name": "setFormatter( self , fmt )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "fmt" ], "start_line": 421, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_log", "long_name": "_log( self , lvl , msg , args , exc_info = None )", "filename": "logging.py", "nloc": 9, "complexity": 3, "token_count": 75, "parameters": [ "self", "lvl", "msg", "args", "exc_info" ], "start_line": 1406, "end_line": 1418, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "addLevelName", "long_name": "addLevelName( lvl , levelName )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "lvl", "levelName" ], "start_line": 115, "end_line": 120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "logging.py", "nloc": 3, "complexity": 1, "token_count": 29, "parameters": [ "self" ], "start_line": 161, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "formatTime", "long_name": "formatTime( self , record , datefmt = None )", "filename": "logging.py", "nloc": 8, "complexity": 2, "token_count": 68, "parameters": [ "self", "record", "datefmt" ], "start_line": 219, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "debug", "long_name": "debug( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1713, "end_line": 1719, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , lvl , pathname , lineno , msg , args , exc_info )", "filename": "logging.py", "nloc": 21, "complexity": 3, "token_count": 142, "parameters": [ "self", "name", "lvl", "pathname", "lineno", "msg", "args", "exc_info" ], "start_line": 136, "end_line": 159, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "info", "long_name": "info( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 49, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1321, "end_line": 1331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , fmt = None , datefmt = None )", "filename": "logging.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "fmt", "datefmt" ], "start_line": 207, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "getEventCategory", "long_name": "getEventCategory( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "record" ], "start_line": 1010, "end_line": 1015, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , capacity )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self", "capacity" ], "start_line": 891, "end_line": 897, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "warn", "long_name": "warn( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1697, "end_line": 1703, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "getMessageID", "long_name": "getMessageID( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "record" ], "start_line": 1000, "end_line": 1008, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , lvl )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "lvl" ], "start_line": 1492, "end_line": 1496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "makeSocket", "long_name": "makeSocket( self )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 575, "end_line": 582, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "removeFilter", "long_name": "removeFilter( self , filter )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 23, "parameters": [ "self", "filter" ], "start_line": 344, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "critical", "long_name": "critical( self , msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 5, "complexity": 3, "token_count": 49, "parameters": [ "self", "msg", "args", "kwargs" ], "start_line": 1363, "end_line": 1373, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "formatHeader", "long_name": "formatHeader( self , records )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self", "records" ], "start_line": 289, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , host , url )", "filename": "logging.py", "nloc": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "host", "url" ], "start_line": 1117, "end_line": 1123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , root )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 29, "parameters": [ "self", "root" ], "start_line": 1210, "end_line": 1217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , level = 0 )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "self", "level" ], "start_line": 377, "end_line": 385, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "exception", "long_name": "exception( msg , * args )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 26, "parameters": [ "msg", "args" ], "start_line": 1690, "end_line": 1695, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "callHandlers", "long_name": "callHandlers( self , record )", "filename": "logging.py", "nloc": 15, "complexity": 7, "token_count": 87, "parameters": [ "self", "record" ], "start_line": 1443, "end_line": 1464, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "sendto", "long_name": "sendto( self , s , addr )", "filename": "logging.py", "nloc": 7, "complexity": 2, "token_count": 50, "parameters": [ "self", "s", "addr" ], "start_line": 656, "end_line": 666, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "info", "long_name": "info( msg , * args , ** kwargs )", "filename": "logging.py", "nloc": 4, "complexity": 2, "token_count": 40, "parameters": [ "msg", "args", "kwargs" ], "start_line": 1705, "end_line": 1711, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "fileConfig", "long_name": "fileConfig( fname )", "filename": "logging.py", "nloc": 64, "complexity": 10, "token_count": 457, "parameters": [ "fname" ], "start_line": 1576, "end_line": 1648, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 }, { "name": "getEventType", "long_name": "getEventType( self , record )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "record" ], "start_line": 1017, "end_line": 1027, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "logging.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 334, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "basicConfig", "long_name": "basicConfig( )", "filename": "logging.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [], "start_line": 1510, "end_line": 1519, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "formatException", "long_name": "formatException( self , ei )", "filename": "logging.py", "nloc": 7, "complexity": 1, "token_count": 54, "parameters": [ "self", "ei" ], "start_line": 237, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "getLogger", "long_name": "getLogger( name )", "filename": "logging.py", "nloc": 5, "complexity": 2, "token_count": 22, "parameters": [ "name" ], "start_line": 1656, "end_line": 1664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "removeHandler", "long_name": "removeHandler( self , hdlr )", "filename": "logging.py", "nloc": 3, "complexity": 2, "token_count": 23, "parameters": [ "self", "hdlr" ], "start_line": 1436, "end_line": 1441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "nloc": null, "complexity": null, "token_count": null, "diff_parsed": { "added": [], "deleted": [ "#! /usr/bin/env python", "#", "# Copyright 2001-2002 by Vinay Sajip. All Rights Reserved.", "#", "# Permission to use, copy, modify, and distribute this software and its", "# documentation for any purpose and without fee is hereby granted,", "# provided that the above copyright notice appear in all copies and that", "# both that copyright notice and this permission notice appear in", "# supporting documentation, and that the name of Vinay Sajip", "# not be used in advertising or publicity pertaining to distribution", "# of the software without specific, written prior permission.", "# VINAY SAJIP DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING", "# ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL", "# VINAY SAJIP BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR", "# ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER", "# IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT", "# OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.", "#", "# For the change history, see README.txt in the distribution.", "#", "# This file is part of the Python logging distribution. See", "# http://www.red-dove.com/python_logging.html", "#", "", "\"\"\"", "Logging module for Python. Based on PEP 282 and comments thereto in", "comp.lang.python, and influenced by Apache's log4j system.", "", "Should work under Python versions >= 1.5.2, except that source line", "information is not available unless 'inspect' is.", "", "Copyright (C) 2001-2002 Vinay Sajip. All Rights Reserved.", "", "To use, simply 'import logging' and log away!", "\"\"\"", "", "import sys, os, types, time, string, socket, cPickle, cStringIO", "", "try:", " import thread", "except ImportError:", " thread = None", "try:", " import inspect", "except ImportError:", " inspect = None", "", "__author__ = \"Vinay Sajip \"", "__status__ = \"alpha\"", "__version__ = \"0.4.1\"", "__date__ = \"03 April 2002\"", "", "#---------------------------------------------------------------------------", "# Module data", "#---------------------------------------------------------------------------", "", "#", "#_srcfile is used when walking the stack to check when we've got the first", "# caller stack frame.", "#If run as a script, __file__ is not bound.", "#", "if __name__ == \"__main__\":", " _srcFile = None", "else:", " _srcfile = os.path.splitext(__file__)", " if _srcfile[1] in [\".pyc\", \".pyo\"]:", " _srcfile = _srcfile[0] + \".py\"", " else:", " _srcfile = __file__", "", "#", "#_start_time is used as the base when calculating the relative time of events", "#", "_start_time = time.time()", "", "DEFAULT_TCP_LOGGING_PORT = 9020", "DEFAULT_UDP_LOGGING_PORT = 9021", "DEFAULT_HTTP_LOGGING_PORT = 9022", "SYSLOG_UDP_PORT = 514", "", "#", "# Default levels and level names, these can be replaced with any positive set", "# of values having corresponding names. There is a pseudo-level, ALL, which", "# is only really there as a lower limit for user-defined levels. Handlers and", "# loggers are initialized with ALL so that they will log all messages, even", "# at user-defined levels.", "#", "CRITICAL = 50", "FATAL = CRITICAL", "ERROR = 40", "WARN = 30", "INFO = 20", "DEBUG = 10", "ALL = 0", "", "_levelNames = {", " CRITICAL : 'CRITICAL',", " ERROR : 'ERROR',", " WARN : 'WARN',", " INFO : 'INFO',", " DEBUG : 'DEBUG',", " ALL : 'ALL',", "}", "", "def getLevelName(lvl):", " \"\"\"", " Return the textual representation of logging level 'lvl'. If the level is", " one of the predefined levels (CRITICAL, ERROR, WARN, INFO, DEBUG) then you", " get the corresponding string. If you have associated levels with names", " using addLevelName then the name you have associated with 'lvl' is", " returned. Otherwise, the string \"Level %s\" % lvl is returned.", " \"\"\"", " return _levelNames.get(lvl, (\"Level %s\" % lvl))", "", "def addLevelName(lvl, levelName):", " \"\"\"", " Associate 'levelName' with 'lvl'. This is used when converting levels", " to text during message formatting.", " \"\"\"", " _levelNames[lvl] = levelName", "", "#---------------------------------------------------------------------------", "# The logging record", "#---------------------------------------------------------------------------", "", "class LogRecord:", " \"\"\"", " LogRecord instances are created every time something is logged. They", " contain all the information pertinent to the event being logged. The", " main information passed in is in msg and args, which are combined", " using msg % args to create the message field of the record. The record", " also includes information such as when the record was created, the", " source line where the logging call was made, and any exception", " information to be logged.", " \"\"\"", " def __init__(self, name, lvl, pathname, lineno, msg, args, exc_info):", " \"\"\"", " Initialize a logging record with interesting information.", " \"\"\"", " ct = time.time()", " self.name = name", " self.msg = msg", " self.args = args", " self.level = getLevelName(lvl)", " self.lvl = lvl", " self.pathname = pathname", " try:", " self.filename = os.path.basename(pathname)", " except:", " self.filename = pathname", " self.exc_info = exc_info", " self.lineno = lineno", " self.created = ct", " self.msecs = (ct - long(ct)) * 1000", " self.relativeCreated = (self.created - _start_time) * 1000", " if thread:", " self.thread = thread.get_ident()", " else:", " self.thread = None", "", " def __str__(self):", " return ''%(self.name, self.lvl,", " self.pathname, self.lineno, self.msg)", "", "#---------------------------------------------------------------------------", "# Formatter classes and functions", "#---------------------------------------------------------------------------", "", "class Formatter:", " \"\"\"", " Formatters need to know how a LogRecord is constructed. They are", " responsible for converting a LogRecord to (usually) a string which can", " be interpreted by either a human or an external system. The base Formatter", " allows a formatting string to be specified. If none is supplied, the", " default value of \"%s(message)\\\\n\" is used.", "", " The Formatter can be initialized with a format string which makes use of", " knowledge of the LogRecord attributes - e.g. the default value mentioned", " above makes use of the fact that the user's message and arguments are pre-", " formatted into a LogRecord's message attribute. Currently, the useful", " attributes in a LogRecord are described by:", "", " %(name)s Name of the logger (logging channel)", " %(lvl)s Numeric logging level for the message (DEBUG, INFO,", " WARN, ERROR, CRITICAL)", " %(level)s Text logging level for the message (\"DEBUG\", \"INFO\",", " \"WARN\", \"ERROR\", \"CRITICAL\")", " %(pathname)s Full pathname of the source file where the logging", " call was issued (if available)", " %(filename)s Filename portion of pathname", " %(lineno)d Source line number where the logging call was issued", " (if available)", " %(created)f Time when the LogRecord was created (time.time()", " return value)", " %(asctime)s textual time when the LogRecord was created", " %(msecs)d Millisecond portion of the creation time", " %(relativeCreated)d Time in milliseconds when the LogRecord was created,", " relative to the time the logging module was loaded", " (typically at application startup time)", " %(thread)d Thread ID (if available)", " %(message)s The result of msg % args, computed just as the", " record is emitted", " %(msg)s The raw formatting string provided by the user", " %(args)r The argument tuple which goes with the formatting", " string in the msg attribute", " \"\"\"", " def __init__(self, fmt=None, datefmt=None):", " \"\"\"", " Initialize the formatter either with the specified format string, or a", " default as described above. Allow for specialized date formatting with", " the optional datefmt argument (if omitted, you get the ISO8601 format).", " \"\"\"", " if fmt:", " self._fmt = fmt", " else:", " self._fmt = \"%(message)s\"", " self.datefmt = datefmt", "", " def formatTime(self, record, datefmt=None):", " \"\"\"", " This method should be called from format() by a formatter which", " wants to make use of a formatted time. This method can be overridden", " in formatters to provide for any specific requirement, but the", " basic behaviour is as follows: if datefmt (a string) is specfied,", " it is used with time.strftime to format the creation time of the", " record. Otherwise, the ISO8601 format is used. The resulting", " string is written to the asctime attribute of the record.", " \"\"\"", " ct = record.created", " if datefmt:", " s = time.strftime(datefmt, time.localtime(ct))", " else:", " t = time.strftime(\"%Y-%m-%d %H:%M:%S\", time.localtime(ct))", " s = \"%s,%03d\" % (t, record.msecs)", " record.asctime = s", "", " def formatException(self, ei):", " \"\"\"", " Format the specified exception information as a string. This", " default implementation just uses traceback.print_exception()", " \"\"\"", " import traceback", " sio = cStringIO.StringIO()", " traceback.print_exception(ei[0], ei[1], ei[2], None, sio)", " s = sio.getvalue()", " sio.close()", " return s", "", " def format(self, record):", " \"\"\"", " The record's attribute dictionary is used as the operand to a", " string formatting operation which yields the returned string.", " Before formatting the dictionary, a couple of preparatory steps", " are carried out. The message attribute of the record is computed", " using msg % args. If the formatting string contains \"(asctime)\",", " formatTime() is called to format the event time. If there is", " exception information, it is formatted using formatException()", " and appended to the message.", " \"\"\"", " record.message = record.msg % record.args", " if string.find(self._fmt,\"(asctime)\") > 0:", " self.formatTime(record, self.datefmt)", " s = self._fmt % record.__dict__", " if record.exc_info:", " if s[-1] != \"\\n\":", " s = s + \"\\n\"", " s = s + self.formatException(record.exc_info)", " return s", "", "#", "# The default formatter to use when no other is specified", "#", "_defaultFormatter = Formatter()", "", "class BufferingFormatter:", " \"\"\"", " A formatter suitable for formatting a number of records.", " \"\"\"", " def __init__(self, linefmt=None):", " \"\"\"", " Optionally specify a formatter which will be used to format each", " individual record.", " \"\"\"", " if linefmt:", " self.linefmt = linefmt", " else:", " self.linefmt = _defaultFormatter", "", " def formatHeader(self, records):", " \"\"\"", " Return the header string for the specified records.", " \"\"\"", " return \"\"", "", " def formatFooter(self, records):", " \"\"\"", " Return the footer string for the specified records.", " \"\"\"", " return \"\"", "", " def format(self, records):", " \"\"\"", " Format the specified records and return the result as a string.", " \"\"\"", " rv = \"\"", " if len(records) > 0:", " rv = rv + self.formatHeader(records)", " for record in records:", " rv = rv + self.linefmt.format(record)", " rv = rv + self.formatFooter(records)", " return rv", "", "#---------------------------------------------------------------------------", "# Filter classes and functions", "#---------------------------------------------------------------------------", "", "class Filter:", " \"\"\"", " The base filter class. This class never filters anything, acting as", " a placeholder which defines the Filter interface. Loggers and Handlers", " can optionally use Filter instances to filter records as desired.", " \"\"\"", " def filter(self, record):", " \"\"\"", " Is the specified record to be logged? Returns a boolean value.", " \"\"\"", " return 1", "", "class Filterer:", " \"\"\"", " A base class for loggers and handlers which allows them to share", " common code.", " \"\"\"", " def __init__(self):", " self.filters = []", "", " def addFilter(self, filter):", " \"\"\"", " Add the specified filter to this handler.", " \"\"\"", " if not (filter in self.filters):", " self.filters.append(filter)", "", " def removeFilter(self, filter):", " \"\"\"", " Remove the specified filter from this handler.", " \"\"\"", " if filter in self.filters:", " self.filters.remove(filter)", "", " def filter(self, record):", " \"\"\"", " Determine if a record is loggable by consulting all the filters. The", " default is to allow the record to be logged; any filter can veto this", " and the record is then dropped. Returns a boolean value.", " \"\"\"", " rv = 1", " for f in self.filters:", " if not f.filter(record):", " rv = 0", " break", " return rv", "", "#---------------------------------------------------------------------------", "# Handler classes and functions", "#---------------------------------------------------------------------------", "", "_handlers = {} #repository of handlers (for flushing when shutdown called)", "", "class Handler(Filterer):", " \"\"\"", " The base handler class. Acts as a placeholder which defines the Handler", " interface. Handlers can optionally use Formatter instances to format", " records as desired. By default, no formatter is specified; in this case,", " the 'raw' message as determined by record.message is logged.", " \"\"\"", " def __init__(self, level=0):", " \"\"\"", " Initializes the instance - basically setting the formatter to None", " and the filter list to empty.", " \"\"\"", " Filterer.__init__(self)", " self.level = level", " self.formatter = None", " _handlers[self] = 1", "", " def setLevel(self, lvl):", " \"\"\"", " Set the logging level of this handler.", " \"\"\"", " self.level = lvl", "", " def format(self, record):", " \"\"\"", " Do formatting for a record - if a formatter is set, use it.", " Otherwise, use the default formatter for the module.", " \"\"\"", " if self.formatter:", " fmt = self.formatter", " else:", " fmt = _defaultFormatter", " return fmt.format(record)", "", " def emit(self, record):", " \"\"\"", " Do whatever it takes to actually log the specified logging record.", " This version is intended to be implemented by subclasses and so", " raises a NotImplementedError.", " \"\"\"", " raise NotImplementedError, 'emit must be implemented '\\", " 'by Handler subclasses'", "", " def handle(self, record):", " \"\"\"", " Conditionally handle the specified logging record, depending on", " filters which may have been added to the handler.", " \"\"\"", " if self.filter(record):", " self.emit(record)", "", " def setFormatter(self, fmt):", " \"\"\"", " Set the formatter for this handler.", " \"\"\"", " self.formatter = fmt", "", " def flush(self):", " \"\"\"", " Ensure all logging output has been flushed. This version does", " nothing and is intended to be implemented by subclasses.", " \"\"\"", " pass", "", " def close(self):", " \"\"\"", " Tidy up any resources used by the handler. This version does", " nothing and is intended to be implemented by subclasses.", " \"\"\"", " pass", "", " def handleError(self):", " \"\"\"", " This method should be called from handlers when an exception is", " encountered during an emit() call. By default it does nothing,", " which means that exceptions get silently ignored. This is what is", " mostly wanted for a logging system - most users will not care", " about errors in the logging system, they are more interested in", " application errors. You could, however, replace this with a custom", " handler if you wish.", " \"\"\"", " #import traceback", " #ei = sys.exc_info()", " #traceback.print_exception(ei[0], ei[1], ei[2], None, sys.stderr)", " #del ei", " pass", "", "class StreamHandler(Handler):", " \"\"\"", " A handler class which writes logging records, appropriately formatted,", " to a stream. Note that this class does not close the stream, as", " sys.stdout or sys.stderr may be used.", " \"\"\"", " def __init__(self, strm=None):", " \"\"\"", " If strm is not specified, sys.stderr is used.", " \"\"\"", " Handler.__init__(self)", " if not strm:", " strm = sys.stderr", " self.stream = strm", " self.formatter = None", "", " def flush(self):", " \"\"\"", " Flushes the stream.", " \"\"\"", " self.stream.flush()", "", " def emit(self, record):", " \"\"\"", " If a formatter is specified, it is used to format the record.", " The record is then written to the stream with a trailing newline", " [N.B. this may be removed depending on feedback]. If exception", " information is present, it is formatted using", " traceback.print_exception and appended to the stream.", " \"\"\"", " try:", " msg = self.format(record)", " self.stream.write(\"%s\\n\" % msg)", " self.flush()", " except:", " self.handleError()", "", "class FileHandler(StreamHandler):", " \"\"\"", " A handler class which writes formatted logging records to disk files.", " \"\"\"", " def __init__(self, filename, mode=\"a+\"):", " \"\"\"", " Open the specified file and use it as the stream for logging.", " By default, the file grows indefinitely. You can call setRollover()", " to allow the file to rollover at a predetermined size.", " \"\"\"", " StreamHandler.__init__(self, open(filename, mode))", " self.max_size = 0", " self.backup_count = 0", " self.basefilename = filename", " self.backup_index = 0", " self.mode = mode", "", " def setRollover(self, max_size, backup_count):", " \"\"\"", " Set the rollover parameters so that rollover occurs whenever the", " current log file is nearly max_size in length. If backup_count", " is >= 1, the system will successively create new files with the", " same pathname as the base file, but with extensions \".1\", \".2\"", " etc. appended to it. For example, with a backup_count of 5 and a", " base file name of \"app.log\", you would get \"app.log\", \"app.log.1\",", " \"app.log.2\", ... through to \"app.log.5\". When the last file reaches", " its size limit, the logging reverts to \"app.log\" which is truncated", " to zero length. If max_size is zero, rollover never occurs.", " \"\"\"", " self.max_size = max_size", " self.backup_count = backup_count", " if max_size > 0:", " self.mode = \"a+\"", "", " def doRollover(self):", " \"\"\"", " Do a rollover, as described in setRollover().", " \"\"\"", " if self.backup_index >= self.backup_count:", " self.backup_index = 0", " fn = self.basefilename", " else:", " self.backup_index = self.backup_index + 1", " fn = \"%s.%d\" % (self.basefilename, self.backup_index)", " self.stream.close()", " self.stream = open(fn, \"w+\")", "", " def emit(self, record):", " \"\"\"", " Output the record to the file, catering for rollover as described", " in setRollover().", " \"\"\"", " if self.max_size > 0: # are we rolling over?", " msg = \"%s\\n\" % self.format(record)", " if self.stream.tell() + len(msg) >= self.max_size:", " self.doRollover()", " StreamHandler.emit(self, record)", "", " def close(self):", " \"\"\"", " Closes the stream.", " \"\"\"", " self.stream.close()", "", "class SocketHandler(StreamHandler):", " \"\"\"", " A handler class which writes logging records, in pickle format, to", " a streaming socket. The socket is kept open across logging calls.", " If the peer resets it, an attempt is made to reconnect on the next call.", " \"\"\"", "", " def __init__(self, host, port):", " \"\"\"", " Initializes the handler with a specific host address and port.", " \"\"\"", " StreamHandler.__init__(self)", " self.host = host", " self.port = port", " self.sock = None", " self.closeOnError = 1", "", " def makeSocket(self):", " \"\"\"", " A factory method which allows subclasses to define the precise", " type of socket they want.", " \"\"\"", " s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)", " s.connect((self.host, self.port))", " return s", "", " def send(self, s):", " \"\"\"", " Send a pickled string to the socket. This function allows for", " partial sends which can happen when the network is busy.", " \"\"\"", " sentsofar = 0", " left = len(s)", " while left > 0:", " sent = self.sock.send(s[sentsofar:])", " sentsofar = sentsofar + sent", " left = left - sent", "", " def makePickle(self, record):", " \"\"\"", " Pickle the record in binary format with a length prefix.", " \"\"\"", " s = cPickle.dumps(record.__dict__, 1)", " n = len(s)", " slen = \"%c%c\" % ((n >> 8) & 0xFF, n & 0xFF)", " return slen + s", "", " def handleError(self):", " \"\"\"", " An error has occurred during logging. Most likely cause -", " connection lost. Close the socket so that we can retry on the", " next event.", " \"\"\"", " if self.closeOnError and self.sock:", " self.sock.close()", " self.sock = None #try to reconnect next time", "", " def emit(self, record):", " \"\"\"", " Pickles the record and writes it to the socket in binary format.", " If there is an error with the socket, silently drop the packet.", " \"\"\"", " try:", " s = self.makePickle(record)", " if not self.sock:", " self.sock = self.makeSocket()", " self.send(s)", " except:", " self.handleError()", "", " def close(self):", " \"\"\"", " Closes the socket.", " \"\"\"", " if self.sock:", " self.sock.close()", " self.sock = None", "", "class DatagramHandler(SocketHandler):", " \"\"\"", " A handler class which writes logging records, in pickle format, to", " a datagram socket.", " \"\"\"", " def __init__(self, host, port):", " \"\"\"", " Initializes the handler with a specific host address and port.", " \"\"\"", " SocketHandler.__init__(self, host, port)", " self.closeOnError = 0", "", " def makeSocket(self):", " \"\"\"", " The factory method of SocketHandler is here overridden to create", " a UDP socket (SOCK_DGRAM).", " \"\"\"", " s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)", " return s", "", " def sendto(self, s, addr):", " \"\"\"", " Send a pickled string to a socket. This function allows for", " partial sends which can happen when the network is busy.", " \"\"\"", " sentsofar = 0", " left = len(s)", " while left > 0:", " sent = self.sock.sendto(s[sentsofar:], addr)", " sentsofar = sentsofar + sent", " left = left - sent", "", " def emit(self, record):", " \"\"\"", " Pickles the record and writes it to the socket in binary format.", " \"\"\"", " try:", " s = self.makePickle(record)", " if not self.sock:", " self.sock = self.makeSocket()", " self.sendto(s, (self.host, self.port))", " except:", " self.handleError()", "", "class SysLogHandler(Handler):", " \"\"\"", " A handler class which sends formatted logging records to a syslog", " server. Based on Sam Rushing's syslog module:", " http://www.nightmare.com/squirl/python-ext/misc/syslog.py", " Contributed by Nicolas Untz (after which minor refactoring changes", " have been made).", " \"\"\"", "", " # from :", " # ======================================================================", " # priorities/facilities are encoded into a single 32-bit quantity, where", " # the bottom 3 bits are the priority (0-7) and the top 28 bits are the", " # facility (0-big number). Both the priorities and the facilities map", " # roughly one-to-one to strings in the syslogd(8) source code. This", " # mapping is included in this file.", " #", " # priorities (these are ordered)", "", " LOG_EMERG = 0 # system is unusable", " LOG_ALERT = 1 # action must be taken immediately", " LOG_CRIT = 2 # critical conditions", " LOG_ERR = 3 # error conditions", " LOG_WARNING = 4 # warning conditions", " LOG_NOTICE = 5 # normal but significant condition", " LOG_INFO = 6 # informational", " LOG_DEBUG = 7 # debug-level messages", "", " # facility codes", " LOG_KERN = 0 # kernel messages", " LOG_USER = 1 # random user-level messages", " LOG_MAIL = 2 # mail system", " LOG_DAEMON = 3 # system daemons", " LOG_AUTH = 4 # security/authorization messages", " LOG_SYSLOG = 5 # messages generated internally by syslogd", " LOG_LPR = 6 # line printer subsystem", " LOG_NEWS = 7 # network news subsystem", " LOG_UUCP = 8 # UUCP subsystem", " LOG_CRON = 9 # clock daemon", " LOG_AUTHPRIV = 10 # security/authorization messages (private)", "", " # other codes through 15 reserved for system use", " LOG_LOCAL0 = 16 # reserved for local use", " LOG_LOCAL1 = 17 # reserved for local use", " LOG_LOCAL2 = 18 # reserved for local use", " LOG_LOCAL3 = 19 # reserved for local use", " LOG_LOCAL4 = 20 # reserved for local use", " LOG_LOCAL5 = 21 # reserved for local use", " LOG_LOCAL6 = 22 # reserved for local use", " LOG_LOCAL7 = 23 # reserved for local use", "", " priority_names = {", " \"alert\": LOG_ALERT,", " \"crit\": LOG_CRIT,", " \"critical\": LOG_CRIT,", " \"debug\": LOG_DEBUG,", " \"emerg\": LOG_EMERG,", " \"err\": LOG_ERR,", " \"error\": LOG_ERR, # DEPRECATED", " \"info\": LOG_INFO,", " \"notice\": LOG_NOTICE,", " \"panic\": LOG_EMERG, # DEPRECATED", " \"warn\": LOG_WARNING, # DEPRECATED", " \"warning\": LOG_WARNING,", " }", "", " facility_names = {", " \"auth\": LOG_AUTH,", " \"authpriv\": LOG_AUTHPRIV,", " \"cron\": LOG_CRON,", " \"daemon\": LOG_DAEMON,", " \"kern\": LOG_KERN,", " \"lpr\": LOG_LPR,", " \"mail\": LOG_MAIL,", " \"news\": LOG_NEWS,", " \"security\": LOG_AUTH, # DEPRECATED", " \"syslog\": LOG_SYSLOG,", " \"user\": LOG_USER,", " \"uucp\": LOG_UUCP,", " \"local0\": LOG_LOCAL0,", " \"local1\": LOG_LOCAL1,", " \"local2\": LOG_LOCAL2,", " \"local3\": LOG_LOCAL3,", " \"local4\": LOG_LOCAL4,", " \"local5\": LOG_LOCAL5,", " \"local6\": LOG_LOCAL6,", " \"local7\": LOG_LOCAL7,", " }", "", " def __init__(self, address=('localhost', SYSLOG_UDP_PORT), facility=LOG_USER):", " \"\"\"", " If address is not specified, UNIX socket is used.", " If facility is not specified, LOG_USER is used.", " \"\"\"", " Handler.__init__(self)", "", " self.address = address", " self.facility = facility", " if type(address) == types.StringType:", " self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)", " self.socket.connect(address)", " self.unixsocket = 1", " else:", " self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)", " self.unixsocket = 0", "", " self.formatter = None", "", " # curious: when talking to the unix-domain '/dev/log' socket, a", " # zero-terminator seems to be required. this string is placed", " # into a class variable so that it can be overridden if", " # necessary.", " log_format_string = '<%d>%s\\000'", "", " def encodePriority (self, facility, priority):", " \"\"\"", " Encode the facility and priority. You can pass in strings or", " integers - if strings are passed, the facility_names and", " priority_names mapping dictionaries are used to convert them to", " integers.", " \"\"\"", " if type(facility) == types.StringType:", " facility = self.facility_names[facility]", " if type(priority) == types.StringType:", " priority = self.priority_names[priority]", " return (facility << 3) | priority", "", " def close (self):", " \"\"\"", " Closes the socket.", " \"\"\"", " if self.unixsocket:", " self.socket.close()", "", " def emit(self, record):", " \"\"\"", " The record is formatted, and then sent to the syslog server. If", " exception information is present, it is NOT sent to the server.", " \"\"\"", " msg = self.format(record)", " \"\"\"", " We need to convert record level to lowercase, maybe this will", " change in the future.", " \"\"\"", " msg = self.log_format_string % (", " self.encodePriority(self.facility, string.lower(record.level)),", " msg)", " try:", " if self.unixsocket:", " self.socket.send(msg)", " else:", " self.socket.sendto(msg, self.address)", " except:", " self.handleError()", "", "class SMTPHandler(Handler):", " \"\"\"", " A handler class which sends an SMTP email for each logging event.", " \"\"\"", " def __init__(self, mailhost, fromaddr, toaddrs, subject):", " \"\"\"", " Initialize the instance with the from and to addresses and subject", " line of the email. To specify a non-standard SMTP port, use the", " (host, port) tuple format for the mailhost argument.", " \"\"\"", " Handler.__init__(self)", " if type(mailhost) == types.TupleType:", " host, port = mailhost", " self.mailhost = host", " self.mailport = port", " else:", " self.mailhost = mailhost", " self.mailport = None", " self.fromaddr = fromaddr", " self.toaddrs = toaddrs", " self.subject = subject", "", " def getSubject(self, record):", " \"\"\"", " If you want to specify a subject line which is record-dependent,", " override this method.", " \"\"\"", " return self.subject", "", " def emit(self, record):", " \"\"\"", " Format the record and send it to the specified addressees.", " \"\"\"", " try:", " import smtplib", " port = self.mailport", " if not port:", " port = smtplib.SMTP_PORT", " smtp = smtplib.SMTP(self.mailhost, port)", " msg = self.format(record)", " msg = \"From: %s\\r\\nTo: %s\\r\\nSubject: %s\\r\\n\\r\\n%s\" % (", " self.fromaddr,", " string.join(self.toaddrs, \",\"),", " self.getSubject(record), msg", " )", " smtp.sendmail(self.fromaddr, self.toaddrs, msg)", " smtp.quit()", " except:", " self.handleError()", "", "class BufferingHandler(Handler):", " \"\"\"", " A handler class which buffers logging records in memory. Whenever each", " record is added to the buffer, a check is made to see if the buffer should", " be flushed. If it should, then flush() is expected to do the needful.", " \"\"\"", " def __init__(self, capacity):", " \"\"\"", " Initialize the handler with the buffer size.", " \"\"\"", " Handler.__init__(self)", " self.capacity = capacity", " self.buffer = []", "", " def shouldFlush(self, record):", " \"\"\"", " Returns true if the buffer is up to capacity. This method can be", " overridden to implement custom flushing strategies.", " \"\"\"", " return (len(self.buffer) >= self.capacity)", "", " def emit(self, record):", " \"\"\"", " Append the record. If shouldFlush() tells us to, call flush() to process", " the buffer.", " \"\"\"", " self.buffer.append(record)", " if self.shouldFlush(record):", " self.flush()", "", " def flush(self):", " \"\"\"", " Override to implement custom flushing behaviour. This version just zaps", " the buffer to empty.", " \"\"\"", " self.buffer = []", "", "class MemoryHandler(BufferingHandler):", " \"\"\"", " A handler class which buffers logging records in memory, periodically", " flushing them to a target handler. Flushing occurs whenever the buffer", " is full, or when an event of a certain severity or greater is seen.", " \"\"\"", " def __init__(self, capacity, flushLevel=ERROR, target=None):", " \"\"\"", " Initialize the handler with the buffer size, the level at which", " flushing should occur and an optional target. Note that without a", " target being set either here or via setTarget(), a MemoryHandler", " is no use to anyone!", " \"\"\"", " BufferingHandler.__init__(self, capacity)", " self.flushLevel = flushLevel", " self.target = target", "", " def shouldFlush(self, record):", " \"\"\"", " Check for buffer full or a record at the flushLevel or higher.", " \"\"\"", " return (len(self.buffer) >= self.capacity) or \\", " (record.lvl >= self.flushLevel)", "", " def setTarget(self, target):", " \"\"\"", " Set the target handler for this handler.", " \"\"\"", " self.target = target", "", " def flush(self):", " \"\"\"", " For a MemoryHandler, flushing means just sending the buffered", " records to the target, if there is one. Override if you want", " different behaviour.", " \"\"\"", " if self.target:", " for record in self.buffer:", " self.target.handle(record)", " self.buffer = []", "", "class NTEventLogHandler(Handler):", " \"\"\"", " A handler class which sends events to the NT Event Log. Adds a", " registry entry for the specified application name. If no dllname is", " provided, win32service.pyd (which contains some basic message", " placeholders) is used. Note that use of these placeholders will make", " your event logs big, as the entire message source is held in the log.", " If you want slimmer logs, you have to pass in the name of your own DLL", " which contains the message definitions you want to use in the event log.", " \"\"\"", " def __init__(self, appname, dllname=None, logtype=\"Application\"):", " Handler.__init__(self)", " try:", " import win32evtlogutil, win32evtlog", " self.appname = appname", " self._welu = win32evtlogutil", " if not dllname:", " import os", " dllname = os.path.split(self._welu.__file__)", " dllname = os.path.split(dllname[0])", " dllname = os.path.join(dllname[0], r'win32service.pyd')", " self.dllname = dllname", " self.logtype = logtype", " self._welu.AddSourceToRegistry(appname, dllname, logtype)", " self.deftype = win32evtlog.EVENTLOG_ERROR_TYPE", " self.typemap = {", " DEBUG : win32evtlog.EVENTLOG_INFORMATION_TYPE,", " INFO : win32evtlog.EVENTLOG_INFORMATION_TYPE,", " WARN : win32evtlog.EVENTLOG_WARNING_TYPE,", " ERROR : win32evtlog.EVENTLOG_ERROR_TYPE,", " CRITICAL: win32evtlog.EVENTLOG_ERROR_TYPE,", " }", " except ImportError:", " print \"The Python Win32 extensions for NT (service, event \"\\", " \"logging) appear not to be available.\"", " self._welu = None", "", " def getMessageID(self, record):", " \"\"\"", " Return the message ID for the event record. If you are using your", " own messages, you could do this by having the msg passed to the", " logger being an ID rather than a formatting string. Then, in here,", " you could use a dictionary lookup to get the message ID. This", " version returns 1, which is the base message ID in win32service.pyd.", " \"\"\"", " return 1", "", " def getEventCategory(self, record):", " \"\"\"", " Return the event category for the record. Override this if you", " want to specify your own categories. This version returns 0.", " \"\"\"", " return 0", "", " def getEventType(self, record):", " \"\"\"", " Return the event type for the record. Override this if you want", " to specify your own types. This version does a mapping using the", " handler's typemap attribute, which is set up in __init__() to a", " dictionary which contains mappings for DEBUG, INFO, WARN, ERROR", " and CRITICAL. If you are using your own levels you will either need", " to override this method or place a suitable dictionary in the", " handler's typemap attribute.", " \"\"\"", " return self.typemap.get(record.lvl, self.deftype)", "", " def emit(self, record):", " \"\"\"", " Determine the message ID, event category and event type. Then", " log the message in the NT event log.", " \"\"\"", " if self._welu:", " try:", " id = self.getMessageID(record)", " cat = self.getEventCategory(record)", " type = self.getEventType(record)", " msg = self.format(record)", " self._welu.ReportEvent(self.appname, id, cat, type, [msg])", " except:", " self.handleError()", "", " def close(self):", " \"\"\"", " You can remove the application name from the registry as a", " source of event log entries. However, if you do this, you will", " not be able to see the events as you intended in the Event Log", " Viewer - it needs to be able to access the registry to get the", " DLL name.", " \"\"\"", " #self._welu.RemoveSourceFromRegistry(self.appname, self.logtype)", " pass", "", "class HTTPHandler(Handler):", " \"\"\"", " A class which sends records to a Web server, using either GET or", " POST semantics.", " \"\"\"", " def __init__(self, host, url, method=\"GET\"):", " \"\"\"", " Initialize the instance with the host, the request URL, and the method", " (\"GET\" or \"POST\")", " \"\"\"", " Handler.__init__(self)", " method = string.upper(method)", " if method not in [\"GET\", \"POST\"]:", " raise ValueError, \"method must be GET or POST\"", " self.host = host", " self.url = url", " self.method = method", "", " def emit(self, record):", " \"\"\"", " Send the record to the Web server as an URL-encoded dictionary", " \"\"\"", " try:", " import httplib, urllib", " h = httplib.HTTP(self.host)", " url = self.url", " data = urllib.urlencode(record.__dict__)", " if self.method == \"GET\":", " if (string.find(url, '?') >= 0):", " sep = '&'", " else:", " sep = '?'", " url = url + \"%c%s\" % (sep, data)", " h.putrequest(self.method, url)", " if self.method == \"POST\":", " h.putheader(\"Content-length\", str(len(data)))", " h.endheaders()", " if self.method == \"POST\":", " h.send(data)", " h.getreply() #can't do anything with the result", " except:", " self.handleError()", "", "SOAP_MESSAGE = \"\"\"", " ", " ", "%s", " ", " ", "", "\"\"\"", "", "class SOAPHandler(Handler):", " \"\"\"", " A class which sends records to a SOAP server.", " \"\"\"", " def __init__(self, host, url):", " \"\"\"", " Initialize the instance with the host and the request URL", " \"\"\"", " Handler.__init__(self)", " self.host = host", " self.url = url", "", " def emit(self, record):", " \"\"\"", " Send the record to the Web server as a SOAP message", " \"\"\"", " try:", " import httplib, urllib", " h = httplib.HTTP(self.host)", " h.putrequest(\"POST\", self.url)", " keys = record.__dict__.keys()", " keys.sort()", " args = \"\"", " for key in keys:", " v = record.__dict__[key]", " if type(v) == types.StringType:", " t = \"string\"", " elif (type(v) == types.IntType) or (type(v) == types.LongType):", " t = \"integer\"", " elif type(v) == types.FloatType:", " t = \"float\"", " else:", " t = \"string\"", " args = args + \"%12s%s\\n\" % (\"\",", " key, t, str(v), key)", " data = SOAP_MESSAGE % args[:-1]", " #print data", " h.putheader(\"Content-type\", \"text/plain; charset=\\\"utf-8\\\"\")", " h.putheader(\"Content-length\", str(len(data)))", " h.endheaders()", " h.send(data)", " r = h.getreply() #can't do anything with the result", " #print r", " f = h.getfile()", " #print f.read()", " f.close()", " except:", " self.handleError()", "", "#---------------------------------------------------------------------------", "# Manager classes and functions", "#---------------------------------------------------------------------------", "", "class PlaceHolder:", " \"\"\"", " PlaceHolder instances are used in the Manager logger hierarchy to take", " the place of nodes for which no loggers have been defined [FIXME add", " example].", " \"\"\"", " def __init__(self, alogger):", " \"\"\"", " Initialize with the specified logger being a child of this placeholder.", " \"\"\"", " self.loggers = [alogger]", "", " def append(self, alogger):", " \"\"\"", " Add the specified logger as a child of this placeholder.", " \"\"\"", " if alogger not in self.loggers:", " self.loggers.append(alogger)", "", "#", "# Determine which class to use when instantiating loggers.", "#", "_loggerClass = None", "", "def setLoggerClass(klass):", " \"\"\"", " Set the class to be used when instantiating a logger. The class should", " define __init__() such that only a name argument is required, and the", " __init__() should call Logger.__init__()", " \"\"\"", " if klass != Logger:", " if type(klass) != types.ClassType:", " raise TypeError, \"setLoggerClass is expecting a class\"", " if not (Logger in klass.__bases__):", " raise TypeError, \"logger not derived from logging.Logger: \" + \\", " klass.__name__", " global _loggerClass", " _loggerClass = klass", "", "class Manager:", " \"\"\"", " There is [under normal circumstances] just one Manager instance, which", " holds the hierarchy of loggers.", " \"\"\"", " def __init__(self, root):", " \"\"\"", " Initialize the manager with the root node of the logger hierarchy.", " \"\"\"", " self.root = root", " self.disable = 0", " self.emittedNoHandlerWarning = 0", " self.loggerDict = {}", "", " def getLogger(self, name):", " \"\"\"", " Get a logger with the specified name, creating it if it doesn't", " yet exist. If a PlaceHolder existed for the specified name [i.e.", " the logger didn't exist but a child of it did], replace it with", " the created logger and fix up the parent/child references which", " pointed to the placeholder to now point to the logger.", " \"\"\"", " rv = None", " if self.loggerDict.has_key(name):", " rv = self.loggerDict[name]", " if isinstance(rv, PlaceHolder):", " ph = rv", " rv = _loggerClass(name)", " rv.manager = self", " self.loggerDict[name] = rv", " self._fixupChildren(ph, rv)", " self._fixupParents(rv)", " else:", " rv = _loggerClass(name)", " rv.manager = self", " self.loggerDict[name] = rv", " self._fixupParents(rv)", " return rv", "", " def _fixupParents(self, alogger):", " \"\"\"", " Ensure that there are either loggers or placeholders all the way", " from the specified logger to the root of the logger hierarchy.", " \"\"\"", " name = alogger.name", " i = string.rfind(name, \".\")", " rv = None", " while (i > 0) and not rv:", " substr = name[:i]", " if not self.loggerDict.has_key(substr):", " self.loggerDict[name] = PlaceHolder(alogger)", " else:", " obj = self.loggerDict[substr]", " if isinstance(obj, Logger):", " rv = obj", " else:", " assert isinstance(obj, PlaceHolder)", " obj.append(alogger)", " i = string.rfind(name, \".\", 0, i - 1)", " if not rv:", " rv = self.root", " alogger.parent = rv", "", " def _fixupChildren(self, ph, alogger):", " \"\"\"", " Ensure that children of the placeholder ph are connected to the", " specified logger.", " \"\"\"", " for c in ph.loggers:", " if string.find(c.parent.name, alogger.name) <> 0:", " alogger.parent = c.parent", " c.parent = alogger", "", "#---------------------------------------------------------------------------", "# Logger classes and functions", "#---------------------------------------------------------------------------", "", "class Logger(Filterer):", " \"\"\"", " Instances of the Logger class represent a single logging channel.", " \"\"\"", " def __init__(self, name, level=0):", " \"\"\"", " Initialize the logger with a name and an optional level.", " \"\"\"", " Filterer.__init__(self)", " self.name = name", " self.level = level", " self.parent = None", " self.propagate = 1", " self.handlers = []", "", " def setLevel(self, lvl):", " \"\"\"", " Set the logging level of this logger.", " \"\"\"", " self.level = lvl", "", "# def getRoot(self):", "# \"\"\"", "# Get the root of the logger hierarchy.", "# \"\"\"", "# return Logger.root", "", " def debug(self, msg, *args, **kwargs):", " \"\"\"", " Log 'msg % args' with severity 'DEBUG'. To pass exception information,", " use the keyword argument exc_info with a true value, e.g.", "", " logger.debug(\"Houston, we have a %s\", \"thorny problem\", exc_info=1)", " \"\"\"", " if self.manager.disable >= DEBUG:", " return", " if DEBUG >= self.getEffectiveLevel():", " apply(self._log, (DEBUG, msg, args), kwargs)", "", " def info(self, msg, *args, **kwargs):", " \"\"\"", " Log 'msg % args' with severity 'INFO'. To pass exception information,", " use the keyword argument exc_info with a true value, e.g.", "", " logger.info(\"Houston, we have a %s\", \"interesting problem\", exc_info=1)", " \"\"\"", " if self.manager.disable >= INFO:", " return", " if INFO >= self.getEffectiveLevel():", " apply(self._log, (INFO, msg, args), kwargs)", "", " def warn(self, msg, *args, **kwargs):", " \"\"\"", " Log 'msg % args' with severity 'WARN'. To pass exception information,", " use the keyword argument exc_info with a true value, e.g.", "", " logger.warn(\"Houston, we have a %s\", \"bit of a problem\", exc_info=1)", " \"\"\"", " if self.manager.disable >= WARN:", " return", " if self.isEnabledFor(WARN):", " apply(self._log, (WARN, msg, args), kwargs)", "", " def error(self, msg, *args, **kwargs):", " \"\"\"", " Log 'msg % args' with severity 'ERROR'. To pass exception information,", " use the keyword argument exc_info with a true value, e.g.", "", " logger.error(\"Houston, we have a %s\", \"major problem\", exc_info=1)", " \"\"\"", " if self.manager.disable >= ERROR:", " return", " if self.isEnabledFor(ERROR):", " apply(self._log, (ERROR, msg, args), kwargs)", "", " def exception(self, msg, *args):", " \"\"\"", " Convenience method for logging an ERROR with exception information", " \"\"\"", " apply(self.error, (msg,) + args, {'exc_info': 1})", "", " def critical(self, msg, *args, **kwargs):", " \"\"\"", " Log 'msg % args' with severity 'CRITICAL'. To pass exception", " information, use the keyword argument exc_info with a true value, e.g.", "", " logger.critical(\"Houston, we have a %s\", \"major disaster\", exc_info=1)", " \"\"\"", " if self.manager.disable >= CRITICAL:", " return", " if CRITICAL >= self.getEffectiveLevel():", " apply(self._log, (CRITICAL, msg, args), kwargs)", "", " fatal = critical", "", " def log(self, lvl, msg, *args, **kwargs):", " \"\"\"", " Log 'msg % args' with the severity 'lvl'. To pass exception", " information, use the keyword argument exc_info with a true value, e.g.", " logger.log(lvl, \"We have a %s\", \"mysterious problem\", exc_info=1)", " \"\"\"", " if self.manager.disable >= lvl:", " return", " if self.isEnabledFor(lvl):", " apply(self._log, (lvl, msg, args), kwargs)", "", " def findCaller(self):", " \"\"\"", " Find the stack frame of the caller so that we can note the source", " file name and line number.", " \"\"\"", " frames = inspect.stack()[1:]", " for f in frames:", " if _srcfile != f[1]:", " return (f[1], f[2])", " return (None, None)", "", " def makeRecord(self, name, lvl, fn, lno, msg, args, exc_info):", " \"\"\"", " A factory method which can be overridden in subclasses to create", " specialized LogRecords.", " \"\"\"", " return LogRecord(name, lvl, fn, lno, msg, args, exc_info)", "", " def _log(self, lvl, msg, args, exc_info=None):", " \"\"\"", " Low-level logging routine which creates a LogRecord and then calls", " all the handlers of this logger to handle the record.", " \"\"\"", " if inspect:", " fn, lno = self.findCaller()", " else:", " fn, lno = \"\", 0", " if exc_info:", " exc_info = sys.exc_info()", " record = self.makeRecord(self.name, lvl, fn, lno, msg, args, exc_info)", " self.handle(record)", "", " def handle(self, record):", " \"\"\"", " Call the handlers for the specified record. This method is used for", " unpickled records received from a socket, as well as those created", " locally. Logger-level filtering is applied.", " \"\"\"", " if self.filter(record):", " self.callHandlers(record)", "", " def addHandler(self, hdlr):", " \"\"\"", " Add the specified handler to this logger.", " \"\"\"", " if not (hdlr in self.handlers):", " self.handlers.append(hdlr)", "", " def removeHandler(self, hdlr):", " \"\"\"", " Remove the specified handler from this logger.", " \"\"\"", " if hdlr in self.handlers:", " self.handlers.remove(hdlr)", "", " def callHandlers(self, record):", " \"\"\"", " Loop through all handlers for this logger and its parents in the", " logger hierarchy. If no handler was found, output a one-off error", " message. Stop searching up the hierarchy whenever a logger with the", " \"propagate\" attribute set to zero is found - that will be the last", " logger whose handlers are called.", " \"\"\"", " c = self", " found = 0", " while c:", " for hdlr in c.handlers:", " found = found + 1", " if record.lvl >= hdlr.level:", " hdlr.handle(record)", " if not c.propagate:", " c = None #break out", " else:", " c = c.parent", " if (found == 0) and not self.manager.emittedNoHandlerWarning:", " print \"No handlers could be found for logger \\\"%s\\\"\" % self.name", " self.manager.emittedNoHandlerWarning = 1", "", " def getEffectiveLevel(self):", " \"\"\"", " Loop through this logger and its parents in the logger hierarchy,", " looking for a non-zero logging level. Return the first one found.", " \"\"\"", " c = self", " while c:", " if c.level:", " return c.level", " c = c.parent", " #print \"NCP\", self.parent", "", " def isEnabledFor(self, lvl):", " \"\"\"", " Is this logger enabled for level lvl?", " \"\"\"", " if self.manager.disable >= lvl:", " return 0", " return lvl >= self.getEffectiveLevel()", "", "class RootLogger(Logger):", " \"\"\"", " A root logger is not that different to any other logger, except that", " it must have a logging level and there is only one instance of it in", " the hierarchy.", " \"\"\"", " def __init__(self, lvl):", " \"\"\"", " Initialize the logger with the name \"root\".", " \"\"\"", " Logger.__init__(self, \"root\", lvl)", "", "_loggerClass = Logger", "", "root = RootLogger(DEBUG)", "Logger.root = root", "Logger.manager = Manager(Logger.root)", "", "#---------------------------------------------------------------------------", "# Configuration classes and functions", "#---------------------------------------------------------------------------", "", "BASIC_FORMAT = \"%(asctime)s %(name)-19s %(level)-5s - %(message)s\"", "", "def basicConfig():", " \"\"\"", " Do basic configuration for the logging system by creating a", " StreamHandler with a default Formatter and adding it to the", " root logger.", " \"\"\"", " hdlr = StreamHandler()", " fmt = Formatter(BASIC_FORMAT)", " hdlr.setFormatter(fmt)", " root.addHandler(hdlr)", "", "#def fileConfig(fname):", "# \"\"\"", "# The old implementation - using dict-based configuration files.", "# Read the logging configuration from a file. Keep it simple for now.", "# \"\"\"", "# file = open(fname, \"r\")", "# data = file.read()", "# file.close()", "# dict = eval(data)", "# handlers = dict.get(\"handlers\", [])", "# loggers = dict.get(\"loggers\", [])", "# formatters = dict.get(\"formatters\", [])", "# for f in formatters:", "# fd = dict[f]", "# fc = fd.get(\"class\", \"logging.Formatter\")", "# args = fd.get(\"args\", ())", "# fc = eval(fc)", "# try:", "# fmt = apply(fc, args)", "# except:", "# print fc, args", "# raise", "# dict[f] = fmt", "#", "# for h in handlers:", "# hd = dict[h]", "# hc = hd.get(\"class\", \"logging.StreamHandler\")", "# args = hd.get(\"args\", ())", "# hc = eval(hc)", "# fmt = hd.get(\"formatter\", None)", "# if fmt:", "# fmt = dict.get(fmt, None)", "# try:", "# hdlr = apply(hc, args)", "# except:", "# print hc, args", "# raise", "# if fmt:", "# hdlr.setFormatter(fmt)", "# dict[h] = hdlr", "#", "# for ln in loggers:", "# ld = dict[ln]", "# name = ld.get(\"name\", None)", "# if name:", "# logger = getLogger(name)", "# else:", "# logger = getRootLogger()", "# logger.propagate = ld.get(\"propagate\", 1)", "# hdlrs = ld.get(\"handlers\", [])", "# for h in hdlrs:", "# hdlr = dict.get(h, None)", "# if hdlr:", "# logger.addHandler(hdlr)", "", "def fileConfig(fname):", " \"\"\"", " Read the logging configuration from a ConfigParser-format file.", " \"\"\"", " import ConfigParser", "", " cp = ConfigParser.ConfigParser()", " cp.read(fname)", " #first, do the formatters...", " flist = cp.get(\"formatters\", \"keys\")", " flist = string.split(flist, \",\")", " formatters = {}", " for form in flist:", " sectname = \"formatter_%s\" % form", " fs = cp.get(sectname, \"format\", 1)", " dfs = cp.get(sectname, \"datefmt\", 1)", " f = Formatter(fs, dfs)", " formatters[form] = f", " #next, do the handlers...", " hlist = cp.get(\"handlers\", \"keys\")", " hlist = string.split(hlist, \",\")", " handlers = {}", " for hand in hlist:", " sectname = \"handler_%s\" % hand", " klass = cp.get(sectname, \"class\")", " fmt = cp.get(sectname, \"formatter\")", " lvl = cp.get(sectname, \"level\")", " klass = eval(klass)", " args = cp.get(sectname, \"args\")", " args = eval(args)", " h = apply(klass, args)", " h.setLevel(eval(lvl))", " h.setFormatter(formatters[fmt])", " #temporary hack for FileHandler.", " if klass == FileHandler:", " maxsize = cp.get(sectname, \"maxsize\")", " if maxsize:", " maxsize = eval(maxsize)", " else:", " maxsize = 0", " if maxsize:", " backcount = cp.get(sectname, \"backcount\")", " if backcount:", " backcount = eval(backcount)", " else:", " backcount = 0", " h.setRollover(maxsize, backcount)", " handlers[hand] = h", " #at last, the loggers...first the root...", " llist = cp.get(\"loggers\", \"keys\")", " llist = string.split(llist, \",\")", " llist.remove(\"root\")", " sectname = \"logger_root\"", " log = root", " lvl = cp.get(sectname, \"level\")", " log.setLevel(eval(lvl))", " hlist = cp.get(sectname, \"handlers\")", " hlist = string.split(hlist, \",\")", " for hand in hlist:", " log.addHandler(handlers[hand])", " #and now the others...", " for log in llist:", " sectname = \"logger_%s\" % log", " qn = cp.get(sectname, \"qualname\")", " lvl = cp.get(sectname, \"level\")", " propagate = cp.get(sectname, \"propagate\")", " logger = getLogger(qn)", " logger.setLevel(eval(lvl))", " logger.propagate = eval(propagate)", " hlist = cp.get(sectname, \"handlers\")", " hlist = string.split(hlist, \",\")", " for hand in hlist:", " logger.addHandler(handlers[hand])", "", "", "#---------------------------------------------------------------------------", "# Utility functions at module level.", "# Basically delegate everything to the root logger.", "#---------------------------------------------------------------------------", "", "def getLogger(name):", " \"\"\"", " Return a logger with the specified name, creating it if necessary.", " If no name is specified, return the root logger.", " \"\"\"", " if name:", " return Logger.manager.getLogger(name)", " else:", " return root", "", "def getRootLogger():", " \"\"\"", " Return the root logger.", " \"\"\"", " return root", "", "def critical(msg, *args, **kwargs):", " \"\"\"", " Log a message with severity 'CRITICAL' on the root logger.", " \"\"\"", " if len(root.handlers) == 0:", " basicConfig()", " apply(root.critical, (msg,)+args, kwargs)", "", "fatal = critical", "", "def error(msg, *args, **kwargs):", " \"\"\"", " Log a message with severity 'ERROR' on the root logger.", " \"\"\"", " if len(root.handlers) == 0:", " basicConfig()", " apply(root.error, (msg,)+args, kwargs)", "", "def exception(msg, *args):", " \"\"\"", " Log a message with severity 'ERROR' on the root logger,", " with exception information.", " \"\"\"", " apply(error, (msg,)+args, {'exc_info': 1})", "", "def warn(msg, *args, **kwargs):", " \"\"\"", " Log a message with severity 'WARN' on the root logger.", " \"\"\"", " if len(root.handlers) == 0:", " basicConfig()", " apply(root.warn, (msg,)+args, kwargs)", "", "def info(msg, *args, **kwargs):", " \"\"\"", " Log a message with severity 'INFO' on the root logger.", " \"\"\"", " if len(root.handlers) == 0:", " basicConfig()", " apply(root.info, (msg,)+args, kwargs)", "", "def debug(msg, *args, **kwargs):", " \"\"\"", " Log a message with severity 'DEBUG' on the root logger.", " \"\"\"", " if len(root.handlers) == 0:", " basicConfig()", " apply(root.debug, (msg,)+args, kwargs)", "", "def disable(level):", " \"\"\"", " Disable all logging calls less severe than 'level'.", " \"\"\"", " root.manager.disable = level", "", "def shutdown():", " \"\"\"", " Perform any cleanup actions in the logging system (e.g. flushing", " buffers). Should be called at application exit.", " \"\"\"", " for h in _handlers.keys():", " h.flush()", " h.close()", "", "if __name__ == \"__main__\":", " print __doc__" ] } }, { "old_path": "weave/__init__.py", "new_path": "weave/__init__.py", "filename": "__init__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -29,9 +29,5 @@ def test(level=10):\n \n def test_suite(level=1):\n import scipy_test.testing\n- try:\n- import scipy.weave as this_mod\n- except ImportError:\n- # punt -- assume we're a stand alone package\n- this_mod = weave\n- return scipy_test.testing.harvest_test_suites(this_mod,level=level)\n+ import weave\n+ return scipy_test.testing.harvest_test_suites(weave,level=level)\n", "added_lines": 2, "deleted_lines": 6, "source_code": "\"\"\" compiler provides several tools:\n\n 1. inline() -- a function for including C/C++ code within Python\n 2. blitz() -- a function for compiling Numeric expressions to C++\n 3. ext_tools-- a module that helps construct C/C++ extension modules.\n 4. accelerate -- a module that inline accelerates Python functions\n\"\"\"\n\ntry:\n from blitz_tools import blitz\nexcept ImportError:\n pass # Numeric wasn't available \n \nfrom inline_tools import inline\nimport ext_tools\nfrom ext_tools import ext_module, ext_function\ntry:\n from accelerate_tools import accelerate\nexcept:\n pass\n\n#---- testing ----#\n\ndef test(level=10):\n import unittest\n runner = unittest.TextTestRunner()\n runner.run(test_suite(level))\n return runner\n\ndef test_suite(level=1):\n import scipy_test.testing\n import weave\n return scipy_test.testing.harvest_test_suites(weave,level=level)\n", "source_code_before": "\"\"\" compiler provides several tools:\n\n 1. inline() -- a function for including C/C++ code within Python\n 2. blitz() -- a function for compiling Numeric expressions to C++\n 3. ext_tools-- a module that helps construct C/C++ extension modules.\n 4. accelerate -- a module that inline accelerates Python functions\n\"\"\"\n\ntry:\n from blitz_tools import blitz\nexcept ImportError:\n pass # Numeric wasn't available \n \nfrom inline_tools import inline\nimport ext_tools\nfrom ext_tools import ext_module, ext_function\ntry:\n from accelerate_tools import accelerate\nexcept:\n pass\n\n#---- testing ----#\n\ndef test(level=10):\n import unittest\n runner = unittest.TextTestRunner()\n runner.run(test_suite(level))\n return runner\n\ndef test_suite(level=1):\n import scipy_test.testing\n try:\n import scipy.weave as this_mod\n except ImportError:\n # punt -- assume we're a stand alone package\n this_mod = weave\n return scipy_test.testing.harvest_test_suites(this_mod,level=level)\n", "methods": [ { "name": "test", "long_name": "test( level = 10 )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "level" ], "start_line": 24, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "__init__.py", "nloc": 4, "complexity": 1, "token_count": 26, "parameters": [ "level" ], "start_line": 30, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 } ], "methods_before": [ { "name": "test", "long_name": "test( level = 10 )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "level" ], "start_line": 24, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "__init__.py", "nloc": 7, "complexity": 2, "token_count": 38, "parameters": [ "level" ], "start_line": 30, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "__init__.py", "nloc": 4, "complexity": 1, "token_count": 26, "parameters": [ "level" ], "start_line": 30, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 } ], "nloc": 27, "complexity": 2, "token_count": 87, "diff_parsed": { "added": [ " import weave", " return scipy_test.testing.harvest_test_suites(weave,level=level)" ], "deleted": [ " try:", " import scipy.weave as this_mod", " except ImportError:", " # punt -- assume we're a stand alone package", " this_mod = weave", " return scipy_test.testing.harvest_test_suites(this_mod,level=level)" ] } }, { "old_path": "weave/build_tools.py", "new_path": "weave/build_tools.py", "filename": "build_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -428,7 +428,7 @@ def import_library_exists():\n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n- import lib2def as lib2def\n+ import scipy_distutils import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\"\"\" Tools for compiling C/C++ code to extension modules\n\n The main function, build_extension(), takes the C/C++ file\n along with some other options and builds a Python extension.\n It uses distutils for most of the heavy lifting.\n \n choose_compiler() is also useful (mainly on windows anyway)\n for trying to determine whether MSVC++ or gcc is available.\n MSVC doesn't handle templates as well, so some of the code emitted\n by the python->C conversions need this info to choose what kind\n of code to create.\n \n The other main thing here is an alternative version of the MingW32\n compiler class. The class makes it possible to build libraries with\n gcc even if the original version of python was built using MSVC. It\n does this by converting a pythonxx.lib file to a libpythonxx.a file.\n Note that you need write access to the pythonxx/lib directory to do this.\n\"\"\"\n\nimport sys,os,string,time\nimport tempfile\nimport exceptions\n\n# If linker is 'gcc', this will convert it to 'g++'\n# necessary to make sure stdc++ is linked in cross-platform way.\nimport distutils.sysconfig\n\nold_init_posix = distutils.sysconfig._init_posix\n\ndef _init_posix():\n old_init_posix()\n ld = distutils.sysconfig._config_vars['LDSHARED']\n #distutils.sysconfig._config_vars['LDSHARED'] = ld.replace('gcc','g++')\n # FreeBSD names gcc as cc, so the above find and replace doesn't work. \n # So, assume first entry in ld is the name of the linker -- gcc or cc or \n # whatever. This is a sane assumption, correct?\n # If the linker is gcc, set it to g++\n link_cmds = ld.split() \n if gcc_exists(link_cmds[0]):\n link_cmds[0] = 'g++'\n ld = ' '.join(link_cmds)\n distutils.sysconfig._config_vars['LDSHARED'] = ld \n\ndistutils.sysconfig._init_posix = _init_posix \n# end force g++\n\n\nclass CompileError(exceptions.Exception):\n pass\n \ndef build_extension(module_path,compiler_name = '',build_dir = None,\n temp_dir = None, verbose = 0, **kw):\n \"\"\" Build the file given by module_path into a Python extension module.\n \n build_extensions uses distutils to build Python extension modules.\n kw arguments not used are passed on to the distutils extension\n module. Directory settings can handle absoulte settings, but don't\n currently expand '~' or environment variables.\n \n module_path -- the full path name to the c file to compile. \n Something like: /full/path/name/module_name.c \n The name of the c/c++ file should be the same as the\n name of the module (i.e. the initmodule() routine)\n compiler_name -- The name of the compiler to use. On Windows if it \n isn't given, MSVC is used if it exists (is found).\n gcc is used as a second choice. If neither are found, \n the default distutils compiler is used. Acceptable \n names are 'gcc', 'msvc' or any of the compiler names \n shown by distutils.ccompiler.show_compilers()\n build_dir -- The location where the resulting extension module \n should be placed. This location must be writable. If\n it isn't, several default locations are tried. If the \n build_dir is not in the current python path, a warning\n is emitted, and it is added to the end of the path.\n build_dir defaults to the current directory.\n temp_dir -- The location where temporary files (*.o or *.obj)\n from the build are placed. This location must be \n writable. If it isn't, several default locations are \n tried. It defaults to tempfile.gettempdir()\n verbose -- 0, 1, or 2. 0 is as quiet as possible. 1 prints\n minimal information. 2 is noisy. \n **kw -- keyword arguments. These are passed on to the \n distutils extension module. Most of the keywords\n are listed below.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n \n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list \n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability) \n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line) \n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n success = 0\n from distutils.core import setup, Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n compiler_name = choose_compiler(compiler_name)\n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n try:\n if verbose == 1:\n print 'Compiling code...'\n \n # set compiler verboseness 2 or more makes it output results\n if verbose > 1: verb = 1 \n else: verb = 0\n \n t1 = time.time() \n # add module to the needed source code files and build extension\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n \n # ! This was fixed at beginning of file by using g++ on most \n # !machines. We'll have to check how to handle it on non-gcc machines \n ## add module to the needed source code files and build extension\n ## FIX this is g++ specific. It probably should be fixed for other\n ## Unices/compilers. Find a generic solution\n #if compiler_name != 'msvc':\n # libraries = kw.get('libraries',[])\n # kw['libraries'] = ['stdc++'] + libraries \n # !\n \n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n platform = sys.platform\n version = sys.version.lower()\n if platform[:5] == 'sunos' and version.find('gcc') != -1:\n extra_link_args = kw.get('extra_link_args',[])\n kw['extra_link_args'] = ['-mimpure-text'] + extra_link_args\n \n ext = Extension(module_name, **kw)\n \n # the switcheroo on SystemExit here is meant to keep command line\n # sessions from exiting when compiles fail.\n builtin = sys.modules['__builtin__']\n old_SysExit = builtin.__dict__['SystemExit']\n builtin.__dict__['SystemExit'] = CompileError\n \n # distutils for MSVC messes with the environment, so we save the\n # current state and restore them afterward.\n import copy\n environ = copy.deepcopy(os.environ)\n try:\n setup(name = module_name, ext_modules = [ext],verbose=verb)\n finally:\n # restore state\n os.environ = environ \n # restore SystemExit\n builtin.__dict__['SystemExit'] = old_SysExit\n t2 = time.time()\n \n if verbose == 1:\n print 'finished compiling (sec): ', t2 - t1 \n success = 1\n configure_python_path(build_dir)\n except SyntaxError: #TypeError:\n success = 0 \n \n # restore argv after our trick... \n restore_sys_argv()\n \n return success\n\nold_argv = []\ndef configure_sys_argv(compiler_name,temp_dir,build_dir):\n # We're gonna play some tricks with argv here to pass info to distutils \n # which is really built for command line use. better way??\n global old_argv\n old_argv = sys.argv[:] \n sys.argv = ['','build_ext','--build-lib', build_dir,\n '--build-temp',temp_dir] \n if compiler_name == 'gcc':\n sys.argv.insert(2,'--compiler='+compiler_name)\n elif compiler_name:\n sys.argv.insert(2,'--compiler='+compiler_name)\n\ndef restore_sys_argv():\n sys.argv = old_argv\n \ndef configure_python_path(build_dir): \n #make sure the module lives in a directory on the python path.\n python_paths = [os.path.abspath(x) for x in sys.path]\n if os.path.abspath(build_dir) not in python_paths:\n #print \"warning: build directory was not part of python path.\"\\\n # \" It has been appended to the path.\"\n sys.path.append(os.path.abspath(build_dir))\n\ndef choose_compiler(compiler_name=''):\n \"\"\" Try and figure out which compiler is gonna be used on windows.\n On other platforms, it just returns whatever value it is given.\n \n converts 'gcc' to 'mingw32' on win32\n \"\"\"\n if sys.platform == 'win32': \n if not compiler_name:\n # On Windows, default to MSVC and use gcc if it wasn't found\n # wasn't found. If neither are found, go with whatever\n # the default is for distutils -- and probably fail...\n if msvc_exists():\n compiler_name = 'msvc'\n elif gcc_exists():\n compiler_name = 'mingw32'\n elif compiler_name == 'gcc':\n compiler_name = 'mingw32'\n else:\n # don't know how to force gcc -- look into this.\n if compiler_name == 'gcc':\n compiler_name = 'unix' \n return compiler_name\n \ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n version = distutils.msvccompiler.get_devstudio_version()\n if version:\n result = 1\n return result\n\ndef configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n print \"warning: specified temp_dir '%s' does not exist \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n\n # final check that that directories are writable. \n if not os.access(temp_dir,os.W_OK):\n msg = \"Either the temp or build directory wasn't writable. Check\" \\\n \" these locations: '%s'\" % temp_dir \n raise ValueError, msg\n return temp_dir\n\ndef configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n print \"warning: specified build_dir '%s' does not exist \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n if build_dir is None:\n #default to building in the home directory of the given module. \n build_dir = os.curdir\n # if it doesn't work use the current directory. This should always\n # be writable. \n if not os.access(build_dir,os.W_OK):\n print \"warning:, neither the module's directory nor the \"\\\n \"current directory are writable. Using the temporary\"\\\n \"directory.\"\n build_dir = tempfile.gettempdir()\n\n # final check that that directories are writable.\n if not os.access(build_dir,os.W_OK):\n msg = \"The build directory wasn't writable. Check\" \\\n \" this location: '%s'\" % build_dir\n raise ValueError, msg\n \n return os.path.abspath(build_dir) \n \nif sys.platform == 'win32':\n import distutils.cygwinccompiler\n # the same as cygwin plus some additional parameters\n class Mingw32CCompiler (distutils.cygwinccompiler.CygwinCCompiler):\n \"\"\" A modified MingW32 compiler compatible with an MSVC built Python.\n \n \"\"\"\n \n compiler_type = 'mingw32'\n \n def __init__ (self,\n verbose=0,\n dry_run=0,\n force=0):\n \n distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose, \n dry_run, force)\n \n # A real mingw32 doesn't need to specify a different entry point,\n # but cygwin 2.91.57 in no-cygwin-mode needs it.\n if self.gcc_version <= \"2.91.57\":\n entry_point = '--entry _DllMain@12'\n else:\n entry_point = ''\n if self.linker_dll == 'dllwrap':\n self.linker = 'dllwrap' + ' --driver-name g++'\n elif self.linker_dll == 'gcc':\n self.linker = 'g++' \n # **changes: eric jones 4/11/01\n # 1. Check for import library on Windows. Build if it doesn't exist.\n if not import_library_exists():\n build_import_library()\n \n # **changes: eric jones 4/11/01\n # 2. increased optimization and turned off all warnings\n # 3. also added --driver-name g++\n #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n # compiler_so='gcc -mno-cygwin -mdll -O2 -w',\n # linker_exe='gcc -mno-cygwin',\n # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' \n # % (self.linker, entry_point))\n self.set_executables(compiler='g++ -mno-cygwin -O2 -w',\n compiler_so='g++ -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',\n linker_exe='g++ -mno-cygwin',\n linker_so='%s -mno-cygwin -mdll -static %s' \n % (self.linker, entry_point))\n \n # Maybe we should also append -mthreads, but then the finished\n # dlls need another dll (mingwm10.dll see Mingw32 docs)\n # (-mthreads: Support thread-safe exception handling on `Mingw32') \n \n # no additional libraries needed \n self.dll_libraries=[]\n \n # __init__ ()\n \n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n # We should also check the version of gcc available...\n #distutils.ccompiler._default_compilers['nt'] = 'mingw32'\n #distutils.ccompiler._default_compilers = (('nt', 'mingw32'))\n # reset the Mingw32 compiler in distutils to the one defined above\n distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler\n \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if os.name == 'nt':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n import scipy_distutils import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print 'WARNING: failed to build import library for gcc. Linking will fail.'\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\n\n\n", "source_code_before": "\"\"\" Tools for compiling C/C++ code to extension modules\n\n The main function, build_extension(), takes the C/C++ file\n along with some other options and builds a Python extension.\n It uses distutils for most of the heavy lifting.\n \n choose_compiler() is also useful (mainly on windows anyway)\n for trying to determine whether MSVC++ or gcc is available.\n MSVC doesn't handle templates as well, so some of the code emitted\n by the python->C conversions need this info to choose what kind\n of code to create.\n \n The other main thing here is an alternative version of the MingW32\n compiler class. The class makes it possible to build libraries with\n gcc even if the original version of python was built using MSVC. It\n does this by converting a pythonxx.lib file to a libpythonxx.a file.\n Note that you need write access to the pythonxx/lib directory to do this.\n\"\"\"\n\nimport sys,os,string,time\nimport tempfile\nimport exceptions\n\n# If linker is 'gcc', this will convert it to 'g++'\n# necessary to make sure stdc++ is linked in cross-platform way.\nimport distutils.sysconfig\n\nold_init_posix = distutils.sysconfig._init_posix\n\ndef _init_posix():\n old_init_posix()\n ld = distutils.sysconfig._config_vars['LDSHARED']\n #distutils.sysconfig._config_vars['LDSHARED'] = ld.replace('gcc','g++')\n # FreeBSD names gcc as cc, so the above find and replace doesn't work. \n # So, assume first entry in ld is the name of the linker -- gcc or cc or \n # whatever. This is a sane assumption, correct?\n # If the linker is gcc, set it to g++\n link_cmds = ld.split() \n if gcc_exists(link_cmds[0]):\n link_cmds[0] = 'g++'\n ld = ' '.join(link_cmds)\n distutils.sysconfig._config_vars['LDSHARED'] = ld \n\ndistutils.sysconfig._init_posix = _init_posix \n# end force g++\n\n\nclass CompileError(exceptions.Exception):\n pass\n \ndef build_extension(module_path,compiler_name = '',build_dir = None,\n temp_dir = None, verbose = 0, **kw):\n \"\"\" Build the file given by module_path into a Python extension module.\n \n build_extensions uses distutils to build Python extension modules.\n kw arguments not used are passed on to the distutils extension\n module. Directory settings can handle absoulte settings, but don't\n currently expand '~' or environment variables.\n \n module_path -- the full path name to the c file to compile. \n Something like: /full/path/name/module_name.c \n The name of the c/c++ file should be the same as the\n name of the module (i.e. the initmodule() routine)\n compiler_name -- The name of the compiler to use. On Windows if it \n isn't given, MSVC is used if it exists (is found).\n gcc is used as a second choice. If neither are found, \n the default distutils compiler is used. Acceptable \n names are 'gcc', 'msvc' or any of the compiler names \n shown by distutils.ccompiler.show_compilers()\n build_dir -- The location where the resulting extension module \n should be placed. This location must be writable. If\n it isn't, several default locations are tried. If the \n build_dir is not in the current python path, a warning\n is emitted, and it is added to the end of the path.\n build_dir defaults to the current directory.\n temp_dir -- The location where temporary files (*.o or *.obj)\n from the build are placed. This location must be \n writable. If it isn't, several default locations are \n tried. It defaults to tempfile.gettempdir()\n verbose -- 0, 1, or 2. 0 is as quiet as possible. 1 prints\n minimal information. 2 is noisy. \n **kw -- keyword arguments. These are passed on to the \n distutils extension module. Most of the keywords\n are listed below.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n \n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list \n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability) \n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line) \n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n success = 0\n from distutils.core import setup, Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n compiler_name = choose_compiler(compiler_name)\n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n try:\n if verbose == 1:\n print 'Compiling code...'\n \n # set compiler verboseness 2 or more makes it output results\n if verbose > 1: verb = 1 \n else: verb = 0\n \n t1 = time.time() \n # add module to the needed source code files and build extension\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n \n # ! This was fixed at beginning of file by using g++ on most \n # !machines. We'll have to check how to handle it on non-gcc machines \n ## add module to the needed source code files and build extension\n ## FIX this is g++ specific. It probably should be fixed for other\n ## Unices/compilers. Find a generic solution\n #if compiler_name != 'msvc':\n # libraries = kw.get('libraries',[])\n # kw['libraries'] = ['stdc++'] + libraries \n # !\n \n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n platform = sys.platform\n version = sys.version.lower()\n if platform[:5] == 'sunos' and version.find('gcc') != -1:\n extra_link_args = kw.get('extra_link_args',[])\n kw['extra_link_args'] = ['-mimpure-text'] + extra_link_args\n \n ext = Extension(module_name, **kw)\n \n # the switcheroo on SystemExit here is meant to keep command line\n # sessions from exiting when compiles fail.\n builtin = sys.modules['__builtin__']\n old_SysExit = builtin.__dict__['SystemExit']\n builtin.__dict__['SystemExit'] = CompileError\n \n # distutils for MSVC messes with the environment, so we save the\n # current state and restore them afterward.\n import copy\n environ = copy.deepcopy(os.environ)\n try:\n setup(name = module_name, ext_modules = [ext],verbose=verb)\n finally:\n # restore state\n os.environ = environ \n # restore SystemExit\n builtin.__dict__['SystemExit'] = old_SysExit\n t2 = time.time()\n \n if verbose == 1:\n print 'finished compiling (sec): ', t2 - t1 \n success = 1\n configure_python_path(build_dir)\n except SyntaxError: #TypeError:\n success = 0 \n \n # restore argv after our trick... \n restore_sys_argv()\n \n return success\n\nold_argv = []\ndef configure_sys_argv(compiler_name,temp_dir,build_dir):\n # We're gonna play some tricks with argv here to pass info to distutils \n # which is really built for command line use. better way??\n global old_argv\n old_argv = sys.argv[:] \n sys.argv = ['','build_ext','--build-lib', build_dir,\n '--build-temp',temp_dir] \n if compiler_name == 'gcc':\n sys.argv.insert(2,'--compiler='+compiler_name)\n elif compiler_name:\n sys.argv.insert(2,'--compiler='+compiler_name)\n\ndef restore_sys_argv():\n sys.argv = old_argv\n \ndef configure_python_path(build_dir): \n #make sure the module lives in a directory on the python path.\n python_paths = [os.path.abspath(x) for x in sys.path]\n if os.path.abspath(build_dir) not in python_paths:\n #print \"warning: build directory was not part of python path.\"\\\n # \" It has been appended to the path.\"\n sys.path.append(os.path.abspath(build_dir))\n\ndef choose_compiler(compiler_name=''):\n \"\"\" Try and figure out which compiler is gonna be used on windows.\n On other platforms, it just returns whatever value it is given.\n \n converts 'gcc' to 'mingw32' on win32\n \"\"\"\n if sys.platform == 'win32': \n if not compiler_name:\n # On Windows, default to MSVC and use gcc if it wasn't found\n # wasn't found. If neither are found, go with whatever\n # the default is for distutils -- and probably fail...\n if msvc_exists():\n compiler_name = 'msvc'\n elif gcc_exists():\n compiler_name = 'mingw32'\n elif compiler_name == 'gcc':\n compiler_name = 'mingw32'\n else:\n # don't know how to force gcc -- look into this.\n if compiler_name == 'gcc':\n compiler_name = 'unix' \n return compiler_name\n \ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n version = distutils.msvccompiler.get_devstudio_version()\n if version:\n result = 1\n return result\n\ndef configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n print \"warning: specified temp_dir '%s' does not exist \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n\n # final check that that directories are writable. \n if not os.access(temp_dir,os.W_OK):\n msg = \"Either the temp or build directory wasn't writable. Check\" \\\n \" these locations: '%s'\" % temp_dir \n raise ValueError, msg\n return temp_dir\n\ndef configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n print \"warning: specified build_dir '%s' does not exist \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n if build_dir is None:\n #default to building in the home directory of the given module. \n build_dir = os.curdir\n # if it doesn't work use the current directory. This should always\n # be writable. \n if not os.access(build_dir,os.W_OK):\n print \"warning:, neither the module's directory nor the \"\\\n \"current directory are writable. Using the temporary\"\\\n \"directory.\"\n build_dir = tempfile.gettempdir()\n\n # final check that that directories are writable.\n if not os.access(build_dir,os.W_OK):\n msg = \"The build directory wasn't writable. Check\" \\\n \" this location: '%s'\" % build_dir\n raise ValueError, msg\n \n return os.path.abspath(build_dir) \n \nif sys.platform == 'win32':\n import distutils.cygwinccompiler\n # the same as cygwin plus some additional parameters\n class Mingw32CCompiler (distutils.cygwinccompiler.CygwinCCompiler):\n \"\"\" A modified MingW32 compiler compatible with an MSVC built Python.\n \n \"\"\"\n \n compiler_type = 'mingw32'\n \n def __init__ (self,\n verbose=0,\n dry_run=0,\n force=0):\n \n distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose, \n dry_run, force)\n \n # A real mingw32 doesn't need to specify a different entry point,\n # but cygwin 2.91.57 in no-cygwin-mode needs it.\n if self.gcc_version <= \"2.91.57\":\n entry_point = '--entry _DllMain@12'\n else:\n entry_point = ''\n if self.linker_dll == 'dllwrap':\n self.linker = 'dllwrap' + ' --driver-name g++'\n elif self.linker_dll == 'gcc':\n self.linker = 'g++' \n # **changes: eric jones 4/11/01\n # 1. Check for import library on Windows. Build if it doesn't exist.\n if not import_library_exists():\n build_import_library()\n \n # **changes: eric jones 4/11/01\n # 2. increased optimization and turned off all warnings\n # 3. also added --driver-name g++\n #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n # compiler_so='gcc -mno-cygwin -mdll -O2 -w',\n # linker_exe='gcc -mno-cygwin',\n # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' \n # % (self.linker, entry_point))\n self.set_executables(compiler='g++ -mno-cygwin -O2 -w',\n compiler_so='g++ -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',\n linker_exe='g++ -mno-cygwin',\n linker_so='%s -mno-cygwin -mdll -static %s' \n % (self.linker, entry_point))\n \n # Maybe we should also append -mthreads, but then the finished\n # dlls need another dll (mingwm10.dll see Mingw32 docs)\n # (-mthreads: Support thread-safe exception handling on `Mingw32') \n \n # no additional libraries needed \n self.dll_libraries=[]\n \n # __init__ ()\n \n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n # We should also check the version of gcc available...\n #distutils.ccompiler._default_compilers['nt'] = 'mingw32'\n #distutils.ccompiler._default_compilers = (('nt', 'mingw32'))\n # reset the Mingw32 compiler in distutils to the one defined above\n distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler\n \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if os.name == 'nt':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n import lib2def as lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print 'WARNING: failed to build import library for gcc. Linking will fail.'\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\n\n\n", "methods": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [], "start_line": 30, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 49, "complexity": 9, "token_count": 364, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 51, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 171, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name , temp_dir , build_dir )", "filename": "build_tools.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [ "compiler_name", "temp_dir", "build_dir" ], "start_line": 224, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "build_tools.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 236, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "configure_python_path", "long_name": "configure_python_path( build_dir )", "filename": "build_tools.py", "nloc": 4, "complexity": 3, "token_count": 51, "parameters": [ "build_dir" ], "start_line": 239, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "build_tools.py", "nloc": 13, "complexity": 7, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 247, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 270, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "build_tools.py", "nloc": 14, "complexity": 4, "token_count": 71, "parameters": [], "start_line": 292, "end_line": 309, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 311, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 327, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_tools.py", "nloc": 22, "complexity": 5, "token_count": 117, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 364, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 2 }, { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "build_tools.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 418, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 428, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 459, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 463, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [], "start_line": 30, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 49, "complexity": 9, "token_count": 364, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 51, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 171, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name , temp_dir , build_dir )", "filename": "build_tools.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [ "compiler_name", "temp_dir", "build_dir" ], "start_line": 224, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "build_tools.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 236, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "configure_python_path", "long_name": "configure_python_path( build_dir )", "filename": "build_tools.py", "nloc": 4, "complexity": 3, "token_count": 51, "parameters": [ "build_dir" ], "start_line": 239, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "build_tools.py", "nloc": 13, "complexity": 7, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 247, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 270, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "build_tools.py", "nloc": 14, "complexity": 4, "token_count": 71, "parameters": [], "start_line": 292, "end_line": 309, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 311, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 327, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_tools.py", "nloc": 22, "complexity": 5, "token_count": 117, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 364, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 2 }, { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "build_tools.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 418, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 428, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 459, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 463, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 428, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 } ], "nloc": 230, "complexity": 56, "token_count": 1440, "diff_parsed": { "added": [ " import scipy_distutils import lib2def" ], "deleted": [ " import lib2def as lib2def" ] } }, { "old_path": "weave/setup.py", "new_path": "weave/setup.py", "filename": "setup.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -15,7 +15,7 @@ def stand_alone_package(with_dependencies = 0):\n try:\n primary = ['weave']\n if with_dependencies:\n- dependencies= ['scipy_distutils','scipy_test'] \n+ dependencies= ['scipy_distutils','scipy_test','scipy_base'] \n else:\n dependencies = [] \n \n", "added_lines": 1, "deleted_lines": 1, "source_code": "#!/usr/bin/env python\nimport os,sys\nfrom scipy_distutils.core import setup\nfrom scipy_distutils.misc_util import get_path, merge_config_dicts\nfrom scipy_distutils.misc_util import package_config\n\n# Enough changes to bump the number. We need a global method for\n# versioning\nversion = \"0.3.0.alpha\"\n \ndef stand_alone_package(with_dependencies = 0):\n path = get_path(__name__)\n old_path = os.getcwd()\n os.chdir(path)\n try:\n primary = ['weave']\n if with_dependencies:\n dependencies= ['scipy_distutils','scipy_test','scipy_base'] \n else:\n dependencies = [] \n \n print 'dep:', dependencies\n config_dict = package_config(primary,dependencies)\n\n setup (name = \"weave\",\n version = version,\n description = \"Tools for inlining C/C++ in Python\",\n author = \"Eric Jones\",\n author_email = \"eric@enthought.com\",\n licence = \"SciPy License (BSD Style)\",\n url = 'http://www.scipy.org',\n **config_dict\n ) \n finally:\n os.chdir(old_path)\n\nif __name__ == '__main__':\n import sys\n if '--without-dependencies' in sys.argv:\n with_dependencies = 0\n sys.argv.remove('--without-dependencies')\n else:\n with_dependencies = 1 \n stand_alone_package(with_dependencies)\n \n", "source_code_before": "#!/usr/bin/env python\nimport os,sys\nfrom scipy_distutils.core import setup\nfrom scipy_distutils.misc_util import get_path, merge_config_dicts\nfrom scipy_distutils.misc_util import package_config\n\n# Enough changes to bump the number. We need a global method for\n# versioning\nversion = \"0.3.0.alpha\"\n \ndef stand_alone_package(with_dependencies = 0):\n path = get_path(__name__)\n old_path = os.getcwd()\n os.chdir(path)\n try:\n primary = ['weave']\n if with_dependencies:\n dependencies= ['scipy_distutils','scipy_test'] \n else:\n dependencies = [] \n \n print 'dep:', dependencies\n config_dict = package_config(primary,dependencies)\n\n setup (name = \"weave\",\n version = version,\n description = \"Tools for inlining C/C++ in Python\",\n author = \"Eric Jones\",\n author_email = \"eric@enthought.com\",\n licence = \"SciPy License (BSD Style)\",\n url = 'http://www.scipy.org',\n **config_dict\n ) \n finally:\n os.chdir(old_path)\n\nif __name__ == '__main__':\n import sys\n if '--without-dependencies' in sys.argv:\n with_dependencies = 0\n sys.argv.remove('--without-dependencies')\n else:\n with_dependencies = 1 \n stand_alone_package(with_dependencies)\n \n", "methods": [ { "name": "stand_alone_package", "long_name": "stand_alone_package( with_dependencies = 0 )", "filename": "setup.py", "nloc": 23, "complexity": 3, "token_count": 104, "parameters": [ "with_dependencies" ], "start_line": 11, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 } ], "methods_before": [ { "name": "stand_alone_package", "long_name": "stand_alone_package( with_dependencies = 0 )", "filename": "setup.py", "nloc": 23, "complexity": 3, "token_count": 102, "parameters": [ "with_dependencies" ], "start_line": 11, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "stand_alone_package", "long_name": "stand_alone_package( with_dependencies = 0 )", "filename": "setup.py", "nloc": 23, "complexity": 3, "token_count": 104, "parameters": [ "with_dependencies" ], "start_line": 11, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 } ], "nloc": 36, "complexity": 3, "token_count": 166, "diff_parsed": { "added": [ " dependencies= ['scipy_distutils','scipy_test','scipy_base']" ], "deleted": [ " dependencies= ['scipy_distutils','scipy_test']" ] } } ] }, { "hash": "9dec5004a2593a123fb80eefcb5d73a229cb7501", "msg": "removed some old comments about stdc++ and linking issues with gcc. They are\nno longer pertinent because we have moved to linking with g++ to solve\nthe problem.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-09-19T03:43:32+00:00", "author_timezone": 0, "committer_date": "2002-09-19T03:43:32+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "9d56fb08134529c827b9bbcf0854d43cf7898d9f" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 11, "insertions": 1, "lines": 12, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "weave/build_tools.py", "new_path": "weave/build_tools.py", "filename": "build_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -167,17 +167,7 @@ def build_extension(module_path,compiler_name = '',build_dir = None,\n # add module to the needed source code files and build extension\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n- \n- # ! This was fixed at beginning of file by using g++ on most \n- # !machines. We'll have to check how to handle it on non-gcc machines \n- ## add module to the needed source code files and build extension\n- ## FIX this is g++ specific. It probably should be fixed for other\n- ## Unices/compilers. Find a generic solution\n- #if compiler_name != 'msvc':\n- # libraries = kw.get('libraries',[])\n- # kw['libraries'] = ['stdc++'] + libraries \n- # !\n- \n+ \n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n", "added_lines": 1, "deleted_lines": 11, "source_code": "\"\"\" Tools for compiling C/C++ code to extension modules\n\n The main function, build_extension(), takes the C/C++ file\n along with some other options and builds a Python extension.\n It uses distutils for most of the heavy lifting.\n \n choose_compiler() is also useful (mainly on windows anyway)\n for trying to determine whether MSVC++ or gcc is available.\n MSVC doesn't handle templates as well, so some of the code emitted\n by the python->C conversions need this info to choose what kind\n of code to create.\n \n The other main thing here is an alternative version of the MingW32\n compiler class. The class makes it possible to build libraries with\n gcc even if the original version of python was built using MSVC. It\n does this by converting a pythonxx.lib file to a libpythonxx.a file.\n Note that you need write access to the pythonxx/lib directory to do this.\n\"\"\"\n\nimport sys,os,string,time\nimport tempfile\nimport exceptions\n\n# If linker is 'gcc', this will convert it to 'g++'\n# necessary to make sure stdc++ is linked in cross-platform way.\nimport distutils.sysconfig\n\nold_init_posix = distutils.sysconfig._init_posix\n\ndef _init_posix():\n old_init_posix()\n ld = distutils.sysconfig._config_vars['LDSHARED']\n #distutils.sysconfig._config_vars['LDSHARED'] = ld.replace('gcc','g++')\n # FreeBSD names gcc as cc, so the above find and replace doesn't work. \n # So, assume first entry in ld is the name of the linker -- gcc or cc or \n # whatever. This is a sane assumption, correct?\n # If the linker is gcc, set it to g++\n link_cmds = ld.split() \n if gcc_exists(link_cmds[0]):\n link_cmds[0] = 'g++'\n ld = ' '.join(link_cmds)\n distutils.sysconfig._config_vars['LDSHARED'] = ld \n\ndistutils.sysconfig._init_posix = _init_posix \n# end force g++\n\n\nclass CompileError(exceptions.Exception):\n pass\n \ndef build_extension(module_path,compiler_name = '',build_dir = None,\n temp_dir = None, verbose = 0, **kw):\n \"\"\" Build the file given by module_path into a Python extension module.\n \n build_extensions uses distutils to build Python extension modules.\n kw arguments not used are passed on to the distutils extension\n module. Directory settings can handle absoulte settings, but don't\n currently expand '~' or environment variables.\n \n module_path -- the full path name to the c file to compile. \n Something like: /full/path/name/module_name.c \n The name of the c/c++ file should be the same as the\n name of the module (i.e. the initmodule() routine)\n compiler_name -- The name of the compiler to use. On Windows if it \n isn't given, MSVC is used if it exists (is found).\n gcc is used as a second choice. If neither are found, \n the default distutils compiler is used. Acceptable \n names are 'gcc', 'msvc' or any of the compiler names \n shown by distutils.ccompiler.show_compilers()\n build_dir -- The location where the resulting extension module \n should be placed. This location must be writable. If\n it isn't, several default locations are tried. If the \n build_dir is not in the current python path, a warning\n is emitted, and it is added to the end of the path.\n build_dir defaults to the current directory.\n temp_dir -- The location where temporary files (*.o or *.obj)\n from the build are placed. This location must be \n writable. If it isn't, several default locations are \n tried. It defaults to tempfile.gettempdir()\n verbose -- 0, 1, or 2. 0 is as quiet as possible. 1 prints\n minimal information. 2 is noisy. \n **kw -- keyword arguments. These are passed on to the \n distutils extension module. Most of the keywords\n are listed below.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n \n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list \n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability) \n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line) \n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n success = 0\n from distutils.core import setup, Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n compiler_name = choose_compiler(compiler_name)\n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n try:\n if verbose == 1:\n print 'Compiling code...'\n \n # set compiler verboseness 2 or more makes it output results\n if verbose > 1: verb = 1 \n else: verb = 0\n \n t1 = time.time() \n # add module to the needed source code files and build extension\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n \n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n platform = sys.platform\n version = sys.version.lower()\n if platform[:5] == 'sunos' and version.find('gcc') != -1:\n extra_link_args = kw.get('extra_link_args',[])\n kw['extra_link_args'] = ['-mimpure-text'] + extra_link_args\n \n ext = Extension(module_name, **kw)\n \n # the switcheroo on SystemExit here is meant to keep command line\n # sessions from exiting when compiles fail.\n builtin = sys.modules['__builtin__']\n old_SysExit = builtin.__dict__['SystemExit']\n builtin.__dict__['SystemExit'] = CompileError\n \n # distutils for MSVC messes with the environment, so we save the\n # current state and restore them afterward.\n import copy\n environ = copy.deepcopy(os.environ)\n try:\n setup(name = module_name, ext_modules = [ext],verbose=verb)\n finally:\n # restore state\n os.environ = environ \n # restore SystemExit\n builtin.__dict__['SystemExit'] = old_SysExit\n t2 = time.time()\n \n if verbose == 1:\n print 'finished compiling (sec): ', t2 - t1 \n success = 1\n configure_python_path(build_dir)\n except SyntaxError: #TypeError:\n success = 0 \n \n # restore argv after our trick... \n restore_sys_argv()\n \n return success\n\nold_argv = []\ndef configure_sys_argv(compiler_name,temp_dir,build_dir):\n # We're gonna play some tricks with argv here to pass info to distutils \n # which is really built for command line use. better way??\n global old_argv\n old_argv = sys.argv[:] \n sys.argv = ['','build_ext','--build-lib', build_dir,\n '--build-temp',temp_dir] \n if compiler_name == 'gcc':\n sys.argv.insert(2,'--compiler='+compiler_name)\n elif compiler_name:\n sys.argv.insert(2,'--compiler='+compiler_name)\n\ndef restore_sys_argv():\n sys.argv = old_argv\n \ndef configure_python_path(build_dir): \n #make sure the module lives in a directory on the python path.\n python_paths = [os.path.abspath(x) for x in sys.path]\n if os.path.abspath(build_dir) not in python_paths:\n #print \"warning: build directory was not part of python path.\"\\\n # \" It has been appended to the path.\"\n sys.path.append(os.path.abspath(build_dir))\n\ndef choose_compiler(compiler_name=''):\n \"\"\" Try and figure out which compiler is gonna be used on windows.\n On other platforms, it just returns whatever value it is given.\n \n converts 'gcc' to 'mingw32' on win32\n \"\"\"\n if sys.platform == 'win32': \n if not compiler_name:\n # On Windows, default to MSVC and use gcc if it wasn't found\n # wasn't found. If neither are found, go with whatever\n # the default is for distutils -- and probably fail...\n if msvc_exists():\n compiler_name = 'msvc'\n elif gcc_exists():\n compiler_name = 'mingw32'\n elif compiler_name == 'gcc':\n compiler_name = 'mingw32'\n else:\n # don't know how to force gcc -- look into this.\n if compiler_name == 'gcc':\n compiler_name = 'unix' \n return compiler_name\n \ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n version = distutils.msvccompiler.get_devstudio_version()\n if version:\n result = 1\n return result\n\ndef configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n print \"warning: specified temp_dir '%s' does not exist \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n\n # final check that that directories are writable. \n if not os.access(temp_dir,os.W_OK):\n msg = \"Either the temp or build directory wasn't writable. Check\" \\\n \" these locations: '%s'\" % temp_dir \n raise ValueError, msg\n return temp_dir\n\ndef configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n print \"warning: specified build_dir '%s' does not exist \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n if build_dir is None:\n #default to building in the home directory of the given module. \n build_dir = os.curdir\n # if it doesn't work use the current directory. This should always\n # be writable. \n if not os.access(build_dir,os.W_OK):\n print \"warning:, neither the module's directory nor the \"\\\n \"current directory are writable. Using the temporary\"\\\n \"directory.\"\n build_dir = tempfile.gettempdir()\n\n # final check that that directories are writable.\n if not os.access(build_dir,os.W_OK):\n msg = \"The build directory wasn't writable. Check\" \\\n \" this location: '%s'\" % build_dir\n raise ValueError, msg\n \n return os.path.abspath(build_dir) \n \nif sys.platform == 'win32':\n import distutils.cygwinccompiler\n # the same as cygwin plus some additional parameters\n class Mingw32CCompiler (distutils.cygwinccompiler.CygwinCCompiler):\n \"\"\" A modified MingW32 compiler compatible with an MSVC built Python.\n \n \"\"\"\n \n compiler_type = 'mingw32'\n \n def __init__ (self,\n verbose=0,\n dry_run=0,\n force=0):\n \n distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose, \n dry_run, force)\n \n # A real mingw32 doesn't need to specify a different entry point,\n # but cygwin 2.91.57 in no-cygwin-mode needs it.\n if self.gcc_version <= \"2.91.57\":\n entry_point = '--entry _DllMain@12'\n else:\n entry_point = ''\n if self.linker_dll == 'dllwrap':\n self.linker = 'dllwrap' + ' --driver-name g++'\n elif self.linker_dll == 'gcc':\n self.linker = 'g++' \n # **changes: eric jones 4/11/01\n # 1. Check for import library on Windows. Build if it doesn't exist.\n if not import_library_exists():\n build_import_library()\n \n # **changes: eric jones 4/11/01\n # 2. increased optimization and turned off all warnings\n # 3. also added --driver-name g++\n #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n # compiler_so='gcc -mno-cygwin -mdll -O2 -w',\n # linker_exe='gcc -mno-cygwin',\n # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' \n # % (self.linker, entry_point))\n self.set_executables(compiler='g++ -mno-cygwin -O2 -w',\n compiler_so='g++ -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',\n linker_exe='g++ -mno-cygwin',\n linker_so='%s -mno-cygwin -mdll -static %s' \n % (self.linker, entry_point))\n \n # Maybe we should also append -mthreads, but then the finished\n # dlls need another dll (mingwm10.dll see Mingw32 docs)\n # (-mthreads: Support thread-safe exception handling on `Mingw32') \n \n # no additional libraries needed \n self.dll_libraries=[]\n \n # __init__ ()\n \n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n # We should also check the version of gcc available...\n #distutils.ccompiler._default_compilers['nt'] = 'mingw32'\n #distutils.ccompiler._default_compilers = (('nt', 'mingw32'))\n # reset the Mingw32 compiler in distutils to the one defined above\n distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler\n \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if os.name == 'nt':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n import scipy_distutils import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print 'WARNING: failed to build import library for gcc. Linking will fail.'\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\n\n\n", "source_code_before": "\"\"\" Tools for compiling C/C++ code to extension modules\n\n The main function, build_extension(), takes the C/C++ file\n along with some other options and builds a Python extension.\n It uses distutils for most of the heavy lifting.\n \n choose_compiler() is also useful (mainly on windows anyway)\n for trying to determine whether MSVC++ or gcc is available.\n MSVC doesn't handle templates as well, so some of the code emitted\n by the python->C conversions need this info to choose what kind\n of code to create.\n \n The other main thing here is an alternative version of the MingW32\n compiler class. The class makes it possible to build libraries with\n gcc even if the original version of python was built using MSVC. It\n does this by converting a pythonxx.lib file to a libpythonxx.a file.\n Note that you need write access to the pythonxx/lib directory to do this.\n\"\"\"\n\nimport sys,os,string,time\nimport tempfile\nimport exceptions\n\n# If linker is 'gcc', this will convert it to 'g++'\n# necessary to make sure stdc++ is linked in cross-platform way.\nimport distutils.sysconfig\n\nold_init_posix = distutils.sysconfig._init_posix\n\ndef _init_posix():\n old_init_posix()\n ld = distutils.sysconfig._config_vars['LDSHARED']\n #distutils.sysconfig._config_vars['LDSHARED'] = ld.replace('gcc','g++')\n # FreeBSD names gcc as cc, so the above find and replace doesn't work. \n # So, assume first entry in ld is the name of the linker -- gcc or cc or \n # whatever. This is a sane assumption, correct?\n # If the linker is gcc, set it to g++\n link_cmds = ld.split() \n if gcc_exists(link_cmds[0]):\n link_cmds[0] = 'g++'\n ld = ' '.join(link_cmds)\n distutils.sysconfig._config_vars['LDSHARED'] = ld \n\ndistutils.sysconfig._init_posix = _init_posix \n# end force g++\n\n\nclass CompileError(exceptions.Exception):\n pass\n \ndef build_extension(module_path,compiler_name = '',build_dir = None,\n temp_dir = None, verbose = 0, **kw):\n \"\"\" Build the file given by module_path into a Python extension module.\n \n build_extensions uses distutils to build Python extension modules.\n kw arguments not used are passed on to the distutils extension\n module. Directory settings can handle absoulte settings, but don't\n currently expand '~' or environment variables.\n \n module_path -- the full path name to the c file to compile. \n Something like: /full/path/name/module_name.c \n The name of the c/c++ file should be the same as the\n name of the module (i.e. the initmodule() routine)\n compiler_name -- The name of the compiler to use. On Windows if it \n isn't given, MSVC is used if it exists (is found).\n gcc is used as a second choice. If neither are found, \n the default distutils compiler is used. Acceptable \n names are 'gcc', 'msvc' or any of the compiler names \n shown by distutils.ccompiler.show_compilers()\n build_dir -- The location where the resulting extension module \n should be placed. This location must be writable. If\n it isn't, several default locations are tried. If the \n build_dir is not in the current python path, a warning\n is emitted, and it is added to the end of the path.\n build_dir defaults to the current directory.\n temp_dir -- The location where temporary files (*.o or *.obj)\n from the build are placed. This location must be \n writable. If it isn't, several default locations are \n tried. It defaults to tempfile.gettempdir()\n verbose -- 0, 1, or 2. 0 is as quiet as possible. 1 prints\n minimal information. 2 is noisy. \n **kw -- keyword arguments. These are passed on to the \n distutils extension module. Most of the keywords\n are listed below.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n \n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list \n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability) \n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line) \n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n success = 0\n from distutils.core import setup, Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n compiler_name = choose_compiler(compiler_name)\n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n try:\n if verbose == 1:\n print 'Compiling code...'\n \n # set compiler verboseness 2 or more makes it output results\n if verbose > 1: verb = 1 \n else: verb = 0\n \n t1 = time.time() \n # add module to the needed source code files and build extension\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n \n # ! This was fixed at beginning of file by using g++ on most \n # !machines. We'll have to check how to handle it on non-gcc machines \n ## add module to the needed source code files and build extension\n ## FIX this is g++ specific. It probably should be fixed for other\n ## Unices/compilers. Find a generic solution\n #if compiler_name != 'msvc':\n # libraries = kw.get('libraries',[])\n # kw['libraries'] = ['stdc++'] + libraries \n # !\n \n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n platform = sys.platform\n version = sys.version.lower()\n if platform[:5] == 'sunos' and version.find('gcc') != -1:\n extra_link_args = kw.get('extra_link_args',[])\n kw['extra_link_args'] = ['-mimpure-text'] + extra_link_args\n \n ext = Extension(module_name, **kw)\n \n # the switcheroo on SystemExit here is meant to keep command line\n # sessions from exiting when compiles fail.\n builtin = sys.modules['__builtin__']\n old_SysExit = builtin.__dict__['SystemExit']\n builtin.__dict__['SystemExit'] = CompileError\n \n # distutils for MSVC messes with the environment, so we save the\n # current state and restore them afterward.\n import copy\n environ = copy.deepcopy(os.environ)\n try:\n setup(name = module_name, ext_modules = [ext],verbose=verb)\n finally:\n # restore state\n os.environ = environ \n # restore SystemExit\n builtin.__dict__['SystemExit'] = old_SysExit\n t2 = time.time()\n \n if verbose == 1:\n print 'finished compiling (sec): ', t2 - t1 \n success = 1\n configure_python_path(build_dir)\n except SyntaxError: #TypeError:\n success = 0 \n \n # restore argv after our trick... \n restore_sys_argv()\n \n return success\n\nold_argv = []\ndef configure_sys_argv(compiler_name,temp_dir,build_dir):\n # We're gonna play some tricks with argv here to pass info to distutils \n # which is really built for command line use. better way??\n global old_argv\n old_argv = sys.argv[:] \n sys.argv = ['','build_ext','--build-lib', build_dir,\n '--build-temp',temp_dir] \n if compiler_name == 'gcc':\n sys.argv.insert(2,'--compiler='+compiler_name)\n elif compiler_name:\n sys.argv.insert(2,'--compiler='+compiler_name)\n\ndef restore_sys_argv():\n sys.argv = old_argv\n \ndef configure_python_path(build_dir): \n #make sure the module lives in a directory on the python path.\n python_paths = [os.path.abspath(x) for x in sys.path]\n if os.path.abspath(build_dir) not in python_paths:\n #print \"warning: build directory was not part of python path.\"\\\n # \" It has been appended to the path.\"\n sys.path.append(os.path.abspath(build_dir))\n\ndef choose_compiler(compiler_name=''):\n \"\"\" Try and figure out which compiler is gonna be used on windows.\n On other platforms, it just returns whatever value it is given.\n \n converts 'gcc' to 'mingw32' on win32\n \"\"\"\n if sys.platform == 'win32': \n if not compiler_name:\n # On Windows, default to MSVC and use gcc if it wasn't found\n # wasn't found. If neither are found, go with whatever\n # the default is for distutils -- and probably fail...\n if msvc_exists():\n compiler_name = 'msvc'\n elif gcc_exists():\n compiler_name = 'mingw32'\n elif compiler_name == 'gcc':\n compiler_name = 'mingw32'\n else:\n # don't know how to force gcc -- look into this.\n if compiler_name == 'gcc':\n compiler_name = 'unix' \n return compiler_name\n \ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n version = distutils.msvccompiler.get_devstudio_version()\n if version:\n result = 1\n return result\n\ndef configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n print \"warning: specified temp_dir '%s' does not exist \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n\n # final check that that directories are writable. \n if not os.access(temp_dir,os.W_OK):\n msg = \"Either the temp or build directory wasn't writable. Check\" \\\n \" these locations: '%s'\" % temp_dir \n raise ValueError, msg\n return temp_dir\n\ndef configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n print \"warning: specified build_dir '%s' does not exist \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n if build_dir is None:\n #default to building in the home directory of the given module. \n build_dir = os.curdir\n # if it doesn't work use the current directory. This should always\n # be writable. \n if not os.access(build_dir,os.W_OK):\n print \"warning:, neither the module's directory nor the \"\\\n \"current directory are writable. Using the temporary\"\\\n \"directory.\"\n build_dir = tempfile.gettempdir()\n\n # final check that that directories are writable.\n if not os.access(build_dir,os.W_OK):\n msg = \"The build directory wasn't writable. Check\" \\\n \" this location: '%s'\" % build_dir\n raise ValueError, msg\n \n return os.path.abspath(build_dir) \n \nif sys.platform == 'win32':\n import distutils.cygwinccompiler\n # the same as cygwin plus some additional parameters\n class Mingw32CCompiler (distutils.cygwinccompiler.CygwinCCompiler):\n \"\"\" A modified MingW32 compiler compatible with an MSVC built Python.\n \n \"\"\"\n \n compiler_type = 'mingw32'\n \n def __init__ (self,\n verbose=0,\n dry_run=0,\n force=0):\n \n distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose, \n dry_run, force)\n \n # A real mingw32 doesn't need to specify a different entry point,\n # but cygwin 2.91.57 in no-cygwin-mode needs it.\n if self.gcc_version <= \"2.91.57\":\n entry_point = '--entry _DllMain@12'\n else:\n entry_point = ''\n if self.linker_dll == 'dllwrap':\n self.linker = 'dllwrap' + ' --driver-name g++'\n elif self.linker_dll == 'gcc':\n self.linker = 'g++' \n # **changes: eric jones 4/11/01\n # 1. Check for import library on Windows. Build if it doesn't exist.\n if not import_library_exists():\n build_import_library()\n \n # **changes: eric jones 4/11/01\n # 2. increased optimization and turned off all warnings\n # 3. also added --driver-name g++\n #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n # compiler_so='gcc -mno-cygwin -mdll -O2 -w',\n # linker_exe='gcc -mno-cygwin',\n # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' \n # % (self.linker, entry_point))\n self.set_executables(compiler='g++ -mno-cygwin -O2 -w',\n compiler_so='g++ -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',\n linker_exe='g++ -mno-cygwin',\n linker_so='%s -mno-cygwin -mdll -static %s' \n % (self.linker, entry_point))\n \n # Maybe we should also append -mthreads, but then the finished\n # dlls need another dll (mingwm10.dll see Mingw32 docs)\n # (-mthreads: Support thread-safe exception handling on `Mingw32') \n \n # no additional libraries needed \n self.dll_libraries=[]\n \n # __init__ ()\n \n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n # We should also check the version of gcc available...\n #distutils.ccompiler._default_compilers['nt'] = 'mingw32'\n #distutils.ccompiler._default_compilers = (('nt', 'mingw32'))\n # reset the Mingw32 compiler in distutils to the one defined above\n distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler\n \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if os.name == 'nt':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n import scipy_distutils import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print 'WARNING: failed to build import library for gcc. Linking will fail.'\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\n\n\n", "methods": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [], "start_line": 30, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 49, "complexity": 9, "token_count": 364, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 51, "end_line": 211, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 161, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name , temp_dir , build_dir )", "filename": "build_tools.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [ "compiler_name", "temp_dir", "build_dir" ], "start_line": 214, "end_line": 224, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "build_tools.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 226, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "configure_python_path", "long_name": "configure_python_path( build_dir )", "filename": "build_tools.py", "nloc": 4, "complexity": 3, "token_count": 51, "parameters": [ "build_dir" ], "start_line": 229, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "build_tools.py", "nloc": 13, "complexity": 7, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 237, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 260, "end_line": 280, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "build_tools.py", "nloc": 14, "complexity": 4, "token_count": 71, "parameters": [], "start_line": 282, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 301, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 317, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_tools.py", "nloc": 22, "complexity": 5, "token_count": 117, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 354, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 2 }, { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "build_tools.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 408, "end_line": 416, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 418, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 449, "end_line": 451, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 453, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [], "start_line": 30, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 49, "complexity": 9, "token_count": 364, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 51, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 171, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name , temp_dir , build_dir )", "filename": "build_tools.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [ "compiler_name", "temp_dir", "build_dir" ], "start_line": 224, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "build_tools.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 236, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "configure_python_path", "long_name": "configure_python_path( build_dir )", "filename": "build_tools.py", "nloc": 4, "complexity": 3, "token_count": 51, "parameters": [ "build_dir" ], "start_line": 239, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "build_tools.py", "nloc": 13, "complexity": 7, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 247, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 270, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "build_tools.py", "nloc": 14, "complexity": 4, "token_count": 71, "parameters": [], "start_line": 292, "end_line": 309, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 311, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 327, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_tools.py", "nloc": 22, "complexity": 5, "token_count": 117, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 364, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 2 }, { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "build_tools.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 418, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 428, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 459, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 463, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 49, "complexity": 9, "token_count": 364, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 51, "end_line": 211, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 161, "top_nesting_level": 0 } ], "nloc": 230, "complexity": 56, "token_count": 1440, "diff_parsed": { "added": [ "" ], "deleted": [ "", " # ! This was fixed at beginning of file by using g++ on most", " # !machines. We'll have to check how to handle it on non-gcc machines", " ## add module to the needed source code files and build extension", " ## FIX this is g++ specific. It probably should be fixed for other", " ## Unices/compilers. Find a generic solution", " #if compiler_name != 'msvc':", " # libraries = kw.get('libraries',[])", " # kw['libraries'] = ['stdc++'] + libraries", " # !", "" ] } } ] }, { "hash": "200bff5384ca06d4d61570a576f94ff63b6c335d", "msg": "added yet another directory into the path of intermediate files generated by\nweave. This is needed so that people switching between compilers don't end\nup trying to link c++ object files built with incompatible compilers together.\n\nchanged Py_INCREF to a Py_XINCREF to guard against NULL pointer problems\nin convert_to_xxx routines.\n\nlengthened the type_names strings for Numeric type names in\nstandard_array_spec. It was shorter than some of the names. yikes!\n\nchoose_compiler stuff is no longer done by ext_modules. This was used\nto allow xxx_convterters and xxx_info objects to generate different code\ndepending on which compiler was used. This is no longer done, and I don't\nthink it should be necessary going forward. I've left a little of the code\nin case I'm wrong, but will probably hack it out soon.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-09-19T07:08:30+00:00", "author_timezone": 0, "committer_date": "2002-09-19T07:08:30+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "9dec5004a2593a123fb80eefcb5d73a229cb7501" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 17, "insertions": 65, "lines": 82, "files": 7, "dmm_unit_size": 0.9444444444444444, "dmm_unit_complexity": 0.8333333333333334, "dmm_unit_interfacing": 0.9444444444444444, "modified_files": [ { "old_path": "weave/blitz-20001213/blitz/config.h", "new_path": "weave/blitz-20001213/blitz/config.h", "filename": "config.h", "extension": "h", "change_type": "MODIFY", "diff": "@@ -52,7 +52,7 @@\n #define BZ_ENUM_COMPUTATIONS_WITH_CAST\n #define BZ_HAVE_COMPLEX\n \n-#ifdef __GNUC__ && __GNUC__==3\n+#if (__GNUC__ && __GNUC__ == 3)\n #define BZ_HAVE_NUMERIC_LIMITS\n #else\n #undef BZ_HAVE_NUMERIC_LIMITS\n", "added_lines": 1, "deleted_lines": 1, "source_code": "/******************************************************************************\n * config.h Compiler language support flags\n *\n * This file was generated automatically by the script bzconfig.\n * You should rerun bzconfig each time you switch compilers, install new\n * standard libraries, or change compiler versions.\n *\n */\n\n \n#ifndef BZ_CONFIG_H\n#define BZ_CONFIG_H\n \n#define BZ_COMPILER_NAME \"g++\"\n#define BZ_COMPILER_OPTIONS \"-ftemplate-depth-30\"\n#define BZ_OS_NAME \"Linux 2.2.14-5.0\"\n#define BZ_BZCONFIG_DATE \"Tue Apr 10 21:43:49 EDT 2001\"\n#define BZ_PLATFORM \"i686-pc-linux-gnu\"\n \n#define BZ_NAMESPACES\n#define BZ_EXCEPTIONS\n#define BZ_RTTI\n#define BZ_MEMBER_CONSTANTS\n#undef BZ_OLD_FOR_SCOPING\n#define BZ_EXPLICIT\n#define BZ_MUTABLE\n#define BZ_TYPENAME\n#undef BZ_NCEG_RESTRICT\n#define BZ_NCEG_RESTRICT_EGCS\n#define BZ_BOOL\n#define BZ_CONST_CAST\n#define BZ_STATIC_CAST\n#define BZ_REINTERPRET_CAST\n#define BZ_DYNAMIC_CAST\n#define BZ_TEMPLATES\n#define BZ_PARTIAL_SPECIALIZATION\n#define BZ_PARTIAL_ORDERING\n#define BZ_DEFAULT_TEMPLATE_PARAMETERS\n#define BZ_MEMBER_TEMPLATES\n#define BZ_MEMBER_TEMPLATES_OUTSIDE_CLASS\n#define BZ_FULL_SPECIALIZATION_SYNTAX\n#define BZ_FUNCTION_NONTYPE_PARAMETERS\n#define BZ_TEMPLATE_QUALIFIED_BASE_CLASS\n#define BZ_TEMPLATE_QUALIFIED_RETURN_TYPE\n#define BZ_EXPLICIT_TEMPLATE_FUNCTION_QUALIFICATION\n#define BZ_TEMPLATES_AS_TEMPLATE_ARGUMENTS\n#define BZ_TEMPLATE_KEYWORD_QUALIFIER\n#define BZ_TEMPLATE_SCOPED_ARGUMENT_MATCHING\n#define BZ_TYPE_PROMOTION\n#define BZ_USE_NUMTRAIT\n#define BZ_ENUM_COMPUTATIONS\n#define BZ_ENUM_COMPUTATIONS_WITH_CAST\n#define BZ_HAVE_COMPLEX\n\n#if (__GNUC__ && __GNUC__ == 3)\n #define BZ_HAVE_NUMERIC_LIMITS\n#else\n #undef BZ_HAVE_NUMERIC_LIMITS\n#endif\n\n#define BZ_HAVE_CLIMITS\n#define BZ_HAVE_VALARRAY\n#undef BZ_HAVE_COMPLEX_MATH\n#define BZ_HAVE_IEEE_MATH\n#undef BZ_HAVE_SYSTEM_V_MATH\n#define BZ_MATH_FN_IN_NAMESPACE_STD\n#define BZ_COMPLEX_MATH_IN_NAMESPACE_STD\n#define BZ_HAVE_STD\n#define BZ_HAVE_STL\n#define BZ_HAVE_RUSAGE\n \n#endif // BZ_CONFIG_H\n", "source_code_before": "/******************************************************************************\n * config.h Compiler language support flags\n *\n * This file was generated automatically by the script bzconfig.\n * You should rerun bzconfig each time you switch compilers, install new\n * standard libraries, or change compiler versions.\n *\n */\n\n \n#ifndef BZ_CONFIG_H\n#define BZ_CONFIG_H\n \n#define BZ_COMPILER_NAME \"g++\"\n#define BZ_COMPILER_OPTIONS \"-ftemplate-depth-30\"\n#define BZ_OS_NAME \"Linux 2.2.14-5.0\"\n#define BZ_BZCONFIG_DATE \"Tue Apr 10 21:43:49 EDT 2001\"\n#define BZ_PLATFORM \"i686-pc-linux-gnu\"\n \n#define BZ_NAMESPACES\n#define BZ_EXCEPTIONS\n#define BZ_RTTI\n#define BZ_MEMBER_CONSTANTS\n#undef BZ_OLD_FOR_SCOPING\n#define BZ_EXPLICIT\n#define BZ_MUTABLE\n#define BZ_TYPENAME\n#undef BZ_NCEG_RESTRICT\n#define BZ_NCEG_RESTRICT_EGCS\n#define BZ_BOOL\n#define BZ_CONST_CAST\n#define BZ_STATIC_CAST\n#define BZ_REINTERPRET_CAST\n#define BZ_DYNAMIC_CAST\n#define BZ_TEMPLATES\n#define BZ_PARTIAL_SPECIALIZATION\n#define BZ_PARTIAL_ORDERING\n#define BZ_DEFAULT_TEMPLATE_PARAMETERS\n#define BZ_MEMBER_TEMPLATES\n#define BZ_MEMBER_TEMPLATES_OUTSIDE_CLASS\n#define BZ_FULL_SPECIALIZATION_SYNTAX\n#define BZ_FUNCTION_NONTYPE_PARAMETERS\n#define BZ_TEMPLATE_QUALIFIED_BASE_CLASS\n#define BZ_TEMPLATE_QUALIFIED_RETURN_TYPE\n#define BZ_EXPLICIT_TEMPLATE_FUNCTION_QUALIFICATION\n#define BZ_TEMPLATES_AS_TEMPLATE_ARGUMENTS\n#define BZ_TEMPLATE_KEYWORD_QUALIFIER\n#define BZ_TEMPLATE_SCOPED_ARGUMENT_MATCHING\n#define BZ_TYPE_PROMOTION\n#define BZ_USE_NUMTRAIT\n#define BZ_ENUM_COMPUTATIONS\n#define BZ_ENUM_COMPUTATIONS_WITH_CAST\n#define BZ_HAVE_COMPLEX\n\n#ifdef __GNUC__ && __GNUC__==3\n #define BZ_HAVE_NUMERIC_LIMITS\n#else\n #undef BZ_HAVE_NUMERIC_LIMITS\n#endif\n\n#define BZ_HAVE_CLIMITS\n#define BZ_HAVE_VALARRAY\n#undef BZ_HAVE_COMPLEX_MATH\n#define BZ_HAVE_IEEE_MATH\n#undef BZ_HAVE_SYSTEM_V_MATH\n#define BZ_MATH_FN_IN_NAMESPACE_STD\n#define BZ_COMPLEX_MATH_IN_NAMESPACE_STD\n#define BZ_HAVE_STD\n#define BZ_HAVE_STL\n#define BZ_HAVE_RUSAGE\n \n#endif // BZ_CONFIG_H\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 0, "complexity": 0, "token_count": 0, "diff_parsed": { "added": [ "#if (__GNUC__ && __GNUC__ == 3)" ], "deleted": [ "#ifdef __GNUC__ && __GNUC__==3" ] } }, { "old_path": "weave/blitz_spec.py", "new_path": "weave/blitz_spec.py", "filename": "blitz_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -89,7 +89,12 @@ def init_info(self):\n self.headers.extend(blitz_headers)\n self.include_dirs = [blitz_dir]\n self.support_code.append(blitz_support_code)\n- self.type_name = 'blitz'\n+ \n+ # type_name is used to setup the initial type conversion. Even\n+ # for blitz conversion, the first step is to convert it to a\n+ # standard numpy array.\n+ #self.type_name = 'blitz'\n+ self.type_name = 'numpy'\n \n def info_object(self):\n return array_info()\n", "added_lines": 6, "deleted_lines": 1, "source_code": "\"\"\"\n build_info holds classes that define the information\n needed for building C++ extension modules for Python that\n handle different data types. The information includes\n such as include files, libraries, and even code snippets.\n \n array_info -- for building functions that use Python\n Numeric arrays.\n\"\"\"\n\nimport base_info\nimport standard_array_spec\nfrom Numeric import *\nfrom types import *\nimport os\n\nblitz_support_code = \\\n\"\"\"\n\n// This should be declared only if they are used by some function\n// to keep from generating needless warnings. for now, we'll always\n// declare them.\n\nint _beg = blitz::fromStart;\nint _end = blitz::toEnd;\nblitz::Range _all = blitz::Range::all();\n\ntemplate\nstatic blitz::Array convert_to_blitz(PyArrayObject* arr_obj,const char* name)\n{ \n blitz::TinyVector shape(0);\n blitz::TinyVector strides(0);\n int stride_acc = 1;\n //for (int i = N-1; i >=0; i--)\n for (int i = 0; i < N; i++)\n {\n shape[i] = arr_obj->dimensions[i];\n strides[i] = arr_obj->strides[i]/sizeof(T);\n }\n //return blitz::Array((T*) arr_obj->data,shape, \n return blitz::Array((T*) arr_obj->data,shape,strides,\n blitz::neverDeleteData);\n}\n\ntemplate\nstatic blitz::Array py_to_blitz(PyArrayObject* arr_obj,const char* name)\n{\n \n blitz::TinyVector shape(0);\n blitz::TinyVector strides(0);\n int stride_acc = 1;\n //for (int i = N-1; i >=0; i--)\n for (int i = 0; i < N; i++)\n {\n shape[i] = arr_obj->dimensions[i];\n strides[i] = arr_obj->strides[i]/sizeof(T);\n }\n //return blitz::Array((T*) arr_obj->data,shape, \n return blitz::Array((T*) arr_obj->data,shape,strides,\n blitz::neverDeleteData);\n}\n\"\"\"\n\nimport os, blitz_spec\nlocal_dir,junk = os.path.split(os.path.abspath(blitz_spec.__file__)) \nblitz_dir = os.path.join(local_dir,'blitz-20001213')\n\n# The need to warn about compilers made the info_object method in\n# converters necessary and also this little class necessary. \n# The spec/info unification needs to continue so that this can \n# incorporated into the spec somehow.\n\nclass array_info(base_info.custom_info): \n # throw error if trying to use msvc compiler\n \n def check_compiler(self,compiler): \n msvc_msg = 'Unfortunately, the blitz arrays used to support numeric' \\\n ' arrays will not compile with MSVC.' \\\n ' Please try using mingw32 (www.mingw.org).'\n if compiler == 'msvc':\n return ValueError, self.msvc_msg \n\n\nclass array_converter(standard_array_spec.array_converter):\n def init_info(self):\n standard_array_spec.array_converter.init_info(self)\n blitz_headers = ['\"blitz/array.h\"','\"Numeric/arrayobject.h\"',\n '','']\n self.headers.extend(blitz_headers)\n self.include_dirs = [blitz_dir]\n self.support_code.append(blitz_support_code)\n \n # type_name is used to setup the initial type conversion. Even\n # for blitz conversion, the first step is to convert it to a\n # standard numpy array.\n #self.type_name = 'blitz'\n self.type_name = 'numpy'\n \n def info_object(self):\n return array_info()\n\n def type_spec(self,name,value):\n new_spec = standard_array_spec.array_converter.type_spec(self,name,value)\n new_spec.dims = len(value.shape)\n if new_spec.dims > 11:\n msg = \"Error converting variable '\" + name + \"'. \" \\\n \"blitz only supports arrays up to 11 dimensions.\"\n raise ValueError, msg\n return new_spec\n\n def template_vars(self,inline=0):\n res = standard_array_spec.array_converter.template_vars(self,inline) \n if hasattr(self,'dims'):\n res['dims'] = self.dims\n return res \n\n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(array_name)s = %(var_convert)s;\\n' \\\n 'conversion_numpy_check_type(%(array_name)s,%(num_typecode)s,\"%(name)s\");\\n' \\\n 'conversion_numpy_check_size(%(array_name)s,%(dims)s,\"%(name)s\");\\n' \\\n 'blitz::Array<%(num_type)s,%(dims)d> %(name)s =' \\\n ' convert_to_blitz<%(num_type)s,%(dims)d>(%(array_name)s,\"%(name)s\");\\n' \\\n 'blitz::TinyVector N%(name)s = %(name)s.shape();\\n'\n code = code % self.template_vars(inline=inline)\n return code\n\n def __cmp__(self,other):\n #only works for equal\n return ( cmp(self.name,other.name) or \n cmp(self.var_type,other.var_type) or \n cmp(self.dims, other.dims) or \n cmp(self.__class__, other.__class__) )\n\n", "source_code_before": "\"\"\"\n build_info holds classes that define the information\n needed for building C++ extension modules for Python that\n handle different data types. The information includes\n such as include files, libraries, and even code snippets.\n \n array_info -- for building functions that use Python\n Numeric arrays.\n\"\"\"\n\nimport base_info\nimport standard_array_spec\nfrom Numeric import *\nfrom types import *\nimport os\n\nblitz_support_code = \\\n\"\"\"\n\n// This should be declared only if they are used by some function\n// to keep from generating needless warnings. for now, we'll always\n// declare them.\n\nint _beg = blitz::fromStart;\nint _end = blitz::toEnd;\nblitz::Range _all = blitz::Range::all();\n\ntemplate\nstatic blitz::Array convert_to_blitz(PyArrayObject* arr_obj,const char* name)\n{ \n blitz::TinyVector shape(0);\n blitz::TinyVector strides(0);\n int stride_acc = 1;\n //for (int i = N-1; i >=0; i--)\n for (int i = 0; i < N; i++)\n {\n shape[i] = arr_obj->dimensions[i];\n strides[i] = arr_obj->strides[i]/sizeof(T);\n }\n //return blitz::Array((T*) arr_obj->data,shape, \n return blitz::Array((T*) arr_obj->data,shape,strides,\n blitz::neverDeleteData);\n}\n\ntemplate\nstatic blitz::Array py_to_blitz(PyArrayObject* arr_obj,const char* name)\n{\n \n blitz::TinyVector shape(0);\n blitz::TinyVector strides(0);\n int stride_acc = 1;\n //for (int i = N-1; i >=0; i--)\n for (int i = 0; i < N; i++)\n {\n shape[i] = arr_obj->dimensions[i];\n strides[i] = arr_obj->strides[i]/sizeof(T);\n }\n //return blitz::Array((T*) arr_obj->data,shape, \n return blitz::Array((T*) arr_obj->data,shape,strides,\n blitz::neverDeleteData);\n}\n\"\"\"\n\nimport os, blitz_spec\nlocal_dir,junk = os.path.split(os.path.abspath(blitz_spec.__file__)) \nblitz_dir = os.path.join(local_dir,'blitz-20001213')\n\n# The need to warn about compilers made the info_object method in\n# converters necessary and also this little class necessary. \n# The spec/info unification needs to continue so that this can \n# incorporated into the spec somehow.\n\nclass array_info(base_info.custom_info): \n # throw error if trying to use msvc compiler\n \n def check_compiler(self,compiler): \n msvc_msg = 'Unfortunately, the blitz arrays used to support numeric' \\\n ' arrays will not compile with MSVC.' \\\n ' Please try using mingw32 (www.mingw.org).'\n if compiler == 'msvc':\n return ValueError, self.msvc_msg \n\n\nclass array_converter(standard_array_spec.array_converter):\n def init_info(self):\n standard_array_spec.array_converter.init_info(self)\n blitz_headers = ['\"blitz/array.h\"','\"Numeric/arrayobject.h\"',\n '','']\n self.headers.extend(blitz_headers)\n self.include_dirs = [blitz_dir]\n self.support_code.append(blitz_support_code)\n self.type_name = 'blitz'\n \n def info_object(self):\n return array_info()\n\n def type_spec(self,name,value):\n new_spec = standard_array_spec.array_converter.type_spec(self,name,value)\n new_spec.dims = len(value.shape)\n if new_spec.dims > 11:\n msg = \"Error converting variable '\" + name + \"'. \" \\\n \"blitz only supports arrays up to 11 dimensions.\"\n raise ValueError, msg\n return new_spec\n\n def template_vars(self,inline=0):\n res = standard_array_spec.array_converter.template_vars(self,inline) \n if hasattr(self,'dims'):\n res['dims'] = self.dims\n return res \n\n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(array_name)s = %(var_convert)s;\\n' \\\n 'conversion_numpy_check_type(%(array_name)s,%(num_typecode)s,\"%(name)s\");\\n' \\\n 'conversion_numpy_check_size(%(array_name)s,%(dims)s,\"%(name)s\");\\n' \\\n 'blitz::Array<%(num_type)s,%(dims)d> %(name)s =' \\\n ' convert_to_blitz<%(num_type)s,%(dims)d>(%(array_name)s,\"%(name)s\");\\n' \\\n 'blitz::TinyVector N%(name)s = %(name)s.shape();\\n'\n code = code % self.template_vars(inline=inline)\n return code\n\n def __cmp__(self,other):\n #only works for equal\n return ( cmp(self.name,other.name) or \n cmp(self.var_type,other.var_type) or \n cmp(self.dims, other.dims) or \n cmp(self.__class__, other.__class__) )\n\n", "methods": [ { "name": "check_compiler", "long_name": "check_compiler( self , compiler )", "filename": "blitz_spec.py", "nloc": 6, "complexity": 2, "token_count": 25, "parameters": [ "self", "compiler" ], "start_line": 76, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "blitz_spec.py", "nloc": 8, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 85, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "info_object", "long_name": "info_object( self )", "filename": "blitz_spec.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 99, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "blitz_spec.py", "nloc": 8, "complexity": 2, "token_count": 55, "parameters": [ "self", "name", "value" ], "start_line": 102, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "blitz_spec.py", "nloc": 5, "complexity": 2, "token_count": 39, "parameters": [ "self", "inline" ], "start_line": 111, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "blitz_spec.py", "nloc": 10, "complexity": 1, "token_count": 42, "parameters": [ "self", "templatize", "inline" ], "start_line": 117, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "blitz_spec.py", "nloc": 5, "complexity": 4, "token_count": 53, "parameters": [ "self", "other" ], "start_line": 128, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "methods_before": [ { "name": "check_compiler", "long_name": "check_compiler( self , compiler )", "filename": "blitz_spec.py", "nloc": 6, "complexity": 2, "token_count": 25, "parameters": [ "self", "compiler" ], "start_line": 76, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "blitz_spec.py", "nloc": 8, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 85, "end_line": 92, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "info_object", "long_name": "info_object( self )", "filename": "blitz_spec.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 94, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "blitz_spec.py", "nloc": 8, "complexity": 2, "token_count": 55, "parameters": [ "self", "name", "value" ], "start_line": 97, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "blitz_spec.py", "nloc": 5, "complexity": 2, "token_count": 39, "parameters": [ "self", "inline" ], "start_line": 106, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "blitz_spec.py", "nloc": 10, "complexity": 1, "token_count": 42, "parameters": [ "self", "templatize", "inline" ], "start_line": 112, "end_line": 121, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "blitz_spec.py", "nloc": 5, "complexity": 4, "token_count": 53, "parameters": [ "self", "other" ], "start_line": 123, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "init_info", "long_name": "init_info( self )", "filename": "blitz_spec.py", "nloc": 8, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 85, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 } ], "nloc": 109, "complexity": 13, "token_count": 354, "diff_parsed": { "added": [ "", " # type_name is used to setup the initial type conversion. Even", " # for blitz conversion, the first step is to convert it to a", " # standard numpy array.", " #self.type_name = 'blitz'", " self.type_name = 'numpy'" ], "deleted": [ " self.type_name = 'blitz'" ] } }, { "old_path": "weave/build_tools.py", "new_path": "weave/build_tools.py", "filename": "build_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -24,6 +24,7 @@\n # If linker is 'gcc', this will convert it to 'g++'\n # necessary to make sure stdc++ is linked in cross-platform way.\n import distutils.sysconfig\n+import distutils.dir_util\n \n old_init_posix = distutils.sysconfig._init_posix\n \n@@ -146,12 +147,22 @@ def build_extension(module_path,compiler_name = '',build_dir = None,\n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n- \n+ \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n+ # dag. We keep having to add directories to the path to keep \n+ # object files separated from each other. gcc2.x and gcc3.x C++ \n+ # object files are not compatible, so we'll stick them in a sub\n+ # dir based on their version. This will add gccX.X to the \n+ # path.\n+ compiler_dir = get_compiler_dir(compiler_name)\n+ temp_dir = os.path.join(temp_dir,compiler_dir)\n+ distutils.dir_util.mkpath(temp_dir)\n+ \n compiler_name = choose_compiler(compiler_name)\n+ \n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n@@ -298,6 +309,29 @@ def msvc_exists():\n result = 1\n return result\n \n+if os.name == 'nt':\n+ def run_command(command):\n+ \"\"\" not sure how to get exit status on nt. \"\"\"\n+ in_pipe,out_pipe = os.popen4(command)\n+ in_pipe.close()\n+ text = out_pipe.read()\n+ return 0, text\n+else:\n+ run_command = commands.getstatusoutput\n+\n+def get_compiler_dir(compiler_name):\n+ if compiler_name == 'gcc': \n+ status, text = run_command(compiler_name + ' --version')\n+ try:\n+ import re\n+ version = re.findall('\\d\\.\\d',text)[0]\n+ except IndexError:\n+ version = ''\n+ compiler_dir = compiler_name + version\n+ else: \n+ compiler_dir = compiler_name\n+ return compiler_dir\n+ \n def configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n@@ -418,7 +452,7 @@ def import_library_exists():\n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n- import scipy_distutils import lib2def\n+ from scipy_distutils import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n", "added_lines": 36, "deleted_lines": 2, "source_code": "\"\"\" Tools for compiling C/C++ code to extension modules\n\n The main function, build_extension(), takes the C/C++ file\n along with some other options and builds a Python extension.\n It uses distutils for most of the heavy lifting.\n \n choose_compiler() is also useful (mainly on windows anyway)\n for trying to determine whether MSVC++ or gcc is available.\n MSVC doesn't handle templates as well, so some of the code emitted\n by the python->C conversions need this info to choose what kind\n of code to create.\n \n The other main thing here is an alternative version of the MingW32\n compiler class. The class makes it possible to build libraries with\n gcc even if the original version of python was built using MSVC. It\n does this by converting a pythonxx.lib file to a libpythonxx.a file.\n Note that you need write access to the pythonxx/lib directory to do this.\n\"\"\"\n\nimport sys,os,string,time\nimport tempfile\nimport exceptions\n\n# If linker is 'gcc', this will convert it to 'g++'\n# necessary to make sure stdc++ is linked in cross-platform way.\nimport distutils.sysconfig\nimport distutils.dir_util\n\nold_init_posix = distutils.sysconfig._init_posix\n\ndef _init_posix():\n old_init_posix()\n ld = distutils.sysconfig._config_vars['LDSHARED']\n #distutils.sysconfig._config_vars['LDSHARED'] = ld.replace('gcc','g++')\n # FreeBSD names gcc as cc, so the above find and replace doesn't work. \n # So, assume first entry in ld is the name of the linker -- gcc or cc or \n # whatever. This is a sane assumption, correct?\n # If the linker is gcc, set it to g++\n link_cmds = ld.split() \n if gcc_exists(link_cmds[0]):\n link_cmds[0] = 'g++'\n ld = ' '.join(link_cmds)\n distutils.sysconfig._config_vars['LDSHARED'] = ld \n\ndistutils.sysconfig._init_posix = _init_posix \n# end force g++\n\n\nclass CompileError(exceptions.Exception):\n pass\n \ndef build_extension(module_path,compiler_name = '',build_dir = None,\n temp_dir = None, verbose = 0, **kw):\n \"\"\" Build the file given by module_path into a Python extension module.\n \n build_extensions uses distutils to build Python extension modules.\n kw arguments not used are passed on to the distutils extension\n module. Directory settings can handle absoulte settings, but don't\n currently expand '~' or environment variables.\n \n module_path -- the full path name to the c file to compile. \n Something like: /full/path/name/module_name.c \n The name of the c/c++ file should be the same as the\n name of the module (i.e. the initmodule() routine)\n compiler_name -- The name of the compiler to use. On Windows if it \n isn't given, MSVC is used if it exists (is found).\n gcc is used as a second choice. If neither are found, \n the default distutils compiler is used. Acceptable \n names are 'gcc', 'msvc' or any of the compiler names \n shown by distutils.ccompiler.show_compilers()\n build_dir -- The location where the resulting extension module \n should be placed. This location must be writable. If\n it isn't, several default locations are tried. If the \n build_dir is not in the current python path, a warning\n is emitted, and it is added to the end of the path.\n build_dir defaults to the current directory.\n temp_dir -- The location where temporary files (*.o or *.obj)\n from the build are placed. This location must be \n writable. If it isn't, several default locations are \n tried. It defaults to tempfile.gettempdir()\n verbose -- 0, 1, or 2. 0 is as quiet as possible. 1 prints\n minimal information. 2 is noisy. \n **kw -- keyword arguments. These are passed on to the \n distutils extension module. Most of the keywords\n are listed below.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n \n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list \n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability) \n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line) \n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n success = 0\n from distutils.core import setup, Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n # dag. We keep having to add directories to the path to keep \n # object files separated from each other. gcc2.x and gcc3.x C++ \n # object files are not compatible, so we'll stick them in a sub\n # dir based on their version. This will add gccX.X to the \n # path.\n compiler_dir = get_compiler_dir(compiler_name)\n temp_dir = os.path.join(temp_dir,compiler_dir)\n distutils.dir_util.mkpath(temp_dir)\n \n compiler_name = choose_compiler(compiler_name)\n \n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n try:\n if verbose == 1:\n print 'Compiling code...'\n \n # set compiler verboseness 2 or more makes it output results\n if verbose > 1: verb = 1 \n else: verb = 0\n \n t1 = time.time() \n # add module to the needed source code files and build extension\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n \n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n platform = sys.platform\n version = sys.version.lower()\n if platform[:5] == 'sunos' and version.find('gcc') != -1:\n extra_link_args = kw.get('extra_link_args',[])\n kw['extra_link_args'] = ['-mimpure-text'] + extra_link_args\n \n ext = Extension(module_name, **kw)\n \n # the switcheroo on SystemExit here is meant to keep command line\n # sessions from exiting when compiles fail.\n builtin = sys.modules['__builtin__']\n old_SysExit = builtin.__dict__['SystemExit']\n builtin.__dict__['SystemExit'] = CompileError\n \n # distutils for MSVC messes with the environment, so we save the\n # current state and restore them afterward.\n import copy\n environ = copy.deepcopy(os.environ)\n try:\n setup(name = module_name, ext_modules = [ext],verbose=verb)\n finally:\n # restore state\n os.environ = environ \n # restore SystemExit\n builtin.__dict__['SystemExit'] = old_SysExit\n t2 = time.time()\n \n if verbose == 1:\n print 'finished compiling (sec): ', t2 - t1 \n success = 1\n configure_python_path(build_dir)\n except SyntaxError: #TypeError:\n success = 0 \n \n # restore argv after our trick... \n restore_sys_argv()\n \n return success\n\nold_argv = []\ndef configure_sys_argv(compiler_name,temp_dir,build_dir):\n # We're gonna play some tricks with argv here to pass info to distutils \n # which is really built for command line use. better way??\n global old_argv\n old_argv = sys.argv[:] \n sys.argv = ['','build_ext','--build-lib', build_dir,\n '--build-temp',temp_dir] \n if compiler_name == 'gcc':\n sys.argv.insert(2,'--compiler='+compiler_name)\n elif compiler_name:\n sys.argv.insert(2,'--compiler='+compiler_name)\n\ndef restore_sys_argv():\n sys.argv = old_argv\n \ndef configure_python_path(build_dir): \n #make sure the module lives in a directory on the python path.\n python_paths = [os.path.abspath(x) for x in sys.path]\n if os.path.abspath(build_dir) not in python_paths:\n #print \"warning: build directory was not part of python path.\"\\\n # \" It has been appended to the path.\"\n sys.path.append(os.path.abspath(build_dir))\n\ndef choose_compiler(compiler_name=''):\n \"\"\" Try and figure out which compiler is gonna be used on windows.\n On other platforms, it just returns whatever value it is given.\n \n converts 'gcc' to 'mingw32' on win32\n \"\"\"\n if sys.platform == 'win32': \n if not compiler_name:\n # On Windows, default to MSVC and use gcc if it wasn't found\n # wasn't found. If neither are found, go with whatever\n # the default is for distutils -- and probably fail...\n if msvc_exists():\n compiler_name = 'msvc'\n elif gcc_exists():\n compiler_name = 'mingw32'\n elif compiler_name == 'gcc':\n compiler_name = 'mingw32'\n else:\n # don't know how to force gcc -- look into this.\n if compiler_name == 'gcc':\n compiler_name = 'unix' \n return compiler_name\n \ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n version = distutils.msvccompiler.get_devstudio_version()\n if version:\n result = 1\n return result\n\nif os.name == 'nt':\n def run_command(command):\n \"\"\" not sure how to get exit status on nt. \"\"\"\n in_pipe,out_pipe = os.popen4(command)\n in_pipe.close()\n text = out_pipe.read()\n return 0, text\nelse:\n run_command = commands.getstatusoutput\n\ndef get_compiler_dir(compiler_name):\n if compiler_name == 'gcc': \n status, text = run_command(compiler_name + ' --version')\n try:\n import re\n version = re.findall('\\d\\.\\d',text)[0]\n except IndexError:\n version = ''\n compiler_dir = compiler_name + version\n else: \n compiler_dir = compiler_name\n return compiler_dir\n \ndef configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n print \"warning: specified temp_dir '%s' does not exist \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n\n # final check that that directories are writable. \n if not os.access(temp_dir,os.W_OK):\n msg = \"Either the temp or build directory wasn't writable. Check\" \\\n \" these locations: '%s'\" % temp_dir \n raise ValueError, msg\n return temp_dir\n\ndef configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n print \"warning: specified build_dir '%s' does not exist \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n if build_dir is None:\n #default to building in the home directory of the given module. \n build_dir = os.curdir\n # if it doesn't work use the current directory. This should always\n # be writable. \n if not os.access(build_dir,os.W_OK):\n print \"warning:, neither the module's directory nor the \"\\\n \"current directory are writable. Using the temporary\"\\\n \"directory.\"\n build_dir = tempfile.gettempdir()\n\n # final check that that directories are writable.\n if not os.access(build_dir,os.W_OK):\n msg = \"The build directory wasn't writable. Check\" \\\n \" this location: '%s'\" % build_dir\n raise ValueError, msg\n \n return os.path.abspath(build_dir) \n \nif sys.platform == 'win32':\n import distutils.cygwinccompiler\n # the same as cygwin plus some additional parameters\n class Mingw32CCompiler (distutils.cygwinccompiler.CygwinCCompiler):\n \"\"\" A modified MingW32 compiler compatible with an MSVC built Python.\n \n \"\"\"\n \n compiler_type = 'mingw32'\n \n def __init__ (self,\n verbose=0,\n dry_run=0,\n force=0):\n \n distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose, \n dry_run, force)\n \n # A real mingw32 doesn't need to specify a different entry point,\n # but cygwin 2.91.57 in no-cygwin-mode needs it.\n if self.gcc_version <= \"2.91.57\":\n entry_point = '--entry _DllMain@12'\n else:\n entry_point = ''\n if self.linker_dll == 'dllwrap':\n self.linker = 'dllwrap' + ' --driver-name g++'\n elif self.linker_dll == 'gcc':\n self.linker = 'g++' \n # **changes: eric jones 4/11/01\n # 1. Check for import library on Windows. Build if it doesn't exist.\n if not import_library_exists():\n build_import_library()\n \n # **changes: eric jones 4/11/01\n # 2. increased optimization and turned off all warnings\n # 3. also added --driver-name g++\n #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n # compiler_so='gcc -mno-cygwin -mdll -O2 -w',\n # linker_exe='gcc -mno-cygwin',\n # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' \n # % (self.linker, entry_point))\n self.set_executables(compiler='g++ -mno-cygwin -O2 -w',\n compiler_so='g++ -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',\n linker_exe='g++ -mno-cygwin',\n linker_so='%s -mno-cygwin -mdll -static %s' \n % (self.linker, entry_point))\n \n # Maybe we should also append -mthreads, but then the finished\n # dlls need another dll (mingwm10.dll see Mingw32 docs)\n # (-mthreads: Support thread-safe exception handling on `Mingw32') \n \n # no additional libraries needed \n self.dll_libraries=[]\n \n # __init__ ()\n \n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n # We should also check the version of gcc available...\n #distutils.ccompiler._default_compilers['nt'] = 'mingw32'\n #distutils.ccompiler._default_compilers = (('nt', 'mingw32'))\n # reset the Mingw32 compiler in distutils to the one defined above\n distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler\n \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if os.name == 'nt':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n from scipy_distutils import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print 'WARNING: failed to build import library for gcc. Linking will fail.'\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\n\n\n", "source_code_before": "\"\"\" Tools for compiling C/C++ code to extension modules\n\n The main function, build_extension(), takes the C/C++ file\n along with some other options and builds a Python extension.\n It uses distutils for most of the heavy lifting.\n \n choose_compiler() is also useful (mainly on windows anyway)\n for trying to determine whether MSVC++ or gcc is available.\n MSVC doesn't handle templates as well, so some of the code emitted\n by the python->C conversions need this info to choose what kind\n of code to create.\n \n The other main thing here is an alternative version of the MingW32\n compiler class. The class makes it possible to build libraries with\n gcc even if the original version of python was built using MSVC. It\n does this by converting a pythonxx.lib file to a libpythonxx.a file.\n Note that you need write access to the pythonxx/lib directory to do this.\n\"\"\"\n\nimport sys,os,string,time\nimport tempfile\nimport exceptions\n\n# If linker is 'gcc', this will convert it to 'g++'\n# necessary to make sure stdc++ is linked in cross-platform way.\nimport distutils.sysconfig\n\nold_init_posix = distutils.sysconfig._init_posix\n\ndef _init_posix():\n old_init_posix()\n ld = distutils.sysconfig._config_vars['LDSHARED']\n #distutils.sysconfig._config_vars['LDSHARED'] = ld.replace('gcc','g++')\n # FreeBSD names gcc as cc, so the above find and replace doesn't work. \n # So, assume first entry in ld is the name of the linker -- gcc or cc or \n # whatever. This is a sane assumption, correct?\n # If the linker is gcc, set it to g++\n link_cmds = ld.split() \n if gcc_exists(link_cmds[0]):\n link_cmds[0] = 'g++'\n ld = ' '.join(link_cmds)\n distutils.sysconfig._config_vars['LDSHARED'] = ld \n\ndistutils.sysconfig._init_posix = _init_posix \n# end force g++\n\n\nclass CompileError(exceptions.Exception):\n pass\n \ndef build_extension(module_path,compiler_name = '',build_dir = None,\n temp_dir = None, verbose = 0, **kw):\n \"\"\" Build the file given by module_path into a Python extension module.\n \n build_extensions uses distutils to build Python extension modules.\n kw arguments not used are passed on to the distutils extension\n module. Directory settings can handle absoulte settings, but don't\n currently expand '~' or environment variables.\n \n module_path -- the full path name to the c file to compile. \n Something like: /full/path/name/module_name.c \n The name of the c/c++ file should be the same as the\n name of the module (i.e. the initmodule() routine)\n compiler_name -- The name of the compiler to use. On Windows if it \n isn't given, MSVC is used if it exists (is found).\n gcc is used as a second choice. If neither are found, \n the default distutils compiler is used. Acceptable \n names are 'gcc', 'msvc' or any of the compiler names \n shown by distutils.ccompiler.show_compilers()\n build_dir -- The location where the resulting extension module \n should be placed. This location must be writable. If\n it isn't, several default locations are tried. If the \n build_dir is not in the current python path, a warning\n is emitted, and it is added to the end of the path.\n build_dir defaults to the current directory.\n temp_dir -- The location where temporary files (*.o or *.obj)\n from the build are placed. This location must be \n writable. If it isn't, several default locations are \n tried. It defaults to tempfile.gettempdir()\n verbose -- 0, 1, or 2. 0 is as quiet as possible. 1 prints\n minimal information. 2 is noisy. \n **kw -- keyword arguments. These are passed on to the \n distutils extension module. Most of the keywords\n are listed below.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n \n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list \n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability) \n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line) \n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n success = 0\n from distutils.core import setup, Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n compiler_name = choose_compiler(compiler_name)\n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n try:\n if verbose == 1:\n print 'Compiling code...'\n \n # set compiler verboseness 2 or more makes it output results\n if verbose > 1: verb = 1 \n else: verb = 0\n \n t1 = time.time() \n # add module to the needed source code files and build extension\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n \n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n platform = sys.platform\n version = sys.version.lower()\n if platform[:5] == 'sunos' and version.find('gcc') != -1:\n extra_link_args = kw.get('extra_link_args',[])\n kw['extra_link_args'] = ['-mimpure-text'] + extra_link_args\n \n ext = Extension(module_name, **kw)\n \n # the switcheroo on SystemExit here is meant to keep command line\n # sessions from exiting when compiles fail.\n builtin = sys.modules['__builtin__']\n old_SysExit = builtin.__dict__['SystemExit']\n builtin.__dict__['SystemExit'] = CompileError\n \n # distutils for MSVC messes with the environment, so we save the\n # current state and restore them afterward.\n import copy\n environ = copy.deepcopy(os.environ)\n try:\n setup(name = module_name, ext_modules = [ext],verbose=verb)\n finally:\n # restore state\n os.environ = environ \n # restore SystemExit\n builtin.__dict__['SystemExit'] = old_SysExit\n t2 = time.time()\n \n if verbose == 1:\n print 'finished compiling (sec): ', t2 - t1 \n success = 1\n configure_python_path(build_dir)\n except SyntaxError: #TypeError:\n success = 0 \n \n # restore argv after our trick... \n restore_sys_argv()\n \n return success\n\nold_argv = []\ndef configure_sys_argv(compiler_name,temp_dir,build_dir):\n # We're gonna play some tricks with argv here to pass info to distutils \n # which is really built for command line use. better way??\n global old_argv\n old_argv = sys.argv[:] \n sys.argv = ['','build_ext','--build-lib', build_dir,\n '--build-temp',temp_dir] \n if compiler_name == 'gcc':\n sys.argv.insert(2,'--compiler='+compiler_name)\n elif compiler_name:\n sys.argv.insert(2,'--compiler='+compiler_name)\n\ndef restore_sys_argv():\n sys.argv = old_argv\n \ndef configure_python_path(build_dir): \n #make sure the module lives in a directory on the python path.\n python_paths = [os.path.abspath(x) for x in sys.path]\n if os.path.abspath(build_dir) not in python_paths:\n #print \"warning: build directory was not part of python path.\"\\\n # \" It has been appended to the path.\"\n sys.path.append(os.path.abspath(build_dir))\n\ndef choose_compiler(compiler_name=''):\n \"\"\" Try and figure out which compiler is gonna be used on windows.\n On other platforms, it just returns whatever value it is given.\n \n converts 'gcc' to 'mingw32' on win32\n \"\"\"\n if sys.platform == 'win32': \n if not compiler_name:\n # On Windows, default to MSVC and use gcc if it wasn't found\n # wasn't found. If neither are found, go with whatever\n # the default is for distutils -- and probably fail...\n if msvc_exists():\n compiler_name = 'msvc'\n elif gcc_exists():\n compiler_name = 'mingw32'\n elif compiler_name == 'gcc':\n compiler_name = 'mingw32'\n else:\n # don't know how to force gcc -- look into this.\n if compiler_name == 'gcc':\n compiler_name = 'unix' \n return compiler_name\n \ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n version = distutils.msvccompiler.get_devstudio_version()\n if version:\n result = 1\n return result\n\ndef configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n print \"warning: specified temp_dir '%s' does not exist \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n\n # final check that that directories are writable. \n if not os.access(temp_dir,os.W_OK):\n msg = \"Either the temp or build directory wasn't writable. Check\" \\\n \" these locations: '%s'\" % temp_dir \n raise ValueError, msg\n return temp_dir\n\ndef configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n print \"warning: specified build_dir '%s' does not exist \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n if build_dir is None:\n #default to building in the home directory of the given module. \n build_dir = os.curdir\n # if it doesn't work use the current directory. This should always\n # be writable. \n if not os.access(build_dir,os.W_OK):\n print \"warning:, neither the module's directory nor the \"\\\n \"current directory are writable. Using the temporary\"\\\n \"directory.\"\n build_dir = tempfile.gettempdir()\n\n # final check that that directories are writable.\n if not os.access(build_dir,os.W_OK):\n msg = \"The build directory wasn't writable. Check\" \\\n \" this location: '%s'\" % build_dir\n raise ValueError, msg\n \n return os.path.abspath(build_dir) \n \nif sys.platform == 'win32':\n import distutils.cygwinccompiler\n # the same as cygwin plus some additional parameters\n class Mingw32CCompiler (distutils.cygwinccompiler.CygwinCCompiler):\n \"\"\" A modified MingW32 compiler compatible with an MSVC built Python.\n \n \"\"\"\n \n compiler_type = 'mingw32'\n \n def __init__ (self,\n verbose=0,\n dry_run=0,\n force=0):\n \n distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose, \n dry_run, force)\n \n # A real mingw32 doesn't need to specify a different entry point,\n # but cygwin 2.91.57 in no-cygwin-mode needs it.\n if self.gcc_version <= \"2.91.57\":\n entry_point = '--entry _DllMain@12'\n else:\n entry_point = ''\n if self.linker_dll == 'dllwrap':\n self.linker = 'dllwrap' + ' --driver-name g++'\n elif self.linker_dll == 'gcc':\n self.linker = 'g++' \n # **changes: eric jones 4/11/01\n # 1. Check for import library on Windows. Build if it doesn't exist.\n if not import_library_exists():\n build_import_library()\n \n # **changes: eric jones 4/11/01\n # 2. increased optimization and turned off all warnings\n # 3. also added --driver-name g++\n #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n # compiler_so='gcc -mno-cygwin -mdll -O2 -w',\n # linker_exe='gcc -mno-cygwin',\n # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' \n # % (self.linker, entry_point))\n self.set_executables(compiler='g++ -mno-cygwin -O2 -w',\n compiler_so='g++ -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',\n linker_exe='g++ -mno-cygwin',\n linker_so='%s -mno-cygwin -mdll -static %s' \n % (self.linker, entry_point))\n \n # Maybe we should also append -mthreads, but then the finished\n # dlls need another dll (mingwm10.dll see Mingw32 docs)\n # (-mthreads: Support thread-safe exception handling on `Mingw32') \n \n # no additional libraries needed \n self.dll_libraries=[]\n \n # __init__ ()\n \n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n # We should also check the version of gcc available...\n #distutils.ccompiler._default_compilers['nt'] = 'mingw32'\n #distutils.ccompiler._default_compilers = (('nt', 'mingw32'))\n # reset the Mingw32 compiler in distutils to the one defined above\n distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler\n \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if os.name == 'nt':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n import scipy_distutils import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print 'WARNING: failed to build import library for gcc. Linking will fail.'\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\n\n\n", "methods": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [], "start_line": 31, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 52, "complexity": 9, "token_count": 390, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 52, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 171, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name , temp_dir , build_dir )", "filename": "build_tools.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [ "compiler_name", "temp_dir", "build_dir" ], "start_line": 225, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "build_tools.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 237, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "configure_python_path", "long_name": "configure_python_path( build_dir )", "filename": "build_tools.py", "nloc": 4, "complexity": 3, "token_count": 51, "parameters": [ "build_dir" ], "start_line": 240, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "build_tools.py", "nloc": 13, "complexity": 7, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 248, "end_line": 269, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 271, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "build_tools.py", "nloc": 14, "complexity": 4, "token_count": 71, "parameters": [], "start_line": 293, "end_line": 310, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "run_command", "long_name": "run_command( command )", "filename": "build_tools.py", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "command" ], "start_line": 313, "end_line": 318, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_compiler_dir", "long_name": "get_compiler_dir( compiler_name )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 322, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 335, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 351, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_tools.py", "nloc": 22, "complexity": 5, "token_count": 117, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 388, "end_line": 430, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 2 }, { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "build_tools.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 442, "end_line": 450, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 452, "end_line": 478, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 483, "end_line": 485, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 487, "end_line": 489, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [], "start_line": 30, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 49, "complexity": 9, "token_count": 364, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 51, "end_line": 211, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 161, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name , temp_dir , build_dir )", "filename": "build_tools.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [ "compiler_name", "temp_dir", "build_dir" ], "start_line": 214, "end_line": 224, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "build_tools.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 226, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "configure_python_path", "long_name": "configure_python_path( build_dir )", "filename": "build_tools.py", "nloc": 4, "complexity": 3, "token_count": 51, "parameters": [ "build_dir" ], "start_line": 229, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "build_tools.py", "nloc": 13, "complexity": 7, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 237, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 260, "end_line": 280, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "build_tools.py", "nloc": 14, "complexity": 4, "token_count": 71, "parameters": [], "start_line": 282, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 301, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 317, "end_line": 342, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_tools.py", "nloc": 22, "complexity": 5, "token_count": 117, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 354, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 2 }, { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "build_tools.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 408, "end_line": 416, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 418, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 449, "end_line": 451, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 453, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_compiler_dir", "long_name": "get_compiler_dir( compiler_name )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 322, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "run_command", "long_name": "run_command( command )", "filename": "build_tools.py", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "command" ], "start_line": 313, "end_line": 318, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 452, "end_line": 478, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 52, "complexity": 9, "token_count": 390, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 52, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 171, "top_nesting_level": 0 } ], "nloc": 254, "complexity": 60, "token_count": 1573, "diff_parsed": { "added": [ "import distutils.dir_util", "", " # dag. We keep having to add directories to the path to keep", " # object files separated from each other. gcc2.x and gcc3.x C++", " # object files are not compatible, so we'll stick them in a sub", " # dir based on their version. This will add gccX.X to the", " # path.", " compiler_dir = get_compiler_dir(compiler_name)", " temp_dir = os.path.join(temp_dir,compiler_dir)", " distutils.dir_util.mkpath(temp_dir)", "", "", "if os.name == 'nt':", " def run_command(command):", " \"\"\" not sure how to get exit status on nt. \"\"\"", " in_pipe,out_pipe = os.popen4(command)", " in_pipe.close()", " text = out_pipe.read()", " return 0, text", "else:", " run_command = commands.getstatusoutput", "", "def get_compiler_dir(compiler_name):", " if compiler_name == 'gcc':", " status, text = run_command(compiler_name + ' --version')", " try:", " import re", " version = re.findall('\\d\\.\\d',text)[0]", " except IndexError:", " version = ''", " compiler_dir = compiler_name + version", " else:", " compiler_dir = compiler_name", " return compiler_dir", "", " from scipy_distutils import lib2def" ], "deleted": [ "", " import scipy_distutils import lib2def" ] } }, { "old_path": "weave/c_spec.py", "new_path": "weave/c_spec.py", "filename": "c_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -135,7 +135,7 @@ def template_vars(self,inline=0):\n code = 'convert_to_%(type_name)s(%(py_var)s,\"%(name)s\")' % d\n d['var_convert'] = code\n if self.use_ref_count:\n- d['inc_ref_count'] = \"Py_INCREF(py_obj);\"\n+ d['inc_ref_count'] = \"Py_XINCREF(py_obj);\"\n else:\n d['inc_ref_count'] = \"\"\n return d\n@@ -154,7 +154,8 @@ def declaration_code(self,templatize = 0,inline=0):\n \n def cleanup_code(self):\n if self.use_ref_count:\n- code = \"Py_XDECREF(%(py_var)s);\\n\" % self.template_vars()\n+ code = 'Py_XDECREF(%(py_var)s);\\n' % self.template_vars()\n+ #code += 'printf(\"cleaning up %(py_var)s\\\\n\");\\n' % self.template_vars()\n else:\n code = \"\" \n return code\n", "added_lines": 3, "deleted_lines": 2, "source_code": "from types import *\nfrom base_spec import base_converter\nimport base_info\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from python objects to C++ objects\n#\n# This is silly code. There is absolutely no reason why these simple\n# conversion functions should be classes. However, some versions of \n# Mandrake Linux ship with broken C++ compilers (or libraries) that do not\n# handle exceptions correctly when they are thrown from functions. However,\n# exceptions thrown from class methods always work, so we make everything\n# a class method to solve this error.\n#----------------------------------------------------------------------------\n\npy_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic: \n %(c_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // Incref occurs even if conversion fails so that\n // the decref in cleanup_code has a matching incref.\n %(inc_ref_count)s\n if (!py_obj || !%(check_func)s(py_obj))\n handle_conversion_error(py_obj,\"%(type_name)s\", name); \n return %(to_c_return)s;\n }\n \n %(c_type)s py_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // !! Pretty sure INCREF should only be called on success since\n // !! py_to_xxx is used by the user -- not the code generator.\n if (!py_obj || !%(check_func)s(py_obj))\n handle_bad_type(py_obj,\"%(type_name)s\", name); \n %(inc_ref_count)s\n return %(to_c_return)s;\n }\n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from C++ objects to Python objects\n#\n#----------------------------------------------------------------------------\n\nsimple_c_to_py_template = \\\n\"\"\"\nPyObject* %(type_name)s_to_py(PyObject* obj)\n{\n return (PyObject*) obj;\n}\n\n\"\"\"\n\nclass common_base_converter(base_converter):\n \n def __init__(self):\n self.init_info()\n self._build_information = [self.generate_build_info()]\n \n def init_info(self):\n self.matching_types = []\n self.headers = []\n self.include_dirs = []\n self.libraries = []\n self.library_dirs = []\n self.sources = []\n self.support_code = []\n self.module_init_code = []\n self.warnings = []\n self.define_macros = []\n self.use_ref_count = 1\n self.name = \"no_name\"\n self.c_type = 'PyObject*'\n self.to_c_return = 'py_obj'\n \n def info_object(self):\n return base_info.custom_info()\n \n def generate_build_info(self):\n info = self.info_object()\n for header in self.headers:\n info.add_header(header)\n for d in self.include_dirs:\n info.add_include_dir(d)\n for lib in self.libraries:\n info.add_library(lib)\n for d in self.library_dirs:\n info.add_library_dir(d)\n for source in self.sources:\n info.add_source(source)\n for code in self.support_code:\n info.add_support_code(code)\n info.add_support_code(self.py_to_c_code())\n info.add_support_code(self.c_to_py_code())\n for init_code in self.module_init_code:\n info.add_module_init_code(init_code)\n for macro in self.define_macros:\n info.add_define_macro(macro)\n for warning in self.warnings:\n info.add_warning(warning)\n return info\n\n def type_match(self,value):\n return type(value) in self.matching_types\n\n def get_var_type(self,value):\n return type(value)\n \n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n new_spec.var_type = self.get_var_type(value)\n return new_spec\n\n def template_vars(self,inline=0):\n d = {}\n d['type_name'] = self.type_name\n d['check_func'] = self.check_func\n d['c_type'] = self.c_type\n d['to_c_return'] = self.to_c_return\n d['name'] = self.name\n d['py_var'] = self.py_variable()\n d['var_lookup'] = self.retrieve_py_variable(inline)\n code = 'convert_to_%(type_name)s(%(py_var)s,\"%(name)s\")' % d\n d['var_convert'] = code\n if self.use_ref_count:\n d['inc_ref_count'] = \"Py_XINCREF(py_obj);\"\n else:\n d['inc_ref_count'] = \"\"\n return d\n\n def py_to_c_code(self):\n return py_to_c_template % self.template_vars()\n\n def c_to_py_code(self):\n return simple_c_to_py_template % self.template_vars()\n \n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(name)s = %(var_convert)s;\\n' % \\\n self.template_vars(inline=inline)\n return code \n\n def cleanup_code(self):\n if self.use_ref_count:\n code = 'Py_XDECREF(%(py_var)s);\\n' % self.template_vars()\n #code += 'printf(\"cleaning up %(py_var)s\\\\n\");\\n' % self.template_vars()\n else:\n code = \"\" \n return code\n \n def __repr__(self):\n msg = \"(file:: name: %s)\" % self.name\n return msg\n def __cmp__(self,other):\n #only works for equal\n result = -1\n try:\n result = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n except AttributeError:\n pass\n return result \n\n#----------------------------------------------------------------------------\n# Module Converter\n#----------------------------------------------------------------------------\nclass module_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'module'\n self.check_func = 'PyModule_Check' \n # probably should test for callable classes here also.\n self.matching_types = [ModuleType]\n\n#----------------------------------------------------------------------------\n# Instance Converter\n#----------------------------------------------------------------------------\nclass instance_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'instance'\n self.check_func = 'PyInstance_Check' \n self.matching_types = [InstanceType]\n\n#----------------------------------------------------------------------------\n# Catchall Converter\n#----------------------------------------------------------------------------\nclass catchall_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'catchall'\n self.check_func = '' \n def type_match(self,value):\n return 1\n\n#----------------------------------------------------------------------------\n# String Converter\n#----------------------------------------------------------------------------\nclass string_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'string'\n self.check_func = 'PyString_Check' \n self.c_type = 'std::string'\n self.to_c_return = \"std::string(PyString_AsString(py_obj))\"\n self.matching_types = [StringType]\n self.headers.append('')\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* string_to_py(std::string s)\n {\n return PyString_FromString(s.c_str());\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n# Unicode Converter\n#----------------------------------------------------------------------------\nclass unicode_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'unicode'\n self.check_func = 'PyUnicode_Check'\n # This isn't supported by gcc 2.95.3 -- MSVC works fine with it. \n #self.c_type = 'std::wstring'\n #self.to_c_return = \"std::wstring(PyUnicode_AS_UNICODE(py_obj))\"\n self.c_type = 'Py_UNICODE*'\n self.to_c_return = \"PyUnicode_AS_UNICODE(py_obj)\"\n self.matching_types = [UnicodeType]\n #self.headers.append('')\n#----------------------------------------------------------------------------\n# File Converter\n#----------------------------------------------------------------------------\nclass file_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'file'\n self.check_func = 'PyFile_Check' \n self.c_type = 'FILE*'\n self.to_c_return = \"PyFile_AsFile(py_obj)\"\n self.headers = ['']\n self.matching_types = [FileType]\n\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* file_to_py(FILE* file, char* name, char* mode)\n {\n PyObject* py_obj = NULL;\n //extern int fclose(FILE *);\n return (PyObject*) PyFile_FromFile(file, name, mode, fclose);\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n#\n# Scalar Number Conversions\n#\n#----------------------------------------------------------------------------\n\n# the following typemaps are for 32 bit platforms. A way to do this\n# general case? maybe ask numeric types how long they are and base\n# the decisions on that.\n\n#----------------------------------------------------------------------------\n# Standard Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types = {}\nnum_to_c_types[type(1)] = 'int'\nnum_to_c_types[type(1.)] = 'double'\nnum_to_c_types[type(1.+1.j)] = 'std::complex '\n# !! hmmm. The following is likely unsafe...\nnum_to_c_types[type(1L)] = 'int'\n\n#----------------------------------------------------------------------------\n# Numeric array Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types['T'] = 'T' # for templates\nnum_to_c_types['F'] = 'std::complex '\nnum_to_c_types['D'] = 'std::complex '\nnum_to_c_types['f'] = 'float'\nnum_to_c_types['d'] = 'double'\nnum_to_c_types['1'] = 'char'\nnum_to_c_types['b'] = 'unsigned char'\nnum_to_c_types['s'] = 'short'\nnum_to_c_types['i'] = 'int'\n# not strictly correct, but shoulld be fine fo numeric work.\n# add test somewhere to make sure long can be cast to int before using.\nnum_to_c_types['l'] = 'int'\n\nclass scalar_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.warnings = ['disable: 4275', 'disable: 4101']\n self.headers = ['','']\n self.use_ref_count = 0\n\nclass int_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'int'\n self.check_func = 'PyInt_Check' \n self.c_type = 'int'\n self.to_c_return = \"(int) PyInt_AsLong(py_obj)\"\n self.matching_types = [IntType]\n\nclass long_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # !! long to int conversion isn't safe!\n self.type_name = 'long'\n self.check_func = 'PyLong_Check' \n self.c_type = 'int'\n self.to_c_return = \"(int) PyLong_AsLong(py_obj)\"\n self.matching_types = [LongType]\n\nclass float_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # Not sure this is really that safe...\n self.type_name = 'float'\n self.check_func = 'PyFloat_Check' \n self.c_type = 'double'\n self.to_c_return = \"PyFloat_AsDouble(py_obj)\"\n self.matching_types = [FloatType]\n\nclass complex_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'complex'\n self.check_func = 'PyComplex_Check' \n self.c_type = 'std::complex'\n self.to_c_return = \"std::complex(PyComplex_RealAsDouble(py_obj),\"\\\n \"PyComplex_ImagAsDouble(py_obj))\"\n self.matching_types = [ComplexType]\n\n#----------------------------------------------------------------------------\n#\n# List, Tuple, and Dict converters.\n#\n# Based on SCXX by Gordon McMillan\n#----------------------------------------------------------------------------\nimport os, c_spec # yes, I import myself to find out my __file__ location.\nlocal_dir,junk = os.path.split(os.path.abspath(c_spec.__file__)) \nscxx_dir = os.path.join(local_dir,'scxx')\n\nclass scxx_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.headers = ['\"scxx/PWOBase.h\"','\"scxx/PWOSequence.h\"',\n '\"scxx/PWOCallable.h\"','\"scxx/PWOMapping.h\"',\n '\"scxx/PWOSequence.h\"','\"scxx/PWOMSequence.h\"',\n '\"scxx/PWONumber.h\"','']\n self.include_dirs = [local_dir,scxx_dir]\n self.sources = [os.path.join(scxx_dir,'PWOImp.cpp'),]\n\nclass list_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'list'\n self.check_func = 'PyList_Check' \n self.c_type = 'PWOList'\n self.to_c_return = 'PWOList(py_obj)'\n self.matching_types = [ListType]\n # ref counting handled by PWOList\n self.use_ref_count = 0\n\nclass tuple_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'tuple'\n self.check_func = 'PyTuple_Check' \n self.c_type = 'PWOTuple'\n self.to_c_return = 'PWOTuple(py_obj)'\n self.matching_types = [TupleType]\n # ref counting handled by PWOTuple\n self.use_ref_count = 0\n\nclass dict_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.support_code.append(\"#define PWODict PWOMapping\")\n self.type_name = 'dict'\n self.check_func = 'PyDict_Check' \n self.c_type = 'PWODict'\n self.to_c_return = 'PWODict(py_obj)'\n self.matching_types = [DictType]\n # ref counting handled by PWODict\n self.use_ref_count = 0\n\n#----------------------------------------------------------------------------\n# Callable Converter\n#----------------------------------------------------------------------------\nclass callable_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'callable'\n self.check_func = 'PyCallable_Check' \n # probably should test for callable classes here also.\n self.matching_types = [FunctionType,MethodType,type(len)]\n self.c_type = 'PWOCallable'\n self.to_c_return = 'PWOCallable(py_obj)'\n # ref counting handled by PWOCallable\n self.use_ref_count = 0\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == \"__main__\":\n x = list_converter().type_spec(\"x\",1)\n print x.py_to_c_code()\n print\n print x.c_to_py_code()\n print\n print x.declaration_code(inline=1)\n print\n print x.cleanup_code()", "source_code_before": "from types import *\nfrom base_spec import base_converter\nimport base_info\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from python objects to C++ objects\n#\n# This is silly code. There is absolutely no reason why these simple\n# conversion functions should be classes. However, some versions of \n# Mandrake Linux ship with broken C++ compilers (or libraries) that do not\n# handle exceptions correctly when they are thrown from functions. However,\n# exceptions thrown from class methods always work, so we make everything\n# a class method to solve this error.\n#----------------------------------------------------------------------------\n\npy_to_c_template = \\\n\"\"\"\nclass %(type_name)s_handler\n{\npublic: \n %(c_type)s convert_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // Incref occurs even if conversion fails so that\n // the decref in cleanup_code has a matching incref.\n %(inc_ref_count)s\n if (!py_obj || !%(check_func)s(py_obj))\n handle_conversion_error(py_obj,\"%(type_name)s\", name); \n return %(to_c_return)s;\n }\n \n %(c_type)s py_to_%(type_name)s(PyObject* py_obj, const char* name)\n {\n // !! Pretty sure INCREF should only be called on success since\n // !! py_to_xxx is used by the user -- not the code generator.\n if (!py_obj || !%(check_func)s(py_obj))\n handle_bad_type(py_obj,\"%(type_name)s\", name); \n %(inc_ref_count)s\n return %(to_c_return)s;\n }\n};\n\n%(type_name)s_handler x__%(type_name)s_handler = %(type_name)s_handler();\n#define convert_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.convert_to_%(type_name)s(py_obj,name)\n#define py_to_%(type_name)s(py_obj,name) \\\\\n x__%(type_name)s_handler.py_to_%(type_name)s(py_obj,name)\n\n\"\"\"\n\n#----------------------------------------------------------------------------\n# C++ code template for converting code from C++ objects to Python objects\n#\n#----------------------------------------------------------------------------\n\nsimple_c_to_py_template = \\\n\"\"\"\nPyObject* %(type_name)s_to_py(PyObject* obj)\n{\n return (PyObject*) obj;\n}\n\n\"\"\"\n\nclass common_base_converter(base_converter):\n \n def __init__(self):\n self.init_info()\n self._build_information = [self.generate_build_info()]\n \n def init_info(self):\n self.matching_types = []\n self.headers = []\n self.include_dirs = []\n self.libraries = []\n self.library_dirs = []\n self.sources = []\n self.support_code = []\n self.module_init_code = []\n self.warnings = []\n self.define_macros = []\n self.use_ref_count = 1\n self.name = \"no_name\"\n self.c_type = 'PyObject*'\n self.to_c_return = 'py_obj'\n \n def info_object(self):\n return base_info.custom_info()\n \n def generate_build_info(self):\n info = self.info_object()\n for header in self.headers:\n info.add_header(header)\n for d in self.include_dirs:\n info.add_include_dir(d)\n for lib in self.libraries:\n info.add_library(lib)\n for d in self.library_dirs:\n info.add_library_dir(d)\n for source in self.sources:\n info.add_source(source)\n for code in self.support_code:\n info.add_support_code(code)\n info.add_support_code(self.py_to_c_code())\n info.add_support_code(self.c_to_py_code())\n for init_code in self.module_init_code:\n info.add_module_init_code(init_code)\n for macro in self.define_macros:\n info.add_define_macro(macro)\n for warning in self.warnings:\n info.add_warning(warning)\n return info\n\n def type_match(self,value):\n return type(value) in self.matching_types\n\n def get_var_type(self,value):\n return type(value)\n \n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n new_spec.var_type = self.get_var_type(value)\n return new_spec\n\n def template_vars(self,inline=0):\n d = {}\n d['type_name'] = self.type_name\n d['check_func'] = self.check_func\n d['c_type'] = self.c_type\n d['to_c_return'] = self.to_c_return\n d['name'] = self.name\n d['py_var'] = self.py_variable()\n d['var_lookup'] = self.retrieve_py_variable(inline)\n code = 'convert_to_%(type_name)s(%(py_var)s,\"%(name)s\")' % d\n d['var_convert'] = code\n if self.use_ref_count:\n d['inc_ref_count'] = \"Py_INCREF(py_obj);\"\n else:\n d['inc_ref_count'] = \"\"\n return d\n\n def py_to_c_code(self):\n return py_to_c_template % self.template_vars()\n\n def c_to_py_code(self):\n return simple_c_to_py_template % self.template_vars()\n \n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(name)s = %(var_convert)s;\\n' % \\\n self.template_vars(inline=inline)\n return code \n\n def cleanup_code(self):\n if self.use_ref_count:\n code = \"Py_XDECREF(%(py_var)s);\\n\" % self.template_vars()\n else:\n code = \"\" \n return code\n \n def __repr__(self):\n msg = \"(file:: name: %s)\" % self.name\n return msg\n def __cmp__(self,other):\n #only works for equal\n result = -1\n try:\n result = cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n except AttributeError:\n pass\n return result \n\n#----------------------------------------------------------------------------\n# Module Converter\n#----------------------------------------------------------------------------\nclass module_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'module'\n self.check_func = 'PyModule_Check' \n # probably should test for callable classes here also.\n self.matching_types = [ModuleType]\n\n#----------------------------------------------------------------------------\n# Instance Converter\n#----------------------------------------------------------------------------\nclass instance_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'instance'\n self.check_func = 'PyInstance_Check' \n self.matching_types = [InstanceType]\n\n#----------------------------------------------------------------------------\n# Catchall Converter\n#----------------------------------------------------------------------------\nclass catchall_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'catchall'\n self.check_func = '' \n def type_match(self,value):\n return 1\n\n#----------------------------------------------------------------------------\n# String Converter\n#----------------------------------------------------------------------------\nclass string_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'string'\n self.check_func = 'PyString_Check' \n self.c_type = 'std::string'\n self.to_c_return = \"std::string(PyString_AsString(py_obj))\"\n self.matching_types = [StringType]\n self.headers.append('')\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* string_to_py(std::string s)\n {\n return PyString_FromString(s.c_str());\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n# Unicode Converter\n#----------------------------------------------------------------------------\nclass unicode_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'unicode'\n self.check_func = 'PyUnicode_Check'\n # This isn't supported by gcc 2.95.3 -- MSVC works fine with it. \n #self.c_type = 'std::wstring'\n #self.to_c_return = \"std::wstring(PyUnicode_AS_UNICODE(py_obj))\"\n self.c_type = 'Py_UNICODE*'\n self.to_c_return = \"PyUnicode_AS_UNICODE(py_obj)\"\n self.matching_types = [UnicodeType]\n #self.headers.append('')\n#----------------------------------------------------------------------------\n# File Converter\n#----------------------------------------------------------------------------\nclass file_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'file'\n self.check_func = 'PyFile_Check' \n self.c_type = 'FILE*'\n self.to_c_return = \"PyFile_AsFile(py_obj)\"\n self.headers = ['']\n self.matching_types = [FileType]\n\n def c_to_py_code(self):\n # !! Need to dedent returned code.\n code = \"\"\"\n PyObject* file_to_py(FILE* file, char* name, char* mode)\n {\n PyObject* py_obj = NULL;\n //extern int fclose(FILE *);\n return (PyObject*) PyFile_FromFile(file, name, mode, fclose);\n }\n \"\"\"\n return code \n\n#----------------------------------------------------------------------------\n#\n# Scalar Number Conversions\n#\n#----------------------------------------------------------------------------\n\n# the following typemaps are for 32 bit platforms. A way to do this\n# general case? maybe ask numeric types how long they are and base\n# the decisions on that.\n\n#----------------------------------------------------------------------------\n# Standard Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types = {}\nnum_to_c_types[type(1)] = 'int'\nnum_to_c_types[type(1.)] = 'double'\nnum_to_c_types[type(1.+1.j)] = 'std::complex '\n# !! hmmm. The following is likely unsafe...\nnum_to_c_types[type(1L)] = 'int'\n\n#----------------------------------------------------------------------------\n# Numeric array Python numeric --> C type maps\n#----------------------------------------------------------------------------\nnum_to_c_types['T'] = 'T' # for templates\nnum_to_c_types['F'] = 'std::complex '\nnum_to_c_types['D'] = 'std::complex '\nnum_to_c_types['f'] = 'float'\nnum_to_c_types['d'] = 'double'\nnum_to_c_types['1'] = 'char'\nnum_to_c_types['b'] = 'unsigned char'\nnum_to_c_types['s'] = 'short'\nnum_to_c_types['i'] = 'int'\n# not strictly correct, but shoulld be fine fo numeric work.\n# add test somewhere to make sure long can be cast to int before using.\nnum_to_c_types['l'] = 'int'\n\nclass scalar_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.warnings = ['disable: 4275', 'disable: 4101']\n self.headers = ['','']\n self.use_ref_count = 0\n\nclass int_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'int'\n self.check_func = 'PyInt_Check' \n self.c_type = 'int'\n self.to_c_return = \"(int) PyInt_AsLong(py_obj)\"\n self.matching_types = [IntType]\n\nclass long_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # !! long to int conversion isn't safe!\n self.type_name = 'long'\n self.check_func = 'PyLong_Check' \n self.c_type = 'int'\n self.to_c_return = \"(int) PyLong_AsLong(py_obj)\"\n self.matching_types = [LongType]\n\nclass float_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n # Not sure this is really that safe...\n self.type_name = 'float'\n self.check_func = 'PyFloat_Check' \n self.c_type = 'double'\n self.to_c_return = \"PyFloat_AsDouble(py_obj)\"\n self.matching_types = [FloatType]\n\nclass complex_converter(scalar_converter):\n def init_info(self):\n scalar_converter.init_info(self)\n self.type_name = 'complex'\n self.check_func = 'PyComplex_Check' \n self.c_type = 'std::complex'\n self.to_c_return = \"std::complex(PyComplex_RealAsDouble(py_obj),\"\\\n \"PyComplex_ImagAsDouble(py_obj))\"\n self.matching_types = [ComplexType]\n\n#----------------------------------------------------------------------------\n#\n# List, Tuple, and Dict converters.\n#\n# Based on SCXX by Gordon McMillan\n#----------------------------------------------------------------------------\nimport os, c_spec # yes, I import myself to find out my __file__ location.\nlocal_dir,junk = os.path.split(os.path.abspath(c_spec.__file__)) \nscxx_dir = os.path.join(local_dir,'scxx')\n\nclass scxx_converter(common_base_converter):\n def init_info(self):\n common_base_converter.init_info(self)\n self.headers = ['\"scxx/PWOBase.h\"','\"scxx/PWOSequence.h\"',\n '\"scxx/PWOCallable.h\"','\"scxx/PWOMapping.h\"',\n '\"scxx/PWOSequence.h\"','\"scxx/PWOMSequence.h\"',\n '\"scxx/PWONumber.h\"','']\n self.include_dirs = [local_dir,scxx_dir]\n self.sources = [os.path.join(scxx_dir,'PWOImp.cpp'),]\n\nclass list_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'list'\n self.check_func = 'PyList_Check' \n self.c_type = 'PWOList'\n self.to_c_return = 'PWOList(py_obj)'\n self.matching_types = [ListType]\n # ref counting handled by PWOList\n self.use_ref_count = 0\n\nclass tuple_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'tuple'\n self.check_func = 'PyTuple_Check' \n self.c_type = 'PWOTuple'\n self.to_c_return = 'PWOTuple(py_obj)'\n self.matching_types = [TupleType]\n # ref counting handled by PWOTuple\n self.use_ref_count = 0\n\nclass dict_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.support_code.append(\"#define PWODict PWOMapping\")\n self.type_name = 'dict'\n self.check_func = 'PyDict_Check' \n self.c_type = 'PWODict'\n self.to_c_return = 'PWODict(py_obj)'\n self.matching_types = [DictType]\n # ref counting handled by PWODict\n self.use_ref_count = 0\n\n#----------------------------------------------------------------------------\n# Callable Converter\n#----------------------------------------------------------------------------\nclass callable_converter(scxx_converter):\n def init_info(self):\n scxx_converter.init_info(self)\n self.type_name = 'callable'\n self.check_func = 'PyCallable_Check' \n # probably should test for callable classes here also.\n self.matching_types = [FunctionType,MethodType,type(len)]\n self.c_type = 'PWOCallable'\n self.to_c_return = 'PWOCallable(py_obj)'\n # ref counting handled by PWOCallable\n self.use_ref_count = 0\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == \"__main__\":\n x = list_converter().type_spec(\"x\",1)\n print x.py_to_c_code()\n print\n print x.c_to_py_code()\n print\n print x.declaration_code(inline=1)\n print\n print x.cleanup_code()", "methods": [ { "name": "__init__", "long_name": "__init__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 15, "complexity": 1, "token_count": 85, "parameters": [ "self" ], "start_line": 70, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "info_object", "long_name": "info_object( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 86, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "c_spec.py", "nloc": 23, "complexity": 10, "token_count": 151, "parameters": [ "self" ], "start_line": 89, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 113, "end_line": 114, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_var_type", "long_name": "get_var_type( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "value" ], "start_line": 116, "end_line": 117, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 33, "parameters": [ "self", "name", "value" ], "start_line": 119, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "c_spec.py", "nloc": 16, "complexity": 2, "token_count": 106, "parameters": [ "self", "inline" ], "start_line": 126, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 143, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 146, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "self", "templatize", "inline" ], "start_line": 149, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "c_spec.py", "nloc": 6, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 155, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 163, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "c_spec.py", "nloc": 8, "complexity": 3, "token_count": 43, "parameters": [ "self", "other" ], "start_line": 166, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "self" ], "start_line": 180, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "self" ], "start_line": 191, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 4, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 201, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "value" ], "start_line": 205, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 46, "parameters": [ "self" ], "start_line": 212, "end_line": 219, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 220, "end_line": 228, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 234, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 249, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 10, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 258, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 307, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 314, "end_line": 320, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 323, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 333, "end_line": 340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 343, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 363, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 373, "end_line": 381, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 384, "end_line": 392, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 395, "end_line": 404, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 50, "parameters": [ "self" ], "start_line": 410, "end_line": 419, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 421, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 425, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 15, "complexity": 1, "token_count": 85, "parameters": [ "self" ], "start_line": 70, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "info_object", "long_name": "info_object( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 86, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate_build_info", "long_name": "generate_build_info( self )", "filename": "c_spec.py", "nloc": 23, "complexity": 10, "token_count": 151, "parameters": [ "self" ], "start_line": 89, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 113, "end_line": 114, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_var_type", "long_name": "get_var_type( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "value" ], "start_line": 116, "end_line": 117, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 33, "parameters": [ "self", "name", "value" ], "start_line": 119, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "c_spec.py", "nloc": 16, "complexity": 2, "token_count": 106, "parameters": [ "self", "inline" ], "start_line": 126, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "py_to_c_code", "long_name": "py_to_c_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 143, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 146, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "self", "templatize", "inline" ], "start_line": 149, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "c_spec.py", "nloc": 6, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 155, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 162, "end_line": 164, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "c_spec.py", "nloc": 8, "complexity": 3, "token_count": 43, "parameters": [ "self", "other" ], "start_line": 165, "end_line": 173, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "self" ], "start_line": 179, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "self" ], "start_line": 190, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 4, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 200, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "c_spec.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "value" ], "start_line": 204, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 46, "parameters": [ "self" ], "start_line": 211, "end_line": 218, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 219, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 233, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 248, "end_line": 255, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "c_to_py_code", "long_name": "c_to_py_code( self )", "filename": "c_spec.py", "nloc": 10, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 257, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 5, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 306, "end_line": 310, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 313, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 322, "end_line": 329, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 7, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 332, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 342, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 362, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 372, "end_line": 380, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 383, "end_line": 391, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 9, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 394, "end_line": 403, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "init_info", "long_name": "init_info( self )", "filename": "c_spec.py", "nloc": 8, "complexity": 1, "token_count": 50, "parameters": [ "self" ], "start_line": 409, "end_line": 418, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 420, "end_line": 422, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "c_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 424, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "c_spec.py", "nloc": 16, "complexity": 2, "token_count": 106, "parameters": [ "self", "inline" ], "start_line": 126, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "c_spec.py", "nloc": 6, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 155, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 } ], "nloc": 320, "complexity": 48, "token_count": 1634, "diff_parsed": { "added": [ " d['inc_ref_count'] = \"Py_XINCREF(py_obj);\"", " code = 'Py_XDECREF(%(py_var)s);\\n' % self.template_vars()", " #code += 'printf(\"cleaning up %(py_var)s\\\\n\");\\n' % self.template_vars()" ], "deleted": [ " d['inc_ref_count'] = \"Py_INCREF(py_obj);\"", " code = \"Py_XDECREF(%(py_var)s);\\n\" % self.template_vars()" ] } }, { "old_path": "weave/common_info.py", "new_path": "weave/common_info.py", "filename": "common_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -32,7 +32,9 @@\n \n void throw_error(PyObject* exc, const char* msg)\n {\n+ //printf(\"setting python error: %s\\\\n\",msg);\n PyErr_SetString(exc, msg);\n+ //printf(\"throwing error\\\\n\");\n throw 1;\n }\n \n", "added_lines": 2, "deleted_lines": 0, "source_code": "\"\"\" Generic support code for: \n error handling code found in every weave module \n local/global dictionary access code for inline() modules\n swig pointer (old style) conversion support\n \n\"\"\"\n\nimport base_info\n\nmodule_support_code = \\\n\"\"\"\n\nchar* find_type(PyObject* py_obj)\n{\n if(py_obj == NULL) return \"C NULL value\";\n if(PyCallable_Check(py_obj)) return \"callable\";\n if(PyString_Check(py_obj)) return \"string\";\n if(PyInt_Check(py_obj)) return \"int\";\n if(PyFloat_Check(py_obj)) return \"float\";\n if(PyDict_Check(py_obj)) return \"dict\";\n if(PyList_Check(py_obj)) return \"list\";\n if(PyTuple_Check(py_obj)) return \"tuple\";\n if(PyFile_Check(py_obj)) return \"file\";\n if(PyModule_Check(py_obj)) return \"module\";\n \n //should probably do more intergation (and thinking) on these.\n if(PyCallable_Check(py_obj) && PyInstance_Check(py_obj)) return \"callable\";\n if(PyInstance_Check(py_obj)) return \"instance\"; \n if(PyCallable_Check(py_obj)) return \"callable\";\n return \"unkown type\";\n}\n\nvoid throw_error(PyObject* exc, const char* msg)\n{\n //printf(\"setting python error: %s\\\\n\",msg);\n PyErr_SetString(exc, msg);\n //printf(\"throwing error\\\\n\");\n throw 1;\n}\n\nvoid handle_bad_type(PyObject* py_obj, const char* good_type, const char* var_name)\n{\n char msg[500];\n sprintf(msg,\"received '%s' type instead of '%s' for variable '%s'\",\n find_type(py_obj),good_type,var_name);\n throw_error(PyExc_TypeError,msg); \n}\n\nvoid handle_conversion_error(PyObject* py_obj, const char* good_type, const char* var_name)\n{\n char msg[500];\n sprintf(msg,\"Conversion Error:, received '%s' type instead of '%s' for variable '%s'\",\n find_type(py_obj),good_type,var_name);\n throw_error(PyExc_TypeError,msg);\n}\n\n\"\"\"\n\nclass basic_module_info(base_info.base_info):\n _headers = ['\"Python.h\"']\n _support_code = [module_support_code]\n\n#----------------------------------------------------------------------------\n# inline() generated support code\n#\n# The following two function declarations handle access to variables in the \n# global and local dictionaries for inline functions.\n#----------------------------------------------------------------------------\n\nget_variable_support_code = \\\n\"\"\"\nvoid handle_variable_not_found(char* var_name)\n{\n char msg[500];\n sprintf(msg,\"Conversion Error: variable '%s' not found in local or global scope.\",var_name);\n throw_error(PyExc_NameError,msg);\n}\nPyObject* get_variable(char* name,PyObject* locals, PyObject* globals)\n{\n // no checking done for error -- locals and globals should\n // already be validated as dictionaries. If var is NULL, the\n // function calling this should handle it.\n PyObject* var = NULL;\n var = PyDict_GetItemString(locals,name);\n if (!var)\n {\n var = PyDict_GetItemString(globals,name);\n }\n if (!var)\n handle_variable_not_found(name);\n return var;\n}\n\"\"\"\n\npy_to_raw_dict_support_code = \\\n\"\"\"\nPyObject* py_to_raw_dict(PyObject* py_obj, char* name)\n{\n // simply check that the value is a valid dictionary pointer.\n if(!py_obj || !PyDict_Check(py_obj))\n handle_bad_type(py_obj, \"dictionary\", name);\n return py_obj;\n}\n\"\"\"\n\nclass inline_info(base_info.base_info):\n _support_code = [get_variable_support_code, py_to_raw_dict_support_code]\n\n\n#----------------------------------------------------------------------------\n# swig pointer support code\n#\n# The support code for swig is just slirped in from the swigptr.c file \n# from the *old* swig distribution. New style swig pointers are not\n# yet supported.\n#----------------------------------------------------------------------------\n\nimport os, common_info\nlocal_dir,junk = os.path.split(os.path.abspath(common_info.__file__)) \nf = open(os.path.join(local_dir,'swig','swigptr.c'))\nswig_support_code = f.read()\nf.close()\n\nclass swig_info(base_info.base_info):\n _support_code = [swig_support_code]\n", "source_code_before": "\"\"\" Generic support code for: \n error handling code found in every weave module \n local/global dictionary access code for inline() modules\n swig pointer (old style) conversion support\n \n\"\"\"\n\nimport base_info\n\nmodule_support_code = \\\n\"\"\"\n\nchar* find_type(PyObject* py_obj)\n{\n if(py_obj == NULL) return \"C NULL value\";\n if(PyCallable_Check(py_obj)) return \"callable\";\n if(PyString_Check(py_obj)) return \"string\";\n if(PyInt_Check(py_obj)) return \"int\";\n if(PyFloat_Check(py_obj)) return \"float\";\n if(PyDict_Check(py_obj)) return \"dict\";\n if(PyList_Check(py_obj)) return \"list\";\n if(PyTuple_Check(py_obj)) return \"tuple\";\n if(PyFile_Check(py_obj)) return \"file\";\n if(PyModule_Check(py_obj)) return \"module\";\n \n //should probably do more intergation (and thinking) on these.\n if(PyCallable_Check(py_obj) && PyInstance_Check(py_obj)) return \"callable\";\n if(PyInstance_Check(py_obj)) return \"instance\"; \n if(PyCallable_Check(py_obj)) return \"callable\";\n return \"unkown type\";\n}\n\nvoid throw_error(PyObject* exc, const char* msg)\n{\n PyErr_SetString(exc, msg);\n throw 1;\n}\n\nvoid handle_bad_type(PyObject* py_obj, const char* good_type, const char* var_name)\n{\n char msg[500];\n sprintf(msg,\"received '%s' type instead of '%s' for variable '%s'\",\n find_type(py_obj),good_type,var_name);\n throw_error(PyExc_TypeError,msg); \n}\n\nvoid handle_conversion_error(PyObject* py_obj, const char* good_type, const char* var_name)\n{\n char msg[500];\n sprintf(msg,\"Conversion Error:, received '%s' type instead of '%s' for variable '%s'\",\n find_type(py_obj),good_type,var_name);\n throw_error(PyExc_TypeError,msg);\n}\n\n\"\"\"\n\nclass basic_module_info(base_info.base_info):\n _headers = ['\"Python.h\"']\n _support_code = [module_support_code]\n\n#----------------------------------------------------------------------------\n# inline() generated support code\n#\n# The following two function declarations handle access to variables in the \n# global and local dictionaries for inline functions.\n#----------------------------------------------------------------------------\n\nget_variable_support_code = \\\n\"\"\"\nvoid handle_variable_not_found(char* var_name)\n{\n char msg[500];\n sprintf(msg,\"Conversion Error: variable '%s' not found in local or global scope.\",var_name);\n throw_error(PyExc_NameError,msg);\n}\nPyObject* get_variable(char* name,PyObject* locals, PyObject* globals)\n{\n // no checking done for error -- locals and globals should\n // already be validated as dictionaries. If var is NULL, the\n // function calling this should handle it.\n PyObject* var = NULL;\n var = PyDict_GetItemString(locals,name);\n if (!var)\n {\n var = PyDict_GetItemString(globals,name);\n }\n if (!var)\n handle_variable_not_found(name);\n return var;\n}\n\"\"\"\n\npy_to_raw_dict_support_code = \\\n\"\"\"\nPyObject* py_to_raw_dict(PyObject* py_obj, char* name)\n{\n // simply check that the value is a valid dictionary pointer.\n if(!py_obj || !PyDict_Check(py_obj))\n handle_bad_type(py_obj, \"dictionary\", name);\n return py_obj;\n}\n\"\"\"\n\nclass inline_info(base_info.base_info):\n _support_code = [get_variable_support_code, py_to_raw_dict_support_code]\n\n\n#----------------------------------------------------------------------------\n# swig pointer support code\n#\n# The support code for swig is just slirped in from the swigptr.c file \n# from the *old* swig distribution. New style swig pointers are not\n# yet supported.\n#----------------------------------------------------------------------------\n\nimport os, common_info\nlocal_dir,junk = os.path.split(os.path.abspath(common_info.__file__)) \nf = open(os.path.join(local_dir,'swig','swigptr.c'))\nswig_support_code = f.read()\nf.close()\n\nclass swig_info(base_info.base_info):\n _support_code = [swig_support_code]\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 101, "complexity": 0, "token_count": 115, "diff_parsed": { "added": [ " //printf(\"setting python error: %s\\\\n\",msg);", " //printf(\"throwing error\\\\n\");" ], "deleted": [] } }, { "old_path": "weave/ext_tools.py", "new_path": "weave/ext_tools.py", "filename": "ext_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -134,13 +134,13 @@ def function_code(self):\n \n return_code = \" /*cleanup code*/ \\n\" + \\\n cleanup_code + \\\n- \" if(!return_val && !exception_occured)\\n\" \\\n- \" {\\n \\n\" \\\n- \" Py_INCREF(Py_None); \\n\" \\\n- \" return_val = Py_None; \\n\" \\\n- \" }\\n \\n\" \\\n- \" return return_val; \\n\" \\\n- \"} \\n\"\n+ ' if(!return_val && !exception_occured)\\n' \\\n+ ' {\\n \\n' \\\n+ ' Py_INCREF(Py_None); \\n' \\\n+ ' return_val = Py_None; \\n' \\\n+ ' }\\n \\n' \\\n+ ' return return_val; \\n' \\\n+ '} \\n'\n \n all_code = self.function_declaration_code() + \\\n indent(self.parse_tuple_code(),4) + \\\n@@ -276,6 +276,7 @@ def generate_file(self,file_name=\"\",location='.'):\n return generate_module(code,name)\n \n def set_compiler(self,compiler):\n+ # This is not used anymore -- I think we should ditch it.\n #for i in self.arg_specs()\n # i.set_compiler(compiler)\n for i in self.build_information():\n@@ -288,10 +289,14 @@ def compile(self,location='.',compiler=None, verbose = 0, **kw):\n \n if compiler is not None:\n self.compiler = compiler\n+ \n+ # !! removed -- we don't have any compiler dependent code\n+ # currently in spec or info classes \n # hmm. Is there a cleaner way to do this? Seems like\n- # choosing the compiler spagettis around a little.\n- compiler = build_tools.choose_compiler(self.compiler) \n- self.set_compiler(compiler)\n+ # choosing the compiler spagettis around a little. \n+ #compiler = build_tools.choose_compiler(self.compiler) \n+ #self.set_compiler(compiler)\n+ \n arg_specs = self.arg_specs()\n info = self.build_information()\n _source_files = info.sources()\n@@ -316,6 +321,7 @@ def compile(self,location='.',compiler=None, verbose = 0, **kw):\n #temp = catalog.default_temp_dir()\n # for speed, build in the machines temp directory\n temp = catalog.intermediate_dir()\n+ \n success = build_tools.build_extension(file, temp_dir = temp,\n sources = source_files, \n compiler_name = compiler,\n", "added_lines": 16, "deleted_lines": 10, "source_code": "import os, sys\nimport string, re\n\nimport catalog \nimport build_tools\nimport converters\nimport base_spec\n\nclass ext_function_from_specs:\n def __init__(self,name,code_block,arg_specs):\n self.name = name\n self.arg_specs = base_spec.arg_spec_list(arg_specs)\n self.code_block = code_block\n self.compiler = ''\n self.customize = base_info.custom_info()\n \n def header_code(self):\n pass\n\n def function_declaration_code(self):\n code = 'static PyObject* %s(PyObject*self, PyObject* args,' \\\n ' PyObject* kywds)\\n{\\n'\n return code % self.name\n\n def template_declaration_code(self):\n code = 'template\\n' \\\n 'static PyObject* %s(PyObject*self, PyObject* args,' \\\n ' PyObject* kywds)\\n{\\n'\n return code % self.name\n\n #def cpp_function_declaration_code(self):\n # pass\n #def cpp_function_call_code(self):\n #s pass\n \n def parse_tuple_code(self):\n \"\"\" Create code block for PyArg_ParseTuple. Variable declarations\n for all PyObjects are done also.\n \n This code got a lot uglier when I added local_dict...\n \"\"\"\n join = string.join\n\n declare_return = 'PyObject *return_val = NULL;\\n' \\\n 'int exception_occured = 0;\\n' \\\n 'PyObject *py_local_dict = NULL;\\n'\n arg_string_list = self.arg_specs.variable_as_strings() + ['\"local_dict\"']\n arg_strings = join(arg_string_list,',')\n if arg_strings: arg_strings += ','\n declare_kwlist = 'static char *kwlist[] = {%s NULL};\\n' % arg_strings\n\n py_objects = join(self.arg_specs.py_pointers(),', ')\n init_flags = join(self.arg_specs.init_flags(),', ')\n init_flags_init = join(self.arg_specs.init_flags(),'= ')\n py_vars = join(self.arg_specs.py_variables(),' = ')\n if py_objects:\n declare_py_objects = 'PyObject ' + py_objects +';\\n'\n declare_py_objects += 'int '+ init_flags + ';\\n' \n init_values = py_vars + ' = NULL;\\n'\n init_values += init_flags_init + ' = 0;\\n\\n'\n else:\n declare_py_objects = ''\n init_values = '' \n\n #Each variable is in charge of its own cleanup now.\n #cnt = len(arg_list)\n #declare_cleanup = \"blitz::TinyVector clean_up(0);\\n\" % cnt\n\n ref_string = join(self.arg_specs.py_references(),', ')\n if ref_string:\n ref_string += ', &py_local_dict'\n else:\n ref_string = '&py_local_dict'\n \n format = \"O\"* len(self.arg_specs) + \"|O\" + ':' + self.name\n parse_tuple = 'if(!PyArg_ParseTupleAndKeywords(args,' \\\n 'kywds,\"%s\",kwlist,%s))\\n' % (format,ref_string)\n parse_tuple += ' return NULL;\\n'\n\n return declare_return + declare_kwlist + declare_py_objects \\\n + init_values + parse_tuple\n\n def arg_declaration_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.declaration_code())\n arg_strings.append(arg.init_flag() +\" = 1;\\n\")\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_cleanup_code(self):\n arg_strings = []\n have_cleanup = filter(lambda x:x.cleanup_code(),self.arg_specs)\n for arg in have_cleanup:\n code = \"if(%s)\\n\" % arg.init_flag()\n code += \"{\\n\"\n code += indent(arg.cleanup_code(),4)\n code += \"}\\n\"\n arg_strings.append(code)\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_local_dict_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.local_dict_code())\n code = string.join(arg_strings,\"\")\n return code\n \n def function_code(self):\n decl_code = indent(self.arg_declaration_code(),4)\n cleanup_code = indent(self.arg_cleanup_code(),4)\n function_code = indent(self.code_block,4)\n local_dict_code = indent(self.arg_local_dict_code(),4)\n\n dict_code = \"if(py_local_dict) \\n\" \\\n \"{ \\n\" \\\n \" PWODict local_dict = PWODict(py_local_dict); \\n\" + \\\n local_dict_code + \\\n \"} \\n\"\n\n try_code = \"try \\n\" \\\n \"{ \\n\" + \\\n decl_code + \\\n \" /**/ \\n\" + \\\n function_code + \\\n indent(dict_code,4) + \\\n \"\\n} \\n\"\n catch_code = \"catch(...) \\n\" \\\n \"{ \\n\" + \\\n \" return_val = NULL; \\n\" \\\n \" exception_occured = 1; \\n\" \\\n \"} \\n\"\n\n return_code = \" /*cleanup code*/ \\n\" + \\\n cleanup_code + \\\n ' if(!return_val && !exception_occured)\\n' \\\n ' {\\n \\n' \\\n ' Py_INCREF(Py_None); \\n' \\\n ' return_val = Py_None; \\n' \\\n ' }\\n \\n' \\\n ' return return_val; \\n' \\\n '} \\n'\n\n all_code = self.function_declaration_code() + \\\n indent(self.parse_tuple_code(),4) + \\\n indent(try_code,4) + \\\n indent(catch_code,4) + \\\n return_code\n\n return all_code\n\n def python_function_definition_code(self):\n args = (self.name, self.name)\n function_decls = '{\"%s\",(PyCFunction)%s , METH_VARARGS|' \\\n 'METH_KEYWORDS},\\n' % args\n return function_decls\n\n def set_compiler(self,compiler):\n self.compiler = compiler\n for arg in self.arg_specs:\n arg.set_compiler(compiler)\n\n\nclass ext_function(ext_function_from_specs):\n def __init__(self,name,code_block, args, local_dict=None, global_dict=None,\n auto_downcast=1, type_converters=None):\n \n call_frame = sys._getframe().f_back\n if local_dict is None:\n local_dict = call_frame.f_locals\n if global_dict is None:\n global_dict = call_frame.f_globals\n if type_converters is None:\n type_converters = converters.default\n arg_specs = assign_variable_types(args,local_dict, global_dict,\n auto_downcast, type_converters)\n ext_function_from_specs.__init__(self,name,code_block,arg_specs)\n \n \nimport base_info\n\nclass ext_module:\n def __init__(self,name,compiler=''):\n standard_info = converters.standard_info\n self.name = name\n self.functions = []\n self.compiler = compiler\n self.customize = base_info.custom_info()\n self._build_information = base_info.info_list(standard_info)\n \n def add_function(self,func):\n self.functions.append(func)\n def module_code(self):\n code = self.warning_code() + \\\n self.header_code() + \\\n self.support_code() + \\\n self.function_code() + \\\n self.python_function_definition_code() + \\\n self.module_init_code()\n return code\n\n def arg_specs(self):\n all_arg_specs = base_spec.arg_spec_list()\n for func in self.functions:\n all_arg_specs += func.arg_specs\n return all_arg_specs\n\n def build_information(self):\n info = [self.customize] + self._build_information + \\\n self.arg_specs().build_information()\n for func in self.functions:\n info.append(func.customize)\n #redundant, but easiest place to make sure compiler is set\n for i in info:\n i.set_compiler(self.compiler)\n return info\n \n def get_headers(self):\n all_headers = self.build_information().headers()\n\n # blitz/array.h always needs to be first so we hack that here...\n if '\"blitz/array.h\"' in all_headers:\n all_headers.remove('\"blitz/array.h\"')\n all_headers.insert(0,'\"blitz/array.h\"')\n return all_headers\n\n def warning_code(self):\n all_warnings = self.build_information().warnings()\n w=map(lambda x: \"#pragma warning(%s)\\n\" % x,all_warnings)\n return ''.join(w)\n \n def header_code(self):\n h = self.get_headers()\n h= map(lambda x: '#include ' + x + '\\n',h)\n return ''.join(h)\n\n def support_code(self):\n code = self.build_information().support_code()\n return ''.join(code)\n\n def function_code(self):\n all_function_code = \"\"\n for func in self.functions:\n all_function_code += func.function_code()\n return ''.join(all_function_code)\n\n def python_function_definition_code(self):\n all_definition_code = \"\"\n for func in self.functions:\n all_definition_code += func.python_function_definition_code()\n all_definition_code = indent(''.join(all_definition_code),4)\n code = 'static PyMethodDef compiled_methods[] = \\n' \\\n '{\\n' \\\n '%s' \\\n ' {NULL, NULL} /* Sentinel */\\n' \\\n '};\\n'\n return code % (all_definition_code)\n\n def module_init_code(self):\n init_code_list = self.build_information().module_init_code()\n init_code = indent(''.join(init_code_list),4)\n code = 'extern \"C\" void init%s()\\n' \\\n '{\\n' \\\n '%s' \\\n ' (void) Py_InitModule(\"%s\", compiled_methods);\\n' \\\n '}\\n' % (self.name,init_code,self.name)\n return code\n\n def generate_file(self,file_name=\"\",location='.'):\n code = self.module_code()\n if not file_name:\n file_name = self.name + '.cpp'\n name = generate_file_name(file_name,location)\n #return name\n return generate_module(code,name)\n\n def set_compiler(self,compiler):\n # This is not used anymore -- I think we should ditch it.\n #for i in self.arg_specs()\n # i.set_compiler(compiler)\n for i in self.build_information():\n i.set_compiler(compiler) \n for i in self.functions:\n i.set_compiler(compiler)\n self.compiler = compiler \n \n def compile(self,location='.',compiler=None, verbose = 0, **kw):\n \n if compiler is not None:\n self.compiler = compiler\n \n # !! removed -- we don't have any compiler dependent code\n # currently in spec or info classes \n # hmm. Is there a cleaner way to do this? Seems like\n # choosing the compiler spagettis around a little. \n #compiler = build_tools.choose_compiler(self.compiler) \n #self.set_compiler(compiler)\n \n arg_specs = self.arg_specs()\n info = self.build_information()\n _source_files = info.sources()\n # remove duplicates\n source_files = {}\n for i in _source_files:\n source_files[i] = None\n source_files = source_files.keys()\n \n # add internally specified macros, includes, etc. to the key words\n # values of the same names so that distutils will use them.\n kw['define_macros'] = kw.get('define_macros',[]) + info.define_macros()\n kw['include_dirs'] = kw.get('include_dirs',[]) + info.include_dirs()\n kw['libraries'] = kw.get('libraries',[]) + info.libraries()\n kw['library_dirs'] = kw.get('library_dirs',[]) + info.library_dirs()\n \n file = self.generate_file(location=location)\n # This is needed so that files build correctly even when different\n # versions of Python are running around.\n # Imported at beginning of file now to help with test paths.\n # import catalog \n #temp = catalog.default_temp_dir()\n # for speed, build in the machines temp directory\n temp = catalog.intermediate_dir()\n \n success = build_tools.build_extension(file, temp_dir = temp,\n sources = source_files, \n compiler_name = compiler,\n verbose = verbose, **kw)\n if not success:\n raise SystemError, 'Compilation failed'\n\ndef generate_file_name(module_name,module_location):\n module_file = os.path.join(module_location,module_name)\n return os.path.abspath(module_file)\n\ndef generate_module(module_string, module_file):\n f =open(module_file,'w')\n f.write(module_string)\n f.close()\n return module_file\n\ndef assign_variable_types(variables,local_dict = {}, global_dict = {},\n auto_downcast = 1,\n type_converters = converters.default):\n incoming_vars = {}\n incoming_vars.update(global_dict)\n incoming_vars.update(local_dict)\n variable_specs = []\n errors={}\n for var in variables:\n try:\n example_type = incoming_vars[var]\n\n # look through possible type specs to find which one\n # should be used to for example_type\n spec = None\n for factory in type_converters:\n if factory.type_match(example_type):\n spec = factory.type_spec(var,example_type)\n break \n if not spec:\n # should really define our own type.\n raise IndexError\n else:\n variable_specs.append(spec)\n except KeyError:\n errors[var] = (\"The type and dimensionality specifications\" +\n \"for variable '\" + var + \"' are missing.\")\n except IndexError:\n errors[var] = (\"Unable to convert variable '\"+ var +\n \"' to a C++ type.\")\n if errors:\n raise TypeError, format_error_msg(errors)\n\n if auto_downcast:\n variable_specs = downcast(variable_specs)\n return variable_specs\n\ndef downcast(var_specs):\n \"\"\" Cast python scalars down to most common type of\n arrays used.\n\n Right now, focus on complex and float types. Ignore int types.\n Require all arrays to have same type before forcing downcasts.\n\n Note: var_specs are currently altered in place (horrors...!)\n \"\"\"\n numeric_types = []\n\n #grab all the numeric types associated with a variables.\n for var in var_specs:\n if hasattr(var,'numeric_type'):\n numeric_types.append(var.numeric_type)\n\n # if arrays are present, but none of them are double precision,\n # make all numeric types float or complex(float)\n if ( ('f' in numeric_types or 'F' in numeric_types) and\n not ('d' in numeric_types or 'D' in numeric_types) ):\n for var in var_specs:\n if hasattr(var,'numeric_type'):\n # really should do this some other way...\n if var.numeric_type == type(1+1j):\n var.numeric_type = 'F'\n elif var.numeric_type == type(1.):\n var.numeric_type = 'f'\n return var_specs\n\ndef indent(st,spaces):\n indention = ' '*spaces\n indented = indention + string.replace(st,'\\n','\\n'+indention)\n # trim off any trailing spaces\n indented = re.sub(r' +$',r'',indented)\n return indented\n\ndef format_error_msg(errors):\n #minimum effort right now...\n import pprint,cStringIO\n msg = cStringIO.StringIO()\n pprint.pprint(errors,msg)\n return msg.getvalue()\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "source_code_before": "import os, sys\nimport string, re\n\nimport catalog \nimport build_tools\nimport converters\nimport base_spec\n\nclass ext_function_from_specs:\n def __init__(self,name,code_block,arg_specs):\n self.name = name\n self.arg_specs = base_spec.arg_spec_list(arg_specs)\n self.code_block = code_block\n self.compiler = ''\n self.customize = base_info.custom_info()\n \n def header_code(self):\n pass\n\n def function_declaration_code(self):\n code = 'static PyObject* %s(PyObject*self, PyObject* args,' \\\n ' PyObject* kywds)\\n{\\n'\n return code % self.name\n\n def template_declaration_code(self):\n code = 'template\\n' \\\n 'static PyObject* %s(PyObject*self, PyObject* args,' \\\n ' PyObject* kywds)\\n{\\n'\n return code % self.name\n\n #def cpp_function_declaration_code(self):\n # pass\n #def cpp_function_call_code(self):\n #s pass\n \n def parse_tuple_code(self):\n \"\"\" Create code block for PyArg_ParseTuple. Variable declarations\n for all PyObjects are done also.\n \n This code got a lot uglier when I added local_dict...\n \"\"\"\n join = string.join\n\n declare_return = 'PyObject *return_val = NULL;\\n' \\\n 'int exception_occured = 0;\\n' \\\n 'PyObject *py_local_dict = NULL;\\n'\n arg_string_list = self.arg_specs.variable_as_strings() + ['\"local_dict\"']\n arg_strings = join(arg_string_list,',')\n if arg_strings: arg_strings += ','\n declare_kwlist = 'static char *kwlist[] = {%s NULL};\\n' % arg_strings\n\n py_objects = join(self.arg_specs.py_pointers(),', ')\n init_flags = join(self.arg_specs.init_flags(),', ')\n init_flags_init = join(self.arg_specs.init_flags(),'= ')\n py_vars = join(self.arg_specs.py_variables(),' = ')\n if py_objects:\n declare_py_objects = 'PyObject ' + py_objects +';\\n'\n declare_py_objects += 'int '+ init_flags + ';\\n' \n init_values = py_vars + ' = NULL;\\n'\n init_values += init_flags_init + ' = 0;\\n\\n'\n else:\n declare_py_objects = ''\n init_values = '' \n\n #Each variable is in charge of its own cleanup now.\n #cnt = len(arg_list)\n #declare_cleanup = \"blitz::TinyVector clean_up(0);\\n\" % cnt\n\n ref_string = join(self.arg_specs.py_references(),', ')\n if ref_string:\n ref_string += ', &py_local_dict'\n else:\n ref_string = '&py_local_dict'\n \n format = \"O\"* len(self.arg_specs) + \"|O\" + ':' + self.name\n parse_tuple = 'if(!PyArg_ParseTupleAndKeywords(args,' \\\n 'kywds,\"%s\",kwlist,%s))\\n' % (format,ref_string)\n parse_tuple += ' return NULL;\\n'\n\n return declare_return + declare_kwlist + declare_py_objects \\\n + init_values + parse_tuple\n\n def arg_declaration_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.declaration_code())\n arg_strings.append(arg.init_flag() +\" = 1;\\n\")\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_cleanup_code(self):\n arg_strings = []\n have_cleanup = filter(lambda x:x.cleanup_code(),self.arg_specs)\n for arg in have_cleanup:\n code = \"if(%s)\\n\" % arg.init_flag()\n code += \"{\\n\"\n code += indent(arg.cleanup_code(),4)\n code += \"}\\n\"\n arg_strings.append(code)\n code = string.join(arg_strings,\"\")\n return code\n\n def arg_local_dict_code(self):\n arg_strings = []\n for arg in self.arg_specs:\n arg_strings.append(arg.local_dict_code())\n code = string.join(arg_strings,\"\")\n return code\n \n def function_code(self):\n decl_code = indent(self.arg_declaration_code(),4)\n cleanup_code = indent(self.arg_cleanup_code(),4)\n function_code = indent(self.code_block,4)\n local_dict_code = indent(self.arg_local_dict_code(),4)\n\n dict_code = \"if(py_local_dict) \\n\" \\\n \"{ \\n\" \\\n \" PWODict local_dict = PWODict(py_local_dict); \\n\" + \\\n local_dict_code + \\\n \"} \\n\"\n\n try_code = \"try \\n\" \\\n \"{ \\n\" + \\\n decl_code + \\\n \" /**/ \\n\" + \\\n function_code + \\\n indent(dict_code,4) + \\\n \"\\n} \\n\"\n catch_code = \"catch(...) \\n\" \\\n \"{ \\n\" + \\\n \" return_val = NULL; \\n\" \\\n \" exception_occured = 1; \\n\" \\\n \"} \\n\"\n\n return_code = \" /*cleanup code*/ \\n\" + \\\n cleanup_code + \\\n \" if(!return_val && !exception_occured)\\n\" \\\n \" {\\n \\n\" \\\n \" Py_INCREF(Py_None); \\n\" \\\n \" return_val = Py_None; \\n\" \\\n \" }\\n \\n\" \\\n \" return return_val; \\n\" \\\n \"} \\n\"\n\n all_code = self.function_declaration_code() + \\\n indent(self.parse_tuple_code(),4) + \\\n indent(try_code,4) + \\\n indent(catch_code,4) + \\\n return_code\n\n return all_code\n\n def python_function_definition_code(self):\n args = (self.name, self.name)\n function_decls = '{\"%s\",(PyCFunction)%s , METH_VARARGS|' \\\n 'METH_KEYWORDS},\\n' % args\n return function_decls\n\n def set_compiler(self,compiler):\n self.compiler = compiler\n for arg in self.arg_specs:\n arg.set_compiler(compiler)\n\n\nclass ext_function(ext_function_from_specs):\n def __init__(self,name,code_block, args, local_dict=None, global_dict=None,\n auto_downcast=1, type_converters=None):\n \n call_frame = sys._getframe().f_back\n if local_dict is None:\n local_dict = call_frame.f_locals\n if global_dict is None:\n global_dict = call_frame.f_globals\n if type_converters is None:\n type_converters = converters.default\n arg_specs = assign_variable_types(args,local_dict, global_dict,\n auto_downcast, type_converters)\n ext_function_from_specs.__init__(self,name,code_block,arg_specs)\n \n \nimport base_info\n\nclass ext_module:\n def __init__(self,name,compiler=''):\n standard_info = converters.standard_info\n self.name = name\n self.functions = []\n self.compiler = compiler\n self.customize = base_info.custom_info()\n self._build_information = base_info.info_list(standard_info)\n \n def add_function(self,func):\n self.functions.append(func)\n def module_code(self):\n code = self.warning_code() + \\\n self.header_code() + \\\n self.support_code() + \\\n self.function_code() + \\\n self.python_function_definition_code() + \\\n self.module_init_code()\n return code\n\n def arg_specs(self):\n all_arg_specs = base_spec.arg_spec_list()\n for func in self.functions:\n all_arg_specs += func.arg_specs\n return all_arg_specs\n\n def build_information(self):\n info = [self.customize] + self._build_information + \\\n self.arg_specs().build_information()\n for func in self.functions:\n info.append(func.customize)\n #redundant, but easiest place to make sure compiler is set\n for i in info:\n i.set_compiler(self.compiler)\n return info\n \n def get_headers(self):\n all_headers = self.build_information().headers()\n\n # blitz/array.h always needs to be first so we hack that here...\n if '\"blitz/array.h\"' in all_headers:\n all_headers.remove('\"blitz/array.h\"')\n all_headers.insert(0,'\"blitz/array.h\"')\n return all_headers\n\n def warning_code(self):\n all_warnings = self.build_information().warnings()\n w=map(lambda x: \"#pragma warning(%s)\\n\" % x,all_warnings)\n return ''.join(w)\n \n def header_code(self):\n h = self.get_headers()\n h= map(lambda x: '#include ' + x + '\\n',h)\n return ''.join(h)\n\n def support_code(self):\n code = self.build_information().support_code()\n return ''.join(code)\n\n def function_code(self):\n all_function_code = \"\"\n for func in self.functions:\n all_function_code += func.function_code()\n return ''.join(all_function_code)\n\n def python_function_definition_code(self):\n all_definition_code = \"\"\n for func in self.functions:\n all_definition_code += func.python_function_definition_code()\n all_definition_code = indent(''.join(all_definition_code),4)\n code = 'static PyMethodDef compiled_methods[] = \\n' \\\n '{\\n' \\\n '%s' \\\n ' {NULL, NULL} /* Sentinel */\\n' \\\n '};\\n'\n return code % (all_definition_code)\n\n def module_init_code(self):\n init_code_list = self.build_information().module_init_code()\n init_code = indent(''.join(init_code_list),4)\n code = 'extern \"C\" void init%s()\\n' \\\n '{\\n' \\\n '%s' \\\n ' (void) Py_InitModule(\"%s\", compiled_methods);\\n' \\\n '}\\n' % (self.name,init_code,self.name)\n return code\n\n def generate_file(self,file_name=\"\",location='.'):\n code = self.module_code()\n if not file_name:\n file_name = self.name + '.cpp'\n name = generate_file_name(file_name,location)\n #return name\n return generate_module(code,name)\n\n def set_compiler(self,compiler):\n #for i in self.arg_specs()\n # i.set_compiler(compiler)\n for i in self.build_information():\n i.set_compiler(compiler) \n for i in self.functions:\n i.set_compiler(compiler)\n self.compiler = compiler \n \n def compile(self,location='.',compiler=None, verbose = 0, **kw):\n \n if compiler is not None:\n self.compiler = compiler\n # hmm. Is there a cleaner way to do this? Seems like\n # choosing the compiler spagettis around a little.\n compiler = build_tools.choose_compiler(self.compiler) \n self.set_compiler(compiler)\n arg_specs = self.arg_specs()\n info = self.build_information()\n _source_files = info.sources()\n # remove duplicates\n source_files = {}\n for i in _source_files:\n source_files[i] = None\n source_files = source_files.keys()\n \n # add internally specified macros, includes, etc. to the key words\n # values of the same names so that distutils will use them.\n kw['define_macros'] = kw.get('define_macros',[]) + info.define_macros()\n kw['include_dirs'] = kw.get('include_dirs',[]) + info.include_dirs()\n kw['libraries'] = kw.get('libraries',[]) + info.libraries()\n kw['library_dirs'] = kw.get('library_dirs',[]) + info.library_dirs()\n \n file = self.generate_file(location=location)\n # This is needed so that files build correctly even when different\n # versions of Python are running around.\n # Imported at beginning of file now to help with test paths.\n # import catalog \n #temp = catalog.default_temp_dir()\n # for speed, build in the machines temp directory\n temp = catalog.intermediate_dir()\n success = build_tools.build_extension(file, temp_dir = temp,\n sources = source_files, \n compiler_name = compiler,\n verbose = verbose, **kw)\n if not success:\n raise SystemError, 'Compilation failed'\n\ndef generate_file_name(module_name,module_location):\n module_file = os.path.join(module_location,module_name)\n return os.path.abspath(module_file)\n\ndef generate_module(module_string, module_file):\n f =open(module_file,'w')\n f.write(module_string)\n f.close()\n return module_file\n\ndef assign_variable_types(variables,local_dict = {}, global_dict = {},\n auto_downcast = 1,\n type_converters = converters.default):\n incoming_vars = {}\n incoming_vars.update(global_dict)\n incoming_vars.update(local_dict)\n variable_specs = []\n errors={}\n for var in variables:\n try:\n example_type = incoming_vars[var]\n\n # look through possible type specs to find which one\n # should be used to for example_type\n spec = None\n for factory in type_converters:\n if factory.type_match(example_type):\n spec = factory.type_spec(var,example_type)\n break \n if not spec:\n # should really define our own type.\n raise IndexError\n else:\n variable_specs.append(spec)\n except KeyError:\n errors[var] = (\"The type and dimensionality specifications\" +\n \"for variable '\" + var + \"' are missing.\")\n except IndexError:\n errors[var] = (\"Unable to convert variable '\"+ var +\n \"' to a C++ type.\")\n if errors:\n raise TypeError, format_error_msg(errors)\n\n if auto_downcast:\n variable_specs = downcast(variable_specs)\n return variable_specs\n\ndef downcast(var_specs):\n \"\"\" Cast python scalars down to most common type of\n arrays used.\n\n Right now, focus on complex and float types. Ignore int types.\n Require all arrays to have same type before forcing downcasts.\n\n Note: var_specs are currently altered in place (horrors...!)\n \"\"\"\n numeric_types = []\n\n #grab all the numeric types associated with a variables.\n for var in var_specs:\n if hasattr(var,'numeric_type'):\n numeric_types.append(var.numeric_type)\n\n # if arrays are present, but none of them are double precision,\n # make all numeric types float or complex(float)\n if ( ('f' in numeric_types or 'F' in numeric_types) and\n not ('d' in numeric_types or 'D' in numeric_types) ):\n for var in var_specs:\n if hasattr(var,'numeric_type'):\n # really should do this some other way...\n if var.numeric_type == type(1+1j):\n var.numeric_type = 'F'\n elif var.numeric_type == type(1.):\n var.numeric_type = 'f'\n return var_specs\n\ndef indent(st,spaces):\n indention = ' '*spaces\n indented = indention + string.replace(st,'\\n','\\n'+indention)\n # trim off any trailing spaces\n indented = re.sub(r' +$',r'',indented)\n return indented\n\ndef format_error_msg(errors):\n #minimum effort right now...\n import pprint,cStringIO\n msg = cStringIO.StringIO()\n pprint.pprint(errors,msg)\n return msg.getvalue()\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "methods": [ { "name": "__init__", "long_name": "__init__( self , name , code_block , arg_specs )", "filename": "ext_tools.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "self", "name", "code_block", "arg_specs" ], "start_line": 10, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "header_code", "long_name": "header_code( self )", "filename": "ext_tools.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [ "self" ], "start_line": 17, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "function_declaration_code", "long_name": "function_declaration_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 20, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "template_declaration_code", "long_name": "template_declaration_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 25, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "parse_tuple_code", "long_name": "parse_tuple_code( self )", "filename": "ext_tools.py", "nloc": 32, "complexity": 4, "token_count": 209, "parameters": [ "self" ], "start_line": 36, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "arg_declaration_code", "long_name": "arg_declaration_code( self )", "filename": "ext_tools.py", "nloc": 7, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 83, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "arg_cleanup_code", "long_name": "arg_cleanup_code( self )", "filename": "ext_tools.py", "nloc": 11, "complexity": 2, "token_count": 76, "parameters": [ "self" ], "start_line": 91, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "arg_local_dict_code", "long_name": "arg_local_dict_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 103, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 37, "complexity": 1, "token_count": 162, "parameters": [ "self" ], "start_line": 110, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 153, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "ext_tools.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [ "self", "compiler" ], "start_line": 159, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , code_block , args , local_dict = None , global_dict = None , auto_downcast = 1 , type_converters = None )", "filename": "ext_tools.py", "nloc": 12, "complexity": 4, "token_count": 92, "parameters": [ "self", "name", "code_block", "args", "local_dict", "global_dict", "auto_downcast", "type_converters" ], "start_line": 166, "end_line": 178, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , compiler = '' )", "filename": "ext_tools.py", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "self", "name", "compiler" ], "start_line": 184, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "add_function", "long_name": "add_function( self , func )", "filename": "ext_tools.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "func" ], "start_line": 192, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "module_code", "long_name": "module_code( self )", "filename": "ext_tools.py", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "self" ], "start_line": 194, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "arg_specs", "long_name": "arg_specs( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 203, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "build_information", "long_name": "build_information( self )", "filename": "ext_tools.py", "nloc": 8, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 209, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "get_headers", "long_name": "get_headers( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "self" ], "start_line": 219, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "warning_code", "long_name": "warning_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 228, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "header_code", "long_name": "header_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 233, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "support_code", "long_name": "support_code( self )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 238, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 2, "token_count": 29, "parameters": [ "self" ], "start_line": 242, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "ext_tools.py", "nloc": 11, "complexity": 2, "token_count": 52, "parameters": [ "self" ], "start_line": 248, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "module_init_code", "long_name": "module_init_code( self )", "filename": "ext_tools.py", "nloc": 9, "complexity": 1, "token_count": 54, "parameters": [ "self" ], "start_line": 260, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "generate_file", "long_name": "generate_file( self , file_name = \"\" , location = '.' )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 46, "parameters": [ "self", "file_name", "location" ], "start_line": 270, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "ext_tools.py", "nloc": 6, "complexity": 3, "token_count": 40, "parameters": [ "self", "compiler" ], "start_line": 278, "end_line": 286, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "compile", "long_name": "compile( self , location = '.' , compiler = None , verbose = 0 , ** kw )", "filename": "ext_tools.py", "nloc": 22, "complexity": 4, "token_count": 206, "parameters": [ "self", "location", "compiler", "verbose", "kw" ], "start_line": 288, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 1 }, { "name": "generate_file_name", "long_name": "generate_file_name( module_name , module_location )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 28, "parameters": [ "module_name", "module_location" ], "start_line": 332, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "generate_module", "long_name": "generate_module( module_string , module_file )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "module_string", "module_file" ], "start_line": 336, "end_line": 340, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "assign_variable_types", "long_name": "assign_variable_types( variables , local_dict = { } , global_dict = { } , auto_downcast = 1 , type_converters = converters . default )", "filename": "ext_tools.py", "nloc": 31, "complexity": 9, "token_count": 156, "parameters": [ "variables", "local_dict", "global_dict", "auto_downcast", "type_converters" ], "start_line": 342, "end_line": 377, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "downcast", "long_name": "downcast( var_specs )", "filename": "ext_tools.py", "nloc": 14, "complexity": 11, "token_count": 103, "parameters": [ "var_specs" ], "start_line": 379, "end_line": 406, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "indent", "long_name": "indent( st , spaces )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 44, "parameters": [ "st", "spaces" ], "start_line": 408, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "format_error_msg", "long_name": "format_error_msg( errors )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "errors" ], "start_line": 415, "end_line": 420, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 422, "end_line": 424, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 426, "end_line": 428, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self , name , code_block , arg_specs )", "filename": "ext_tools.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "self", "name", "code_block", "arg_specs" ], "start_line": 10, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "header_code", "long_name": "header_code( self )", "filename": "ext_tools.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [ "self" ], "start_line": 17, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "function_declaration_code", "long_name": "function_declaration_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 20, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "template_declaration_code", "long_name": "template_declaration_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 25, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "parse_tuple_code", "long_name": "parse_tuple_code( self )", "filename": "ext_tools.py", "nloc": 32, "complexity": 4, "token_count": 209, "parameters": [ "self" ], "start_line": 36, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 1 }, { "name": "arg_declaration_code", "long_name": "arg_declaration_code( self )", "filename": "ext_tools.py", "nloc": 7, "complexity": 2, "token_count": 50, "parameters": [ "self" ], "start_line": 83, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "arg_cleanup_code", "long_name": "arg_cleanup_code( self )", "filename": "ext_tools.py", "nloc": 11, "complexity": 2, "token_count": 76, "parameters": [ "self" ], "start_line": 91, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "arg_local_dict_code", "long_name": "arg_local_dict_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 103, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 37, "complexity": 1, "token_count": 162, "parameters": [ "self" ], "start_line": 110, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 153, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "ext_tools.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [ "self", "compiler" ], "start_line": 159, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , code_block , args , local_dict = None , global_dict = None , auto_downcast = 1 , type_converters = None )", "filename": "ext_tools.py", "nloc": 12, "complexity": 4, "token_count": 92, "parameters": [ "self", "name", "code_block", "args", "local_dict", "global_dict", "auto_downcast", "type_converters" ], "start_line": 166, "end_line": 178, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , name , compiler = '' )", "filename": "ext_tools.py", "nloc": 7, "complexity": 1, "token_count": 51, "parameters": [ "self", "name", "compiler" ], "start_line": 184, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "add_function", "long_name": "add_function( self , func )", "filename": "ext_tools.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "func" ], "start_line": 192, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "module_code", "long_name": "module_code( self )", "filename": "ext_tools.py", "nloc": 8, "complexity": 1, "token_count": 49, "parameters": [ "self" ], "start_line": 194, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "arg_specs", "long_name": "arg_specs( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 203, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "build_information", "long_name": "build_information( self )", "filename": "ext_tools.py", "nloc": 8, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 209, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "get_headers", "long_name": "get_headers( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "self" ], "start_line": 219, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "warning_code", "long_name": "warning_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 36, "parameters": [ "self" ], "start_line": 228, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "header_code", "long_name": "header_code( self )", "filename": "ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 233, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "support_code", "long_name": "support_code( self )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 238, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 5, "complexity": 2, "token_count": 29, "parameters": [ "self" ], "start_line": 242, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "ext_tools.py", "nloc": 11, "complexity": 2, "token_count": 52, "parameters": [ "self" ], "start_line": 248, "end_line": 258, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "module_init_code", "long_name": "module_init_code( self )", "filename": "ext_tools.py", "nloc": 9, "complexity": 1, "token_count": 54, "parameters": [ "self" ], "start_line": 260, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "generate_file", "long_name": "generate_file( self , file_name = \"\" , location = '.' )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 46, "parameters": [ "self", "file_name", "location" ], "start_line": 270, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "ext_tools.py", "nloc": 6, "complexity": 3, "token_count": 40, "parameters": [ "self", "compiler" ], "start_line": 278, "end_line": 285, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "compile", "long_name": "compile( self , location = '.' , compiler = None , verbose = 0 , ** kw )", "filename": "ext_tools.py", "nloc": 24, "complexity": 4, "token_count": 222, "parameters": [ "self", "location", "compiler", "verbose", "kw" ], "start_line": 287, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 1 }, { "name": "generate_file_name", "long_name": "generate_file_name( module_name , module_location )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 28, "parameters": [ "module_name", "module_location" ], "start_line": 326, "end_line": 328, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "generate_module", "long_name": "generate_module( module_string , module_file )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "module_string", "module_file" ], "start_line": 330, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "assign_variable_types", "long_name": "assign_variable_types( variables , local_dict = { } , global_dict = { } , auto_downcast = 1 , type_converters = converters . default )", "filename": "ext_tools.py", "nloc": 31, "complexity": 9, "token_count": 156, "parameters": [ "variables", "local_dict", "global_dict", "auto_downcast", "type_converters" ], "start_line": 336, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "downcast", "long_name": "downcast( var_specs )", "filename": "ext_tools.py", "nloc": 14, "complexity": 11, "token_count": 103, "parameters": [ "var_specs" ], "start_line": 373, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "indent", "long_name": "indent( st , spaces )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 44, "parameters": [ "st", "spaces" ], "start_line": 402, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "format_error_msg", "long_name": "format_error_msg( errors )", "filename": "ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "errors" ], "start_line": 409, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 416, "end_line": 418, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 420, "end_line": 422, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "ext_tools.py", "nloc": 6, "complexity": 3, "token_count": 40, "parameters": [ "self", "compiler" ], "start_line": 278, "end_line": 286, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "compile", "long_name": "compile( self , location = '.' , compiler = None , verbose = 0 , ** kw )", "filename": "ext_tools.py", "nloc": 22, "complexity": 4, "token_count": 206, "parameters": [ "self", "location", "compiler", "verbose", "kw" ], "start_line": 288, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 37, "complexity": 1, "token_count": 162, "parameters": [ "self" ], "start_line": 110, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 1 } ], "nloc": 316, "complexity": 75, "token_count": 2018, "diff_parsed": { "added": [ " ' if(!return_val && !exception_occured)\\n' \\", " ' {\\n \\n' \\", " ' Py_INCREF(Py_None); \\n' \\", " ' return_val = Py_None; \\n' \\", " ' }\\n \\n' \\", " ' return return_val; \\n' \\", " '} \\n'", " # This is not used anymore -- I think we should ditch it.", "", " # !! removed -- we don't have any compiler dependent code", " # currently in spec or info classes", " # choosing the compiler spagettis around a little.", " #compiler = build_tools.choose_compiler(self.compiler)", " #self.set_compiler(compiler)", "", "" ], "deleted": [ " \" if(!return_val && !exception_occured)\\n\" \\", " \" {\\n \\n\" \\", " \" Py_INCREF(Py_None); \\n\" \\", " \" return_val = Py_None; \\n\" \\", " \" }\\n \\n\" \\", " \" return return_val; \\n\" \\", " \"} \\n\"", " # choosing the compiler spagettis around a little.", " compiler = build_tools.choose_compiler(self.compiler)", " self.set_compiler(compiler)" ] } }, { "old_path": "weave/standard_array_spec.py", "new_path": "weave/standard_array_spec.py", "filename": "standard_array_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -34,7 +34,7 @@ class numpy_type_handler\n !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&\n !(numeric_type == PyArray_LONG && arr_type == PyArray_INT)) \n {\n- char* type_names[13] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"int\", \n+ char* type_names[20] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"int\", \n \"long\", \"float\", \"double\", \"complex float\",\n \"complex double\", \"object\",\"ntype\",\"unkown\"};\n char msg[500];\n", "added_lines": 1, "deleted_lines": 1, "source_code": "from c_spec import common_base_converter\nfrom c_spec import num_to_c_types\nfrom Numeric import *\nfrom types import *\nimport os\n\nnum_typecode = {}\nnum_typecode['c'] = 'PyArray_CHAR'\nnum_typecode['1'] = 'PyArray_SBYTE'\nnum_typecode['b'] = 'PyArray_UBYTE'\nnum_typecode['s'] = 'PyArray_SHORT'\nnum_typecode['i'] = 'PyArray_INT' # PyArray_INT has troubles ?? What does this note mean ??\nnum_typecode['l'] = 'PyArray_LONG'\nnum_typecode['f'] = 'PyArray_FLOAT'\nnum_typecode['d'] = 'PyArray_DOUBLE'\nnum_typecode['F'] = 'PyArray_CFLOAT'\nnum_typecode['D'] = 'PyArray_CDOUBLE'\n\ntype_check_code = \\\n\"\"\"\nclass numpy_type_handler\n{\npublic:\n void conversion_numpy_check_type(PyArrayObject* arr_obj, int numeric_type,\n const char* name)\n {\n // Make sure input has correct numeric type.\n // allow character and byte to match\n // also allow int and long to match\n int arr_type = arr_obj->descr->type_num;\n if ( arr_type != numeric_type &&\n !(numeric_type == PyArray_CHAR && arr_type == PyArray_SBYTE) &&\n !(numeric_type == PyArray_SBYTE && arr_type == PyArray_CHAR) &&\n !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&\n !(numeric_type == PyArray_LONG && arr_type == PyArray_INT)) \n {\n char* type_names[20] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"int\", \n \"long\", \"float\", \"double\", \"complex float\",\n \"complex double\", \"object\",\"ntype\",\"unkown\"};\n char msg[500];\n sprintf(msg,\"Conversion Error: received '%s' typed array instead of '%s' typed array for variable '%s'\",\n type_names[arr_type],type_names[numeric_type],name);\n throw_error(PyExc_TypeError,msg); \n }\n }\n \n void numpy_check_type(PyArrayObject* arr_obj, int numeric_type, const char* name)\n {\n // Make sure input has correct numeric type.\n int arr_type = arr_obj->descr->type_num;\n if ( arr_type != numeric_type &&\n !(numeric_type == PyArray_CHAR && arr_type == PyArray_SBYTE) &&\n !(numeric_type == PyArray_SBYTE && arr_type == PyArray_CHAR) &&\n !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&\n !(numeric_type == PyArray_LONG && arr_type == PyArray_INT)) \n {\n char* type_names[13] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"int\", \n \"long\", \"float\", \"double\", \"complex float\",\n \"complex double\", \"object\",\"ntype\",\"unkown\"};\n char msg[500];\n sprintf(msg,\"received '%s' typed array instead of '%s' typed array for variable '%s'\",\n type_names[arr_type],type_names[numeric_type],name);\n throw_error(PyExc_TypeError,msg); \n }\n }\n};\n\nnumpy_type_handler x__numpy_type_handler = numpy_type_handler();\n#define conversion_numpy_check_type x__numpy_type_handler.conversion_numpy_check_type\n#define numpy_check_type x__numpy_type_handler.numpy_check_type\n\n\"\"\"\n\nsize_check_code = \\\n\"\"\"\nclass numpy_size_handler\n{\npublic:\n void conversion_numpy_check_size(PyArrayObject* arr_obj, int Ndims, \n const char* name)\n {\n if (arr_obj->nd != Ndims)\n {\n char msg[500];\n sprintf(msg,\"Conversion Error: received '%d' dimensional array instead of '%d' dimensional array for variable '%s'\",\n arr_obj->nd,Ndims,name);\n throw_error(PyExc_TypeError,msg);\n } \n }\n \n void numpy_check_size(PyArrayObject* arr_obj, int Ndims, const char* name)\n {\n if (arr_obj->nd != Ndims)\n {\n char msg[500];\n sprintf(msg,\"received '%d' dimensional array instead of '%d' dimensional array for variable '%s'\",\n arr_obj->nd,Ndims,name);\n throw_error(PyExc_TypeError,msg);\n } \n }\n};\n\nnumpy_size_handler x__numpy_size_handler = numpy_size_handler();\n#define conversion_numpy_check_size x__numpy_size_handler.conversion_numpy_check_size\n#define numpy_check_size x__numpy_size_handler.numpy_check_size\n\n\"\"\"\n\nnumeric_init_code = \\\n\"\"\"\nPy_Initialize();\nimport_array();\nPyImport_ImportModule(\"Numeric\");\n\"\"\"\n \nclass array_converter(common_base_converter):\n\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'numpy'\n self.check_func = 'PyArray_Check' \n self.c_type = 'PyArrayObject*'\n self.to_c_return = '(PyArrayObject*) py_obj'\n self.matching_types = [ArrayType]\n self.headers = ['\"Numeric/arrayobject.h\"','','']\n self.support_code = [size_check_code, type_check_code]\n self.module_init_code = [numeric_init_code] \n \n def get_var_type(self,value):\n return value.typecode()\n \n def template_vars(self,inline=0):\n res = common_base_converter.template_vars(self,inline) \n if hasattr(self,'var_type'):\n res['num_type'] = num_to_c_types[self.var_type]\n res['num_typecode'] = num_typecode[self.var_type]\n res['array_name'] = self.name + \"_array\"\n return res\n \n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(array_name)s = %(var_convert)s;\\n' \\\n 'conversion_numpy_check_type(%(array_name)s,%(num_typecode)s,\"%(name)s\");\\n' \\\n 'int* N%(name)s = %(array_name)s->dimensions;\\n' \\\n 'int* S%(name)s = %(array_name)s->strides;\\n' \\\n 'int D%(name)s = %(array_name)s->nd;\\n' \\\n '%(num_type)s* %(name)s = (%(num_type)s*) %(array_name)s->data;\\n' \n code = code % self.template_vars(inline=inline)\n return code\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "source_code_before": "from c_spec import common_base_converter\nfrom c_spec import num_to_c_types\nfrom Numeric import *\nfrom types import *\nimport os\n\nnum_typecode = {}\nnum_typecode['c'] = 'PyArray_CHAR'\nnum_typecode['1'] = 'PyArray_SBYTE'\nnum_typecode['b'] = 'PyArray_UBYTE'\nnum_typecode['s'] = 'PyArray_SHORT'\nnum_typecode['i'] = 'PyArray_INT' # PyArray_INT has troubles ?? What does this note mean ??\nnum_typecode['l'] = 'PyArray_LONG'\nnum_typecode['f'] = 'PyArray_FLOAT'\nnum_typecode['d'] = 'PyArray_DOUBLE'\nnum_typecode['F'] = 'PyArray_CFLOAT'\nnum_typecode['D'] = 'PyArray_CDOUBLE'\n\ntype_check_code = \\\n\"\"\"\nclass numpy_type_handler\n{\npublic:\n void conversion_numpy_check_type(PyArrayObject* arr_obj, int numeric_type,\n const char* name)\n {\n // Make sure input has correct numeric type.\n // allow character and byte to match\n // also allow int and long to match\n int arr_type = arr_obj->descr->type_num;\n if ( arr_type != numeric_type &&\n !(numeric_type == PyArray_CHAR && arr_type == PyArray_SBYTE) &&\n !(numeric_type == PyArray_SBYTE && arr_type == PyArray_CHAR) &&\n !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&\n !(numeric_type == PyArray_LONG && arr_type == PyArray_INT)) \n {\n char* type_names[13] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"int\", \n \"long\", \"float\", \"double\", \"complex float\",\n \"complex double\", \"object\",\"ntype\",\"unkown\"};\n char msg[500];\n sprintf(msg,\"Conversion Error: received '%s' typed array instead of '%s' typed array for variable '%s'\",\n type_names[arr_type],type_names[numeric_type],name);\n throw_error(PyExc_TypeError,msg); \n }\n }\n \n void numpy_check_type(PyArrayObject* arr_obj, int numeric_type, const char* name)\n {\n // Make sure input has correct numeric type.\n int arr_type = arr_obj->descr->type_num;\n if ( arr_type != numeric_type &&\n !(numeric_type == PyArray_CHAR && arr_type == PyArray_SBYTE) &&\n !(numeric_type == PyArray_SBYTE && arr_type == PyArray_CHAR) &&\n !(numeric_type == PyArray_INT && arr_type == PyArray_LONG) &&\n !(numeric_type == PyArray_LONG && arr_type == PyArray_INT)) \n {\n char* type_names[13] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"int\", \n \"long\", \"float\", \"double\", \"complex float\",\n \"complex double\", \"object\",\"ntype\",\"unkown\"};\n char msg[500];\n sprintf(msg,\"received '%s' typed array instead of '%s' typed array for variable '%s'\",\n type_names[arr_type],type_names[numeric_type],name);\n throw_error(PyExc_TypeError,msg); \n }\n }\n};\n\nnumpy_type_handler x__numpy_type_handler = numpy_type_handler();\n#define conversion_numpy_check_type x__numpy_type_handler.conversion_numpy_check_type\n#define numpy_check_type x__numpy_type_handler.numpy_check_type\n\n\"\"\"\n\nsize_check_code = \\\n\"\"\"\nclass numpy_size_handler\n{\npublic:\n void conversion_numpy_check_size(PyArrayObject* arr_obj, int Ndims, \n const char* name)\n {\n if (arr_obj->nd != Ndims)\n {\n char msg[500];\n sprintf(msg,\"Conversion Error: received '%d' dimensional array instead of '%d' dimensional array for variable '%s'\",\n arr_obj->nd,Ndims,name);\n throw_error(PyExc_TypeError,msg);\n } \n }\n \n void numpy_check_size(PyArrayObject* arr_obj, int Ndims, const char* name)\n {\n if (arr_obj->nd != Ndims)\n {\n char msg[500];\n sprintf(msg,\"received '%d' dimensional array instead of '%d' dimensional array for variable '%s'\",\n arr_obj->nd,Ndims,name);\n throw_error(PyExc_TypeError,msg);\n } \n }\n};\n\nnumpy_size_handler x__numpy_size_handler = numpy_size_handler();\n#define conversion_numpy_check_size x__numpy_size_handler.conversion_numpy_check_size\n#define numpy_check_size x__numpy_size_handler.numpy_check_size\n\n\"\"\"\n\nnumeric_init_code = \\\n\"\"\"\nPy_Initialize();\nimport_array();\nPyImport_ImportModule(\"Numeric\");\n\"\"\"\n \nclass array_converter(common_base_converter):\n\n def init_info(self):\n common_base_converter.init_info(self)\n self.type_name = 'numpy'\n self.check_func = 'PyArray_Check' \n self.c_type = 'PyArrayObject*'\n self.to_c_return = '(PyArrayObject*) py_obj'\n self.matching_types = [ArrayType]\n self.headers = ['\"Numeric/arrayobject.h\"','','']\n self.support_code = [size_check_code, type_check_code]\n self.module_init_code = [numeric_init_code] \n \n def get_var_type(self,value):\n return value.typecode()\n \n def template_vars(self,inline=0):\n res = common_base_converter.template_vars(self,inline) \n if hasattr(self,'var_type'):\n res['num_type'] = num_to_c_types[self.var_type]\n res['num_typecode'] = num_typecode[self.var_type]\n res['array_name'] = self.name + \"_array\"\n return res\n \n def declaration_code(self,templatize = 0,inline=0):\n code = '%(py_var)s = %(var_lookup)s;\\n' \\\n '%(c_type)s %(array_name)s = %(var_convert)s;\\n' \\\n 'conversion_numpy_check_type(%(array_name)s,%(num_typecode)s,\"%(name)s\");\\n' \\\n 'int* N%(name)s = %(array_name)s->dimensions;\\n' \\\n 'int* S%(name)s = %(array_name)s->strides;\\n' \\\n 'int D%(name)s = %(array_name)s->nd;\\n' \\\n '%(num_type)s* %(name)s = (%(num_type)s*) %(array_name)s->data;\\n' \n code = code % self.template_vars(inline=inline)\n return code\n\ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "methods": [ { "name": "init_info", "long_name": "init_info( self )", "filename": "standard_array_spec.py", "nloc": 10, "complexity": 1, "token_count": 65, "parameters": [ "self" ], "start_line": 118, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_var_type", "long_name": "get_var_type( self , value )", "filename": "standard_array_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "value" ], "start_line": 129, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 7, "complexity": 2, "token_count": 61, "parameters": [ "self", "inline" ], "start_line": 132, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 10, "complexity": 1, "token_count": 42, "parameters": [ "self", "templatize", "inline" ], "start_line": 140, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 151, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 155, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "init_info", "long_name": "init_info( self )", "filename": "standard_array_spec.py", "nloc": 10, "complexity": 1, "token_count": 65, "parameters": [ "self" ], "start_line": 118, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_var_type", "long_name": "get_var_type( self , value )", "filename": "standard_array_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self", "value" ], "start_line": 129, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "template_vars", "long_name": "template_vars( self , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 7, "complexity": 2, "token_count": 61, "parameters": [ "self", "inline" ], "start_line": 132, "end_line": 138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 10, "complexity": 1, "token_count": 42, "parameters": [ "self", "templatize", "inline" ], "start_line": 140, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 151, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 155, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 146, "complexity": 7, "token_count": 334, "diff_parsed": { "added": [ " char* type_names[20] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"int\"," ], "deleted": [ " char* type_names[13] = {\"char\",\"unsigned byte\",\"byte\", \"short\", \"int\"," ] } } ] }, { "hash": "f55fb2ec42b239d62f7fc25131045795f7aa35bf", "msg": "missing import", "author": { "name": "skip", "email": "skip@localhost" }, "committer": { "name": "skip", "email": "skip@localhost" }, "author_date": "2002-09-19T12:20:51+00:00", "author_timezone": 0, "committer_date": "2002-09-19T12:20:51+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "200bff5384ca06d4d61570a576f94ff63b6c335d" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 0, "insertions": 1, "lines": 1, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "weave/build_tools.py", "new_path": "weave/build_tools.py", "filename": "build_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -20,6 +20,7 @@\n import sys,os,string,time\n import tempfile\n import exceptions\n+import commands\n \n # If linker is 'gcc', this will convert it to 'g++'\n # necessary to make sure stdc++ is linked in cross-platform way.\n", "added_lines": 1, "deleted_lines": 0, "source_code": "\"\"\" Tools for compiling C/C++ code to extension modules\n\n The main function, build_extension(), takes the C/C++ file\n along with some other options and builds a Python extension.\n It uses distutils for most of the heavy lifting.\n \n choose_compiler() is also useful (mainly on windows anyway)\n for trying to determine whether MSVC++ or gcc is available.\n MSVC doesn't handle templates as well, so some of the code emitted\n by the python->C conversions need this info to choose what kind\n of code to create.\n \n The other main thing here is an alternative version of the MingW32\n compiler class. The class makes it possible to build libraries with\n gcc even if the original version of python was built using MSVC. It\n does this by converting a pythonxx.lib file to a libpythonxx.a file.\n Note that you need write access to the pythonxx/lib directory to do this.\n\"\"\"\n\nimport sys,os,string,time\nimport tempfile\nimport exceptions\nimport commands\n\n# If linker is 'gcc', this will convert it to 'g++'\n# necessary to make sure stdc++ is linked in cross-platform way.\nimport distutils.sysconfig\nimport distutils.dir_util\n\nold_init_posix = distutils.sysconfig._init_posix\n\ndef _init_posix():\n old_init_posix()\n ld = distutils.sysconfig._config_vars['LDSHARED']\n #distutils.sysconfig._config_vars['LDSHARED'] = ld.replace('gcc','g++')\n # FreeBSD names gcc as cc, so the above find and replace doesn't work. \n # So, assume first entry in ld is the name of the linker -- gcc or cc or \n # whatever. This is a sane assumption, correct?\n # If the linker is gcc, set it to g++\n link_cmds = ld.split() \n if gcc_exists(link_cmds[0]):\n link_cmds[0] = 'g++'\n ld = ' '.join(link_cmds)\n distutils.sysconfig._config_vars['LDSHARED'] = ld \n\ndistutils.sysconfig._init_posix = _init_posix \n# end force g++\n\n\nclass CompileError(exceptions.Exception):\n pass\n \ndef build_extension(module_path,compiler_name = '',build_dir = None,\n temp_dir = None, verbose = 0, **kw):\n \"\"\" Build the file given by module_path into a Python extension module.\n \n build_extensions uses distutils to build Python extension modules.\n kw arguments not used are passed on to the distutils extension\n module. Directory settings can handle absoulte settings, but don't\n currently expand '~' or environment variables.\n \n module_path -- the full path name to the c file to compile. \n Something like: /full/path/name/module_name.c \n The name of the c/c++ file should be the same as the\n name of the module (i.e. the initmodule() routine)\n compiler_name -- The name of the compiler to use. On Windows if it \n isn't given, MSVC is used if it exists (is found).\n gcc is used as a second choice. If neither are found, \n the default distutils compiler is used. Acceptable \n names are 'gcc', 'msvc' or any of the compiler names \n shown by distutils.ccompiler.show_compilers()\n build_dir -- The location where the resulting extension module \n should be placed. This location must be writable. If\n it isn't, several default locations are tried. If the \n build_dir is not in the current python path, a warning\n is emitted, and it is added to the end of the path.\n build_dir defaults to the current directory.\n temp_dir -- The location where temporary files (*.o or *.obj)\n from the build are placed. This location must be \n writable. If it isn't, several default locations are \n tried. It defaults to tempfile.gettempdir()\n verbose -- 0, 1, or 2. 0 is as quiet as possible. 1 prints\n minimal information. 2 is noisy. \n **kw -- keyword arguments. These are passed on to the \n distutils extension module. Most of the keywords\n are listed below.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n \n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list \n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability) \n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line) \n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n success = 0\n from distutils.core import setup, Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n # dag. We keep having to add directories to the path to keep \n # object files separated from each other. gcc2.x and gcc3.x C++ \n # object files are not compatible, so we'll stick them in a sub\n # dir based on their version. This will add gccX.X to the \n # path.\n compiler_dir = get_compiler_dir(compiler_name)\n temp_dir = os.path.join(temp_dir,compiler_dir)\n distutils.dir_util.mkpath(temp_dir)\n \n compiler_name = choose_compiler(compiler_name)\n \n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n try:\n if verbose == 1:\n print 'Compiling code...'\n \n # set compiler verboseness 2 or more makes it output results\n if verbose > 1: verb = 1 \n else: verb = 0\n \n t1 = time.time() \n # add module to the needed source code files and build extension\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n \n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n platform = sys.platform\n version = sys.version.lower()\n if platform[:5] == 'sunos' and version.find('gcc') != -1:\n extra_link_args = kw.get('extra_link_args',[])\n kw['extra_link_args'] = ['-mimpure-text'] + extra_link_args\n \n ext = Extension(module_name, **kw)\n \n # the switcheroo on SystemExit here is meant to keep command line\n # sessions from exiting when compiles fail.\n builtin = sys.modules['__builtin__']\n old_SysExit = builtin.__dict__['SystemExit']\n builtin.__dict__['SystemExit'] = CompileError\n \n # distutils for MSVC messes with the environment, so we save the\n # current state and restore them afterward.\n import copy\n environ = copy.deepcopy(os.environ)\n try:\n setup(name = module_name, ext_modules = [ext],verbose=verb)\n finally:\n # restore state\n os.environ = environ \n # restore SystemExit\n builtin.__dict__['SystemExit'] = old_SysExit\n t2 = time.time()\n \n if verbose == 1:\n print 'finished compiling (sec): ', t2 - t1 \n success = 1\n configure_python_path(build_dir)\n except SyntaxError: #TypeError:\n success = 0 \n \n # restore argv after our trick... \n restore_sys_argv()\n \n return success\n\nold_argv = []\ndef configure_sys_argv(compiler_name,temp_dir,build_dir):\n # We're gonna play some tricks with argv here to pass info to distutils \n # which is really built for command line use. better way??\n global old_argv\n old_argv = sys.argv[:] \n sys.argv = ['','build_ext','--build-lib', build_dir,\n '--build-temp',temp_dir] \n if compiler_name == 'gcc':\n sys.argv.insert(2,'--compiler='+compiler_name)\n elif compiler_name:\n sys.argv.insert(2,'--compiler='+compiler_name)\n\ndef restore_sys_argv():\n sys.argv = old_argv\n \ndef configure_python_path(build_dir): \n #make sure the module lives in a directory on the python path.\n python_paths = [os.path.abspath(x) for x in sys.path]\n if os.path.abspath(build_dir) not in python_paths:\n #print \"warning: build directory was not part of python path.\"\\\n # \" It has been appended to the path.\"\n sys.path.append(os.path.abspath(build_dir))\n\ndef choose_compiler(compiler_name=''):\n \"\"\" Try and figure out which compiler is gonna be used on windows.\n On other platforms, it just returns whatever value it is given.\n \n converts 'gcc' to 'mingw32' on win32\n \"\"\"\n if sys.platform == 'win32': \n if not compiler_name:\n # On Windows, default to MSVC and use gcc if it wasn't found\n # wasn't found. If neither are found, go with whatever\n # the default is for distutils -- and probably fail...\n if msvc_exists():\n compiler_name = 'msvc'\n elif gcc_exists():\n compiler_name = 'mingw32'\n elif compiler_name == 'gcc':\n compiler_name = 'mingw32'\n else:\n # don't know how to force gcc -- look into this.\n if compiler_name == 'gcc':\n compiler_name = 'unix' \n return compiler_name\n \ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n version = distutils.msvccompiler.get_devstudio_version()\n if version:\n result = 1\n return result\n\nif os.name == 'nt':\n def run_command(command):\n \"\"\" not sure how to get exit status on nt. \"\"\"\n in_pipe,out_pipe = os.popen4(command)\n in_pipe.close()\n text = out_pipe.read()\n return 0, text\nelse:\n run_command = commands.getstatusoutput\n\ndef get_compiler_dir(compiler_name):\n if compiler_name == 'gcc': \n status, text = run_command(compiler_name + ' --version')\n try:\n import re\n version = re.findall('\\d\\.\\d',text)[0]\n except IndexError:\n version = ''\n compiler_dir = compiler_name + version\n else: \n compiler_dir = compiler_name\n return compiler_dir\n \ndef configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n print \"warning: specified temp_dir '%s' does not exist \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n\n # final check that that directories are writable. \n if not os.access(temp_dir,os.W_OK):\n msg = \"Either the temp or build directory wasn't writable. Check\" \\\n \" these locations: '%s'\" % temp_dir \n raise ValueError, msg\n return temp_dir\n\ndef configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n print \"warning: specified build_dir '%s' does not exist \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n if build_dir is None:\n #default to building in the home directory of the given module. \n build_dir = os.curdir\n # if it doesn't work use the current directory. This should always\n # be writable. \n if not os.access(build_dir,os.W_OK):\n print \"warning:, neither the module's directory nor the \"\\\n \"current directory are writable. Using the temporary\"\\\n \"directory.\"\n build_dir = tempfile.gettempdir()\n\n # final check that that directories are writable.\n if not os.access(build_dir,os.W_OK):\n msg = \"The build directory wasn't writable. Check\" \\\n \" this location: '%s'\" % build_dir\n raise ValueError, msg\n \n return os.path.abspath(build_dir) \n \nif sys.platform == 'win32':\n import distutils.cygwinccompiler\n # the same as cygwin plus some additional parameters\n class Mingw32CCompiler (distutils.cygwinccompiler.CygwinCCompiler):\n \"\"\" A modified MingW32 compiler compatible with an MSVC built Python.\n \n \"\"\"\n \n compiler_type = 'mingw32'\n \n def __init__ (self,\n verbose=0,\n dry_run=0,\n force=0):\n \n distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose, \n dry_run, force)\n \n # A real mingw32 doesn't need to specify a different entry point,\n # but cygwin 2.91.57 in no-cygwin-mode needs it.\n if self.gcc_version <= \"2.91.57\":\n entry_point = '--entry _DllMain@12'\n else:\n entry_point = ''\n if self.linker_dll == 'dllwrap':\n self.linker = 'dllwrap' + ' --driver-name g++'\n elif self.linker_dll == 'gcc':\n self.linker = 'g++' \n # **changes: eric jones 4/11/01\n # 1. Check for import library on Windows. Build if it doesn't exist.\n if not import_library_exists():\n build_import_library()\n \n # **changes: eric jones 4/11/01\n # 2. increased optimization and turned off all warnings\n # 3. also added --driver-name g++\n #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n # compiler_so='gcc -mno-cygwin -mdll -O2 -w',\n # linker_exe='gcc -mno-cygwin',\n # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' \n # % (self.linker, entry_point))\n self.set_executables(compiler='g++ -mno-cygwin -O2 -w',\n compiler_so='g++ -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',\n linker_exe='g++ -mno-cygwin',\n linker_so='%s -mno-cygwin -mdll -static %s' \n % (self.linker, entry_point))\n \n # Maybe we should also append -mthreads, but then the finished\n # dlls need another dll (mingwm10.dll see Mingw32 docs)\n # (-mthreads: Support thread-safe exception handling on `Mingw32') \n \n # no additional libraries needed \n self.dll_libraries=[]\n \n # __init__ ()\n \n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n # We should also check the version of gcc available...\n #distutils.ccompiler._default_compilers['nt'] = 'mingw32'\n #distutils.ccompiler._default_compilers = (('nt', 'mingw32'))\n # reset the Mingw32 compiler in distutils to the one defined above\n distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler\n \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if os.name == 'nt':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n from scipy_distutils import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print 'WARNING: failed to build import library for gcc. Linking will fail.'\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\n\n\n", "source_code_before": "\"\"\" Tools for compiling C/C++ code to extension modules\n\n The main function, build_extension(), takes the C/C++ file\n along with some other options and builds a Python extension.\n It uses distutils for most of the heavy lifting.\n \n choose_compiler() is also useful (mainly on windows anyway)\n for trying to determine whether MSVC++ or gcc is available.\n MSVC doesn't handle templates as well, so some of the code emitted\n by the python->C conversions need this info to choose what kind\n of code to create.\n \n The other main thing here is an alternative version of the MingW32\n compiler class. The class makes it possible to build libraries with\n gcc even if the original version of python was built using MSVC. It\n does this by converting a pythonxx.lib file to a libpythonxx.a file.\n Note that you need write access to the pythonxx/lib directory to do this.\n\"\"\"\n\nimport sys,os,string,time\nimport tempfile\nimport exceptions\n\n# If linker is 'gcc', this will convert it to 'g++'\n# necessary to make sure stdc++ is linked in cross-platform way.\nimport distutils.sysconfig\nimport distutils.dir_util\n\nold_init_posix = distutils.sysconfig._init_posix\n\ndef _init_posix():\n old_init_posix()\n ld = distutils.sysconfig._config_vars['LDSHARED']\n #distutils.sysconfig._config_vars['LDSHARED'] = ld.replace('gcc','g++')\n # FreeBSD names gcc as cc, so the above find and replace doesn't work. \n # So, assume first entry in ld is the name of the linker -- gcc or cc or \n # whatever. This is a sane assumption, correct?\n # If the linker is gcc, set it to g++\n link_cmds = ld.split() \n if gcc_exists(link_cmds[0]):\n link_cmds[0] = 'g++'\n ld = ' '.join(link_cmds)\n distutils.sysconfig._config_vars['LDSHARED'] = ld \n\ndistutils.sysconfig._init_posix = _init_posix \n# end force g++\n\n\nclass CompileError(exceptions.Exception):\n pass\n \ndef build_extension(module_path,compiler_name = '',build_dir = None,\n temp_dir = None, verbose = 0, **kw):\n \"\"\" Build the file given by module_path into a Python extension module.\n \n build_extensions uses distutils to build Python extension modules.\n kw arguments not used are passed on to the distutils extension\n module. Directory settings can handle absoulte settings, but don't\n currently expand '~' or environment variables.\n \n module_path -- the full path name to the c file to compile. \n Something like: /full/path/name/module_name.c \n The name of the c/c++ file should be the same as the\n name of the module (i.e. the initmodule() routine)\n compiler_name -- The name of the compiler to use. On Windows if it \n isn't given, MSVC is used if it exists (is found).\n gcc is used as a second choice. If neither are found, \n the default distutils compiler is used. Acceptable \n names are 'gcc', 'msvc' or any of the compiler names \n shown by distutils.ccompiler.show_compilers()\n build_dir -- The location where the resulting extension module \n should be placed. This location must be writable. If\n it isn't, several default locations are tried. If the \n build_dir is not in the current python path, a warning\n is emitted, and it is added to the end of the path.\n build_dir defaults to the current directory.\n temp_dir -- The location where temporary files (*.o or *.obj)\n from the build are placed. This location must be \n writable. If it isn't, several default locations are \n tried. It defaults to tempfile.gettempdir()\n verbose -- 0, 1, or 2. 0 is as quiet as possible. 1 prints\n minimal information. 2 is noisy. \n **kw -- keyword arguments. These are passed on to the \n distutils extension module. Most of the keywords\n are listed below.\n\n Distutils keywords. These are cut and pasted from Greg Ward's\n distutils.extension.Extension class for convenience:\n \n sources : [string]\n list of source filenames, relative to the distribution root\n (where the setup script lives), in Unix form (slash-separated)\n for portability. Source files may be C, C++, SWIG (.i),\n platform-specific resource files, or whatever else is recognized\n by the \"build_ext\" command as source for a Python extension.\n Note: The module_path file is always appended to the front of this\n list \n include_dirs : [string]\n list of directories to search for C/C++ header files (in Unix\n form for portability) \n define_macros : [(name : string, value : string|None)]\n list of macros to define; each macro is defined using a 2-tuple,\n where 'value' is either the string to define it to or None to\n define it without a particular value (equivalent of \"#define\n FOO\" in source or -DFOO on Unix C compiler command line) \n undef_macros : [string]\n list of macros to undefine explicitly\n library_dirs : [string]\n list of directories to search for C/C++ libraries at link time\n libraries : [string]\n list of library names (not filenames or paths) to link against\n runtime_library_dirs : [string]\n list of directories to search for C/C++ libraries at run time\n (for shared extensions, this is when the extension is loaded)\n extra_objects : [string]\n list of extra files to link with (eg. object files not implied\n by 'sources', static library that must be explicitly specified,\n binary resource files, etc.)\n extra_compile_args : [string]\n any extra platform- and compiler-specific information to use\n when compiling the source files in 'sources'. For platforms and\n compilers where \"command line\" makes sense, this is typically a\n list of command-line arguments, but for other platforms it could\n be anything.\n extra_link_args : [string]\n any extra platform- and compiler-specific information to use\n when linking object files together to create the extension (or\n to create a new static Python interpreter). Similar\n interpretation as for 'extra_compile_args'.\n export_symbols : [string]\n list of symbols to be exported from a shared extension. Not\n used on all platforms, and not generally necessary for Python\n extensions, which typically export exactly one symbol: \"init\" +\n extension_name.\n \"\"\"\n success = 0\n from distutils.core import setup, Extension\n \n # this is a screwy trick to get rid of a ton of warnings on Unix\n import distutils.sysconfig\n distutils.sysconfig.get_config_vars()\n if distutils.sysconfig._config_vars.has_key('OPT'):\n flags = distutils.sysconfig._config_vars['OPT'] \n flags = flags.replace('-Wall','')\n distutils.sysconfig._config_vars['OPT'] = flags\n \n # get the name of the module and the extension directory it lives in. \n module_dir,cpp_name = os.path.split(os.path.abspath(module_path))\n module_name,ext = os.path.splitext(cpp_name) \n \n # configure temp and build directories\n temp_dir = configure_temp_dir(temp_dir) \n build_dir = configure_build_dir(module_dir)\n \n # dag. We keep having to add directories to the path to keep \n # object files separated from each other. gcc2.x and gcc3.x C++ \n # object files are not compatible, so we'll stick them in a sub\n # dir based on their version. This will add gccX.X to the \n # path.\n compiler_dir = get_compiler_dir(compiler_name)\n temp_dir = os.path.join(temp_dir,compiler_dir)\n distutils.dir_util.mkpath(temp_dir)\n \n compiler_name = choose_compiler(compiler_name)\n \n configure_sys_argv(compiler_name,temp_dir,build_dir)\n \n # the business end of the function\n try:\n if verbose == 1:\n print 'Compiling code...'\n \n # set compiler verboseness 2 or more makes it output results\n if verbose > 1: verb = 1 \n else: verb = 0\n \n t1 = time.time() \n # add module to the needed source code files and build extension\n sources = kw.get('sources',[])\n kw['sources'] = [module_path] + sources \n \n # SunOS specific\n # fix for issue with linking to libstdc++.a. see:\n # http://mail.python.org/pipermail/python-dev/2001-March/013510.html\n platform = sys.platform\n version = sys.version.lower()\n if platform[:5] == 'sunos' and version.find('gcc') != -1:\n extra_link_args = kw.get('extra_link_args',[])\n kw['extra_link_args'] = ['-mimpure-text'] + extra_link_args\n \n ext = Extension(module_name, **kw)\n \n # the switcheroo on SystemExit here is meant to keep command line\n # sessions from exiting when compiles fail.\n builtin = sys.modules['__builtin__']\n old_SysExit = builtin.__dict__['SystemExit']\n builtin.__dict__['SystemExit'] = CompileError\n \n # distutils for MSVC messes with the environment, so we save the\n # current state and restore them afterward.\n import copy\n environ = copy.deepcopy(os.environ)\n try:\n setup(name = module_name, ext_modules = [ext],verbose=verb)\n finally:\n # restore state\n os.environ = environ \n # restore SystemExit\n builtin.__dict__['SystemExit'] = old_SysExit\n t2 = time.time()\n \n if verbose == 1:\n print 'finished compiling (sec): ', t2 - t1 \n success = 1\n configure_python_path(build_dir)\n except SyntaxError: #TypeError:\n success = 0 \n \n # restore argv after our trick... \n restore_sys_argv()\n \n return success\n\nold_argv = []\ndef configure_sys_argv(compiler_name,temp_dir,build_dir):\n # We're gonna play some tricks with argv here to pass info to distutils \n # which is really built for command line use. better way??\n global old_argv\n old_argv = sys.argv[:] \n sys.argv = ['','build_ext','--build-lib', build_dir,\n '--build-temp',temp_dir] \n if compiler_name == 'gcc':\n sys.argv.insert(2,'--compiler='+compiler_name)\n elif compiler_name:\n sys.argv.insert(2,'--compiler='+compiler_name)\n\ndef restore_sys_argv():\n sys.argv = old_argv\n \ndef configure_python_path(build_dir): \n #make sure the module lives in a directory on the python path.\n python_paths = [os.path.abspath(x) for x in sys.path]\n if os.path.abspath(build_dir) not in python_paths:\n #print \"warning: build directory was not part of python path.\"\\\n # \" It has been appended to the path.\"\n sys.path.append(os.path.abspath(build_dir))\n\ndef choose_compiler(compiler_name=''):\n \"\"\" Try and figure out which compiler is gonna be used on windows.\n On other platforms, it just returns whatever value it is given.\n \n converts 'gcc' to 'mingw32' on win32\n \"\"\"\n if sys.platform == 'win32': \n if not compiler_name:\n # On Windows, default to MSVC and use gcc if it wasn't found\n # wasn't found. If neither are found, go with whatever\n # the default is for distutils -- and probably fail...\n if msvc_exists():\n compiler_name = 'msvc'\n elif gcc_exists():\n compiler_name = 'mingw32'\n elif compiler_name == 'gcc':\n compiler_name = 'mingw32'\n else:\n # don't know how to force gcc -- look into this.\n if compiler_name == 'gcc':\n compiler_name = 'unix' \n return compiler_name\n \ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n version = distutils.msvccompiler.get_devstudio_version()\n if version:\n result = 1\n return result\n\nif os.name == 'nt':\n def run_command(command):\n \"\"\" not sure how to get exit status on nt. \"\"\"\n in_pipe,out_pipe = os.popen4(command)\n in_pipe.close()\n text = out_pipe.read()\n return 0, text\nelse:\n run_command = commands.getstatusoutput\n\ndef get_compiler_dir(compiler_name):\n if compiler_name == 'gcc': \n status, text = run_command(compiler_name + ' --version')\n try:\n import re\n version = re.findall('\\d\\.\\d',text)[0]\n except IndexError:\n version = ''\n compiler_dir = compiler_name + version\n else: \n compiler_dir = compiler_name\n return compiler_dir\n \ndef configure_temp_dir(temp_dir=None):\n if temp_dir is None: \n temp_dir = tempfile.gettempdir()\n elif not os.path.exists(temp_dir) or not os.access(temp_dir,os.W_OK):\n print \"warning: specified temp_dir '%s' does not exist \" \\\n \"or is not writable. Using the default temp directory\" % \\\n temp_dir\n temp_dir = tempfile.gettempdir()\n\n # final check that that directories are writable. \n if not os.access(temp_dir,os.W_OK):\n msg = \"Either the temp or build directory wasn't writable. Check\" \\\n \" these locations: '%s'\" % temp_dir \n raise ValueError, msg\n return temp_dir\n\ndef configure_build_dir(build_dir=None):\n # make sure build_dir exists and is writable\n if build_dir and (not os.path.exists(build_dir) or \n not os.access(build_dir,os.W_OK)):\n print \"warning: specified build_dir '%s' does not exist \" \\\n \"or is not writable. Trying default locations\" % build_dir\n build_dir = None\n \n if build_dir is None:\n #default to building in the home directory of the given module. \n build_dir = os.curdir\n # if it doesn't work use the current directory. This should always\n # be writable. \n if not os.access(build_dir,os.W_OK):\n print \"warning:, neither the module's directory nor the \"\\\n \"current directory are writable. Using the temporary\"\\\n \"directory.\"\n build_dir = tempfile.gettempdir()\n\n # final check that that directories are writable.\n if not os.access(build_dir,os.W_OK):\n msg = \"The build directory wasn't writable. Check\" \\\n \" this location: '%s'\" % build_dir\n raise ValueError, msg\n \n return os.path.abspath(build_dir) \n \nif sys.platform == 'win32':\n import distutils.cygwinccompiler\n # the same as cygwin plus some additional parameters\n class Mingw32CCompiler (distutils.cygwinccompiler.CygwinCCompiler):\n \"\"\" A modified MingW32 compiler compatible with an MSVC built Python.\n \n \"\"\"\n \n compiler_type = 'mingw32'\n \n def __init__ (self,\n verbose=0,\n dry_run=0,\n force=0):\n \n distutils.cygwinccompiler.CygwinCCompiler.__init__ (self, verbose, \n dry_run, force)\n \n # A real mingw32 doesn't need to specify a different entry point,\n # but cygwin 2.91.57 in no-cygwin-mode needs it.\n if self.gcc_version <= \"2.91.57\":\n entry_point = '--entry _DllMain@12'\n else:\n entry_point = ''\n if self.linker_dll == 'dllwrap':\n self.linker = 'dllwrap' + ' --driver-name g++'\n elif self.linker_dll == 'gcc':\n self.linker = 'g++' \n # **changes: eric jones 4/11/01\n # 1. Check for import library on Windows. Build if it doesn't exist.\n if not import_library_exists():\n build_import_library()\n \n # **changes: eric jones 4/11/01\n # 2. increased optimization and turned off all warnings\n # 3. also added --driver-name g++\n #self.set_executables(compiler='gcc -mno-cygwin -O2 -w',\n # compiler_so='gcc -mno-cygwin -mdll -O2 -w',\n # linker_exe='gcc -mno-cygwin',\n # linker_so='%s --driver-name g++ -mno-cygwin -mdll -static %s' \n # % (self.linker, entry_point))\n self.set_executables(compiler='g++ -mno-cygwin -O2 -w',\n compiler_so='g++ -mno-cygwin -mdll -O2 -w -Wstrict-prototypes',\n linker_exe='g++ -mno-cygwin',\n linker_so='%s -mno-cygwin -mdll -static %s' \n % (self.linker, entry_point))\n \n # Maybe we should also append -mthreads, but then the finished\n # dlls need another dll (mingwm10.dll see Mingw32 docs)\n # (-mthreads: Support thread-safe exception handling on `Mingw32') \n \n # no additional libraries needed \n self.dll_libraries=[]\n \n # __init__ ()\n \n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n # We should also check the version of gcc available...\n #distutils.ccompiler._default_compilers['nt'] = 'mingw32'\n #distutils.ccompiler._default_compilers = (('nt', 'mingw32'))\n # reset the Mingw32 compiler in distutils to the one defined above\n distutils.cygwinccompiler.Mingw32CCompiler = Mingw32CCompiler\n \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if os.name == 'nt':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n from scipy_distutils import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile is None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print 'WARNING: failed to build import library for gcc. Linking will fail.'\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \ndef test(level=10):\n from scipy_test.testing import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test.testing import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\n\n\n", "methods": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [], "start_line": 32, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 52, "complexity": 9, "token_count": 390, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 53, "end_line": 223, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 171, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name , temp_dir , build_dir )", "filename": "build_tools.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [ "compiler_name", "temp_dir", "build_dir" ], "start_line": 226, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "build_tools.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 238, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "configure_python_path", "long_name": "configure_python_path( build_dir )", "filename": "build_tools.py", "nloc": 4, "complexity": 3, "token_count": 51, "parameters": [ "build_dir" ], "start_line": 241, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "build_tools.py", "nloc": 13, "complexity": 7, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 249, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 272, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "build_tools.py", "nloc": 14, "complexity": 4, "token_count": 71, "parameters": [], "start_line": 294, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "run_command", "long_name": "run_command( command )", "filename": "build_tools.py", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "command" ], "start_line": 314, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_compiler_dir", "long_name": "get_compiler_dir( compiler_name )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 323, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 336, "end_line": 350, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 352, "end_line": 377, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_tools.py", "nloc": 22, "complexity": 5, "token_count": 117, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 389, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 2 }, { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "build_tools.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 443, "end_line": 451, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 453, "end_line": 479, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 484, "end_line": 486, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 488, "end_line": 490, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 8, "complexity": 2, "token_count": 57, "parameters": [], "start_line": 31, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "build_extension", "long_name": "build_extension( module_path , compiler_name = '' , build_dir = None , temp_dir = None , verbose = 0 , ** kw )", "filename": "build_tools.py", "nloc": 52, "complexity": 9, "token_count": 390, "parameters": [ "module_path", "compiler_name", "build_dir", "temp_dir", "verbose", "kw" ], "start_line": 52, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 171, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name , temp_dir , build_dir )", "filename": "build_tools.py", "nloc": 9, "complexity": 3, "token_count": 68, "parameters": [ "compiler_name", "temp_dir", "build_dir" ], "start_line": 225, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "build_tools.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 237, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "configure_python_path", "long_name": "configure_python_path( build_dir )", "filename": "build_tools.py", "nloc": 4, "complexity": 3, "token_count": 51, "parameters": [ "build_dir" ], "start_line": 240, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "build_tools.py", "nloc": 13, "complexity": 7, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 248, "end_line": 269, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 271, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "build_tools.py", "nloc": 14, "complexity": 4, "token_count": 71, "parameters": [], "start_line": 293, "end_line": 310, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "run_command", "long_name": "run_command( command )", "filename": "build_tools.py", "nloc": 5, "complexity": 1, "token_count": 32, "parameters": [ "command" ], "start_line": 313, "end_line": 318, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_compiler_dir", "long_name": "get_compiler_dir( compiler_name )", "filename": "build_tools.py", "nloc": 12, "complexity": 3, "token_count": 55, "parameters": [ "compiler_name" ], "start_line": 322, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "configure_temp_dir", "long_name": "configure_temp_dir( temp_dir = None )", "filename": "build_tools.py", "nloc": 13, "complexity": 5, "token_count": 82, "parameters": [ "temp_dir" ], "start_line": 335, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "configure_build_dir", "long_name": "configure_build_dir( build_dir = None )", "filename": "build_tools.py", "nloc": 18, "complexity": 7, "token_count": 112, "parameters": [ "build_dir" ], "start_line": 351, "end_line": 376, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "build_tools.py", "nloc": 22, "complexity": 5, "token_count": 117, "parameters": [ "self", "verbose", "dry_run", "force" ], "start_line": 388, "end_line": 430, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 43, "top_nesting_level": 2 }, { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "build_tools.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 442, "end_line": 450, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "build_tools.py", "nloc": 18, "complexity": 2, "token_count": 190, "parameters": [], "start_line": 452, "end_line": 478, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "level" ], "start_line": 483, "end_line": 485, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "level" ], "start_line": 487, "end_line": 489, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 255, "complexity": 60, "token_count": 1575, "diff_parsed": { "added": [ "import commands" ], "deleted": [] } } ] }, { "hash": "4ce790846079e3a252fa37ecc6d789dc282b012a", "msg": "scipy_test can be build/installed separately", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-09-20T22:25:53+00:00", "author_timezone": 0, "committer_date": "2002-09-20T22:25:53+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "f55fb2ec42b239d62f7fc25131045795f7aa35bf" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 7, "insertions": 11, "lines": 18, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_test/setup_scipy_test.py", "new_path": "scipy_test/setup_scipy_test.py", "filename": "setup_scipy_test.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,14 +1,18 @@\n+#!/usr/bin/env python\n+\n import os\n-from scipy_distutils.misc_util import get_path, default_config_dict\n+from scipy_distutils.misc_util import get_path, default_config_dict,\\\n+ dot_join\n \n def configuration(parent_package=''):\n- parent_path = parent_package\n- if parent_package:\n- parent_package += '.'\n+ package = 'scipy_test'\n local_path = get_path(__name__)\n \n- config = default_config_dict()\n- package = 'scipy_test'\n- config['packages'].append(parent_package+package)\n+ config = default_config_dict(package,parent_package)\n+ config['packages'].append(dot_join(parent_package,package))\n config['package_dir'][package] = local_path \n return config\n+\n+if __name__ == '__main__': \n+ from scipy_distutils.core import setup\n+ setup(**configuration())\n", "added_lines": 11, "deleted_lines": 7, "source_code": "#!/usr/bin/env python\n\nimport os\nfrom scipy_distutils.misc_util import get_path, default_config_dict,\\\n dot_join\n\ndef configuration(parent_package=''):\n package = 'scipy_test'\n local_path = get_path(__name__)\n\n config = default_config_dict(package,parent_package)\n config['packages'].append(dot_join(parent_package,package))\n config['package_dir'][package] = local_path \n return config\n\nif __name__ == '__main__': \n from scipy_distutils.core import setup\n setup(**configuration())\n", "source_code_before": "import os\nfrom scipy_distutils.misc_util import get_path, default_config_dict\n\ndef configuration(parent_package=''):\n parent_path = parent_package\n if parent_package:\n parent_package += '.'\n local_path = get_path(__name__)\n\n config = default_config_dict()\n package = 'scipy_test'\n config['packages'].append(parent_package+package)\n config['package_dir'][package] = local_path \n return config\n", "methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' )", "filename": "setup_scipy_test.py", "nloc": 7, "complexity": 1, "token_count": 49, "parameters": [ "parent_package" ], "start_line": 7, "end_line": 14, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "methods_before": [ { "name": "configuration", "long_name": "configuration( parent_package = '' )", "filename": "setup_scipy_test.py", "nloc": 10, "complexity": 2, "token_count": 52, "parameters": [ "parent_package" ], "start_line": 4, "end_line": 14, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' )", "filename": "setup_scipy_test.py", "nloc": 7, "complexity": 1, "token_count": 49, "parameters": [ "parent_package" ], "start_line": 7, "end_line": 14, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "nloc": 13, "complexity": 1, "token_count": 81, "diff_parsed": { "added": [ "#!/usr/bin/env python", "", "from scipy_distutils.misc_util import get_path, default_config_dict,\\", " dot_join", " package = 'scipy_test'", " config = default_config_dict(package,parent_package)", " config['packages'].append(dot_join(parent_package,package))", "", "if __name__ == '__main__':", " from scipy_distutils.core import setup", " setup(**configuration())" ], "deleted": [ "from scipy_distutils.misc_util import get_path, default_config_dict", " parent_path = parent_package", " if parent_package:", " parent_package += '.'", " config = default_config_dict()", " package = 'scipy_test'", " config['packages'].append(parent_package+package)" ] } } ] }, { "hash": "9ec0eb7714b132ea85db3a88f78c5f368cbd3bdd", "msg": "Copied missing get_package_path,jiffies functions from scipy_base/testing.py. The latter should be removed.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-09-20T22:27:26+00:00", "author_timezone": 0, "committer_date": "2002-09-20T22:27:26+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "4ce790846079e3a252fa37ecc6d789dc282b012a" ], "project_name": "repo_copy", "project_path": "/tmp/tmphl8gozk0/repo_copy", "deletions": 3, "insertions": 40, "lines": 43, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -11,7 +11,44 @@\n import scipy_base.fastumath as math\n except ImportError:\n pass\n- \n+\n+def get_package_path(testfile):\n+ \"\"\" Return path to package directory first assuming that testfile\n+ satisfies the following tree structure:\n+ /build/lib.-\n+ //testfile\n+ If build directory does not exist, then return\n+ /..\n+ \"\"\"\n+ from distutils.util import get_platform\n+ d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n+ d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n+ if os.path.isdir(d1):\n+ return d1\n+ return os.path.dirname(d)\n+\n+if sys.platform=='linux2':\n+ def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n+ _load_time=time.time()):\n+ \"\"\" Return number of jiffies (1/100ths of a second) that this\n+ process has been scheduled in user mode. See man 5 proc. \"\"\"\n+ try:\n+ f=open(_proc_pid_stat,'r')\n+ l = f.readline().split(' ')\n+ f.close()\n+ return int(l[13])\n+ except:\n+ return int(100*(time.time()-_load_time))\n+else:\n+ # os.getpid is not in all platforms available.\n+ # Using time is safe but inaccurate, especially when process\n+ # was suspended or sleeping.\n+ def jiffies(_load_time=time.time()):\n+ \"\"\" Return number of jiffies (1/100ths of a second) that this\n+ process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n+ return int(100*(time.time()-_load_time))\n+\n+\n __all__.append('ScipyTestCase')\n class ScipyTestCase (unittest.TestCase):\n \n@@ -25,11 +62,11 @@ def measure(self,code_str,times=1):\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n- elapsed = time.time()\n+ elapsed = jiffies()\n while i/build/lib.-\n //testfile\n If build directory does not exist, then return\n /..\n \"\"\"\n from distutils.util import get_platform\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if os.path.isdir(d1):\n return d1\n return os.path.dirname(d)\n\nif sys.platform=='linux2':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i/build/lib.-", " //testfile", " If build directory does not exist, then return", " /..", " \"\"\"", " from distutils.util import get_platform", " d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))", " d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))", " if os.path.isdir(d1):", " return d1", " return os.path.dirname(d)", "", "if sys.platform=='linux2':", " def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),", " _load_time=time.time()):", " \"\"\" Return number of jiffies (1/100ths of a second) that this", " process has been scheduled in user mode. See man 5 proc. \"\"\"", " try:", " f=open(_proc_pid_stat,'r')", " l = f.readline().split(' ')", " f.close()", " return int(l[13])", " except:", " return int(100*(time.time()-_load_time))", "else:", " # os.getpid is not in all platforms available.", " # Using time is safe but inaccurate, especially when process", " # was suspended or sleeping.", " def jiffies(_load_time=time.time()):", " \"\"\" Return number of jiffies (1/100ths of a second) that this", " process has been scheduled in user mode. [Emulation with time.time]. \"\"\"", " return int(100*(time.time()-_load_time))", "", "", " elapsed = jiffies()", " elapsed = jiffies() - elapsed" ], "deleted": [ "", " elapsed = time.time()", " elapsed = time.time() - elapsed" ] } } ] } ]