[ { "hash": "51b51361f8390ab1acc017da1e27644cb1fa4446", "msg": "line ending cleanup", "author": { "name": "Travis Vaught", "email": "travis@enthought.com" }, "committer": { "name": "Travis Vaught", "email": "travis@enthought.com" }, "author_date": "2002-02-01T16:43:49+00:00", "author_timezone": 0, "committer_date": "2002-02-01T16:43:49+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "c604a3821cf1114c63dc719aae36ebe262d7d303" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 0, "insertions": 0, "lines": 0, "files": 0, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null }, { "hash": "fdb510696ec5874ce2630a24828f24197c3cffe9", "msg": "fixed a naming error of compiler->weave", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-02-12T23:47:45+00:00", "author_timezone": 0, "committer_date": "2002-02-12T23:47:45+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "51b51361f8390ab1acc017da1e27644cb1fa4446" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/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": "scipy_distutils/mingw32_support.py", "new_path": "scipy_distutils/mingw32_support.py", "filename": "mingw32_support.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -36,8 +36,8 @@ def import_library_exists():\n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n- # lib2def lives in compiler\n- sys.path.append(os.path.join('.','compiler'))\n+ # lib2def lives in weave\n+ sys.path.append(os.path.join('.','weave'))\n \n import lib2def\n #libfile, deffile = parse_cmd()\n", "added_lines": 2, "deleted_lines": 2, "source_code": "\"\"\"\nSupport code for building Python extensions on Windows.\n\n # NT stuff\n # 1. Make sure libpython.a exists for gcc. If not, build it.\n # 2. Force windows to use gcc (we're struggling with MSVC and g77 support) \n # 3. Force windows to use g77\n\n\"\"\"\n\nimport os, sys\nimport distutils.ccompiler\n\n# I'd really like to pull this out of scipy and make it part of distutils...\nimport scipy_distutils.command.build_flib as build_flib\n\n\nif sys.platform == 'win32':\n # NT stuff\n # 1. Make sure libpython.a exists for gcc. If not, build it.\n # 2. Force windows to use gcc (we're struggling with MSVC and g77 support) \n # 3. Force windows to use g77\n \n # 1. Build libpython from .lib and .dll if they don't exist. \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if sys.platform == 'win32':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n #print full_path\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 # lib2def lives in weave\n sys.path.append(os.path.join('.','weave'))\n\n import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile == 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 print cmd\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. \"\\\n \"Linking will fail.\"\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \n def set_windows_compiler(compiler):\n distutils.ccompiler._default_compilers = (\n \n # Platform string mappings\n \n # on a cygwin built python we can use gcc like an ordinary UNIXish\n # compiler\n ('cygwin.*', 'unix'),\n \n # OS name mappings\n ('posix', 'unix'),\n ('nt', compiler),\n ('mac', 'mwerks'),\n \n ) \n def use_msvc():\n set_windows_compiler('msvc')\n \n def use_gcc(): \n set_windows_compiler('mingw32') \n \n def use_g77():\n build_flib.all_compilers = [build_flib.gnu_fortran_compiler] \n \n # 2. force the use of gcc on windows platform\n use_gcc()\n # 3. force the use of g77 on windows platform\n use_g77()\n if not import_library_exists():\n build_import_library()\n\n \n", "source_code_before": "\"\"\"\nSupport code for building Python extensions on Windows.\n\n # NT stuff\n # 1. Make sure libpython.a exists for gcc. If not, build it.\n # 2. Force windows to use gcc (we're struggling with MSVC and g77 support) \n # 3. Force windows to use g77\n\n\"\"\"\n\nimport os, sys\nimport distutils.ccompiler\n\n# I'd really like to pull this out of scipy and make it part of distutils...\nimport scipy_distutils.command.build_flib as build_flib\n\n\nif sys.platform == 'win32':\n # NT stuff\n # 1. Make sure libpython.a exists for gcc. If not, build it.\n # 2. Force windows to use gcc (we're struggling with MSVC and g77 support) \n # 3. Force windows to use g77\n \n # 1. Build libpython from .lib and .dll if they don't exist. \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if sys.platform == 'win32':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n #print full_path\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 # lib2def lives in compiler\n sys.path.append(os.path.join('.','compiler'))\n\n import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile == 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 print cmd\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. \"\\\n \"Linking will fail.\"\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \n def set_windows_compiler(compiler):\n distutils.ccompiler._default_compilers = (\n \n # Platform string mappings\n \n # on a cygwin built python we can use gcc like an ordinary UNIXish\n # compiler\n ('cygwin.*', 'unix'),\n \n # OS name mappings\n ('posix', 'unix'),\n ('nt', compiler),\n ('mac', 'mwerks'),\n \n ) \n def use_msvc():\n set_windows_compiler('msvc')\n \n def use_gcc(): \n set_windows_compiler('mingw32') \n \n def use_g77():\n build_flib.all_compilers = [build_flib.gnu_fortran_compiler] \n \n # 2. force the use of gcc on windows platform\n use_gcc()\n # 3. force the use of g77 on windows platform\n use_g77()\n if not import_library_exists():\n build_import_library()\n\n \n", "methods": [ { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "mingw32_support.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 25, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "mingw32_support.py", "nloc": 21, "complexity": 2, "token_count": 209, "parameters": [], "start_line": 36, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "set_windows_compiler", "long_name": "set_windows_compiler( compiler )", "filename": "mingw32_support.py", "nloc": 7, "complexity": 1, "token_count": 37, "parameters": [ "compiler" ], "start_line": 72, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "use_msvc", "long_name": "use_msvc( )", "filename": "mingw32_support.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [], "start_line": 87, "end_line": 88, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "use_gcc", "long_name": "use_gcc( )", "filename": "mingw32_support.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [], "start_line": 90, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "use_g77", "long_name": "use_g77( )", "filename": "mingw32_support.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [], "start_line": 93, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "import_library_exists", "long_name": "import_library_exists( )", "filename": "mingw32_support.py", "nloc": 7, "complexity": 3, "token_count": 57, "parameters": [], "start_line": 25, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "mingw32_support.py", "nloc": 21, "complexity": 2, "token_count": 209, "parameters": [], "start_line": 36, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 }, { "name": "set_windows_compiler", "long_name": "set_windows_compiler( compiler )", "filename": "mingw32_support.py", "nloc": 7, "complexity": 1, "token_count": 37, "parameters": [ "compiler" ], "start_line": 72, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "use_msvc", "long_name": "use_msvc( )", "filename": "mingw32_support.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [], "start_line": 87, "end_line": 88, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "use_gcc", "long_name": "use_gcc( )", "filename": "mingw32_support.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [], "start_line": 90, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "use_g77", "long_name": "use_g77( )", "filename": "mingw32_support.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [], "start_line": 93, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "build_import_library", "long_name": "build_import_library( )", "filename": "mingw32_support.py", "nloc": 21, "complexity": 2, "token_count": 209, "parameters": [], "start_line": 36, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 } ], "nloc": 58, "complexity": 9, "token_count": 377, "diff_parsed": { "added": [ " # lib2def lives in weave", " sys.path.append(os.path.join('.','weave'))" ], "deleted": [ " # lib2def lives in compiler", " sys.path.append(os.path.join('.','compiler'))" ] } } ] }, { "hash": "45819f94a39fe9c46678c09db406eb36c38170ac", "msg": "removed template code from use for scalar conversions. Template versions were moved into blitz support stuff because that is the only place they are utilized.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-02-13T08:28:22+00:00", "author_timezone": 0, "committer_date": "2002-02-13T08:28:22+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "fdb510696ec5874ce2630a24828f24197c3cffe9" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 158, "insertions": 194, "lines": 352, "files": 6, "dmm_unit_size": 0.10526315789473684, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "weave/blitz_info.py", "new_path": "weave/blitz_info.py", "filename": "blitz_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -81,6 +81,128 @@ class py_type >{public: enum { code = PyArray_CDOUBLE};};\n }\n \"\"\"\n \n+# this code will not build with msvc...\n+# This is only used for blitz stuff now. The non-templated\n+# version, defined further down, is now used for most code.\n+scalar_support_code = \\\n+\"\"\"\n+// conversion routines\n+\n+template \n+static T convert_to_scalar(PyObject* py_obj,const char* name)\n+{\n+ //never used.\n+ return (T) 0;\n+}\n+template<>\n+static int convert_to_scalar(PyObject* py_obj,const char* name)\n+{\n+ if (!py_obj || !PyInt_Check(py_obj))\n+ handle_conversion_error(py_obj,\"int\", name);\n+ return (int) PyInt_AsLong(py_obj);\n+}\n+\n+template<>\n+static long convert_to_scalar(PyObject* py_obj,const char* name)\n+{\n+ if (!py_obj || !PyLong_Check(py_obj))\n+ handle_conversion_error(py_obj,\"long\", name);\n+ return (long) PyLong_AsLong(py_obj);\n+}\n+\n+template<> \n+static double convert_to_scalar(PyObject* py_obj,const char* name)\n+{\n+ if (!py_obj || !PyFloat_Check(py_obj))\n+ handle_conversion_error(py_obj,\"float\", name);\n+ return PyFloat_AsDouble(py_obj);\n+}\n+\n+template<> \n+static float convert_to_scalar(PyObject* py_obj,const char* name)\n+{\n+ return (float) convert_to_scalar(py_obj,name);\n+}\n+\n+// complex not checked.\n+template<> \n+static std::complex convert_to_scalar >(PyObject* py_obj,\n+ const char* name)\n+{\n+ if (!py_obj || !PyComplex_Check(py_obj))\n+ handle_conversion_error(py_obj,\"complex\", name);\n+ return std::complex((float) PyComplex_RealAsDouble(py_obj),\n+ (float) PyComplex_ImagAsDouble(py_obj)); \n+}\n+template<> \n+static std::complex convert_to_scalar >(\n+ PyObject* py_obj,const char* name)\n+{\n+ if (!py_obj || !PyComplex_Check(py_obj))\n+ handle_conversion_error(py_obj,\"complex\", name);\n+ return std::complex(PyComplex_RealAsDouble(py_obj),\n+ PyComplex_ImagAsDouble(py_obj)); \n+}\n+\n+/////////////////////////////////\n+// standard translation routines\n+\n+template \n+static T py_to_scalar(PyObject* py_obj,const char* name)\n+{\n+ //never used.\n+ return (T) 0;\n+}\n+template<>\n+static int py_to_scalar(PyObject* py_obj,const char* name)\n+{\n+ if (!py_obj || !PyInt_Check(py_obj))\n+ handle_bad_type(py_obj,\"int\", name);\n+ return (int) PyInt_AsLong(py_obj);\n+}\n+\n+template<>\n+static long py_to_scalar(PyObject* py_obj,const char* name)\n+{\n+ if (!py_obj || !PyLong_Check(py_obj))\n+ handle_bad_type(py_obj,\"long\", name);\n+ return (long) PyLong_AsLong(py_obj);\n+}\n+\n+template<> \n+static double py_to_scalar(PyObject* py_obj,const char* name)\n+{\n+ if (!py_obj || !PyFloat_Check(py_obj))\n+ handle_bad_type(py_obj,\"float\", name);\n+ return PyFloat_AsDouble(py_obj);\n+}\n+\n+template<> \n+static float py_to_scalar(PyObject* py_obj,const char* name)\n+{\n+ return (float) py_to_scalar(py_obj,name);\n+}\n+\n+// complex not checked.\n+template<> \n+static std::complex py_to_scalar >(PyObject* py_obj,\n+ const char* name)\n+{\n+ if (!py_obj || !PyComplex_Check(py_obj))\n+ handle_bad_type(py_obj,\"complex\", name);\n+ return std::complex((float) PyComplex_RealAsDouble(py_obj),\n+ (float) PyComplex_ImagAsDouble(py_obj)); \n+}\n+template<> \n+static std::complex py_to_scalar >(\n+ PyObject* py_obj,const char* name)\n+{\n+ if (!py_obj || !PyComplex_Check(py_obj))\n+ handle_bad_type(py_obj,\"complex\", name);\n+ return std::complex(PyComplex_RealAsDouble(py_obj),\n+ PyComplex_ImagAsDouble(py_obj)); \n+}\n+\"\"\" \n \n import standard_array_info\n import os, blitz_info\n@@ -94,7 +216,9 @@ class array_info(base_info.base_info):\n _support_code = [standard_array_info.array_convert_code,\n standard_array_info.type_check_code,\n standard_array_info.size_check_code,\n- blitz_support_code]\n+ scalar_support_code,\n+ blitz_support_code,\n+ ]\n _module_init_code = [standard_array_info.numeric_init_code] \n \n # throw error if trying to use msvc compiler\n", "added_lines": 125, "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\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\n// simple meta-program templates to specify python typecodes\n// for each of the numeric types.\ntemplate\nclass py_type{public: enum {code = 100};};\nclass py_type{public: enum {code = PyArray_CHAR};};\nclass py_type{public: enum { code = PyArray_UBYTE};};\nclass py_type{public: enum { code = PyArray_SHORT};};\nclass py_type{public: enum { code = PyArray_LONG};};// PyArray_INT has troubles;\nclass py_type{public: enum { code = PyArray_LONG};};\nclass py_type{public: enum { code = PyArray_FLOAT};};\nclass py_type{public: enum { code = PyArray_DOUBLE};};\nclass py_type >{public: enum { code = PyArray_CFLOAT};};\nclass py_type >{public: enum { code = PyArray_CDOUBLE};};\n\ntemplate\nstatic blitz::Array convert_to_blitz(PyArrayObject* arr_obj,const char* name)\n{\n\n //This is now handled externally (for now) to deal with exception/Abort issue\n //PyArrayObject* arr_obj = convert_to_numpy(py_obj,name);\n //conversion_numpy_check_size(arr_obj,N,name);\n //conversion_numpy_check_type(arr_obj,py_type::code,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 //This is now handled externally (for now) to deal with exception/Abort issue\n //PyArrayObject* arr_obj = py_to_numpy(py_obj,name);\n //numpy_check_size(arr_obj,N,name);\n //numpy_check_type(arr_obj,py_type::code,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\"\"\"\n\n# this code will not build with msvc...\n# This is only used for blitz stuff now. The non-templated\n# version, defined further down, is now used for most code.\nscalar_support_code = \\\n\"\"\"\n// conversion routines\n\ntemplate \nstatic T convert_to_scalar(PyObject* py_obj,const char* name)\n{\n //never used.\n return (T) 0;\n}\ntemplate<>\nstatic int convert_to_scalar(PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyInt_Check(py_obj))\n handle_conversion_error(py_obj,\"int\", name);\n return (int) PyInt_AsLong(py_obj);\n}\n\ntemplate<>\nstatic long convert_to_scalar(PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyLong_Check(py_obj))\n handle_conversion_error(py_obj,\"long\", name);\n return (long) PyLong_AsLong(py_obj);\n}\n\ntemplate<> \nstatic double convert_to_scalar(PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyFloat_Check(py_obj))\n handle_conversion_error(py_obj,\"float\", name);\n return PyFloat_AsDouble(py_obj);\n}\n\ntemplate<> \nstatic float convert_to_scalar(PyObject* py_obj,const char* name)\n{\n return (float) convert_to_scalar(py_obj,name);\n}\n\n// complex not checked.\ntemplate<> \nstatic std::complex convert_to_scalar >(PyObject* py_obj,\n const char* name)\n{\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_conversion_error(py_obj,\"complex\", name);\n return std::complex((float) PyComplex_RealAsDouble(py_obj),\n (float) PyComplex_ImagAsDouble(py_obj)); \n}\ntemplate<> \nstatic std::complex convert_to_scalar >(\n PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_conversion_error(py_obj,\"complex\", name);\n return std::complex(PyComplex_RealAsDouble(py_obj),\n PyComplex_ImagAsDouble(py_obj)); \n}\n\n/////////////////////////////////\n// standard translation routines\n\ntemplate \nstatic T py_to_scalar(PyObject* py_obj,const char* name)\n{\n //never used.\n return (T) 0;\n}\ntemplate<>\nstatic int py_to_scalar(PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyInt_Check(py_obj))\n handle_bad_type(py_obj,\"int\", name);\n return (int) PyInt_AsLong(py_obj);\n}\n\ntemplate<>\nstatic long py_to_scalar(PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyLong_Check(py_obj))\n handle_bad_type(py_obj,\"long\", name);\n return (long) PyLong_AsLong(py_obj);\n}\n\ntemplate<> \nstatic double py_to_scalar(PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyFloat_Check(py_obj))\n handle_bad_type(py_obj,\"float\", name);\n return PyFloat_AsDouble(py_obj);\n}\n\ntemplate<> \nstatic float py_to_scalar(PyObject* py_obj,const char* name)\n{\n return (float) py_to_scalar(py_obj,name);\n}\n\n// complex not checked.\ntemplate<> \nstatic std::complex py_to_scalar >(PyObject* py_obj,\n const char* name)\n{\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_bad_type(py_obj,\"complex\", name);\n return std::complex((float) PyComplex_RealAsDouble(py_obj),\n (float) PyComplex_ImagAsDouble(py_obj)); \n}\ntemplate<> \nstatic std::complex py_to_scalar >(\n PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_bad_type(py_obj,\"complex\", name);\n return std::complex(PyComplex_RealAsDouble(py_obj),\n PyComplex_ImagAsDouble(py_obj)); \n}\n\"\"\" \n\nimport standard_array_info\nimport os, blitz_info\nlocal_dir,junk = os.path.split(os.path.abspath(blitz_info.__file__)) \nblitz_dir = os.path.join(local_dir,'blitz-20001213')\n\nclass array_info(base_info.base_info):\n _include_dirs = [blitz_dir]\n _headers = ['\"blitz/array.h\"','\"Numeric/arrayobject.h\"','','']\n \n _support_code = [standard_array_info.array_convert_code,\n standard_array_info.type_check_code,\n standard_array_info.size_check_code,\n scalar_support_code,\n blitz_support_code,\n ]\n _module_init_code = [standard_array_info.numeric_init_code] \n \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 ", "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\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\n// simple meta-program templates to specify python typecodes\n// for each of the numeric types.\ntemplate\nclass py_type{public: enum {code = 100};};\nclass py_type{public: enum {code = PyArray_CHAR};};\nclass py_type{public: enum { code = PyArray_UBYTE};};\nclass py_type{public: enum { code = PyArray_SHORT};};\nclass py_type{public: enum { code = PyArray_LONG};};// PyArray_INT has troubles;\nclass py_type{public: enum { code = PyArray_LONG};};\nclass py_type{public: enum { code = PyArray_FLOAT};};\nclass py_type{public: enum { code = PyArray_DOUBLE};};\nclass py_type >{public: enum { code = PyArray_CFLOAT};};\nclass py_type >{public: enum { code = PyArray_CDOUBLE};};\n\ntemplate\nstatic blitz::Array convert_to_blitz(PyArrayObject* arr_obj,const char* name)\n{\n\n //This is now handled externally (for now) to deal with exception/Abort issue\n //PyArrayObject* arr_obj = convert_to_numpy(py_obj,name);\n //conversion_numpy_check_size(arr_obj,N,name);\n //conversion_numpy_check_type(arr_obj,py_type::code,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 //This is now handled externally (for now) to deal with exception/Abort issue\n //PyArrayObject* arr_obj = py_to_numpy(py_obj,name);\n //numpy_check_size(arr_obj,N,name);\n //numpy_check_type(arr_obj,py_type::code,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\"\"\"\n\n\nimport standard_array_info\nimport os, blitz_info\nlocal_dir,junk = os.path.split(os.path.abspath(blitz_info.__file__)) \nblitz_dir = os.path.join(local_dir,'blitz-20001213')\n\nclass array_info(base_info.base_info):\n _include_dirs = [blitz_dir]\n _headers = ['\"blitz/array.h\"','\"Numeric/arrayobject.h\"','','']\n \n _support_code = [standard_array_info.array_convert_code,\n standard_array_info.type_check_code,\n standard_array_info.size_check_code,\n blitz_support_code]\n _module_init_code = [standard_array_info.numeric_init_code] \n \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 ", "methods": [ { "name": "check_compiler", "long_name": "check_compiler( self , compiler )", "filename": "blitz_info.py", "nloc": 6, "complexity": 2, "token_count": 25, "parameters": [ "self", "compiler" ], "start_line": 226, "end_line": 231, "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_info.py", "nloc": 6, "complexity": 2, "token_count": 25, "parameters": [ "self", "compiler" ], "start_line": 102, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 219, "complexity": 2, "token_count": 127, "diff_parsed": { "added": [ "# this code will not build with msvc...", "# This is only used for blitz stuff now. The non-templated", "# version, defined further down, is now used for most code.", "scalar_support_code = \\", "\"\"\"", "// conversion routines", "", "template", "static T convert_to_scalar(PyObject* py_obj,const char* name)", "{", " //never used.", " return (T) 0;", "}", "template<>", "static int convert_to_scalar(PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyInt_Check(py_obj))", " handle_conversion_error(py_obj,\"int\", name);", " return (int) PyInt_AsLong(py_obj);", "}", "", "template<>", "static long convert_to_scalar(PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyLong_Check(py_obj))", " handle_conversion_error(py_obj,\"long\", name);", " return (long) PyLong_AsLong(py_obj);", "}", "", "template<>", "static double convert_to_scalar(PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyFloat_Check(py_obj))", " handle_conversion_error(py_obj,\"float\", name);", " return PyFloat_AsDouble(py_obj);", "}", "", "template<>", "static float convert_to_scalar(PyObject* py_obj,const char* name)", "{", " return (float) convert_to_scalar(py_obj,name);", "}", "", "// complex not checked.", "template<>", "static std::complex convert_to_scalar >(PyObject* py_obj,", " const char* name)", "{", " if (!py_obj || !PyComplex_Check(py_obj))", " handle_conversion_error(py_obj,\"complex\", name);", " return std::complex((float) PyComplex_RealAsDouble(py_obj),", " (float) PyComplex_ImagAsDouble(py_obj));", "}", "template<>", "static std::complex convert_to_scalar >(", " PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyComplex_Check(py_obj))", " handle_conversion_error(py_obj,\"complex\", name);", " return std::complex(PyComplex_RealAsDouble(py_obj),", " PyComplex_ImagAsDouble(py_obj));", "}", "", "/////////////////////////////////", "// standard translation routines", "", "template", "static T py_to_scalar(PyObject* py_obj,const char* name)", "{", " //never used.", " return (T) 0;", "}", "template<>", "static int py_to_scalar(PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyInt_Check(py_obj))", " handle_bad_type(py_obj,\"int\", name);", " return (int) PyInt_AsLong(py_obj);", "}", "", "template<>", "static long py_to_scalar(PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyLong_Check(py_obj))", " handle_bad_type(py_obj,\"long\", name);", " return (long) PyLong_AsLong(py_obj);", "}", "", "template<>", "static double py_to_scalar(PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyFloat_Check(py_obj))", " handle_bad_type(py_obj,\"float\", name);", " return PyFloat_AsDouble(py_obj);", "}", "", "template<>", "static float py_to_scalar(PyObject* py_obj,const char* name)", "{", " return (float) py_to_scalar(py_obj,name);", "}", "", "// complex not checked.", "template<>", "static std::complex py_to_scalar >(PyObject* py_obj,", " const char* name)", "{", " if (!py_obj || !PyComplex_Check(py_obj))", " handle_bad_type(py_obj,\"complex\", name);", " return std::complex((float) PyComplex_RealAsDouble(py_obj),", " (float) PyComplex_ImagAsDouble(py_obj));", "}", "template<>", "static std::complex py_to_scalar >(", " PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyComplex_Check(py_obj))", " handle_bad_type(py_obj,\"complex\", name);", " return std::complex(PyComplex_RealAsDouble(py_obj),", " PyComplex_ImagAsDouble(py_obj));", "}", "\"\"\"", " scalar_support_code,", " blitz_support_code,", " ]" ], "deleted": [ " blitz_support_code]" ] } }, { "old_path": "weave/common_info.py", "new_path": "weave/common_info.py", "filename": "common_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -13,7 +13,7 @@\n from conversion_code import callable_convert_code\n from conversion_code import module_convert_code\n from conversion_code import scalar_support_code\n-from conversion_code import non_template_scalar_support_code\n+#from conversion_code import non_template_scalar_support_code\n \n class basic_module_info(base_info.base_info):\n _headers = ['\"Python.h\"']\n@@ -36,8 +36,10 @@ class scalar_info(base_info.base_info):\n _warnings = ['disable: 4275', 'disable: 4101']\n _headers = ['','']\n def support_code(self):\n- if self.compiler != 'msvc':\n- # maybe this should only be for gcc...\n- return [scalar_support_code,non_template_scalar_support_code]\n- else:\n- return [non_template_scalar_support_code]\n+ return [scalar_support_code]\n+ #def support_code(self):\n+ # if self.compiler != 'msvc':\n+ # # maybe this should only be for gcc...\n+ # return [scalar_support_code,non_template_scalar_support_code]\n+ # else:\n+ # return [non_template_scalar_support_code]\n", "added_lines": 8, "deleted_lines": 6, "source_code": "\"\"\" Generic support code for handling standard Numeric arrays \n\"\"\"\n\nimport base_info\n\n#############################################################\n# Basic module support code\n#############################################################\n\nfrom conversion_code import module_support_code\nfrom conversion_code import file_convert_code\nfrom conversion_code import instance_convert_code\nfrom conversion_code import callable_convert_code\nfrom conversion_code import module_convert_code\nfrom conversion_code import scalar_support_code\n#from conversion_code import non_template_scalar_support_code\n\nclass basic_module_info(base_info.base_info):\n _headers = ['\"Python.h\"']\n _support_code = [module_support_code]\n\nclass file_info(base_info.base_info):\n _headers = ['']\n _support_code = [file_convert_code]\n\nclass instance_info(base_info.base_info):\n _support_code = [instance_convert_code]\n\nclass callable_info(base_info.base_info):\n _support_code = [callable_convert_code]\n\nclass module_info(base_info.base_info):\n _support_code = [module_convert_code]\n\nclass scalar_info(base_info.base_info):\n _warnings = ['disable: 4275', 'disable: 4101']\n _headers = ['','']\n def support_code(self):\n return [scalar_support_code]\n #def support_code(self):\n # if self.compiler != 'msvc':\n # # maybe this should only be for gcc...\n # return [scalar_support_code,non_template_scalar_support_code]\n # else:\n # return [non_template_scalar_support_code]\n", "source_code_before": "\"\"\" Generic support code for handling standard Numeric arrays \n\"\"\"\n\nimport base_info\n\n#############################################################\n# Basic module support code\n#############################################################\n\nfrom conversion_code import module_support_code\nfrom conversion_code import file_convert_code\nfrom conversion_code import instance_convert_code\nfrom conversion_code import callable_convert_code\nfrom conversion_code import module_convert_code\nfrom conversion_code import scalar_support_code\nfrom conversion_code import non_template_scalar_support_code\n\nclass basic_module_info(base_info.base_info):\n _headers = ['\"Python.h\"']\n _support_code = [module_support_code]\n\nclass file_info(base_info.base_info):\n _headers = ['']\n _support_code = [file_convert_code]\n\nclass instance_info(base_info.base_info):\n _support_code = [instance_convert_code]\n\nclass callable_info(base_info.base_info):\n _support_code = [callable_convert_code]\n\nclass module_info(base_info.base_info):\n _support_code = [module_convert_code]\n\nclass scalar_info(base_info.base_info):\n _warnings = ['disable: 4275', 'disable: 4101']\n _headers = ['','']\n def support_code(self):\n if self.compiler != 'msvc':\n # maybe this should only be for gcc...\n return [scalar_support_code,non_template_scalar_support_code]\n else:\n return [non_template_scalar_support_code]\n", "methods": [ { "name": "support_code", "long_name": "support_code( self )", "filename": "common_info.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 38, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "support_code", "long_name": "support_code( self )", "filename": "common_info.py", "nloc": 5, "complexity": 2, "token_count": 24, "parameters": [ "self" ], "start_line": 38, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "support_code", "long_name": "support_code( self )", "filename": "common_info.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 38, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "nloc": 26, "complexity": 1, "token_count": 134, "diff_parsed": { "added": [ "#from conversion_code import non_template_scalar_support_code", " return [scalar_support_code]", " #def support_code(self):", " # if self.compiler != 'msvc':", " # # maybe this should only be for gcc...", " # return [scalar_support_code,non_template_scalar_support_code]", " # else:", " # return [non_template_scalar_support_code]" ], "deleted": [ "from conversion_code import non_template_scalar_support_code", " if self.compiler != 'msvc':", " # maybe this should only be for gcc...", " return [scalar_support_code,non_template_scalar_support_code]", " else:", " return [non_template_scalar_support_code]" ] } }, { "old_path": "weave/conversion_code.py", "new_path": "weave/conversion_code.py", "filename": "conversion_code.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -255,7 +255,7 @@ class module_handler\n #############################################################\n \n # These non-templated version is now used for most scalar conversions.\n-non_template_scalar_support_code = \\\n+scalar_support_code = \\\n \"\"\"\n \n class scalar_handler\n@@ -335,125 +335,3 @@ class scalar_handler\n \n \"\"\" \n \n-# this code will not build with msvc...\n-# This is only used for blitz stuff now. The non-templated\n-# version, defined further down, is now used for most code.\n-scalar_support_code = \\\n-\"\"\"\n-// conversion routines\n-\n-template \n-static T convert_to_scalar(PyObject* py_obj,const char* name)\n-{\n- //never used.\n- return (T) 0;\n-}\n-template<>\n-static int convert_to_scalar(PyObject* py_obj,const char* name)\n-{\n- if (!py_obj || !PyInt_Check(py_obj))\n- handle_conversion_error(py_obj,\"int\", name);\n- return (int) PyInt_AsLong(py_obj);\n-}\n-\n-template<>\n-static long convert_to_scalar(PyObject* py_obj,const char* name)\n-{\n- if (!py_obj || !PyLong_Check(py_obj))\n- handle_conversion_error(py_obj,\"long\", name);\n- return (long) PyLong_AsLong(py_obj);\n-}\n-\n-template<> \n-static double convert_to_scalar(PyObject* py_obj,const char* name)\n-{\n- if (!py_obj || !PyFloat_Check(py_obj))\n- handle_conversion_error(py_obj,\"float\", name);\n- return PyFloat_AsDouble(py_obj);\n-}\n-\n-template<> \n-static float convert_to_scalar(PyObject* py_obj,const char* name)\n-{\n- return (float) convert_to_scalar(py_obj,name);\n-}\n-\n-// complex not checked.\n-template<> \n-static std::complex convert_to_scalar >(PyObject* py_obj,\n- const char* name)\n-{\n- if (!py_obj || !PyComplex_Check(py_obj))\n- handle_conversion_error(py_obj,\"complex\", name);\n- return std::complex((float) PyComplex_RealAsDouble(py_obj),\n- (float) PyComplex_ImagAsDouble(py_obj)); \n-}\n-template<> \n-static std::complex convert_to_scalar >(\n- PyObject* py_obj,const char* name)\n-{\n- if (!py_obj || !PyComplex_Check(py_obj))\n- handle_conversion_error(py_obj,\"complex\", name);\n- return std::complex(PyComplex_RealAsDouble(py_obj),\n- PyComplex_ImagAsDouble(py_obj)); \n-}\n-\n-/////////////////////////////////\n-// standard translation routines\n-\n-template \n-static T py_to_scalar(PyObject* py_obj,const char* name)\n-{\n- //never used.\n- return (T) 0;\n-}\n-template<>\n-static int py_to_scalar(PyObject* py_obj,const char* name)\n-{\n- if (!py_obj || !PyInt_Check(py_obj))\n- handle_bad_type(py_obj,\"int\", name);\n- return (int) PyInt_AsLong(py_obj);\n-}\n-\n-template<>\n-static long py_to_scalar(PyObject* py_obj,const char* name)\n-{\n- if (!py_obj || !PyLong_Check(py_obj))\n- handle_bad_type(py_obj,\"long\", name);\n- return (long) PyLong_AsLong(py_obj);\n-}\n-\n-template<> \n-static double py_to_scalar(PyObject* py_obj,const char* name)\n-{\n- if (!py_obj || !PyFloat_Check(py_obj))\n- handle_bad_type(py_obj,\"float\", name);\n- return PyFloat_AsDouble(py_obj);\n-}\n-\n-template<> \n-static float py_to_scalar(PyObject* py_obj,const char* name)\n-{\n- return (float) py_to_scalar(py_obj,name);\n-}\n-\n-// complex not checked.\n-template<> \n-static std::complex py_to_scalar >(PyObject* py_obj,\n- const char* name)\n-{\n- if (!py_obj || !PyComplex_Check(py_obj))\n- handle_bad_type(py_obj,\"complex\", name);\n- return std::complex((float) PyComplex_RealAsDouble(py_obj),\n- (float) PyComplex_ImagAsDouble(py_obj)); \n-}\n-template<> \n-static std::complex py_to_scalar >(\n- PyObject* py_obj,const char* name)\n-{\n- if (!py_obj || !PyComplex_Check(py_obj))\n- handle_bad_type(py_obj,\"complex\", name);\n- return std::complex(PyComplex_RealAsDouble(py_obj),\n- PyComplex_ImagAsDouble(py_obj)); \n-}\n-\"\"\" \n", "added_lines": 1, "deleted_lines": 123, "source_code": "\"\"\" C/C++ code strings needed for converting most non-sequence\n Python variables:\n module_support_code -- several routines used by most other code \n conversion methods. It holds the only\n CXX dependent code in this file. The CXX\n stuff is used for exceptions\n file_convert_code\n instance_convert_code\n callable_convert_code\n module_convert_code\n \n scalar_convert_code\n non_template_scalar_support_code \n Scalar conversion covers int, float, double, complex,\n and double complex. While Python doesn't support all these,\n Numeric does and so all of them are made available.\n Python longs are currently converted to C ints. Any\n better way to handle this?\n\"\"\"\n\nimport base_info\n\n#############################################################\n# Basic module support code\n#############################################################\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\n#############################################################\n# File conversion support code\n#############################################################\n\nfile_convert_code = \\\n\"\"\"\n\nclass file_handler\n{\npublic:\n FILE* convert_to_file(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyFile_Check(py_obj))\n handle_conversion_error(py_obj,\"file\", name);\n \n // Cleanup code should call DECREF\n Py_INCREF(py_obj);\n return PyFile_AsFile(py_obj);\n }\n \n FILE* py_to_file(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyFile_Check(py_obj))\n handle_bad_type(py_obj,\"file\", name);\n \n // Cleanup code should call DECREF\n Py_INCREF(py_obj);\n return PyFile_AsFile(py_obj);\n }\n};\n\nfile_handler x__file_handler = file_handler();\n#define convert_to_file(py_obj,name) x__file_handler.convert_to_file(py_obj,name)\n#define py_to_file(py_obj,name) x__file_handler.py_to_file(py_obj,name)\n\nPyObject* 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\"\"\"\n\n\n#############################################################\n# Instance conversion code\n#############################################################\n\ninstance_convert_code = \\\n\"\"\"\n\nclass instance_handler\n{\npublic:\n PyObject* convert_to_instance(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyFile_Check(py_obj))\n handle_conversion_error(py_obj,\"instance\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n \n PyObject* py_to_instance(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyFile_Check(py_obj))\n handle_bad_type(py_obj,\"instance\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n};\n\ninstance_handler x__instance_handler = instance_handler();\n#define convert_to_instance(py_obj,name) x__instance_handler.convert_to_instance(py_obj,name)\n#define py_to_instance(py_obj,name) x__instance_handler.py_to_instance(py_obj,name)\n\nPyObject* instance_to_py(PyObject* instance)\n{\n // Don't think I need to do anything...\n return (PyObject*) instance;\n}\n\n\"\"\"\n\n#############################################################\n# Callable conversion code\n#############################################################\n\ncallable_convert_code = \\\n\"\"\"\n\nclass callable_handler\n{\npublic: \n PyObject* convert_to_callable(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyCallable_Check(py_obj))\n handle_conversion_error(py_obj,\"callable\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n \n PyObject* py_to_callable(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyCallable_Check(py_obj))\n handle_bad_type(py_obj,\"callable\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n};\n\ncallable_handler x__callable_handler = callable_handler();\n#define convert_to_callable(py_obj,name) x__callable_handler.convert_to_callable(py_obj,name)\n#define py_to_callable(py_obj,name) x__callable_handler.py_to_callable(py_obj,name)\n\nPyObject* callable_to_py(PyObject* callable)\n{\n // Don't think I need to do anything...\n return (PyObject*) callable;\n}\n\n\"\"\"\n\n#############################################################\n# Module conversion code\n#############################################################\n\nmodule_convert_code = \\\n\"\"\"\nclass module_handler\n{\npublic:\n PyObject* convert_to_module(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyModule_Check(py_obj))\n handle_conversion_error(py_obj,\"module\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n \n PyObject* py_to_module(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyModule_Check(py_obj))\n handle_bad_type(py_obj,\"module\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n};\n\nmodule_handler x__module_handler = module_handler();\n#define convert_to_module(py_obj,name) x__module_handler.convert_to_module(py_obj,name)\n#define py_to_module(py_obj,name) x__module_handler.py_to_module(py_obj,name)\n\nPyObject* module_to_py(PyObject* module)\n{\n // Don't think I need to do anything...\n return (PyObject*) module;\n}\n\n\"\"\"\n\n#############################################################\n# Scalar conversion code\n#############################################################\n\n# These non-templated version is now used for most scalar conversions.\nscalar_support_code = \\\n\"\"\"\n\nclass scalar_handler\n{\npublic: \n int convert_to_int(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyInt_Check(py_obj))\n handle_conversion_error(py_obj,\"int\", name);\n return (int) PyInt_AsLong(py_obj);\n }\n long convert_to_long(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyLong_Check(py_obj))\n handle_conversion_error(py_obj,\"long\", name);\n return (long) PyLong_AsLong(py_obj);\n }\n\n double convert_to_float(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyFloat_Check(py_obj))\n handle_conversion_error(py_obj,\"float\", name);\n return PyFloat_AsDouble(py_obj);\n }\n\n std::complex convert_to_complex(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_conversion_error(py_obj,\"complex\", name);\n return std::complex(PyComplex_RealAsDouble(py_obj),\n PyComplex_ImagAsDouble(py_obj)); \n }\n\n int py_to_int(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyInt_Check(py_obj))\n handle_bad_type(py_obj,\"int\", name);\n return (int) PyInt_AsLong(py_obj);\n }\n \n long py_to_long(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyLong_Check(py_obj))\n handle_bad_type(py_obj,\"long\", name);\n return (long) PyLong_AsLong(py_obj);\n }\n \n double py_to_float(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyFloat_Check(py_obj))\n handle_bad_type(py_obj,\"float\", name);\n return PyFloat_AsDouble(py_obj);\n }\n \n std::complex py_to_complex(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_bad_type(py_obj,\"complex\", name);\n return std::complex(PyComplex_RealAsDouble(py_obj),\n PyComplex_ImagAsDouble(py_obj)); \n }\n\n};\n\nscalar_handler x__scalar_handler = scalar_handler();\n#define convert_to_int(py_obj,name) x__scalar_handler.convert_to_int(py_obj,name)\n#define py_to_int(py_obj,name) x__scalar_handler.py_to_int(py_obj,name)\n\n#define convert_to_long(py_obj,name) x__scalar_handler.convert_to_long(py_obj,name)\n#define py_to_long(py_obj,name) x__scalar_handler.py_to_long(py_obj,name)\n\n#define convert_to_float(py_obj,name) x__scalar_handler.convert_to_float(py_obj,name)\n#define py_to_float(py_obj,name) x__scalar_handler.py_to_float(py_obj,name)\n\n#define convert_to_complex(py_obj,name) x__scalar_handler.convert_to_complex(py_obj,name)\n#define py_to_complex(py_obj,name) x__scalar_handler.py_to_complex(py_obj,name)\n\n\"\"\" \n\n", "source_code_before": "\"\"\" C/C++ code strings needed for converting most non-sequence\n Python variables:\n module_support_code -- several routines used by most other code \n conversion methods. It holds the only\n CXX dependent code in this file. The CXX\n stuff is used for exceptions\n file_convert_code\n instance_convert_code\n callable_convert_code\n module_convert_code\n \n scalar_convert_code\n non_template_scalar_support_code \n Scalar conversion covers int, float, double, complex,\n and double complex. While Python doesn't support all these,\n Numeric does and so all of them are made available.\n Python longs are currently converted to C ints. Any\n better way to handle this?\n\"\"\"\n\nimport base_info\n\n#############################################################\n# Basic module support code\n#############################################################\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\n#############################################################\n# File conversion support code\n#############################################################\n\nfile_convert_code = \\\n\"\"\"\n\nclass file_handler\n{\npublic:\n FILE* convert_to_file(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyFile_Check(py_obj))\n handle_conversion_error(py_obj,\"file\", name);\n \n // Cleanup code should call DECREF\n Py_INCREF(py_obj);\n return PyFile_AsFile(py_obj);\n }\n \n FILE* py_to_file(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyFile_Check(py_obj))\n handle_bad_type(py_obj,\"file\", name);\n \n // Cleanup code should call DECREF\n Py_INCREF(py_obj);\n return PyFile_AsFile(py_obj);\n }\n};\n\nfile_handler x__file_handler = file_handler();\n#define convert_to_file(py_obj,name) x__file_handler.convert_to_file(py_obj,name)\n#define py_to_file(py_obj,name) x__file_handler.py_to_file(py_obj,name)\n\nPyObject* 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\"\"\"\n\n\n#############################################################\n# Instance conversion code\n#############################################################\n\ninstance_convert_code = \\\n\"\"\"\n\nclass instance_handler\n{\npublic:\n PyObject* convert_to_instance(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyFile_Check(py_obj))\n handle_conversion_error(py_obj,\"instance\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n \n PyObject* py_to_instance(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyFile_Check(py_obj))\n handle_bad_type(py_obj,\"instance\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n};\n\ninstance_handler x__instance_handler = instance_handler();\n#define convert_to_instance(py_obj,name) x__instance_handler.convert_to_instance(py_obj,name)\n#define py_to_instance(py_obj,name) x__instance_handler.py_to_instance(py_obj,name)\n\nPyObject* instance_to_py(PyObject* instance)\n{\n // Don't think I need to do anything...\n return (PyObject*) instance;\n}\n\n\"\"\"\n\n#############################################################\n# Callable conversion code\n#############################################################\n\ncallable_convert_code = \\\n\"\"\"\n\nclass callable_handler\n{\npublic: \n PyObject* convert_to_callable(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyCallable_Check(py_obj))\n handle_conversion_error(py_obj,\"callable\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n \n PyObject* py_to_callable(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyCallable_Check(py_obj))\n handle_bad_type(py_obj,\"callable\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n};\n\ncallable_handler x__callable_handler = callable_handler();\n#define convert_to_callable(py_obj,name) x__callable_handler.convert_to_callable(py_obj,name)\n#define py_to_callable(py_obj,name) x__callable_handler.py_to_callable(py_obj,name)\n\nPyObject* callable_to_py(PyObject* callable)\n{\n // Don't think I need to do anything...\n return (PyObject*) callable;\n}\n\n\"\"\"\n\n#############################################################\n# Module conversion code\n#############################################################\n\nmodule_convert_code = \\\n\"\"\"\nclass module_handler\n{\npublic:\n PyObject* convert_to_module(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyModule_Check(py_obj))\n handle_conversion_error(py_obj,\"module\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n \n PyObject* py_to_module(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyModule_Check(py_obj))\n handle_bad_type(py_obj,\"module\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n};\n\nmodule_handler x__module_handler = module_handler();\n#define convert_to_module(py_obj,name) x__module_handler.convert_to_module(py_obj,name)\n#define py_to_module(py_obj,name) x__module_handler.py_to_module(py_obj,name)\n\nPyObject* module_to_py(PyObject* module)\n{\n // Don't think I need to do anything...\n return (PyObject*) module;\n}\n\n\"\"\"\n\n#############################################################\n# Scalar conversion code\n#############################################################\n\n# These non-templated version is now used for most scalar conversions.\nnon_template_scalar_support_code = \\\n\"\"\"\n\nclass scalar_handler\n{\npublic: \n int convert_to_int(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyInt_Check(py_obj))\n handle_conversion_error(py_obj,\"int\", name);\n return (int) PyInt_AsLong(py_obj);\n }\n long convert_to_long(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyLong_Check(py_obj))\n handle_conversion_error(py_obj,\"long\", name);\n return (long) PyLong_AsLong(py_obj);\n }\n\n double convert_to_float(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyFloat_Check(py_obj))\n handle_conversion_error(py_obj,\"float\", name);\n return PyFloat_AsDouble(py_obj);\n }\n\n std::complex convert_to_complex(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_conversion_error(py_obj,\"complex\", name);\n return std::complex(PyComplex_RealAsDouble(py_obj),\n PyComplex_ImagAsDouble(py_obj)); \n }\n\n int py_to_int(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyInt_Check(py_obj))\n handle_bad_type(py_obj,\"int\", name);\n return (int) PyInt_AsLong(py_obj);\n }\n \n long py_to_long(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyLong_Check(py_obj))\n handle_bad_type(py_obj,\"long\", name);\n return (long) PyLong_AsLong(py_obj);\n }\n \n double py_to_float(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyFloat_Check(py_obj))\n handle_bad_type(py_obj,\"float\", name);\n return PyFloat_AsDouble(py_obj);\n }\n \n std::complex py_to_complex(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_bad_type(py_obj,\"complex\", name);\n return std::complex(PyComplex_RealAsDouble(py_obj),\n PyComplex_ImagAsDouble(py_obj)); \n }\n\n};\n\nscalar_handler x__scalar_handler = scalar_handler();\n#define convert_to_int(py_obj,name) x__scalar_handler.convert_to_int(py_obj,name)\n#define py_to_int(py_obj,name) x__scalar_handler.py_to_int(py_obj,name)\n\n#define convert_to_long(py_obj,name) x__scalar_handler.convert_to_long(py_obj,name)\n#define py_to_long(py_obj,name) x__scalar_handler.py_to_long(py_obj,name)\n\n#define convert_to_float(py_obj,name) x__scalar_handler.convert_to_float(py_obj,name)\n#define py_to_float(py_obj,name) x__scalar_handler.py_to_float(py_obj,name)\n\n#define convert_to_complex(py_obj,name) x__scalar_handler.convert_to_complex(py_obj,name)\n#define py_to_complex(py_obj,name) x__scalar_handler.py_to_complex(py_obj,name)\n\n\"\"\" \n\n# this code will not build with msvc...\n# This is only used for blitz stuff now. The non-templated\n# version, defined further down, is now used for most code.\nscalar_support_code = \\\n\"\"\"\n// conversion routines\n\ntemplate \nstatic T convert_to_scalar(PyObject* py_obj,const char* name)\n{\n //never used.\n return (T) 0;\n}\ntemplate<>\nstatic int convert_to_scalar(PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyInt_Check(py_obj))\n handle_conversion_error(py_obj,\"int\", name);\n return (int) PyInt_AsLong(py_obj);\n}\n\ntemplate<>\nstatic long convert_to_scalar(PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyLong_Check(py_obj))\n handle_conversion_error(py_obj,\"long\", name);\n return (long) PyLong_AsLong(py_obj);\n}\n\ntemplate<> \nstatic double convert_to_scalar(PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyFloat_Check(py_obj))\n handle_conversion_error(py_obj,\"float\", name);\n return PyFloat_AsDouble(py_obj);\n}\n\ntemplate<> \nstatic float convert_to_scalar(PyObject* py_obj,const char* name)\n{\n return (float) convert_to_scalar(py_obj,name);\n}\n\n// complex not checked.\ntemplate<> \nstatic std::complex convert_to_scalar >(PyObject* py_obj,\n const char* name)\n{\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_conversion_error(py_obj,\"complex\", name);\n return std::complex((float) PyComplex_RealAsDouble(py_obj),\n (float) PyComplex_ImagAsDouble(py_obj)); \n}\ntemplate<> \nstatic std::complex convert_to_scalar >(\n PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_conversion_error(py_obj,\"complex\", name);\n return std::complex(PyComplex_RealAsDouble(py_obj),\n PyComplex_ImagAsDouble(py_obj)); \n}\n\n/////////////////////////////////\n// standard translation routines\n\ntemplate \nstatic T py_to_scalar(PyObject* py_obj,const char* name)\n{\n //never used.\n return (T) 0;\n}\ntemplate<>\nstatic int py_to_scalar(PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyInt_Check(py_obj))\n handle_bad_type(py_obj,\"int\", name);\n return (int) PyInt_AsLong(py_obj);\n}\n\ntemplate<>\nstatic long py_to_scalar(PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyLong_Check(py_obj))\n handle_bad_type(py_obj,\"long\", name);\n return (long) PyLong_AsLong(py_obj);\n}\n\ntemplate<> \nstatic double py_to_scalar(PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyFloat_Check(py_obj))\n handle_bad_type(py_obj,\"float\", name);\n return PyFloat_AsDouble(py_obj);\n}\n\ntemplate<> \nstatic float py_to_scalar(PyObject* py_obj,const char* name)\n{\n return (float) py_to_scalar(py_obj,name);\n}\n\n// complex not checked.\ntemplate<> \nstatic std::complex py_to_scalar >(PyObject* py_obj,\n const char* name)\n{\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_bad_type(py_obj,\"complex\", name);\n return std::complex((float) PyComplex_RealAsDouble(py_obj),\n (float) PyComplex_ImagAsDouble(py_obj)); \n}\ntemplate<> \nstatic std::complex py_to_scalar >(\n PyObject* py_obj,const char* name)\n{\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_bad_type(py_obj,\"complex\", name);\n return std::complex(PyComplex_RealAsDouble(py_obj),\n PyComplex_ImagAsDouble(py_obj)); \n}\n\"\"\" \n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 303, "complexity": 0, "token_count": 27, "diff_parsed": { "added": [ "scalar_support_code = \\" ], "deleted": [ "non_template_scalar_support_code = \\", "# this code will not build with msvc...", "# This is only used for blitz stuff now. The non-templated", "# version, defined further down, is now used for most code.", "scalar_support_code = \\", "\"\"\"", "// conversion routines", "", "template", "static T convert_to_scalar(PyObject* py_obj,const char* name)", "{", " //never used.", " return (T) 0;", "}", "template<>", "static int convert_to_scalar(PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyInt_Check(py_obj))", " handle_conversion_error(py_obj,\"int\", name);", " return (int) PyInt_AsLong(py_obj);", "}", "", "template<>", "static long convert_to_scalar(PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyLong_Check(py_obj))", " handle_conversion_error(py_obj,\"long\", name);", " return (long) PyLong_AsLong(py_obj);", "}", "", "template<>", "static double convert_to_scalar(PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyFloat_Check(py_obj))", " handle_conversion_error(py_obj,\"float\", name);", " return PyFloat_AsDouble(py_obj);", "}", "", "template<>", "static float convert_to_scalar(PyObject* py_obj,const char* name)", "{", " return (float) convert_to_scalar(py_obj,name);", "}", "", "// complex not checked.", "template<>", "static std::complex convert_to_scalar >(PyObject* py_obj,", " const char* name)", "{", " if (!py_obj || !PyComplex_Check(py_obj))", " handle_conversion_error(py_obj,\"complex\", name);", " return std::complex((float) PyComplex_RealAsDouble(py_obj),", " (float) PyComplex_ImagAsDouble(py_obj));", "}", "template<>", "static std::complex convert_to_scalar >(", " PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyComplex_Check(py_obj))", " handle_conversion_error(py_obj,\"complex\", name);", " return std::complex(PyComplex_RealAsDouble(py_obj),", " PyComplex_ImagAsDouble(py_obj));", "}", "", "/////////////////////////////////", "// standard translation routines", "", "template", "static T py_to_scalar(PyObject* py_obj,const char* name)", "{", " //never used.", " return (T) 0;", "}", "template<>", "static int py_to_scalar(PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyInt_Check(py_obj))", " handle_bad_type(py_obj,\"int\", name);", " return (int) PyInt_AsLong(py_obj);", "}", "", "template<>", "static long py_to_scalar(PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyLong_Check(py_obj))", " handle_bad_type(py_obj,\"long\", name);", " return (long) PyLong_AsLong(py_obj);", "}", "", "template<>", "static double py_to_scalar(PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyFloat_Check(py_obj))", " handle_bad_type(py_obj,\"float\", name);", " return PyFloat_AsDouble(py_obj);", "}", "", "template<>", "static float py_to_scalar(PyObject* py_obj,const char* name)", "{", " return (float) py_to_scalar(py_obj,name);", "}", "", "// complex not checked.", "template<>", "static std::complex py_to_scalar >(PyObject* py_obj,", " const char* name)", "{", " if (!py_obj || !PyComplex_Check(py_obj))", " handle_bad_type(py_obj,\"complex\", name);", " return std::complex((float) PyComplex_RealAsDouble(py_obj),", " (float) PyComplex_ImagAsDouble(py_obj));", "}", "template<>", "static std::complex py_to_scalar >(", " PyObject* py_obj,const char* name)", "{", " if (!py_obj || !PyComplex_Check(py_obj))", " handle_bad_type(py_obj,\"complex\", name);", " return std::complex(PyComplex_RealAsDouble(py_obj),", " PyComplex_ImagAsDouble(py_obj));", "}", "\"\"\"" ] } }, { "old_path": "weave/examples/cast_copy_transpose.py", "new_path": "weave/examples/cast_copy_transpose.py", "filename": "cast_copy_transpose.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -52,8 +52,23 @@ def _inplace_transpose(a_2d):\n } \n \"\"\" % numeric_type\n inline_tools.inline(code,['a_2d'],\n+ type_factories = blitz_type_factories,\n+ compiler='gcc',def _cast_copy_transpose(type,a_2d):\n+ assert(len(shape(a_2d)) == 2)\n+ new_array = zeros(shape(a_2d),type)\n+ #trans_a_2d = transpose(a_2d)\n+ numeric_type = scalar_spec.numeric_to_blitz_type_mapping[type]\n+ code = \"\"\"\n+ for(int i = 0; i < _Na_2d[0]; i++)\n+ for(int j = 0; j < _Na_2d[1]; j++)\n+ new_array(i,j) = (%s) a_2d(j,i);\n+ \"\"\" % numeric_type\n+ inline_tools.inline(code,['new_array','a_2d'],\n type_factories = blitz_type_factories,\n compiler='gcc',\n+ verbose = 1)\n+ return new_array\n+\n verbose = 1)\n return a_2d\n \n", "added_lines": 15, "deleted_lines": 0, "source_code": "\"\"\" Cast Copy Tranpose is used in Numeric's LinearAlgebra.py to convert\n C ordered arrays to Fortran order arrays before calling Fortran\n functions. A couple of C implementations are provided here that \n show modest speed improvements. One is an \"inplace\" transpose that\n does an in memory transpose of an arrays elements. This is the\n fastest approach and is beneficial if you don't need to keep the\n original array. \n\"\"\"\n# C:\\home\\ej\\wrk\\scipy\\compiler\\examples>python cast_copy_transpose.py\n# Cast/Copy/Transposing (150,150)array 1 times\n# speed in python: 0.870999932289\n# speed in c: 0.25\n# speed up: 3.48\n# inplace transpose c: 0.129999995232\n# speed up: 6.70\n\nimport Numeric\nfrom Numeric import *\nimport sys\nsys.path.insert(0,'..')\nimport inline_tools\nimport scalar_spec\nfrom blitz_tools import blitz_type_factories\n\ndef _cast_copy_transpose(type,a_2d):\n assert(len(shape(a_2d)) == 2)\n new_array = zeros(shape(a_2d),type)\n #trans_a_2d = transpose(a_2d)\n numeric_type = scalar_spec.numeric_to_blitz_type_mapping[type]\n code = \"\"\"\n for(int i = 0; i < _Na_2d[0]; i++)\n for(int j = 0; j < _Na_2d[1]; j++)\n new_array(i,j) = (%s) a_2d(j,i);\n \"\"\" % numeric_type\n inline_tools.inline(code,['new_array','a_2d'],\n type_factories = blitz_type_factories,\n compiler='gcc',\n verbose = 1)\n return new_array\n\ndef _inplace_transpose(a_2d):\n assert(len(shape(a_2d)) == 2)\n numeric_type = scalar_spec.numeric_to_blitz_type_mapping[a_2d.typecode()]\n code = \"\"\"\n %s temp;\n for(int i = 0; i < _Na_2d[0]; i++)\n for(int j = 0; j < _Na_2d[1]; j++)\n {\n temp = a_2d(i,j);\n a_2d(i,j) = a_2d(j,i);\n a_2d(j,i) = temp;\n } \n \"\"\" % numeric_type\n inline_tools.inline(code,['a_2d'],\n type_factories = blitz_type_factories,\n compiler='gcc',def _cast_copy_transpose(type,a_2d):\n assert(len(shape(a_2d)) == 2)\n new_array = zeros(shape(a_2d),type)\n #trans_a_2d = transpose(a_2d)\n numeric_type = scalar_spec.numeric_to_blitz_type_mapping[type]\n code = \"\"\"\n for(int i = 0; i < _Na_2d[0]; i++)\n for(int j = 0; j < _Na_2d[1]; j++)\n new_array(i,j) = (%s) a_2d(j,i);\n \"\"\" % numeric_type\n inline_tools.inline(code,['new_array','a_2d'],\n type_factories = blitz_type_factories,\n compiler='gcc',\n verbose = 1)\n return new_array\n\n verbose = 1)\n return a_2d\n\ndef cast_copy_transpose(type,*arrays):\n results = []\n for a in arrays:\n results.append(_cast_copy_transpose(type,a))\n if len(results) == 1:\n return results[0]\n else:\n return results\n\ndef inplace_cast_copy_transpose(*arrays):\n results = []\n for a in arrays:\n results.append(_inplace_transpose(a))\n if len(results) == 1:\n return results[0]\n else:\n return results\n\ndef _castCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.typecode() == type:\n cast_arrays = cast_arrays + (copy.copy(Numeric.transpose(a)),)\n else:\n cast_arrays = cast_arrays + (copy.copy(\n Numeric.transpose(a).astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\nimport time\n\n\ndef compare(m,n):\n a = ones((n,n),Float64)\n type = Float32\n print 'Cast/Copy/Transposing (%d,%d)array %d times' % (n,n,m)\n t1 = time.time()\n for i in range(m):\n for i in range(n):\n b = _castCopyAndTranspose(type,a)\n t2 = time.time()\n py = (t2-t1)\n print ' speed in python:', (t2 - t1)/m\n \n\n # load into cache \n b = cast_copy_transpose(type,a)\n t1 = time.time()\n for i in range(m):\n for i in range(n):\n b = cast_copy_transpose(type,a)\n t2 = time.time()\n print ' speed in c:',(t2 - t1)/ m \n print ' speed up: %3.2f' % (py/(t2-t1))\n\n # inplace tranpose\n b = _inplace_transpose(a)\n t1 = time.time()\n for i in range(m):\n for i in range(n):\n b = _inplace_transpose(a)\n t2 = time.time()\n print ' inplace transpose c:',(t2 - t1)/ m \n print ' speed up: %3.2f' % (py/(t2-t1))\n \nif __name__ == \"__main__\":\n m,n = 1,150\n compare(m,n) \n", "source_code_before": "\"\"\" Cast Copy Tranpose is used in Numeric's LinearAlgebra.py to convert\n C ordered arrays to Fortran order arrays before calling Fortran\n functions. A couple of C implementations are provided here that \n show modest speed improvements. One is an \"inplace\" transpose that\n does an in memory transpose of an arrays elements. This is the\n fastest approach and is beneficial if you don't need to keep the\n original array. \n\"\"\"\n# C:\\home\\ej\\wrk\\scipy\\compiler\\examples>python cast_copy_transpose.py\n# Cast/Copy/Transposing (150,150)array 1 times\n# speed in python: 0.870999932289\n# speed in c: 0.25\n# speed up: 3.48\n# inplace transpose c: 0.129999995232\n# speed up: 6.70\n\nimport Numeric\nfrom Numeric import *\nimport sys\nsys.path.insert(0,'..')\nimport inline_tools\nimport scalar_spec\nfrom blitz_tools import blitz_type_factories\n\ndef _cast_copy_transpose(type,a_2d):\n assert(len(shape(a_2d)) == 2)\n new_array = zeros(shape(a_2d),type)\n #trans_a_2d = transpose(a_2d)\n numeric_type = scalar_spec.numeric_to_blitz_type_mapping[type]\n code = \"\"\"\n for(int i = 0; i < _Na_2d[0]; i++)\n for(int j = 0; j < _Na_2d[1]; j++)\n new_array(i,j) = (%s) a_2d(j,i);\n \"\"\" % numeric_type\n inline_tools.inline(code,['new_array','a_2d'],\n type_factories = blitz_type_factories,\n compiler='gcc',\n verbose = 1)\n return new_array\n\ndef _inplace_transpose(a_2d):\n assert(len(shape(a_2d)) == 2)\n numeric_type = scalar_spec.numeric_to_blitz_type_mapping[a_2d.typecode()]\n code = \"\"\"\n %s temp;\n for(int i = 0; i < _Na_2d[0]; i++)\n for(int j = 0; j < _Na_2d[1]; j++)\n {\n temp = a_2d(i,j);\n a_2d(i,j) = a_2d(j,i);\n a_2d(j,i) = temp;\n } \n \"\"\" % numeric_type\n inline_tools.inline(code,['a_2d'],\n type_factories = blitz_type_factories,\n compiler='gcc',\n verbose = 1)\n return a_2d\n\ndef cast_copy_transpose(type,*arrays):\n results = []\n for a in arrays:\n results.append(_cast_copy_transpose(type,a))\n if len(results) == 1:\n return results[0]\n else:\n return results\n\ndef inplace_cast_copy_transpose(*arrays):\n results = []\n for a in arrays:\n results.append(_inplace_transpose(a))\n if len(results) == 1:\n return results[0]\n else:\n return results\n\ndef _castCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.typecode() == type:\n cast_arrays = cast_arrays + (copy.copy(Numeric.transpose(a)),)\n else:\n cast_arrays = cast_arrays + (copy.copy(\n Numeric.transpose(a).astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\nimport time\n\n\ndef compare(m,n):\n a = ones((n,n),Float64)\n type = Float32\n print 'Cast/Copy/Transposing (%d,%d)array %d times' % (n,n,m)\n t1 = time.time()\n for i in range(m):\n for i in range(n):\n b = _castCopyAndTranspose(type,a)\n t2 = time.time()\n py = (t2-t1)\n print ' speed in python:', (t2 - t1)/m\n \n\n # load into cache \n b = cast_copy_transpose(type,a)\n t1 = time.time()\n for i in range(m):\n for i in range(n):\n b = cast_copy_transpose(type,a)\n t2 = time.time()\n print ' speed in c:',(t2 - t1)/ m \n print ' speed up: %3.2f' % (py/(t2-t1))\n\n # inplace tranpose\n b = _inplace_transpose(a)\n t1 = time.time()\n for i in range(m):\n for i in range(n):\n b = _inplace_transpose(a)\n t2 = time.time()\n print ' inplace transpose c:',(t2 - t1)/ m \n print ' speed up: %3.2f' % (py/(t2-t1))\n \nif __name__ == \"__main__\":\n m,n = 1,150\n compare(m,n) \n", "methods": [ { "name": "_cast_copy_transpose", "long_name": "_cast_copy_transpose( type , a_2d )", "filename": "cast_copy_transpose.py", "nloc": 14, "complexity": 1, "token_count": 69, "parameters": [ "type", "a_2d" ], "start_line": 25, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "_inplace_transpose._cast_copy_transpose", "long_name": "_inplace_transpose._cast_copy_transpose( type , a_2d )", "filename": "cast_copy_transpose.py", "nloc": 16, "complexity": 1, "token_count": 75, "parameters": [ "type", "a_2d" ], "start_line": 56, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 2 }, { "name": "cast_copy_transpose", "long_name": "cast_copy_transpose( type , * arrays )", "filename": "cast_copy_transpose.py", "nloc": 8, "complexity": 3, "token_count": 45, "parameters": [ "type", "arrays" ], "start_line": 75, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "inplace_cast_copy_transpose", "long_name": "inplace_cast_copy_transpose( * arrays )", "filename": "cast_copy_transpose.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "arrays" ], "start_line": 84, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_castCopyAndTranspose", "long_name": "_castCopyAndTranspose( type , * arrays )", "filename": "cast_copy_transpose.py", "nloc": 12, "complexity": 4, "token_count": 86, "parameters": [ "type", "arrays" ], "start_line": 93, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "compare", "long_name": "compare( m , n )", "filename": "cast_copy_transpose.py", "nloc": 27, "complexity": 7, "token_count": 219, "parameters": [ "m", "n" ], "start_line": 109, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 } ], "methods_before": [ { "name": "_cast_copy_transpose", "long_name": "_cast_copy_transpose( type , a_2d )", "filename": "cast_copy_transpose.py", "nloc": 14, "complexity": 1, "token_count": 69, "parameters": [ "type", "a_2d" ], "start_line": 25, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "_inplace_transpose", "long_name": "_inplace_transpose( a_2d )", "filename": "cast_copy_transpose.py", "nloc": 18, "complexity": 1, "token_count": 58, "parameters": [ "a_2d" ], "start_line": 41, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 0 }, { "name": "cast_copy_transpose", "long_name": "cast_copy_transpose( type , * arrays )", "filename": "cast_copy_transpose.py", "nloc": 8, "complexity": 3, "token_count": 45, "parameters": [ "type", "arrays" ], "start_line": 60, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "inplace_cast_copy_transpose", "long_name": "inplace_cast_copy_transpose( * arrays )", "filename": "cast_copy_transpose.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "arrays" ], "start_line": 69, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_castCopyAndTranspose", "long_name": "_castCopyAndTranspose( type , * arrays )", "filename": "cast_copy_transpose.py", "nloc": 12, "complexity": 4, "token_count": 86, "parameters": [ "type", "arrays" ], "start_line": 78, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "compare", "long_name": "compare( m , n )", "filename": "cast_copy_transpose.py", "nloc": 27, "complexity": 7, "token_count": 219, "parameters": [ "m", "n" ], "start_line": 94, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "_inplace_transpose._cast_copy_transpose", "long_name": "_inplace_transpose._cast_copy_transpose( type , a_2d )", "filename": "cast_copy_transpose.py", "nloc": 16, "complexity": 1, "token_count": 75, "parameters": [ "type", "a_2d" ], "start_line": 56, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 2 } ], "nloc": 119, "complexity": 19, "token_count": 641, "diff_parsed": { "added": [ " type_factories = blitz_type_factories,", " compiler='gcc',def _cast_copy_transpose(type,a_2d):", " assert(len(shape(a_2d)) == 2)", " new_array = zeros(shape(a_2d),type)", " #trans_a_2d = transpose(a_2d)", " numeric_type = scalar_spec.numeric_to_blitz_type_mapping[type]", " code = \"\"\"", " for(int i = 0; i < _Na_2d[0]; i++)", " for(int j = 0; j < _Na_2d[1]; j++)", " new_array(i,j) = (%s) a_2d(j,i);", " \"\"\" % numeric_type", " inline_tools.inline(code,['new_array','a_2d'],", " verbose = 1)", " return new_array", "" ], "deleted": [] } }, { "old_path": "weave/scalar_info.py", "new_path": "weave/scalar_info.py", "filename": "scalar_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -11,15 +11,17 @@\n import base_info\n \n from conversion_code import scalar_support_code\n-from conversion_code import non_template_scalar_support_code\n+#from conversion_code import non_template_scalar_support_code\n \n class scalar_info(base_info.base_info):\n _warnings = ['disable: 4275', 'disable: 4101']\n _headers = ['','']\n def support_code(self):\n- if self.compiler != 'msvc':\n- # maybe this should only be for gcc...\n- return [scalar_support_code,non_template_scalar_support_code]\n- else:\n- return [non_template_scalar_support_code]\n+ return [scalar_support_code]\n+ # REMOVED WHEN TEMPLATE CODE REMOVED\n+ #if self.compiler != 'msvc':\n+ # # maybe this should only be for gcc...\n+ # return [scalar_support_code,non_template_scalar_support_code]\n+ #else:\n+ # return [non_template_scalar_support_code]\n \n\\ No newline at end of file\n", "added_lines": 8, "deleted_lines": 6, "source_code": "\"\"\" support code and other things needed to compile support\n for numeric expressions in python.\n \n There are two sets of support code, one with templated\n functions and one without. This is because msvc cannot\n handle the templated functions. We need the templated\n versions for more complex support of numeric arrays with\n blitz. \n\"\"\"\n\nimport base_info\n\nfrom conversion_code import scalar_support_code\n#from conversion_code import non_template_scalar_support_code\n\nclass scalar_info(base_info.base_info):\n _warnings = ['disable: 4275', 'disable: 4101']\n _headers = ['','']\n def support_code(self):\n return [scalar_support_code]\n # REMOVED WHEN TEMPLATE CODE REMOVED\n #if self.compiler != 'msvc':\n # # maybe this should only be for gcc...\n # return [scalar_support_code,non_template_scalar_support_code]\n #else:\n # return [non_template_scalar_support_code]\n ", "source_code_before": "\"\"\" support code and other things needed to compile support\n for numeric expressions in python.\n \n There are two sets of support code, one with templated\n functions and one without. This is because msvc cannot\n handle the templated functions. We need the templated\n versions for more complex support of numeric arrays with\n blitz. \n\"\"\"\n\nimport base_info\n\nfrom conversion_code import scalar_support_code\nfrom conversion_code import non_template_scalar_support_code\n\nclass scalar_info(base_info.base_info):\n _warnings = ['disable: 4275', 'disable: 4101']\n _headers = ['','']\n def support_code(self):\n if self.compiler != 'msvc':\n # maybe this should only be for gcc...\n return [scalar_support_code,non_template_scalar_support_code]\n else:\n return [non_template_scalar_support_code]\n ", "methods": [ { "name": "support_code", "long_name": "support_code( self )", "filename": "scalar_info.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 19, "end_line": 20, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "support_code", "long_name": "support_code( self )", "filename": "scalar_info.py", "nloc": 5, "complexity": 2, "token_count": 24, "parameters": [ "self" ], "start_line": 19, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "support_code", "long_name": "support_code( self )", "filename": "scalar_info.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 19, "end_line": 20, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "nloc": 16, "complexity": 1, "token_count": 39, "diff_parsed": { "added": [ "#from conversion_code import non_template_scalar_support_code", " return [scalar_support_code]", " # REMOVED WHEN TEMPLATE CODE REMOVED", " #if self.compiler != 'msvc':", " # # maybe this should only be for gcc...", " # return [scalar_support_code,non_template_scalar_support_code]", " #else:", " # return [non_template_scalar_support_code]" ], "deleted": [ "from conversion_code import non_template_scalar_support_code", " if self.compiler != 'msvc':", " # maybe this should only be for gcc...", " return [scalar_support_code,non_template_scalar_support_code]", " else:", " return [non_template_scalar_support_code]" ] } }, { "old_path": "weave/scalar_spec.py", "new_path": "weave/scalar_spec.py", "filename": "scalar_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -38,28 +38,9 @@ def type_spec(self,name,value):\n new_spec.name = name\n new_spec.numeric_type = type(value)\n return new_spec\n- \n- def declaration_code(self,templatize = 0,inline=0):\n- #if self.compiler == 'msvc':\n- # return self.msvc_decl_code(templatize,inline)\n- #else:\n- # return self.template_decl_code(templatize,inline) \\\n- return self.msvc_decl_code(templatize,inline)\n-\n- def template_decl_code(self,template = 0,inline=0):\n- type = numeric_to_blitz_type_mapping[self.numeric_type]\n- name = self.name\n- var_name = self.retrieve_py_variable(inline)\n- template = '%(type)s %(name)s = '\\\n- 'convert_to_scalar<%(type)s >(%(var_name)s,\"%(name)s\");\\n'\n- code = template % locals()\n- return code\n- \n- def msvc_decl_code(self,template = 0,inline=0):\n- # doesn't support template = 1\n- if template:\n- ValueError, 'msvc compiler does not support templated scalar '\\\n- 'code. try mingw32 instead (www.mingw.org).'\n+ \n+ # BEGIN ADDED WHEN TEMPLATE SUPPORT REMOVED\n+ def declaration_code(self,inline=0):\n type = numeric_to_blitz_type_mapping[self.numeric_type]\n func_type = self.type_name\n name = self.name\n@@ -68,7 +49,41 @@ def msvc_decl_code(self,template = 0,inline=0):\n 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n+ # END ADDED WHEN TEMPLATE SUPPORT REMOVED\n+ \n+ # BEGIN OF THINGS REMOVED FOR TEMPLATES \n+ #def declaration_code(self,templatize = 0,inline=0):\n+ # #if self.compiler == 'msvc':\n+ # # return self.msvc_decl_code(templatize,inline)\n+ # #else:\n+ # # return self.template_decl_code(templatize,inline) \\\n+ # return self.msvc_decl_code(templatize,inline)\n \n+ # This is no longer used by anything except blitz code.\n+ #def template_decl_code(self,template = 0,inline=0):\n+ # type = numeric_to_blitz_type_mapping[self.numeric_type]\n+ # name = self.name\n+ # var_name = self.retrieve_py_variable(inline)\n+ # template = '%(type)s %(name)s = '\\\n+ # 'convert_to_scalar<%(type)s >(%(var_name)s,\"%(name)s\");\\n'\n+ # code = template % locals()\n+ # return code\n+ \n+ #def msvc_decl_code(self,template = 0,inline=0):\n+ # # doesn't support template = 1\n+ # if template:\n+ # ValueError, 'msvc compiler does not support templated scalar '\\\n+ # 'code. try mingw32 instead (www.mingw.org).'\n+ # type = numeric_to_blitz_type_mapping[self.numeric_type]\n+ # func_type = self.type_name\n+ # name = self.name\n+ # var_name = self.retrieve_py_variable(inline)\n+ # template = '%(type)s %(name)s = '\\\n+ # 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'\n+ # code = template % locals()\n+ # return code\n+ # END OF THINGS REMOVED FOR TEMPLATES\n+ \n #def c_function_declaration_code(self):\n # code = '%s &%s\" % \\\n # (numeric_to_blitz_type_mapping[self.numeric_type], self.name)\n", "added_lines": 37, "deleted_lines": 22, "source_code": "from base_spec import base_specification\nimport scalar_info\n#from Numeric import *\nfrom types import *\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\nnumeric_to_blitz_type_mapping = {}\n\nnumeric_to_blitz_type_mapping['T'] = 'T' # for templates\nnumeric_to_blitz_type_mapping['F'] = 'std::complex '\nnumeric_to_blitz_type_mapping['D'] = 'std::complex '\nnumeric_to_blitz_type_mapping['f'] = 'float'\nnumeric_to_blitz_type_mapping['d'] = 'double'\nnumeric_to_blitz_type_mapping['1'] = 'char'\nnumeric_to_blitz_type_mapping['b'] = 'unsigned char'\nnumeric_to_blitz_type_mapping['s'] = 'short'\nnumeric_to_blitz_type_mapping['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.\nnumeric_to_blitz_type_mapping['l'] = 'int'\n\n# standard Python numeric type mappings.\nnumeric_to_blitz_type_mapping[type(1)] = 'int'\nnumeric_to_blitz_type_mapping[type(1.)] = 'double'\nnumeric_to_blitz_type_mapping[type(1.+1.j)] = 'std::complex '\n#hmmm. The following is likely unsafe...\nnumeric_to_blitz_type_mapping[type(1L)] = 'int'\n\nclass scalar_specification(base_specification):\n _build_information = [scalar_info.scalar_info()] \n\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name\n new_spec.numeric_type = type(value)\n return new_spec\n \n # BEGIN ADDED WHEN TEMPLATE SUPPORT REMOVED\n def declaration_code(self,inline=0):\n type = numeric_to_blitz_type_mapping[self.numeric_type]\n func_type = self.type_name\n name = self.name\n var_name = self.retrieve_py_variable(inline)\n template = '%(type)s %(name)s = '\\\n 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n # END ADDED WHEN TEMPLATE SUPPORT REMOVED\n \n # BEGIN OF THINGS REMOVED FOR TEMPLATES \n #def declaration_code(self,templatize = 0,inline=0):\n # #if self.compiler == 'msvc':\n # # return self.msvc_decl_code(templatize,inline)\n # #else:\n # # return self.template_decl_code(templatize,inline) \\\n # return self.msvc_decl_code(templatize,inline)\n\n # This is no longer used by anything except blitz code.\n #def template_decl_code(self,template = 0,inline=0):\n # type = numeric_to_blitz_type_mapping[self.numeric_type]\n # name = self.name\n # var_name = self.retrieve_py_variable(inline)\n # template = '%(type)s %(name)s = '\\\n # 'convert_to_scalar<%(type)s >(%(var_name)s,\"%(name)s\");\\n'\n # code = template % locals()\n # return code\n \n #def msvc_decl_code(self,template = 0,inline=0):\n # # doesn't support template = 1\n # if template:\n # ValueError, 'msvc compiler does not support templated scalar '\\\n # 'code. try mingw32 instead (www.mingw.org).'\n # type = numeric_to_blitz_type_mapping[self.numeric_type]\n # func_type = self.type_name\n # name = self.name\n # var_name = self.retrieve_py_variable(inline)\n # template = '%(type)s %(name)s = '\\\n # 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'\n # code = template % locals()\n # return code\n # END OF THINGS REMOVED FOR TEMPLATES\n \n #def c_function_declaration_code(self):\n # code = '%s &%s\" % \\\n # (numeric_to_blitz_type_mapping[self.numeric_type], self.name)\n # return code\n\n def __repr__(self):\n msg = \"(%s:: name: %s, type: %s)\" % \\\n (self.type_name,self.name, self.numeric_type)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.__class__, other.__class__)\n\nclass int_specification(scalar_specification):\n type_name = 'int'\n def type_match(self,value):\n return type(value) in [IntType, LongType]\n \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Int(%s);\\n' % (self.name,self.name) \n return code\n \nclass float_specification(scalar_specification):\n type_name = 'float'\n def type_match(self,value):\n return type(value) in [FloatType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Float(%s);\\n' % (self.name,self.name) \n return code\n\nclass complex_specification(scalar_specification):\n type_name = 'complex'\n def type_match(self,value):\n return type(value) in [ComplexType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Complex(%s.real(),%s.imag());\\n' % \\\n (self.name,self.name,self.name) \n return code\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n ", "source_code_before": "from base_spec import base_specification\nimport scalar_info\n#from Numeric import *\nfrom types import *\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\nnumeric_to_blitz_type_mapping = {}\n\nnumeric_to_blitz_type_mapping['T'] = 'T' # for templates\nnumeric_to_blitz_type_mapping['F'] = 'std::complex '\nnumeric_to_blitz_type_mapping['D'] = 'std::complex '\nnumeric_to_blitz_type_mapping['f'] = 'float'\nnumeric_to_blitz_type_mapping['d'] = 'double'\nnumeric_to_blitz_type_mapping['1'] = 'char'\nnumeric_to_blitz_type_mapping['b'] = 'unsigned char'\nnumeric_to_blitz_type_mapping['s'] = 'short'\nnumeric_to_blitz_type_mapping['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.\nnumeric_to_blitz_type_mapping['l'] = 'int'\n\n# standard Python numeric type mappings.\nnumeric_to_blitz_type_mapping[type(1)] = 'int'\nnumeric_to_blitz_type_mapping[type(1.)] = 'double'\nnumeric_to_blitz_type_mapping[type(1.+1.j)] = 'std::complex '\n#hmmm. The following is likely unsafe...\nnumeric_to_blitz_type_mapping[type(1L)] = 'int'\n\nclass scalar_specification(base_specification):\n _build_information = [scalar_info.scalar_info()] \n\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name\n new_spec.numeric_type = type(value)\n return new_spec\n \n def declaration_code(self,templatize = 0,inline=0):\n #if self.compiler == 'msvc':\n # return self.msvc_decl_code(templatize,inline)\n #else:\n # return self.template_decl_code(templatize,inline) \\\n return self.msvc_decl_code(templatize,inline)\n\n def template_decl_code(self,template = 0,inline=0):\n type = numeric_to_blitz_type_mapping[self.numeric_type]\n name = self.name\n var_name = self.retrieve_py_variable(inline)\n template = '%(type)s %(name)s = '\\\n 'convert_to_scalar<%(type)s >(%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n \n def msvc_decl_code(self,template = 0,inline=0):\n # doesn't support template = 1\n if template:\n ValueError, 'msvc compiler does not support templated scalar '\\\n 'code. try mingw32 instead (www.mingw.org).'\n type = numeric_to_blitz_type_mapping[self.numeric_type]\n func_type = self.type_name\n name = self.name\n var_name = self.retrieve_py_variable(inline)\n template = '%(type)s %(name)s = '\\\n 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n\n #def c_function_declaration_code(self):\n # code = '%s &%s\" % \\\n # (numeric_to_blitz_type_mapping[self.numeric_type], self.name)\n # return code\n\n def __repr__(self):\n msg = \"(%s:: name: %s, type: %s)\" % \\\n (self.type_name,self.name, self.numeric_type)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.__class__, other.__class__)\n\nclass int_specification(scalar_specification):\n type_name = 'int'\n def type_match(self,value):\n return type(value) in [IntType, LongType]\n \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Int(%s);\\n' % (self.name,self.name) \n return code\n \nclass float_specification(scalar_specification):\n type_name = 'float'\n def type_match(self,value):\n return type(value) in [FloatType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Float(%s);\\n' % (self.name,self.name) \n return code\n\nclass complex_specification(scalar_specification):\n type_name = 'complex'\n def type_match(self,value):\n return type(value) in [ComplexType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Complex(%s.real(),%s.imag());\\n' % \\\n (self.name,self.name,self.name) \n return code\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n ", "methods": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self", "name", "value" ], "start_line": 35, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , inline = 0 )", "filename": "scalar_spec.py", "nloc": 9, "complexity": 1, "token_count": 49, "parameters": [ "self", "inline" ], "start_line": 43, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 92, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 3, "token_count": 42, "parameters": [ "self", "other" ], "start_line": 96, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "value" ], "start_line": 104, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "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": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_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": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 115, "end_line": 117, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 121, "end_line": 122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 123, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 128, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 132, "end_line": 134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self", "name", "value" ], "start_line": 35, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "template_decl_code", "long_name": "template_decl_code( self , template = 0 , inline = 0 )", "filename": "scalar_spec.py", "nloc": 8, "complexity": 1, "token_count": 48, "parameters": [ "self", "template", "inline" ], "start_line": 49, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "msvc_decl_code", "long_name": "msvc_decl_code( self , template = 0 , inline = 0 )", "filename": "scalar_spec.py", "nloc": 12, "complexity": 2, "token_count": 61, "parameters": [ "self", "template", "inline" ], "start_line": 58, "end_line": 70, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 77, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 3, "token_count": 42, "parameters": [ "self", "other" ], "start_line": 81, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "value" ], "start_line": 89, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 92, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 98, "end_line": 99, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 100, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 106, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 108, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 113, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 117, "end_line": 119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "declaration_code", "long_name": "declaration_code( self , inline = 0 )", "filename": "scalar_spec.py", "nloc": 9, "complexity": 1, "token_count": 49, "parameters": [ "self", "inline" ], "start_line": 43, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "msvc_decl_code", "long_name": "msvc_decl_code( self , template = 0 , inline = 0 )", "filename": "scalar_spec.py", "nloc": 12, "complexity": 2, "token_count": 61, "parameters": [ "self", "template", "inline" ], "start_line": 58, "end_line": 70, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "template_decl_code", "long_name": "template_decl_code( self , template = 0 , inline = 0 )", "filename": "scalar_spec.py", "nloc": 8, "complexity": 1, "token_count": 48, "parameters": [ "self", "template", "inline" ], "start_line": 49, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 } ], "nloc": 70, "complexity": 14, "token_count": 461, "diff_parsed": { "added": [ "", " # BEGIN ADDED WHEN TEMPLATE SUPPORT REMOVED", " def declaration_code(self,inline=0):", " # END ADDED WHEN TEMPLATE SUPPORT REMOVED", "", " # BEGIN OF THINGS REMOVED FOR TEMPLATES", " #def declaration_code(self,templatize = 0,inline=0):", " # #if self.compiler == 'msvc':", " # # return self.msvc_decl_code(templatize,inline)", " # #else:", " # # return self.template_decl_code(templatize,inline) \\", " # return self.msvc_decl_code(templatize,inline)", " # This is no longer used by anything except blitz code.", " #def template_decl_code(self,template = 0,inline=0):", " # type = numeric_to_blitz_type_mapping[self.numeric_type]", " # name = self.name", " # var_name = self.retrieve_py_variable(inline)", " # template = '%(type)s %(name)s = '\\", " # 'convert_to_scalar<%(type)s >(%(var_name)s,\"%(name)s\");\\n'", " # code = template % locals()", " # return code", "", " #def msvc_decl_code(self,template = 0,inline=0):", " # # doesn't support template = 1", " # if template:", " # ValueError, 'msvc compiler does not support templated scalar '\\", " # 'code. try mingw32 instead (www.mingw.org).'", " # type = numeric_to_blitz_type_mapping[self.numeric_type]", " # func_type = self.type_name", " # name = self.name", " # var_name = self.retrieve_py_variable(inline)", " # template = '%(type)s %(name)s = '\\", " # 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'", " # code = template % locals()", " # return code", " # END OF THINGS REMOVED FOR TEMPLATES", "" ], "deleted": [ "", " def declaration_code(self,templatize = 0,inline=0):", " #if self.compiler == 'msvc':", " # return self.msvc_decl_code(templatize,inline)", " #else:", " # return self.template_decl_code(templatize,inline) \\", " return self.msvc_decl_code(templatize,inline)", "", " def template_decl_code(self,template = 0,inline=0):", " type = numeric_to_blitz_type_mapping[self.numeric_type]", " name = self.name", " var_name = self.retrieve_py_variable(inline)", " template = '%(type)s %(name)s = '\\", " 'convert_to_scalar<%(type)s >(%(var_name)s,\"%(name)s\");\\n'", " code = template % locals()", " return code", "", " def msvc_decl_code(self,template = 0,inline=0):", " # doesn't support template = 1", " if template:", " ValueError, 'msvc compiler does not support templated scalar '\\", " 'code. try mingw32 instead (www.mingw.org).'" ] } } ] }, { "hash": "eb18cbf21d6e820fe289f4b7c8e66e1c2df3dee3", "msg": "added docs for get_version", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-02-13T10:25:36+00:00", "author_timezone": 0, "committer_date": "2002-02-13T10:25:36+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "45819f94a39fe9c46678c09db406eb36c38170ac" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 3, "insertions": 12, "lines": 15, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_distutils/misc_util.py", "new_path": "scipy_distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -35,9 +35,13 @@ def update_version(release_level='alpha',\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n- # is commited with old version information to CVS. To get\n- # __version__.py also up to date in CVS repository, \n- # a second commit of the __version__.py file is required.\n+ # is commited with the old version information. To get\n+ # __version__.py also up to date, a second commit of the\n+ # __version__.py file is required after you re-run\n+ # update_version(..). To summarize:\n+ # 1) cvs commit ...\n+ # 2) python setup.py # that should call update_version\n+ # 3) cvs commit -m \"updating version\" __version__.py\n \n release_level_map = {'alpha':0,\n 'beta':1,\n@@ -110,6 +114,11 @@ def get_version(release_level='alpha',\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n+ \"\"\"\n+ Return version string calculated from CVS/Entries file(s) starting\n+ at . Does not change /__version__.py.\n+ See also update_version(..) function.\n+ \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n", "added_lines": 12, "deleted_lines": 3, "source_code": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict():\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict() \n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n", "source_code_before": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with old version information to CVS. To get\n # __version__.py also up to date in CVS repository, \n # a second commit of the __version__.py file is required.\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict():\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict() \n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n", "methods": [ { "name": "update_version", "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", "filename": "misc_util.py", "nloc": 65, "complexity": 12, "token_count": 351, "parameters": [ "release_level", "path", "major", "overwrite_version_py" ], "start_line": 3, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 }, { "name": "get_version", "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", "filename": "misc_util.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "release_level", "path", "major" ], "start_line": 111, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_cvs_revision", "long_name": "get_cvs_revision( path )", "filename": "misc_util.py", "nloc": 21, "complexity": 10, "token_count": 190, "parameters": [ "path" ], "start_line": 127, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_path", "long_name": "get_path( mod_name )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 80, "parameters": [ "mod_name" ], "start_line": 156, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 174, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "add_grandparent_to_path", "long_name": "add_grandparent_to_path( mod_name )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "mod_name" ], "start_line": 179, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 184, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "append_package_dir_to_path", "long_name": "append_package_dir_to_path( package_name )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 64, "parameters": [ "package_name" ], "start_line": 187, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "get_package_config", "long_name": "get_package_config( package_name )", "filename": "misc_util.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "package_name" ], "start_line": 203, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "package_config", "long_name": "package_config( primary , dependencies = [ ] )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 53, "parameters": [ "primary", "dependencies" ], "start_line": 215, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [], "start_line": 234, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 61, "parameters": [ "config_list" ], "start_line": 240, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "methods_before": [ { "name": "update_version", "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", "filename": "misc_util.py", "nloc": 65, "complexity": 12, "token_count": 351, "parameters": [ "release_level", "path", "major", "overwrite_version_py" ], "start_line": 3, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 103, "top_nesting_level": 0 }, { "name": "get_version", "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", "filename": "misc_util.py", "nloc": 9, "complexity": 1, "token_count": 44, "parameters": [ "release_level", "path", "major" ], "start_line": 107, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "get_cvs_revision", "long_name": "get_cvs_revision( path )", "filename": "misc_util.py", "nloc": 21, "complexity": 10, "token_count": 190, "parameters": [ "path" ], "start_line": 118, "end_line": 145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_path", "long_name": "get_path( mod_name )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 80, "parameters": [ "mod_name" ], "start_line": 147, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 165, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "add_grandparent_to_path", "long_name": "add_grandparent_to_path( mod_name )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "mod_name" ], "start_line": 170, "end_line": 173, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 175, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "append_package_dir_to_path", "long_name": "append_package_dir_to_path( package_name )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 64, "parameters": [ "package_name" ], "start_line": 178, "end_line": 192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "get_package_config", "long_name": "get_package_config( package_name )", "filename": "misc_util.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "package_name" ], "start_line": 194, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "package_config", "long_name": "package_config( primary , dependencies = [ ] )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 53, "parameters": [ "primary", "dependencies" ], "start_line": 206, "end_line": 218, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [], "start_line": 225, "end_line": 229, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 61, "parameters": [ "config_list" ], "start_line": 231, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_version", "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", "filename": "misc_util.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "release_level", "path", "major" ], "start_line": 111, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "update_version", "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", "filename": "misc_util.py", "nloc": 65, "complexity": 12, "token_count": 351, "parameters": [ "release_level", "path", "major", "overwrite_version_py" ], "start_line": 3, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 } ], "nloc": 149, "complexity": 43, "token_count": 1011, "diff_parsed": { "added": [ " # is commited with the old version information. To get", " # __version__.py also up to date, a second commit of the", " # __version__.py file is required after you re-run", " # update_version(..). To summarize:", " # 1) cvs commit ...", " # 2) python setup.py # that should call update_version", " # 3) cvs commit -m \"updating version\" __version__.py", " \"\"\"", " Return version string calculated from CVS/Entries file(s) starting", " at . Does not change /__version__.py.", " See also update_version(..) function.", " \"\"\"" ], "deleted": [ " # is commited with old version information to CVS. To get", " # __version__.py also up to date in CVS repository,", " # a second commit of the __version__.py file is required." ] } } ] }, { "hash": "e0e4a3f3a2453af3043f6c29cefa49a1eb24e528", "msg": "impl. linking fortran libs only on demand", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-02-13T21:53:27+00:00", "author_timezone": 0, "committer_date": "2002-02-13T21:53:27+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "eb18cbf21d6e820fe289f4b7c8e66e1c2df3dee3" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 39, "insertions": 79, "lines": 118, "files": 3, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.5853658536585366, "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": "@@ -9,37 +9,33 @@\n from distutils.command.build_ext import build_ext as old_build_ext\n \n class build_ext (old_build_ext):\n- \n- def run (self):\n- if self.distribution.has_f_libraries():\n- build_flib = self.get_finalized_command('build_flib')\n- self.libraries.extend(build_flib.get_library_names() or [])\n- self.library_dirs.extend(build_flib.get_library_dirs() or [])\n- #self.library_dirs.extend(build_flib.get_library_dirs() or [])\n- #runtime_dirs = build_flib.get_runtime_library_dirs()\n- #self.runtime_library_dirs.extend(runtime_dirs or [])\n- \n- #?? what is this ??\n- self.library_dirs.append(build_flib.build_flib)\n- \n- old_build_ext.run(self)\n \n def build_extension(self, ext):\n # support for building static fortran libraries\n+ need_f_libs = 0\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n+ for lib_name in ext.libraries:\n+ if build_flib.has_f_library(lib_name):\n+ need_f_libs = 1\n+ break\n+ if need_f_libs:\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- # be sure to include fortran runtime library directory names\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 runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n linker_so = build_flib.fcompiler.get_linker_so()\n if linker_so is not None:\n self.compiler.linker_so = linker_so\n+\n # end of fortran source support\n return old_build_ext.build_extension(self,ext)\n \n", "added_lines": 11, "deleted_lines": 15, "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 *\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n # support for building static fortran libraries\n need_f_libs = 0\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n for lib_name in ext.libraries:\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n if need_f_libs:\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 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 runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n linker_so = build_flib.fcompiler.get_linker_so()\n if linker_so is not None:\n self.compiler.linker_so = linker_so\n\n # end of fortran source support\n return old_build_ext.build_extension(self,ext)\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", "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 *\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nclass build_ext (old_build_ext):\n \n def run (self):\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n self.libraries.extend(build_flib.get_library_names() or [])\n self.library_dirs.extend(build_flib.get_library_dirs() or [])\n #self.library_dirs.extend(build_flib.get_library_dirs() or [])\n #runtime_dirs = build_flib.get_runtime_library_dirs()\n #self.runtime_library_dirs.extend(runtime_dirs or [])\n \n #?? what is this ??\n self.library_dirs.append(build_flib.build_flib)\n \n old_build_ext.run(self)\n\n def build_extension(self, ext):\n # support for building static fortran libraries\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\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 # be sure to include fortran runtime library directory names\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n linker_so = build_flib.fcompiler.get_linker_so()\n if linker_so is not None:\n self.compiler.linker_so = linker_so\n # end of fortran source support\n return old_build_ext.build_extension(self,ext)\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", "methods": [ { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 25, "complexity": 10, "token_count": 178, "parameters": [ "self", "ext" ], "start_line": 13, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "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": 42, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 } ], "methods_before": [ { "name": "run", "long_name": "run( self )", "filename": "build_ext.py", "nloc": 7, "complexity": 4, "token_count": 68, "parameters": [ "self" ], "start_line": 13, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 15, "complexity": 6, "token_count": 107, "parameters": [ "self", "ext" ], "start_line": 27, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "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": 46, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "run", "long_name": "run( self )", "filename": "build_ext.py", "nloc": 7, "complexity": 4, "token_count": 68, "parameters": [ "self" ], "start_line": 13, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 25, "complexity": 10, "token_count": 178, "parameters": [ "self", "ext" ], "start_line": 13, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 1 } ], "nloc": 40, "complexity": 12, "token_count": 269, "diff_parsed": { "added": [ " need_f_libs = 0", " for lib_name in ext.libraries:", " if build_flib.has_f_library(lib_name):", " need_f_libs = 1", " break", " if need_f_libs:", " for lib_name in ext.libraries[:]:", " ext.libraries.extend(build_flib.get_library_names(lib_name))", " ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))", " ext.library_dirs.append(build_flib.build_flib)", "" ], "deleted": [ "", " def run (self):", " if self.distribution.has_f_libraries():", " build_flib = self.get_finalized_command('build_flib')", " self.libraries.extend(build_flib.get_library_names() or [])", " self.library_dirs.extend(build_flib.get_library_dirs() or [])", " #self.library_dirs.extend(build_flib.get_library_dirs() or [])", " #runtime_dirs = build_flib.get_runtime_library_dirs()", " #self.runtime_library_dirs.extend(runtime_dirs or [])", "", " #?? what is this ??", " self.library_dirs.append(build_flib.build_flib)", "", " old_build_ext.run(self)", " # be sure to include fortran runtime library directory names" ] } }, { "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": "@@ -145,40 +145,62 @@ def run (self):\n \n # run ()\n \n- def get_library_names(self):\n+ def has_f_library(self,name):\n+ if self.has_f_libraries():\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+ lib_names = []\n \n- for (lib_name, build_info) in self.fortran_libraries:\n- lib_names.append(lib_name)\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- \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 # get_library_names ()\n \n- def get_library_dirs(self):\n+ def get_library_dirs(self, name=None):\n if not self.has_f_libraries():\n- return []#None\n+ return []\n \n lib_dirs = [] \n \n- if self.fcompiler is not None:\n- lib_dirs.extend(self.fcompiler.get_library_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 []#None\n+ return []\n \n- lib_dirs = [] \n+ lib_dirs = []\n \n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_runtime_library_dirs())\n@@ -329,23 +351,28 @@ def build_library(self,library_name,source_list,module_dirs=None,\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,module_dirs,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- #self.create_static_lib(object_list,library_name,temp_dir) \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- self.create_static_lib(obj,library_name,temp_dir)\n+\n+ if os.name == 'nt':\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+ self.create_static_lib(obj,library_name,temp_dir)\n+ else:\n+ self.create_static_lib(object_list,library_name,temp_dir)\n \n def dummy_fortran_files(self):\n import tempfile \n", "added_lines": 51, "deleted_lines": 24, "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\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 Gnu\n VAST\n\"\"\"\n\nimport distutils\nimport distutils.dep_util, distutils.dir_util\nimport os,sys,string\nimport commands,re\nfrom types import *\nfrom distutils.command.build_clib import build_clib\nfrom distutils.errors import *\n\nclass FortranCompilerError (CCompilerError):\n \"\"\"Some compile/link operation failed.\"\"\"\nclass FortranCompileError (FortranCompilerError):\n \"\"\"Failure to compile one or more Fortran source files.\"\"\"\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 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 fc = find_fortran_compiler(self.fcompiler,\n self.fcompiler_exec,\n self.f90compiler_exec)\n if not fc:\n raise DistutilsOptionError, 'Fortran compiler not available: %s'%(self.fcompiler)\n else:\n self.announce(' using %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 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 # 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 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 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 self.announce(\" building '%s' library\" % lib_name)\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\n\nclass fortran_compiler_base:\n\n vendor = None\n ver_match = None\n \n def __init__(self):\n # Default initialization. Constructors of derived classes MUST\n # call this functions.\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,dirty_files,module_dirs=None, 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 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 + ' -c ' + source + ' -o ' + object \n print cmd\n failure = os.system(cmd)\n if failure:\n raise FortranCompileError, 'failure during compile' \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\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):\n lib_file = os.path.join(output_dir,'lib'+library_name+'.a')\n newer = distutils.dep_util.newer\n # This doesn't work -- no way to know if the file is in the archive\n #object_files = filter(lambda o,lib=lib_file:\\\n # distutils.dep_util.newer(o,lib),object_files)\n objects = string.join(object_files)\n if objects:\n cmd = 'ar -cur %s %s' % (lib_file,objects)\n print cmd\n os.system(cmd)\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,module_dirs,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':\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 self.create_static_lib(obj,library_name,temp_dir)\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 #print 'command:', self.ver_cmd\n exit_status, out_text = run_command(self.ver_cmd)\n #print exit_status, out_text\n if not exit_status:\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\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):\n fortran_compiler_base.__init__(self)\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\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\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 self.ver_cmd = self.f77_compiler + ' -V'\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 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 \n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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 = ' -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.libraries = ['fortran', 'ftn', 'm']\n self.library_dirs = self.find_lib_dir()\n\n self.ver_cmd = self.f77_compiler + ' -version'\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\n\nclass gnu_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Gnu'\n ver_match = r'g77 version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if sys.platform == 'win32':\n self.libraries = ['gcc','g2c']\n self.library_dirs = self.find_lib_directories()\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 switches = ' -Wall -fno-second-underscore '\n\n if os.name != 'nt':\n switches = switches + ' -fpic '\n\n self.f77_switches = switches\n\n self.ver_cmd = self.f77_compiler + ' -v '\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\n # it.\n if self.get_version():\n if self.version[0]=='3': # is g77 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 ' \n return opt\n \n def find_lib_directories(self):\n lib_dir = []\n match = r'Reading specs from (.*)/specs'\n\n # works I think only for unix... \n exit_status, out_text = run_command('g77 -v')\n if not exit_status:\n m = re.findall(match,out_text)\n if m:\n lib_dir= m #m[0] \n return lib_dir\n\n def get_linker_so(self):\n # win32 linking should be handled by standard linker\n if sys.platform != 'win32':\n return [self.f77_compiler,'-shared']\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, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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 for the Itanium\\(TM\\)-based applications, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n if fc is None:\n fc = 'efc'\n intel_ia32_fortran_compiler.__init__(self, fc, f90c)\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):\n fortran_compiler_base.__init__(self)\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\nclass vast_fortran_compiler(fortran_compiler_base):\n\n vendor = 'VAST'\n ver_match = r'\\s*Pacific-Sierra Research vf90 (Personal|Professional)\\s+(?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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\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):\n fortran_compiler_base.__init__(self)\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 -assume nozsize -math_library fast -tune host '\n return opt\n\n def get_linker_so(self):\n # XXX: is -shared needed?\n return [self.f77_compiler,'-shared']\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):\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)\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 vast_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\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 Gnu\n VAST\n\"\"\"\n\nimport distutils\nimport distutils.dep_util, distutils.dir_util\nimport os,sys,string\nimport commands,re\nfrom types import *\nfrom distutils.command.build_clib import build_clib\nfrom distutils.errors import *\n\nclass FortranCompilerError (CCompilerError):\n \"\"\"Some compile/link operation failed.\"\"\"\nclass FortranCompileError (FortranCompilerError):\n \"\"\"Failure to compile one or more Fortran source files.\"\"\"\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 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 fc = find_fortran_compiler(self.fcompiler,\n self.fcompiler_exec,\n self.f90compiler_exec)\n if not fc:\n raise DistutilsOptionError, 'Fortran compiler not available: %s'%(self.fcompiler)\n else:\n self.announce(' using %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 get_library_names(self):\n if not self.has_f_libraries():\n return None\n\n lib_names = [] \n\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 \n return lib_names\n\n # get_library_names ()\n\n def get_library_dirs(self):\n if not self.has_f_libraries():\n return []#None\n\n lib_dirs = [] \n\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_library_dirs())\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 []#None\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 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 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 self.announce(\" building '%s' library\" % lib_name)\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\n\nclass fortran_compiler_base:\n\n vendor = None\n ver_match = None\n \n def __init__(self):\n # Default initialization. Constructors of derived classes MUST\n # call this functions.\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,dirty_files,module_dirs=None, 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 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 + ' -c ' + source + ' -o ' + object \n print cmd\n failure = os.system(cmd)\n if failure:\n raise FortranCompileError, 'failure during compile' \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\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):\n lib_file = os.path.join(output_dir,'lib'+library_name+'.a')\n newer = distutils.dep_util.newer\n # This doesn't work -- no way to know if the file is in the archive\n #object_files = filter(lambda o,lib=lib_file:\\\n # distutils.dep_util.newer(o,lib),object_files)\n objects = string.join(object_files)\n if objects:\n cmd = 'ar -cur %s %s' % (lib_file,objects)\n print cmd\n os.system(cmd)\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 #this compiles the files\n object_list = self.to_object(source_list,module_dirs,temp_dir)\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 #self.create_static_lib(object_list,library_name,temp_dir) \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 self.create_static_lib(obj,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 #print 'command:', self.ver_cmd\n exit_status, out_text = run_command(self.ver_cmd)\n #print exit_status, out_text\n if not exit_status:\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\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):\n fortran_compiler_base.__init__(self)\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\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\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 self.ver_cmd = self.f77_compiler + ' -V'\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 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 \n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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 = ' -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.libraries = ['fortran', 'ftn', 'm']\n self.library_dirs = self.find_lib_dir()\n\n self.ver_cmd = self.f77_compiler + ' -version'\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\n\nclass gnu_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Gnu'\n ver_match = r'g77 version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if sys.platform == 'win32':\n self.libraries = ['gcc','g2c']\n self.library_dirs = self.find_lib_directories()\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 switches = ' -Wall -fno-second-underscore '\n\n if os.name != 'nt':\n switches = switches + ' -fpic '\n\n self.f77_switches = switches\n\n self.ver_cmd = self.f77_compiler + ' -v '\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\n # it.\n if self.get_version():\n if self.version[0]=='3': # is g77 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 ' \n return opt\n \n def find_lib_directories(self):\n lib_dir = []\n match = r'Reading specs from (.*)/specs'\n\n # works I think only for unix... \n exit_status, out_text = run_command('g77 -v')\n if not exit_status:\n m = re.findall(match,out_text)\n if m:\n lib_dir= m #m[0] \n return lib_dir\n\n def get_linker_so(self):\n # win32 linking should be handled by standard linker\n if sys.platform != 'win32':\n return [self.f77_compiler,'-shared']\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, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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 for the Itanium\\(TM\\)-based applications, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n if fc is None:\n fc = 'efc'\n intel_ia32_fortran_compiler.__init__(self, fc, f90c)\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):\n fortran_compiler_base.__init__(self)\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\nclass vast_fortran_compiler(fortran_compiler_base):\n\n vendor = 'VAST'\n ver_match = r'\\s*Pacific-Sierra Research vf90 (Personal|Professional)\\s+(?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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\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):\n fortran_compiler_base.__init__(self)\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 -assume nozsize -math_library fast -tune host '\n return opt\n\n def get_linker_so(self):\n # XXX: is -shared needed?\n return [self.f77_compiler,'-shared']\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):\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)\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 vast_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": 58, "end_line": 63, "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": 23, "parameters": [], "start_line": 67, "end_line": 71, "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": 101, "end_line": 113, "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": 17, "complexity": 3, "token_count": 104, "parameters": [ "self" ], "start_line": 117, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "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": 137, "end_line": 139, "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": 141, "end_line": 144, "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": 148, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "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": 154, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "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": 178, "end_line": 195, "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": 7, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 199, "end_line": 208, "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": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 212, "end_line": 220, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , fortran_libraries )", "filename": "build_flib.py", "nloc": 18, "complexity": 5, "token_count": 122, "parameters": [ "self", "fortran_libraries" ], "start_line": 222, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 88, "parameters": [ "self" ], "start_line": 255, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "to_object", "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 13, "complexity": 3, "token_count": 89, "parameters": [ "self", "dirty_files", "module_dirs", "temp_dir" ], "start_line": 278, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 292, "end_line": 297, "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": 299, "end_line": 302, "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": 15, "complexity": 4, "token_count": 103, "parameters": [ "self", "compiler", "switches", "source_files", "module_dirs", "temp_dir" ], "start_line": 304, "end_line": 318, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 322, "end_line": 325, "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": 327, "end_line": 330, "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": 333, "end_line": 334, "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 )", "filename": "build_flib.py", "nloc": 9, "complexity": 2, "token_count": 68, "parameters": [ "self", "object_files", "library_name", "output_dir", "debug" ], "start_line": 336, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "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": 13, "complexity": 3, "token_count": 104, "parameters": [ "self", "library_name", "source_list", "module_dirs", "temp_dir" ], "start_line": 349, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "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": 377, "end_line": 384, "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": 386, "end_line": 387, "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": 10, "complexity": 4, "token_count": 66, "parameters": [ "self" ], "start_line": 389, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 409, "end_line": 410, "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": 411, "end_line": 412, "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": 413, "end_line": 414, "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": 415, "end_line": 416, "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": 417, "end_line": 422, "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": 424, "end_line": 425, "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 )", "filename": "build_flib.py", "nloc": 31, "complexity": 5, "token_count": 177, "parameters": [ "self", "fc", "f90c" ], "start_line": 433, "end_line": 471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 473, "end_line": 478, "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": 480, "end_line": 481, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 98, "parameters": [ "self", "fc", "f90c" ], "start_line": 494, "end_line": 516, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "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": 518, "end_line": 523, "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": 15, "complexity": 3, "token_count": 99, "parameters": [ "self" ], "start_line": 525, "end_line": 539, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 540, "end_line": 541, "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": 542, "end_line": 543, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 94, "parameters": [ "self", "fc", "f90c" ], "start_line": 551, "end_line": 569, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 571, "end_line": 573, "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": 574, "end_line": 576, "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": 577, "end_line": 578, "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": 579, "end_line": 580, "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 )", "filename": "build_flib.py", "nloc": 16, "complexity": 5, "token_count": 103, "parameters": [ "self", "fc", "f90c" ], "start_line": 588, "end_line": 609, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 21, "complexity": 10, "token_count": 120, "parameters": [ "self" ], "start_line": 611, "end_line": 634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "find_lib_directories", "long_name": "find_lib_directories( self )", "filename": "build_flib.py", "nloc": 9, "complexity": 3, "token_count": 43, "parameters": [ "self" ], "start_line": 636, "end_line": 646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 2, "token_count": 20, "parameters": [ "self" ], "start_line": 648, "end_line": 651, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "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": 653, "end_line": 654, "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 )", "filename": "build_flib.py", "nloc": 22, "complexity": 5, "token_count": 140, "parameters": [ "self", "fc", "f90c" ], "start_line": 663, "end_line": 691, "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": 693, "end_line": 707, "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": 710, "end_line": 711, "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 )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 31, "parameters": [ "self", "fc", "f90c" ], "start_line": 719, "end_line": 722, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 100, "parameters": [ "self", "fc", "f90c" ], "start_line": 730, "end_line": 749, "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": 751, "end_line": 753, "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": 755, "end_line": 756, "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 )", "filename": "build_flib.py", "nloc": 20, "complexity": 5, "token_count": 128, "parameters": [ "self", "fc", "f90c" ], "start_line": 764, "end_line": 788, "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": 792, "end_line": 793, "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 )", "filename": "build_flib.py", "nloc": 14, "complexity": 3, "token_count": 91, "parameters": [ "self", "fc", "f90c" ], "start_line": 800, "end_line": 822, "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": 3, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 824, "end_line": 826, "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": 828, "end_line": 830, "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": 833, "end_line": 835, "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": 837, "end_line": 838, "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": 840, "end_line": 841, "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": 843, "end_line": 844, "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 )", "filename": "build_flib.py", "nloc": 11, "complexity": 5, "token_count": 59, "parameters": [ "vendor", "fc", "f90c" ], "start_line": 846, "end_line": 856, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 58, "end_line": 63, "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": 23, "parameters": [], "start_line": 67, "end_line": 71, "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": 101, "end_line": 113, "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": 17, "complexity": 3, "token_count": 104, "parameters": [ "self" ], "start_line": 117, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "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": 137, "end_line": 139, "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": 141, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_library_names", "long_name": "get_library_names( self )", "filename": "build_flib.py", "nloc": 9, "complexity": 4, "token_count": 58, "parameters": [ "self" ], "start_line": 148, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "build_flib.py", "nloc": 7, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 164, "end_line": 173, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 7, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 177, "end_line": 186, "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": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 190, "end_line": 198, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , fortran_libraries )", "filename": "build_flib.py", "nloc": 18, "complexity": 5, "token_count": 122, "parameters": [ "self", "fortran_libraries" ], "start_line": 200, "end_line": 221, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 88, "parameters": [ "self" ], "start_line": 233, "end_line": 254, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "to_object", "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 13, "complexity": 3, "token_count": 89, "parameters": [ "self", "dirty_files", "module_dirs", "temp_dir" ], "start_line": 256, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 270, "end_line": 275, "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": 277, "end_line": 280, "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": 15, "complexity": 4, "token_count": 103, "parameters": [ "self", "compiler", "switches", "source_files", "module_dirs", "temp_dir" ], "start_line": 282, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 300, "end_line": 303, "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": 305, "end_line": 308, "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": 311, "end_line": 312, "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 )", "filename": "build_flib.py", "nloc": 9, "complexity": 2, "token_count": 68, "parameters": [ "self", "object_files", "library_name", "output_dir", "debug" ], "start_line": 314, "end_line": 325, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "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": 10, "complexity": 2, "token_count": 85, "parameters": [ "self", "library_name", "source_list", "module_dirs", "temp_dir" ], "start_line": 327, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "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": 350, "end_line": 357, "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": 359, "end_line": 360, "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": 10, "complexity": 4, "token_count": 66, "parameters": [ "self" ], "start_line": 362, "end_line": 380, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 382, "end_line": 383, "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": 384, "end_line": 385, "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": 386, "end_line": 387, "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": 388, "end_line": 389, "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": 390, "end_line": 395, "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": 397, "end_line": 398, "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 )", "filename": "build_flib.py", "nloc": 31, "complexity": 5, "token_count": 177, "parameters": [ "self", "fc", "f90c" ], "start_line": 406, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 446, "end_line": 451, "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": 453, "end_line": 454, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 98, "parameters": [ "self", "fc", "f90c" ], "start_line": 467, "end_line": 489, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "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": 491, "end_line": 496, "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": 15, "complexity": 3, "token_count": 99, "parameters": [ "self" ], "start_line": 498, "end_line": 512, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 513, "end_line": 514, "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": 515, "end_line": 516, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 94, "parameters": [ "self", "fc", "f90c" ], "start_line": 524, "end_line": 542, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 544, "end_line": 546, "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": 547, "end_line": 549, "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": 550, "end_line": 551, "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": 552, "end_line": 553, "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 )", "filename": "build_flib.py", "nloc": 16, "complexity": 5, "token_count": 103, "parameters": [ "self", "fc", "f90c" ], "start_line": 561, "end_line": 582, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 21, "complexity": 10, "token_count": 120, "parameters": [ "self" ], "start_line": 584, "end_line": 607, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "find_lib_directories", "long_name": "find_lib_directories( self )", "filename": "build_flib.py", "nloc": 9, "complexity": 3, "token_count": 43, "parameters": [ "self" ], "start_line": 609, "end_line": 619, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 2, "token_count": 20, "parameters": [ "self" ], "start_line": 621, "end_line": 624, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "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": 626, "end_line": 627, "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 )", "filename": "build_flib.py", "nloc": 22, "complexity": 5, "token_count": 140, "parameters": [ "self", "fc", "f90c" ], "start_line": 636, "end_line": 664, "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": 666, "end_line": 680, "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": 683, "end_line": 684, "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 )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 31, "parameters": [ "self", "fc", "f90c" ], "start_line": 692, "end_line": 695, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 100, "parameters": [ "self", "fc", "f90c" ], "start_line": 703, "end_line": 722, "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": 724, "end_line": 726, "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": 728, "end_line": 729, "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 )", "filename": "build_flib.py", "nloc": 20, "complexity": 5, "token_count": 128, "parameters": [ "self", "fc", "f90c" ], "start_line": 737, "end_line": 761, "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": 765, "end_line": 766, "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 )", "filename": "build_flib.py", "nloc": 14, "complexity": 3, "token_count": 91, "parameters": [ "self", "fc", "f90c" ], "start_line": 773, "end_line": 795, "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": 3, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 797, "end_line": 799, "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": 801, "end_line": 803, "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": 806, "end_line": 808, "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": 810, "end_line": 811, "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": 813, "end_line": 814, "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": 816, "end_line": 817, "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 )", "filename": "build_flib.py", "nloc": 11, "complexity": 5, "token_count": 59, "parameters": [ "vendor", "fc", "f90c" ], "start_line": 819, "end_line": 829, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "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": 154, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "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": 13, "complexity": 3, "token_count": 104, "parameters": [ "self", "library_name", "source_list", "module_dirs", "temp_dir" ], "start_line": 349, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "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": 148, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "build_flib.py", "nloc": 7, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 164, "end_line": 173, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_runtime_library_dirs", "long_name": "get_runtime_library_dirs( self )", "filename": "build_flib.py", "nloc": 7, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 199, "end_line": 208, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_library_names", "long_name": "get_library_names( self )", "filename": "build_flib.py", "nloc": 9, "complexity": 4, "token_count": 58, "parameters": [ "self" ], "start_line": 148, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 178, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 } ], "nloc": 630, "complexity": 161, "token_count": 3661, "diff_parsed": { "added": [ " def has_f_library(self,name):", " if self.has_f_libraries():", " for (lib_name, build_info) in self.fortran_libraries:", " if lib_name == name:", " return 1", "", " def get_library_names(self, name=None):", " lib_names = []", " if name is None:", " for (lib_name, build_info) in self.fortran_libraries:", " lib_names.append(lib_name)", " if self.fcompiler is not None:", " lib_names.extend(self.fcompiler.get_libraries())", " else:", " for (lib_name, build_info) in self.fortran_libraries:", " if name != lib_name: continue", " for n in build_info.get('libraries',[]):", " lib_names.append(n)", " #XXX: how to catch recursive calls here?", " lib_names.extend(self.get_library_names(n))", " break", " def get_library_dirs(self, name=None):", " return []", " if name is None:", " if self.fcompiler is not None:", " lib_dirs.extend(self.fcompiler.get_library_dirs())", " else:", " for (lib_name, build_info) in self.fortran_libraries:", " if name != lib_name: continue", " lib_dirs.extend(build_info.get('library_dirs',[]))", " for n in build_info.get('libraries',[]):", " lib_dirs.extend(self.get_library_dirs(n))", " break", "", " return []", " lib_dirs = []", "", "", "", " if os.name == 'nt':", " # This is pure bunk...", " # Windows fails for long argument strings on the command line.", " # if objects is real long (> 2048 chars or so on my machine),", " # the command fails (cmd.exe /e:2048 on w2k)", " # for now we'll split linking into to steps which should work for", " objects = object_list[:]", " while objects:", " obj,objects = objects[:20],objects[20:]", " self.create_static_lib(obj,library_name,temp_dir)", " else:", " self.create_static_lib(object_list,library_name,temp_dir)" ], "deleted": [ " def get_library_names(self):", " lib_names = []", " for (lib_name, build_info) in self.fortran_libraries:", " lib_names.append(lib_name)", " if self.fcompiler is not None:", " lib_names.extend(self.fcompiler.get_libraries())", "", " def get_library_dirs(self):", " return []#None", " if self.fcompiler is not None:", " lib_dirs.extend(self.fcompiler.get_library_dirs())", "", " return []#None", " lib_dirs = []", " #self.create_static_lib(object_list,library_name,temp_dir)", " # This is pure bunk...", " # Windows fails for long argument strings on the command line.", " # if objects is real long (> 2048 chars or so on my machine),", " # the command fails (cmd.exe /e:2048 on w2k)", " # for now we'll split linking into to steps which should work for", " objects = object_list[:]", " while objects:", " obj,objects = objects[:20],objects[20:]", " self.create_static_lib(obj,library_name,temp_dir)" ] } }, { "old_path": "scipy_distutils/misc_util.py", "new_path": "scipy_distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -245,3 +245,20 @@ def merge_config_dicts(config_list):\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n+\n+def fortran_library_item(lib_name,\n+ sources,\n+ **attrs\n+ ):\n+ \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n+ build_info = {'sources':sources}\n+ known_attrs = ['module_files','module_dirs',\n+ 'libraries','library_dirs']\n+ for key,value in attrs.items():\n+ if key not in known_attrs:\n+ raise TypeError,\\\n+ \"fortran_library_item() got an unexpected keyword \"\\\n+ \"argument '%s'\" % key\n+ build_info[key] = value\n+ \n+ return (lib_name,build_info)\n", "added_lines": 17, "deleted_lines": 0, "source_code": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict():\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict() \n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", "source_code_before": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict():\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict() \n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n", "methods": [ { "name": "update_version", "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", "filename": "misc_util.py", "nloc": 65, "complexity": 12, "token_count": 351, "parameters": [ "release_level", "path", "major", "overwrite_version_py" ], "start_line": 3, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 }, { "name": "get_version", "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", "filename": "misc_util.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "release_level", "path", "major" ], "start_line": 111, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_cvs_revision", "long_name": "get_cvs_revision( path )", "filename": "misc_util.py", "nloc": 21, "complexity": 10, "token_count": 190, "parameters": [ "path" ], "start_line": 127, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_path", "long_name": "get_path( mod_name )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 80, "parameters": [ "mod_name" ], "start_line": 156, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 174, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "add_grandparent_to_path", "long_name": "add_grandparent_to_path( mod_name )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "mod_name" ], "start_line": 179, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 184, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "append_package_dir_to_path", "long_name": "append_package_dir_to_path( package_name )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 64, "parameters": [ "package_name" ], "start_line": 187, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "get_package_config", "long_name": "get_package_config( package_name )", "filename": "misc_util.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "package_name" ], "start_line": 203, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "package_config", "long_name": "package_config( primary , dependencies = [ ] )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 53, "parameters": [ "primary", "dependencies" ], "start_line": 215, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [], "start_line": 234, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 61, "parameters": [ "config_list" ], "start_line": 240, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "fortran_library_item", "long_name": "fortran_library_item( lib_name , sources , ** attrs )", "filename": "misc_util.py", "nloc": 14, "complexity": 3, "token_count": 67, "parameters": [ "lib_name", "sources", "attrs" ], "start_line": 249, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "methods_before": [ { "name": "update_version", "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", "filename": "misc_util.py", "nloc": 65, "complexity": 12, "token_count": 351, "parameters": [ "release_level", "path", "major", "overwrite_version_py" ], "start_line": 3, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 }, { "name": "get_version", "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", "filename": "misc_util.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "release_level", "path", "major" ], "start_line": 111, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_cvs_revision", "long_name": "get_cvs_revision( path )", "filename": "misc_util.py", "nloc": 21, "complexity": 10, "token_count": 190, "parameters": [ "path" ], "start_line": 127, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_path", "long_name": "get_path( mod_name )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 80, "parameters": [ "mod_name" ], "start_line": 156, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 174, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "add_grandparent_to_path", "long_name": "add_grandparent_to_path( mod_name )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "mod_name" ], "start_line": 179, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 184, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "append_package_dir_to_path", "long_name": "append_package_dir_to_path( package_name )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 64, "parameters": [ "package_name" ], "start_line": 187, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "get_package_config", "long_name": "get_package_config( package_name )", "filename": "misc_util.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "package_name" ], "start_line": 203, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "package_config", "long_name": "package_config( primary , dependencies = [ ] )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 53, "parameters": [ "primary", "dependencies" ], "start_line": 215, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [], "start_line": 234, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 61, "parameters": [ "config_list" ], "start_line": 240, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "fortran_library_item", "long_name": "fortran_library_item( lib_name , sources , ** attrs )", "filename": "misc_util.py", "nloc": 14, "complexity": 3, "token_count": 67, "parameters": [ "lib_name", "sources", "attrs" ], "start_line": 249, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "nloc": 163, "complexity": 46, "token_count": 1079, "diff_parsed": { "added": [ "", "def fortran_library_item(lib_name,", " sources,", " **attrs", " ):", " \"\"\" Helper function for creating fortran_libraries items. \"\"\"", " build_info = {'sources':sources}", " known_attrs = ['module_files','module_dirs',", " 'libraries','library_dirs']", " for key,value in attrs.items():", " if key not in known_attrs:", " raise TypeError,\\", " \"fortran_library_item() got an unexpected keyword \"\\", " \"argument '%s'\" % key", " build_info[key] = value", "", " return (lib_name,build_info)" ], "deleted": [] } } ] }, { "hash": "958af342c7822dc302ac814fb962d1305d6a0a75", "msg": "adding support for instance variables and a few bug cleanups", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-02-14T08:17:04+00:00", "author_timezone": 0, "committer_date": "2002-02-14T08:17:04+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "e0e4a3f3a2453af3043f6c29cefa49a1eb24e528" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 6, "insertions": 16, "lines": 22, "files": 4, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 0.2857142857142857, "modified_files": [ { "old_path": "weave/common_spec.py", "new_path": "weave/common_spec.py", "filename": "common_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -47,12 +47,22 @@ def type_match(self,value):\n \n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n- #code = 'PyObject* %s = convert_to_callable(%s,\"%s\");\\n' % \\\n- # (self.name,var_name,self.name)\n code = 'PyObject* %s = convert_to_callable(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n \n+class instance_specification(common_base_specification):\n+ type_name = 'instance'\n+ _build_information = [common_info.instance_info()]\n+ def type_match(self,value):\n+ return type(value) in [InstanceType]\n+\n+ def declaration_code(self,templatize = 0,inline=0):\n+ var_name = self.retrieve_py_variable(inline)\n+ code = 'PyObject* %s = convert_to_instance(%s,\"%s\");\\n' % \\\n+ (self.name,var_name,self.name)\n+ return code \n+\n def test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n", "added_lines": 12, "deleted_lines": 2, "source_code": "from base_spec import base_specification\nimport common_info\nfrom types import *\nimport os\n\nclass common_base_specification(base_specification):\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n return new_spec\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 return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n \n \nclass file_specification(common_base_specification):\n type_name = 'file'\n _build_information = [common_info.file_info()]\n def type_match(self,value):\n return type(value) in [FileType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n #code = 'PyObject* py_%s = %s;\\n' \\\n # 'FILE* %s = convert_to_file(py_%s,\"%s\");\\n' % \\\n # (self.name,var_name,self.name,self.name,self.name)\n code = 'PyObject* py_%s = %s;\\n' \\\n 'FILE* %s = convert_to_file(py_%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name,self.name,self.name)\n return code \n def cleanup_code(self):\n # could use Py_DECREF here I think and save NULL test.\n code = \"Py_XDECREF(py_%s);\\n\" % self.name\n return code\n\nclass callable_specification(common_base_specification):\n type_name = 'callable'\n _build_information = [common_info.callable_info()]\n def type_match(self,value):\n # probably should test for callable classes here also.\n return type(value) in [FunctionType,MethodType,type(len)]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'PyObject* %s = convert_to_callable(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n\nclass instance_specification(common_base_specification):\n type_name = 'instance'\n _build_information = [common_info.instance_info()]\n def type_match(self,value):\n return type(value) in [InstanceType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'PyObject* %s = convert_to_instance(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n", "source_code_before": "from base_spec import base_specification\nimport common_info\nfrom types import *\nimport os\n\nclass common_base_specification(base_specification):\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n return new_spec\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 return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n \n \nclass file_specification(common_base_specification):\n type_name = 'file'\n _build_information = [common_info.file_info()]\n def type_match(self,value):\n return type(value) in [FileType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n #code = 'PyObject* py_%s = %s;\\n' \\\n # 'FILE* %s = convert_to_file(py_%s,\"%s\");\\n' % \\\n # (self.name,var_name,self.name,self.name,self.name)\n code = 'PyObject* py_%s = %s;\\n' \\\n 'FILE* %s = convert_to_file(py_%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name,self.name,self.name)\n return code \n def cleanup_code(self):\n # could use Py_DECREF here I think and save NULL test.\n code = \"Py_XDECREF(py_%s);\\n\" % self.name\n return code\n\nclass callable_specification(common_base_specification):\n type_name = 'callable'\n _build_information = [common_info.callable_info()]\n def type_match(self,value):\n # probably should test for callable classes here also.\n return type(value) in [FunctionType,MethodType,type(len)]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n #code = 'PyObject* %s = convert_to_callable(%s,\"%s\");\\n' % \\\n # (self.name,var_name,self.name)\n code = 'PyObject* %s = convert_to_callable(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n", "methods": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "common_spec.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "self", "name", "value" ], "start_line": 7, "end_line": 11, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 12, "end_line": 14, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "common_spec.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "self", "other" ], "start_line": 15, "end_line": 18, "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": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 24, "end_line": 25, "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": "common_spec.py", "nloc": 6, "complexity": 1, "token_count": 49, "parameters": [ "self", "templatize", "inline" ], "start_line": 27, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 36, "end_line": 39, "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": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "value" ], "start_line": 44, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "common_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 48, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 57, "end_line": 58, "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": "common_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 60, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 70, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "common_spec.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "self", "name", "value" ], "start_line": 7, "end_line": 11, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 12, "end_line": 14, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "common_spec.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "self", "other" ], "start_line": 15, "end_line": 18, "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": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 24, "end_line": 25, "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": "common_spec.py", "nloc": 6, "complexity": 1, "token_count": 49, "parameters": [ "self", "templatize", "inline" ], "start_line": 27, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 36, "end_line": 39, "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": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "value" ], "start_line": 44, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "common_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 48, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 56, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 60, "end_line": 62, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "type_match", "long_name": "type_match( self , value )", "filename": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 57, "end_line": 58, "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": "common_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 60, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 } ], "nloc": 55, "complexity": 13, "token_count": 376, "diff_parsed": { "added": [ "class instance_specification(common_base_specification):", " type_name = 'instance'", " _build_information = [common_info.instance_info()]", " def type_match(self,value):", " return type(value) in [InstanceType]", "", " def declaration_code(self,templatize = 0,inline=0):", " var_name = self.retrieve_py_variable(inline)", " code = 'PyObject* %s = convert_to_instance(%s,\"%s\");\\n' % \\", " (self.name,var_name,self.name)", " return code", "" ], "deleted": [ " #code = 'PyObject* %s = convert_to_callable(%s,\"%s\");\\n' % \\", " # (self.name,var_name,self.name)" ] } }, { "old_path": "weave/conversion_code.py", "new_path": "weave/conversion_code.py", "filename": "conversion_code.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -128,7 +128,7 @@ class instance_handler\n public:\n PyObject* convert_to_instance(PyObject* py_obj, const char* name)\n {\n- if (!py_obj || !PyFile_Check(py_obj))\n+ if (!py_obj || !PyInstance_Check(py_obj))\n handle_conversion_error(py_obj,\"instance\", name);\n \n // Should I INCREF???\n@@ -139,7 +139,7 @@ class instance_handler\n \n PyObject* py_to_instance(PyObject* py_obj, const char* name)\n {\n- if (!py_obj || !PyFile_Check(py_obj))\n+ if (!py_obj || !PyInstance_Check(py_obj))\n handle_bad_type(py_obj,\"instance\", name);\n \n // Should I INCREF???\n", "added_lines": 2, "deleted_lines": 2, "source_code": "\"\"\" C/C++ code strings needed for converting most non-sequence\n Python variables:\n module_support_code -- several routines used by most other code \n conversion methods. It holds the only\n CXX dependent code in this file. The CXX\n stuff is used for exceptions\n file_convert_code\n instance_convert_code\n callable_convert_code\n module_convert_code\n \n scalar_convert_code\n non_template_scalar_support_code \n Scalar conversion covers int, float, double, complex,\n and double complex. While Python doesn't support all these,\n Numeric does and so all of them are made available.\n Python longs are currently converted to C ints. Any\n better way to handle this?\n\"\"\"\n\nimport base_info\n\n#############################################################\n# Basic module support code\n#############################################################\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\n#############################################################\n# File conversion support code\n#############################################################\n\nfile_convert_code = \\\n\"\"\"\n\nclass file_handler\n{\npublic:\n FILE* convert_to_file(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyFile_Check(py_obj))\n handle_conversion_error(py_obj,\"file\", name);\n \n // Cleanup code should call DECREF\n Py_INCREF(py_obj);\n return PyFile_AsFile(py_obj);\n }\n \n FILE* py_to_file(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyFile_Check(py_obj))\n handle_bad_type(py_obj,\"file\", name);\n \n // Cleanup code should call DECREF\n Py_INCREF(py_obj);\n return PyFile_AsFile(py_obj);\n }\n};\n\nfile_handler x__file_handler = file_handler();\n#define convert_to_file(py_obj,name) x__file_handler.convert_to_file(py_obj,name)\n#define py_to_file(py_obj,name) x__file_handler.py_to_file(py_obj,name)\n\nPyObject* 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\"\"\"\n\n\n#############################################################\n# Instance conversion code\n#############################################################\n\ninstance_convert_code = \\\n\"\"\"\n\nclass instance_handler\n{\npublic:\n PyObject* convert_to_instance(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyInstance_Check(py_obj))\n handle_conversion_error(py_obj,\"instance\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n \n PyObject* py_to_instance(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyInstance_Check(py_obj))\n handle_bad_type(py_obj,\"instance\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n};\n\ninstance_handler x__instance_handler = instance_handler();\n#define convert_to_instance(py_obj,name) x__instance_handler.convert_to_instance(py_obj,name)\n#define py_to_instance(py_obj,name) x__instance_handler.py_to_instance(py_obj,name)\n\nPyObject* instance_to_py(PyObject* instance)\n{\n // Don't think I need to do anything...\n return (PyObject*) instance;\n}\n\n\"\"\"\n\n#############################################################\n# Callable conversion code\n#############################################################\n\ncallable_convert_code = \\\n\"\"\"\n\nclass callable_handler\n{\npublic: \n PyObject* convert_to_callable(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyCallable_Check(py_obj))\n handle_conversion_error(py_obj,\"callable\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n \n PyObject* py_to_callable(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyCallable_Check(py_obj))\n handle_bad_type(py_obj,\"callable\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n};\n\ncallable_handler x__callable_handler = callable_handler();\n#define convert_to_callable(py_obj,name) x__callable_handler.convert_to_callable(py_obj,name)\n#define py_to_callable(py_obj,name) x__callable_handler.py_to_callable(py_obj,name)\n\nPyObject* callable_to_py(PyObject* callable)\n{\n // Don't think I need to do anything...\n return (PyObject*) callable;\n}\n\n\"\"\"\n\n#############################################################\n# Module conversion code\n#############################################################\n\nmodule_convert_code = \\\n\"\"\"\nclass module_handler\n{\npublic:\n PyObject* convert_to_module(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyModule_Check(py_obj))\n handle_conversion_error(py_obj,\"module\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n \n PyObject* py_to_module(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyModule_Check(py_obj))\n handle_bad_type(py_obj,\"module\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n};\n\nmodule_handler x__module_handler = module_handler();\n#define convert_to_module(py_obj,name) x__module_handler.convert_to_module(py_obj,name)\n#define py_to_module(py_obj,name) x__module_handler.py_to_module(py_obj,name)\n\nPyObject* module_to_py(PyObject* module)\n{\n // Don't think I need to do anything...\n return (PyObject*) module;\n}\n\n\"\"\"\n\n#############################################################\n# Scalar conversion code\n#############################################################\n\n# These non-templated version is now used for most scalar conversions.\nscalar_support_code = \\\n\"\"\"\n\nclass scalar_handler\n{\npublic: \n int convert_to_int(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyInt_Check(py_obj))\n handle_conversion_error(py_obj,\"int\", name);\n return (int) PyInt_AsLong(py_obj);\n }\n long convert_to_long(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyLong_Check(py_obj))\n handle_conversion_error(py_obj,\"long\", name);\n return (long) PyLong_AsLong(py_obj);\n }\n\n double convert_to_float(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyFloat_Check(py_obj))\n handle_conversion_error(py_obj,\"float\", name);\n return PyFloat_AsDouble(py_obj);\n }\n\n std::complex convert_to_complex(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_conversion_error(py_obj,\"complex\", name);\n return std::complex(PyComplex_RealAsDouble(py_obj),\n PyComplex_ImagAsDouble(py_obj)); \n }\n\n int py_to_int(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyInt_Check(py_obj))\n handle_bad_type(py_obj,\"int\", name);\n return (int) PyInt_AsLong(py_obj);\n }\n \n long py_to_long(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyLong_Check(py_obj))\n handle_bad_type(py_obj,\"long\", name);\n return (long) PyLong_AsLong(py_obj);\n }\n \n double py_to_float(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyFloat_Check(py_obj))\n handle_bad_type(py_obj,\"float\", name);\n return PyFloat_AsDouble(py_obj);\n }\n \n std::complex py_to_complex(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_bad_type(py_obj,\"complex\", name);\n return std::complex(PyComplex_RealAsDouble(py_obj),\n PyComplex_ImagAsDouble(py_obj)); \n }\n\n};\n\nscalar_handler x__scalar_handler = scalar_handler();\n#define convert_to_int(py_obj,name) x__scalar_handler.convert_to_int(py_obj,name)\n#define py_to_int(py_obj,name) x__scalar_handler.py_to_int(py_obj,name)\n\n#define convert_to_long(py_obj,name) x__scalar_handler.convert_to_long(py_obj,name)\n#define py_to_long(py_obj,name) x__scalar_handler.py_to_long(py_obj,name)\n\n#define convert_to_float(py_obj,name) x__scalar_handler.convert_to_float(py_obj,name)\n#define py_to_float(py_obj,name) x__scalar_handler.py_to_float(py_obj,name)\n\n#define convert_to_complex(py_obj,name) x__scalar_handler.convert_to_complex(py_obj,name)\n#define py_to_complex(py_obj,name) x__scalar_handler.py_to_complex(py_obj,name)\n\n\"\"\" \n\n", "source_code_before": "\"\"\" C/C++ code strings needed for converting most non-sequence\n Python variables:\n module_support_code -- several routines used by most other code \n conversion methods. It holds the only\n CXX dependent code in this file. The CXX\n stuff is used for exceptions\n file_convert_code\n instance_convert_code\n callable_convert_code\n module_convert_code\n \n scalar_convert_code\n non_template_scalar_support_code \n Scalar conversion covers int, float, double, complex,\n and double complex. While Python doesn't support all these,\n Numeric does and so all of them are made available.\n Python longs are currently converted to C ints. Any\n better way to handle this?\n\"\"\"\n\nimport base_info\n\n#############################################################\n# Basic module support code\n#############################################################\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\n#############################################################\n# File conversion support code\n#############################################################\n\nfile_convert_code = \\\n\"\"\"\n\nclass file_handler\n{\npublic:\n FILE* convert_to_file(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyFile_Check(py_obj))\n handle_conversion_error(py_obj,\"file\", name);\n \n // Cleanup code should call DECREF\n Py_INCREF(py_obj);\n return PyFile_AsFile(py_obj);\n }\n \n FILE* py_to_file(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyFile_Check(py_obj))\n handle_bad_type(py_obj,\"file\", name);\n \n // Cleanup code should call DECREF\n Py_INCREF(py_obj);\n return PyFile_AsFile(py_obj);\n }\n};\n\nfile_handler x__file_handler = file_handler();\n#define convert_to_file(py_obj,name) x__file_handler.convert_to_file(py_obj,name)\n#define py_to_file(py_obj,name) x__file_handler.py_to_file(py_obj,name)\n\nPyObject* 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\"\"\"\n\n\n#############################################################\n# Instance conversion code\n#############################################################\n\ninstance_convert_code = \\\n\"\"\"\n\nclass instance_handler\n{\npublic:\n PyObject* convert_to_instance(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyFile_Check(py_obj))\n handle_conversion_error(py_obj,\"instance\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n \n PyObject* py_to_instance(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyFile_Check(py_obj))\n handle_bad_type(py_obj,\"instance\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n};\n\ninstance_handler x__instance_handler = instance_handler();\n#define convert_to_instance(py_obj,name) x__instance_handler.convert_to_instance(py_obj,name)\n#define py_to_instance(py_obj,name) x__instance_handler.py_to_instance(py_obj,name)\n\nPyObject* instance_to_py(PyObject* instance)\n{\n // Don't think I need to do anything...\n return (PyObject*) instance;\n}\n\n\"\"\"\n\n#############################################################\n# Callable conversion code\n#############################################################\n\ncallable_convert_code = \\\n\"\"\"\n\nclass callable_handler\n{\npublic: \n PyObject* convert_to_callable(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyCallable_Check(py_obj))\n handle_conversion_error(py_obj,\"callable\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n \n PyObject* py_to_callable(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyCallable_Check(py_obj))\n handle_bad_type(py_obj,\"callable\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n};\n\ncallable_handler x__callable_handler = callable_handler();\n#define convert_to_callable(py_obj,name) x__callable_handler.convert_to_callable(py_obj,name)\n#define py_to_callable(py_obj,name) x__callable_handler.py_to_callable(py_obj,name)\n\nPyObject* callable_to_py(PyObject* callable)\n{\n // Don't think I need to do anything...\n return (PyObject*) callable;\n}\n\n\"\"\"\n\n#############################################################\n# Module conversion code\n#############################################################\n\nmodule_convert_code = \\\n\"\"\"\nclass module_handler\n{\npublic:\n PyObject* convert_to_module(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyModule_Check(py_obj))\n handle_conversion_error(py_obj,\"module\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n \n PyObject* py_to_module(PyObject* py_obj, const char* name)\n {\n if (!py_obj || !PyModule_Check(py_obj))\n handle_bad_type(py_obj,\"module\", name);\n \n // Should I INCREF???\n // Py_INCREF(py_obj);\n // just return the raw python pointer.\n return py_obj;\n }\n};\n\nmodule_handler x__module_handler = module_handler();\n#define convert_to_module(py_obj,name) x__module_handler.convert_to_module(py_obj,name)\n#define py_to_module(py_obj,name) x__module_handler.py_to_module(py_obj,name)\n\nPyObject* module_to_py(PyObject* module)\n{\n // Don't think I need to do anything...\n return (PyObject*) module;\n}\n\n\"\"\"\n\n#############################################################\n# Scalar conversion code\n#############################################################\n\n# These non-templated version is now used for most scalar conversions.\nscalar_support_code = \\\n\"\"\"\n\nclass scalar_handler\n{\npublic: \n int convert_to_int(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyInt_Check(py_obj))\n handle_conversion_error(py_obj,\"int\", name);\n return (int) PyInt_AsLong(py_obj);\n }\n long convert_to_long(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyLong_Check(py_obj))\n handle_conversion_error(py_obj,\"long\", name);\n return (long) PyLong_AsLong(py_obj);\n }\n\n double convert_to_float(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyFloat_Check(py_obj))\n handle_conversion_error(py_obj,\"float\", name);\n return PyFloat_AsDouble(py_obj);\n }\n\n std::complex convert_to_complex(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_conversion_error(py_obj,\"complex\", name);\n return std::complex(PyComplex_RealAsDouble(py_obj),\n PyComplex_ImagAsDouble(py_obj)); \n }\n\n int py_to_int(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyInt_Check(py_obj))\n handle_bad_type(py_obj,\"int\", name);\n return (int) PyInt_AsLong(py_obj);\n }\n \n long py_to_long(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyLong_Check(py_obj))\n handle_bad_type(py_obj,\"long\", name);\n return (long) PyLong_AsLong(py_obj);\n }\n \n double py_to_float(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyFloat_Check(py_obj))\n handle_bad_type(py_obj,\"float\", name);\n return PyFloat_AsDouble(py_obj);\n }\n \n std::complex py_to_complex(PyObject* py_obj,const char* name)\n {\n if (!py_obj || !PyComplex_Check(py_obj))\n handle_bad_type(py_obj,\"complex\", name);\n return std::complex(PyComplex_RealAsDouble(py_obj),\n PyComplex_ImagAsDouble(py_obj)); \n }\n\n};\n\nscalar_handler x__scalar_handler = scalar_handler();\n#define convert_to_int(py_obj,name) x__scalar_handler.convert_to_int(py_obj,name)\n#define py_to_int(py_obj,name) x__scalar_handler.py_to_int(py_obj,name)\n\n#define convert_to_long(py_obj,name) x__scalar_handler.convert_to_long(py_obj,name)\n#define py_to_long(py_obj,name) x__scalar_handler.py_to_long(py_obj,name)\n\n#define convert_to_float(py_obj,name) x__scalar_handler.convert_to_float(py_obj,name)\n#define py_to_float(py_obj,name) x__scalar_handler.py_to_float(py_obj,name)\n\n#define convert_to_complex(py_obj,name) x__scalar_handler.convert_to_complex(py_obj,name)\n#define py_to_complex(py_obj,name) x__scalar_handler.py_to_complex(py_obj,name)\n\n\"\"\" \n\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 303, "complexity": 0, "token_count": 27, "diff_parsed": { "added": [ " if (!py_obj || !PyInstance_Check(py_obj))", " if (!py_obj || !PyInstance_Check(py_obj))" ], "deleted": [ " if (!py_obj || !PyFile_Check(py_obj))", " if (!py_obj || !PyFile_Check(py_obj))" ] } }, { "old_path": "weave/ext_tools.py", "new_path": "weave/ext_tools.py", "filename": "ext_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -18,7 +18,7 @@\n sequence_spec.tuple_specification(),\n common_spec.file_specification(),\n common_spec.callable_specification()]\n- #common_spec.instance_specification(), \n+ common_spec.instance_specification(), \n #common_spec.module_specification()]\n \n try: \n", "added_lines": 1, "deleted_lines": 1, "source_code": "import os, sys\nimport string, re\n\nimport build_tools\n\nimport base_spec\nimport scalar_spec\nimport sequence_spec\nimport common_spec\nimport catalog \n\ndefault_type_factories = [scalar_spec.int_specification(),\n scalar_spec.float_specification(),\n scalar_spec.complex_specification(),\n sequence_spec.string_specification(),\n sequence_spec.list_specification(),\n sequence_spec.dict_specification(),\n sequence_spec.tuple_specification(),\n common_spec.file_specification(),\n common_spec.callable_specification()]\n common_spec.instance_specification(), \n #common_spec.module_specification()]\n\ntry: \n from standard_array_spec import array_specification\n default_type_factories.append(array_specification())\nexcept: \n pass \n\ntry: \n # this is currently safe because it doesn't import wxPython.\n import wx_spec\n default_type_factories.append(wx_spec.wx_specification())\nexcept: \n pass \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 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 #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 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 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 \" Py::Dict local_dict = Py::Dict(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 = Py::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_factories=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_factories is None:\n type_factories = default_type_factories\n arg_specs = assign_variable_types(args,local_dict, global_dict,\n auto_downcast, type_factories)\n ext_function_from_specs.__init__(self,name,code_block,arg_specs)\n \n \nimport base_info, common_info, cxx_info, scalar_info\n\nclass ext_module:\n def __init__(self,name,compiler=''):\n standard_info = [common_info.basic_module_info(),\n common_info.file_info(), \n common_info.instance_info(), \n common_info.callable_info(), \n common_info.module_info(), \n cxx_info.cxx_info(),\n scalar_info.scalar_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_factories = default_type_factories):\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_factories:\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():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n", "source_code_before": "import os, sys\nimport string, re\n\nimport build_tools\n\nimport base_spec\nimport scalar_spec\nimport sequence_spec\nimport common_spec\nimport catalog \n\ndefault_type_factories = [scalar_spec.int_specification(),\n scalar_spec.float_specification(),\n scalar_spec.complex_specification(),\n sequence_spec.string_specification(),\n sequence_spec.list_specification(),\n sequence_spec.dict_specification(),\n sequence_spec.tuple_specification(),\n common_spec.file_specification(),\n common_spec.callable_specification()]\n #common_spec.instance_specification(), \n #common_spec.module_specification()]\n\ntry: \n from standard_array_spec import array_specification\n default_type_factories.append(array_specification())\nexcept: \n pass \n\ntry: \n # this is currently safe because it doesn't import wxPython.\n import wx_spec\n default_type_factories.append(wx_spec.wx_specification())\nexcept: \n pass \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 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 #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 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 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 \" Py::Dict local_dict = Py::Dict(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 = Py::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_factories=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_factories is None:\n type_factories = default_type_factories\n arg_specs = assign_variable_types(args,local_dict, global_dict,\n auto_downcast, type_factories)\n ext_function_from_specs.__init__(self,name,code_block,arg_specs)\n \n \nimport base_info, common_info, cxx_info, scalar_info\n\nclass ext_module:\n def __init__(self,name,compiler=''):\n standard_info = [common_info.basic_module_info(),\n common_info.file_info(), \n common_info.instance_info(), \n common_info.callable_info(), \n common_info.module_info(), \n cxx_info.cxx_info(),\n scalar_info.scalar_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_factories = default_type_factories):\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_factories:\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():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \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": 38, "end_line": 43, "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": 45, "end_line": 46, "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": 48, "end_line": 51, "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": 53, "end_line": 57, "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": 30, "complexity": 5, "token_count": 174, "parameters": [ "self" ], "start_line": 64, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 1 }, { "name": "arg_declaration_code", "long_name": "arg_declaration_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "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": "arg_cleanup_code", "long_name": "arg_cleanup_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 117, "end_line": 122, "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": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 124, "end_line": 129, "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": 131, "end_line": 172, "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": 174, "end_line": 178, "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": 180, "end_line": 183, "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_factories = None )", "filename": "ext_tools.py", "nloc": 12, "complexity": 4, "token_count": 90, "parameters": [ "self", "name", "code_block", "args", "local_dict", "global_dict", "auto_downcast", "type_factories" ], "start_line": 187, "end_line": 199, "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": 13, "complexity": 1, "token_count": 91, "parameters": [ "self", "name", "compiler" ], "start_line": 205, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 219, "end_line": 220, "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": 221, "end_line": 228, "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": 230, "end_line": 234, "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": 236, "end_line": 244, "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": 246, "end_line": 253, "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": 255, "end_line": 258, "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": 260, "end_line": 263, "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": 265, "end_line": 267, "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": 269, "end_line": 273, "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": 275, "end_line": 285, "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": 287, "end_line": 295, "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": 297, "end_line": 303, "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": 305, "end_line": 312, "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": 314, "end_line": 351, "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": 353, "end_line": 355, "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": 357, "end_line": 361, "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_factories = default_type_factories )", "filename": "ext_tools.py", "nloc": 31, "complexity": 9, "token_count": 154, "parameters": [ "variables", "local_dict", "global_dict", "auto_downcast", "type_factories" ], "start_line": 363, "end_line": 398, "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": 400, "end_line": 427, "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": 429, "end_line": 434, "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": 436, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 443, "end_line": 445, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 447, "end_line": 449, "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": 38, "end_line": 43, "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": 45, "end_line": 46, "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": 48, "end_line": 51, "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": 53, "end_line": 57, "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": 30, "complexity": 5, "token_count": 174, "parameters": [ "self" ], "start_line": 64, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 1 }, { "name": "arg_declaration_code", "long_name": "arg_declaration_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "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": "arg_cleanup_code", "long_name": "arg_cleanup_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 117, "end_line": 122, "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": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 124, "end_line": 129, "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": 131, "end_line": 172, "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": 174, "end_line": 178, "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": 180, "end_line": 183, "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_factories = None )", "filename": "ext_tools.py", "nloc": 12, "complexity": 4, "token_count": 90, "parameters": [ "self", "name", "code_block", "args", "local_dict", "global_dict", "auto_downcast", "type_factories" ], "start_line": 187, "end_line": 199, "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": 13, "complexity": 1, "token_count": 91, "parameters": [ "self", "name", "compiler" ], "start_line": 205, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 219, "end_line": 220, "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": 221, "end_line": 228, "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": 230, "end_line": 234, "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": 236, "end_line": 244, "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": 246, "end_line": 253, "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": 255, "end_line": 258, "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": 260, "end_line": 263, "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": 265, "end_line": 267, "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": 269, "end_line": 273, "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": 275, "end_line": 285, "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": 287, "end_line": 295, "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": 297, "end_line": 303, "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": 305, "end_line": 312, "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": 314, "end_line": 351, "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": 353, "end_line": 355, "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": 357, "end_line": 361, "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_factories = default_type_factories )", "filename": "ext_tools.py", "nloc": 31, "complexity": 9, "token_count": 154, "parameters": [ "variables", "local_dict", "global_dict", "auto_downcast", "type_factories" ], "start_line": 363, "end_line": 398, "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": 400, "end_line": 427, "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": 429, "end_line": 434, "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": 436, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 443, "end_line": 445, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 447, "end_line": 449, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 338, "complexity": 76, "token_count": 2074, "diff_parsed": { "added": [ " common_spec.instance_specification()," ], "deleted": [ " #common_spec.instance_specification()," ] } }, { "old_path": "weave/standard_array_info.py", "new_path": "weave/standard_array_info.py", "filename": "standard_array_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -37,7 +37,7 @@ class numpy_handler\n \n numpy_handler x__numpy_handler = numpy_handler();\n #define convert_to_numpy x__numpy_handler.convert_to_numpy\n-#define convert_to_numpy x__numpy_handler.py_to_numpy\n+#define py_to_numpy x__numpy_handler.py_to_numpy\n \"\"\"\n \n type_check_code = \\\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\"\"\" Generic support code for handling standard Numeric arrays \n\"\"\"\n\nimport base_info\n\n\narray_convert_code = \\\n\"\"\"\n\nclass numpy_handler\n{\npublic:\n PyArrayObject* convert_to_numpy(PyObject* py_obj, const char* name)\n {\n PyArrayObject* arr_obj = NULL;\n \n if (!py_obj || !PyArray_Check(py_obj))\n handle_conversion_error(py_obj,\"array\", name);\n \n // Any need to deal with INC/DEC REFs?\n Py_INCREF(py_obj);\n return (PyArrayObject*) py_obj;\n }\n \n PyArrayObject* py_to_numpy(PyObject* py_obj, const char* name)\n {\n PyArrayObject* arr_obj = NULL;\n \n if (!py_obj || !PyArray_Check(py_obj))\n handle_bad_type(py_obj,\"array\", name);\n \n // Any need to deal with INC/DEC REFs?\n Py_INCREF(py_obj);\n return (PyArrayObject*) py_obj;\n }\n};\n\nnumpy_handler x__numpy_handler = numpy_handler();\n#define convert_to_numpy x__numpy_handler.convert_to_numpy\n#define py_to_numpy x__numpy_handler.py_to_numpy\n\"\"\"\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 if (arr_obj->descr->type_num != numeric_type)\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_obj->descr->type_num],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 if (arr_obj->descr->type_num != numeric_type)\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_obj->descr->type_num],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_info(base_info.base_info):\n _headers = ['\"Numeric/arrayobject.h\"','','']\n _support_code = [array_convert_code,size_check_code, type_check_code]\n _module_init_code = [numeric_init_code] ", "source_code_before": "\"\"\" Generic support code for handling standard Numeric arrays \n\"\"\"\n\nimport base_info\n\n\narray_convert_code = \\\n\"\"\"\n\nclass numpy_handler\n{\npublic:\n PyArrayObject* convert_to_numpy(PyObject* py_obj, const char* name)\n {\n PyArrayObject* arr_obj = NULL;\n \n if (!py_obj || !PyArray_Check(py_obj))\n handle_conversion_error(py_obj,\"array\", name);\n \n // Any need to deal with INC/DEC REFs?\n Py_INCREF(py_obj);\n return (PyArrayObject*) py_obj;\n }\n \n PyArrayObject* py_to_numpy(PyObject* py_obj, const char* name)\n {\n PyArrayObject* arr_obj = NULL;\n \n if (!py_obj || !PyArray_Check(py_obj))\n handle_bad_type(py_obj,\"array\", name);\n \n // Any need to deal with INC/DEC REFs?\n Py_INCREF(py_obj);\n return (PyArrayObject*) py_obj;\n }\n};\n\nnumpy_handler x__numpy_handler = numpy_handler();\n#define convert_to_numpy x__numpy_handler.convert_to_numpy\n#define convert_to_numpy x__numpy_handler.py_to_numpy\n\"\"\"\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 if (arr_obj->descr->type_num != numeric_type)\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_obj->descr->type_num],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 if (arr_obj->descr->type_num != numeric_type)\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_obj->descr->type_num],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_info(base_info.base_info):\n _headers = ['\"Numeric/arrayobject.h\"','','']\n _support_code = [array_convert_code,size_check_code, type_check_code]\n _module_init_code = [numeric_init_code] ", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 124, "complexity": 0, "token_count": 50, "diff_parsed": { "added": [ "#define py_to_numpy x__numpy_handler.py_to_numpy" ], "deleted": [ "#define convert_to_numpy x__numpy_handler.py_to_numpy" ] } } ] }, { "hash": "71100a2cf4fd5d8db0b229f4803fbf08efff4757", "msg": "some code cleanup after template support for scalars removed.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-02-14T19:31:20+00:00", "author_timezone": 0, "committer_date": "2002-02-14T19:31:20+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "958af342c7822dc302ac814fb962d1305d6a0a75" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 40, "insertions": 0, "lines": 40, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "weave/scalar_spec.py", "new_path": "weave/scalar_spec.py", "filename": "scalar_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -39,7 +39,6 @@ def type_spec(self,name,value):\n new_spec.numeric_type = type(value)\n return new_spec\n \n- # BEGIN ADDED WHEN TEMPLATE SUPPORT REMOVED\n def declaration_code(self,inline=0):\n type = numeric_to_blitz_type_mapping[self.numeric_type]\n func_type = self.type_name\n@@ -49,45 +48,6 @@ def declaration_code(self,inline=0):\n 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n- # END ADDED WHEN TEMPLATE SUPPORT REMOVED\n- \n- # BEGIN OF THINGS REMOVED FOR TEMPLATES \n- #def declaration_code(self,templatize = 0,inline=0):\n- # #if self.compiler == 'msvc':\n- # # return self.msvc_decl_code(templatize,inline)\n- # #else:\n- # # return self.template_decl_code(templatize,inline) \\\n- # return self.msvc_decl_code(templatize,inline)\n-\n- # This is no longer used by anything except blitz code.\n- #def template_decl_code(self,template = 0,inline=0):\n- # type = numeric_to_blitz_type_mapping[self.numeric_type]\n- # name = self.name\n- # var_name = self.retrieve_py_variable(inline)\n- # template = '%(type)s %(name)s = '\\\n- # 'convert_to_scalar<%(type)s >(%(var_name)s,\"%(name)s\");\\n'\n- # code = template % locals()\n- # return code\n- \n- #def msvc_decl_code(self,template = 0,inline=0):\n- # # doesn't support template = 1\n- # if template:\n- # ValueError, 'msvc compiler does not support templated scalar '\\\n- # 'code. try mingw32 instead (www.mingw.org).'\n- # type = numeric_to_blitz_type_mapping[self.numeric_type]\n- # func_type = self.type_name\n- # name = self.name\n- # var_name = self.retrieve_py_variable(inline)\n- # template = '%(type)s %(name)s = '\\\n- # 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'\n- # code = template % locals()\n- # return code\n- # END OF THINGS REMOVED FOR TEMPLATES\n- \n- #def c_function_declaration_code(self):\n- # code = '%s &%s\" % \\\n- # (numeric_to_blitz_type_mapping[self.numeric_type], self.name)\n- # return code\n \n def __repr__(self):\n msg = \"(%s:: name: %s, type: %s)\" % \\\n", "added_lines": 0, "deleted_lines": 40, "source_code": "from base_spec import base_specification\nimport scalar_info\n#from Numeric import *\nfrom types import *\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\nnumeric_to_blitz_type_mapping = {}\n\nnumeric_to_blitz_type_mapping['T'] = 'T' # for templates\nnumeric_to_blitz_type_mapping['F'] = 'std::complex '\nnumeric_to_blitz_type_mapping['D'] = 'std::complex '\nnumeric_to_blitz_type_mapping['f'] = 'float'\nnumeric_to_blitz_type_mapping['d'] = 'double'\nnumeric_to_blitz_type_mapping['1'] = 'char'\nnumeric_to_blitz_type_mapping['b'] = 'unsigned char'\nnumeric_to_blitz_type_mapping['s'] = 'short'\nnumeric_to_blitz_type_mapping['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.\nnumeric_to_blitz_type_mapping['l'] = 'int'\n\n# standard Python numeric type mappings.\nnumeric_to_blitz_type_mapping[type(1)] = 'int'\nnumeric_to_blitz_type_mapping[type(1.)] = 'double'\nnumeric_to_blitz_type_mapping[type(1.+1.j)] = 'std::complex '\n#hmmm. The following is likely unsafe...\nnumeric_to_blitz_type_mapping[type(1L)] = 'int'\n\nclass scalar_specification(base_specification):\n _build_information = [scalar_info.scalar_info()] \n\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name\n new_spec.numeric_type = type(value)\n return new_spec\n \n def declaration_code(self,inline=0):\n type = numeric_to_blitz_type_mapping[self.numeric_type]\n func_type = self.type_name\n name = self.name\n var_name = self.retrieve_py_variable(inline)\n template = '%(type)s %(name)s = '\\\n 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n\n def __repr__(self):\n msg = \"(%s:: name: %s, type: %s)\" % \\\n (self.type_name,self.name, self.numeric_type)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.__class__, other.__class__)\n\nclass int_specification(scalar_specification):\n type_name = 'int'\n def type_match(self,value):\n return type(value) in [IntType, LongType]\n \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Int(%s);\\n' % (self.name,self.name) \n return code\n \nclass float_specification(scalar_specification):\n type_name = 'float'\n def type_match(self,value):\n return type(value) in [FloatType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Float(%s);\\n' % (self.name,self.name) \n return code\n\nclass complex_specification(scalar_specification):\n type_name = 'complex'\n def type_match(self,value):\n return type(value) in [ComplexType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Complex(%s.real(),%s.imag());\\n' % \\\n (self.name,self.name,self.name) \n return code\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n ", "source_code_before": "from base_spec import base_specification\nimport scalar_info\n#from Numeric import *\nfrom types import *\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\nnumeric_to_blitz_type_mapping = {}\n\nnumeric_to_blitz_type_mapping['T'] = 'T' # for templates\nnumeric_to_blitz_type_mapping['F'] = 'std::complex '\nnumeric_to_blitz_type_mapping['D'] = 'std::complex '\nnumeric_to_blitz_type_mapping['f'] = 'float'\nnumeric_to_blitz_type_mapping['d'] = 'double'\nnumeric_to_blitz_type_mapping['1'] = 'char'\nnumeric_to_blitz_type_mapping['b'] = 'unsigned char'\nnumeric_to_blitz_type_mapping['s'] = 'short'\nnumeric_to_blitz_type_mapping['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.\nnumeric_to_blitz_type_mapping['l'] = 'int'\n\n# standard Python numeric type mappings.\nnumeric_to_blitz_type_mapping[type(1)] = 'int'\nnumeric_to_blitz_type_mapping[type(1.)] = 'double'\nnumeric_to_blitz_type_mapping[type(1.+1.j)] = 'std::complex '\n#hmmm. The following is likely unsafe...\nnumeric_to_blitz_type_mapping[type(1L)] = 'int'\n\nclass scalar_specification(base_specification):\n _build_information = [scalar_info.scalar_info()] \n\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name\n new_spec.numeric_type = type(value)\n return new_spec\n \n # BEGIN ADDED WHEN TEMPLATE SUPPORT REMOVED\n def declaration_code(self,inline=0):\n type = numeric_to_blitz_type_mapping[self.numeric_type]\n func_type = self.type_name\n name = self.name\n var_name = self.retrieve_py_variable(inline)\n template = '%(type)s %(name)s = '\\\n 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n # END ADDED WHEN TEMPLATE SUPPORT REMOVED\n \n # BEGIN OF THINGS REMOVED FOR TEMPLATES \n #def declaration_code(self,templatize = 0,inline=0):\n # #if self.compiler == 'msvc':\n # # return self.msvc_decl_code(templatize,inline)\n # #else:\n # # return self.template_decl_code(templatize,inline) \\\n # return self.msvc_decl_code(templatize,inline)\n\n # This is no longer used by anything except blitz code.\n #def template_decl_code(self,template = 0,inline=0):\n # type = numeric_to_blitz_type_mapping[self.numeric_type]\n # name = self.name\n # var_name = self.retrieve_py_variable(inline)\n # template = '%(type)s %(name)s = '\\\n # 'convert_to_scalar<%(type)s >(%(var_name)s,\"%(name)s\");\\n'\n # code = template % locals()\n # return code\n \n #def msvc_decl_code(self,template = 0,inline=0):\n # # doesn't support template = 1\n # if template:\n # ValueError, 'msvc compiler does not support templated scalar '\\\n # 'code. try mingw32 instead (www.mingw.org).'\n # type = numeric_to_blitz_type_mapping[self.numeric_type]\n # func_type = self.type_name\n # name = self.name\n # var_name = self.retrieve_py_variable(inline)\n # template = '%(type)s %(name)s = '\\\n # 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'\n # code = template % locals()\n # return code\n # END OF THINGS REMOVED FOR TEMPLATES\n \n #def c_function_declaration_code(self):\n # code = '%s &%s\" % \\\n # (numeric_to_blitz_type_mapping[self.numeric_type], self.name)\n # return code\n\n def __repr__(self):\n msg = \"(%s:: name: %s, type: %s)\" % \\\n (self.type_name,self.name, self.numeric_type)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.__class__, other.__class__)\n\nclass int_specification(scalar_specification):\n type_name = 'int'\n def type_match(self,value):\n return type(value) in [IntType, LongType]\n \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Int(%s);\\n' % (self.name,self.name) \n return code\n \nclass float_specification(scalar_specification):\n type_name = 'float'\n def type_match(self,value):\n return type(value) in [FloatType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Float(%s);\\n' % (self.name,self.name) \n return code\n\nclass complex_specification(scalar_specification):\n type_name = 'complex'\n def type_match(self,value):\n return type(value) in [ComplexType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Complex(%s.real(),%s.imag());\\n' % \\\n (self.name,self.name,self.name) \n return code\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n ", "methods": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self", "name", "value" ], "start_line": 35, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , inline = 0 )", "filename": "scalar_spec.py", "nloc": 9, "complexity": 1, "token_count": 49, "parameters": [ "self", "inline" ], "start_line": 42, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 52, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 3, "token_count": 42, "parameters": [ "self", "other" ], "start_line": 56, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "value" ], "start_line": 64, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 67, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 73, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 75, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 81, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 83, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 88, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 92, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self", "name", "value" ], "start_line": 35, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , inline = 0 )", "filename": "scalar_spec.py", "nloc": 9, "complexity": 1, "token_count": 49, "parameters": [ "self", "inline" ], "start_line": 43, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 92, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 3, "token_count": 42, "parameters": [ "self", "other" ], "start_line": 96, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "value" ], "start_line": 104, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "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": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_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": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 115, "end_line": 117, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 121, "end_line": 122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 123, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 128, "end_line": 130, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 132, "end_line": 134, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 70, "complexity": 14, "token_count": 461, "diff_parsed": { "added": [], "deleted": [ " # BEGIN ADDED WHEN TEMPLATE SUPPORT REMOVED", " # END ADDED WHEN TEMPLATE SUPPORT REMOVED", "", " # BEGIN OF THINGS REMOVED FOR TEMPLATES", " #def declaration_code(self,templatize = 0,inline=0):", " # #if self.compiler == 'msvc':", " # # return self.msvc_decl_code(templatize,inline)", " # #else:", " # # return self.template_decl_code(templatize,inline) \\", " # return self.msvc_decl_code(templatize,inline)", "", " # This is no longer used by anything except blitz code.", " #def template_decl_code(self,template = 0,inline=0):", " # type = numeric_to_blitz_type_mapping[self.numeric_type]", " # name = self.name", " # var_name = self.retrieve_py_variable(inline)", " # template = '%(type)s %(name)s = '\\", " # 'convert_to_scalar<%(type)s >(%(var_name)s,\"%(name)s\");\\n'", " # code = template % locals()", " # return code", "", " #def msvc_decl_code(self,template = 0,inline=0):", " # # doesn't support template = 1", " # if template:", " # ValueError, 'msvc compiler does not support templated scalar '\\", " # 'code. try mingw32 instead (www.mingw.org).'", " # type = numeric_to_blitz_type_mapping[self.numeric_type]", " # func_type = self.type_name", " # name = self.name", " # var_name = self.retrieve_py_variable(inline)", " # template = '%(type)s %(name)s = '\\", " # 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'", " # code = template % locals()", " # return code", " # END OF THINGS REMOVED FOR TEMPLATES", "", " #def c_function_declaration_code(self):", " # code = '%s &%s\" % \\", " # (numeric_to_blitz_type_mapping[self.numeric_type], self.name)", " # return code" ] } } ] }, { "hash": "d7048594f8955af6b85d0377c5ad2a3d9c32909e", "msg": "Fixed build_ext to add ext.name to library list, if required", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-02-14T20:23:46+00:00", "author_timezone": 0, "committer_date": "2002-02-14T20:23:46+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "71100a2cf4fd5d8db0b229f4803fbf08efff4757" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 7, "insertions": 10, "lines": 17, "files": 2, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/__version__.py", "new_path": "scipy_distutils/__version__.py", "filename": "__version__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,4 +1,4 @@\n # This file is automatically updated with update_version\n # function from scipy_distutils.misc_util.py\n-version = '0.6.23-alpha-93'\n-version_info = (0, 6, 23, 'alpha', 93)\n+version = '0.6.23-alpha-98'\n+version_info = (0, 6, 23, 'alpha', 98)\n", "added_lines": 2, "deleted_lines": 2, "source_code": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-98'\nversion_info = (0, 6, 23, 'alpha', 98)\n", "source_code_before": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-93'\nversion_info = (0, 6, 23, 'alpha', 93)\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 2, "complexity": 0, "token_count": 16, "diff_parsed": { "added": [ "version = '0.6.23-alpha-98'", "version_info = (0, 6, 23, 'alpha', 98)" ], "deleted": [ "version = '0.6.23-alpha-93'", "version_info = (0, 6, 23, 'alpha', 93)" ] } }, { "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": "@@ -15,13 +15,16 @@ def build_extension(self, ext):\n need_f_libs = 0\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n- for lib_name in ext.libraries:\n- if build_flib.has_f_library(lib_name):\n- need_f_libs = 1\n- break\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 if need_f_libs:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n- if moreargs != []: \n+ if moreargs != []:\n if ext.extra_link_args is None:\n ext.extra_link_args = moreargs\n else:\n", "added_lines": 8, "deleted_lines": 5, "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 *\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n # support for building static fortran libraries\n need_f_libs = 0\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 if need_f_libs:\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 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 runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n linker_so = build_flib.fcompiler.get_linker_so()\n if linker_so is not None:\n self.compiler.linker_so = linker_so\n\n # end of fortran source support\n return old_build_ext.build_extension(self,ext)\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", "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 *\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n # support for building static fortran libraries\n need_f_libs = 0\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n for lib_name in ext.libraries:\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n if need_f_libs:\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 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 runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n linker_so = build_flib.fcompiler.get_linker_so()\n if linker_so is not None:\n self.compiler.linker_so = linker_so\n\n # end of fortran source support\n return old_build_ext.build_extension(self,ext)\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", "methods": [ { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 28, "complexity": 11, "token_count": 193, "parameters": [ "self", "ext" ], "start_line": 13, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "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": 45, "end_line": 54, "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": 25, "complexity": 10, "token_count": 178, "parameters": [ "self", "ext" ], "start_line": 13, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "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": 42, "end_line": 51, "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": 28, "complexity": 11, "token_count": 193, "parameters": [ "self", "ext" ], "start_line": 13, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 } ], "nloc": 43, "complexity": 13, "token_count": 284, "diff_parsed": { "added": [ " if build_flib.has_f_library(ext.name):", " need_f_libs = 1", " else:", " for lib_name in ext.libraries:", " if build_flib.has_f_library(lib_name):", " need_f_libs = 1", " break", " if moreargs != []:" ], "deleted": [ " for lib_name in ext.libraries:", " if build_flib.has_f_library(lib_name):", " need_f_libs = 1", " break", " if moreargs != []:" ] } } ] }, { "hash": "3e4586635bf5443887c4b781d4aa0a3cfc4a2a0a", "msg": "Forgot minor code fragment for prev. fix", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-02-14T20:36:28+00:00", "author_timezone": 0, "committer_date": "2002-02-14T20:36:28+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "d7048594f8955af6b85d0377c5ad2a3d9c32909e" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 2, "insertions": 5, "lines": 7, "files": 2, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/__version__.py", "new_path": "scipy_distutils/__version__.py", "filename": "__version__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,4 +1,4 @@\n # This file is automatically updated with update_version\n # function from scipy_distutils.misc_util.py\n-version = '0.6.23-alpha-98'\n-version_info = (0, 6, 23, 'alpha', 98)\n+version = '0.6.23-alpha-99'\n+version_info = (0, 6, 23, 'alpha', 99)\n", "added_lines": 2, "deleted_lines": 2, "source_code": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-99'\nversion_info = (0, 6, 23, 'alpha', 99)\n", "source_code_before": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-98'\nversion_info = (0, 6, 23, 'alpha', 98)\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 2, "complexity": 0, "token_count": 16, "diff_parsed": { "added": [ "version = '0.6.23-alpha-99'", "version_info = (0, 6, 23, 'alpha', 99)" ], "deleted": [ "version = '0.6.23-alpha-98'", "version_info = (0, 6, 23, 'alpha', 98)" ] } }, { "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": "@@ -29,6 +29,9 @@ def build_extension(self, ext):\n ext.extra_link_args = moreargs\n else:\n ext.extra_link_args += moreargs\n+ if build_flib.has_f_library(ext.name) and \\\n+ ext.name not in ext.libraries:\n+ ext.libraries.append(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", "added_lines": 3, "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 *\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n # support for building static fortran libraries\n need_f_libs = 0\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 if need_f_libs:\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 if build_flib.has_f_library(ext.name) and \\\n ext.name not in ext.libraries:\n ext.libraries.append(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 runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n linker_so = build_flib.fcompiler.get_linker_so()\n if linker_so is not None:\n self.compiler.linker_so = linker_so\n\n # end of fortran source support\n return old_build_ext.build_extension(self,ext)\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", "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 *\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n # support for building static fortran libraries\n need_f_libs = 0\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 if need_f_libs:\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 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 runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n linker_so = build_flib.fcompiler.get_linker_so()\n if linker_so is not None:\n self.compiler.linker_so = linker_so\n\n # end of fortran source support\n return old_build_ext.build_extension(self,ext)\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", "methods": [ { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 31, "complexity": 13, "token_count": 223, "parameters": [ "self", "ext" ], "start_line": 13, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 48, "end_line": 57, "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": 28, "complexity": 11, "token_count": 193, "parameters": [ "self", "ext" ], "start_line": 13, "end_line": 43, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "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": 45, "end_line": 54, "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": 31, "complexity": 13, "token_count": 223, "parameters": [ "self", "ext" ], "start_line": 13, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 1 } ], "nloc": 46, "complexity": 15, "token_count": 314, "diff_parsed": { "added": [ " if build_flib.has_f_library(ext.name) and \\", " ext.name not in ext.libraries:", " ext.libraries.append(ext.name)" ], "deleted": [] } } ] }, { "hash": "635ec7216d6c5c52b966a080054067577aee3882", "msg": "major refactoring -- renamed _specification classes to _converter. Moved all conversion lists to the converters.py module", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-02-14T21:22:22+00:00", "author_timezone": 0, "committer_date": "2002-02-14T21:22:22+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "3e4586635bf5443887c4b781d4aa0a3cfc4a2a0a" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 227, "insertions": 191, "lines": 418, "files": 20, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "weave/base_spec.py", "new_path": "weave/base_spec.py", "filename": "base_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,4 +1,4 @@\n-class base_specification:\n+class base_converter:\n \"\"\"\n Properties:\n headers -- list of strings that name the header files needed by this\n", "added_lines": 1, "deleted_lines": 1, "source_code": "class base_converter:\n \"\"\"\n Properties:\n headers -- list of strings that name the header files needed by this\n object.\n include_dirs -- list of directories where the header files can be found.\n libraries -- list of libraries needed to link to when compiling\n extension.\n library_dirs -- list of directories to search for libraries.\n\n support_code -- list of strings. Each string is a subroutine needed\n by the type. Functions that are used in the conversion\n between Python and C++ files are examples of these.\n\n Methods:\n\n type_match(value) returns 1 if this class is used to represent type\n specification for value.\n type_spec(name, value) returns a new object (of this class) that is\n used to produce C++ code for value.\n declaration_code() returns C++ code fragment for type declaration and\n conversion of python object to C++ object.\n cleanup_code() returns C++ code fragment for cleaning up after the\n variable after main C++ code fragment has executed.\n\n \"\"\"\n _build_information = []\n compiler = '' \n \n def set_compiler(self,compiler):\n self.compiler = compiler\n def type_match(self,value):\n raise NotImplementedError, \"You must override method in derived class\"\n def build_information(self):\n return self._build_information\n def type_spec(self,name,value): pass\n def declaration_code(self,templatize = 0): return \"\"\n def local_dict_code(self): return \"\"\n def cleanup_code(self): return \"\"\n def retrieve_py_variable(self,inline=0):\n # this needs a little coordination in name choices with the\n # ext_inline_function class.\n if inline:\n vn = 'get_variable(\"%s\",raw_locals,raw_globals)' % self.name\n else:\n vn = 'py_' + self.name \n return vn\n \n def py_reference(self):\n return \"&py_\" + self.name\n def py_pointer(self):\n return \"*py_\" + self.name\n def py_variable(self):\n return \"py_\" + self.name\n def reference(self):\n return \"&\" + self.name\n def pointer(self):\n return \"*\" + self.name\n def variable(self):\n return self.name\n def variable_as_string(self):\n return '\"' + self.name + '\"'\n\nimport UserList\nimport base_info\n\nclass arg_spec_list(UserList.UserList): \n def build_information(self): \n all_info = base_info.info_list()\n for i in self:\n all_info.extend(i.build_information())\n return all_info\n \n def py_references(self): return map(lambda x: x.py_reference(),self)\n def py_pointers(self): return map(lambda x: x.py_pointer(),self)\n def py_variables(self): return map(lambda x: x.py_variable(),self)\n\n def references(self): return map(lambda x: x.py_reference(),self)\n def pointers(self): return map(lambda x: x.pointer(),self) \n def variables(self): return map(lambda x: x.variable(),self)\n \n def variable_as_strings(self): \n return map(lambda x: x.variable_as_string(),self)\n\n ", "source_code_before": "class base_specification:\n \"\"\"\n Properties:\n headers -- list of strings that name the header files needed by this\n object.\n include_dirs -- list of directories where the header files can be found.\n libraries -- list of libraries needed to link to when compiling\n extension.\n library_dirs -- list of directories to search for libraries.\n\n support_code -- list of strings. Each string is a subroutine needed\n by the type. Functions that are used in the conversion\n between Python and C++ files are examples of these.\n\n Methods:\n\n type_match(value) returns 1 if this class is used to represent type\n specification for value.\n type_spec(name, value) returns a new object (of this class) that is\n used to produce C++ code for value.\n declaration_code() returns C++ code fragment for type declaration and\n conversion of python object to C++ object.\n cleanup_code() returns C++ code fragment for cleaning up after the\n variable after main C++ code fragment has executed.\n\n \"\"\"\n _build_information = []\n compiler = '' \n \n def set_compiler(self,compiler):\n self.compiler = compiler\n def type_match(self,value):\n raise NotImplementedError, \"You must override method in derived class\"\n def build_information(self):\n return self._build_information\n def type_spec(self,name,value): pass\n def declaration_code(self,templatize = 0): return \"\"\n def local_dict_code(self): return \"\"\n def cleanup_code(self): return \"\"\n def retrieve_py_variable(self,inline=0):\n # this needs a little coordination in name choices with the\n # ext_inline_function class.\n if inline:\n vn = 'get_variable(\"%s\",raw_locals,raw_globals)' % self.name\n else:\n vn = 'py_' + self.name \n return vn\n \n def py_reference(self):\n return \"&py_\" + self.name\n def py_pointer(self):\n return \"*py_\" + self.name\n def py_variable(self):\n return \"py_\" + self.name\n def reference(self):\n return \"&\" + self.name\n def pointer(self):\n return \"*\" + self.name\n def variable(self):\n return self.name\n def variable_as_string(self):\n return '\"' + self.name + '\"'\n\nimport UserList\nimport base_info\n\nclass arg_spec_list(UserList.UserList): \n def build_information(self): \n all_info = base_info.info_list()\n for i in self:\n all_info.extend(i.build_information())\n return all_info\n \n def py_references(self): return map(lambda x: x.py_reference(),self)\n def py_pointers(self): return map(lambda x: x.py_pointer(),self)\n def py_variables(self): return map(lambda x: x.py_variable(),self)\n\n def references(self): return map(lambda x: x.py_reference(),self)\n def pointers(self): return map(lambda x: x.pointer(),self) \n def variables(self): return map(lambda x: x.variable(),self)\n \n def variable_as_strings(self): \n return map(lambda x: x.variable_as_string(),self)\n\n ", "methods": [ { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "compiler" ], "start_line": 30, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "value" ], "start_line": 32, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "build_information", "long_name": "build_information( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 34, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "retrieve_py_variable", "long_name": "retrieve_py_variable( self , inline = 0 )", "filename": "base_spec.py", "nloc": 6, "complexity": 2, "token_count": 30, "parameters": [ "self", "inline" ], "start_line": 40, "end_line": 47, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "py_reference", "long_name": "py_reference( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 49, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "py_pointer", "long_name": "py_pointer( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 51, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "py_variable", "long_name": "py_variable( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 53, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "reference", "long_name": "reference( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 55, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "pointer", "long_name": "pointer( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 57, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "variable", "long_name": "variable( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 59, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "variable_as_string", "long_name": "variable_as_string( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 61, "end_line": 62, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "build_information", "long_name": "build_information( self )", "filename": "base_spec.py", "nloc": 5, "complexity": 2, "token_count": 29, "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": "variable_as_strings", "long_name": "variable_as_strings( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 82, "end_line": 83, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "set_compiler", "long_name": "set_compiler( self , compiler )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "compiler" ], "start_line": 30, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "value" ], "start_line": 32, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "build_information", "long_name": "build_information( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 34, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "retrieve_py_variable", "long_name": "retrieve_py_variable( self , inline = 0 )", "filename": "base_spec.py", "nloc": 6, "complexity": 2, "token_count": 30, "parameters": [ "self", "inline" ], "start_line": 40, "end_line": 47, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "py_reference", "long_name": "py_reference( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 49, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "py_pointer", "long_name": "py_pointer( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 51, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "py_variable", "long_name": "py_variable( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 53, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "reference", "long_name": "reference( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 55, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "pointer", "long_name": "pointer( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 57, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "variable", "long_name": "variable( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 59, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "variable_as_string", "long_name": "variable_as_string( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 61, "end_line": 62, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "build_information", "long_name": "build_information( self )", "filename": "base_spec.py", "nloc": 5, "complexity": 2, "token_count": 29, "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": "variable_as_strings", "long_name": "variable_as_strings( self )", "filename": "base_spec.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 82, "end_line": 83, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 74, "complexity": 15, "token_count": 382, "diff_parsed": { "added": [ "class base_converter:" ], "deleted": [ "class base_specification:" ] } }, { "old_path": "weave/blitz_spec.py", "new_path": "weave/blitz_spec.py", "filename": "blitz_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,19 +1,18 @@\n-from base_spec import base_specification\n-from scalar_spec import numeric_to_blitz_type_mapping\n+from base_spec import base_converter\n+from scalar_spec import numeric_to_c_type_mapping\n from Numeric import *\n from types import *\n import os\n import blitz_info\n \n-class array_specification(base_specification):\n+class array_converter(base_converter):\n _build_information = [blitz_info.array_info()]\n \n def type_match(self,value):\n return type(value) is ArrayType\n \n def type_spec(self,name,value):\n- # factory\n- new_spec = array_specification()\n+ new_spec = array_converter()\n new_spec.name = name\n new_spec.numeric_type = value.typecode()\n new_spec.dims = len(value.shape)\n@@ -31,7 +30,7 @@ def declaration_code(self,templatize = 0,inline=0):\n return code\n \n def inline_decl_code(self):\n- type = numeric_to_blitz_type_mapping[self.numeric_type]\n+ type = numeric_to_c_type_mapping[self.numeric_type]\n dims = self.dims\n name = self.name\n var_name = self.retrieve_py_variable(inline=1)\n@@ -47,17 +46,11 @@ def inline_decl_code(self):\n 'blitz::Array<%(type)s,%(dims)d> %(name)s =' \\\n ' convert_to_blitz<%(type)s,%(dims)d>(%(arr_name)s,\"%(name)s\");\\n' \\\n 'blitz::TinyVector _N%(name)s = %(name)s.shape();\\n'\n- # old version\n- #templ = '// blitz_array_declaration\\n' \\\n- # 'py_%(name)s= %(var_name)s;\\n' \\\n- # 'blitz::Array<%(type)s,%(dims)d> %(name)s =' \\\n- # ' convert_to_blitz<%(type)s,%(dims)d>(py_%(name)s,\"%(name)s\");\\n' \\\n- # 'blitz::TinyVector _N%(name)s = %(name)s.shape();\\n'\n code = templ % locals()\n return code\n \n def standard_decl_code(self):\n- type = numeric_to_blitz_type_mapping[self.numeric_type]\n+ type = numeric_to_c_type_mapping[self.numeric_type]\n dims = self.dims\n name = self.name\n var_name = self.retrieve_py_variable(inline=0)\n@@ -72,24 +65,8 @@ def standard_decl_code(self):\n 'blitz::Array<%(type)s,%(dims)d> %(name)s =' \\\n ' convert_to_blitz<%(type)s,%(dims)d>(%(arr_name)s,\"%(name)s\");\\n' \\\n 'blitz::TinyVector _N%(name)s = %(name)s.shape();\\n'\n- # old version\n- #templ = '// blitz_array_declaration\\n' \\\n- # 'blitz::Array<%(type)s,%(dims)d> %(name)s =' \\\n- # ' convert_to_blitz<%(type)s,%(dims)d>(%(var_name)s,\"%(name)s\");\\n' \\\n- # 'blitz::TinyVector _N%(name)s = %(name)s.shape();\\n'\n code = templ % locals()\n return code\n- #def c_function_declaration_code(self):\n- # \"\"\"\n- # This doesn't pass the size through. That info is gonna have to\n- # be redone in the c function.\n- # \"\"\"\n- # templ_dict = {}\n- # templ_dict['type'] = numeric_to_blitz_type_mapping[self.numeric_type]\n- # templ_dict['dims'] = self.dims\n- # templ_dict['name'] = self.name\n- # code = 'blitz::Array<%(type)s,%(dims)d> &%(name)s' % templ_dict\n- # return code\n \n def local_dict_code(self):\n code = '// for now, array \"%s\" is not returned as arryas are edited' \\\n@@ -113,6 +90,3 @@ def __cmp__(self,other):\n cmp(self.dims, other.dims) or \\\n cmp(self.__class__, other.__class__)\n \n-# stick this factory on the front of the type factories\n-import ext_tools\n-blitz_aware_factories = [array_specification()] + ext_tools.default_type_factories\n", "added_lines": 6, "deleted_lines": 32, "source_code": "from base_spec import base_converter\nfrom scalar_spec import numeric_to_c_type_mapping\nfrom Numeric import *\nfrom types import *\nimport os\nimport blitz_info\n\nclass array_converter(base_converter):\n _build_information = [blitz_info.array_info()]\n\n def type_match(self,value):\n return type(value) is ArrayType\n\n def type_spec(self,name,value):\n new_spec = array_converter()\n new_spec.name = name\n new_spec.numeric_type = value.typecode()\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 declaration_code(self,templatize = 0,inline=0):\n if inline:\n code = self.inline_decl_code()\n else:\n code = self.standard_decl_code()\n return code\n\n def inline_decl_code(self):\n type = numeric_to_c_type_mapping[self.numeric_type]\n dims = self.dims\n name = self.name\n var_name = self.retrieve_py_variable(inline=1)\n arr_name = name + '_arr_obj'\n # We've had to inject quite a bit of code in here to handle the Aborted error\n # caused by exceptions. The templates made the easy fix (with MACROS) for all\n # other types difficult here. Oh well.\n templ = '// blitz_array_declaration\\n' \\\n 'py_%(name)s= %(var_name)s;\\n' \\\n 'PyArrayObject* %(arr_name)s = convert_to_numpy(py_%(name)s,\"%(name)s\");\\n' \\\n 'conversion_numpy_check_size(%(arr_name)s,%(dims)s,\"%(name)s\");\\n' \\\n 'conversion_numpy_check_type(%(arr_name)s,py_type<%(type)s>::code,\"%(name)s\");\\n' \\\n 'blitz::Array<%(type)s,%(dims)d> %(name)s =' \\\n ' convert_to_blitz<%(type)s,%(dims)d>(%(arr_name)s,\"%(name)s\");\\n' \\\n 'blitz::TinyVector _N%(name)s = %(name)s.shape();\\n'\n code = templ % locals()\n return code\n\n def standard_decl_code(self):\n type = numeric_to_c_type_mapping[self.numeric_type]\n dims = self.dims\n name = self.name\n var_name = self.retrieve_py_variable(inline=0)\n arr_name = name + '_arr_obj'\n # We've had to inject quite a bit of code in here to handle the Aborted error\n # caused by exceptions. The templates made the easy fix (with MACROS) for all\n # other types difficult here. Oh well.\n templ = '// blitz_array_declaration\\n' \\\n 'PyArrayObject* %(arr_name)s = convert_to_numpy(%(var_name)s,\"%(name)s\");\\n' \\\n 'conversion_numpy_check_size(%(arr_name)s,%(dims)s,\"%(name)s\");\\n' \\\n 'conversion_numpy_check_type(%(arr_name)s,py_type<%(type)s>::code,\"%(name)s\");\\n' \\\n 'blitz::Array<%(type)s,%(dims)d> %(name)s =' \\\n ' convert_to_blitz<%(type)s,%(dims)d>(%(arr_name)s,\"%(name)s\");\\n' \\\n 'blitz::TinyVector _N%(name)s = %(name)s.shape();\\n'\n code = templ % locals()\n return code\n\n def local_dict_code(self):\n code = '// for now, array \"%s\" is not returned as arryas are edited' \\\n ' in place (should this change?)\\n' % (self.name)\n return code\n\n def cleanup_code(self):\n # could use Py_DECREF here I think and save NULL test.\n code = \"Py_XDECREF(py_%s);\\n\" % self.name\n return code\n\n def __repr__(self):\n msg = \"(array:: name: %s, type: %s, dims: %d)\" % \\\n (self.name, self.numeric_type, self.dims)\n return msg\n\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.dims, other.dims) or \\\n cmp(self.__class__, other.__class__)\n\n", "source_code_before": "from base_spec import base_specification\nfrom scalar_spec import numeric_to_blitz_type_mapping\nfrom Numeric import *\nfrom types import *\nimport os\nimport blitz_info\n\nclass array_specification(base_specification):\n _build_information = [blitz_info.array_info()]\n\n def type_match(self,value):\n return type(value) is ArrayType\n\n def type_spec(self,name,value):\n # factory\n new_spec = array_specification()\n new_spec.name = name\n new_spec.numeric_type = value.typecode()\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 declaration_code(self,templatize = 0,inline=0):\n if inline:\n code = self.inline_decl_code()\n else:\n code = self.standard_decl_code()\n return code\n\n def inline_decl_code(self):\n type = numeric_to_blitz_type_mapping[self.numeric_type]\n dims = self.dims\n name = self.name\n var_name = self.retrieve_py_variable(inline=1)\n arr_name = name + '_arr_obj'\n # We've had to inject quite a bit of code in here to handle the Aborted error\n # caused by exceptions. The templates made the easy fix (with MACROS) for all\n # other types difficult here. Oh well.\n templ = '// blitz_array_declaration\\n' \\\n 'py_%(name)s= %(var_name)s;\\n' \\\n 'PyArrayObject* %(arr_name)s = convert_to_numpy(py_%(name)s,\"%(name)s\");\\n' \\\n 'conversion_numpy_check_size(%(arr_name)s,%(dims)s,\"%(name)s\");\\n' \\\n 'conversion_numpy_check_type(%(arr_name)s,py_type<%(type)s>::code,\"%(name)s\");\\n' \\\n 'blitz::Array<%(type)s,%(dims)d> %(name)s =' \\\n ' convert_to_blitz<%(type)s,%(dims)d>(%(arr_name)s,\"%(name)s\");\\n' \\\n 'blitz::TinyVector _N%(name)s = %(name)s.shape();\\n'\n # old version\n #templ = '// blitz_array_declaration\\n' \\\n # 'py_%(name)s= %(var_name)s;\\n' \\\n # 'blitz::Array<%(type)s,%(dims)d> %(name)s =' \\\n # ' convert_to_blitz<%(type)s,%(dims)d>(py_%(name)s,\"%(name)s\");\\n' \\\n # 'blitz::TinyVector _N%(name)s = %(name)s.shape();\\n'\n code = templ % locals()\n return code\n\n def standard_decl_code(self):\n type = numeric_to_blitz_type_mapping[self.numeric_type]\n dims = self.dims\n name = self.name\n var_name = self.retrieve_py_variable(inline=0)\n arr_name = name + '_arr_obj'\n # We've had to inject quite a bit of code in here to handle the Aborted error\n # caused by exceptions. The templates made the easy fix (with MACROS) for all\n # other types difficult here. Oh well.\n templ = '// blitz_array_declaration\\n' \\\n 'PyArrayObject* %(arr_name)s = convert_to_numpy(%(var_name)s,\"%(name)s\");\\n' \\\n 'conversion_numpy_check_size(%(arr_name)s,%(dims)s,\"%(name)s\");\\n' \\\n 'conversion_numpy_check_type(%(arr_name)s,py_type<%(type)s>::code,\"%(name)s\");\\n' \\\n 'blitz::Array<%(type)s,%(dims)d> %(name)s =' \\\n ' convert_to_blitz<%(type)s,%(dims)d>(%(arr_name)s,\"%(name)s\");\\n' \\\n 'blitz::TinyVector _N%(name)s = %(name)s.shape();\\n'\n # old version\n #templ = '// blitz_array_declaration\\n' \\\n # 'blitz::Array<%(type)s,%(dims)d> %(name)s =' \\\n # ' convert_to_blitz<%(type)s,%(dims)d>(%(var_name)s,\"%(name)s\");\\n' \\\n # 'blitz::TinyVector _N%(name)s = %(name)s.shape();\\n'\n code = templ % locals()\n return code\n #def c_function_declaration_code(self):\n # \"\"\"\n # This doesn't pass the size through. That info is gonna have to\n # be redone in the c function.\n # \"\"\"\n # templ_dict = {}\n # templ_dict['type'] = numeric_to_blitz_type_mapping[self.numeric_type]\n # templ_dict['dims'] = self.dims\n # templ_dict['name'] = self.name\n # code = 'blitz::Array<%(type)s,%(dims)d> &%(name)s' % templ_dict\n # return code\n\n def local_dict_code(self):\n code = '// for now, array \"%s\" is not returned as arryas are edited' \\\n ' in place (should this change?)\\n' % (self.name)\n return code\n\n def cleanup_code(self):\n # could use Py_DECREF here I think and save NULL test.\n code = \"Py_XDECREF(py_%s);\\n\" % self.name\n return code\n\n def __repr__(self):\n msg = \"(array:: name: %s, type: %s, dims: %d)\" % \\\n (self.name, self.numeric_type, self.dims)\n return msg\n\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.dims, other.dims) or \\\n cmp(self.__class__, other.__class__)\n\n# stick this factory on the front of the type factories\nimport ext_tools\nblitz_aware_factories = [array_specification()] + ext_tools.default_type_factories\n", "methods": [ { "name": "type_match", "long_name": "type_match( self , value )", "filename": "blitz_spec.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "value" ], "start_line": 11, "end_line": 12, "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": 10, "complexity": 2, "token_count": 60, "parameters": [ "self", "name", "value" ], "start_line": 14, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "blitz_spec.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "templatize", "inline" ], "start_line": 25, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "inline_decl_code", "long_name": "inline_decl_code( self )", "filename": "blitz_spec.py", "nloc": 16, "complexity": 1, "token_count": 64, "parameters": [ "self" ], "start_line": 32, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "standard_decl_code", "long_name": "standard_decl_code( self )", "filename": "blitz_spec.py", "nloc": 15, "complexity": 1, "token_count": 62, "parameters": [ "self" ], "start_line": 52, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "blitz_spec.py", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 71, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "blitz_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 76, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "blitz_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "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": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "blitz_spec.py", "nloc": 5, "complexity": 4, "token_count": 54, "parameters": [ "self", "other" ], "start_line": 86, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "methods_before": [ { "name": "type_match", "long_name": "type_match( self , value )", "filename": "blitz_spec.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "value" ], "start_line": 11, "end_line": 12, "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": 10, "complexity": 2, "token_count": 60, "parameters": [ "self", "name", "value" ], "start_line": 14, "end_line": 24, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "blitz_spec.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "templatize", "inline" ], "start_line": 26, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "inline_decl_code", "long_name": "inline_decl_code( self )", "filename": "blitz_spec.py", "nloc": 16, "complexity": 1, "token_count": 64, "parameters": [ "self" ], "start_line": 33, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "standard_decl_code", "long_name": "standard_decl_code( self )", "filename": "blitz_spec.py", "nloc": 15, "complexity": 1, "token_count": 62, "parameters": [ "self" ], "start_line": 59, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "blitz_spec.py", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 94, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "blitz_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "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": "__repr__", "long_name": "__repr__( self )", "filename": "blitz_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 104, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "blitz_spec.py", "nloc": 5, "complexity": 4, "token_count": 54, "parameters": [ "self", "other" ], "start_line": 109, "end_line": 114, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "inline_decl_code", "long_name": "inline_decl_code( self )", "filename": "blitz_spec.py", "nloc": 16, "complexity": 1, "token_count": 64, "parameters": [ "self" ], "start_line": 32, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "blitz_spec.py", "nloc": 10, "complexity": 2, "token_count": 60, "parameters": [ "self", "name", "value" ], "start_line": 14, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "standard_decl_code", "long_name": "standard_decl_code( self )", "filename": "blitz_spec.py", "nloc": 15, "complexity": 1, "token_count": 62, "parameters": [ "self" ], "start_line": 52, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 } ], "nloc": 73, "complexity": 14, "token_count": 389, "diff_parsed": { "added": [ "from base_spec import base_converter", "from scalar_spec import numeric_to_c_type_mapping", "class array_converter(base_converter):", " new_spec = array_converter()", " type = numeric_to_c_type_mapping[self.numeric_type]", " type = numeric_to_c_type_mapping[self.numeric_type]" ], "deleted": [ "from base_spec import base_specification", "from scalar_spec import numeric_to_blitz_type_mapping", "class array_specification(base_specification):", " # factory", " new_spec = array_specification()", " type = numeric_to_blitz_type_mapping[self.numeric_type]", " # old version", " #templ = '// blitz_array_declaration\\n' \\", " # 'py_%(name)s= %(var_name)s;\\n' \\", " # 'blitz::Array<%(type)s,%(dims)d> %(name)s =' \\", " # ' convert_to_blitz<%(type)s,%(dims)d>(py_%(name)s,\"%(name)s\");\\n' \\", " # 'blitz::TinyVector _N%(name)s = %(name)s.shape();\\n'", " type = numeric_to_blitz_type_mapping[self.numeric_type]", " # old version", " #templ = '// blitz_array_declaration\\n' \\", " # 'blitz::Array<%(type)s,%(dims)d> %(name)s =' \\", " # ' convert_to_blitz<%(type)s,%(dims)d>(%(var_name)s,\"%(name)s\");\\n' \\", " # 'blitz::TinyVector _N%(name)s = %(name)s.shape();\\n'", " #def c_function_declaration_code(self):", " # \"\"\"", " # This doesn't pass the size through. That info is gonna have to", " # be redone in the c function.", " # \"\"\"", " # templ_dict = {}", " # templ_dict['type'] = numeric_to_blitz_type_mapping[self.numeric_type]", " # templ_dict['dims'] = self.dims", " # templ_dict['name'] = self.name", " # code = 'blitz::Array<%(type)s,%(dims)d> &%(name)s' % templ_dict", " # return code", "# stick this factory on the front of the type factories", "import ext_tools", "blitz_aware_factories = [array_specification()] + ext_tools.default_type_factories" ] } }, { "old_path": "weave/blitz_tools.py", "new_path": "weave/blitz_tools.py", "filename": "blitz_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -22,35 +22,7 @@\n from inline_tools import attempt_function_call\n function_catalog = inline_tools.function_catalog\n function_cache = inline_tools.function_cache\n-\n-# this is pretty much the same as the default factories.\n-# We've just replaced the array specification with the blitz\n-# specification\n-import base_spec\n-import scalar_spec\n-import sequence_spec\n-import common_spec\n-from blitz_spec import array_specification\n-blitz_type_factories = [sequence_spec.string_specification(),\n- sequence_spec.list_specification(),\n- sequence_spec.dict_specification(),\n- sequence_spec.tuple_specification(),\n- scalar_spec.int_specification(),\n- scalar_spec.float_specification(),\n- scalar_spec.complex_specification(),\n- common_spec.file_specification(),\n- common_spec.callable_specification(),\n- array_specification()]\n- #common_spec.instance_specification(), \n- #common_spec.module_specification()]\n-\n-try: \n- # this is currently safe because it doesn't import wxPython.\n- import wx_spec\n- default_type_factories.append(wx_spec.wx_specification())\n-except: \n- pass \n- \n+ \n def 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@@ -96,7 +68,7 @@ def blitz(expr,local_dict=None, global_dict=None,check_size=1,verbose=0,**kw):\n global_dict,module_dir,\n compiler='gcc',auto_downcast=1,\n verbose = verbose,\n- type_factories = blitz_type_factories,\n+ type_converters = converters.blitz,\n **kw)\n function_catalog.add_function(expr,func,module_dir)\n try: \n", "added_lines": 2, "deleted_lines": 30, "source_code": "import parser\nimport string\nimport copy\nimport os,sys\nimport ast_tools\nimport token,symbol\nimport slice_handler\nimport size_check\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 fastumath import *\nexcept:\n pass # 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 from code_blocks import module_header\n\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 \"\"\"\n ast_list = ast.tolist()\n \n expr_code = ast_to_blitz_expr(ast_list)\n arg_list = harvest_variables(ast_list)\n arg_specs = assign_variable_types(arg_list,locals())\n \n func,template_types = create_function('test_function',expr_code,arg_list,arg_specs)\n init,used_names = create_module_init('compile_sample','test_function',template_types)\n #wrapper = create_wrapper(mod_name,func_name,used_names)\n return string.join( [module_header,func,init],'\\n')\n \"\"\"\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n\nif __name__ == \"__main__\":\n test_function()", "source_code_before": "import parser\nimport string\nimport copy\nimport os,sys\nimport ast_tools\nimport token,symbol\nimport slice_handler\nimport size_check\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 fastumath import *\nexcept:\n pass # 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\n# this is pretty much the same as the default factories.\n# We've just replaced the array specification with the blitz\n# specification\nimport base_spec\nimport scalar_spec\nimport sequence_spec\nimport common_spec\nfrom blitz_spec import array_specification\nblitz_type_factories = [sequence_spec.string_specification(),\n sequence_spec.list_specification(),\n sequence_spec.dict_specification(),\n sequence_spec.tuple_specification(),\n scalar_spec.int_specification(),\n scalar_spec.float_specification(),\n scalar_spec.complex_specification(),\n common_spec.file_specification(),\n common_spec.callable_specification(),\n array_specification()]\n #common_spec.instance_specification(), \n #common_spec.module_specification()]\n\ntry: \n # this is currently safe because it doesn't import wxPython.\n import wx_spec\n default_type_factories.append(wx_spec.wx_specification())\nexcept: \n pass \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_factories = blitz_type_factories,\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 from code_blocks import module_header\n\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 \"\"\"\n ast_list = ast.tolist()\n \n expr_code = ast_to_blitz_expr(ast_list)\n arg_list = harvest_variables(ast_list)\n arg_specs = assign_variable_types(arg_list,locals())\n \n func,template_types = create_function('test_function',expr_code,arg_list,arg_specs)\n init,used_names = create_module_init('compile_sample','test_function',template_types)\n #wrapper = create_wrapper(mod_name,func_name,used_names)\n return string.join( [module_header,func,init],'\\n')\n \"\"\"\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n\nif __name__ == \"__main__\":\n test_function()", "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": 26, "end_line": 78, "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": 80, "end_line": 116, "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": 26, "complexity": 1, "token_count": 128, "parameters": [], "start_line": 118, "end_line": 145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 146, "end_line": 148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 150, "end_line": 152, "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": 214, "parameters": [ "expr", "local_dict", "global_dict", "check_size", "verbose", "kw" ], "start_line": 54, "end_line": 106, "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": 108, "end_line": 144, "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": 26, "complexity": 1, "token_count": 128, "parameters": [], "start_line": 146, "end_line": 173, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 174, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 178, "end_line": 180, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_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": 26, "end_line": 78, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 53, "top_nesting_level": 0 } ], "nloc": 97, "complexity": 12, "token_count": 535, "diff_parsed": { "added": [ "", " type_converters = converters.blitz," ], "deleted": [ "", "# this is pretty much the same as the default factories.", "# We've just replaced the array specification with the blitz", "# specification", "import base_spec", "import scalar_spec", "import sequence_spec", "import common_spec", "from blitz_spec import array_specification", "blitz_type_factories = [sequence_spec.string_specification(),", " sequence_spec.list_specification(),", " sequence_spec.dict_specification(),", " sequence_spec.tuple_specification(),", " scalar_spec.int_specification(),", " scalar_spec.float_specification(),", " scalar_spec.complex_specification(),", " common_spec.file_specification(),", " common_spec.callable_specification(),", " array_specification()]", " #common_spec.instance_specification(),", " #common_spec.module_specification()]", "", "try:", " # this is currently safe because it doesn't import wxPython.", " import wx_spec", " default_type_factories.append(wx_spec.wx_specification())", "except:", " pass", "", " type_factories = blitz_type_factories," ] } }, { "old_path": "weave/common_spec.py", "new_path": "weave/common_spec.py", "filename": "common_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,9 +1,9 @@\n-from base_spec import base_specification\n+from base_spec import base_converter\n import common_info\n from types import *\n import os\n \n-class common_base_specification(base_specification):\n+class common_base_converter(base_converter):\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n@@ -18,7 +18,7 @@ def __cmp__(self,other):\n cmp(self.__class__, other.__class__)\n \n \n-class file_specification(common_base_specification):\n+class file_converter(common_base_converter):\n type_name = 'file'\n _build_information = [common_info.file_info()]\n def type_match(self,value):\n@@ -38,7 +38,7 @@ def cleanup_code(self):\n code = \"Py_XDECREF(py_%s);\\n\" % self.name\n return code\n \n-class callable_specification(common_base_specification):\n+class callable_converter(common_base_converter):\n type_name = 'callable'\n _build_information = [common_info.callable_info()]\n def type_match(self,value):\n@@ -51,7 +51,7 @@ def declaration_code(self,templatize = 0,inline=0):\n (self.name,var_name,self.name)\n return code \n \n-class instance_specification(common_base_specification):\n+class instance_converter(common_base_converter):\n type_name = 'instance'\n _build_information = [common_info.instance_info()]\n def type_match(self,value):\n", "added_lines": 5, "deleted_lines": 5, "source_code": "from base_spec import base_converter\nimport common_info\nfrom types import *\nimport os\n\nclass common_base_converter(base_converter):\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n return new_spec\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 return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n \n \nclass file_converter(common_base_converter):\n type_name = 'file'\n _build_information = [common_info.file_info()]\n def type_match(self,value):\n return type(value) in [FileType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n #code = 'PyObject* py_%s = %s;\\n' \\\n # 'FILE* %s = convert_to_file(py_%s,\"%s\");\\n' % \\\n # (self.name,var_name,self.name,self.name,self.name)\n code = 'PyObject* py_%s = %s;\\n' \\\n 'FILE* %s = convert_to_file(py_%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name,self.name,self.name)\n return code \n def cleanup_code(self):\n # could use Py_DECREF here I think and save NULL test.\n code = \"Py_XDECREF(py_%s);\\n\" % self.name\n return code\n\nclass callable_converter(common_base_converter):\n type_name = 'callable'\n _build_information = [common_info.callable_info()]\n def type_match(self,value):\n # probably should test for callable classes here also.\n return type(value) in [FunctionType,MethodType,type(len)]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'PyObject* %s = convert_to_callable(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n\nclass instance_converter(common_base_converter):\n type_name = 'instance'\n _build_information = [common_info.instance_info()]\n def type_match(self,value):\n return type(value) in [InstanceType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'PyObject* %s = convert_to_instance(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n", "source_code_before": "from base_spec import base_specification\nimport common_info\nfrom types import *\nimport os\n\nclass common_base_specification(base_specification):\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n return new_spec\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 return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n \n \nclass file_specification(common_base_specification):\n type_name = 'file'\n _build_information = [common_info.file_info()]\n def type_match(self,value):\n return type(value) in [FileType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n #code = 'PyObject* py_%s = %s;\\n' \\\n # 'FILE* %s = convert_to_file(py_%s,\"%s\");\\n' % \\\n # (self.name,var_name,self.name,self.name,self.name)\n code = 'PyObject* py_%s = %s;\\n' \\\n 'FILE* %s = convert_to_file(py_%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name,self.name,self.name)\n return code \n def cleanup_code(self):\n # could use Py_DECREF here I think and save NULL test.\n code = \"Py_XDECREF(py_%s);\\n\" % self.name\n return code\n\nclass callable_specification(common_base_specification):\n type_name = 'callable'\n _build_information = [common_info.callable_info()]\n def type_match(self,value):\n # probably should test for callable classes here also.\n return type(value) in [FunctionType,MethodType,type(len)]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'PyObject* %s = convert_to_callable(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n\nclass instance_specification(common_base_specification):\n type_name = 'instance'\n _build_information = [common_info.instance_info()]\n def type_match(self,value):\n return type(value) in [InstanceType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'PyObject* %s = convert_to_instance(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n", "methods": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "common_spec.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "self", "name", "value" ], "start_line": 7, "end_line": 11, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 12, "end_line": 14, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "common_spec.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "self", "other" ], "start_line": 15, "end_line": 18, "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": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 24, "end_line": 25, "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": "common_spec.py", "nloc": 6, "complexity": 1, "token_count": 49, "parameters": [ "self", "templatize", "inline" ], "start_line": 27, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 36, "end_line": 39, "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": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "value" ], "start_line": 44, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "common_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 48, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 57, "end_line": 58, "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": "common_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 60, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 70, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "common_spec.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "self", "name", "value" ], "start_line": 7, "end_line": 11, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 12, "end_line": 14, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "common_spec.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "self", "other" ], "start_line": 15, "end_line": 18, "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": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 24, "end_line": 25, "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": "common_spec.py", "nloc": 6, "complexity": 1, "token_count": 49, "parameters": [ "self", "templatize", "inline" ], "start_line": 27, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 36, "end_line": 39, "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": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "value" ], "start_line": 44, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "common_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 48, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 57, "end_line": 58, "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": "common_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 60, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 70, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 55, "complexity": 13, "token_count": 376, "diff_parsed": { "added": [ "from base_spec import base_converter", "class common_base_converter(base_converter):", "class file_converter(common_base_converter):", "class callable_converter(common_base_converter):", "class instance_converter(common_base_converter):" ], "deleted": [ "from base_spec import base_specification", "class common_base_specification(base_specification):", "class file_specification(common_base_specification):", "class callable_specification(common_base_specification):", "class instance_specification(common_base_specification):" ] } }, { "old_path": null, "new_path": "weave/converters.py", "filename": "converters.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,48 @@\n+\"\"\" converters.py\n+\"\"\"\n+\n+\n+import base_spec\n+import scalar_spec\n+import sequence_spec\n+import common_spec\n+\n+\n+#--------------------------------------------------------\n+# The \"standard\" conversion classes\n+#--------------------------------------------------------\n+\n+default = [scalar_spec.int_converter(),\n+ scalar_spec.float_converter(),\n+ scalar_spec.complex_converter(),\n+ sequence_spec.string_converter(),\n+ sequence_spec.list_converter(),\n+ sequence_spec.dict_converter(),\n+ sequence_spec.tuple_converter(),\n+ common_spec.file_converter(),\n+ common_spec.callable_converter(),\n+ common_spec.instance_converter(),] \n+ #common_spec.module_converter()]\n+\n+try: \n+ import standard_array_spec\n+ default.append(standard_array_spec.array_converter())\n+except: \n+ pass \n+\n+try: \n+ # this is currently safe because it doesn't import wxPython.\n+ import wx_spec\n+ default.append(wx_spec.wx_converter())\n+except: \n+ pass \n+\n+#--------------------------------------------------------\n+# Blitz conversion classes\n+#\n+# same as default, but will convert Numeric arrays to blitz\n+# C++ classes \n+#--------------------------------------------------------\n+import blitz_spec\n+blitz = [blitz_spec.array_converter()] + default\n+\n", "added_lines": 48, "deleted_lines": 0, "source_code": "\"\"\" converters.py\n\"\"\"\n\n\nimport base_spec\nimport scalar_spec\nimport sequence_spec\nimport common_spec\n\n\n#--------------------------------------------------------\n# The \"standard\" conversion classes\n#--------------------------------------------------------\n\ndefault = [scalar_spec.int_converter(),\n scalar_spec.float_converter(),\n scalar_spec.complex_converter(),\n sequence_spec.string_converter(),\n sequence_spec.list_converter(),\n sequence_spec.dict_converter(),\n sequence_spec.tuple_converter(),\n common_spec.file_converter(),\n common_spec.callable_converter(),\n common_spec.instance_converter(),] \n #common_spec.module_converter()]\n\ntry: \n import standard_array_spec\n default.append(standard_array_spec.array_converter())\nexcept: \n pass \n\ntry: \n # this is currently safe because it doesn't import wxPython.\n import wx_spec\n default.append(wx_spec.wx_converter())\nexcept: \n pass \n\n#--------------------------------------------------------\n# Blitz conversion classes\n#\n# same as default, but will convert Numeric arrays to blitz\n# C++ classes \n#--------------------------------------------------------\nimport blitz_spec\nblitz = [blitz_spec.array_converter()] + default\n\n", "source_code_before": null, "methods": [], "methods_before": [], "changed_methods": [], "nloc": 28, "complexity": 0, "token_count": 120, "diff_parsed": { "added": [ "\"\"\" converters.py", "\"\"\"", "", "", "import base_spec", "import scalar_spec", "import sequence_spec", "import common_spec", "", "", "#--------------------------------------------------------", "# The \"standard\" conversion classes", "#--------------------------------------------------------", "", "default = [scalar_spec.int_converter(),", " scalar_spec.float_converter(),", " scalar_spec.complex_converter(),", " sequence_spec.string_converter(),", " sequence_spec.list_converter(),", " sequence_spec.dict_converter(),", " sequence_spec.tuple_converter(),", " common_spec.file_converter(),", " common_spec.callable_converter(),", " common_spec.instance_converter(),]", " #common_spec.module_converter()]", "", "try:", " import standard_array_spec", " default.append(standard_array_spec.array_converter())", "except:", " pass", "", "try:", " # this is currently safe because it doesn't import wxPython.", " import wx_spec", " default.append(wx_spec.wx_converter())", "except:", " pass", "", "#--------------------------------------------------------", "# Blitz conversion classes", "#", "# same as default, but will convert Numeric arrays to blitz", "# C++ classes", "#--------------------------------------------------------", "import blitz_spec", "blitz = [blitz_spec.array_converter()] + default", "" ], "deleted": [] } }, { "old_path": "weave/examples/cast_copy_transpose.py", "new_path": "weave/examples/cast_copy_transpose.py", "filename": "cast_copy_transpose.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -20,27 +20,27 @@\n sys.path.insert(0,'..')\n import inline_tools\n import scalar_spec\n-from blitz_tools import blitz_type_factories\n+from blitz_tools import blitz_type_converters\n \n def _cast_copy_transpose(type,a_2d):\n assert(len(shape(a_2d)) == 2)\n new_array = zeros(shape(a_2d),type)\n #trans_a_2d = transpose(a_2d)\n- numeric_type = scalar_spec.numeric_to_blitz_type_mapping[type]\n+ numeric_type = scalar_spec.numeric_to_c_type_mapping[type]\n code = \"\"\"\n for(int i = 0; i < _Na_2d[0]; i++)\n for(int j = 0; j < _Na_2d[1]; j++)\n new_array(i,j) = (%s) a_2d(j,i);\n \"\"\" % numeric_type\n inline_tools.inline(code,['new_array','a_2d'],\n- type_factories = blitz_type_factories,\n+ type_converters = blitz_type_converters,\n compiler='gcc',\n verbose = 1)\n return new_array\n \n def _inplace_transpose(a_2d):\n assert(len(shape(a_2d)) == 2)\n- numeric_type = scalar_spec.numeric_to_blitz_type_mapping[a_2d.typecode()]\n+ numeric_type = scalar_spec.numeric_to_c_type_mapping[a_2d.typecode()]\n code = \"\"\"\n %s temp;\n for(int i = 0; i < _Na_2d[0]; i++)\n@@ -52,19 +52,19 @@ def _inplace_transpose(a_2d):\n } \n \"\"\" % numeric_type\n inline_tools.inline(code,['a_2d'],\n- type_factories = blitz_type_factories,\n+ type_converters = blitz_type_converters,\n compiler='gcc',def _cast_copy_transpose(type,a_2d):\n assert(len(shape(a_2d)) == 2)\n new_array = zeros(shape(a_2d),type)\n #trans_a_2d = transpose(a_2d)\n- numeric_type = scalar_spec.numeric_to_blitz_type_mapping[type]\n+ numeric_type = scalar_spec.numeric_to_c_type_mapping[type]\n code = \"\"\"\n for(int i = 0; i < _Na_2d[0]; i++)\n for(int j = 0; j < _Na_2d[1]; j++)\n new_array(i,j) = (%s) a_2d(j,i);\n \"\"\" % numeric_type\n inline_tools.inline(code,['new_array','a_2d'],\n- type_factories = blitz_type_factories,\n+ type_converters = blitz_type_converters,\n compiler='gcc',\n verbose = 1)\n return new_array\n", "added_lines": 7, "deleted_lines": 7, "source_code": "\"\"\" Cast Copy Tranpose is used in Numeric's LinearAlgebra.py to convert\n C ordered arrays to Fortran order arrays before calling Fortran\n functions. A couple of C implementations are provided here that \n show modest speed improvements. One is an \"inplace\" transpose that\n does an in memory transpose of an arrays elements. This is the\n fastest approach and is beneficial if you don't need to keep the\n original array. \n\"\"\"\n# C:\\home\\ej\\wrk\\scipy\\compiler\\examples>python cast_copy_transpose.py\n# Cast/Copy/Transposing (150,150)array 1 times\n# speed in python: 0.870999932289\n# speed in c: 0.25\n# speed up: 3.48\n# inplace transpose c: 0.129999995232\n# speed up: 6.70\n\nimport Numeric\nfrom Numeric import *\nimport sys\nsys.path.insert(0,'..')\nimport inline_tools\nimport scalar_spec\nfrom blitz_tools import blitz_type_converters\n\ndef _cast_copy_transpose(type,a_2d):\n assert(len(shape(a_2d)) == 2)\n new_array = zeros(shape(a_2d),type)\n #trans_a_2d = transpose(a_2d)\n numeric_type = scalar_spec.numeric_to_c_type_mapping[type]\n code = \"\"\"\n for(int i = 0; i < _Na_2d[0]; i++)\n for(int j = 0; j < _Na_2d[1]; j++)\n new_array(i,j) = (%s) a_2d(j,i);\n \"\"\" % numeric_type\n inline_tools.inline(code,['new_array','a_2d'],\n type_converters = blitz_type_converters,\n compiler='gcc',\n verbose = 1)\n return new_array\n\ndef _inplace_transpose(a_2d):\n assert(len(shape(a_2d)) == 2)\n numeric_type = scalar_spec.numeric_to_c_type_mapping[a_2d.typecode()]\n code = \"\"\"\n %s temp;\n for(int i = 0; i < _Na_2d[0]; i++)\n for(int j = 0; j < _Na_2d[1]; j++)\n {\n temp = a_2d(i,j);\n a_2d(i,j) = a_2d(j,i);\n a_2d(j,i) = temp;\n } \n \"\"\" % numeric_type\n inline_tools.inline(code,['a_2d'],\n type_converters = blitz_type_converters,\n compiler='gcc',def _cast_copy_transpose(type,a_2d):\n assert(len(shape(a_2d)) == 2)\n new_array = zeros(shape(a_2d),type)\n #trans_a_2d = transpose(a_2d)\n numeric_type = scalar_spec.numeric_to_c_type_mapping[type]\n code = \"\"\"\n for(int i = 0; i < _Na_2d[0]; i++)\n for(int j = 0; j < _Na_2d[1]; j++)\n new_array(i,j) = (%s) a_2d(j,i);\n \"\"\" % numeric_type\n inline_tools.inline(code,['new_array','a_2d'],\n type_converters = blitz_type_converters,\n compiler='gcc',\n verbose = 1)\n return new_array\n\n verbose = 1)\n return a_2d\n\ndef cast_copy_transpose(type,*arrays):\n results = []\n for a in arrays:\n results.append(_cast_copy_transpose(type,a))\n if len(results) == 1:\n return results[0]\n else:\n return results\n\ndef inplace_cast_copy_transpose(*arrays):\n results = []\n for a in arrays:\n results.append(_inplace_transpose(a))\n if len(results) == 1:\n return results[0]\n else:\n return results\n\ndef _castCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.typecode() == type:\n cast_arrays = cast_arrays + (copy.copy(Numeric.transpose(a)),)\n else:\n cast_arrays = cast_arrays + (copy.copy(\n Numeric.transpose(a).astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\nimport time\n\n\ndef compare(m,n):\n a = ones((n,n),Float64)\n type = Float32\n print 'Cast/Copy/Transposing (%d,%d)array %d times' % (n,n,m)\n t1 = time.time()\n for i in range(m):\n for i in range(n):\n b = _castCopyAndTranspose(type,a)\n t2 = time.time()\n py = (t2-t1)\n print ' speed in python:', (t2 - t1)/m\n \n\n # load into cache \n b = cast_copy_transpose(type,a)\n t1 = time.time()\n for i in range(m):\n for i in range(n):\n b = cast_copy_transpose(type,a)\n t2 = time.time()\n print ' speed in c:',(t2 - t1)/ m \n print ' speed up: %3.2f' % (py/(t2-t1))\n\n # inplace tranpose\n b = _inplace_transpose(a)\n t1 = time.time()\n for i in range(m):\n for i in range(n):\n b = _inplace_transpose(a)\n t2 = time.time()\n print ' inplace transpose c:',(t2 - t1)/ m \n print ' speed up: %3.2f' % (py/(t2-t1))\n \nif __name__ == \"__main__\":\n m,n = 1,150\n compare(m,n) \n", "source_code_before": "\"\"\" Cast Copy Tranpose is used in Numeric's LinearAlgebra.py to convert\n C ordered arrays to Fortran order arrays before calling Fortran\n functions. A couple of C implementations are provided here that \n show modest speed improvements. One is an \"inplace\" transpose that\n does an in memory transpose of an arrays elements. This is the\n fastest approach and is beneficial if you don't need to keep the\n original array. \n\"\"\"\n# C:\\home\\ej\\wrk\\scipy\\compiler\\examples>python cast_copy_transpose.py\n# Cast/Copy/Transposing (150,150)array 1 times\n# speed in python: 0.870999932289\n# speed in c: 0.25\n# speed up: 3.48\n# inplace transpose c: 0.129999995232\n# speed up: 6.70\n\nimport Numeric\nfrom Numeric import *\nimport sys\nsys.path.insert(0,'..')\nimport inline_tools\nimport scalar_spec\nfrom blitz_tools import blitz_type_factories\n\ndef _cast_copy_transpose(type,a_2d):\n assert(len(shape(a_2d)) == 2)\n new_array = zeros(shape(a_2d),type)\n #trans_a_2d = transpose(a_2d)\n numeric_type = scalar_spec.numeric_to_blitz_type_mapping[type]\n code = \"\"\"\n for(int i = 0; i < _Na_2d[0]; i++)\n for(int j = 0; j < _Na_2d[1]; j++)\n new_array(i,j) = (%s) a_2d(j,i);\n \"\"\" % numeric_type\n inline_tools.inline(code,['new_array','a_2d'],\n type_factories = blitz_type_factories,\n compiler='gcc',\n verbose = 1)\n return new_array\n\ndef _inplace_transpose(a_2d):\n assert(len(shape(a_2d)) == 2)\n numeric_type = scalar_spec.numeric_to_blitz_type_mapping[a_2d.typecode()]\n code = \"\"\"\n %s temp;\n for(int i = 0; i < _Na_2d[0]; i++)\n for(int j = 0; j < _Na_2d[1]; j++)\n {\n temp = a_2d(i,j);\n a_2d(i,j) = a_2d(j,i);\n a_2d(j,i) = temp;\n } \n \"\"\" % numeric_type\n inline_tools.inline(code,['a_2d'],\n type_factories = blitz_type_factories,\n compiler='gcc',def _cast_copy_transpose(type,a_2d):\n assert(len(shape(a_2d)) == 2)\n new_array = zeros(shape(a_2d),type)\n #trans_a_2d = transpose(a_2d)\n numeric_type = scalar_spec.numeric_to_blitz_type_mapping[type]\n code = \"\"\"\n for(int i = 0; i < _Na_2d[0]; i++)\n for(int j = 0; j < _Na_2d[1]; j++)\n new_array(i,j) = (%s) a_2d(j,i);\n \"\"\" % numeric_type\n inline_tools.inline(code,['new_array','a_2d'],\n type_factories = blitz_type_factories,\n compiler='gcc',\n verbose = 1)\n return new_array\n\n verbose = 1)\n return a_2d\n\ndef cast_copy_transpose(type,*arrays):\n results = []\n for a in arrays:\n results.append(_cast_copy_transpose(type,a))\n if len(results) == 1:\n return results[0]\n else:\n return results\n\ndef inplace_cast_copy_transpose(*arrays):\n results = []\n for a in arrays:\n results.append(_inplace_transpose(a))\n if len(results) == 1:\n return results[0]\n else:\n return results\n\ndef _castCopyAndTranspose(type, *arrays):\n cast_arrays = ()\n for a in arrays:\n if a.typecode() == type:\n cast_arrays = cast_arrays + (copy.copy(Numeric.transpose(a)),)\n else:\n cast_arrays = cast_arrays + (copy.copy(\n Numeric.transpose(a).astype(type)),)\n if len(cast_arrays) == 1:\n return cast_arrays[0]\n else:\n return cast_arrays\n\nimport time\n\n\ndef compare(m,n):\n a = ones((n,n),Float64)\n type = Float32\n print 'Cast/Copy/Transposing (%d,%d)array %d times' % (n,n,m)\n t1 = time.time()\n for i in range(m):\n for i in range(n):\n b = _castCopyAndTranspose(type,a)\n t2 = time.time()\n py = (t2-t1)\n print ' speed in python:', (t2 - t1)/m\n \n\n # load into cache \n b = cast_copy_transpose(type,a)\n t1 = time.time()\n for i in range(m):\n for i in range(n):\n b = cast_copy_transpose(type,a)\n t2 = time.time()\n print ' speed in c:',(t2 - t1)/ m \n print ' speed up: %3.2f' % (py/(t2-t1))\n\n # inplace tranpose\n b = _inplace_transpose(a)\n t1 = time.time()\n for i in range(m):\n for i in range(n):\n b = _inplace_transpose(a)\n t2 = time.time()\n print ' inplace transpose c:',(t2 - t1)/ m \n print ' speed up: %3.2f' % (py/(t2-t1))\n \nif __name__ == \"__main__\":\n m,n = 1,150\n compare(m,n) \n", "methods": [ { "name": "_cast_copy_transpose", "long_name": "_cast_copy_transpose( type , a_2d )", "filename": "cast_copy_transpose.py", "nloc": 14, "complexity": 1, "token_count": 69, "parameters": [ "type", "a_2d" ], "start_line": 25, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "_inplace_transpose._cast_copy_transpose", "long_name": "_inplace_transpose._cast_copy_transpose( type , a_2d )", "filename": "cast_copy_transpose.py", "nloc": 16, "complexity": 1, "token_count": 75, "parameters": [ "type", "a_2d" ], "start_line": 56, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 2 }, { "name": "cast_copy_transpose", "long_name": "cast_copy_transpose( type , * arrays )", "filename": "cast_copy_transpose.py", "nloc": 8, "complexity": 3, "token_count": 45, "parameters": [ "type", "arrays" ], "start_line": 75, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "inplace_cast_copy_transpose", "long_name": "inplace_cast_copy_transpose( * arrays )", "filename": "cast_copy_transpose.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "arrays" ], "start_line": 84, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_castCopyAndTranspose", "long_name": "_castCopyAndTranspose( type , * arrays )", "filename": "cast_copy_transpose.py", "nloc": 12, "complexity": 4, "token_count": 86, "parameters": [ "type", "arrays" ], "start_line": 93, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "compare", "long_name": "compare( m , n )", "filename": "cast_copy_transpose.py", "nloc": 27, "complexity": 7, "token_count": 219, "parameters": [ "m", "n" ], "start_line": 109, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 } ], "methods_before": [ { "name": "_cast_copy_transpose", "long_name": "_cast_copy_transpose( type , a_2d )", "filename": "cast_copy_transpose.py", "nloc": 14, "complexity": 1, "token_count": 69, "parameters": [ "type", "a_2d" ], "start_line": 25, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "_inplace_transpose._cast_copy_transpose", "long_name": "_inplace_transpose._cast_copy_transpose( type , a_2d )", "filename": "cast_copy_transpose.py", "nloc": 16, "complexity": 1, "token_count": 75, "parameters": [ "type", "a_2d" ], "start_line": 56, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 2 }, { "name": "cast_copy_transpose", "long_name": "cast_copy_transpose( type , * arrays )", "filename": "cast_copy_transpose.py", "nloc": 8, "complexity": 3, "token_count": 45, "parameters": [ "type", "arrays" ], "start_line": 75, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "inplace_cast_copy_transpose", "long_name": "inplace_cast_copy_transpose( * arrays )", "filename": "cast_copy_transpose.py", "nloc": 8, "complexity": 3, "token_count": 41, "parameters": [ "arrays" ], "start_line": 84, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "_castCopyAndTranspose", "long_name": "_castCopyAndTranspose( type , * arrays )", "filename": "cast_copy_transpose.py", "nloc": 12, "complexity": 4, "token_count": 86, "parameters": [ "type", "arrays" ], "start_line": 93, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "compare", "long_name": "compare( m , n )", "filename": "cast_copy_transpose.py", "nloc": 27, "complexity": 7, "token_count": 219, "parameters": [ "m", "n" ], "start_line": 109, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "_inplace_transpose._cast_copy_transpose", "long_name": "_inplace_transpose._cast_copy_transpose( type , a_2d )", "filename": "cast_copy_transpose.py", "nloc": 16, "complexity": 1, "token_count": 75, "parameters": [ "type", "a_2d" ], "start_line": 56, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 2 }, { "name": "_cast_copy_transpose", "long_name": "_cast_copy_transpose( type , a_2d )", "filename": "cast_copy_transpose.py", "nloc": 14, "complexity": 1, "token_count": 69, "parameters": [ "type", "a_2d" ], "start_line": 25, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 } ], "nloc": 119, "complexity": 19, "token_count": 641, "diff_parsed": { "added": [ "from blitz_tools import blitz_type_converters", " numeric_type = scalar_spec.numeric_to_c_type_mapping[type]", " type_converters = blitz_type_converters,", " numeric_type = scalar_spec.numeric_to_c_type_mapping[a_2d.typecode()]", " type_converters = blitz_type_converters,", " numeric_type = scalar_spec.numeric_to_c_type_mapping[type]", " type_converters = blitz_type_converters," ], "deleted": [ "from blitz_tools import blitz_type_factories", " numeric_type = scalar_spec.numeric_to_blitz_type_mapping[type]", " type_factories = blitz_type_factories,", " numeric_type = scalar_spec.numeric_to_blitz_type_mapping[a_2d.typecode()]", " type_factories = blitz_type_factories,", " numeric_type = scalar_spec.numeric_to_blitz_type_mapping[type]", " type_factories = blitz_type_factories," ] } }, { "old_path": "weave/examples/vq.py", "new_path": "weave/examples/vq.py", "filename": "vq.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -19,7 +19,7 @@\n import sys\n sys.path.insert(0,'..')\n import inline_tools\n-from blitz_tools import blitz_type_factories\n+from blitz_tools import blitz_type_converters\n import scalar_spec\n \n def vq(obs,code_book):\n@@ -31,7 +31,7 @@ def vq(obs,code_book):\n code_book_sh = shape(code_book)\n assert(len(obs_sh) == 2 and len(code_book_sh) == 2) \n assert(obs_sh[1] == code_book_sh[1]) \n- type = scalar_spec.numeric_to_blitz_type_mapping[obs.typecode()]\n+ type = scalar_spec.numeric_to_c_type_mapping[obs.typecode()]\n # band aid for now.\n ar_type = 'PyArray_FLOAT'\n code = \"\"\"\n@@ -58,7 +58,7 @@ def vq(obs,code_book):\n \t return_val = Py::new_reference_to(results); \t \n \"\"\" % locals()\n code, distortion = inline_tools.inline(code,['obs','code_book'],\n- type_factories = blitz_type_factories,\n+ type_converters = blitz_type_converters,\n compiler = 'gcc',\n verbose = 1)\n return code, distortion\n@@ -76,7 +76,7 @@ def vq2(obs,code_book):\n assert(len(obs_sh) == 2 and len(code_book_sh) == 2) \n assert(obs_sh[1] == code_book_sh[1]) \n assert(obs.typecode() == code_book.typecode()) \n- type = scalar_spec.numeric_to_blitz_type_mapping[obs.typecode()]\n+ type = scalar_spec.numeric_to_c_type_mapping[obs.typecode()]\n # band aid for now.\n ar_type = 'PyArray_FLOAT'\n code = \"\"\"\n@@ -122,12 +122,11 @@ def vq2(obs,code_book):\n \t return_val = Py::new_reference_to(results); \t \n \"\"\" % locals()\n code, distortion = inline_tools.inline(code,['obs','code_book'],\n- type_factories = blitz_type_factories,\n+ type_converters = blitz_type_converters,\n compiler = 'gcc',\n verbose = 1)\n return code, distortion\n \n-from standard_array_spec import standard_array_factories\n \n def vq3(obs,code_book):\n \"\"\" Uses standard array conversion completely bi-passing blitz.\n@@ -142,7 +141,7 @@ def vq3(obs,code_book):\n assert(len(obs_sh) == 2 and len(code_book_sh) == 2) \n assert(obs_sh[1] == code_book_sh[1]) \n assert(obs.typecode() == code_book.typecode()) \n- type = scalar_spec.numeric_to_blitz_type_mapping[obs.typecode()]\n+ type = scalar_spec.numeric_to_c_type_mapping[obs.typecode()]\n code = \"\"\"\n #line 139 \"vq.py\"\n // Surely there is a better way to do this...\n", "added_lines": 6, "deleted_lines": 7, "source_code": "\"\"\" \n\"\"\"\n# C:\\home\\ej\\wrk\\scipy\\weave\\examples>python vq.py\n# vq with 1000 observation, 10 features and 30 codes fo 100 iterations\n# speed in python: 0.150119999647\n# [25 29] [ 2.49147266 3.83021032]\n# speed in standard c: 0.00710999965668\n# [25 29] [ 2.49147266 3.83021032]\n# speed up: 21.11\n# speed inline/blitz: 0.0186300003529\n# [25 29] [ 2.49147272 3.83021021]\n# speed up: 8.06\n# speed inline/blitz2: 0.00461000084877\n# [25 29] [ 2.49147272 3.83021021]\n# speed up: 32.56\n \nimport Numeric\nfrom Numeric import *\nimport sys\nsys.path.insert(0,'..')\nimport inline_tools\nfrom blitz_tools import blitz_type_converters\nimport scalar_spec\n\ndef vq(obs,code_book):\n # make sure we're looking at arrays.\n obs = asarray(obs)\n code_book = asarray(code_book)\n # check for 2d arrays and compatible sizes.\n obs_sh = shape(obs)\n code_book_sh = shape(code_book)\n assert(len(obs_sh) == 2 and len(code_book_sh) == 2) \n assert(obs_sh[1] == code_book_sh[1]) \n type = scalar_spec.numeric_to_c_type_mapping[obs.typecode()]\n # band aid for now.\n ar_type = 'PyArray_FLOAT'\n code = \"\"\"\n #line 37 \"vq.py\"\n // Use tensor notation. \n blitz::Array<%(type)s,2> dist_sq(_Ncode_book[0],_Nobs[0]);\n \t blitz::firstIndex i; \n blitz::secondIndex j; \n blitz::thirdIndex k;\n dist_sq = sum(pow2(obs(j,k) - code_book(i,k)),k);\n // Surely there is a better way to do this...\n PyArrayObject* py_code = (PyArrayObject*) PyArray_FromDims(1,&_Nobs[0],PyArray_LONG);\n \t blitz::Array code((int*)(py_code->data),\n blitz::shape(_Nobs[0]), blitz::neverDeleteData);\n \t code = minIndex(dist_sq(j,i),j);\n \t \n \t PyArrayObject* py_min_dist = (PyArrayObject*) PyArray_FromDims(1,&_Nobs[0],PyArray_FLOAT);\n \t blitz::Array min_dist((float*)(py_min_dist->data),\n \t blitz::shape(_Nobs[0]), blitz::neverDeleteData);\n \t min_dist = sqrt(min(dist_sq(j,i),j));\n \t Py::Tuple results(2);\n \t results[0] = Py::Object((PyObject*)py_code);\n \t results[1] = Py::Object((PyObject*)py_min_dist);\n \t return_val = Py::new_reference_to(results); \t \n \"\"\" % locals()\n code, distortion = inline_tools.inline(code,['obs','code_book'],\n type_converters = blitz_type_converters,\n compiler = 'gcc',\n verbose = 1)\n return code, distortion\n\ndef vq2(obs,code_book):\n \"\"\" doesn't use blitz (except in conversion)\n ALSO DOES NOT HANDLE STRIDED ARRAYS CORRECTLY\n \"\"\"\n # make sure we're looking at arrays.\n obs = asarray(obs)\n code_book = asarray(code_book)\n # check for 2d arrays and compatible sizes.\n obs_sh = shape(obs)\n code_book_sh = shape(code_book)\n assert(len(obs_sh) == 2 and len(code_book_sh) == 2) \n assert(obs_sh[1] == code_book_sh[1]) \n assert(obs.typecode() == code_book.typecode()) \n type = scalar_spec.numeric_to_c_type_mapping[obs.typecode()]\n # band aid for now.\n ar_type = 'PyArray_FLOAT'\n code = \"\"\"\n #line 83 \"vq.py\"\n // THIS DOES NOT HANDLE STRIDED ARRAYS CORRECTLY\n // Surely there is a better way to do this...\n PyArrayObject* py_code = (PyArrayObject*) PyArray_FromDims(1,&_Nobs[0],PyArray_LONG);\t \n \t PyArrayObject* py_min_dist = (PyArrayObject*) PyArray_FromDims(1,&_Nobs[0],PyArray_FLOAT);\n \t \n int* raw_code = (int*)(py_code->data);\n float* raw_min_dist = (float*)(py_min_dist->data);\n %(type)s* raw_obs = obs.data();\n %(type)s* raw_code_book = code_book.data(); \n %(type)s* this_obs = NULL;\n %(type)s* this_code = NULL; \n int Nfeatures = _Nobs[1];\n float diff,dist;\n for(int i=0; i < _Nobs[0]; i++)\n {\n this_obs = &raw_obs[i*Nfeatures];\n raw_min_dist[i] = (%(type)s)10000000.; // big number\n for(int j=0; j < _Ncode_book[0]; j++)\n {\n this_code = &raw_code_book[j*Nfeatures];\n dist = 0;\n for(int k=0; k < Nfeatures; k++)\n {\n diff = this_obs[k] - this_code[k];\n dist += diff*diff;\n }\n dist = dist;\n if (dist < raw_min_dist[i])\n {\n raw_code[i] = j;\n raw_min_dist[i] = dist; \n } \n }\n raw_min_dist[i] = sqrt(raw_min_dist[i]);\n \t }\n \t Py::Tuple results(2);\n \t results[0] = Py::Object((PyObject*)py_code);\n \t results[1] = Py::Object((PyObject*)py_min_dist);\n \t return_val = Py::new_reference_to(results); \t \n \"\"\" % locals()\n code, distortion = inline_tools.inline(code,['obs','code_book'],\n type_converters = blitz_type_converters,\n compiler = 'gcc',\n verbose = 1)\n return code, distortion\n\n\ndef vq3(obs,code_book):\n \"\"\" Uses standard array conversion completely bi-passing blitz.\n THIS DOES NOT HANDLE STRIDED ARRAYS CORRECTLY\n \"\"\"\n # make sure we're looking at arrays.\n obs = asarray(obs)\n code_book = asarray(code_book)\n # check for 2d arrays and compatible sizes.\n obs_sh = shape(obs)\n code_book_sh = shape(code_book)\n assert(len(obs_sh) == 2 and len(code_book_sh) == 2) \n assert(obs_sh[1] == code_book_sh[1]) \n assert(obs.typecode() == code_book.typecode()) \n type = scalar_spec.numeric_to_c_type_mapping[obs.typecode()]\n code = \"\"\"\n #line 139 \"vq.py\"\n // Surely there is a better way to do this...\n PyArrayObject* py_code = (PyArrayObject*) PyArray_FromDims(1,&_Nobs[0],PyArray_LONG);\t \n \t PyArrayObject* py_min_dist = (PyArrayObject*) PyArray_FromDims(1,&_Nobs[0],PyArray_FLOAT);\n \t \n int* code_data = (int*)(py_code->data);\n float* min_dist_data = (float*)(py_min_dist->data);\n %(type)s* this_obs = NULL;\n %(type)s* this_code = NULL; \n int Nfeatures = _Nobs[1];\n float diff,dist;\n\n for(int i=0; i < _Nobs[0]; i++)\n {\n this_obs = &obs_data[i*Nfeatures];\n min_dist_data[i] = (float)10000000.; // big number\n for(int j=0; j < _Ncode_book[0]; j++)\n {\n this_code = &code_book_data[j*Nfeatures];\n dist = 0;\n for(int k=0; k < Nfeatures; k++)\n {\n diff = this_obs[k] - this_code[k];\n dist += diff*diff;\n }\n if (dist < min_dist_data[i])\n {\n code_data[i] = j;\n min_dist_data[i] = dist; \n } \n }\n min_dist_data[i] = sqrt(min_dist_data[i]);\n \t }\n \t Py::Tuple results(2);\n \t results[0] = Py::Object((PyObject*)py_code);\n \t results[1] = Py::Object((PyObject*)py_min_dist);\n \t return Py::new_reference_to(results); \t \n \"\"\" % locals()\n # this is an unpleasant way to specify type factories -- work on it.\n import ext_tools\n code, distortion = inline_tools.inline(code,['obs','code_book'])\n return code, distortion\n\nimport time\nimport RandomArray\ndef compare(m,Nobs,Ncodes,Nfeatures):\n obs = RandomArray.normal(0.,1.,(Nobs,Nfeatures))\n codes = RandomArray.normal(0.,1.,(Ncodes,Nfeatures))\n import scipy.cluster.vq\n scipy.cluster.vq\n print 'vq with %d observation, %d features and %d codes for %d iterations' % \\\n (Nobs,Nfeatures,Ncodes,m)\n t1 = time.time()\n for i in range(m):\n code,dist = scipy.cluster.vq.py_vq(obs,codes)\n t2 = time.time()\n py = (t2-t1)\n print ' speed in python:', (t2 - t1)/m\n print code[:2],dist[:2]\n \n t1 = time.time()\n for i in range(m):\n code,dist = scipy.cluster.vq.vq(obs,codes)\n t2 = time.time()\n print ' speed in standard c:', (t2 - t1)/m\n print code[:2],dist[:2]\n print ' speed up: %3.2f' % (py/(t2-t1))\n \n # load into cache \n b = vq(obs,codes)\n t1 = time.time()\n for i in range(m):\n code,dist = vq(obs,codes)\n t2 = time.time()\n print ' speed inline/blitz:',(t2 - t1)/ m \n print code[:2],dist[:2]\n print ' speed up: %3.2f' % (py/(t2-t1))\n\n # load into cache \n b = vq2(obs,codes)\n t1 = time.time()\n for i in range(m):\n code,dist = vq2(obs,codes)\n t2 = time.time()\n print ' speed inline/blitz2:',(t2 - t1)/ m \n print code[:2],dist[:2]\n print ' speed up: %3.2f' % (py/(t2-t1))\n\n # load into cache \n b = vq3(obs,codes)\n t1 = time.time()\n for i in range(m):\n code,dist = vq3(obs,codes)\n t2 = time.time()\n print ' speed using C arrays:',(t2 - t1)/ m \n print code[:2],dist[:2]\n print ' speed up: %3.2f' % (py/(t2-t1))\n \nif __name__ == \"__main__\":\n compare(100,1000,30,10) \n #compare(1,10,2,10) \n", "source_code_before": "\"\"\" \n\"\"\"\n# C:\\home\\ej\\wrk\\scipy\\weave\\examples>python vq.py\n# vq with 1000 observation, 10 features and 30 codes fo 100 iterations\n# speed in python: 0.150119999647\n# [25 29] [ 2.49147266 3.83021032]\n# speed in standard c: 0.00710999965668\n# [25 29] [ 2.49147266 3.83021032]\n# speed up: 21.11\n# speed inline/blitz: 0.0186300003529\n# [25 29] [ 2.49147272 3.83021021]\n# speed up: 8.06\n# speed inline/blitz2: 0.00461000084877\n# [25 29] [ 2.49147272 3.83021021]\n# speed up: 32.56\n \nimport Numeric\nfrom Numeric import *\nimport sys\nsys.path.insert(0,'..')\nimport inline_tools\nfrom blitz_tools import blitz_type_factories\nimport scalar_spec\n\ndef vq(obs,code_book):\n # make sure we're looking at arrays.\n obs = asarray(obs)\n code_book = asarray(code_book)\n # check for 2d arrays and compatible sizes.\n obs_sh = shape(obs)\n code_book_sh = shape(code_book)\n assert(len(obs_sh) == 2 and len(code_book_sh) == 2) \n assert(obs_sh[1] == code_book_sh[1]) \n type = scalar_spec.numeric_to_blitz_type_mapping[obs.typecode()]\n # band aid for now.\n ar_type = 'PyArray_FLOAT'\n code = \"\"\"\n #line 37 \"vq.py\"\n // Use tensor notation. \n blitz::Array<%(type)s,2> dist_sq(_Ncode_book[0],_Nobs[0]);\n \t blitz::firstIndex i; \n blitz::secondIndex j; \n blitz::thirdIndex k;\n dist_sq = sum(pow2(obs(j,k) - code_book(i,k)),k);\n // Surely there is a better way to do this...\n PyArrayObject* py_code = (PyArrayObject*) PyArray_FromDims(1,&_Nobs[0],PyArray_LONG);\n \t blitz::Array code((int*)(py_code->data),\n blitz::shape(_Nobs[0]), blitz::neverDeleteData);\n \t code = minIndex(dist_sq(j,i),j);\n \t \n \t PyArrayObject* py_min_dist = (PyArrayObject*) PyArray_FromDims(1,&_Nobs[0],PyArray_FLOAT);\n \t blitz::Array min_dist((float*)(py_min_dist->data),\n \t blitz::shape(_Nobs[0]), blitz::neverDeleteData);\n \t min_dist = sqrt(min(dist_sq(j,i),j));\n \t Py::Tuple results(2);\n \t results[0] = Py::Object((PyObject*)py_code);\n \t results[1] = Py::Object((PyObject*)py_min_dist);\n \t return_val = Py::new_reference_to(results); \t \n \"\"\" % locals()\n code, distortion = inline_tools.inline(code,['obs','code_book'],\n type_factories = blitz_type_factories,\n compiler = 'gcc',\n verbose = 1)\n return code, distortion\n\ndef vq2(obs,code_book):\n \"\"\" doesn't use blitz (except in conversion)\n ALSO DOES NOT HANDLE STRIDED ARRAYS CORRECTLY\n \"\"\"\n # make sure we're looking at arrays.\n obs = asarray(obs)\n code_book = asarray(code_book)\n # check for 2d arrays and compatible sizes.\n obs_sh = shape(obs)\n code_book_sh = shape(code_book)\n assert(len(obs_sh) == 2 and len(code_book_sh) == 2) \n assert(obs_sh[1] == code_book_sh[1]) \n assert(obs.typecode() == code_book.typecode()) \n type = scalar_spec.numeric_to_blitz_type_mapping[obs.typecode()]\n # band aid for now.\n ar_type = 'PyArray_FLOAT'\n code = \"\"\"\n #line 83 \"vq.py\"\n // THIS DOES NOT HANDLE STRIDED ARRAYS CORRECTLY\n // Surely there is a better way to do this...\n PyArrayObject* py_code = (PyArrayObject*) PyArray_FromDims(1,&_Nobs[0],PyArray_LONG);\t \n \t PyArrayObject* py_min_dist = (PyArrayObject*) PyArray_FromDims(1,&_Nobs[0],PyArray_FLOAT);\n \t \n int* raw_code = (int*)(py_code->data);\n float* raw_min_dist = (float*)(py_min_dist->data);\n %(type)s* raw_obs = obs.data();\n %(type)s* raw_code_book = code_book.data(); \n %(type)s* this_obs = NULL;\n %(type)s* this_code = NULL; \n int Nfeatures = _Nobs[1];\n float diff,dist;\n for(int i=0; i < _Nobs[0]; i++)\n {\n this_obs = &raw_obs[i*Nfeatures];\n raw_min_dist[i] = (%(type)s)10000000.; // big number\n for(int j=0; j < _Ncode_book[0]; j++)\n {\n this_code = &raw_code_book[j*Nfeatures];\n dist = 0;\n for(int k=0; k < Nfeatures; k++)\n {\n diff = this_obs[k] - this_code[k];\n dist += diff*diff;\n }\n dist = dist;\n if (dist < raw_min_dist[i])\n {\n raw_code[i] = j;\n raw_min_dist[i] = dist; \n } \n }\n raw_min_dist[i] = sqrt(raw_min_dist[i]);\n \t }\n \t Py::Tuple results(2);\n \t results[0] = Py::Object((PyObject*)py_code);\n \t results[1] = Py::Object((PyObject*)py_min_dist);\n \t return_val = Py::new_reference_to(results); \t \n \"\"\" % locals()\n code, distortion = inline_tools.inline(code,['obs','code_book'],\n type_factories = blitz_type_factories,\n compiler = 'gcc',\n verbose = 1)\n return code, distortion\n\nfrom standard_array_spec import standard_array_factories\n\ndef vq3(obs,code_book):\n \"\"\" Uses standard array conversion completely bi-passing blitz.\n THIS DOES NOT HANDLE STRIDED ARRAYS CORRECTLY\n \"\"\"\n # make sure we're looking at arrays.\n obs = asarray(obs)\n code_book = asarray(code_book)\n # check for 2d arrays and compatible sizes.\n obs_sh = shape(obs)\n code_book_sh = shape(code_book)\n assert(len(obs_sh) == 2 and len(code_book_sh) == 2) \n assert(obs_sh[1] == code_book_sh[1]) \n assert(obs.typecode() == code_book.typecode()) \n type = scalar_spec.numeric_to_blitz_type_mapping[obs.typecode()]\n code = \"\"\"\n #line 139 \"vq.py\"\n // Surely there is a better way to do this...\n PyArrayObject* py_code = (PyArrayObject*) PyArray_FromDims(1,&_Nobs[0],PyArray_LONG);\t \n \t PyArrayObject* py_min_dist = (PyArrayObject*) PyArray_FromDims(1,&_Nobs[0],PyArray_FLOAT);\n \t \n int* code_data = (int*)(py_code->data);\n float* min_dist_data = (float*)(py_min_dist->data);\n %(type)s* this_obs = NULL;\n %(type)s* this_code = NULL; \n int Nfeatures = _Nobs[1];\n float diff,dist;\n\n for(int i=0; i < _Nobs[0]; i++)\n {\n this_obs = &obs_data[i*Nfeatures];\n min_dist_data[i] = (float)10000000.; // big number\n for(int j=0; j < _Ncode_book[0]; j++)\n {\n this_code = &code_book_data[j*Nfeatures];\n dist = 0;\n for(int k=0; k < Nfeatures; k++)\n {\n diff = this_obs[k] - this_code[k];\n dist += diff*diff;\n }\n if (dist < min_dist_data[i])\n {\n code_data[i] = j;\n min_dist_data[i] = dist; \n } \n }\n min_dist_data[i] = sqrt(min_dist_data[i]);\n \t }\n \t Py::Tuple results(2);\n \t results[0] = Py::Object((PyObject*)py_code);\n \t results[1] = Py::Object((PyObject*)py_min_dist);\n \t return Py::new_reference_to(results); \t \n \"\"\" % locals()\n # this is an unpleasant way to specify type factories -- work on it.\n import ext_tools\n code, distortion = inline_tools.inline(code,['obs','code_book'])\n return code, distortion\n\nimport time\nimport RandomArray\ndef compare(m,Nobs,Ncodes,Nfeatures):\n obs = RandomArray.normal(0.,1.,(Nobs,Nfeatures))\n codes = RandomArray.normal(0.,1.,(Ncodes,Nfeatures))\n import scipy.cluster.vq\n scipy.cluster.vq\n print 'vq with %d observation, %d features and %d codes for %d iterations' % \\\n (Nobs,Nfeatures,Ncodes,m)\n t1 = time.time()\n for i in range(m):\n code,dist = scipy.cluster.vq.py_vq(obs,codes)\n t2 = time.time()\n py = (t2-t1)\n print ' speed in python:', (t2 - t1)/m\n print code[:2],dist[:2]\n \n t1 = time.time()\n for i in range(m):\n code,dist = scipy.cluster.vq.vq(obs,codes)\n t2 = time.time()\n print ' speed in standard c:', (t2 - t1)/m\n print code[:2],dist[:2]\n print ' speed up: %3.2f' % (py/(t2-t1))\n \n # load into cache \n b = vq(obs,codes)\n t1 = time.time()\n for i in range(m):\n code,dist = vq(obs,codes)\n t2 = time.time()\n print ' speed inline/blitz:',(t2 - t1)/ m \n print code[:2],dist[:2]\n print ' speed up: %3.2f' % (py/(t2-t1))\n\n # load into cache \n b = vq2(obs,codes)\n t1 = time.time()\n for i in range(m):\n code,dist = vq2(obs,codes)\n t2 = time.time()\n print ' speed inline/blitz2:',(t2 - t1)/ m \n print code[:2],dist[:2]\n print ' speed up: %3.2f' % (py/(t2-t1))\n\n # load into cache \n b = vq3(obs,codes)\n t1 = time.time()\n for i in range(m):\n code,dist = vq3(obs,codes)\n t2 = time.time()\n print ' speed using C arrays:',(t2 - t1)/ m \n print code[:2],dist[:2]\n print ' speed up: %3.2f' % (py/(t2-t1))\n \nif __name__ == \"__main__\":\n compare(100,1000,30,10) \n #compare(1,10,2,10) \n", "methods": [ { "name": "vq", "long_name": "vq( obs , code_book )", "filename": "vq.py", "nloc": 37, "complexity": 2, "token_count": 113, "parameters": [ "obs", "code_book" ], "start_line": 25, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "vq2", "long_name": "vq2( obs , code_book )", "filename": "vq.py", "nloc": 57, "complexity": 2, "token_count": 128, "parameters": [ "obs", "code_book" ], "start_line": 66, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 63, "top_nesting_level": 0 }, { "name": "vq3", "long_name": "vq3( obs , code_book )", "filename": "vq.py", "nloc": 51, "complexity": 2, "token_count": 115, "parameters": [ "obs", "code_book" ], "start_line": 131, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 57, "top_nesting_level": 0 }, { "name": "compare", "long_name": "compare( m , Nobs , Ncodes , Nfeatures )", "filename": "vq.py", "nloc": 45, "complexity": 6, "token_count": 432, "parameters": [ "m", "Nobs", "Ncodes", "Nfeatures" ], "start_line": 191, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 } ], "methods_before": [ { "name": "vq", "long_name": "vq( obs , code_book )", "filename": "vq.py", "nloc": 37, "complexity": 2, "token_count": 113, "parameters": [ "obs", "code_book" ], "start_line": 25, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "vq2", "long_name": "vq2( obs , code_book )", "filename": "vq.py", "nloc": 57, "complexity": 2, "token_count": 128, "parameters": [ "obs", "code_book" ], "start_line": 66, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 63, "top_nesting_level": 0 }, { "name": "vq3", "long_name": "vq3( obs , code_book )", "filename": "vq.py", "nloc": 51, "complexity": 2, "token_count": 115, "parameters": [ "obs", "code_book" ], "start_line": 132, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 57, "top_nesting_level": 0 }, { "name": "compare", "long_name": "compare( m , Nobs , Ncodes , Nfeatures )", "filename": "vq.py", "nloc": 45, "complexity": 6, "token_count": 432, "parameters": [ "m", "Nobs", "Ncodes", "Nfeatures" ], "start_line": 192, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 52, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "vq3", "long_name": "vq3( obs , code_book )", "filename": "vq.py", "nloc": 51, "complexity": 2, "token_count": 115, "parameters": [ "obs", "code_book" ], "start_line": 131, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 57, "top_nesting_level": 0 }, { "name": "vq", "long_name": "vq( obs , code_book )", "filename": "vq.py", "nloc": 37, "complexity": 2, "token_count": 113, "parameters": [ "obs", "code_book" ], "start_line": 25, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "vq2", "long_name": "vq2( obs , code_book )", "filename": "vq.py", "nloc": 57, "complexity": 2, "token_count": 128, "parameters": [ "obs", "code_book" ], "start_line": 66, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 63, "top_nesting_level": 0 } ], "nloc": 203, "complexity": 12, "token_count": 838, "diff_parsed": { "added": [ "from blitz_tools import blitz_type_converters", " type = scalar_spec.numeric_to_c_type_mapping[obs.typecode()]", " type_converters = blitz_type_converters,", " type = scalar_spec.numeric_to_c_type_mapping[obs.typecode()]", " type_converters = blitz_type_converters,", " type = scalar_spec.numeric_to_c_type_mapping[obs.typecode()]" ], "deleted": [ "from blitz_tools import blitz_type_factories", " type = scalar_spec.numeric_to_blitz_type_mapping[obs.typecode()]", " type_factories = blitz_type_factories,", " type = scalar_spec.numeric_to_blitz_type_mapping[obs.typecode()]", " type_factories = blitz_type_factories,", "from standard_array_spec import standard_array_factories", " type = scalar_spec.numeric_to_blitz_type_mapping[obs.typecode()]" ] } }, { "old_path": "weave/ext_tools.py", "new_path": "weave/ext_tools.py", "filename": "ext_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,38 +1,10 @@\n import os, sys\n import string, re\n \n+import catalog \n import build_tools\n-\n+import converters\n import base_spec\n-import scalar_spec\n-import sequence_spec\n-import common_spec\n-import catalog \n-\n-default_type_factories = [scalar_spec.int_specification(),\n- scalar_spec.float_specification(),\n- scalar_spec.complex_specification(),\n- sequence_spec.string_specification(),\n- sequence_spec.list_specification(),\n- sequence_spec.dict_specification(),\n- sequence_spec.tuple_specification(),\n- common_spec.file_specification(),\n- common_spec.callable_specification()]\n- common_spec.instance_specification(), \n- #common_spec.module_specification()]\n-\n-try: \n- from standard_array_spec import array_specification\n- default_type_factories.append(array_specification())\n-except: \n- pass \n-\n-try: \n- # this is currently safe because it doesn't import wxPython.\n- import wx_spec\n- default_type_factories.append(wx_spec.wx_specification())\n-except: \n- pass \n \n class ext_function_from_specs:\n def __init__(self,name,code_block,arg_specs):\n@@ -185,17 +157,17 @@ def set_compiler(self,compiler):\n \n class 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_factories=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_factories is None:\n- type_factories = default_type_factories\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_factories)\n+ auto_downcast, type_converters)\n ext_function_from_specs.__init__(self,name,code_block,arg_specs)\n \n \n@@ -362,7 +334,7 @@ def generate_module(module_string, module_file):\n \n def assign_variable_types(variables,local_dict = {}, global_dict = {},\n auto_downcast = 1,\n- type_factories = default_type_factories):\n+ type_converters = converters.default):\n incoming_vars = {}\n incoming_vars.update(global_dict)\n incoming_vars.update(local_dict)\n@@ -375,7 +347,7 @@ def assign_variable_types(variables,local_dict = {}, global_dict = {},\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_factories:\n+ for factory in type_converters:\n if factory.type_match(example_type):\n spec = factory.type_spec(var,example_type)\n break\n", "added_lines": 8, "deleted_lines": 36, "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 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 #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 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 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 \" Py::Dict local_dict = Py::Dict(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 = Py::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, common_info, cxx_info, scalar_info\n\nclass ext_module:\n def __init__(self,name,compiler=''):\n standard_info = [common_info.basic_module_info(),\n common_info.file_info(), \n common_info.instance_info(), \n common_info.callable_info(), \n common_info.module_info(), \n cxx_info.cxx_info(),\n scalar_info.scalar_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():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n", "source_code_before": "import os, sys\nimport string, re\n\nimport build_tools\n\nimport base_spec\nimport scalar_spec\nimport sequence_spec\nimport common_spec\nimport catalog \n\ndefault_type_factories = [scalar_spec.int_specification(),\n scalar_spec.float_specification(),\n scalar_spec.complex_specification(),\n sequence_spec.string_specification(),\n sequence_spec.list_specification(),\n sequence_spec.dict_specification(),\n sequence_spec.tuple_specification(),\n common_spec.file_specification(),\n common_spec.callable_specification()]\n common_spec.instance_specification(), \n #common_spec.module_specification()]\n\ntry: \n from standard_array_spec import array_specification\n default_type_factories.append(array_specification())\nexcept: \n pass \n\ntry: \n # this is currently safe because it doesn't import wxPython.\n import wx_spec\n default_type_factories.append(wx_spec.wx_specification())\nexcept: \n pass \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 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 #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 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 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 \" Py::Dict local_dict = Py::Dict(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 = Py::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_factories=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_factories is None:\n type_factories = default_type_factories\n arg_specs = assign_variable_types(args,local_dict, global_dict,\n auto_downcast, type_factories)\n ext_function_from_specs.__init__(self,name,code_block,arg_specs)\n \n \nimport base_info, common_info, cxx_info, scalar_info\n\nclass ext_module:\n def __init__(self,name,compiler=''):\n standard_info = [common_info.basic_module_info(),\n common_info.file_info(), \n common_info.instance_info(), \n common_info.callable_info(), \n common_info.module_info(), \n cxx_info.cxx_info(),\n scalar_info.scalar_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_factories = default_type_factories):\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_factories:\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():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \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": 30, "complexity": 5, "token_count": 174, "parameters": [ "self" ], "start_line": 36, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 1 }, { "name": "arg_declaration_code", "long_name": "arg_declaration_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 82, "end_line": 87, "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": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 89, "end_line": 94, "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": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "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": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 37, "complexity": 1, "token_count": 162, "parameters": [ "self" ], "start_line": 103, "end_line": 144, "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": 146, "end_line": 150, "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": 152, "end_line": 155, "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": 159, "end_line": 171, "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": 13, "complexity": 1, "token_count": 91, "parameters": [ "self", "name", "compiler" ], "start_line": 177, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 191, "end_line": 192, "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": 193, "end_line": 200, "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": 202, "end_line": 206, "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": 208, "end_line": 216, "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": 218, "end_line": 225, "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": 227, "end_line": 230, "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": 232, "end_line": 235, "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": 237, "end_line": 239, "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": 241, "end_line": 245, "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": 247, "end_line": 257, "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": 259, "end_line": 267, "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": 269, "end_line": 275, "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": 277, "end_line": 284, "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": 286, "end_line": 323, "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": 325, "end_line": 327, "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": 329, "end_line": 333, "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": 335, "end_line": 370, "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": 372, "end_line": 399, "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": 401, "end_line": 406, "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": 408, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 415, "end_line": 417, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 419, "end_line": 421, "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": 38, "end_line": 43, "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": 45, "end_line": 46, "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": 48, "end_line": 51, "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": 53, "end_line": 57, "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": 30, "complexity": 5, "token_count": 174, "parameters": [ "self" ], "start_line": 64, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 1 }, { "name": "arg_declaration_code", "long_name": "arg_declaration_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "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": "arg_cleanup_code", "long_name": "arg_cleanup_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 117, "end_line": 122, "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": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 124, "end_line": 129, "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": 131, "end_line": 172, "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": 174, "end_line": 178, "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": 180, "end_line": 183, "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_factories = None )", "filename": "ext_tools.py", "nloc": 12, "complexity": 4, "token_count": 90, "parameters": [ "self", "name", "code_block", "args", "local_dict", "global_dict", "auto_downcast", "type_factories" ], "start_line": 187, "end_line": 199, "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": 13, "complexity": 1, "token_count": 91, "parameters": [ "self", "name", "compiler" ], "start_line": 205, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 219, "end_line": 220, "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": 221, "end_line": 228, "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": 230, "end_line": 234, "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": 236, "end_line": 244, "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": 246, "end_line": 253, "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": 255, "end_line": 258, "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": 260, "end_line": 263, "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": 265, "end_line": 267, "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": 269, "end_line": 273, "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": 275, "end_line": 285, "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": 287, "end_line": 295, "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": 297, "end_line": 303, "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": 305, "end_line": 312, "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": 314, "end_line": 351, "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": 353, "end_line": 355, "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": 357, "end_line": 361, "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_factories = default_type_factories )", "filename": "ext_tools.py", "nloc": 31, "complexity": 9, "token_count": 154, "parameters": [ "variables", "local_dict", "global_dict", "auto_downcast", "type_factories" ], "start_line": 363, "end_line": 398, "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": 400, "end_line": 427, "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": 429, "end_line": 434, "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": 436, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 443, "end_line": 445, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 447, "end_line": 449, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "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": 159, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "assign_variable_types", "long_name": "assign_variable_types( variables , local_dict = { } , global_dict = { } , auto_downcast = 1 , type_factories = default_type_factories )", "filename": "ext_tools.py", "nloc": 31, "complexity": 9, "token_count": 154, "parameters": [ "variables", "local_dict", "global_dict", "auto_downcast", "type_factories" ], "start_line": 363, "end_line": 398, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , name , code_block , args , local_dict = None , global_dict = None , auto_downcast = 1 , type_factories = None )", "filename": "ext_tools.py", "nloc": 12, "complexity": 4, "token_count": 90, "parameters": [ "self", "name", "code_block", "args", "local_dict", "global_dict", "auto_downcast", "type_factories" ], "start_line": 187, "end_line": 199, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "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": 335, "end_line": 370, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 } ], "nloc": 316, "complexity": 76, "token_count": 1977, "diff_parsed": { "added": [ "import catalog", "import converters", " auto_downcast=1, type_converters=None):", " if type_converters is None:", " type_converters = converters.default", " auto_downcast, type_converters)", " type_converters = converters.default):", " for factory in type_converters:" ], "deleted": [ "", "import scalar_spec", "import sequence_spec", "import common_spec", "import catalog", "", "default_type_factories = [scalar_spec.int_specification(),", " scalar_spec.float_specification(),", " scalar_spec.complex_specification(),", " sequence_spec.string_specification(),", " sequence_spec.list_specification(),", " sequence_spec.dict_specification(),", " sequence_spec.tuple_specification(),", " common_spec.file_specification(),", " common_spec.callable_specification()]", " common_spec.instance_specification(),", " #common_spec.module_specification()]", "", "try:", " from standard_array_spec import array_specification", " default_type_factories.append(array_specification())", "except:", " pass", "", "try:", " # this is currently safe because it doesn't import wxPython.", " import wx_spec", " default_type_factories.append(wx_spec.wx_specification())", "except:", " pass", " auto_downcast=1, type_factories=None):", " if type_factories is None:", " type_factories = default_type_factories", " auto_downcast, type_factories)", " type_factories = default_type_factories):", " for factory in type_factories:" ] } }, { "old_path": "weave/inline_tools.py", "new_path": "weave/inline_tools.py", "filename": "inline_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -445,3 +445,4 @@ def test_suite():\n \n if __name__ == \"__main__\":\n test_function()\n+\n", "added_lines": 1, "deleted_lines": 0, "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 inline_info, cxx_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 = Py::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(inline_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_factories = 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_factories -- optional. list of type specification factories. 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_factories = type_factories,\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_factories = type_factories,\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_factories=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_factories = type_factories)\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_factories = 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_factories = type_factories)\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():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \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 inline_info, cxx_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 = Py::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(inline_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_factories = 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_factories -- optional. list of type specification factories. 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_factories = type_factories,\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_factories = type_factories,\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_factories=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_factories = type_factories)\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_factories = 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_factories = type_factories)\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():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n\nif __name__ == \"__main__\":\n test_function()\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_factories = 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_factories", "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_factories = None , compiler = '' )", "filename": "inline_tools.py", "nloc": 15, "complexity": 3, "token_count": 98, "parameters": [ "code", "arg_names", "local_dict", "global_dict", "auto_downcast", "type_factories", "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_factories = 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_factories", "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( )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "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_factories = 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_factories", "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_factories = None , compiler = '' )", "filename": "inline_tools.py", "nloc": 15, "complexity": 3, "token_count": 98, "parameters": [ "code", "arg_names", "local_dict", "global_dict", "auto_downcast", "type_factories", "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_factories = 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_factories", "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( )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 442, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 246, "complexity": 41, "token_count": 1306, "diff_parsed": { "added": [ "" ], "deleted": [] } }, { "old_path": "weave/scalar_spec.py", "new_path": "weave/scalar_spec.py", "filename": "scalar_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,4 +1,4 @@\n-from base_spec import base_specification\n+from base_spec import base_converter\n import scalar_info\n #from Numeric import *\n from types import *\n@@ -7,29 +7,29 @@\n # general case? maybe ask numeric types how long they are and base\n # the decisions on that.\n \n-numeric_to_blitz_type_mapping = {}\n+numeric_to_c_type_mapping = {}\n \n-numeric_to_blitz_type_mapping['T'] = 'T' # for templates\n-numeric_to_blitz_type_mapping['F'] = 'std::complex '\n-numeric_to_blitz_type_mapping['D'] = 'std::complex '\n-numeric_to_blitz_type_mapping['f'] = 'float'\n-numeric_to_blitz_type_mapping['d'] = 'double'\n-numeric_to_blitz_type_mapping['1'] = 'char'\n-numeric_to_blitz_type_mapping['b'] = 'unsigned char'\n-numeric_to_blitz_type_mapping['s'] = 'short'\n-numeric_to_blitz_type_mapping['i'] = 'int'\n+numeric_to_c_type_mapping['T'] = 'T' # for templates\n+numeric_to_c_type_mapping['F'] = 'std::complex '\n+numeric_to_c_type_mapping['D'] = 'std::complex '\n+numeric_to_c_type_mapping['f'] = 'float'\n+numeric_to_c_type_mapping['d'] = 'double'\n+numeric_to_c_type_mapping['1'] = 'char'\n+numeric_to_c_type_mapping['b'] = 'unsigned char'\n+numeric_to_c_type_mapping['s'] = 'short'\n+numeric_to_c_type_mapping['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.\n-numeric_to_blitz_type_mapping['l'] = 'int'\n+numeric_to_c_type_mapping['l'] = 'int'\n \n # standard Python numeric type mappings.\n-numeric_to_blitz_type_mapping[type(1)] = 'int'\n-numeric_to_blitz_type_mapping[type(1.)] = 'double'\n-numeric_to_blitz_type_mapping[type(1.+1.j)] = 'std::complex '\n+numeric_to_c_type_mapping[type(1)] = 'int'\n+numeric_to_c_type_mapping[type(1.)] = 'double'\n+numeric_to_c_type_mapping[type(1.+1.j)] = 'std::complex '\n #hmmm. The following is likely unsafe...\n-numeric_to_blitz_type_mapping[type(1L)] = 'int'\n+numeric_to_c_type_mapping[type(1L)] = 'int'\n \n-class scalar_specification(base_specification):\n+class scalar_converter(base_converter):\n _build_information = [scalar_info.scalar_info()] \n \n def type_spec(self,name,value):\n@@ -40,7 +40,7 @@ def type_spec(self,name,value):\n return new_spec\n \n def declaration_code(self,inline=0):\n- type = numeric_to_blitz_type_mapping[self.numeric_type]\n+ type = numeric_to_c_type_mapping[self.numeric_type]\n func_type = self.type_name\n name = self.name\n var_name = self.retrieve_py_variable(inline)\n@@ -59,7 +59,7 @@ def __cmp__(self,other):\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.__class__, other.__class__)\n \n-class int_specification(scalar_specification):\n+class int_converter(scalar_converter):\n type_name = 'int'\n def type_match(self,value):\n return type(value) in [IntType, LongType]\n@@ -68,7 +68,7 @@ def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Int(%s);\\n' % (self.name,self.name) \n return code\n \n-class float_specification(scalar_specification):\n+class float_converter(scalar_converter):\n type_name = 'float'\n def type_match(self,value):\n return type(value) in [FloatType]\n@@ -76,7 +76,7 @@ def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Float(%s);\\n' % (self.name,self.name) \n return code\n \n-class complex_specification(scalar_specification):\n+class complex_converter(scalar_converter):\n type_name = 'complex'\n def type_match(self,value):\n return type(value) in [ComplexType]\n", "added_lines": 21, "deleted_lines": 21, "source_code": "from base_spec import base_converter\nimport scalar_info\n#from Numeric import *\nfrom types import *\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\nnumeric_to_c_type_mapping = {}\n\nnumeric_to_c_type_mapping['T'] = 'T' # for templates\nnumeric_to_c_type_mapping['F'] = 'std::complex '\nnumeric_to_c_type_mapping['D'] = 'std::complex '\nnumeric_to_c_type_mapping['f'] = 'float'\nnumeric_to_c_type_mapping['d'] = 'double'\nnumeric_to_c_type_mapping['1'] = 'char'\nnumeric_to_c_type_mapping['b'] = 'unsigned char'\nnumeric_to_c_type_mapping['s'] = 'short'\nnumeric_to_c_type_mapping['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.\nnumeric_to_c_type_mapping['l'] = 'int'\n\n# standard Python numeric type mappings.\nnumeric_to_c_type_mapping[type(1)] = 'int'\nnumeric_to_c_type_mapping[type(1.)] = 'double'\nnumeric_to_c_type_mapping[type(1.+1.j)] = 'std::complex '\n#hmmm. The following is likely unsafe...\nnumeric_to_c_type_mapping[type(1L)] = 'int'\n\nclass scalar_converter(base_converter):\n _build_information = [scalar_info.scalar_info()] \n\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name\n new_spec.numeric_type = type(value)\n return new_spec\n \n def declaration_code(self,inline=0):\n type = numeric_to_c_type_mapping[self.numeric_type]\n func_type = self.type_name\n name = self.name\n var_name = self.retrieve_py_variable(inline)\n template = '%(type)s %(name)s = '\\\n 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n\n def __repr__(self):\n msg = \"(%s:: name: %s, type: %s)\" % \\\n (self.type_name,self.name, self.numeric_type)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.__class__, other.__class__)\n\nclass int_converter(scalar_converter):\n type_name = 'int'\n def type_match(self,value):\n return type(value) in [IntType, LongType]\n \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Int(%s);\\n' % (self.name,self.name) \n return code\n \nclass float_converter(scalar_converter):\n type_name = 'float'\n def type_match(self,value):\n return type(value) in [FloatType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Float(%s);\\n' % (self.name,self.name) \n return code\n\nclass complex_converter(scalar_converter):\n type_name = 'complex'\n def type_match(self,value):\n return type(value) in [ComplexType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Complex(%s.real(),%s.imag());\\n' % \\\n (self.name,self.name,self.name) \n return code\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n ", "source_code_before": "from base_spec import base_specification\nimport scalar_info\n#from Numeric import *\nfrom types import *\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\nnumeric_to_blitz_type_mapping = {}\n\nnumeric_to_blitz_type_mapping['T'] = 'T' # for templates\nnumeric_to_blitz_type_mapping['F'] = 'std::complex '\nnumeric_to_blitz_type_mapping['D'] = 'std::complex '\nnumeric_to_blitz_type_mapping['f'] = 'float'\nnumeric_to_blitz_type_mapping['d'] = 'double'\nnumeric_to_blitz_type_mapping['1'] = 'char'\nnumeric_to_blitz_type_mapping['b'] = 'unsigned char'\nnumeric_to_blitz_type_mapping['s'] = 'short'\nnumeric_to_blitz_type_mapping['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.\nnumeric_to_blitz_type_mapping['l'] = 'int'\n\n# standard Python numeric type mappings.\nnumeric_to_blitz_type_mapping[type(1)] = 'int'\nnumeric_to_blitz_type_mapping[type(1.)] = 'double'\nnumeric_to_blitz_type_mapping[type(1.+1.j)] = 'std::complex '\n#hmmm. The following is likely unsafe...\nnumeric_to_blitz_type_mapping[type(1L)] = 'int'\n\nclass scalar_specification(base_specification):\n _build_information = [scalar_info.scalar_info()] \n\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name\n new_spec.numeric_type = type(value)\n return new_spec\n \n def declaration_code(self,inline=0):\n type = numeric_to_blitz_type_mapping[self.numeric_type]\n func_type = self.type_name\n name = self.name\n var_name = self.retrieve_py_variable(inline)\n template = '%(type)s %(name)s = '\\\n 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n\n def __repr__(self):\n msg = \"(%s:: name: %s, type: %s)\" % \\\n (self.type_name,self.name, self.numeric_type)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.__class__, other.__class__)\n\nclass int_specification(scalar_specification):\n type_name = 'int'\n def type_match(self,value):\n return type(value) in [IntType, LongType]\n \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Int(%s);\\n' % (self.name,self.name) \n return code\n \nclass float_specification(scalar_specification):\n type_name = 'float'\n def type_match(self,value):\n return type(value) in [FloatType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Float(%s);\\n' % (self.name,self.name) \n return code\n\nclass complex_specification(scalar_specification):\n type_name = 'complex'\n def type_match(self,value):\n return type(value) in [ComplexType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Complex(%s.real(),%s.imag());\\n' % \\\n (self.name,self.name,self.name) \n return code\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n ", "methods": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self", "name", "value" ], "start_line": 35, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , inline = 0 )", "filename": "scalar_spec.py", "nloc": 9, "complexity": 1, "token_count": 49, "parameters": [ "self", "inline" ], "start_line": 42, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 52, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 3, "token_count": 42, "parameters": [ "self", "other" ], "start_line": 56, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "value" ], "start_line": 64, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 67, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 73, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 75, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 81, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 83, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 88, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 92, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self", "name", "value" ], "start_line": 35, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , inline = 0 )", "filename": "scalar_spec.py", "nloc": 9, "complexity": 1, "token_count": 49, "parameters": [ "self", "inline" ], "start_line": 42, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 52, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 3, "token_count": 42, "parameters": [ "self", "other" ], "start_line": 56, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "value" ], "start_line": 64, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 67, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 73, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 75, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 81, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 83, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 88, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 92, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "declaration_code", "long_name": "declaration_code( self , inline = 0 )", "filename": "scalar_spec.py", "nloc": 9, "complexity": 1, "token_count": 49, "parameters": [ "self", "inline" ], "start_line": 42, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 } ], "nloc": 70, "complexity": 14, "token_count": 461, "diff_parsed": { "added": [ "from base_spec import base_converter", "numeric_to_c_type_mapping = {}", "numeric_to_c_type_mapping['T'] = 'T' # for templates", "numeric_to_c_type_mapping['F'] = 'std::complex '", "numeric_to_c_type_mapping['D'] = 'std::complex '", "numeric_to_c_type_mapping['f'] = 'float'", "numeric_to_c_type_mapping['d'] = 'double'", "numeric_to_c_type_mapping['1'] = 'char'", "numeric_to_c_type_mapping['b'] = 'unsigned char'", "numeric_to_c_type_mapping['s'] = 'short'", "numeric_to_c_type_mapping['i'] = 'int'", "numeric_to_c_type_mapping['l'] = 'int'", "numeric_to_c_type_mapping[type(1)] = 'int'", "numeric_to_c_type_mapping[type(1.)] = 'double'", "numeric_to_c_type_mapping[type(1.+1.j)] = 'std::complex '", "numeric_to_c_type_mapping[type(1L)] = 'int'", "class scalar_converter(base_converter):", " type = numeric_to_c_type_mapping[self.numeric_type]", "class int_converter(scalar_converter):", "class float_converter(scalar_converter):", "class complex_converter(scalar_converter):" ], "deleted": [ "from base_spec import base_specification", "numeric_to_blitz_type_mapping = {}", "numeric_to_blitz_type_mapping['T'] = 'T' # for templates", "numeric_to_blitz_type_mapping['F'] = 'std::complex '", "numeric_to_blitz_type_mapping['D'] = 'std::complex '", "numeric_to_blitz_type_mapping['f'] = 'float'", "numeric_to_blitz_type_mapping['d'] = 'double'", "numeric_to_blitz_type_mapping['1'] = 'char'", "numeric_to_blitz_type_mapping['b'] = 'unsigned char'", "numeric_to_blitz_type_mapping['s'] = 'short'", "numeric_to_blitz_type_mapping['i'] = 'int'", "numeric_to_blitz_type_mapping['l'] = 'int'", "numeric_to_blitz_type_mapping[type(1)] = 'int'", "numeric_to_blitz_type_mapping[type(1.)] = 'double'", "numeric_to_blitz_type_mapping[type(1.+1.j)] = 'std::complex '", "numeric_to_blitz_type_mapping[type(1L)] = 'int'", "class scalar_specification(base_specification):", " type = numeric_to_blitz_type_mapping[self.numeric_type]", "class int_specification(scalar_specification):", "class float_specification(scalar_specification):", "class complex_specification(scalar_specification):" ] } }, { "old_path": "weave/sequence_spec.py", "new_path": "weave/sequence_spec.py", "filename": "sequence_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -83,3 +83,4 @@ def test():\n def test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n+\n", "added_lines": 1, "deleted_lines": 0, "source_code": "import cxx_info\nfrom base_spec import base_specification\nfrom types import *\nimport os\n\nclass base_cxx_specification(base_specification):\n _build_information = [cxx_info.cxx_info()]\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n return new_spec\n def __repr__(self):\n msg = \"(%s:: name: %s)\" % (self.type_name,self.name)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n \nclass string_specification(base_cxx_specification):\n type_name = 'string'\n def type_match(self,value):\n return type(value) in [StringType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::String %s = convert_to_string(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\n\nclass list_specification(base_cxx_specification):\n type_name = 'list'\n def type_match(self,value):\n return type(value) in [ListType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::List %s = convert_to_list(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\nclass dict_specification(base_cxx_specification):\n type_name = 'dict'\n def type_match(self,value):\n return type(value) in [DictType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::Dict %s = convert_to_dict(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name) \n return code\n \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\nclass tuple_specification(base_cxx_specification):\n type_name = 'tuple'\n def type_match(self,value):\n return type(value) in [TupleType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::Tuple %s = convert_to_tuple(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n\n", "source_code_before": "import cxx_info\nfrom base_spec import base_specification\nfrom types import *\nimport os\n\nclass base_cxx_specification(base_specification):\n _build_information = [cxx_info.cxx_info()]\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n return new_spec\n def __repr__(self):\n msg = \"(%s:: name: %s)\" % (self.type_name,self.name)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n \nclass string_specification(base_cxx_specification):\n type_name = 'string'\n def type_match(self,value):\n return type(value) in [StringType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::String %s = convert_to_string(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\n\nclass list_specification(base_cxx_specification):\n type_name = 'list'\n def type_match(self,value):\n return type(value) in [ListType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::List %s = convert_to_list(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\nclass dict_specification(base_cxx_specification):\n type_name = 'dict'\n def type_match(self,value):\n return type(value) in [DictType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::Dict %s = convert_to_dict(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name) \n return code\n \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\nclass tuple_specification(base_cxx_specification):\n type_name = 'tuple'\n def type_match(self,value):\n return type(value) in [TupleType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::Tuple %s = convert_to_tuple(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n", "methods": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "sequence_spec.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "self", "name", "value" ], "start_line": 8, "end_line": 12, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 13, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "self", "other" ], "start_line": 16, "end_line": 19, "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": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 23, "end_line": 24, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 26, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 31, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 38, "end_line": 39, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 41, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 46, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 52, "end_line": 53, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 55, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 61, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 67, "end_line": 68, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 70, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 75, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 79, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 83, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "sequence_spec.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "self", "name", "value" ], "start_line": 8, "end_line": 12, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 13, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "self", "other" ], "start_line": 16, "end_line": 19, "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": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 23, "end_line": 24, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 26, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 31, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 38, "end_line": 39, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 41, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 46, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 52, "end_line": 53, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 55, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 61, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 67, "end_line": 68, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 70, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 75, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 79, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 83, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 70, "complexity": 18, "token_count": 482, "diff_parsed": { "added": [ "" ], "deleted": [] } }, { "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": "@@ -1,11 +1,11 @@\n-from base_spec import base_specification\n-from scalar_spec import numeric_to_blitz_type_mapping\n+from base_spec import base_converter\n+from scalar_spec import numeric_to_c_type_mapping\n from Numeric import *\n from types import *\n import os\n import standard_array_info\n \n-class array_specification(base_specification):\n+class array_converter(base_converter):\n _build_information = [standard_array_info.array_info()]\n \n def type_match(self,value):\n@@ -13,7 +13,7 @@ def type_match(self,value):\n \n def type_spec(self,name,value):\n # factory\n- new_spec = array_specification()\n+ new_spec = array_converter()\n new_spec.name = name\n new_spec.numeric_type = value.typecode()\n # dims not used, but here for compatibility with blitz_spec\n@@ -28,7 +28,7 @@ def declaration_code(self,templatize = 0,inline=0):\n return code\n \n def inline_decl_code(self):\n- type = numeric_to_blitz_type_mapping[self.numeric_type]\n+ type = numeric_to_c_type_mapping[self.numeric_type]\n name = self.name\n var_name = self.retrieve_py_variable(inline=1)\n templ = '// %(name)s array declaration\\n' \\\n@@ -42,7 +42,7 @@ def inline_decl_code(self):\n return code\n \n def standard_decl_code(self): \n- type = numeric_to_blitz_type_mapping[self.numeric_type]\n+ type = numeric_to_c_type_mapping[self.numeric_type]\n name = self.name\n templ = '// %(name)s array declaration\\n' \\\n 'PyArrayObject* %(name)s = convert_to_numpy(py_%(name)s,\"%(name)s\");\\n' \\\n@@ -58,7 +58,7 @@ def standard_decl_code(self):\n # be redone in the c function.\n # \"\"\"\n # templ_dict = {}\n- # templ_dict['type'] = numeric_to_blitz_type_mapping[self.numeric_type]\n+ # templ_dict['type'] = numeric_to_c_type_mapping[self.numeric_type]\n # templ_dict['dims'] = self.dims\n # templ_dict['name'] = self.name\n # code = 'blitz::Array<%(type)s,%(dims)d> &%(name)s' % templ_dict\n@@ -86,9 +86,6 @@ def __cmp__(self,other):\n cmp(self.dims, other.dims) or \\\n cmp(self.__class__, other.__class__)\n \n-import ext_tools\n-standard_array_factories = [array_specification()] + ext_tools.default_type_factories\n-\n def test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n", "added_lines": 7, "deleted_lines": 10, "source_code": "from base_spec import base_converter\nfrom scalar_spec import numeric_to_c_type_mapping\nfrom Numeric import *\nfrom types import *\nimport os\nimport standard_array_info\n\nclass array_converter(base_converter):\n _build_information = [standard_array_info.array_info()]\n \n def type_match(self,value):\n return type(value) is ArrayType\n\n def type_spec(self,name,value):\n # factory\n new_spec = array_converter()\n new_spec.name = name\n new_spec.numeric_type = value.typecode()\n # dims not used, but here for compatibility with blitz_spec\n new_spec.dims = len(shape(value))\n return new_spec\n\n def declaration_code(self,templatize = 0,inline=0):\n if inline:\n code = self.inline_decl_code()\n else:\n code = self.standard_decl_code()\n return code\n \n def inline_decl_code(self):\n type = numeric_to_c_type_mapping[self.numeric_type]\n name = self.name\n var_name = self.retrieve_py_variable(inline=1)\n templ = '// %(name)s array declaration\\n' \\\n 'py_%(name)s= %(var_name)s;\\n' \\\n 'PyArrayObject* %(name)s = convert_to_numpy(py_%(name)s,\"%(name)s\");\\n' \\\n 'int* _N%(name)s = %(name)s->dimensions;\\n' \\\n 'int* _S%(name)s = %(name)s->strides;\\n' \\\n 'int _D%(name)s = %(name)s->nd;\\n' \\\n '%(type)s* %(name)s_data = (%(type)s*) %(name)s->data;\\n' \n code = templ % locals()\n return code\n\n def standard_decl_code(self): \n type = numeric_to_c_type_mapping[self.numeric_type]\n name = self.name\n templ = '// %(name)s array declaration\\n' \\\n 'PyArrayObject* %(name)s = convert_to_numpy(py_%(name)s,\"%(name)s\");\\n' \\\n 'int* _N%(name)s = %(name)s->dimensions;\\n' \\\n 'int* _S%(name)s = %(name)s->strides;\\n' \\\n 'int _D%(name)s = %(name)s->nd;\\n' \\\n '%(type)s* %(name)s_data = (%(type)s*) %(name)s->data;\\n' \n code = templ % locals()\n return code\n #def c_function_declaration_code(self):\n # \"\"\"\n # This doesn't pass the size through. That info is gonna have to \n # be redone in the c function.\n # \"\"\"\n # templ_dict = {}\n # templ_dict['type'] = numeric_to_c_type_mapping[self.numeric_type]\n # templ_dict['dims'] = self.dims\n # templ_dict['name'] = self.name\n # code = 'blitz::Array<%(type)s,%(dims)d> &%(name)s' % templ_dict\n # return code\n \n def local_dict_code(self):\n code = '// for now, array \"%s\" is not returned as arryas are edited' \\\n ' in place (should this change?)\\n' % (self.name) \n return code\n\n def cleanup_code(self):\n # could use Py_DECREF here I think and save NULL test.\n code = \"Py_XDECREF(py_%s);\\n\" % self.name\n return code\n\n def __repr__(self):\n msg = \"(array:: name: %s, type: %s)\" % \\\n (self.name, self.numeric_type)\n return msg\n\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.dims, other.dims) or \\\n cmp(self.__class__, other.__class__)\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n", "source_code_before": "from base_spec import base_specification\nfrom scalar_spec import numeric_to_blitz_type_mapping\nfrom Numeric import *\nfrom types import *\nimport os\nimport standard_array_info\n\nclass array_specification(base_specification):\n _build_information = [standard_array_info.array_info()]\n \n def type_match(self,value):\n return type(value) is ArrayType\n\n def type_spec(self,name,value):\n # factory\n new_spec = array_specification()\n new_spec.name = name\n new_spec.numeric_type = value.typecode()\n # dims not used, but here for compatibility with blitz_spec\n new_spec.dims = len(shape(value))\n return new_spec\n\n def declaration_code(self,templatize = 0,inline=0):\n if inline:\n code = self.inline_decl_code()\n else:\n code = self.standard_decl_code()\n return code\n \n def inline_decl_code(self):\n type = numeric_to_blitz_type_mapping[self.numeric_type]\n name = self.name\n var_name = self.retrieve_py_variable(inline=1)\n templ = '// %(name)s array declaration\\n' \\\n 'py_%(name)s= %(var_name)s;\\n' \\\n 'PyArrayObject* %(name)s = convert_to_numpy(py_%(name)s,\"%(name)s\");\\n' \\\n 'int* _N%(name)s = %(name)s->dimensions;\\n' \\\n 'int* _S%(name)s = %(name)s->strides;\\n' \\\n 'int _D%(name)s = %(name)s->nd;\\n' \\\n '%(type)s* %(name)s_data = (%(type)s*) %(name)s->data;\\n' \n code = templ % locals()\n return code\n\n def standard_decl_code(self): \n type = numeric_to_blitz_type_mapping[self.numeric_type]\n name = self.name\n templ = '// %(name)s array declaration\\n' \\\n 'PyArrayObject* %(name)s = convert_to_numpy(py_%(name)s,\"%(name)s\");\\n' \\\n 'int* _N%(name)s = %(name)s->dimensions;\\n' \\\n 'int* _S%(name)s = %(name)s->strides;\\n' \\\n 'int _D%(name)s = %(name)s->nd;\\n' \\\n '%(type)s* %(name)s_data = (%(type)s*) %(name)s->data;\\n' \n code = templ % locals()\n return code\n #def c_function_declaration_code(self):\n # \"\"\"\n # This doesn't pass the size through. That info is gonna have to \n # be redone in the c function.\n # \"\"\"\n # templ_dict = {}\n # templ_dict['type'] = numeric_to_blitz_type_mapping[self.numeric_type]\n # templ_dict['dims'] = self.dims\n # templ_dict['name'] = self.name\n # code = 'blitz::Array<%(type)s,%(dims)d> &%(name)s' % templ_dict\n # return code\n \n def local_dict_code(self):\n code = '// for now, array \"%s\" is not returned as arryas are edited' \\\n ' in place (should this change?)\\n' % (self.name) \n return code\n\n def cleanup_code(self):\n # could use Py_DECREF here I think and save NULL test.\n code = \"Py_XDECREF(py_%s);\\n\" % self.name\n return code\n\n def __repr__(self):\n msg = \"(array:: name: %s, type: %s)\" % \\\n (self.name, self.numeric_type)\n return msg\n\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.dims, other.dims) or \\\n cmp(self.__class__, other.__class__)\n\nimport ext_tools\nstandard_array_factories = [array_specification()] + ext_tools.default_type_factories\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n", "methods": [ { "name": "type_match", "long_name": "type_match( self , value )", "filename": "standard_array_spec.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "value" ], "start_line": 11, "end_line": 12, "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": "standard_array_spec.py", "nloc": 6, "complexity": 1, "token_count": 41, "parameters": [ "self", "name", "value" ], "start_line": 14, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "templatize", "inline" ], "start_line": 23, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "inline_decl_code", "long_name": "inline_decl_code( self )", "filename": "standard_array_spec.py", "nloc": 13, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 30, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "standard_decl_code", "long_name": "standard_decl_code( self )", "filename": "standard_array_spec.py", "nloc": 11, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 44, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "standard_array_spec.py", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 67, "end_line": 70, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 72, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "standard_array_spec.py", "nloc": 4, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 77, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "standard_array_spec.py", "nloc": 5, "complexity": 4, "token_count": 54, "parameters": [ "self", "other" ], "start_line": 82, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 89, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 93, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "type_match", "long_name": "type_match( self , value )", "filename": "standard_array_spec.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "value" ], "start_line": 11, "end_line": 12, "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": "standard_array_spec.py", "nloc": 6, "complexity": 1, "token_count": 41, "parameters": [ "self", "name", "value" ], "start_line": 14, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "templatize", "inline" ], "start_line": 23, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "inline_decl_code", "long_name": "inline_decl_code( self )", "filename": "standard_array_spec.py", "nloc": 13, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 30, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "standard_decl_code", "long_name": "standard_decl_code( self )", "filename": "standard_array_spec.py", "nloc": 11, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 44, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "standard_array_spec.py", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 67, "end_line": 70, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 72, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "standard_array_spec.py", "nloc": 4, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 77, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "standard_array_spec.py", "nloc": 5, "complexity": 4, "token_count": 54, "parameters": [ "self", "other" ], "start_line": 82, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "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": "inline_decl_code", "long_name": "inline_decl_code( self )", "filename": "standard_array_spec.py", "nloc": 13, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 30, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "standard_array_spec.py", "nloc": 6, "complexity": 1, "token_count": 41, "parameters": [ "self", "name", "value" ], "start_line": 14, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "standard_decl_code", "long_name": "standard_decl_code( self )", "filename": "standard_array_spec.py", "nloc": 11, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 44, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 } ], "nloc": 68, "complexity": 15, "token_count": 363, "diff_parsed": { "added": [ "from base_spec import base_converter", "from scalar_spec import numeric_to_c_type_mapping", "class array_converter(base_converter):", " new_spec = array_converter()", " type = numeric_to_c_type_mapping[self.numeric_type]", " type = numeric_to_c_type_mapping[self.numeric_type]", " # templ_dict['type'] = numeric_to_c_type_mapping[self.numeric_type]" ], "deleted": [ "from base_spec import base_specification", "from scalar_spec import numeric_to_blitz_type_mapping", "class array_specification(base_specification):", " new_spec = array_specification()", " type = numeric_to_blitz_type_mapping[self.numeric_type]", " type = numeric_to_blitz_type_mapping[self.numeric_type]", " # templ_dict['type'] = numeric_to_blitz_type_mapping[self.numeric_type]", "import ext_tools", "standard_array_factories = [array_specification()] + ext_tools.default_type_factories", "" ] } }, { "old_path": "weave/tests/test_common_spec.py", "new_path": "weave/tests/test_common_spec.py", "filename": "test_common_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -6,7 +6,7 @@\n import inline_tools\n restore_path()\n \n-class test_file_specification(unittest.TestCase): \n+class test_file_converter(unittest.TestCase): \n def check_py_to_file(self):\n import tempfile\n file_name = tempfile.mktemp() \n@@ -35,10 +35,10 @@ def check_file_to_py(self):\n file = open(file_name,'r')\n assert(file.read() == \"hello fred\")\n \n-class test_instance_specification(unittest.TestCase): \n+class test_instance_converter(unittest.TestCase): \n pass\n \n-class test_callable_specification(unittest.TestCase): \n+class test_callable_converter(unittest.TestCase): \n def check_call_function(self):\n import string\n func = string.find\n@@ -59,9 +59,9 @@ def check_call_function(self):\n \n def test_suite():\n suites = [] \n- suites.append( unittest.makeSuite(test_file_specification,'check_'))\n- suites.append( unittest.makeSuite(test_instance_specification,'check_'))\n- suites.append( unittest.makeSuite(test_callable_specification,'check_'))\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 total_suite = unittest.TestSuite(suites)\n return total_suite\n \n", "added_lines": 6, "deleted_lines": 6, "source_code": "import unittest\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport inline_tools\nrestore_path()\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 = PyString_AsString( file_name.ptr() );\n FILE* file = fopen(_file_name,\"w\");\n Py::Object file_obj(file_to_py(file,_file_name,\"w\"));\n return_val = Py::new_reference_to(file_obj);\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\nclass test_instance_converter(unittest.TestCase): \n pass\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 Py::Tuple args(2);\n args[0] = Py::String(search_str);\n args[1] = Py::String(sub_str);\n PyObject* result = PyObject_CallObject(func,args.ptr());\n return_val = Py::new_reference_to(Py::Int(result));\n \"\"\"\n actual = inline_tools.inline(code,['func','search_str','sub_str'])\n desired = func(search_str,sub_str) \n assert(desired == actual)\n\ndef test_suite():\n suites = [] \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 total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "source_code_before": "import unittest\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport inline_tools\nrestore_path()\n \nclass test_file_specification(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 = PyString_AsString( file_name.ptr() );\n FILE* file = fopen(_file_name,\"w\");\n Py::Object file_obj(file_to_py(file,_file_name,\"w\"));\n return_val = Py::new_reference_to(file_obj);\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\nclass test_instance_specification(unittest.TestCase): \n pass\n \nclass test_callable_specification(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 Py::Tuple args(2);\n args[0] = Py::String(search_str);\n args[1] = Py::String(sub_str);\n PyObject* result = PyObject_CallObject(func,args.ptr());\n return_val = Py::new_reference_to(Py::Int(result));\n \"\"\"\n actual = inline_tools.inline(code,['func','search_str','sub_str'])\n desired = func(search_str,sub_str) \n assert(desired == actual)\n\ndef test_suite():\n suites = [] \n suites.append( unittest.makeSuite(test_file_specification,'check_'))\n suites.append( unittest.makeSuite(test_instance_specification,'check_'))\n suites.append( unittest.makeSuite(test_callable_specification,'check_'))\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "check_py_to_file", "long_name": "check_py_to_file( self )", "filename": "test_common_spec.py", "nloc": 11, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 10, "end_line": 20, "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_common_spec.py", "nloc": 14, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 21, "end_line": 36, "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_common_spec.py", "nloc": 15, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 42, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_common_spec.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 60, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_common_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 68, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_py_to_file", "long_name": "check_py_to_file( self )", "filename": "test_common_spec.py", "nloc": 11, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 10, "end_line": 20, "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_common_spec.py", "nloc": 14, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 21, "end_line": 36, "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_common_spec.py", "nloc": 15, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 42, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_common_spec.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 60, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_common_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 68, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_common_spec.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 60, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 } ], "nloc": 63, "complexity": 5, "token_count": 305, "diff_parsed": { "added": [ "class test_file_converter(unittest.TestCase):", "class test_instance_converter(unittest.TestCase):", "class test_callable_converter(unittest.TestCase):", " suites.append( unittest.makeSuite(test_file_converter,'check_'))", " suites.append( unittest.makeSuite(test_instance_converter,'check_'))", " suites.append( unittest.makeSuite(test_callable_converter,'check_'))" ], "deleted": [ "class test_file_specification(unittest.TestCase):", "class test_instance_specification(unittest.TestCase):", "class test_callable_specification(unittest.TestCase):", " suites.append( unittest.makeSuite(test_file_specification,'check_'))", " suites.append( unittest.makeSuite(test_instance_specification,'check_'))", " suites.append( unittest.makeSuite(test_callable_specification,'check_'))" ] } }, { "old_path": "weave/tests/test_ext_tools.py", "new_path": "weave/tests/test_ext_tools.py", "filename": "test_ext_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -7,7 +7,7 @@\n add_grandparent_to_path(__name__)\n import ext_tools\n try:\n- from standard_array_spec import array_specification\n+ from standard_array_spec import array_converter\n except ImportError:\n pass # requires Numeric \n restore_path()\n@@ -125,12 +125,12 @@ def check_assign_variable_types(self):\n actual = ext_tools.assign_variable_types(arg_list,locals()) \n #desired = {'a':(Float32,1),'b':(Float32,1),'i':(Int32,0)}\n \n- ad = array_specification()\n+ ad = array_converter()\n ad.name, ad.numeric_type, ad.dims = 'a', Float32, 1\n- bd = array_specification()\n+ bd = array_converter()\n bd.name, bd.numeric_type, bd.dims = 'b', Float64, 1\n import scalar_spec\n- cd = scalar_spec.int_specification()\n+ cd = scalar_spec.int_converter()\n cd.name, cd.numeric_type = 'c', types.IntType \n desired = [ad,bd,cd]\n expr = \"\"\n", "added_lines": 4, "deleted_lines": 4, "source_code": "import unittest\nimport time\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\nfrom scipy_distutils.misc_util import add_local_to_path\n\nadd_grandparent_to_path(__name__)\nimport ext_tools\ntry:\n from standard_array_spec import array_converter\nexcept ImportError:\n pass # requires Numeric \nrestore_path()\n\nadd_local_to_path(__name__)\nfrom weave_test_utils import *\nrestore_path()\n\nbuild_dir = empty_temp_dir()\nprint 'building extensions here:', build_dir \n\nclass test_ext_module(unittest.TestCase):\n #should really do some testing of where modules end up\n def check_simple(self):\n \"\"\" Simplest possible module \"\"\"\n mod = ext_tools.ext_module('simple_ext_module')\n mod.compile(location = build_dir)\n import simple_ext_module\n def check_multi_functions(self):\n mod = ext_tools.ext_module('module_multi_function')\n var_specs = []\n code = \"\"\n test = ext_tools.ext_function_from_specs('test',code,var_specs)\n mod.add_function(test)\n test2 = ext_tools.ext_function_from_specs('test2',code,var_specs)\n mod.add_function(test2)\n mod.compile(location = build_dir)\n import module_multi_function\n module_multi_function.test()\n module_multi_function.test2()\n def check_with_include(self):\n # decalaring variables\n a = 2.;\n \n # declare module\n mod = ext_tools.ext_module('ext_module_with_include')\n mod.customize.add_header('')\n \n # function 2 --> a little more complex expression\n var_specs = ext_tools.assign_variable_types(['a'],locals(),globals())\n code = \"\"\"\n std::cout << std::endl;\n std::cout << \"test printing a value:\" << a << std::endl;\n \"\"\"\n test = ext_tools.ext_function_from_specs('test',code,var_specs)\n mod.add_function(test)\n # build module\n mod.compile(location = build_dir)\n import ext_module_with_include\n ext_module_with_include.test(a)\n\n def check_string_and_int(self): \n # decalaring variables\n a = 2;b = 'string' \n # declare module\n mod = ext_tools.ext_module('ext_string_and_int')\n code = \"\"\"\n a=b.length();\n return_val = Py::new_reference_to(Py::Int(a));\n \"\"\"\n test = ext_tools.ext_function('test',code,['a','b'])\n mod.add_function(test)\n mod.compile(location = build_dir)\n import ext_string_and_int\n c = ext_string_and_int.test(a,b)\n assert(c == len(b))\n \n def check_return_tuple(self): \n # decalaring variables\n a = 2 \n # declare module\n mod = ext_tools.ext_module('ext_return_tuple')\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n int b;\n b = a + 1;\n Py::Tuple returned(2);\n returned[0] = Py::Int(a);\n returned[1] = Py::Int(b);\n return_val = Py::new_reference_to(returned);\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = build_dir)\n import ext_return_tuple\n c,d = ext_return_tuple.test(a)\n assert(c==a and d == a+1)\n \nclass test_ext_function(unittest.TestCase):\n #should really do some testing of where modules end up\n def check_simple(self):\n \"\"\" Simplest possible function \"\"\"\n mod = ext_tools.ext_module('simple_ext_function')\n var_specs = []\n code = \"\"\n test = ext_tools.ext_function_from_specs('test',code,var_specs)\n mod.add_function(test)\n mod.compile(location = build_dir)\n import simple_ext_function\n simple_ext_function.test()\n \nclass test_assign_variable_types(unittest.TestCase): \n def check_assign_variable_types(self):\n try:\n from Numeric import arange, Float32, Float64\n except:\n # skip this test if Numeric not installed\n return\n \n import types\n a = arange(10,typecode = Float32)\n b = arange(5,typecode = Float64)\n c = 5\n arg_list = ['a','b','c']\n actual = ext_tools.assign_variable_types(arg_list,locals()) \n #desired = {'a':(Float32,1),'b':(Float32,1),'i':(Int32,0)}\n \n ad = array_converter()\n ad.name, ad.numeric_type, ad.dims = 'a', Float32, 1\n bd = array_converter()\n bd.name, bd.numeric_type, bd.dims = 'b', Float64, 1\n import scalar_spec\n cd = scalar_spec.int_converter()\n cd.name, cd.numeric_type = 'c', types.IntType \n desired = [ad,bd,cd]\n expr = \"\"\n print_assert_equal(expr,actual,desired)\n\n\ndef test_suite():\n suites = []\n suites.append( unittest.makeSuite(test_assign_variable_types,'check_') )\n suites.append( unittest.makeSuite(test_ext_module,'check_'))\n suites.append( unittest.makeSuite(test_ext_function,'check_')) \n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\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\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\nfrom scipy_distutils.misc_util import add_local_to_path\n\nadd_grandparent_to_path(__name__)\nimport ext_tools\ntry:\n from standard_array_spec import array_specification\nexcept ImportError:\n pass # requires Numeric \nrestore_path()\n\nadd_local_to_path(__name__)\nfrom weave_test_utils import *\nrestore_path()\n\nbuild_dir = empty_temp_dir()\nprint 'building extensions here:', build_dir \n\nclass test_ext_module(unittest.TestCase):\n #should really do some testing of where modules end up\n def check_simple(self):\n \"\"\" Simplest possible module \"\"\"\n mod = ext_tools.ext_module('simple_ext_module')\n mod.compile(location = build_dir)\n import simple_ext_module\n def check_multi_functions(self):\n mod = ext_tools.ext_module('module_multi_function')\n var_specs = []\n code = \"\"\n test = ext_tools.ext_function_from_specs('test',code,var_specs)\n mod.add_function(test)\n test2 = ext_tools.ext_function_from_specs('test2',code,var_specs)\n mod.add_function(test2)\n mod.compile(location = build_dir)\n import module_multi_function\n module_multi_function.test()\n module_multi_function.test2()\n def check_with_include(self):\n # decalaring variables\n a = 2.;\n \n # declare module\n mod = ext_tools.ext_module('ext_module_with_include')\n mod.customize.add_header('')\n \n # function 2 --> a little more complex expression\n var_specs = ext_tools.assign_variable_types(['a'],locals(),globals())\n code = \"\"\"\n std::cout << std::endl;\n std::cout << \"test printing a value:\" << a << std::endl;\n \"\"\"\n test = ext_tools.ext_function_from_specs('test',code,var_specs)\n mod.add_function(test)\n # build module\n mod.compile(location = build_dir)\n import ext_module_with_include\n ext_module_with_include.test(a)\n\n def check_string_and_int(self): \n # decalaring variables\n a = 2;b = 'string' \n # declare module\n mod = ext_tools.ext_module('ext_string_and_int')\n code = \"\"\"\n a=b.length();\n return_val = Py::new_reference_to(Py::Int(a));\n \"\"\"\n test = ext_tools.ext_function('test',code,['a','b'])\n mod.add_function(test)\n mod.compile(location = build_dir)\n import ext_string_and_int\n c = ext_string_and_int.test(a,b)\n assert(c == len(b))\n \n def check_return_tuple(self): \n # decalaring variables\n a = 2 \n # declare module\n mod = ext_tools.ext_module('ext_return_tuple')\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n int b;\n b = a + 1;\n Py::Tuple returned(2);\n returned[0] = Py::Int(a);\n returned[1] = Py::Int(b);\n return_val = Py::new_reference_to(returned);\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = build_dir)\n import ext_return_tuple\n c,d = ext_return_tuple.test(a)\n assert(c==a and d == a+1)\n \nclass test_ext_function(unittest.TestCase):\n #should really do some testing of where modules end up\n def check_simple(self):\n \"\"\" Simplest possible function \"\"\"\n mod = ext_tools.ext_module('simple_ext_function')\n var_specs = []\n code = \"\"\n test = ext_tools.ext_function_from_specs('test',code,var_specs)\n mod.add_function(test)\n mod.compile(location = build_dir)\n import simple_ext_function\n simple_ext_function.test()\n \nclass test_assign_variable_types(unittest.TestCase): \n def check_assign_variable_types(self):\n try:\n from Numeric import arange, Float32, Float64\n except:\n # skip this test if Numeric not installed\n return\n \n import types\n a = arange(10,typecode = Float32)\n b = arange(5,typecode = Float64)\n c = 5\n arg_list = ['a','b','c']\n actual = ext_tools.assign_variable_types(arg_list,locals()) \n #desired = {'a':(Float32,1),'b':(Float32,1),'i':(Int32,0)}\n \n ad = array_specification()\n ad.name, ad.numeric_type, ad.dims = 'a', Float32, 1\n bd = array_specification()\n bd.name, bd.numeric_type, bd.dims = 'b', Float64, 1\n import scalar_spec\n cd = scalar_spec.int_specification()\n cd.name, cd.numeric_type = 'c', types.IntType \n desired = [ad,bd,cd]\n expr = \"\"\n print_assert_equal(expr,actual,desired)\n\n\ndef test_suite():\n suites = []\n suites.append( unittest.makeSuite(test_assign_variable_types,'check_') )\n suites.append( unittest.makeSuite(test_ext_module,'check_'))\n suites.append( unittest.makeSuite(test_ext_function,'check_')) \n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 24, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_multi_functions", "long_name": "check_multi_functions( self )", "filename": "test_ext_tools.py", "nloc": 12, "complexity": 1, "token_count": 76, "parameters": [ "self" ], "start_line": 29, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "check_with_include", "long_name": "check_with_include( self )", "filename": "test_ext_tools.py", "nloc": 14, "complexity": 1, "token_count": 81, "parameters": [ "self" ], "start_line": 41, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_string_and_int", "long_name": "check_string_and_int( self )", "filename": "test_ext_tools.py", "nloc": 13, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 62, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_return_tuple", "long_name": "check_return_tuple( self )", "filename": "test_ext_tools.py", "nloc": 18, "complexity": 2, "token_count": 85, "parameters": [ "self" ], "start_line": 78, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_ext_tools.py", "nloc": 9, "complexity": 1, "token_count": 54, "parameters": [ "self" ], "start_line": 101, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_assign_variable_types", "long_name": "check_assign_variable_types( self )", "filename": "test_ext_tools.py", "nloc": 21, "complexity": 2, "token_count": 150, "parameters": [ "self" ], "start_line": 113, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_ext_tools.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 140, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 148, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 24, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_multi_functions", "long_name": "check_multi_functions( self )", "filename": "test_ext_tools.py", "nloc": 12, "complexity": 1, "token_count": 76, "parameters": [ "self" ], "start_line": 29, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "check_with_include", "long_name": "check_with_include( self )", "filename": "test_ext_tools.py", "nloc": 14, "complexity": 1, "token_count": 81, "parameters": [ "self" ], "start_line": 41, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_string_and_int", "long_name": "check_string_and_int( self )", "filename": "test_ext_tools.py", "nloc": 13, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 62, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_return_tuple", "long_name": "check_return_tuple( self )", "filename": "test_ext_tools.py", "nloc": 18, "complexity": 2, "token_count": 85, "parameters": [ "self" ], "start_line": 78, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_ext_tools.py", "nloc": 9, "complexity": 1, "token_count": 54, "parameters": [ "self" ], "start_line": 101, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_assign_variable_types", "long_name": "check_assign_variable_types( self )", "filename": "test_ext_tools.py", "nloc": 21, "complexity": 2, "token_count": 150, "parameters": [ "self" ], "start_line": 113, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_ext_tools.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 140, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 148, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "check_assign_variable_types", "long_name": "check_assign_variable_types( self )", "filename": "test_ext_tools.py", "nloc": 21, "complexity": 2, "token_count": 150, "parameters": [ "self" ], "start_line": 113, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 } ], "nloc": 124, "complexity": 11, "token_count": 723, "diff_parsed": { "added": [ " from standard_array_spec import array_converter", " ad = array_converter()", " bd = array_converter()", " cd = scalar_spec.int_converter()" ], "deleted": [ " from standard_array_spec import array_specification", " ad = array_specification()", " bd = array_specification()", " cd = scalar_spec.int_specification()" ] } }, { "old_path": "weave/tests/test_scalar_spec.py", "new_path": "weave/tests/test_scalar_spec.py", "filename": "test_scalar_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -39,19 +39,19 @@ def print_assert_equal(test_string,actual,desired):\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n \n-class test_int_specification(unittest.TestCase):\n+class test_int_converter(unittest.TestCase):\n compiler = '' \n def check_type_match_string(self):\n- s = scalar_spec.int_specification()\n+ s = scalar_spec.int_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n- s = scalar_spec.int_specification() \n+ s = scalar_spec.int_converter() \n assert(s.type_match(5))\n def check_type_match_float(self):\n- s = scalar_spec.int_specification() \n+ s = scalar_spec.int_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n- s = scalar_spec.int_specification() \n+ s = scalar_spec.int_converter() \n assert(not s.type_match(5.+1j))\n def check_var_in(self):\n test_dir = setup_test_location()\n@@ -113,19 +113,19 @@ def check_int_return(self):\n teardown_test_location()\n assert( c == 3)\n \n-class test_float_specification(unittest.TestCase): \n+class test_float_converter(unittest.TestCase): \n compiler = ''\n def check_type_match_string(self):\n- s = scalar_spec.float_specification()\n+ s = scalar_spec.float_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n- s = scalar_spec.float_specification() \n+ s = scalar_spec.float_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n- s = scalar_spec.float_specification() \n+ s = scalar_spec.float_converter() \n assert(s.type_match(5.))\n def check_type_match_complex(self):\n- s = scalar_spec.float_specification() \n+ s = scalar_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@@ -187,19 +187,19 @@ def check_float_return(self):\n teardown_test_location()\n assert( c == 3.)\n \n-class test_complex_specification(unittest.TestCase): \n+class test_complex_converter(unittest.TestCase): \n compiler = ''\n def check_type_match_string(self):\n- s = scalar_spec.complex_specification()\n+ s = scalar_spec.complex_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n- s = scalar_spec.complex_specification() \n+ s = scalar_spec.complex_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n- s = scalar_spec.complex_specification() \n+ s = scalar_spec.complex_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n- s = scalar_spec.complex_specification() \n+ s = scalar_spec.complex_converter() \n assert(s.type_match(5.+1j))\n def check_complex_var_in(self):\n test_dir = setup_test_location() \n@@ -260,25 +260,25 @@ def check_complex_return(self):\n teardown_test_location() \n assert( c == 3.+3j)\n \n-class test_msvc_int_specification(test_int_specification): \n+class test_msvc_int_converter(test_int_converter): \n compiler = 'msvc'\n-class test_msvc_float_specification(test_float_specification): \n+class test_msvc_float_converter(test_float_converter): \n compiler = 'msvc'\n-class test_msvc_complex_specification(test_complex_specification): \n+class test_msvc_complex_converter(test_complex_converter): \n compiler = 'msvc'\n \n-class test_unix_int_specification(test_int_specification): \n+class test_unix_int_converter(test_int_converter): \n compiler = ''\n-class test_unix_float_specification(test_float_specification): \n+class test_unix_float_converter(test_float_converter): \n compiler = ''\n-class test_unix_complex_specification(test_complex_specification): \n+class test_unix_complex_converter(test_complex_converter): \n compiler = ''\n \n-class test_gcc_int_specification(test_int_specification): \n+class test_gcc_int_converter(test_int_converter): \n compiler = 'gcc'\n-class test_gcc_float_specification(test_float_specification): \n+class test_gcc_float_converter(test_float_converter): \n compiler = 'gcc'\n-class test_gcc_complex_specification(test_complex_specification): \n+class test_gcc_complex_converter(test_complex_converter): \n compiler = 'gcc'\n \n \n@@ -303,19 +303,19 @@ def test_suite():\n suites = []\n \n if msvc_exists():\n- suites.append( unittest.makeSuite(test_msvc_int_specification,'check_'))\n- suites.append( unittest.makeSuite(test_msvc_float_specification,'check_')) \n- suites.append( unittest.makeSuite(test_msvc_complex_specification,'check_'))\n+ suites.append( unittest.makeSuite(test_msvc_int_converter,'check_'))\n+ suites.append( unittest.makeSuite(test_msvc_float_converter,'check_')) \n+ suites.append( unittest.makeSuite(test_msvc_complex_converter,'check_'))\n pass\n else: # unix\n- suites.append( unittest.makeSuite(test_unix_int_specification,'check_'))\n- suites.append( unittest.makeSuite(test_unix_float_specification,'check_')) \n- suites.append( unittest.makeSuite(test_unix_complex_specification,'check_'))\n+ suites.append( unittest.makeSuite(test_unix_int_converter,'check_'))\n+ suites.append( unittest.makeSuite(test_unix_float_converter,'check_')) \n+ suites.append( unittest.makeSuite(test_unix_complex_converter,'check_'))\n \n if gcc_exists(): \n- suites.append( unittest.makeSuite(test_gcc_int_specification,'check_'))\n- suites.append( unittest.makeSuite(test_gcc_float_specification,'check_')) \n- suites.append( unittest.makeSuite(test_gcc_complex_specification,'check_'))\n+ suites.append( unittest.makeSuite(test_gcc_int_converter,'check_'))\n+ suites.append( unittest.makeSuite(test_gcc_float_converter,'check_')) \n+ suites.append( unittest.makeSuite(test_gcc_complex_converter,'check_'))\n \n total_suite = unittest.TestSuite(suites)\n return total_suite\n", "added_lines": 33, "deleted_lines": 33, "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 ext_tools\nfrom catalog import unique_file\nfrom build_tools import msvc_exists, gcc_exists\nimport scalar_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.scipy_test\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_int_converter(unittest.TestCase):\n compiler = '' \n def check_type_match_string(self):\n s = scalar_spec.int_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.int_converter() \n assert(s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.int_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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_var_local(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 = \"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 q={}\n test(b,q)\n teardown_test_location()\n assert(q['a'] == 2)\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 = Py::new_reference_to(Py::Int(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 = scalar_spec.float_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.float_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.float_converter() \n assert(s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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 def check_float_var_local(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 = \"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 q={}\n test(b,q)\n teardown_test_location()\n assert(q['a'] == 2.)\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 = Py::new_reference_to(Py::Float(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 = scalar_spec.complex_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.complex_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.complex_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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 def check_complex_var_local(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= 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 q={}\n test(b,q)\n teardown_test_location() \n assert(q['a'] == 3.+3j)\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 = Py::new_reference_to(Py::Complex(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 \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)\ndef test_suite():\n suites = []\n\n if msvc_exists():\n suites.append( unittest.makeSuite(test_msvc_int_converter,'check_'))\n suites.append( unittest.makeSuite(test_msvc_float_converter,'check_')) \n suites.append( unittest.makeSuite(test_msvc_complex_converter,'check_'))\n pass\n else: # unix\n suites.append( unittest.makeSuite(test_unix_int_converter,'check_'))\n suites.append( unittest.makeSuite(test_unix_float_converter,'check_')) \n suites.append( unittest.makeSuite(test_unix_complex_converter,'check_'))\n \n if gcc_exists(): \n suites.append( unittest.makeSuite(test_gcc_int_converter,'check_'))\n suites.append( unittest.makeSuite(test_gcc_float_converter,'check_')) \n suites.append( unittest.makeSuite(test_gcc_complex_converter,'check_'))\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\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 ext_tools\nfrom catalog import unique_file\nfrom build_tools import msvc_exists, gcc_exists\nimport scalar_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.scipy_test\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_int_specification(unittest.TestCase):\n compiler = '' \n def check_type_match_string(self):\n s = scalar_spec.int_specification()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.int_specification() \n assert(s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.int_specification() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_spec.int_specification() \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_var_local(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 = \"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 q={}\n test(b,q)\n teardown_test_location()\n assert(q['a'] == 2)\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 = Py::new_reference_to(Py::Int(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_specification(unittest.TestCase): \n compiler = ''\n def check_type_match_string(self):\n s = scalar_spec.float_specification()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.float_specification() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.float_specification() \n assert(s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_spec.float_specification() \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 def check_float_var_local(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 = \"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 q={}\n test(b,q)\n teardown_test_location()\n assert(q['a'] == 2.)\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 = Py::new_reference_to(Py::Float(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_specification(unittest.TestCase): \n compiler = ''\n def check_type_match_string(self):\n s = scalar_spec.complex_specification()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.complex_specification() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.complex_specification() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_spec.complex_specification() \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 def check_complex_var_local(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= 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 q={}\n test(b,q)\n teardown_test_location() \n assert(q['a'] == 3.+3j)\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 = Py::new_reference_to(Py::Complex(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_specification(test_int_specification): \n compiler = 'msvc'\nclass test_msvc_float_specification(test_float_specification): \n compiler = 'msvc'\nclass test_msvc_complex_specification(test_complex_specification): \n compiler = 'msvc'\n\nclass test_unix_int_specification(test_int_specification): \n compiler = ''\nclass test_unix_float_specification(test_float_specification): \n compiler = ''\nclass test_unix_complex_specification(test_complex_specification): \n compiler = ''\n\nclass test_gcc_int_specification(test_int_specification): \n compiler = 'gcc'\nclass test_gcc_float_specification(test_float_specification): \n compiler = 'gcc'\nclass test_gcc_complex_specification(test_complex_specification): \n compiler = 'gcc'\n \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)\ndef test_suite():\n suites = []\n\n if msvc_exists():\n suites.append( unittest.makeSuite(test_msvc_int_specification,'check_'))\n suites.append( unittest.makeSuite(test_msvc_float_specification,'check_')) \n suites.append( unittest.makeSuite(test_msvc_complex_specification,'check_'))\n pass\n else: # unix\n suites.append( unittest.makeSuite(test_unix_int_specification,'check_'))\n suites.append( unittest.makeSuite(test_unix_float_specification,'check_')) \n suites.append( unittest.makeSuite(test_unix_complex_specification,'check_'))\n \n if gcc_exists(): \n suites.append( unittest.makeSuite(test_gcc_int_specification,'check_'))\n suites.append( unittest.makeSuite(test_gcc_float_specification,'check_')) \n suites.append( unittest.makeSuite(test_gcc_complex_specification,'check_'))\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\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_scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "d", "file_name" ], "start_line": 14, "end_line": 17, "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_scalar_spec.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "in_str" ], "start_line": 19, "end_line": 24, "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_scalar_spec.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 26, "end_line": 40, "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_scalar_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_int", "long_name": "check_type_match_int( self )", "filename": "test_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "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": "check_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 50, "end_line": 52, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 53, "end_line": 55, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 116, "parameters": [ "self" ], "start_line": 56, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_int_var_local", "long_name": "check_int_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 112, "parameters": [ "self" ], "start_line": 81, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_int_return", "long_name": "check_int_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 97, "end_line": 114, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 118, "end_line": 120, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 121, "end_line": 123, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 124, "end_line": 126, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 127, "end_line": 129, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 126, "parameters": [ "self" ], "start_line": 130, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "check_float_var_local", "long_name": "check_float_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 115, "parameters": [ "self" ], "start_line": 155, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_float_return", "long_name": "check_float_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 108, "parameters": [ "self" ], "start_line": 171, "end_line": 188, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 192, "end_line": 194, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 195, "end_line": 197, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 198, "end_line": 200, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 201, "end_line": 203, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 130, "parameters": [ "self" ], "start_line": 204, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_complex_var_local", "long_name": "check_complex_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 121, "parameters": [ "self" ], "start_line": 228, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_complex_return", "long_name": "check_complex_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 114, "parameters": [ "self" ], "start_line": 244, "end_line": 261, "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_scalar_spec.py", "nloc": 7, "complexity": 2, "token_count": 51, "parameters": [], "start_line": 285, "end_line": 291, "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_scalar_spec.py", "nloc": 6, "complexity": 2, "token_count": 45, "parameters": [], "start_line": 293, "end_line": 298, "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_scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "name" ], "start_line": 300, "end_line": 301, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_scalar_spec.py", "nloc": 17, "complexity": 3, "token_count": 148, "parameters": [], "start_line": 302, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 323, "end_line": 327, "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_scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "d", "file_name" ], "start_line": 14, "end_line": 17, "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_scalar_spec.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "in_str" ], "start_line": 19, "end_line": 24, "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_scalar_spec.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 26, "end_line": 40, "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_scalar_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_int", "long_name": "check_type_match_int( self )", "filename": "test_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "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": "check_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 50, "end_line": 52, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 53, "end_line": 55, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 116, "parameters": [ "self" ], "start_line": 56, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_int_var_local", "long_name": "check_int_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 112, "parameters": [ "self" ], "start_line": 81, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_int_return", "long_name": "check_int_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 97, "end_line": 114, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 118, "end_line": 120, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 121, "end_line": 123, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 124, "end_line": 126, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 127, "end_line": 129, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 126, "parameters": [ "self" ], "start_line": 130, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "check_float_var_local", "long_name": "check_float_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 115, "parameters": [ "self" ], "start_line": 155, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_float_return", "long_name": "check_float_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 108, "parameters": [ "self" ], "start_line": 171, "end_line": 188, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 192, "end_line": 194, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 195, "end_line": 197, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 198, "end_line": 200, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 201, "end_line": 203, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 130, "parameters": [ "self" ], "start_line": 204, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_complex_var_local", "long_name": "check_complex_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 121, "parameters": [ "self" ], "start_line": 228, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_complex_return", "long_name": "check_complex_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 114, "parameters": [ "self" ], "start_line": 244, "end_line": 261, "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_scalar_spec.py", "nloc": 7, "complexity": 2, "token_count": 51, "parameters": [], "start_line": 285, "end_line": 291, "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_scalar_spec.py", "nloc": 6, "complexity": 2, "token_count": 45, "parameters": [], "start_line": 293, "end_line": 298, "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_scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "name" ], "start_line": 300, "end_line": 301, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_scalar_spec.py", "nloc": 17, "complexity": 3, "token_count": 148, "parameters": [], "start_line": 302, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 323, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_scalar_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_int", "long_name": "check_type_match_int( self )", "filename": "test_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "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( )", "filename": "test_scalar_spec.py", "nloc": 17, "complexity": 3, "token_count": 148, "parameters": [], "start_line": 302, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "check_type_match_complex", "long_name": "check_type_match_complex( self )", "filename": "test_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 53, "end_line": 55, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 50, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 } ], "nloc": 306, "complexity": 40, "token_count": 1947, "diff_parsed": { "added": [ "class test_int_converter(unittest.TestCase):", " s = scalar_spec.int_converter()", " s = scalar_spec.int_converter()", " s = scalar_spec.int_converter()", " s = scalar_spec.int_converter()", "class test_float_converter(unittest.TestCase):", " s = scalar_spec.float_converter()", " s = scalar_spec.float_converter()", " s = scalar_spec.float_converter()", " s = scalar_spec.float_converter()", "class test_complex_converter(unittest.TestCase):", " s = scalar_spec.complex_converter()", " s = scalar_spec.complex_converter()", " s = scalar_spec.complex_converter()", " s = scalar_spec.complex_converter()", "class test_msvc_int_converter(test_int_converter):", "class test_msvc_float_converter(test_float_converter):", "class test_msvc_complex_converter(test_complex_converter):", "class test_unix_int_converter(test_int_converter):", "class test_unix_float_converter(test_float_converter):", "class test_unix_complex_converter(test_complex_converter):", "class test_gcc_int_converter(test_int_converter):", "class test_gcc_float_converter(test_float_converter):", "class test_gcc_complex_converter(test_complex_converter):", " suites.append( unittest.makeSuite(test_msvc_int_converter,'check_'))", " suites.append( unittest.makeSuite(test_msvc_float_converter,'check_'))", " suites.append( unittest.makeSuite(test_msvc_complex_converter,'check_'))", " suites.append( unittest.makeSuite(test_unix_int_converter,'check_'))", " suites.append( unittest.makeSuite(test_unix_float_converter,'check_'))", " suites.append( unittest.makeSuite(test_unix_complex_converter,'check_'))", " suites.append( unittest.makeSuite(test_gcc_int_converter,'check_'))", " suites.append( unittest.makeSuite(test_gcc_float_converter,'check_'))", " suites.append( unittest.makeSuite(test_gcc_complex_converter,'check_'))" ], "deleted": [ "class test_int_specification(unittest.TestCase):", " s = scalar_spec.int_specification()", " s = scalar_spec.int_specification()", " s = scalar_spec.int_specification()", " s = scalar_spec.int_specification()", "class test_float_specification(unittest.TestCase):", " s = scalar_spec.float_specification()", " s = scalar_spec.float_specification()", " s = scalar_spec.float_specification()", " s = scalar_spec.float_specification()", "class test_complex_specification(unittest.TestCase):", " s = scalar_spec.complex_specification()", " s = scalar_spec.complex_specification()", " s = scalar_spec.complex_specification()", " s = scalar_spec.complex_specification()", "class test_msvc_int_specification(test_int_specification):", "class test_msvc_float_specification(test_float_specification):", "class test_msvc_complex_specification(test_complex_specification):", "class test_unix_int_specification(test_int_specification):", "class test_unix_float_specification(test_float_specification):", "class test_unix_complex_specification(test_complex_specification):", "class test_gcc_int_specification(test_int_specification):", "class test_gcc_float_specification(test_float_specification):", "class test_gcc_complex_specification(test_complex_specification):", " suites.append( unittest.makeSuite(test_msvc_int_specification,'check_'))", " suites.append( unittest.makeSuite(test_msvc_float_specification,'check_'))", " suites.append( unittest.makeSuite(test_msvc_complex_specification,'check_'))", " suites.append( unittest.makeSuite(test_unix_int_specification,'check_'))", " suites.append( unittest.makeSuite(test_unix_float_specification,'check_'))", " suites.append( unittest.makeSuite(test_unix_complex_specification,'check_'))", " suites.append( unittest.makeSuite(test_gcc_int_specification,'check_'))", " suites.append( unittest.makeSuite(test_gcc_float_specification,'check_'))", " suites.append( unittest.makeSuite(test_gcc_complex_specification,'check_'))" ] } }, { "old_path": "weave/tests/test_sequence_spec.py", "new_path": "weave/tests/test_sequence_spec.py", "filename": "test_sequence_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -6,7 +6,7 @@\n import inline_tools\n restore_path()\n \n-class test_sequence_specification(unittest.TestCase): \n+class test_sequence_converter(unittest.TestCase): \n def check_convert_to_dict(self):\n d = {}\n inline_tools.inline(\"\",['d']) \n@@ -22,7 +22,7 @@ def check_convert_to_tuple(self):\n \n def test_suite():\n suites = [] \n- suites.append( unittest.makeSuite(test_sequence_specification,'check_'))\n+ suites.append( unittest.makeSuite(test_sequence_converter,'check_'))\n total_suite = unittest.TestSuite(suites)\n return total_suite\n \n", "added_lines": 2, "deleted_lines": 2, "source_code": "import unittest\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport inline_tools\nrestore_path()\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 \ndef test_suite():\n suites = [] \n suites.append( unittest.makeSuite(test_sequence_converter,'check_'))\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "source_code_before": "import unittest\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport inline_tools\nrestore_path()\n \nclass test_sequence_specification(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 \ndef test_suite():\n suites = [] \n suites.append( unittest.makeSuite(test_sequence_specification,'check_'))\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "check_convert_to_dict", "long_name": "check_convert_to_dict( self )", "filename": "test_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 10, "end_line": 12, "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_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 13, "end_line": 15, "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_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 16, "end_line": 18, "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_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 19, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 23, "end_line": 27, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 29, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_convert_to_dict", "long_name": "check_convert_to_dict( self )", "filename": "test_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 10, "end_line": 12, "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_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 13, "end_line": 15, "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_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 16, "end_line": 18, "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_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 19, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 23, "end_line": 27, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 29, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 23, "end_line": 27, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 30, "complexity": 6, "token_count": 171, "diff_parsed": { "added": [ "class test_sequence_converter(unittest.TestCase):", " suites.append( unittest.makeSuite(test_sequence_converter,'check_'))" ], "deleted": [ "class test_sequence_specification(unittest.TestCase):", " suites.append( unittest.makeSuite(test_sequence_specification,'check_'))" ] } }, { "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": "@@ -37,21 +37,21 @@ def print_assert_equal(test_string,actual,desired):\n pprint.pprint(desired,msg)\n raise AssertionError, msg.getvalue()\n \n-class test_array_specification(unittest.TestCase): \n+class test_array_converter(unittest.TestCase): \n def check_type_match_string(self):\n- s = standard_array_spec.array_specification()\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_specification() \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_specification() \n+ s = standard_array_spec.array_converter() \n assert(s.type_match(arange(4)))\n \n def test_suite():\n suites = []\n \n- suites.append( unittest.makeSuite(test_array_specification,'check_'))\n+ suites.append( unittest.makeSuite(test_array_converter,'check_'))\n \n total_suite = unittest.TestSuite(suites)\n return total_suite\n", "added_lines": 5, "deleted_lines": 5, "source_code": "import unittest\nfrom Numeric import *\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from fastumath import *\nexcept:\n pass # 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.scipy_test\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():\n suites = []\n \n suites.append( unittest.makeSuite(test_array_converter,'check_'))\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\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 fastumath import *\nexcept:\n pass # 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.scipy_test\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_specification(unittest.TestCase): \n def check_type_match_string(self):\n s = standard_array_spec.array_specification()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = standard_array_spec.array_specification() \n assert(not s.type_match(5))\n def check_type_match_array(self):\n s = standard_array_spec.array_specification() \n assert(s.type_match(arange(4)))\n\ndef test_suite():\n suites = []\n \n suites.append( unittest.makeSuite(test_array_specification,'check_'))\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\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( )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "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( )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "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( )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "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( )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "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": "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": "test_suite", "long_name": "test_suite( )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 51, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "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 } ], "nloc": 53, "complexity": 8, "token_count": 301, "diff_parsed": { "added": [ "class test_array_converter(unittest.TestCase):", " s = standard_array_spec.array_converter()", " s = standard_array_spec.array_converter()", " s = standard_array_spec.array_converter()", " suites.append( unittest.makeSuite(test_array_converter,'check_'))" ], "deleted": [ "class test_array_specification(unittest.TestCase):", " s = standard_array_spec.array_specification()", " s = standard_array_spec.array_specification()", " s = standard_array_spec.array_specification()", " suites.append( unittest.makeSuite(test_array_specification,'check_'))" ] } }, { "old_path": "weave/tests/test_string_spec.py", "new_path": "weave/tests/test_string_spec.py", "filename": "test_string_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -14,18 +14,18 @@\n sys.path.append('..')\n import ext_tools\n \n-class test_string_specification(unittest.TestCase): \n+class test_string_converter(unittest.TestCase): \n def check_type_match_string(self):\n- s = ext_tools.string_specification()\n+ s = ext_tools.string_converter()\n assert( s.type_match('string') )\n def check_type_match_int(self):\n- s = ext_tools.string_specification() \n+ s = ext_tools.string_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n- s = ext_tools.string_specification() \n+ s = ext_tools.string_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n- s = ext_tools.string_specification() \n+ s = ext_tools.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@@ -78,14 +78,14 @@ def check_return(self):\n c = string_return.test(b)\n assert( c == 'hello')\n \n-class test_list_specification(unittest.TestCase): \n+class test_list_converter(unittest.TestCase): \n def check_type_match_bad(self):\n- s = ext_tools.list_specification()\n+ s = ext_tools.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 = ext_tools.list_specification() \n+ s = ext_tools.list_converter() \n assert(s.type_match([]))\n def check_var_in(self):\n mod = ext_tools.ext_module('list_var_in')\n@@ -201,14 +201,14 @@ def check_speed(self):\n print 'python:', t2 - t1 \n assert( sum1 == sum2 and sum1 == sum3)\n \n-class test_tuple_specification(unittest.TestCase): \n+class test_tuple_converter(unittest.TestCase): \n def check_type_match_bad(self):\n- s = ext_tools.tuple_specification()\n+ s = ext_tools.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 = ext_tools.tuple_specification() \n+ s = ext_tools.tuple_converter() \n assert(s.type_match((1,)))\n def check_var_in(self):\n mod = ext_tools.ext_module('tuple_var_in')\n@@ -266,14 +266,14 @@ def check_return(self):\n assert( c == ('hello',None))\n \n \n-class test_dict_specification(unittest.TestCase): \n+class test_dict_converter(unittest.TestCase): \n def check_type_match_bad(self):\n- s = ext_tools.dict_specification()\n+ s = ext_tools.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 = ext_tools.dict_specification() \n+ s = ext_tools.dict_converter() \n assert(s.type_match({}))\n def check_var_in(self):\n mod = ext_tools.ext_module('dict_var_in')\n@@ -333,10 +333,10 @@ def check_return(self):\n def test_suite():\n suites = []\n \n- #suites.append( unittest.makeSuite(test_string_specification,'check_'))\n- suites.append( unittest.makeSuite(test_list_specification,'check_'))\n- #suites.append( unittest.makeSuite(test_tuple_specification,'check_'))\n- #suites.append( unittest.makeSuite(test_dict_specification,'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 total_suite = unittest.TestSuite(suites)\n return total_suite\n \n", "added_lines": 18, "deleted_lines": 18, "source_code": "\"\"\"\ncheck_var_in -- tests whether a variable is passed in correctly\n and also if the passed in variable can be reassigned\ncheck_var_local -- tests wheter a variable is passed in , modified,\n and returned correctly in the local_dict dictionary\n argument\ncheck_return -- test whether a variable is passed in, modified, and\n then returned as a function return value correctly \n\"\"\"\nimport unittest\nimport time\n\nimport sys\nsys.path.append('..')\nimport ext_tools\n\nclass test_string_converter(unittest.TestCase): \n def check_type_match_string(self):\n s = ext_tools.string_converter()\n assert( s.type_match('string') )\n def check_type_match_int(self):\n s = ext_tools.string_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = ext_tools.string_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = ext_tools.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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::String(\"hello\");'\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('string_var_local')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::String(\"hello\");'\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import string_var_local\n b='bub'\n q={}\n string_var_local.test(b,q)\n assert(q['a'] == 'hello')\n def check_return(self):\n mod = ext_tools.ext_module('string_return')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a= Py::String(\"hello\");\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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 = ext_tools.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 = ext_tools.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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::List();'\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('list_var_local')\n a = []\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::List();\n a.append(Py::String(\"hello\"));\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import list_var_local\n a=[1,2]\n q={}\n list_var_local.test(a,q)\n assert(q['a'] == ['hello'])\n def check_return(self):\n mod = ext_tools.ext_module('list_return')\n a = [1]\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::List();\n a.append(Py::String(\"hello\"));\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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);b=1 # b to force availability of py_to_scalar\n var_specs = ext_tools.assign_variable_types(['a','b'],locals())\n code = \"\"\"\n Py::Int v = Py::Int();\n int vv, sum = 0; \n for(int i = 0; i < a.length(); 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 = Py::new_reference_to(Py::Int(sum));\n \"\"\"\n with_cxx = ext_tools.ext_function('with_cxx',var_specs,code)\n mod.add_function(with_cxx)\n code = \"\"\"\n int vv, sum = 0;\n PyObject *a_ptr = a.ptr(), *v; \n for(int i = 0; i < a.length(); i++)\n {\n v = PyList_GetItem(a_ptr,i);\n //didn't set error here -- just speed test\n vv = py_to_scalar(v,\"list item\");\n if (vv % 2)\n sum += vv;\n else\n sum -= vv; \n }\n return_val = Py::new_reference_to(Py::Int(sum));\n \"\"\"\n no_checking = ext_tools.ext_function('no_checking',var_specs,code)\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,b)\n t2 = time.time()\n print 'cxx:', t2 - t1\n t1 = time.time()\n sum2 = list_speed.no_checking(a,b)\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 = ext_tools.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 = ext_tools.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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::Tuple();'\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('tuple_var_local')\n a = (1,)\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Tuple(2);\n a[0] = Py::String(\"hello\");\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import tuple_var_local\n a=(1,2)\n q={}\n tuple_var_local.test(a,q)\n assert(q['a'] == ('hello',None))\n def check_return(self):\n mod = ext_tools.ext_module('tuple_return')\n a = (1,)\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Tuple(2);\n a[0] = Py::String(\"hello\");\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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 = ext_tools.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 = ext_tools.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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::Dict();' # This just checks to make sure the type is correct\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('dict_var_local')\n a = {'z':1}\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Dict();\n a[Py::String(\"hello\")] = Py::Int(5);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import dict_var_local\n a = {'z':2}\n q={}\n dict_var_local.test(a,q)\n assert(q['a']['hello'] == 5)\n def check_return(self):\n mod = ext_tools.ext_module('dict_return')\n a = {'z':1}\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Dict();\n a[Py::String(\"hello\")] = Py::Int(5);\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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():\n suites = []\n \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 total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "source_code_before": "\"\"\"\ncheck_var_in -- tests whether a variable is passed in correctly\n and also if the passed in variable can be reassigned\ncheck_var_local -- tests wheter a variable is passed in , modified,\n and returned correctly in the local_dict dictionary\n argument\ncheck_return -- test whether a variable is passed in, modified, and\n then returned as a function return value correctly \n\"\"\"\nimport unittest\nimport time\n\nimport sys\nsys.path.append('..')\nimport ext_tools\n\nclass test_string_specification(unittest.TestCase): \n def check_type_match_string(self):\n s = ext_tools.string_specification()\n assert( s.type_match('string') )\n def check_type_match_int(self):\n s = ext_tools.string_specification() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = ext_tools.string_specification() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = ext_tools.string_specification() \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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::String(\"hello\");'\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('string_var_local')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::String(\"hello\");'\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import string_var_local\n b='bub'\n q={}\n string_var_local.test(b,q)\n assert(q['a'] == 'hello')\n def check_return(self):\n mod = ext_tools.ext_module('string_return')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a= Py::String(\"hello\");\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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_specification(unittest.TestCase): \n def check_type_match_bad(self):\n s = ext_tools.list_specification()\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 = ext_tools.list_specification() \n assert(s.type_match([]))\n def check_var_in(self):\n mod = ext_tools.ext_module('list_var_in')\n a = [1]\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::List();'\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('list_var_local')\n a = []\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::List();\n a.append(Py::String(\"hello\"));\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import list_var_local\n a=[1,2]\n q={}\n list_var_local.test(a,q)\n assert(q['a'] == ['hello'])\n def check_return(self):\n mod = ext_tools.ext_module('list_return')\n a = [1]\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::List();\n a.append(Py::String(\"hello\"));\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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);b=1 # b to force availability of py_to_scalar\n var_specs = ext_tools.assign_variable_types(['a','b'],locals())\n code = \"\"\"\n Py::Int v = Py::Int();\n int vv, sum = 0; \n for(int i = 0; i < a.length(); 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 = Py::new_reference_to(Py::Int(sum));\n \"\"\"\n with_cxx = ext_tools.ext_function('with_cxx',var_specs,code)\n mod.add_function(with_cxx)\n code = \"\"\"\n int vv, sum = 0;\n PyObject *a_ptr = a.ptr(), *v; \n for(int i = 0; i < a.length(); i++)\n {\n v = PyList_GetItem(a_ptr,i);\n //didn't set error here -- just speed test\n vv = py_to_scalar(v,\"list item\");\n if (vv % 2)\n sum += vv;\n else\n sum -= vv; \n }\n return_val = Py::new_reference_to(Py::Int(sum));\n \"\"\"\n no_checking = ext_tools.ext_function('no_checking',var_specs,code)\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,b)\n t2 = time.time()\n print 'cxx:', t2 - t1\n t1 = time.time()\n sum2 = list_speed.no_checking(a,b)\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_specification(unittest.TestCase): \n def check_type_match_bad(self):\n s = ext_tools.tuple_specification()\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 = ext_tools.tuple_specification() \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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::Tuple();'\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('tuple_var_local')\n a = (1,)\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Tuple(2);\n a[0] = Py::String(\"hello\");\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import tuple_var_local\n a=(1,2)\n q={}\n tuple_var_local.test(a,q)\n assert(q['a'] == ('hello',None))\n def check_return(self):\n mod = ext_tools.ext_module('tuple_return')\n a = (1,)\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Tuple(2);\n a[0] = Py::String(\"hello\");\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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_specification(unittest.TestCase): \n def check_type_match_bad(self):\n s = ext_tools.dict_specification()\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 = ext_tools.dict_specification() \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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::Dict();' # This just checks to make sure the type is correct\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('dict_var_local')\n a = {'z':1}\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Dict();\n a[Py::String(\"hello\")] = Py::Int(5);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import dict_var_local\n a = {'z':2}\n q={}\n dict_var_local.test(a,q)\n assert(q['a']['hello'] == 5)\n def check_return(self):\n mod = ext_tools.ext_module('dict_return')\n a = {'z':1}\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Dict();\n a[Py::String(\"hello\")] = Py::Int(5);\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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():\n suites = []\n \n #suites.append( unittest.makeSuite(test_string_specification,'check_'))\n suites.append( unittest.makeSuite(test_list_specification,'check_'))\n #suites.append( unittest.makeSuite(test_tuple_specification,'check_'))\n #suites.append( unittest.makeSuite(test_dict_specification,'check_'))\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 18, "end_line": 20, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 21, "end_line": 23, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 24, "end_line": 26, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "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_var_in", "long_name": "check_var_in( self )", "filename": "test_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 98, "parameters": [ "self" ], "start_line": 30, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 13, "complexity": 1, "token_count": 82, "parameters": [ "self" ], "start_line": 52, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 15, "complexity": 1, "token_count": 75, "parameters": [ "self" ], "start_line": 65, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 82, "end_line": 86, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 87, "end_line": 89, "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_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 104, "parameters": [ "self" ], "start_line": 90, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 89, "parameters": [ "self" ], "start_line": 112, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 83, "parameters": [ "self" ], "start_line": 128, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_speed", "long_name": "check_speed( self )", "filename": "test_string_spec.py", "nloc": 58, "complexity": 4, "token_count": 201, "parameters": [ "self" ], "start_line": 145, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 1 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 205, "end_line": 209, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 210, "end_line": 212, "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_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 105, "parameters": [ "self" ], "start_line": 213, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 93, "parameters": [ "self" ], "start_line": 235, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 86, "parameters": [ "self" ], "start_line": 251, "end_line": 266, "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_string_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 270, "end_line": 274, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 275, "end_line": 277, "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_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 106, "parameters": [ "self" ], "start_line": 278, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 93, "parameters": [ "self" ], "start_line": 300, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 86, "parameters": [ "self" ], "start_line": 316, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 333, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 343, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 18, "end_line": 20, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 21, "end_line": 23, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 24, "end_line": 26, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "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_var_in", "long_name": "check_var_in( self )", "filename": "test_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 98, "parameters": [ "self" ], "start_line": 30, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 13, "complexity": 1, "token_count": 82, "parameters": [ "self" ], "start_line": 52, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 15, "complexity": 1, "token_count": 75, "parameters": [ "self" ], "start_line": 65, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 82, "end_line": 86, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 87, "end_line": 89, "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_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 104, "parameters": [ "self" ], "start_line": 90, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 89, "parameters": [ "self" ], "start_line": 112, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 83, "parameters": [ "self" ], "start_line": 128, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_speed", "long_name": "check_speed( self )", "filename": "test_string_spec.py", "nloc": 58, "complexity": 4, "token_count": 201, "parameters": [ "self" ], "start_line": 145, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 1 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 205, "end_line": 209, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 210, "end_line": 212, "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_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 105, "parameters": [ "self" ], "start_line": 213, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 93, "parameters": [ "self" ], "start_line": 235, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 86, "parameters": [ "self" ], "start_line": 251, "end_line": 266, "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_string_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 270, "end_line": 274, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 275, "end_line": 277, "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_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 106, "parameters": [ "self" ], "start_line": 278, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 93, "parameters": [ "self" ], "start_line": 300, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 86, "parameters": [ "self" ], "start_line": 316, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 333, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 343, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 18, "end_line": 20, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 21, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 333, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 82, "end_line": 86, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 87, "end_line": 89, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "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_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 24, "end_line": 26, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 } ], "nloc": 332, "complexity": 39, "token_count": 1738, "diff_parsed": { "added": [ "class test_string_converter(unittest.TestCase):", " s = ext_tools.string_converter()", " s = ext_tools.string_converter()", " s = ext_tools.string_converter()", " s = ext_tools.string_converter()", "class test_list_converter(unittest.TestCase):", " s = ext_tools.list_converter()", " s = ext_tools.list_converter()", "class test_tuple_converter(unittest.TestCase):", " s = ext_tools.tuple_converter()", " s = ext_tools.tuple_converter()", "class test_dict_converter(unittest.TestCase):", " s = ext_tools.dict_converter()", " s = ext_tools.dict_converter()", " #suites.append( unittest.makeSuite(test_string_converter,'check_'))", " suites.append( unittest.makeSuite(test_list_converter,'check_'))", " #suites.append( unittest.makeSuite(test_tuple_converter,'check_'))", " #suites.append( unittest.makeSuite(test_dict_converter,'check_'))" ], "deleted": [ "class test_string_specification(unittest.TestCase):", " s = ext_tools.string_specification()", " s = ext_tools.string_specification()", " s = ext_tools.string_specification()", " s = ext_tools.string_specification()", "class test_list_specification(unittest.TestCase):", " s = ext_tools.list_specification()", " s = ext_tools.list_specification()", "class test_tuple_specification(unittest.TestCase):", " s = ext_tools.tuple_specification()", " s = ext_tools.tuple_specification()", "class test_dict_specification(unittest.TestCase):", " s = ext_tools.dict_specification()", " s = ext_tools.dict_specification()", " #suites.append( unittest.makeSuite(test_string_specification,'check_'))", " suites.append( unittest.makeSuite(test_list_specification,'check_'))", " #suites.append( unittest.makeSuite(test_tuple_specification,'check_'))", " #suites.append( unittest.makeSuite(test_dict_specification,'check_'))" ] } }, { "old_path": "weave/tests/test_wx_spec.py", "new_path": "weave/tests/test_wx_spec.py", "filename": "test_wx_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -19,24 +19,24 @@\n import wxPython\n import wxPython.wx\n \n-class test_wx_specification(unittest.TestCase): \n+class test_wx_converter(unittest.TestCase): \n def check_type_match_string(self):\n- s = wx_spec.wx_specification()\n+ s = wx_spec.wx_converter()\n assert(not s.type_match('string') )\n def check_type_match_int(self):\n- s = wx_spec.wx_specification() \n+ s = wx_spec.wx_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n- s = wx_spec.wx_specification() \n+ s = wx_spec.wx_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n- s = wx_spec.wx_specification() \n+ s = wx_spec.wx_converter() \n assert(not s.type_match(5.+1j))\n def check_type_match_complex(self):\n- s = wx_spec.wx_specification() \n+ s = wx_spec.wx_converter() \n assert(not s.type_match(5.+1j))\n def check_type_match_wxframe(self):\n- s = wx_spec.wx_specification()\n+ s = wx_spec.wx_converter()\n f=wxPython.wx.wxFrame(wxPython.wx.NULL,-1,'bob') \n assert(s.type_match(f))\n \n@@ -96,7 +96,7 @@ def no_check_return(self):\n def test_suite():\n suites = []\n \n- suites.append( unittest.makeSuite(test_wx_specification,'check_'))\n+ suites.append( unittest.makeSuite(test_wx_converter,'check_'))\n total_suite = unittest.TestSuite(suites)\n return total_suite\n \n", "added_lines": 8, "deleted_lines": 8, "source_code": "\"\"\"\ncheck_var_in -- tests whether a variable is passed in correctly\n and also if the passed in variable can be reassigned\ncheck_var_local -- tests wheter a variable is passed in , modified,\n and returned correctly in the local_dict dictionary\n argument\ncheck_return -- test whether a variable is passed in, modified, and\n then returned as a function return value correctly \n\"\"\"\nimport unittest\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport ext_tools\nimport wx_spec\nrestore_path()\n\nimport wxPython\nimport wxPython.wx\n\nclass test_wx_converter(unittest.TestCase): \n def check_type_match_string(self):\n s = wx_spec.wx_converter()\n assert(not s.type_match('string') )\n def check_type_match_int(self):\n s = wx_spec.wx_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = wx_spec.wx_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = wx_spec.wx_converter() \n assert(not s.type_match(5.+1j))\n def check_type_match_complex(self):\n s = wx_spec.wx_converter() \n assert(not s.type_match(5.+1j))\n def check_type_match_wxframe(self):\n s = wx_spec.wx_converter()\n f=wxPython.wx.wxFrame(wxPython.wx.NULL,-1,'bob') \n assert(s.type_match(f))\n \n def check_var_in(self):\n mod = ext_tools.ext_module('wx_var_in',compiler='msvc')\n a = wxPython.wx.wxFrame(wxPython.wx.NULL,-1,'bob') \n code = \"\"\"\n a->SetTitle(wxString(\"jim\"));\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'],locals(),globals())\n mod.add_function(test)\n mod.compile()\n import wx_var_in\n b=a\n wx_var_in.test(b)\n assert(b.GetTitle() == \"jim\")\n try:\n b = 1.\n wx_var_in.test(b)\n except TypeError:\n pass\n try:\n b = 1\n wx_var_in.test(b)\n except TypeError:\n pass\n \n def no_check_var_local(self):\n mod = ext_tools.ext_module('wx_var_local')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::String(\"hello\");'\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import wx_var_local\n b='bub'\n q={}\n wx_var_local.test(b,q)\n assert(q['a'] == 'hello')\n def no_check_return(self):\n mod = ext_tools.ext_module('wx_return')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a= Py::wx(\"hello\");\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import wx_return\n b='bub'\n c = wx_return.test(b)\n assert( c == 'hello')\n\ndef test_suite():\n suites = []\n \n suites.append( unittest.makeSuite(test_wx_converter,'check_'))\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "source_code_before": "\"\"\"\ncheck_var_in -- tests whether a variable is passed in correctly\n and also if the passed in variable can be reassigned\ncheck_var_local -- tests wheter a variable is passed in , modified,\n and returned correctly in the local_dict dictionary\n argument\ncheck_return -- test whether a variable is passed in, modified, and\n then returned as a function return value correctly \n\"\"\"\nimport unittest\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport ext_tools\nimport wx_spec\nrestore_path()\n\nimport wxPython\nimport wxPython.wx\n\nclass test_wx_specification(unittest.TestCase): \n def check_type_match_string(self):\n s = wx_spec.wx_specification()\n assert(not s.type_match('string') )\n def check_type_match_int(self):\n s = wx_spec.wx_specification() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = wx_spec.wx_specification() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = wx_spec.wx_specification() \n assert(not s.type_match(5.+1j))\n def check_type_match_complex(self):\n s = wx_spec.wx_specification() \n assert(not s.type_match(5.+1j))\n def check_type_match_wxframe(self):\n s = wx_spec.wx_specification()\n f=wxPython.wx.wxFrame(wxPython.wx.NULL,-1,'bob') \n assert(s.type_match(f))\n \n def check_var_in(self):\n mod = ext_tools.ext_module('wx_var_in',compiler='msvc')\n a = wxPython.wx.wxFrame(wxPython.wx.NULL,-1,'bob') \n code = \"\"\"\n a->SetTitle(wxString(\"jim\"));\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'],locals(),globals())\n mod.add_function(test)\n mod.compile()\n import wx_var_in\n b=a\n wx_var_in.test(b)\n assert(b.GetTitle() == \"jim\")\n try:\n b = 1.\n wx_var_in.test(b)\n except TypeError:\n pass\n try:\n b = 1\n wx_var_in.test(b)\n except TypeError:\n pass\n \n def no_check_var_local(self):\n mod = ext_tools.ext_module('wx_var_local')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::String(\"hello\");'\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import wx_var_local\n b='bub'\n q={}\n wx_var_local.test(b,q)\n assert(q['a'] == 'hello')\n def no_check_return(self):\n mod = ext_tools.ext_module('wx_return')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a= Py::wx(\"hello\");\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import wx_return\n b='bub'\n c = wx_return.test(b)\n assert( c == 'hello')\n\ndef test_suite():\n suites = []\n \n suites.append( unittest.makeSuite(test_wx_specification,'check_'))\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "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_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 26, "end_line": 28, "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_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 29, "end_line": 31, "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_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "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_type_match_complex", "long_name": "check_type_match_complex( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 35, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_wxframe", "long_name": "check_type_match_wxframe( self )", "filename": "test_wx_spec.py", "nloc": 4, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 38, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_var_in", "long_name": "check_var_in( self )", "filename": "test_wx_spec.py", "nloc": 23, "complexity": 3, "token_count": 124, "parameters": [ "self" ], "start_line": 43, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "no_check_var_local", "long_name": "no_check_var_local( self )", "filename": "test_wx_spec.py", "nloc": 13, "complexity": 1, "token_count": 82, "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": "no_check_return", "long_name": "no_check_return( self )", "filename": "test_wx_spec.py", "nloc": 15, "complexity": 1, "token_count": 75, "parameters": [ "self" ], "start_line": 80, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_wx_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 96, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_wx_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 103, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "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_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 26, "end_line": 28, "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_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 29, "end_line": 31, "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_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "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_type_match_complex", "long_name": "check_type_match_complex( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 35, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_wxframe", "long_name": "check_type_match_wxframe( self )", "filename": "test_wx_spec.py", "nloc": 4, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 38, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_var_in", "long_name": "check_var_in( self )", "filename": "test_wx_spec.py", "nloc": 23, "complexity": 3, "token_count": 124, "parameters": [ "self" ], "start_line": 43, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "no_check_var_local", "long_name": "no_check_var_local( self )", "filename": "test_wx_spec.py", "nloc": 13, "complexity": 1, "token_count": 82, "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": "no_check_return", "long_name": "no_check_return( self )", "filename": "test_wx_spec.py", "nloc": 15, "complexity": 1, "token_count": 75, "parameters": [ "self" ], "start_line": 80, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_wx_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 96, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_wx_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 103, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "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_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 26, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_wx_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 96, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "check_type_match_wxframe", "long_name": "check_type_match_wxframe( self )", "filename": "test_wx_spec.py", "nloc": 4, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 38, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_type_match_complex", "long_name": "check_type_match_complex( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "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_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 29, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 } ], "nloc": 100, "complexity": 13, "token_count": 548, "diff_parsed": { "added": [ "class test_wx_converter(unittest.TestCase):", " s = wx_spec.wx_converter()", " s = wx_spec.wx_converter()", " s = wx_spec.wx_converter()", " s = wx_spec.wx_converter()", " s = wx_spec.wx_converter()", " s = wx_spec.wx_converter()", " suites.append( unittest.makeSuite(test_wx_converter,'check_'))" ], "deleted": [ "class test_wx_specification(unittest.TestCase):", " s = wx_spec.wx_specification()", " s = wx_spec.wx_specification()", " s = wx_spec.wx_specification()", " s = wx_spec.wx_specification()", " s = wx_spec.wx_specification()", " s = wx_spec.wx_specification()", " suites.append( unittest.makeSuite(test_wx_specification,'check_'))" ] } }, { "old_path": "weave/wx_spec.py", "new_path": "weave/wx_spec.py", "filename": "wx_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,6 +1,6 @@\n import wx_info\n import base_info\n-from base_spec import base_specification\n+from base_spec import base_converter\n from types import *\n import os\n \n@@ -27,7 +27,7 @@\n } \n \"\"\" \n \n-class wx_specification(base_specification):\n+class wx_converter(base_converter):\n _build_information = [wx_info.wx_info()]\n def __init__(self,class_name=None):\n self.type_name = 'unkown wx_object'\n", "added_lines": 2, "deleted_lines": 2, "source_code": "import wx_info\nimport base_info\nfrom base_spec import base_converter\nfrom types import *\nimport os\n\nwx_support_template = \\\n\"\"\"\nstatic %(wx_class)s* convert_to_%(wx_class)s(PyObject* py_obj,char* name)\n{\n %(wx_class)s *wx_ptr;\n \n // work on this error reporting...\n if (SWIG_GetPtrObj(py_obj,(void **) &wx_ptr,\"_%(wx_class)s_p\"))\n handle_conversion_error(py_obj,\"%(wx_class)s\", name);\n return wx_ptr;\n} \n\nstatic %(wx_class)s* py_to_%(wx_class)s(PyObject* py_obj,char* name)\n{\n %(wx_class)s *wx_ptr;\n \n // work on this error reporting...\n if (SWIG_GetPtrObj(py_obj,(void **) &wx_ptr,\"_%(wx_class)s_p\"))\n handle_bad_type(py_obj,\"%(wx_class)s\", name);\n return wx_ptr;\n} \n\"\"\" \n\nclass wx_converter(base_converter):\n _build_information = [wx_info.wx_info()]\n def __init__(self,class_name=None):\n self.type_name = 'unkown wx_object'\n if class_name:\n # customize support_code for whatever type I was handed.\n vals = {'wx_class': class_name}\n specialized_support = wx_support_template % vals\n custom = base_info.base_info()\n custom._support_code = [specialized_support]\n self._build_information = self._build_information + [custom]\n self.type_name = class_name\n\n def type_match(self,value):\n try:\n class_name = value.this.split('_')[-2]\n if class_name[:2] == 'wx':\n return 1\n except AttributeError:\n pass\n return 0\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 def declaration_code(self,inline=0):\n type = self.type_name\n name = self.name\n var_name = self.retrieve_py_variable(inline)\n template = '%(type)s *%(name)s = '\\\n 'convert_to_%(type)s(%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n \n def __repr__(self):\n msg = \"(%s:: name: %s)\" % (self.type_name,self.name)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__) or \\\n cmp(self.type_name,other.type_name)\n\n\"\"\"\n# this should only be enabled on machines with access to a display device\n# It'll cause problems otherwise.\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n\"\"\" ", "source_code_before": "import wx_info\nimport base_info\nfrom base_spec import base_specification\nfrom types import *\nimport os\n\nwx_support_template = \\\n\"\"\"\nstatic %(wx_class)s* convert_to_%(wx_class)s(PyObject* py_obj,char* name)\n{\n %(wx_class)s *wx_ptr;\n \n // work on this error reporting...\n if (SWIG_GetPtrObj(py_obj,(void **) &wx_ptr,\"_%(wx_class)s_p\"))\n handle_conversion_error(py_obj,\"%(wx_class)s\", name);\n return wx_ptr;\n} \n\nstatic %(wx_class)s* py_to_%(wx_class)s(PyObject* py_obj,char* name)\n{\n %(wx_class)s *wx_ptr;\n \n // work on this error reporting...\n if (SWIG_GetPtrObj(py_obj,(void **) &wx_ptr,\"_%(wx_class)s_p\"))\n handle_bad_type(py_obj,\"%(wx_class)s\", name);\n return wx_ptr;\n} \n\"\"\" \n\nclass wx_specification(base_specification):\n _build_information = [wx_info.wx_info()]\n def __init__(self,class_name=None):\n self.type_name = 'unkown wx_object'\n if class_name:\n # customize support_code for whatever type I was handed.\n vals = {'wx_class': class_name}\n specialized_support = wx_support_template % vals\n custom = base_info.base_info()\n custom._support_code = [specialized_support]\n self._build_information = self._build_information + [custom]\n self.type_name = class_name\n\n def type_match(self,value):\n try:\n class_name = value.this.split('_')[-2]\n if class_name[:2] == 'wx':\n return 1\n except AttributeError:\n pass\n return 0\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 def declaration_code(self,inline=0):\n type = self.type_name\n name = self.name\n var_name = self.retrieve_py_variable(inline)\n template = '%(type)s *%(name)s = '\\\n 'convert_to_%(type)s(%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n \n def __repr__(self):\n msg = \"(%s:: name: %s)\" % (self.type_name,self.name)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__) or \\\n cmp(self.type_name,other.type_name)\n\n\"\"\"\n# this should only be enabled on machines with access to a display device\n# It'll cause problems otherwise.\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n\"\"\" ", "methods": [ { "name": "__init__", "long_name": "__init__( self , class_name = None )", "filename": "wx_spec.py", "nloc": 9, "complexity": 2, "token_count": 59, "parameters": [ "self", "class_name" ], "start_line": 32, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "wx_spec.py", "nloc": 8, "complexity": 3, "token_count": 40, "parameters": [ "self", "value" ], "start_line": 43, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "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": 52, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , inline = 0 )", "filename": "wx_spec.py", "nloc": 8, "complexity": 1, "token_count": 41, "parameters": [ "self", "inline" ], "start_line": 58, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 67, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "wx_spec.py", "nloc": 4, "complexity": 3, "token_count": 42, "parameters": [ "self", "other" ], "start_line": 70, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self , class_name = None )", "filename": "wx_spec.py", "nloc": 9, "complexity": 2, "token_count": 59, "parameters": [ "self", "class_name" ], "start_line": 32, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "wx_spec.py", "nloc": 8, "complexity": 3, "token_count": 40, "parameters": [ "self", "value" ], "start_line": 43, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "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": 52, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , inline = 0 )", "filename": "wx_spec.py", "nloc": 8, "complexity": 1, "token_count": 41, "parameters": [ "self", "inline" ], "start_line": 58, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 67, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "wx_spec.py", "nloc": 4, "complexity": 3, "token_count": 42, "parameters": [ "self", "other" ], "start_line": 70, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 77, "complexity": 11, "token_count": 280, "diff_parsed": { "added": [ "from base_spec import base_converter", "class wx_converter(base_converter):" ], "deleted": [ "from base_spec import base_specification", "class wx_specification(base_specification):" ] } } ] }, { "hash": "280b6f215cc20277ffd8769a267155e04a501bbd", "msg": "several bug fixes for problems introduced in renaming of classes", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-02-14T22:29:01+00:00", "author_timezone": 0, "committer_date": "2002-02-14T22:29:01+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "635ec7216d6c5c52b966a080054067577aee3882" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 14, "insertions": 15, "lines": 29, "files": 3, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "weave/blitz_tools.py", "new_path": "weave/blitz_tools.py", "filename": "blitz_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -6,6 +6,7 @@\n import token,symbol\n import slice_handler\n import size_check\n+import converters\n \n from ast_tools import *\n \n", "added_lines": 1, "deleted_lines": 0, "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 fastumath import *\nexcept:\n pass # 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 from code_blocks import module_header\n\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 \"\"\"\n ast_list = ast.tolist()\n \n expr_code = ast_to_blitz_expr(ast_list)\n arg_list = harvest_variables(ast_list)\n arg_specs = assign_variable_types(arg_list,locals())\n \n func,template_types = create_function('test_function',expr_code,arg_list,arg_specs)\n init,used_names = create_module_init('compile_sample','test_function',template_types)\n #wrapper = create_wrapper(mod_name,func_name,used_names)\n return string.join( [module_header,func,init],'\\n')\n \"\"\"\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n\nif __name__ == \"__main__\":\n test_function()", "source_code_before": "import parser\nimport string\nimport copy\nimport os,sys\nimport ast_tools\nimport token,symbol\nimport slice_handler\nimport size_check\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 fastumath import *\nexcept:\n pass # 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 from code_blocks import module_header\n\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 \"\"\"\n ast_list = ast.tolist()\n \n expr_code = ast_to_blitz_expr(ast_list)\n arg_list = harvest_variables(ast_list)\n arg_specs = assign_variable_types(arg_list,locals())\n \n func,template_types = create_function('test_function',expr_code,arg_list,arg_specs)\n init,used_names = create_module_init('compile_sample','test_function',template_types)\n #wrapper = create_wrapper(mod_name,func_name,used_names)\n return string.join( [module_header,func,init],'\\n')\n \"\"\"\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n\nif __name__ == \"__main__\":\n test_function()", "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": 26, "complexity": 1, "token_count": 128, "parameters": [], "start_line": 119, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 147, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 151, "end_line": 153, "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": 26, "end_line": 78, "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": 80, "end_line": 116, "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": 26, "complexity": 1, "token_count": 128, "parameters": [], "start_line": 118, "end_line": 145, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 146, "end_line": 148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 150, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 98, "complexity": 12, "token_count": 537, "diff_parsed": { "added": [ "import converters" ], "deleted": [] } }, { "old_path": "weave/inline_tools.py", "new_path": "weave/inline_tools.py", "filename": "inline_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -136,7 +136,7 @@ def inline(code,arg_names=[],local_dict = None, global_dict = None,\n verbose = 0,\n support_code = None,\n customize=None,\n- type_factories = None,\n+ type_converters = None,\n auto_downcast=1,\n **kw):\n \"\"\" Inline C/C++ code within Python scripts.\n@@ -204,7 +204,7 @@ def inline(code,arg_names=[],local_dict = None, global_dict = None,\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_factories -- optional. list of type specification factories. These\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@@ -285,7 +285,7 @@ def inline(code,arg_names=[],local_dict = None, global_dict = None,\n verbose=verbose,\n support_code = support_code,\n customize=customize,\n- type_factories = type_factories,\n+ type_converters = type_converters,\n auto_downcast = auto_downcast,\n **kw)\n \n@@ -323,7 +323,7 @@ def inline(code,arg_names=[],local_dict = None, global_dict = None,\n verbose=verbose,\n support_code = support_code,\n customize=customize,\n- type_factories = type_factories,\n+ type_converters = type_converters,\n auto_downcast = auto_downcast,\n **kw)\n \n@@ -375,7 +375,7 @@ def attempt_function_call(code,local_dict,global_dict):\n \n def inline_function_code(code,arg_names,local_dict=None,\n global_dict=None,auto_downcast = 1,\n- type_factories=None,compiler=''):\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@@ -383,7 +383,7 @@ def inline_function_code(code,arg_names,local_dict=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_factories = type_factories)\n+ type_converters = type_converters)\n import build_tools\n compiler = build_tools.choose_compiler(compiler)\n ext_func.set_compiler(compiler)\n@@ -395,7 +395,7 @@ def compile_function(code,arg_names,local_dict,global_dict,\n verbose = 0,\n support_code = None,\n customize = None,\n- type_factories = 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@@ -409,7 +409,7 @@ def compile_function(code,arg_names,local_dict,global_dict,\n # type factories setting\n ext_func = inline_ext_function('compiled_func',code,arg_names,\n local_dict,global_dict,auto_downcast,\n- type_factories = type_factories)\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", "added_lines": 8, "deleted_lines": 8, "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 inline_info, cxx_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 = Py::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(inline_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():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \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 inline_info, cxx_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 = Py::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(inline_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_factories = 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_factories -- optional. list of type specification factories. 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_factories = type_factories,\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_factories = type_factories,\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_factories=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_factories = type_factories)\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_factories = 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_factories = type_factories)\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():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \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( )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "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_factories = 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_factories", "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_factories = None , compiler = '' )", "filename": "inline_tools.py", "nloc": 15, "complexity": 3, "token_count": 98, "parameters": [ "code", "arg_names", "local_dict", "global_dict", "auto_downcast", "type_factories", "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_factories = 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_factories", "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( )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "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": "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": "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": "compile_function", "long_name": "compile_function( code , arg_names , local_dict , global_dict , module_dir , compiler = '' , verbose = 0 , support_code = None , customize = None , type_factories = 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_factories", "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": "inline_function_code", "long_name": "inline_function_code( code , arg_names , local_dict = None , global_dict = None , auto_downcast = 1 , type_factories = None , compiler = '' )", "filename": "inline_tools.py", "nloc": 15, "complexity": 3, "token_count": 98, "parameters": [ "code", "arg_names", "local_dict", "global_dict", "auto_downcast", "type_factories", "compiler" ], "start_line": 376, "end_line": 390, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "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_factories = 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_factories", "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": "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 } ], "nloc": 246, "complexity": 41, "token_count": 1306, "diff_parsed": { "added": [ " type_converters = None,", " type_converters -- optional. list of type converters. These", " type_converters = type_converters,", " type_converters = type_converters,", " type_converters=None,compiler=''):", " type_converters = type_converters)", " type_converters = None,", " type_converters = type_converters)" ], "deleted": [ " type_factories = None,", " type_factories -- optional. list of type specification factories. These", " type_factories = type_factories,", " type_factories = type_factories,", " type_factories=None,compiler=''):", " type_factories = type_factories)", " type_factories = None,", " type_factories = type_factories)" ] } }, { "old_path": "weave/sequence_spec.py", "new_path": "weave/sequence_spec.py", "filename": "sequence_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,9 +1,9 @@\n import cxx_info\n-from base_spec import base_specification\n+from base_spec import base_converter\n from types import *\n import os\n \n-class base_cxx_specification(base_specification):\n+class base_cxx_converter(base_converter):\n _build_information = [cxx_info.cxx_info()]\n def type_spec(self,name,value):\n # factory\n@@ -18,7 +18,7 @@ def __cmp__(self,other):\n return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n \n-class string_specification(base_cxx_specification):\n+class string_converter(base_cxx_converter):\n type_name = 'string'\n def type_match(self,value):\n return type(value) in [StringType]\n@@ -33,7 +33,7 @@ def local_dict_code(self):\n return code\n \n \n-class list_specification(base_cxx_specification):\n+class list_converter(base_cxx_converter):\n type_name = 'list'\n def type_match(self,value):\n return type(value) in [ListType]\n@@ -47,7 +47,7 @@ def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n \n-class dict_specification(base_cxx_specification):\n+class dict_converter(base_cxx_converter):\n type_name = 'dict'\n def type_match(self,value):\n return type(value) in [DictType]\n@@ -62,7 +62,7 @@ def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n \n-class tuple_specification(base_cxx_specification):\n+class tuple_converter(base_cxx_converter):\n type_name = 'tuple'\n def type_match(self,value):\n return type(value) in [TupleType]\n", "added_lines": 6, "deleted_lines": 6, "source_code": "import cxx_info\nfrom base_spec import base_converter\nfrom types import *\nimport os\n\nclass base_cxx_converter(base_converter):\n _build_information = [cxx_info.cxx_info()]\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n return new_spec\n def __repr__(self):\n msg = \"(%s:: name: %s)\" % (self.type_name,self.name)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n \nclass string_converter(base_cxx_converter):\n type_name = 'string'\n def type_match(self,value):\n return type(value) in [StringType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::String %s = convert_to_string(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\n\nclass list_converter(base_cxx_converter):\n type_name = 'list'\n def type_match(self,value):\n return type(value) in [ListType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::List %s = convert_to_list(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\nclass dict_converter(base_cxx_converter):\n type_name = 'dict'\n def type_match(self,value):\n return type(value) in [DictType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::Dict %s = convert_to_dict(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name) \n return code\n \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\nclass tuple_converter(base_cxx_converter):\n type_name = 'tuple'\n def type_match(self,value):\n return type(value) in [TupleType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::Tuple %s = convert_to_tuple(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n\n", "source_code_before": "import cxx_info\nfrom base_spec import base_specification\nfrom types import *\nimport os\n\nclass base_cxx_specification(base_specification):\n _build_information = [cxx_info.cxx_info()]\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n return new_spec\n def __repr__(self):\n msg = \"(%s:: name: %s)\" % (self.type_name,self.name)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n \nclass string_specification(base_cxx_specification):\n type_name = 'string'\n def type_match(self,value):\n return type(value) in [StringType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::String %s = convert_to_string(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\n\nclass list_specification(base_cxx_specification):\n type_name = 'list'\n def type_match(self,value):\n return type(value) in [ListType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::List %s = convert_to_list(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\nclass dict_specification(base_cxx_specification):\n type_name = 'dict'\n def type_match(self,value):\n return type(value) in [DictType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::Dict %s = convert_to_dict(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name) \n return code\n \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\nclass tuple_specification(base_cxx_specification):\n type_name = 'tuple'\n def type_match(self,value):\n return type(value) in [TupleType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::Tuple %s = convert_to_tuple(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n\n", "methods": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "sequence_spec.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "self", "name", "value" ], "start_line": 8, "end_line": 12, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 13, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "self", "other" ], "start_line": 16, "end_line": 19, "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": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 23, "end_line": 24, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 26, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 31, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 38, "end_line": 39, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 41, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 46, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 52, "end_line": 53, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 55, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 61, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 67, "end_line": 68, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 70, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 75, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 79, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 83, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "sequence_spec.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "self", "name", "value" ], "start_line": 8, "end_line": 12, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 13, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "self", "other" ], "start_line": 16, "end_line": 19, "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": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 23, "end_line": 24, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 26, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 31, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 38, "end_line": 39, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 41, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 46, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 52, "end_line": 53, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 55, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 61, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 67, "end_line": 68, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 70, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 75, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 79, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 83, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 70, "complexity": 18, "token_count": 482, "diff_parsed": { "added": [ "from base_spec import base_converter", "class base_cxx_converter(base_converter):", "class string_converter(base_cxx_converter):", "class list_converter(base_cxx_converter):", "class dict_converter(base_cxx_converter):", "class tuple_converter(base_cxx_converter):" ], "deleted": [ "from base_spec import base_specification", "class base_cxx_specification(base_specification):", "class string_specification(base_cxx_specification):", "class list_specification(base_cxx_specification):", "class dict_specification(base_cxx_specification):", "class tuple_specification(base_cxx_specification):" ] } } ] }, { "hash": "880f4ceaa27d11845aec0ae826fd04abe9bf2e80", "msg": "Added fcompiler libs to ext libs list when needed", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-02-17T08:10:03+00:00", "author_timezone": 0, "committer_date": "2002-02-17T08:10:03+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "280b6f215cc20277ffd8769a267155e04a501bbd" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 7, "insertions": 32, "lines": 39, "files": 4, "dmm_unit_size": 0.631578947368421, "dmm_unit_complexity": 0.7368421052631579, "dmm_unit_interfacing": 0.8947368421052632, "modified_files": [ { "old_path": "scipy_distutils/__version__.py", "new_path": "scipy_distutils/__version__.py", "filename": "__version__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,4 +1,4 @@\n # This file is automatically updated with update_version\n # function from scipy_distutils.misc_util.py\n-version = '0.6.23-alpha-99'\n-version_info = (0, 6, 23, 'alpha', 99)\n+version = '0.6.23-alpha-100'\n+version_info = (0, 6, 23, 'alpha', 100)\n", "added_lines": 2, "deleted_lines": 2, "source_code": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-100'\nversion_info = (0, 6, 23, 'alpha', 100)\n", "source_code_before": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-99'\nversion_info = (0, 6, 23, 'alpha', 99)\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 2, "complexity": 0, "token_count": 16, "diff_parsed": { "added": [ "version = '0.6.23-alpha-100'", "version_info = (0, 6, 23, 'alpha', 100)" ], "deleted": [ "version = '0.6.23-alpha-99'", "version_info = (0, 6, 23, 'alpha', 99)" ] } }, { "old_path": "scipy_distutils/atlas_info.py", "new_path": "scipy_distutils/atlas_info.py", "filename": "atlas_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -16,7 +16,7 @@ def get_atlas_info():\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n- blas_libraries = ['cblas','f77blas','atlas','g2c']\n+ blas_libraries = ['cblas','f77blas','atlas']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n \n", "added_lines": 1, "deleted_lines": 1, "source_code": "import sys, os\nfrom misc_util import get_path\n\nlibrary_path = ''\n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not library_path:\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries \n else:\n if not library_path:\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", "source_code_before": "import sys, os\nfrom misc_util import get_path\n\nlibrary_path = ''\n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not library_path:\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries \n else:\n if not library_path:\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", "methods": [ { "name": "get_atlas_info", "long_name": "get_atlas_info( )", "filename": "atlas_info.py", "nloc": 16, "complexity": 4, "token_count": 84, "parameters": [], "start_line": 6, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "unix_atlas_directory", "long_name": "unix_atlas_directory( platform )", "filename": "atlas_info.py", "nloc": 7, "complexity": 3, "token_count": 39, "parameters": [ "platform" ], "start_line": 23, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_atlas_info", "long_name": "get_atlas_info( )", "filename": "atlas_info.py", "nloc": 16, "complexity": 4, "token_count": 86, "parameters": [], "start_line": 6, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "unix_atlas_directory", "long_name": "unix_atlas_directory( platform )", "filename": "atlas_info.py", "nloc": 7, "complexity": 3, "token_count": 39, "parameters": [ "platform" ], "start_line": 23, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_atlas_info", "long_name": "get_atlas_info( )", "filename": "atlas_info.py", "nloc": 16, "complexity": 4, "token_count": 84, "parameters": [], "start_line": 6, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "nloc": 26, "complexity": 7, "token_count": 136, "diff_parsed": { "added": [ " blas_libraries = ['cblas','f77blas','atlas']" ], "deleted": [ " blas_libraries = ['cblas','f77blas','atlas','g2c']" ] } }, { "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": "@@ -13,15 +13,17 @@ class build_ext (old_build_ext):\n def build_extension(self, ext):\n # support for building static fortran libraries\n need_f_libs = 0\n+ ext_name = string.split(ext.name,'.')[-1]\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+ 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+ print ext.name,ext_name,'needs fortran libraries',need_f_libs\n if need_f_libs:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n if moreargs != []:\n@@ -29,12 +31,18 @@ def build_extension(self, ext):\n ext.extra_link_args = moreargs\n else:\n ext.extra_link_args += moreargs\n- if build_flib.has_f_library(ext.name) and \\\n- ext.name not in ext.libraries:\n- ext.libraries.append(ext.name)\n+ if build_flib.has_f_library(ext_name) and \\\n+ ext_name not in ext.libraries:\n+ ext.libraries.append(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+\n+ ext.libraries.extend(build_flib.get_fcompiler_library_names())\n+ ext.library_dirs.extend(build_flib.get_fcompiler_library_dirs())\n+\n+ print ext.libraries\n+ \n ext.library_dirs.append(build_flib.build_flib)\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n", "added_lines": 12, "deleted_lines": 4, "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 *\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n # support for building static fortran libraries\n need_f_libs = 0\n ext_name = string.split(ext.name,'.')[-1]\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 print ext.name,ext_name,'needs fortran libraries',need_f_libs\n if need_f_libs:\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 if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.append(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\n ext.libraries.extend(build_flib.get_fcompiler_library_names())\n ext.library_dirs.extend(build_flib.get_fcompiler_library_dirs())\n\n print ext.libraries\n \n ext.library_dirs.append(build_flib.build_flib)\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n linker_so = build_flib.fcompiler.get_linker_so()\n if linker_so is not None:\n self.compiler.linker_so = linker_so\n\n # end of fortran source support\n return old_build_ext.build_extension(self,ext)\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", "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 *\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n # support for building static fortran libraries\n need_f_libs = 0\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 if need_f_libs:\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 if build_flib.has_f_library(ext.name) and \\\n ext.name not in ext.libraries:\n ext.libraries.append(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 runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n linker_so = build_flib.fcompiler.get_linker_so()\n if linker_so is not None:\n self.compiler.linker_so = linker_so\n\n # end of fortran source support\n return old_build_ext.build_extension(self,ext)\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", "methods": [ { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 36, "complexity": 13, "token_count": 269, "parameters": [ "self", "ext" ], "start_line": 13, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "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": 56, "end_line": 65, "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": 31, "complexity": 13, "token_count": 223, "parameters": [ "self", "ext" ], "start_line": 13, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "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": 48, "end_line": 57, "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": 36, "complexity": 13, "token_count": 269, "parameters": [ "self", "ext" ], "start_line": 13, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "top_nesting_level": 1 } ], "nloc": 51, "complexity": 15, "token_count": 360, "diff_parsed": { "added": [ " ext_name = string.split(ext.name,'.')[-1]", " if build_flib.has_f_library(ext_name):", " print ext.name,ext_name,'needs fortran libraries',need_f_libs", " if build_flib.has_f_library(ext_name) and \\", " ext_name not in ext.libraries:", " ext.libraries.append(ext_name)", "", " ext.libraries.extend(build_flib.get_fcompiler_library_names())", " ext.library_dirs.extend(build_flib.get_fcompiler_library_dirs())", "", " print ext.libraries", "" ], "deleted": [ " if build_flib.has_f_library(ext.name):", " if build_flib.has_f_library(ext.name) and \\", " ext.name not in ext.libraries:", " ext.libraries.append(ext.name)" ] } }, { "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": "@@ -173,6 +173,20 @@ def get_library_names(self, name=None):\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@@ -590,6 +604,9 @@ def __init__(self, fc = None, f90c = None):\n if sys.platform == 'win32':\n self.libraries = ['gcc','g2c']\n self.library_dirs = self.find_lib_directories()\n+ else:\n+ # On linux g77 does not need lib_directories to be specified.\n+ self.libraries = ['g2c']\n \n if fc is None:\n fc = 'g77'\n", "added_lines": 17, "deleted_lines": 0, "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\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 Gnu\n VAST\n\"\"\"\n\nimport distutils\nimport distutils.dep_util, distutils.dir_util\nimport os,sys,string\nimport commands,re\nfrom types import *\nfrom distutils.command.build_clib import build_clib\nfrom distutils.errors import *\n\nclass FortranCompilerError (CCompilerError):\n \"\"\"Some compile/link operation failed.\"\"\"\nclass FortranCompileError (FortranCompilerError):\n \"\"\"Failure to compile one or more Fortran source files.\"\"\"\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 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 fc = find_fortran_compiler(self.fcompiler,\n self.fcompiler_exec,\n self.f90compiler_exec)\n if not fc:\n raise DistutilsOptionError, 'Fortran compiler not available: %s'%(self.fcompiler)\n else:\n self.announce(' using %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 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 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 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 self.announce(\" building '%s' library\" % lib_name)\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\n\nclass fortran_compiler_base:\n\n vendor = None\n ver_match = None\n \n def __init__(self):\n # Default initialization. Constructors of derived classes MUST\n # call this functions.\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,dirty_files,module_dirs=None, 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 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 + ' -c ' + source + ' -o ' + object \n print cmd\n failure = os.system(cmd)\n if failure:\n raise FortranCompileError, 'failure during compile' \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\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):\n lib_file = os.path.join(output_dir,'lib'+library_name+'.a')\n newer = distutils.dep_util.newer\n # This doesn't work -- no way to know if the file is in the archive\n #object_files = filter(lambda o,lib=lib_file:\\\n # distutils.dep_util.newer(o,lib),object_files)\n objects = string.join(object_files)\n if objects:\n cmd = 'ar -cur %s %s' % (lib_file,objects)\n print cmd\n os.system(cmd)\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,module_dirs,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':\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 self.create_static_lib(obj,library_name,temp_dir)\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 #print 'command:', self.ver_cmd\n exit_status, out_text = run_command(self.ver_cmd)\n #print exit_status, out_text\n if not exit_status:\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\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):\n fortran_compiler_base.__init__(self)\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\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\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 self.ver_cmd = self.f77_compiler + ' -V'\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 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 \n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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 = ' -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.libraries = ['fortran', 'ftn', 'm']\n self.library_dirs = self.find_lib_dir()\n\n self.ver_cmd = self.f77_compiler + ' -version'\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\n\nclass gnu_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Gnu'\n ver_match = r'g77 version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if sys.platform == 'win32':\n self.libraries = ['gcc','g2c']\n self.library_dirs = self.find_lib_directories()\n else:\n # On linux g77 does not need lib_directories to be specified.\n self.libraries = ['g2c']\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 switches = ' -Wall -fno-second-underscore '\n\n if os.name != 'nt':\n switches = switches + ' -fpic '\n\n self.f77_switches = switches\n\n self.ver_cmd = self.f77_compiler + ' -v '\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\n # it.\n if self.get_version():\n if self.version[0]=='3': # is g77 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 ' \n return opt\n \n def find_lib_directories(self):\n lib_dir = []\n match = r'Reading specs from (.*)/specs'\n\n # works I think only for unix... \n exit_status, out_text = run_command('g77 -v')\n if not exit_status:\n m = re.findall(match,out_text)\n if m:\n lib_dir= m #m[0] \n return lib_dir\n\n def get_linker_so(self):\n # win32 linking should be handled by standard linker\n if sys.platform != 'win32':\n return [self.f77_compiler,'-shared']\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, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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 for the Itanium\\(TM\\)-based applications, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n if fc is None:\n fc = 'efc'\n intel_ia32_fortran_compiler.__init__(self, fc, f90c)\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):\n fortran_compiler_base.__init__(self)\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\nclass vast_fortran_compiler(fortran_compiler_base):\n\n vendor = 'VAST'\n ver_match = r'\\s*Pacific-Sierra Research vf90 (Personal|Professional)\\s+(?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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\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):\n fortran_compiler_base.__init__(self)\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 -assume nozsize -math_library fast -tune host '\n return opt\n\n def get_linker_so(self):\n # XXX: is -shared needed?\n return [self.f77_compiler,'-shared']\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):\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)\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 vast_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\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 Gnu\n VAST\n\"\"\"\n\nimport distutils\nimport distutils.dep_util, distutils.dir_util\nimport os,sys,string\nimport commands,re\nfrom types import *\nfrom distutils.command.build_clib import build_clib\nfrom distutils.errors import *\n\nclass FortranCompilerError (CCompilerError):\n \"\"\"Some compile/link operation failed.\"\"\"\nclass FortranCompileError (FortranCompilerError):\n \"\"\"Failure to compile one or more Fortran source files.\"\"\"\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 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 fc = find_fortran_compiler(self.fcompiler,\n self.fcompiler_exec,\n self.f90compiler_exec)\n if not fc:\n raise DistutilsOptionError, 'Fortran compiler not available: %s'%(self.fcompiler)\n else:\n self.announce(' using %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 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 # 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 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 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 self.announce(\" building '%s' library\" % lib_name)\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\n\nclass fortran_compiler_base:\n\n vendor = None\n ver_match = None\n \n def __init__(self):\n # Default initialization. Constructors of derived classes MUST\n # call this functions.\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,dirty_files,module_dirs=None, 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 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 + ' -c ' + source + ' -o ' + object \n print cmd\n failure = os.system(cmd)\n if failure:\n raise FortranCompileError, 'failure during compile' \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\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):\n lib_file = os.path.join(output_dir,'lib'+library_name+'.a')\n newer = distutils.dep_util.newer\n # This doesn't work -- no way to know if the file is in the archive\n #object_files = filter(lambda o,lib=lib_file:\\\n # distutils.dep_util.newer(o,lib),object_files)\n objects = string.join(object_files)\n if objects:\n cmd = 'ar -cur %s %s' % (lib_file,objects)\n print cmd\n os.system(cmd)\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,module_dirs,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':\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 self.create_static_lib(obj,library_name,temp_dir)\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 #print 'command:', self.ver_cmd\n exit_status, out_text = run_command(self.ver_cmd)\n #print exit_status, out_text\n if not exit_status:\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\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):\n fortran_compiler_base.__init__(self)\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\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\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 self.ver_cmd = self.f77_compiler + ' -V'\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 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 \n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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 = ' -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.libraries = ['fortran', 'ftn', 'm']\n self.library_dirs = self.find_lib_dir()\n\n self.ver_cmd = self.f77_compiler + ' -version'\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\n\nclass gnu_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Gnu'\n ver_match = r'g77 version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if sys.platform == 'win32':\n self.libraries = ['gcc','g2c']\n self.library_dirs = self.find_lib_directories()\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 switches = ' -Wall -fno-second-underscore '\n\n if os.name != 'nt':\n switches = switches + ' -fpic '\n\n self.f77_switches = switches\n\n self.ver_cmd = self.f77_compiler + ' -v '\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\n # it.\n if self.get_version():\n if self.version[0]=='3': # is g77 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 ' \n return opt\n \n def find_lib_directories(self):\n lib_dir = []\n match = r'Reading specs from (.*)/specs'\n\n # works I think only for unix... \n exit_status, out_text = run_command('g77 -v')\n if not exit_status:\n m = re.findall(match,out_text)\n if m:\n lib_dir= m #m[0] \n return lib_dir\n\n def get_linker_so(self):\n # win32 linking should be handled by standard linker\n if sys.platform != 'win32':\n return [self.f77_compiler,'-shared']\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, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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 for the Itanium\\(TM\\)-based applications, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n if fc is None:\n fc = 'efc'\n intel_ia32_fortran_compiler.__init__(self, fc, f90c)\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):\n fortran_compiler_base.__init__(self)\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\nclass vast_fortran_compiler(fortran_compiler_base):\n\n vendor = 'VAST'\n ver_match = r'\\s*Pacific-Sierra Research vf90 (Personal|Professional)\\s+(?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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\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):\n fortran_compiler_base.__init__(self)\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 -assume nozsize -math_library fast -tune host '\n return opt\n\n def get_linker_so(self):\n # XXX: is -shared needed?\n return [self.f77_compiler,'-shared']\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):\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)\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 vast_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": 58, "end_line": 63, "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": 23, "parameters": [], "start_line": 67, "end_line": 71, "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": 101, "end_line": 113, "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": 17, "complexity": 3, "token_count": 104, "parameters": [ "self" ], "start_line": 117, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "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": 137, "end_line": 139, "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": 141, "end_line": 144, "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": 148, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "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": 154, "end_line": 174, "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": 6, "complexity": 3, "token_count": 34, "parameters": [ "self" ], "start_line": 176, "end_line": 181, "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": 6, "complexity": 3, "token_count": 34, "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": "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": 192, "end_line": 209, "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": 7, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 213, "end_line": 222, "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": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 226, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , fortran_libraries )", "filename": "build_flib.py", "nloc": 18, "complexity": 5, "token_count": 122, "parameters": [ "self", "fortran_libraries" ], "start_line": 236, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 88, "parameters": [ "self" ], "start_line": 269, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "to_object", "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 13, "complexity": 3, "token_count": 89, "parameters": [ "self", "dirty_files", "module_dirs", "temp_dir" ], "start_line": 292, "end_line": 304, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 306, "end_line": 311, "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": 313, "end_line": 316, "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": 15, "complexity": 4, "token_count": 103, "parameters": [ "self", "compiler", "switches", "source_files", "module_dirs", "temp_dir" ], "start_line": 318, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 336, "end_line": 339, "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": 341, "end_line": 344, "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": 347, "end_line": 348, "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 )", "filename": "build_flib.py", "nloc": 9, "complexity": 2, "token_count": 68, "parameters": [ "self", "object_files", "library_name", "output_dir", "debug" ], "start_line": 350, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "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": 13, "complexity": 3, "token_count": 104, "parameters": [ "self", "library_name", "source_list", "module_dirs", "temp_dir" ], "start_line": 363, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "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": 391, "end_line": 398, "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": 400, "end_line": 401, "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": 10, "complexity": 4, "token_count": 66, "parameters": [ "self" ], "start_line": 403, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 423, "end_line": 424, "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": 425, "end_line": 426, "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": 427, "end_line": 428, "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": 429, "end_line": 430, "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": 431, "end_line": 436, "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": 438, "end_line": 439, "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 )", "filename": "build_flib.py", "nloc": 31, "complexity": 5, "token_count": 177, "parameters": [ "self", "fc", "f90c" ], "start_line": 447, "end_line": 485, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 487, "end_line": 492, "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": 494, "end_line": 495, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 98, "parameters": [ "self", "fc", "f90c" ], "start_line": 508, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "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": 532, "end_line": 537, "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": 15, "complexity": 3, "token_count": 99, "parameters": [ "self" ], "start_line": 539, "end_line": 553, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 554, "end_line": 555, "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": 556, "end_line": 557, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 94, "parameters": [ "self", "fc", "f90c" ], "start_line": 565, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 585, "end_line": 587, "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": 588, "end_line": 590, "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": 591, "end_line": 592, "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": 593, "end_line": 594, "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 )", "filename": "build_flib.py", "nloc": 18, "complexity": 5, "token_count": 112, "parameters": [ "self", "fc", "f90c" ], "start_line": 602, "end_line": 626, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 21, "complexity": 10, "token_count": 120, "parameters": [ "self" ], "start_line": 628, "end_line": 651, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "find_lib_directories", "long_name": "find_lib_directories( self )", "filename": "build_flib.py", "nloc": 9, "complexity": 3, "token_count": 43, "parameters": [ "self" ], "start_line": 653, "end_line": 663, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 2, "token_count": 20, "parameters": [ "self" ], "start_line": 665, "end_line": 668, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "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": 670, "end_line": 671, "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 )", "filename": "build_flib.py", "nloc": 22, "complexity": 5, "token_count": 140, "parameters": [ "self", "fc", "f90c" ], "start_line": 680, "end_line": 708, "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": 710, "end_line": 724, "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": 727, "end_line": 728, "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 )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 31, "parameters": [ "self", "fc", "f90c" ], "start_line": 736, "end_line": 739, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 100, "parameters": [ "self", "fc", "f90c" ], "start_line": 747, "end_line": 766, "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": 768, "end_line": 770, "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": 772, "end_line": 773, "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 )", "filename": "build_flib.py", "nloc": 20, "complexity": 5, "token_count": 128, "parameters": [ "self", "fc", "f90c" ], "start_line": 781, "end_line": 805, "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": 809, "end_line": 810, "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 )", "filename": "build_flib.py", "nloc": 14, "complexity": 3, "token_count": 91, "parameters": [ "self", "fc", "f90c" ], "start_line": 817, "end_line": 839, "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": 3, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 841, "end_line": 843, "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": 845, "end_line": 847, "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": 850, "end_line": 852, "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": 854, "end_line": 855, "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": 857, "end_line": 858, "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": 860, "end_line": 861, "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 )", "filename": "build_flib.py", "nloc": 11, "complexity": 5, "token_count": 59, "parameters": [ "vendor", "fc", "f90c" ], "start_line": 863, "end_line": 873, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 58, "end_line": 63, "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": 23, "parameters": [], "start_line": 67, "end_line": 71, "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": 101, "end_line": 113, "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": 17, "complexity": 3, "token_count": 104, "parameters": [ "self" ], "start_line": 117, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "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": 137, "end_line": 139, "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": 141, "end_line": 144, "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": 148, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "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": 154, "end_line": 174, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "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": 178, "end_line": 195, "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": 7, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 199, "end_line": 208, "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": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 212, "end_line": 220, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , fortran_libraries )", "filename": "build_flib.py", "nloc": 18, "complexity": 5, "token_count": 122, "parameters": [ "self", "fortran_libraries" ], "start_line": 222, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 88, "parameters": [ "self" ], "start_line": 255, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "to_object", "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 13, "complexity": 3, "token_count": 89, "parameters": [ "self", "dirty_files", "module_dirs", "temp_dir" ], "start_line": 278, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 292, "end_line": 297, "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": 299, "end_line": 302, "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": 15, "complexity": 4, "token_count": 103, "parameters": [ "self", "compiler", "switches", "source_files", "module_dirs", "temp_dir" ], "start_line": 304, "end_line": 318, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 322, "end_line": 325, "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": 327, "end_line": 330, "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": 333, "end_line": 334, "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 )", "filename": "build_flib.py", "nloc": 9, "complexity": 2, "token_count": 68, "parameters": [ "self", "object_files", "library_name", "output_dir", "debug" ], "start_line": 336, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "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": 13, "complexity": 3, "token_count": 104, "parameters": [ "self", "library_name", "source_list", "module_dirs", "temp_dir" ], "start_line": 349, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "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": 377, "end_line": 384, "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": 386, "end_line": 387, "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": 10, "complexity": 4, "token_count": 66, "parameters": [ "self" ], "start_line": 389, "end_line": 407, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 409, "end_line": 410, "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": 411, "end_line": 412, "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": 413, "end_line": 414, "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": 415, "end_line": 416, "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": 417, "end_line": 422, "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": 424, "end_line": 425, "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 )", "filename": "build_flib.py", "nloc": 31, "complexity": 5, "token_count": 177, "parameters": [ "self", "fc", "f90c" ], "start_line": 433, "end_line": 471, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 473, "end_line": 478, "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": 480, "end_line": 481, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 98, "parameters": [ "self", "fc", "f90c" ], "start_line": 494, "end_line": 516, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "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": 518, "end_line": 523, "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": 15, "complexity": 3, "token_count": 99, "parameters": [ "self" ], "start_line": 525, "end_line": 539, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 540, "end_line": 541, "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": 542, "end_line": 543, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 94, "parameters": [ "self", "fc", "f90c" ], "start_line": 551, "end_line": 569, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 571, "end_line": 573, "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": 574, "end_line": 576, "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": 577, "end_line": 578, "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": 579, "end_line": 580, "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 )", "filename": "build_flib.py", "nloc": 16, "complexity": 5, "token_count": 103, "parameters": [ "self", "fc", "f90c" ], "start_line": 588, "end_line": 609, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 21, "complexity": 10, "token_count": 120, "parameters": [ "self" ], "start_line": 611, "end_line": 634, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "find_lib_directories", "long_name": "find_lib_directories( self )", "filename": "build_flib.py", "nloc": 9, "complexity": 3, "token_count": 43, "parameters": [ "self" ], "start_line": 636, "end_line": 646, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 2, "token_count": 20, "parameters": [ "self" ], "start_line": 648, "end_line": 651, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "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": 653, "end_line": 654, "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 )", "filename": "build_flib.py", "nloc": 22, "complexity": 5, "token_count": 140, "parameters": [ "self", "fc", "f90c" ], "start_line": 663, "end_line": 691, "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": 693, "end_line": 707, "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": 710, "end_line": 711, "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 )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 31, "parameters": [ "self", "fc", "f90c" ], "start_line": 719, "end_line": 722, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 100, "parameters": [ "self", "fc", "f90c" ], "start_line": 730, "end_line": 749, "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": 751, "end_line": 753, "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": 755, "end_line": 756, "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 )", "filename": "build_flib.py", "nloc": 20, "complexity": 5, "token_count": 128, "parameters": [ "self", "fc", "f90c" ], "start_line": 764, "end_line": 788, "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": 792, "end_line": 793, "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 )", "filename": "build_flib.py", "nloc": 14, "complexity": 3, "token_count": 91, "parameters": [ "self", "fc", "f90c" ], "start_line": 800, "end_line": 822, "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": 3, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 824, "end_line": 826, "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": 828, "end_line": 830, "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": 833, "end_line": 835, "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": 837, "end_line": 838, "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": 840, "end_line": 841, "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": 843, "end_line": 844, "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 )", "filename": "build_flib.py", "nloc": 11, "complexity": 5, "token_count": 59, "parameters": [ "vendor", "fc", "f90c" ], "start_line": 846, "end_line": 856, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_fcompiler_library_names", "long_name": "get_fcompiler_library_names( self )", "filename": "build_flib.py", "nloc": 6, "complexity": 3, "token_count": 34, "parameters": [ "self" ], "start_line": 176, "end_line": 181, "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": 6, "complexity": 3, "token_count": 34, "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": "__init__", "long_name": "__init__( self , fc = None , f90c = None )", "filename": "build_flib.py", "nloc": 18, "complexity": 5, "token_count": 112, "parameters": [ "self", "fc", "f90c" ], "start_line": 602, "end_line": 626, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 } ], "nloc": 644, "complexity": 167, "token_count": 3740, "diff_parsed": { "added": [ " def get_fcompiler_library_names(self):", " if not self.has_f_libraries():", " return None", " if self.fcompiler is not None:", " return self.fcompiler.get_libraries()", " return []", "", " def get_fcompiler_library_dirs(self):", " if not self.has_f_libraries():", " return None", " if self.fcompiler is not None:", " return self.fcompiler.get_library_dirs()", " return []", "", " else:", " # On linux g77 does not need lib_directories to be specified.", " self.libraries = ['g2c']" ], "deleted": [] } } ] }, { "hash": "1ba73fe9c5fc7798e8dd2ae6387d56b94cac5cde", "msg": "Added fcompiler libs to ext libs list when needed", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-02-17T08:17:42+00:00", "author_timezone": 0, "committer_date": "2002-02-17T08:17:42+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "880f4ceaa27d11845aec0ae826fd04abe9bf2e80" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/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": "scipy_distutils/atlas_info.py", "new_path": "scipy_distutils/atlas_info.py", "filename": "atlas_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -16,7 +16,7 @@ def get_atlas_info():\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n- blas_libraries = ['cblas','f77blas','atlas']\n+ blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n \n", "added_lines": 1, "deleted_lines": 1, "source_code": "import sys, os\nfrom misc_util import get_path\n\nlibrary_path = ''\n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not library_path:\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries \n else:\n if not library_path:\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", "source_code_before": "import sys, os\nfrom misc_util import get_path\n\nlibrary_path = ''\n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not library_path:\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries \n else:\n if not library_path:\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", "methods": [ { "name": "get_atlas_info", "long_name": "get_atlas_info( )", "filename": "atlas_info.py", "nloc": 16, "complexity": 4, "token_count": 86, "parameters": [], "start_line": 6, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "unix_atlas_directory", "long_name": "unix_atlas_directory( platform )", "filename": "atlas_info.py", "nloc": 7, "complexity": 3, "token_count": 39, "parameters": [ "platform" ], "start_line": 23, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_atlas_info", "long_name": "get_atlas_info( )", "filename": "atlas_info.py", "nloc": 16, "complexity": 4, "token_count": 84, "parameters": [], "start_line": 6, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "unix_atlas_directory", "long_name": "unix_atlas_directory( platform )", "filename": "atlas_info.py", "nloc": 7, "complexity": 3, "token_count": 39, "parameters": [ "platform" ], "start_line": 23, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_atlas_info", "long_name": "get_atlas_info( )", "filename": "atlas_info.py", "nloc": 16, "complexity": 4, "token_count": 86, "parameters": [], "start_line": 6, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "nloc": 26, "complexity": 7, "token_count": 138, "diff_parsed": { "added": [ " blas_libraries = ['cblas','f77blas','atlas','g2c']" ], "deleted": [ " blas_libraries = ['cblas','f77blas','atlas']" ] } } ] }, { "hash": "1a0784ac35f32056fb2f60c99f82ce073a4a2af0", "msg": "Fixed sdist", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-02-17T09:41:24+00:00", "author_timezone": 0, "committer_date": "2002-02-17T09:41:24+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "1ba73fe9c5fc7798e8dd2ae6387d56b94cac5cde" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 3, "insertions": 7, "lines": 10, "files": 2, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.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": "@@ -8,6 +8,8 @@\n from distutils.command.build_ext import *\n from distutils.command.build_ext import build_ext as old_build_ext\n \n+from scipy_distutils.command.build_clib import get_headers,get_directories\n+\n class build_ext (old_build_ext):\n \n def build_extension(self, ext):\n", "added_lines": 2, "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 *\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 # support for building static fortran libraries\n need_f_libs = 0\n ext_name = string.split(ext.name,'.')[-1]\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 print ext.name,ext_name,'needs fortran libraries',need_f_libs\n if need_f_libs:\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 if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.append(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\n ext.libraries.extend(build_flib.get_fcompiler_library_names())\n ext.library_dirs.extend(build_flib.get_fcompiler_library_dirs())\n\n print ext.libraries\n \n ext.library_dirs.append(build_flib.build_flib)\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n linker_so = build_flib.fcompiler.get_linker_so()\n if linker_so is not None:\n self.compiler.linker_so = linker_so\n\n # end of fortran source support\n return old_build_ext.build_extension(self,ext)\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", "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 *\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n # support for building static fortran libraries\n need_f_libs = 0\n ext_name = string.split(ext.name,'.')[-1]\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 print ext.name,ext_name,'needs fortran libraries',need_f_libs\n if need_f_libs:\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 if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.append(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\n ext.libraries.extend(build_flib.get_fcompiler_library_names())\n ext.library_dirs.extend(build_flib.get_fcompiler_library_dirs())\n\n print ext.libraries\n \n ext.library_dirs.append(build_flib.build_flib)\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n linker_so = build_flib.fcompiler.get_linker_so()\n if linker_so is not None:\n self.compiler.linker_so = linker_so\n\n # end of fortran source support\n return old_build_ext.build_extension(self,ext)\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", "methods": [ { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 36, "complexity": 13, "token_count": 269, "parameters": [ "self", "ext" ], "start_line": 15, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "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": 58, "end_line": 67, "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": 36, "complexity": 13, "token_count": 269, "parameters": [ "self", "ext" ], "start_line": 13, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "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": 56, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 52, "complexity": 15, "token_count": 370, "diff_parsed": { "added": [ "from scipy_distutils.command.build_clib import get_headers,get_directories", "" ], "deleted": [] } }, { "old_path": "scipy_distutils/command/sdist.py", "new_path": "scipy_distutils/command/sdist.py", "filename": "sdist.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -29,6 +29,7 @@ def make_release_tree (self, base_dir, files):\n # Create all the directories under 'base_dir' necessary to\n # put 'files' there; the 'mkpath()' is just so we don't die\n # if the manifest happens to be empty.\n+\n dest_files = remove_common_base(files)\n self.mkpath(base_dir)\n dir_util.create_tree(base_dir, dest_files,\n@@ -90,7 +91,8 @@ def make_distribution (self):\n base_dir = self.distribution.get_fullname()\n base_name = os.path.join(self.dist_dir, base_dir)\n \n- self.make_release_tree(base_dir, self.filelist.files)\n+ files = map(os.path.abspath, self.filelist.files)\n+ self.make_release_tree(base_dir, files)\n archive_files = [] # remember names of files we create\n for fmt in self.formats: \n self.convert_line_endings(base_dir,fmt)\n@@ -130,7 +132,7 @@ def find_common_base(files):\n \"\"\" Find the \"greatest common base directory\" of a list of files\n \"\"\"\n if not files:\n- return files\n+ return ''\n result = ''\n d,f = os.path.split(files[0])\n keep_looking = 1 \n@@ -147,4 +149,4 @@ def find_common_base(files):\n \n if d: \n d = os.path.join(d,'')\n- return d \n\\ No newline at end of file\n+ return d \n", "added_lines": 5, "deleted_lines": 3, "source_code": "from distutils.command.sdist import *\nfrom distutils.command.sdist import sdist as old_sdist\n\nimport sys, os\nmod = __import__(__name__)\nsys.path.append(os.path.dirname(mod.__file__))\nimport line_endings\nsys.path = sys.path[:-1]\n\nclass sdist(old_sdist):\n def add_defaults (self):\n old_sdist.add_defaults(self)\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n self.filelist.extend(build_flib.get_source_files())\n\n if self.distribution.has_data_files():\n self.filelist.extend(self.distribution.get_data_files())\n\n def make_release_tree (self, base_dir, files):\n \"\"\"Create the directory tree that will become the source\n distribution archive. All directories implied by the filenames in\n 'files' are created under 'base_dir', and then we hard link or copy\n (if hard linking is unavailable) those files into place.\n Essentially, this duplicates the developer's source tree, but in a\n directory named after the distribution, containing only the files\n to be distributed.\n \"\"\"\n # Create all the directories under 'base_dir' necessary to\n # put 'files' there; the 'mkpath()' is just so we don't die\n # if the manifest happens to be empty.\n\n dest_files = remove_common_base(files)\n self.mkpath(base_dir)\n dir_util.create_tree(base_dir, dest_files,\n verbose=self.verbose, dry_run=self.dry_run)\n\n # And walk over the list of files, either making a hard link (if\n # os.link exists) to each one that doesn't already exist in its\n # corresponding location under 'base_dir', or copying each file\n # that's out-of-date in 'base_dir'. (Usually, all files will be\n # out-of-date, because by default we blow away 'base_dir' when\n # we're done making the distribution archives.)\n \n if hasattr(os, 'link'): # can make hard links on this system\n link = 'hard'\n msg = \"making hard links in %s...\" % base_dir\n else: # nope, have to copy\n link = None\n msg = \"copying files to %s...\" % base_dir\n\n if not files:\n self.warn(\"no files to distribute -- empty manifest?\")\n else:\n self.announce(msg)\n \n dest_files = [os.path.join(base_dir,file) for file in dest_files]\n file_pairs = zip(files,dest_files) \n for file,dest in file_pairs:\n if not os.path.isfile(file):\n self.warn(\"'%s' not a regular file -- skipping\" % file)\n else:\n #ej: here is the only change -- made to handle\n # absolute paths to files as well as relative\n #par,file_name = os.path.split(file)\n #dest = os.path.join(base_dir, file_name)\n # end of changes\n \n # old code\n #dest = os.path.join(base_dir, file)\n #end old code\n self.copy_file(file, dest, link=link)\n\n self.distribution.metadata.write_pkg_info(base_dir)\n #raise ValueError\n # make_release_tree ()\n\n def make_distribution (self):\n \"\"\" Overridden to force a build of zip files to have Windows line \n endings and tar balls to have Unix line endings.\n \n Create the source distribution(s). First, we create the release\n tree with 'make_release_tree()'; then, we create all required\n archive files (according to 'self.formats') from the release tree.\n Finally, we clean up by blowing away the release tree (unless\n 'self.keep_temp' is true). The list of archive files created is\n stored so it can be retrieved later by 'get_archive_files()'.\n \"\"\"\n # Don't warn about missing meta-data here -- should be (and is!)\n # done elsewhere.\n base_dir = self.distribution.get_fullname()\n base_name = os.path.join(self.dist_dir, base_dir)\n\n files = map(os.path.abspath, self.filelist.files)\n self.make_release_tree(base_dir, files)\n archive_files = [] # remember names of files we create\n for fmt in self.formats: \n self.convert_line_endings(base_dir,fmt)\n file = self.make_archive(base_name, fmt, base_dir=base_dir)\n archive_files.append(file)\n \n self.archive_files = archive_files\n\n if not self.keep_temp:\n dir_util.remove_tree(base_dir, self.verbose, self.dry_run)\n\n def convert_line_endings(self,base_dir,fmt):\n \"\"\" Convert all text files in a tree to have correct line endings.\n \n gztar --> \\n (Unix style)\n zip --> \\r\\n (Windows style)\n \"\"\"\n if fmt == 'gztar':\n line_endings.dos2unix_dir(base_dir)\n elif fmt == 'zip':\n line_endings.unix2dos_dir(base_dir)\n \ndef remove_common_base(files):\n \"\"\" Remove the greatest common base directory from all the\n absolute file paths in the list of files. files in the\n list without a parent directory are not affected.\n \"\"\"\n rel_files = filter(lambda x: not os.path.dirname(x),files)\n abs_files = filter(os.path.dirname,files)\n base = find_common_base(abs_files)\n # will leave files with local path unaffected\n # and maintains original file order\n results = [string.replace(file,base,'') for file in files]\n return results\n\ndef find_common_base(files):\n \"\"\" Find the \"greatest common base directory\" of a list of files\n \"\"\"\n if not files:\n return ''\n result = ''\n d,f = os.path.split(files[0])\n keep_looking = 1 \n while(keep_looking and d):\n keep_looking = 0\n for file in files:\n if string.find('start'+file,'start'+d) == -1:\n keep_looking = 1\n break\n if keep_looking:\n d,f = os.path.split(d)\n else:\n result = d\n \n if d: \n d = os.path.join(d,'')\n return d \n", "source_code_before": "from distutils.command.sdist import *\nfrom distutils.command.sdist import sdist as old_sdist\n\nimport sys, os\nmod = __import__(__name__)\nsys.path.append(os.path.dirname(mod.__file__))\nimport line_endings\nsys.path = sys.path[:-1]\n\nclass sdist(old_sdist):\n def add_defaults (self):\n old_sdist.add_defaults(self)\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n self.filelist.extend(build_flib.get_source_files())\n\n if self.distribution.has_data_files():\n self.filelist.extend(self.distribution.get_data_files())\n\n def make_release_tree (self, base_dir, files):\n \"\"\"Create the directory tree that will become the source\n distribution archive. All directories implied by the filenames in\n 'files' are created under 'base_dir', and then we hard link or copy\n (if hard linking is unavailable) those files into place.\n Essentially, this duplicates the developer's source tree, but in a\n directory named after the distribution, containing only the files\n to be distributed.\n \"\"\"\n # Create all the directories under 'base_dir' necessary to\n # put 'files' there; the 'mkpath()' is just so we don't die\n # if the manifest happens to be empty.\n dest_files = remove_common_base(files)\n self.mkpath(base_dir)\n dir_util.create_tree(base_dir, dest_files,\n verbose=self.verbose, dry_run=self.dry_run)\n\n # And walk over the list of files, either making a hard link (if\n # os.link exists) to each one that doesn't already exist in its\n # corresponding location under 'base_dir', or copying each file\n # that's out-of-date in 'base_dir'. (Usually, all files will be\n # out-of-date, because by default we blow away 'base_dir' when\n # we're done making the distribution archives.)\n \n if hasattr(os, 'link'): # can make hard links on this system\n link = 'hard'\n msg = \"making hard links in %s...\" % base_dir\n else: # nope, have to copy\n link = None\n msg = \"copying files to %s...\" % base_dir\n\n if not files:\n self.warn(\"no files to distribute -- empty manifest?\")\n else:\n self.announce(msg)\n \n dest_files = [os.path.join(base_dir,file) for file in dest_files]\n file_pairs = zip(files,dest_files) \n for file,dest in file_pairs:\n if not os.path.isfile(file):\n self.warn(\"'%s' not a regular file -- skipping\" % file)\n else:\n #ej: here is the only change -- made to handle\n # absolute paths to files as well as relative\n #par,file_name = os.path.split(file)\n #dest = os.path.join(base_dir, file_name)\n # end of changes\n \n # old code\n #dest = os.path.join(base_dir, file)\n #end old code\n self.copy_file(file, dest, link=link)\n\n self.distribution.metadata.write_pkg_info(base_dir)\n #raise ValueError\n # make_release_tree ()\n\n def make_distribution (self):\n \"\"\" Overridden to force a build of zip files to have Windows line \n endings and tar balls to have Unix line endings.\n \n Create the source distribution(s). First, we create the release\n tree with 'make_release_tree()'; then, we create all required\n archive files (according to 'self.formats') from the release tree.\n Finally, we clean up by blowing away the release tree (unless\n 'self.keep_temp' is true). The list of archive files created is\n stored so it can be retrieved later by 'get_archive_files()'.\n \"\"\"\n # Don't warn about missing meta-data here -- should be (and is!)\n # done elsewhere.\n base_dir = self.distribution.get_fullname()\n base_name = os.path.join(self.dist_dir, base_dir)\n\n self.make_release_tree(base_dir, self.filelist.files)\n archive_files = [] # remember names of files we create\n for fmt in self.formats: \n self.convert_line_endings(base_dir,fmt)\n file = self.make_archive(base_name, fmt, base_dir=base_dir)\n archive_files.append(file)\n \n self.archive_files = archive_files\n\n if not self.keep_temp:\n dir_util.remove_tree(base_dir, self.verbose, self.dry_run)\n\n def convert_line_endings(self,base_dir,fmt):\n \"\"\" Convert all text files in a tree to have correct line endings.\n \n gztar --> \\n (Unix style)\n zip --> \\r\\n (Windows style)\n \"\"\"\n if fmt == 'gztar':\n line_endings.dos2unix_dir(base_dir)\n elif fmt == 'zip':\n line_endings.unix2dos_dir(base_dir)\n \ndef remove_common_base(files):\n \"\"\" Remove the greatest common base directory from all the\n absolute file paths in the list of files. files in the\n list without a parent directory are not affected.\n \"\"\"\n rel_files = filter(lambda x: not os.path.dirname(x),files)\n abs_files = filter(os.path.dirname,files)\n base = find_common_base(abs_files)\n # will leave files with local path unaffected\n # and maintains original file order\n results = [string.replace(file,base,'') for file in files]\n return results\n\ndef find_common_base(files):\n \"\"\" Find the \"greatest common base directory\" of a list of files\n \"\"\"\n if not files:\n return files\n result = ''\n d,f = os.path.split(files[0])\n keep_looking = 1 \n while(keep_looking and d):\n keep_looking = 0\n for file in files:\n if string.find('start'+file,'start'+d) == -1:\n keep_looking = 1\n break\n if keep_looking:\n d,f = os.path.split(d)\n else:\n result = d\n \n if d: \n d = os.path.join(d,'')\n return d ", "methods": [ { "name": "add_defaults", "long_name": "add_defaults( self )", "filename": "sdist.py", "nloc": 7, "complexity": 3, "token_count": 63, "parameters": [ "self" ], "start_line": 11, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "make_release_tree", "long_name": "make_release_tree( self , base_dir , files )", "filename": "sdist.py", "nloc": 23, "complexity": 6, "token_count": 162, "parameters": [ "self", "base_dir", "files" ], "start_line": 20, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 1 }, { "name": "make_distribution", "long_name": "make_distribution( self )", "filename": "sdist.py", "nloc": 13, "complexity": 3, "token_count": 117, "parameters": [ "self" ], "start_line": 78, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 1 }, { "name": "convert_line_endings", "long_name": "convert_line_endings( self , base_dir , fmt )", "filename": "sdist.py", "nloc": 5, "complexity": 3, "token_count": 32, "parameters": [ "self", "base_dir", "fmt" ], "start_line": 107, "end_line": 116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "remove_common_base", "long_name": "remove_common_base( files )", "filename": "sdist.py", "nloc": 6, "complexity": 2, "token_count": 63, "parameters": [ "files" ], "start_line": 118, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "find_common_base", "long_name": "find_common_base( files )", "filename": "sdist.py", "nloc": 19, "complexity": 8, "token_count": 106, "parameters": [ "files" ], "start_line": 131, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "methods_before": [ { "name": "add_defaults", "long_name": "add_defaults( self )", "filename": "sdist.py", "nloc": 7, "complexity": 3, "token_count": 63, "parameters": [ "self" ], "start_line": 11, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "make_release_tree", "long_name": "make_release_tree( self , base_dir , files )", "filename": "sdist.py", "nloc": 23, "complexity": 6, "token_count": 162, "parameters": [ "self", "base_dir", "files" ], "start_line": 20, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "make_distribution", "long_name": "make_distribution( self )", "filename": "sdist.py", "nloc": 12, "complexity": 3, "token_count": 105, "parameters": [ "self" ], "start_line": 77, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "convert_line_endings", "long_name": "convert_line_endings( self , base_dir , fmt )", "filename": "sdist.py", "nloc": 5, "complexity": 3, "token_count": 32, "parameters": [ "self", "base_dir", "fmt" ], "start_line": 105, "end_line": 114, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "remove_common_base", "long_name": "remove_common_base( files )", "filename": "sdist.py", "nloc": 6, "complexity": 2, "token_count": 63, "parameters": [ "files" ], "start_line": 116, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "find_common_base", "long_name": "find_common_base( files )", "filename": "sdist.py", "nloc": 19, "complexity": 8, "token_count": 106, "parameters": [ "files" ], "start_line": 129, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "find_common_base", "long_name": "find_common_base( files )", "filename": "sdist.py", "nloc": 19, "complexity": 8, "token_count": 106, "parameters": [ "files" ], "start_line": 131, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "make_distribution", "long_name": "make_distribution( self )", "filename": "sdist.py", "nloc": 13, "complexity": 3, "token_count": 117, "parameters": [ "self" ], "start_line": 78, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 1 }, { "name": "make_release_tree", "long_name": "make_release_tree( self , base_dir , files )", "filename": "sdist.py", "nloc": 23, "complexity": 6, "token_count": 162, "parameters": [ "self", "base_dir", "files" ], "start_line": 20, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 1 } ], "nloc": 81, "complexity": 25, "token_count": 614, "diff_parsed": { "added": [ "", " files = map(os.path.abspath, self.filelist.files)", " self.make_release_tree(base_dir, files)", " return ''", " return d" ], "deleted": [ " self.make_release_tree(base_dir, self.filelist.files)", " return files", " return d" ] } } ] }, { "hash": "d17624c1b932f64ebae0c01f8ef715e97b0a1bf2", "msg": "added optional name argument to default_config_dict so that sdist can be used locally", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-02-17T10:55:37+00:00", "author_timezone": 0, "committer_date": "2002-02-17T10:55:37+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "1a0784ac35f32056fb2f60c99f82ce073a4a2af0" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 4, "insertions": 12, "lines": 16, "files": 4, "dmm_unit_size": 0.8333333333333334, "dmm_unit_complexity": 0.8333333333333334, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/__version__.py", "new_path": "scipy_distutils/__version__.py", "filename": "__version__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,4 +1,4 @@\n # This file is automatically updated with update_version\n # function from scipy_distutils.misc_util.py\n-version = '0.6.23-alpha-100'\n-version_info = (0, 6, 23, 'alpha', 100)\n+version = '0.6.23-alpha-106'\n+version_info = (0, 6, 23, 'alpha', 106)\n", "added_lines": 2, "deleted_lines": 2, "source_code": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-106'\nversion_info = (0, 6, 23, 'alpha', 106)\n", "source_code_before": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-100'\nversion_info = (0, 6, 23, 'alpha', 100)\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 2, "complexity": 0, "token_count": 16, "diff_parsed": { "added": [ "version = '0.6.23-alpha-106'", "version_info = (0, 6, 23, 'alpha', 106)" ], "deleted": [ "version = '0.6.23-alpha-100'", "version_info = (0, 6, 23, 'alpha', 100)" ] } }, { "old_path": "scipy_distutils/command/build_clib.py", "new_path": "scipy_distutils/command/build_clib.py", "filename": "build_clib.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -162,6 +162,7 @@ def check_library_list (self, libraries):\n # with only names changed to protect the innocent!\n \n if type(libraries) is not ListType:\n+ print type(libraries)\n raise DistutilsSetupError, \\\n \"'libraries' option must be a list of tuples\"\n \n", "added_lines": 1, "deleted_lines": 0, "source_code": "\"\"\"distutils.command.build_clib\n\nImplements the Distutils 'build_clib' command, to build a C/C++ library\nthat is included in the module distribution and needed by an extension\nmodule.\"\"\"\n\n# created (an empty husk) 1999/12/18, Greg Ward\n# fleshed out 2000/02/03-04\n\n__revision__ = \"$Id$\"\n\n\n# XXX this module has *lots* of code ripped-off quite transparently from\n# build_ext.py -- not surprisingly really, as the work required to build\n# a static library from a collection of C source files is not really all\n# that different from what's required to build a shared object file from\n# a collection of C source files. Nevertheless, I haven't done the\n# necessary refactoring to account for the overlap in code between the\n# two modules, mainly because a number of subtle details changed in the\n# cut 'n paste. Sigh.\n\nimport os, string\nfrom glob import glob\nfrom types import *\nfrom distutils.core import Command\nfrom distutils.errors import *\nfrom distutils.sysconfig import customize_compiler\n\n\ndef show_compilers ():\n from distutils.ccompiler import show_compilers\n show_compilers()\n\ndef get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob(os.path.join(dir,\"*.h\"))\n headers.extend(head)\n\n return headers\n\ndef get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n\n return direcs\n\n\nclass build_clib (Command):\n\n description = \"build C/C++ libraries used by Python extensions\"\n\n user_options = [\n ('build-clib', 'b',\n \"directory to build C/C++ 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 ('compiler=', 'c',\n \"specify the compiler type\"),\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 self.build_clib = None\n self.build_temp = None\n\n # List of libraries to build\n self.libraries = None\n\n # Compilation options for all libraries\n self.include_dirs = None\n self.define = None\n self.undef = None\n self.debug = None\n self.force = 0\n self.compiler = None\n\n # initialize_options()\n\n\n def finalize_options (self):\n\n # This might be confusing: both build-clib and build-temp default\n # to build-temp as defined by the \"build\" command. This is because\n # I think that C libraries are really just temporary build\n # by-products, at least from the point of view of building Python\n # extensions -- but I want to keep my options open.\n self.set_undefined_options('build',\n ('build_temp', 'build_clib'),\n ('build_temp', 'build_temp'),\n ('compiler', 'compiler'),\n ('debug', 'debug'),\n ('force', 'force'))\n\n self.libraries = self.distribution.libraries\n if self.libraries:\n self.check_library_list(self.libraries)\n\n if self.include_dirs is None:\n self.include_dirs = self.distribution.include_dirs or []\n if type(self.include_dirs) is StringType:\n self.include_dirs = string.split(self.include_dirs,\n os.pathsep)\n\n # XXX same as for build_ext -- what about 'self.define' and\n # 'self.undef' ?\n\n # finalize_options()\n\n\n def run (self):\n\n if not self.libraries:\n return\n\n # Yech -- this is cut 'n pasted from build_ext.py!\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n customize_compiler(self.compiler)\n\n if self.include_dirs is not None:\n self.compiler.set_include_dirs(self.include_dirs)\n if self.define is not None:\n # 'define' option is a list of (name,value) tuples\n for (name,value) in self.define:\n self.compiler.define_macro(name, value)\n if self.undef is not None:\n for macro in self.undef:\n self.compiler.undefine_macro(macro)\n\n self.build_libraries(self.libraries)\n\n # run()\n\n\n def check_library_list (self, libraries):\n \"\"\"Ensure that the list of libraries (presumably provided as a\n command option 'libraries') is valid, i.e. it is a list of\n 2-tuples, where the tuples are (library_name, build_info_dict).\n Raise DistutilsSetupError if the structure is invalid anywhere;\n just returns otherwise.\"\"\"\n\n # Yechh, blecch, ackk: this is ripped straight out of build_ext.py,\n # with only names changed to protect the innocent!\n\n if type(libraries) is not ListType:\n print type(libraries)\n raise DistutilsSetupError, \\\n \"'libraries' option must be a list of tuples\"\n\n for lib in libraries:\n if type(lib) is not TupleType and len(lib) != 2:\n raise DistutilsSetupError, \\\n \"each element of 'libraries' must a 2-tuple\"\n\n if type(lib[0]) is not StringType:\n raise DistutilsSetupError, \\\n \"first element of each tuple in 'libraries' \" + \\\n \"must be a string (the library name)\"\n if '/' in lib[0] or (os.sep != '/' and os.sep in lib[0]):\n raise DistutilsSetupError, \\\n (\"bad library name '%s': \" + \n \"may not contain directory separators\") % \\\n lib[0]\n\n if type(lib[1]) is not DictionaryType:\n raise DistutilsSetupError, \\\n \"second element of each tuple in 'libraries' \" + \\\n \"must be a dictionary (build info)\"\n # for lib\n\n # check_library_list ()\n\n\n def get_library_names (self):\n # Assume the library list is valid -- 'check_library_list()' is\n # called from 'finalize_options()', so it should be!\n\n if not self.libraries:\n return None\n\n lib_names = []\n for (lib_name, build_info) in self.libraries:\n lib_names.append(lib_name)\n return lib_names\n\n # get_library_names ()\n\n\n def get_source_files (self):\n self.check_library_list(self.libraries)\n filenames = []\n\n # Gets source files specified and any \"*.h\" header files in\n # those directories. \n for ext in self.libraries:\n filenames.extend(ext[1]['sources'])\n filenames.extend(get_headers(get_directories(ext[1]['sources'])))\n\n return filenames\n\n def build_libraries (self, libraries):\n\n compiler = self.compiler\n\n for (lib_name, build_info) in libraries:\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in '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\n self.announce(\"building '%s' library\" % lib_name)\n\n # First, compile the source code to object files in the library\n # directory. (This should probably change to putting object\n # files in a temporary build directory.)\n macros = build_info.get('macros')\n include_dirs = build_info.get('include_dirs')\n objects = self.compiler.compile(sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug)\n\n # Now \"link\" the object files together into a static library.\n # (On Unix at least, this isn't really linking -- it just\n # builds an archive. Whatever.)\n self.compiler.create_static_lib(objects, lib_name,\n output_dir=self.build_clib,\n debug=self.debug)\n\n # for libraries\n\n # build_libraries ()\n\n# class build_lib\n", "source_code_before": "\"\"\"distutils.command.build_clib\n\nImplements the Distutils 'build_clib' command, to build a C/C++ library\nthat is included in the module distribution and needed by an extension\nmodule.\"\"\"\n\n# created (an empty husk) 1999/12/18, Greg Ward\n# fleshed out 2000/02/03-04\n\n__revision__ = \"$Id$\"\n\n\n# XXX this module has *lots* of code ripped-off quite transparently from\n# build_ext.py -- not surprisingly really, as the work required to build\n# a static library from a collection of C source files is not really all\n# that different from what's required to build a shared object file from\n# a collection of C source files. Nevertheless, I haven't done the\n# necessary refactoring to account for the overlap in code between the\n# two modules, mainly because a number of subtle details changed in the\n# cut 'n paste. Sigh.\n\nimport os, string\nfrom glob import glob\nfrom types import *\nfrom distutils.core import Command\nfrom distutils.errors import *\nfrom distutils.sysconfig import customize_compiler\n\n\ndef show_compilers ():\n from distutils.ccompiler import show_compilers\n show_compilers()\n\ndef get_headers(directory_list):\n # get *.h files from list of directories\n headers = []\n for dir in directory_list:\n head = glob(os.path.join(dir,\"*.h\"))\n headers.extend(head)\n\n return headers\n\ndef get_directories(list_of_sources):\n # get unique directories from list of sources.\n direcs = []\n for file in list_of_sources:\n dir = os.path.split(file)\n if dir[0] != '' and not dir[0] in direcs:\n direcs.append(dir[0])\n\n return direcs\n\n\nclass build_clib (Command):\n\n description = \"build C/C++ libraries used by Python extensions\"\n\n user_options = [\n ('build-clib', 'b',\n \"directory to build C/C++ 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 ('compiler=', 'c',\n \"specify the compiler type\"),\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 self.build_clib = None\n self.build_temp = None\n\n # List of libraries to build\n self.libraries = None\n\n # Compilation options for all libraries\n self.include_dirs = None\n self.define = None\n self.undef = None\n self.debug = None\n self.force = 0\n self.compiler = None\n\n # initialize_options()\n\n\n def finalize_options (self):\n\n # This might be confusing: both build-clib and build-temp default\n # to build-temp as defined by the \"build\" command. This is because\n # I think that C libraries are really just temporary build\n # by-products, at least from the point of view of building Python\n # extensions -- but I want to keep my options open.\n self.set_undefined_options('build',\n ('build_temp', 'build_clib'),\n ('build_temp', 'build_temp'),\n ('compiler', 'compiler'),\n ('debug', 'debug'),\n ('force', 'force'))\n\n self.libraries = self.distribution.libraries\n if self.libraries:\n self.check_library_list(self.libraries)\n\n if self.include_dirs is None:\n self.include_dirs = self.distribution.include_dirs or []\n if type(self.include_dirs) is StringType:\n self.include_dirs = string.split(self.include_dirs,\n os.pathsep)\n\n # XXX same as for build_ext -- what about 'self.define' and\n # 'self.undef' ?\n\n # finalize_options()\n\n\n def run (self):\n\n if not self.libraries:\n return\n\n # Yech -- this is cut 'n pasted from build_ext.py!\n from distutils.ccompiler import new_compiler\n self.compiler = new_compiler(compiler=self.compiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n customize_compiler(self.compiler)\n\n if self.include_dirs is not None:\n self.compiler.set_include_dirs(self.include_dirs)\n if self.define is not None:\n # 'define' option is a list of (name,value) tuples\n for (name,value) in self.define:\n self.compiler.define_macro(name, value)\n if self.undef is not None:\n for macro in self.undef:\n self.compiler.undefine_macro(macro)\n\n self.build_libraries(self.libraries)\n\n # run()\n\n\n def check_library_list (self, libraries):\n \"\"\"Ensure that the list of libraries (presumably provided as a\n command option 'libraries') is valid, i.e. it is a list of\n 2-tuples, where the tuples are (library_name, build_info_dict).\n Raise DistutilsSetupError if the structure is invalid anywhere;\n just returns otherwise.\"\"\"\n\n # Yechh, blecch, ackk: this is ripped straight out of build_ext.py,\n # with only names changed to protect the innocent!\n\n if type(libraries) is not ListType:\n raise DistutilsSetupError, \\\n \"'libraries' option must be a list of tuples\"\n\n for lib in libraries:\n if type(lib) is not TupleType and len(lib) != 2:\n raise DistutilsSetupError, \\\n \"each element of 'libraries' must a 2-tuple\"\n\n if type(lib[0]) is not StringType:\n raise DistutilsSetupError, \\\n \"first element of each tuple in 'libraries' \" + \\\n \"must be a string (the library name)\"\n if '/' in lib[0] or (os.sep != '/' and os.sep in lib[0]):\n raise DistutilsSetupError, \\\n (\"bad library name '%s': \" + \n \"may not contain directory separators\") % \\\n lib[0]\n\n if type(lib[1]) is not DictionaryType:\n raise DistutilsSetupError, \\\n \"second element of each tuple in 'libraries' \" + \\\n \"must be a dictionary (build info)\"\n # for lib\n\n # check_library_list ()\n\n\n def get_library_names (self):\n # Assume the library list is valid -- 'check_library_list()' is\n # called from 'finalize_options()', so it should be!\n\n if not self.libraries:\n return None\n\n lib_names = []\n for (lib_name, build_info) in self.libraries:\n lib_names.append(lib_name)\n return lib_names\n\n # get_library_names ()\n\n\n def get_source_files (self):\n self.check_library_list(self.libraries)\n filenames = []\n\n # Gets source files specified and any \"*.h\" header files in\n # those directories. \n for ext in self.libraries:\n filenames.extend(ext[1]['sources'])\n filenames.extend(get_headers(get_directories(ext[1]['sources'])))\n\n return filenames\n\n def build_libraries (self, libraries):\n\n compiler = self.compiler\n\n for (lib_name, build_info) in libraries:\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in '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\n self.announce(\"building '%s' library\" % lib_name)\n\n # First, compile the source code to object files in the library\n # directory. (This should probably change to putting object\n # files in a temporary build directory.)\n macros = build_info.get('macros')\n include_dirs = build_info.get('include_dirs')\n objects = self.compiler.compile(sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug)\n\n # Now \"link\" the object files together into a static library.\n # (On Unix at least, this isn't really linking -- it just\n # builds an archive. Whatever.)\n self.compiler.create_static_lib(objects, lib_name,\n output_dir=self.build_clib,\n debug=self.debug)\n\n # for libraries\n\n # build_libraries ()\n\n# class build_lib\n", "methods": [ { "name": "show_compilers", "long_name": "show_compilers( )", "filename": "build_clib.py", "nloc": 3, "complexity": 1, "token_count": 13, "parameters": [], "start_line": 30, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "get_headers", "long_name": "get_headers( directory_list )", "filename": "build_clib.py", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "directory_list" ], "start_line": 34, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "get_directories", "long_name": "get_directories( list_of_sources )", "filename": "build_clib.py", "nloc": 7, "complexity": 4, "token_count": 51, "parameters": [ "list_of_sources" ], "start_line": 43, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_clib.py", "nloc": 10, "complexity": 1, "token_count": 50, "parameters": [ "self" ], "start_line": 78, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "build_clib.py", "nloc": 15, "complexity": 5, "token_count": 108, "parameters": [ "self" ], "start_line": 96, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_clib.py", "nloc": 18, "complexity": 7, "token_count": 132, "parameters": [ "self" ], "start_line": 126, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_library_list", "long_name": "check_library_list( self , libraries )", "filename": "build_clib.py", "nloc": 22, "complexity": 10, "token_count": 133, "parameters": [ "self", "libraries" ], "start_line": 154, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 1 }, { "name": "get_library_names", "long_name": "get_library_names( self )", "filename": "build_clib.py", "nloc": 7, "complexity": 3, "token_count": 36, "parameters": [ "self" ], "start_line": 193, "end_line": 203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_clib.py", "nloc": 7, "complexity": 2, "token_count": 56, "parameters": [ "self" ], "start_line": 208, "end_line": 218, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , libraries )", "filename": "build_clib.py", "nloc": 21, "complexity": 4, "token_count": 141, "parameters": [ "self", "libraries" ], "start_line": 220, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 } ], "methods_before": [ { "name": "show_compilers", "long_name": "show_compilers( )", "filename": "build_clib.py", "nloc": 3, "complexity": 1, "token_count": 13, "parameters": [], "start_line": 30, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "get_headers", "long_name": "get_headers( directory_list )", "filename": "build_clib.py", "nloc": 6, "complexity": 2, "token_count": 37, "parameters": [ "directory_list" ], "start_line": 34, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "get_directories", "long_name": "get_directories( list_of_sources )", "filename": "build_clib.py", "nloc": 7, "complexity": 4, "token_count": 51, "parameters": [ "list_of_sources" ], "start_line": 43, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_clib.py", "nloc": 10, "complexity": 1, "token_count": 50, "parameters": [ "self" ], "start_line": 78, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "build_clib.py", "nloc": 15, "complexity": 5, "token_count": 108, "parameters": [ "self" ], "start_line": 96, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "build_clib.py", "nloc": 18, "complexity": 7, "token_count": 132, "parameters": [ "self" ], "start_line": 126, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_library_list", "long_name": "check_library_list( self , libraries )", "filename": "build_clib.py", "nloc": 21, "complexity": 10, "token_count": 128, "parameters": [ "self", "libraries" ], "start_line": 154, "end_line": 186, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 1 }, { "name": "get_library_names", "long_name": "get_library_names( self )", "filename": "build_clib.py", "nloc": 7, "complexity": 3, "token_count": 36, "parameters": [ "self" ], "start_line": 192, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_clib.py", "nloc": 7, "complexity": 2, "token_count": 56, "parameters": [ "self" ], "start_line": 207, "end_line": 217, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , libraries )", "filename": "build_clib.py", "nloc": 21, "complexity": 4, "token_count": 141, "parameters": [ "self", "libraries" ], "start_line": 219, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "check_library_list", "long_name": "check_library_list( self , libraries )", "filename": "build_clib.py", "nloc": 22, "complexity": 10, "token_count": 133, "parameters": [ "self", "libraries" ], "start_line": 154, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 1 } ], "nloc": 147, "complexity": 39, "token_count": 875, "diff_parsed": { "added": [ " print type(libraries)" ], "deleted": [] } }, { "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": "@@ -224,6 +224,9 @@ def get_runtime_library_dirs(self):\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", "added_lines": 3, "deleted_lines": 0, "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\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 Gnu\n VAST\n\"\"\"\n\nimport distutils\nimport distutils.dep_util, distutils.dir_util\nimport os,sys,string\nimport commands,re\nfrom types import *\nfrom distutils.command.build_clib import build_clib\nfrom distutils.errors import *\n\nclass FortranCompilerError (CCompilerError):\n \"\"\"Some compile/link operation failed.\"\"\"\nclass FortranCompileError (FortranCompilerError):\n \"\"\"Failure to compile one or more Fortran source files.\"\"\"\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 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 fc = find_fortran_compiler(self.fcompiler,\n self.fcompiler_exec,\n self.f90compiler_exec)\n if not fc:\n raise DistutilsOptionError, 'Fortran compiler not available: %s'%(self.fcompiler)\n else:\n self.announce(' using %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 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 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 self.announce(\" building '%s' library\" % lib_name)\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\n\nclass fortran_compiler_base:\n\n vendor = None\n ver_match = None\n \n def __init__(self):\n # Default initialization. Constructors of derived classes MUST\n # call this functions.\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,dirty_files,module_dirs=None, 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 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 + ' -c ' + source + ' -o ' + object \n print cmd\n failure = os.system(cmd)\n if failure:\n raise FortranCompileError, 'failure during compile' \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\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):\n lib_file = os.path.join(output_dir,'lib'+library_name+'.a')\n newer = distutils.dep_util.newer\n # This doesn't work -- no way to know if the file is in the archive\n #object_files = filter(lambda o,lib=lib_file:\\\n # distutils.dep_util.newer(o,lib),object_files)\n objects = string.join(object_files)\n if objects:\n cmd = 'ar -cur %s %s' % (lib_file,objects)\n print cmd\n os.system(cmd)\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,module_dirs,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':\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 self.create_static_lib(obj,library_name,temp_dir)\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 #print 'command:', self.ver_cmd\n exit_status, out_text = run_command(self.ver_cmd)\n #print exit_status, out_text\n if not exit_status:\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\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):\n fortran_compiler_base.__init__(self)\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\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\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 self.ver_cmd = self.f77_compiler + ' -V'\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 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 \n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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 = ' -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.libraries = ['fortran', 'ftn', 'm']\n self.library_dirs = self.find_lib_dir()\n\n self.ver_cmd = self.f77_compiler + ' -version'\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\n\nclass gnu_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Gnu'\n ver_match = r'g77 version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if sys.platform == 'win32':\n self.libraries = ['gcc','g2c']\n self.library_dirs = self.find_lib_directories()\n else:\n # On linux g77 does not need lib_directories to be specified.\n self.libraries = ['g2c']\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 switches = ' -Wall -fno-second-underscore '\n\n if os.name != 'nt':\n switches = switches + ' -fpic '\n\n self.f77_switches = switches\n\n self.ver_cmd = self.f77_compiler + ' -v '\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\n # it.\n if self.get_version():\n if self.version[0]=='3': # is g77 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 ' \n return opt\n \n def find_lib_directories(self):\n lib_dir = []\n match = r'Reading specs from (.*)/specs'\n\n # works I think only for unix... \n exit_status, out_text = run_command('g77 -v')\n if not exit_status:\n m = re.findall(match,out_text)\n if m:\n lib_dir= m #m[0] \n return lib_dir\n\n def get_linker_so(self):\n # win32 linking should be handled by standard linker\n if sys.platform != 'win32':\n return [self.f77_compiler,'-shared']\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, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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 for the Itanium\\(TM\\)-based applications, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n if fc is None:\n fc = 'efc'\n intel_ia32_fortran_compiler.__init__(self, fc, f90c)\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):\n fortran_compiler_base.__init__(self)\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\nclass vast_fortran_compiler(fortran_compiler_base):\n\n vendor = 'VAST'\n ver_match = r'\\s*Pacific-Sierra Research vf90 (Personal|Professional)\\s+(?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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\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):\n fortran_compiler_base.__init__(self)\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 -assume nozsize -math_library fast -tune host '\n return opt\n\n def get_linker_so(self):\n # XXX: is -shared needed?\n return [self.f77_compiler,'-shared']\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):\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)\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 vast_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\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 Gnu\n VAST\n\"\"\"\n\nimport distutils\nimport distutils.dep_util, distutils.dir_util\nimport os,sys,string\nimport commands,re\nfrom types import *\nfrom distutils.command.build_clib import build_clib\nfrom distutils.errors import *\n\nclass FortranCompilerError (CCompilerError):\n \"\"\"Some compile/link operation failed.\"\"\"\nclass FortranCompileError (FortranCompilerError):\n \"\"\"Failure to compile one or more Fortran source files.\"\"\"\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 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 fc = find_fortran_compiler(self.fcompiler,\n self.fcompiler_exec,\n self.f90compiler_exec)\n if not fc:\n raise DistutilsOptionError, 'Fortran compiler not available: %s'%(self.fcompiler)\n else:\n self.announce(' using %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 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 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 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 self.announce(\" building '%s' library\" % lib_name)\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\n\nclass fortran_compiler_base:\n\n vendor = None\n ver_match = None\n \n def __init__(self):\n # Default initialization. Constructors of derived classes MUST\n # call this functions.\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,dirty_files,module_dirs=None, 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 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 + ' -c ' + source + ' -o ' + object \n print cmd\n failure = os.system(cmd)\n if failure:\n raise FortranCompileError, 'failure during compile' \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\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):\n lib_file = os.path.join(output_dir,'lib'+library_name+'.a')\n newer = distutils.dep_util.newer\n # This doesn't work -- no way to know if the file is in the archive\n #object_files = filter(lambda o,lib=lib_file:\\\n # distutils.dep_util.newer(o,lib),object_files)\n objects = string.join(object_files)\n if objects:\n cmd = 'ar -cur %s %s' % (lib_file,objects)\n print cmd\n os.system(cmd)\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,module_dirs,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':\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 self.create_static_lib(obj,library_name,temp_dir)\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 #print 'command:', self.ver_cmd\n exit_status, out_text = run_command(self.ver_cmd)\n #print exit_status, out_text\n if not exit_status:\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\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):\n fortran_compiler_base.__init__(self)\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\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\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 self.ver_cmd = self.f77_compiler + ' -V'\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 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 \n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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 = ' -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.libraries = ['fortran', 'ftn', 'm']\n self.library_dirs = self.find_lib_dir()\n\n self.ver_cmd = self.f77_compiler + ' -version'\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\n\nclass gnu_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Gnu'\n ver_match = r'g77 version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if sys.platform == 'win32':\n self.libraries = ['gcc','g2c']\n self.library_dirs = self.find_lib_directories()\n else:\n # On linux g77 does not need lib_directories to be specified.\n self.libraries = ['g2c']\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 switches = ' -Wall -fno-second-underscore '\n\n if os.name != 'nt':\n switches = switches + ' -fpic '\n\n self.f77_switches = switches\n\n self.ver_cmd = self.f77_compiler + ' -v '\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\n # it.\n if self.get_version():\n if self.version[0]=='3': # is g77 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 ' \n return opt\n \n def find_lib_directories(self):\n lib_dir = []\n match = r'Reading specs from (.*)/specs'\n\n # works I think only for unix... \n exit_status, out_text = run_command('g77 -v')\n if not exit_status:\n m = re.findall(match,out_text)\n if m:\n lib_dir= m #m[0] \n return lib_dir\n\n def get_linker_so(self):\n # win32 linking should be handled by standard linker\n if sys.platform != 'win32':\n return [self.f77_compiler,'-shared']\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, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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 for the Itanium\\(TM\\)-based applications, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n if fc is None:\n fc = 'efc'\n intel_ia32_fortran_compiler.__init__(self, fc, f90c)\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):\n fortran_compiler_base.__init__(self)\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\nclass vast_fortran_compiler(fortran_compiler_base):\n\n vendor = 'VAST'\n ver_match = r'\\s*Pacific-Sierra Research vf90 (Personal|Professional)\\s+(?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\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\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):\n fortran_compiler_base.__init__(self)\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 -assume nozsize -math_library fast -tune host '\n return opt\n\n def get_linker_so(self):\n # XXX: is -shared needed?\n return [self.f77_compiler,'-shared']\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):\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)\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 vast_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": 58, "end_line": 63, "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": 23, "parameters": [], "start_line": 67, "end_line": 71, "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": 101, "end_line": 113, "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": 17, "complexity": 3, "token_count": 104, "parameters": [ "self" ], "start_line": 117, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "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": 137, "end_line": 139, "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": 141, "end_line": 144, "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": 148, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "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": 154, "end_line": 174, "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": 6, "complexity": 3, "token_count": 34, "parameters": [ "self" ], "start_line": 176, "end_line": 181, "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": 6, "complexity": 3, "token_count": 34, "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": "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": 192, "end_line": 209, "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": 7, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 213, "end_line": 222, "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": 226, "end_line": 237, "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": 18, "complexity": 5, "token_count": 122, "parameters": [ "self", "fortran_libraries" ], "start_line": 239, "end_line": 260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 88, "parameters": [ "self" ], "start_line": 272, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "to_object", "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 13, "complexity": 3, "token_count": 89, "parameters": [ "self", "dirty_files", "module_dirs", "temp_dir" ], "start_line": 295, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 309, "end_line": 314, "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": 316, "end_line": 319, "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": 15, "complexity": 4, "token_count": 103, "parameters": [ "self", "compiler", "switches", "source_files", "module_dirs", "temp_dir" ], "start_line": 321, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 339, "end_line": 342, "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": 344, "end_line": 347, "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": 350, "end_line": 351, "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 )", "filename": "build_flib.py", "nloc": 9, "complexity": 2, "token_count": 68, "parameters": [ "self", "object_files", "library_name", "output_dir", "debug" ], "start_line": 353, "end_line": 364, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "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": 13, "complexity": 3, "token_count": 104, "parameters": [ "self", "library_name", "source_list", "module_dirs", "temp_dir" ], "start_line": 366, "end_line": 392, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "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": 394, "end_line": 401, "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": 403, "end_line": 404, "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": 10, "complexity": 4, "token_count": 66, "parameters": [ "self" ], "start_line": 406, "end_line": 424, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 426, "end_line": 427, "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": 428, "end_line": 429, "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": 430, "end_line": 431, "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": 432, "end_line": 433, "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": 434, "end_line": 439, "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": 441, "end_line": 442, "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 )", "filename": "build_flib.py", "nloc": 31, "complexity": 5, "token_count": 177, "parameters": [ "self", "fc", "f90c" ], "start_line": 450, "end_line": 488, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 490, "end_line": 495, "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": 497, "end_line": 498, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 98, "parameters": [ "self", "fc", "f90c" ], "start_line": 511, "end_line": 533, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "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": 535, "end_line": 540, "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": 15, "complexity": 3, "token_count": 99, "parameters": [ "self" ], "start_line": 542, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 557, "end_line": 558, "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": 559, "end_line": 560, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 94, "parameters": [ "self", "fc", "f90c" ], "start_line": 568, "end_line": 586, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 588, "end_line": 590, "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": 591, "end_line": 593, "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": 594, "end_line": 595, "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": 596, "end_line": 597, "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 )", "filename": "build_flib.py", "nloc": 18, "complexity": 5, "token_count": 112, "parameters": [ "self", "fc", "f90c" ], "start_line": 605, "end_line": 629, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 21, "complexity": 10, "token_count": 120, "parameters": [ "self" ], "start_line": 631, "end_line": 654, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "find_lib_directories", "long_name": "find_lib_directories( self )", "filename": "build_flib.py", "nloc": 9, "complexity": 3, "token_count": 43, "parameters": [ "self" ], "start_line": 656, "end_line": 666, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 2, "token_count": 20, "parameters": [ "self" ], "start_line": 668, "end_line": 671, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "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": 673, "end_line": 674, "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 )", "filename": "build_flib.py", "nloc": 22, "complexity": 5, "token_count": 140, "parameters": [ "self", "fc", "f90c" ], "start_line": 683, "end_line": 711, "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": 713, "end_line": 727, "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": 730, "end_line": 731, "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 )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 31, "parameters": [ "self", "fc", "f90c" ], "start_line": 739, "end_line": 742, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 100, "parameters": [ "self", "fc", "f90c" ], "start_line": 750, "end_line": 769, "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": 771, "end_line": 773, "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": 775, "end_line": 776, "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 )", "filename": "build_flib.py", "nloc": 20, "complexity": 5, "token_count": 128, "parameters": [ "self", "fc", "f90c" ], "start_line": 784, "end_line": 808, "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": 812, "end_line": 813, "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 )", "filename": "build_flib.py", "nloc": 14, "complexity": 3, "token_count": 91, "parameters": [ "self", "fc", "f90c" ], "start_line": 820, "end_line": 842, "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": 3, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 844, "end_line": 846, "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": 848, "end_line": 850, "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": 853, "end_line": 855, "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": 857, "end_line": 858, "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": 860, "end_line": 861, "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": 863, "end_line": 864, "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 )", "filename": "build_flib.py", "nloc": 11, "complexity": 5, "token_count": 59, "parameters": [ "vendor", "fc", "f90c" ], "start_line": 866, "end_line": 876, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "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": 58, "end_line": 63, "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": 23, "parameters": [], "start_line": 67, "end_line": 71, "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": 101, "end_line": 113, "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": 17, "complexity": 3, "token_count": 104, "parameters": [ "self" ], "start_line": 117, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "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": 137, "end_line": 139, "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": 141, "end_line": 144, "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": 148, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "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": 154, "end_line": 174, "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": 6, "complexity": 3, "token_count": 34, "parameters": [ "self" ], "start_line": 176, "end_line": 181, "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": 6, "complexity": 3, "token_count": 34, "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": "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": 192, "end_line": 209, "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": 7, "complexity": 3, "token_count": 42, "parameters": [ "self" ], "start_line": 213, "end_line": 222, "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": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 226, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "build_libraries", "long_name": "build_libraries( self , fortran_libraries )", "filename": "build_flib.py", "nloc": 18, "complexity": 5, "token_count": 122, "parameters": [ "self", "fortran_libraries" ], "start_line": 236, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "build_flib.py", "nloc": 16, "complexity": 3, "token_count": 88, "parameters": [ "self" ], "start_line": 269, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "to_object", "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", "filename": "build_flib.py", "nloc": 13, "complexity": 3, "token_count": 89, "parameters": [ "self", "dirty_files", "module_dirs", "temp_dir" ], "start_line": 292, "end_line": 304, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 306, "end_line": 311, "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": 313, "end_line": 316, "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": 15, "complexity": 4, "token_count": 103, "parameters": [ "self", "compiler", "switches", "source_files", "module_dirs", "temp_dir" ], "start_line": 318, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 336, "end_line": 339, "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": 341, "end_line": 344, "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": 347, "end_line": 348, "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 )", "filename": "build_flib.py", "nloc": 9, "complexity": 2, "token_count": 68, "parameters": [ "self", "object_files", "library_name", "output_dir", "debug" ], "start_line": 350, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "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": 13, "complexity": 3, "token_count": 104, "parameters": [ "self", "library_name", "source_list", "module_dirs", "temp_dir" ], "start_line": 363, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "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": 391, "end_line": 398, "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": 400, "end_line": 401, "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": 10, "complexity": 4, "token_count": 66, "parameters": [ "self" ], "start_line": 403, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 423, "end_line": 424, "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": 425, "end_line": 426, "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": 427, "end_line": 428, "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": 429, "end_line": 430, "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": 431, "end_line": 436, "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": 438, "end_line": 439, "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 )", "filename": "build_flib.py", "nloc": 31, "complexity": 5, "token_count": 177, "parameters": [ "self", "fc", "f90c" ], "start_line": 447, "end_line": 485, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "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": 487, "end_line": 492, "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": 494, "end_line": 495, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 98, "parameters": [ "self", "fc", "f90c" ], "start_line": 508, "end_line": 530, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "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": 532, "end_line": 537, "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": 15, "complexity": 3, "token_count": 99, "parameters": [ "self" ], "start_line": 539, "end_line": 553, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "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": 554, "end_line": 555, "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": 556, "end_line": 557, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 94, "parameters": [ "self", "fc", "f90c" ], "start_line": 565, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "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": 585, "end_line": 587, "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": 588, "end_line": 590, "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": 591, "end_line": 592, "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": 593, "end_line": 594, "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 )", "filename": "build_flib.py", "nloc": 18, "complexity": 5, "token_count": 112, "parameters": [ "self", "fc", "f90c" ], "start_line": 602, "end_line": 626, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "get_opt", "long_name": "get_opt( self )", "filename": "build_flib.py", "nloc": 21, "complexity": 10, "token_count": 120, "parameters": [ "self" ], "start_line": 628, "end_line": 651, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "find_lib_directories", "long_name": "find_lib_directories( self )", "filename": "build_flib.py", "nloc": 9, "complexity": 3, "token_count": 43, "parameters": [ "self" ], "start_line": 653, "end_line": 663, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "build_flib.py", "nloc": 3, "complexity": 2, "token_count": 20, "parameters": [ "self" ], "start_line": 665, "end_line": 668, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "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": 670, "end_line": 671, "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 )", "filename": "build_flib.py", "nloc": 22, "complexity": 5, "token_count": 140, "parameters": [ "self", "fc", "f90c" ], "start_line": 680, "end_line": 708, "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": 710, "end_line": 724, "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": 727, "end_line": 728, "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 )", "filename": "build_flib.py", "nloc": 4, "complexity": 2, "token_count": 31, "parameters": [ "self", "fc", "f90c" ], "start_line": 736, "end_line": 739, "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 )", "filename": "build_flib.py", "nloc": 15, "complexity": 3, "token_count": 100, "parameters": [ "self", "fc", "f90c" ], "start_line": 747, "end_line": 766, "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": 768, "end_line": 770, "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": 772, "end_line": 773, "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 )", "filename": "build_flib.py", "nloc": 20, "complexity": 5, "token_count": 128, "parameters": [ "self", "fc", "f90c" ], "start_line": 781, "end_line": 805, "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": 809, "end_line": 810, "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 )", "filename": "build_flib.py", "nloc": 14, "complexity": 3, "token_count": 91, "parameters": [ "self", "fc", "f90c" ], "start_line": 817, "end_line": 839, "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": 3, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 841, "end_line": 843, "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": 845, "end_line": 847, "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": 850, "end_line": 852, "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": 854, "end_line": 855, "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": 857, "end_line": 858, "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": 860, "end_line": 861, "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 )", "filename": "build_flib.py", "nloc": 11, "complexity": 5, "token_count": 59, "parameters": [ "vendor", "fc", "f90c" ], "start_line": 863, "end_line": 873, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "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": 226, "end_line": 237, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 } ], "nloc": 646, "complexity": 168, "token_count": 3751, "diff_parsed": { "added": [ " if not self.has_f_libraries():", " return []", "" ], "deleted": [] } }, { "old_path": "scipy_distutils/misc_util.py", "new_path": "scipy_distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -231,14 +231,18 @@ def package_config(primary,dependencies=[]):\n 'headers']\n dict_keys = ['package_dir'] \n \n-def default_config_dict():\n+def default_config_dict(name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n+ if name is not None:\n+ # Useful for local builds\n+ d['name'] = name\n+ d['version'] = update_version() \n return d\n \n def merge_config_dicts(config_list):\n- result = default_config_dict() \n+ result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n", "added_lines": 6, "deleted_lines": 2, "source_code": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n if name is not None:\n # Useful for local builds\n d['name'] = name\n d['version'] = update_version() \n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", "source_code_before": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict():\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict() \n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", "methods": [ { "name": "update_version", "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", "filename": "misc_util.py", "nloc": 65, "complexity": 12, "token_count": 351, "parameters": [ "release_level", "path", "major", "overwrite_version_py" ], "start_line": 3, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 }, { "name": "get_version", "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", "filename": "misc_util.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "release_level", "path", "major" ], "start_line": 111, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_cvs_revision", "long_name": "get_cvs_revision( path )", "filename": "misc_util.py", "nloc": 21, "complexity": 10, "token_count": 190, "parameters": [ "path" ], "start_line": 127, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_path", "long_name": "get_path( mod_name )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 80, "parameters": [ "mod_name" ], "start_line": 156, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 174, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "add_grandparent_to_path", "long_name": "add_grandparent_to_path( mod_name )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "mod_name" ], "start_line": 179, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 184, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "append_package_dir_to_path", "long_name": "append_package_dir_to_path( package_name )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 64, "parameters": [ "package_name" ], "start_line": 187, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "get_package_config", "long_name": "get_package_config( package_name )", "filename": "misc_util.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "package_name" ], "start_line": 203, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "package_config", "long_name": "package_config( primary , dependencies = [ ] )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 53, "parameters": [ "primary", "dependencies" ], "start_line": 215, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 57, "parameters": [ "name" ], "start_line": 234, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 61, "parameters": [ "config_list" ], "start_line": 244, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "fortran_library_item", "long_name": "fortran_library_item( lib_name , sources , ** attrs )", "filename": "misc_util.py", "nloc": 14, "complexity": 3, "token_count": 67, "parameters": [ "lib_name", "sources", "attrs" ], "start_line": 253, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "methods_before": [ { "name": "update_version", "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", "filename": "misc_util.py", "nloc": 65, "complexity": 12, "token_count": 351, "parameters": [ "release_level", "path", "major", "overwrite_version_py" ], "start_line": 3, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 }, { "name": "get_version", "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", "filename": "misc_util.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "release_level", "path", "major" ], "start_line": 111, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_cvs_revision", "long_name": "get_cvs_revision( path )", "filename": "misc_util.py", "nloc": 21, "complexity": 10, "token_count": 190, "parameters": [ "path" ], "start_line": 127, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_path", "long_name": "get_path( mod_name )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 80, "parameters": [ "mod_name" ], "start_line": 156, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 174, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "add_grandparent_to_path", "long_name": "add_grandparent_to_path( mod_name )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "mod_name" ], "start_line": 179, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 184, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "append_package_dir_to_path", "long_name": "append_package_dir_to_path( package_name )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 64, "parameters": [ "package_name" ], "start_line": 187, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "get_package_config", "long_name": "get_package_config( package_name )", "filename": "misc_util.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "package_name" ], "start_line": 203, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "package_config", "long_name": "package_config( primary , dependencies = [ ] )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 53, "parameters": [ "primary", "dependencies" ], "start_line": 215, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [], "start_line": 234, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 61, "parameters": [ "config_list" ], "start_line": 240, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "fortran_library_item", "long_name": "fortran_library_item( lib_name , sources , ** attrs )", "filename": "misc_util.py", "nloc": 14, "complexity": 3, "token_count": 67, "parameters": [ "lib_name", "sources", "attrs" ], "start_line": 249, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 61, "parameters": [ "config_list" ], "start_line": 244, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 57, "parameters": [ "name" ], "start_line": 234, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 34, "parameters": [], "start_line": 234, "end_line": 238, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 166, "complexity": 47, "token_count": 1102, "diff_parsed": { "added": [ "def default_config_dict(name = None):", " if name is not None:", " # Useful for local builds", " d['name'] = name", " d['version'] = update_version()", " result = default_config_dict()" ], "deleted": [ "def default_config_dict():", " result = default_config_dict()" ] } } ] }, { "hash": "c81f4e82b11f0d93725f014bba0b2643dc7375e7", "msg": "Made locally buildable", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-02-17T11:00:18+00:00", "author_timezone": 0, "committer_date": "2002-02-17T11:00:18+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "d17624c1b932f64ebae0c01f8ef715e97b0a1bf2" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/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/setup_weave.py", "new_path": "weave/setup_weave.py", "filename": "setup_weave.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,3 +1,5 @@\n+#!/usr/bin/env python\n+\n import os\n from glob import glob\n from scipy_distutils.misc_util import get_path, default_config_dict\n@@ -8,7 +10,7 @@ def configuration(parent_package=''):\n parent_package += '.'\n local_path = get_path(__name__)\n \n- config = default_config_dict()\n+ config = default_config_dict('weave')\n config['packages'].append(parent_package+'weave')\n config['packages'].append(parent_package+'weave.tests') \n config['package_dir']['weave'] = local_path\n@@ -53,3 +55,7 @@ def configuration(parent_package=''):\n config['data_files'].extend( [(install_path,example_files)])\n \n return config\n+\n+if __name__ == '__main__': \n+ from scipy_distutils.core import setup\n+ setup(**configuration())\n", "added_lines": 7, "deleted_lines": 1, "source_code": "#!/usr/bin/env python\n\nimport os\nfrom glob import glob\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('weave')\n config['packages'].append(parent_package+'weave')\n config['packages'].append(parent_package+'weave.tests') \n config['package_dir']['weave'] = local_path\n test_path = os.path.join(local_path,'tests')\n config['package_dir']['weave.tests'] = test_path\n \n scxx_files = glob(os.path.join(local_path,'scxx','*.h'))\n install_path = os.path.join(parent_path,'weave','scxx')\n config['data_files'].extend( [(install_path,scxx_files)])\n\n cxx_files = glob(os.path.join(local_path,'CXX','*.*'))\n install_path = os.path.join(parent_path,'weave','CXX')\n config['data_files'].extend( [(install_path,cxx_files)])\n \n blitz_files = glob(os.path.join(local_path,'blitz-20001213','blitz','*.*'))\n install_path = os.path.join(parent_path,'weave','blitz-20001213',\n 'blitz')\n config['data_files'].extend( [(install_path,blitz_files)])\n \n array_files = glob(os.path.join(local_path,'blitz-20001213','blitz',\n 'array','*.*'))\n install_path = os.path.join(parent_path,'weave','blitz-20001213',\n 'blitz','array')\n config['data_files'].extend( [(install_path,array_files)])\n \n meta_files = glob(os.path.join(local_path,'blitz-20001213','blitz',\n 'meta','*.*'))\n install_path = os.path.join(parent_path,'weave','blitz-20001213',\n 'blitz','meta')\n config['data_files'].extend( [(install_path,meta_files)])\n\n swig_files = glob(os.path.join(local_path,'swig','*.c'))\n install_path = os.path.join(parent_path,'weave','swig')\n config['data_files'].extend( [(install_path,swig_files)])\n\n doc_files = glob(os.path.join(local_path,'doc','*.html'))\n install_path = os.path.join(parent_path,'weave','doc')\n config['data_files'].extend( [(install_path,doc_files)])\n\n example_files = glob(os.path.join(local_path,'examples','*.py'))\n install_path = os.path.join(parent_path,'weave','examples')\n config['data_files'].extend( [(install_path,example_files)])\n \n return config\n\nif __name__ == '__main__': \n from scipy_distutils.core import setup\n setup(**configuration())\n", "source_code_before": "import os\nfrom glob import glob\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 config['packages'].append(parent_package+'weave')\n config['packages'].append(parent_package+'weave.tests') \n config['package_dir']['weave'] = local_path\n test_path = os.path.join(local_path,'tests')\n config['package_dir']['weave.tests'] = test_path\n \n scxx_files = glob(os.path.join(local_path,'scxx','*.h'))\n install_path = os.path.join(parent_path,'weave','scxx')\n config['data_files'].extend( [(install_path,scxx_files)])\n\n cxx_files = glob(os.path.join(local_path,'CXX','*.*'))\n install_path = os.path.join(parent_path,'weave','CXX')\n config['data_files'].extend( [(install_path,cxx_files)])\n \n blitz_files = glob(os.path.join(local_path,'blitz-20001213','blitz','*.*'))\n install_path = os.path.join(parent_path,'weave','blitz-20001213',\n 'blitz')\n config['data_files'].extend( [(install_path,blitz_files)])\n \n array_files = glob(os.path.join(local_path,'blitz-20001213','blitz',\n 'array','*.*'))\n install_path = os.path.join(parent_path,'weave','blitz-20001213',\n 'blitz','array')\n config['data_files'].extend( [(install_path,array_files)])\n \n meta_files = glob(os.path.join(local_path,'blitz-20001213','blitz',\n 'meta','*.*'))\n install_path = os.path.join(parent_path,'weave','blitz-20001213',\n 'blitz','meta')\n config['data_files'].extend( [(install_path,meta_files)])\n\n swig_files = glob(os.path.join(local_path,'swig','*.c'))\n install_path = os.path.join(parent_path,'weave','swig')\n config['data_files'].extend( [(install_path,swig_files)])\n\n doc_files = glob(os.path.join(local_path,'doc','*.html'))\n install_path = os.path.join(parent_path,'weave','doc')\n config['data_files'].extend( [(install_path,doc_files)])\n\n example_files = glob(os.path.join(local_path,'examples','*.py'))\n install_path = os.path.join(parent_path,'weave','examples')\n config['data_files'].extend( [(install_path,example_files)])\n \n return config\n", "methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' )", "filename": "setup_weave.py", "nloc": 41, "complexity": 2, "token_count": 470, "parameters": [ "parent_package" ], "start_line": 7, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "top_nesting_level": 0 } ], "methods_before": [ { "name": "configuration", "long_name": "configuration( parent_package = '' )", "filename": "setup_weave.py", "nloc": 41, "complexity": 2, "token_count": 469, "parameters": [ "parent_package" ], "start_line": 5, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' )", "filename": "setup_weave.py", "nloc": 41, "complexity": 2, "token_count": 470, "parameters": [ "parent_package" ], "start_line": 7, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "top_nesting_level": 0 } ], "nloc": 47, "complexity": 2, "token_count": 503, "diff_parsed": { "added": [ "#!/usr/bin/env python", "", " config = default_config_dict('weave')", "", "if __name__ == '__main__':", " from scipy_distutils.core import setup", " setup(**configuration())" ], "deleted": [ " config = default_config_dict()" ] } } ] }, { "hash": "5d22e0e816d103462c95f31e92b5a13481937795", "msg": "Added opt. parent_name argument to default_config_dict", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-02-17T12:24:36+00:00", "author_timezone": 0, "committer_date": "2002-02-17T12:24:36+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "c81f4e82b11f0d93725f014bba0b2643dc7375e7" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 9, "insertions": 32, "lines": 41, "files": 3, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/__version__.py", "new_path": "scipy_distutils/__version__.py", "filename": "__version__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,4 +1,4 @@\n # This file is automatically updated with update_version\n # function from scipy_distutils.misc_util.py\n-version = '0.6.23-alpha-106'\n-version_info = (0, 6, 23, 'alpha', 106)\n+version = '0.6.23-alpha-109'\n+version_info = (0, 6, 23, 'alpha', 109)\n", "added_lines": 2, "deleted_lines": 2, "source_code": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-109'\nversion_info = (0, 6, 23, 'alpha', 109)\n", "source_code_before": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-106'\nversion_info = (0, 6, 23, 'alpha', 106)\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 2, "complexity": 0, "token_count": 16, "diff_parsed": { "added": [ "version = '0.6.23-alpha-109'", "version_info = (0, 6, 23, 'alpha', 109)" ], "deleted": [ "version = '0.6.23-alpha-106'", "version_info = (0, 6, 23, 'alpha', 106)" ] } }, { "old_path": "scipy_distutils/command/sdist.py", "new_path": "scipy_distutils/command/sdist.py", "filename": "sdist.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -29,7 +29,7 @@ def make_release_tree (self, base_dir, files):\n # Create all the directories under 'base_dir' necessary to\n # put 'files' there; the 'mkpath()' is just so we don't die\n # if the manifest happens to be empty.\n-\n+ \n dest_files = remove_common_base(files)\n self.mkpath(base_dir)\n dir_util.create_tree(base_dir, dest_files,\n@@ -90,7 +90,6 @@ def make_distribution (self):\n # done elsewhere.\n base_dir = self.distribution.get_fullname()\n base_name = os.path.join(self.dist_dir, base_dir)\n-\n files = map(os.path.abspath, self.filelist.files)\n self.make_release_tree(base_dir, files)\n archive_files = [] # remember names of files we create\n", "added_lines": 1, "deleted_lines": 2, "source_code": "from distutils.command.sdist import *\nfrom distutils.command.sdist import sdist as old_sdist\n\nimport sys, os\nmod = __import__(__name__)\nsys.path.append(os.path.dirname(mod.__file__))\nimport line_endings\nsys.path = sys.path[:-1]\n\nclass sdist(old_sdist):\n def add_defaults (self):\n old_sdist.add_defaults(self)\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n self.filelist.extend(build_flib.get_source_files())\n\n if self.distribution.has_data_files():\n self.filelist.extend(self.distribution.get_data_files())\n\n def make_release_tree (self, base_dir, files):\n \"\"\"Create the directory tree that will become the source\n distribution archive. All directories implied by the filenames in\n 'files' are created under 'base_dir', and then we hard link or copy\n (if hard linking is unavailable) those files into place.\n Essentially, this duplicates the developer's source tree, but in a\n directory named after the distribution, containing only the files\n to be distributed.\n \"\"\"\n # Create all the directories under 'base_dir' necessary to\n # put 'files' there; the 'mkpath()' is just so we don't die\n # if the manifest happens to be empty.\n \n dest_files = remove_common_base(files)\n self.mkpath(base_dir)\n dir_util.create_tree(base_dir, dest_files,\n verbose=self.verbose, dry_run=self.dry_run)\n\n # And walk over the list of files, either making a hard link (if\n # os.link exists) to each one that doesn't already exist in its\n # corresponding location under 'base_dir', or copying each file\n # that's out-of-date in 'base_dir'. (Usually, all files will be\n # out-of-date, because by default we blow away 'base_dir' when\n # we're done making the distribution archives.)\n \n if hasattr(os, 'link'): # can make hard links on this system\n link = 'hard'\n msg = \"making hard links in %s...\" % base_dir\n else: # nope, have to copy\n link = None\n msg = \"copying files to %s...\" % base_dir\n\n if not files:\n self.warn(\"no files to distribute -- empty manifest?\")\n else:\n self.announce(msg)\n \n dest_files = [os.path.join(base_dir,file) for file in dest_files]\n file_pairs = zip(files,dest_files) \n for file,dest in file_pairs:\n if not os.path.isfile(file):\n self.warn(\"'%s' not a regular file -- skipping\" % file)\n else:\n #ej: here is the only change -- made to handle\n # absolute paths to files as well as relative\n #par,file_name = os.path.split(file)\n #dest = os.path.join(base_dir, file_name)\n # end of changes\n \n # old code\n #dest = os.path.join(base_dir, file)\n #end old code\n self.copy_file(file, dest, link=link)\n\n self.distribution.metadata.write_pkg_info(base_dir)\n #raise ValueError\n # make_release_tree ()\n\n def make_distribution (self):\n \"\"\" Overridden to force a build of zip files to have Windows line \n endings and tar balls to have Unix line endings.\n \n Create the source distribution(s). First, we create the release\n tree with 'make_release_tree()'; then, we create all required\n archive files (according to 'self.formats') from the release tree.\n Finally, we clean up by blowing away the release tree (unless\n 'self.keep_temp' is true). The list of archive files created is\n stored so it can be retrieved later by 'get_archive_files()'.\n \"\"\"\n # Don't warn about missing meta-data here -- should be (and is!)\n # done elsewhere.\n base_dir = self.distribution.get_fullname()\n base_name = os.path.join(self.dist_dir, base_dir)\n files = map(os.path.abspath, self.filelist.files)\n self.make_release_tree(base_dir, files)\n archive_files = [] # remember names of files we create\n for fmt in self.formats: \n self.convert_line_endings(base_dir,fmt)\n file = self.make_archive(base_name, fmt, base_dir=base_dir)\n archive_files.append(file)\n \n self.archive_files = archive_files\n\n if not self.keep_temp:\n dir_util.remove_tree(base_dir, self.verbose, self.dry_run)\n\n def convert_line_endings(self,base_dir,fmt):\n \"\"\" Convert all text files in a tree to have correct line endings.\n \n gztar --> \\n (Unix style)\n zip --> \\r\\n (Windows style)\n \"\"\"\n if fmt == 'gztar':\n line_endings.dos2unix_dir(base_dir)\n elif fmt == 'zip':\n line_endings.unix2dos_dir(base_dir)\n \ndef remove_common_base(files):\n \"\"\" Remove the greatest common base directory from all the\n absolute file paths in the list of files. files in the\n list without a parent directory are not affected.\n \"\"\"\n rel_files = filter(lambda x: not os.path.dirname(x),files)\n abs_files = filter(os.path.dirname,files)\n base = find_common_base(abs_files)\n # will leave files with local path unaffected\n # and maintains original file order\n results = [string.replace(file,base,'') for file in files]\n return results\n\ndef find_common_base(files):\n \"\"\" Find the \"greatest common base directory\" of a list of files\n \"\"\"\n if not files:\n return ''\n result = ''\n d,f = os.path.split(files[0])\n keep_looking = 1 \n while(keep_looking and d):\n keep_looking = 0\n for file in files:\n if string.find('start'+file,'start'+d) == -1:\n keep_looking = 1\n break\n if keep_looking:\n d,f = os.path.split(d)\n else:\n result = d\n \n if d: \n d = os.path.join(d,'')\n return d \n", "source_code_before": "from distutils.command.sdist import *\nfrom distutils.command.sdist import sdist as old_sdist\n\nimport sys, os\nmod = __import__(__name__)\nsys.path.append(os.path.dirname(mod.__file__))\nimport line_endings\nsys.path = sys.path[:-1]\n\nclass sdist(old_sdist):\n def add_defaults (self):\n old_sdist.add_defaults(self)\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n self.filelist.extend(build_flib.get_source_files())\n\n if self.distribution.has_data_files():\n self.filelist.extend(self.distribution.get_data_files())\n\n def make_release_tree (self, base_dir, files):\n \"\"\"Create the directory tree that will become the source\n distribution archive. All directories implied by the filenames in\n 'files' are created under 'base_dir', and then we hard link or copy\n (if hard linking is unavailable) those files into place.\n Essentially, this duplicates the developer's source tree, but in a\n directory named after the distribution, containing only the files\n to be distributed.\n \"\"\"\n # Create all the directories under 'base_dir' necessary to\n # put 'files' there; the 'mkpath()' is just so we don't die\n # if the manifest happens to be empty.\n\n dest_files = remove_common_base(files)\n self.mkpath(base_dir)\n dir_util.create_tree(base_dir, dest_files,\n verbose=self.verbose, dry_run=self.dry_run)\n\n # And walk over the list of files, either making a hard link (if\n # os.link exists) to each one that doesn't already exist in its\n # corresponding location under 'base_dir', or copying each file\n # that's out-of-date in 'base_dir'. (Usually, all files will be\n # out-of-date, because by default we blow away 'base_dir' when\n # we're done making the distribution archives.)\n \n if hasattr(os, 'link'): # can make hard links on this system\n link = 'hard'\n msg = \"making hard links in %s...\" % base_dir\n else: # nope, have to copy\n link = None\n msg = \"copying files to %s...\" % base_dir\n\n if not files:\n self.warn(\"no files to distribute -- empty manifest?\")\n else:\n self.announce(msg)\n \n dest_files = [os.path.join(base_dir,file) for file in dest_files]\n file_pairs = zip(files,dest_files) \n for file,dest in file_pairs:\n if not os.path.isfile(file):\n self.warn(\"'%s' not a regular file -- skipping\" % file)\n else:\n #ej: here is the only change -- made to handle\n # absolute paths to files as well as relative\n #par,file_name = os.path.split(file)\n #dest = os.path.join(base_dir, file_name)\n # end of changes\n \n # old code\n #dest = os.path.join(base_dir, file)\n #end old code\n self.copy_file(file, dest, link=link)\n\n self.distribution.metadata.write_pkg_info(base_dir)\n #raise ValueError\n # make_release_tree ()\n\n def make_distribution (self):\n \"\"\" Overridden to force a build of zip files to have Windows line \n endings and tar balls to have Unix line endings.\n \n Create the source distribution(s). First, we create the release\n tree with 'make_release_tree()'; then, we create all required\n archive files (according to 'self.formats') from the release tree.\n Finally, we clean up by blowing away the release tree (unless\n 'self.keep_temp' is true). The list of archive files created is\n stored so it can be retrieved later by 'get_archive_files()'.\n \"\"\"\n # Don't warn about missing meta-data here -- should be (and is!)\n # done elsewhere.\n base_dir = self.distribution.get_fullname()\n base_name = os.path.join(self.dist_dir, base_dir)\n\n files = map(os.path.abspath, self.filelist.files)\n self.make_release_tree(base_dir, files)\n archive_files = [] # remember names of files we create\n for fmt in self.formats: \n self.convert_line_endings(base_dir,fmt)\n file = self.make_archive(base_name, fmt, base_dir=base_dir)\n archive_files.append(file)\n \n self.archive_files = archive_files\n\n if not self.keep_temp:\n dir_util.remove_tree(base_dir, self.verbose, self.dry_run)\n\n def convert_line_endings(self,base_dir,fmt):\n \"\"\" Convert all text files in a tree to have correct line endings.\n \n gztar --> \\n (Unix style)\n zip --> \\r\\n (Windows style)\n \"\"\"\n if fmt == 'gztar':\n line_endings.dos2unix_dir(base_dir)\n elif fmt == 'zip':\n line_endings.unix2dos_dir(base_dir)\n \ndef remove_common_base(files):\n \"\"\" Remove the greatest common base directory from all the\n absolute file paths in the list of files. files in the\n list without a parent directory are not affected.\n \"\"\"\n rel_files = filter(lambda x: not os.path.dirname(x),files)\n abs_files = filter(os.path.dirname,files)\n base = find_common_base(abs_files)\n # will leave files with local path unaffected\n # and maintains original file order\n results = [string.replace(file,base,'') for file in files]\n return results\n\ndef find_common_base(files):\n \"\"\" Find the \"greatest common base directory\" of a list of files\n \"\"\"\n if not files:\n return ''\n result = ''\n d,f = os.path.split(files[0])\n keep_looking = 1 \n while(keep_looking and d):\n keep_looking = 0\n for file in files:\n if string.find('start'+file,'start'+d) == -1:\n keep_looking = 1\n break\n if keep_looking:\n d,f = os.path.split(d)\n else:\n result = d\n \n if d: \n d = os.path.join(d,'')\n return d \n", "methods": [ { "name": "add_defaults", "long_name": "add_defaults( self )", "filename": "sdist.py", "nloc": 7, "complexity": 3, "token_count": 63, "parameters": [ "self" ], "start_line": 11, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "make_release_tree", "long_name": "make_release_tree( self , base_dir , files )", "filename": "sdist.py", "nloc": 23, "complexity": 6, "token_count": 162, "parameters": [ "self", "base_dir", "files" ], "start_line": 20, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 1 }, { "name": "make_distribution", "long_name": "make_distribution( self )", "filename": "sdist.py", "nloc": 13, "complexity": 3, "token_count": 117, "parameters": [ "self" ], "start_line": 78, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "convert_line_endings", "long_name": "convert_line_endings( self , base_dir , fmt )", "filename": "sdist.py", "nloc": 5, "complexity": 3, "token_count": 32, "parameters": [ "self", "base_dir", "fmt" ], "start_line": 106, "end_line": 115, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "remove_common_base", "long_name": "remove_common_base( files )", "filename": "sdist.py", "nloc": 6, "complexity": 2, "token_count": 63, "parameters": [ "files" ], "start_line": 117, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "find_common_base", "long_name": "find_common_base( files )", "filename": "sdist.py", "nloc": 19, "complexity": 8, "token_count": 106, "parameters": [ "files" ], "start_line": 130, "end_line": 151, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "methods_before": [ { "name": "add_defaults", "long_name": "add_defaults( self )", "filename": "sdist.py", "nloc": 7, "complexity": 3, "token_count": 63, "parameters": [ "self" ], "start_line": 11, "end_line": 18, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "make_release_tree", "long_name": "make_release_tree( self , base_dir , files )", "filename": "sdist.py", "nloc": 23, "complexity": 6, "token_count": 162, "parameters": [ "self", "base_dir", "files" ], "start_line": 20, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 1 }, { "name": "make_distribution", "long_name": "make_distribution( self )", "filename": "sdist.py", "nloc": 13, "complexity": 3, "token_count": 117, "parameters": [ "self" ], "start_line": 78, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 1 }, { "name": "convert_line_endings", "long_name": "convert_line_endings( self , base_dir , fmt )", "filename": "sdist.py", "nloc": 5, "complexity": 3, "token_count": 32, "parameters": [ "self", "base_dir", "fmt" ], "start_line": 107, "end_line": 116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "remove_common_base", "long_name": "remove_common_base( files )", "filename": "sdist.py", "nloc": 6, "complexity": 2, "token_count": 63, "parameters": [ "files" ], "start_line": 118, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "find_common_base", "long_name": "find_common_base( files )", "filename": "sdist.py", "nloc": 19, "complexity": 8, "token_count": 106, "parameters": [ "files" ], "start_line": 131, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "make_distribution", "long_name": "make_distribution( self )", "filename": "sdist.py", "nloc": 13, "complexity": 3, "token_count": 117, "parameters": [ "self" ], "start_line": 78, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 1 }, { "name": "make_release_tree", "long_name": "make_release_tree( self , base_dir , files )", "filename": "sdist.py", "nloc": 23, "complexity": 6, "token_count": 162, "parameters": [ "self", "base_dir", "files" ], "start_line": 20, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 55, "top_nesting_level": 1 } ], "nloc": 81, "complexity": 25, "token_count": 614, "diff_parsed": { "added": [ "" ], "deleted": [ "", "" ] } }, { "old_path": "scipy_distutils/misc_util.py", "new_path": "scipy_distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -231,14 +231,38 @@ def package_config(primary,dependencies=[]):\n 'headers']\n dict_keys = ['package_dir'] \n \n-def default_config_dict(name = None):\n+def default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n- if name is not None:\n- # Useful for local builds\n- d['name'] = name\n- d['version'] = update_version() \n+\n+ if name and parent_name:\n+ full_name = '%s.%s' % (parent_name,name)\n+ else:\n+ if name:\n+ # Useful for local builds\n+ d['version'] = update_version()\n+ full_name = name\n+\n+ if full_name:\n+ # XXX: The following assumes that default_config_dict is called\n+ # only from setup_.configuration().\n+ frame = sys._getframe(1)\n+ caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n+ local_path = get_path(caller_name)\n+ d['packages'].append(full_name)\n+ d['package_dir'][full_name] = local_path\n+ d['name'] = full_name\n+ if not parent_name:\n+ # Include scipy_distutils to local distributions\n+ for p in ['.','..']:\n+ dir_name = os.path.abspath(os.path.join(local_path,\n+ p,'scipy_distutils'))\n+ if os.path.exists(dir_name):\n+ d['packages'].append('scipy_distutils')\n+ d['packages'].append('scipy_distutils.command')\n+ d['package_dir']['scipy_distutils'] = dir_name\n+ break\n return d\n \n def merge_config_dicts(config_list):\n", "added_lines": 29, "deleted_lines": 5, "source_code": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n if name and parent_name:\n full_name = '%s.%s' % (parent_name,name)\n else:\n if name:\n # Useful for local builds\n d['version'] = update_version()\n full_name = name\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = sys._getframe(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", "source_code_before": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n if name is not None:\n # Useful for local builds\n d['name'] = name\n d['version'] = update_version() \n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", "methods": [ { "name": "update_version", "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", "filename": "misc_util.py", "nloc": 65, "complexity": 12, "token_count": 351, "parameters": [ "release_level", "path", "major", "overwrite_version_py" ], "start_line": 3, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 }, { "name": "get_version", "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", "filename": "misc_util.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "release_level", "path", "major" ], "start_line": 111, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_cvs_revision", "long_name": "get_cvs_revision( path )", "filename": "misc_util.py", "nloc": 21, "complexity": 10, "token_count": 190, "parameters": [ "path" ], "start_line": 127, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_path", "long_name": "get_path( mod_name )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 80, "parameters": [ "mod_name" ], "start_line": 156, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 174, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "add_grandparent_to_path", "long_name": "add_grandparent_to_path( mod_name )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "mod_name" ], "start_line": 179, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 184, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "append_package_dir_to_path", "long_name": "append_package_dir_to_path( package_name )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 64, "parameters": [ "package_name" ], "start_line": 187, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "get_package_config", "long_name": "get_package_config( package_name )", "filename": "misc_util.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "package_name" ], "start_line": 203, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "package_config", "long_name": "package_config( primary , dependencies = [ ] )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 53, "parameters": [ "primary", "dependencies" ], "start_line": 215, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None )", "filename": "misc_util.py", "nloc": 27, "complexity": 10, "token_count": 198, "parameters": [ "name", "parent_name" ], "start_line": 234, "end_line": 266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 61, "parameters": [ "config_list" ], "start_line": 268, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "fortran_library_item", "long_name": "fortran_library_item( lib_name , sources , ** attrs )", "filename": "misc_util.py", "nloc": 14, "complexity": 3, "token_count": 67, "parameters": [ "lib_name", "sources", "attrs" ], "start_line": 277, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "methods_before": [ { "name": "update_version", "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", "filename": "misc_util.py", "nloc": 65, "complexity": 12, "token_count": 351, "parameters": [ "release_level", "path", "major", "overwrite_version_py" ], "start_line": 3, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 }, { "name": "get_version", "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", "filename": "misc_util.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "release_level", "path", "major" ], "start_line": 111, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_cvs_revision", "long_name": "get_cvs_revision( path )", "filename": "misc_util.py", "nloc": 21, "complexity": 10, "token_count": 190, "parameters": [ "path" ], "start_line": 127, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_path", "long_name": "get_path( mod_name )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 80, "parameters": [ "mod_name" ], "start_line": 156, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 174, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "add_grandparent_to_path", "long_name": "add_grandparent_to_path( mod_name )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "mod_name" ], "start_line": 179, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 184, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "append_package_dir_to_path", "long_name": "append_package_dir_to_path( package_name )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 64, "parameters": [ "package_name" ], "start_line": 187, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "get_package_config", "long_name": "get_package_config( package_name )", "filename": "misc_util.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "package_name" ], "start_line": 203, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "package_config", "long_name": "package_config( primary , dependencies = [ ] )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 53, "parameters": [ "primary", "dependencies" ], "start_line": 215, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 57, "parameters": [ "name" ], "start_line": 234, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 61, "parameters": [ "config_list" ], "start_line": 244, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "fortran_library_item", "long_name": "fortran_library_item( lib_name , sources , ** attrs )", "filename": "misc_util.py", "nloc": 14, "complexity": 3, "token_count": 67, "parameters": [ "lib_name", "sources", "attrs" ], "start_line": 253, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "default_config_dict", "long_name": "default_config_dict( name = None )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 57, "parameters": [ "name" ], "start_line": 234, "end_line": 242, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None )", "filename": "misc_util.py", "nloc": 27, "complexity": 10, "token_count": 198, "parameters": [ "name", "parent_name" ], "start_line": 234, "end_line": 266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 } ], "nloc": 185, "complexity": 53, "token_count": 1243, "diff_parsed": { "added": [ "def default_config_dict(name = None, parent_name = None):", "", " if name and parent_name:", " full_name = '%s.%s' % (parent_name,name)", " else:", " if name:", " # Useful for local builds", " d['version'] = update_version()", " full_name = name", "", " if full_name:", " # XXX: The following assumes that default_config_dict is called", " # only from setup_.configuration().", " frame = sys._getframe(1)", " caller_name = eval('__name__',frame.f_globals,frame.f_locals)", " local_path = get_path(caller_name)", " d['packages'].append(full_name)", " d['package_dir'][full_name] = local_path", " d['name'] = full_name", " if not parent_name:", " # Include scipy_distutils to local distributions", " for p in ['.','..']:", " dir_name = os.path.abspath(os.path.join(local_path,", " p,'scipy_distutils'))", " if os.path.exists(dir_name):", " d['packages'].append('scipy_distutils')", " d['packages'].append('scipy_distutils.command')", " d['package_dir']['scipy_distutils'] = dir_name", " break" ], "deleted": [ "def default_config_dict(name = None):", " if name is not None:", " # Useful for local builds", " d['name'] = name", " d['version'] = update_version()" ] } } ] }, { "hash": "66496b3b771ab9079fa842b4cae86022fe61ef6b", "msg": "Fixed trivial bug that prevented setup.py from running at all.", "author": { "name": "prabhu", "email": "prabhu@localhost" }, "committer": { "name": "prabhu", "email": "prabhu@localhost" }, "author_date": "2002-02-17T18:07:21+00:00", "author_timezone": 0, "committer_date": "2002-02-17T18:07:21+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "5d22e0e816d103462c95f31e92b5a13481937795" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 0, "insertions": 1, "lines": 1, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/misc_util.py", "new_path": "scipy_distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -235,6 +235,7 @@ def default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n+ full_name = \"\"\n \n if name and parent_name:\n full_name = '%s.%s' % (parent_name,name)\n", "added_lines": 1, "deleted_lines": 0, "source_code": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n full_name = \"\"\n\n if name and parent_name:\n full_name = '%s.%s' % (parent_name,name)\n else:\n if name:\n # Useful for local builds\n d['version'] = update_version()\n full_name = name\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = sys._getframe(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", "source_code_before": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n if name and parent_name:\n full_name = '%s.%s' % (parent_name,name)\n else:\n if name:\n # Useful for local builds\n d['version'] = update_version()\n full_name = name\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = sys._getframe(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", "methods": [ { "name": "update_version", "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", "filename": "misc_util.py", "nloc": 65, "complexity": 12, "token_count": 351, "parameters": [ "release_level", "path", "major", "overwrite_version_py" ], "start_line": 3, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 }, { "name": "get_version", "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", "filename": "misc_util.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "release_level", "path", "major" ], "start_line": 111, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_cvs_revision", "long_name": "get_cvs_revision( path )", "filename": "misc_util.py", "nloc": 21, "complexity": 10, "token_count": 190, "parameters": [ "path" ], "start_line": 127, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_path", "long_name": "get_path( mod_name )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 80, "parameters": [ "mod_name" ], "start_line": 156, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 174, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "add_grandparent_to_path", "long_name": "add_grandparent_to_path( mod_name )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "mod_name" ], "start_line": 179, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 184, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "append_package_dir_to_path", "long_name": "append_package_dir_to_path( package_name )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 64, "parameters": [ "package_name" ], "start_line": 187, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "get_package_config", "long_name": "get_package_config( package_name )", "filename": "misc_util.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "package_name" ], "start_line": 203, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "package_config", "long_name": "package_config( primary , dependencies = [ ] )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 53, "parameters": [ "primary", "dependencies" ], "start_line": 215, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None )", "filename": "misc_util.py", "nloc": 28, "complexity": 10, "token_count": 201, "parameters": [ "name", "parent_name" ], "start_line": 234, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 61, "parameters": [ "config_list" ], "start_line": 269, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "fortran_library_item", "long_name": "fortran_library_item( lib_name , sources , ** attrs )", "filename": "misc_util.py", "nloc": 14, "complexity": 3, "token_count": 67, "parameters": [ "lib_name", "sources", "attrs" ], "start_line": 278, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "methods_before": [ { "name": "update_version", "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", "filename": "misc_util.py", "nloc": 65, "complexity": 12, "token_count": 351, "parameters": [ "release_level", "path", "major", "overwrite_version_py" ], "start_line": 3, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 }, { "name": "get_version", "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", "filename": "misc_util.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "release_level", "path", "major" ], "start_line": 111, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_cvs_revision", "long_name": "get_cvs_revision( path )", "filename": "misc_util.py", "nloc": 21, "complexity": 10, "token_count": 190, "parameters": [ "path" ], "start_line": 127, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_path", "long_name": "get_path( mod_name )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 80, "parameters": [ "mod_name" ], "start_line": 156, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 174, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "add_grandparent_to_path", "long_name": "add_grandparent_to_path( mod_name )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "mod_name" ], "start_line": 179, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 184, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "append_package_dir_to_path", "long_name": "append_package_dir_to_path( package_name )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 64, "parameters": [ "package_name" ], "start_line": 187, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "get_package_config", "long_name": "get_package_config( package_name )", "filename": "misc_util.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "package_name" ], "start_line": 203, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "package_config", "long_name": "package_config( primary , dependencies = [ ] )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 53, "parameters": [ "primary", "dependencies" ], "start_line": 215, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None )", "filename": "misc_util.py", "nloc": 27, "complexity": 10, "token_count": 198, "parameters": [ "name", "parent_name" ], "start_line": 234, "end_line": 266, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 61, "parameters": [ "config_list" ], "start_line": 268, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "fortran_library_item", "long_name": "fortran_library_item( lib_name , sources , ** attrs )", "filename": "misc_util.py", "nloc": 14, "complexity": 3, "token_count": 67, "parameters": [ "lib_name", "sources", "attrs" ], "start_line": 277, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None )", "filename": "misc_util.py", "nloc": 28, "complexity": 10, "token_count": 201, "parameters": [ "name", "parent_name" ], "start_line": 234, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 } ], "nloc": 186, "complexity": 53, "token_count": 1246, "diff_parsed": { "added": [ " full_name = \"\"" ], "deleted": [] } } ] }, { "hash": "2dfed378bdc129e2f0d5fcc814b5a8a8b02dff0b", "msg": "CVS state is now sdist-build-import'able", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-02-17T18:59:25+00:00", "author_timezone": 0, "committer_date": "2002-02-17T18:59:25+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "66496b3b771ab9079fa842b4cae86022fe61ef6b" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 29, "insertions": 42, "lines": 71, "files": 6, "dmm_unit_size": 0.2857142857142857, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/__version__.py", "new_path": "scipy_distutils/__version__.py", "filename": "__version__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,4 +1,4 @@\n # This file is automatically updated with update_version\n # function from scipy_distutils.misc_util.py\n-version = '0.6.23-alpha-109'\n-version_info = (0, 6, 23, 'alpha', 109)\n+version = '0.6.23-alpha-111'\n+version_info = (0, 6, 23, 'alpha', 111)\n", "added_lines": 2, "deleted_lines": 2, "source_code": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-111'\nversion_info = (0, 6, 23, 'alpha', 111)\n", "source_code_before": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-109'\nversion_info = (0, 6, 23, 'alpha', 109)\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 2, "complexity": 0, "token_count": 16, "diff_parsed": { "added": [ "version = '0.6.23-alpha-111'", "version_info = (0, 6, 23, 'alpha', 111)" ], "deleted": [ "version = '0.6.23-alpha-109'", "version_info = (0, 6, 23, 'alpha', 109)" ] } }, { "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": "@@ -13,6 +13,11 @@\n class 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 ext_name = string.split(ext.name,'.')[-1]\n@@ -39,21 +44,33 @@ def build_extension(self, ext):\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-\n- ext.libraries.extend(build_flib.get_fcompiler_library_names())\n- ext.library_dirs.extend(build_flib.get_fcompiler_library_dirs())\n-\n- print ext.libraries\n \n ext.library_dirs.append(build_flib.build_flib)\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 if linker_so is not None:\n- self.compiler.linker_so = linker_so\n+ if linker_so is not save_linker_so:\n+ print 'replacing linker_so %s with %s' %(save_linker_so,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 = build_flib.get_fcompiler_library_dirs()\n+ #l = self.compiler.library_dirs + l\n+ self.compiler.library_dirs = l\n \n # end of fortran source support\n- return old_build_ext.build_extension(self,ext)\n+ res = old_build_ext.build_extension(self,ext)\n+\n+ if save_linker_so is not self.compiler.linker_so:\n+ print 'restoring linker_so',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", "added_lines": 24, "deleted_lines": 7, "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 *\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 ext_name = string.split(ext.name,'.')[-1]\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 print ext.name,ext_name,'needs fortran libraries',need_f_libs\n if need_f_libs:\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 if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.append(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 \n ext.library_dirs.append(build_flib.build_flib)\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 if linker_so is not None:\n if linker_so is not save_linker_so:\n print 'replacing linker_so %s with %s' %(save_linker_so,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 = build_flib.get_fcompiler_library_dirs()\n #l = self.compiler.library_dirs + l\n self.compiler.library_dirs = l\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 print 'restoring linker_so',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", "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 *\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 # support for building static fortran libraries\n need_f_libs = 0\n ext_name = string.split(ext.name,'.')[-1]\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 print ext.name,ext_name,'needs fortran libraries',need_f_libs\n if need_f_libs:\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 if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.append(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\n ext.libraries.extend(build_flib.get_fcompiler_library_names())\n ext.library_dirs.extend(build_flib.get_fcompiler_library_dirs())\n\n print ext.libraries\n \n ext.library_dirs.append(build_flib.build_flib)\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n linker_so = build_flib.fcompiler.get_linker_so()\n if linker_so is not None:\n self.compiler.linker_so = linker_so\n\n # end of fortran source support\n return old_build_ext.build_extension(self,ext)\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", "methods": [ { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 48, "complexity": 15, "token_count": 342, "parameters": [ "self", "ext" ], "start_line": 15, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "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": 75, "end_line": 84, "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": 36, "complexity": 13, "token_count": 269, "parameters": [ "self", "ext" ], "start_line": 15, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 42, "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": 58, "end_line": 67, "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": 48, "complexity": 15, "token_count": 342, "parameters": [ "self", "ext" ], "start_line": 15, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "top_nesting_level": 1 } ], "nloc": 64, "complexity": 17, "token_count": 443, "diff_parsed": { "added": [ " #XXX: anything else we need to save?", " save_linker_so = self.compiler.linker_so", " save_compiler_libs = self.compiler.libraries", " save_compiler_libs_dirs = self.compiler.library_dirs", "", "", " if linker_so is not save_linker_so:", " print 'replacing linker_so %s with %s' %(save_linker_so,linker_so)", " self.compiler.linker_so = linker_so", " l = build_flib.get_fcompiler_library_names()", " #l = self.compiler.libraries + l", " self.compiler.libraries = l", " l = build_flib.get_fcompiler_library_dirs()", " #l = self.compiler.library_dirs + l", " self.compiler.library_dirs = l", " res = old_build_ext.build_extension(self,ext)", "", " if save_linker_so is not self.compiler.linker_so:", " print 'restoring linker_so',save_linker_so", " self.compiler.linker_so = save_linker_so", " self.compiler.libraries = save_compiler_libs", " self.compiler.library_dirs = save_compiler_libs_dirs", "", " return res" ], "deleted": [ "", " ext.libraries.extend(build_flib.get_fcompiler_library_names())", " ext.library_dirs.extend(build_flib.get_fcompiler_library_dirs())", "", " print ext.libraries", " self.compiler.linker_so = linker_so", " return old_build_ext.build_extension(self,ext)" ] } }, { "old_path": "scipy_distutils/command/build_py.py", "new_path": "scipy_distutils/command/build_py.py", "filename": "build_py.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -8,6 +8,7 @@ def is_setup_script(file):\n # return (fnmatch(file,\"setup.py\") or fnmatch(file,\"setup_*.py\"))\n \n class build_py(old_build_py):\n+\n def find_package_modules (self, package, package_dir):\n # we filter all files that are setup.py or setup_xxx.py \n self.check_package(package, package_dir)\n@@ -23,4 +24,3 @@ def find_package_modules (self, package, package_dir):\n else:\n self.debug_print(\"excluding %s\" % setup_script)\n return modules\n-\n", "added_lines": 1, "deleted_lines": 1, "source_code": "from distutils.command.build_py import *\nfrom distutils.command.build_py import build_py as old_build_py\nfrom fnmatch import fnmatch\n\ndef is_setup_script(file):\n file = os.path.basename(file)\n return fnmatch(file,\"setup.py\")\n# return (fnmatch(file,\"setup.py\") or fnmatch(file,\"setup_*.py\"))\n \nclass build_py(old_build_py):\n\n def find_package_modules (self, package, package_dir):\n # we filter all files that are setup.py or setup_xxx.py \n self.check_package(package, package_dir)\n module_files = glob(os.path.join(package_dir, \"*.py\"))\n modules = []\n setup_script = os.path.abspath(self.distribution.script_name)\n\n for f in module_files:\n abs_f = os.path.abspath(f)\n if abs_f != setup_script and not is_setup_script(f):\n module = os.path.splitext(os.path.basename(f))[0]\n modules.append((package, module, f))\n else:\n self.debug_print(\"excluding %s\" % setup_script)\n return modules\n", "source_code_before": "from distutils.command.build_py import *\nfrom distutils.command.build_py import build_py as old_build_py\nfrom fnmatch import fnmatch\n\ndef is_setup_script(file):\n file = os.path.basename(file)\n return fnmatch(file,\"setup.py\")\n# return (fnmatch(file,\"setup.py\") or fnmatch(file,\"setup_*.py\"))\n \nclass build_py(old_build_py):\n def find_package_modules (self, package, package_dir):\n # we filter all files that are setup.py or setup_xxx.py \n self.check_package(package, package_dir)\n module_files = glob(os.path.join(package_dir, \"*.py\"))\n modules = []\n setup_script = os.path.abspath(self.distribution.script_name)\n\n for f in module_files:\n abs_f = os.path.abspath(f)\n if abs_f != setup_script and not is_setup_script(f):\n module = os.path.splitext(os.path.basename(f))[0]\n modules.append((package, module, f))\n else:\n self.debug_print(\"excluding %s\" % setup_script)\n return modules\n\n", "methods": [ { "name": "is_setup_script", "long_name": "is_setup_script( file )", "filename": "build_py.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "file" ], "start_line": 5, "end_line": 7, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "find_package_modules", "long_name": "find_package_modules( self , package , package_dir )", "filename": "build_py.py", "nloc": 13, "complexity": 4, "token_count": 120, "parameters": [ "self", "package", "package_dir" ], "start_line": 12, "end_line": 26, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 } ], "methods_before": [ { "name": "is_setup_script", "long_name": "is_setup_script( file )", "filename": "build_py.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "file" ], "start_line": 5, "end_line": 7, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "find_package_modules", "long_name": "find_package_modules( self , package , package_dir )", "filename": "build_py.py", "nloc": 13, "complexity": 4, "token_count": 120, "parameters": [ "self", "package", "package_dir" ], "start_line": 11, "end_line": 25, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 20, "complexity": 5, "token_count": 172, "diff_parsed": { "added": [ "" ], "deleted": [ "" ] } }, { "old_path": "scipy_distutils/command/run_f2py.py", "new_path": "scipy_distutils/command/run_f2py.py", "filename": "run_f2py.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -112,7 +112,7 @@ def f2py_sources (self, sources, ext):\n f.close()\n if ext.name == 'untitled':\n ext.name = base\n- if base != ext.name:\n+ if base != string.split(ext.name,'.')[-1]:\n # XXX: Should we do here more than just warn?\n self.warn('%s provides %s but this extension is %s' \\\n % (source,`base`,`ext.name`))\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\"\"\"distutils.command.run_f2py\n\nImplements the Distutils 'run_f2py' command.\n\"\"\"\n\n# created 2002/01/09, Pearu Peterson \n\n__revision__ = \"$Id$\"\n\nfrom distutils.dep_util import newer\nfrom scipy_distutils.core import Command\n\nimport re,os\n\nmodule_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',re.I).match\nuser_module_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?__user__[\\w_]*)',re.I).match\nfortran_ext_re = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\n\nclass run_f2py(Command):\n\n description = \"\\\"run_f2py\\\" runs f2py that builds Fortran wrapper sources\"\\\n \"(C and occasionally Fortran).\"\n\n user_options = [('build-dir=', 'b',\n \"directory to build fortran wrappers to\"),\n ('debug-capi', None,\n \"generate C/API extensions with debugging code\"),\n ('no-wrap-functions', None,\n \"do not generate wrappers for Fortran functions,etc.\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ]\n\n def initialize_options (self):\n self.build_dir = None\n self.debug_capi = None\n self.force = None\n self.no_wrap_functions = None\n self.f2py_options = []\n # initialize_options()\n\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_dir'),\n ('force', 'force'))\n\n self.f2py_options.extend(['--build-dir',self.build_dir])\n\n if self.debug_capi is not None:\n self.f2py_options.append('--debug-capi')\n if self.no_wrap_functions is not None:\n self.f2py_options.append('--no-wrap-functions')\n\n # finalize_options()\n\n def run (self):\n if self.distribution.has_ext_modules():\n # XXX: might need also\n # build_flib = self.get_finalized_command('build_flib')\n # ...\n # for getting extra f2py_options that are specific to\n # a given fortran compiler.\n for ext in self.distribution.ext_modules:\n ext.sources = self.f2py_sources(ext.sources,ext)\n self.fortran_sources_to_flib(ext)\n # run()\n\n def f2py_sources (self, sources, ext):\n\n \"\"\"Walk the list of source files in 'sources', looking for f2py\n interface (.pyf) files. Run f2py on all that are found, and\n return a modified 'sources' list with f2py source files replaced\n by the generated C (or C++) and Fortran files.\n If 'sources' contains not .pyf files, then create a temporary\n one from the Fortran files in 'sources'.\n \"\"\"\n import string\n import f2py2e\n # f2py generates the following files for an extension module\n # with a name :\n # module.c\n # -f2pywrappers.f [occasionally]\n # In addition, /src/fortranobject.{c,h} are needed\n # for building f2py generated extension modules.\n # It is assumed that one pyf file contains defintions for exactly\n # one extension module.\n\n target_dir = self.build_dir\n \n new_sources = []\n f2py_sources = []\n fortran_sources = []\n f2py_targets = {}\n f2py_fortran_targets = {}\n target_ext = 'module.c'\n fortran_target_ext = '-f2pywrappers.f'\n\n for source in sources:\n (base, source_ext) = os.path.splitext(source)\n (source_dir, base) = os.path.split(base)\n if source_ext == \".pyf\": # f2py interface file\n # get extension module name\n f = open(source)\n for line in f.xreadlines():\n m = module_name_re(line)\n if m:\n if user_module_name_re(line): # skip *__user__* names\n continue\n base = m.group('name')\n break\n f.close()\n if ext.name == 'untitled':\n ext.name = base\n if base != string.split(ext.name,'.')[-1]:\n # XXX: Should we do here more than just warn?\n self.warn('%s provides %s but this extension is %s' \\\n % (source,`base`,`ext.name`))\n target_file = os.path.join(target_dir,base+target_ext)\n fortran_target_file = os.path.join(target_dir,base+fortran_target_ext)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n f2py_fortran_targets[source] = fortran_target_file\n elif fortran_ext_re(source_ext):\n fortran_sources.append(source) \n else:\n new_sources.append(source)\n\n if not (f2py_sources or fortran_sources):\n return new_sources\n\n # make sure the target dir exists\n from distutils.dir_util import mkpath\n mkpath(target_dir)\n\n if not f2py_sources:\n # creating a temporary pyf file from fortran sources\n pyf_target = os.path.join(target_dir,ext.name+'.pyf')\n pyf_target_file = os.path.join(target_dir,ext.name+target_ext)\n pyf_fortran_target_file = os.path.join(target_dir,ext.name+fortran_target_ext)\n f2py_opts2 = ['-m',ext.name,'-h',pyf_target,'--overwrite-signature']\n for source in fortran_sources:\n if newer(source,pyf_target) or self.force:\n self.announce(\"f2py-ing a new %s\" % (pyf_target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_opts2,' '))\n f2py2e.run_main(fortran_sources + f2py_opts2)\n break\n f2py_sources.append(pyf_target)\n f2py_targets[pyf_target] = pyf_target_file\n f2py_fortran_targets[pyf_target] = pyf_fortran_target_file\n\n new_sources.extend(fortran_sources)\n\n if len(f2py_sources) > 1:\n self.warn('Only one .pyf file can be used per Extension but got %s.'\\\n % (len(f2py_sources)))\n\n # a bit of a hack, but I think it'll work. Just include one of\n # the fortranobject.c files that was copied into most \n d = os.path.dirname(f2py2e.__file__)\n new_sources.append(os.path.join(d,'src','fortranobject.c'))\n ext.include_dirs.append(os.path.join(d,'src'))\n\n f2py_options = ext.f2py_options + self.f2py_options\n\n for source in f2py_sources:\n target = f2py_targets[source]\n fortran_target = f2py_fortran_targets[source]\n if newer(source,target) or self.force:\n self.announce(\"f2py-ing %s to %s\" % (source, target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_options,' '))\n f2py2e.run_main(f2py_options + [source])\n new_sources.append(target)\n if os.path.exists(fortran_target):\n new_sources.append(fortran_target)\n\n return new_sources\n\n # f2py_sources ()\n\n def fortran_sources_to_flib(self, ext):\n \"\"\"\n Extract fortran files from ext.sources and append them to\n fortran_libraries item having the same name as ext.\n \"\"\"\n sources = []\n f_files = []\n\n for file in ext.sources:\n if fortran_ext_re(file):\n f_files.append(file)\n else:\n sources.append(file)\n if not f_files:\n return\n\n ext.sources = sources\n\n if self.distribution.fortran_libraries is None:\n self.distribution.fortran_libraries = []\n fortran_libraries = self.distribution.fortran_libraries\n\n name = ext.name\n flib = None\n for n,d in fortran_libraries:\n if n == name:\n flib = d\n break\n if flib is None:\n flib = {'sources':[]}\n fortran_libraries.append((name,flib))\n\n flib['sources'].extend(f_files)\n \n# class run_f2py\n", "source_code_before": "\"\"\"distutils.command.run_f2py\n\nImplements the Distutils 'run_f2py' command.\n\"\"\"\n\n# created 2002/01/09, Pearu Peterson \n\n__revision__ = \"$Id$\"\n\nfrom distutils.dep_util import newer\nfrom scipy_distutils.core import Command\n\nimport re,os\n\nmodule_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',re.I).match\nuser_module_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?__user__[\\w_]*)',re.I).match\nfortran_ext_re = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\n\nclass run_f2py(Command):\n\n description = \"\\\"run_f2py\\\" runs f2py that builds Fortran wrapper sources\"\\\n \"(C and occasionally Fortran).\"\n\n user_options = [('build-dir=', 'b',\n \"directory to build fortran wrappers to\"),\n ('debug-capi', None,\n \"generate C/API extensions with debugging code\"),\n ('no-wrap-functions', None,\n \"do not generate wrappers for Fortran functions,etc.\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ]\n\n def initialize_options (self):\n self.build_dir = None\n self.debug_capi = None\n self.force = None\n self.no_wrap_functions = None\n self.f2py_options = []\n # initialize_options()\n\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_dir'),\n ('force', 'force'))\n\n self.f2py_options.extend(['--build-dir',self.build_dir])\n\n if self.debug_capi is not None:\n self.f2py_options.append('--debug-capi')\n if self.no_wrap_functions is not None:\n self.f2py_options.append('--no-wrap-functions')\n\n # finalize_options()\n\n def run (self):\n if self.distribution.has_ext_modules():\n # XXX: might need also\n # build_flib = self.get_finalized_command('build_flib')\n # ...\n # for getting extra f2py_options that are specific to\n # a given fortran compiler.\n for ext in self.distribution.ext_modules:\n ext.sources = self.f2py_sources(ext.sources,ext)\n self.fortran_sources_to_flib(ext)\n # run()\n\n def f2py_sources (self, sources, ext):\n\n \"\"\"Walk the list of source files in 'sources', looking for f2py\n interface (.pyf) files. Run f2py on all that are found, and\n return a modified 'sources' list with f2py source files replaced\n by the generated C (or C++) and Fortran files.\n If 'sources' contains not .pyf files, then create a temporary\n one from the Fortran files in 'sources'.\n \"\"\"\n import string\n import f2py2e\n # f2py generates the following files for an extension module\n # with a name :\n # module.c\n # -f2pywrappers.f [occasionally]\n # In addition, /src/fortranobject.{c,h} are needed\n # for building f2py generated extension modules.\n # It is assumed that one pyf file contains defintions for exactly\n # one extension module.\n\n target_dir = self.build_dir\n \n new_sources = []\n f2py_sources = []\n fortran_sources = []\n f2py_targets = {}\n f2py_fortran_targets = {}\n target_ext = 'module.c'\n fortran_target_ext = '-f2pywrappers.f'\n\n for source in sources:\n (base, source_ext) = os.path.splitext(source)\n (source_dir, base) = os.path.split(base)\n if source_ext == \".pyf\": # f2py interface file\n # get extension module name\n f = open(source)\n for line in f.xreadlines():\n m = module_name_re(line)\n if m:\n if user_module_name_re(line): # skip *__user__* names\n continue\n base = m.group('name')\n break\n f.close()\n if ext.name == 'untitled':\n ext.name = base\n if base != ext.name:\n # XXX: Should we do here more than just warn?\n self.warn('%s provides %s but this extension is %s' \\\n % (source,`base`,`ext.name`))\n target_file = os.path.join(target_dir,base+target_ext)\n fortran_target_file = os.path.join(target_dir,base+fortran_target_ext)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n f2py_fortran_targets[source] = fortran_target_file\n elif fortran_ext_re(source_ext):\n fortran_sources.append(source) \n else:\n new_sources.append(source)\n\n if not (f2py_sources or fortran_sources):\n return new_sources\n\n # make sure the target dir exists\n from distutils.dir_util import mkpath\n mkpath(target_dir)\n\n if not f2py_sources:\n # creating a temporary pyf file from fortran sources\n pyf_target = os.path.join(target_dir,ext.name+'.pyf')\n pyf_target_file = os.path.join(target_dir,ext.name+target_ext)\n pyf_fortran_target_file = os.path.join(target_dir,ext.name+fortran_target_ext)\n f2py_opts2 = ['-m',ext.name,'-h',pyf_target,'--overwrite-signature']\n for source in fortran_sources:\n if newer(source,pyf_target) or self.force:\n self.announce(\"f2py-ing a new %s\" % (pyf_target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_opts2,' '))\n f2py2e.run_main(fortran_sources + f2py_opts2)\n break\n f2py_sources.append(pyf_target)\n f2py_targets[pyf_target] = pyf_target_file\n f2py_fortran_targets[pyf_target] = pyf_fortran_target_file\n\n new_sources.extend(fortran_sources)\n\n if len(f2py_sources) > 1:\n self.warn('Only one .pyf file can be used per Extension but got %s.'\\\n % (len(f2py_sources)))\n\n # a bit of a hack, but I think it'll work. Just include one of\n # the fortranobject.c files that was copied into most \n d = os.path.dirname(f2py2e.__file__)\n new_sources.append(os.path.join(d,'src','fortranobject.c'))\n ext.include_dirs.append(os.path.join(d,'src'))\n\n f2py_options = ext.f2py_options + self.f2py_options\n\n for source in f2py_sources:\n target = f2py_targets[source]\n fortran_target = f2py_fortran_targets[source]\n if newer(source,target) or self.force:\n self.announce(\"f2py-ing %s to %s\" % (source, target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_options,' '))\n f2py2e.run_main(f2py_options + [source])\n new_sources.append(target)\n if os.path.exists(fortran_target):\n new_sources.append(fortran_target)\n\n return new_sources\n\n # f2py_sources ()\n\n def fortran_sources_to_flib(self, ext):\n \"\"\"\n Extract fortran files from ext.sources and append them to\n fortran_libraries item having the same name as ext.\n \"\"\"\n sources = []\n f_files = []\n\n for file in ext.sources:\n if fortran_ext_re(file):\n f_files.append(file)\n else:\n sources.append(file)\n if not f_files:\n return\n\n ext.sources = sources\n\n if self.distribution.fortran_libraries is None:\n self.distribution.fortran_libraries = []\n fortran_libraries = self.distribution.fortran_libraries\n\n name = ext.name\n flib = None\n for n,d in fortran_libraries:\n if n == name:\n flib = d\n break\n if flib is None:\n flib = {'sources':[]}\n fortran_libraries.append((name,flib))\n\n flib['sources'].extend(f_files)\n \n# class run_f2py\n", "methods": [ { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "run_f2py.py", "nloc": 6, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 34, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "run_f2py.py", "nloc": 9, "complexity": 3, "token_count": 69, "parameters": [ "self" ], "start_line": 43, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "run_f2py.py", "nloc": 5, "complexity": 3, "token_count": 43, "parameters": [ "self" ], "start_line": 57, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "f2py_sources", "long_name": "f2py_sources( self , sources , ext )", "filename": "run_f2py.py", "nloc": 75, "complexity": 20, "token_count": 574, "parameters": [ "self", "sources", "ext" ], "start_line": 69, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 109, "top_nesting_level": 1 }, { "name": "fortran_sources_to_flib", "long_name": "fortran_sources_to_flib( self , ext )", "filename": "run_f2py.py", "nloc": 24, "complexity": 8, "token_count": 133, "parameters": [ "self", "ext" ], "start_line": 181, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 1 } ], "methods_before": [ { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "run_f2py.py", "nloc": 6, "complexity": 1, "token_count": 31, "parameters": [ "self" ], "start_line": 34, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "run_f2py.py", "nloc": 9, "complexity": 3, "token_count": 69, "parameters": [ "self" ], "start_line": 43, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "run_f2py.py", "nloc": 5, "complexity": 3, "token_count": 43, "parameters": [ "self" ], "start_line": 57, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "f2py_sources", "long_name": "f2py_sources( self , sources , ext )", "filename": "run_f2py.py", "nloc": 75, "complexity": 20, "token_count": 563, "parameters": [ "self", "sources", "ext" ], "start_line": 69, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 109, "top_nesting_level": 1 }, { "name": "fortran_sources_to_flib", "long_name": "fortran_sources_to_flib( self , ext )", "filename": "run_f2py.py", "nloc": 24, "complexity": 8, "token_count": 133, "parameters": [ "self", "ext" ], "start_line": 181, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "f2py_sources", "long_name": "f2py_sources( self , sources , ext )", "filename": "run_f2py.py", "nloc": 75, "complexity": 20, "token_count": 574, "parameters": [ "self", "sources", "ext" ], "start_line": 69, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 109, "top_nesting_level": 1 } ], "nloc": 142, "complexity": 35, "token_count": 967, "diff_parsed": { "added": [ " if base != string.split(ext.name,'.')[-1]:" ], "deleted": [ " if base != ext.name:" ] } }, { "old_path": "scipy_distutils/misc_util.py", "new_path": "scipy_distutils/misc_util.py", "filename": "misc_util.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -235,15 +235,8 @@ def default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n- full_name = \"\"\n \n- if name and parent_name:\n- full_name = '%s.%s' % (parent_name,name)\n- else:\n- if name:\n- # Useful for local builds\n- d['version'] = update_version()\n- full_name = name\n+ full_name = dot_join(parent_name,name)\n \n if full_name:\n # XXX: The following assumes that default_config_dict is called\n@@ -251,8 +244,13 @@ def default_config_dict(name = None, parent_name = None):\n frame = sys._getframe(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n- d['packages'].append(full_name)\n- d['package_dir'][full_name] = local_path\n+ if name and not parent_name:\n+ # Useful for local builds\n+ d['version'] = update_version(path=local_path)\n+\n+ if os.path.exists(os.path.join(local_path,'__init__.py')):\n+ d['packages'].append(full_name)\n+ d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n@@ -275,6 +273,9 @@ def merge_config_dicts(config_list):\n result[key].update(d.get(key,{}))\n return result\n \n+def dot_join(*args):\n+ return string.join(filter(None,args),'.')\n+\n def fortran_library_item(lib_name,\n sources,\n **attrs\n", "added_lines": 11, "deleted_lines": 10, "source_code": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = sys._getframe(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and not parent_name:\n # Useful for local builds\n d['version'] = update_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", "source_code_before": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n full_name = \"\"\n\n if name and parent_name:\n full_name = '%s.%s' % (parent_name,name)\n else:\n if name:\n # Useful for local builds\n d['version'] = update_version()\n full_name = name\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = sys._getframe(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", "methods": [ { "name": "update_version", "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", "filename": "misc_util.py", "nloc": 65, "complexity": 12, "token_count": 351, "parameters": [ "release_level", "path", "major", "overwrite_version_py" ], "start_line": 3, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 }, { "name": "get_version", "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", "filename": "misc_util.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "release_level", "path", "major" ], "start_line": 111, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_cvs_revision", "long_name": "get_cvs_revision( path )", "filename": "misc_util.py", "nloc": 21, "complexity": 10, "token_count": 190, "parameters": [ "path" ], "start_line": 127, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_path", "long_name": "get_path( mod_name )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 80, "parameters": [ "mod_name" ], "start_line": 156, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 174, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "add_grandparent_to_path", "long_name": "add_grandparent_to_path( mod_name )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "mod_name" ], "start_line": 179, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 184, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "append_package_dir_to_path", "long_name": "append_package_dir_to_path( package_name )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 64, "parameters": [ "package_name" ], "start_line": 187, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "get_package_config", "long_name": "get_package_config( package_name )", "filename": "misc_util.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "package_name" ], "start_line": 203, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "package_config", "long_name": "package_config( primary , dependencies = [ ] )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 53, "parameters": [ "primary", "dependencies" ], "start_line": 215, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None )", "filename": "misc_util.py", "nloc": 25, "complexity": 10, "token_count": 212, "parameters": [ "name", "parent_name" ], "start_line": 234, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 61, "parameters": [ "config_list" ], "start_line": 267, "end_line": 274, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "dot_join", "long_name": "dot_join( * args )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "args" ], "start_line": 276, "end_line": 277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "fortran_library_item", "long_name": "fortran_library_item( lib_name , sources , ** attrs )", "filename": "misc_util.py", "nloc": 14, "complexity": 3, "token_count": 67, "parameters": [ "lib_name", "sources", "attrs" ], "start_line": 279, "end_line": 294, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "methods_before": [ { "name": "update_version", "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", "filename": "misc_util.py", "nloc": 65, "complexity": 12, "token_count": 351, "parameters": [ "release_level", "path", "major", "overwrite_version_py" ], "start_line": 3, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 107, "top_nesting_level": 0 }, { "name": "get_version", "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", "filename": "misc_util.py", "nloc": 9, "complexity": 1, "token_count": 45, "parameters": [ "release_level", "path", "major" ], "start_line": 111, "end_line": 124, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_cvs_revision", "long_name": "get_cvs_revision( path )", "filename": "misc_util.py", "nloc": 21, "complexity": 10, "token_count": 190, "parameters": [ "path" ], "start_line": 127, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "get_path", "long_name": "get_path( mod_name )", "filename": "misc_util.py", "nloc": 10, "complexity": 3, "token_count": 80, "parameters": [ "mod_name" ], "start_line": 156, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "add_local_to_path", "long_name": "add_local_to_path( mod_name )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "mod_name" ], "start_line": 174, "end_line": 176, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "add_grandparent_to_path", "long_name": "add_grandparent_to_path( mod_name )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [ "mod_name" ], "start_line": 179, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 184, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "append_package_dir_to_path", "long_name": "append_package_dir_to_path( package_name )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 64, "parameters": [ "package_name" ], "start_line": 187, "end_line": 201, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "get_package_config", "long_name": "get_package_config( package_name )", "filename": "misc_util.py", "nloc": 5, "complexity": 1, "token_count": 27, "parameters": [ "package_name" ], "start_line": 203, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 }, { "name": "package_config", "long_name": "package_config( primary , dependencies = [ ] )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 53, "parameters": [ "primary", "dependencies" ], "start_line": 215, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None )", "filename": "misc_util.py", "nloc": 28, "complexity": 10, "token_count": 201, "parameters": [ "name", "parent_name" ], "start_line": 234, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 34, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 8, "complexity": 4, "token_count": 61, "parameters": [ "config_list" ], "start_line": 269, "end_line": 276, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "fortran_library_item", "long_name": "fortran_library_item( lib_name , sources , ** attrs )", "filename": "misc_util.py", "nloc": 14, "complexity": 3, "token_count": 67, "parameters": [ "lib_name", "sources", "attrs" ], "start_line": 278, "end_line": 293, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None )", "filename": "misc_util.py", "nloc": 25, "complexity": 10, "token_count": 212, "parameters": [ "name", "parent_name" ], "start_line": 234, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "dot_join", "long_name": "dot_join( * args )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "args" ], "start_line": 276, "end_line": 277, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 } ], "nloc": 185, "complexity": 54, "token_count": 1278, "diff_parsed": { "added": [ " full_name = dot_join(parent_name,name)", " if name and not parent_name:", " # Useful for local builds", " d['version'] = update_version(path=local_path)", "", " if os.path.exists(os.path.join(local_path,'__init__.py')):", " d['packages'].append(full_name)", " d['package_dir'][full_name] = local_path", "def dot_join(*args):", " return string.join(filter(None,args),'.')", "" ], "deleted": [ " full_name = \"\"", " if name and parent_name:", " full_name = '%s.%s' % (parent_name,name)", " else:", " if name:", " # Useful for local builds", " d['version'] = update_version()", " full_name = name", " d['packages'].append(full_name)", " d['package_dir'][full_name] = local_path" ] } }, { "old_path": "weave/setup_weave.py", "new_path": "weave/setup_weave.py", "filename": "setup_weave.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -2,18 +2,13 @@\n \n import os\n from glob import glob\n-from scipy_distutils.misc_util import get_path, default_config_dict\n+from scipy_distutils.misc_util import get_path, default_config_dict, dot_join\n \n def 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('weave')\n- config['packages'].append(parent_package+'weave')\n- config['packages'].append(parent_package+'weave.tests') \n- config['package_dir']['weave'] = local_path\n+ config = default_config_dict('weave',parent_package)\n+ config['packages'].append(dot_join(parent_package,'weave.tests'))\n test_path = os.path.join(local_path,'tests')\n config['package_dir']['weave.tests'] = test_path\n \n", "added_lines": 3, "deleted_lines": 8, "source_code": "#!/usr/bin/env python\n\nimport os\nfrom glob import glob\nfrom scipy_distutils.misc_util import get_path, default_config_dict, dot_join\n\ndef configuration(parent_package=''):\n parent_path = parent_package\n local_path = get_path(__name__)\n config = default_config_dict('weave',parent_package)\n config['packages'].append(dot_join(parent_package,'weave.tests'))\n test_path = os.path.join(local_path,'tests')\n config['package_dir']['weave.tests'] = test_path\n \n scxx_files = glob(os.path.join(local_path,'scxx','*.h'))\n install_path = os.path.join(parent_path,'weave','scxx')\n config['data_files'].extend( [(install_path,scxx_files)])\n\n cxx_files = glob(os.path.join(local_path,'CXX','*.*'))\n install_path = os.path.join(parent_path,'weave','CXX')\n config['data_files'].extend( [(install_path,cxx_files)])\n \n blitz_files = glob(os.path.join(local_path,'blitz-20001213','blitz','*.*'))\n install_path = os.path.join(parent_path,'weave','blitz-20001213',\n 'blitz')\n config['data_files'].extend( [(install_path,blitz_files)])\n \n array_files = glob(os.path.join(local_path,'blitz-20001213','blitz',\n 'array','*.*'))\n install_path = os.path.join(parent_path,'weave','blitz-20001213',\n 'blitz','array')\n config['data_files'].extend( [(install_path,array_files)])\n \n meta_files = glob(os.path.join(local_path,'blitz-20001213','blitz',\n 'meta','*.*'))\n install_path = os.path.join(parent_path,'weave','blitz-20001213',\n 'blitz','meta')\n config['data_files'].extend( [(install_path,meta_files)])\n\n swig_files = glob(os.path.join(local_path,'swig','*.c'))\n install_path = os.path.join(parent_path,'weave','swig')\n config['data_files'].extend( [(install_path,swig_files)])\n\n doc_files = glob(os.path.join(local_path,'doc','*.html'))\n install_path = os.path.join(parent_path,'weave','doc')\n config['data_files'].extend( [(install_path,doc_files)])\n\n example_files = glob(os.path.join(local_path,'examples','*.py'))\n install_path = os.path.join(parent_path,'weave','examples')\n config['data_files'].extend( [(install_path,example_files)])\n \n return config\n\nif __name__ == '__main__': \n from scipy_distutils.core import setup\n setup(**configuration())\n", "source_code_before": "#!/usr/bin/env python\n\nimport os\nfrom glob import glob\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('weave')\n config['packages'].append(parent_package+'weave')\n config['packages'].append(parent_package+'weave.tests') \n config['package_dir']['weave'] = local_path\n test_path = os.path.join(local_path,'tests')\n config['package_dir']['weave.tests'] = test_path\n \n scxx_files = glob(os.path.join(local_path,'scxx','*.h'))\n install_path = os.path.join(parent_path,'weave','scxx')\n config['data_files'].extend( [(install_path,scxx_files)])\n\n cxx_files = glob(os.path.join(local_path,'CXX','*.*'))\n install_path = os.path.join(parent_path,'weave','CXX')\n config['data_files'].extend( [(install_path,cxx_files)])\n \n blitz_files = glob(os.path.join(local_path,'blitz-20001213','blitz','*.*'))\n install_path = os.path.join(parent_path,'weave','blitz-20001213',\n 'blitz')\n config['data_files'].extend( [(install_path,blitz_files)])\n \n array_files = glob(os.path.join(local_path,'blitz-20001213','blitz',\n 'array','*.*'))\n install_path = os.path.join(parent_path,'weave','blitz-20001213',\n 'blitz','array')\n config['data_files'].extend( [(install_path,array_files)])\n \n meta_files = glob(os.path.join(local_path,'blitz-20001213','blitz',\n 'meta','*.*'))\n install_path = os.path.join(parent_path,'weave','blitz-20001213',\n 'blitz','meta')\n config['data_files'].extend( [(install_path,meta_files)])\n\n swig_files = glob(os.path.join(local_path,'swig','*.c'))\n install_path = os.path.join(parent_path,'weave','swig')\n config['data_files'].extend( [(install_path,swig_files)])\n\n doc_files = glob(os.path.join(local_path,'doc','*.html'))\n install_path = os.path.join(parent_path,'weave','doc')\n config['data_files'].extend( [(install_path,doc_files)])\n\n example_files = glob(os.path.join(local_path,'examples','*.py'))\n install_path = os.path.join(parent_path,'weave','examples')\n config['data_files'].extend( [(install_path,example_files)])\n \n return config\n\nif __name__ == '__main__': \n from scipy_distutils.core import setup\n setup(**configuration())\n", "methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' )", "filename": "setup_weave.py", "nloc": 37, "complexity": 1, "token_count": 449, "parameters": [ "parent_package" ], "start_line": 7, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 0 } ], "methods_before": [ { "name": "configuration", "long_name": "configuration( parent_package = '' )", "filename": "setup_weave.py", "nloc": 41, "complexity": 2, "token_count": 470, "parameters": [ "parent_package" ], "start_line": 7, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "configuration", "long_name": "configuration( parent_package = '' )", "filename": "setup_weave.py", "nloc": 37, "complexity": 1, "token_count": 449, "parameters": [ "parent_package" ], "start_line": 7, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 46, "top_nesting_level": 0 } ], "nloc": 43, "complexity": 1, "token_count": 484, "diff_parsed": { "added": [ "from scipy_distutils.misc_util import get_path, default_config_dict, dot_join", " config = default_config_dict('weave',parent_package)", " config['packages'].append(dot_join(parent_package,'weave.tests'))" ], "deleted": [ "from scipy_distutils.misc_util import get_path, default_config_dict", " if parent_package:", " parent_package += '.'", "", " config = default_config_dict('weave')", " config['packages'].append(parent_package+'weave')", " config['packages'].append(parent_package+'weave.tests')", " config['package_dir']['weave'] = local_path" ] } } ] }, { "hash": "9ae4d9e810749413fb6a91106b4c5ee05f6c0fc1", "msg": "Introduced x11_info and fixed the inefficiency of xplt setup", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2002-02-17T23:23:07+00:00", "author_timezone": 0, "committer_date": "2002-02-17T23:23:07+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "2dfed378bdc129e2f0d5fcc814b5a8a8b02dff0b" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 2, "insertions": 43, "lines": 45, "files": 2, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/__version__.py", "new_path": "scipy_distutils/__version__.py", "filename": "__version__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1,4 +1,4 @@\n # This file is automatically updated with update_version\n # function from scipy_distutils.misc_util.py\n-version = '0.6.23-alpha-111'\n-version_info = (0, 6, 23, 'alpha', 111)\n+version = '0.6.23-alpha-116'\n+version_info = (0, 6, 23, 'alpha', 116)\n", "added_lines": 2, "deleted_lines": 2, "source_code": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-116'\nversion_info = (0, 6, 23, 'alpha', 116)\n", "source_code_before": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-111'\nversion_info = (0, 6, 23, 'alpha', 111)\n", "methods": [], "methods_before": [], "changed_methods": [], "nloc": 2, "complexity": 0, "token_count": 16, "diff_parsed": { "added": [ "version = '0.6.23-alpha-116'", "version_info = (0, 6, 23, 'alpha', 116)" ], "deleted": [ "version = '0.6.23-alpha-111'", "version_info = (0, 6, 23, 'alpha', 111)" ] } }, { "old_path": null, "new_path": "scipy_distutils/x11_info.py", "filename": "x11_info.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,41 @@\n+\n+import sys, os, glob\n+\n+def get_x11_info():\n+ if sys.platform == 'win32':\n+ return {}\n+\n+ #XXX: add other combinations if needed\n+ libs = ['X11']\n+ prefixes = ['/usr','/usr/local','/opt']\n+ x11_names = ['X11R6','X11']\n+ header_files = ['X.h','X11/X.h']\n+\n+ x11_lib,x11_lib_dir,x11_inc_dir = None,None,None\n+ for p in prefixes:\n+ for n in x11_names:\n+ d = os.path.join(p,n)\n+ if not os.path.exists(d): continue\n+ if x11_lib is None:\n+ # Find library and its location\n+ for l in libs:\n+ if glob.glob(os.path.join(d,'lib','lib%s.*' % l)):\n+ x11_lib = l\n+ x11_lib_dir = os.path.join(d,'lib')\n+ break\n+ if x11_inc_dir is None:\n+ # Find the location of header file\n+ for h in header_files:\n+ if os.path.exists(os.path.join(d,'include',h)):\n+ x11_inc_dir = os.path.join(d,'include')\n+ break\n+ if None not in [x11_lib,x11_inc_dir]:\n+ break\n+ if None in [x11_lib,x11_inc_dir]:\n+ return {}\n+ info = {}\n+ info['libraries'] = [x11_lib]\n+ info['library_dirs'] = [x11_lib_dir]\n+ info['include_dirs'] = [x11_inc_dir]\n+ return info\n+\n", "added_lines": 41, "deleted_lines": 0, "source_code": "\nimport sys, os, glob\n\ndef get_x11_info():\n if sys.platform == 'win32':\n return {}\n\n #XXX: add other combinations if needed\n libs = ['X11']\n prefixes = ['/usr','/usr/local','/opt']\n x11_names = ['X11R6','X11']\n header_files = ['X.h','X11/X.h']\n\n x11_lib,x11_lib_dir,x11_inc_dir = None,None,None\n for p in prefixes:\n for n in x11_names:\n d = os.path.join(p,n)\n if not os.path.exists(d): continue\n if x11_lib is None:\n # Find library and its location\n for l in libs:\n if glob.glob(os.path.join(d,'lib','lib%s.*' % l)):\n x11_lib = l\n x11_lib_dir = os.path.join(d,'lib')\n break\n if x11_inc_dir is None:\n # Find the location of header file\n for h in header_files:\n if os.path.exists(os.path.join(d,'include',h)):\n x11_inc_dir = os.path.join(d,'include')\n break\n if None not in [x11_lib,x11_inc_dir]:\n break\n if None in [x11_lib,x11_inc_dir]:\n return {}\n info = {}\n info['libraries'] = [x11_lib]\n info['library_dirs'] = [x11_lib_dir]\n info['include_dirs'] = [x11_inc_dir]\n return info\n\n", "source_code_before": null, "methods": [ { "name": "get_x11_info", "long_name": "get_x11_info( )", "filename": "x11_info.py", "nloc": 32, "complexity": 13, "token_count": 231, "parameters": [], "start_line": 4, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 } ], "methods_before": [], "changed_methods": [ { "name": "get_x11_info", "long_name": "get_x11_info( )", "filename": "x11_info.py", "nloc": 32, "complexity": 13, "token_count": 231, "parameters": [], "start_line": 4, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 } ], "nloc": 33, "complexity": 13, "token_count": 238, "diff_parsed": { "added": [ "", "import sys, os, glob", "", "def get_x11_info():", " if sys.platform == 'win32':", " return {}", "", " #XXX: add other combinations if needed", " libs = ['X11']", " prefixes = ['/usr','/usr/local','/opt']", " x11_names = ['X11R6','X11']", " header_files = ['X.h','X11/X.h']", "", " x11_lib,x11_lib_dir,x11_inc_dir = None,None,None", " for p in prefixes:", " for n in x11_names:", " d = os.path.join(p,n)", " if not os.path.exists(d): continue", " if x11_lib is None:", " # Find library and its location", " for l in libs:", " if glob.glob(os.path.join(d,'lib','lib%s.*' % l)):", " x11_lib = l", " x11_lib_dir = os.path.join(d,'lib')", " break", " if x11_inc_dir is None:", " # Find the location of header file", " for h in header_files:", " if os.path.exists(os.path.join(d,'include',h)):", " x11_inc_dir = os.path.join(d,'include')", " break", " if None not in [x11_lib,x11_inc_dir]:", " break", " if None in [x11_lib,x11_inc_dir]:", " return {}", " info = {}", " info['libraries'] = [x11_lib]", " info['library_dirs'] = [x11_lib_dir]", " info['include_dirs'] = [x11_inc_dir]", " return info", "" ], "deleted": [] } } ] }, { "hash": "0894dd3f103ce8e44416fb3369f241dee5c6dd9a", "msg": "Very prototypical version of weave.accelerate\nThis one is sensitive to argument types and chooses\nthe appropriate function. It includes functionality\nto allow\n\nfoo = weave.accelerate(foo)\nfoo_int = foo.sample(0) # arguments are for type sampling only...\nfoo_double = foo.sample(0.0)\n\nNumeric is still hosed (Dying on PyArray_Check of all things! --\nIt is trying to pull in the C API array instead of using the\nnormal type checking mechanism (ends up using a NULL pointer))\n\nNo tests as yet. I'll build a unittest compatible version for\nthe simple test. Current \"super\" function object is about\n10 times more overhead to check function types. We may do\nwell to pull that into one generic mega-test inside the wrapper\ncode eventually. The \"accelerated\" generic version of a+b is 10\ntimes slower than native. The full accelerated version is 2x\nfaster (hey -- it's a+b what do you want!)", "author": { "name": "patmiller", "email": "patmiller@localhost" }, "committer": { "name": "patmiller", "email": "patmiller@localhost" }, "author_date": "2002-02-19T04:46:38+00:00", "author_timezone": 0, "committer_date": "2002-02-19T04:46:38+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "9ae4d9e810749413fb6a91106b4c5ee05f6c0fc1" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 0, "insertions": 1420, "lines": 1420, "files": 3, "dmm_unit_size": 0.7349693251533742, "dmm_unit_complexity": 0.905521472392638, "dmm_unit_interfacing": 0.5987730061349693, "modified_files": [ { "old_path": "weave/__init__.py", "new_path": "weave/__init__.py", "filename": "__init__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -3,6 +3,7 @@\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 \n try:\n@@ -13,6 +14,10 @@\n from inline_tools import inline\n import ext_tools\n from ext_tools import ext_module, ext_function\n+try:\n+ from accelerate_tools import accelerate\n+except:\n+ pass\n \n #---- testing ----#\n \n", "added_lines": 5, "deleted_lines": 0, "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():\n import unittest\n runner = unittest.TextTestRunner()\n runner.run(test_suite())\n return runner\n\ndef test_suite():\n import scipy_test\n # this isn't a perfect fix, but it will work for\n # most cases I think.\n this_mod = __import__(__name__)\n return scipy_test.harvest_test_suites(this_mod)\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\"\"\"\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\n\n#---- testing ----#\n\ndef test():\n import unittest\n runner = unittest.TextTestRunner()\n runner.run(test_suite())\n return runner\n\ndef test_suite():\n import scipy_test\n # this isn't a perfect fix, but it will work for\n # most cases I think.\n this_mod = __import__(__name__)\n return scipy_test.harvest_test_suites(this_mod)\n", "methods": [ { "name": "test", "long_name": "test( )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [], "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( )", "filename": "__init__.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [], "start_line": 30, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 } ], "methods_before": [ { "name": "test", "long_name": "test( )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [], "start_line": 19, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "__init__.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [], "start_line": 25, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 } ], "changed_methods": [], "nloc": 27, "complexity": 2, "token_count": 76, "diff_parsed": { "added": [ " 4. accelerate -- a module that inline accelerates Python functions", "try:", " from accelerate_tools import accelerate", "except:", " pass" ], "deleted": [] } }, { "old_path": null, "new_path": "weave/accelerate_tools.py", "filename": "accelerate_tools.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,211 @@\n+#**************************************************************************#\n+#* FILE ************** accelerate_tools.py ************************#\n+#**************************************************************************#\n+#* Author: Patrick Miller February 9 2002 *#\n+#**************************************************************************#\n+\"\"\"\n+accelerate_tools contains the interface for on-the-fly building of\n+C++ equivalents to Python functions.\n+\"\"\"\n+#**************************************************************************#\n+\n+from types import FunctionType,IntType,FloatType,StringType,TypeType\n+import inspect\n+import md5\n+import weave\n+import bytecodecompiler\n+\n+def CStr(s):\n+ \"Hacky way to get legal C string from Python string\"\n+ if s == None: return '\"\"'\n+ assert type(s) == StringType,\"Only None and string allowed\"\n+ r = repr('\"'+s) # Better for embedded quotes\n+ return '\"'+r[2:-1]+'\"'\n+\n+class Basic(bytecodecompiler.Type_Descriptor):\n+ def check(self,s):\n+ return \"%s(%s)\"%(self.checker,s)\n+ def inbound(self,s):\n+ return \"%s(%s)\"%(self.inbounder,s)\n+ def outbound(self,s):\n+ return \"%s(%s)\"%(self.outbounder,s)\n+\n+class Basic_Number(Basic):\n+ def binop(self,symbol,a,b):\n+ assert symbol in ['+','-','*','/'],symbol\n+ return '%s %s %s'%(a,symbol,b),self\n+\n+class Integer(Basic_Number):\n+ cxxtype = \"long\"\n+ checker = \"PyInt_Check\"\n+ inbounder = \"PyInt_AsLong\"\n+ outbounder = \"PyInt_FromLong\"\n+\n+class Double(Basic_Number):\n+ cxxtype = \"double\"\n+ checker = \"PyFloat_Check\"\n+ inbounder = \"PyFloat_AsDouble\"\n+ outbounder = \"PyFloat_FromDouble\"\n+\n+class String(Basic):\n+ cxxtype = \"char*\"\n+ checker = \"PyString_Check\"\n+ inbounder = \"PyString_AsString\"\n+ outbounder = \"PyString_FromString\"\n+\n+ def literalizer(self,s):\n+ return CStr(s)\n+\n+import Numeric\n+\n+class Vector(bytecodecompiler.Type_Descriptor):\n+ cxxtype = 'PyArrayObject*'\n+ prerequisites = bytecodecompiler.Type_Descriptor.prerequisites+\\\n+ ['#include \"Numeric/arrayobject.h\"',\n+ 'static PyObject* PyArray_AsPyObject(PyArrayObject* A) { PyObject* X = '\n+ 'reinterpret_cast(A);'\n+ 'std::cerr << \"Here in cast\" << std::endl;'\n+ 'Py_XINCREF(X); return X;}']\n+ dims = 1\n+ def check(self,s):\n+ return \"PyArray_Check(%s) /* && dims==%d && typecode==%s */\"%(s,self.dims,self.typecode)\n+ def inbound(self,s):\n+ return \"(PyArrayObject*)(%s)\"%s\n+ def outbound(self,s):\n+ return \"(PyObject*)(%s)\"%s\n+\n+class IntegerVector(Vector):\n+ typecode = 'l'\n+\n+typedefs = {\n+ IntType: Integer(),\n+ FloatType: Double(),\n+ StringType: String(),\n+ (Numeric.ArrayType,1,'l'): IntegerVector(),\n+ }\n+\n+\n+##################################################################\n+# FUNCTION LOOKUP_TYPE #\n+##################################################################\n+def lookup_type(x):\n+ T = type(x)\n+ try:\n+ return typedefs[T]\n+ except:\n+ return typedefs[(T,len(x.shape),x.typecode())]\n+\n+##################################################################\n+# class ACCELERATE #\n+##################################################################\n+class accelerate:\n+ \n+ def __init__(self, function, *args, **kw):\n+ assert type(function) == FunctionType\n+ self.function = function\n+ self.module = inspect.getmodule(function)\n+ if self.module == None:\n+ import __main__\n+ self.module = __main__\n+ self.__call_map = {}\n+ return\n+\n+ def __call__(self,*args):\n+ # Figure out type info -- Do as tuple so its hashable\n+ signature = tuple( map(lookup_type,args) )\n+\n+ # If we know the function, call it\n+ try:\n+ return self.__call_map[signature](*args)\n+ except:\n+ fast = self.singleton(signature)\n+ self.__call_map[signature] = fast\n+ return fast(*args)\n+\n+ def signature(self,*args):\n+ # Figure out type info -- Do as tuple so its hashable\n+ signature = tuple( map(lookup_type,args) )\n+ return self.singleton(signature)\n+\n+\n+ def singleton(self,signature):\n+ identifier = self.identifier(signature)\n+ \n+ # Generate a new function, then call it\n+ f = self.function\n+\n+ # See if we have an accelerated version of module\n+ try:\n+ accelerated_module = __import__(self.module.__name__+'_weave')\n+ fast = getattr(accelerated_module,identifier)\n+ return fast\n+ except:\n+ accelerated_module = None\n+\n+ P = self.accelerate(signature,identifier)\n+\n+ E = weave.ext_tools.ext_module(self.module.__name__+'_weave')\n+ E.add_function(P)\n+ E.generate_file()\n+ weave.build_tools.build_extension(self.module.__name__+'_weave.cpp',verbose=2)\n+\n+ if accelerated_module:\n+ accelerated_module = reload(accelerated_module)\n+ else:\n+ accelerated_module = __import__(self.module.__name__+'_weave')\n+\n+ fast = getattr(accelerated_module,identifier)\n+ return fast\n+\n+ def identifier(self,signature):\n+ # Build an MD5 checksum\n+ f = self.function\n+ co = f.func_code\n+ identifier = str(signature)+\\\n+ str(co.co_consts)+\\\n+ str(co.co_varnames)+\\\n+ co.co_code\n+ return 'F'+md5.md5(identifier).hexdigest()\n+ \n+ def accelerate(self,signature,identifier):\n+ P = Python2CXX(self.function,signature,name=identifier)\n+ return P\n+\n+ def code(self,*args):\n+ signature = tuple( map(lookup_type,args) )\n+ ident = self.function.__name__\n+ return self.accelerate(signature,ident).function_code()\n+ \n+\n+##################################################################\n+# CLASS PYTHON2CXX #\n+##################################################################\n+class Python2CXX(bytecodecompiler.CXXCoder):\n+ def typedef_by_value(self,v):\n+ T = lookup_type(v)\n+ if T not in self.used: self.used.append(T)\n+ return T\n+\n+ def __init__(self,f,signature,name=None):\n+ # Make sure function is a function\n+ import types\n+ assert type(f) == FunctionType\n+ # and check the input type signature\n+ assert reduce(lambda x,y: x and y,\n+ map(lambda x: isinstance(x,bytecodecompiler.Type_Descriptor),\n+ signature),\n+ 1),'%s not all type objects'%signature\n+ self.arg_specs = []\n+ self.customize = weave.base_info.custom_info()\n+\n+ bytecodecompiler.CXXCoder.__init__(self,f,signature,name)\n+ return\n+\n+ def function_code(self):\n+ return self.wrapped_code()\n+\n+ def python_function_definition_code(self):\n+ return '{ \"%s\", wrapper_%s, METH_VARARGS, %s },\\n'%(\n+ self.name,\n+ self.name,\n+ CStr(self.function.__doc__))\n", "added_lines": 211, "deleted_lines": 0, "source_code": "#**************************************************************************#\n#* FILE ************** accelerate_tools.py ************************#\n#**************************************************************************#\n#* Author: Patrick Miller February 9 2002 *#\n#**************************************************************************#\n\"\"\"\naccelerate_tools contains the interface for on-the-fly building of\nC++ equivalents to Python functions.\n\"\"\"\n#**************************************************************************#\n\nfrom types import FunctionType,IntType,FloatType,StringType,TypeType\nimport inspect\nimport md5\nimport weave\nimport bytecodecompiler\n\ndef CStr(s):\n \"Hacky way to get legal C string from Python string\"\n if s == None: return '\"\"'\n assert type(s) == StringType,\"Only None and string allowed\"\n r = repr('\"'+s) # Better for embedded quotes\n return '\"'+r[2:-1]+'\"'\n\nclass Basic(bytecodecompiler.Type_Descriptor):\n def check(self,s):\n return \"%s(%s)\"%(self.checker,s)\n def inbound(self,s):\n return \"%s(%s)\"%(self.inbounder,s)\n def outbound(self,s):\n return \"%s(%s)\"%(self.outbounder,s)\n\nclass Basic_Number(Basic):\n def binop(self,symbol,a,b):\n assert symbol in ['+','-','*','/'],symbol\n return '%s %s %s'%(a,symbol,b),self\n\nclass Integer(Basic_Number):\n cxxtype = \"long\"\n checker = \"PyInt_Check\"\n inbounder = \"PyInt_AsLong\"\n outbounder = \"PyInt_FromLong\"\n\nclass Double(Basic_Number):\n cxxtype = \"double\"\n checker = \"PyFloat_Check\"\n inbounder = \"PyFloat_AsDouble\"\n outbounder = \"PyFloat_FromDouble\"\n\nclass String(Basic):\n cxxtype = \"char*\"\n checker = \"PyString_Check\"\n inbounder = \"PyString_AsString\"\n outbounder = \"PyString_FromString\"\n\n def literalizer(self,s):\n return CStr(s)\n\nimport Numeric\n\nclass Vector(bytecodecompiler.Type_Descriptor):\n cxxtype = 'PyArrayObject*'\n prerequisites = bytecodecompiler.Type_Descriptor.prerequisites+\\\n ['#include \"Numeric/arrayobject.h\"',\n 'static PyObject* PyArray_AsPyObject(PyArrayObject* A) { PyObject* X = '\n 'reinterpret_cast(A);'\n 'std::cerr << \"Here in cast\" << std::endl;'\n 'Py_XINCREF(X); return X;}']\n dims = 1\n def check(self,s):\n return \"PyArray_Check(%s) /* && dims==%d && typecode==%s */\"%(s,self.dims,self.typecode)\n def inbound(self,s):\n return \"(PyArrayObject*)(%s)\"%s\n def outbound(self,s):\n return \"(PyObject*)(%s)\"%s\n\nclass IntegerVector(Vector):\n typecode = 'l'\n\ntypedefs = {\n IntType: Integer(),\n FloatType: Double(),\n StringType: String(),\n (Numeric.ArrayType,1,'l'): IntegerVector(),\n }\n\n\n##################################################################\n# FUNCTION LOOKUP_TYPE #\n##################################################################\ndef lookup_type(x):\n T = type(x)\n try:\n return typedefs[T]\n except:\n return typedefs[(T,len(x.shape),x.typecode())]\n\n##################################################################\n# class ACCELERATE #\n##################################################################\nclass accelerate:\n \n def __init__(self, function, *args, **kw):\n assert type(function) == FunctionType\n self.function = function\n self.module = inspect.getmodule(function)\n if self.module == None:\n import __main__\n self.module = __main__\n self.__call_map = {}\n return\n\n def __call__(self,*args):\n # Figure out type info -- Do as tuple so its hashable\n signature = tuple( map(lookup_type,args) )\n\n # If we know the function, call it\n try:\n return self.__call_map[signature](*args)\n except:\n fast = self.singleton(signature)\n self.__call_map[signature] = fast\n return fast(*args)\n\n def signature(self,*args):\n # Figure out type info -- Do as tuple so its hashable\n signature = tuple( map(lookup_type,args) )\n return self.singleton(signature)\n\n\n def singleton(self,signature):\n identifier = self.identifier(signature)\n \n # Generate a new function, then call it\n f = self.function\n\n # See if we have an accelerated version of module\n try:\n accelerated_module = __import__(self.module.__name__+'_weave')\n fast = getattr(accelerated_module,identifier)\n return fast\n except:\n accelerated_module = None\n\n P = self.accelerate(signature,identifier)\n\n E = weave.ext_tools.ext_module(self.module.__name__+'_weave')\n E.add_function(P)\n E.generate_file()\n weave.build_tools.build_extension(self.module.__name__+'_weave.cpp',verbose=2)\n\n if accelerated_module:\n accelerated_module = reload(accelerated_module)\n else:\n accelerated_module = __import__(self.module.__name__+'_weave')\n\n fast = getattr(accelerated_module,identifier)\n return fast\n\n def identifier(self,signature):\n # Build an MD5 checksum\n f = self.function\n co = f.func_code\n identifier = str(signature)+\\\n str(co.co_consts)+\\\n str(co.co_varnames)+\\\n co.co_code\n return 'F'+md5.md5(identifier).hexdigest()\n \n def accelerate(self,signature,identifier):\n P = Python2CXX(self.function,signature,name=identifier)\n return P\n\n def code(self,*args):\n signature = tuple( map(lookup_type,args) )\n ident = self.function.__name__\n return self.accelerate(signature,ident).function_code()\n \n\n##################################################################\n# CLASS PYTHON2CXX #\n##################################################################\nclass Python2CXX(bytecodecompiler.CXXCoder):\n def typedef_by_value(self,v):\n T = lookup_type(v)\n if T not in self.used: self.used.append(T)\n return T\n\n def __init__(self,f,signature,name=None):\n # Make sure function is a function\n import types\n assert type(f) == FunctionType\n # and check the input type signature\n assert reduce(lambda x,y: x and y,\n map(lambda x: isinstance(x,bytecodecompiler.Type_Descriptor),\n signature),\n 1),'%s not all type objects'%signature\n self.arg_specs = []\n self.customize = weave.base_info.custom_info()\n\n bytecodecompiler.CXXCoder.__init__(self,f,signature,name)\n return\n\n def function_code(self):\n return self.wrapped_code()\n\n def python_function_definition_code(self):\n return '{ \"%s\", wrapper_%s, METH_VARARGS, %s },\\n'%(\n self.name,\n self.name,\n CStr(self.function.__doc__))\n", "source_code_before": null, "methods": [ { "name": "CStr", "long_name": "CStr( s )", "filename": "accelerate_tools.py", "nloc": 6, "complexity": 2, "token_count": 42, "parameters": [ "s" ], "start_line": 18, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "check", "long_name": "check( self , s )", "filename": "accelerate_tools.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "s" ], "start_line": 26, "end_line": 27, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "inbound", "long_name": "inbound( self , s )", "filename": "accelerate_tools.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "s" ], "start_line": 28, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "outbound", "long_name": "outbound( self , s )", "filename": "accelerate_tools.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "s" ], "start_line": 30, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "binop", "long_name": "binop( self , symbol , a , b )", "filename": "accelerate_tools.py", "nloc": 3, "complexity": 1, "token_count": 37, "parameters": [ "self", "symbol", "a", "b" ], "start_line": 34, "end_line": 36, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "literalizer", "long_name": "literalizer( self , s )", "filename": "accelerate_tools.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "s" ], "start_line": 56, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "check", "long_name": "check( self , s )", "filename": "accelerate_tools.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "self", "s" ], "start_line": 70, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "inbound", "long_name": "inbound( self , s )", "filename": "accelerate_tools.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "s" ], "start_line": 72, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "outbound", "long_name": "outbound( self , s )", "filename": "accelerate_tools.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "s" ], "start_line": 74, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "lookup_type", "long_name": "lookup_type( x )", "filename": "accelerate_tools.py", "nloc": 6, "complexity": 2, "token_count": 40, "parameters": [ "x" ], "start_line": 91, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , function , * args , ** kw )", "filename": "accelerate_tools.py", "nloc": 9, "complexity": 2, "token_count": 56, "parameters": [ "self", "function", "args", "kw" ], "start_line": 103, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args )", "filename": "accelerate_tools.py", "nloc": 8, "complexity": 2, "token_count": 56, "parameters": [ "self", "args" ], "start_line": 113, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "signature", "long_name": "signature( self , * args )", "filename": "accelerate_tools.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "self", "args" ], "start_line": 125, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "singleton", "long_name": "singleton( self , signature )", "filename": "accelerate_tools.py", "nloc": 20, "complexity": 3, "token_count": 137, "parameters": [ "self", "signature" ], "start_line": 131, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 1 }, { "name": "identifier", "long_name": "identifier( self , signature )", "filename": "accelerate_tools.py", "nloc": 8, "complexity": 1, "token_count": 57, "parameters": [ "self", "signature" ], "start_line": 160, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "accelerate", "long_name": "accelerate( self , signature , identifier )", "filename": "accelerate_tools.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "signature", "identifier" ], "start_line": 170, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "code", "long_name": "code( self , * args )", "filename": "accelerate_tools.py", "nloc": 4, "complexity": 1, "token_count": 39, "parameters": [ "self", "args" ], "start_line": 174, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "typedef_by_value", "long_name": "typedef_by_value( self , v )", "filename": "accelerate_tools.py", "nloc": 4, "complexity": 2, "token_count": 31, "parameters": [ "self", "v" ], "start_line": 184, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , f , signature , name = None )", "filename": "accelerate_tools.py", "nloc": 11, "complexity": 2, "token_count": 89, "parameters": [ "self", "f", "signature", "name" ], "start_line": 189, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "accelerate_tools.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 204, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "accelerate_tools.py", "nloc": 5, "complexity": 1, "token_count": 26, "parameters": [ "self" ], "start_line": 207, "end_line": 211, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 } ], "methods_before": [], "changed_methods": [ { "name": "signature", "long_name": "signature( self , * args )", "filename": "accelerate_tools.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "self", "args" ], "start_line": 125, "end_line": 128, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "singleton", "long_name": "singleton( self , signature )", "filename": "accelerate_tools.py", "nloc": 20, "complexity": 3, "token_count": 137, "parameters": [ "self", "signature" ], "start_line": 131, "end_line": 158, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 1 }, { "name": "lookup_type", "long_name": "lookup_type( x )", "filename": "accelerate_tools.py", "nloc": 6, "complexity": 2, "token_count": 40, "parameters": [ "x" ], "start_line": 91, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "function_code", "long_name": "function_code( self )", "filename": "accelerate_tools.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 204, "end_line": 205, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "typedef_by_value", "long_name": "typedef_by_value( self , v )", "filename": "accelerate_tools.py", "nloc": 4, "complexity": 2, "token_count": 31, "parameters": [ "self", "v" ], "start_line": 184, "end_line": 187, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check", "long_name": "check( self , s )", "filename": "accelerate_tools.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "s" ], "start_line": 26, "end_line": 27, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "python_function_definition_code", "long_name": "python_function_definition_code( self )", "filename": "accelerate_tools.py", "nloc": 5, "complexity": 1, "token_count": 26, "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": "CStr", "long_name": "CStr( s )", "filename": "accelerate_tools.py", "nloc": 6, "complexity": 2, "token_count": 42, "parameters": [ "s" ], "start_line": 18, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "binop", "long_name": "binop( self , symbol , a , b )", "filename": "accelerate_tools.py", "nloc": 3, "complexity": 1, "token_count": 37, "parameters": [ "self", "symbol", "a", "b" ], "start_line": 34, "end_line": 36, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , * args )", "filename": "accelerate_tools.py", "nloc": 8, "complexity": 2, "token_count": 56, "parameters": [ "self", "args" ], "start_line": 113, "end_line": 123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "code", "long_name": "code( self , * args )", "filename": "accelerate_tools.py", "nloc": 4, "complexity": 1, "token_count": 39, "parameters": [ "self", "args" ], "start_line": 174, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , f , signature , name = None )", "filename": "accelerate_tools.py", "nloc": 11, "complexity": 2, "token_count": 89, "parameters": [ "self", "f", "signature", "name" ], "start_line": 189, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , function , * args , ** kw )", "filename": "accelerate_tools.py", "nloc": 9, "complexity": 2, "token_count": 56, "parameters": [ "self", "function", "args", "kw" ], "start_line": 103, "end_line": 111, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "identifier", "long_name": "identifier( self , signature )", "filename": "accelerate_tools.py", "nloc": 8, "complexity": 1, "token_count": 57, "parameters": [ "self", "signature" ], "start_line": 160, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "literalizer", "long_name": "literalizer( self , s )", "filename": "accelerate_tools.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "s" ], "start_line": 56, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "accelerate", "long_name": "accelerate( self , signature , identifier )", "filename": "accelerate_tools.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self", "signature", "identifier" ], "start_line": 170, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "inbound", "long_name": "inbound( self , s )", "filename": "accelerate_tools.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "s" ], "start_line": 28, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "outbound", "long_name": "outbound( self , s )", "filename": "accelerate_tools.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self", "s" ], "start_line": 30, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "nloc": 152, "complexity": 29, "token_count": 977, "diff_parsed": { "added": [ "#**************************************************************************#", "#* FILE ************** accelerate_tools.py ************************#", "#**************************************************************************#", "#* Author: Patrick Miller February 9 2002 *#", "#**************************************************************************#", "\"\"\"", "accelerate_tools contains the interface for on-the-fly building of", "C++ equivalents to Python functions.", "\"\"\"", "#**************************************************************************#", "", "from types import FunctionType,IntType,FloatType,StringType,TypeType", "import inspect", "import md5", "import weave", "import bytecodecompiler", "", "def CStr(s):", " \"Hacky way to get legal C string from Python string\"", " if s == None: return '\"\"'", " assert type(s) == StringType,\"Only None and string allowed\"", " r = repr('\"'+s) # Better for embedded quotes", " return '\"'+r[2:-1]+'\"'", "", "class Basic(bytecodecompiler.Type_Descriptor):", " def check(self,s):", " return \"%s(%s)\"%(self.checker,s)", " def inbound(self,s):", " return \"%s(%s)\"%(self.inbounder,s)", " def outbound(self,s):", " return \"%s(%s)\"%(self.outbounder,s)", "", "class Basic_Number(Basic):", " def binop(self,symbol,a,b):", " assert symbol in ['+','-','*','/'],symbol", " return '%s %s %s'%(a,symbol,b),self", "", "class Integer(Basic_Number):", " cxxtype = \"long\"", " checker = \"PyInt_Check\"", " inbounder = \"PyInt_AsLong\"", " outbounder = \"PyInt_FromLong\"", "", "class Double(Basic_Number):", " cxxtype = \"double\"", " checker = \"PyFloat_Check\"", " inbounder = \"PyFloat_AsDouble\"", " outbounder = \"PyFloat_FromDouble\"", "", "class String(Basic):", " cxxtype = \"char*\"", " checker = \"PyString_Check\"", " inbounder = \"PyString_AsString\"", " outbounder = \"PyString_FromString\"", "", " def literalizer(self,s):", " return CStr(s)", "", "import Numeric", "", "class Vector(bytecodecompiler.Type_Descriptor):", " cxxtype = 'PyArrayObject*'", " prerequisites = bytecodecompiler.Type_Descriptor.prerequisites+\\", " ['#include \"Numeric/arrayobject.h\"',", " 'static PyObject* PyArray_AsPyObject(PyArrayObject* A) { PyObject* X = '", " 'reinterpret_cast(A);'", " 'std::cerr << \"Here in cast\" << std::endl;'", " 'Py_XINCREF(X); return X;}']", " dims = 1", " def check(self,s):", " return \"PyArray_Check(%s) /* && dims==%d && typecode==%s */\"%(s,self.dims,self.typecode)", " def inbound(self,s):", " return \"(PyArrayObject*)(%s)\"%s", " def outbound(self,s):", " return \"(PyObject*)(%s)\"%s", "", "class IntegerVector(Vector):", " typecode = 'l'", "", "typedefs = {", " IntType: Integer(),", " FloatType: Double(),", " StringType: String(),", " (Numeric.ArrayType,1,'l'): IntegerVector(),", " }", "", "", "##################################################################", "# FUNCTION LOOKUP_TYPE #", "##################################################################", "def lookup_type(x):", " T = type(x)", " try:", " return typedefs[T]", " except:", " return typedefs[(T,len(x.shape),x.typecode())]", "", "##################################################################", "# class ACCELERATE #", "##################################################################", "class accelerate:", "", " def __init__(self, function, *args, **kw):", " assert type(function) == FunctionType", " self.function = function", " self.module = inspect.getmodule(function)", " if self.module == None:", " import __main__", " self.module = __main__", " self.__call_map = {}", " return", "", " def __call__(self,*args):", " # Figure out type info -- Do as tuple so its hashable", " signature = tuple( map(lookup_type,args) )", "", " # If we know the function, call it", " try:", " return self.__call_map[signature](*args)", " except:", " fast = self.singleton(signature)", " self.__call_map[signature] = fast", " return fast(*args)", "", " def signature(self,*args):", " # Figure out type info -- Do as tuple so its hashable", " signature = tuple( map(lookup_type,args) )", " return self.singleton(signature)", "", "", " def singleton(self,signature):", " identifier = self.identifier(signature)", "", " # Generate a new function, then call it", " f = self.function", "", " # See if we have an accelerated version of module", " try:", " accelerated_module = __import__(self.module.__name__+'_weave')", " fast = getattr(accelerated_module,identifier)", " return fast", " except:", " accelerated_module = None", "", " P = self.accelerate(signature,identifier)", "", " E = weave.ext_tools.ext_module(self.module.__name__+'_weave')", " E.add_function(P)", " E.generate_file()", " weave.build_tools.build_extension(self.module.__name__+'_weave.cpp',verbose=2)", "", " if accelerated_module:", " accelerated_module = reload(accelerated_module)", " else:", " accelerated_module = __import__(self.module.__name__+'_weave')", "", " fast = getattr(accelerated_module,identifier)", " return fast", "", " def identifier(self,signature):", " # Build an MD5 checksum", " f = self.function", " co = f.func_code", " identifier = str(signature)+\\", " str(co.co_consts)+\\", " str(co.co_varnames)+\\", " co.co_code", " return 'F'+md5.md5(identifier).hexdigest()", "", " def accelerate(self,signature,identifier):", " P = Python2CXX(self.function,signature,name=identifier)", " return P", "", " def code(self,*args):", " signature = tuple( map(lookup_type,args) )", " ident = self.function.__name__", " return self.accelerate(signature,ident).function_code()", "", "", "##################################################################", "# CLASS PYTHON2CXX #", "##################################################################", "class Python2CXX(bytecodecompiler.CXXCoder):", " def typedef_by_value(self,v):", " T = lookup_type(v)", " if T not in self.used: self.used.append(T)", " return T", "", " def __init__(self,f,signature,name=None):", " # Make sure function is a function", " import types", " assert type(f) == FunctionType", " # and check the input type signature", " assert reduce(lambda x,y: x and y,", " map(lambda x: isinstance(x,bytecodecompiler.Type_Descriptor),", " signature),", " 1),'%s not all type objects'%signature", " self.arg_specs = []", " self.customize = weave.base_info.custom_info()", "", " bytecodecompiler.CXXCoder.__init__(self,f,signature,name)", " return", "", " def function_code(self):", " return self.wrapped_code()", "", " def python_function_definition_code(self):", " return '{ \"%s\", wrapper_%s, METH_VARARGS, %s },\\n'%(", " self.name,", " self.name,", " CStr(self.function.__doc__))" ], "deleted": [] } }, { "old_path": null, "new_path": "weave/bytecodecompiler.py", "filename": "bytecodecompiler.py", "extension": "py", "change_type": "ADD", "diff": "@@ -0,0 +1,1204 @@\n+#**************************************************************************#\n+#* FILE ************** bytecodecompiler.py ************************#\n+#************************************************************************ **#\n+#* Author: Patrick Miller February 9 2002 *#\n+#* Copyright (C) 2002 Patrick J. Miller *#\n+#**************************************************************************#\n+#* *#\n+#**************************************************************************#\n+from types import *\n+import string\n+import inspect\n+\n+\n+##################################################################\n+# CLASS CXXTYPEDESCRIPTION #\n+##################################################################\n+class Type_Descriptor:\n+ prerequisites = []\n+ def __repr__(self):\n+ return self.__module__+'.'+self.__class__.__name__\n+\n+\n+haveArgument = 90 # Opcodes greater-equal to this have argument\n+byName = {\n+ 'STOP_CODE': 0,\n+ 'POP_TOP': 1,\n+ 'ROT_TWO': 2,\n+ 'ROT_THREE': 3,\n+ 'DUP_TOP': 4,\n+ 'ROT_FOUR': 5,\n+ 'UNARY_POSITIVE': 10,\n+ 'UNARY_NEGATIVE': 11,\n+ 'UNARY_NOT': 12,\n+ 'UNARY_CONVERT': 13,\n+ 'UNARY_INVERT': 15,\n+ 'BINARY_POWER': 19,\n+ 'BINARY_MULTIPLY': 20,\n+ 'BINARY_DIVIDE': 21,\n+ 'BINARY_MODULO': 22,\n+ 'BINARY_ADD': 23,\n+ 'BINARY_SUBTRACT': 24,\n+ 'BINARY_SUBSCR': 25,\n+ 'BINARY_FLOOR_DIVIDE': 26,\n+ 'BINARY_TRUE_DIVIDE': 27,\n+ 'INPLACE_FLOOR_DIVIDE': 28,\n+ 'INPLACE_TRUE_DIVIDE': 29,\n+ 'SLICE': 30,\n+ 'STORE_SLICE': 40,\n+ 'DELETE_SLICE': 50,\n+ 'INPLACE_ADD': 55,\n+ 'INPLACE_SUBTRACT': 56,\n+ 'INPLACE_MULTIPLY': 57,\n+ 'INPLACE_DIVIDE': 58,\n+ 'INPLACE_MODULO': 59,\n+ 'STORE_SUBSCR': 60,\n+ 'DELETE_SUBSCR': 61,\n+ 'BINARY_LSHIFT': 62,\n+ 'BINARY_RSHIFT': 63,\n+ 'BINARY_AND': 64,\n+ 'BINARY_XOR': 65,\n+ 'BINARY_OR': 66,\n+ 'INPLACE_POWER': 67,\n+ 'GET_ITER': 68,\n+ 'PRINT_EXPR': 70,\n+ 'PRINT_ITEM': 71,\n+ 'PRINT_NEWLINE': 72,\n+ 'PRINT_ITEM_TO': 73,\n+ 'PRINT_NEWLINE_TO': 74,\n+ 'INPLACE_LSHIFT': 75,\n+ 'INPLACE_RSHIFT': 76,\n+ 'INPLACE_AND': 77,\n+ 'INPLACE_XOR': 78,\n+ 'INPLACE_OR': 79,\n+ 'BREAK_LOOP': 80,\n+ 'LOAD_LOCALS': 82,\n+ 'RETURN_VALUE': 83,\n+ 'IMPORT_STAR': 84,\n+ 'EXEC_STMT': 85,\n+ 'YIELD_VALUE': 86,\n+ 'POP_BLOCK': 87,\n+ 'END_FINALLY': 88,\n+ 'BUILD_CLASS': 89,\n+ 'STORE_NAME': 90,\n+ 'DELETE_NAME': 91,\n+ 'UNPACK_SEQUENCE': 92,\n+ 'FOR_ITER': 93,\n+ 'STORE_ATTR': 95,\n+ 'DELETE_ATTR': 96,\n+ 'STORE_GLOBAL': 97,\n+ 'DELETE_GLOBAL': 98,\n+ 'DUP_TOPX': 99,\n+ 'LOAD_CONST': 100,\n+ 'LOAD_NAME': 101,\n+ 'BUILD_TUPLE': 102,\n+ 'BUILD_LIST': 103,\n+ 'BUILD_MAP': 104,\n+ 'LOAD_ATTR': 105,\n+ 'COMPARE_OP': 106,\n+ 'IMPORT_NAME': 107,\n+ 'IMPORT_FROM': 108,\n+ 'JUMP_FORWARD': 110,\n+ 'JUMP_IF_FALSE': 111,\n+ 'JUMP_IF_TRUE': 112,\n+ 'JUMP_ABSOLUTE': 113,\n+ 'FOR_LOOP': 114,\n+ 'LOAD_GLOBAL': 116,\n+ 'CONTINUE_LOOP': 119,\n+ 'SETUP_LOOP': 120,\n+ 'SETUP_EXCEPT': 121,\n+ 'SETUP_FINALLY': 122,\n+ 'LOAD_FAST': 124,\n+ 'STORE_FAST': 125,\n+ 'DELETE_FAST': 126,\n+ 'SET_LINENO': 127,\n+ 'RAISE_VARARGS': 130,\n+ 'CALL_FUNCTION': 131,\n+ 'MAKE_FUNCTION': 132,\n+ 'BUILD_SLICE': 133,\n+ 'MAKE_CLOSURE': 134,\n+ 'LOAD_CLOSURE': 135,\n+ 'LOAD_DEREF': 136,\n+ 'STORE_DEREF': 137,\n+ 'CALL_FUNCTION_VAR': 140,\n+ 'CALL_FUNCTION_KW': 141,\n+ 'CALL_FUNCTION_VAR_KW': 142,\n+ }\n+\n+# -----------------------------------------------\n+# Build one in the reverse sense\n+# -----------------------------------------------\n+byOpcode = {}\n+for name,op in map(None, byName.keys(), byName.values()):\n+ byOpcode[op] = name\n+ del name\n+ del op\n+ \n+\n+##################################################################\n+# FUNCTION OPCODIZE #\n+##################################################################\n+def opcodize(s):\n+ \"Slightly more readable form\"\n+ length = len(s)\n+ i = 0\n+ answer = []\n+ while i < length:\n+ bytecode = ord(s[i])\n+ name = byOpcode[bytecode]\n+ if bytecode >= haveArgument:\n+ argument = 256*ord(s[i+2])+ord(s[i+1])\n+ i += 3\n+ else:\n+ argument = None\n+ i += 1\n+ answer.append((bytecode,argument,name))\n+ return answer\n+\n+\n+\n+##################################################################\n+# FUNCTION LIST #\n+##################################################################\n+def listing(f):\n+ \"Pretty print the internals of your function\"\n+ assert type(f) == FunctionType,\"Arg %r must be a function\"%f\n+ filename = f.func_code.co_filename\n+ try:\n+ lines = open(filename).readlines()\n+ except:\n+ lines = None\n+ pc = 0\n+ s = ''\n+ lastLine = None\n+ for op,arg,name in opcodize(f.func_code.co_code):\n+ if lines and name == 'SET_LINENO':\n+ source = lines[arg-1][:-1]\n+ while lastLine and lastLine < arg-1:\n+ nonEmittingSource = lines[lastLine][:-1]\n+ lastLine += 1\n+ s += '%3s %20s %5s : %s\\n'%(\n+ '','','',nonEmittingSource)\n+ lastLine = arg\n+ else:\n+ source = ''\n+ if arg == None: arg = ''\n+ s += '%3d] %20s %5s : %s\\n'%(pc,name,arg,source)\n+ pc += 1\n+ return s\n+\n+##################################################################\n+# CLASS BYTECODEMEANING #\n+##################################################################\n+class ByteCodeMeaning:\n+ def fetch(self, pc,code):\n+ opcode = ord(code[pc])\n+ if opcode >= haveArgument:\n+ argument = 256*ord(code[pc+2])+ord(code[pc+1])\n+ next = pc+3\n+ else:\n+ argument = None\n+ next = pc+1\n+ return next,opcode,argument\n+ \n+ def execute(self,pc,opcode,argument):\n+ name = byOpcode[opcode]\n+ method = getattr(self,name)\n+ if argument == None:\n+ return apply(method,(pc,))\n+ else:\n+ return apply(method,(pc,argument,))\n+\n+ def evaluate(self, pc,code):\n+ next, opcode,argument = self.fetch(pc,code)\n+ goto = self.execute(next,opcode,argument)\n+ if goto == -1:\n+ return None # Must be done\n+ elif goto == None:\n+ return next # Normal\n+ else:\n+ raise 'xx'\n+\n+ symbols = { 0: 'less', 1: 'lesseq', 2: 'equal', 3: 'notequal',\n+ 4: 'greater', 5: 'greatereq', 6: 'in', 7: 'not in',\n+ 8: 'is', 9: 'is not', 10: 'exe match',\n+ 11 : 'bad',\n+ }\n+ def cmp_op(self,opname):\n+ return self.symbols[opname]\n+ \n+ def STOP_CODE(self,pc):\n+ \"Indicates end-of-code to the compiler, not used by the interpreter.\"\n+ raise NotImplementedError\n+ def POP_TOP(self,pc):\n+ \"Removes the top-of-stack (TOS) item.\"\n+ raise NotImplementedError\n+\n+ def ROT_TWO(self,pc):\n+ \"Swaps the two top-most stack items.\"\n+ raise NotImplementedError\n+\n+ def ROT_THREE(self,pc):\n+ \"Lifts second and third stack item one position up, moves top down to position three.\"\n+ raise NotImplementedError\n+\n+ def ROT_FOUR(self,pc):\n+ \"Lifts second, third and forth stack item one position up, moves top down to position four.\"\n+ raise NotImplementedError\n+\n+ def DUP_TOP(self,pc):\n+ \"Duplicates the reference on top of the stack.\"\n+ raise NotImplementedError\n+\n+ # Unary Operations take the top of the stack, apply the operation, and push the result back on the stack.\n+\n+ def UNARY_POSITIVE(self,pc):\n+ \"Implements TOS = +TOS.\"\n+ raise NotImplementedError\n+\n+ def UNARY_NEGATIVE(self,pc):\n+ \"Implements TOS = -TOS.\"\n+ raise NotImplementedError\n+\n+ def UNARY_NOT(self,pc):\n+ \"Implements TOS = not TOS.\"\n+ raise NotImplementedError\n+\n+ def UNARY_CONVERT(self,pc):\n+ \"Implements TOS = `TOS`.\"\n+ raise NotImplementedError\n+\n+ def UNARY_INVERT(self,pc):\n+ \"Implements TOS = ~TOS.\"\n+ raise NotImplementedError\n+\n+ #Binary operations remove the top of the stack (TOS) and the second top-most stack item (TOS1) from the stack. They perform the operation, and put the result back on the stack.\n+\n+ def BINARY_POWER(self,pc):\n+ \"Implements TOS = TOS1 ** TOS.\"\n+ raise NotImplementedError\n+\n+ def BINARY_MULTIPLY(self,pc):\n+ \"Implements TOS = TOS1 * TOS.\"\n+ raise NotImplementedError\n+\n+ def BINARY_DIVIDE(self,pc):\n+ \"Implements TOS = TOS1 / TOS.\"\n+ raise NotImplementedError\n+\n+ def BINARY_MODULO(self,pc):\n+ \"Implements TOS = TOS1 % TOS.\"\n+ raise NotImplementedError\n+\n+ def BINARY_ADD(self,pc):\n+ \"Implements TOS = TOS1 + TOS.\"\n+ raise NotImplementedError\n+\n+ def BINARY_SUBTRACT(self,pc):\n+ \"Implements TOS = TOS1 - TOS.\"\n+ raise NotImplementedError\n+\n+ def BINARY_SUBSCR(self,pc):\n+ \"Implements TOS = TOS1[TOS].\"\n+ raise NotImplementedError\n+\n+ def BINARY_LSHIFT(self,pc):\n+ \"Implements TOS = TOS1 << TOS.\"\n+ raise NotImplementedError\n+\n+ def BINARY_RSHIFT(self,pc):\n+ \"Implements TOS = TOS1 >> TOS.\"\n+ raise NotImplementedError\n+\n+ def BINARY_AND(self,pc):\n+ \"Implements TOS = TOS1 & TOS.\"\n+ raise NotImplementedError\n+\n+ def BINARY_XOR(self,pc):\n+ \"Implements TOS = TOS1 ^ TOS.\"\n+ raise NotImplementedError\n+\n+ def BINARY_OR(self,pc):\n+ \"Implements TOS = TOS1 | TOS.\"\n+ raise NotImplementedError\n+\n+ #In-place operations are like binary operations, in that they remove TOS and TOS1, and push the result back on the stack, but the operation is done in-place when TOS1 supports it, and the resulting TOS may be (but does not have to be) the original TOS1.\n+\n+ def INPLACE_POWER(self,pc):\n+ \"Implements in-place TOS = TOS1 ** TOS.\"\n+ raise NotImplementedError\n+\n+ def INPLACE_MULTIPLY(self,pc):\n+ \"Implements in-place TOS = TOS1 * TOS.\"\n+ raise NotImplementedError\n+\n+ def INPLACE_DIVIDE(self,pc):\n+ \"Implements in-place TOS = TOS1 / TOS.\"\n+ raise NotImplementedError\n+\n+ def INPLACE_MODULO(self,pc):\n+ \"Implements in-place TOS = TOS1 % TOS.\"\n+ raise NotImplementedError\n+\n+ def INPLACE_ADD(self,pc):\n+ \"Implements in-place TOS = TOS1 + TOS.\"\n+ raise NotImplementedError\n+\n+ def INPLACE_SUBTRACT(self,pc):\n+ \"Implements in-place TOS = TOS1 - TOS.\"\n+ raise NotImplementedError\n+\n+ def INPLACE_LSHIFT(self,pc):\n+ \"Implements in-place TOS = TOS1 << TOS.\"\n+ raise NotImplementedError\n+\n+ def INPLACE_RSHIFT(self,pc):\n+ \"Implements in-place TOS = TOS1 >> TOS.\"\n+ raise NotImplementedError\n+\n+ def INPLACE_AND(self,pc):\n+ \"Implements in-place TOS = TOS1 & TOS.\"\n+ raise NotImplementedError\n+\n+ def INPLACE_XOR(self,pc):\n+ \"Implements in-place TOS = TOS1 ^ TOS.\"\n+ raise NotImplementedError\n+\n+ def INPLACE_OR(self,pc):\n+ \"Implements in-place TOS = TOS1 | TOS.\"\n+ raise NotImplementedError\n+\n+ #The slice opcodes take up to three parameters.\n+\n+ def SLICE_0(self,pc):\n+ \"Implements TOS = TOS[:].\"\n+ raise NotImplementedError\n+\n+ def SLICE_1(self,pc):\n+ \"Implements TOS = TOS1[TOS:].\"\n+ raise NotImplementedError\n+\n+ def SLICE_2(self,pc):\n+ \"Implements TOS = TOS1[:TOS1].\"\n+ raise NotImplementedError\n+\n+ def SLICE_3(self,pc):\n+ \"Implements TOS = TOS2[TOS1:TOS].\"\n+ raise NotImplementedError\n+\n+ #Slice assignment needs even an additional parameter. As any statement, they put nothing on the stack.\n+\n+ def STORE_SLICE_0(self,pc):\n+ \"Implements TOS[:] = TOS1.\"\n+ raise NotImplementedError\n+\n+ def STORE_SLICE_1(self,pc):\n+ \"Implements TOS1[TOS:] = TOS2.\"\n+ raise NotImplementedError\n+\n+ def STORE_SLICE_2(self,pc):\n+ \"Implements TOS1[:TOS] = TOS2.\"\n+ raise NotImplementedError\n+\n+ def STORE_SLICE_3(self,pc):\n+ \"Implements TOS2[TOS1:TOS] = TOS3.\"\n+ raise NotImplementedError\n+\n+ def DELETE_SLICE_0(self,pc):\n+ \"Implements del TOS[:].\"\n+ raise NotImplementedError\n+\n+ def DELETE_SLICE_1(self,pc):\n+ \"Implements del TOS1[TOS:].\"\n+ raise NotImplementedError\n+\n+ def DELETE_SLICE_2(self,pc):\n+ \"Implements del TOS1[:TOS].\"\n+ raise NotImplementedError\n+\n+ def DELETE_SLICE_3(self,pc):\n+ \"Implements del TOS2[TOS1:TOS].\"\n+ raise NotImplementedError\n+\n+ def STORE_SUBSCR(self,pc):\n+ \"Implements TOS1[TOS] = TOS2.\"\n+ raise NotImplementedError\n+\n+ def DELETE_SUBSCR(self,pc):\n+ \"Implements del TOS1[TOS].\"\n+ raise NotImplementedError\n+\n+ def PRINT_EXPR(self,pc):\n+ \"Implements the expression statement for the interactive mode. TOS is removed from the stack and printed. In non-interactive mode, an expression statement is terminated with POP_STACK.\"\n+ raise NotImplementedError\n+\n+ def PRINT_ITEM(self,pc):\n+ \"Prints TOS to the file-like object bound to sys.stdout. There is one such instruction for each item in the print statement.\"\n+ raise NotImplementedError\n+\n+ def PRINT_ITEM_TO(self,pc):\n+ \"Like PRINT_ITEM, but prints the item second from TOS to the file-like object at TOS. This is used by the extended print statement.\"\n+ raise NotImplementedError\n+\n+ def PRINT_NEWLINE(self,pc):\n+ \"Prints a new line on sys.stdout. This is generated as the last operation of a print statement, unless the statement ends with a comma.\"\n+ raise NotImplementedError\n+\n+ def PRINT_NEWLINE_TO(self,pc):\n+ \"Like PRINT_NEWLINE, but prints the new line on the file-like object on the TOS. This is used by the extended print statement.\"\n+ raise NotImplementedError\n+\n+ def BREAK_LOOP(self,pc):\n+ \"Terminates a loop due to a break statement.\"\n+ raise NotImplementedError\n+\n+ def LOAD_LOCALS(self,pc):\n+ \"Pushes a reference to the locals of the current scope on the stack. This is used in the code for a class definition: After the class body is evaluated, the locals are passed to the class definition.\"\n+ raise NotImplementedError\n+\n+ def RETURN_VALUE(self,pc):\n+ \"Returns with TOS to the caller of the function.\"\n+ raise NotImplementedError\n+\n+ def IMPORT_STAR(self,pc):\n+ \"Loads all symbols not starting with _ directly from the module TOS to the local namespace. The module is popped after loading all names. This opcode implements from module import *.\"\n+ raise NotImplementedError\n+\n+ def EXEC_STMT(self,pc):\n+ \"Implements exec TOS2,TOS1,TOS. The compiler fills missing optional parameters with None.\"\n+ raise NotImplementedError\n+\n+ def POP_BLOCK(self,pc):\n+ \"Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.\"\n+ raise NotImplementedError\n+\n+ def END_FINALLY(self,pc):\n+ \"Terminates a finally clause. The interpreter recalls whether the exception has to be re-raised, or whether the function returns, and continues with the outer-next block.\"\n+ raise NotImplementedError\n+\n+ def BUILD_CLASS(self,pc):\n+ \"Creates a new class object. TOS is the methods dictionary, TOS1 the tuple of the names of the base classes, and TOS2 the class name.\"\n+ raise NotImplementedError\n+\n+ #All of the following opcodes expect arguments. An argument is two bytes, with the more significant byte last.\n+\n+ def STORE_NAME(self,pc,namei):\n+ \"Implements name = TOS. namei is the index of name in the attribute co_names of the code object. The compiler tries to use STORE_LOCAL or STORE_GLOBAL if possible.\"\n+ raise NotImplementedError\n+\n+ def DELETE_NAME(self,pc,namei):\n+ \"Implements del name, where namei is the index into co_names attribute of the code object.\"\n+ raise NotImplementedError\n+\n+ def UNPACK_SEQUENCE(self,pc,count):\n+ \"Unpacks TOS into count individual values, which are put onto the stack right-to-left.\"\n+ raise NotImplementedError\n+\n+ def DUP_TOPX(self,pc,count):\n+ \"Duplicate count items, keeping them in the same order. Due to implementation limits, count should be between 1 and 5 inclusive.\"\n+ raise NotImplementedError\n+\n+ def STORE_ATTR(self,pc,namei):\n+ \"Implements TOS.name = TOS1, where namei is the index of name in co_names.\"\n+ raise NotImplementedError\n+\n+ def DELETE_ATTR(self,pc,namei):\n+ \"Implements del TOS.name, using namei as index into co_names.\"\n+ raise NotImplementedError\n+\n+ def STORE_GLOBAL(self,pc,namei):\n+ \"Works as STORE_NAME, but stores the name as a global.\"\n+ raise NotImplementedError\n+\n+ def DELETE_GLOBAL(self,pc,namei):\n+ \"Works as DELETE_NAME, but deletes a global name.\"\n+ raise NotImplementedError\n+\n+ def LOAD_CONST(self,pc,consti):\n+ \"Pushes co_consts[consti] onto the stack.\"\n+ raise NotImplementedError\n+\n+ def LOAD_NAME(self,pc,namei):\n+ \"Pushes the value associated with co_names[namei] onto the stack.\"\n+ raise NotImplementedError\n+\n+ def BUILD_TUPLE(self,pc,count):\n+ \"Creates a tuple consuming count items from the stack, and pushes the resulting tuple onto the stack.\"\n+ raise NotImplementedError\n+\n+ def BUILD_LIST(self,pc,count):\n+ \"Works as BUILD_TUPLE, but creates a list.\"\n+ raise NotImplementedError\n+\n+ def BUILD_MAP(self,pc,zero):\n+ \"Pushes a new empty dictionary object onto the stack. The argument is ignored and set to zero by the compiler.\"\n+ raise NotImplementedError\n+\n+ def LOAD_ATTR(self,pc,namei):\n+ \"Replaces TOS with getattr(TOS, co_names[namei].\"\n+ raise NotImplementedError\n+\n+ def COMPARE_OP(self,pc,opname):\n+ \"Performs a Boolean operation. The operation name can be found in cmp_op[opname].\"\n+ raise NotImplementedError\n+\n+ def IMPORT_NAME(self,pc,namei):\n+ \"Imports the module co_names[namei]. The module object is pushed onto the stack. The current namespace is not affected: for a proper import statement, a subsequent STORE_FAST instruction modifies the namespace.\"\n+ raise NotImplementedError\n+\n+ def IMPORT_FROM(self,pc,namei):\n+ \"Loads the attribute co_names[namei] from the module found in TOS. The resulting object is pushed onto the stack, to be subsequently stored by a STORE_FAST instruction.\"\n+ raise NotImplementedError\n+\n+ def JUMP_FORWARD(self,pc,delta):\n+ \"Increments byte code counter by delta.\"\n+ raise NotImplementedError\n+\n+ def JUMP_IF_TRUE(self,pc,delta):\n+ \"If TOS is true, increment the byte code counter by delta. TOS is left on the stack.\"\n+ raise NotImplementedError\n+\n+ def JUMP_IF_FALSE(self,pc,delta):\n+ \"If TOS is false, increment the byte code counter by delta. TOS is not changed.\"\n+ raise NotImplementedError\n+\n+ def JUMP_ABSOLUTE(self,pc,target):\n+ \"Set byte code counter to target.\"\n+ raise NotImplementedError\n+\n+ def FOR_LOOP(self,pc,delta):\n+ \"Iterate over a sequence. TOS is the current index, TOS1 the sequence. First, the next element is computed. If the sequence is exhausted, increment byte code counter by delta. Otherwise, push the sequence, the incremented counter, and the current item onto the stack.\"\n+ raise NotImplementedError\n+\n+ def LOAD_GLOBAL(self,pc,namei):\n+ \"Loads the global named co_names[namei] onto the stack.\"\n+ raise NotImplementedError\n+\n+ def SETUP_LOOP(self,pc,delta):\n+ \"Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.\"\n+ raise NotImplementedError\n+\n+ def SETUP_EXCEPT(self,pc,delta):\n+ \"Pushes a try block from a try-except clause onto the block stack. delta points to the first except block.\"\n+ raise NotImplementedError\n+\n+ def SETUP_FINALLY(self,pc,delta):\n+ \"Pushes a try block from a try-except clause onto the block stack. delta points to the finally block.\"\n+ raise NotImplementedError\n+\n+ def LOAD_FAST(self,pc,var_num):\n+ \"Pushes a reference to the local co_varnames[var_num] onto the stack.\"\n+ raise NotImplementedError\n+\n+ def STORE_FAST(self,pc,var_num):\n+ \"Stores TOS into the local co_varnames[var_num].\"\n+ raise NotImplementedError\n+\n+ def DELETE_FAST(self,pc,var_num):\n+ \"Deletes local co_varnames[var_num].\"\n+ raise NotImplementedError\n+\n+ def LOAD_CLOSURE(self,pc,i):\n+ \"Pushes a reference to the cell contained in slot i of the cell and free variable storage. The name of the variable is co_cellvars[i] if i is less than the length of co_cellvars. Otherwise it is co_freevars[i - len(co_cellvars)].\"\n+ raise NotImplementedError\n+\n+ def LOAD_DEREF(self,pc,i):\n+ \"Loads the cell contained in slot i of the cell and free variable storage. Pushes a reference to the object the cell contains on the stack.\"\n+ raise NotImplementedError\n+\n+ def STORE_DEREF(self,pc,i):\n+ \"Stores TOS into the cell contained in slot i of the cell and free variable storage.\"\n+ raise NotImplementedError\n+\n+ def SET_LINENO(self,pc,lineno):\n+ \"Sets the current line number to lineno.\"\n+ raise NotImplementedError\n+\n+ def RAISE_VARARGS(self,pc,argc):\n+ \"Raises an exception. argc indicates the number of parameters to the raise statement, ranging from 0 to 3. The handler will find the traceback as TOS2, the parameter as TOS1, and the exception as TOS.\"\n+ raise NotImplementedError\n+\n+ def CALL_FUNCTION(self,pc,argc):\n+ \"Calls a function. The low byte of argc indicates the number of positional parameters, the high byte the number of keyword parameters. On the stack, the opcode finds the keyword parameters first. For each keyword argument, the value is on top of the key. Below the keyword parameters, the positional parameters are on the stack, with the right-most parameter on top. Below the parameters, the function object to call is on the stack.\"\n+ raise NotImplementedError\n+\n+ def MAKE_FUNCTION(self,pc,argc):\n+ \"Pushes a new function object on the stack. TOS is the code associated with the function. The function object is defined to have argc default parameters, which are found below TOS.\"\n+ raise NotImplementedError\n+\n+ def MAKE_CLOSURE(self,pc,argc):\n+ \"Creates a new function object, sets its func_closure slot, and pushes it on the stack. TOS is the code associated with the function. If the code object has N free variables, the next N items on the stack are the cells for these variables. The function also has argc default parameters, where are found before the cells.\"\n+ raise NotImplementedError\n+\n+ def BUILD_SLICE(self,pc,argc):\n+ \"Pushes a slice object on the stack. argc must be 2 or 3. If it is 2, slice(TOS1, TOS) is pushed; if it is 3, slice(TOS2, TOS1, TOS) is pushed. See the slice() built-in function for more information.\"\n+ raise NotImplementedError\n+\n+ def EXTENDED_ARG(self,pc,ext):\n+ \"Prefixes any opcode which has an argument too big to fit into the default two bytes. ext holds two additional bytes which, taken together with the subsequent opcode's argument, comprise a four-byte argument, ext being the two most-significant bytes.\"\n+ raise NotImplementedError\n+\n+ def CALL_FUNCTION_VAR(self,pc,argc):\n+ \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the variable argument list, followed by keyword and positional arguments.\"\n+ raise NotImplementedError\n+\n+ def CALL_FUNCTION_KW(self,pc,argc):\n+ \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by explicit keyword and positional arguments.\"\n+ raise NotImplementedError\n+\n+ def CALL_FUNCTION_VAR_KW(self,pc,argc):\n+ \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by the variable-arguments tuple, followed by explicit keyword and positional arguments.\"\n+ raise NotImplementedError\n+\n+ \n+\n+##################################################################\n+# CLASS CXXCODER #\n+##################################################################\n+class CXXCoder(ByteCodeMeaning):\n+\n+ ##################################################################\n+ # MEMBER TYPEDEF_BY_VALUE #\n+ ##################################################################\n+ def typedef_by_value(self,v):\n+ raise NotImplementedError # VIRTUAL\n+ \n+ ##################################################################\n+ # MEMBER __INIT__ #\n+ ##################################################################\n+ def __init__(self,function,signature,name=None):\n+ assert type(function) == FunctionType,\"Arg must be a user function\"\n+ assert not function.func_defaults ,\"Function cannot have default args (yet)\"\n+ if name == None: name = function.func_name\n+ self.name = name\n+ self.function = function\n+ self.signature = signature\n+ self.codeobject = function.func_code\n+ self.__uid = 0 # Builds temps\n+ return\n+\n+ ##################################################################\n+ # MEMBER EVALUATE #\n+ ##################################################################\n+ def evaluate(self, pc,code):\n+ # See if we posted any forwards for this offset\n+ if self.forwards.has_key(pc):\n+ for f in self.forwards[pc]:\n+ f()\n+ self.forwards[pc] = []\n+ return ByteCodeMeaning.evaluate(self,pc,code)\n+ \n+ ##################################################################\n+ # MEMBER GENERATE #\n+ ##################################################################\n+ def generate(self):\n+ self.forwards = {} # Actions on forward interprets\n+ self.__body = '' # Body will be built\n+ self.helpers = [] # headers and stuff\n+\n+ # -----------------------------------------------\n+ # OK, crack open the function object and build\n+ # initial stack (not a real frame!)\n+ # -----------------------------------------------\n+ arglen = len(self.signature)\n+ nlocals = self.codeobject.co_nlocals\n+\n+ self.consts = self.codeobject.co_consts\n+ self.stack = list(self.codeobject.co_varnames)\n+ self.types = list(self.signature)+[None]*(nlocals-arglen)\n+ self.used = []\n+ for T in self.types:\n+ if T not in self.used: self.used.append(T)\n+\n+ # -----------------------------------------------\n+ # One pass through the byte codes to generate\n+ # the body\n+ # -----------------------------------------------\n+ code = self.codeobject.co_code\n+ pc = 0\n+ while pc != None:\n+ pc = self.evaluate(pc,code)\n+\n+ # -----------------------------------------------\n+ # Return?\n+ # -----------------------------------------------\n+ if self.rtype == NoneType:\n+ rtype = 'void'\n+ else:\n+ rtype = self.rtype.cxxtype\n+ \n+ # -----------------------------------------------\n+ # Insert code body if available\n+ # -----------------------------------------------\n+ source = inspect.getsource(self.function)\n+ if not source: source = ''\n+ comments = inspect.getcomments(self.function)\n+ if comments: source = comments+source\n+ code = string.join(map(lambda x: '/////// '+x,string.split(source,'\\n')),\n+ '\\n')+'\\n'\n+\n+ # -----------------------------------------------\n+ # Add in the headers\n+ # -----------------------------------------------\n+ code += '#include \"Python.h\"\\n'\n+ for T in self.used:\n+ print T.prerequisites\n+ for pre in T.prerequisites:\n+ code += pre\n+ code += '\\n'\n+\n+ # -----------------------------------------------\n+ # Real body\n+ # -----------------------------------------------\n+ code += '\\n'\n+ code += '\\nstatic %s %s('%(rtype,self.name)\n+ for i in range(len(self.signature)):\n+ if i != 0: code += ', '\n+ n = self.stack[i]\n+ t = self.types[i]\n+ code += '%s %s'%(t.cxxtype,n)\n+ code += ') {\\n'\n+\n+ # Add in non-argument temporaries\n+ # Assuming first argcount locals are positional args\n+ for i in range(self.codeobject.co_argcount,\n+ self.codeobject.co_nlocals):\n+ t = self.types[i]\n+ descriptor = typedefs[t]\n+ code += '%s %s;\\n'%(\n+ descriptor.cxxtype,\n+ self.codeobject.co_varnames[i],\n+ )\n+\n+ # Add in the body\n+ code += self.__body\n+ code += '}\\n\\n'\n+ return code\n+\n+\n+ ##################################################################\n+ # MEMBER WRAPPED_CODE #\n+ ##################################################################\n+ def wrapped_code(self):\n+ code = self.generate()\n+ \n+ # -----------------------------------------------\n+ # Wrapper\n+ # -----------------------------------------------\n+ code += 'static PyObject* wrapper_%s(PyObject*,PyObject* args) {\\n'%self.name\n+\n+ code += ' // Length check\\n'\n+ code += ' if ( PyTuple_Size(args) != %d ) {\\n'%len(self.signature)\n+ code += ' PyErr_SetString(PyExc_TypeError,\"Expected %d arguments\");\\n'%len(self.signature)\n+ code += ' return 0;\\n'\n+ code += ' }\\n'\n+\n+ code += '\\n // Load Py versions of args\\n'\n+ for i in range(len(self.signature)):\n+ T = self.signature[i]\n+ code += ' PyObject* py_%s = PyTuple_GET_ITEM(args,%d);\\n'%(\n+ self.codeobject.co_varnames[i],i\n+ )\n+\n+ code += ' if ( !%s ) {\\n'% \\\n+ T.check('py_'+self.codeobject.co_varnames[i])\n+ code += ' PyErr_SetString(PyExc_TypeError,\"Bad type for arg %d (expected %s)\");\\n'%(\n+ i+1,\n+ T.__class__.__name__)\n+ code += ' return 0;\\n'\n+ code += ' }\\n'\n+ \n+ code += '\\n // Do conversions\\n'\n+ argnames = []\n+ for i in range(len(self.signature)):\n+ T = self.signature[i]\n+\n+ code += ' %s %s=%s;\\n'%(\n+ T.cxxtype,\n+ self.codeobject.co_varnames[i],\n+ T.inbound('py_'+self.codeobject.co_varnames[i]),\n+ )\n+ code += ' if ( PyErr_Occurred() ) return 0;\\n'\n+ argnames.append(self.codeobject.co_varnames[i])\n+\n+ code += '\\n // Compute result\\n'\n+ if self.rtype != NoneType:\n+ code += ' %s _result = '%(\n+ self.rtype.cxxtype,\n+ )\n+ else:\n+ code += ' '\n+ code += '%s(%s);\\n'%(\n+ self.name,\n+ string.join(argnames,','),\n+ )\n+\n+\n+ code += '\\n // Pack return\\n'\n+ if ( self.rtype == NoneType ):\n+ code += ' Py_INCREF(Py_None);\\n'\n+ code += ' return Py_None;\\n'\n+ else:\n+ result = self.rtype.outbound('_result')\n+ code += ' return %s;\\n'%result\n+ code += '}\\n'\n+ return code\n+\n+\n+ ##################################################################\n+ # MEMBER EMIT #\n+ ##################################################################\n+ def emit(self,s):\n+ self.__body += s\n+ self.__body += '\\n'\n+ return\n+\n+ ##################################################################\n+ # MEMBER PUSH #\n+ ##################################################################\n+ def push(self,v,t):\n+ self.stack.append(v)\n+ self.types.append(t)\n+ return\n+\n+\n+ ##################################################################\n+ # MEMBER POP #\n+ ##################################################################\n+ def pop(self):\n+ v = self.stack[-1]\n+ del self.stack[-1]\n+ t = self.types[-1]\n+ del self.types[-1]\n+ return v,t\n+\n+ ##################################################################\n+ # MEMBER UNIQUE #\n+ ##################################################################\n+ def unique(self):\n+ self.__uid += 1\n+ return 't%d'%self.__uid\n+\n+ ##################################################################\n+ # MEMBER POST #\n+ ##################################################################\n+ def post(self,pc,action):\n+ if not self.forwards.has_key(pc):\n+ self.forwards[pc] = []\n+ self.forwards[pc].append(action)\n+ return\n+\n+ ##################################################################\n+ # MEMBER EMIT_VALUE #\n+ ##################################################################\n+ def emit_value(self, v):\n+ descriptor = self.typedef_by_value(v)\n+ \n+ # Convert representation to CXX rhs\n+ rhs = descriptor.literalizer(v)\n+ lhs = self.unique()\n+ self.emit('%s %s = %s;'%(\n+ descriptor.cxxtype,\n+ lhs,\n+ rhs))\n+ self.push(lhs,descriptor)\n+ return \n+\n+ ##################################################################\n+ # MEMBER GLOBAL_INFO #\n+ ##################################################################\n+ def global_info(self,var_num):\n+ # This is the name value is known by\n+ var_name = self.codeobject.co_names[var_num]\n+\n+ # First, figure out who owns this global\n+ import sys\n+ myHash = id(self.function.func_globals)\n+ for module_name in sys.modules.keys():\n+ module = sys.modules[module_name]\n+ if module and id(module.__dict__) == myHash:\n+ break\n+ else:\n+ raise ValueError,'Cannot locate module owning %s'%varname\n+ return module_name,var_name\n+\n+ ##################################################################\n+ # MEMBER BINOP #\n+ ##################################################################\n+ def binop(self,pc,symbol):\n+ v2,t2 = self.pop()\n+ v1,t1 = self.pop()\n+\n+ if t1 == t2:\n+ rhs,rhs_type = t1.binop(symbol,v1,v2)\n+ else:\n+ raise NotImplementedError,'mixed types'\n+ \n+ lhs = self.unique()\n+ self.emit('%s %s = %s;\\n'%(\n+ rhs_type.cxxtype,\n+ lhs,\n+ rhs))\n+ self.push(lhs,rhs_type)\n+ return \n+\n+ ##################################################################\n+ # MEMBER BINARY_XXX #\n+ ##################################################################\n+ def BINARY_ADD(self,pc):\n+ return self.binop(pc,'+')\n+ def BINARY_SUBTRACT(self,pc):\n+ return self.binop(pc,'-')\n+ def BINARY_MULTIPLY(self,pc):\n+ return self.binop(pc,'*')\n+ def BINARY_DIVIDE(self,pc):\n+ return self.binop(pc,'/')\n+ def BINARY_MODULO(self,pc):\n+ return self.binop(pc,'%')\n+ def COMPARE_OP(self,pc,opname):\n+ symbol = self.cmp_op(opname) # convert numeric to name\n+ return self.binop(pc,symbol)\n+\n+\n+ ##################################################################\n+ # MEMBER PRINT_ITEM #\n+ ##################################################################\n+ def PRINT_ITEM(self,pc):\n+ # Printing correctly is tricky... best to let Python\n+ # do the real work here\n+ w = self.unique()\n+ self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n+ self.emit('if (PyFile_SoftSpace(%s,1)) PyFile_WriteString(\" \",%s);'%(w,w))\n+ v,t = self.pop()\n+\n+ py = self.unique()\n+ self.emit('PyObject* %s = %s;'%(py, t.outbound(v)))\n+ self.emit('PyFile_WriteObject(%s,%s,Py_PRINT_RAW);'%(\n+ py,w))\n+ self.emit('Py_XDECREF(%s);'%py)\n+ return\n+\n+\n+ ##################################################################\n+ # MEMBER PRINT_NEWLINE #\n+ ##################################################################\n+ def PRINT_NEWLINE(self,pc):\n+ # Printing correctly is tricky... best to let Python\n+ # do the real work here\n+ w = self.unique()\n+ self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n+ self.emit('PyFile_WriteString(\"\\\\n\",%s);'%w);\n+ self.emit('PyFile_SoftSpace(%s,0);'%w);\n+ return\n+ \n+ ##################################################################\n+ # MEMBER SET_LINENO #\n+ ##################################################################\n+ def SET_LINENO(self,pc,lineno):\n+ self.emit('// %s:%d'%(self.codeobject.co_filename,lineno))\n+ return\n+\n+ ##################################################################\n+ # MEMBER POP_TOP #\n+ ##################################################################\n+ def POP_TOP(self,pc):\n+ v,t = self.pop()\n+ return\n+\n+ ##################################################################\n+ # MEMBER LOAD_CONST #\n+ ##################################################################\n+ def LOAD_CONST(self,pc,consti):\n+ # Fetch the constant\n+ k = self.consts[consti]\n+ t = type(k)\n+\n+ # Fetch a None is just skipped\n+ if t == NoneType:\n+ self.push('',t) \n+ return\n+\n+ self.emit_value(k)\n+ return\n+\n+\n+ ##################################################################\n+ # MEMBER LOAD_FAST #\n+ ##################################################################\n+ def LOAD_FAST(self,pc,var_num):\n+ v = self.stack[var_num]\n+ t = self.types[var_num]\n+ self.push(v,t)\n+ return\n+\n+ ##################################################################\n+ # MEMBER LOAD_GLOBAL #\n+ ##################################################################\n+ def LOAD_GLOBAL(self,pc,var_num):\n+ # Figure out the name and load it\n+ try:\n+ F = self.function.func_globals[self.codeobject.co_names[var_num]]\n+ except:\n+ F = getattr(__builtins__,self.codeobject.co_names[var_num])\n+\n+ # For functions, we see if we know about this function\n+ if callable(F):\n+ assert functiondefs.has_key(F),\"Function %s is known\"%F\n+ self.push(F,type(F))\n+ return\n+\n+ # We need the name of the module that matches\n+ # the global state for the function and\n+ # the name of the variable\n+ module_name,var_name = self.global_info(var_num)\n+\n+ # We hope it's type is correct\n+ t = type(F)\n+ descriptor = typedefs[t]\n+ native = self.unique()\n+ py = self.unique()\n+ mod = self.unique()\n+\n+ self.emit('')\n+ self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n+ mod,module_name))\n+ self.emit('PyObject* %s = PyObject_GetAttrString(%s,\"%s\");'%(\n+ py,mod,var_name))\n+ self.emit('%s %s = %s;'%(\n+ descriptor.cxxtype,\n+ native,\n+ descriptor.inbound%py))\n+\n+ self.push(native,t)\n+ return\n+\n+ ##################################################################\n+ # MEMBER STORE_FAST #\n+ ##################################################################\n+ def STORE_FAST(self,pc,var_num):\n+\n+ v,t = self.pop()\n+\n+ save = self.stack[var_num]\n+ saveT = self.types[var_num]\n+\n+ # See if type is same....\n+ # Note that None means no assignment made yet\n+ if saveT == None or t == saveT:\n+ self.emit('%s = %s;\\n'%(save,v))\n+ self.types[var_num] = t\n+ return\n+\n+ raise TypeError,(t,saveT)\n+\n+ ##################################################################\n+ # MEMBER STORE_GLOBAL #\n+ ##################################################################\n+ def STORE_GLOBAL(self,pc,var_num):\n+\n+ # We need the name of the module that matches\n+ # the global state for the function and\n+ # the name of the variable\n+ module_name,var_name = self.global_info(var_num)\n+\n+ # Convert the value to Python object\n+ v,t = self.pop()\n+ descriptor = typedefs[t]\n+ py = self.unique()\n+ self.emit('PyObject* %s = %s;'%(\n+ py,\n+ descriptor.outbound%v))\n+ mod = self.unique()\n+ self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n+ mod,module_name))\n+ self.emit('PyObject_SetAttrString(%s,\"%s\",%s);'%(\n+ mod,var_name,py))\n+ self.emit('Py_DECREF(%s);'%py)\n+ return\n+\n+ ##################################################################\n+ # MEMBER CALL_FUNCTION #\n+ ##################################################################\n+ def CALL_FUNCTION(self,pc,argc):\n+ # Pull args off stack\n+ args = []\n+ types = []\n+ for i in range(argc):\n+ v,t = self.pop()\n+ args = [v]+args\n+ types = [t]+types\n+ \n+ # Pull function object off stack and get descriptor\n+ f,t = self.pop()\n+ descriptor = functiondefs[f]\n+ #self.prerequisites += descriptor['prerequisite']+'\\n'\n+ \n+ # Look through descriptors for a match\n+ for inputs,outputs,format in descriptor:\n+ if inputs == types:\n+ break\n+ else:\n+ raise TypeError,f\n+\n+ # Build a rhs\n+ rhs = format%string.join(args,',')\n+\n+ # Build a statement\n+ assert len(outputs) == 1,\"Single valued return\"\n+ assert typedefs.has_key(outputs[0]),\"Know about type %s\"%outputs[0]\n+ description = typedefs[outputs[0]]\n+ temp = self.unique()\n+ self.emit('%s %s = %s;\\n'%(\n+ description.cxxtype,\n+ temp,\n+ rhs))\n+\n+ self.push(temp,outputs[0])\n+ return\n+\n+\n+ ##################################################################\n+ # MEMBER JUMP_IF_FALSE #\n+ ##################################################################\n+ def JUMP_IF_FALSE(self,pc,delta):\n+ v,t = self.pop()\n+ self.push(v,t)\n+ # We need to do some work when we get to the\n+ # else part (put the value that's gonna get\n+ # popped back on the stack, emit } else {,\n+ # ...)\n+ action = lambda v=v,t=t,self=self: (\n+ self.emit('} else {'),\n+ self.push(v,t),\n+ )\n+ self.post(pc+delta,action)\n+ if t != IntType: raise TypeError, 'Invalid comparison type %s'%t\n+ self.emit('if (%s) {\\n'%v)\n+ return\n+ \n+\n+ ##################################################################\n+ # MEMBER JUMP_FORWARD #\n+ ##################################################################\n+ def JUMP_FORWARD(self,pc,delta):\n+ # We need to close the if after the delta\n+ action = lambda self=self: (\n+ self.emit('}'),\n+ )\n+ self.post(pc+delta,action)\n+ return\n+ \n+ ##################################################################\n+ # MEMBER RETURN_VALUE #\n+ ##################################################################\n+ def RETURN_VALUE(self,pc):\n+ v,t = self.pop()\n+ if hasattr(self,'rtype'):\n+ raise ValueError,'multiple returns'\n+ self.rtype = t\n+ if t == NoneType:\n+ self.emit('return;')\n+ else:\n+ self.emit('return %s;'%v)\n+ return -1\n+\n", "added_lines": 1204, "deleted_lines": 0, "source_code": "#**************************************************************************#\n#* FILE ************** bytecodecompiler.py ************************#\n#************************************************************************ **#\n#* Author: Patrick Miller February 9 2002 *#\n#* Copyright (C) 2002 Patrick J. Miller *#\n#**************************************************************************#\n#* *#\n#**************************************************************************#\nfrom types import *\nimport string\nimport inspect\n\n\n##################################################################\n# CLASS CXXTYPEDESCRIPTION #\n##################################################################\nclass Type_Descriptor:\n prerequisites = []\n def __repr__(self):\n return self.__module__+'.'+self.__class__.__name__\n\n\nhaveArgument = 90 # Opcodes greater-equal to this have argument\nbyName = {\n 'STOP_CODE': 0,\n 'POP_TOP': 1,\n 'ROT_TWO': 2,\n 'ROT_THREE': 3,\n 'DUP_TOP': 4,\n 'ROT_FOUR': 5,\n 'UNARY_POSITIVE': 10,\n 'UNARY_NEGATIVE': 11,\n 'UNARY_NOT': 12,\n 'UNARY_CONVERT': 13,\n 'UNARY_INVERT': 15,\n 'BINARY_POWER': 19,\n 'BINARY_MULTIPLY': 20,\n 'BINARY_DIVIDE': 21,\n 'BINARY_MODULO': 22,\n 'BINARY_ADD': 23,\n 'BINARY_SUBTRACT': 24,\n 'BINARY_SUBSCR': 25,\n 'BINARY_FLOOR_DIVIDE': 26,\n 'BINARY_TRUE_DIVIDE': 27,\n 'INPLACE_FLOOR_DIVIDE': 28,\n 'INPLACE_TRUE_DIVIDE': 29,\n 'SLICE': 30,\n 'STORE_SLICE': 40,\n 'DELETE_SLICE': 50,\n 'INPLACE_ADD': 55,\n 'INPLACE_SUBTRACT': 56,\n 'INPLACE_MULTIPLY': 57,\n 'INPLACE_DIVIDE': 58,\n 'INPLACE_MODULO': 59,\n 'STORE_SUBSCR': 60,\n 'DELETE_SUBSCR': 61,\n 'BINARY_LSHIFT': 62,\n 'BINARY_RSHIFT': 63,\n 'BINARY_AND': 64,\n 'BINARY_XOR': 65,\n 'BINARY_OR': 66,\n 'INPLACE_POWER': 67,\n 'GET_ITER': 68,\n 'PRINT_EXPR': 70,\n 'PRINT_ITEM': 71,\n 'PRINT_NEWLINE': 72,\n 'PRINT_ITEM_TO': 73,\n 'PRINT_NEWLINE_TO': 74,\n 'INPLACE_LSHIFT': 75,\n 'INPLACE_RSHIFT': 76,\n 'INPLACE_AND': 77,\n 'INPLACE_XOR': 78,\n 'INPLACE_OR': 79,\n 'BREAK_LOOP': 80,\n 'LOAD_LOCALS': 82,\n 'RETURN_VALUE': 83,\n 'IMPORT_STAR': 84,\n 'EXEC_STMT': 85,\n 'YIELD_VALUE': 86,\n 'POP_BLOCK': 87,\n 'END_FINALLY': 88,\n 'BUILD_CLASS': 89,\n 'STORE_NAME': 90,\n 'DELETE_NAME': 91,\n 'UNPACK_SEQUENCE': 92,\n 'FOR_ITER': 93,\n 'STORE_ATTR': 95,\n 'DELETE_ATTR': 96,\n 'STORE_GLOBAL': 97,\n 'DELETE_GLOBAL': 98,\n 'DUP_TOPX': 99,\n 'LOAD_CONST': 100,\n 'LOAD_NAME': 101,\n 'BUILD_TUPLE': 102,\n 'BUILD_LIST': 103,\n 'BUILD_MAP': 104,\n 'LOAD_ATTR': 105,\n 'COMPARE_OP': 106,\n 'IMPORT_NAME': 107,\n 'IMPORT_FROM': 108,\n 'JUMP_FORWARD': 110,\n 'JUMP_IF_FALSE': 111,\n 'JUMP_IF_TRUE': 112,\n 'JUMP_ABSOLUTE': 113,\n 'FOR_LOOP': 114,\n 'LOAD_GLOBAL': 116,\n 'CONTINUE_LOOP': 119,\n 'SETUP_LOOP': 120,\n 'SETUP_EXCEPT': 121,\n 'SETUP_FINALLY': 122,\n 'LOAD_FAST': 124,\n 'STORE_FAST': 125,\n 'DELETE_FAST': 126,\n 'SET_LINENO': 127,\n 'RAISE_VARARGS': 130,\n 'CALL_FUNCTION': 131,\n 'MAKE_FUNCTION': 132,\n 'BUILD_SLICE': 133,\n 'MAKE_CLOSURE': 134,\n 'LOAD_CLOSURE': 135,\n 'LOAD_DEREF': 136,\n 'STORE_DEREF': 137,\n 'CALL_FUNCTION_VAR': 140,\n 'CALL_FUNCTION_KW': 141,\n 'CALL_FUNCTION_VAR_KW': 142,\n }\n\n# -----------------------------------------------\n# Build one in the reverse sense\n# -----------------------------------------------\nbyOpcode = {}\nfor name,op in map(None, byName.keys(), byName.values()):\n byOpcode[op] = name\n del name\n del op\n \n\n##################################################################\n# FUNCTION OPCODIZE #\n##################################################################\ndef opcodize(s):\n \"Slightly more readable form\"\n length = len(s)\n i = 0\n answer = []\n while i < length:\n bytecode = ord(s[i])\n name = byOpcode[bytecode]\n if bytecode >= haveArgument:\n argument = 256*ord(s[i+2])+ord(s[i+1])\n i += 3\n else:\n argument = None\n i += 1\n answer.append((bytecode,argument,name))\n return answer\n\n\n\n##################################################################\n# FUNCTION LIST #\n##################################################################\ndef listing(f):\n \"Pretty print the internals of your function\"\n assert type(f) == FunctionType,\"Arg %r must be a function\"%f\n filename = f.func_code.co_filename\n try:\n lines = open(filename).readlines()\n except:\n lines = None\n pc = 0\n s = ''\n lastLine = None\n for op,arg,name in opcodize(f.func_code.co_code):\n if lines and name == 'SET_LINENO':\n source = lines[arg-1][:-1]\n while lastLine and lastLine < arg-1:\n nonEmittingSource = lines[lastLine][:-1]\n lastLine += 1\n s += '%3s %20s %5s : %s\\n'%(\n '','','',nonEmittingSource)\n lastLine = arg\n else:\n source = ''\n if arg == None: arg = ''\n s += '%3d] %20s %5s : %s\\n'%(pc,name,arg,source)\n pc += 1\n return s\n\n##################################################################\n# CLASS BYTECODEMEANING #\n##################################################################\nclass ByteCodeMeaning:\n def fetch(self, pc,code):\n opcode = ord(code[pc])\n if opcode >= haveArgument:\n argument = 256*ord(code[pc+2])+ord(code[pc+1])\n next = pc+3\n else:\n argument = None\n next = pc+1\n return next,opcode,argument\n \n def execute(self,pc,opcode,argument):\n name = byOpcode[opcode]\n method = getattr(self,name)\n if argument == None:\n return apply(method,(pc,))\n else:\n return apply(method,(pc,argument,))\n\n def evaluate(self, pc,code):\n next, opcode,argument = self.fetch(pc,code)\n goto = self.execute(next,opcode,argument)\n if goto == -1:\n return None # Must be done\n elif goto == None:\n return next # Normal\n else:\n raise 'xx'\n\n symbols = { 0: 'less', 1: 'lesseq', 2: 'equal', 3: 'notequal',\n 4: 'greater', 5: 'greatereq', 6: 'in', 7: 'not in',\n 8: 'is', 9: 'is not', 10: 'exe match',\n 11 : 'bad',\n }\n def cmp_op(self,opname):\n return self.symbols[opname]\n \n def STOP_CODE(self,pc):\n \"Indicates end-of-code to the compiler, not used by the interpreter.\"\n raise NotImplementedError\n def POP_TOP(self,pc):\n \"Removes the top-of-stack (TOS) item.\"\n raise NotImplementedError\n\n def ROT_TWO(self,pc):\n \"Swaps the two top-most stack items.\"\n raise NotImplementedError\n\n def ROT_THREE(self,pc):\n \"Lifts second and third stack item one position up, moves top down to position three.\"\n raise NotImplementedError\n\n def ROT_FOUR(self,pc):\n \"Lifts second, third and forth stack item one position up, moves top down to position four.\"\n raise NotImplementedError\n\n def DUP_TOP(self,pc):\n \"Duplicates the reference on top of the stack.\"\n raise NotImplementedError\n\n # Unary Operations take the top of the stack, apply the operation, and push the result back on the stack.\n\n def UNARY_POSITIVE(self,pc):\n \"Implements TOS = +TOS.\"\n raise NotImplementedError\n\n def UNARY_NEGATIVE(self,pc):\n \"Implements TOS = -TOS.\"\n raise NotImplementedError\n\n def UNARY_NOT(self,pc):\n \"Implements TOS = not TOS.\"\n raise NotImplementedError\n\n def UNARY_CONVERT(self,pc):\n \"Implements TOS = `TOS`.\"\n raise NotImplementedError\n\n def UNARY_INVERT(self,pc):\n \"Implements TOS = ~TOS.\"\n raise NotImplementedError\n\n #Binary operations remove the top of the stack (TOS) and the second top-most stack item (TOS1) from the stack. They perform the operation, and put the result back on the stack.\n\n def BINARY_POWER(self,pc):\n \"Implements TOS = TOS1 ** TOS.\"\n raise NotImplementedError\n\n def BINARY_MULTIPLY(self,pc):\n \"Implements TOS = TOS1 * TOS.\"\n raise NotImplementedError\n\n def BINARY_DIVIDE(self,pc):\n \"Implements TOS = TOS1 / TOS.\"\n raise NotImplementedError\n\n def BINARY_MODULO(self,pc):\n \"Implements TOS = TOS1 % TOS.\"\n raise NotImplementedError\n\n def BINARY_ADD(self,pc):\n \"Implements TOS = TOS1 + TOS.\"\n raise NotImplementedError\n\n def BINARY_SUBTRACT(self,pc):\n \"Implements TOS = TOS1 - TOS.\"\n raise NotImplementedError\n\n def BINARY_SUBSCR(self,pc):\n \"Implements TOS = TOS1[TOS].\"\n raise NotImplementedError\n\n def BINARY_LSHIFT(self,pc):\n \"Implements TOS = TOS1 << TOS.\"\n raise NotImplementedError\n\n def BINARY_RSHIFT(self,pc):\n \"Implements TOS = TOS1 >> TOS.\"\n raise NotImplementedError\n\n def BINARY_AND(self,pc):\n \"Implements TOS = TOS1 & TOS.\"\n raise NotImplementedError\n\n def BINARY_XOR(self,pc):\n \"Implements TOS = TOS1 ^ TOS.\"\n raise NotImplementedError\n\n def BINARY_OR(self,pc):\n \"Implements TOS = TOS1 | TOS.\"\n raise NotImplementedError\n\n #In-place operations are like binary operations, in that they remove TOS and TOS1, and push the result back on the stack, but the operation is done in-place when TOS1 supports it, and the resulting TOS may be (but does not have to be) the original TOS1.\n\n def INPLACE_POWER(self,pc):\n \"Implements in-place TOS = TOS1 ** TOS.\"\n raise NotImplementedError\n\n def INPLACE_MULTIPLY(self,pc):\n \"Implements in-place TOS = TOS1 * TOS.\"\n raise NotImplementedError\n\n def INPLACE_DIVIDE(self,pc):\n \"Implements in-place TOS = TOS1 / TOS.\"\n raise NotImplementedError\n\n def INPLACE_MODULO(self,pc):\n \"Implements in-place TOS = TOS1 % TOS.\"\n raise NotImplementedError\n\n def INPLACE_ADD(self,pc):\n \"Implements in-place TOS = TOS1 + TOS.\"\n raise NotImplementedError\n\n def INPLACE_SUBTRACT(self,pc):\n \"Implements in-place TOS = TOS1 - TOS.\"\n raise NotImplementedError\n\n def INPLACE_LSHIFT(self,pc):\n \"Implements in-place TOS = TOS1 << TOS.\"\n raise NotImplementedError\n\n def INPLACE_RSHIFT(self,pc):\n \"Implements in-place TOS = TOS1 >> TOS.\"\n raise NotImplementedError\n\n def INPLACE_AND(self,pc):\n \"Implements in-place TOS = TOS1 & TOS.\"\n raise NotImplementedError\n\n def INPLACE_XOR(self,pc):\n \"Implements in-place TOS = TOS1 ^ TOS.\"\n raise NotImplementedError\n\n def INPLACE_OR(self,pc):\n \"Implements in-place TOS = TOS1 | TOS.\"\n raise NotImplementedError\n\n #The slice opcodes take up to three parameters.\n\n def SLICE_0(self,pc):\n \"Implements TOS = TOS[:].\"\n raise NotImplementedError\n\n def SLICE_1(self,pc):\n \"Implements TOS = TOS1[TOS:].\"\n raise NotImplementedError\n\n def SLICE_2(self,pc):\n \"Implements TOS = TOS1[:TOS1].\"\n raise NotImplementedError\n\n def SLICE_3(self,pc):\n \"Implements TOS = TOS2[TOS1:TOS].\"\n raise NotImplementedError\n\n #Slice assignment needs even an additional parameter. As any statement, they put nothing on the stack.\n\n def STORE_SLICE_0(self,pc):\n \"Implements TOS[:] = TOS1.\"\n raise NotImplementedError\n\n def STORE_SLICE_1(self,pc):\n \"Implements TOS1[TOS:] = TOS2.\"\n raise NotImplementedError\n\n def STORE_SLICE_2(self,pc):\n \"Implements TOS1[:TOS] = TOS2.\"\n raise NotImplementedError\n\n def STORE_SLICE_3(self,pc):\n \"Implements TOS2[TOS1:TOS] = TOS3.\"\n raise NotImplementedError\n\n def DELETE_SLICE_0(self,pc):\n \"Implements del TOS[:].\"\n raise NotImplementedError\n\n def DELETE_SLICE_1(self,pc):\n \"Implements del TOS1[TOS:].\"\n raise NotImplementedError\n\n def DELETE_SLICE_2(self,pc):\n \"Implements del TOS1[:TOS].\"\n raise NotImplementedError\n\n def DELETE_SLICE_3(self,pc):\n \"Implements del TOS2[TOS1:TOS].\"\n raise NotImplementedError\n\n def STORE_SUBSCR(self,pc):\n \"Implements TOS1[TOS] = TOS2.\"\n raise NotImplementedError\n\n def DELETE_SUBSCR(self,pc):\n \"Implements del TOS1[TOS].\"\n raise NotImplementedError\n\n def PRINT_EXPR(self,pc):\n \"Implements the expression statement for the interactive mode. TOS is removed from the stack and printed. In non-interactive mode, an expression statement is terminated with POP_STACK.\"\n raise NotImplementedError\n\n def PRINT_ITEM(self,pc):\n \"Prints TOS to the file-like object bound to sys.stdout. There is one such instruction for each item in the print statement.\"\n raise NotImplementedError\n\n def PRINT_ITEM_TO(self,pc):\n \"Like PRINT_ITEM, but prints the item second from TOS to the file-like object at TOS. This is used by the extended print statement.\"\n raise NotImplementedError\n\n def PRINT_NEWLINE(self,pc):\n \"Prints a new line on sys.stdout. This is generated as the last operation of a print statement, unless the statement ends with a comma.\"\n raise NotImplementedError\n\n def PRINT_NEWLINE_TO(self,pc):\n \"Like PRINT_NEWLINE, but prints the new line on the file-like object on the TOS. This is used by the extended print statement.\"\n raise NotImplementedError\n\n def BREAK_LOOP(self,pc):\n \"Terminates a loop due to a break statement.\"\n raise NotImplementedError\n\n def LOAD_LOCALS(self,pc):\n \"Pushes a reference to the locals of the current scope on the stack. This is used in the code for a class definition: After the class body is evaluated, the locals are passed to the class definition.\"\n raise NotImplementedError\n\n def RETURN_VALUE(self,pc):\n \"Returns with TOS to the caller of the function.\"\n raise NotImplementedError\n\n def IMPORT_STAR(self,pc):\n \"Loads all symbols not starting with _ directly from the module TOS to the local namespace. The module is popped after loading all names. This opcode implements from module import *.\"\n raise NotImplementedError\n\n def EXEC_STMT(self,pc):\n \"Implements exec TOS2,TOS1,TOS. The compiler fills missing optional parameters with None.\"\n raise NotImplementedError\n\n def POP_BLOCK(self,pc):\n \"Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.\"\n raise NotImplementedError\n\n def END_FINALLY(self,pc):\n \"Terminates a finally clause. The interpreter recalls whether the exception has to be re-raised, or whether the function returns, and continues with the outer-next block.\"\n raise NotImplementedError\n\n def BUILD_CLASS(self,pc):\n \"Creates a new class object. TOS is the methods dictionary, TOS1 the tuple of the names of the base classes, and TOS2 the class name.\"\n raise NotImplementedError\n\n #All of the following opcodes expect arguments. An argument is two bytes, with the more significant byte last.\n\n def STORE_NAME(self,pc,namei):\n \"Implements name = TOS. namei is the index of name in the attribute co_names of the code object. The compiler tries to use STORE_LOCAL or STORE_GLOBAL if possible.\"\n raise NotImplementedError\n\n def DELETE_NAME(self,pc,namei):\n \"Implements del name, where namei is the index into co_names attribute of the code object.\"\n raise NotImplementedError\n\n def UNPACK_SEQUENCE(self,pc,count):\n \"Unpacks TOS into count individual values, which are put onto the stack right-to-left.\"\n raise NotImplementedError\n\n def DUP_TOPX(self,pc,count):\n \"Duplicate count items, keeping them in the same order. Due to implementation limits, count should be between 1 and 5 inclusive.\"\n raise NotImplementedError\n\n def STORE_ATTR(self,pc,namei):\n \"Implements TOS.name = TOS1, where namei is the index of name in co_names.\"\n raise NotImplementedError\n\n def DELETE_ATTR(self,pc,namei):\n \"Implements del TOS.name, using namei as index into co_names.\"\n raise NotImplementedError\n\n def STORE_GLOBAL(self,pc,namei):\n \"Works as STORE_NAME, but stores the name as a global.\"\n raise NotImplementedError\n\n def DELETE_GLOBAL(self,pc,namei):\n \"Works as DELETE_NAME, but deletes a global name.\"\n raise NotImplementedError\n\n def LOAD_CONST(self,pc,consti):\n \"Pushes co_consts[consti] onto the stack.\"\n raise NotImplementedError\n\n def LOAD_NAME(self,pc,namei):\n \"Pushes the value associated with co_names[namei] onto the stack.\"\n raise NotImplementedError\n\n def BUILD_TUPLE(self,pc,count):\n \"Creates a tuple consuming count items from the stack, and pushes the resulting tuple onto the stack.\"\n raise NotImplementedError\n\n def BUILD_LIST(self,pc,count):\n \"Works as BUILD_TUPLE, but creates a list.\"\n raise NotImplementedError\n\n def BUILD_MAP(self,pc,zero):\n \"Pushes a new empty dictionary object onto the stack. The argument is ignored and set to zero by the compiler.\"\n raise NotImplementedError\n\n def LOAD_ATTR(self,pc,namei):\n \"Replaces TOS with getattr(TOS, co_names[namei].\"\n raise NotImplementedError\n\n def COMPARE_OP(self,pc,opname):\n \"Performs a Boolean operation. The operation name can be found in cmp_op[opname].\"\n raise NotImplementedError\n\n def IMPORT_NAME(self,pc,namei):\n \"Imports the module co_names[namei]. The module object is pushed onto the stack. The current namespace is not affected: for a proper import statement, a subsequent STORE_FAST instruction modifies the namespace.\"\n raise NotImplementedError\n\n def IMPORT_FROM(self,pc,namei):\n \"Loads the attribute co_names[namei] from the module found in TOS. The resulting object is pushed onto the stack, to be subsequently stored by a STORE_FAST instruction.\"\n raise NotImplementedError\n\n def JUMP_FORWARD(self,pc,delta):\n \"Increments byte code counter by delta.\"\n raise NotImplementedError\n\n def JUMP_IF_TRUE(self,pc,delta):\n \"If TOS is true, increment the byte code counter by delta. TOS is left on the stack.\"\n raise NotImplementedError\n\n def JUMP_IF_FALSE(self,pc,delta):\n \"If TOS is false, increment the byte code counter by delta. TOS is not changed.\"\n raise NotImplementedError\n\n def JUMP_ABSOLUTE(self,pc,target):\n \"Set byte code counter to target.\"\n raise NotImplementedError\n\n def FOR_LOOP(self,pc,delta):\n \"Iterate over a sequence. TOS is the current index, TOS1 the sequence. First, the next element is computed. If the sequence is exhausted, increment byte code counter by delta. Otherwise, push the sequence, the incremented counter, and the current item onto the stack.\"\n raise NotImplementedError\n\n def LOAD_GLOBAL(self,pc,namei):\n \"Loads the global named co_names[namei] onto the stack.\"\n raise NotImplementedError\n\n def SETUP_LOOP(self,pc,delta):\n \"Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.\"\n raise NotImplementedError\n\n def SETUP_EXCEPT(self,pc,delta):\n \"Pushes a try block from a try-except clause onto the block stack. delta points to the first except block.\"\n raise NotImplementedError\n\n def SETUP_FINALLY(self,pc,delta):\n \"Pushes a try block from a try-except clause onto the block stack. delta points to the finally block.\"\n raise NotImplementedError\n\n def LOAD_FAST(self,pc,var_num):\n \"Pushes a reference to the local co_varnames[var_num] onto the stack.\"\n raise NotImplementedError\n\n def STORE_FAST(self,pc,var_num):\n \"Stores TOS into the local co_varnames[var_num].\"\n raise NotImplementedError\n\n def DELETE_FAST(self,pc,var_num):\n \"Deletes local co_varnames[var_num].\"\n raise NotImplementedError\n\n def LOAD_CLOSURE(self,pc,i):\n \"Pushes a reference to the cell contained in slot i of the cell and free variable storage. The name of the variable is co_cellvars[i] if i is less than the length of co_cellvars. Otherwise it is co_freevars[i - len(co_cellvars)].\"\n raise NotImplementedError\n\n def LOAD_DEREF(self,pc,i):\n \"Loads the cell contained in slot i of the cell and free variable storage. Pushes a reference to the object the cell contains on the stack.\"\n raise NotImplementedError\n\n def STORE_DEREF(self,pc,i):\n \"Stores TOS into the cell contained in slot i of the cell and free variable storage.\"\n raise NotImplementedError\n\n def SET_LINENO(self,pc,lineno):\n \"Sets the current line number to lineno.\"\n raise NotImplementedError\n\n def RAISE_VARARGS(self,pc,argc):\n \"Raises an exception. argc indicates the number of parameters to the raise statement, ranging from 0 to 3. The handler will find the traceback as TOS2, the parameter as TOS1, and the exception as TOS.\"\n raise NotImplementedError\n\n def CALL_FUNCTION(self,pc,argc):\n \"Calls a function. The low byte of argc indicates the number of positional parameters, the high byte the number of keyword parameters. On the stack, the opcode finds the keyword parameters first. For each keyword argument, the value is on top of the key. Below the keyword parameters, the positional parameters are on the stack, with the right-most parameter on top. Below the parameters, the function object to call is on the stack.\"\n raise NotImplementedError\n\n def MAKE_FUNCTION(self,pc,argc):\n \"Pushes a new function object on the stack. TOS is the code associated with the function. The function object is defined to have argc default parameters, which are found below TOS.\"\n raise NotImplementedError\n\n def MAKE_CLOSURE(self,pc,argc):\n \"Creates a new function object, sets its func_closure slot, and pushes it on the stack. TOS is the code associated with the function. If the code object has N free variables, the next N items on the stack are the cells for these variables. The function also has argc default parameters, where are found before the cells.\"\n raise NotImplementedError\n\n def BUILD_SLICE(self,pc,argc):\n \"Pushes a slice object on the stack. argc must be 2 or 3. If it is 2, slice(TOS1, TOS) is pushed; if it is 3, slice(TOS2, TOS1, TOS) is pushed. See the slice() built-in function for more information.\"\n raise NotImplementedError\n\n def EXTENDED_ARG(self,pc,ext):\n \"Prefixes any opcode which has an argument too big to fit into the default two bytes. ext holds two additional bytes which, taken together with the subsequent opcode's argument, comprise a four-byte argument, ext being the two most-significant bytes.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_VAR(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the variable argument list, followed by keyword and positional arguments.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_KW(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by explicit keyword and positional arguments.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_VAR_KW(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by the variable-arguments tuple, followed by explicit keyword and positional arguments.\"\n raise NotImplementedError\n\n \n\n##################################################################\n# CLASS CXXCODER #\n##################################################################\nclass CXXCoder(ByteCodeMeaning):\n\n ##################################################################\n # MEMBER TYPEDEF_BY_VALUE #\n ##################################################################\n def typedef_by_value(self,v):\n raise NotImplementedError # VIRTUAL\n \n ##################################################################\n # MEMBER __INIT__ #\n ##################################################################\n def __init__(self,function,signature,name=None):\n assert type(function) == FunctionType,\"Arg must be a user function\"\n assert not function.func_defaults ,\"Function cannot have default args (yet)\"\n if name == None: name = function.func_name\n self.name = name\n self.function = function\n self.signature = signature\n self.codeobject = function.func_code\n self.__uid = 0 # Builds temps\n return\n\n ##################################################################\n # MEMBER EVALUATE #\n ##################################################################\n def evaluate(self, pc,code):\n # See if we posted any forwards for this offset\n if self.forwards.has_key(pc):\n for f in self.forwards[pc]:\n f()\n self.forwards[pc] = []\n return ByteCodeMeaning.evaluate(self,pc,code)\n \n ##################################################################\n # MEMBER GENERATE #\n ##################################################################\n def generate(self):\n self.forwards = {} # Actions on forward interprets\n self.__body = '' # Body will be built\n self.helpers = [] # headers and stuff\n\n # -----------------------------------------------\n # OK, crack open the function object and build\n # initial stack (not a real frame!)\n # -----------------------------------------------\n arglen = len(self.signature)\n nlocals = self.codeobject.co_nlocals\n\n self.consts = self.codeobject.co_consts\n self.stack = list(self.codeobject.co_varnames)\n self.types = list(self.signature)+[None]*(nlocals-arglen)\n self.used = []\n for T in self.types:\n if T not in self.used: self.used.append(T)\n\n # -----------------------------------------------\n # One pass through the byte codes to generate\n # the body\n # -----------------------------------------------\n code = self.codeobject.co_code\n pc = 0\n while pc != None:\n pc = self.evaluate(pc,code)\n\n # -----------------------------------------------\n # Return?\n # -----------------------------------------------\n if self.rtype == NoneType:\n rtype = 'void'\n else:\n rtype = self.rtype.cxxtype\n \n # -----------------------------------------------\n # Insert code body if available\n # -----------------------------------------------\n source = inspect.getsource(self.function)\n if not source: source = ''\n comments = inspect.getcomments(self.function)\n if comments: source = comments+source\n code = string.join(map(lambda x: '/////// '+x,string.split(source,'\\n')),\n '\\n')+'\\n'\n\n # -----------------------------------------------\n # Add in the headers\n # -----------------------------------------------\n code += '#include \"Python.h\"\\n'\n for T in self.used:\n print T.prerequisites\n for pre in T.prerequisites:\n code += pre\n code += '\\n'\n\n # -----------------------------------------------\n # Real body\n # -----------------------------------------------\n code += '\\n'\n code += '\\nstatic %s %s('%(rtype,self.name)\n for i in range(len(self.signature)):\n if i != 0: code += ', '\n n = self.stack[i]\n t = self.types[i]\n code += '%s %s'%(t.cxxtype,n)\n code += ') {\\n'\n\n # Add in non-argument temporaries\n # Assuming first argcount locals are positional args\n for i in range(self.codeobject.co_argcount,\n self.codeobject.co_nlocals):\n t = self.types[i]\n descriptor = typedefs[t]\n code += '%s %s;\\n'%(\n descriptor.cxxtype,\n self.codeobject.co_varnames[i],\n )\n\n # Add in the body\n code += self.__body\n code += '}\\n\\n'\n return code\n\n\n ##################################################################\n # MEMBER WRAPPED_CODE #\n ##################################################################\n def wrapped_code(self):\n code = self.generate()\n \n # -----------------------------------------------\n # Wrapper\n # -----------------------------------------------\n code += 'static PyObject* wrapper_%s(PyObject*,PyObject* args) {\\n'%self.name\n\n code += ' // Length check\\n'\n code += ' if ( PyTuple_Size(args) != %d ) {\\n'%len(self.signature)\n code += ' PyErr_SetString(PyExc_TypeError,\"Expected %d arguments\");\\n'%len(self.signature)\n code += ' return 0;\\n'\n code += ' }\\n'\n\n code += '\\n // Load Py versions of args\\n'\n for i in range(len(self.signature)):\n T = self.signature[i]\n code += ' PyObject* py_%s = PyTuple_GET_ITEM(args,%d);\\n'%(\n self.codeobject.co_varnames[i],i\n )\n\n code += ' if ( !%s ) {\\n'% \\\n T.check('py_'+self.codeobject.co_varnames[i])\n code += ' PyErr_SetString(PyExc_TypeError,\"Bad type for arg %d (expected %s)\");\\n'%(\n i+1,\n T.__class__.__name__)\n code += ' return 0;\\n'\n code += ' }\\n'\n \n code += '\\n // Do conversions\\n'\n argnames = []\n for i in range(len(self.signature)):\n T = self.signature[i]\n\n code += ' %s %s=%s;\\n'%(\n T.cxxtype,\n self.codeobject.co_varnames[i],\n T.inbound('py_'+self.codeobject.co_varnames[i]),\n )\n code += ' if ( PyErr_Occurred() ) return 0;\\n'\n argnames.append(self.codeobject.co_varnames[i])\n\n code += '\\n // Compute result\\n'\n if self.rtype != NoneType:\n code += ' %s _result = '%(\n self.rtype.cxxtype,\n )\n else:\n code += ' '\n code += '%s(%s);\\n'%(\n self.name,\n string.join(argnames,','),\n )\n\n\n code += '\\n // Pack return\\n'\n if ( self.rtype == NoneType ):\n code += ' Py_INCREF(Py_None);\\n'\n code += ' return Py_None;\\n'\n else:\n result = self.rtype.outbound('_result')\n code += ' return %s;\\n'%result\n code += '}\\n'\n return code\n\n\n ##################################################################\n # MEMBER EMIT #\n ##################################################################\n def emit(self,s):\n self.__body += s\n self.__body += '\\n'\n return\n\n ##################################################################\n # MEMBER PUSH #\n ##################################################################\n def push(self,v,t):\n self.stack.append(v)\n self.types.append(t)\n return\n\n\n ##################################################################\n # MEMBER POP #\n ##################################################################\n def pop(self):\n v = self.stack[-1]\n del self.stack[-1]\n t = self.types[-1]\n del self.types[-1]\n return v,t\n\n ##################################################################\n # MEMBER UNIQUE #\n ##################################################################\n def unique(self):\n self.__uid += 1\n return 't%d'%self.__uid\n\n ##################################################################\n # MEMBER POST #\n ##################################################################\n def post(self,pc,action):\n if not self.forwards.has_key(pc):\n self.forwards[pc] = []\n self.forwards[pc].append(action)\n return\n\n ##################################################################\n # MEMBER EMIT_VALUE #\n ##################################################################\n def emit_value(self, v):\n descriptor = self.typedef_by_value(v)\n \n # Convert representation to CXX rhs\n rhs = descriptor.literalizer(v)\n lhs = self.unique()\n self.emit('%s %s = %s;'%(\n descriptor.cxxtype,\n lhs,\n rhs))\n self.push(lhs,descriptor)\n return \n\n ##################################################################\n # MEMBER GLOBAL_INFO #\n ##################################################################\n def global_info(self,var_num):\n # This is the name value is known by\n var_name = self.codeobject.co_names[var_num]\n\n # First, figure out who owns this global\n import sys\n myHash = id(self.function.func_globals)\n for module_name in sys.modules.keys():\n module = sys.modules[module_name]\n if module and id(module.__dict__) == myHash:\n break\n else:\n raise ValueError,'Cannot locate module owning %s'%varname\n return module_name,var_name\n\n ##################################################################\n # MEMBER BINOP #\n ##################################################################\n def binop(self,pc,symbol):\n v2,t2 = self.pop()\n v1,t1 = self.pop()\n\n if t1 == t2:\n rhs,rhs_type = t1.binop(symbol,v1,v2)\n else:\n raise NotImplementedError,'mixed types'\n \n lhs = self.unique()\n self.emit('%s %s = %s;\\n'%(\n rhs_type.cxxtype,\n lhs,\n rhs))\n self.push(lhs,rhs_type)\n return \n\n ##################################################################\n # MEMBER BINARY_XXX #\n ##################################################################\n def BINARY_ADD(self,pc):\n return self.binop(pc,'+')\n def BINARY_SUBTRACT(self,pc):\n return self.binop(pc,'-')\n def BINARY_MULTIPLY(self,pc):\n return self.binop(pc,'*')\n def BINARY_DIVIDE(self,pc):\n return self.binop(pc,'/')\n def BINARY_MODULO(self,pc):\n return self.binop(pc,'%')\n def COMPARE_OP(self,pc,opname):\n symbol = self.cmp_op(opname) # convert numeric to name\n return self.binop(pc,symbol)\n\n\n ##################################################################\n # MEMBER PRINT_ITEM #\n ##################################################################\n def PRINT_ITEM(self,pc):\n # Printing correctly is tricky... best to let Python\n # do the real work here\n w = self.unique()\n self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n self.emit('if (PyFile_SoftSpace(%s,1)) PyFile_WriteString(\" \",%s);'%(w,w))\n v,t = self.pop()\n\n py = self.unique()\n self.emit('PyObject* %s = %s;'%(py, t.outbound(v)))\n self.emit('PyFile_WriteObject(%s,%s,Py_PRINT_RAW);'%(\n py,w))\n self.emit('Py_XDECREF(%s);'%py)\n return\n\n\n ##################################################################\n # MEMBER PRINT_NEWLINE #\n ##################################################################\n def PRINT_NEWLINE(self,pc):\n # Printing correctly is tricky... best to let Python\n # do the real work here\n w = self.unique()\n self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n self.emit('PyFile_WriteString(\"\\\\n\",%s);'%w);\n self.emit('PyFile_SoftSpace(%s,0);'%w);\n return\n \n ##################################################################\n # MEMBER SET_LINENO #\n ##################################################################\n def SET_LINENO(self,pc,lineno):\n self.emit('// %s:%d'%(self.codeobject.co_filename,lineno))\n return\n\n ##################################################################\n # MEMBER POP_TOP #\n ##################################################################\n def POP_TOP(self,pc):\n v,t = self.pop()\n return\n\n ##################################################################\n # MEMBER LOAD_CONST #\n ##################################################################\n def LOAD_CONST(self,pc,consti):\n # Fetch the constant\n k = self.consts[consti]\n t = type(k)\n\n # Fetch a None is just skipped\n if t == NoneType:\n self.push('',t) \n return\n\n self.emit_value(k)\n return\n\n\n ##################################################################\n # MEMBER LOAD_FAST #\n ##################################################################\n def LOAD_FAST(self,pc,var_num):\n v = self.stack[var_num]\n t = self.types[var_num]\n self.push(v,t)\n return\n\n ##################################################################\n # MEMBER LOAD_GLOBAL #\n ##################################################################\n def LOAD_GLOBAL(self,pc,var_num):\n # Figure out the name and load it\n try:\n F = self.function.func_globals[self.codeobject.co_names[var_num]]\n except:\n F = getattr(__builtins__,self.codeobject.co_names[var_num])\n\n # For functions, we see if we know about this function\n if callable(F):\n assert functiondefs.has_key(F),\"Function %s is known\"%F\n self.push(F,type(F))\n return\n\n # We need the name of the module that matches\n # the global state for the function and\n # the name of the variable\n module_name,var_name = self.global_info(var_num)\n\n # We hope it's type is correct\n t = type(F)\n descriptor = typedefs[t]\n native = self.unique()\n py = self.unique()\n mod = self.unique()\n\n self.emit('')\n self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n mod,module_name))\n self.emit('PyObject* %s = PyObject_GetAttrString(%s,\"%s\");'%(\n py,mod,var_name))\n self.emit('%s %s = %s;'%(\n descriptor.cxxtype,\n native,\n descriptor.inbound%py))\n\n self.push(native,t)\n return\n\n ##################################################################\n # MEMBER STORE_FAST #\n ##################################################################\n def STORE_FAST(self,pc,var_num):\n\n v,t = self.pop()\n\n save = self.stack[var_num]\n saveT = self.types[var_num]\n\n # See if type is same....\n # Note that None means no assignment made yet\n if saveT == None or t == saveT:\n self.emit('%s = %s;\\n'%(save,v))\n self.types[var_num] = t\n return\n\n raise TypeError,(t,saveT)\n\n ##################################################################\n # MEMBER STORE_GLOBAL #\n ##################################################################\n def STORE_GLOBAL(self,pc,var_num):\n\n # We need the name of the module that matches\n # the global state for the function and\n # the name of the variable\n module_name,var_name = self.global_info(var_num)\n\n # Convert the value to Python object\n v,t = self.pop()\n descriptor = typedefs[t]\n py = self.unique()\n self.emit('PyObject* %s = %s;'%(\n py,\n descriptor.outbound%v))\n mod = self.unique()\n self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n mod,module_name))\n self.emit('PyObject_SetAttrString(%s,\"%s\",%s);'%(\n mod,var_name,py))\n self.emit('Py_DECREF(%s);'%py)\n return\n\n ##################################################################\n # MEMBER CALL_FUNCTION #\n ##################################################################\n def CALL_FUNCTION(self,pc,argc):\n # Pull args off stack\n args = []\n types = []\n for i in range(argc):\n v,t = self.pop()\n args = [v]+args\n types = [t]+types\n \n # Pull function object off stack and get descriptor\n f,t = self.pop()\n descriptor = functiondefs[f]\n #self.prerequisites += descriptor['prerequisite']+'\\n'\n \n # Look through descriptors for a match\n for inputs,outputs,format in descriptor:\n if inputs == types:\n break\n else:\n raise TypeError,f\n\n # Build a rhs\n rhs = format%string.join(args,',')\n\n # Build a statement\n assert len(outputs) == 1,\"Single valued return\"\n assert typedefs.has_key(outputs[0]),\"Know about type %s\"%outputs[0]\n description = typedefs[outputs[0]]\n temp = self.unique()\n self.emit('%s %s = %s;\\n'%(\n description.cxxtype,\n temp,\n rhs))\n\n self.push(temp,outputs[0])\n return\n\n\n ##################################################################\n # MEMBER JUMP_IF_FALSE #\n ##################################################################\n def JUMP_IF_FALSE(self,pc,delta):\n v,t = self.pop()\n self.push(v,t)\n # We need to do some work when we get to the\n # else part (put the value that's gonna get\n # popped back on the stack, emit } else {,\n # ...)\n action = lambda v=v,t=t,self=self: (\n self.emit('} else {'),\n self.push(v,t),\n )\n self.post(pc+delta,action)\n if t != IntType: raise TypeError, 'Invalid comparison type %s'%t\n self.emit('if (%s) {\\n'%v)\n return\n \n\n ##################################################################\n # MEMBER JUMP_FORWARD #\n ##################################################################\n def JUMP_FORWARD(self,pc,delta):\n # We need to close the if after the delta\n action = lambda self=self: (\n self.emit('}'),\n )\n self.post(pc+delta,action)\n return\n \n ##################################################################\n # MEMBER RETURN_VALUE #\n ##################################################################\n def RETURN_VALUE(self,pc):\n v,t = self.pop()\n if hasattr(self,'rtype'):\n raise ValueError,'multiple returns'\n self.rtype = t\n if t == NoneType:\n self.emit('return;')\n else:\n self.emit('return %s;'%v)\n return -1\n\n", "source_code_before": null, "methods": [ { "name": "__repr__", "long_name": "__repr__( self )", "filename": "bytecodecompiler.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 19, "end_line": 20, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "opcodize", "long_name": "opcodize( s )", "filename": "bytecodecompiler.py", "nloc": 16, "complexity": 3, "token_count": 92, "parameters": [ "s" ], "start_line": 141, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "listing", "long_name": "listing( f )", "filename": "bytecodecompiler.py", "nloc": 26, "complexity": 8, "token_count": 156, "parameters": [ "f" ], "start_line": 163, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "fetch", "long_name": "fetch( self , pc , code )", "filename": "bytecodecompiler.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [ "self", "pc", "code" ], "start_line": 194, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "execute", "long_name": "execute( self , pc , opcode , argument )", "filename": "bytecodecompiler.py", "nloc": 7, "complexity": 2, "token_count": 54, "parameters": [ "self", "pc", "opcode", "argument" ], "start_line": 204, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "evaluate", "long_name": "evaluate( self , pc , code )", "filename": "bytecodecompiler.py", "nloc": 9, "complexity": 3, "token_count": 54, "parameters": [ "self", "pc", "code" ], "start_line": 212, "end_line": 220, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "cmp_op", "long_name": "cmp_op( self , opname )", "filename": "bytecodecompiler.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "opname" ], "start_line": 227, "end_line": 228, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "STOP_CODE", "long_name": "STOP_CODE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 230, "end_line": 232, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "POP_TOP", "long_name": "POP_TOP( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 233, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "ROT_TWO", "long_name": "ROT_TWO( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 237, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "ROT_THREE", "long_name": "ROT_THREE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 241, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "ROT_FOUR", "long_name": "ROT_FOUR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 245, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DUP_TOP", "long_name": "DUP_TOP( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 249, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "UNARY_POSITIVE", "long_name": "UNARY_POSITIVE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 255, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "UNARY_NEGATIVE", "long_name": "UNARY_NEGATIVE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 259, "end_line": 261, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "UNARY_NOT", "long_name": "UNARY_NOT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 263, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "UNARY_CONVERT", "long_name": "UNARY_CONVERT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 267, "end_line": 269, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "UNARY_INVERT", "long_name": "UNARY_INVERT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 271, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_POWER", "long_name": "BINARY_POWER( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 277, "end_line": 279, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_MULTIPLY", "long_name": "BINARY_MULTIPLY( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 281, "end_line": 283, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_DIVIDE", "long_name": "BINARY_DIVIDE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 285, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_MODULO", "long_name": "BINARY_MODULO( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 289, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_ADD", "long_name": "BINARY_ADD( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 293, "end_line": 295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_SUBTRACT", "long_name": "BINARY_SUBTRACT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 297, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_SUBSCR", "long_name": "BINARY_SUBSCR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 301, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_LSHIFT", "long_name": "BINARY_LSHIFT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 305, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_RSHIFT", "long_name": "BINARY_RSHIFT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 309, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_AND", "long_name": "BINARY_AND( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 313, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_XOR", "long_name": "BINARY_XOR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 317, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_OR", "long_name": "BINARY_OR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 321, "end_line": 323, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_POWER", "long_name": "INPLACE_POWER( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 327, "end_line": 329, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_MULTIPLY", "long_name": "INPLACE_MULTIPLY( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 331, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_DIVIDE", "long_name": "INPLACE_DIVIDE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 335, "end_line": 337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_MODULO", "long_name": "INPLACE_MODULO( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 339, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_ADD", "long_name": "INPLACE_ADD( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 343, "end_line": 345, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_SUBTRACT", "long_name": "INPLACE_SUBTRACT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 347, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_LSHIFT", "long_name": "INPLACE_LSHIFT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 351, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_RSHIFT", "long_name": "INPLACE_RSHIFT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 355, "end_line": 357, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_AND", "long_name": "INPLACE_AND( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 359, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_XOR", "long_name": "INPLACE_XOR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 363, "end_line": 365, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_OR", "long_name": "INPLACE_OR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 367, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SLICE_0", "long_name": "SLICE_0( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 373, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SLICE_1", "long_name": "SLICE_1( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 377, "end_line": 379, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SLICE_2", "long_name": "SLICE_2( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 381, "end_line": 383, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SLICE_3", "long_name": "SLICE_3( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 385, "end_line": 387, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_SLICE_0", "long_name": "STORE_SLICE_0( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 391, "end_line": 393, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_SLICE_1", "long_name": "STORE_SLICE_1( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 395, "end_line": 397, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_SLICE_2", "long_name": "STORE_SLICE_2( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 399, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_SLICE_3", "long_name": "STORE_SLICE_3( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 403, "end_line": 405, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_SLICE_0", "long_name": "DELETE_SLICE_0( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 407, "end_line": 409, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_SLICE_1", "long_name": "DELETE_SLICE_1( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 411, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_SLICE_2", "long_name": "DELETE_SLICE_2( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 415, "end_line": 417, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_SLICE_3", "long_name": "DELETE_SLICE_3( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 419, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_SUBSCR", "long_name": "STORE_SUBSCR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 423, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_SUBSCR", "long_name": "DELETE_SUBSCR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 427, "end_line": 429, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PRINT_EXPR", "long_name": "PRINT_EXPR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 431, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PRINT_ITEM", "long_name": "PRINT_ITEM( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 435, "end_line": 437, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PRINT_ITEM_TO", "long_name": "PRINT_ITEM_TO( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 439, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PRINT_NEWLINE", "long_name": "PRINT_NEWLINE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 443, "end_line": 445, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PRINT_NEWLINE_TO", "long_name": "PRINT_NEWLINE_TO( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 447, "end_line": 449, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BREAK_LOOP", "long_name": "BREAK_LOOP( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 451, "end_line": 453, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "LOAD_LOCALS", "long_name": "LOAD_LOCALS( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 455, "end_line": 457, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "RETURN_VALUE", "long_name": "RETURN_VALUE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 459, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "IMPORT_STAR", "long_name": "IMPORT_STAR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 463, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "EXEC_STMT", "long_name": "EXEC_STMT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 467, "end_line": 469, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "POP_BLOCK", "long_name": "POP_BLOCK( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 471, "end_line": 473, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "END_FINALLY", "long_name": "END_FINALLY( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 475, "end_line": 477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BUILD_CLASS", "long_name": "BUILD_CLASS( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 479, "end_line": 481, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_NAME", "long_name": "STORE_NAME( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 485, "end_line": 487, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_NAME", "long_name": "DELETE_NAME( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 489, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "UNPACK_SEQUENCE", "long_name": "UNPACK_SEQUENCE( self , pc , count )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "count" ], "start_line": 493, "end_line": 495, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DUP_TOPX", "long_name": "DUP_TOPX( self , pc , count )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "count" ], "start_line": 497, "end_line": 499, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_ATTR", "long_name": "STORE_ATTR( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 501, "end_line": 503, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_ATTR", "long_name": "DELETE_ATTR( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 505, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_GLOBAL", "long_name": "STORE_GLOBAL( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 509, "end_line": 511, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_GLOBAL", "long_name": "DELETE_GLOBAL( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 513, "end_line": 515, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "LOAD_CONST", "long_name": "LOAD_CONST( self , pc , consti )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "consti" ], "start_line": 517, "end_line": 519, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "LOAD_NAME", "long_name": "LOAD_NAME( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 521, "end_line": 523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BUILD_TUPLE", "long_name": "BUILD_TUPLE( self , pc , count )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "count" ], "start_line": 525, "end_line": 527, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BUILD_LIST", "long_name": "BUILD_LIST( self , pc , count )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "count" ], "start_line": 529, "end_line": 531, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BUILD_MAP", "long_name": "BUILD_MAP( self , pc , zero )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "zero" ], "start_line": 533, "end_line": 535, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "LOAD_ATTR", "long_name": "LOAD_ATTR( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 537, "end_line": 539, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "COMPARE_OP", "long_name": "COMPARE_OP( self , pc , opname )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "opname" ], "start_line": 541, "end_line": 543, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "IMPORT_NAME", "long_name": "IMPORT_NAME( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 545, "end_line": 547, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "IMPORT_FROM", "long_name": "IMPORT_FROM( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 549, "end_line": 551, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "JUMP_FORWARD", "long_name": "JUMP_FORWARD( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "delta" ], "start_line": 553, "end_line": 555, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "JUMP_IF_TRUE", "long_name": "JUMP_IF_TRUE( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "delta" ], "start_line": 557, "end_line": 559, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "JUMP_IF_FALSE", "long_name": "JUMP_IF_FALSE( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "delta" ], "start_line": 561, "end_line": 563, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "JUMP_ABSOLUTE", "long_name": "JUMP_ABSOLUTE( self , pc , target )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "target" ], "start_line": 565, "end_line": 567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "FOR_LOOP", "long_name": "FOR_LOOP( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "delta" ], "start_line": 569, "end_line": 571, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "LOAD_GLOBAL", "long_name": "LOAD_GLOBAL( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 573, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SETUP_LOOP", "long_name": "SETUP_LOOP( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "delta" ], "start_line": 577, "end_line": 579, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SETUP_EXCEPT", "long_name": "SETUP_EXCEPT( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "delta" ], "start_line": 581, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SETUP_FINALLY", "long_name": "SETUP_FINALLY( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "delta" ], "start_line": 585, "end_line": 587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "LOAD_FAST", "long_name": "LOAD_FAST( self , pc , var_num )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "var_num" ], "start_line": 589, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_FAST", "long_name": "STORE_FAST( self , pc , var_num )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "var_num" ], "start_line": 593, "end_line": 595, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_FAST", "long_name": "DELETE_FAST( self , pc , var_num )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "var_num" ], "start_line": 597, "end_line": 599, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "LOAD_CLOSURE", "long_name": "LOAD_CLOSURE( self , pc , i )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "i" ], "start_line": 601, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "LOAD_DEREF", "long_name": "LOAD_DEREF( self , pc , i )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "i" ], "start_line": 605, "end_line": 607, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_DEREF", "long_name": "STORE_DEREF( self , pc , i )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "i" ], "start_line": 609, "end_line": 611, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SET_LINENO", "long_name": "SET_LINENO( self , pc , lineno )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "lineno" ], "start_line": 613, "end_line": 615, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "RAISE_VARARGS", "long_name": "RAISE_VARARGS( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 617, "end_line": 619, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "CALL_FUNCTION", "long_name": "CALL_FUNCTION( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 621, "end_line": 623, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "MAKE_FUNCTION", "long_name": "MAKE_FUNCTION( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 625, "end_line": 627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "MAKE_CLOSURE", "long_name": "MAKE_CLOSURE( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 629, "end_line": 631, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BUILD_SLICE", "long_name": "BUILD_SLICE( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 633, "end_line": 635, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "EXTENDED_ARG", "long_name": "EXTENDED_ARG( self , pc , ext )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "ext" ], "start_line": 637, "end_line": 639, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "CALL_FUNCTION_VAR", "long_name": "CALL_FUNCTION_VAR( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 641, "end_line": 643, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "CALL_FUNCTION_KW", "long_name": "CALL_FUNCTION_KW( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 645, "end_line": 647, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "CALL_FUNCTION_VAR_KW", "long_name": "CALL_FUNCTION_VAR_KW( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 649, "end_line": 651, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "typedef_by_value", "long_name": "typedef_by_value( self , v )", "filename": "bytecodecompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "v" ], "start_line": 663, "end_line": 664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , function , signature , name = None )", "filename": "bytecodecompiler.py", "nloc": 10, "complexity": 2, "token_count": 67, "parameters": [ "self", "function", "signature", "name" ], "start_line": 669, "end_line": 678, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "evaluate", "long_name": "evaluate( self , pc , code )", "filename": "bytecodecompiler.py", "nloc": 6, "complexity": 3, "token_count": 52, "parameters": [ "self", "pc", "code" ], "start_line": 683, "end_line": 689, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "bytecodecompiler.py", "nloc": 51, "complexity": 12, "token_count": 368, "parameters": [ "self" ], "start_line": 694, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 83, "top_nesting_level": 1 }, { "name": "wrapped_code", "long_name": "wrapped_code( self )", "filename": "bytecodecompiler.py", "nloc": 52, "complexity": 5, "token_count": 294, "parameters": [ "self" ], "start_line": 782, "end_line": 845, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , s )", "filename": "bytecodecompiler.py", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self", "s" ], "start_line": 851, "end_line": 854, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "push", "long_name": "push( self , v , t )", "filename": "bytecodecompiler.py", "nloc": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "v", "t" ], "start_line": 859, "end_line": 862, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "pop", "long_name": "pop( self )", "filename": "bytecodecompiler.py", "nloc": 6, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 868, "end_line": 873, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "unique", "long_name": "unique( self )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 878, "end_line": 880, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "post", "long_name": "post( self , pc , action )", "filename": "bytecodecompiler.py", "nloc": 5, "complexity": 2, "token_count": 41, "parameters": [ "self", "pc", "action" ], "start_line": 885, "end_line": 889, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "emit_value", "long_name": "emit_value( self , v )", "filename": "bytecodecompiler.py", "nloc": 10, "complexity": 1, "token_count": 55, "parameters": [ "self", "v" ], "start_line": 894, "end_line": 905, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "global_info", "long_name": "global_info( self , var_num )", "filename": "bytecodecompiler.py", "nloc": 11, "complexity": 4, "token_count": 73, "parameters": [ "self", "var_num" ], "start_line": 910, "end_line": 923, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "binop", "long_name": "binop( self , pc , symbol )", "filename": "bytecodecompiler.py", "nloc": 14, "complexity": 2, "token_count": 84, "parameters": [ "self", "pc", "symbol" ], "start_line": 928, "end_line": 943, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "BINARY_ADD", "long_name": "BINARY_ADD( self , pc )", "filename": "bytecodecompiler.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "pc" ], "start_line": 948, "end_line": 949, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "BINARY_SUBTRACT", "long_name": "BINARY_SUBTRACT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "pc" ], "start_line": 950, "end_line": 951, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "BINARY_MULTIPLY", "long_name": "BINARY_MULTIPLY( self , pc )", "filename": "bytecodecompiler.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "pc" ], "start_line": 952, "end_line": 953, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "BINARY_DIVIDE", "long_name": "BINARY_DIVIDE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "pc" ], "start_line": 954, "end_line": 955, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "BINARY_MODULO", "long_name": "BINARY_MODULO( self , pc )", "filename": "bytecodecompiler.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "pc" ], "start_line": 956, "end_line": 957, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "COMPARE_OP", "long_name": "COMPARE_OP( self , pc , opname )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "self", "pc", "opname" ], "start_line": 958, "end_line": 960, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PRINT_ITEM", "long_name": "PRINT_ITEM( self , pc )", "filename": "bytecodecompiler.py", "nloc": 11, "complexity": 1, "token_count": 88, "parameters": [ "self", "pc" ], "start_line": 966, "end_line": 979, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "PRINT_NEWLINE", "long_name": "PRINT_NEWLINE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 6, "complexity": 1, "token_count": 41, "parameters": [ "self", "pc" ], "start_line": 985, "end_line": 992, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "SET_LINENO", "long_name": "SET_LINENO( self , pc , lineno )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 26, "parameters": [ "self", "pc", "lineno" ], "start_line": 997, "end_line": 999, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "POP_TOP", "long_name": "POP_TOP( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "self", "pc" ], "start_line": 1004, "end_line": 1006, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "LOAD_CONST", "long_name": "LOAD_CONST( self , pc , consti )", "filename": "bytecodecompiler.py", "nloc": 8, "complexity": 2, "token_count": 44, "parameters": [ "self", "pc", "consti" ], "start_line": 1011, "end_line": 1022, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "LOAD_FAST", "long_name": "LOAD_FAST( self , pc , var_num )", "filename": "bytecodecompiler.py", "nloc": 5, "complexity": 1, "token_count": 34, "parameters": [ "self", "pc", "var_num" ], "start_line": 1028, "end_line": 1032, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "LOAD_GLOBAL", "long_name": "LOAD_GLOBAL( self , pc , var_num )", "filename": "bytecodecompiler.py", "nloc": 26, "complexity": 3, "token_count": 178, "parameters": [ "self", "pc", "var_num" ], "start_line": 1037, "end_line": 1073, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 1 }, { "name": "STORE_FAST", "long_name": "STORE_FAST( self , pc , var_num )", "filename": "bytecodecompiler.py", "nloc": 9, "complexity": 3, "token_count": 72, "parameters": [ "self", "pc", "var_num" ], "start_line": 1078, "end_line": 1092, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "STORE_GLOBAL", "long_name": "STORE_GLOBAL( self , pc , var_num )", "filename": "bytecodecompiler.py", "nloc": 15, "complexity": 1, "token_count": 99, "parameters": [ "self", "pc", "var_num" ], "start_line": 1097, "end_line": 1117, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "CALL_FUNCTION", "long_name": "CALL_FUNCTION( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 25, "complexity": 4, "token_count": 166, "parameters": [ "self", "pc", "argc" ], "start_line": 1122, "end_line": 1157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "JUMP_IF_FALSE", "long_name": "JUMP_IF_FALSE( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 11, "complexity": 2, "token_count": 89, "parameters": [ "self", "pc", "delta" ], "start_line": 1163, "end_line": 1177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "JUMP_FORWARD", "long_name": "JUMP_FORWARD( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 6, "complexity": 1, "token_count": 36, "parameters": [ "self", "pc", "delta" ], "start_line": 1183, "end_line": 1189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "RETURN_VALUE", "long_name": "RETURN_VALUE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 10, "complexity": 3, "token_count": 57, "parameters": [ "self", "pc" ], "start_line": 1194, "end_line": 1203, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 } ], "methods_before": [], "changed_methods": [ { "name": "IMPORT_STAR", "long_name": "IMPORT_STAR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 463, "end_line": 465, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "CALL_FUNCTION_KW", "long_name": "CALL_FUNCTION_KW( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 645, "end_line": 647, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SLICE_1", "long_name": "SLICE_1( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 377, "end_line": 379, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "CALL_FUNCTION_VAR", "long_name": "CALL_FUNCTION_VAR( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 641, "end_line": 643, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_RSHIFT", "long_name": "INPLACE_RSHIFT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 355, "end_line": 357, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "MAKE_FUNCTION", "long_name": "MAKE_FUNCTION( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 625, "end_line": 627, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "LOAD_NAME", "long_name": "LOAD_NAME( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 521, "end_line": 523, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_DIVIDE", "long_name": "BINARY_DIVIDE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 285, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "bytecodecompiler.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 19, "end_line": 20, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "LOAD_DEREF", "long_name": "LOAD_DEREF( self , pc , i )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "i" ], "start_line": 605, "end_line": 607, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "FOR_LOOP", "long_name": "FOR_LOOP( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "delta" ], "start_line": 569, "end_line": 571, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "UNARY_NOT", "long_name": "UNARY_NOT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 263, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_AND", "long_name": "INPLACE_AND( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 359, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "UNPACK_SEQUENCE", "long_name": "UNPACK_SEQUENCE( self , pc , count )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "count" ], "start_line": 493, "end_line": 495, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_SUBSCR", "long_name": "BINARY_SUBSCR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 301, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_ATTR", "long_name": "DELETE_ATTR( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 505, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "JUMP_IF_TRUE", "long_name": "JUMP_IF_TRUE( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "delta" ], "start_line": 557, "end_line": 559, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SETUP_LOOP", "long_name": "SETUP_LOOP( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "delta" ], "start_line": 577, "end_line": 579, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "MAKE_CLOSURE", "long_name": "MAKE_CLOSURE( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 629, "end_line": 631, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BUILD_SLICE", "long_name": "BUILD_SLICE( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 633, "end_line": 635, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_GLOBAL", "long_name": "DELETE_GLOBAL( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 513, "end_line": 515, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SLICE_2", "long_name": "SLICE_2( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 381, "end_line": 383, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "opcodize", "long_name": "opcodize( s )", "filename": "bytecodecompiler.py", "nloc": 16, "complexity": 3, "token_count": 92, "parameters": [ "s" ], "start_line": 141, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "STORE_NAME", "long_name": "STORE_NAME( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 485, "end_line": 487, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "UNARY_INVERT", "long_name": "UNARY_INVERT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 271, "end_line": 273, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "JUMP_ABSOLUTE", "long_name": "JUMP_ABSOLUTE( self , pc , target )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "target" ], "start_line": 565, "end_line": 567, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_SUBSCR", "long_name": "STORE_SUBSCR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 423, "end_line": 425, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_ATTR", "long_name": "STORE_ATTR( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 501, "end_line": 503, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_SLICE_3", "long_name": "DELETE_SLICE_3( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 419, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "push", "long_name": "push( self , v , t )", "filename": "bytecodecompiler.py", "nloc": 4, "complexity": 1, "token_count": 26, "parameters": [ "self", "v", "t" ], "start_line": 859, "end_line": 862, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "BUILD_CLASS", "long_name": "BUILD_CLASS( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 479, "end_line": 481, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "LOAD_FAST", "long_name": "LOAD_FAST( self , pc , var_num )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "var_num" ], "start_line": 589, "end_line": 591, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SET_LINENO", "long_name": "SET_LINENO( self , pc , lineno )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "lineno" ], "start_line": 613, "end_line": 615, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "execute", "long_name": "execute( self , pc , opcode , argument )", "filename": "bytecodecompiler.py", "nloc": 7, "complexity": 2, "token_count": 54, "parameters": [ "self", "pc", "opcode", "argument" ], "start_line": 204, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "DELETE_SLICE_2", "long_name": "DELETE_SLICE_2( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 415, "end_line": 417, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_FAST", "long_name": "DELETE_FAST( self , pc , var_num )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "var_num" ], "start_line": 597, "end_line": 599, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PRINT_ITEM", "long_name": "PRINT_ITEM( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 435, "end_line": 437, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "IMPORT_FROM", "long_name": "IMPORT_FROM( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 549, "end_line": 551, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "emit", "long_name": "emit( self , s )", "filename": "bytecodecompiler.py", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self", "s" ], "start_line": 851, "end_line": 854, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "PRINT_EXPR", "long_name": "PRINT_EXPR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 431, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_MULTIPLY", "long_name": "INPLACE_MULTIPLY( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 331, "end_line": 333, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "fetch", "long_name": "fetch( self , pc , code )", "filename": "bytecodecompiler.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [ "self", "pc", "code" ], "start_line": 194, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "BUILD_LIST", "long_name": "BUILD_LIST( self , pc , count )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "count" ], "start_line": 529, "end_line": 531, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "JUMP_IF_FALSE", "long_name": "JUMP_IF_FALSE( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "delta" ], "start_line": 561, "end_line": 563, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "UNARY_POSITIVE", "long_name": "UNARY_POSITIVE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 255, "end_line": 257, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SLICE_3", "long_name": "SLICE_3( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 385, "end_line": 387, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "global_info", "long_name": "global_info( self , var_num )", "filename": "bytecodecompiler.py", "nloc": 11, "complexity": 4, "token_count": 73, "parameters": [ "self", "var_num" ], "start_line": 910, "end_line": 923, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "BINARY_MULTIPLY", "long_name": "BINARY_MULTIPLY( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 281, "end_line": 283, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_SLICE_3", "long_name": "STORE_SLICE_3( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 403, "end_line": 405, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_MODULO", "long_name": "BINARY_MODULO( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 289, "end_line": 291, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "UNARY_NEGATIVE", "long_name": "UNARY_NEGATIVE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 259, "end_line": 261, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_SLICE_2", "long_name": "STORE_SLICE_2( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 399, "end_line": 401, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SLICE_0", "long_name": "SLICE_0( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 373, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "RAISE_VARARGS", "long_name": "RAISE_VARARGS( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 617, "end_line": 619, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "ROT_THREE", "long_name": "ROT_THREE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 241, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "POP_TOP", "long_name": "POP_TOP( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 233, "end_line": 235, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "EXEC_STMT", "long_name": "EXEC_STMT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 467, "end_line": 469, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_OR", "long_name": "BINARY_OR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 321, "end_line": 323, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "ROT_FOUR", "long_name": "ROT_FOUR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 245, "end_line": 247, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PRINT_NEWLINE_TO", "long_name": "PRINT_NEWLINE_TO( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 447, "end_line": 449, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_SLICE_1", "long_name": "STORE_SLICE_1( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 395, "end_line": 397, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SETUP_EXCEPT", "long_name": "SETUP_EXCEPT( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "delta" ], "start_line": 581, "end_line": 583, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_ADD", "long_name": "INPLACE_ADD( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 343, "end_line": 345, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_POWER", "long_name": "INPLACE_POWER( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 327, "end_line": 329, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "CALL_FUNCTION_VAR_KW", "long_name": "CALL_FUNCTION_VAR_KW( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 649, "end_line": 651, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "unique", "long_name": "unique( self )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 16, "parameters": [ "self" ], "start_line": 878, "end_line": 880, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "LOAD_ATTR", "long_name": "LOAD_ATTR( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 537, "end_line": 539, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "POP_BLOCK", "long_name": "POP_BLOCK( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 471, "end_line": 473, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "COMPARE_OP", "long_name": "COMPARE_OP( self , pc , opname )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "opname" ], "start_line": 541, "end_line": 543, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_SUBSCR", "long_name": "DELETE_SUBSCR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 427, "end_line": 429, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_AND", "long_name": "BINARY_AND( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 313, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_RSHIFT", "long_name": "BINARY_RSHIFT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 309, "end_line": 311, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PRINT_NEWLINE", "long_name": "PRINT_NEWLINE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 443, "end_line": 445, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "pop", "long_name": "pop( self )", "filename": "bytecodecompiler.py", "nloc": 6, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 868, "end_line": 873, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "DUP_TOP", "long_name": "DUP_TOP( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 249, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "PRINT_ITEM_TO", "long_name": "PRINT_ITEM_TO( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 439, "end_line": 441, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_SLICE_0", "long_name": "STORE_SLICE_0( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 391, "end_line": 393, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "SETUP_FINALLY", "long_name": "SETUP_FINALLY( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "delta" ], "start_line": 585, "end_line": 587, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_ADD", "long_name": "BINARY_ADD( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 293, "end_line": 295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BREAK_LOOP", "long_name": "BREAK_LOOP( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 451, "end_line": 453, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_NAME", "long_name": "DELETE_NAME( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 489, "end_line": 491, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STOP_CODE", "long_name": "STOP_CODE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 230, "end_line": 232, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_LSHIFT", "long_name": "BINARY_LSHIFT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 305, "end_line": 307, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "LOAD_GLOBAL", "long_name": "LOAD_GLOBAL( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 573, "end_line": 575, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "evaluate", "long_name": "evaluate( self , pc , code )", "filename": "bytecodecompiler.py", "nloc": 9, "complexity": 3, "token_count": 54, "parameters": [ "self", "pc", "code" ], "start_line": 212, "end_line": 220, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "IMPORT_NAME", "long_name": "IMPORT_NAME( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 545, "end_line": 547, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_SLICE_1", "long_name": "DELETE_SLICE_1( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 411, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_GLOBAL", "long_name": "STORE_GLOBAL( self , pc , var_num )", "filename": "bytecodecompiler.py", "nloc": 15, "complexity": 1, "token_count": 99, "parameters": [ "self", "pc", "var_num" ], "start_line": 1097, "end_line": 1117, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "BINARY_SUBTRACT", "long_name": "BINARY_SUBTRACT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 297, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "UNARY_CONVERT", "long_name": "UNARY_CONVERT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 267, "end_line": 269, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_XOR", "long_name": "BINARY_XOR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 317, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_GLOBAL", "long_name": "STORE_GLOBAL( self , pc , namei )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "namei" ], "start_line": 509, "end_line": 511, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "listing", "long_name": "listing( f )", "filename": "bytecodecompiler.py", "nloc": 26, "complexity": 8, "token_count": 156, "parameters": [ "f" ], "start_line": 163, "end_line": 188, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "LOAD_CLOSURE", "long_name": "LOAD_CLOSURE( self , pc , i )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "i" ], "start_line": 601, "end_line": 603, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "emit_value", "long_name": "emit_value( self , v )", "filename": "bytecodecompiler.py", "nloc": 10, "complexity": 1, "token_count": 55, "parameters": [ "self", "v" ], "start_line": 894, "end_line": 905, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "BUILD_TUPLE", "long_name": "BUILD_TUPLE( self , pc , count )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "count" ], "start_line": 525, "end_line": 527, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , function , signature , name = None )", "filename": "bytecodecompiler.py", "nloc": 10, "complexity": 2, "token_count": 67, "parameters": [ "self", "function", "signature", "name" ], "start_line": 669, "end_line": 678, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "INPLACE_DIVIDE", "long_name": "INPLACE_DIVIDE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 335, "end_line": 337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "typedef_by_value", "long_name": "typedef_by_value( self , v )", "filename": "bytecodecompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "v" ], "start_line": 663, "end_line": 664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "bytecodecompiler.py", "nloc": 51, "complexity": 12, "token_count": 368, "parameters": [ "self" ], "start_line": 694, "end_line": 776, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 83, "top_nesting_level": 1 }, { "name": "JUMP_FORWARD", "long_name": "JUMP_FORWARD( self , pc , delta )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "delta" ], "start_line": 553, "end_line": 555, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "ROT_TWO", "long_name": "ROT_TWO( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 237, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_XOR", "long_name": "INPLACE_XOR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 363, "end_line": 365, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BINARY_POWER", "long_name": "BINARY_POWER( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 277, "end_line": 279, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_OR", "long_name": "INPLACE_OR( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 367, "end_line": 369, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "binop", "long_name": "binop( self , pc , symbol )", "filename": "bytecodecompiler.py", "nloc": 14, "complexity": 2, "token_count": 84, "parameters": [ "self", "pc", "symbol" ], "start_line": 928, "end_line": 943, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "post", "long_name": "post( self , pc , action )", "filename": "bytecodecompiler.py", "nloc": 5, "complexity": 2, "token_count": 41, "parameters": [ "self", "pc", "action" ], "start_line": 885, "end_line": 889, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "INPLACE_SUBTRACT", "long_name": "INPLACE_SUBTRACT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 347, "end_line": 349, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DELETE_SLICE_0", "long_name": "DELETE_SLICE_0( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 407, "end_line": 409, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "CALL_FUNCTION", "long_name": "CALL_FUNCTION( self , pc , argc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "argc" ], "start_line": 621, "end_line": 623, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "EXTENDED_ARG", "long_name": "EXTENDED_ARG( self , pc , ext )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "ext" ], "start_line": 637, "end_line": 639, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_FAST", "long_name": "STORE_FAST( self , pc , var_num )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "var_num" ], "start_line": 593, "end_line": 595, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "LOAD_GLOBAL", "long_name": "LOAD_GLOBAL( self , pc , var_num )", "filename": "bytecodecompiler.py", "nloc": 26, "complexity": 3, "token_count": 178, "parameters": [ "self", "pc", "var_num" ], "start_line": 1037, "end_line": 1073, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 1 }, { "name": "LOAD_LOCALS", "long_name": "LOAD_LOCALS( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 455, "end_line": 457, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "wrapped_code", "long_name": "wrapped_code( self )", "filename": "bytecodecompiler.py", "nloc": 52, "complexity": 5, "token_count": 294, "parameters": [ "self" ], "start_line": 782, "end_line": 845, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 64, "top_nesting_level": 1 }, { "name": "cmp_op", "long_name": "cmp_op( self , opname )", "filename": "bytecodecompiler.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "opname" ], "start_line": 227, "end_line": 228, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "LOAD_CONST", "long_name": "LOAD_CONST( self , pc , consti )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "consti" ], "start_line": 517, "end_line": 519, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "DUP_TOPX", "long_name": "DUP_TOPX( self , pc , count )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "count" ], "start_line": 497, "end_line": 499, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_LSHIFT", "long_name": "INPLACE_LSHIFT( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 351, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "STORE_DEREF", "long_name": "STORE_DEREF( self , pc , i )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "i" ], "start_line": 609, "end_line": 611, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "END_FINALLY", "long_name": "END_FINALLY( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 475, "end_line": 477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "INPLACE_MODULO", "long_name": "INPLACE_MODULO( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 339, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "BUILD_MAP", "long_name": "BUILD_MAP( self , pc , zero )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self", "pc", "zero" ], "start_line": 533, "end_line": 535, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "RETURN_VALUE", "long_name": "RETURN_VALUE( self , pc )", "filename": "bytecodecompiler.py", "nloc": 3, "complexity": 1, "token_count": 10, "parameters": [ "self", "pc" ], "start_line": 459, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 } ], "nloc": 830, "complexity": 189, "token_count": 4432, "diff_parsed": { "added": [ "#**************************************************************************#", "#* FILE ************** bytecodecompiler.py ************************#", "#************************************************************************ **#", "#* Author: Patrick Miller February 9 2002 *#", "#* Copyright (C) 2002 Patrick J. Miller *#", "#**************************************************************************#", "#* *#", "#**************************************************************************#", "from types import *", "import string", "import inspect", "", "", "##################################################################", "# CLASS CXXTYPEDESCRIPTION #", "##################################################################", "class Type_Descriptor:", " prerequisites = []", " def __repr__(self):", " return self.__module__+'.'+self.__class__.__name__", "", "", "haveArgument = 90 # Opcodes greater-equal to this have argument", "byName = {", " 'STOP_CODE': 0,", " 'POP_TOP': 1,", " 'ROT_TWO': 2,", " 'ROT_THREE': 3,", " 'DUP_TOP': 4,", " 'ROT_FOUR': 5,", " 'UNARY_POSITIVE': 10,", " 'UNARY_NEGATIVE': 11,", " 'UNARY_NOT': 12,", " 'UNARY_CONVERT': 13,", " 'UNARY_INVERT': 15,", " 'BINARY_POWER': 19,", " 'BINARY_MULTIPLY': 20,", " 'BINARY_DIVIDE': 21,", " 'BINARY_MODULO': 22,", " 'BINARY_ADD': 23,", " 'BINARY_SUBTRACT': 24,", " 'BINARY_SUBSCR': 25,", " 'BINARY_FLOOR_DIVIDE': 26,", " 'BINARY_TRUE_DIVIDE': 27,", " 'INPLACE_FLOOR_DIVIDE': 28,", " 'INPLACE_TRUE_DIVIDE': 29,", " 'SLICE': 30,", " 'STORE_SLICE': 40,", " 'DELETE_SLICE': 50,", " 'INPLACE_ADD': 55,", " 'INPLACE_SUBTRACT': 56,", " 'INPLACE_MULTIPLY': 57,", " 'INPLACE_DIVIDE': 58,", " 'INPLACE_MODULO': 59,", " 'STORE_SUBSCR': 60,", " 'DELETE_SUBSCR': 61,", " 'BINARY_LSHIFT': 62,", " 'BINARY_RSHIFT': 63,", " 'BINARY_AND': 64,", " 'BINARY_XOR': 65,", " 'BINARY_OR': 66,", " 'INPLACE_POWER': 67,", " 'GET_ITER': 68,", " 'PRINT_EXPR': 70,", " 'PRINT_ITEM': 71,", " 'PRINT_NEWLINE': 72,", " 'PRINT_ITEM_TO': 73,", " 'PRINT_NEWLINE_TO': 74,", " 'INPLACE_LSHIFT': 75,", " 'INPLACE_RSHIFT': 76,", " 'INPLACE_AND': 77,", " 'INPLACE_XOR': 78,", " 'INPLACE_OR': 79,", " 'BREAK_LOOP': 80,", " 'LOAD_LOCALS': 82,", " 'RETURN_VALUE': 83,", " 'IMPORT_STAR': 84,", " 'EXEC_STMT': 85,", " 'YIELD_VALUE': 86,", " 'POP_BLOCK': 87,", " 'END_FINALLY': 88,", " 'BUILD_CLASS': 89,", " 'STORE_NAME': 90,", " 'DELETE_NAME': 91,", " 'UNPACK_SEQUENCE': 92,", " 'FOR_ITER': 93,", " 'STORE_ATTR': 95,", " 'DELETE_ATTR': 96,", " 'STORE_GLOBAL': 97,", " 'DELETE_GLOBAL': 98,", " 'DUP_TOPX': 99,", " 'LOAD_CONST': 100,", " 'LOAD_NAME': 101,", " 'BUILD_TUPLE': 102,", " 'BUILD_LIST': 103,", " 'BUILD_MAP': 104,", " 'LOAD_ATTR': 105,", " 'COMPARE_OP': 106,", " 'IMPORT_NAME': 107,", " 'IMPORT_FROM': 108,", " 'JUMP_FORWARD': 110,", " 'JUMP_IF_FALSE': 111,", " 'JUMP_IF_TRUE': 112,", " 'JUMP_ABSOLUTE': 113,", " 'FOR_LOOP': 114,", " 'LOAD_GLOBAL': 116,", " 'CONTINUE_LOOP': 119,", " 'SETUP_LOOP': 120,", " 'SETUP_EXCEPT': 121,", " 'SETUP_FINALLY': 122,", " 'LOAD_FAST': 124,", " 'STORE_FAST': 125,", " 'DELETE_FAST': 126,", " 'SET_LINENO': 127,", " 'RAISE_VARARGS': 130,", " 'CALL_FUNCTION': 131,", " 'MAKE_FUNCTION': 132,", " 'BUILD_SLICE': 133,", " 'MAKE_CLOSURE': 134,", " 'LOAD_CLOSURE': 135,", " 'LOAD_DEREF': 136,", " 'STORE_DEREF': 137,", " 'CALL_FUNCTION_VAR': 140,", " 'CALL_FUNCTION_KW': 141,", " 'CALL_FUNCTION_VAR_KW': 142,", " }", "", "# -----------------------------------------------", "# Build one in the reverse sense", "# -----------------------------------------------", "byOpcode = {}", "for name,op in map(None, byName.keys(), byName.values()):", " byOpcode[op] = name", " del name", " del op", "", "", "##################################################################", "# FUNCTION OPCODIZE #", "##################################################################", "def opcodize(s):", " \"Slightly more readable form\"", " length = len(s)", " i = 0", " answer = []", " while i < length:", " bytecode = ord(s[i])", " name = byOpcode[bytecode]", " if bytecode >= haveArgument:", " argument = 256*ord(s[i+2])+ord(s[i+1])", " i += 3", " else:", " argument = None", " i += 1", " answer.append((bytecode,argument,name))", " return answer", "", "", "", "##################################################################", "# FUNCTION LIST #", "##################################################################", "def listing(f):", " \"Pretty print the internals of your function\"", " assert type(f) == FunctionType,\"Arg %r must be a function\"%f", " filename = f.func_code.co_filename", " try:", " lines = open(filename).readlines()", " except:", " lines = None", " pc = 0", " s = ''", " lastLine = None", " for op,arg,name in opcodize(f.func_code.co_code):", " if lines and name == 'SET_LINENO':", " source = lines[arg-1][:-1]", " while lastLine and lastLine < arg-1:", " nonEmittingSource = lines[lastLine][:-1]", " lastLine += 1", " s += '%3s %20s %5s : %s\\n'%(", " '','','',nonEmittingSource)", " lastLine = arg", " else:", " source = ''", " if arg == None: arg = ''", " s += '%3d] %20s %5s : %s\\n'%(pc,name,arg,source)", " pc += 1", " return s", "", "##################################################################", "# CLASS BYTECODEMEANING #", "##################################################################", "class ByteCodeMeaning:", " def fetch(self, pc,code):", " opcode = ord(code[pc])", " if opcode >= haveArgument:", " argument = 256*ord(code[pc+2])+ord(code[pc+1])", " next = pc+3", " else:", " argument = None", " next = pc+1", " return next,opcode,argument", "", " def execute(self,pc,opcode,argument):", " name = byOpcode[opcode]", " method = getattr(self,name)", " if argument == None:", " return apply(method,(pc,))", " else:", " return apply(method,(pc,argument,))", "", " def evaluate(self, pc,code):", " next, opcode,argument = self.fetch(pc,code)", " goto = self.execute(next,opcode,argument)", " if goto == -1:", " return None # Must be done", " elif goto == None:", " return next # Normal", " else:", " raise 'xx'", "", " symbols = { 0: 'less', 1: 'lesseq', 2: 'equal', 3: 'notequal',", " 4: 'greater', 5: 'greatereq', 6: 'in', 7: 'not in',", " 8: 'is', 9: 'is not', 10: 'exe match',", " 11 : 'bad',", " }", " def cmp_op(self,opname):", " return self.symbols[opname]", "", " def STOP_CODE(self,pc):", " \"Indicates end-of-code to the compiler, not used by the interpreter.\"", " raise NotImplementedError", " def POP_TOP(self,pc):", " \"Removes the top-of-stack (TOS) item.\"", " raise NotImplementedError", "", " def ROT_TWO(self,pc):", " \"Swaps the two top-most stack items.\"", " raise NotImplementedError", "", " def ROT_THREE(self,pc):", " \"Lifts second and third stack item one position up, moves top down to position three.\"", " raise NotImplementedError", "", " def ROT_FOUR(self,pc):", " \"Lifts second, third and forth stack item one position up, moves top down to position four.\"", " raise NotImplementedError", "", " def DUP_TOP(self,pc):", " \"Duplicates the reference on top of the stack.\"", " raise NotImplementedError", "", " # Unary Operations take the top of the stack, apply the operation, and push the result back on the stack.", "", " def UNARY_POSITIVE(self,pc):", " \"Implements TOS = +TOS.\"", " raise NotImplementedError", "", " def UNARY_NEGATIVE(self,pc):", " \"Implements TOS = -TOS.\"", " raise NotImplementedError", "", " def UNARY_NOT(self,pc):", " \"Implements TOS = not TOS.\"", " raise NotImplementedError", "", " def UNARY_CONVERT(self,pc):", " \"Implements TOS = `TOS`.\"", " raise NotImplementedError", "", " def UNARY_INVERT(self,pc):", " \"Implements TOS = ~TOS.\"", " raise NotImplementedError", "", " #Binary operations remove the top of the stack (TOS) and the second top-most stack item (TOS1) from the stack. They perform the operation, and put the result back on the stack.", "", " def BINARY_POWER(self,pc):", " \"Implements TOS = TOS1 ** TOS.\"", " raise NotImplementedError", "", " def BINARY_MULTIPLY(self,pc):", " \"Implements TOS = TOS1 * TOS.\"", " raise NotImplementedError", "", " def BINARY_DIVIDE(self,pc):", " \"Implements TOS = TOS1 / TOS.\"", " raise NotImplementedError", "", " def BINARY_MODULO(self,pc):", " \"Implements TOS = TOS1 % TOS.\"", " raise NotImplementedError", "", " def BINARY_ADD(self,pc):", " \"Implements TOS = TOS1 + TOS.\"", " raise NotImplementedError", "", " def BINARY_SUBTRACT(self,pc):", " \"Implements TOS = TOS1 - TOS.\"", " raise NotImplementedError", "", " def BINARY_SUBSCR(self,pc):", " \"Implements TOS = TOS1[TOS].\"", " raise NotImplementedError", "", " def BINARY_LSHIFT(self,pc):", " \"Implements TOS = TOS1 << TOS.\"", " raise NotImplementedError", "", " def BINARY_RSHIFT(self,pc):", " \"Implements TOS = TOS1 >> TOS.\"", " raise NotImplementedError", "", " def BINARY_AND(self,pc):", " \"Implements TOS = TOS1 & TOS.\"", " raise NotImplementedError", "", " def BINARY_XOR(self,pc):", " \"Implements TOS = TOS1 ^ TOS.\"", " raise NotImplementedError", "", " def BINARY_OR(self,pc):", " \"Implements TOS = TOS1 | TOS.\"", " raise NotImplementedError", "", " #In-place operations are like binary operations, in that they remove TOS and TOS1, and push the result back on the stack, but the operation is done in-place when TOS1 supports it, and the resulting TOS may be (but does not have to be) the original TOS1.", "", " def INPLACE_POWER(self,pc):", " \"Implements in-place TOS = TOS1 ** TOS.\"", " raise NotImplementedError", "", " def INPLACE_MULTIPLY(self,pc):", " \"Implements in-place TOS = TOS1 * TOS.\"", " raise NotImplementedError", "", " def INPLACE_DIVIDE(self,pc):", " \"Implements in-place TOS = TOS1 / TOS.\"", " raise NotImplementedError", "", " def INPLACE_MODULO(self,pc):", " \"Implements in-place TOS = TOS1 % TOS.\"", " raise NotImplementedError", "", " def INPLACE_ADD(self,pc):", " \"Implements in-place TOS = TOS1 + TOS.\"", " raise NotImplementedError", "", " def INPLACE_SUBTRACT(self,pc):", " \"Implements in-place TOS = TOS1 - TOS.\"", " raise NotImplementedError", "", " def INPLACE_LSHIFT(self,pc):", " \"Implements in-place TOS = TOS1 << TOS.\"", " raise NotImplementedError", "", " def INPLACE_RSHIFT(self,pc):", " \"Implements in-place TOS = TOS1 >> TOS.\"", " raise NotImplementedError", "", " def INPLACE_AND(self,pc):", " \"Implements in-place TOS = TOS1 & TOS.\"", " raise NotImplementedError", "", " def INPLACE_XOR(self,pc):", " \"Implements in-place TOS = TOS1 ^ TOS.\"", " raise NotImplementedError", "", " def INPLACE_OR(self,pc):", " \"Implements in-place TOS = TOS1 | TOS.\"", " raise NotImplementedError", "", " #The slice opcodes take up to three parameters.", "", " def SLICE_0(self,pc):", " \"Implements TOS = TOS[:].\"", " raise NotImplementedError", "", " def SLICE_1(self,pc):", " \"Implements TOS = TOS1[TOS:].\"", " raise NotImplementedError", "", " def SLICE_2(self,pc):", " \"Implements TOS = TOS1[:TOS1].\"", " raise NotImplementedError", "", " def SLICE_3(self,pc):", " \"Implements TOS = TOS2[TOS1:TOS].\"", " raise NotImplementedError", "", " #Slice assignment needs even an additional parameter. As any statement, they put nothing on the stack.", "", " def STORE_SLICE_0(self,pc):", " \"Implements TOS[:] = TOS1.\"", " raise NotImplementedError", "", " def STORE_SLICE_1(self,pc):", " \"Implements TOS1[TOS:] = TOS2.\"", " raise NotImplementedError", "", " def STORE_SLICE_2(self,pc):", " \"Implements TOS1[:TOS] = TOS2.\"", " raise NotImplementedError", "", " def STORE_SLICE_3(self,pc):", " \"Implements TOS2[TOS1:TOS] = TOS3.\"", " raise NotImplementedError", "", " def DELETE_SLICE_0(self,pc):", " \"Implements del TOS[:].\"", " raise NotImplementedError", "", " def DELETE_SLICE_1(self,pc):", " \"Implements del TOS1[TOS:].\"", " raise NotImplementedError", "", " def DELETE_SLICE_2(self,pc):", " \"Implements del TOS1[:TOS].\"", " raise NotImplementedError", "", " def DELETE_SLICE_3(self,pc):", " \"Implements del TOS2[TOS1:TOS].\"", " raise NotImplementedError", "", " def STORE_SUBSCR(self,pc):", " \"Implements TOS1[TOS] = TOS2.\"", " raise NotImplementedError", "", " def DELETE_SUBSCR(self,pc):", " \"Implements del TOS1[TOS].\"", " raise NotImplementedError", "", " def PRINT_EXPR(self,pc):", " \"Implements the expression statement for the interactive mode. TOS is removed from the stack and printed. In non-interactive mode, an expression statement is terminated with POP_STACK.\"", " raise NotImplementedError", "", " def PRINT_ITEM(self,pc):", " \"Prints TOS to the file-like object bound to sys.stdout. There is one such instruction for each item in the print statement.\"", " raise NotImplementedError", "", " def PRINT_ITEM_TO(self,pc):", " \"Like PRINT_ITEM, but prints the item second from TOS to the file-like object at TOS. This is used by the extended print statement.\"", " raise NotImplementedError", "", " def PRINT_NEWLINE(self,pc):", " \"Prints a new line on sys.stdout. This is generated as the last operation of a print statement, unless the statement ends with a comma.\"", " raise NotImplementedError", "", " def PRINT_NEWLINE_TO(self,pc):", " \"Like PRINT_NEWLINE, but prints the new line on the file-like object on the TOS. This is used by the extended print statement.\"", " raise NotImplementedError", "", " def BREAK_LOOP(self,pc):", " \"Terminates a loop due to a break statement.\"", " raise NotImplementedError", "", " def LOAD_LOCALS(self,pc):", " \"Pushes a reference to the locals of the current scope on the stack. This is used in the code for a class definition: After the class body is evaluated, the locals are passed to the class definition.\"", " raise NotImplementedError", "", " def RETURN_VALUE(self,pc):", " \"Returns with TOS to the caller of the function.\"", " raise NotImplementedError", "", " def IMPORT_STAR(self,pc):", " \"Loads all symbols not starting with _ directly from the module TOS to the local namespace. The module is popped after loading all names. This opcode implements from module import *.\"", " raise NotImplementedError", "", " def EXEC_STMT(self,pc):", " \"Implements exec TOS2,TOS1,TOS. The compiler fills missing optional parameters with None.\"", " raise NotImplementedError", "", " def POP_BLOCK(self,pc):", " \"Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.\"", " raise NotImplementedError", "", " def END_FINALLY(self,pc):", " \"Terminates a finally clause. The interpreter recalls whether the exception has to be re-raised, or whether the function returns, and continues with the outer-next block.\"", " raise NotImplementedError", "", " def BUILD_CLASS(self,pc):", " \"Creates a new class object. TOS is the methods dictionary, TOS1 the tuple of the names of the base classes, and TOS2 the class name.\"", " raise NotImplementedError", "", " #All of the following opcodes expect arguments. An argument is two bytes, with the more significant byte last.", "", " def STORE_NAME(self,pc,namei):", " \"Implements name = TOS. namei is the index of name in the attribute co_names of the code object. The compiler tries to use STORE_LOCAL or STORE_GLOBAL if possible.\"", " raise NotImplementedError", "", " def DELETE_NAME(self,pc,namei):", " \"Implements del name, where namei is the index into co_names attribute of the code object.\"", " raise NotImplementedError", "", " def UNPACK_SEQUENCE(self,pc,count):", " \"Unpacks TOS into count individual values, which are put onto the stack right-to-left.\"", " raise NotImplementedError", "", " def DUP_TOPX(self,pc,count):", " \"Duplicate count items, keeping them in the same order. Due to implementation limits, count should be between 1 and 5 inclusive.\"", " raise NotImplementedError", "", " def STORE_ATTR(self,pc,namei):", " \"Implements TOS.name = TOS1, where namei is the index of name in co_names.\"", " raise NotImplementedError", "", " def DELETE_ATTR(self,pc,namei):", " \"Implements del TOS.name, using namei as index into co_names.\"", " raise NotImplementedError", "", " def STORE_GLOBAL(self,pc,namei):", " \"Works as STORE_NAME, but stores the name as a global.\"", " raise NotImplementedError", "", " def DELETE_GLOBAL(self,pc,namei):", " \"Works as DELETE_NAME, but deletes a global name.\"", " raise NotImplementedError", "", " def LOAD_CONST(self,pc,consti):", " \"Pushes co_consts[consti] onto the stack.\"", " raise NotImplementedError", "", " def LOAD_NAME(self,pc,namei):", " \"Pushes the value associated with co_names[namei] onto the stack.\"", " raise NotImplementedError", "", " def BUILD_TUPLE(self,pc,count):", " \"Creates a tuple consuming count items from the stack, and pushes the resulting tuple onto the stack.\"", " raise NotImplementedError", "", " def BUILD_LIST(self,pc,count):", " \"Works as BUILD_TUPLE, but creates a list.\"", " raise NotImplementedError", "", " def BUILD_MAP(self,pc,zero):", " \"Pushes a new empty dictionary object onto the stack. The argument is ignored and set to zero by the compiler.\"", " raise NotImplementedError", "", " def LOAD_ATTR(self,pc,namei):", " \"Replaces TOS with getattr(TOS, co_names[namei].\"", " raise NotImplementedError", "", " def COMPARE_OP(self,pc,opname):", " \"Performs a Boolean operation. The operation name can be found in cmp_op[opname].\"", " raise NotImplementedError", "", " def IMPORT_NAME(self,pc,namei):", " \"Imports the module co_names[namei]. The module object is pushed onto the stack. The current namespace is not affected: for a proper import statement, a subsequent STORE_FAST instruction modifies the namespace.\"", " raise NotImplementedError", "", " def IMPORT_FROM(self,pc,namei):", " \"Loads the attribute co_names[namei] from the module found in TOS. The resulting object is pushed onto the stack, to be subsequently stored by a STORE_FAST instruction.\"", " raise NotImplementedError", "", " def JUMP_FORWARD(self,pc,delta):", " \"Increments byte code counter by delta.\"", " raise NotImplementedError", "", " def JUMP_IF_TRUE(self,pc,delta):", " \"If TOS is true, increment the byte code counter by delta. TOS is left on the stack.\"", " raise NotImplementedError", "", " def JUMP_IF_FALSE(self,pc,delta):", " \"If TOS is false, increment the byte code counter by delta. TOS is not changed.\"", " raise NotImplementedError", "", " def JUMP_ABSOLUTE(self,pc,target):", " \"Set byte code counter to target.\"", " raise NotImplementedError", "", " def FOR_LOOP(self,pc,delta):", " \"Iterate over a sequence. TOS is the current index, TOS1 the sequence. First, the next element is computed. If the sequence is exhausted, increment byte code counter by delta. Otherwise, push the sequence, the incremented counter, and the current item onto the stack.\"", " raise NotImplementedError", "", " def LOAD_GLOBAL(self,pc,namei):", " \"Loads the global named co_names[namei] onto the stack.\"", " raise NotImplementedError", "", " def SETUP_LOOP(self,pc,delta):", " \"Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.\"", " raise NotImplementedError", "", " def SETUP_EXCEPT(self,pc,delta):", " \"Pushes a try block from a try-except clause onto the block stack. delta points to the first except block.\"", " raise NotImplementedError", "", " def SETUP_FINALLY(self,pc,delta):", " \"Pushes a try block from a try-except clause onto the block stack. delta points to the finally block.\"", " raise NotImplementedError", "", " def LOAD_FAST(self,pc,var_num):", " \"Pushes a reference to the local co_varnames[var_num] onto the stack.\"", " raise NotImplementedError", "", " def STORE_FAST(self,pc,var_num):", " \"Stores TOS into the local co_varnames[var_num].\"", " raise NotImplementedError", "", " def DELETE_FAST(self,pc,var_num):", " \"Deletes local co_varnames[var_num].\"", " raise NotImplementedError", "", " def LOAD_CLOSURE(self,pc,i):", " \"Pushes a reference to the cell contained in slot i of the cell and free variable storage. The name of the variable is co_cellvars[i] if i is less than the length of co_cellvars. Otherwise it is co_freevars[i - len(co_cellvars)].\"", " raise NotImplementedError", "", " def LOAD_DEREF(self,pc,i):", " \"Loads the cell contained in slot i of the cell and free variable storage. Pushes a reference to the object the cell contains on the stack.\"", " raise NotImplementedError", "", " def STORE_DEREF(self,pc,i):", " \"Stores TOS into the cell contained in slot i of the cell and free variable storage.\"", " raise NotImplementedError", "", " def SET_LINENO(self,pc,lineno):", " \"Sets the current line number to lineno.\"", " raise NotImplementedError", "", " def RAISE_VARARGS(self,pc,argc):", " \"Raises an exception. argc indicates the number of parameters to the raise statement, ranging from 0 to 3. The handler will find the traceback as TOS2, the parameter as TOS1, and the exception as TOS.\"", " raise NotImplementedError", "", " def CALL_FUNCTION(self,pc,argc):", " \"Calls a function. The low byte of argc indicates the number of positional parameters, the high byte the number of keyword parameters. On the stack, the opcode finds the keyword parameters first. For each keyword argument, the value is on top of the key. Below the keyword parameters, the positional parameters are on the stack, with the right-most parameter on top. Below the parameters, the function object to call is on the stack.\"", " raise NotImplementedError", "", " def MAKE_FUNCTION(self,pc,argc):", " \"Pushes a new function object on the stack. TOS is the code associated with the function. The function object is defined to have argc default parameters, which are found below TOS.\"", " raise NotImplementedError", "", " def MAKE_CLOSURE(self,pc,argc):", " \"Creates a new function object, sets its func_closure slot, and pushes it on the stack. TOS is the code associated with the function. If the code object has N free variables, the next N items on the stack are the cells for these variables. The function also has argc default parameters, where are found before the cells.\"", " raise NotImplementedError", "", " def BUILD_SLICE(self,pc,argc):", " \"Pushes a slice object on the stack. argc must be 2 or 3. If it is 2, slice(TOS1, TOS) is pushed; if it is 3, slice(TOS2, TOS1, TOS) is pushed. See the slice() built-in function for more information.\"", " raise NotImplementedError", "", " def EXTENDED_ARG(self,pc,ext):", " \"Prefixes any opcode which has an argument too big to fit into the default two bytes. ext holds two additional bytes which, taken together with the subsequent opcode's argument, comprise a four-byte argument, ext being the two most-significant bytes.\"", " raise NotImplementedError", "", " def CALL_FUNCTION_VAR(self,pc,argc):", " \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the variable argument list, followed by keyword and positional arguments.\"", " raise NotImplementedError", "", " def CALL_FUNCTION_KW(self,pc,argc):", " \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by explicit keyword and positional arguments.\"", " raise NotImplementedError", "", " def CALL_FUNCTION_VAR_KW(self,pc,argc):", " \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by the variable-arguments tuple, followed by explicit keyword and positional arguments.\"", " raise NotImplementedError", "", "", "", "##################################################################", "# CLASS CXXCODER #", "##################################################################", "class CXXCoder(ByteCodeMeaning):", "", " ##################################################################", " # MEMBER TYPEDEF_BY_VALUE #", " ##################################################################", " def typedef_by_value(self,v):", " raise NotImplementedError # VIRTUAL", "", " ##################################################################", " # MEMBER __INIT__ #", " ##################################################################", " def __init__(self,function,signature,name=None):", " assert type(function) == FunctionType,\"Arg must be a user function\"", " assert not function.func_defaults ,\"Function cannot have default args (yet)\"", " if name == None: name = function.func_name", " self.name = name", " self.function = function", " self.signature = signature", " self.codeobject = function.func_code", " self.__uid = 0 # Builds temps", " return", "", " ##################################################################", " # MEMBER EVALUATE #", " ##################################################################", " def evaluate(self, pc,code):", " # See if we posted any forwards for this offset", " if self.forwards.has_key(pc):", " for f in self.forwards[pc]:", " f()", " self.forwards[pc] = []", " return ByteCodeMeaning.evaluate(self,pc,code)", "", " ##################################################################", " # MEMBER GENERATE #", " ##################################################################", " def generate(self):", " self.forwards = {} # Actions on forward interprets", " self.__body = '' # Body will be built", " self.helpers = [] # headers and stuff", "", " # -----------------------------------------------", " # OK, crack open the function object and build", " # initial stack (not a real frame!)", " # -----------------------------------------------", " arglen = len(self.signature)", " nlocals = self.codeobject.co_nlocals", "", " self.consts = self.codeobject.co_consts", " self.stack = list(self.codeobject.co_varnames)", " self.types = list(self.signature)+[None]*(nlocals-arglen)", " self.used = []", " for T in self.types:", " if T not in self.used: self.used.append(T)", "", " # -----------------------------------------------", " # One pass through the byte codes to generate", " # the body", " # -----------------------------------------------", " code = self.codeobject.co_code", " pc = 0", " while pc != None:", " pc = self.evaluate(pc,code)", "", " # -----------------------------------------------", " # Return?", " # -----------------------------------------------", " if self.rtype == NoneType:", " rtype = 'void'", " else:", " rtype = self.rtype.cxxtype", "", " # -----------------------------------------------", " # Insert code body if available", " # -----------------------------------------------", " source = inspect.getsource(self.function)", " if not source: source = ''", " comments = inspect.getcomments(self.function)", " if comments: source = comments+source", " code = string.join(map(lambda x: '/////// '+x,string.split(source,'\\n')),", " '\\n')+'\\n'", "", " # -----------------------------------------------", " # Add in the headers", " # -----------------------------------------------", " code += '#include \"Python.h\"\\n'", " for T in self.used:", " print T.prerequisites", " for pre in T.prerequisites:", " code += pre", " code += '\\n'", "", " # -----------------------------------------------", " # Real body", " # -----------------------------------------------", " code += '\\n'", " code += '\\nstatic %s %s('%(rtype,self.name)", " for i in range(len(self.signature)):", " if i != 0: code += ', '", " n = self.stack[i]", " t = self.types[i]", " code += '%s %s'%(t.cxxtype,n)", " code += ') {\\n'", "", " # Add in non-argument temporaries", " # Assuming first argcount locals are positional args", " for i in range(self.codeobject.co_argcount,", " self.codeobject.co_nlocals):", " t = self.types[i]", " descriptor = typedefs[t]", " code += '%s %s;\\n'%(", " descriptor.cxxtype,", " self.codeobject.co_varnames[i],", " )", "", " # Add in the body", " code += self.__body", " code += '}\\n\\n'", " return code", "", "", " ##################################################################", " # MEMBER WRAPPED_CODE #", " ##################################################################", " def wrapped_code(self):", " code = self.generate()", "", " # -----------------------------------------------", " # Wrapper", " # -----------------------------------------------", " code += 'static PyObject* wrapper_%s(PyObject*,PyObject* args) {\\n'%self.name", "", " code += ' // Length check\\n'", " code += ' if ( PyTuple_Size(args) != %d ) {\\n'%len(self.signature)", " code += ' PyErr_SetString(PyExc_TypeError,\"Expected %d arguments\");\\n'%len(self.signature)", " code += ' return 0;\\n'", " code += ' }\\n'", "", " code += '\\n // Load Py versions of args\\n'", " for i in range(len(self.signature)):", " T = self.signature[i]", " code += ' PyObject* py_%s = PyTuple_GET_ITEM(args,%d);\\n'%(", " self.codeobject.co_varnames[i],i", " )", "", " code += ' if ( !%s ) {\\n'% \\", " T.check('py_'+self.codeobject.co_varnames[i])", " code += ' PyErr_SetString(PyExc_TypeError,\"Bad type for arg %d (expected %s)\");\\n'%(", " i+1,", " T.__class__.__name__)", " code += ' return 0;\\n'", " code += ' }\\n'", "", " code += '\\n // Do conversions\\n'", " argnames = []", " for i in range(len(self.signature)):", " T = self.signature[i]", "", " code += ' %s %s=%s;\\n'%(", " T.cxxtype,", " self.codeobject.co_varnames[i],", " T.inbound('py_'+self.codeobject.co_varnames[i]),", " )", " code += ' if ( PyErr_Occurred() ) return 0;\\n'", " argnames.append(self.codeobject.co_varnames[i])", "", " code += '\\n // Compute result\\n'", " if self.rtype != NoneType:", " code += ' %s _result = '%(", " self.rtype.cxxtype,", " )", " else:", " code += ' '", " code += '%s(%s);\\n'%(", " self.name,", " string.join(argnames,','),", " )", "", "", " code += '\\n // Pack return\\n'", " if ( self.rtype == NoneType ):", " code += ' Py_INCREF(Py_None);\\n'", " code += ' return Py_None;\\n'", " else:", " result = self.rtype.outbound('_result')", " code += ' return %s;\\n'%result", " code += '}\\n'", " return code", "", "", " ##################################################################", " # MEMBER EMIT #", " ##################################################################", " def emit(self,s):", " self.__body += s", " self.__body += '\\n'", " return", "", " ##################################################################", " # MEMBER PUSH #", " ##################################################################", " def push(self,v,t):", " self.stack.append(v)", " self.types.append(t)", " return", "", "", " ##################################################################", " # MEMBER POP #", " ##################################################################", " def pop(self):", " v = self.stack[-1]", " del self.stack[-1]", " t = self.types[-1]", " del self.types[-1]", " return v,t", "", " ##################################################################", " # MEMBER UNIQUE #", " ##################################################################", " def unique(self):", " self.__uid += 1", " return 't%d'%self.__uid", "", " ##################################################################", " # MEMBER POST #", " ##################################################################", " def post(self,pc,action):", " if not self.forwards.has_key(pc):", " self.forwards[pc] = []", " self.forwards[pc].append(action)", " return", "", " ##################################################################", " # MEMBER EMIT_VALUE #", " ##################################################################", " def emit_value(self, v):", " descriptor = self.typedef_by_value(v)", "", " # Convert representation to CXX rhs", " rhs = descriptor.literalizer(v)", " lhs = self.unique()", " self.emit('%s %s = %s;'%(", " descriptor.cxxtype,", " lhs,", " rhs))", " self.push(lhs,descriptor)", " return", "", " ##################################################################", " # MEMBER GLOBAL_INFO #", " ##################################################################", " def global_info(self,var_num):", " # This is the name value is known by", " var_name = self.codeobject.co_names[var_num]", "", " # First, figure out who owns this global", " import sys", " myHash = id(self.function.func_globals)", " for module_name in sys.modules.keys():", " module = sys.modules[module_name]", " if module and id(module.__dict__) == myHash:", " break", " else:", " raise ValueError,'Cannot locate module owning %s'%varname", " return module_name,var_name", "", " ##################################################################", " # MEMBER BINOP #", " ##################################################################", " def binop(self,pc,symbol):", " v2,t2 = self.pop()", " v1,t1 = self.pop()", "", " if t1 == t2:", " rhs,rhs_type = t1.binop(symbol,v1,v2)", " else:", " raise NotImplementedError,'mixed types'", "", " lhs = self.unique()", " self.emit('%s %s = %s;\\n'%(", " rhs_type.cxxtype,", " lhs,", " rhs))", " self.push(lhs,rhs_type)", " return", "", " ##################################################################", " # MEMBER BINARY_XXX #", " ##################################################################", " def BINARY_ADD(self,pc):", " return self.binop(pc,'+')", " def BINARY_SUBTRACT(self,pc):", " return self.binop(pc,'-')", " def BINARY_MULTIPLY(self,pc):", " return self.binop(pc,'*')", " def BINARY_DIVIDE(self,pc):", " return self.binop(pc,'/')", " def BINARY_MODULO(self,pc):", " return self.binop(pc,'%')", " def COMPARE_OP(self,pc,opname):", " symbol = self.cmp_op(opname) # convert numeric to name", " return self.binop(pc,symbol)", "", "", " ##################################################################", " # MEMBER PRINT_ITEM #", " ##################################################################", " def PRINT_ITEM(self,pc):", " # Printing correctly is tricky... best to let Python", " # do the real work here", " w = self.unique()", " self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)", " self.emit('if (PyFile_SoftSpace(%s,1)) PyFile_WriteString(\" \",%s);'%(w,w))", " v,t = self.pop()", "", " py = self.unique()", " self.emit('PyObject* %s = %s;'%(py, t.outbound(v)))", " self.emit('PyFile_WriteObject(%s,%s,Py_PRINT_RAW);'%(", " py,w))", " self.emit('Py_XDECREF(%s);'%py)", " return", "", "", " ##################################################################", " # MEMBER PRINT_NEWLINE #", " ##################################################################", " def PRINT_NEWLINE(self,pc):", " # Printing correctly is tricky... best to let Python", " # do the real work here", " w = self.unique()", " self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)", " self.emit('PyFile_WriteString(\"\\\\n\",%s);'%w);", " self.emit('PyFile_SoftSpace(%s,0);'%w);", " return", "", " ##################################################################", " # MEMBER SET_LINENO #", " ##################################################################", " def SET_LINENO(self,pc,lineno):", " self.emit('// %s:%d'%(self.codeobject.co_filename,lineno))", " return", "", " ##################################################################", " # MEMBER POP_TOP #", " ##################################################################", " def POP_TOP(self,pc):", " v,t = self.pop()", " return", "", " ##################################################################", " # MEMBER LOAD_CONST #", " ##################################################################", " def LOAD_CONST(self,pc,consti):", " # Fetch the constant", " k = self.consts[consti]", " t = type(k)", "", " # Fetch a None is just skipped", " if t == NoneType:", " self.push('',t)", " return", "", " self.emit_value(k)", " return", "", "", " ##################################################################", " # MEMBER LOAD_FAST #", " ##################################################################", " def LOAD_FAST(self,pc,var_num):", " v = self.stack[var_num]", " t = self.types[var_num]", " self.push(v,t)", " return", "", " ##################################################################", " # MEMBER LOAD_GLOBAL #", " ##################################################################", " def LOAD_GLOBAL(self,pc,var_num):", " # Figure out the name and load it", " try:", " F = self.function.func_globals[self.codeobject.co_names[var_num]]", " except:", " F = getattr(__builtins__,self.codeobject.co_names[var_num])", "", " # For functions, we see if we know about this function", " if callable(F):", " assert functiondefs.has_key(F),\"Function %s is known\"%F", " self.push(F,type(F))", " return", "", " # We need the name of the module that matches", " # the global state for the function and", " # the name of the variable", " module_name,var_name = self.global_info(var_num)", "", " # We hope it's type is correct", " t = type(F)", " descriptor = typedefs[t]", " native = self.unique()", " py = self.unique()", " mod = self.unique()", "", " self.emit('')", " self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(", " mod,module_name))", " self.emit('PyObject* %s = PyObject_GetAttrString(%s,\"%s\");'%(", " py,mod,var_name))", " self.emit('%s %s = %s;'%(", " descriptor.cxxtype,", " native,", " descriptor.inbound%py))", "", " self.push(native,t)", " return", "", " ##################################################################", " # MEMBER STORE_FAST #", " ##################################################################", " def STORE_FAST(self,pc,var_num):", "", " v,t = self.pop()", "", " save = self.stack[var_num]", " saveT = self.types[var_num]", "", " # See if type is same....", " # Note that None means no assignment made yet", " if saveT == None or t == saveT:", " self.emit('%s = %s;\\n'%(save,v))", " self.types[var_num] = t", " return", "", " raise TypeError,(t,saveT)", "", " ##################################################################", " # MEMBER STORE_GLOBAL #", " ##################################################################", " def STORE_GLOBAL(self,pc,var_num):", "", " # We need the name of the module that matches", " # the global state for the function and", " # the name of the variable", " module_name,var_name = self.global_info(var_num)", "", " # Convert the value to Python object", " v,t = self.pop()", " descriptor = typedefs[t]", " py = self.unique()", " self.emit('PyObject* %s = %s;'%(", " py,", " descriptor.outbound%v))", " mod = self.unique()", " self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(", " mod,module_name))", " self.emit('PyObject_SetAttrString(%s,\"%s\",%s);'%(", " mod,var_name,py))", " self.emit('Py_DECREF(%s);'%py)", " return", "", " ##################################################################", " # MEMBER CALL_FUNCTION #", " ##################################################################", " def CALL_FUNCTION(self,pc,argc):", " # Pull args off stack", " args = []", " types = []", " for i in range(argc):", " v,t = self.pop()", " args = [v]+args", " types = [t]+types", "", " # Pull function object off stack and get descriptor", " f,t = self.pop()", " descriptor = functiondefs[f]", " #self.prerequisites += descriptor['prerequisite']+'\\n'", "", " # Look through descriptors for a match", " for inputs,outputs,format in descriptor:", " if inputs == types:", " break", " else:", " raise TypeError,f", "", " # Build a rhs", " rhs = format%string.join(args,',')", "", " # Build a statement", " assert len(outputs) == 1,\"Single valued return\"", " assert typedefs.has_key(outputs[0]),\"Know about type %s\"%outputs[0]", " description = typedefs[outputs[0]]", " temp = self.unique()", " self.emit('%s %s = %s;\\n'%(", " description.cxxtype,", " temp,", " rhs))", "", " self.push(temp,outputs[0])", " return", "", "", " ##################################################################", " # MEMBER JUMP_IF_FALSE #", " ##################################################################", " def JUMP_IF_FALSE(self,pc,delta):", " v,t = self.pop()", " self.push(v,t)", " # We need to do some work when we get to the", " # else part (put the value that's gonna get", " # popped back on the stack, emit } else {,", " # ...)", " action = lambda v=v,t=t,self=self: (", " self.emit('} else {'),", " self.push(v,t),", " )", " self.post(pc+delta,action)", " if t != IntType: raise TypeError, 'Invalid comparison type %s'%t", " self.emit('if (%s) {\\n'%v)", " return", "", "", " ##################################################################", " # MEMBER JUMP_FORWARD #", " ##################################################################", " def JUMP_FORWARD(self,pc,delta):", " # We need to close the if after the delta", " action = lambda self=self: (", " self.emit('}'),", " )", " self.post(pc+delta,action)", " return", "", " ##################################################################", " # MEMBER RETURN_VALUE #", " ##################################################################", " def RETURN_VALUE(self,pc):", " v,t = self.pop()", " if hasattr(self,'rtype'):", " raise ValueError,'multiple returns'", " self.rtype = t", " if t == NoneType:", " self.emit('return;')", " else:", " self.emit('return %s;'%v)", " return -1", "" ], "deleted": [] } } ] }, { "hash": "1f880dac85d9ba8f01006db67e61f924df983af0", "msg": "When Fortran compilers didn't specify a shared library, the Fortran specific libraries were linked in. The additions hopefully take care of this.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-02-19T07:31:04+00:00", "author_timezone": 0, "committer_date": "2002-02-19T07:31:04+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "0894dd3f103ce8e44416fb3369f241dee5c6dd9a" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 1, "insertions": 15, "lines": 16, "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": "@@ -21,6 +21,7 @@ def build_extension(self, ext):\n # support for building static fortran libraries\n need_f_libs = 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@@ -31,6 +32,7 @@ def build_extension(self, ext):\n need_f_libs = 1\n break\n print ext.name,ext_name,'needs fortran libraries',need_f_libs\n+ \n if need_f_libs:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n if moreargs != []:\n@@ -50,6 +52,7 @@ def build_extension(self, ext):\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 print 'replacing linker_so %s with %s' %(save_linker_so,linker_so)\n@@ -60,7 +63,18 @@ def build_extension(self, ext):\n l = build_flib.get_fcompiler_library_dirs()\n #l = self.compiler.library_dirs + l\n self.compiler.library_dirs = l\n-\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+ #self.compiler.libraries = self.compiler.libraries + l\n+ lib_dirs = build_flib.get_fcompiler_library_dirs()\n+ for lib_dir in lib_dirs:\n+ if lib_dir not in self.compiler.libraries_dirs:\n+ self.compiler.libraries.append(lib_dir)\n+ #self.compiler.library_dirs = self.compiler.library_dirs + l\n+ \n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n \n", "added_lines": 15, "deleted_lines": 1, "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 *\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 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 print ext.name,ext_name,'needs fortran libraries',need_f_libs\n \n if need_f_libs:\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 if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.append(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 \n ext.library_dirs.append(build_flib.build_flib)\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 print 'replacing linker_so %s with %s' %(save_linker_so,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 = build_flib.get_fcompiler_library_dirs()\n #l = self.compiler.library_dirs + l\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 #self.compiler.libraries = self.compiler.libraries + l\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n if lib_dir not in self.compiler.libraries_dirs:\n self.compiler.libraries.append(lib_dir)\n #self.compiler.library_dirs = self.compiler.library_dirs + l\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 print 'restoring linker_so',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", "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 *\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 ext_name = string.split(ext.name,'.')[-1]\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 print ext.name,ext_name,'needs fortran libraries',need_f_libs\n if need_f_libs:\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 if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.append(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 \n ext.library_dirs.append(build_flib.build_flib)\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 if linker_so is not None:\n if linker_so is not save_linker_so:\n print 'replacing linker_so %s with %s' %(save_linker_so,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 = build_flib.get_fcompiler_library_dirs()\n #l = self.compiler.library_dirs + l\n self.compiler.library_dirs = l\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 print 'restoring linker_so',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", "methods": [ { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 57, "complexity": 19, "token_count": 408, "parameters": [ "self", "ext" ], "start_line": 15, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "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": 89, "end_line": 98, "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": 48, "complexity": 15, "token_count": 342, "parameters": [ "self", "ext" ], "start_line": 15, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 59, "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": 75, "end_line": 84, "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": 57, "complexity": 19, "token_count": 408, "parameters": [ "self", "ext" ], "start_line": 15, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 1 } ], "nloc": 73, "complexity": 21, "token_count": 509, "diff_parsed": { "added": [ "", "", "", " else:", " libs = build_flib.get_fcompiler_library_names()", " for lib in libs:", " if lib not in self.compiler.libraries:", " self.compiler.libraries.append(lib)", " #self.compiler.libraries = self.compiler.libraries + l", " lib_dirs = build_flib.get_fcompiler_library_dirs()", " for lib_dir in lib_dirs:", " if lib_dir not in self.compiler.libraries_dirs:", " self.compiler.libraries.append(lib_dir)", " #self.compiler.library_dirs = self.compiler.library_dirs + l", "" ], "deleted": [ "" ] } } ] }, { "hash": "22dd77138b93cc32d7f87bb1d4c3df81c333f60a", "msg": "The import method in the testing methods was causing an infinite loop when running test suites. The new approach is less general, but it does work.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-02-19T08:51:37+00:00", "author_timezone": 0, "committer_date": "2002-02-19T08:51:37+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "1f880dac85d9ba8f01006db67e61f924df983af0" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 3, "insertions": 2, "lines": 5, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "weave/__init__.py", "new_path": "weave/__init__.py", "filename": "__init__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -29,7 +29,6 @@ def test():\n \n def test_suite():\n import scipy_test\n- # this isn't a perfect fix, but it will work for\n- # most cases I think.\n- this_mod = __import__(__name__)\n+ import scipy.weave\n+ this_mod = scipy.weave\n return scipy_test.harvest_test_suites(this_mod)\n", "added_lines": 2, "deleted_lines": 3, "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():\n import unittest\n runner = unittest.TextTestRunner()\n runner.run(test_suite())\n return runner\n\ndef test_suite():\n import scipy_test\n import scipy.weave\n this_mod = scipy.weave\n return scipy_test.harvest_test_suites(this_mod)\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():\n import unittest\n runner = unittest.TextTestRunner()\n runner.run(test_suite())\n return runner\n\ndef test_suite():\n import scipy_test\n # this isn't a perfect fix, but it will work for\n # most cases I think.\n this_mod = __import__(__name__)\n return scipy_test.harvest_test_suites(this_mod)\n", "methods": [ { "name": "test", "long_name": "test( )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [], "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( )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 22, "parameters": [], "start_line": 30, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "test", "long_name": "test( )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [], "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( )", "filename": "__init__.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [], "start_line": 30, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 22, "parameters": [], "start_line": 30, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 28, "complexity": 2, "token_count": 79, "diff_parsed": { "added": [ " import scipy.weave", " this_mod = scipy.weave" ], "deleted": [ " # this isn't a perfect fix, but it will work for", " # most cases I think.", " this_mod = __import__(__name__)" ] } } ] }, { "hash": "04891cf9a4a66f2c64391eda97ecf38fff9d35c9", "msg": "changed references to scipy.scipy_test to scipy_test.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-02-19T09:01:03+00:00", "author_timezone": 0, "committer_date": "2002-02-19T09:01:03+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "22dd77138b93cc32d7f87bb1d4c3df81c333f60a" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 7, "insertions": 7, "lines": 14, "files": 4, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "weave/tests/test_scalar_spec.py", "new_path": "weave/tests/test_scalar_spec.py", "filename": "test_scalar_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -24,7 +24,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.scipy_test\n+ \"\"\"this should probably be in scipy_test\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 ext_tools\nfrom catalog import unique_file\nfrom build_tools import msvc_exists, gcc_exists\nimport scalar_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\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_int_converter(unittest.TestCase):\n compiler = '' \n def check_type_match_string(self):\n s = scalar_spec.int_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.int_converter() \n assert(s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.int_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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_var_local(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 = \"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 q={}\n test(b,q)\n teardown_test_location()\n assert(q['a'] == 2)\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 = Py::new_reference_to(Py::Int(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 = scalar_spec.float_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.float_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.float_converter() \n assert(s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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 def check_float_var_local(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 = \"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 q={}\n test(b,q)\n teardown_test_location()\n assert(q['a'] == 2.)\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 = Py::new_reference_to(Py::Float(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 = scalar_spec.complex_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.complex_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.complex_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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 def check_complex_var_local(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= 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 q={}\n test(b,q)\n teardown_test_location() \n assert(q['a'] == 3.+3j)\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 = Py::new_reference_to(Py::Complex(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 \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)\ndef test_suite():\n suites = []\n\n if msvc_exists():\n suites.append( unittest.makeSuite(test_msvc_int_converter,'check_'))\n suites.append( unittest.makeSuite(test_msvc_float_converter,'check_')) \n suites.append( unittest.makeSuite(test_msvc_complex_converter,'check_'))\n pass\n else: # unix\n suites.append( unittest.makeSuite(test_unix_int_converter,'check_'))\n suites.append( unittest.makeSuite(test_unix_float_converter,'check_')) \n suites.append( unittest.makeSuite(test_unix_complex_converter,'check_'))\n \n if gcc_exists(): \n suites.append( unittest.makeSuite(test_gcc_int_converter,'check_'))\n suites.append( unittest.makeSuite(test_gcc_float_converter,'check_')) \n suites.append( unittest.makeSuite(test_gcc_complex_converter,'check_'))\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\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 ext_tools\nfrom catalog import unique_file\nfrom build_tools import msvc_exists, gcc_exists\nimport scalar_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.scipy_test\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_int_converter(unittest.TestCase):\n compiler = '' \n def check_type_match_string(self):\n s = scalar_spec.int_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.int_converter() \n assert(s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.int_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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_var_local(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 = \"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 q={}\n test(b,q)\n teardown_test_location()\n assert(q['a'] == 2)\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 = Py::new_reference_to(Py::Int(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 = scalar_spec.float_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.float_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.float_converter() \n assert(s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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 def check_float_var_local(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 = \"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 q={}\n test(b,q)\n teardown_test_location()\n assert(q['a'] == 2.)\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 = Py::new_reference_to(Py::Float(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 = scalar_spec.complex_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.complex_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.complex_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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 def check_complex_var_local(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= 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 q={}\n test(b,q)\n teardown_test_location() \n assert(q['a'] == 3.+3j)\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 = Py::new_reference_to(Py::Complex(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 \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)\ndef test_suite():\n suites = []\n\n if msvc_exists():\n suites.append( unittest.makeSuite(test_msvc_int_converter,'check_'))\n suites.append( unittest.makeSuite(test_msvc_float_converter,'check_')) \n suites.append( unittest.makeSuite(test_msvc_complex_converter,'check_'))\n pass\n else: # unix\n suites.append( unittest.makeSuite(test_unix_int_converter,'check_'))\n suites.append( unittest.makeSuite(test_unix_float_converter,'check_')) \n suites.append( unittest.makeSuite(test_unix_complex_converter,'check_'))\n \n if gcc_exists(): \n suites.append( unittest.makeSuite(test_gcc_int_converter,'check_'))\n suites.append( unittest.makeSuite(test_gcc_float_converter,'check_')) \n suites.append( unittest.makeSuite(test_gcc_complex_converter,'check_'))\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\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_scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "d", "file_name" ], "start_line": 14, "end_line": 17, "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_scalar_spec.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "in_str" ], "start_line": 19, "end_line": 24, "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_scalar_spec.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 26, "end_line": 40, "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_scalar_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_int", "long_name": "check_type_match_int( self )", "filename": "test_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "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": "check_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 50, "end_line": 52, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 53, "end_line": 55, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 116, "parameters": [ "self" ], "start_line": 56, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_int_var_local", "long_name": "check_int_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 112, "parameters": [ "self" ], "start_line": 81, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_int_return", "long_name": "check_int_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 97, "end_line": 114, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 118, "end_line": 120, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 121, "end_line": 123, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 124, "end_line": 126, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 127, "end_line": 129, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 126, "parameters": [ "self" ], "start_line": 130, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "check_float_var_local", "long_name": "check_float_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 115, "parameters": [ "self" ], "start_line": 155, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_float_return", "long_name": "check_float_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 108, "parameters": [ "self" ], "start_line": 171, "end_line": 188, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 192, "end_line": 194, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 195, "end_line": 197, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 198, "end_line": 200, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 201, "end_line": 203, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 130, "parameters": [ "self" ], "start_line": 204, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_complex_var_local", "long_name": "check_complex_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 121, "parameters": [ "self" ], "start_line": 228, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_complex_return", "long_name": "check_complex_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 114, "parameters": [ "self" ], "start_line": 244, "end_line": 261, "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_scalar_spec.py", "nloc": 7, "complexity": 2, "token_count": 51, "parameters": [], "start_line": 285, "end_line": 291, "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_scalar_spec.py", "nloc": 6, "complexity": 2, "token_count": 45, "parameters": [], "start_line": 293, "end_line": 298, "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_scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "name" ], "start_line": 300, "end_line": 301, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_scalar_spec.py", "nloc": 17, "complexity": 3, "token_count": 148, "parameters": [], "start_line": 302, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 323, "end_line": 327, "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_scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "d", "file_name" ], "start_line": 14, "end_line": 17, "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_scalar_spec.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "in_str" ], "start_line": 19, "end_line": 24, "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_scalar_spec.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 26, "end_line": 40, "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_scalar_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_int", "long_name": "check_type_match_int( self )", "filename": "test_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "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": "check_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 50, "end_line": 52, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 53, "end_line": 55, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 116, "parameters": [ "self" ], "start_line": 56, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_int_var_local", "long_name": "check_int_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 112, "parameters": [ "self" ], "start_line": 81, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_int_return", "long_name": "check_int_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 97, "end_line": 114, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 118, "end_line": 120, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 121, "end_line": 123, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 124, "end_line": 126, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 127, "end_line": 129, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 126, "parameters": [ "self" ], "start_line": 130, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "check_float_var_local", "long_name": "check_float_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 115, "parameters": [ "self" ], "start_line": 155, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_float_return", "long_name": "check_float_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 108, "parameters": [ "self" ], "start_line": 171, "end_line": 188, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 192, "end_line": 194, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 195, "end_line": 197, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 198, "end_line": 200, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 201, "end_line": 203, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 130, "parameters": [ "self" ], "start_line": 204, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_complex_var_local", "long_name": "check_complex_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 121, "parameters": [ "self" ], "start_line": 228, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_complex_return", "long_name": "check_complex_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 114, "parameters": [ "self" ], "start_line": 244, "end_line": 261, "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_scalar_spec.py", "nloc": 7, "complexity": 2, "token_count": 51, "parameters": [], "start_line": 285, "end_line": 291, "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_scalar_spec.py", "nloc": 6, "complexity": 2, "token_count": 45, "parameters": [], "start_line": 293, "end_line": 298, "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_scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "name" ], "start_line": 300, "end_line": 301, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_scalar_spec.py", "nloc": 17, "complexity": 3, "token_count": 148, "parameters": [], "start_line": 302, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 323, "end_line": 327, "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_scalar_spec.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 26, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 } ], "nloc": 306, "complexity": 40, "token_count": 1947, "diff_parsed": { "added": [ " \"\"\"this should probably be in scipy_test" ], "deleted": [ " \"\"\"this should probably be in scipy.scipy_test" ] } }, { "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.scipy_test\n+ \"\"\"this should probably be in scipy_test\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.scipy_test\n+ \"\"\"this should probably be in scipy_test\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.scipy_test\n+ \"\"\"this should probably be in scipy_test\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.scipy_test\n+ \"\"\"this should probably be in scipy_test\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 fastumath import *\nexcept:\n pass # 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\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\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\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\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():\n suites = []\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():\n all_tests = test_suite()\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 fastumath import *\nexcept:\n pass # 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.scipy_test\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.scipy_test\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.scipy_test\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.scipy_test\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():\n suites = []\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():\n all_tests = test_suite()\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( )", "filename": "test_size_check.py", "nloc": 10, "complexity": 1, "token_count": 96, "parameters": [], "start_line": 446, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 457, "end_line": 461, "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( )", "filename": "test_size_check.py", "nloc": 10, "complexity": 1, "token_count": 96, "parameters": [], "start_line": 446, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 457, "end_line": 461, "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": 420, "complexity": 116, "token_count": 3145, "diff_parsed": { "added": [ " \"\"\"this should probably be in scipy_test", " \"\"\"this should probably be in scipy_test", " \"\"\"this should probably be in scipy_test", " \"\"\"this should probably be in scipy_test" ], "deleted": [ " \"\"\"this should probably be in scipy.scipy_test", " \"\"\"this should probably be in scipy.scipy_test", " \"\"\"this should probably be in scipy.scipy_test", " \"\"\"this should probably be in scipy.scipy_test" ] } }, { "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.scipy_test\n+ \"\"\"this should probably be in scipy_test\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\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():\n suites = []\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():\n all_tests = test_suite()\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.scipy_test\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():\n suites = []\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():\n all_tests = test_suite()\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( )", "filename": "test_slice_handler.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 169, "end_line": 175, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 177, "end_line": 181, "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( )", "filename": "test_slice_handler.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 169, "end_line": 175, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 177, "end_line": 181, "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": 149, "complexity": 25, "token_count": 1026, "diff_parsed": { "added": [ " \"\"\"this should probably be in scipy_test" ], "deleted": [ " \"\"\"this should probably be in scipy.scipy_test" ] } }, { "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.scipy_test\n+ \"\"\"this should probably be in scipy_test\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 fastumath import *\nexcept:\n pass # 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\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():\n suites = []\n \n suites.append( unittest.makeSuite(test_array_converter,'check_'))\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\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 fastumath import *\nexcept:\n pass # 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.scipy_test\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():\n suites = []\n \n suites.append( unittest.makeSuite(test_array_converter,'check_'))\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\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( )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "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( )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "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( )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "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( )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "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": 53, "complexity": 8, "token_count": 301, "diff_parsed": { "added": [ " \"\"\"this should probably be in scipy_test" ], "deleted": [ " \"\"\"this should probably be in scipy.scipy_test" ] } } ] }, { "hash": "5ba533b4b7b4562c36df4d0a698efff872a98086", "msg": "major overhaul to testing framework. module_xxx.test() now takes a 'level' argument to specify how thorough the testing should be. Level 1 is the least thorough, and only runs rapid tests (as specified by the test writer) on the module/package. level=10 is the most thorough testing. Any value between 1 and 10 can be used. I'm currently using 1, 5, and 10 for most of my tests, but others may wish to use more fine grained settings.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2002-02-19T10:35:37+00:00", "author_timezone": 0, "committer_date": "2002-02-19T10:35:37+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "04891cf9a4a66f2c64391eda97ecf38fff9d35c9" ], "project_name": "repo_copy", "project_path": "/tmp/tmpe0fq8n4n/repo_copy", "deletions": 162, "insertions": 198, "lines": 360, "files": 29, "dmm_unit_size": 0.5806451612903226, "dmm_unit_complexity": 0.1935483870967742, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_test/scipy_test.py", "new_path": "scipy_test/scipy_test.py", "filename": "scipy_test.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -115,7 +115,15 @@ def harvest_modules_and_packages(package,ignore=None):\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n \n-def harvest_test_suites(package,ignore = None):\n+def harvest_test_suites(package,ignore = None,level=10):\n+ \"\"\"\n+ package -- the module to test. This is an actual module object \n+ (not a string) \n+ ignore -- a list of module names to omit from the tests\n+ level -- a value between 1 and 10. 1 will run the minimum number\n+ of tests. This is a fast \"smoke test\". Tests that take\n+ longer to run should have higher numbers ranging up to 10.\n+ \"\"\"\n import unittest\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n@@ -124,7 +132,7 @@ def harvest_test_suites(package,ignore = None):\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n- suite = module.test_suite()\n+ suite = module.test_suite(level=level)\n if suite:\n suites.append(suite) \n else:\n@@ -136,11 +144,17 @@ def harvest_test_suites(package,ignore = None):\n print ' ',\n output_exception() \n else:\n- print 'No test suite found for ', module.__name__\n+ try:\n+ print 'No test suite found for ', module.__name__\n+ except AttributeError:\n+ # __version__.py getting replaced by a string throws a kink\n+ # in checking for modules, so we think is a module has \n+ # actually been overwritten\n+ print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n \n-def module_test(mod_name,mod_file):\n+def module_test(mod_name,mod_file,level=10):\n \"\"\"*\n \n *\"\"\"\n@@ -158,19 +172,19 @@ def module_test(mod_name,mod_file):\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n- test_string = 'import %s;reload(%s);%s.test()' % \\\n- ((test_module,)*3)\n+ test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n+ ((test_module)*3 + (level,))\n \n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n- #test_string = 'reload(%s);import %s;reload(%s);%s.test()' % \\\n+ #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n \n # remove test directory from python path.\n sys.path = sys.path[:-1]\n \n-def module_test_suite(mod_name,mod_file):\n+def module_test_suite(mod_name,mod_file,level=10):\n #try:\n import os,sys,string\n print ' creating test suite for:', mod_name\n@@ -186,7 +200,8 @@ def module_test_suite(mod_name,mod_file):\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n- test_string = 'import %s;reload(%s);suite = %s.test_suite()' % ((test_module,)*3)\n+ test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n+ ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n \n", "added_lines": 24, "deleted_lines": 9, "source_code": "import os\n\ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files \n \ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n \n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files \n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n \n return good_files\n \ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n import os,sys\n\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n import glob\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n \n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n \n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f) \n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception() \n \n return all_modules\n\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n import os,sys\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n \n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files: \n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception() \n return all_packages\n\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object \n (not a string) \n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n import unittest\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite) \n else:\n msg = \" !! FAILURE without error - shouldn't happen\" + \\\n module.__name__ \n print msg\n except:\n print ' !! FAILURE building test for ', module.__name__ \n print ' ',\n output_exception() \n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has \n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n import os,sys,string\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # add the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.append(test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[:-1]\n\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n import os,sys,string\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # add the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.append(test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[:-1]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception() \n\n\n# Utility function to facilitate testing.\n\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(str(desired)) < 100 and len(str(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n assert desired == actual, msg\n\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(str(desired)) < 100 and len(str(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits \n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n sc_desired = desired/pow(10,math.floor(math.log10(desired)))\n sc_actual = actual/pow(10,math.floor(math.log10(actual)))\n try:\n if ( verbose and len(str(desired)) < 100 and len(str(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n \ntry:\n # Numeric specific testss\n from Numeric import *\n from fastumath import *\n \n def assert_array_equal(x,y,err_msg=''):\n msg = '\\nArrays are not equal'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = equal(x,y)\n assert alltrue(ravel(reduced)),\\\n msg + ':\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not equal'\n \n def assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n msg = '\\nArrays are not almost equal'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = equal(around(abs(x-y),decimal),0)\n assert alltrue(ravel(reduced)),\\\n msg + ':\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\nexcept:\n pass # Numeric not installed\n \nimport traceback,sys\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n", "source_code_before": "import os\n\ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files \n \ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n \n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files \n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n \n return good_files\n \ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n import os,sys\n\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n import glob\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n \n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n \n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f) \n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception() \n \n return all_modules\n\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n import os,sys\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n \n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files: \n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception() \n return all_packages\n\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\ndef harvest_test_suites(package,ignore = None):\n import unittest\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite()\n if suite:\n suites.append(suite) \n else:\n msg = \" !! FAILURE without error - shouldn't happen\" + \\\n module.__name__ \n print msg\n except:\n print ' !! FAILURE building test for ', module.__name__ \n print ' ',\n output_exception() \n else:\n print 'No test suite found for ', module.__name__\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef module_test(mod_name,mod_file):\n \"\"\"*\n\n *\"\"\"\n import os,sys,string\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # add the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.append(test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test()' % \\\n ((test_module,)*3)\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test()' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[:-1]\n\ndef module_test_suite(mod_name,mod_file):\n #try:\n import os,sys,string\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # add the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.append(test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite()' % ((test_module,)*3)\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[:-1]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception() \n\n\n# Utility function to facilitate testing.\n\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(str(desired)) < 100 and len(str(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n assert desired == actual, msg\n\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(str(desired)) < 100 and len(str(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits \n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n sc_desired = desired/pow(10,math.floor(math.log10(desired)))\n sc_actual = actual/pow(10,math.floor(math.log10(actual)))\n try:\n if ( verbose and len(str(desired)) < 100 and len(str(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n \ntry:\n # Numeric specific testss\n from Numeric import *\n from fastumath import *\n \n def assert_array_equal(x,y,err_msg=''):\n msg = '\\nArrays are not equal'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = equal(x,y)\n assert alltrue(ravel(reduced)),\\\n msg + ':\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not equal'\n \n def assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n msg = '\\nArrays are not almost equal'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = equal(around(abs(x-y),decimal),0)\n assert alltrue(ravel(reduced)),\\\n msg + ':\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\nexcept:\n pass # Numeric not installed\n \nimport traceback,sys\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n", "methods": [ { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "scipy_test.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 3, "end_line": 9, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "scipy_test.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 11, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "scipy_test.py", "nloc": 23, "complexity": 4, "token_count": 140, "parameters": [ "package", "ignore" ], "start_line": 32, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "scipy_test.py", "nloc": 24, "complexity": 6, "token_count": 152, "parameters": [ "package", "ignore" ], "start_line": 73, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "scipy_test.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 110, "end_line": 116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "scipy_test.py", "nloc": 25, "complexity": 6, "token_count": 118, "parameters": [ "package", "ignore", "level" ], "start_line": 118, "end_line": 155, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "scipy_test.py", "nloc": 11, "complexity": 1, "token_count": 102, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 157, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "scipy_test.py", "nloc": 13, "complexity": 1, "token_count": 108, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 187, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "scipy_test.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 219, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "scipy_test.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 235, "end_line": 249, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "scipy_test.py", "nloc": 15, "complexity": 5, "token_count": 155, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 251, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "scipy_test.py", "nloc": 11, "complexity": 2, "token_count": 79, "parameters": [ "x", "y", "err_msg" ], "start_line": 277, "end_line": 287, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "scipy_test.py", "nloc": 13, "complexity": 2, "token_count": 101, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 289, "end_line": 301, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "scipy_test.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 306, "end_line": 316, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "scipy_test.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 3, "end_line": 9, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "remove_ignored_files", "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", "filename": "scipy_test.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 11, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "harvest_modules", "long_name": "harvest_modules( package , ignore = None )", "filename": "scipy_test.py", "nloc": 23, "complexity": 4, "token_count": 140, "parameters": [ "package", "ignore" ], "start_line": 32, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "scipy_test.py", "nloc": 24, "complexity": 6, "token_count": 152, "parameters": [ "package", "ignore" ], "start_line": 73, "end_line": 108, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "scipy_test.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 110, "end_line": 116, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None )", "filename": "scipy_test.py", "nloc": 22, "complexity": 5, "token_count": 98, "parameters": [ "package", "ignore" ], "start_line": 118, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file )", "filename": "scipy_test.py", "nloc": 11, "complexity": 1, "token_count": 94, "parameters": [ "mod_name", "mod_file" ], "start_line": 143, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file )", "filename": "scipy_test.py", "nloc": 12, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file" ], "start_line": 173, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_equal", "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", "filename": "scipy_test.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 204, "end_line": 218, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_almost_equal", "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", "filename": "scipy_test.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 220, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "assert_approx_equal", "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", "filename": "scipy_test.py", "nloc": 15, "complexity": 5, "token_count": 155, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 236, "end_line": 255, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "scipy_test.py", "nloc": 11, "complexity": 2, "token_count": 79, "parameters": [ "x", "y", "err_msg" ], "start_line": 262, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "scipy_test.py", "nloc": 13, "complexity": 2, "token_count": 101, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 274, "end_line": 286, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "scipy_test.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 291, "end_line": 301, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "module_test", "long_name": "module_test( mod_name , mod_file )", "filename": "scipy_test.py", "nloc": 11, "complexity": 1, "token_count": 94, "parameters": [ "mod_name", "mod_file" ], "start_line": 143, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", "filename": "scipy_test.py", "nloc": 25, "complexity": 6, "token_count": 118, "parameters": [ "package", "ignore", "level" ], "start_line": 118, "end_line": 155, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "harvest_test_suites", "long_name": "harvest_test_suites( package , ignore = None )", "filename": "scipy_test.py", "nloc": 22, "complexity": 5, "token_count": 98, "parameters": [ "package", "ignore" ], "start_line": 118, "end_line": 141, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "scipy_test.py", "nloc": 13, "complexity": 1, "token_count": 108, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 187, "end_line": 210, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "scipy_test.py", "nloc": 11, "complexity": 1, "token_count": 102, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 157, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file )", "filename": "scipy_test.py", "nloc": 12, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file" ], "start_line": 173, "end_line": 195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 } ], "nloc": 197, "complexity": 46, "token_count": 1410, "diff_parsed": { "added": [ "def harvest_test_suites(package,ignore = None,level=10):", " \"\"\"", " package -- the module to test. This is an actual module object", " (not a string)", " ignore -- a list of module names to omit from the tests", " level -- a value between 1 and 10. 1 will run the minimum number", " of tests. This is a fast \"smoke test\". Tests that take", " longer to run should have higher numbers ranging up to 10.", " \"\"\"", " suite = module.test_suite(level=level)", " try:", " print 'No test suite found for ', module.__name__", " except AttributeError:", " # __version__.py getting replaced by a string throws a kink", " # in checking for modules, so we think is a module has", " # actually been overwritten", " print 'No test suite found for ', str(module)", "def module_test(mod_name,mod_file,level=10):", " test_string = 'import %s;reload(%s);%s.test(%d)' % \\", " ((test_module)*3 + (level,))", " #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\", "def module_test_suite(mod_name,mod_file,level=10):", " test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\", " ((test_module,)*3+(level,))" ], "deleted": [ "def harvest_test_suites(package,ignore = None):", " suite = module.test_suite()", " print 'No test suite found for ', module.__name__", "def module_test(mod_name,mod_file):", " test_string = 'import %s;reload(%s);%s.test()' % \\", " ((test_module,)*3)", " #test_string = 'reload(%s);import %s;reload(%s);%s.test()' % \\", "def module_test_suite(mod_name,mod_file):", " test_string = 'import %s;reload(%s);suite = %s.test_suite()' % ((test_module,)*3)" ] } }, { "old_path": "weave/__init__.py", "new_path": "weave/__init__.py", "filename": "__init__.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -21,14 +21,14 @@\n \n #---- testing ----#\n \n-def test():\n+def test(level=10):\n import unittest\n runner = unittest.TextTestRunner()\n runner.run(test_suite())\n return runner\n \n-def test_suite():\n+def test_suite(level=1):\n import scipy_test\n import scipy.weave\n this_mod = scipy.weave\n- return scipy_test.harvest_test_suites(this_mod)\n+ return scipy_test.harvest_test_suites(this_mod,level=level)\n", "added_lines": 3, "deleted_lines": 3, "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())\n return runner\n\ndef test_suite(level=1):\n import scipy_test\n import scipy.weave\n this_mod = scipy.weave\n return scipy_test.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():\n import unittest\n runner = unittest.TextTestRunner()\n runner.run(test_suite())\n return runner\n\ndef test_suite():\n import scipy_test\n import scipy.weave\n this_mod = scipy.weave\n return scipy_test.harvest_test_suites(this_mod)\n", "methods": [ { "name": "test", "long_name": "test( level = 10 )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 26, "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": 5, "complexity": 1, "token_count": 29, "parameters": [ "level" ], "start_line": 30, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "test", "long_name": "test( )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [], "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( )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 22, "parameters": [], "start_line": 30, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 29, "parameters": [ "level" ], "start_line": 30, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 26, "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", "long_name": "test( )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 23, "parameters": [], "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( )", "filename": "__init__.py", "nloc": 5, "complexity": 1, "token_count": 22, "parameters": [], "start_line": 30, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 28, "complexity": 2, "token_count": 89, "diff_parsed": { "added": [ "def test(level=10):", "def test_suite(level=1):", " return scipy_test.harvest_test_suites(this_mod,level=level)" ], "deleted": [ "def test():", "def test_suite():", " return scipy_test.harvest_test_suites(this_mod)" ] } }, { "old_path": "weave/ast_tools.py", "new_path": "weave/ast_tools.py", "filename": "ast_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -197,13 +197,13 @@ def tuples_to_lists(ast_tuple):\n new_list.append(tuples_to_lists(item))\n return new_list\n \n-def test():\n+def test(level=10):\n from scipy_test import module_test\n- module_test(__name__,__file__)\n+ module_test(__name__,__file__,level=level)\n \n-def test_suite():\n+def test_suite(level=1):\n from scipy_test import module_test_suite\n- return module_test_suite(__name__,__file__) \n+ return module_test_suite(__name__,__file__,level=level)\n \n \"\"\"\n A little tree I built to help me understand the parse trees.\n", "added_lines": 4, "deleted_lines": 4, "source_code": "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_test import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test 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():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \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": 21, "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": 22, "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( )", "filename": "ast_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "ast_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "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": 22, "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": 21, "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", "long_name": "test( )", "filename": "ast_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "ast_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 204, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 123, "complexity": 46, "token_count": 699, "diff_parsed": { "added": [ "def test(level=10):", " module_test(__name__,__file__,level=level)", "def test_suite(level=1):", " return module_test_suite(__name__,__file__,level=level)" ], "deleted": [ "def test():", " module_test(__name__,__file__)", "def test_suite():", " return module_test_suite(__name__,__file__)" ] } }, { "old_path": "weave/blitz_tools.py", "new_path": "weave/blitz_tools.py", "filename": "blitz_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -144,13 +144,13 @@ def test_function():\n #wrapper = create_wrapper(mod_name,func_name,used_names)\n return string.join( [module_header,func,init],'\\n')\n \"\"\"\n-def test():\n+def test(level=10):\n from scipy_test import module_test\n- module_test(__name__,__file__)\n+ module_test(__name__,__file__,level=level)\n \n-def test_suite():\n+def test_suite(level=1):\n from scipy_test import module_test_suite\n- return module_test_suite(__name__,__file__) \n+ return module_test_suite(__name__,__file__,level=level)\n \n if __name__ == \"__main__\":\n test_function()\n\\ No newline at end of file\n", "added_lines": 4, "deleted_lines": 4, "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 fastumath import *\nexcept:\n pass # 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 from code_blocks import module_header\n\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 \"\"\"\n ast_list = ast.tolist()\n \n expr_code = ast_to_blitz_expr(ast_list)\n arg_list = harvest_variables(ast_list)\n arg_specs = assign_variable_types(arg_list,locals())\n \n func,template_types = create_function('test_function',expr_code,arg_list,arg_specs)\n init,used_names = create_module_init('compile_sample','test_function',template_types)\n #wrapper = create_wrapper(mod_name,func_name,used_names)\n return string.join( [module_header,func,init],'\\n')\n \"\"\"\ndef test(level=10):\n from scipy_test import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\nif __name__ == \"__main__\":\n test_function()", "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 fastumath import *\nexcept:\n pass # 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 from code_blocks import module_header\n\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 \"\"\"\n ast_list = ast.tolist()\n \n expr_code = ast_to_blitz_expr(ast_list)\n arg_list = harvest_variables(ast_list)\n arg_specs = assign_variable_types(arg_list,locals())\n \n func,template_types = create_function('test_function',expr_code,arg_list,arg_specs)\n init,used_names = create_module_init('compile_sample','test_function',template_types)\n #wrapper = create_wrapper(mod_name,func_name,used_names)\n return string.join( [module_header,func,init],'\\n')\n \"\"\"\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n\nif __name__ == \"__main__\":\n test_function()", "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": 26, "complexity": 1, "token_count": 128, "parameters": [], "start_line": 119, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "level" ], "start_line": 147, "end_line": 149, "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": 22, "parameters": [ "level" ], "start_line": 151, "end_line": 153, "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": 26, "complexity": 1, "token_count": 128, "parameters": [], "start_line": 119, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 147, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 151, "end_line": 153, "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": 22, "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", "long_name": "test( level = 10 )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "level" ], "start_line": 147, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 147, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "blitz_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 151, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 98, "complexity": 12, "token_count": 551, "diff_parsed": { "added": [ "def test(level=10):", " module_test(__name__,__file__,level=level)", "def test_suite(level=1):", " return module_test_suite(__name__,__file__,level=level)" ], "deleted": [ "def test():", " module_test(__name__,__file__)", "def test_suite():", " return module_test_suite(__name__,__file__)" ] } }, { "old_path": "weave/build_tools.py", "new_path": "weave/build_tools.py", "filename": "build_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -446,13 +446,13 @@ def build_import_library():\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \n-def test():\n+def test(level=10):\n from scipy_test import module_test\n- module_test(__name__,__file__)\n+ module_test(__name__,__file__,level=level)\n \n-def test_suite():\n+def test_suite(level=1):\n from scipy_test import module_test_suite\n- return module_test_suite(__name__,__file__) \n+ return module_test_suite(__name__,__file__,level=level)\n \n \n \n", "added_lines": 4, "deleted_lines": 4, "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\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():\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('gcc -v')\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('gcc -v')\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 == 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 import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test 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\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():\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('gcc -v')\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('gcc -v')\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 == 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():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n\n\n\n", "methods": [ { "name": "_init_posix", "long_name": "_init_posix( )", "filename": "build_tools.py", "nloc": 4, "complexity": 1, "token_count": 34, "parameters": [], "start_line": 30, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "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": 42, "end_line": 212, "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": 215, "end_line": 225, "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": 227, "end_line": 228, "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": 230, "end_line": 236, "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": 238, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( )", "filename": "build_tools.py", "nloc": 11, "complexity": 3, "token_count": 61, "parameters": [], "start_line": 261, "end_line": 280, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "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": 21, "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": 22, "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": 4, "complexity": 1, "token_count": 34, "parameters": [], "start_line": 30, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "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": 42, "end_line": 212, "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": 215, "end_line": 225, "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": 227, "end_line": 228, "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": 230, "end_line": 236, "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": 238, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( )", "filename": "build_tools.py", "nloc": 11, "complexity": 3, "token_count": 61, "parameters": [], "start_line": 261, "end_line": 280, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "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( )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "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": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "level" ], "start_line": 453, "end_line": 455, "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": 21, "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", "long_name": "test( )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "build_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 453, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 225, "complexity": 55, "token_count": 1405, "diff_parsed": { "added": [ "def test(level=10):", " module_test(__name__,__file__,level=level)", "def test_suite(level=1):", " return module_test_suite(__name__,__file__,level=level)" ], "deleted": [ "def test():", " module_test(__name__,__file__)", "def test_suite():", " return module_test_suite(__name__,__file__)" ] } }, { "old_path": "weave/catalog.py", "new_path": "weave/catalog.py", "filename": "catalog.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -647,10 +647,10 @@ def fast_cache(self,code,function):\n # put new function at the beginning of the list to search.\n self.cache[code].insert(0,function)\n \n-def test():\n+def test(level=10):\n from scipy_test import module_test\n- module_test(__name__,__file__)\n+ module_test(__name__,__file__,level=level)\n \n-def test_suite():\n+def test_suite(level=1):\n from scipy_test import module_test_suite\n- return module_test_suite(__name__,__file__) \n+ return module_test_suite(__name__,__file__,level=level)\n", "added_lines": 4, "deleted_lines": 4, "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\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_test import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test 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():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n", "methods": [ { "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": 21, "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": 22, "parameters": [ "level" ], "start_line": 654, "end_line": 656, "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( )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "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": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "level" ], "start_line": 654, "end_line": 656, "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": 21, "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", "long_name": "test( )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "catalog.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 654, "end_line": 656, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 351, "complexity": 100, "token_count": 1922, "diff_parsed": { "added": [ "def test(level=10):", " module_test(__name__,__file__,level=level)", "def test_suite(level=1):", " return module_test_suite(__name__,__file__,level=level)" ], "deleted": [ "def test():", " module_test(__name__,__file__)", "def test_suite():", " return module_test_suite(__name__,__file__)" ] } }, { "old_path": "weave/common_spec.py", "new_path": "weave/common_spec.py", "filename": "common_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -63,10 +63,10 @@ def declaration_code(self,templatize = 0,inline=0):\n (self.name,var_name,self.name)\n return code \n \n-def test():\n+def test(level=10):\n from scipy_test import module_test\n- module_test(__name__,__file__)\n+ module_test(__name__,__file__,level=level)\n \n-def test_suite():\n+def test_suite(level=1):\n from scipy_test import module_test_suite\n- return module_test_suite(__name__,__file__) \n+ return module_test_suite(__name__,__file__,level=level)\n", "added_lines": 4, "deleted_lines": 4, "source_code": "from base_spec import base_converter\nimport common_info\nfrom types import *\nimport os\n\nclass common_base_converter(base_converter):\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n return new_spec\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 return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n \n \nclass file_converter(common_base_converter):\n type_name = 'file'\n _build_information = [common_info.file_info()]\n def type_match(self,value):\n return type(value) in [FileType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n #code = 'PyObject* py_%s = %s;\\n' \\\n # 'FILE* %s = convert_to_file(py_%s,\"%s\");\\n' % \\\n # (self.name,var_name,self.name,self.name,self.name)\n code = 'PyObject* py_%s = %s;\\n' \\\n 'FILE* %s = convert_to_file(py_%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name,self.name,self.name)\n return code \n def cleanup_code(self):\n # could use Py_DECREF here I think and save NULL test.\n code = \"Py_XDECREF(py_%s);\\n\" % self.name\n return code\n\nclass callable_converter(common_base_converter):\n type_name = 'callable'\n _build_information = [common_info.callable_info()]\n def type_match(self,value):\n # probably should test for callable classes here also.\n return type(value) in [FunctionType,MethodType,type(len)]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'PyObject* %s = convert_to_callable(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n\nclass instance_converter(common_base_converter):\n type_name = 'instance'\n _build_information = [common_info.instance_info()]\n def type_match(self,value):\n return type(value) in [InstanceType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'PyObject* %s = convert_to_instance(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n\ndef test(level=10):\n from scipy_test import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "source_code_before": "from base_spec import base_converter\nimport common_info\nfrom types import *\nimport os\n\nclass common_base_converter(base_converter):\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n return new_spec\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 return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n \n \nclass file_converter(common_base_converter):\n type_name = 'file'\n _build_information = [common_info.file_info()]\n def type_match(self,value):\n return type(value) in [FileType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n #code = 'PyObject* py_%s = %s;\\n' \\\n # 'FILE* %s = convert_to_file(py_%s,\"%s\");\\n' % \\\n # (self.name,var_name,self.name,self.name,self.name)\n code = 'PyObject* py_%s = %s;\\n' \\\n 'FILE* %s = convert_to_file(py_%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name,self.name,self.name)\n return code \n def cleanup_code(self):\n # could use Py_DECREF here I think and save NULL test.\n code = \"Py_XDECREF(py_%s);\\n\" % self.name\n return code\n\nclass callable_converter(common_base_converter):\n type_name = 'callable'\n _build_information = [common_info.callable_info()]\n def type_match(self,value):\n # probably should test for callable classes here also.\n return type(value) in [FunctionType,MethodType,type(len)]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'PyObject* %s = convert_to_callable(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n\nclass instance_converter(common_base_converter):\n type_name = 'instance'\n _build_information = [common_info.instance_info()]\n def type_match(self,value):\n return type(value) in [InstanceType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'PyObject* %s = convert_to_instance(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n", "methods": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "common_spec.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "self", "name", "value" ], "start_line": 7, "end_line": 11, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 12, "end_line": 14, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "common_spec.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "self", "other" ], "start_line": 15, "end_line": 18, "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": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 24, "end_line": 25, "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": "common_spec.py", "nloc": 6, "complexity": 1, "token_count": 49, "parameters": [ "self", "templatize", "inline" ], "start_line": 27, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 36, "end_line": 39, "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": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "value" ], "start_line": 44, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "common_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 48, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 57, "end_line": 58, "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": "common_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 60, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "level" ], "start_line": 66, "end_line": 68, "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": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "level" ], "start_line": 70, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "common_spec.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "self", "name", "value" ], "start_line": 7, "end_line": 11, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 12, "end_line": 14, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "common_spec.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "self", "other" ], "start_line": 15, "end_line": 18, "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": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 24, "end_line": 25, "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": "common_spec.py", "nloc": 6, "complexity": 1, "token_count": 49, "parameters": [ "self", "templatize", "inline" ], "start_line": 27, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 36, "end_line": 39, "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": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "value" ], "start_line": 44, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "common_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 48, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "common_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 57, "end_line": 58, "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": "common_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 60, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 70, "end_line": 72, "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": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "level" ], "start_line": 70, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "level" ], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 66, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "common_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 70, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 55, "complexity": 13, "token_count": 390, "diff_parsed": { "added": [ "def test(level=10):", " module_test(__name__,__file__,level=level)", "def test_suite(level=1):", " return module_test_suite(__name__,__file__,level=level)" ], "deleted": [ "def test():", " module_test(__name__,__file__)", "def test_suite():", " return module_test_suite(__name__,__file__)" ] } }, { "old_path": "weave/ext_tools.py", "new_path": "weave/ext_tools.py", "filename": "ext_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -412,10 +412,10 @@ def format_error_msg(errors):\n pprint.pprint(errors,msg)\n return msg.getvalue()\n \n-def test():\n+def test(level=10):\n from scipy_test import module_test\n- module_test(__name__,__file__)\n+ module_test(__name__,__file__,level=level)\n \n-def test_suite():\n+def test_suite(level=1):\n from scipy_test import module_test_suite\n- return module_test_suite(__name__,__file__) \n+ return module_test_suite(__name__,__file__,level=level)\n", "added_lines": 4, "deleted_lines": 4, "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 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 #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 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 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 \" Py::Dict local_dict = Py::Dict(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 = Py::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, common_info, cxx_info, scalar_info\n\nclass ext_module:\n def __init__(self,name,compiler=''):\n standard_info = [common_info.basic_module_info(),\n common_info.file_info(), \n common_info.instance_info(), \n common_info.callable_info(), \n common_info.module_info(), \n cxx_info.cxx_info(),\n scalar_info.scalar_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 import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test 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 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 #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 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 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 \" Py::Dict local_dict = Py::Dict(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 = Py::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, common_info, cxx_info, scalar_info\n\nclass ext_module:\n def __init__(self,name,compiler=''):\n standard_info = [common_info.basic_module_info(),\n common_info.file_info(), \n common_info.instance_info(), \n common_info.callable_info(), \n common_info.module_info(), \n cxx_info.cxx_info(),\n scalar_info.scalar_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():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \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": 30, "complexity": 5, "token_count": 174, "parameters": [ "self" ], "start_line": 36, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 1 }, { "name": "arg_declaration_code", "long_name": "arg_declaration_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 82, "end_line": 87, "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": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 89, "end_line": 94, "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": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "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": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 37, "complexity": 1, "token_count": 162, "parameters": [ "self" ], "start_line": 103, "end_line": 144, "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": 146, "end_line": 150, "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": 152, "end_line": 155, "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": 159, "end_line": 171, "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": 13, "complexity": 1, "token_count": 91, "parameters": [ "self", "name", "compiler" ], "start_line": 177, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 191, "end_line": 192, "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": 193, "end_line": 200, "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": 202, "end_line": 206, "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": 208, "end_line": 216, "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": 218, "end_line": 225, "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": 227, "end_line": 230, "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": 232, "end_line": 235, "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": 237, "end_line": 239, "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": 241, "end_line": 245, "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": 247, "end_line": 257, "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": 259, "end_line": 267, "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": 269, "end_line": 275, "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": 277, "end_line": 284, "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": 286, "end_line": 323, "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": 325, "end_line": 327, "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": 329, "end_line": 333, "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": 335, "end_line": 370, "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": 372, "end_line": 399, "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": 401, "end_line": 406, "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": 408, "end_line": 413, "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": 21, "parameters": [ "level" ], "start_line": 415, "end_line": 417, "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": 22, "parameters": [ "level" ], "start_line": 419, "end_line": 421, "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": 30, "complexity": 5, "token_count": 174, "parameters": [ "self" ], "start_line": 36, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 1 }, { "name": "arg_declaration_code", "long_name": "arg_declaration_code( self )", "filename": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 82, "end_line": 87, "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": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "parameters": [ "self" ], "start_line": 89, "end_line": 94, "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": "ext_tools.py", "nloc": 6, "complexity": 2, "token_count": 38, "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": "function_code", "long_name": "function_code( self )", "filename": "ext_tools.py", "nloc": 37, "complexity": 1, "token_count": 162, "parameters": [ "self" ], "start_line": 103, "end_line": 144, "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": 146, "end_line": 150, "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": 152, "end_line": 155, "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": 159, "end_line": 171, "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": 13, "complexity": 1, "token_count": 91, "parameters": [ "self", "name", "compiler" ], "start_line": 177, "end_line": 189, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "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": 191, "end_line": 192, "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": 193, "end_line": 200, "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": 202, "end_line": 206, "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": 208, "end_line": 216, "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": 218, "end_line": 225, "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": 227, "end_line": 230, "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": 232, "end_line": 235, "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": 237, "end_line": 239, "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": 241, "end_line": 245, "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": 247, "end_line": 257, "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": 259, "end_line": 267, "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": 269, "end_line": 275, "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": 277, "end_line": 284, "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": 286, "end_line": 323, "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": 325, "end_line": 327, "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": 329, "end_line": 333, "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": 335, "end_line": 370, "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": 372, "end_line": 399, "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": 401, "end_line": 406, "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": 408, "end_line": 413, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 415, "end_line": 417, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 419, "end_line": 421, "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": 22, "parameters": [ "level" ], "start_line": 419, "end_line": 421, "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": 21, "parameters": [ "level" ], "start_line": 415, "end_line": 417, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 415, "end_line": 417, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "ext_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 419, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 316, "complexity": 76, "token_count": 1991, "diff_parsed": { "added": [ "def test(level=10):", " module_test(__name__,__file__,level=level)", "def test_suite(level=1):", " return module_test_suite(__name__,__file__,level=level)" ], "deleted": [ "def test():", " module_test(__name__,__file__)", "def test_suite():", " return module_test_suite(__name__,__file__)" ] } }, { "old_path": "weave/inline_tools.py", "new_path": "weave/inline_tools.py", "filename": "inline_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -435,13 +435,13 @@ def compile_function(code,arg_names,local_dict,global_dict,\n del sys.path[0]\n return func\n \n-def test():\n+def test(level=10):\n from scipy_test import module_test\n- module_test(__name__,__file__)\n+ module_test(__name__,__file__,level=level)\n \n-def test_suite():\n+def test_suite(level=1):\n from scipy_test import module_test_suite\n- return module_test_suite(__name__,__file__) \n+ return module_test_suite(__name__,__file__,level=level)\n \n if __name__ == \"__main__\":\n test_function()\n", "added_lines": 4, "deleted_lines": 4, "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 inline_info, cxx_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 = Py::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(inline_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 import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test 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 inline_info, cxx_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 = Py::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(inline_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():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \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": 21, "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": 22, "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( )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "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": 22, "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": 21, "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", "long_name": "test( )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "inline_tools.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 442, "end_line": 444, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 246, "complexity": 41, "token_count": 1320, "diff_parsed": { "added": [ "def test(level=10):", " module_test(__name__,__file__,level=level)", "def test_suite(level=1):", " return module_test_suite(__name__,__file__,level=level)" ], "deleted": [ "def test():", " module_test(__name__,__file__)", "def test_suite():", " return module_test_suite(__name__,__file__)" ] } }, { "old_path": "weave/scalar_spec.py", "new_path": "weave/scalar_spec.py", "filename": "scalar_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -85,11 +85,11 @@ def local_dict_code(self):\n (self.name,self.name,self.name) \n return code\n \n-def test():\n+def test(level=10):\n from scipy_test import module_test\n- module_test(__name__,__file__)\n+ module_test(__name__,__file__,level=level)\n \n-def test_suite():\n+def test_suite(level=1):\n from scipy_test import module_test_suite\n- return module_test_suite(__name__,__file__) \n+ return module_test_suite(__name__,__file__,level=level)\n \n\\ No newline at end of file\n", "added_lines": 4, "deleted_lines": 4, "source_code": "from base_spec import base_converter\nimport scalar_info\n#from Numeric import *\nfrom types import *\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\nnumeric_to_c_type_mapping = {}\n\nnumeric_to_c_type_mapping['T'] = 'T' # for templates\nnumeric_to_c_type_mapping['F'] = 'std::complex '\nnumeric_to_c_type_mapping['D'] = 'std::complex '\nnumeric_to_c_type_mapping['f'] = 'float'\nnumeric_to_c_type_mapping['d'] = 'double'\nnumeric_to_c_type_mapping['1'] = 'char'\nnumeric_to_c_type_mapping['b'] = 'unsigned char'\nnumeric_to_c_type_mapping['s'] = 'short'\nnumeric_to_c_type_mapping['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.\nnumeric_to_c_type_mapping['l'] = 'int'\n\n# standard Python numeric type mappings.\nnumeric_to_c_type_mapping[type(1)] = 'int'\nnumeric_to_c_type_mapping[type(1.)] = 'double'\nnumeric_to_c_type_mapping[type(1.+1.j)] = 'std::complex '\n#hmmm. The following is likely unsafe...\nnumeric_to_c_type_mapping[type(1L)] = 'int'\n\nclass scalar_converter(base_converter):\n _build_information = [scalar_info.scalar_info()] \n\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name\n new_spec.numeric_type = type(value)\n return new_spec\n \n def declaration_code(self,inline=0):\n type = numeric_to_c_type_mapping[self.numeric_type]\n func_type = self.type_name\n name = self.name\n var_name = self.retrieve_py_variable(inline)\n template = '%(type)s %(name)s = '\\\n 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n\n def __repr__(self):\n msg = \"(%s:: name: %s, type: %s)\" % \\\n (self.type_name,self.name, self.numeric_type)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.__class__, other.__class__)\n\nclass int_converter(scalar_converter):\n type_name = 'int'\n def type_match(self,value):\n return type(value) in [IntType, LongType]\n \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Int(%s);\\n' % (self.name,self.name) \n return code\n \nclass float_converter(scalar_converter):\n type_name = 'float'\n def type_match(self,value):\n return type(value) in [FloatType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Float(%s);\\n' % (self.name,self.name) \n return code\n\nclass complex_converter(scalar_converter):\n type_name = 'complex'\n def type_match(self,value):\n return type(value) in [ComplexType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Complex(%s.real(),%s.imag());\\n' % \\\n (self.name,self.name,self.name) \n return code\n\ndef test(level=10):\n from scipy_test import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n ", "source_code_before": "from base_spec import base_converter\nimport scalar_info\n#from Numeric import *\nfrom types import *\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\nnumeric_to_c_type_mapping = {}\n\nnumeric_to_c_type_mapping['T'] = 'T' # for templates\nnumeric_to_c_type_mapping['F'] = 'std::complex '\nnumeric_to_c_type_mapping['D'] = 'std::complex '\nnumeric_to_c_type_mapping['f'] = 'float'\nnumeric_to_c_type_mapping['d'] = 'double'\nnumeric_to_c_type_mapping['1'] = 'char'\nnumeric_to_c_type_mapping['b'] = 'unsigned char'\nnumeric_to_c_type_mapping['s'] = 'short'\nnumeric_to_c_type_mapping['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.\nnumeric_to_c_type_mapping['l'] = 'int'\n\n# standard Python numeric type mappings.\nnumeric_to_c_type_mapping[type(1)] = 'int'\nnumeric_to_c_type_mapping[type(1.)] = 'double'\nnumeric_to_c_type_mapping[type(1.+1.j)] = 'std::complex '\n#hmmm. The following is likely unsafe...\nnumeric_to_c_type_mapping[type(1L)] = 'int'\n\nclass scalar_converter(base_converter):\n _build_information = [scalar_info.scalar_info()] \n\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name\n new_spec.numeric_type = type(value)\n return new_spec\n \n def declaration_code(self,inline=0):\n type = numeric_to_c_type_mapping[self.numeric_type]\n func_type = self.type_name\n name = self.name\n var_name = self.retrieve_py_variable(inline)\n template = '%(type)s %(name)s = '\\\n 'convert_to_%(func_type)s (%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n\n def __repr__(self):\n msg = \"(%s:: name: %s, type: %s)\" % \\\n (self.type_name,self.name, self.numeric_type)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.__class__, other.__class__)\n\nclass int_converter(scalar_converter):\n type_name = 'int'\n def type_match(self,value):\n return type(value) in [IntType, LongType]\n \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Int(%s);\\n' % (self.name,self.name) \n return code\n \nclass float_converter(scalar_converter):\n type_name = 'float'\n def type_match(self,value):\n return type(value) in [FloatType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Float(%s);\\n' % (self.name,self.name) \n return code\n\nclass complex_converter(scalar_converter):\n type_name = 'complex'\n def type_match(self,value):\n return type(value) in [ComplexType]\n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = Py::Complex(%s.real(),%s.imag());\\n' % \\\n (self.name,self.name,self.name) \n return code\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n ", "methods": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self", "name", "value" ], "start_line": 35, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , inline = 0 )", "filename": "scalar_spec.py", "nloc": 9, "complexity": 1, "token_count": 49, "parameters": [ "self", "inline" ], "start_line": 42, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 52, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 3, "token_count": 42, "parameters": [ "self", "other" ], "start_line": 56, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "value" ], "start_line": 64, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 67, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 73, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 75, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 81, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 83, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "level" ], "start_line": 88, "end_line": 90, "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": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "level" ], "start_line": 92, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [ "self", "name", "value" ], "start_line": 35, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , inline = 0 )", "filename": "scalar_spec.py", "nloc": 9, "complexity": 1, "token_count": 49, "parameters": [ "self", "inline" ], "start_line": 42, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 52, "end_line": 55, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 3, "token_count": 42, "parameters": [ "self", "other" ], "start_line": 56, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 18, "parameters": [ "self", "value" ], "start_line": 64, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 67, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 73, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 75, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 81, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 83, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 88, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 92, "end_line": 94, "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": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "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", "long_name": "test( level = 10 )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "level" ], "start_line": 88, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 88, "end_line": 90, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 92, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 70, "complexity": 14, "token_count": 475, "diff_parsed": { "added": [ "def test(level=10):", " module_test(__name__,__file__,level=level)", "def test_suite(level=1):", " return module_test_suite(__name__,__file__,level=level)" ], "deleted": [ "def test():", " module_test(__name__,__file__)", "def test_suite():", " return module_test_suite(__name__,__file__)" ] } }, { "old_path": "weave/sequence_spec.py", "new_path": "weave/sequence_spec.py", "filename": "sequence_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -76,11 +76,11 @@ def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n \n-def test():\n+def test(level=10):\n from scipy_test import module_test\n- module_test(__name__,__file__)\n+ module_test(__name__,__file__,level=level)\n \n-def test_suite():\n+def test_suite(level=1):\n from scipy_test import module_test_suite\n- return module_test_suite(__name__,__file__) \n+ return module_test_suite(__name__,__file__,level=level)\n \n", "added_lines": 4, "deleted_lines": 4, "source_code": "import cxx_info\nfrom base_spec import base_converter\nfrom types import *\nimport os\n\nclass base_cxx_converter(base_converter):\n _build_information = [cxx_info.cxx_info()]\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n return new_spec\n def __repr__(self):\n msg = \"(%s:: name: %s)\" % (self.type_name,self.name)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n \nclass string_converter(base_cxx_converter):\n type_name = 'string'\n def type_match(self,value):\n return type(value) in [StringType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::String %s = convert_to_string(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\n\nclass list_converter(base_cxx_converter):\n type_name = 'list'\n def type_match(self,value):\n return type(value) in [ListType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::List %s = convert_to_list(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\nclass dict_converter(base_cxx_converter):\n type_name = 'dict'\n def type_match(self,value):\n return type(value) in [DictType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::Dict %s = convert_to_dict(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name) \n return code\n \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\nclass tuple_converter(base_cxx_converter):\n type_name = 'tuple'\n def type_match(self,value):\n return type(value) in [TupleType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::Tuple %s = convert_to_tuple(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\ndef test(level=10):\n from scipy_test import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\n", "source_code_before": "import cxx_info\nfrom base_spec import base_converter\nfrom types import *\nimport os\n\nclass base_cxx_converter(base_converter):\n _build_information = [cxx_info.cxx_info()]\n def type_spec(self,name,value):\n # factory\n new_spec = self.__class__()\n new_spec.name = name \n return new_spec\n def __repr__(self):\n msg = \"(%s:: name: %s)\" % (self.type_name,self.name)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__)\n \nclass string_converter(base_cxx_converter):\n type_name = 'string'\n def type_match(self,value):\n return type(value) in [StringType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::String %s = convert_to_string(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\n\nclass list_converter(base_cxx_converter):\n type_name = 'list'\n def type_match(self,value):\n return type(value) in [ListType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::List %s = convert_to_list(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\nclass dict_converter(base_cxx_converter):\n type_name = 'dict'\n def type_match(self,value):\n return type(value) in [DictType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::Dict %s = convert_to_dict(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name) \n return code\n \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\nclass tuple_converter(base_cxx_converter):\n type_name = 'tuple'\n def type_match(self,value):\n return type(value) in [TupleType]\n\n def declaration_code(self,templatize = 0,inline=0):\n var_name = self.retrieve_py_variable(inline)\n code = 'Py::Tuple %s = convert_to_tuple(%s,\"%s\");\\n' % \\\n (self.name,var_name,self.name)\n return code \n def local_dict_code(self):\n code = 'local_dict[\"%s\"] = %s;\\n' % (self.name,self.name) \n return code\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n\n", "methods": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "sequence_spec.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "self", "name", "value" ], "start_line": 8, "end_line": 12, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 13, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "self", "other" ], "start_line": 16, "end_line": 19, "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": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 23, "end_line": 24, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 26, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 31, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 38, "end_line": 39, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 41, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 46, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 52, "end_line": 53, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 55, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 61, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 67, "end_line": 68, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 70, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 75, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "level" ], "start_line": 79, "end_line": 81, "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": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "level" ], "start_line": 83, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "type_spec", "long_name": "type_spec( self , name , value )", "filename": "sequence_spec.py", "nloc": 4, "complexity": 1, "token_count": 23, "parameters": [ "self", "name", "value" ], "start_line": 8, "end_line": 12, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 13, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 2, "token_count": 30, "parameters": [ "self", "other" ], "start_line": 16, "end_line": 19, "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": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 23, "end_line": 24, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 26, "end_line": 30, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 31, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 38, "end_line": 39, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 41, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 46, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 52, "end_line": 53, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 55, "end_line": 59, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 61, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "sequence_spec.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "self", "value" ], "start_line": 67, "end_line": 68, "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": "sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "templatize", "inline" ], "start_line": 70, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 75, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 79, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 83, "end_line": 85, "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": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "level" ], "start_line": 83, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "level" ], "start_line": 79, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 79, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 83, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 70, "complexity": 18, "token_count": 496, "diff_parsed": { "added": [ "def test(level=10):", " module_test(__name__,__file__,level=level)", "def test_suite(level=1):", " return module_test_suite(__name__,__file__,level=level)" ], "deleted": [ "def test():", " module_test(__name__,__file__)", "def test_suite():", " return module_test_suite(__name__,__file__)" ] } }, { "old_path": "weave/size_check.py", "new_path": "weave/size_check.py", "filename": "size_check.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -283,11 +283,11 @@ def reduction(ary,axis=0):\n def take(ary,axis=0): raise NotImplemented\n # and all the rest\n \n-def test():\n+def test(level=10):\n from scipy_test import module_test\n- module_test(__name__,__file__)\n+ module_test(__name__,__file__,level=level)\n \n-def test_suite():\n+def test_suite(level=1):\n from scipy_test import module_test_suite\n- return module_test_suite(__name__,__file__) \n+ return module_test_suite(__name__,__file__,level=level)\n \n\\ No newline at end of file\n", "added_lines": 4, "deleted_lines": 4, "source_code": "from Numeric import *\n\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from fastumath import *\nexcept:\n pass # 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 import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\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 fastumath import *\nexcept:\n pass # 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():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \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": 21, "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": 22, "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( )", "filename": "size_check.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "size_check.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "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": 22, "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": 21, "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", "long_name": "test( )", "filename": "size_check.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "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( )", "filename": "size_check.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 290, "end_line": 292, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 213, "complexity": 82, "token_count": 1678, "diff_parsed": { "added": [ "def test(level=10):", " module_test(__name__,__file__,level=level)", "def test_suite(level=1):", " return module_test_suite(__name__,__file__,level=level)" ], "deleted": [ "def test():", " module_test(__name__,__file__)", "def test_suite():", " return module_test_suite(__name__,__file__)" ] } }, { "old_path": "weave/slice_handler.py", "new_path": "weave/slice_handler.py", "filename": "slice_handler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -154,15 +154,13 @@ def transform_slices(ast_list):\n )\n )\n \n-def test():\n- import slice_handler\n+def test(level=10):\n from scipy_test import module_test\n- module_test(slice_handler.__name__,slice_handler.__file__)\n+ module_test(__name__,__file__,level=level)\n \n-def test_suite():\n- import slice_handler\n+def test_suite(level=1):\n from scipy_test import module_test_suite\n- return module_test_suite(slice_handler.__name__,slice_handler.__file__)\n+ return module_test_suite(__name__,__file__,level=level)\n \n if __name__ == \"__main__\": \n test()\n\\ No newline at end of file\n", "added_lines": 4, "deleted_lines": 6, "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 import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test 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():\n import slice_handler\n from scipy_test import module_test\n module_test(slice_handler.__name__,slice_handler.__file__)\n\ndef test_suite():\n import slice_handler\n from scipy_test import module_test_suite\n return module_test_suite(slice_handler.__name__,slice_handler.__file__)\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": 21, "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": 22, "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( )", "filename": "slice_handler.py", "nloc": 4, "complexity": 1, "token_count": 20, "parameters": [], "start_line": 157, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "slice_handler.py", "nloc": 4, "complexity": 1, "token_count": 21, "parameters": [], "start_line": 162, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "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": 22, "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": 21, "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", "long_name": "test( )", "filename": "slice_handler.py", "nloc": 4, "complexity": 1, "token_count": 20, "parameters": [], "start_line": 157, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "slice_handler.py", "nloc": 4, "complexity": 1, "token_count": 21, "parameters": [], "start_line": 162, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 } ], "nloc": 94, "complexity": 24, "token_count": 776, "diff_parsed": { "added": [ "def test(level=10):", " module_test(__name__,__file__,level=level)", "def test_suite(level=1):", " return module_test_suite(__name__,__file__,level=level)" ], "deleted": [ "def test():", " import slice_handler", " module_test(slice_handler.__name__,slice_handler.__file__)", "def test_suite():", " import slice_handler", " return module_test_suite(slice_handler.__name__,slice_handler.__file__)" ] } }, { "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": "@@ -86,10 +86,10 @@ def __cmp__(self,other):\n cmp(self.dims, other.dims) or \\\n cmp(self.__class__, other.__class__)\n \n-def test():\n+def test(level=10):\n from scipy_test import module_test\n- module_test(__name__,__file__)\n+ module_test(__name__,__file__,level=level)\n \n-def test_suite():\n+def test_suite(level=1):\n from scipy_test import module_test_suite\n- return module_test_suite(__name__,__file__) \n+ return module_test_suite(__name__,__file__,level=level)\n", "added_lines": 4, "deleted_lines": 4, "source_code": "from base_spec import base_converter\nfrom scalar_spec import numeric_to_c_type_mapping\nfrom Numeric import *\nfrom types import *\nimport os\nimport standard_array_info\n\nclass array_converter(base_converter):\n _build_information = [standard_array_info.array_info()]\n \n def type_match(self,value):\n return type(value) is ArrayType\n\n def type_spec(self,name,value):\n # factory\n new_spec = array_converter()\n new_spec.name = name\n new_spec.numeric_type = value.typecode()\n # dims not used, but here for compatibility with blitz_spec\n new_spec.dims = len(shape(value))\n return new_spec\n\n def declaration_code(self,templatize = 0,inline=0):\n if inline:\n code = self.inline_decl_code()\n else:\n code = self.standard_decl_code()\n return code\n \n def inline_decl_code(self):\n type = numeric_to_c_type_mapping[self.numeric_type]\n name = self.name\n var_name = self.retrieve_py_variable(inline=1)\n templ = '// %(name)s array declaration\\n' \\\n 'py_%(name)s= %(var_name)s;\\n' \\\n 'PyArrayObject* %(name)s = convert_to_numpy(py_%(name)s,\"%(name)s\");\\n' \\\n 'int* _N%(name)s = %(name)s->dimensions;\\n' \\\n 'int* _S%(name)s = %(name)s->strides;\\n' \\\n 'int _D%(name)s = %(name)s->nd;\\n' \\\n '%(type)s* %(name)s_data = (%(type)s*) %(name)s->data;\\n' \n code = templ % locals()\n return code\n\n def standard_decl_code(self): \n type = numeric_to_c_type_mapping[self.numeric_type]\n name = self.name\n templ = '// %(name)s array declaration\\n' \\\n 'PyArrayObject* %(name)s = convert_to_numpy(py_%(name)s,\"%(name)s\");\\n' \\\n 'int* _N%(name)s = %(name)s->dimensions;\\n' \\\n 'int* _S%(name)s = %(name)s->strides;\\n' \\\n 'int _D%(name)s = %(name)s->nd;\\n' \\\n '%(type)s* %(name)s_data = (%(type)s*) %(name)s->data;\\n' \n code = templ % locals()\n return code\n #def c_function_declaration_code(self):\n # \"\"\"\n # This doesn't pass the size through. That info is gonna have to \n # be redone in the c function.\n # \"\"\"\n # templ_dict = {}\n # templ_dict['type'] = numeric_to_c_type_mapping[self.numeric_type]\n # templ_dict['dims'] = self.dims\n # templ_dict['name'] = self.name\n # code = 'blitz::Array<%(type)s,%(dims)d> &%(name)s' % templ_dict\n # return code\n \n def local_dict_code(self):\n code = '// for now, array \"%s\" is not returned as arryas are edited' \\\n ' in place (should this change?)\\n' % (self.name) \n return code\n\n def cleanup_code(self):\n # could use Py_DECREF here I think and save NULL test.\n code = \"Py_XDECREF(py_%s);\\n\" % self.name\n return code\n\n def __repr__(self):\n msg = \"(array:: name: %s, type: %s)\" % \\\n (self.name, self.numeric_type)\n return msg\n\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.dims, other.dims) or \\\n cmp(self.__class__, other.__class__)\n\ndef test(level=10):\n from scipy_test import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n", "source_code_before": "from base_spec import base_converter\nfrom scalar_spec import numeric_to_c_type_mapping\nfrom Numeric import *\nfrom types import *\nimport os\nimport standard_array_info\n\nclass array_converter(base_converter):\n _build_information = [standard_array_info.array_info()]\n \n def type_match(self,value):\n return type(value) is ArrayType\n\n def type_spec(self,name,value):\n # factory\n new_spec = array_converter()\n new_spec.name = name\n new_spec.numeric_type = value.typecode()\n # dims not used, but here for compatibility with blitz_spec\n new_spec.dims = len(shape(value))\n return new_spec\n\n def declaration_code(self,templatize = 0,inline=0):\n if inline:\n code = self.inline_decl_code()\n else:\n code = self.standard_decl_code()\n return code\n \n def inline_decl_code(self):\n type = numeric_to_c_type_mapping[self.numeric_type]\n name = self.name\n var_name = self.retrieve_py_variable(inline=1)\n templ = '// %(name)s array declaration\\n' \\\n 'py_%(name)s= %(var_name)s;\\n' \\\n 'PyArrayObject* %(name)s = convert_to_numpy(py_%(name)s,\"%(name)s\");\\n' \\\n 'int* _N%(name)s = %(name)s->dimensions;\\n' \\\n 'int* _S%(name)s = %(name)s->strides;\\n' \\\n 'int _D%(name)s = %(name)s->nd;\\n' \\\n '%(type)s* %(name)s_data = (%(type)s*) %(name)s->data;\\n' \n code = templ % locals()\n return code\n\n def standard_decl_code(self): \n type = numeric_to_c_type_mapping[self.numeric_type]\n name = self.name\n templ = '// %(name)s array declaration\\n' \\\n 'PyArrayObject* %(name)s = convert_to_numpy(py_%(name)s,\"%(name)s\");\\n' \\\n 'int* _N%(name)s = %(name)s->dimensions;\\n' \\\n 'int* _S%(name)s = %(name)s->strides;\\n' \\\n 'int _D%(name)s = %(name)s->nd;\\n' \\\n '%(type)s* %(name)s_data = (%(type)s*) %(name)s->data;\\n' \n code = templ % locals()\n return code\n #def c_function_declaration_code(self):\n # \"\"\"\n # This doesn't pass the size through. That info is gonna have to \n # be redone in the c function.\n # \"\"\"\n # templ_dict = {}\n # templ_dict['type'] = numeric_to_c_type_mapping[self.numeric_type]\n # templ_dict['dims'] = self.dims\n # templ_dict['name'] = self.name\n # code = 'blitz::Array<%(type)s,%(dims)d> &%(name)s' % templ_dict\n # return code\n \n def local_dict_code(self):\n code = '// for now, array \"%s\" is not returned as arryas are edited' \\\n ' in place (should this change?)\\n' % (self.name) \n return code\n\n def cleanup_code(self):\n # could use Py_DECREF here I think and save NULL test.\n code = \"Py_XDECREF(py_%s);\\n\" % self.name\n return code\n\n def __repr__(self):\n msg = \"(array:: name: %s, type: %s)\" % \\\n (self.name, self.numeric_type)\n return msg\n\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.numeric_type,other.numeric_type) or \\\n cmp(self.dims, other.dims) or \\\n cmp(self.__class__, other.__class__)\n\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n", "methods": [ { "name": "type_match", "long_name": "type_match( self , value )", "filename": "standard_array_spec.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "value" ], "start_line": 11, "end_line": 12, "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": "standard_array_spec.py", "nloc": 6, "complexity": 1, "token_count": 41, "parameters": [ "self", "name", "value" ], "start_line": 14, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "templatize", "inline" ], "start_line": 23, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "inline_decl_code", "long_name": "inline_decl_code( self )", "filename": "standard_array_spec.py", "nloc": 13, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 30, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "standard_decl_code", "long_name": "standard_decl_code( self )", "filename": "standard_array_spec.py", "nloc": 11, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 44, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "standard_array_spec.py", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 67, "end_line": 70, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 72, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "standard_array_spec.py", "nloc": 4, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 77, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "standard_array_spec.py", "nloc": 5, "complexity": 4, "token_count": 54, "parameters": [ "self", "other" ], "start_line": 82, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "level" ], "start_line": 89, "end_line": 91, "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": 22, "parameters": [ "level" ], "start_line": 93, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "type_match", "long_name": "type_match( self , value )", "filename": "standard_array_spec.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "value" ], "start_line": 11, "end_line": 12, "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": "standard_array_spec.py", "nloc": 6, "complexity": 1, "token_count": 41, "parameters": [ "self", "name", "value" ], "start_line": 14, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , templatize = 0 , inline = 0 )", "filename": "standard_array_spec.py", "nloc": 6, "complexity": 2, "token_count": 34, "parameters": [ "self", "templatize", "inline" ], "start_line": 23, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "inline_decl_code", "long_name": "inline_decl_code( self )", "filename": "standard_array_spec.py", "nloc": 13, "complexity": 1, "token_count": 52, "parameters": [ "self" ], "start_line": 30, "end_line": 42, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "standard_decl_code", "long_name": "standard_decl_code( self )", "filename": "standard_array_spec.py", "nloc": 11, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 44, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "local_dict_code", "long_name": "local_dict_code( self )", "filename": "standard_array_spec.py", "nloc": 4, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 67, "end_line": 70, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "cleanup_code", "long_name": "cleanup_code( self )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 72, "end_line": 75, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "standard_array_spec.py", "nloc": 4, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 77, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "standard_array_spec.py", "nloc": 5, "complexity": 4, "token_count": 54, "parameters": [ "self", "other" ], "start_line": 82, "end_line": 87, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 89, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 93, "end_line": 95, "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": 22, "parameters": [ "level" ], "start_line": 93, "end_line": 95, "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": 21, "parameters": [ "level" ], "start_line": 89, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [], "start_line": 89, "end_line": 91, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "standard_array_spec.py", "nloc": 3, "complexity": 1, "token_count": 15, "parameters": [], "start_line": 93, "end_line": 95, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "nloc": 68, "complexity": 15, "token_count": 377, "diff_parsed": { "added": [ "def test(level=10):", " module_test(__name__,__file__,level=level)", "def test_suite(level=1):", " return module_test_suite(__name__,__file__,level=level)" ], "deleted": [ "def test():", " module_test(__name__,__file__)", "def test_suite():", " return module_test_suite(__name__,__file__)" ] } }, { "old_path": "weave/tests/test_ast_tools.py", "new_path": "weave/tests/test_ast_tools.py", "filename": "test_ast_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -39,14 +39,15 @@ def check_simple_expr(self):\n self.generic_test(expr,desired)\n \n \n-def test_suite():\n+def test_suite(level=1):\n suites = []\n- suites.append( unittest.makeSuite(test_harvest_variables,'check_') )\n+ if level > 0:\n+ suites.append( unittest.makeSuite(test_harvest_variables,'check_') )\n total_suite = unittest.TestSuite(suites)\n return total_suite\n \n-def test():\n- all_tests = test_suite()\n+def test(level=10):\n+ all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n", "added_lines": 5, "deleted_lines": 4, "source_code": "import unittest\nfrom Numeric import *\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from fastumath import *\nexcept:\n pass # fastumath not available \nimport RandomArray\nimport time\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\nfrom scipy_distutils.misc_util import add_local_to_path\n\nadd_grandparent_to_path(__name__)\nimport ast_tools\nrestore_path()\n\nadd_local_to_path(__name__)\nfrom weave_test_utils import *\nrestore_path()\n\nclass test_harvest_variables(unittest.TestCase):\n \"\"\" Not much testing going on here, but \n at least it is a flame test.\n \"\"\" \n def generic_test(self,expr,desired):\n import parser\n ast_list = parser.suite(expr).tolist()\n actual = ast_tools.harvest_variables(ast_list)\n print_assert_equal(expr,actual,desired)\n\n def check_simple_expr(self):\n \"\"\"convert simple expr to blitz\n \n a[:1:2] = b[:1+i+2:]\n \"\"\"\n expr = \"a[:1:2] = b[:1+i+2:]\" \n desired = ['a','b','i'] \n self.generic_test(expr,desired)\n\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_harvest_variables,'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\nfrom Numeric import *\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from fastumath import *\nexcept:\n pass # fastumath not available \nimport RandomArray\nimport time\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\nfrom scipy_distutils.misc_util import add_local_to_path\n\nadd_grandparent_to_path(__name__)\nimport ast_tools\nrestore_path()\n\nadd_local_to_path(__name__)\nfrom weave_test_utils import *\nrestore_path()\n\nclass test_harvest_variables(unittest.TestCase):\n \"\"\" Not much testing going on here, but \n at least it is a flame test.\n \"\"\" \n def generic_test(self,expr,desired):\n import parser\n ast_list = parser.suite(expr).tolist()\n actual = ast_tools.harvest_variables(ast_list)\n print_assert_equal(expr,actual,desired)\n\n def check_simple_expr(self):\n \"\"\"convert simple expr to blitz\n \n a[:1:2] = b[:1+i+2:]\n \"\"\"\n expr = \"a[:1:2] = b[:1+i+2:]\" \n desired = ['a','b','i'] \n self.generic_test(expr,desired)\n\n\ndef test_suite():\n suites = []\n suites.append( unittest.makeSuite(test_harvest_variables,'check_') )\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "generic_test", "long_name": "generic_test( self , expr , desired )", "filename": "test_ast_tools.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "expr", "desired" ], "start_line": 26, "end_line": 30, "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_ast_tools.py", "nloc": 4, "complexity": 1, "token_count": 26, "parameters": [ "self" ], "start_line": 32, "end_line": 39, "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_ast_tools.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "level" ], "start_line": 42, "end_line": 47, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_ast_tools.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 49, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "generic_test", "long_name": "generic_test( self , expr , desired )", "filename": "test_ast_tools.py", "nloc": 5, "complexity": 1, "token_count": 39, "parameters": [ "self", "expr", "desired" ], "start_line": 26, "end_line": 30, "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_ast_tools.py", "nloc": 4, "complexity": 1, "token_count": 26, "parameters": [ "self" ], "start_line": 32, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_ast_tools.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 42, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_ast_tools.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 48, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_ast_tools.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "level" ], "start_line": 42, "end_line": 47, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_ast_tools.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 42, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_ast_tools.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 49, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_ast_tools.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 48, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 42, "complexity": 5, "token_count": 206, "diff_parsed": { "added": [ "def test_suite(level=1):", " if level > 0:", " suites.append( unittest.makeSuite(test_harvest_variables,'check_') )", "def test(level=10):", " all_tests = test_suite(level)" ], "deleted": [ "def test_suite():", " suites.append( unittest.makeSuite(test_harvest_variables,'check_') )", "def test():", " all_tests = test_suite()" ] } }, { "old_path": "weave/tests/test_blitz_tools.py", "new_path": "weave/tests/test_blitz_tools.py", "filename": "test_blitz_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -153,15 +153,17 @@ def check_5point_avg_2d(self):\n \"+ b[1:-1,2:] + b[1:-1,:-2]) / 5.\"\n self.generic_2d(expr)\n \n-def test_suite():\n+def test_suite(level=1):\n suites = []\n- suites.append( unittest.makeSuite(test_ast_to_blitz_expr,'check_') )\n- suites.append( unittest.makeSuite(test_blitz,'check_') ) \n+ if level > 0:\n+ suites.append( unittest.makeSuite(test_ast_to_blitz_expr,'check_') )\n+ if level >= 10:\n+ suites.append( unittest.makeSuite(test_blitz,'check_') ) \n total_suite = unittest.TestSuite(suites)\n return total_suite\n \n-def test():\n- all_tests = test_suite()\n+def test(level=10):\n+ all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n", "added_lines": 7, "deleted_lines": 5, "source_code": "import unittest\nfrom Numeric import *\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from fastumath import *\nexcept:\n pass # fastumath not available \nimport RandomArray\nimport os\nimport time\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path,restore_path\nfrom scipy_distutils.misc_util import add_local_to_path\n\nadd_grandparent_to_path(__name__)\nimport blitz_tools\nfrom ast_tools import *\nfrom weave_test_utils import *\nrestore_path()\n\nadd_local_to_path(__name__)\nimport test_scalar_spec\nrestore_path()\n\nclass test_ast_to_blitz_expr(unittest.TestCase):\n\n def generic_test(self,expr,desired):\n import parser\n ast = parser.suite(expr)\n ast_list = ast.tolist()\n actual = blitz_tools.ast_to_blitz_expr(ast_list)\n actual = remove_whitespace(actual)\n desired = remove_whitespace(desired)\n print_assert_equal(expr,actual,desired)\n\n def check_simple_expr(self):\n \"\"\"convert simple expr to blitz\n \n a[:1:2] = b[:1+i+2:]\n \"\"\"\n expr = \"a[:1:2] = b[:1+i+2:]\" \n desired = \"a(blitz::Range(_beg,1-1,2))=\"\\\n \"b(blitz::Range(_beg,1+i+2-1));\"\n self.generic_test(expr,desired)\n\n def check_fdtd_expr(self):\n \"\"\" convert fdtd equation to blitz.\n ex[:,1:,1:] = ca_x[:,1:,1:] * ex[:,1:,1:] \n + cb_y_x[:,1:,1:] * (hz[:,1:,1:] - hz[:,:-1,:])\n - cb_z_x[:,1:,1:] * (hy[:,1:,1:] - hy[:,1:,:-1]);\n Note: This really should have \"\\\" at the end of each line\n to indicate continuation. \n \"\"\"\n expr = \"ex[:,1:,1:] = ca_x[:,1:,1:] * ex[:,1:,1:]\" \\\n \"+ cb_y_x[:,1:,1:] * (hz[:,1:,1:] - hz[:,:-1,:])\"\\\n \"- cb_z_x[:,1:,1:] * (hy[:,1:,1:] - hy[:,1:,:-1])\" \n desired = 'ex(_all,blitz::Range(1,_end),blitz::Range(1,_end))='\\\n ' ca_x(_all,blitz::Range(1,_end),blitz::Range(1,_end))'\\\n ' *ex(_all,blitz::Range(1,_end),blitz::Range(1,_end))'\\\n '+cb_y_x(_all,blitz::Range(1,_end),blitz::Range(1,_end))'\\\n '*(hz(_all,blitz::Range(1,_end),blitz::Range(1,_end))'\\\n ' -hz(_all,blitz::Range(_beg,_Nhz(1)-1-1),_all))'\\\n ' -cb_z_x(_all,blitz::Range(1,_end),blitz::Range(1,_end))'\\\n '*(hy(_all,blitz::Range(1,_end),blitz::Range(1,_end))'\\\n '-hy(_all,blitz::Range(1,_end),blitz::Range(_beg,_Nhy(2)-1-1)));'\n self.generic_test(expr,desired)\n\nclass test_blitz(unittest.TestCase):\n \"\"\"* These are long running tests...\n \n I'd like to benchmark these things somehow.\n *\"\"\"\n def generic_test(self,expr,arg_dict,type,size,mod_location):\n clean_result = array(arg_dict['result'],copy=1)\n t1 = time.time()\n exec expr in globals(),arg_dict\n t2 = time.time()\n standard = t2 - t1\n desired = arg_dict['result']\n arg_dict['result'] = clean_result\n t1 = time.time()\n old_env = os.environ.get('PYTHONCOMPILED','')\n os.environ['PYTHONCOMPILED'] = mod_location\n blitz_tools.blitz(expr,arg_dict,{},verbose=0) #,\n #extra_compile_args = ['-O3','-malign-double','-funroll-loops'])\n os.environ['PYTHONCOMPILED'] = old_env\n t2 = time.time()\n compiled = t2 - t1\n actual = arg_dict['result']\n # this really should give more info...\n try:\n # this isn't very stringent. Need to tighten this up and\n # learn where failures are occuring.\n assert(allclose(abs(actual.flat),abs(desired.flat),1e-4,1e-6))\n except:\n diff = actual-desired\n print diff[:4,:4]\n print diff[:4,-4:]\n print diff[-4:,:4]\n print diff[-4:,-4:]\n print sum(abs(diff.flat)) \n raise AssertionError \n return standard,compiled\n \n def generic_2d(self,expr):\n \"\"\" The complex testing is pretty lame...\n \"\"\"\n mod_location = empty_temp_dir()\n import parser\n ast = parser.suite(expr)\n arg_list = harvest_variables(ast.tolist())\n #print arg_list\n all_types = [Float32,Float64,Complex32,Complex64]\n all_sizes = [(10,10), (50,50), (100,100), (500,500), (1000,1000)]\n print '\\nExpression:', expr\n for typ in all_types:\n for size in all_sizes:\n result = zeros(size,typ)\n arg_dict = {}\n for arg in arg_list:\n arg_dict[arg] = RandomArray.normal(0,1,size).astype(typ)\n arg_dict[arg].savespace(1)\n # set imag part of complex values to non-zero value\n try: arg_dict[arg].imag = arg_dict[arg].real\n except: pass \n print 'Run:', size,typ\n standard,compiled = self.generic_test(expr,arg_dict,type,size,\n mod_location)\n try:\n speed_up = standard/compiled\n except:\n speed_up = -1.\n print \"1st run(Numeric,compiled,speed up): %3.4f, %3.4f, \" \\\n \"%3.4f\" % (standard,compiled,speed_up) \n standard,compiled = self.generic_test(expr,arg_dict,type,size,\n mod_location)\n try:\n speed_up = standard/compiled\n except:\n speed_up = -1. \n print \"2nd run(Numeric,compiled,speed up): %3.4f, %3.4f, \" \\\n \"%3.4f\" % (standard,compiled,speed_up)\n cleanup_temp_dir(mod_location) \n #def check_simple_2d(self):\n # \"\"\" result = a + b\"\"\" \n # expr = \"result = a + b\"\n # self.generic_2d(expr)\n def check_5point_avg_2d(self):\n \"\"\" result[1:-1,1:-1] = (b[1:-1,1:-1] + b[2:,1:-1] + b[:-2,1:-1]\n + b[1:-1,2:] + b[1:-1,:-2]) / 5.\n \"\"\" \n expr = \"result[1:-1,1:-1] = (b[1:-1,1:-1] + b[2:,1:-1] + b[:-2,1:-1]\" \\\n \"+ b[1:-1,2:] + b[1:-1,:-2]) / 5.\"\n self.generic_2d(expr)\n \ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_ast_to_blitz_expr,'check_') )\n if level >= 10:\n suites.append( unittest.makeSuite(test_blitz,'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\nfrom Numeric import *\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from fastumath import *\nexcept:\n pass # fastumath not available \nimport RandomArray\nimport os\nimport time\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path,restore_path\nfrom scipy_distutils.misc_util import add_local_to_path\n\nadd_grandparent_to_path(__name__)\nimport blitz_tools\nfrom ast_tools import *\nfrom weave_test_utils import *\nrestore_path()\n\nadd_local_to_path(__name__)\nimport test_scalar_spec\nrestore_path()\n\nclass test_ast_to_blitz_expr(unittest.TestCase):\n\n def generic_test(self,expr,desired):\n import parser\n ast = parser.suite(expr)\n ast_list = ast.tolist()\n actual = blitz_tools.ast_to_blitz_expr(ast_list)\n actual = remove_whitespace(actual)\n desired = remove_whitespace(desired)\n print_assert_equal(expr,actual,desired)\n\n def check_simple_expr(self):\n \"\"\"convert simple expr to blitz\n \n a[:1:2] = b[:1+i+2:]\n \"\"\"\n expr = \"a[:1:2] = b[:1+i+2:]\" \n desired = \"a(blitz::Range(_beg,1-1,2))=\"\\\n \"b(blitz::Range(_beg,1+i+2-1));\"\n self.generic_test(expr,desired)\n\n def check_fdtd_expr(self):\n \"\"\" convert fdtd equation to blitz.\n ex[:,1:,1:] = ca_x[:,1:,1:] * ex[:,1:,1:] \n + cb_y_x[:,1:,1:] * (hz[:,1:,1:] - hz[:,:-1,:])\n - cb_z_x[:,1:,1:] * (hy[:,1:,1:] - hy[:,1:,:-1]);\n Note: This really should have \"\\\" at the end of each line\n to indicate continuation. \n \"\"\"\n expr = \"ex[:,1:,1:] = ca_x[:,1:,1:] * ex[:,1:,1:]\" \\\n \"+ cb_y_x[:,1:,1:] * (hz[:,1:,1:] - hz[:,:-1,:])\"\\\n \"- cb_z_x[:,1:,1:] * (hy[:,1:,1:] - hy[:,1:,:-1])\" \n desired = 'ex(_all,blitz::Range(1,_end),blitz::Range(1,_end))='\\\n ' ca_x(_all,blitz::Range(1,_end),blitz::Range(1,_end))'\\\n ' *ex(_all,blitz::Range(1,_end),blitz::Range(1,_end))'\\\n '+cb_y_x(_all,blitz::Range(1,_end),blitz::Range(1,_end))'\\\n '*(hz(_all,blitz::Range(1,_end),blitz::Range(1,_end))'\\\n ' -hz(_all,blitz::Range(_beg,_Nhz(1)-1-1),_all))'\\\n ' -cb_z_x(_all,blitz::Range(1,_end),blitz::Range(1,_end))'\\\n '*(hy(_all,blitz::Range(1,_end),blitz::Range(1,_end))'\\\n '-hy(_all,blitz::Range(1,_end),blitz::Range(_beg,_Nhy(2)-1-1)));'\n self.generic_test(expr,desired)\n\nclass test_blitz(unittest.TestCase):\n \"\"\"* These are long running tests...\n \n I'd like to benchmark these things somehow.\n *\"\"\"\n def generic_test(self,expr,arg_dict,type,size,mod_location):\n clean_result = array(arg_dict['result'],copy=1)\n t1 = time.time()\n exec expr in globals(),arg_dict\n t2 = time.time()\n standard = t2 - t1\n desired = arg_dict['result']\n arg_dict['result'] = clean_result\n t1 = time.time()\n old_env = os.environ.get('PYTHONCOMPILED','')\n os.environ['PYTHONCOMPILED'] = mod_location\n blitz_tools.blitz(expr,arg_dict,{},verbose=0) #,\n #extra_compile_args = ['-O3','-malign-double','-funroll-loops'])\n os.environ['PYTHONCOMPILED'] = old_env\n t2 = time.time()\n compiled = t2 - t1\n actual = arg_dict['result']\n # this really should give more info...\n try:\n # this isn't very stringent. Need to tighten this up and\n # learn where failures are occuring.\n assert(allclose(abs(actual.flat),abs(desired.flat),1e-4,1e-6))\n except:\n diff = actual-desired\n print diff[:4,:4]\n print diff[:4,-4:]\n print diff[-4:,:4]\n print diff[-4:,-4:]\n print sum(abs(diff.flat)) \n raise AssertionError \n return standard,compiled\n \n def generic_2d(self,expr):\n \"\"\" The complex testing is pretty lame...\n \"\"\"\n mod_location = empty_temp_dir()\n import parser\n ast = parser.suite(expr)\n arg_list = harvest_variables(ast.tolist())\n #print arg_list\n all_types = [Float32,Float64,Complex32,Complex64]\n all_sizes = [(10,10), (50,50), (100,100), (500,500), (1000,1000)]\n print '\\nExpression:', expr\n for typ in all_types:\n for size in all_sizes:\n result = zeros(size,typ)\n arg_dict = {}\n for arg in arg_list:\n arg_dict[arg] = RandomArray.normal(0,1,size).astype(typ)\n arg_dict[arg].savespace(1)\n # set imag part of complex values to non-zero value\n try: arg_dict[arg].imag = arg_dict[arg].real\n except: pass \n print 'Run:', size,typ\n standard,compiled = self.generic_test(expr,arg_dict,type,size,\n mod_location)\n try:\n speed_up = standard/compiled\n except:\n speed_up = -1.\n print \"1st run(Numeric,compiled,speed up): %3.4f, %3.4f, \" \\\n \"%3.4f\" % (standard,compiled,speed_up) \n standard,compiled = self.generic_test(expr,arg_dict,type,size,\n mod_location)\n try:\n speed_up = standard/compiled\n except:\n speed_up = -1. \n print \"2nd run(Numeric,compiled,speed up): %3.4f, %3.4f, \" \\\n \"%3.4f\" % (standard,compiled,speed_up)\n cleanup_temp_dir(mod_location) \n #def check_simple_2d(self):\n # \"\"\" result = a + b\"\"\" \n # expr = \"result = a + b\"\n # self.generic_2d(expr)\n def check_5point_avg_2d(self):\n \"\"\" result[1:-1,1:-1] = (b[1:-1,1:-1] + b[2:,1:-1] + b[:-2,1:-1]\n + b[1:-1,2:] + b[1:-1,:-2]) / 5.\n \"\"\" \n expr = \"result[1:-1,1:-1] = (b[1:-1,1:-1] + b[2:,1:-1] + b[:-2,1:-1]\" \\\n \"+ b[1:-1,2:] + b[1:-1,:-2]) / 5.\"\n self.generic_2d(expr)\n \ndef test_suite():\n suites = []\n suites.append( unittest.makeSuite(test_ast_to_blitz_expr,'check_') )\n suites.append( unittest.makeSuite(test_blitz,'check_') ) \n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "generic_test", "long_name": "generic_test( self , expr , desired )", "filename": "test_blitz_tools.py", "nloc": 8, "complexity": 1, "token_count": 54, "parameters": [ "self", "expr", "desired" ], "start_line": 27, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_simple_expr", "long_name": "check_simple_expr( self )", "filename": "test_blitz_tools.py", "nloc": 5, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 36, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_fdtd_expr", "long_name": "check_fdtd_expr( self )", "filename": "test_blitz_tools.py", "nloc": 14, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 46, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "generic_test", "long_name": "generic_test( self , expr , arg_dict , type , size , mod_location )", "filename": "test_blitz_tools.py", "nloc": 27, "complexity": 2, "token_count": 227, "parameters": [ "self", "expr", "arg_dict", "type", "size", "mod_location" ], "start_line": 73, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "generic_2d", "long_name": "generic_2d( self , expr )", "filename": "test_blitz_tools.py", "nloc": 35, "complexity": 7, "token_count": 253, "parameters": [ "self", "expr" ], "start_line": 105, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 1 }, { "name": "check_5point_avg_2d", "long_name": "check_5point_avg_2d( self )", "filename": "test_blitz_tools.py", "nloc": 4, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 148, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_blitz_tools.py", "nloc": 8, "complexity": 3, "token_count": 57, "parameters": [ "level" ], "start_line": 156, "end_line": 163, "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_blitz_tools.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 165, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "generic_test", "long_name": "generic_test( self , expr , desired )", "filename": "test_blitz_tools.py", "nloc": 8, "complexity": 1, "token_count": 54, "parameters": [ "self", "expr", "desired" ], "start_line": 27, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_simple_expr", "long_name": "check_simple_expr( self )", "filename": "test_blitz_tools.py", "nloc": 5, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 36, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_fdtd_expr", "long_name": "check_fdtd_expr( self )", "filename": "test_blitz_tools.py", "nloc": 14, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 46, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "generic_test", "long_name": "generic_test( self , expr , arg_dict , type , size , mod_location )", "filename": "test_blitz_tools.py", "nloc": 27, "complexity": 2, "token_count": 227, "parameters": [ "self", "expr", "arg_dict", "type", "size", "mod_location" ], "start_line": 73, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 1 }, { "name": "generic_2d", "long_name": "generic_2d( self , expr )", "filename": "test_blitz_tools.py", "nloc": 35, "complexity": 7, "token_count": 253, "parameters": [ "self", "expr" ], "start_line": 105, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 1 }, { "name": "check_5point_avg_2d", "long_name": "check_5point_avg_2d( self )", "filename": "test_blitz_tools.py", "nloc": 4, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 148, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_blitz_tools.py", "nloc": 6, "complexity": 1, "token_count": 44, "parameters": [], "start_line": 156, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_blitz_tools.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 163, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_blitz_tools.py", "nloc": 8, "complexity": 3, "token_count": 57, "parameters": [ "level" ], "start_line": 156, "end_line": 163, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_blitz_tools.py", "nloc": 6, "complexity": 1, "token_count": 44, "parameters": [], "start_line": 156, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_blitz_tools.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 165, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_blitz_tools.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 163, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 133, "complexity": 17, "token_count": 792, "diff_parsed": { "added": [ "def test_suite(level=1):", " if level > 0:", " suites.append( unittest.makeSuite(test_ast_to_blitz_expr,'check_') )", " if level >= 10:", " suites.append( unittest.makeSuite(test_blitz,'check_') )", "def test(level=10):", " all_tests = test_suite(level)" ], "deleted": [ "def test_suite():", " suites.append( unittest.makeSuite(test_ast_to_blitz_expr,'check_') )", " suites.append( unittest.makeSuite(test_blitz,'check_') )", "def test():", " all_tests = test_suite()" ] } }, { "old_path": "weave/tests/test_build_tools.py", "new_path": "weave/tests/test_build_tools.py", "filename": "test_build_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -64,16 +64,17 @@ def check_simple(self):\n build_tools.restore_sys_argv()\n assert(pre_argv == sys.argv[:])\n \n-def test_suite():\n+def test_suite(level = 1):\n suites = []\n- suites.append( unittest.makeSuite(test_configure_build_dir,'check_') )\n- suites.append( unittest.makeSuite(test_configure_temp_dir,'check_') )\n- suites.append( unittest.makeSuite(test_configure_sys_argv,'check_') )\n+ if level > 0:\n+ suites.append( unittest.makeSuite(test_configure_build_dir,'check_') )\n+ suites.append( unittest.makeSuite(test_configure_temp_dir,'check_') )\n+ suites.append( unittest.makeSuite(test_configure_sys_argv,'check_') )\n total_suite = unittest.TestSuite(suites)\n return total_suite\n \n-def test():\n- all_tests = test_suite()\n+def test(level=10):\n+ all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n", "added_lines": 7, "deleted_lines": 6, "source_code": "# still needed\n# tests for MingW32Compiler\n# don't know how to test gcc_exists() and msvc_exists()...\n\nimport unittest\nimport os, sys, tempfile\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport build_tools\nrestore_path()\n\ndef is_writable(val):\n return os.access(val,os.W_OK)\n \nclass test_configure_build_dir(unittest.TestCase):\n def check_default(self):\n \" default behavior is to return current directory \"\n d = build_tools.configure_build_dir()\n if is_writable('.'):\n assert(d == os.path.abspath('.'))\n assert(is_writable(d))\n def check_curdir(self):\n \" make sure it handles relative values. \"\n d = build_tools.configure_build_dir('.')\n if is_writable('.'):\n assert(d == os.path.abspath('.'))\n assert(is_writable(d)) \n def check_pardir(self):\n \" make sure it handles relative values \" \n d = build_tools.configure_build_dir('..')\n if is_writable('..'):\n assert(d == os.path.abspath('..'))\n assert(is_writable(d)) \n def check_bad_path(self):\n \" bad path should return same as default (and warn) \"\n d = build_tools.configure_build_dir('_bad_path_')\n d2 = build_tools.configure_build_dir()\n assert(d == d2)\n assert(is_writable(d))\n\nclass test_configure_temp_dir(test_configure_build_dir):\n def check_default(self):\n \" default behavior returns tempdir\"\n # this'll fail if the temp directory isn't writable.\n d = build_tools.configure_temp_dir()\n assert(d == tempfile.gettempdir())\n assert(is_writable(d))\n\nclass test_configure_sys_argv(unittest.TestCase):\n def check_simple(self):\n build_dir = 'build_dir'\n temp_dir = 'temp_dir'\n compiler = 'compiler'\n pre_argv = sys.argv[:]\n build_tools.configure_sys_argv(compiler,temp_dir,build_dir)\n argv = sys.argv[:]\n bd = argv[argv.index('--build-lib')+1]\n assert(bd == build_dir)\n td = argv[argv.index('--build-temp')+1]\n assert(td == temp_dir)\n argv.index('--compiler='+compiler)\n build_tools.restore_sys_argv()\n assert(pre_argv == sys.argv[:])\n \ndef test_suite(level = 1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_configure_build_dir,'check_') )\n suites.append( unittest.makeSuite(test_configure_temp_dir,'check_') )\n suites.append( unittest.makeSuite(test_configure_sys_argv,'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": "# still needed\n# tests for MingW32Compiler\n# don't know how to test gcc_exists() and msvc_exists()...\n\nimport unittest\nimport os, sys, tempfile\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport build_tools\nrestore_path()\n\ndef is_writable(val):\n return os.access(val,os.W_OK)\n \nclass test_configure_build_dir(unittest.TestCase):\n def check_default(self):\n \" default behavior is to return current directory \"\n d = build_tools.configure_build_dir()\n if is_writable('.'):\n assert(d == os.path.abspath('.'))\n assert(is_writable(d))\n def check_curdir(self):\n \" make sure it handles relative values. \"\n d = build_tools.configure_build_dir('.')\n if is_writable('.'):\n assert(d == os.path.abspath('.'))\n assert(is_writable(d)) \n def check_pardir(self):\n \" make sure it handles relative values \" \n d = build_tools.configure_build_dir('..')\n if is_writable('..'):\n assert(d == os.path.abspath('..'))\n assert(is_writable(d)) \n def check_bad_path(self):\n \" bad path should return same as default (and warn) \"\n d = build_tools.configure_build_dir('_bad_path_')\n d2 = build_tools.configure_build_dir()\n assert(d == d2)\n assert(is_writable(d))\n\nclass test_configure_temp_dir(test_configure_build_dir):\n def check_default(self):\n \" default behavior returns tempdir\"\n # this'll fail if the temp directory isn't writable.\n d = build_tools.configure_temp_dir()\n assert(d == tempfile.gettempdir())\n assert(is_writable(d))\n\nclass test_configure_sys_argv(unittest.TestCase):\n def check_simple(self):\n build_dir = 'build_dir'\n temp_dir = 'temp_dir'\n compiler = 'compiler'\n pre_argv = sys.argv[:]\n build_tools.configure_sys_argv(compiler,temp_dir,build_dir)\n argv = sys.argv[:]\n bd = argv[argv.index('--build-lib')+1]\n assert(bd == build_dir)\n td = argv[argv.index('--build-temp')+1]\n assert(td == temp_dir)\n argv.index('--compiler='+compiler)\n build_tools.restore_sys_argv()\n assert(pre_argv == sys.argv[:])\n \ndef test_suite():\n suites = []\n suites.append( unittest.makeSuite(test_configure_build_dir,'check_') )\n suites.append( unittest.makeSuite(test_configure_temp_dir,'check_') )\n suites.append( unittest.makeSuite(test_configure_sys_argv,'check_') )\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()", "methods": [ { "name": "is_writable", "long_name": "is_writable( val )", "filename": "test_build_tools.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 14, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "check_default", "long_name": "check_default( self )", "filename": "test_build_tools.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "self" ], "start_line": 18, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_curdir", "long_name": "check_curdir( self )", "filename": "test_build_tools.py", "nloc": 6, "complexity": 2, "token_count": 40, "parameters": [ "self" ], "start_line": 24, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_pardir", "long_name": "check_pardir( self )", "filename": "test_build_tools.py", "nloc": 6, "complexity": 2, "token_count": 40, "parameters": [ "self" ], "start_line": 30, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_bad_path", "long_name": "check_bad_path( self )", "filename": "test_build_tools.py", "nloc": 6, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 36, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_default", "long_name": "check_default( self )", "filename": "test_build_tools.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 44, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_build_tools.py", "nloc": 14, "complexity": 1, "token_count": 102, "parameters": [ "self" ], "start_line": 52, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_build_tools.py", "nloc": 8, "complexity": 2, "token_count": 65, "parameters": [ "level" ], "start_line": 67, "end_line": 74, "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_build_tools.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 76, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "is_writable", "long_name": "is_writable( val )", "filename": "test_build_tools.py", "nloc": 2, "complexity": 1, "token_count": 16, "parameters": [ "val" ], "start_line": 14, "end_line": 15, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "check_default", "long_name": "check_default( self )", "filename": "test_build_tools.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "self" ], "start_line": 18, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_curdir", "long_name": "check_curdir( self )", "filename": "test_build_tools.py", "nloc": 6, "complexity": 2, "token_count": 40, "parameters": [ "self" ], "start_line": 24, "end_line": 29, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_pardir", "long_name": "check_pardir( self )", "filename": "test_build_tools.py", "nloc": 6, "complexity": 2, "token_count": 40, "parameters": [ "self" ], "start_line": 30, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_bad_path", "long_name": "check_bad_path( self )", "filename": "test_build_tools.py", "nloc": 6, "complexity": 1, "token_count": 34, "parameters": [ "self" ], "start_line": 36, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_default", "long_name": "check_default( self )", "filename": "test_build_tools.py", "nloc": 5, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 44, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_build_tools.py", "nloc": 14, "complexity": 1, "token_count": 102, "parameters": [ "self" ], "start_line": 52, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_build_tools.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 67, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_build_tools.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 75, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_build_tools.py", "nloc": 8, "complexity": 2, "token_count": 65, "parameters": [ "level" ], "start_line": 67, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_build_tools.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 67, "end_line": 73, "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_build_tools.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 76, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_build_tools.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 75, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 69, "complexity": 13, "token_count": 458, "diff_parsed": { "added": [ "def test_suite(level = 1):", " if level > 0:", " suites.append( unittest.makeSuite(test_configure_build_dir,'check_') )", " suites.append( unittest.makeSuite(test_configure_temp_dir,'check_') )", " suites.append( unittest.makeSuite(test_configure_sys_argv,'check_') )", "def test(level=10):", " all_tests = test_suite(level)" ], "deleted": [ "def test_suite():", " suites.append( unittest.makeSuite(test_configure_build_dir,'check_') )", " suites.append( unittest.makeSuite(test_configure_temp_dir,'check_') )", " suites.append( unittest.makeSuite(test_configure_sys_argv,'check_') )", "def test():", " all_tests = test_suite()" ] } }, { "old_path": "weave/tests/test_catalog.py", "new_path": "weave/tests/test_catalog.py", "filename": "test_catalog.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -334,19 +334,21 @@ def check_add_function_ordered(self):\n cleanup_temp_dir(env_dir)\n \n \n-def test_suite():\n+def test_suite(level=1):\n suites = []\n- suites.append( unittest.makeSuite(test_default_dir,'check_'))\n- suites.append( unittest.makeSuite(test_os_dependent_catalog_name,'check_'))\n- suites.append( unittest.makeSuite(test_catalog_path,'check_'))\n- suites.append( unittest.makeSuite(test_get_catalog,'check_'))\n- suites.append( unittest.makeSuite(test_catalog,'check_'))\n+ if level > 0:\n+ suites.append( unittest.makeSuite(test_default_dir,'check_'))\n+ suites.append( unittest.makeSuite(test_os_dependent_catalog_name,\n+ 'check_'))\n+ suites.append( unittest.makeSuite(test_catalog_path,'check_'))\n+ suites.append( unittest.makeSuite(test_get_catalog,'check_'))\n+ suites.append( unittest.makeSuite(test_catalog,'check_'))\n \n total_suite = unittest.TestSuite(suites)\n return total_suite\n \n-def test():\n- all_tests = test_suite()\n+def test(level=10):\n+ all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n", "added_lines": 10, "deleted_lines": 8, "source_code": "import unittest\nimport sys, os\n\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\nfrom scipy_distutils.misc_util import add_local_to_path\n\nadd_grandparent_to_path(__name__)\nimport catalog\nreload(catalog) # this'll pick up any recent code changes\nrestore_path()\n\nadd_local_to_path(__name__)\nfrom weave_test_utils import *\nrestore_path()\n\n\nclass test_default_dir(unittest.TestCase):\n def check_is_writable(self):\n path = catalog.default_dir()\n name = os.path.join(path,'dummy_catalog')\n test_file = open(name,'w')\n try:\n test_file.write('making sure default location is writable\\n')\n finally:\n test_file.close()\n os.remove(name)\n\nclass test_os_dependent_catalog_name(unittest.TestCase): \n pass\n \nclass test_catalog_path(unittest.TestCase): \n def check_default(self):\n in_path = catalog.default_dir()\n path = catalog.catalog_path(in_path)\n d,f = os.path.split(path)\n assert(d == in_path)\n assert(f == catalog.os_dependent_catalog_name())\n def check_current(self):\n in_path = '.'\n path = catalog.catalog_path(in_path)\n d,f = os.path.split(path)\n assert(d == os.path.abspath(in_path)) \n assert(f == catalog.os_dependent_catalog_name()) \n def check_user(path):\n if sys.platform != 'win32':\n in_path = '~'\n path = catalog.catalog_path(in_path)\n d,f = os.path.split(path)\n assert(d == os.path.expanduser(in_path)) \n assert(f == catalog.os_dependent_catalog_name())\n def check_module(self):\n # hand it a module and see if it uses the parent directory\n # of the module.\n path = catalog.catalog_path(os.__file__)\n d,f = os.path.split(os.__file__)\n d2,f = os.path.split(path)\n assert (d2 == d)\n def check_path(self):\n # use os.__file__ to get a usable directory.\n in_path,f = os.path.split(os.__file__)\n path = catalog.catalog_path(in_path)\n d,f = os.path.split(path)\n assert (d == in_path)\n def check_bad_path(self):\n # stupid_path_name\n in_path = 'stupid_path_name'\n path = catalog.catalog_path(in_path)\n assert (path is None)\n\nclass test_get_catalog(unittest.TestCase):\n \"\"\" This only tests whether new catalogs are created correctly.\n And whether non-existent return None correctly with read mode.\n Putting catalogs in the right place is all tested with\n catalog_dir tests.\n \"\"\"\n def get_test_dir(self,erase = 0):\n # make sure tempdir catalog doesn't exist\n import tempfile, glob\n #temp = tempfile.gettempdir()\n pardir = tempfile.mktemp(suffix='cat_test')\n if not os.path.exists(pardir):\n os.mkdir(pardir)\n cat_glob = os.path.join(pardir,catalog.os_dependent_catalog_name()+'.*') \n cat_files = glob.glob(cat_glob)\n if erase:\n for cat_file in cat_files:\n os.remove(cat_file)\n return pardir\n def remove_dir(self,d):\n import distutils.dir_util\n distutils.dir_util.remove_tree(d)\n \n def check_nonexistent_catalog_is_none(self):\n pardir = self.get_test_dir(erase=1)\n cat = catalog.get_catalog(pardir,'r')\n self.remove_dir(pardir)\n assert(cat is None)\n def check_create_catalog(self):\n pardir = self.get_test_dir(erase=1)\n cat = catalog.get_catalog(pardir,'c')\n self.remove_dir(pardir)\n assert(cat is not None)\n\nclass test_catalog(unittest.TestCase):\n\n def clear_environ(self):\n if os.environ.has_key('PYTHONCOMPILED'):\n self.old_PYTHONCOMPILED = os.environ['PYTHONCOMPILED']\n del os.environ['PYTHONCOMPILED']\n else: \n self.old_PYTHONCOMPILED = None\n def reset_environ(self):\n if self.old_PYTHONCOMPILED:\n os.environ['PYTHONCOMPILED'] = self.old_PYTHONCOMPILED\n self.old_PYTHONCOMPILED = None\n def setUp(self):\n self.clear_environ() \n def tearDown(self):\n self.reset_environ()\n \n def check_set_module_directory(self):\n q = catalog.catalog()\n q.set_module_directory('bob')\n r = q.get_module_directory()\n assert (r == 'bob')\n def check_clear_module_directory(self):\n q = catalog.catalog()\n r = q.get_module_directory()\n assert (r == None)\n q.set_module_directory('bob')\n r = q.clear_module_directory()\n assert (r == None)\n def check_get_environ_path(self):\n if sys.platform == 'win32': sep = ';'\n else: sep = ':'\n os.environ['PYTHONCOMPILED'] = sep.join(('path1','path2','path3'))\n q = catalog.catalog()\n path = q.get_environ_path() \n assert(path == ['path1','path2','path3'])\n def check_build_search_order1(self): \n \"\"\" MODULE in search path should be replaced by module_dir.\n \"\"\" \n q = catalog.catalog(['first','MODULE','third'])\n q.set_module_directory('second')\n order = q.build_search_order()\n assert(order == ['first','second','third',catalog.default_dir()])\n def check_build_search_order2(self): \n \"\"\" MODULE in search path should be removed if module_dir==None.\n \"\"\" \n q = catalog.catalog(['first','MODULE','third'])\n order = q.build_search_order()\n assert(order == ['first','third',catalog.default_dir()]) \n def check_build_search_order3(self):\n \"\"\" If MODULE is absent, module_dir shouldn't be in search path.\n \"\"\" \n q = catalog.catalog(['first','second'])\n q.set_module_directory('third')\n order = q.build_search_order()\n assert(order == ['first','second',catalog.default_dir()])\n def check_build_search_order4(self):\n \"\"\" Make sure environment variable is getting used.\n \"\"\" \n q = catalog.catalog(['first','second'])\n if sys.platform == 'win32': sep = ';'\n else: sep = ':'\n os.environ['PYTHONCOMPILED'] = sep.join(('MODULE','fourth','fifth'))\n q.set_module_directory('third')\n order = q.build_search_order()\n assert(order == ['first','second','third','fourth','fifth',catalog.default_dir()])\n \n def check_catalog_files1(self):\n \"\"\" Be sure we get at least one file even without specifying the path.\n \"\"\"\n q = catalog.catalog()\n files = q.get_catalog_files()\n assert(len(files) == 1)\n\n def check_catalog_files2(self):\n \"\"\" Ignore bad paths in the path.\n \"\"\"\n q = catalog.catalog()\n os.environ['PYTHONCOMPILED'] = '_some_bad_path_'\n files = q.get_catalog_files()\n assert(len(files) == 1)\n \n def check_get_existing_files1(self):\n \"\"\" Shouldn't get any files when temp doesn't exist and no path set. \n \"\"\" \n clear_temp_catalog()\n q = catalog.catalog()\n files = q.get_existing_files()\n restore_temp_catalog()\n assert(len(files) == 0)\n def check_get_existing_files2(self):\n \"\"\" Shouldn't get a single file from the temp dir.\n \"\"\" \n clear_temp_catalog()\n q = catalog.catalog()\n # create a dummy file\n import os \n q.add_function('code', os.getpid)\n del q\n q = catalog.catalog()\n files = q.get_existing_files()\n restore_temp_catalog()\n assert(len(files) == 1)\n \n def check_access_writable_file(self):\n \"\"\" There should always be a writable file -- even if it is in temp\n \"\"\"\n q = catalog.catalog()\n file = q.get_writable_file()\n try:\n f = open(file,'w')\n f.write('bob')\n finally:\n f.close()\n os.remove(file) \n def check_writable_with_bad_path(self):\n \"\"\" There should always be a writable file -- even if search paths contain\n bad values.\n \"\"\"\n if sys.platform == 'win32': sep = ';'\n else: sep = ':' \n os.environ['PYTHONCOMPILED'] = sep.join(('_bad_path_name_'))\n q = catalog.catalog()\n file = q.get_writable_file()\n try:\n f = open(file,'w')\n f.write('bob')\n finally:\n f.close()\n os.remove(file) \n def check_writable_dir(self):\n \"\"\" Check that we can create a file in the writable directory\n \"\"\"\n q = catalog.catalog()\n d = q.get_writable_dir()\n file = os.path.join(d,'some_silly_file')\n try:\n f = open(file,'w')\n f.write('bob')\n finally:\n f.close()\n os.remove(file)\n def check_unique_module_name(self):\n \"\"\" Check that we can create a file in the writable directory\n \"\"\"\n q = catalog.catalog()\n file = q.unique_module_name('bob')\n cfile1 = file+'.cpp'\n assert(not os.path.exists(cfile1))\n #make sure it is writable\n try:\n f = open(cfile1,'w')\n f.write('bob')\n finally: \n f.close()\n # try again with same code fragment -- should get unique name\n file = q.unique_module_name('bob')\n cfile2 = file+'.cpp'\n assert(not os.path.exists(cfile2+'.cpp'))\n os.remove(cfile1)\n def check_add_function_persistent1(self):\n \"\"\" Test persisting a function in the default catalog\n \"\"\"\n clear_temp_catalog()\n q = catalog.catalog()\n # just use some already available functions\n import string\n funcs = [string.upper, string.lower, string.find,string.replace]\n for i in funcs:\n q.add_function_persistent('code',i)\n pfuncs = q.get_cataloged_functions('code') \n # any way to clean modules???\n restore_temp_catalog()\n for i in funcs:\n assert(i in pfuncs) \n \n def check_add_function_ordered(self):\n clear_temp_catalog()\n q = catalog.catalog()\n import string\n \n q.add_function('f',string.upper) \n q.add_function('f',string.lower)\n q.add_function('ff',string.find) \n q.add_function('ff',string.replace)\n q.add_function('fff',string.atof)\n q.add_function('fff',string.atoi)\n del q\n\n # now we're gonna make a new catalog with same code\n # but different functions in a specified module directory\n env_dir = empty_temp_dir()\n r = catalog.catalog(env_dir)\n r.add_function('ff',os.abort)\n r.add_function('ff',os.chdir)\n r.add_function('fff',os.access)\n r.add_function('fff',os.open)\n del r\n # now we're gonna make a new catalog with same code\n # but different functions in a user specified directory\n user_dir = empty_temp_dir()\n s = catalog.catalog(user_dir)\n import re\n s.add_function('fff',re.match)\n s.add_function('fff',re.purge)\n del s\n\n # open new catalog and make sure it retreives the functions\n # from d catalog instead of the temp catalog (made by q)\n os.environ['PYTHONCOMPILED'] = env_dir\n t = catalog.catalog(user_dir)\n funcs1 = t.get_functions('f')\n funcs2 = t.get_functions('ff')\n funcs3 = t.get_functions('fff')\n restore_temp_catalog()\n # make sure everything is read back in the correct order\n # a little cheating... I'm ignoring any functions that might have\n # been read in from a prior catalog file (such as the defualt one).\n # the test should really be made so that these aren't read in, but\n # until I get this figured out...\n #assert(funcs1 == [string.lower,string.upper])\n #assert(funcs2 == [os.chdir,os.abort,string.replace,string.find])\n #assert(funcs3 == [re.purge,re.match,os.open,\n # os.access,string.atoi,string.atof])\n assert(funcs1[:2] == [string.lower,string.upper])\n assert(funcs2[:4] == [os.chdir,os.abort,string.replace,string.find])\n assert(funcs3[:6] == [re.purge,re.match,os.open,\n os.access,string.atoi,string.atof])\n cleanup_temp_dir(user_dir)\n cleanup_temp_dir(env_dir)\n \n \ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_default_dir,'check_'))\n suites.append( unittest.makeSuite(test_os_dependent_catalog_name,\n 'check_'))\n suites.append( unittest.makeSuite(test_catalog_path,'check_'))\n suites.append( unittest.makeSuite(test_get_catalog,'check_'))\n suites.append( unittest.makeSuite(test_catalog,'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": "import unittest\nimport sys, os\n\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\nfrom scipy_distutils.misc_util import add_local_to_path\n\nadd_grandparent_to_path(__name__)\nimport catalog\nreload(catalog) # this'll pick up any recent code changes\nrestore_path()\n\nadd_local_to_path(__name__)\nfrom weave_test_utils import *\nrestore_path()\n\n\nclass test_default_dir(unittest.TestCase):\n def check_is_writable(self):\n path = catalog.default_dir()\n name = os.path.join(path,'dummy_catalog')\n test_file = open(name,'w')\n try:\n test_file.write('making sure default location is writable\\n')\n finally:\n test_file.close()\n os.remove(name)\n\nclass test_os_dependent_catalog_name(unittest.TestCase): \n pass\n \nclass test_catalog_path(unittest.TestCase): \n def check_default(self):\n in_path = catalog.default_dir()\n path = catalog.catalog_path(in_path)\n d,f = os.path.split(path)\n assert(d == in_path)\n assert(f == catalog.os_dependent_catalog_name())\n def check_current(self):\n in_path = '.'\n path = catalog.catalog_path(in_path)\n d,f = os.path.split(path)\n assert(d == os.path.abspath(in_path)) \n assert(f == catalog.os_dependent_catalog_name()) \n def check_user(path):\n if sys.platform != 'win32':\n in_path = '~'\n path = catalog.catalog_path(in_path)\n d,f = os.path.split(path)\n assert(d == os.path.expanduser(in_path)) \n assert(f == catalog.os_dependent_catalog_name())\n def check_module(self):\n # hand it a module and see if it uses the parent directory\n # of the module.\n path = catalog.catalog_path(os.__file__)\n d,f = os.path.split(os.__file__)\n d2,f = os.path.split(path)\n assert (d2 == d)\n def check_path(self):\n # use os.__file__ to get a usable directory.\n in_path,f = os.path.split(os.__file__)\n path = catalog.catalog_path(in_path)\n d,f = os.path.split(path)\n assert (d == in_path)\n def check_bad_path(self):\n # stupid_path_name\n in_path = 'stupid_path_name'\n path = catalog.catalog_path(in_path)\n assert (path is None)\n\nclass test_get_catalog(unittest.TestCase):\n \"\"\" This only tests whether new catalogs are created correctly.\n And whether non-existent return None correctly with read mode.\n Putting catalogs in the right place is all tested with\n catalog_dir tests.\n \"\"\"\n def get_test_dir(self,erase = 0):\n # make sure tempdir catalog doesn't exist\n import tempfile, glob\n #temp = tempfile.gettempdir()\n pardir = tempfile.mktemp(suffix='cat_test')\n if not os.path.exists(pardir):\n os.mkdir(pardir)\n cat_glob = os.path.join(pardir,catalog.os_dependent_catalog_name()+'.*') \n cat_files = glob.glob(cat_glob)\n if erase:\n for cat_file in cat_files:\n os.remove(cat_file)\n return pardir\n def remove_dir(self,d):\n import distutils.dir_util\n distutils.dir_util.remove_tree(d)\n \n def check_nonexistent_catalog_is_none(self):\n pardir = self.get_test_dir(erase=1)\n cat = catalog.get_catalog(pardir,'r')\n self.remove_dir(pardir)\n assert(cat is None)\n def check_create_catalog(self):\n pardir = self.get_test_dir(erase=1)\n cat = catalog.get_catalog(pardir,'c')\n self.remove_dir(pardir)\n assert(cat is not None)\n\nclass test_catalog(unittest.TestCase):\n\n def clear_environ(self):\n if os.environ.has_key('PYTHONCOMPILED'):\n self.old_PYTHONCOMPILED = os.environ['PYTHONCOMPILED']\n del os.environ['PYTHONCOMPILED']\n else: \n self.old_PYTHONCOMPILED = None\n def reset_environ(self):\n if self.old_PYTHONCOMPILED:\n os.environ['PYTHONCOMPILED'] = self.old_PYTHONCOMPILED\n self.old_PYTHONCOMPILED = None\n def setUp(self):\n self.clear_environ() \n def tearDown(self):\n self.reset_environ()\n \n def check_set_module_directory(self):\n q = catalog.catalog()\n q.set_module_directory('bob')\n r = q.get_module_directory()\n assert (r == 'bob')\n def check_clear_module_directory(self):\n q = catalog.catalog()\n r = q.get_module_directory()\n assert (r == None)\n q.set_module_directory('bob')\n r = q.clear_module_directory()\n assert (r == None)\n def check_get_environ_path(self):\n if sys.platform == 'win32': sep = ';'\n else: sep = ':'\n os.environ['PYTHONCOMPILED'] = sep.join(('path1','path2','path3'))\n q = catalog.catalog()\n path = q.get_environ_path() \n assert(path == ['path1','path2','path3'])\n def check_build_search_order1(self): \n \"\"\" MODULE in search path should be replaced by module_dir.\n \"\"\" \n q = catalog.catalog(['first','MODULE','third'])\n q.set_module_directory('second')\n order = q.build_search_order()\n assert(order == ['first','second','third',catalog.default_dir()])\n def check_build_search_order2(self): \n \"\"\" MODULE in search path should be removed if module_dir==None.\n \"\"\" \n q = catalog.catalog(['first','MODULE','third'])\n order = q.build_search_order()\n assert(order == ['first','third',catalog.default_dir()]) \n def check_build_search_order3(self):\n \"\"\" If MODULE is absent, module_dir shouldn't be in search path.\n \"\"\" \n q = catalog.catalog(['first','second'])\n q.set_module_directory('third')\n order = q.build_search_order()\n assert(order == ['first','second',catalog.default_dir()])\n def check_build_search_order4(self):\n \"\"\" Make sure environment variable is getting used.\n \"\"\" \n q = catalog.catalog(['first','second'])\n if sys.platform == 'win32': sep = ';'\n else: sep = ':'\n os.environ['PYTHONCOMPILED'] = sep.join(('MODULE','fourth','fifth'))\n q.set_module_directory('third')\n order = q.build_search_order()\n assert(order == ['first','second','third','fourth','fifth',catalog.default_dir()])\n \n def check_catalog_files1(self):\n \"\"\" Be sure we get at least one file even without specifying the path.\n \"\"\"\n q = catalog.catalog()\n files = q.get_catalog_files()\n assert(len(files) == 1)\n\n def check_catalog_files2(self):\n \"\"\" Ignore bad paths in the path.\n \"\"\"\n q = catalog.catalog()\n os.environ['PYTHONCOMPILED'] = '_some_bad_path_'\n files = q.get_catalog_files()\n assert(len(files) == 1)\n \n def check_get_existing_files1(self):\n \"\"\" Shouldn't get any files when temp doesn't exist and no path set. \n \"\"\" \n clear_temp_catalog()\n q = catalog.catalog()\n files = q.get_existing_files()\n restore_temp_catalog()\n assert(len(files) == 0)\n def check_get_existing_files2(self):\n \"\"\" Shouldn't get a single file from the temp dir.\n \"\"\" \n clear_temp_catalog()\n q = catalog.catalog()\n # create a dummy file\n import os \n q.add_function('code', os.getpid)\n del q\n q = catalog.catalog()\n files = q.get_existing_files()\n restore_temp_catalog()\n assert(len(files) == 1)\n \n def check_access_writable_file(self):\n \"\"\" There should always be a writable file -- even if it is in temp\n \"\"\"\n q = catalog.catalog()\n file = q.get_writable_file()\n try:\n f = open(file,'w')\n f.write('bob')\n finally:\n f.close()\n os.remove(file) \n def check_writable_with_bad_path(self):\n \"\"\" There should always be a writable file -- even if search paths contain\n bad values.\n \"\"\"\n if sys.platform == 'win32': sep = ';'\n else: sep = ':' \n os.environ['PYTHONCOMPILED'] = sep.join(('_bad_path_name_'))\n q = catalog.catalog()\n file = q.get_writable_file()\n try:\n f = open(file,'w')\n f.write('bob')\n finally:\n f.close()\n os.remove(file) \n def check_writable_dir(self):\n \"\"\" Check that we can create a file in the writable directory\n \"\"\"\n q = catalog.catalog()\n d = q.get_writable_dir()\n file = os.path.join(d,'some_silly_file')\n try:\n f = open(file,'w')\n f.write('bob')\n finally:\n f.close()\n os.remove(file)\n def check_unique_module_name(self):\n \"\"\" Check that we can create a file in the writable directory\n \"\"\"\n q = catalog.catalog()\n file = q.unique_module_name('bob')\n cfile1 = file+'.cpp'\n assert(not os.path.exists(cfile1))\n #make sure it is writable\n try:\n f = open(cfile1,'w')\n f.write('bob')\n finally: \n f.close()\n # try again with same code fragment -- should get unique name\n file = q.unique_module_name('bob')\n cfile2 = file+'.cpp'\n assert(not os.path.exists(cfile2+'.cpp'))\n os.remove(cfile1)\n def check_add_function_persistent1(self):\n \"\"\" Test persisting a function in the default catalog\n \"\"\"\n clear_temp_catalog()\n q = catalog.catalog()\n # just use some already available functions\n import string\n funcs = [string.upper, string.lower, string.find,string.replace]\n for i in funcs:\n q.add_function_persistent('code',i)\n pfuncs = q.get_cataloged_functions('code') \n # any way to clean modules???\n restore_temp_catalog()\n for i in funcs:\n assert(i in pfuncs) \n \n def check_add_function_ordered(self):\n clear_temp_catalog()\n q = catalog.catalog()\n import string\n \n q.add_function('f',string.upper) \n q.add_function('f',string.lower)\n q.add_function('ff',string.find) \n q.add_function('ff',string.replace)\n q.add_function('fff',string.atof)\n q.add_function('fff',string.atoi)\n del q\n\n # now we're gonna make a new catalog with same code\n # but different functions in a specified module directory\n env_dir = empty_temp_dir()\n r = catalog.catalog(env_dir)\n r.add_function('ff',os.abort)\n r.add_function('ff',os.chdir)\n r.add_function('fff',os.access)\n r.add_function('fff',os.open)\n del r\n # now we're gonna make a new catalog with same code\n # but different functions in a user specified directory\n user_dir = empty_temp_dir()\n s = catalog.catalog(user_dir)\n import re\n s.add_function('fff',re.match)\n s.add_function('fff',re.purge)\n del s\n\n # open new catalog and make sure it retreives the functions\n # from d catalog instead of the temp catalog (made by q)\n os.environ['PYTHONCOMPILED'] = env_dir\n t = catalog.catalog(user_dir)\n funcs1 = t.get_functions('f')\n funcs2 = t.get_functions('ff')\n funcs3 = t.get_functions('fff')\n restore_temp_catalog()\n # make sure everything is read back in the correct order\n # a little cheating... I'm ignoring any functions that might have\n # been read in from a prior catalog file (such as the defualt one).\n # the test should really be made so that these aren't read in, but\n # until I get this figured out...\n #assert(funcs1 == [string.lower,string.upper])\n #assert(funcs2 == [os.chdir,os.abort,string.replace,string.find])\n #assert(funcs3 == [re.purge,re.match,os.open,\n # os.access,string.atoi,string.atof])\n assert(funcs1[:2] == [string.lower,string.upper])\n assert(funcs2[:4] == [os.chdir,os.abort,string.replace,string.find])\n assert(funcs3[:6] == [re.purge,re.match,os.open,\n os.access,string.atoi,string.atof])\n cleanup_temp_dir(user_dir)\n cleanup_temp_dir(env_dir)\n \n \ndef test_suite():\n suites = []\n suites.append( unittest.makeSuite(test_default_dir,'check_'))\n suites.append( unittest.makeSuite(test_os_dependent_catalog_name,'check_'))\n suites.append( unittest.makeSuite(test_catalog_path,'check_'))\n suites.append( unittest.makeSuite(test_get_catalog,'check_'))\n suites.append( unittest.makeSuite(test_catalog,'check_'))\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\n\nif __name__ == '__main__':\n test()\n", "methods": [ { "name": "check_is_writable", "long_name": "check_is_writable( self )", "filename": "test_catalog.py", "nloc": 9, "complexity": 2, "token_count": 53, "parameters": [ "self" ], "start_line": 19, "end_line": 27, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_default", "long_name": "check_default( self )", "filename": "test_catalog.py", "nloc": 6, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 33, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_current", "long_name": "check_current( self )", "filename": "test_catalog.py", "nloc": 6, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 39, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_user", "long_name": "check_user( path )", "filename": "test_catalog.py", "nloc": 7, "complexity": 2, "token_count": 58, "parameters": [ "path" ], "start_line": 45, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_module", "long_name": "check_module( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 47, "parameters": [ "self" ], "start_line": 52, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_path", "long_name": "check_path( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 59, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_bad_path", "long_name": "check_bad_path( self )", "filename": "test_catalog.py", "nloc": 4, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 65, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_test_dir", "long_name": "get_test_dir( self , erase = 0 )", "filename": "test_catalog.py", "nloc": 11, "complexity": 4, "token_count": 82, "parameters": [ "self", "erase" ], "start_line": 77, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "remove_dir", "long_name": "remove_dir( self , d )", "filename": "test_catalog.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self", "d" ], "start_line": 90, "end_line": 92, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_nonexistent_catalog_is_none", "long_name": "check_nonexistent_catalog_is_none( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 37, "parameters": [ "self" ], "start_line": 94, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_create_catalog", "long_name": "check_create_catalog( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 99, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "clear_environ", "long_name": "clear_environ( self )", "filename": "test_catalog.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "self" ], "start_line": 107, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "reset_environ", "long_name": "reset_environ( self )", "filename": "test_catalog.py", "nloc": 4, "complexity": 2, "token_count": 25, "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": "setUp", "long_name": "setUp( self )", "filename": "test_catalog.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 117, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "tearDown", "long_name": "tearDown( self )", "filename": "test_catalog.py", "nloc": 2, "complexity": 1, "token_count": 10, "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_set_module_directory", "long_name": "check_set_module_directory( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 31, "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_clear_module_directory", "long_name": "check_clear_module_directory( self )", "filename": "test_catalog.py", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [ "self" ], "start_line": 127, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_get_environ_path", "long_name": "check_get_environ_path( self )", "filename": "test_catalog.py", "nloc": 7, "complexity": 2, "token_count": 65, "parameters": [ "self" ], "start_line": 134, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_build_search_order1", "long_name": "check_build_search_order1( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 141, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_build_search_order2", "long_name": "check_build_search_order2( self )", "filename": "test_catalog.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 148, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_build_search_order3", "long_name": "check_build_search_order3( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 47, "parameters": [ "self" ], "start_line": 154, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_build_search_order4", "long_name": "check_build_search_order4( self )", "filename": "test_catalog.py", "nloc": 8, "complexity": 2, "token_count": 87, "parameters": [ "self" ], "start_line": 161, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_catalog_files1", "long_name": "check_catalog_files1( self )", "filename": "test_catalog.py", "nloc": 4, "complexity": 1, "token_count": 29, "parameters": [ "self" ], "start_line": 172, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_catalog_files2", "long_name": "check_catalog_files2( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 37, "parameters": [ "self" ], "start_line": 179, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_get_existing_files1", "long_name": "check_get_existing_files1( self )", "filename": "test_catalog.py", "nloc": 6, "complexity": 1, "token_count": 35, "parameters": [ "self" ], "start_line": 187, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_get_existing_files2", "long_name": "check_get_existing_files2( self )", "filename": "test_catalog.py", "nloc": 10, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 195, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_access_writable_file", "long_name": "check_access_writable_file( self )", "filename": "test_catalog.py", "nloc": 9, "complexity": 2, "token_count": 49, "parameters": [ "self" ], "start_line": 209, "end_line": 219, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_writable_with_bad_path", "long_name": "check_writable_with_bad_path( self )", "filename": "test_catalog.py", "nloc": 12, "complexity": 3, "token_count": 79, "parameters": [ "self" ], "start_line": 220, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_writable_dir", "long_name": "check_writable_dir( self )", "filename": "test_catalog.py", "nloc": 10, "complexity": 2, "token_count": 61, "parameters": [ "self" ], "start_line": 235, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "check_unique_module_name", "long_name": "check_unique_module_name( self )", "filename": "test_catalog.py", "nloc": 14, "complexity": 2, "token_count": 94, "parameters": [ "self" ], "start_line": 247, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "check_add_function_persistent1", "long_name": "check_add_function_persistent1( self )", "filename": "test_catalog.py", "nloc": 11, "complexity": 3, "token_count": 72, "parameters": [ "self" ], "start_line": 265, "end_line": 279, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_add_function_ordered", "long_name": "check_add_function_ordered( self )", "filename": "test_catalog.py", "nloc": 36, "complexity": 1, "token_count": 300, "parameters": [ "self" ], "start_line": 281, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_catalog.py", "nloc": 11, "complexity": 2, "token_count": 91, "parameters": [ "level" ], "start_line": 337, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 350, "end_line": 354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_is_writable", "long_name": "check_is_writable( self )", "filename": "test_catalog.py", "nloc": 9, "complexity": 2, "token_count": 53, "parameters": [ "self" ], "start_line": 19, "end_line": 27, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "check_default", "long_name": "check_default( self )", "filename": "test_catalog.py", "nloc": 6, "complexity": 1, "token_count": 48, "parameters": [ "self" ], "start_line": 33, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_current", "long_name": "check_current( self )", "filename": "test_catalog.py", "nloc": 6, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 39, "end_line": 44, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_user", "long_name": "check_user( path )", "filename": "test_catalog.py", "nloc": 7, "complexity": 2, "token_count": 58, "parameters": [ "path" ], "start_line": 45, "end_line": 51, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_module", "long_name": "check_module( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 47, "parameters": [ "self" ], "start_line": 52, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_path", "long_name": "check_path( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 59, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_bad_path", "long_name": "check_bad_path( self )", "filename": "test_catalog.py", "nloc": 4, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 65, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_test_dir", "long_name": "get_test_dir( self , erase = 0 )", "filename": "test_catalog.py", "nloc": 11, "complexity": 4, "token_count": 82, "parameters": [ "self", "erase" ], "start_line": 77, "end_line": 89, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "remove_dir", "long_name": "remove_dir( self , d )", "filename": "test_catalog.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self", "d" ], "start_line": 90, "end_line": 92, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_nonexistent_catalog_is_none", "long_name": "check_nonexistent_catalog_is_none( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 37, "parameters": [ "self" ], "start_line": 94, "end_line": 98, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_create_catalog", "long_name": "check_create_catalog( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 38, "parameters": [ "self" ], "start_line": 99, "end_line": 103, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "clear_environ", "long_name": "clear_environ( self )", "filename": "test_catalog.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "self" ], "start_line": 107, "end_line": 112, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "reset_environ", "long_name": "reset_environ( self )", "filename": "test_catalog.py", "nloc": 4, "complexity": 2, "token_count": 25, "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": "setUp", "long_name": "setUp( self )", "filename": "test_catalog.py", "nloc": 2, "complexity": 1, "token_count": 10, "parameters": [ "self" ], "start_line": 117, "end_line": 118, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "tearDown", "long_name": "tearDown( self )", "filename": "test_catalog.py", "nloc": 2, "complexity": 1, "token_count": 10, "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_set_module_directory", "long_name": "check_set_module_directory( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 31, "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_clear_module_directory", "long_name": "check_clear_module_directory( self )", "filename": "test_catalog.py", "nloc": 7, "complexity": 1, "token_count": 44, "parameters": [ "self" ], "start_line": 127, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_get_environ_path", "long_name": "check_get_environ_path( self )", "filename": "test_catalog.py", "nloc": 7, "complexity": 2, "token_count": 65, "parameters": [ "self" ], "start_line": 134, "end_line": 140, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_build_search_order1", "long_name": "check_build_search_order1( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 141, "end_line": 147, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_build_search_order2", "long_name": "check_build_search_order2( self )", "filename": "test_catalog.py", "nloc": 4, "complexity": 1, "token_count": 43, "parameters": [ "self" ], "start_line": 148, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_build_search_order3", "long_name": "check_build_search_order3( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 47, "parameters": [ "self" ], "start_line": 154, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_build_search_order4", "long_name": "check_build_search_order4( self )", "filename": "test_catalog.py", "nloc": 8, "complexity": 2, "token_count": 87, "parameters": [ "self" ], "start_line": 161, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_catalog_files1", "long_name": "check_catalog_files1( self )", "filename": "test_catalog.py", "nloc": 4, "complexity": 1, "token_count": 29, "parameters": [ "self" ], "start_line": 172, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_catalog_files2", "long_name": "check_catalog_files2( self )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 37, "parameters": [ "self" ], "start_line": 179, "end_line": 185, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "check_get_existing_files1", "long_name": "check_get_existing_files1( self )", "filename": "test_catalog.py", "nloc": 6, "complexity": 1, "token_count": 35, "parameters": [ "self" ], "start_line": 187, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "check_get_existing_files2", "long_name": "check_get_existing_files2( self )", "filename": "test_catalog.py", "nloc": 10, "complexity": 1, "token_count": 56, "parameters": [ "self" ], "start_line": 195, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_access_writable_file", "long_name": "check_access_writable_file( self )", "filename": "test_catalog.py", "nloc": 9, "complexity": 2, "token_count": 49, "parameters": [ "self" ], "start_line": 209, "end_line": 219, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 1 }, { "name": "check_writable_with_bad_path", "long_name": "check_writable_with_bad_path( self )", "filename": "test_catalog.py", "nloc": 12, "complexity": 3, "token_count": 79, "parameters": [ "self" ], "start_line": 220, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_writable_dir", "long_name": "check_writable_dir( self )", "filename": "test_catalog.py", "nloc": 10, "complexity": 2, "token_count": 61, "parameters": [ "self" ], "start_line": 235, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "check_unique_module_name", "long_name": "check_unique_module_name( self )", "filename": "test_catalog.py", "nloc": 14, "complexity": 2, "token_count": 94, "parameters": [ "self" ], "start_line": 247, "end_line": 264, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "check_add_function_persistent1", "long_name": "check_add_function_persistent1( self )", "filename": "test_catalog.py", "nloc": 11, "complexity": 3, "token_count": 72, "parameters": [ "self" ], "start_line": 265, "end_line": 279, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_add_function_ordered", "long_name": "check_add_function_ordered( self )", "filename": "test_catalog.py", "nloc": 36, "complexity": 1, "token_count": 300, "parameters": [ "self" ], "start_line": 281, "end_line": 334, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_catalog.py", "nloc": 9, "complexity": 1, "token_count": 83, "parameters": [], "start_line": 337, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 348, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_catalog.py", "nloc": 11, "complexity": 2, "token_count": 91, "parameters": [ "level" ], "start_line": 337, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_catalog.py", "nloc": 9, "complexity": 1, "token_count": 83, "parameters": [], "start_line": 337, "end_line": 346, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 350, "end_line": 354, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_catalog.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 348, "end_line": 352, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 278, "complexity": 51, "token_count": 2011, "diff_parsed": { "added": [ "def test_suite(level=1):", " if level > 0:", " suites.append( unittest.makeSuite(test_default_dir,'check_'))", " suites.append( unittest.makeSuite(test_os_dependent_catalog_name,", " 'check_'))", " suites.append( unittest.makeSuite(test_catalog_path,'check_'))", " suites.append( unittest.makeSuite(test_get_catalog,'check_'))", " suites.append( unittest.makeSuite(test_catalog,'check_'))", "def test(level=10):", " all_tests = test_suite(level)" ], "deleted": [ "def test_suite():", " suites.append( unittest.makeSuite(test_default_dir,'check_'))", " suites.append( unittest.makeSuite(test_os_dependent_catalog_name,'check_'))", " suites.append( unittest.makeSuite(test_catalog_path,'check_'))", " suites.append( unittest.makeSuite(test_get_catalog,'check_'))", " suites.append( unittest.makeSuite(test_catalog,'check_'))", "def test():", " all_tests = test_suite()" ] } }, { "old_path": "weave/tests/test_common_spec.py", "new_path": "weave/tests/test_common_spec.py", "filename": "test_common_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -57,16 +57,17 @@ def check_call_function(self):\n desired = func(search_str,sub_str) \n assert(desired == actual)\n \n-def test_suite():\n- suites = [] \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+def test_suite(level=1):\n+ suites = []\n+ if level >= 5: \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 total_suite = unittest.TestSuite(suites)\n return total_suite\n \n-def test():\n- all_tests = test_suite()\n+def test(level=10):\n+ all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n", "added_lines": 8, "deleted_lines": 7, "source_code": "import unittest\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport inline_tools\nrestore_path()\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 = PyString_AsString( file_name.ptr() );\n FILE* file = fopen(_file_name,\"w\");\n Py::Object file_obj(file_to_py(file,_file_name,\"w\"));\n return_val = Py::new_reference_to(file_obj);\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\nclass test_instance_converter(unittest.TestCase): \n pass\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 Py::Tuple args(2);\n args[0] = Py::String(search_str);\n args[1] = Py::String(sub_str);\n PyObject* result = PyObject_CallObject(func,args.ptr());\n return_val = Py::new_reference_to(Py::Int(result));\n \"\"\"\n actual = inline_tools.inline(code,['func','search_str','sub_str'])\n desired = func(search_str,sub_str) \n assert(desired == actual)\n\ndef test_suite(level=1):\n suites = []\n if level >= 5: \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 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\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport inline_tools\nrestore_path()\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 = PyString_AsString( file_name.ptr() );\n FILE* file = fopen(_file_name,\"w\");\n Py::Object file_obj(file_to_py(file,_file_name,\"w\"));\n return_val = Py::new_reference_to(file_obj);\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\nclass test_instance_converter(unittest.TestCase): \n pass\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 Py::Tuple args(2);\n args[0] = Py::String(search_str);\n args[1] = Py::String(sub_str);\n PyObject* result = PyObject_CallObject(func,args.ptr());\n return_val = Py::new_reference_to(Py::Int(result));\n \"\"\"\n actual = inline_tools.inline(code,['func','search_str','sub_str'])\n desired = func(search_str,sub_str) \n assert(desired == actual)\n\ndef test_suite():\n suites = [] \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 total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "check_py_to_file", "long_name": "check_py_to_file( self )", "filename": "test_common_spec.py", "nloc": 11, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 10, "end_line": 20, "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_common_spec.py", "nloc": 14, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 21, "end_line": 36, "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_common_spec.py", "nloc": 15, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 42, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_common_spec.py", "nloc": 8, "complexity": 2, "token_count": 65, "parameters": [ "level" ], "start_line": 60, "end_line": 67, "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_common_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 69, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_py_to_file", "long_name": "check_py_to_file( self )", "filename": "test_common_spec.py", "nloc": 11, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 10, "end_line": 20, "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_common_spec.py", "nloc": 14, "complexity": 1, "token_count": 58, "parameters": [ "self" ], "start_line": 21, "end_line": 36, "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_common_spec.py", "nloc": 15, "complexity": 1, "token_count": 51, "parameters": [ "self" ], "start_line": 42, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_common_spec.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 60, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_common_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 68, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_common_spec.py", "nloc": 8, "complexity": 2, "token_count": 65, "parameters": [ "level" ], "start_line": 60, "end_line": 67, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_common_spec.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 60, "end_line": 66, "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_common_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 69, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_common_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 68, "end_line": 72, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 64, "complexity": 6, "token_count": 317, "diff_parsed": { "added": [ "def test_suite(level=1):", " suites = []", " if level >= 5:", " suites.append( unittest.makeSuite(test_file_converter,'check_'))", " suites.append( unittest.makeSuite(test_instance_converter,'check_'))", " suites.append( unittest.makeSuite(test_callable_converter,'check_'))", "def test(level=10):", " all_tests = test_suite(level)" ], "deleted": [ "def test_suite():", " suites = []", " suites.append( unittest.makeSuite(test_file_converter,'check_'))", " suites.append( unittest.makeSuite(test_instance_converter,'check_'))", " suites.append( unittest.makeSuite(test_callable_converter,'check_'))", "def test():", " all_tests = test_suite()" ] } }, { "old_path": "weave/tests/test_ext_tools.py", "new_path": "weave/tests/test_ext_tools.py", "filename": "test_ext_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -137,16 +137,18 @@ def check_assign_variable_types(self):\n print_assert_equal(expr,actual,desired)\n \n \n-def test_suite():\n+def test_suite(level=1):\n suites = []\n- suites.append( unittest.makeSuite(test_assign_variable_types,'check_') )\n- suites.append( unittest.makeSuite(test_ext_module,'check_'))\n- suites.append( unittest.makeSuite(test_ext_function,'check_')) \n+ if level > 0:\n+ suites.append( unittest.makeSuite(test_assign_variable_types,'check_'))\n+ if level >= 5: \n+ suites.append( unittest.makeSuite(test_ext_module,'check_'))\n+ suites.append( unittest.makeSuite(test_ext_function,'check_')) \n total_suite = unittest.TestSuite(suites)\n return total_suite\n \n-def test():\n- all_tests = test_suite()\n+def test(level=10):\n+ all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n", "added_lines": 8, "deleted_lines": 6, "source_code": "import unittest\nimport time\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\nfrom scipy_distutils.misc_util import add_local_to_path\n\nadd_grandparent_to_path(__name__)\nimport ext_tools\ntry:\n from standard_array_spec import array_converter\nexcept ImportError:\n pass # requires Numeric \nrestore_path()\n\nadd_local_to_path(__name__)\nfrom weave_test_utils import *\nrestore_path()\n\nbuild_dir = empty_temp_dir()\nprint 'building extensions here:', build_dir \n\nclass test_ext_module(unittest.TestCase):\n #should really do some testing of where modules end up\n def check_simple(self):\n \"\"\" Simplest possible module \"\"\"\n mod = ext_tools.ext_module('simple_ext_module')\n mod.compile(location = build_dir)\n import simple_ext_module\n def check_multi_functions(self):\n mod = ext_tools.ext_module('module_multi_function')\n var_specs = []\n code = \"\"\n test = ext_tools.ext_function_from_specs('test',code,var_specs)\n mod.add_function(test)\n test2 = ext_tools.ext_function_from_specs('test2',code,var_specs)\n mod.add_function(test2)\n mod.compile(location = build_dir)\n import module_multi_function\n module_multi_function.test()\n module_multi_function.test2()\n def check_with_include(self):\n # decalaring variables\n a = 2.;\n \n # declare module\n mod = ext_tools.ext_module('ext_module_with_include')\n mod.customize.add_header('')\n \n # function 2 --> a little more complex expression\n var_specs = ext_tools.assign_variable_types(['a'],locals(),globals())\n code = \"\"\"\n std::cout << std::endl;\n std::cout << \"test printing a value:\" << a << std::endl;\n \"\"\"\n test = ext_tools.ext_function_from_specs('test',code,var_specs)\n mod.add_function(test)\n # build module\n mod.compile(location = build_dir)\n import ext_module_with_include\n ext_module_with_include.test(a)\n\n def check_string_and_int(self): \n # decalaring variables\n a = 2;b = 'string' \n # declare module\n mod = ext_tools.ext_module('ext_string_and_int')\n code = \"\"\"\n a=b.length();\n return_val = Py::new_reference_to(Py::Int(a));\n \"\"\"\n test = ext_tools.ext_function('test',code,['a','b'])\n mod.add_function(test)\n mod.compile(location = build_dir)\n import ext_string_and_int\n c = ext_string_and_int.test(a,b)\n assert(c == len(b))\n \n def check_return_tuple(self): \n # decalaring variables\n a = 2 \n # declare module\n mod = ext_tools.ext_module('ext_return_tuple')\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n int b;\n b = a + 1;\n Py::Tuple returned(2);\n returned[0] = Py::Int(a);\n returned[1] = Py::Int(b);\n return_val = Py::new_reference_to(returned);\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = build_dir)\n import ext_return_tuple\n c,d = ext_return_tuple.test(a)\n assert(c==a and d == a+1)\n \nclass test_ext_function(unittest.TestCase):\n #should really do some testing of where modules end up\n def check_simple(self):\n \"\"\" Simplest possible function \"\"\"\n mod = ext_tools.ext_module('simple_ext_function')\n var_specs = []\n code = \"\"\n test = ext_tools.ext_function_from_specs('test',code,var_specs)\n mod.add_function(test)\n mod.compile(location = build_dir)\n import simple_ext_function\n simple_ext_function.test()\n \nclass test_assign_variable_types(unittest.TestCase): \n def check_assign_variable_types(self):\n try:\n from Numeric import arange, Float32, Float64\n except:\n # skip this test if Numeric not installed\n return\n \n import types\n a = arange(10,typecode = Float32)\n b = arange(5,typecode = Float64)\n c = 5\n arg_list = ['a','b','c']\n actual = ext_tools.assign_variable_types(arg_list,locals()) \n #desired = {'a':(Float32,1),'b':(Float32,1),'i':(Int32,0)}\n \n ad = array_converter()\n ad.name, ad.numeric_type, ad.dims = 'a', Float32, 1\n bd = array_converter()\n bd.name, bd.numeric_type, bd.dims = 'b', Float64, 1\n import scalar_spec\n cd = scalar_spec.int_converter()\n cd.name, cd.numeric_type = 'c', types.IntType \n desired = [ad,bd,cd]\n expr = \"\"\n print_assert_equal(expr,actual,desired)\n\n\ndef test_suite(level=1):\n suites = []\n if level > 0:\n suites.append( unittest.makeSuite(test_assign_variable_types,'check_'))\n if level >= 5: \n suites.append( unittest.makeSuite(test_ext_module,'check_'))\n suites.append( unittest.makeSuite(test_ext_function,'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\nimport time\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\nfrom scipy_distutils.misc_util import add_local_to_path\n\nadd_grandparent_to_path(__name__)\nimport ext_tools\ntry:\n from standard_array_spec import array_converter\nexcept ImportError:\n pass # requires Numeric \nrestore_path()\n\nadd_local_to_path(__name__)\nfrom weave_test_utils import *\nrestore_path()\n\nbuild_dir = empty_temp_dir()\nprint 'building extensions here:', build_dir \n\nclass test_ext_module(unittest.TestCase):\n #should really do some testing of where modules end up\n def check_simple(self):\n \"\"\" Simplest possible module \"\"\"\n mod = ext_tools.ext_module('simple_ext_module')\n mod.compile(location = build_dir)\n import simple_ext_module\n def check_multi_functions(self):\n mod = ext_tools.ext_module('module_multi_function')\n var_specs = []\n code = \"\"\n test = ext_tools.ext_function_from_specs('test',code,var_specs)\n mod.add_function(test)\n test2 = ext_tools.ext_function_from_specs('test2',code,var_specs)\n mod.add_function(test2)\n mod.compile(location = build_dir)\n import module_multi_function\n module_multi_function.test()\n module_multi_function.test2()\n def check_with_include(self):\n # decalaring variables\n a = 2.;\n \n # declare module\n mod = ext_tools.ext_module('ext_module_with_include')\n mod.customize.add_header('')\n \n # function 2 --> a little more complex expression\n var_specs = ext_tools.assign_variable_types(['a'],locals(),globals())\n code = \"\"\"\n std::cout << std::endl;\n std::cout << \"test printing a value:\" << a << std::endl;\n \"\"\"\n test = ext_tools.ext_function_from_specs('test',code,var_specs)\n mod.add_function(test)\n # build module\n mod.compile(location = build_dir)\n import ext_module_with_include\n ext_module_with_include.test(a)\n\n def check_string_and_int(self): \n # decalaring variables\n a = 2;b = 'string' \n # declare module\n mod = ext_tools.ext_module('ext_string_and_int')\n code = \"\"\"\n a=b.length();\n return_val = Py::new_reference_to(Py::Int(a));\n \"\"\"\n test = ext_tools.ext_function('test',code,['a','b'])\n mod.add_function(test)\n mod.compile(location = build_dir)\n import ext_string_and_int\n c = ext_string_and_int.test(a,b)\n assert(c == len(b))\n \n def check_return_tuple(self): \n # decalaring variables\n a = 2 \n # declare module\n mod = ext_tools.ext_module('ext_return_tuple')\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n int b;\n b = a + 1;\n Py::Tuple returned(2);\n returned[0] = Py::Int(a);\n returned[1] = Py::Int(b);\n return_val = Py::new_reference_to(returned);\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'])\n mod.add_function(test)\n mod.compile(location = build_dir)\n import ext_return_tuple\n c,d = ext_return_tuple.test(a)\n assert(c==a and d == a+1)\n \nclass test_ext_function(unittest.TestCase):\n #should really do some testing of where modules end up\n def check_simple(self):\n \"\"\" Simplest possible function \"\"\"\n mod = ext_tools.ext_module('simple_ext_function')\n var_specs = []\n code = \"\"\n test = ext_tools.ext_function_from_specs('test',code,var_specs)\n mod.add_function(test)\n mod.compile(location = build_dir)\n import simple_ext_function\n simple_ext_function.test()\n \nclass test_assign_variable_types(unittest.TestCase): \n def check_assign_variable_types(self):\n try:\n from Numeric import arange, Float32, Float64\n except:\n # skip this test if Numeric not installed\n return\n \n import types\n a = arange(10,typecode = Float32)\n b = arange(5,typecode = Float64)\n c = 5\n arg_list = ['a','b','c']\n actual = ext_tools.assign_variable_types(arg_list,locals()) \n #desired = {'a':(Float32,1),'b':(Float32,1),'i':(Int32,0)}\n \n ad = array_converter()\n ad.name, ad.numeric_type, ad.dims = 'a', Float32, 1\n bd = array_converter()\n bd.name, bd.numeric_type, bd.dims = 'b', Float64, 1\n import scalar_spec\n cd = scalar_spec.int_converter()\n cd.name, cd.numeric_type = 'c', types.IntType \n desired = [ad,bd,cd]\n expr = \"\"\n print_assert_equal(expr,actual,desired)\n\n\ndef test_suite():\n suites = []\n suites.append( unittest.makeSuite(test_assign_variable_types,'check_') )\n suites.append( unittest.makeSuite(test_ext_module,'check_'))\n suites.append( unittest.makeSuite(test_ext_function,'check_')) \n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 24, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_multi_functions", "long_name": "check_multi_functions( self )", "filename": "test_ext_tools.py", "nloc": 12, "complexity": 1, "token_count": 76, "parameters": [ "self" ], "start_line": 29, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "check_with_include", "long_name": "check_with_include( self )", "filename": "test_ext_tools.py", "nloc": 14, "complexity": 1, "token_count": 81, "parameters": [ "self" ], "start_line": 41, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_string_and_int", "long_name": "check_string_and_int( self )", "filename": "test_ext_tools.py", "nloc": 13, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 62, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_return_tuple", "long_name": "check_return_tuple( self )", "filename": "test_ext_tools.py", "nloc": 18, "complexity": 2, "token_count": 85, "parameters": [ "self" ], "start_line": 78, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_ext_tools.py", "nloc": 9, "complexity": 1, "token_count": 54, "parameters": [ "self" ], "start_line": 101, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_assign_variable_types", "long_name": "check_assign_variable_types( self )", "filename": "test_ext_tools.py", "nloc": 21, "complexity": 2, "token_count": 150, "parameters": [ "self" ], "start_line": 113, "end_line": 137, "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_ext_tools.py", "nloc": 9, "complexity": 3, "token_count": 70, "parameters": [ "level" ], "start_line": 140, "end_line": 148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 150, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_ext_tools.py", "nloc": 4, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 24, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "check_multi_functions", "long_name": "check_multi_functions( self )", "filename": "test_ext_tools.py", "nloc": 12, "complexity": 1, "token_count": 76, "parameters": [ "self" ], "start_line": 29, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "check_with_include", "long_name": "check_with_include( self )", "filename": "test_ext_tools.py", "nloc": 14, "complexity": 1, "token_count": 81, "parameters": [ "self" ], "start_line": 41, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_string_and_int", "long_name": "check_string_and_int( self )", "filename": "test_ext_tools.py", "nloc": 13, "complexity": 1, "token_count": 74, "parameters": [ "self" ], "start_line": 62, "end_line": 76, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_return_tuple", "long_name": "check_return_tuple( self )", "filename": "test_ext_tools.py", "nloc": 18, "complexity": 2, "token_count": 85, "parameters": [ "self" ], "start_line": 78, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "check_simple", "long_name": "check_simple( self )", "filename": "test_ext_tools.py", "nloc": 9, "complexity": 1, "token_count": 54, "parameters": [ "self" ], "start_line": 101, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "check_assign_variable_types", "long_name": "check_assign_variable_types( self )", "filename": "test_ext_tools.py", "nloc": 21, "complexity": 2, "token_count": 150, "parameters": [ "self" ], "start_line": 113, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_ext_tools.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 140, "end_line": 146, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 148, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_ext_tools.py", "nloc": 9, "complexity": 3, "token_count": 70, "parameters": [ "level" ], "start_line": 140, "end_line": 148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_ext_tools.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 140, "end_line": 146, "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_ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 150, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_ext_tools.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 148, "end_line": 152, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 126, "complexity": 13, "token_count": 740, "diff_parsed": { "added": [ "def test_suite(level=1):", " if level > 0:", " suites.append( unittest.makeSuite(test_assign_variable_types,'check_'))", " if level >= 5:", " suites.append( unittest.makeSuite(test_ext_module,'check_'))", " suites.append( unittest.makeSuite(test_ext_function,'check_'))", "def test(level=10):", " all_tests = test_suite(level)" ], "deleted": [ "def test_suite():", " suites.append( unittest.makeSuite(test_assign_variable_types,'check_') )", " suites.append( unittest.makeSuite(test_ext_module,'check_'))", " suites.append( unittest.makeSuite(test_ext_function,'check_'))", "def test():", " all_tests = test_suite()" ] } }, { "old_path": "weave/tests/test_inline_tools.py", "new_path": "weave/tests/test_inline_tools.py", "filename": "test_inline_tools.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -39,14 +39,15 @@ def check_exceptions(self):\n # ?CompileError is the error reported, but catching it doesn't work\n pass\n \n-def test_suite():\n+def test_suite(level=1):\n suites = []\n- suites.append( unittest.makeSuite(test_inline,'check_') ) \n+ if level >= 5:\n+ suites.append( unittest.makeSuite(test_inline,'check_') ) \n total_suite = unittest.TestSuite(suites)\n return total_suite\n \n-def test():\n- all_tests = test_suite()\n+def test(level=10):\n+ all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n", "added_lines": 5, "deleted_lines": 4, "source_code": "import unittest\nfrom Numeric import *\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path,restore_path\nfrom scipy_distutils.misc_util import add_local_to_path\n\nadd_grandparent_to_path(__name__)\nimport inline_tools\nrestore_path()\n\nclass test_inline(unittest.TestCase):\n \"\"\" These are long running tests...\n \n I'd like to benchmark these things somehow.\n \"\"\"\n def check_exceptions(self):\n a = 1 \n code = \"\"\"\n if (a < 2)\n Py::ValueError(\"the variable 'a' should not be less than 2\");\n return_val = Py::new_reference_to(Py::Int(a+1));\n \"\"\"\n result = inline_tools.inline(code,['a'])\n assert(result == 2)\n \n try:\n a = 3\n result = inline_tools.inline(code,['a'])\n assert(1) # should've thrown a ValueError\n except ValueError:\n pass\n \n from distutils.errors import DistutilsError, CompileError \n try:\n a = 'string'\n result = inline_tools.inline(code,['a'])\n assert(1) # should've gotten an error\n except: \n # ?CompileError is the error reported, but catching it doesn't work\n pass\n \ndef test_suite(level=1):\n suites = []\n if level >= 5:\n suites.append( unittest.makeSuite(test_inline,'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\nfrom Numeric import *\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path,restore_path\nfrom scipy_distutils.misc_util import add_local_to_path\n\nadd_grandparent_to_path(__name__)\nimport inline_tools\nrestore_path()\n\nclass test_inline(unittest.TestCase):\n \"\"\" These are long running tests...\n \n I'd like to benchmark these things somehow.\n \"\"\"\n def check_exceptions(self):\n a = 1 \n code = \"\"\"\n if (a < 2)\n Py::ValueError(\"the variable 'a' should not be less than 2\");\n return_val = Py::new_reference_to(Py::Int(a+1));\n \"\"\"\n result = inline_tools.inline(code,['a'])\n assert(result == 2)\n \n try:\n a = 3\n result = inline_tools.inline(code,['a'])\n assert(1) # should've thrown a ValueError\n except ValueError:\n pass\n \n from distutils.errors import DistutilsError, CompileError \n try:\n a = 'string'\n result = inline_tools.inline(code,['a'])\n assert(1) # should've gotten an error\n except: \n # ?CompileError is the error reported, but catching it doesn't work\n pass\n \ndef test_suite():\n suites = []\n suites.append( unittest.makeSuite(test_inline,'check_') ) \n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "check_exceptions", "long_name": "check_exceptions( self )", "filename": "test_inline_tools.py", "nloc": 22, "complexity": 3, "token_count": 86, "parameters": [ "self" ], "start_line": 16, "end_line": 40, "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_inline_tools.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "level" ], "start_line": 42, "end_line": 47, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_inline_tools.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 49, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_exceptions", "long_name": "check_exceptions( self )", "filename": "test_inline_tools.py", "nloc": 22, "complexity": 3, "token_count": 86, "parameters": [ "self" ], "start_line": 16, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_inline_tools.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 42, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_inline_tools.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 48, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_inline_tools.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "level" ], "start_line": 42, "end_line": 47, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_inline_tools.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 42, "end_line": 46, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_inline_tools.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 49, "end_line": 53, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_inline_tools.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 48, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 47, "complexity": 6, "token_count": 202, "diff_parsed": { "added": [ "def test_suite(level=1):", " if level >= 5:", " suites.append( unittest.makeSuite(test_inline,'check_') )", "def test(level=10):", " all_tests = test_suite(level)" ], "deleted": [ "def test_suite():", " suites.append( unittest.makeSuite(test_inline,'check_') )", "def test():", " all_tests = test_suite()" ] } }, { "old_path": "weave/tests/test_scalar_spec.py", "new_path": "weave/tests/test_scalar_spec.py", "filename": "test_scalar_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -299,29 +299,39 @@ def teardown_test_location():\n \n def remove_file(name):\n test_dir = os.path.abspath(name)\n-def test_suite():\n- suites = []\n-\n- if msvc_exists():\n- suites.append( unittest.makeSuite(test_msvc_int_converter,'check_'))\n- suites.append( unittest.makeSuite(test_msvc_float_converter,'check_')) \n- suites.append( unittest.makeSuite(test_msvc_complex_converter,'check_'))\n- pass\n- else: # unix\n- suites.append( unittest.makeSuite(test_unix_int_converter,'check_'))\n- suites.append( unittest.makeSuite(test_unix_float_converter,'check_')) \n- suites.append( unittest.makeSuite(test_unix_complex_converter,'check_'))\n \n- if gcc_exists(): \n- suites.append( unittest.makeSuite(test_gcc_int_converter,'check_'))\n- suites.append( unittest.makeSuite(test_gcc_float_converter,'check_')) \n- suites.append( unittest.makeSuite(test_gcc_complex_converter,'check_'))\n+def test_suite(level=1):\n+ suites = [] \n+ if level >= 5:\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 total_suite = unittest.TestSuite(suites)\n return total_suite\n \n-def test():\n- all_tests = test_suite()\n+def test(level=10):\n+ all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n", "added_lines": 28, "deleted_lines": 18, "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 ext_tools\nfrom catalog import unique_file\nfrom build_tools import msvc_exists, gcc_exists\nimport scalar_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\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_int_converter(unittest.TestCase):\n compiler = '' \n def check_type_match_string(self):\n s = scalar_spec.int_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.int_converter() \n assert(s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.int_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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_var_local(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 = \"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 q={}\n test(b,q)\n teardown_test_location()\n assert(q['a'] == 2)\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 = Py::new_reference_to(Py::Int(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 = scalar_spec.float_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.float_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.float_converter() \n assert(s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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 def check_float_var_local(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 = \"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 q={}\n test(b,q)\n teardown_test_location()\n assert(q['a'] == 2.)\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 = Py::new_reference_to(Py::Float(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 = scalar_spec.complex_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.complex_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.complex_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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 def check_complex_var_local(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= 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 q={}\n test(b,q)\n teardown_test_location() \n assert(q['a'] == 3.+3j)\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 = Py::new_reference_to(Py::Complex(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 \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 \ndef test_suite(level=1):\n suites = [] \n if level >= 5:\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 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 ext_tools\nfrom catalog import unique_file\nfrom build_tools import msvc_exists, gcc_exists\nimport scalar_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\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_int_converter(unittest.TestCase):\n compiler = '' \n def check_type_match_string(self):\n s = scalar_spec.int_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.int_converter() \n assert(s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.int_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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_var_local(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 = \"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 q={}\n test(b,q)\n teardown_test_location()\n assert(q['a'] == 2)\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 = Py::new_reference_to(Py::Int(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 = scalar_spec.float_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.float_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.float_converter() \n assert(s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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 def check_float_var_local(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 = \"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 q={}\n test(b,q)\n teardown_test_location()\n assert(q['a'] == 2.)\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 = Py::new_reference_to(Py::Float(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 = scalar_spec.complex_converter()\n assert( not s.type_match('string') )\n def check_type_match_int(self):\n s = scalar_spec.complex_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = scalar_spec.complex_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = scalar_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 def check_complex_var_local(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= 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 q={}\n test(b,q)\n teardown_test_location() \n assert(q['a'] == 3.+3j)\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 = Py::new_reference_to(Py::Complex(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 \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)\ndef test_suite():\n suites = []\n\n if msvc_exists():\n suites.append( unittest.makeSuite(test_msvc_int_converter,'check_'))\n suites.append( unittest.makeSuite(test_msvc_float_converter,'check_')) \n suites.append( unittest.makeSuite(test_msvc_complex_converter,'check_'))\n pass\n else: # unix\n suites.append( unittest.makeSuite(test_unix_int_converter,'check_'))\n suites.append( unittest.makeSuite(test_unix_float_converter,'check_')) \n suites.append( unittest.makeSuite(test_unix_complex_converter,'check_'))\n \n if gcc_exists(): \n suites.append( unittest.makeSuite(test_gcc_int_converter,'check_'))\n suites.append( unittest.makeSuite(test_gcc_float_converter,'check_')) \n suites.append( unittest.makeSuite(test_gcc_complex_converter,'check_'))\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\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_scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "d", "file_name" ], "start_line": 14, "end_line": 17, "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_scalar_spec.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "in_str" ], "start_line": 19, "end_line": 24, "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_scalar_spec.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 26, "end_line": 40, "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_scalar_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_int", "long_name": "check_type_match_int( self )", "filename": "test_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "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": "check_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 50, "end_line": 52, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 53, "end_line": 55, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 116, "parameters": [ "self" ], "start_line": 56, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_int_var_local", "long_name": "check_int_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 112, "parameters": [ "self" ], "start_line": 81, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_int_return", "long_name": "check_int_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 97, "end_line": 114, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 118, "end_line": 120, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 121, "end_line": 123, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 124, "end_line": 126, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 127, "end_line": 129, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 126, "parameters": [ "self" ], "start_line": 130, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "check_float_var_local", "long_name": "check_float_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 115, "parameters": [ "self" ], "start_line": 155, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_float_return", "long_name": "check_float_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 108, "parameters": [ "self" ], "start_line": 171, "end_line": 188, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 192, "end_line": 194, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 195, "end_line": 197, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 198, "end_line": 200, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 201, "end_line": 203, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 130, "parameters": [ "self" ], "start_line": 204, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_complex_var_local", "long_name": "check_complex_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 121, "parameters": [ "self" ], "start_line": 228, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_complex_return", "long_name": "check_complex_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 114, "parameters": [ "self" ], "start_line": 244, "end_line": 261, "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_scalar_spec.py", "nloc": 7, "complexity": 2, "token_count": 51, "parameters": [], "start_line": 285, "end_line": 291, "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_scalar_spec.py", "nloc": 6, "complexity": 2, "token_count": 45, "parameters": [], "start_line": 293, "end_line": 298, "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_scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "name" ], "start_line": 300, "end_line": 301, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_scalar_spec.py", "nloc": 27, "complexity": 4, "token_count": 156, "parameters": [ "level" ], "start_line": 303, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 333, "end_line": 337, "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_scalar_spec.py", "nloc": 4, "complexity": 1, "token_count": 37, "parameters": [ "d", "file_name" ], "start_line": 14, "end_line": 17, "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_scalar_spec.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "in_str" ], "start_line": 19, "end_line": 24, "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_scalar_spec.py", "nloc": 13, "complexity": 2, "token_count": 74, "parameters": [ "test_string", "actual", "desired" ], "start_line": 26, "end_line": 40, "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_scalar_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_int", "long_name": "check_type_match_int( self )", "filename": "test_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "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": "check_type_match_float", "long_name": "check_type_match_float( self )", "filename": "test_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 50, "end_line": 52, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 53, "end_line": 55, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 116, "parameters": [ "self" ], "start_line": 56, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_int_var_local", "long_name": "check_int_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 112, "parameters": [ "self" ], "start_line": 81, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_int_return", "long_name": "check_int_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 105, "parameters": [ "self" ], "start_line": 97, "end_line": 114, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 118, "end_line": 120, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 121, "end_line": 123, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 124, "end_line": 126, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 127, "end_line": 129, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 126, "parameters": [ "self" ], "start_line": 130, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "check_float_var_local", "long_name": "check_float_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 115, "parameters": [ "self" ], "start_line": 155, "end_line": 170, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_float_return", "long_name": "check_float_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 108, "parameters": [ "self" ], "start_line": 171, "end_line": 188, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 192, "end_line": 194, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 195, "end_line": 197, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 198, "end_line": 200, "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_scalar_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 201, "end_line": 203, "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_scalar_spec.py", "nloc": 24, "complexity": 3, "token_count": 130, "parameters": [ "self" ], "start_line": 204, "end_line": 227, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "check_complex_var_local", "long_name": "check_complex_var_local( self )", "filename": "test_scalar_spec.py", "nloc": 16, "complexity": 1, "token_count": 121, "parameters": [ "self" ], "start_line": 228, "end_line": 243, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_complex_return", "long_name": "check_complex_return( self )", "filename": "test_scalar_spec.py", "nloc": 18, "complexity": 1, "token_count": 114, "parameters": [ "self" ], "start_line": 244, "end_line": 261, "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_scalar_spec.py", "nloc": 7, "complexity": 2, "token_count": 51, "parameters": [], "start_line": 285, "end_line": 291, "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_scalar_spec.py", "nloc": 6, "complexity": 2, "token_count": 45, "parameters": [], "start_line": 293, "end_line": 298, "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_scalar_spec.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "name" ], "start_line": 300, "end_line": 301, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_scalar_spec.py", "nloc": 17, "complexity": 3, "token_count": 148, "parameters": [], "start_line": 302, "end_line": 321, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 323, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_scalar_spec.py", "nloc": 27, "complexity": 4, "token_count": 156, "parameters": [ "level" ], "start_line": 303, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_scalar_spec.py", "nloc": 17, "complexity": 3, "token_count": 148, "parameters": [], "start_line": 302, "end_line": 321, "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_scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 333, "end_line": 337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_scalar_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 323, "end_line": 327, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 316, "complexity": 41, "token_count": 1959, "diff_parsed": { "added": [ "def test_suite(level=1):", " suites = []", " if level >= 5:", " if msvc_exists():", " suites.append( unittest.makeSuite(test_msvc_int_converter,", " 'check_'))", " suites.append( unittest.makeSuite(test_msvc_float_converter,", " 'check_'))", " suites.append( unittest.makeSuite(test_msvc_complex_converter,", " 'check_'))", " pass", " else: # unix", " suites.append( unittest.makeSuite(test_unix_int_converter,", " 'check_'))", " suites.append( unittest.makeSuite(test_unix_float_converter,", " 'check_'))", " suites.append( unittest.makeSuite(test_unix_complex_converter,", " 'check_'))", "", " if gcc_exists():", " suites.append( unittest.makeSuite(test_gcc_int_converter,", " 'check_'))", " suites.append( unittest.makeSuite(test_gcc_float_converter,", " 'check_'))", " suites.append( unittest.makeSuite(test_gcc_complex_converter,", " 'check_'))", "def test(level=10):", " all_tests = test_suite(level)" ], "deleted": [ "def test_suite():", " suites = []", "", " if msvc_exists():", " suites.append( unittest.makeSuite(test_msvc_int_converter,'check_'))", " suites.append( unittest.makeSuite(test_msvc_float_converter,'check_'))", " suites.append( unittest.makeSuite(test_msvc_complex_converter,'check_'))", " pass", " else: # unix", " suites.append( unittest.makeSuite(test_unix_int_converter,'check_'))", " suites.append( unittest.makeSuite(test_unix_float_converter,'check_'))", " suites.append( unittest.makeSuite(test_unix_complex_converter,'check_'))", " if gcc_exists():", " suites.append( unittest.makeSuite(test_gcc_int_converter,'check_'))", " suites.append( unittest.makeSuite(test_gcc_float_converter,'check_'))", " suites.append( unittest.makeSuite(test_gcc_complex_converter,'check_'))", "def test():", " all_tests = test_suite()" ] } }, { "old_path": "weave/tests/test_sequence_spec.py", "new_path": "weave/tests/test_sequence_spec.py", "filename": "test_sequence_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -20,14 +20,15 @@ def check_convert_to_tuple(self):\n t = ()\n inline_tools.inline(\"\",['t']) \n \n-def test_suite():\n- suites = [] \n- suites.append( unittest.makeSuite(test_sequence_converter,'check_'))\n+def test_suite(level=1):\n+ suites = []\n+ if level >= 5:\n+ suites.append( unittest.makeSuite(test_sequence_converter,'check_'))\n total_suite = unittest.TestSuite(suites)\n return total_suite\n \n-def test():\n- all_tests = test_suite()\n+def test(level=10):\n+ all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n", "added_lines": 6, "deleted_lines": 5, "source_code": "import unittest\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport inline_tools\nrestore_path()\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 \ndef test_suite(level=1):\n suites = []\n if level >= 5:\n suites.append( unittest.makeSuite(test_sequence_converter,'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\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport inline_tools\nrestore_path()\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 \ndef test_suite():\n suites = [] \n suites.append( unittest.makeSuite(test_sequence_converter,'check_'))\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "check_convert_to_dict", "long_name": "check_convert_to_dict( self )", "filename": "test_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 10, "end_line": 12, "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_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 13, "end_line": 15, "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_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 16, "end_line": 18, "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_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 19, "end_line": 21, "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_sequence_spec.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "level" ], "start_line": 23, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 30, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_convert_to_dict", "long_name": "check_convert_to_dict( self )", "filename": "test_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 10, "end_line": 12, "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_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 13, "end_line": 15, "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_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 18, "parameters": [ "self" ], "start_line": 16, "end_line": 18, "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_sequence_spec.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 19, "end_line": 21, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 23, "end_line": 27, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 29, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_sequence_spec.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "level" ], "start_line": 23, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 23, "end_line": 27, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 30, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_sequence_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 29, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 31, "complexity": 7, "token_count": 183, "diff_parsed": { "added": [ "def test_suite(level=1):", " suites = []", " if level >= 5:", " suites.append( unittest.makeSuite(test_sequence_converter,'check_'))", "def test(level=10):", " all_tests = test_suite(level)" ], "deleted": [ "def test_suite():", " suites = []", " suites.append( unittest.makeSuite(test_sequence_converter,'check_'))", "def test():", " all_tests = test_suite()" ] } }, { "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": "@@ -443,19 +443,20 @@ def generic_3d(self,expr):\n a = ones((10,20,1))\n self.generic_wrap(a,expr)\n \n-def test_suite():\n+def test_suite(level=1):\n suites = []\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+ 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 \n-def test():\n- all_tests = test_suite()\n+def test(level=10):\n+ all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n", "added_lines": 10, "deleted_lines": 9, "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 fastumath import *\nexcept:\n pass # 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\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\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\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\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 fastumath import *\nexcept:\n pass # 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\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\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\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\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():\n suites = []\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():\n all_tests = test_suite()\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( )", "filename": "test_size_check.py", "nloc": 10, "complexity": 1, "token_count": 96, "parameters": [], "start_line": 446, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 457, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "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_suite", "long_name": "test_suite( )", "filename": "test_size_check.py", "nloc": 10, "complexity": 1, "token_count": 96, "parameters": [], "start_line": 446, "end_line": 455, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "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 }, { "name": "test", "long_name": "test( )", "filename": "test_size_check.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 457, "end_line": 461, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 421, "complexity": 117, "token_count": 3157, "diff_parsed": { "added": [ "def test_suite(level=1):", " if level > 0:", " suites.append( unittest.makeSuite(test_make_same_length,'check_') )", " suites.append( unittest.makeSuite(test_binary_op_size,'check_') )", " suites.append( unittest.makeSuite(test_dummy_array,'check_') )", " suites.append( unittest.makeSuite(test_dummy_array_indexing,'check_') )", " suites.append( unittest.makeSuite(test_reduction,'check_') )", " suites.append( unittest.makeSuite(test_expressions,'check_') )", "def test(level=10):", " all_tests = test_suite(level)" ], "deleted": [ "def test_suite():", " suites.append( unittest.makeSuite(test_make_same_length,'check_') )", " suites.append( unittest.makeSuite(test_binary_op_size,'check_') )", " suites.append( unittest.makeSuite(test_dummy_array,'check_') )", " suites.append( unittest.makeSuite(test_dummy_array_indexing,'check_') )", " suites.append( unittest.makeSuite(test_reduction,'check_') )", " suites.append( unittest.makeSuite(test_expressions,'check_') )", "def test():", " all_tests = test_suite()" ] } }, { "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": "@@ -166,16 +166,17 @@ def check_simple_expr(self):\n self.generic_test(test,desired)\n \n \n-def test_suite():\n+def test_suite(level=1):\n suites = []\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+ 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 \n-def test():\n- all_tests = test_suite()\n+def test(level=10):\n+ all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n", "added_lines": 7, "deleted_lines": 6, "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\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_test\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():\n suites = []\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():\n all_tests = test_suite()\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( )", "filename": "test_slice_handler.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 169, "end_line": 175, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 177, "end_line": 181, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "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_suite", "long_name": "test_suite( )", "filename": "test_slice_handler.py", "nloc": 7, "complexity": 1, "token_count": 57, "parameters": [], "start_line": 169, "end_line": 175, "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_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 }, { "name": "test", "long_name": "test( )", "filename": "test_slice_handler.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 177, "end_line": 181, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 150, "complexity": 26, "token_count": 1038, "diff_parsed": { "added": [ "def test_suite(level=1):", " if level > 0:", " suites.append( unittest.makeSuite(test_slice,'check_') )", " suites.append( unittest.makeSuite(test_transform_slices,'check_') )", " suites.append( unittest.makeSuite(test_build_slice_atom,'check_') )", "def test(level=10):", " all_tests = test_suite(level)" ], "deleted": [ "def test_suite():", " suites.append( unittest.makeSuite(test_slice,'check_') )", " suites.append( unittest.makeSuite(test_transform_slices,'check_') )", " suites.append( unittest.makeSuite(test_build_slice_atom,'check_') )", "def test():", " all_tests = test_suite()" ] } }, { "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": "@@ -48,16 +48,16 @@ def check_type_match_array(self):\n s = standard_array_spec.array_converter() \n assert(s.type_match(arange(4)))\n \n-def test_suite():\n+def test_suite(level=1):\n suites = []\n- \n- suites.append( unittest.makeSuite(test_array_converter,'check_'))\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 \n-def test():\n- all_tests = test_suite()\n+def test(level=10):\n+ all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n", "added_lines": 5, "deleted_lines": 5, "source_code": "import unittest\nfrom Numeric import *\n# The following try/except so that non-SciPy users can still use blitz\ntry:\n from fastumath import *\nexcept:\n pass # 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\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 fastumath import *\nexcept:\n pass # 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\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():\n suites = []\n \n suites.append( unittest.makeSuite(test_array_converter,'check_'))\n\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\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( )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "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( )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "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": "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_suite", "long_name": "test_suite( )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "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 }, { "name": "test", "long_name": "test( )", "filename": "test_standard_array_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 59, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 54, "complexity": 9, "token_count": 313, "diff_parsed": { "added": [ "def test_suite(level=1):", " if level > 0:", " suites.append( unittest.makeSuite(test_array_converter,'check_'))", "def test(level=10):", " all_tests = test_suite(level)" ], "deleted": [ "def test_suite():", "", " suites.append( unittest.makeSuite(test_array_converter,'check_'))", "def test():", " all_tests = test_suite()" ] } }, { "old_path": "weave/tests/test_string_spec.py", "new_path": "weave/tests/test_string_spec.py", "filename": "test_string_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -330,18 +330,18 @@ def check_return(self):\n c = dict_return.test(b)\n assert( c['hello'] == 5)\n \n-def test_suite():\n+def test_suite(level=1):\n suites = []\n- \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+ if level >= 5: \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 total_suite = unittest.TestSuite(suites)\n return total_suite\n \n-def test():\n- all_tests = test_suite()\n+def test(level=10):\n+ all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n", "added_lines": 8, "deleted_lines": 8, "source_code": "\"\"\"\ncheck_var_in -- tests whether a variable is passed in correctly\n and also if the passed in variable can be reassigned\ncheck_var_local -- tests wheter a variable is passed in , modified,\n and returned correctly in the local_dict dictionary\n argument\ncheck_return -- test whether a variable is passed in, modified, and\n then returned as a function return value correctly \n\"\"\"\nimport unittest\nimport time\n\nimport sys\nsys.path.append('..')\nimport ext_tools\n\nclass test_string_converter(unittest.TestCase): \n def check_type_match_string(self):\n s = ext_tools.string_converter()\n assert( s.type_match('string') )\n def check_type_match_int(self):\n s = ext_tools.string_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = ext_tools.string_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = ext_tools.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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::String(\"hello\");'\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('string_var_local')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::String(\"hello\");'\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import string_var_local\n b='bub'\n q={}\n string_var_local.test(b,q)\n assert(q['a'] == 'hello')\n def check_return(self):\n mod = ext_tools.ext_module('string_return')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a= Py::String(\"hello\");\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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 = ext_tools.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 = ext_tools.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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::List();'\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('list_var_local')\n a = []\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::List();\n a.append(Py::String(\"hello\"));\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import list_var_local\n a=[1,2]\n q={}\n list_var_local.test(a,q)\n assert(q['a'] == ['hello'])\n def check_return(self):\n mod = ext_tools.ext_module('list_return')\n a = [1]\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::List();\n a.append(Py::String(\"hello\"));\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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);b=1 # b to force availability of py_to_scalar\n var_specs = ext_tools.assign_variable_types(['a','b'],locals())\n code = \"\"\"\n Py::Int v = Py::Int();\n int vv, sum = 0; \n for(int i = 0; i < a.length(); 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 = Py::new_reference_to(Py::Int(sum));\n \"\"\"\n with_cxx = ext_tools.ext_function('with_cxx',var_specs,code)\n mod.add_function(with_cxx)\n code = \"\"\"\n int vv, sum = 0;\n PyObject *a_ptr = a.ptr(), *v; \n for(int i = 0; i < a.length(); i++)\n {\n v = PyList_GetItem(a_ptr,i);\n //didn't set error here -- just speed test\n vv = py_to_scalar(v,\"list item\");\n if (vv % 2)\n sum += vv;\n else\n sum -= vv; \n }\n return_val = Py::new_reference_to(Py::Int(sum));\n \"\"\"\n no_checking = ext_tools.ext_function('no_checking',var_specs,code)\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,b)\n t2 = time.time()\n print 'cxx:', t2 - t1\n t1 = time.time()\n sum2 = list_speed.no_checking(a,b)\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 = ext_tools.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 = ext_tools.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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::Tuple();'\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('tuple_var_local')\n a = (1,)\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Tuple(2);\n a[0] = Py::String(\"hello\");\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import tuple_var_local\n a=(1,2)\n q={}\n tuple_var_local.test(a,q)\n assert(q['a'] == ('hello',None))\n def check_return(self):\n mod = ext_tools.ext_module('tuple_return')\n a = (1,)\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Tuple(2);\n a[0] = Py::String(\"hello\");\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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 = ext_tools.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 = ext_tools.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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::Dict();' # This just checks to make sure the type is correct\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('dict_var_local')\n a = {'z':1}\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Dict();\n a[Py::String(\"hello\")] = Py::Int(5);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import dict_var_local\n a = {'z':2}\n q={}\n dict_var_local.test(a,q)\n assert(q['a']['hello'] == 5)\n def check_return(self):\n mod = ext_tools.ext_module('dict_return')\n a = {'z':1}\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Dict();\n a[Py::String(\"hello\")] = Py::Int(5);\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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 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 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": "\"\"\"\ncheck_var_in -- tests whether a variable is passed in correctly\n and also if the passed in variable can be reassigned\ncheck_var_local -- tests wheter a variable is passed in , modified,\n and returned correctly in the local_dict dictionary\n argument\ncheck_return -- test whether a variable is passed in, modified, and\n then returned as a function return value correctly \n\"\"\"\nimport unittest\nimport time\n\nimport sys\nsys.path.append('..')\nimport ext_tools\n\nclass test_string_converter(unittest.TestCase): \n def check_type_match_string(self):\n s = ext_tools.string_converter()\n assert( s.type_match('string') )\n def check_type_match_int(self):\n s = ext_tools.string_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = ext_tools.string_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = ext_tools.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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::String(\"hello\");'\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('string_var_local')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::String(\"hello\");'\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import string_var_local\n b='bub'\n q={}\n string_var_local.test(b,q)\n assert(q['a'] == 'hello')\n def check_return(self):\n mod = ext_tools.ext_module('string_return')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a= Py::String(\"hello\");\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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 = ext_tools.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 = ext_tools.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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::List();'\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('list_var_local')\n a = []\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::List();\n a.append(Py::String(\"hello\"));\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import list_var_local\n a=[1,2]\n q={}\n list_var_local.test(a,q)\n assert(q['a'] == ['hello'])\n def check_return(self):\n mod = ext_tools.ext_module('list_return')\n a = [1]\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::List();\n a.append(Py::String(\"hello\"));\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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);b=1 # b to force availability of py_to_scalar\n var_specs = ext_tools.assign_variable_types(['a','b'],locals())\n code = \"\"\"\n Py::Int v = Py::Int();\n int vv, sum = 0; \n for(int i = 0; i < a.length(); 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 = Py::new_reference_to(Py::Int(sum));\n \"\"\"\n with_cxx = ext_tools.ext_function('with_cxx',var_specs,code)\n mod.add_function(with_cxx)\n code = \"\"\"\n int vv, sum = 0;\n PyObject *a_ptr = a.ptr(), *v; \n for(int i = 0; i < a.length(); i++)\n {\n v = PyList_GetItem(a_ptr,i);\n //didn't set error here -- just speed test\n vv = py_to_scalar(v,\"list item\");\n if (vv % 2)\n sum += vv;\n else\n sum -= vv; \n }\n return_val = Py::new_reference_to(Py::Int(sum));\n \"\"\"\n no_checking = ext_tools.ext_function('no_checking',var_specs,code)\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,b)\n t2 = time.time()\n print 'cxx:', t2 - t1\n t1 = time.time()\n sum2 = list_speed.no_checking(a,b)\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 = ext_tools.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 = ext_tools.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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::Tuple();'\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('tuple_var_local')\n a = (1,)\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Tuple(2);\n a[0] = Py::String(\"hello\");\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import tuple_var_local\n a=(1,2)\n q={}\n tuple_var_local.test(a,q)\n assert(q['a'] == ('hello',None))\n def check_return(self):\n mod = ext_tools.ext_module('tuple_return')\n a = (1,)\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Tuple(2);\n a[0] = Py::String(\"hello\");\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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 = ext_tools.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 = ext_tools.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 var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::Dict();' # This just checks to make sure the type is correct\n test = ext_tools.ext_function('test',var_specs,code)\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_var_local(self):\n mod = ext_tools.ext_module('dict_var_local')\n a = {'z':1}\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Dict();\n a[Py::String(\"hello\")] = Py::Int(5);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import dict_var_local\n a = {'z':2}\n q={}\n dict_var_local.test(a,q)\n assert(q['a']['hello'] == 5)\n def check_return(self):\n mod = ext_tools.ext_module('dict_return')\n a = {'z':1}\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a=Py::Dict();\n a[Py::String(\"hello\")] = Py::Int(5);\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\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():\n suites = []\n \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 total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 18, "end_line": 20, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 21, "end_line": 23, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 24, "end_line": 26, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "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_var_in", "long_name": "check_var_in( self )", "filename": "test_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 98, "parameters": [ "self" ], "start_line": 30, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 13, "complexity": 1, "token_count": 82, "parameters": [ "self" ], "start_line": 52, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 15, "complexity": 1, "token_count": 75, "parameters": [ "self" ], "start_line": 65, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 82, "end_line": 86, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 87, "end_line": 89, "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_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 104, "parameters": [ "self" ], "start_line": 90, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 89, "parameters": [ "self" ], "start_line": 112, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 83, "parameters": [ "self" ], "start_line": 128, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_speed", "long_name": "check_speed( self )", "filename": "test_string_spec.py", "nloc": 58, "complexity": 4, "token_count": 201, "parameters": [ "self" ], "start_line": 145, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 1 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 205, "end_line": 209, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 210, "end_line": 212, "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_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 105, "parameters": [ "self" ], "start_line": 213, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 93, "parameters": [ "self" ], "start_line": 235, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 86, "parameters": [ "self" ], "start_line": 251, "end_line": 266, "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_string_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 270, "end_line": 274, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 275, "end_line": 277, "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_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 106, "parameters": [ "self" ], "start_line": 278, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 93, "parameters": [ "self" ], "start_line": 300, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 86, "parameters": [ "self" ], "start_line": 316, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_string_spec.py", "nloc": 9, "complexity": 2, "token_count": 78, "parameters": [ "level" ], "start_line": 333, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 343, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 21, "parameters": [ "self" ], "start_line": 18, "end_line": 20, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 21, "end_line": 23, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 24, "end_line": 26, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "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_var_in", "long_name": "check_var_in( self )", "filename": "test_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 98, "parameters": [ "self" ], "start_line": 30, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 13, "complexity": 1, "token_count": 82, "parameters": [ "self" ], "start_line": 52, "end_line": 64, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 15, "complexity": 1, "token_count": 75, "parameters": [ "self" ], "start_line": 65, "end_line": 79, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 82, "end_line": 86, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 87, "end_line": 89, "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_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 104, "parameters": [ "self" ], "start_line": 90, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 89, "parameters": [ "self" ], "start_line": 112, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 83, "parameters": [ "self" ], "start_line": 128, "end_line": 143, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_speed", "long_name": "check_speed( self )", "filename": "test_string_spec.py", "nloc": 58, "complexity": 4, "token_count": 201, "parameters": [ "self" ], "start_line": 145, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 58, "top_nesting_level": 1 }, { "name": "check_type_match_bad", "long_name": "check_type_match_bad( self )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 205, "end_line": 209, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [ "self" ], "start_line": 210, "end_line": 212, "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_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 105, "parameters": [ "self" ], "start_line": 213, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 93, "parameters": [ "self" ], "start_line": 235, "end_line": 250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 86, "parameters": [ "self" ], "start_line": 251, "end_line": 266, "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_string_spec.py", "nloc": 5, "complexity": 2, "token_count": 47, "parameters": [ "self" ], "start_line": 270, "end_line": 274, "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_string_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 275, "end_line": 277, "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_string_spec.py", "nloc": 21, "complexity": 3, "token_count": 106, "parameters": [ "self" ], "start_line": 278, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "check_var_local", "long_name": "check_var_local( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 93, "parameters": [ "self" ], "start_line": 300, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "check_return", "long_name": "check_return( self )", "filename": "test_string_spec.py", "nloc": 16, "complexity": 1, "token_count": 86, "parameters": [ "self" ], "start_line": 316, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 333, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 343, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_string_spec.py", "nloc": 9, "complexity": 2, "token_count": 78, "parameters": [ "level" ], "start_line": 333, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 333, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 343, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_string_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 343, "end_line": 347, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 336, "complexity": 40, "token_count": 1789, "diff_parsed": { "added": [ "def test_suite(level=1):", " if level >= 5:", " suites.append( unittest.makeSuite(test_string_converter,'check_'))", " suites.append( unittest.makeSuite(test_list_converter,'check_'))", " suites.append( unittest.makeSuite(test_tuple_converter,'check_'))", " suites.append( unittest.makeSuite(test_dict_converter,'check_'))", "def test(level=10):", " all_tests = test_suite(level)" ], "deleted": [ "def test_suite():", "", " #suites.append( unittest.makeSuite(test_string_converter,'check_'))", " suites.append( unittest.makeSuite(test_list_converter,'check_'))", " #suites.append( unittest.makeSuite(test_tuple_converter,'check_'))", " #suites.append( unittest.makeSuite(test_dict_converter,'check_'))", "def test():", " all_tests = test_suite()" ] } }, { "old_path": "weave/tests/test_wx_spec.py", "new_path": "weave/tests/test_wx_spec.py", "filename": "test_wx_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -93,15 +93,15 @@ def no_check_return(self):\n c = wx_return.test(b)\n assert( c == 'hello')\n \n-def test_suite():\n+def test_suite(level=1):\n suites = []\n- \n- suites.append( unittest.makeSuite(test_wx_converter,'check_'))\n+ if level >= 5:\n+ suites.append( unittest.makeSuite(test_wx_converter,'check_'))\n total_suite = unittest.TestSuite(suites)\n return total_suite\n \n-def test():\n- all_tests = test_suite()\n+def test(level=10):\n+ all_tests = test_suite(level)\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n", "added_lines": 5, "deleted_lines": 5, "source_code": "\"\"\"\ncheck_var_in -- tests whether a variable is passed in correctly\n and also if the passed in variable can be reassigned\ncheck_var_local -- tests wheter a variable is passed in , modified,\n and returned correctly in the local_dict dictionary\n argument\ncheck_return -- test whether a variable is passed in, modified, and\n then returned as a function return value correctly \n\"\"\"\nimport unittest\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport ext_tools\nimport wx_spec\nrestore_path()\n\nimport wxPython\nimport wxPython.wx\n\nclass test_wx_converter(unittest.TestCase): \n def check_type_match_string(self):\n s = wx_spec.wx_converter()\n assert(not s.type_match('string') )\n def check_type_match_int(self):\n s = wx_spec.wx_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = wx_spec.wx_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = wx_spec.wx_converter() \n assert(not s.type_match(5.+1j))\n def check_type_match_complex(self):\n s = wx_spec.wx_converter() \n assert(not s.type_match(5.+1j))\n def check_type_match_wxframe(self):\n s = wx_spec.wx_converter()\n f=wxPython.wx.wxFrame(wxPython.wx.NULL,-1,'bob') \n assert(s.type_match(f))\n \n def check_var_in(self):\n mod = ext_tools.ext_module('wx_var_in',compiler='msvc')\n a = wxPython.wx.wxFrame(wxPython.wx.NULL,-1,'bob') \n code = \"\"\"\n a->SetTitle(wxString(\"jim\"));\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'],locals(),globals())\n mod.add_function(test)\n mod.compile()\n import wx_var_in\n b=a\n wx_var_in.test(b)\n assert(b.GetTitle() == \"jim\")\n try:\n b = 1.\n wx_var_in.test(b)\n except TypeError:\n pass\n try:\n b = 1\n wx_var_in.test(b)\n except TypeError:\n pass\n \n def no_check_var_local(self):\n mod = ext_tools.ext_module('wx_var_local')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::String(\"hello\");'\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import wx_var_local\n b='bub'\n q={}\n wx_var_local.test(b,q)\n assert(q['a'] == 'hello')\n def no_check_return(self):\n mod = ext_tools.ext_module('wx_return')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a= Py::wx(\"hello\");\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import wx_return\n b='bub'\n c = wx_return.test(b)\n assert( c == 'hello')\n\ndef test_suite(level=1):\n suites = []\n if level >= 5:\n suites.append( unittest.makeSuite(test_wx_converter,'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": "\"\"\"\ncheck_var_in -- tests whether a variable is passed in correctly\n and also if the passed in variable can be reassigned\ncheck_var_local -- tests wheter a variable is passed in , modified,\n and returned correctly in the local_dict dictionary\n argument\ncheck_return -- test whether a variable is passed in, modified, and\n then returned as a function return value correctly \n\"\"\"\nimport unittest\n\nfrom scipy_distutils.misc_util import add_grandparent_to_path, restore_path\n\nadd_grandparent_to_path(__name__)\nimport ext_tools\nimport wx_spec\nrestore_path()\n\nimport wxPython\nimport wxPython.wx\n\nclass test_wx_converter(unittest.TestCase): \n def check_type_match_string(self):\n s = wx_spec.wx_converter()\n assert(not s.type_match('string') )\n def check_type_match_int(self):\n s = wx_spec.wx_converter() \n assert(not s.type_match(5))\n def check_type_match_float(self):\n s = wx_spec.wx_converter() \n assert(not s.type_match(5.))\n def check_type_match_complex(self):\n s = wx_spec.wx_converter() \n assert(not s.type_match(5.+1j))\n def check_type_match_complex(self):\n s = wx_spec.wx_converter() \n assert(not s.type_match(5.+1j))\n def check_type_match_wxframe(self):\n s = wx_spec.wx_converter()\n f=wxPython.wx.wxFrame(wxPython.wx.NULL,-1,'bob') \n assert(s.type_match(f))\n \n def check_var_in(self):\n mod = ext_tools.ext_module('wx_var_in',compiler='msvc')\n a = wxPython.wx.wxFrame(wxPython.wx.NULL,-1,'bob') \n code = \"\"\"\n a->SetTitle(wxString(\"jim\"));\n \"\"\"\n test = ext_tools.ext_function('test',code,['a'],locals(),globals())\n mod.add_function(test)\n mod.compile()\n import wx_var_in\n b=a\n wx_var_in.test(b)\n assert(b.GetTitle() == \"jim\")\n try:\n b = 1.\n wx_var_in.test(b)\n except TypeError:\n pass\n try:\n b = 1\n wx_var_in.test(b)\n except TypeError:\n pass\n \n def no_check_var_local(self):\n mod = ext_tools.ext_module('wx_var_local')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = 'a=Py::String(\"hello\");'\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import wx_var_local\n b='bub'\n q={}\n wx_var_local.test(b,q)\n assert(q['a'] == 'hello')\n def no_check_return(self):\n mod = ext_tools.ext_module('wx_return')\n a = 'string'\n var_specs = ext_tools.assign_variable_types(['a'],locals())\n code = \"\"\"\n a= Py::wx(\"hello\");\n return_val = Py::new_reference_to(a);\n \"\"\"\n test = ext_tools.ext_function('test',var_specs,code)\n mod.add_function(test)\n mod.compile()\n import wx_return\n b='bub'\n c = wx_return.test(b)\n assert( c == 'hello')\n\ndef test_suite():\n suites = []\n \n suites.append( unittest.makeSuite(test_wx_converter,'check_'))\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef test():\n all_tests = test_suite()\n runner = unittest.TextTestRunner()\n runner.run(all_tests)\n return runner\n\nif __name__ == \"__main__\":\n test()\n", "methods": [ { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "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_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 26, "end_line": 28, "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_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 29, "end_line": 31, "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_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "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_type_match_complex", "long_name": "check_type_match_complex( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 35, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_wxframe", "long_name": "check_type_match_wxframe( self )", "filename": "test_wx_spec.py", "nloc": 4, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 38, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_var_in", "long_name": "check_var_in( self )", "filename": "test_wx_spec.py", "nloc": 23, "complexity": 3, "token_count": 124, "parameters": [ "self" ], "start_line": 43, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "no_check_var_local", "long_name": "no_check_var_local( self )", "filename": "test_wx_spec.py", "nloc": 13, "complexity": 1, "token_count": 82, "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": "no_check_return", "long_name": "no_check_return( self )", "filename": "test_wx_spec.py", "nloc": 15, "complexity": 1, "token_count": 75, "parameters": [ "self" ], "start_line": 80, "end_line": 94, "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_wx_spec.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "level" ], "start_line": 96, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_wx_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 103, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "methods_before": [ { "name": "check_type_match_string", "long_name": "check_type_match_string( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "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_type_match_int", "long_name": "check_type_match_int( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 22, "parameters": [ "self" ], "start_line": 26, "end_line": 28, "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_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 23, "parameters": [ "self" ], "start_line": 29, "end_line": 31, "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_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "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_type_match_complex", "long_name": "check_type_match_complex( self )", "filename": "test_wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 25, "parameters": [ "self" ], "start_line": 35, "end_line": 37, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "check_type_match_wxframe", "long_name": "check_type_match_wxframe( self )", "filename": "test_wx_spec.py", "nloc": 4, "complexity": 1, "token_count": 40, "parameters": [ "self" ], "start_line": 38, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "check_var_in", "long_name": "check_var_in( self )", "filename": "test_wx_spec.py", "nloc": 23, "complexity": 3, "token_count": 124, "parameters": [ "self" ], "start_line": 43, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "no_check_var_local", "long_name": "no_check_var_local( self )", "filename": "test_wx_spec.py", "nloc": 13, "complexity": 1, "token_count": 82, "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": "no_check_return", "long_name": "no_check_return( self )", "filename": "test_wx_spec.py", "nloc": 15, "complexity": 1, "token_count": 75, "parameters": [ "self" ], "start_line": 80, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_wx_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 96, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_wx_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 103, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_suite", "long_name": "test_suite( level = 1 )", "filename": "test_wx_spec.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "level" ], "start_line": 96, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test_suite", "long_name": "test_suite( )", "filename": "test_wx_spec.py", "nloc": 5, "complexity": 1, "token_count": 31, "parameters": [], "start_line": 96, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( level = 10 )", "filename": "test_wx_spec.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [ "level" ], "start_line": 103, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "test", "long_name": "test( )", "filename": "test_wx_spec.py", "nloc": 5, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 103, "end_line": 107, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 } ], "nloc": 101, "complexity": 14, "token_count": 560, "diff_parsed": { "added": [ "def test_suite(level=1):", " if level >= 5:", " suites.append( unittest.makeSuite(test_wx_converter,'check_'))", "def test(level=10):", " all_tests = test_suite(level)" ], "deleted": [ "def test_suite():", "", " suites.append( unittest.makeSuite(test_wx_converter,'check_'))", "def test():", " all_tests = test_suite()" ] } }, { "old_path": "weave/wx_spec.py", "new_path": "weave/wx_spec.py", "filename": "wx_spec.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -76,11 +76,11 @@ def __cmp__(self,other):\n \"\"\"\n # this should only be enabled on machines with access to a display device\n # It'll cause problems otherwise.\n-def test():\n+def test(level=10):\n from scipy_test import module_test\n- module_test(__name__,__file__)\n+ module_test(__name__,__file__,level=level)\n \n-def test_suite():\n+def test_suite(level=1):\n from scipy_test import module_test_suite\n- return module_test_suite(__name__,__file__) \n+ return module_test_suite(__name__,__file__,level=level)\n \"\"\" \n\\ No newline at end of file\n", "added_lines": 4, "deleted_lines": 4, "source_code": "import wx_info\nimport base_info\nfrom base_spec import base_converter\nfrom types import *\nimport os\n\nwx_support_template = \\\n\"\"\"\nstatic %(wx_class)s* convert_to_%(wx_class)s(PyObject* py_obj,char* name)\n{\n %(wx_class)s *wx_ptr;\n \n // work on this error reporting...\n if (SWIG_GetPtrObj(py_obj,(void **) &wx_ptr,\"_%(wx_class)s_p\"))\n handle_conversion_error(py_obj,\"%(wx_class)s\", name);\n return wx_ptr;\n} \n\nstatic %(wx_class)s* py_to_%(wx_class)s(PyObject* py_obj,char* name)\n{\n %(wx_class)s *wx_ptr;\n \n // work on this error reporting...\n if (SWIG_GetPtrObj(py_obj,(void **) &wx_ptr,\"_%(wx_class)s_p\"))\n handle_bad_type(py_obj,\"%(wx_class)s\", name);\n return wx_ptr;\n} \n\"\"\" \n\nclass wx_converter(base_converter):\n _build_information = [wx_info.wx_info()]\n def __init__(self,class_name=None):\n self.type_name = 'unkown wx_object'\n if class_name:\n # customize support_code for whatever type I was handed.\n vals = {'wx_class': class_name}\n specialized_support = wx_support_template % vals\n custom = base_info.base_info()\n custom._support_code = [specialized_support]\n self._build_information = self._build_information + [custom]\n self.type_name = class_name\n\n def type_match(self,value):\n try:\n class_name = value.this.split('_')[-2]\n if class_name[:2] == 'wx':\n return 1\n except AttributeError:\n pass\n return 0\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 def declaration_code(self,inline=0):\n type = self.type_name\n name = self.name\n var_name = self.retrieve_py_variable(inline)\n template = '%(type)s *%(name)s = '\\\n 'convert_to_%(type)s(%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n \n def __repr__(self):\n msg = \"(%s:: name: %s)\" % (self.type_name,self.name)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__) or \\\n cmp(self.type_name,other.type_name)\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 import module_test\n module_test(__name__,__file__,level=level)\n\ndef test_suite(level=1):\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__,level=level)\n\"\"\" ", "source_code_before": "import wx_info\nimport base_info\nfrom base_spec import base_converter\nfrom types import *\nimport os\n\nwx_support_template = \\\n\"\"\"\nstatic %(wx_class)s* convert_to_%(wx_class)s(PyObject* py_obj,char* name)\n{\n %(wx_class)s *wx_ptr;\n \n // work on this error reporting...\n if (SWIG_GetPtrObj(py_obj,(void **) &wx_ptr,\"_%(wx_class)s_p\"))\n handle_conversion_error(py_obj,\"%(wx_class)s\", name);\n return wx_ptr;\n} \n\nstatic %(wx_class)s* py_to_%(wx_class)s(PyObject* py_obj,char* name)\n{\n %(wx_class)s *wx_ptr;\n \n // work on this error reporting...\n if (SWIG_GetPtrObj(py_obj,(void **) &wx_ptr,\"_%(wx_class)s_p\"))\n handle_bad_type(py_obj,\"%(wx_class)s\", name);\n return wx_ptr;\n} \n\"\"\" \n\nclass wx_converter(base_converter):\n _build_information = [wx_info.wx_info()]\n def __init__(self,class_name=None):\n self.type_name = 'unkown wx_object'\n if class_name:\n # customize support_code for whatever type I was handed.\n vals = {'wx_class': class_name}\n specialized_support = wx_support_template % vals\n custom = base_info.base_info()\n custom._support_code = [specialized_support]\n self._build_information = self._build_information + [custom]\n self.type_name = class_name\n\n def type_match(self,value):\n try:\n class_name = value.this.split('_')[-2]\n if class_name[:2] == 'wx':\n return 1\n except AttributeError:\n pass\n return 0\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 def declaration_code(self,inline=0):\n type = self.type_name\n name = self.name\n var_name = self.retrieve_py_variable(inline)\n template = '%(type)s *%(name)s = '\\\n 'convert_to_%(type)s(%(var_name)s,\"%(name)s\");\\n'\n code = template % locals()\n return code\n \n def __repr__(self):\n msg = \"(%s:: name: %s)\" % (self.type_name,self.name)\n return msg\n def __cmp__(self,other):\n #only works for equal\n return cmp(self.name,other.name) or \\\n cmp(self.__class__, other.__class__) or \\\n cmp(self.type_name,other.type_name)\n\n\"\"\"\n# this should only be enabled on machines with access to a display device\n# It'll cause problems otherwise.\ndef test():\n from scipy_test import module_test\n module_test(__name__,__file__)\n\ndef test_suite():\n from scipy_test import module_test_suite\n return module_test_suite(__name__,__file__) \n\"\"\" ", "methods": [ { "name": "__init__", "long_name": "__init__( self , class_name = None )", "filename": "wx_spec.py", "nloc": 9, "complexity": 2, "token_count": 59, "parameters": [ "self", "class_name" ], "start_line": 32, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "wx_spec.py", "nloc": 8, "complexity": 3, "token_count": 40, "parameters": [ "self", "value" ], "start_line": 43, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "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": 52, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , inline = 0 )", "filename": "wx_spec.py", "nloc": 8, "complexity": 1, "token_count": 41, "parameters": [ "self", "inline" ], "start_line": 58, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 67, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "wx_spec.py", "nloc": 4, "complexity": 3, "token_count": 42, "parameters": [ "self", "other" ], "start_line": 70, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 } ], "methods_before": [ { "name": "__init__", "long_name": "__init__( self , class_name = None )", "filename": "wx_spec.py", "nloc": 9, "complexity": 2, "token_count": 59, "parameters": [ "self", "class_name" ], "start_line": 32, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "type_match", "long_name": "type_match( self , value )", "filename": "wx_spec.py", "nloc": 8, "complexity": 3, "token_count": 40, "parameters": [ "self", "value" ], "start_line": 43, "end_line": 50, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "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": 52, "end_line": 57, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "declaration_code", "long_name": "declaration_code( self , inline = 0 )", "filename": "wx_spec.py", "nloc": 8, "complexity": 1, "token_count": 41, "parameters": [ "self", "inline" ], "start_line": 58, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "__repr__", "long_name": "__repr__( self )", "filename": "wx_spec.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 67, "end_line": 69, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__cmp__", "long_name": "__cmp__( self , other )", "filename": "wx_spec.py", "nloc": 4, "complexity": 3, "token_count": 42, "parameters": [ "self", "other" ], "start_line": 70, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 77, "complexity": 11, "token_count": 280, "diff_parsed": { "added": [ "def test(level=10):", " module_test(__name__,__file__,level=level)", "def test_suite(level=1):", " return module_test_suite(__name__,__file__,level=level)" ], "deleted": [ "def test():", " module_test(__name__,__file__)", "def test_suite():", " return module_test_suite(__name__,__file__)" ] } } ] } ]