[ { "hash": "9760c22f6dbe9789d5fed58f34d3d859c30ad9e3", "msg": "Fixed intel compiler warnings, using -72 for compiling F77 sources", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-06T08:40:29+00:00", "author_timezone": 0, "committer_date": "2004-03-06T08:40:29+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "d3f741153b13bcab2fd5d64bf4df179179aea719" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/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/intelfcompiler.py", "new_path": "scipy_distutils/intelfcompiler.py", "filename": "intelfcompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -20,8 +20,8 @@ class IntelFCompiler(FCompiler):\n executables = {\n 'version_cmd' : [fc_exe, \"-FI -V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':dummy_fortran_file()}],\n- 'compiler_f77' : [fc_exe,\"-FI\",\"-w90\",\"-w95\"],\n- 'compiler_fix' : [fc_exe,\"-FI\",\"-72\"],\n+ 'compiler_f77' : [fc_exe,\"-72\",\"-w90\",\"-w95\"],\n+ 'compiler_fix' : [fc_exe,\"-FI\"],\n 'compiler_f90' : [fc_exe],\n 'linker_so' : [fc_exe,\"-shared\"],\n 'archiver' : [\"ar\", \"-cr\"],\n", "added_lines": 2, "deleted_lines": 2, "source_code": "# http://developer.intel.com/software/products/compilers/flin/\n\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler, dummy_fortran_file\nfrom exec_command import find_executable\n\nclass IntelFCompiler(FCompiler):\n\n compiler_type = 'intel'\n version_pattern = r'Intel\\(R\\) Fortran Compiler for 32-bit '\\\n 'applications, Version (?P[^\\s*]*)'\n\n for fc_exe in map(find_executable,['ifort','ifc']):\n if os.path.isfile(fc_exe):\n break\n\n executables = {\n 'version_cmd' : [fc_exe, \"-FI -V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':dummy_fortran_file()}],\n 'compiler_f77' : [fc_exe,\"-72\",\"-w90\",\"-w95\"],\n 'compiler_fix' : [fc_exe,\"-FI\"],\n 'compiler_f90' : [fc_exe],\n 'linker_so' : [fc_exe,\"-shared\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\n pic_flags = ['-KPIC']\n module_dir_switch = '-module ' # Don't remove ending space!\n module_include_switch = '-I'\n\n def get_flags(self):\n opt = self.pic_flags + [\"-cm\"]\n return opt\n\n def get_flags_opt(self):\n return ['-O3','-unroll']\n\n def get_flags_arch(self):\n opt = []\n if cpu.has_fdiv_bug():\n opt.append('-fdiv_check')\n if cpu.has_f00f_bug():\n opt.append('-0f_check')\n if cpu.is_PentiumPro() or cpu.is_PentiumII():\n opt.extend(['-tpp6','-xi'])\n elif cpu.is_PentiumIII():\n opt.append('-tpp6')\n elif cpu.is_Pentium():\n opt.append('-tpp5')\n elif cpu.is_PentiumIV():\n opt.extend(['-tpp7','-xW'])\n if cpu.has_mmx():\n opt.append('-xM')\n return opt\n\n def get_flags_linker_so(self):\n opt = FCompiler.get_flags_linker_so(self)\n v = self.get_version()\n if v and v >= '8.0':\n opt.append('-nofor_main')\n return opt\n\nclass IntelItaniumFCompiler(IntelFCompiler):\n compiler_type = 'intele'\n version_pattern = r'Intel\\(R\\) Fortran 90 Compiler Itanium\\(TM\\) Compiler'\\\n ' for the Itanium\\(TM\\)-based applications,'\\\n ' Version (?P[^\\s*]*)'\n\n for fc_exe in map(find_executable,['efort','efc','ifort']):\n if os.path.isfile(fc_exe):\n break\n\n executables = {\n 'version_cmd' : [fc_exe, \"-FI -V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':dummy_fortran_file()}],\n 'compiler_f77' : [fc_exe,\"-FI\",\"-w90\",\"-w95\"],\n 'compiler_fix' : [fc_exe,\"-FI\"],\n 'compiler_f90' : [fc_exe],\n 'linker_so' : [fc_exe,\"-shared\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\nclass IntelVisualFCompiler(FCompiler):\n\n compiler_type = 'intelv'\n version_pattern = r'Intel\\(R\\) Fortran Compiler for 32-bit applications, '\\\n 'Version (?P[^\\s*]*)'\n\n ar_exe = 'lib.exe'\n fc_exe = 'ifl'\n if sys.platform=='win32':\n from distutils.msvccompiler import MSVCCompiler\n ar_exe = MSVCCompiler().lib\n\n executables = {\n 'version_cmd' : [fc_exe, \"-FI -V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':dummy_fortran_file()}],\n 'compiler_f77' : [fc_exe,\"-FI\",\"-w90\",\"-w95\"],\n 'compiler_fix' : [fc_exe,\"-FI\",\"-4L72\",\"-w\"],\n 'compiler_f90' : [fc_exe],\n 'linker_so' : [fc_exe,\"-shared\"],\n 'archiver' : [ar_exe, \"/verbose\", \"/OUT:\"],\n 'ranlib' : None\n }\n\n compile_switch = '/c '\n object_switch = '/Fo' #No space after /Fo!\n library_switch = '/OUT:' #No space after /OUT:!\n module_dir_switch = '/module:' #No space after /module:\n module_include_switch = '/I'\n\n def get_flags(self):\n opt = ['/nologo','/MD','/nbs','/Qlowercase','/us']\n return opt\n\n def get_flags_debug(self):\n return ['/4Yb','/d2']\n\n def get_flags_opt(self):\n return ['/O3','/Qip','/Qipo','/Qipo_obj']\n\n def get_flags_arch(self):\n opt = []\n if cpu.is_PentiumPro() or cpu.is_PentiumII():\n opt.extend(['/G6','/Qaxi'])\n elif cpu.is_PentiumIII():\n opt.extend(['/G6','/QaxK'])\n elif cpu.is_Pentium():\n opt.append('/G5')\n elif cpu.is_PentiumIV():\n opt.extend(['/G7','/QaxW'])\n if cpu.has_mmx():\n opt.append('/QaxM')\n return opt\n\nclass IntelItaniumVisualFCompiler(IntelVisualFCompiler):\n\n compiler_type = 'intelev'\n version_pattern = r'Intel\\(R\\) Fortran 90 Compiler Itanium\\(TM\\) Compiler'\\\n ' for the Itanium\\(TM\\)-based applications,'\\\n ' Version (?P[^\\s*]*)'\n\n fc_exe = 'efl' # XXX this is a wild guess\n ar_exe = IntelVisualFCompiler.ar_exe\n\n executables = {\n 'version_cmd' : [fc_exe, \"-FI -V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':dummy_fortran_file()}],\n 'compiler_f77' : [fc_exe,\"-FI\",\"-w90\",\"-w95\"],\n 'compiler_fix' : [fc_exe,\"-FI\",\"-4L72\",\"-w\"],\n 'compiler_f90' : [fc_exe],\n 'linker_so' : [fc_exe,\"-shared\"],\n 'archiver' : [ar_exe, \"/verbose\", \"/OUT:\"],\n 'ranlib' : None\n }\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='intel')\n compiler.customize()\n print compiler.get_version()\n", "source_code_before": "# http://developer.intel.com/software/products/compilers/flin/\n\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler, dummy_fortran_file\nfrom exec_command import find_executable\n\nclass IntelFCompiler(FCompiler):\n\n compiler_type = 'intel'\n version_pattern = r'Intel\\(R\\) Fortran Compiler for 32-bit '\\\n 'applications, Version (?P[^\\s*]*)'\n\n for fc_exe in map(find_executable,['ifort','ifc']):\n if os.path.isfile(fc_exe):\n break\n\n executables = {\n 'version_cmd' : [fc_exe, \"-FI -V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':dummy_fortran_file()}],\n 'compiler_f77' : [fc_exe,\"-FI\",\"-w90\",\"-w95\"],\n 'compiler_fix' : [fc_exe,\"-FI\",\"-72\"],\n 'compiler_f90' : [fc_exe],\n 'linker_so' : [fc_exe,\"-shared\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\n pic_flags = ['-KPIC']\n module_dir_switch = '-module ' # Don't remove ending space!\n module_include_switch = '-I'\n\n def get_flags(self):\n opt = self.pic_flags + [\"-cm\"]\n return opt\n\n def get_flags_opt(self):\n return ['-O3','-unroll']\n\n def get_flags_arch(self):\n opt = []\n if cpu.has_fdiv_bug():\n opt.append('-fdiv_check')\n if cpu.has_f00f_bug():\n opt.append('-0f_check')\n if cpu.is_PentiumPro() or cpu.is_PentiumII():\n opt.extend(['-tpp6','-xi'])\n elif cpu.is_PentiumIII():\n opt.append('-tpp6')\n elif cpu.is_Pentium():\n opt.append('-tpp5')\n elif cpu.is_PentiumIV():\n opt.extend(['-tpp7','-xW'])\n if cpu.has_mmx():\n opt.append('-xM')\n return opt\n\n def get_flags_linker_so(self):\n opt = FCompiler.get_flags_linker_so(self)\n v = self.get_version()\n if v and v >= '8.0':\n opt.append('-nofor_main')\n return opt\n\nclass IntelItaniumFCompiler(IntelFCompiler):\n compiler_type = 'intele'\n version_pattern = r'Intel\\(R\\) Fortran 90 Compiler Itanium\\(TM\\) Compiler'\\\n ' for the Itanium\\(TM\\)-based applications,'\\\n ' Version (?P[^\\s*]*)'\n\n for fc_exe in map(find_executable,['efort','efc','ifort']):\n if os.path.isfile(fc_exe):\n break\n\n executables = {\n 'version_cmd' : [fc_exe, \"-FI -V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':dummy_fortran_file()}],\n 'compiler_f77' : [fc_exe,\"-FI\",\"-w90\",\"-w95\"],\n 'compiler_fix' : [fc_exe,\"-FI\"],\n 'compiler_f90' : [fc_exe],\n 'linker_so' : [fc_exe,\"-shared\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\nclass IntelVisualFCompiler(FCompiler):\n\n compiler_type = 'intelv'\n version_pattern = r'Intel\\(R\\) Fortran Compiler for 32-bit applications, '\\\n 'Version (?P[^\\s*]*)'\n\n ar_exe = 'lib.exe'\n fc_exe = 'ifl'\n if sys.platform=='win32':\n from distutils.msvccompiler import MSVCCompiler\n ar_exe = MSVCCompiler().lib\n\n executables = {\n 'version_cmd' : [fc_exe, \"-FI -V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':dummy_fortran_file()}],\n 'compiler_f77' : [fc_exe,\"-FI\",\"-w90\",\"-w95\"],\n 'compiler_fix' : [fc_exe,\"-FI\",\"-4L72\",\"-w\"],\n 'compiler_f90' : [fc_exe],\n 'linker_so' : [fc_exe,\"-shared\"],\n 'archiver' : [ar_exe, \"/verbose\", \"/OUT:\"],\n 'ranlib' : None\n }\n\n compile_switch = '/c '\n object_switch = '/Fo' #No space after /Fo!\n library_switch = '/OUT:' #No space after /OUT:!\n module_dir_switch = '/module:' #No space after /module:\n module_include_switch = '/I'\n\n def get_flags(self):\n opt = ['/nologo','/MD','/nbs','/Qlowercase','/us']\n return opt\n\n def get_flags_debug(self):\n return ['/4Yb','/d2']\n\n def get_flags_opt(self):\n return ['/O3','/Qip','/Qipo','/Qipo_obj']\n\n def get_flags_arch(self):\n opt = []\n if cpu.is_PentiumPro() or cpu.is_PentiumII():\n opt.extend(['/G6','/Qaxi'])\n elif cpu.is_PentiumIII():\n opt.extend(['/G6','/QaxK'])\n elif cpu.is_Pentium():\n opt.append('/G5')\n elif cpu.is_PentiumIV():\n opt.extend(['/G7','/QaxW'])\n if cpu.has_mmx():\n opt.append('/QaxM')\n return opt\n\nclass IntelItaniumVisualFCompiler(IntelVisualFCompiler):\n\n compiler_type = 'intelev'\n version_pattern = r'Intel\\(R\\) Fortran 90 Compiler Itanium\\(TM\\) Compiler'\\\n ' for the Itanium\\(TM\\)-based applications,'\\\n ' Version (?P[^\\s*]*)'\n\n fc_exe = 'efl' # XXX this is a wild guess\n ar_exe = IntelVisualFCompiler.ar_exe\n\n executables = {\n 'version_cmd' : [fc_exe, \"-FI -V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':dummy_fortran_file()}],\n 'compiler_f77' : [fc_exe,\"-FI\",\"-w90\",\"-w95\"],\n 'compiler_fix' : [fc_exe,\"-FI\",\"-4L72\",\"-w\"],\n 'compiler_f90' : [fc_exe],\n 'linker_so' : [fc_exe,\"-shared\"],\n 'archiver' : [ar_exe, \"/verbose\", \"/OUT:\"],\n 'ranlib' : None\n }\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='intel')\n compiler.customize()\n print compiler.get_version()\n", "methods": [ { "name": "get_flags", "long_name": "get_flags( self )", "filename": "intelfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 16, "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": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "intelfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 39, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "intelfcompiler.py", "nloc": 17, "complexity": 9, "token_count": 116, "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": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "intelfcompiler.py", "nloc": 6, "complexity": 3, "token_count": 35, "parameters": [ "self" ], "start_line": 60, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "intelfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 117, "end_line": 119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "intelfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 121, "end_line": 122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "intelfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self" ], "start_line": 124, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "intelfcompiler.py", "nloc": 13, "complexity": 7, "token_count": 94, "parameters": [ "self" ], "start_line": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 } ], "methods_before": [ { "name": "get_flags", "long_name": "get_flags( self )", "filename": "intelfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 16, "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": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "intelfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 39, "end_line": 40, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "intelfcompiler.py", "nloc": 17, "complexity": 9, "token_count": 116, "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": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "intelfcompiler.py", "nloc": 6, "complexity": 3, "token_count": 35, "parameters": [ "self" ], "start_line": 60, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "intelfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 20, "parameters": [ "self" ], "start_line": 117, "end_line": 119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "intelfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 121, "end_line": 122, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "intelfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self" ], "start_line": 124, "end_line": 125, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "intelfcompiler.py", "nloc": 13, "complexity": 7, "token_count": 94, "parameters": [ "self" ], "start_line": 127, "end_line": 139, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 139, "complexity": 24, "token_count": 838, "diff_parsed": { "added": [ " 'compiler_f77' : [fc_exe,\"-72\",\"-w90\",\"-w95\"],", " 'compiler_fix' : [fc_exe,\"-FI\"]," ], "deleted": [ " 'compiler_f77' : [fc_exe,\"-FI\",\"-w90\",\"-w95\"],", " 'compiler_fix' : [fc_exe,\"-FI\",\"-72\"]," ] } } ] }, { "hash": "339ad8f76b648d545c7435d224bbf349ebfcf264", "msg": "Impl. better handling of getting suites from a python script", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-06T08:46:37+00:00", "author_timezone": 0, "committer_date": "2004-03-06T08:46:37+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "9760c22f6dbe9789d5fed58f34d3d859c30ad9e3" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 2, "insertions": 7, "lines": 9, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -158,7 +158,7 @@ class ScipyTest:\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n- def __init__(self, package):\n+ def __init__(self, package='__main__'):\n self.package = package\n \n def _module_str(self, module):\n@@ -229,7 +229,9 @@ def _get_module_tests(self,module,level):\n print ' ',\n output_exception()\n return []\n+ return self._get_suite_list(test_module, level, module.__name__)\n \n+ def _get_suite_list(self, test_module, level, module_name='__main__'):\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n@@ -248,7 +250,7 @@ def _get_module_tests(self,module,level):\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n- print ' Found',len(suite_list),'tests for',module.__name__\n+ print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n \n def _touch_ppimported(self, module):\n@@ -284,6 +286,9 @@ def test(self,level=1,verbosity=1):\n continue\n suites.extend(self._get_module_tests(module, level))\n \n+ if package_name == '__main__':\n+ suites.extend(self._get_suite_list(sys.modules[package_name], level))\n+\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n", "added_lines": 7, "deleted_lines": 2, "source_code": "\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n import scipy_base.fastumath as math\nexcept ImportError:\n pass\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.dirname(os.path.abspath(testfile))\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n if package_name == '__main__':\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog []'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\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\n__all__.append('harvest_modules')\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 d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\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\n__all__.append('harvest_packages')\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 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\n__all__.append('harvest_modules_and_packages')\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\n__all__.append('harvest_test_suites')\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 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 print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\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\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('assert_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\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 actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n try:\n sc_desired = desired/pow(10,math.floor(math.log10(abs(desired))))\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/pow(10,math.floor(math.log10(abs(actual))))\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\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 = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not equal'\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\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 = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\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'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import whrandom\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = whrandom.random()\n return results\n\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": "\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n import scipy_base.fastumath as math\nexcept ImportError:\n pass\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.dirname(os.path.abspath(testfile))\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module.__name__\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog []'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\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\n__all__.append('harvest_modules')\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 d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\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\n__all__.append('harvest_packages')\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 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\n__all__.append('harvest_modules_and_packages')\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\n__all__.append('harvest_test_suites')\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 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 print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\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\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('assert_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\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 actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n try:\n sc_desired = desired/pow(10,math.floor(math.log10(abs(desired))))\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/pow(10,math.floor(math.log10(abs(actual))))\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\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 = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not equal'\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\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 = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\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'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import whrandom\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = whrandom.random()\n return results\n\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": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 3, "token_count": 143, "parameters": [ "level" ], "start_line": 19, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( level = 1 )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 75, "parameters": [ "level" ], "start_line": 52, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 69, "end_line": 70, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 73, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 85, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 99, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 104, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 111, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 130, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 161, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 164, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 21, "complexity": 10, "token_count": 136, "parameters": [ "self", "clsobj", "level" ], "start_line": 170, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 36, "complexity": 8, "token_count": 331, "parameters": [ "self", "module", "level" ], "start_line": 192, "end_line": 232, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 141, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 234, "end_line": 254, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 256, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 171, "parameters": [ "self", "level", "verbosity" ], "start_line": 269, "end_line": 295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 297, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 323, "end_line": 329, "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": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 331, "end_line": 350, "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": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 353, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 392, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 429, "end_line": 435, "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": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 438, "end_line": 473, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 476, "end_line": 503, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 506, "end_line": 528, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 538, "end_line": 552, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 555, "end_line": 569, "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": "testing.py", "nloc": 22, "complexity": 7, "token_count": 195, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 572, "end_line": 599, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 603, "end_line": 622, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 23, "complexity": 5, "token_count": 226, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 625, "end_line": 647, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 650, "end_line": 669, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 672, "end_line": 681, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 683, "end_line": 693, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 3, "token_count": 143, "parameters": [ "level" ], "start_line": 19, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( level = 1 )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 75, "parameters": [ "level" ], "start_line": 52, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 69, "end_line": 70, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 73, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 85, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 99, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 104, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 111, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 130, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "package" ], "start_line": 161, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 164, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 21, "complexity": 10, "token_count": 136, "parameters": [ "self", "clsobj", "level" ], "start_line": 170, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 54, "complexity": 14, "token_count": 448, "parameters": [ "self", "module", "level" ], "start_line": 192, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 61, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 254, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 18, "complexity": 6, "token_count": 148, "parameters": [ "self", "level", "verbosity" ], "start_line": 267, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 292, "end_line": 314, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 318, "end_line": 324, "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": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 326, "end_line": 345, "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": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 348, "end_line": 384, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 387, "end_line": 421, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 424, "end_line": 430, "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": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 433, "end_line": 468, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 471, "end_line": 498, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 501, "end_line": 523, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 533, "end_line": 547, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 550, "end_line": 564, "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": "testing.py", "nloc": 22, "complexity": 7, "token_count": 195, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 567, "end_line": 594, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 598, "end_line": 617, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 23, "complexity": 5, "token_count": 226, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 620, "end_line": 642, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 645, "end_line": 664, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 667, "end_line": 676, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 678, "end_line": 688, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "__init__", "long_name": "__init__( self , package )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self", "package" ], "start_line": 161, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 36, "complexity": 8, "token_count": 331, "parameters": [ "self", "module", "level" ], "start_line": 192, "end_line": 232, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 141, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 234, "end_line": 254, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 161, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 171, "parameters": [ "self", "level", "verbosity" ], "start_line": 269, "end_line": 295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 } ], "nloc": 496, "complexity": 123, "token_count": 3655, "diff_parsed": { "added": [ " def __init__(self, package='__main__'):", " return self._get_suite_list(test_module, level, module.__name__)", " def _get_suite_list(self, test_module, level, module_name='__main__'):", " print ' Found',len(suite_list),'tests for',module_name", " if package_name == '__main__':", " suites.extend(self._get_suite_list(sys.modules[package_name], level))", "" ], "deleted": [ " def __init__(self, package):", " print ' Found',len(suite_list),'tests for',module.__name__" ] } } ] }, { "hash": "dbd133aa98ff9b3b100ac6afb9e870b500b62102", "msg": "Made debugging messages optional.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-06T14:07:52+00:00", "author_timezone": 0, "committer_date": "2004-03-06T14:07:52+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "339ad8f76b648d545c7435d224bbf349ebfcf264" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 1, "insertions": 8, "lines": 9, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -15,6 +15,8 @@\n except ImportError:\n pass\n \n+DEBUG=0\n+\n __all__.append('set_package_path')\n def set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n@@ -45,7 +47,8 @@ def set_package_path(level=1):\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n- print 'Inserting %r to sys.path' % (d1)\n+ if DEBUG:\n+ print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n \n __all__.append('set_local_path')\n@@ -63,10 +66,14 @@ def set_local_path(level=1):\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.dirname(os.path.abspath(testfile))\n+ if DEBUG:\n+ print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n \n __all__.append('restore_path')\n def restore_path():\n+ if DEBUG:\n+ print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n \n if sys.platform[:5]=='linux':\n", "added_lines": 8, "deleted_lines": 1, "source_code": "\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n import scipy_base.fastumath as math\nexcept ImportError:\n pass\n\nDEBUG=0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.dirname(os.path.abspath(testfile))\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n if package_name == '__main__':\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog []'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\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\n__all__.append('harvest_modules')\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 d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\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\n__all__.append('harvest_packages')\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 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\n__all__.append('harvest_modules_and_packages')\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\n__all__.append('harvest_test_suites')\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 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 print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\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\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('assert_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\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 actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n try:\n sc_desired = desired/pow(10,math.floor(math.log10(abs(desired))))\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/pow(10,math.floor(math.log10(abs(actual))))\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\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 = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not equal'\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\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 = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\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'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import whrandom\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = whrandom.random()\n return results\n\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": "\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n import scipy_base.fastumath as math\nexcept ImportError:\n pass\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.dirname(os.path.abspath(testfile))\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n if package_name == '__main__':\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog []'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\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\n__all__.append('harvest_modules')\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 d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\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\n__all__.append('harvest_packages')\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 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\n__all__.append('harvest_modules_and_packages')\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\n__all__.append('harvest_test_suites')\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 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 print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\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\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('assert_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\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 actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n try:\n sc_desired = desired/pow(10,math.floor(math.log10(abs(desired))))\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/pow(10,math.floor(math.log10(abs(actual))))\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\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 = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not equal'\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\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 = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\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'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import whrandom\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = whrandom.random()\n return results\n\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": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 21, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 84, "parameters": [ "level" ], "start_line": 55, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 74, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 80, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 92, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 106, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 111, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 118, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 137, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 168, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 171, "end_line": 175, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 21, "complexity": 10, "token_count": 136, "parameters": [ "self", "clsobj", "level" ], "start_line": 177, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 36, "complexity": 8, "token_count": 331, "parameters": [ "self", "module", "level" ], "start_line": 199, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 141, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 241, "end_line": 261, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 263, "end_line": 274, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 171, "parameters": [ "self", "level", "verbosity" ], "start_line": 276, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 304, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 330, "end_line": 336, "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": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 338, "end_line": 357, "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": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 360, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 399, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 436, "end_line": 442, "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": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 445, "end_line": 480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 483, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 513, "end_line": 535, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 545, "end_line": 559, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 562, "end_line": 576, "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": "testing.py", "nloc": 22, "complexity": 7, "token_count": 195, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 579, "end_line": 606, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 610, "end_line": 629, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 23, "complexity": 5, "token_count": 226, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 632, "end_line": 654, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 657, "end_line": 676, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 679, "end_line": 688, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 690, "end_line": 700, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 14, "complexity": 3, "token_count": 143, "parameters": [ "level" ], "start_line": 19, "end_line": 49, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( level = 1 )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 75, "parameters": [ "level" ], "start_line": 52, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [], "start_line": 69, "end_line": 70, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 73, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 85, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 99, "end_line": 102, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 104, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 111, "end_line": 126, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 130, "end_line": 137, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 161, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 164, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 21, "complexity": 10, "token_count": 136, "parameters": [ "self", "clsobj", "level" ], "start_line": 170, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 36, "complexity": 8, "token_count": 331, "parameters": [ "self", "module", "level" ], "start_line": 192, "end_line": 232, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 141, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 234, "end_line": 254, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 256, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 171, "parameters": [ "self", "level", "verbosity" ], "start_line": 269, "end_line": 295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 297, "end_line": 319, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 323, "end_line": 329, "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": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 331, "end_line": 350, "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": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 353, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 392, "end_line": 426, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 429, "end_line": 435, "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": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 438, "end_line": 473, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 476, "end_line": 503, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 506, "end_line": 528, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 538, "end_line": 552, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 555, "end_line": 569, "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": "testing.py", "nloc": 22, "complexity": 7, "token_count": 195, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 572, "end_line": 599, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 603, "end_line": 622, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 23, "complexity": 5, "token_count": 226, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 625, "end_line": 647, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 650, "end_line": 669, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 672, "end_line": 681, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 683, "end_line": 693, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "set_local_path", "long_name": "set_local_path( level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 84, "parameters": [ "level" ], "start_line": 55, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 74, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 21, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 } ], "nloc": 502, "complexity": 126, "token_count": 3684, "diff_parsed": { "added": [ "DEBUG=0", "", " if DEBUG:", " print 'Inserting %r to sys.path' % (d1)", " if DEBUG:", " print 'Inserting %r to sys.path' % (local_path)", " if DEBUG:", " print 'Removing %r from sys.path' % (sys.path[0])" ], "deleted": [ " print 'Inserting %r to sys.path' % (d1)" ] } } ] }, { "hash": "7f73fd1245115768196a07c9676b11eb3806489e", "msg": "Fixed several issues with msvc support.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-07T07:49:37+00:00", "author_timezone": 0, "committer_date": "2004-03-07T07:49:37+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "dbd133aa98ff9b3b100ac6afb9e870b500b62102" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 4, "insertions": 6, "lines": 10, "files": 2, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/ccompiler.py", "new_path": "scipy_distutils/ccompiler.py", "filename": "ccompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -156,7 +156,7 @@ def CCompiler_customize(self, dist, need_cxx=0):\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n- if self.compiler[0].find('gcc')>=0:\n+ if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\nimport re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import compiler_to_string\nfrom distutils.spawn import _nt_quote_args \n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if type(display) is type([]): display = ' '.join(display)\n log.info(display)\n if type(cmd) is type([]) and os.name == 'nt':\n cmd = _nt_quote_args(cmd)\n s,o = exec_command(cmd)\n if os.name != 'posix': print len(cmd), s, o\n if s:\n if type(cmd) is type([]):\n cmd = ' '.join(cmd)\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n \n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n \n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n print '*'*80\n print self.__class__\n print compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n if not (hasattr(self,'version_cmd') and\n hasattr(self,'version_pattern')):\n log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n % (self.__class__))\n return\n\n cmd = ' '.join(self.version_cmd)\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n m = re.match(self.version_pattern,output)\n if m:\n version = m.group('version')\n assert version,`version`\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if os.environ.get('OSTYPE','')=='msys' or \\\n os.environ.get('MSYSTEM','')=='MINGW32':\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from scipy_distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n\n module_name = \"scipy_distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n", "source_code_before": "\nimport re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import compiler_to_string\nfrom distutils.spawn import _nt_quote_args \n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if type(display) is type([]): display = ' '.join(display)\n log.info(display)\n if type(cmd) is type([]) and os.name == 'nt':\n cmd = _nt_quote_args(cmd)\n s,o = exec_command(cmd)\n if os.name != 'posix': print len(cmd), s, o\n if s:\n if type(cmd) is type([]):\n cmd = ' '.join(cmd)\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n \n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n \n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n print '*'*80\n print self.__class__\n print compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n if self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n if not (hasattr(self,'version_cmd') and\n hasattr(self,'version_pattern')):\n log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n % (self.__class__))\n return\n\n cmd = ' '.join(self.version_cmd)\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n m = re.match(self.version_pattern,output)\n if m:\n version = m.group('version')\n assert version,`version`\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if os.environ.get('OSTYPE','')=='msys' or \\\n os.environ.get('MSYSTEM','')=='MINGW32':\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from scipy_distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n\n module_name = \"scipy_distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n", "methods": [ { "name": "CCompiler_spawn", "long_name": "CCompiler_spawn( self , cmd , display = None )", "filename": "ccompiler.py", "nloc": 14, "complexity": 8, "token_count": 127, "parameters": [ "self", "cmd", "display" ], "start_line": 18, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "CCompiler_object_filenames", "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", "filename": "ccompiler.py", "nloc": 21, "complexity": 6, "token_count": 185, "parameters": [ "self", "source_filenames", "strip_dir", "output_dir" ], "start_line": 34, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "CCompiler_compile", "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "ccompiler.py", "nloc": 39, "complexity": 10, "token_count": 323, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 61, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 0 }, { "name": "CCompiler_customize_cmd", "long_name": "CCompiler_customize_cmd( self , cmd )", "filename": "ccompiler.py", "nloc": 20, "complexity": 10, "token_count": 200, "parameters": [ "self", "cmd" ], "start_line": 108, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_show_customization", "long_name": "CCompiler_show_customization( self )", "filename": "ccompiler.py", "nloc": 15, "complexity": 5, "token_count": 81, "parameters": [ "self" ], "start_line": 134, "end_line": 148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 15, "complexity": 6, "token_count": 144, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 154, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_get_version", "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", "filename": "ccompiler.py", "nloc": 19, "complexity": 7, "token_count": 135, "parameters": [ "self", "force", "ok_status" ], "start_line": 174, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "new_compiler", "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "ccompiler.py", "nloc": 38, "complexity": 8, "token_count": 184, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 213, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 } ], "methods_before": [ { "name": "CCompiler_spawn", "long_name": "CCompiler_spawn( self , cmd , display = None )", "filename": "ccompiler.py", "nloc": 14, "complexity": 8, "token_count": 127, "parameters": [ "self", "cmd", "display" ], "start_line": 18, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "CCompiler_object_filenames", "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", "filename": "ccompiler.py", "nloc": 21, "complexity": 6, "token_count": 185, "parameters": [ "self", "source_filenames", "strip_dir", "output_dir" ], "start_line": 34, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "CCompiler_compile", "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "ccompiler.py", "nloc": 39, "complexity": 10, "token_count": 323, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 61, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 0 }, { "name": "CCompiler_customize_cmd", "long_name": "CCompiler_customize_cmd( self , cmd )", "filename": "ccompiler.py", "nloc": 20, "complexity": 10, "token_count": 200, "parameters": [ "self", "cmd" ], "start_line": 108, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_show_customization", "long_name": "CCompiler_show_customization( self )", "filename": "ccompiler.py", "nloc": 15, "complexity": 5, "token_count": 81, "parameters": [ "self" ], "start_line": 134, "end_line": 148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 15, "complexity": 5, "token_count": 137, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 154, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_get_version", "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", "filename": "ccompiler.py", "nloc": 19, "complexity": 7, "token_count": 135, "parameters": [ "self", "force", "ok_status" ], "start_line": 174, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "new_compiler", "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "ccompiler.py", "nloc": 38, "complexity": 8, "token_count": 184, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 213, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 15, "complexity": 6, "token_count": 144, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 154, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "nloc": 216, "complexity": 60, "token_count": 1615, "diff_parsed": { "added": [ " if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:" ], "deleted": [ " if self.compiler[0].find('gcc')>=0:" ] } }, { "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": "@@ -260,10 +260,12 @@ def build_extension(self, ext):\n use_fortran_linker = 1\n break\n \n- # Always use system linker on win32\n- if sys.platform == 'win32':\n+ # Always use system linker when using MSVC compiler.\n+ if self.compiler.compiler_type=='msvc' and use_fortran_linker:\n+ c_libraries.extend(self.fcompiler.libraries)\n+ c_library_dirs.extend(self.fcompiler.library_dirs)\n use_fortran_linker = 0\n- \n+\n if use_fortran_linker:\n if cxx_sources:\n # XXX: Which linker should be used, Fortran or C++?\n", "added_lines": 5, "deleted_lines": 3, "source_code": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nfrom glob import glob\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\nfrom scipy_distutils import misc_util, log\nfrom scipy_distutils.misc_util import filter_sources, has_f_sources, \\\n has_cxx_sources\nfrom distutils.errors import DistutilsFileError\n\n\nclass build_ext (old_build_ext):\n\n description = \"build C/C++/F extensions (compile/link to build directory)\"\n\n user_options = old_build_ext.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_ext.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_ext.finalize_options(self)\n self.set_undefined_options('config_fc',\n ('fcompiler', 'fcompiler'))\n return\n\n def run(self):\n if not self.extensions:\n return\n\n # Make sure that extension sources are complete.\n for ext in self.extensions:\n if not misc_util.all_strings(ext.sources):\n raise TypeError,'Extension \"%s\" sources contains unresolved'\\\n ' items (call build_src before build_ext).' % (ext.name)\n\n if self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n self.library_dirs.append(build_clib.build_clib)\n else:\n build_clib = None\n\n # Not including C libraries to the list of\n # extension libraries automatically to prevent\n # bogus linking commands. Extensions must\n # explicitly specify the C libraries that they use.\n\n # Determine if Fortran compiler is needed.\n if build_clib and build_clib.fcompiler is not None:\n need_f_compiler = 1\n else:\n need_f_compiler = 0\n for ext in self.extensions:\n if has_f_sources(ext.sources):\n need_f_compiler = 1\n break\n if getattr(ext,'language','c') in ['f77','f90']:\n need_f_compiler = 1\n break\n\n # Determine if C++ compiler is needed.\n need_cxx_compiler = 0\n for ext in self.extensions:\n if has_cxx_sources(ext.sources):\n need_cxx_compiler = 1\n break\n if getattr(ext,'language','c')=='c++':\n need_cxx_compiler = 1\n break\n\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 self.compiler.customize(self.distribution,need_cxx=need_cxx_compiler)\n self.compiler.customize_cmd(self)\n self.compiler.show_customization()\n \n # Initialize Fortran/C++ compilers if needed.\n if need_f_compiler:\n from scipy_distutils.fcompiler import new_fcompiler\n self.fcompiler = new_fcompiler(compiler=self.fcompiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.fcompiler.customize(self.distribution)\n self.fcompiler.customize_cmd(self)\n self.fcompiler.show_customization()\n\n # Build extensions\n self.build_extensions()\n return\n\n def swig_sources(self, sources):\n # Do nothing. Swig sources have beed handled in build_src command.\n return sources\n\n def build_extension(self, ext):\n sources = ext.sources\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'ext_modules' option (extension '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % ext.name\n sources = list(sources)\n\n fullname = self.get_ext_fullname(ext.name)\n if self.inplace:\n modpath = string.split(fullname, '.')\n package = string.join(modpath[0:-1], '.')\n base = modpath[-1]\n\n build_py = self.get_finalized_command('build_py')\n package_dir = build_py.get_package_dir(package)\n ext_filename = os.path.join(package_dir,\n self.get_ext_filename(base))\n else:\n ext_filename = os.path.join(self.build_lib,\n self.get_ext_filename(fullname))\n depends = sources + ext.depends\n\n if not (self.force or newer_group(depends, ext_filename, 'newer')):\n log.debug(\"skipping '%s' extension (up-to-date)\", ext.name)\n return\n else:\n log.info(\"building '%s' extension\", ext.name)\n\n extra_args = ext.extra_compile_args or []\n macros = ext.define_macros[:]\n for undef in ext.undef_macros:\n macros.append((undef,))\n\n c_sources, cxx_sources, f_sources, fmodule_sources = \\\n filter_sources(ext.sources)\n\n if sys.version[:3]>='2.3':\n kws = {'depends':ext.depends}\n else:\n kws = {}\n\n c_objects = []\n if c_sources:\n log.info(\"compling C sources\")\n c_objects = self.compiler.compile(c_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=ext.include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n if cxx_sources:\n log.info(\"compling C++ sources\")\n\n old_compiler = self.compiler.compiler_so[0]\n self.compiler.compiler_so[0] = self.compiler.compiler_cxx[0]\n\n c_objects += self.compiler.compile(cxx_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=ext.include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n self.compiler.compiler_so[0] = old_compiler\n\n check_for_f90_modules = not not fmodule_sources\n\n if f_sources or fmodule_sources:\n extra_postargs = []\n include_dirs = ext.include_dirs[:]\n module_dirs = ext.module_dirs[:]\n\n if check_for_f90_modules:\n module_build_dir = os.path.join(\\\n self.build_temp,os.path.dirname(\\\n self.get_ext_filename(fullname)))\n\n self.mkpath(module_build_dir)\n if self.fcompiler.module_dir_switch is None:\n existing_modules = glob('*.mod')\n extra_postargs += self.fcompiler.module_options(\\\n module_dirs,module_build_dir)\n\n f_objects = []\n if fmodule_sources:\n log.info(\"compling Fortran 90 module sources\")\n f_objects = self.fcompiler.compile(fmodule_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n\n if check_for_f90_modules \\\n and self.fcompiler.module_dir_switch is None:\n for f in glob('*.mod'):\n if f in existing_modules:\n continue\n try:\n self.move_file(f, module_build_dir)\n except DistutilsFileError: # already exists in destination\n os.remove(f)\n \n if f_sources:\n log.info(\"compling Fortran sources\")\n f_objects += self.fcompiler.compile(f_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n else:\n f_objects = []\n\n objects = c_objects + f_objects\n\n if ext.extra_objects:\n objects.extend(ext.extra_objects)\n extra_args = ext.extra_link_args or []\n\n try:\n old_linker_so_0 = self.compiler.linker_so[0]\n except:\n pass\n \n use_fortran_linker = getattr(ext,'language','c') in ['f77','f90']\n c_libraries = []\n c_library_dirs = []\n if use_fortran_linker or f_sources:\n use_fortran_linker = 1\n elif self.distribution.has_c_libraries(): \n build_clib = self.get_finalized_command('build_clib')\n f_libs = []\n for (lib_name, build_info) in build_clib.libraries:\n if has_f_sources(build_info.get('sources',[])):\n f_libs.append(lib_name)\n if lib_name in ext.libraries:\n # XXX: how to determine if c_libraries contain\n # fortran compiled sources?\n c_libraries.extend(build_info.get('libraries',[]))\n c_library_dirs.extend(build_info.get('library_dirs',[]))\n for l in ext.libraries:\n if l in f_libs:\n use_fortran_linker = 1\n break\n\n # Always use system linker when using MSVC compiler.\n if self.compiler.compiler_type=='msvc' and use_fortran_linker:\n c_libraries.extend(self.fcompiler.libraries)\n c_library_dirs.extend(self.fcompiler.library_dirs)\n use_fortran_linker = 0\n\n if use_fortran_linker:\n if cxx_sources:\n # XXX: Which linker should be used, Fortran or C++?\n log.warn('mixing Fortran and C++ is untested')\n link = self.fcompiler.link_shared_object\n language = ext.language or self.fcompiler.detect_language(f_sources)\n else:\n link = self.compiler.link_shared_object\n if sys.version[:3]>='2.3':\n language = ext.language or self.compiler.detect_language(sources)\n else:\n language = ext.language\n if cxx_sources:\n self.compiler.linker_so[0] = self.compiler.compiler_cxx[0]\n\n if sys.version[:3]>='2.3':\n kws = {'target_lang':language}\n else:\n kws = {}\n\n link(objects, ext_filename,\n libraries=self.get_libraries(ext) + c_libraries,\n library_dirs=ext.library_dirs + c_library_dirs,\n runtime_library_dirs=ext.runtime_library_dirs,\n extra_postargs=extra_args,\n export_symbols=self.get_export_symbols(ext),\n debug=self.debug,\n build_temp=self.build_temp,**kws)\n\n try:\n self.compiler.linker_so[0] = old_linker_so_0\n except:\n pass\n\n return\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n def visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn']:\n names[:] = []\n return\n for name in names:\n fullname = os.path.join(dirname,name)\n if os.path.isfile(fullname):\n filenames.append(fullname)\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n sources = filter(lambda s:type(s) is StringType,ext.sources)\n filenames.extend(sources)\n filenames.extend(get_headers(get_directories(sources)))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return 0\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n", "source_code_before": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os\nimport string\nimport sys\nfrom glob import glob\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\nfrom scipy_distutils import misc_util, log\nfrom scipy_distutils.misc_util import filter_sources, has_f_sources, \\\n has_cxx_sources\nfrom distutils.errors import DistutilsFileError\n\n\nclass build_ext (old_build_ext):\n\n description = \"build C/C++/F extensions (compile/link to build directory)\"\n\n user_options = old_build_ext.user_options + [\n ('fcompiler=', None,\n \"specify the Fortran compiler type\"),\n ]\n\n def initialize_options(self):\n old_build_ext.initialize_options(self)\n self.fcompiler = None\n return\n\n def finalize_options(self):\n old_build_ext.finalize_options(self)\n self.set_undefined_options('config_fc',\n ('fcompiler', 'fcompiler'))\n return\n\n def run(self):\n if not self.extensions:\n return\n\n # Make sure that extension sources are complete.\n for ext in self.extensions:\n if not misc_util.all_strings(ext.sources):\n raise TypeError,'Extension \"%s\" sources contains unresolved'\\\n ' items (call build_src before build_ext).' % (ext.name)\n\n if self.distribution.has_c_libraries():\n build_clib = self.get_finalized_command('build_clib')\n self.library_dirs.append(build_clib.build_clib)\n else:\n build_clib = None\n\n # Not including C libraries to the list of\n # extension libraries automatically to prevent\n # bogus linking commands. Extensions must\n # explicitly specify the C libraries that they use.\n\n # Determine if Fortran compiler is needed.\n if build_clib and build_clib.fcompiler is not None:\n need_f_compiler = 1\n else:\n need_f_compiler = 0\n for ext in self.extensions:\n if has_f_sources(ext.sources):\n need_f_compiler = 1\n break\n if getattr(ext,'language','c') in ['f77','f90']:\n need_f_compiler = 1\n break\n\n # Determine if C++ compiler is needed.\n need_cxx_compiler = 0\n for ext in self.extensions:\n if has_cxx_sources(ext.sources):\n need_cxx_compiler = 1\n break\n if getattr(ext,'language','c')=='c++':\n need_cxx_compiler = 1\n break\n\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 self.compiler.customize(self.distribution,need_cxx=need_cxx_compiler)\n self.compiler.customize_cmd(self)\n self.compiler.show_customization()\n \n # Initialize Fortran/C++ compilers if needed.\n if need_f_compiler:\n from scipy_distutils.fcompiler import new_fcompiler\n self.fcompiler = new_fcompiler(compiler=self.fcompiler,\n verbose=self.verbose,\n dry_run=self.dry_run,\n force=self.force)\n self.fcompiler.customize(self.distribution)\n self.fcompiler.customize_cmd(self)\n self.fcompiler.show_customization()\n\n # Build extensions\n self.build_extensions()\n return\n\n def swig_sources(self, sources):\n # Do nothing. Swig sources have beed handled in build_src command.\n return sources\n\n def build_extension(self, ext):\n sources = ext.sources\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'ext_modules' option (extension '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % ext.name\n sources = list(sources)\n\n fullname = self.get_ext_fullname(ext.name)\n if self.inplace:\n modpath = string.split(fullname, '.')\n package = string.join(modpath[0:-1], '.')\n base = modpath[-1]\n\n build_py = self.get_finalized_command('build_py')\n package_dir = build_py.get_package_dir(package)\n ext_filename = os.path.join(package_dir,\n self.get_ext_filename(base))\n else:\n ext_filename = os.path.join(self.build_lib,\n self.get_ext_filename(fullname))\n depends = sources + ext.depends\n\n if not (self.force or newer_group(depends, ext_filename, 'newer')):\n log.debug(\"skipping '%s' extension (up-to-date)\", ext.name)\n return\n else:\n log.info(\"building '%s' extension\", ext.name)\n\n extra_args = ext.extra_compile_args or []\n macros = ext.define_macros[:]\n for undef in ext.undef_macros:\n macros.append((undef,))\n\n c_sources, cxx_sources, f_sources, fmodule_sources = \\\n filter_sources(ext.sources)\n\n if sys.version[:3]>='2.3':\n kws = {'depends':ext.depends}\n else:\n kws = {}\n\n c_objects = []\n if c_sources:\n log.info(\"compling C sources\")\n c_objects = self.compiler.compile(c_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=ext.include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n if cxx_sources:\n log.info(\"compling C++ sources\")\n\n old_compiler = self.compiler.compiler_so[0]\n self.compiler.compiler_so[0] = self.compiler.compiler_cxx[0]\n\n c_objects += self.compiler.compile(cxx_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=ext.include_dirs,\n debug=self.debug,\n extra_postargs=extra_args,\n **kws)\n self.compiler.compiler_so[0] = old_compiler\n\n check_for_f90_modules = not not fmodule_sources\n\n if f_sources or fmodule_sources:\n extra_postargs = []\n include_dirs = ext.include_dirs[:]\n module_dirs = ext.module_dirs[:]\n\n if check_for_f90_modules:\n module_build_dir = os.path.join(\\\n self.build_temp,os.path.dirname(\\\n self.get_ext_filename(fullname)))\n\n self.mkpath(module_build_dir)\n if self.fcompiler.module_dir_switch is None:\n existing_modules = glob('*.mod')\n extra_postargs += self.fcompiler.module_options(\\\n module_dirs,module_build_dir)\n\n f_objects = []\n if fmodule_sources:\n log.info(\"compling Fortran 90 module sources\")\n f_objects = self.fcompiler.compile(fmodule_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n\n if check_for_f90_modules \\\n and self.fcompiler.module_dir_switch is None:\n for f in glob('*.mod'):\n if f in existing_modules:\n continue\n try:\n self.move_file(f, module_build_dir)\n except DistutilsFileError: # already exists in destination\n os.remove(f)\n \n if f_sources:\n log.info(\"compling Fortran sources\")\n f_objects += self.fcompiler.compile(f_sources,\n output_dir=self.build_temp,\n macros=macros,\n include_dirs=include_dirs,\n debug=self.debug,\n extra_postargs=extra_postargs,\n depends=ext.depends)\n else:\n f_objects = []\n\n objects = c_objects + f_objects\n\n if ext.extra_objects:\n objects.extend(ext.extra_objects)\n extra_args = ext.extra_link_args or []\n\n try:\n old_linker_so_0 = self.compiler.linker_so[0]\n except:\n pass\n \n use_fortran_linker = getattr(ext,'language','c') in ['f77','f90']\n c_libraries = []\n c_library_dirs = []\n if use_fortran_linker or f_sources:\n use_fortran_linker = 1\n elif self.distribution.has_c_libraries(): \n build_clib = self.get_finalized_command('build_clib')\n f_libs = []\n for (lib_name, build_info) in build_clib.libraries:\n if has_f_sources(build_info.get('sources',[])):\n f_libs.append(lib_name)\n if lib_name in ext.libraries:\n # XXX: how to determine if c_libraries contain\n # fortran compiled sources?\n c_libraries.extend(build_info.get('libraries',[]))\n c_library_dirs.extend(build_info.get('library_dirs',[]))\n for l in ext.libraries:\n if l in f_libs:\n use_fortran_linker = 1\n break\n\n # Always use system linker on win32\n if sys.platform == 'win32':\n use_fortran_linker = 0\n \n if use_fortran_linker:\n if cxx_sources:\n # XXX: Which linker should be used, Fortran or C++?\n log.warn('mixing Fortran and C++ is untested')\n link = self.fcompiler.link_shared_object\n language = ext.language or self.fcompiler.detect_language(f_sources)\n else:\n link = self.compiler.link_shared_object\n if sys.version[:3]>='2.3':\n language = ext.language or self.compiler.detect_language(sources)\n else:\n language = ext.language\n if cxx_sources:\n self.compiler.linker_so[0] = self.compiler.compiler_cxx[0]\n\n if sys.version[:3]>='2.3':\n kws = {'target_lang':language}\n else:\n kws = {}\n\n link(objects, ext_filename,\n libraries=self.get_libraries(ext) + c_libraries,\n library_dirs=ext.library_dirs + c_library_dirs,\n runtime_library_dirs=ext.runtime_library_dirs,\n extra_postargs=extra_args,\n export_symbols=self.get_export_symbols(ext),\n debug=self.debug,\n build_temp=self.build_temp,**kws)\n\n try:\n self.compiler.linker_so[0] = old_linker_so_0\n except:\n pass\n\n return\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n def visit_func(filenames,dirname,names):\n if os.path.basename(dirname) in ['CVS','.svn']:\n names[:] = []\n return\n for name in names:\n fullname = os.path.join(dirname,name)\n if os.path.isfile(fullname):\n filenames.append(fullname)\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n sources = filter(lambda s:type(s) is StringType,ext.sources)\n filenames.extend(sources)\n filenames.extend(get_headers(get_directories(sources)))\n for d in ext.depends:\n if is_local_src_dir(d):\n os.path.walk(d,visit_func,filenames)\n elif os.path.isfile(d):\n filenames.append(d)\n return filenames\n\ndef is_local_src_dir(directory):\n \"\"\" Return true if directory is local directory.\n \"\"\"\n abs_dir = os.path.abspath(directory)\n c = os.path.commonprefix([os.getcwd(),abs_dir])\n new_dir = abs_dir[len(c):].split(os.sep)\n if new_dir and not new_dir[0]:\n new_dir = new_dir[1:]\n if new_dir and new_dir[0]=='build':\n return 0\n new_dir = os.sep.join(new_dir)\n return os.path.isdir(new_dir)\n", "methods": [ { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_ext.py", "nloc": 4, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 29, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "build_ext.py", "nloc": 5, "complexity": 1, "token_count": 24, "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": "run", "long_name": "run( self )", "filename": "build_ext.py", "nloc": 50, "complexity": 14, "token_count": 304, "parameters": [ "self" ], "start_line": 40, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 67, "top_nesting_level": 1 }, { "name": "swig_sources", "long_name": "swig_sources( self , sources )", "filename": "build_ext.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "sources" ], "start_line": 108, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 162, "complexity": 43, "token_count": 1060, "parameters": [ "self", "ext" ], "start_line": 112, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 192, "top_nesting_level": 1 }, { "name": "get_source_files.visit_func", "long_name": "get_source_files.visit_func( filenames , dirname , names )", "filename": "build_ext.py", "nloc": 8, "complexity": 4, "token_count": 66, "parameters": [ "filenames", "dirname", "names" ], "start_line": 308, "end_line": 315, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 2 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_ext.py", "nloc": 14, "complexity": 5, "token_count": 105, "parameters": [ "self" ], "start_line": 305, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "is_local_src_dir", "long_name": "is_local_src_dir( directory )", "filename": "build_ext.py", "nloc": 10, "complexity": 5, "token_count": 98, "parameters": [ "directory" ], "start_line": 328, "end_line": 339, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "methods_before": [ { "name": "initialize_options", "long_name": "initialize_options( self )", "filename": "build_ext.py", "nloc": 4, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 29, "end_line": 32, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "finalize_options", "long_name": "finalize_options( self )", "filename": "build_ext.py", "nloc": 5, "complexity": 1, "token_count": 24, "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": "run", "long_name": "run( self )", "filename": "build_ext.py", "nloc": 50, "complexity": 14, "token_count": 304, "parameters": [ "self" ], "start_line": 40, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 67, "top_nesting_level": 1 }, { "name": "swig_sources", "long_name": "swig_sources( self , sources )", "filename": "build_ext.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self", "sources" ], "start_line": 108, "end_line": 110, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 160, "complexity": 42, "token_count": 1036, "parameters": [ "self", "ext" ], "start_line": 112, "end_line": 301, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 190, "top_nesting_level": 1 }, { "name": "get_source_files.visit_func", "long_name": "get_source_files.visit_func( filenames , dirname , names )", "filename": "build_ext.py", "nloc": 8, "complexity": 4, "token_count": 66, "parameters": [ "filenames", "dirname", "names" ], "start_line": 306, "end_line": 313, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 2 }, { "name": "get_source_files", "long_name": "get_source_files( self )", "filename": "build_ext.py", "nloc": 14, "complexity": 5, "token_count": 105, "parameters": [ "self" ], "start_line": 303, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "is_local_src_dir", "long_name": "is_local_src_dir( directory )", "filename": "build_ext.py", "nloc": 10, "complexity": 5, "token_count": 98, "parameters": [ "directory" ], "start_line": 326, "end_line": 337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "build_extension", "long_name": "build_extension( self , ext )", "filename": "build_ext.py", "nloc": 162, "complexity": 43, "token_count": 1060, "parameters": [ "self", "ext" ], "start_line": 112, "end_line": 303, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 192, "top_nesting_level": 1 } ], "nloc": 274, "complexity": 74, "token_count": 1780, "diff_parsed": { "added": [ " # Always use system linker when using MSVC compiler.", " if self.compiler.compiler_type=='msvc' and use_fortran_linker:", " c_libraries.extend(self.fcompiler.libraries)", " c_library_dirs.extend(self.fcompiler.library_dirs)", "" ], "deleted": [ " # Always use system linker on win32", " if sys.platform == 'win32':", "" ] } } ] }, { "hash": "a96e326af1b0f1084269af3d9f3934a9d357e0ee", "msg": "Multiple suites were found when package_name==__main__, fixed it. Now TestCase classes can be implemented also in module sources.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-07T10:05:13+00:00", "author_timezone": 0, "committer_date": "2004-03-07T10:05:13+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "7f73fd1245115768196a07c9676b11eb3806489e" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 5, "insertions": 5, "lines": 10, "files": 1, "dmm_unit_size": null, "dmm_unit_complexity": null, "dmm_unit_interfacing": null, "modified_files": [ { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -189,7 +189,8 @@ def _get_method_names(self,clsobj,level):\n else:\n mthlevel = 1\n if level>=mthlevel:\n- names.append(mthname)\n+ if mthname not in names:\n+ names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n@@ -288,13 +289,12 @@ def test(self,level=1,verbosity=1):\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n- or module is None \\\n- or os.path.basename(os.path.dirname(module.__file__))=='tests':\n+ or module is None \\\n+ or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n \n- if package_name == '__main__':\n- suites.extend(self._get_suite_list(sys.modules[package_name], level))\n+ suites.extend(self._get_suite_list(sys.modules[package_name], level))\n \n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n", "added_lines": 5, "deleted_lines": 5, "source_code": "\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n import scipy_base.fastumath as math\nexcept ImportError:\n pass\n\nDEBUG=0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.dirname(os.path.abspath(testfile))\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog []'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\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\n__all__.append('harvest_modules')\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 d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\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\n__all__.append('harvest_packages')\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 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\n__all__.append('harvest_modules_and_packages')\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\n__all__.append('harvest_test_suites')\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 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 print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\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\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('assert_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\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 actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n try:\n sc_desired = desired/pow(10,math.floor(math.log10(abs(desired))))\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/pow(10,math.floor(math.log10(abs(actual))))\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\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 = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not equal'\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\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 = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\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'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import whrandom\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = whrandom.random()\n return results\n\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": "\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n import scipy_base.fastumath as math\nexcept ImportError:\n pass\n\nDEBUG=0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.dirname(os.path.abspath(testfile))\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n if package_name == '__main__':\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog []'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\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\n__all__.append('harvest_modules')\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 d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\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\n__all__.append('harvest_packages')\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 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\n__all__.append('harvest_modules_and_packages')\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\n__all__.append('harvest_test_suites')\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 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 print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\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\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('assert_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\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 actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n try:\n sc_desired = desired/pow(10,math.floor(math.log10(abs(desired))))\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/pow(10,math.floor(math.log10(abs(actual))))\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\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 = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not equal'\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\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 = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\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'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import whrandom\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = whrandom.random()\n return results\n\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": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 21, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 84, "parameters": [ "level" ], "start_line": 55, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 74, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 80, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 92, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 106, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 111, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 118, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 137, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 168, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 171, "end_line": 175, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 177, "end_line": 198, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 36, "complexity": 8, "token_count": 331, "parameters": [ "self", "module", "level" ], "start_line": 200, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 141, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 242, "end_line": 262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 264, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 277, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 304, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 330, "end_line": 336, "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": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 338, "end_line": 357, "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": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 360, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 399, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 436, "end_line": 442, "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": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 445, "end_line": 480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 483, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 513, "end_line": 535, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 545, "end_line": 559, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 562, "end_line": 576, "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": "testing.py", "nloc": 22, "complexity": 7, "token_count": 195, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 579, "end_line": 606, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 610, "end_line": 629, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 23, "complexity": 5, "token_count": 226, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 632, "end_line": 654, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 657, "end_line": 676, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 679, "end_line": 688, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 690, "end_line": 700, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 21, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 84, "parameters": [ "level" ], "start_line": 55, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 74, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 80, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 92, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 106, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 111, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 118, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 137, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 168, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 171, "end_line": 175, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 21, "complexity": 10, "token_count": 136, "parameters": [ "self", "clsobj", "level" ], "start_line": 177, "end_line": 197, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 36, "complexity": 8, "token_count": 331, "parameters": [ "self", "module", "level" ], "start_line": 199, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 141, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 241, "end_line": 261, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 263, "end_line": 274, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 171, "parameters": [ "self", "level", "verbosity" ], "start_line": 276, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 27, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 304, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 330, "end_line": 336, "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": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 338, "end_line": 357, "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": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 360, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 399, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 436, "end_line": 442, "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": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 445, "end_line": 480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 483, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 513, "end_line": 535, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 545, "end_line": 559, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 562, "end_line": 576, "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": "testing.py", "nloc": 22, "complexity": 7, "token_count": 195, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 579, "end_line": 606, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 610, "end_line": 629, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 23, "complexity": 5, "token_count": 226, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 632, "end_line": 654, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 657, "end_line": 676, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 679, "end_line": 688, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 690, "end_line": 700, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 277, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 177, "end_line": 198, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 } ], "nloc": 502, "complexity": 126, "token_count": 3685, "diff_parsed": { "added": [ " if mthname not in names:", " names.append(mthname)", " or module is None \\", " or os.path.basename(os.path.dirname(module.__file__))=='tests':", " suites.extend(self._get_suite_list(sys.modules[package_name], level))" ], "deleted": [ " names.append(mthname)", " or module is None \\", " or os.path.basename(os.path.dirname(module.__file__))=='tests':", " if package_name == '__main__':", " suites.extend(self._get_suite_list(sys.modules[package_name], level))" ] } } ] }, { "hash": "77976141c814bc23dc283e1eceac416e4c39bb81", "msg": "Introduced IgnoreException. When it is raised then scipy unittesting framework does not treat it as an error. Useful when certain features of a package are disabled but testing site contains tests for these features. Added agg_platform_support.cpp to sources list.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-09T08:35:38+00:00", "author_timezone": 0, "committer_date": "2004-03-09T08:35:38+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "a96e326af1b0f1084269af3d9f3934a9d357e0ee" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 4, "insertions": 32, "lines": 36, "files": 2, "dmm_unit_size": 0.95, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/system_info.py", "new_path": "scipy_distutils/system_info.py", "filename": "system_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -1180,6 +1180,7 @@ def calc_info(self):\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n+ agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n", "added_lines": 1, "deleted_lines": 0, "source_code": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python\n agg2\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the \nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\n__revision__ = '$Id$'\n\nimport sys,os,re,types\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'x11':x11_info,\n 'fftw':fftw_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def set_info(self,**info):\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n if self.dir_env_var and os.environ.has_key(self.dir_env_var):\n d = os.environ[self.dir_env_var]\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n dirs = d.split(os.pathsep) + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n return default\n return [a.strip() for a in libs.split(',')]\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n lapack_libs = self.get_libs('lapack_libs',['lapack'])\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n atlas = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\nclass atlas_threads_info(atlas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,macig=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = []\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if type(a) is types.StringType:\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n if 0:\n c = lapack_opt_info()\n c.verbosity = 2\n c.get_info()\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python\n agg2\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the \nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\n__revision__ = '$Id$'\n\nimport sys,os,re,types\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'x11':x11_info,\n 'fftw':fftw_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def set_info(self,**info):\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n if self.dir_env_var and os.environ.has_key(self.dir_env_var):\n d = os.environ[self.dir_env_var]\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n dirs = d.split(os.pathsep) + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n return default\n return [a.strip() for a in libs.split(',')]\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n lapack_libs = self.get_libs('lapack_libs',['lapack'])\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n atlas = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\nclass atlas_threads_info(atlas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,macig=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = []\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if type(a) is types.StringType:\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n if 0:\n c = lapack_opt_info()\n c.verbosity = 2\n c.get_info()\n", "methods": [ { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 27, "complexity": 1, "token_count": 130, "parameters": [ "name", "notfound_action" ], "start_line": 129, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", "filename": "system_info.py", "nloc": 25, "complexity": 3, "token_count": 200, "parameters": [ "self", "default_lib_dirs", "default_include_dirs", "verbosity" ], "start_line": 241, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "set_info", "long_name": "set_info( self , ** info )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "info" ], "start_line": 267, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "has_info", "long_name": "has_info( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "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": "get_info", "long_name": "get_info( self , notfound_action = 0 )", "filename": "system_info.py", "nloc": 30, "complexity": 15, "token_count": 206, "parameters": [ "self", "notfound_action" ], "start_line": 273, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 23, "complexity": 10, "token_count": 252, "parameters": [ "self", "section", "key" ], "start_line": 310, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 334, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_include_dirs", "long_name": "get_include_dirs( self , key = 'include_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 337, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_src_dirs", "long_name": "get_src_dirs( self , key = 'src_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 340, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libs", "long_name": "get_libs( self , key , default )", "filename": "system_info.py", "nloc": 6, "complexity": 3, "token_count": 49, "parameters": [ "self", "key", "default" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_libs", "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", "filename": "system_info.py", "nloc": 10, "complexity": 5, "token_count": 76, "parameters": [ "self", "lib_dir", "libs", "opt_libs" ], "start_line": 350, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "_lib_list", "long_name": "_lib_list( self , lib_dir , libs , ext )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "lib_dir", "libs", "ext" ], "start_line": 363, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "_extract_lib_names", "long_name": "_extract_lib_names( self , libs )", "filename": "system_info.py", "nloc": 3, "complexity": 2, "token_count": 37, "parameters": [ "self", "libs" ], "start_line": 373, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_check_libs", "long_name": "_check_libs( self , lib_dir , libs , opt_libs , ext )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 99, "parameters": [ "self", "lib_dir", "libs", "opt_libs", "ext" ], "start_line": 377, "end_line": 386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( self , * args )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "args" ], "start_line": 388, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 399, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 26, "complexity": 8, "token_count": 150, "parameters": [ "self" ], "start_line": 402, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 469, "end_line": 474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 7, "token_count": 139, "parameters": [ "self" ], "start_line": 476, "end_line": 496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 7, "complexity": 4, "token_count": 74, "parameters": [ "self", "section", "key" ], "start_line": 505, "end_line": 511, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 78, "complexity": 17, "token_count": 441, "parameters": [ "self" ], "start_line": 513, "end_line": 592, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 80, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 27, "complexity": 8, "token_count": 176, "parameters": [ "self" ], "start_line": 597, "end_line": 625, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 645, "end_line": 657, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 68, "parameters": [ "self", "section", "key" ], "start_line": 664, "end_line": 669, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 81, "complexity": 10, "token_count": 232, "parameters": [ "self" ], "start_line": 671, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , macig = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "macig" ], "start_line": 778, "end_line": 787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 41, "complexity": 8, "token_count": 269, "parameters": [ "config" ], "start_line": 774, "end_line": 824, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "top_nesting_level": 0 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 67, "complexity": 18, "token_count": 431, "parameters": [ "self" ], "start_line": 829, "end_line": 903, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 50, "complexity": 13, "token_count": 331, "parameters": [ "self" ], "start_line": 908, "end_line": 961, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 970, "end_line": 982, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 990, "end_line": 995, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 34, "complexity": 5, "token_count": 106, "parameters": [ "self" ], "start_line": 997, "end_line": 1032, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 1038, "end_line": 1041, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 20, "complexity": 7, "token_count": 114, "parameters": [ "self" ], "start_line": 1043, "end_line": 1062, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 139, "parameters": [ "self" ], "start_line": 1069, "end_line": 1090, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 121, "parameters": [ "self" ], "start_line": 1092, "end_line": 1120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1130, "end_line": 1135, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 5, "token_count": 156, "parameters": [ "self" ], "start_line": 1137, "end_line": 1157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1163, "end_line": 1168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 177, "parameters": [ "self" ], "start_line": 1170, "end_line": 1192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( * args , ** kws )", "filename": "system_info.py", "nloc": 22, "complexity": 11, "token_count": 195, "parameters": [ "args", "kws" ], "start_line": 1206, "end_line": 1230, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "system_info.py", "nloc": 17, "complexity": 9, "token_count": 128, "parameters": [ "d", "kws" ], "start_line": 1234, "end_line": 1250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "show_all", "long_name": "show_all( )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 64, "parameters": [], "start_line": 1252, "end_line": 1260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 27, "complexity": 1, "token_count": 130, "parameters": [ "name", "notfound_action" ], "start_line": 129, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", "filename": "system_info.py", "nloc": 25, "complexity": 3, "token_count": 200, "parameters": [ "self", "default_lib_dirs", "default_include_dirs", "verbosity" ], "start_line": 241, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "set_info", "long_name": "set_info( self , ** info )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "info" ], "start_line": 267, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "has_info", "long_name": "has_info( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "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": "get_info", "long_name": "get_info( self , notfound_action = 0 )", "filename": "system_info.py", "nloc": 30, "complexity": 15, "token_count": 206, "parameters": [ "self", "notfound_action" ], "start_line": 273, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 23, "complexity": 10, "token_count": 252, "parameters": [ "self", "section", "key" ], "start_line": 310, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 334, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_include_dirs", "long_name": "get_include_dirs( self , key = 'include_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 337, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_src_dirs", "long_name": "get_src_dirs( self , key = 'src_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 340, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libs", "long_name": "get_libs( self , key , default )", "filename": "system_info.py", "nloc": 6, "complexity": 3, "token_count": 49, "parameters": [ "self", "key", "default" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_libs", "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", "filename": "system_info.py", "nloc": 10, "complexity": 5, "token_count": 76, "parameters": [ "self", "lib_dir", "libs", "opt_libs" ], "start_line": 350, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "_lib_list", "long_name": "_lib_list( self , lib_dir , libs , ext )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "lib_dir", "libs", "ext" ], "start_line": 363, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "_extract_lib_names", "long_name": "_extract_lib_names( self , libs )", "filename": "system_info.py", "nloc": 3, "complexity": 2, "token_count": 37, "parameters": [ "self", "libs" ], "start_line": 373, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_check_libs", "long_name": "_check_libs( self , lib_dir , libs , opt_libs , ext )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 99, "parameters": [ "self", "lib_dir", "libs", "opt_libs", "ext" ], "start_line": 377, "end_line": 386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( self , * args )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "args" ], "start_line": 388, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 399, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 26, "complexity": 8, "token_count": 150, "parameters": [ "self" ], "start_line": 402, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 469, "end_line": 474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 7, "token_count": 139, "parameters": [ "self" ], "start_line": 476, "end_line": 496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 7, "complexity": 4, "token_count": 74, "parameters": [ "self", "section", "key" ], "start_line": 505, "end_line": 511, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 78, "complexity": 17, "token_count": 441, "parameters": [ "self" ], "start_line": 513, "end_line": 592, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 80, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 27, "complexity": 8, "token_count": 176, "parameters": [ "self" ], "start_line": 597, "end_line": 625, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 645, "end_line": 657, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 68, "parameters": [ "self", "section", "key" ], "start_line": 664, "end_line": 669, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 81, "complexity": 10, "token_count": 232, "parameters": [ "self" ], "start_line": 671, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , macig = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "macig" ], "start_line": 778, "end_line": 787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 41, "complexity": 8, "token_count": 269, "parameters": [ "config" ], "start_line": 774, "end_line": 824, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "top_nesting_level": 0 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 67, "complexity": 18, "token_count": 431, "parameters": [ "self" ], "start_line": 829, "end_line": 903, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 50, "complexity": 13, "token_count": 331, "parameters": [ "self" ], "start_line": 908, "end_line": 961, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 970, "end_line": 982, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 990, "end_line": 995, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 34, "complexity": 5, "token_count": 106, "parameters": [ "self" ], "start_line": 997, "end_line": 1032, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 1038, "end_line": 1041, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 20, "complexity": 7, "token_count": 114, "parameters": [ "self" ], "start_line": 1043, "end_line": 1062, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 139, "parameters": [ "self" ], "start_line": 1069, "end_line": 1090, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 121, "parameters": [ "self" ], "start_line": 1092, "end_line": 1120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1130, "end_line": 1135, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 5, "token_count": 156, "parameters": [ "self" ], "start_line": 1137, "end_line": 1157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1163, "end_line": 1168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 6, "token_count": 157, "parameters": [ "self" ], "start_line": 1170, "end_line": 1191, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( * args , ** kws )", "filename": "system_info.py", "nloc": 22, "complexity": 11, "token_count": 195, "parameters": [ "args", "kws" ], "start_line": 1205, "end_line": 1229, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "system_info.py", "nloc": 17, "complexity": 9, "token_count": 128, "parameters": [ "d", "kws" ], "start_line": 1233, "end_line": 1249, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "show_all", "long_name": "show_all( )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 64, "parameters": [], "start_line": 1251, "end_line": 1259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 177, "parameters": [ "self" ], "start_line": 1170, "end_line": 1192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 } ], "nloc": 1109, "complexity": 233, "token_count": 6154, "diff_parsed": { "added": [ " agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]" ], "deleted": [] } }, { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -132,6 +132,33 @@ def measure(self,code_str,times=1):\n elapsed = jiffies() - elapsed\n return 0.01*elapsed\n \n+ def __call__(self, result=None):\n+ if result is None:\n+ return unittest.TestCase.__call__(self, result)\n+\n+ nof_errors = len(result.errors)\n+ save_stream = result.stream\n+ result.stream = _dummy_stream()\n+ unittest.TestCase.__call__(self, result)\n+ if nof_errors != len(result.errors):\n+ test, errstr = result.errors[-1]\n+ if errstr.split('\\n')[-2].startswith('IgnoreException:'):\n+ assert result.stream.data[-1]=='E',`result.stream.data`\n+ result.stream.data[-1] = 'i'\n+ del result.errors[-1]\n+ map(save_stream.write, result.stream.data)\n+ result.stream = save_stream\n+\n+class _dummy_stream:\n+ def __init__(self):\n+ self.data = []\n+ def write(self,message):\n+ self.data.append(message)\n+\n+__all__.append('IgnoreException')\n+class IgnoreException(Exception):\n+ \"Ignoring this exception due to disabled feature\"\n+\n #------------\n \n def _get_all_method_names(cls):\n@@ -611,8 +638,9 @@ def assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\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+ assert len(shape(x))==len(shape(y)) and \\\n+ alltrue(equal(shape(x),shape(y))),\\\n+ msg + ' (shapes %s, %s mismatch):\\n\\t' % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n@@ -625,8 +653,7 @@ def assert_array_equal(x,y,err_msg=''):\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n- print shape(x),shape(y)\n- raise ValueError, 'arrays are not equal'\n+ raise ValueError, msg\n \n __all__.append('assert_array_almost_equal')\n def assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n", "added_lines": 31, "deleted_lines": 4, "source_code": "\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n import scipy_base.fastumath as math\nexcept ImportError:\n pass\n\nDEBUG=0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.dirname(os.path.abspath(testfile))\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog []'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\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\n__all__.append('harvest_modules')\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 d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\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\n__all__.append('harvest_packages')\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 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\n__all__.append('harvest_modules_and_packages')\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\n__all__.append('harvest_test_suites')\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 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 print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\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\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('assert_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\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 actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n try:\n sc_desired = desired/pow(10,math.floor(math.log10(abs(desired))))\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/pow(10,math.floor(math.log10(abs(actual))))\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\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 = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\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'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import whrandom\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = whrandom.random()\n return results\n\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": "\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n import scipy_base.fastumath as math\nexcept ImportError:\n pass\n\nDEBUG=0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.dirname(os.path.abspath(testfile))\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog []'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\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\n__all__.append('harvest_modules')\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 d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\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\n__all__.append('harvest_packages')\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 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\n__all__.append('harvest_modules_and_packages')\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\n__all__.append('harvest_test_suites')\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 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 print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\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\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('assert_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\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 actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n try:\n sc_desired = desired/pow(10,math.floor(math.log10(abs(desired))))\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/pow(10,math.floor(math.log10(abs(actual))))\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\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 = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not equal'\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\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 = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\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'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import whrandom\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = whrandom.random()\n return results\n\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": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 21, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 84, "parameters": [ "level" ], "start_line": 55, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 74, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 80, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 92, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 106, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 111, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 118, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 149, "parameters": [ "self", "result" ], "start_line": 135, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 153, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 155, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 164, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 195, "end_line": 196, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 198, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 204, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 36, "complexity": 8, "token_count": 331, "parameters": [ "self", "module", "level" ], "start_line": 227, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 141, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 269, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 291, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 304, "end_line": 329, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 331, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 357, "end_line": 363, "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": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 365, "end_line": 384, "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": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 387, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 426, "end_line": 460, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 463, "end_line": 469, "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": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 472, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 510, "end_line": 537, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 540, "end_line": 562, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 572, "end_line": 586, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 589, "end_line": 603, "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": "testing.py", "nloc": 22, "complexity": 7, "token_count": 195, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 606, "end_line": 633, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 6, "token_count": 208, "parameters": [ "x", "y", "err_msg" ], "start_line": 637, "end_line": 656, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 23, "complexity": 5, "token_count": 226, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 659, "end_line": 681, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 684, "end_line": 703, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 706, "end_line": 715, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 717, "end_line": 727, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 21, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 84, "parameters": [ "level" ], "start_line": 55, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 74, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 80, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 92, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 106, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 111, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 118, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 137, "end_line": 144, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 168, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 171, "end_line": 175, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 177, "end_line": 198, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 36, "complexity": 8, "token_count": 331, "parameters": [ "self", "module", "level" ], "start_line": 200, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 141, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 242, "end_line": 262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 264, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 277, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 304, "end_line": 326, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 330, "end_line": 336, "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": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 338, "end_line": 357, "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": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 360, "end_line": 396, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 399, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 436, "end_line": 442, "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": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 445, "end_line": 480, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 483, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 513, "end_line": 535, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 545, "end_line": 559, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 562, "end_line": 576, "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": "testing.py", "nloc": 22, "complexity": 7, "token_count": 195, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 579, "end_line": 606, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 610, "end_line": 629, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 23, "complexity": 5, "token_count": 226, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 632, "end_line": 654, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 657, "end_line": 676, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 679, "end_line": 688, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 690, "end_line": 700, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 153, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 6, "token_count": 208, "parameters": [ "x", "y", "err_msg" ], "start_line": 637, "end_line": 656, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 155, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 149, "parameters": [ "self", "result" ], "start_line": 135, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 } ], "nloc": 525, "complexity": 133, "token_count": 3898, "diff_parsed": { "added": [ " def __call__(self, result=None):", " if result is None:", " return unittest.TestCase.__call__(self, result)", "", " nof_errors = len(result.errors)", " save_stream = result.stream", " result.stream = _dummy_stream()", " unittest.TestCase.__call__(self, result)", " if nof_errors != len(result.errors):", " test, errstr = result.errors[-1]", " if errstr.split('\\n')[-2].startswith('IgnoreException:'):", " assert result.stream.data[-1]=='E',`result.stream.data`", " result.stream.data[-1] = 'i'", " del result.errors[-1]", " map(save_stream.write, result.stream.data)", " result.stream = save_stream", "", "class _dummy_stream:", " def __init__(self):", " self.data = []", " def write(self,message):", " self.data.append(message)", "", "__all__.append('IgnoreException')", "class IgnoreException(Exception):", " \"Ignoring this exception due to disabled feature\"", "", " assert len(shape(x))==len(shape(y)) and \\", " alltrue(equal(shape(x),shape(y))),\\", " msg + ' (shapes %s, %s mismatch):\\n\\t' % (shape(x),shape(y)) + err_msg", " raise ValueError, msg" ], "deleted": [ " assert alltrue(equal(shape(x),shape(y))),\\", " msg + ' (shapes mismatch):\\n\\t' + err_msg", " print shape(x),shape(y)", " raise ValueError, 'arrays are not equal'" ] } } ] }, { "hash": "9b5b7b2501eeb380c0f9368ed1d0435b3a683c84", "msg": "fix to get MSVC compilers working.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2004-03-10T22:46:22+00:00", "author_timezone": 0, "committer_date": "2004-03-10T22:46:22+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "77976141c814bc23dc283e1eceac416e4c39bb81" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 1, "insertions": 9, "lines": 10, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_distutils/ccompiler.py", "new_path": "scipy_distutils/ccompiler.py", "filename": "ccompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -23,7 +23,9 @@ def CCompiler_spawn(self, cmd, display=None):\n if type(cmd) is type([]) and os.name == 'nt':\n cmd = _nt_quote_args(cmd)\n s,o = exec_command(cmd)\n- if os.name != 'posix': print len(cmd), s, o\n+ if os.name != 'posix': \n+ print \" \".join(cmd)\n+ print o\n if s:\n if type(cmd) is type([]):\n cmd = ' '.join(cmd)\n@@ -155,6 +157,12 @@ def CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n+ \n+ # MSVC doesn't appear to have compiler defined?? This\n+ # was a hack added by Travis O.\n+ if not hasattr(self,'compiler'):\n+ return\n+ \n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n", "added_lines": 9, "deleted_lines": 1, "source_code": "\nimport re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import compiler_to_string\nfrom distutils.spawn import _nt_quote_args \n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if type(display) is type([]): display = ' '.join(display)\n log.info(display)\n if type(cmd) is type([]) and os.name == 'nt':\n cmd = _nt_quote_args(cmd)\n s,o = exec_command(cmd)\n if os.name != 'posix': \n print \" \".join(cmd)\n print o\n if s:\n if type(cmd) is type([]):\n cmd = ' '.join(cmd)\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n \n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n \n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n print '*'*80\n print self.__class__\n print compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n \n # MSVC doesn't appear to have compiler defined?? This\n # was a hack added by Travis O.\n if not hasattr(self,'compiler'):\n return\n \n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n if not (hasattr(self,'version_cmd') and\n hasattr(self,'version_pattern')):\n log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n % (self.__class__))\n return\n\n cmd = ' '.join(self.version_cmd)\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n m = re.match(self.version_pattern,output)\n if m:\n version = m.group('version')\n assert version,`version`\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if os.environ.get('OSTYPE','')=='msys' or \\\n os.environ.get('MSYSTEM','')=='MINGW32':\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from scipy_distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n\n module_name = \"scipy_distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n", "source_code_before": "\nimport re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import compiler_to_string\nfrom distutils.spawn import _nt_quote_args \n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if type(display) is type([]): display = ' '.join(display)\n log.info(display)\n if type(cmd) is type([]) and os.name == 'nt':\n cmd = _nt_quote_args(cmd)\n s,o = exec_command(cmd)\n if os.name != 'posix': print len(cmd), s, o\n if s:\n if type(cmd) is type([]):\n cmd = ' '.join(cmd)\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n \n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n \n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n print '*'*80\n print self.__class__\n print compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n if not (hasattr(self,'version_cmd') and\n hasattr(self,'version_pattern')):\n log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n % (self.__class__))\n return\n\n cmd = ' '.join(self.version_cmd)\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n m = re.match(self.version_pattern,output)\n if m:\n version = m.group('version')\n assert version,`version`\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if os.environ.get('OSTYPE','')=='msys' or \\\n os.environ.get('MSYSTEM','')=='MINGW32':\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from scipy_distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n\n module_name = \"scipy_distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n", "methods": [ { "name": "CCompiler_spawn", "long_name": "CCompiler_spawn( self , cmd , display = None )", "filename": "ccompiler.py", "nloc": 16, "complexity": 8, "token_count": 127, "parameters": [ "self", "cmd", "display" ], "start_line": 18, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_object_filenames", "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", "filename": "ccompiler.py", "nloc": 21, "complexity": 6, "token_count": 185, "parameters": [ "self", "source_filenames", "strip_dir", "output_dir" ], "start_line": 36, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "CCompiler_compile", "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "ccompiler.py", "nloc": 39, "complexity": 10, "token_count": 323, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 63, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 0 }, { "name": "CCompiler_customize_cmd", "long_name": "CCompiler_customize_cmd( self , cmd )", "filename": "ccompiler.py", "nloc": 20, "complexity": 10, "token_count": 200, "parameters": [ "self", "cmd" ], "start_line": 110, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_show_customization", "long_name": "CCompiler_show_customization( self )", "filename": "ccompiler.py", "nloc": 15, "complexity": 5, "token_count": 81, "parameters": [ "self" ], "start_line": 136, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 17, "complexity": 7, "token_count": 154, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 156, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_get_version", "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", "filename": "ccompiler.py", "nloc": 19, "complexity": 7, "token_count": 135, "parameters": [ "self", "force", "ok_status" ], "start_line": 182, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "new_compiler", "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "ccompiler.py", "nloc": 38, "complexity": 8, "token_count": 184, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 221, "end_line": 260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 } ], "methods_before": [ { "name": "CCompiler_spawn", "long_name": "CCompiler_spawn( self , cmd , display = None )", "filename": "ccompiler.py", "nloc": 14, "complexity": 8, "token_count": 127, "parameters": [ "self", "cmd", "display" ], "start_line": 18, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "CCompiler_object_filenames", "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", "filename": "ccompiler.py", "nloc": 21, "complexity": 6, "token_count": 185, "parameters": [ "self", "source_filenames", "strip_dir", "output_dir" ], "start_line": 34, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "CCompiler_compile", "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "ccompiler.py", "nloc": 39, "complexity": 10, "token_count": 323, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 61, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 0 }, { "name": "CCompiler_customize_cmd", "long_name": "CCompiler_customize_cmd( self , cmd )", "filename": "ccompiler.py", "nloc": 20, "complexity": 10, "token_count": 200, "parameters": [ "self", "cmd" ], "start_line": 108, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_show_customization", "long_name": "CCompiler_show_customization( self )", "filename": "ccompiler.py", "nloc": 15, "complexity": 5, "token_count": 81, "parameters": [ "self" ], "start_line": 134, "end_line": 148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 15, "complexity": 6, "token_count": 144, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 154, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_get_version", "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", "filename": "ccompiler.py", "nloc": 19, "complexity": 7, "token_count": 135, "parameters": [ "self", "force", "ok_status" ], "start_line": 174, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "new_compiler", "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "ccompiler.py", "nloc": 38, "complexity": 8, "token_count": 184, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 213, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 17, "complexity": 7, "token_count": 154, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 156, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_spawn", "long_name": "CCompiler_spawn( self , cmd , display = None )", "filename": "ccompiler.py", "nloc": 16, "complexity": 8, "token_count": 127, "parameters": [ "self", "cmd", "display" ], "start_line": 18, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 } ], "nloc": 220, "complexity": 61, "token_count": 1625, "diff_parsed": { "added": [ " if os.name != 'posix':", " print \" \".join(cmd)", " print o", "", " # MSVC doesn't appear to have compiler defined?? This", " # was a hack added by Travis O.", " if not hasattr(self,'compiler'):", " return", "" ], "deleted": [ " if os.name != 'posix': print len(cmd), s, o" ] } } ] }, { "hash": "cf8d1e6eedf7171969771dcec1218a8258d1731f", "msg": "platform_info now try to use scipy_distutils and falls back to distutils if it isn't available.", "author": { "name": "Eric Jones", "email": "eric@enthought.com" }, "committer": { "name": "Eric Jones", "email": "eric@enthought.com" }, "author_date": "2004-03-10T22:47:10+00:00", "author_timezone": 0, "committer_date": "2004-03-10T22:47:10+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "9b5b7b2501eeb380c0f9368ed1d0435b3a683c84" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 3, "insertions": 11, "lines": 14, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "weave/platform_info.py", "new_path": "weave/platform_info.py", "filename": "platform_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -8,10 +8,17 @@\n import os, sys\n \n import distutils\n-from distutils.core import Extension, setup\n-from distutils.command.build_ext import build_ext\n from distutils.sysconfig import customize_compiler\n-from distutils.ccompiler import new_compiler\n+\n+\n+try:\n+ from scipy_distutils.ccompiler import new_compiler\n+ from scipy_distutils.core import Extension, setup\n+ from scipy_distutils.command.build_ext import build_ext\n+except ImportError:\n+ from distutils.ccompiler import new_compiler\n+ from distutils.core import Extension, setup\n+ from distutils.command.build_ext import build_ext\n \n import distutils.bcppcompiler\n \n@@ -47,6 +54,7 @@ def create_compiler_instance(dist):\n # and return it. \n if not compiler_name:\n compiler_name = None\n+ print compiler_name \n compiler = new_compiler(compiler=compiler_name)\n customize_compiler(compiler)\n return compiler\n", "added_lines": 11, "deleted_lines": 3, "source_code": "\"\"\" Information about platform and python version and compilers\n\n This information is manly used to build directory names that\n keep the object files and shared libaries straight when\n multiple platforms share the same file system.\n\"\"\"\n\nimport os, sys\n\nimport distutils\nfrom distutils.sysconfig import customize_compiler\n\n\ntry:\n from scipy_distutils.ccompiler import new_compiler\n from scipy_distutils.core import Extension, setup\n from scipy_distutils.command.build_ext import build_ext\nexcept ImportError:\n from distutils.ccompiler import new_compiler\n from distutils.core import Extension, setup\n from distutils.command.build_ext import build_ext\n\nimport distutils.bcppcompiler\n\n#from scipy_distutils import mingw32_support\n\ndef dummy_dist():\n # create a dummy distribution. It will look at any site configuration files\n # and parse the command line to pick up any user configured stuff. The \n # resulting Distribution object is returned from setup.\n # Setting _setup_stop_after prevents the any commands from actually executing.\n distutils.core._setup_stop_after = \"commandline\"\n dist = setup(name=\"dummy\")\n distutils.core._setup_stop_after = None\n return dist\n\ndef create_compiler_instance(dist): \n # build_ext is in charge of building C/C++ files.\n # We are using it and dist to parse config files, and command line \n # configurations. There may be other ways to handle this, but I'm\n # worried I may miss one of the steps in distutils if I do it my self.\n #ext_builder = build_ext(dist)\n #ext_builder.finalize_options ()\n \n # For some reason the build_ext stuff wasn't picking up the compiler \n # setting, so we grab it manually from the distribution object instead.\n opts = dist.command_options.get('build_ext',None)\n compiler_name = ''\n if opts:\n comp = opts.get('compiler',('',''))\n compiler_name = comp[1]\n \n # Create a new compiler, customize it based on the build settings,\n # and return it. \n if not compiler_name:\n compiler_name = None\n print compiler_name \n compiler = new_compiler(compiler=compiler_name)\n customize_compiler(compiler)\n return compiler\n\ndef compiler_exe_name(compiler): \n exe_name = ''\n # this is really ugly... Why aren't the attribute names \n # standardized and used in a consistent way?\n if hasattr(compiler, \"compiler\"):\n # standard unix format\n exe_name = compiler.compiler[0]\n elif hasattr(compiler, \"cc\"):\n exe_name = compiler.cc\n elif compiler.__class__ is distutils.bcppcompiler.BCPPCompiler:\n exe_name = 'brcc32'\n return exe_name\n\ndef compiler_exe_path(exe_name):\n exe_path = None\n if os.path.exists(exe_name):\n exe_path = exe_name\n else:\n path_string = os.environ['PATH']\n path_string = os.path.expandvars(path_string)\n path_string = os.path.expanduser(path_string)\n paths = path_string.split(os.pathsep)\n for path in paths:\n path = os.path.join(path,exe_name)\n if os.path.exists(path):\n exe_path = path\n break \n # needed to catch gcc on mingw32 installations. \n path = path + '.exe' \n if os.path.exists(path):\n exe_path = path\n break\n return exe_path\n\ndef check_sum(file):\n \n import md5\n try:\n f = open(file,'r')\n bytes = f.read(-1)\n except IOError:\n bytes = '' \n chk_sum = md5.md5(bytes)\n return chk_sum.hexdigest()\n\ndef get_compiler_dir(compiler_name):\n \"\"\" Try to figure out the compiler directory based on the\n input compiler name. This is fragile and really should\n be done at the distutils level inside the compiler. I\n think it is only useful on windows at the moment.\n \"\"\"\n compiler_type = choose_compiler(compiler_name)\n #print compiler_type\n configure_sys_argv(compiler_type)\n #print sys.argv\n dist = dummy_dist() \n compiler_obj = create_compiler_instance(dist)\n #print compiler_obj.__class__\n exe_name = compiler_exe_name(compiler_obj)\n exe_path = compiler_exe_path(exe_name)\n if not exe_path:\n raise ValueError, \"The '%s' compiler was not found.\" % compiler_name\n chk_sum = check_sum(exe_path) \n restore_sys_argv()\n \n return 'compiler_'+chk_sum\n\n#----------------------------------------------------------------------------\n# Not needed -- used for testing.\n#----------------------------------------------------------------------------\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 not compiler_name:\n compiler_name = ''\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\nold_argv = []\ndef configure_sys_argv(compiler_name):\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','--compiler='+compiler_name]\n\ndef restore_sys_argv():\n sys.argv = old_argv\n\ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n\n # There was a change to 'distutils.msvccompiler' between Python 2.2\n # and Python 2.3.\n #\n # In Python 2.2 the function is 'get_devstudio_versions'\n # In Python 2.3 the function is 'get_build_version'\n try:\n version = distutils.msvccompiler.get_devstudio_versions()\n \n except:\n version = distutils.msvccompiler.get_build_version()\n \n if version:\n result = 1\n return result\n\nif __name__ == \"__main__\":\n \"\"\"\n import time\n t1 = time.time() \n dist = dummy_dist() \n compiler_obj = create_compiler_instance(dist)\n exe_name = compiler_exe_name(compiler_obj)\n exe_path = compiler_exe_path(exe_name)\n chk_sum = check_sum(exe_path) \n \n t2 = time.time()\n print 'compiler exe:', exe_path\n print 'check sum:', chk_sum\n print 'time (sec):', t2 - t1\n print\n \"\"\"\n path = get_compiler_dir('gcc')\n print 'gcc path:', path\n print\n try: \n path = get_compiler_dir('msvc')\n print 'gcc path:', path\n except ValueError:\n pass \n", "source_code_before": "\"\"\" Information about platform and python version and compilers\n\n This information is manly used to build directory names that\n keep the object files and shared libaries straight when\n multiple platforms share the same file system.\n\"\"\"\n\nimport os, sys\n\nimport distutils\nfrom distutils.core import Extension, setup\nfrom distutils.command.build_ext import build_ext\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.ccompiler import new_compiler\n\nimport distutils.bcppcompiler\n\n#from scipy_distutils import mingw32_support\n\ndef dummy_dist():\n # create a dummy distribution. It will look at any site configuration files\n # and parse the command line to pick up any user configured stuff. The \n # resulting Distribution object is returned from setup.\n # Setting _setup_stop_after prevents the any commands from actually executing.\n distutils.core._setup_stop_after = \"commandline\"\n dist = setup(name=\"dummy\")\n distutils.core._setup_stop_after = None\n return dist\n\ndef create_compiler_instance(dist): \n # build_ext is in charge of building C/C++ files.\n # We are using it and dist to parse config files, and command line \n # configurations. There may be other ways to handle this, but I'm\n # worried I may miss one of the steps in distutils if I do it my self.\n #ext_builder = build_ext(dist)\n #ext_builder.finalize_options ()\n \n # For some reason the build_ext stuff wasn't picking up the compiler \n # setting, so we grab it manually from the distribution object instead.\n opts = dist.command_options.get('build_ext',None)\n compiler_name = ''\n if opts:\n comp = opts.get('compiler',('',''))\n compiler_name = comp[1]\n \n # Create a new compiler, customize it based on the build settings,\n # and return it. \n if not compiler_name:\n compiler_name = None\n compiler = new_compiler(compiler=compiler_name)\n customize_compiler(compiler)\n return compiler\n\ndef compiler_exe_name(compiler): \n exe_name = ''\n # this is really ugly... Why aren't the attribute names \n # standardized and used in a consistent way?\n if hasattr(compiler, \"compiler\"):\n # standard unix format\n exe_name = compiler.compiler[0]\n elif hasattr(compiler, \"cc\"):\n exe_name = compiler.cc\n elif compiler.__class__ is distutils.bcppcompiler.BCPPCompiler:\n exe_name = 'brcc32'\n return exe_name\n\ndef compiler_exe_path(exe_name):\n exe_path = None\n if os.path.exists(exe_name):\n exe_path = exe_name\n else:\n path_string = os.environ['PATH']\n path_string = os.path.expandvars(path_string)\n path_string = os.path.expanduser(path_string)\n paths = path_string.split(os.pathsep)\n for path in paths:\n path = os.path.join(path,exe_name)\n if os.path.exists(path):\n exe_path = path\n break \n # needed to catch gcc on mingw32 installations. \n path = path + '.exe' \n if os.path.exists(path):\n exe_path = path\n break\n return exe_path\n\ndef check_sum(file):\n \n import md5\n try:\n f = open(file,'r')\n bytes = f.read(-1)\n except IOError:\n bytes = '' \n chk_sum = md5.md5(bytes)\n return chk_sum.hexdigest()\n\ndef get_compiler_dir(compiler_name):\n \"\"\" Try to figure out the compiler directory based on the\n input compiler name. This is fragile and really should\n be done at the distutils level inside the compiler. I\n think it is only useful on windows at the moment.\n \"\"\"\n compiler_type = choose_compiler(compiler_name)\n #print compiler_type\n configure_sys_argv(compiler_type)\n #print sys.argv\n dist = dummy_dist() \n compiler_obj = create_compiler_instance(dist)\n #print compiler_obj.__class__\n exe_name = compiler_exe_name(compiler_obj)\n exe_path = compiler_exe_path(exe_name)\n if not exe_path:\n raise ValueError, \"The '%s' compiler was not found.\" % compiler_name\n chk_sum = check_sum(exe_path) \n restore_sys_argv()\n \n return 'compiler_'+chk_sum\n\n#----------------------------------------------------------------------------\n# Not needed -- used for testing.\n#----------------------------------------------------------------------------\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 not compiler_name:\n compiler_name = ''\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\nold_argv = []\ndef configure_sys_argv(compiler_name):\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','--compiler='+compiler_name]\n\ndef restore_sys_argv():\n sys.argv = old_argv\n\ndef gcc_exists(name = 'gcc'):\n \"\"\" Test to make sure gcc is found \n \n Does this return correct value on win98???\n \"\"\"\n result = 0\n cmd = '%s -v' % name\n try:\n w,r=os.popen4(cmd)\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Reading specs') != -1:\n result = 1\n except:\n # This was needed because the msvc compiler messes with\n # the path variable. and will occasionlly mess things up\n # so much that gcc is lost in the path. (Occurs in test\n # scripts)\n result = not os.system(cmd)\n return result\n\ndef msvc_exists():\n \"\"\" Determine whether MSVC is available on the machine.\n \"\"\"\n result = 0\n try:\n w,r=os.popen4('cl')\n w.close()\n str_result = r.read()\n #print str_result\n if string.find(str_result,'Microsoft') != -1:\n result = 1\n except:\n #assume we're ok if devstudio exists\n import distutils.msvccompiler\n\n # There was a change to 'distutils.msvccompiler' between Python 2.2\n # and Python 2.3.\n #\n # In Python 2.2 the function is 'get_devstudio_versions'\n # In Python 2.3 the function is 'get_build_version'\n try:\n version = distutils.msvccompiler.get_devstudio_versions()\n \n except:\n version = distutils.msvccompiler.get_build_version()\n \n if version:\n result = 1\n return result\n\nif __name__ == \"__main__\":\n \"\"\"\n import time\n t1 = time.time() \n dist = dummy_dist() \n compiler_obj = create_compiler_instance(dist)\n exe_name = compiler_exe_name(compiler_obj)\n exe_path = compiler_exe_path(exe_name)\n chk_sum = check_sum(exe_path) \n \n t2 = time.time()\n print 'compiler exe:', exe_path\n print 'check sum:', chk_sum\n print 'time (sec):', t2 - t1\n print\n \"\"\"\n path = get_compiler_dir('gcc')\n print 'gcc path:', path\n print\n try: \n path = get_compiler_dir('msvc')\n print 'gcc path:', path\n except ValueError:\n pass \n", "methods": [ { "name": "dummy_dist", "long_name": "dummy_dist( )", "filename": "platform_info.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [], "start_line": 27, "end_line": 35, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "create_compiler_instance", "long_name": "create_compiler_instance( dist )", "filename": "platform_info.py", "nloc": 12, "complexity": 3, "token_count": 66, "parameters": [ "dist" ], "start_line": 37, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 }, { "name": "compiler_exe_name", "long_name": "compiler_exe_name( compiler )", "filename": "platform_info.py", "nloc": 9, "complexity": 4, "token_count": 53, "parameters": [ "compiler" ], "start_line": 62, "end_line": 73, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "compiler_exe_path", "long_name": "compiler_exe_path( exe_name )", "filename": "platform_info.py", "nloc": 19, "complexity": 5, "token_count": 113, "parameters": [ "exe_name" ], "start_line": 75, "end_line": 94, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "check_sum", "long_name": "check_sum( file )", "filename": "platform_info.py", "nloc": 9, "complexity": 2, "token_count": 46, "parameters": [ "file" ], "start_line": 96, "end_line": 105, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_compiler_dir", "long_name": "get_compiler_dir( compiler_name )", "filename": "platform_info.py", "nloc": 12, "complexity": 2, "token_count": 62, "parameters": [ "compiler_name" ], "start_line": 107, "end_line": 127, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "platform_info.py", "nloc": 15, "complexity": 8, "token_count": 62, "parameters": [ "compiler_name" ], "start_line": 133, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name )", "filename": "platform_info.py", "nloc": 4, "complexity": 1, "token_count": 28, "parameters": [ "compiler_name" ], "start_line": 160, "end_line": 165, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "platform_info.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 167, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "platform_info.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 170, "end_line": 190, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "platform_info.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [], "start_line": 192, "end_line": 220, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 } ], "methods_before": [ { "name": "dummy_dist", "long_name": "dummy_dist( )", "filename": "platform_info.py", "nloc": 5, "complexity": 1, "token_count": 28, "parameters": [], "start_line": 20, "end_line": 28, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 }, { "name": "create_compiler_instance", "long_name": "create_compiler_instance( dist )", "filename": "platform_info.py", "nloc": 11, "complexity": 3, "token_count": 64, "parameters": [ "dist" ], "start_line": 30, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "compiler_exe_name", "long_name": "compiler_exe_name( compiler )", "filename": "platform_info.py", "nloc": 9, "complexity": 4, "token_count": 53, "parameters": [ "compiler" ], "start_line": 54, "end_line": 65, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 0 }, { "name": "compiler_exe_path", "long_name": "compiler_exe_path( exe_name )", "filename": "platform_info.py", "nloc": 19, "complexity": 5, "token_count": 113, "parameters": [ "exe_name" ], "start_line": 67, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "check_sum", "long_name": "check_sum( file )", "filename": "platform_info.py", "nloc": 9, "complexity": 2, "token_count": 46, "parameters": [ "file" ], "start_line": 88, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "get_compiler_dir", "long_name": "get_compiler_dir( compiler_name )", "filename": "platform_info.py", "nloc": 12, "complexity": 2, "token_count": 62, "parameters": [ "compiler_name" ], "start_line": 99, "end_line": 119, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "choose_compiler", "long_name": "choose_compiler( compiler_name = '' )", "filename": "platform_info.py", "nloc": 15, "complexity": 8, "token_count": 62, "parameters": [ "compiler_name" ], "start_line": 125, "end_line": 149, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "configure_sys_argv", "long_name": "configure_sys_argv( compiler_name )", "filename": "platform_info.py", "nloc": 4, "complexity": 1, "token_count": 28, "parameters": [ "compiler_name" ], "start_line": 152, "end_line": 157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "restore_sys_argv", "long_name": "restore_sys_argv( )", "filename": "platform_info.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [], "start_line": 159, "end_line": 160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 0 }, { "name": "gcc_exists", "long_name": "gcc_exists( name = 'gcc' )", "filename": "platform_info.py", "nloc": 12, "complexity": 3, "token_count": 69, "parameters": [ "name" ], "start_line": 162, "end_line": 182, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "msvc_exists", "long_name": "msvc_exists( )", "filename": "platform_info.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [], "start_line": 184, "end_line": 212, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "create_compiler_instance", "long_name": "create_compiler_instance( dist )", "filename": "platform_info.py", "nloc": 12, "complexity": 3, "token_count": 66, "parameters": [ "dist" ], "start_line": 37, "end_line": 60, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 24, "top_nesting_level": 0 } ], "nloc": 159, "complexity": 35, "token_count": 734, "diff_parsed": { "added": [ "", "", "try:", " from scipy_distutils.ccompiler import new_compiler", " from scipy_distutils.core import Extension, setup", " from scipy_distutils.command.build_ext import build_ext", "except ImportError:", " from distutils.ccompiler import new_compiler", " from distutils.core import Extension, setup", " from distutils.command.build_ext import build_ext", " print compiler_name" ], "deleted": [ "from distutils.core import Extension, setup", "from distutils.command.build_ext import build_ext", "from distutils.ccompiler import new_compiler" ] } } ] }, { "hash": "8d935d1126580300b0340a5ef65b4ec6378a50d9", "msg": "Fixed dependency libraries on absoft compiler.", "author": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "committer": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "author_date": "2004-03-11T20:20:03+00:00", "author_timezone": 0, "committer_date": "2004-03-11T20:20:03+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "cf8d1e6eedf7171969771dcec1218a8258d1731f" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 7, "insertions": 1, "lines": 8, "files": 2, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/absoftfcompiler.py", "new_path": "scipy_distutils/absoftfcompiler.py", "filename": "absoftfcompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -42,7 +42,7 @@ def get_library_dirs(self):\n \n def get_libraries(self):\n opt = FCompiler.get_libraries(self)\n- opt.extend(['fio','f77math','f90math'])\n+ opt.extend(['fio','f90math','fmath'])\n if os.name =='nt':\n opt.append('COMDLG32')\n return opt\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\n# http://www.absoft.com/literature/osxuserguide.pdf\n# http://www.absoft.com/documentation.html\n\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler, dummy_fortran_file\n\nclass AbsoftFCompiler(FCompiler):\n\n compiler_type = 'absoft'\n version_pattern = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n\n # samt5735(8)$ f90 -V -c dummy.f\n # f90: Copyright Absoft Corporation 1994-2002; Absoft Pro FORTRAN Version 8.0\n # Note that fink installs g77 as f77, so need to use f90 for detection.\n\n executables = {\n 'version_cmd' : [\"f77\", \"-V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':dummy_fortran_file()}],\n 'compiler_f77' : [\"f77\"],\n 'compiler_fix' : [\"f90\"],\n 'compiler_f90' : [\"f90\"],\n 'linker_so' : [\"f77\",\"-shared\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\n if os.name != 'nt':\n pic_flags = ['-fpic']\n module_dir_switch = None\n module_include_switch = '-p'\n\n def get_library_dirs(self):\n opt = FCompiler.get_library_dirs(self)\n d = os.environ.get('ABSOFT')\n if d:\n opt.append(os.path.join(d,'LIB'))\n return opt\n\n def get_libraries(self):\n opt = FCompiler.get_libraries(self)\n opt.extend(['fio','f90math','fmath'])\n if os.name =='nt':\n opt.append('COMDLG32')\n return opt\n\n def get_flags(self):\n opt = FCompiler.get_flags(self)\n if os.name != 'nt':\n opt.extend(['-s'])\n return opt\n\n def get_flags_f77(self):\n opt = FCompiler.get_flags_f77(self)\n opt.extend(['-N22','-N90','-N110'])\n if os.name != 'nt':\n opt.append('-f')\n if self.get_version():\n if self.get_version()<='4.6':\n opt.append('-B108')\n else:\n # Though -N15 is undocumented, it works with\n # Absoft 8.0 on Linux\n opt.append('-N15')\n return opt\n\n def get_flags_f90(self):\n opt = FCompiler.get_flags_f90(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n return opt\n\n def get_flags_fix(self):\n opt = FCompiler.get_flags_fix(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n opt.extend([\"-f\",\"fixed\"])\n return opt\n\n def get_flags_opt(self):\n opt = ['-O']\n return opt\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='absoft')\n compiler.customize()\n print compiler.get_version()\n", "source_code_before": "\n# http://www.absoft.com/literature/osxuserguide.pdf\n# http://www.absoft.com/documentation.html\n\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler, dummy_fortran_file\n\nclass AbsoftFCompiler(FCompiler):\n\n compiler_type = 'absoft'\n version_pattern = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n\n # samt5735(8)$ f90 -V -c dummy.f\n # f90: Copyright Absoft Corporation 1994-2002; Absoft Pro FORTRAN Version 8.0\n # Note that fink installs g77 as f77, so need to use f90 for detection.\n\n executables = {\n 'version_cmd' : [\"f77\", \"-V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':dummy_fortran_file()}],\n 'compiler_f77' : [\"f77\"],\n 'compiler_fix' : [\"f90\"],\n 'compiler_f90' : [\"f90\"],\n 'linker_so' : [\"f77\",\"-shared\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\n if os.name != 'nt':\n pic_flags = ['-fpic']\n module_dir_switch = None\n module_include_switch = '-p'\n\n def get_library_dirs(self):\n opt = FCompiler.get_library_dirs(self)\n d = os.environ.get('ABSOFT')\n if d:\n opt.append(os.path.join(d,'LIB'))\n return opt\n\n def get_libraries(self):\n opt = FCompiler.get_libraries(self)\n opt.extend(['fio','f77math','f90math'])\n if os.name =='nt':\n opt.append('COMDLG32')\n return opt\n\n def get_flags(self):\n opt = FCompiler.get_flags(self)\n if os.name != 'nt':\n opt.extend(['-s'])\n return opt\n\n def get_flags_f77(self):\n opt = FCompiler.get_flags_f77(self)\n opt.extend(['-N22','-N90','-N110'])\n if os.name != 'nt':\n opt.append('-f')\n if self.get_version():\n if self.get_version()<='4.6':\n opt.append('-B108')\n else:\n # Though -N15 is undocumented, it works with\n # Absoft 8.0 on Linux\n opt.append('-N15')\n return opt\n\n def get_flags_f90(self):\n opt = FCompiler.get_flags_f90(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n return opt\n\n def get_flags_fix(self):\n opt = FCompiler.get_flags_fix(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n opt.extend([\"-f\",\"fixed\"])\n return opt\n\n def get_flags_opt(self):\n opt = ['-O']\n return opt\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='absoft')\n compiler.customize()\n print compiler.get_version()\n", "methods": [ { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "absoftfcompiler.py", "nloc": 6, "complexity": 2, "token_count": 43, "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": "get_libraries", "long_name": "get_libraries( self )", "filename": "absoftfcompiler.py", "nloc": 6, "complexity": 2, "token_count": 40, "parameters": [ "self" ], "start_line": 43, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "absoftfcompiler.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "self" ], "start_line": 50, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f77", "long_name": "get_flags_f77( self )", "filename": "absoftfcompiler.py", "nloc": 11, "complexity": 4, "token_count": 70, "parameters": [ "self" ], "start_line": 56, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_flags_f90", "long_name": "get_flags_f90( self )", "filename": "absoftfcompiler.py", "nloc": 5, "complexity": 1, "token_count": 35, "parameters": [ "self" ], "start_line": 70, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_fix", "long_name": "get_flags_fix( self )", "filename": "absoftfcompiler.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 76, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "absoftfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 83, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 } ], "methods_before": [ { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "absoftfcompiler.py", "nloc": 6, "complexity": 2, "token_count": 43, "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": "get_libraries", "long_name": "get_libraries( self )", "filename": "absoftfcompiler.py", "nloc": 6, "complexity": 2, "token_count": 40, "parameters": [ "self" ], "start_line": 43, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "absoftfcompiler.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "self" ], "start_line": 50, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f77", "long_name": "get_flags_f77( self )", "filename": "absoftfcompiler.py", "nloc": 11, "complexity": 4, "token_count": 70, "parameters": [ "self" ], "start_line": 56, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_flags_f90", "long_name": "get_flags_f90( self )", "filename": "absoftfcompiler.py", "nloc": 5, "complexity": 1, "token_count": 35, "parameters": [ "self" ], "start_line": 70, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_fix", "long_name": "get_flags_fix( self )", "filename": "absoftfcompiler.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 76, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "absoftfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 83, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "absoftfcompiler.py", "nloc": 6, "complexity": 2, "token_count": 40, "parameters": [ "self" ], "start_line": 43, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 } ], "nloc": 70, "complexity": 13, "token_count": 425, "diff_parsed": { "added": [ " opt.extend(['fio','f90math','fmath'])" ], "deleted": [ " opt.extend(['fio','f77math','f90math'])" ] } }, { "old_path": "scipy_distutils/ccompiler.py", "new_path": "scipy_distutils/ccompiler.py", "filename": "ccompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -157,12 +157,6 @@ def CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n- \n- # MSVC doesn't appear to have compiler defined?? This\n- # was a hack added by Travis O.\n- if not hasattr(self,'compiler'):\n- return\n- \n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n", "added_lines": 0, "deleted_lines": 6, "source_code": "\nimport re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import compiler_to_string\nfrom distutils.spawn import _nt_quote_args \n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if type(display) is type([]): display = ' '.join(display)\n log.info(display)\n if type(cmd) is type([]) and os.name == 'nt':\n cmd = _nt_quote_args(cmd)\n s,o = exec_command(cmd)\n if os.name != 'posix': \n print \" \".join(cmd)\n print o\n if s:\n if type(cmd) is type([]):\n cmd = ' '.join(cmd)\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n \n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n \n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n print '*'*80\n print self.__class__\n print compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n if not (hasattr(self,'version_cmd') and\n hasattr(self,'version_pattern')):\n log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n % (self.__class__))\n return\n\n cmd = ' '.join(self.version_cmd)\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n m = re.match(self.version_pattern,output)\n if m:\n version = m.group('version')\n assert version,`version`\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if os.environ.get('OSTYPE','')=='msys' or \\\n os.environ.get('MSYSTEM','')=='MINGW32':\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from scipy_distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n\n module_name = \"scipy_distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n", "source_code_before": "\nimport re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import compiler_to_string\nfrom distutils.spawn import _nt_quote_args \n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if type(display) is type([]): display = ' '.join(display)\n log.info(display)\n if type(cmd) is type([]) and os.name == 'nt':\n cmd = _nt_quote_args(cmd)\n s,o = exec_command(cmd)\n if os.name != 'posix': \n print \" \".join(cmd)\n print o\n if s:\n if type(cmd) is type([]):\n cmd = ' '.join(cmd)\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n \n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n \n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n print '*'*80\n print self.__class__\n print compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n \n # MSVC doesn't appear to have compiler defined?? This\n # was a hack added by Travis O.\n if not hasattr(self,'compiler'):\n return\n \n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n if not (hasattr(self,'version_cmd') and\n hasattr(self,'version_pattern')):\n log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n % (self.__class__))\n return\n\n cmd = ' '.join(self.version_cmd)\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n m = re.match(self.version_pattern,output)\n if m:\n version = m.group('version')\n assert version,`version`\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if os.environ.get('OSTYPE','')=='msys' or \\\n os.environ.get('MSYSTEM','')=='MINGW32':\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from scipy_distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n\n module_name = \"scipy_distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n", "methods": [ { "name": "CCompiler_spawn", "long_name": "CCompiler_spawn( self , cmd , display = None )", "filename": "ccompiler.py", "nloc": 16, "complexity": 8, "token_count": 127, "parameters": [ "self", "cmd", "display" ], "start_line": 18, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_object_filenames", "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", "filename": "ccompiler.py", "nloc": 21, "complexity": 6, "token_count": 185, "parameters": [ "self", "source_filenames", "strip_dir", "output_dir" ], "start_line": 36, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "CCompiler_compile", "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "ccompiler.py", "nloc": 39, "complexity": 10, "token_count": 323, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 63, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 0 }, { "name": "CCompiler_customize_cmd", "long_name": "CCompiler_customize_cmd( self , cmd )", "filename": "ccompiler.py", "nloc": 20, "complexity": 10, "token_count": 200, "parameters": [ "self", "cmd" ], "start_line": 110, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_show_customization", "long_name": "CCompiler_show_customization( self )", "filename": "ccompiler.py", "nloc": 15, "complexity": 5, "token_count": 81, "parameters": [ "self" ], "start_line": 136, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 15, "complexity": 6, "token_count": 144, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 156, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_get_version", "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", "filename": "ccompiler.py", "nloc": 19, "complexity": 7, "token_count": 135, "parameters": [ "self", "force", "ok_status" ], "start_line": 176, "end_line": 196, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "new_compiler", "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "ccompiler.py", "nloc": 38, "complexity": 8, "token_count": 184, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 215, "end_line": 254, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 } ], "methods_before": [ { "name": "CCompiler_spawn", "long_name": "CCompiler_spawn( self , cmd , display = None )", "filename": "ccompiler.py", "nloc": 16, "complexity": 8, "token_count": 127, "parameters": [ "self", "cmd", "display" ], "start_line": 18, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_object_filenames", "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", "filename": "ccompiler.py", "nloc": 21, "complexity": 6, "token_count": 185, "parameters": [ "self", "source_filenames", "strip_dir", "output_dir" ], "start_line": 36, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "CCompiler_compile", "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "ccompiler.py", "nloc": 39, "complexity": 10, "token_count": 323, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 63, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 0 }, { "name": "CCompiler_customize_cmd", "long_name": "CCompiler_customize_cmd( self , cmd )", "filename": "ccompiler.py", "nloc": 20, "complexity": 10, "token_count": 200, "parameters": [ "self", "cmd" ], "start_line": 110, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_show_customization", "long_name": "CCompiler_show_customization( self )", "filename": "ccompiler.py", "nloc": 15, "complexity": 5, "token_count": 81, "parameters": [ "self" ], "start_line": 136, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 17, "complexity": 7, "token_count": 154, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 156, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_get_version", "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", "filename": "ccompiler.py", "nloc": 19, "complexity": 7, "token_count": 135, "parameters": [ "self", "force", "ok_status" ], "start_line": 182, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "new_compiler", "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "ccompiler.py", "nloc": 38, "complexity": 8, "token_count": 184, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 221, "end_line": 260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 17, "complexity": 7, "token_count": 154, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 156, "end_line": 177, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "nloc": 218, "complexity": 60, "token_count": 1615, "diff_parsed": { "added": [], "deleted": [ "", " # MSVC doesn't appear to have compiler defined?? This", " # was a hack added by Travis O.", " if not hasattr(self,'compiler'):", " return", "" ] } } ] }, { "hash": "4d2ead9b70e451408cb184f19c692814ec4781ca", "msg": "Added compiler flag for versions later than Absoft 6.2 so that compiler will free memory on encountering a dealloc.", "author": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "committer": { "name": "Travis Oliphant", "email": "oliphant@enthought.com" }, "author_date": "2004-03-11T21:54:41+00:00", "author_timezone": 0, "committer_date": "2004-03-11T21:54:41+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "8d935d1126580300b0340a5ef65b4ec6378a50d9" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 0, "insertions": 3, "lines": 3, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/absoftfcompiler.py", "new_path": "scipy_distutils/absoftfcompiler.py", "filename": "absoftfcompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -71,6 +71,9 @@ def get_flags_f90(self):\n opt = FCompiler.get_flags_f90(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n+ if self.get_version():\n+ if self.get_version()>'4.6':\n+ opt.extend([\"-YDEALLOC=ALL\"]) \n return opt\n \n def get_flags_fix(self):\n", "added_lines": 3, "deleted_lines": 0, "source_code": "\n# http://www.absoft.com/literature/osxuserguide.pdf\n# http://www.absoft.com/documentation.html\n\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler, dummy_fortran_file\n\nclass AbsoftFCompiler(FCompiler):\n\n compiler_type = 'absoft'\n version_pattern = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n\n # samt5735(8)$ f90 -V -c dummy.f\n # f90: Copyright Absoft Corporation 1994-2002; Absoft Pro FORTRAN Version 8.0\n # Note that fink installs g77 as f77, so need to use f90 for detection.\n\n executables = {\n 'version_cmd' : [\"f77\", \"-V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':dummy_fortran_file()}],\n 'compiler_f77' : [\"f77\"],\n 'compiler_fix' : [\"f90\"],\n 'compiler_f90' : [\"f90\"],\n 'linker_so' : [\"f77\",\"-shared\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\n if os.name != 'nt':\n pic_flags = ['-fpic']\n module_dir_switch = None\n module_include_switch = '-p'\n\n def get_library_dirs(self):\n opt = FCompiler.get_library_dirs(self)\n d = os.environ.get('ABSOFT')\n if d:\n opt.append(os.path.join(d,'LIB'))\n return opt\n\n def get_libraries(self):\n opt = FCompiler.get_libraries(self)\n opt.extend(['fio','f90math','fmath'])\n if os.name =='nt':\n opt.append('COMDLG32')\n return opt\n\n def get_flags(self):\n opt = FCompiler.get_flags(self)\n if os.name != 'nt':\n opt.extend(['-s'])\n return opt\n\n def get_flags_f77(self):\n opt = FCompiler.get_flags_f77(self)\n opt.extend(['-N22','-N90','-N110'])\n if os.name != 'nt':\n opt.append('-f')\n if self.get_version():\n if self.get_version()<='4.6':\n opt.append('-B108')\n else:\n # Though -N15 is undocumented, it works with\n # Absoft 8.0 on Linux\n opt.append('-N15')\n return opt\n\n def get_flags_f90(self):\n opt = FCompiler.get_flags_f90(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n if self.get_version():\n if self.get_version()>'4.6':\n opt.extend([\"-YDEALLOC=ALL\"]) \n return opt\n\n def get_flags_fix(self):\n opt = FCompiler.get_flags_fix(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n opt.extend([\"-f\",\"fixed\"])\n return opt\n\n def get_flags_opt(self):\n opt = ['-O']\n return opt\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='absoft')\n compiler.customize()\n print compiler.get_version()\n", "source_code_before": "\n# http://www.absoft.com/literature/osxuserguide.pdf\n# http://www.absoft.com/documentation.html\n\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler, dummy_fortran_file\n\nclass AbsoftFCompiler(FCompiler):\n\n compiler_type = 'absoft'\n version_pattern = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n\n # samt5735(8)$ f90 -V -c dummy.f\n # f90: Copyright Absoft Corporation 1994-2002; Absoft Pro FORTRAN Version 8.0\n # Note that fink installs g77 as f77, so need to use f90 for detection.\n\n executables = {\n 'version_cmd' : [\"f77\", \"-V -c %(fname)s.f -o %(fname)s.o\" \\\n % {'fname':dummy_fortran_file()}],\n 'compiler_f77' : [\"f77\"],\n 'compiler_fix' : [\"f90\"],\n 'compiler_f90' : [\"f90\"],\n 'linker_so' : [\"f77\",\"-shared\"],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\n if os.name != 'nt':\n pic_flags = ['-fpic']\n module_dir_switch = None\n module_include_switch = '-p'\n\n def get_library_dirs(self):\n opt = FCompiler.get_library_dirs(self)\n d = os.environ.get('ABSOFT')\n if d:\n opt.append(os.path.join(d,'LIB'))\n return opt\n\n def get_libraries(self):\n opt = FCompiler.get_libraries(self)\n opt.extend(['fio','f90math','fmath'])\n if os.name =='nt':\n opt.append('COMDLG32')\n return opt\n\n def get_flags(self):\n opt = FCompiler.get_flags(self)\n if os.name != 'nt':\n opt.extend(['-s'])\n return opt\n\n def get_flags_f77(self):\n opt = FCompiler.get_flags_f77(self)\n opt.extend(['-N22','-N90','-N110'])\n if os.name != 'nt':\n opt.append('-f')\n if self.get_version():\n if self.get_version()<='4.6':\n opt.append('-B108')\n else:\n # Though -N15 is undocumented, it works with\n # Absoft 8.0 on Linux\n opt.append('-N15')\n return opt\n\n def get_flags_f90(self):\n opt = FCompiler.get_flags_f90(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n return opt\n\n def get_flags_fix(self):\n opt = FCompiler.get_flags_fix(self)\n opt.extend([\"-YCFRL=1\",\"-YCOM_NAMES=LCS\",\"-YCOM_PFX\",\"-YEXT_PFX\",\n \"-YCOM_SFX=_\",\"-YEXT_SFX=_\",\"-YEXT_NAMES=LCS\"])\n opt.extend([\"-f\",\"fixed\"])\n return opt\n\n def get_flags_opt(self):\n opt = ['-O']\n return opt\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='absoft')\n compiler.customize()\n print compiler.get_version()\n", "methods": [ { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "absoftfcompiler.py", "nloc": 6, "complexity": 2, "token_count": 43, "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": "get_libraries", "long_name": "get_libraries( self )", "filename": "absoftfcompiler.py", "nloc": 6, "complexity": 2, "token_count": 40, "parameters": [ "self" ], "start_line": 43, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "absoftfcompiler.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "self" ], "start_line": 50, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f77", "long_name": "get_flags_f77( self )", "filename": "absoftfcompiler.py", "nloc": 11, "complexity": 4, "token_count": 70, "parameters": [ "self" ], "start_line": 56, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_flags_f90", "long_name": "get_flags_f90( self )", "filename": "absoftfcompiler.py", "nloc": 8, "complexity": 3, "token_count": 59, "parameters": [ "self" ], "start_line": 70, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "get_flags_fix", "long_name": "get_flags_fix( self )", "filename": "absoftfcompiler.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 79, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "absoftfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 86, "end_line": 88, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 } ], "methods_before": [ { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "absoftfcompiler.py", "nloc": 6, "complexity": 2, "token_count": 43, "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": "get_libraries", "long_name": "get_libraries( self )", "filename": "absoftfcompiler.py", "nloc": 6, "complexity": 2, "token_count": 40, "parameters": [ "self" ], "start_line": 43, "end_line": 48, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "absoftfcompiler.py", "nloc": 5, "complexity": 2, "token_count": 30, "parameters": [ "self" ], "start_line": 50, "end_line": 54, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f77", "long_name": "get_flags_f77( self )", "filename": "absoftfcompiler.py", "nloc": 11, "complexity": 4, "token_count": 70, "parameters": [ "self" ], "start_line": 56, "end_line": 68, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_flags_f90", "long_name": "get_flags_f90( self )", "filename": "absoftfcompiler.py", "nloc": 5, "complexity": 1, "token_count": 35, "parameters": [ "self" ], "start_line": 70, "end_line": 74, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_fix", "long_name": "get_flags_fix( self )", "filename": "absoftfcompiler.py", "nloc": 6, "complexity": 1, "token_count": 45, "parameters": [ "self" ], "start_line": 76, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "absoftfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 83, "end_line": 85, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "get_flags_f90", "long_name": "get_flags_f90( self )", "filename": "absoftfcompiler.py", "nloc": 8, "complexity": 3, "token_count": 59, "parameters": [ "self" ], "start_line": 70, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 } ], "nloc": 73, "complexity": 15, "token_count": 449, "diff_parsed": { "added": [ " if self.get_version():", " if self.get_version()>'4.6':", " opt.extend([\"-YDEALLOC=ALL\"])" ], "deleted": [] } } ] }, { "hash": "c9165603cee9cdb8921e1a41f92267675d049b8b", "msg": "Use -framework Python only with apple python, fink python does not need it (as I have been told)", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-12T07:20:17+00:00", "author_timezone": 0, "committer_date": "2004-03-12T07:20:17+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "4d2ead9b70e451408cb184f19c692814ec4781ca" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 1, "insertions": 5, "lines": 6, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/gnufcompiler.py", "new_path": "scipy_distutils/gnufcompiler.py", "filename": "gnufcompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -48,7 +48,11 @@ class GnuFCompiler(FCompiler):\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n- opt.extend([\"-Wl,-framework\",\"-Wl,Python\",\"-lcc_dynamic\",\"-bundle\"])\n+ if sys.executable.startswith('/usr/bin'):\n+ # This is when Python is from Apple framework\n+ opt.extend([\"-Wl,-framework\",\"-Wl,Python\"])\n+ #else we are running in Fink python.\n+ opt.extend([\"-lcc_dynamic\",\"-bundle\"])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n", "added_lines": 5, "deleted_lines": 1, "source_code": "\nimport re\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler\nfrom exec_command import exec_command, find_executable\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\\n '(?P[^\\s*\\)]+)'\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n if sys.executable.startswith('/usr/bin'):\n # This is when Python is from Apple framework\n opt.extend([\"-Wl,-framework\",\"-Wl,Python\"])\n #else we are running in Fink python.\n opt.extend([\"-lcc_dynamic\",\"-bundle\"])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0) \n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n for g2c in ['g2c-pic','g2c']:\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if os.path.isfile(os.path.join(d,f)):\n break\n else:\n g2c = 'g2c'\n if sys.platform=='win32':\n opt.extend(['gcc',g2c])\n else:\n opt.append(g2c)\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n opt = ['-O3','-funroll-loops']\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break \n return opt\n march_flag = 1\n # 0.5.25 corresponds to 2.95.x\n if self.get_version() == '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n else:\n march_flag = 0\n # Note: gcc 3.2 on win32 has breakage with -march specified\n elif self.get_version() >= '3.1.1' \\\n and not sys.platform=='win32': # gcc >= 3.1.1\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK6_2():\n opt.append('-march=k6-2')\n elif cpu.is_AthlonK6_3():\n opt.append('-march=k6-3')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n elif cpu.is_AthlonMP():\n opt.append('-march=athlon-mp')\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_PentiumIV():\n opt.append('-march=pentium4')\n elif cpu.is_PentiumIII():\n opt.append('-march=pentium3')\n elif cpu.is_PentiumII():\n opt.append('-march=pentium2')\n else:\n march_flag = 0\n if cpu.has_mmx(): opt.append('-mmmx') \n if self.get_version() > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n else:\n march_flag = 0\n if march_flag:\n pass\n elif cpu.is_i686():\n opt.append('-march=i686')\n elif cpu.is_i586():\n opt.append('-march=i586')\n elif cpu.is_i486():\n opt.append('-march=i486')\n elif cpu.is_i386():\n opt.append('-march=i386')\n if cpu.is_Intel():\n opt.extend(['-malign-double','-fomit-frame-pointer'])\n return opt\n\nif __name__ == '__main__':\n from scipy_distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", "source_code_before": "\nimport re\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler\nfrom exec_command import exec_command, find_executable\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\\n '(?P[^\\s*\\)]+)'\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n opt.extend([\"-Wl,-framework\",\"-Wl,Python\",\"-lcc_dynamic\",\"-bundle\"])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0) \n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n for g2c in ['g2c-pic','g2c']:\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if os.path.isfile(os.path.join(d,f)):\n break\n else:\n g2c = 'g2c'\n if sys.platform=='win32':\n opt.extend(['gcc',g2c])\n else:\n opt.append(g2c)\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n opt = ['-O3','-funroll-loops']\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break \n return opt\n march_flag = 1\n # 0.5.25 corresponds to 2.95.x\n if self.get_version() == '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n else:\n march_flag = 0\n # Note: gcc 3.2 on win32 has breakage with -march specified\n elif self.get_version() >= '3.1.1' \\\n and not sys.platform=='win32': # gcc >= 3.1.1\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK6_2():\n opt.append('-march=k6-2')\n elif cpu.is_AthlonK6_3():\n opt.append('-march=k6-3')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n elif cpu.is_AthlonMP():\n opt.append('-march=athlon-mp')\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_PentiumIV():\n opt.append('-march=pentium4')\n elif cpu.is_PentiumIII():\n opt.append('-march=pentium3')\n elif cpu.is_PentiumII():\n opt.append('-march=pentium2')\n else:\n march_flag = 0\n if cpu.has_mmx(): opt.append('-mmmx') \n if self.get_version() > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n else:\n march_flag = 0\n if march_flag:\n pass\n elif cpu.is_i686():\n opt.append('-march=i686')\n elif cpu.is_i586():\n opt.append('-march=i586')\n elif cpu.is_i486():\n opt.append('-march=i486')\n elif cpu.is_i386():\n opt.append('-march=i386')\n if cpu.is_Intel():\n opt.extend(['-malign-double','-fomit-frame-pointer'])\n return opt\n\nif __name__ == '__main__':\n from scipy_distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", "methods": [ { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "gnufcompiler.py", "nloc": 11, "complexity": 4, "token_count": 73, "parameters": [ "self" ], "start_line": 48, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "get_libgcc_dir", "long_name": "get_libgcc_dir( self )", "filename": "gnufcompiler.py", "nloc": 6, "complexity": 2, "token_count": 41, "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": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "gnufcompiler.py", "nloc": 7, "complexity": 3, "token_count": 38, "parameters": [ "self" ], "start_line": 75, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "gnufcompiler.py", "nloc": 15, "complexity": 5, "token_count": 96, "parameters": [ "self" ], "start_line": 83, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "gnufcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 99, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "gnufcompiler.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 102, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "gnufcompiler.py", "nloc": 63, "complexity": 31, "token_count": 401, "parameters": [ "self" ], "start_line": 106, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 67, "top_nesting_level": 1 } ], "methods_before": [ { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "gnufcompiler.py", "nloc": 9, "complexity": 3, "token_count": 57, "parameters": [ "self" ], "start_line": 48, "end_line": 62, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "get_libgcc_dir", "long_name": "get_libgcc_dir( self )", "filename": "gnufcompiler.py", "nloc": 6, "complexity": 2, "token_count": 41, "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": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "gnufcompiler.py", "nloc": 7, "complexity": 3, "token_count": 38, "parameters": [ "self" ], "start_line": 71, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "gnufcompiler.py", "nloc": 15, "complexity": 5, "token_count": 96, "parameters": [ "self" ], "start_line": 79, "end_line": 93, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "gnufcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 95, "end_line": 96, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "gnufcompiler.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 98, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "gnufcompiler.py", "nloc": 63, "complexity": 31, "token_count": 401, "parameters": [ "self" ], "start_line": 102, "end_line": 168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 67, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "gnufcompiler.py", "nloc": 11, "complexity": 4, "token_count": 73, "parameters": [ "self" ], "start_line": 48, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 } ], "nloc": 140, "complexity": 47, "token_count": 848, "diff_parsed": { "added": [ " if sys.executable.startswith('/usr/bin'):", " # This is when Python is from Apple framework", " opt.extend([\"-Wl,-framework\",\"-Wl,Python\"])", " #else we are running in Fink python.", " opt.extend([\"-lcc_dynamic\",\"-bundle\"])" ], "deleted": [ " opt.extend([\"-Wl,-framework\",\"-Wl,Python\",\"-lcc_dynamic\",\"-bundle\"])" ] } } ] }, { "hash": "0bec5dcc37dd85bf86e5f14df9cd1ba154a7dab4", "msg": "changed /c to /compile_only for compaq visual (DF98)", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-12T14:24:44+00:00", "author_timezone": 0, "committer_date": "2004-03-12T14:24:44+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "c9165603cee9cdb8921e1a41f92267675d049b8b" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/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/compaqfcompiler.py", "new_path": "scipy_distutils/compaqfcompiler.py", "filename": "compaqfcompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -50,7 +50,7 @@ class CompaqVisualFCompiler(FCompiler):\n version_pattern = r'(DIGITAL|Compaq) Visual Fortran Optimizing Compiler'\\\n ' Version (?P[^\\s]*).*'\n \n- compile_switch = '/c '\n+ compile_switch = '/compile_only '\n object_switch = '/object:'\n library_switch = '/OUT:' #No space after /OUT:!\n \n", "added_lines": 1, "deleted_lines": 1, "source_code": "\n#http://www.compaq.com/fortran/docs/\n\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler\n\nclass CompaqFCompiler(FCompiler):\n\n compiler_type = 'compaq'\n version_pattern = r'Compaq Fortran (?P[^\\s]*).*'\n\n if sys.platform[:5]=='linux':\n fc_exe = 'fort'\n else:\n fc_exe = 'f90'\n\n executables = {\n 'version_cmd' : [fc_exe, \"-version\"],\n 'compiler_f77' : [fc_exe, \"-f77rtl\",\"-fixed\"],\n 'compiler_fix' : [fc_exe, \"-fixed\"],\n 'compiler_f90' : [fc_exe],\n 'linker_so' : [fc_exe],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\n module_dir_switch = None #XXX Fix me\n module_include_switch = None #XXX Fix me\n\n def get_flags(self):\n return ['-assume no2underscore','-nomixed_str_len_arg']\n def get_flags_debug(self):\n return ['-g','-check bounds']\n def get_flags_opt(self):\n return ['-O4','-align dcommons','-assume bigarrays',\n '-assume nozsize','-math_library fast']\n def get_flags_arch(self):\n return ['-arch host', '-tune host']\n def get_flags_linker_so(self):\n if sys.platform[:5]=='linux':\n return ['-shared']\n return ['-shared','-Wl,-expect_unresolved,*']\n\nclass CompaqVisualFCompiler(FCompiler):\n\n compiler_type = 'compaqv'\n version_pattern = r'(DIGITAL|Compaq) Visual Fortran Optimizing Compiler'\\\n ' Version (?P[^\\s]*).*'\n\n compile_switch = '/compile_only '\n object_switch = '/object:'\n library_switch = '/OUT:' #No space after /OUT:!\n\n static_lib_extension = \".lib\"\n static_lib_format = \"%s%s\"\n module_dir_switch = None #XXX Fix me\n module_include_switch = None #XXX Fix me\n\n ar_exe = 'lib.exe'\n fc_exe = 'DF'\n if sys.platform=='win32':\n from distutils.msvccompiler import MSVCCompiler\n ar_exe = MSVCCompiler().lib\n\n executables = {\n 'version_cmd' : ['DF', \"/what\"],\n 'compiler_f77' : ['DF', \"/f77rtl\",\"/fixed\"],\n 'compiler_fix' : ['DF', \"/fixed\"],\n 'compiler_f90' : ['DF'],\n 'linker_so' : ['DF'],\n 'archiver' : [ar_exe, \"/OUT:\"],\n 'ranlib' : None\n }\n\n def get_flags(self):\n return ['/nologo','/MD','/WX','/iface=(cref,nomixed_str_len_arg)',\n '/names:lowercase','/assume:underscore']\n def get_flags_opt(self):\n return ['/Ox','/fast','/optimize:5','/unroll:0','/math_library:fast']\n def get_flags_arch(self):\n return ['/threads']\n def get_flags_debug(self):\n return ['/debug']\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='compaq')\n compiler.customize()\n print compiler.get_version()\n", "source_code_before": "\n#http://www.compaq.com/fortran/docs/\n\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler\n\nclass CompaqFCompiler(FCompiler):\n\n compiler_type = 'compaq'\n version_pattern = r'Compaq Fortran (?P[^\\s]*).*'\n\n if sys.platform[:5]=='linux':\n fc_exe = 'fort'\n else:\n fc_exe = 'f90'\n\n executables = {\n 'version_cmd' : [fc_exe, \"-version\"],\n 'compiler_f77' : [fc_exe, \"-f77rtl\",\"-fixed\"],\n 'compiler_fix' : [fc_exe, \"-fixed\"],\n 'compiler_f90' : [fc_exe],\n 'linker_so' : [fc_exe],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\n module_dir_switch = None #XXX Fix me\n module_include_switch = None #XXX Fix me\n\n def get_flags(self):\n return ['-assume no2underscore','-nomixed_str_len_arg']\n def get_flags_debug(self):\n return ['-g','-check bounds']\n def get_flags_opt(self):\n return ['-O4','-align dcommons','-assume bigarrays',\n '-assume nozsize','-math_library fast']\n def get_flags_arch(self):\n return ['-arch host', '-tune host']\n def get_flags_linker_so(self):\n if sys.platform[:5]=='linux':\n return ['-shared']\n return ['-shared','-Wl,-expect_unresolved,*']\n\nclass CompaqVisualFCompiler(FCompiler):\n\n compiler_type = 'compaqv'\n version_pattern = r'(DIGITAL|Compaq) Visual Fortran Optimizing Compiler'\\\n ' Version (?P[^\\s]*).*'\n\n compile_switch = '/c '\n object_switch = '/object:'\n library_switch = '/OUT:' #No space after /OUT:!\n\n static_lib_extension = \".lib\"\n static_lib_format = \"%s%s\"\n module_dir_switch = None #XXX Fix me\n module_include_switch = None #XXX Fix me\n\n ar_exe = 'lib.exe'\n fc_exe = 'DF'\n if sys.platform=='win32':\n from distutils.msvccompiler import MSVCCompiler\n ar_exe = MSVCCompiler().lib\n\n executables = {\n 'version_cmd' : ['DF', \"/what\"],\n 'compiler_f77' : ['DF', \"/f77rtl\",\"/fixed\"],\n 'compiler_fix' : ['DF', \"/fixed\"],\n 'compiler_f90' : ['DF'],\n 'linker_so' : ['DF'],\n 'archiver' : [ar_exe, \"/OUT:\"],\n 'ranlib' : None\n }\n\n def get_flags(self):\n return ['/nologo','/MD','/WX','/iface=(cref,nomixed_str_len_arg)',\n '/names:lowercase','/assume:underscore']\n def get_flags_opt(self):\n return ['/Ox','/fast','/optimize:5','/unroll:0','/math_library:fast']\n def get_flags_arch(self):\n return ['/threads']\n def get_flags_debug(self):\n return ['/debug']\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='compaq')\n compiler.customize()\n print compiler.get_version()\n", "methods": [ { "name": "get_flags", "long_name": "get_flags( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 33, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 35, "end_line": 36, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "compaqfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 37, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 40, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "compaqfcompiler.py", "nloc": 4, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 42, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "compaqfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 78, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 81, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 83, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 85, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "get_flags", "long_name": "get_flags( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 33, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 35, "end_line": 36, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "compaqfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 37, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 40, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "compaqfcompiler.py", "nloc": 4, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 42, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "compaqfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 78, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 81, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 83, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 85, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 76, "complexity": 10, "token_count": 397, "diff_parsed": { "added": [ " compile_switch = '/compile_only '" ], "deleted": [ " compile_switch = '/c '" ] } } ] }, { "hash": "1a08dbbfcd2097776ad67c95e2f64b94c112b78b", "msg": "Fixed Apple python test", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-13T17:11:12+00:00", "author_timezone": 0, "committer_date": "2004-03-13T17:11:12+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "0bec5dcc37dd85bf86e5f14df9cd1ba154a7dab4" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/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/gnufcompiler.py", "new_path": "scipy_distutils/gnufcompiler.py", "filename": "gnufcompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -48,7 +48,7 @@ class GnuFCompiler(FCompiler):\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n- if sys.executable.startswith('/usr/bin'):\n+ if os.path.realpath(sys.executable).startswith('/System'):\n # This is when Python is from Apple framework\n opt.extend([\"-Wl,-framework\",\"-Wl,Python\"])\n #else we are running in Fink python.\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\nimport re\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler\nfrom exec_command import exec_command, find_executable\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\\n '(?P[^\\s*\\)]+)'\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n if os.path.realpath(sys.executable).startswith('/System'):\n # This is when Python is from Apple framework\n opt.extend([\"-Wl,-framework\",\"-Wl,Python\"])\n #else we are running in Fink python.\n opt.extend([\"-lcc_dynamic\",\"-bundle\"])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0) \n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n for g2c in ['g2c-pic','g2c']:\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if os.path.isfile(os.path.join(d,f)):\n break\n else:\n g2c = 'g2c'\n if sys.platform=='win32':\n opt.extend(['gcc',g2c])\n else:\n opt.append(g2c)\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n opt = ['-O3','-funroll-loops']\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break \n return opt\n march_flag = 1\n # 0.5.25 corresponds to 2.95.x\n if self.get_version() == '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n else:\n march_flag = 0\n # Note: gcc 3.2 on win32 has breakage with -march specified\n elif self.get_version() >= '3.1.1' \\\n and not sys.platform=='win32': # gcc >= 3.1.1\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK6_2():\n opt.append('-march=k6-2')\n elif cpu.is_AthlonK6_3():\n opt.append('-march=k6-3')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n elif cpu.is_AthlonMP():\n opt.append('-march=athlon-mp')\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_PentiumIV():\n opt.append('-march=pentium4')\n elif cpu.is_PentiumIII():\n opt.append('-march=pentium3')\n elif cpu.is_PentiumII():\n opt.append('-march=pentium2')\n else:\n march_flag = 0\n if cpu.has_mmx(): opt.append('-mmmx') \n if self.get_version() > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n else:\n march_flag = 0\n if march_flag:\n pass\n elif cpu.is_i686():\n opt.append('-march=i686')\n elif cpu.is_i586():\n opt.append('-march=i586')\n elif cpu.is_i486():\n opt.append('-march=i486')\n elif cpu.is_i386():\n opt.append('-march=i386')\n if cpu.is_Intel():\n opt.extend(['-malign-double','-fomit-frame-pointer'])\n return opt\n\nif __name__ == '__main__':\n from scipy_distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", "source_code_before": "\nimport re\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler\nfrom exec_command import exec_command, find_executable\n\nclass GnuFCompiler(FCompiler):\n\n compiler_type = 'gnu'\n version_pattern = r'GNU Fortran ((\\(GCC[^\\)]*(\\)\\)|\\)))|)\\s*'\\\n '(?P[^\\s*\\)]+)'\n\n # 'g77 --version' results\n # SunOS: GNU Fortran (GCC 3.2) 3.2 20020814 (release)\n # Debian: GNU Fortran (GCC) 3.3.3 20040110 (prerelease) (Debian)\n # GNU Fortran 0.5.25 20010319 (prerelease)\n # Redhat: GNU Fortran (GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-5)) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)\n\n for fc_exe in map(find_executable,['g77','f77']):\n if os.path.isfile(fc_exe):\n break\n executables = {\n 'version_cmd' : [fc_exe,\"--version\"],\n 'compiler_f77' : [fc_exe,\"-Wall\",\"-fno-second-underscore\"],\n 'compiler_f90' : None,\n 'compiler_fix' : None,\n 'linker_so' : [fc_exe],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"],\n }\n module_dir_switch = None\n module_include_switch = None\n\n # Cygwin: f771: warning: -fPIC ignored for target (all code is position independent)\n if os.name != 'nt' and sys.platform!='cygwin':\n pic_flags = ['-fPIC']\n\n #def get_linker_so(self):\n # # win32 linking should be handled by standard linker\n # # Darwin g77 cannot be used as a linker.\n # #if re.match(r'(darwin)', sys.platform):\n # # return\n # return FCompiler.get_linker_so(self)\n\n def get_flags_linker_so(self):\n opt = []\n if sys.platform=='darwin':\n if sys.executable.startswith('/usr/bin'):\n # This is when Python is from Apple framework\n opt.extend([\"-Wl,-framework\",\"-Wl,Python\"])\n #else we are running in Fink python.\n opt.extend([\"-lcc_dynamic\",\"-bundle\"])\n else:\n opt.append(\"-shared\")\n if sys.platform[:5]=='sunos':\n # SunOS often has dynamically loaded symbols defined in the\n # static library libg2c.a The linker doesn't like this. To\n # ignore the problem, use the -mimpure-text flag. It isn't\n # the safest thing, but seems to work. 'man gcc' says:\n # \".. Instead of using -mimpure-text, you should compile all\n # source code with -fpic or -fPIC.\"\n opt.append('-mimpure-text')\n return opt\n\n def get_libgcc_dir(self):\n status, output = exec_command('%s -print-libgcc-file-name' \\\n % (self.compiler_f77[0]),use_tee=0) \n if not status:\n return os.path.dirname(output)\n return\n\n def get_library_dirs(self):\n opt = []\n if sys.platform[:5] != 'linux':\n d = self.get_libgcc_dir()\n if d:\n opt.append(d)\n return opt\n\n def get_libraries(self):\n opt = []\n d = self.get_libgcc_dir()\n if d is not None:\n for g2c in ['g2c-pic','g2c']:\n f = self.static_lib_format % (g2c, self.static_lib_extension)\n if os.path.isfile(os.path.join(d,f)):\n break\n else:\n g2c = 'g2c'\n if sys.platform=='win32':\n opt.extend(['gcc',g2c])\n else:\n opt.append(g2c)\n return opt\n\n def get_flags_debug(self):\n return ['-g']\n\n def get_flags_opt(self):\n opt = ['-O3','-funroll-loops']\n return opt\n\n def get_flags_arch(self):\n opt = []\n if sys.platform=='darwin':\n if os.name != 'posix':\n # this should presumably correspond to Apple\n if cpu.is_ppc():\n opt.append('-arch ppc')\n elif cpu.is_i386():\n opt.append('-arch i386')\n for a in '601 602 603 603e 604 604e 620 630 740 7400 7450 750'\\\n '403 505 801 821 823 860'.split():\n if getattr(cpu,'is_ppc%s'%a)():\n opt.append('-mcpu='+a)\n opt.append('-mtune='+a)\n break \n return opt\n march_flag = 1\n # 0.5.25 corresponds to 2.95.x\n if self.get_version() == '0.5.26': # gcc 3.0\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n else:\n march_flag = 0\n # Note: gcc 3.2 on win32 has breakage with -march specified\n elif self.get_version() >= '3.1.1' \\\n and not sys.platform=='win32': # gcc >= 3.1.1\n if cpu.is_AthlonK6():\n opt.append('-march=k6')\n elif cpu.is_AthlonK6_2():\n opt.append('-march=k6-2')\n elif cpu.is_AthlonK6_3():\n opt.append('-march=k6-3')\n elif cpu.is_AthlonK7():\n opt.append('-march=athlon')\n elif cpu.is_AthlonMP():\n opt.append('-march=athlon-mp')\n # there's also: athlon-tbird, athlon-4, athlon-xp\n elif cpu.is_PentiumIV():\n opt.append('-march=pentium4')\n elif cpu.is_PentiumIII():\n opt.append('-march=pentium3')\n elif cpu.is_PentiumII():\n opt.append('-march=pentium2')\n else:\n march_flag = 0\n if cpu.has_mmx(): opt.append('-mmmx') \n if self.get_version() > '3.2.2':\n if cpu.has_sse2(): opt.append('-msse2')\n if cpu.has_sse(): opt.append('-msse')\n if cpu.has_3dnow(): opt.append('-m3dnow')\n else:\n march_flag = 0\n if march_flag:\n pass\n elif cpu.is_i686():\n opt.append('-march=i686')\n elif cpu.is_i586():\n opt.append('-march=i586')\n elif cpu.is_i486():\n opt.append('-march=i486')\n elif cpu.is_i386():\n opt.append('-march=i386')\n if cpu.is_Intel():\n opt.extend(['-malign-double','-fomit-frame-pointer'])\n return opt\n\nif __name__ == '__main__':\n from scipy_distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n #compiler = new_fcompiler(compiler='gnu')\n compiler = GnuFCompiler()\n compiler.customize()\n print compiler.get_version()\n", "methods": [ { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "gnufcompiler.py", "nloc": 11, "complexity": 4, "token_count": 80, "parameters": [ "self" ], "start_line": 48, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "get_libgcc_dir", "long_name": "get_libgcc_dir( self )", "filename": "gnufcompiler.py", "nloc": 6, "complexity": 2, "token_count": 41, "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": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "gnufcompiler.py", "nloc": 7, "complexity": 3, "token_count": 38, "parameters": [ "self" ], "start_line": 75, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "gnufcompiler.py", "nloc": 15, "complexity": 5, "token_count": 96, "parameters": [ "self" ], "start_line": 83, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "gnufcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 99, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "gnufcompiler.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 102, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "gnufcompiler.py", "nloc": 63, "complexity": 31, "token_count": 401, "parameters": [ "self" ], "start_line": 106, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 67, "top_nesting_level": 1 } ], "methods_before": [ { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "gnufcompiler.py", "nloc": 11, "complexity": 4, "token_count": 73, "parameters": [ "self" ], "start_line": 48, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 }, { "name": "get_libgcc_dir", "long_name": "get_libgcc_dir( self )", "filename": "gnufcompiler.py", "nloc": 6, "complexity": 2, "token_count": 41, "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": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "gnufcompiler.py", "nloc": 7, "complexity": 3, "token_count": 38, "parameters": [ "self" ], "start_line": 75, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "gnufcompiler.py", "nloc": 15, "complexity": 5, "token_count": 96, "parameters": [ "self" ], "start_line": 83, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "gnufcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 99, "end_line": 100, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "gnufcompiler.py", "nloc": 3, "complexity": 1, "token_count": 14, "parameters": [ "self" ], "start_line": 102, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "gnufcompiler.py", "nloc": 63, "complexity": 31, "token_count": 401, "parameters": [ "self" ], "start_line": 106, "end_line": 172, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 67, "top_nesting_level": 1 } ], "changed_methods": [ { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "gnufcompiler.py", "nloc": 11, "complexity": 4, "token_count": 80, "parameters": [ "self" ], "start_line": 48, "end_line": 66, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 1 } ], "nloc": 140, "complexity": 47, "token_count": 855, "diff_parsed": { "added": [ " if os.path.realpath(sys.executable).startswith('/System'):" ], "deleted": [ " if sys.executable.startswith('/usr/bin'):" ] } } ] }, { "hash": "8957ad32bf04dc802ae86caa8bcf11233679e976", "msg": "fixed typo", "author": { "name": "Travis Vaught", "email": "travis@enthought.com" }, "committer": { "name": "Travis Vaught", "email": "travis@enthought.com" }, "author_date": "2004-03-17T20:56:02+00:00", "author_timezone": 0, "committer_date": "2004-03-17T20:56:02+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "1a08dbbfcd2097776ad67c95e2f64b94c112b78b" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 1, "insertions": 4, "lines": 5, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/system_info.py", "new_path": "scipy_distutils/system_info.py", "filename": "system_info.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -775,7 +775,7 @@ def get_atlas_version(**config):\n from core import Extension, setup\n import log\n magic = hex(hash(`config`))\n- def atlas_version_c(extension, build_dir,macig=magic):\n+ def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n@@ -797,6 +797,9 @@ def atlas_version_c(extension, build_dir,macig=magic):\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n+ print \"##### msg: %s\" % msg\n+ if not msg:\n+ msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n \n", "added_lines": 4, "deleted_lines": 1, "source_code": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python\n agg2\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the \nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\n__revision__ = '$Id$'\n\nimport sys,os,re,types\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'x11':x11_info,\n 'fftw':fftw_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def set_info(self,**info):\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n if self.dir_env_var and os.environ.has_key(self.dir_env_var):\n d = os.environ[self.dir_env_var]\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n dirs = d.split(os.pathsep) + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n return default\n return [a.strip() for a in libs.split(',')]\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n lapack_libs = self.get_libs('lapack_libs',['lapack'])\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n atlas = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\nclass atlas_threads_info(atlas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,magic=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = []\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n print \"##### msg: %s\" % msg\n if not msg:\n msg = \"Unknown Exception\"\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if type(a) is types.StringType:\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n if 0:\n c = lapack_opt_info()\n c.verbosity = 2\n c.get_info()\n", "source_code_before": "#!/usr/bin/env python\n\"\"\"\nThis file defines a set of system_info classes for getting\ninformation about various resources (libraries, library directories,\ninclude directories, etc.) in the system. Currently, the following\nclasses are available:\n atlas_info\n atlas_threads_info\n atlas_blas_info\n atlas_blas_threads_info\n lapack_atlas_info\n blas_info\n lapack_info\n blas_opt_info # usage recommended\n lapack_opt_info # usage recommended\n fftw_info,dfftw_info,sfftw_info\n fftw_threads_info,dfftw_threads_info,sfftw_threads_info\n djbfft_info\n x11_info\n lapack_src_info\n blas_src_info\n numpy_info\n numarray_info\n boost_python\n agg2\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw','lapack','blas',\n 'lapack_src', 'blas_src', etc. For a complete list of allowed names,\n see the definition of get_info() function below.\n\n Returned info_dict is a dictionary which is compatible with\n distutils.setup keyword arguments. If info_dict == {}, then the\n asked resource is not available (system_info could not find it).\n\nGlobal parameters:\n system_info.search_static_first - search static libraries (.a)\n in precedence to shared ones (.so, .sl) if enabled.\n system_info.verbosity - output the results to stdout if enabled.\n\nThe file 'site.cfg' in the same directory as this module is read\nfor configuration options. The format is that used by ConfigParser (i.e.,\nWindows .INI style). The section DEFAULT has options that are the default\nfor each section. The available sections are fftw, atlas, and x11. Appropiate\ndefaults are used if nothing is specified.\n\nThe order of finding the locations of resources is the following:\n 1. environment variable\n 2. section in site.cfg\n 3. DEFAULT section in site.cfg\nOnly the first complete match is returned.\n\nExample:\n----------\n[DEFAULT]\nlibrary_dirs = /usr/lib:/usr/local/lib:/opt/lib\ninclude_dirs = /usr/include:/usr/local/include:/opt/include\nsrc_dirs = /usr/local/src:/opt/src\n# search static libraries (.a) in preference to shared ones (.so)\nsearch_static_first = 0\n\n[fftw]\nfftw_libs = rfftw, fftw\nfftw_opt_libs = rfftw_threaded, fftw_threaded\n# if the above aren't found, look for {s,d}fftw_libs and {s,d}fftw_opt_libs\n\n[atlas]\nlibrary_dirs = /usr/lib/3dnow:/usr/lib/3dnow/atlas\n# for overriding the names of the atlas libraries\natlas_libs = lapack, f77blas, cblas, atlas\n\n[x11]\nlibrary_dirs = /usr/X11R6/lib\ninclude_dirs = /usr/X11R6/include\n----------\n\nAuthors:\n Pearu Peterson , February 2002\n David M. Cooke , April 2002\n\nCopyright 2002 Pearu Peterson all rights reserved,\nPearu Peterson \nPermission to use, modify, and distribute this software is given under the \nterms of the SciPy (BSD style) license. See LICENSE.txt that came with\nthis distribution for specifics.\n\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\n__revision__ = '$Id$'\n\nimport sys,os,re,types\nimport warnings\nfrom distutils.errors import DistutilsError\nfrom glob import glob\nimport ConfigParser\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n default_lib_dirs = ['C:\\\\'] # probably not very helpful...\n default_include_dirs = []\n default_src_dirs = ['.']\n default_x11_lib_dirs = []\n default_x11_include_dirs = []\nelse:\n default_lib_dirs = ['/usr/local/lib', '/opt/lib', '/usr/lib',\n '/sw/lib']\n default_include_dirs = ['/usr/local/include',\n '/opt/include', '/usr/include',\n '/sw/include']\n default_src_dirs = ['.','/usr/local/src', '/opt/src','/sw/src']\n default_x11_lib_dirs = ['/usr/X11R6/lib','/usr/X11/lib','/usr/lib']\n default_x11_include_dirs = ['/usr/X11R6/include','/usr/X11/include',\n '/usr/include']\n\nif os.path.join(sys.prefix, 'lib') not in default_lib_dirs:\n default_lib_dirs.insert(0,os.path.join(sys.prefix, 'lib'))\n default_include_dirs.append(os.path.join(sys.prefix, 'include'))\n default_src_dirs.append(os.path.join(sys.prefix, 'src'))\n\ndefault_lib_dirs = filter(os.path.isdir, default_lib_dirs)\ndefault_include_dirs = filter(os.path.isdir, default_include_dirs)\ndefault_src_dirs = filter(os.path.isdir, default_src_dirs)\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name,notfound_action=0):\n \"\"\"\n notfound_action:\n 0 - do nothing\n 1 - display warning message\n 2 - raise error\n \"\"\"\n cl = {'atlas':atlas_info, # use lapack_opt or blas_opt instead\n 'atlas_threads':atlas_threads_info, # ditto\n 'atlas_blas':atlas_blas_info,\n 'atlas_blas_threads':atlas_blas_threads_info,\n 'lapack_atlas':lapack_atlas_info, # use lapack_opt instead\n 'lapack_atlas_threads':lapack_atlas_threads_info, # ditto\n 'x11':x11_info,\n 'fftw':fftw_info,\n 'dfftw':dfftw_info,\n 'sfftw':sfftw_info,\n 'fftw_threads':fftw_threads_info,\n 'dfftw_threads':dfftw_threads_info,\n 'sfftw_threads':sfftw_threads_info,\n 'djbfft':djbfft_info,\n 'blas':blas_info, # use blas_opt instead\n 'lapack':lapack_info, # use lapack_opt instead\n 'lapack_src':lapack_src_info,\n 'blas_src':blas_src_info,\n 'numpy':numpy_info,\n 'numarray':numarray_info,\n 'lapack_opt':lapack_opt_info,\n 'blas_opt':blas_opt_info,\n 'boost_python':boost_python_info,\n 'agg2':agg2_info,\n }.get(name.lower(),system_info)\n return cl().get_info(notfound_action)\n\nclass NotFoundError(DistutilsError):\n \"\"\"Some third-party program or library is not found.\"\"\"\n\nclass AtlasNotFoundError(NotFoundError):\n \"\"\"\n Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [atlas]) or by setting\n the ATLAS environment variable.\"\"\"\n\nclass LapackNotFoundError(NotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [lapack]) or by setting\n the LAPACK environment variable.\"\"\"\n\nclass LapackSrcNotFoundError(LapackNotFoundError):\n \"\"\"\n Lapack (http://www.netlib.org/lapack/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [lapack_src]) or by setting\n the LAPACK_SRC environment variable.\"\"\"\n\nclass BlasNotFoundError(NotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [blas]) or by setting\n the BLAS environment variable.\"\"\"\n\nclass BlasSrcNotFoundError(BlasNotFoundError):\n \"\"\"\n Blas (http://www.netlib.org/blas/) sources not found.\n Directories to search for the sources can be specified in the\n scipy_distutils/site.cfg file (section [blas_src]) or by setting\n the BLAS_SRC environment variable.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [fftw]) or by setting\n the FFTW environment variable.\"\"\"\n\nclass DJBFFTNotFoundError(NotFoundError):\n \"\"\"\n DJBFFT (http://cr.yp.to/djbfft.html) libraries not found.\n Directories to search for the libraries can be specified in the\n scipy_distutils/site.cfg file (section [djbfft]) or by setting\n the DJBFFT environment variable.\"\"\"\n\nclass F2pyNotFoundError(NotFoundError):\n \"\"\"\n f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass NumericNotFoundError(NotFoundError):\n \"\"\"\n Numeric (http://www.numpy.org/) module not found.\n Get it from above location, install it, and retry setup.py.\"\"\"\n\nclass X11NotFoundError(NotFoundError):\n \"\"\"X11 libraries not found.\"\"\"\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n section = 'DEFAULT'\n dir_env_var = None\n search_static_first = 0 # XXX: disabled by default, may disappear in\n # future unless it is proved to be useful.\n verbosity = 1\n saved_results = {}\n\n notfounderror = NotFoundError\n\n def __init__ (self,\n default_lib_dirs=default_lib_dirs,\n default_include_dirs=default_include_dirs,\n verbosity = 1,\n ):\n self.__class__.info = {}\n self.local_prefixes = []\n defaults = {}\n defaults['library_dirs'] = os.pathsep.join(default_lib_dirs)\n defaults['include_dirs'] = os.pathsep.join(default_include_dirs)\n defaults['src_dirs'] = os.pathsep.join(default_src_dirs)\n defaults['search_static_first'] = str(self.search_static_first)\n self.cp = ConfigParser.ConfigParser(defaults)\n try:\n __file__\n except NameError:\n __file__ = sys.argv[0]\n cf = os.path.join(os.path.split(os.path.abspath(__file__))[0],\n 'site.cfg')\n self.cp.read([cf])\n if not self.cp.has_section(self.section):\n self.cp.add_section(self.section)\n self.search_static_first = self.cp.getboolean(self.section,\n 'search_static_first')\n assert isinstance(self.search_static_first, type(0))\n\n def set_info(self,**info):\n self.saved_results[self.__class__.__name__] = info\n\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n\n def get_info(self,notfound_action=0):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n flag = 0\n if not self.has_info():\n flag = 1\n if self.verbosity>0:\n print self.__class__.__name__ + ':'\n if hasattr(self, 'calc_info'):\n self.calc_info()\n if notfound_action:\n if not self.has_info():\n if notfound_action==1:\n warnings.warn(self.notfounderror.__doc__)\n elif notfound_action==2:\n raise self.notfounderror,self.notfounderror.__doc__\n else:\n raise ValueError,`notfound_action`\n\n if self.verbosity>0:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n \n res = self.saved_results.get(self.__class__.__name__)\n if self.verbosity>0 and flag:\n for k,v in res.items():\n v = str(v)\n if k=='sources' and len(v)>200: v = v[:60]+' ...\\n... '+v[-60:]\n print ' %s = %s'%(k,v)\n print\n \n return res\n\n def get_paths(self, section, key):\n dirs = self.cp.get(section, key).split(os.pathsep)\n if self.dir_env_var and os.environ.has_key(self.dir_env_var):\n d = os.environ[self.dir_env_var]\n if os.path.isfile(d):\n dirs = [os.path.dirname(d)] + dirs\n l = getattr(self,'_lib_names',[])\n if len(l)==1:\n b = os.path.basename(d)\n b = os.path.splitext(b)[0]\n if b[:3]=='lib':\n print 'Replacing _lib_names[0]==%r with %r' \\\n % (self._lib_names[0], b[3:])\n self._lib_names[0] = b[3:]\n else:\n dirs = d.split(os.pathsep) + dirs\n default_dirs = self.cp.get('DEFAULT', key).split(os.pathsep)\n dirs.extend(default_dirs)\n ret = []\n [ret.append(d) for d in dirs if os.path.isdir(d) and d not in ret]\n if self.verbosity>1:\n print '(',key,'=',':'.join(ret),')'\n return ret\n\n def get_lib_dirs(self, key='library_dirs'):\n return self.get_paths(self.section, key)\n\n def get_include_dirs(self, key='include_dirs'):\n return self.get_paths(self.section, key)\n\n def get_src_dirs(self, key='src_dirs'):\n return self.get_paths(self.section, key)\n\n def get_libs(self, key, default):\n try:\n libs = self.cp.get(self.section, key)\n except ConfigParser.NoOptionError:\n return default\n return [a.strip() for a in libs.split(',')]\n\n def check_libs(self,lib_dir,libs,opt_libs =[]):\n \"\"\" If static or shared libraries are available then return\n their info dictionary. \"\"\"\n if self.search_static_first:\n exts = ['.a',so_ext]\n else:\n exts = [so_ext,'.a']\n if sys.platform=='cygwin':\n exts.append('.dll.a')\n for ext in exts:\n info = self._check_libs(lib_dir,libs,opt_libs,ext)\n if info is not None: return info\n\n def _lib_list(self, lib_dir, libs, ext):\n assert type(lib_dir) is type('')\n liblist = []\n for l in libs:\n p = self.combine_paths(lib_dir, 'lib'+l+ext)\n if p:\n assert len(p)==1\n liblist.append(p[0])\n return liblist\n\n def _extract_lib_names(self,libs):\n return [os.path.splitext(os.path.basename(p))[0][3:] \\\n for p in libs]\n\n def _check_libs(self,lib_dir,libs, opt_libs, ext):\n found_libs = self._lib_list(lib_dir, libs, ext)\n if len(found_libs) == len(libs):\n found_libs = self._extract_lib_names(found_libs)\n info = {'libraries' : found_libs, 'library_dirs' : [lib_dir]}\n opt_found_libs = self._lib_list(lib_dir, opt_libs, ext)\n if len(opt_found_libs) == len(opt_libs):\n opt_found_libs = self._extract_lib_names(opt_found_libs)\n info['libraries'].extend(opt_found_libs)\n return info\n\n def combine_paths(self,*args):\n return combine_paths(*args,**{'verbosity':self.verbosity})\n\nclass fftw_info(system_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw', 'fftw']\n includes = ['fftw.h','rfftw.h']\n macros = [('SCIPY_FFTW_H',None)]\n notfounderror = FFTWNotFoundError\n\n def __init__(self):\n system_info.__init__(self)\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n incl_dir = None\n libs = self.get_libs(self.section+'_libs', self.libs)\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs)\n if r is not None:\n info = r\n break\n if info is not None:\n flag = 0\n for d in incl_dirs:\n if len(self.combine_paths(d,self.includes))==2:\n dict_append(info,include_dirs=[d])\n flag = 1\n incl_dirs = [d]\n incl_dir = d\n break\n if flag:\n dict_append(info,define_macros=self.macros)\n else:\n info = None\n if info is not None:\n self.set_info(**info)\n\nclass dfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw','dfftw']\n includes = ['dfftw.h','drfftw.h']\n macros = [('SCIPY_DFFTW_H',None)]\n\nclass sfftw_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw','sfftw']\n includes = ['sfftw.h','srfftw.h']\n macros = [('SCIPY_SFFTW_H',None)]\n\nclass fftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['rfftw_threads','fftw_threads']\n includes = ['fftw_threads.h','rfftw_threads.h']\n macros = [('SCIPY_FFTW_THREADS_H',None)]\n\nclass dfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['drfftw_threads','dfftw_threads']\n includes = ['dfftw_threads.h','drfftw_threads.h']\n macros = [('SCIPY_DFFTW_THREADS_H',None)]\n\nclass sfftw_threads_info(fftw_info):\n section = 'fftw'\n dir_env_var = 'FFTW'\n libs = ['srfftw_threads','sfftw_threads']\n includes = ['sfftw_threads.h','srfftw_threads.h']\n macros = [('SCIPY_SFFTW_THREADS_H',None)]\n\nclass djbfft_info(system_info):\n section = 'djbfft'\n dir_env_var = 'DJBFFT'\n notfounderror = DJBFFTNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['djbfft'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n incl_dirs = self.get_include_dirs()\n info = None\n for d in lib_dirs:\n p = self.combine_paths (d,['djbfft.a'])\n if p:\n info = {'extra_objects':p}\n break\n p = self.combine_paths (d,['libdjbfft.a'])\n if p:\n info = {'libraries':['djbfft'],'library_dirs':[d]}\n break\n if info is None:\n return\n for d in incl_dirs:\n if len(self.combine_paths(d,['fftc8.h','fftfreq.h']))==2:\n dict_append(info,include_dirs=[d],\n define_macros=[('SCIPY_DJBFFT_H',None)])\n self.set_info(**info)\n return\n\n\nclass atlas_info(system_info):\n section = 'atlas'\n dir_env_var = 'ATLAS'\n _lib_names = ['f77blas','cblas']\n notfounderror = AtlasNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend(self.combine_paths(d,['atlas*','ATLAS*',\n 'sse','3dnow','sse2'])+[d])\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n lapack_libs = self.get_libs('lapack_libs',['lapack'])\n atlas = None\n lapack = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n lapack_atlas = self.check_libs(d,['lapack_atlas'],[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n for d2 in lib_dirs2:\n lapack = self.check_libs(d2,lapack_libs,[])\n if lapack is not None:\n break\n else:\n lapack = None\n if lapack is not None:\n break\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n if lapack is not None:\n dict_append(info,**lapack)\n dict_append(info,**atlas)\n elif 'lapack_atlas' in atlas['libraries']:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITH_LAPACK_ATLAS',None)])\n self.set_info(**info)\n return\n else:\n dict_append(info,**atlas)\n dict_append(info,define_macros=[('ATLAS_WITHOUT_LAPACK',None)])\n message = \"\"\"\n*********************************************************************\n Could not find lapack library within the ATLAS installation.\n*********************************************************************\n\"\"\"\n warnings.warn(message)\n self.set_info(**info)\n return\n # Check if lapack library is complete, only warn if it is not.\n lapack_dir = lapack['library_dirs'][0]\n lapack_name = lapack['libraries'][0]\n lapack_lib = None\n for e in ['.a',so_ext]:\n fn = os.path.join(lapack_dir,'lib'+lapack_name+e)\n if os.path.exists(fn):\n lapack_lib = fn\n break\n if lapack_lib is not None:\n sz = os.stat(lapack_lib)[6]\n if sz <= 4000*1024:\n message = \"\"\"\n*********************************************************************\n Lapack library (from ATLAS) is probably incomplete:\n size of %s is %sk (expected >4000k)\n\n Follow the instructions in the KNOWN PROBLEMS section of the file\n scipy/INSTALL.txt.\n*********************************************************************\n\"\"\" % (lapack_lib,sz/1024)\n warnings.warn(message)\n else:\n info['language'] = 'f77'\n\n self.set_info(**info)\n\nclass atlas_blas_info(atlas_info):\n _lib_names = ['f77blas','cblas']\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n info = {}\n atlas_libs = self.get_libs('atlas_libs',\n self._lib_names + ['atlas'])\n atlas = None\n atlas_1 = None\n for d in lib_dirs:\n atlas = self.check_libs(d,atlas_libs,[])\n if atlas is not None:\n lib_dirs2 = self.combine_paths(d,['atlas*','ATLAS*'])+[d]\n if atlas:\n atlas_1 = atlas\n print self.__class__\n if atlas is None:\n atlas = atlas_1\n if atlas is None:\n return\n include_dirs = self.get_include_dirs()\n h = (self.combine_paths(lib_dirs+include_dirs,'cblas.h') or [None])[0]\n if h:\n h = os.path.dirname(h)\n dict_append(info,include_dirs=[h])\n info['language'] = 'c'\n\n dict_append(info,**atlas)\n\n self.set_info(**info)\n return\n\nclass atlas_threads_info(atlas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass atlas_blas_threads_info(atlas_blas_info):\n _lib_names = ['ptf77blas','ptcblas']\n\nclass lapack_atlas_info(atlas_info):\n _lib_names = ['lapack_atlas'] + atlas_info._lib_names\n\nclass lapack_atlas_threads_info(atlas_threads_info):\n _lib_names = ['lapack_atlas'] + atlas_threads_info._lib_names\n\nclass lapack_info(system_info):\n section = 'lapack'\n dir_env_var = 'LAPACK'\n _lib_names = ['lapack']\n notfounderror = LapackNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n lapack_libs = self.get_libs('lapack_libs', self._lib_names)\n for d in lib_dirs:\n lapack = self.check_libs(d,lapack_libs,[])\n if lapack is not None:\n info = lapack \n break\n else:\n return\n info['language'] = 'f77'\n self.set_info(**info)\n\nclass lapack_src_info(system_info):\n section = 'lapack_src'\n dir_env_var = 'LAPACK_SRC'\n notfounderror = LapackSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['LAPACK*/SRC','SRC']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'dgesv.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n # The following is extracted from LAPACK-3.0/SRC/Makefile\n allaux='''\n ilaenv ieeeck lsame lsamen xerbla\n ''' # *.f\n laux = '''\n bdsdc bdsqr disna labad lacpy ladiv lae2 laebz laed0 laed1\n laed2 laed3 laed4 laed5 laed6 laed7 laed8 laed9 laeda laev2\n lagtf lagts lamch lamrg lanst lapy2 lapy3 larnv larrb larre\n larrf lartg laruv las2 lascl lasd0 lasd1 lasd2 lasd3 lasd4\n lasd5 lasd6 lasd7 lasd8 lasd9 lasda lasdq lasdt laset lasq1\n lasq2 lasq3 lasq4 lasq5 lasq6 lasr lasrt lassq lasv2 pttrf\n stebz stedc steqr sterf\n ''' # [s|d]*.f\n lasrc = '''\n gbbrd gbcon gbequ gbrfs gbsv gbsvx gbtf2 gbtrf gbtrs gebak\n gebal gebd2 gebrd gecon geequ gees geesx geev geevx gegs gegv\n gehd2 gehrd gelq2 gelqf gels gelsd gelss gelsx gelsy geql2\n geqlf geqp3 geqpf geqr2 geqrf gerfs gerq2 gerqf gesc2 gesdd\n gesv gesvd gesvx getc2 getf2 getrf getri getrs ggbak ggbal\n gges ggesx ggev ggevx ggglm gghrd gglse ggqrf ggrqf ggsvd\n ggsvp gtcon gtrfs gtsv gtsvx gttrf gttrs gtts2 hgeqz hsein\n hseqr labrd lacon laein lags2 lagtm lahqr lahrd laic1 lals0\n lalsa lalsd langb lange langt lanhs lansb lansp lansy lantb\n lantp lantr lapll lapmt laqgb laqge laqp2 laqps laqsb laqsp\n laqsy lar1v lar2v larf larfb larfg larft larfx largv larrv\n lartv larz larzb larzt laswp lasyf latbs latdf latps latrd\n latrs latrz latzm lauu2 lauum pbcon pbequ pbrfs pbstf pbsv\n pbsvx pbtf2 pbtrf pbtrs pocon poequ porfs posv posvx potf2\n potrf potri potrs ppcon ppequ pprfs ppsv ppsvx pptrf pptri\n pptrs ptcon pteqr ptrfs ptsv ptsvx pttrs ptts2 spcon sprfs\n spsv spsvx sptrf sptri sptrs stegr stein sycon syrfs sysv\n sysvx sytf2 sytrf sytri sytrs tbcon tbrfs tbtrs tgevc tgex2\n tgexc tgsen tgsja tgsna tgsy2 tgsyl tpcon tprfs tptri tptrs\n trcon trevc trexc trrfs trsen trsna trsyl trti2 trtri trtrs\n tzrqf tzrzf\n ''' # [s|c|d|z]*.f\n sd_lasrc = '''\n laexc lag2 lagv2 laln2 lanv2 laqtr lasy2 opgtr opmtr org2l\n org2r orgbr orghr orgl2 orglq orgql orgqr orgr2 orgrq orgtr\n orm2l orm2r ormbr ormhr orml2 ormlq ormql ormqr ormr2 ormr3\n ormrq ormrz ormtr rscl sbev sbevd sbevx sbgst sbgv sbgvd sbgvx\n sbtrd spev spevd spevx spgst spgv spgvd spgvx sptrd stev stevd\n stevr stevx syev syevd syevr syevx sygs2 sygst sygv sygvd\n sygvx sytd2 sytrd\n ''' # [s|d]*.f\n cz_lasrc = '''\n bdsqr hbev hbevd hbevx hbgst hbgv hbgvd hbgvx hbtrd hecon heev\n heevd heevr heevx hegs2 hegst hegv hegvd hegvx herfs hesv\n hesvx hetd2 hetf2 hetrd hetrf hetri hetrs hpcon hpev hpevd\n hpevx hpgst hpgv hpgvd hpgvx hprfs hpsv hpsvx hptrd hptrf\n hptri hptrs lacgv lacp2 lacpy lacrm lacrt ladiv laed0 laed7\n laed8 laesy laev2 lahef lanhb lanhe lanhp lanht laqhb laqhe\n laqhp larcm larnv lartg lascl laset lasr lassq pttrf rot spmv\n spr stedc steqr symv syr ung2l ung2r ungbr unghr ungl2 unglq\n ungql ungqr ungr2 ungrq ungtr unm2l unm2r unmbr unmhr unml2\n unmlq unmql unmqr unmr2 unmr3 unmrq unmrz unmtr upgtr upmtr\n ''' # [c|z]*.f\n #######\n sclaux = laux + ' econd ' # s*.f\n dzlaux = laux + ' secnd ' # d*.f\n slasrc = lasrc + sd_lasrc # s*.f\n dlasrc = lasrc + sd_lasrc # d*.f\n clasrc = lasrc + cz_lasrc + ' srot srscl ' # c*.f\n zlasrc = lasrc + cz_lasrc + ' drot drscl ' # z*.f\n oclasrc = ' icmax1 scsum1 ' # *.f\n ozlasrc = ' izmax1 dzsum1 ' # *.f\n sources = ['s%s.f'%f for f in (sclaux+slasrc).split()] \\\n + ['d%s.f'%f for f in (dzlaux+dlasrc).split()] \\\n + ['c%s.f'%f for f in (clasrc).split()] \\\n + ['z%s.f'%f for f in (zlasrc).split()] \\\n + ['%s.f'%f for f in (allaux+oclasrc+ozlasrc).split()]\n sources = [os.path.join(src_dir,f) for f in sources]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\natlas_version_c_text = r'''\n/* This file is generated from scipy_distutils/system_info.py */\n#ifdef __CPLUSPLUS__\nextern \"C\" {\n#endif\n#include \"Python.h\"\nstatic PyMethodDef module_methods[] = { {NULL,NULL} };\nDL_EXPORT(void) initatlas_version(void) {\n void ATL_buildinfo(void);\n ATL_buildinfo();\n Py_InitModule(\"atlas_version\", module_methods);\n}\n#ifdef __CPLUSCPLUS__\n}\n#endif\n'''\n\ndef get_atlas_version(**config):\n from core import Extension, setup\n import log\n magic = hex(hash(`config`))\n def atlas_version_c(extension, build_dir,macig=magic):\n source = os.path.join(build_dir,'atlas_version_%s.c' % (magic))\n if os.path.isfile(source):\n from distutils.dep_util import newer\n if newer(source,__file__):\n return source\n f = open(source,'w')\n f.write(atlas_version_c_text)\n f.close()\n return source\n ext = Extension('atlas_version',\n sources=[atlas_version_c],\n **config)\n extra_args = []\n for a in sys.argv:\n if re.match('[-][-]compiler[=]',a):\n extra_args.append(a)\n try:\n dist = setup(ext_modules=[ext],\n script_name = 'get_atlas_version',\n script_args = ['build_src','build_ext']+extra_args)\n except Exception,msg:\n log.warn(msg)\n return None\n\n from distutils.sysconfig import get_config_var\n so_ext = get_config_var('SO')\n build_ext = dist.get_command_obj('build_ext')\n target = os.path.join(build_ext.build_lib,'atlas_version'+so_ext)\n from exec_command import exec_command,get_pythonexe\n cmd = [get_pythonexe(),'-c',\n '\"import imp;imp.load_dynamic(\\\\\"atlas_version\\\\\",\\\\\"%s\\\\\")\"'\\\n % (os.path.basename(target))]\n s,o = exec_command(cmd,execute_in=os.path.dirname(target),use_tee=0)\n atlas_version = None\n if not s:\n m = re.match(r'ATLAS version (?P\\d+[.]\\d+[.]\\d+)',o)\n if m:\n atlas_version = m.group('version')\n if atlas_version is None:\n if re.search(r'undefined symbol: ATL_buildinfo',o,re.M):\n atlas_version = '3.2.1_pre3.3.6'\n else:\n print 'Command:',' '.join(cmd)\n print 'Status:',s\n print 'Output:',o\n return atlas_version\n\n\nclass lapack_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas')\n #atlas_info = {} ## uncomment for testing\n atlas_version = None\n need_lapack = 0\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n l = atlas_info.get('define_macros',[])\n if ('ATLAS_WITH_LAPACK_ATLAS',None) in l \\\n or ('ATLAS_WITHOUT_LAPACK',None) in l:\n need_lapack = 1\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n need_lapack = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_lapack:\n lapack_info = get_info('lapack')\n #lapack_info = {} ## uncomment for testing\n if lapack_info:\n dict_append(info,**lapack_info)\n else:\n warnings.warn(LapackNotFoundError.__doc__)\n lapack_src_info = get_info('lapack_src')\n if not lapack_src_info:\n warnings.warn(LapackSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('flapack_src',lapack_src_info)])\n\n if need_blas:\n blas_info = get_info('blas')\n #blas_info = {} ## uncomment for testing\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_opt_info(system_info):\n \n def calc_info(self):\n\n if sys.platform=='darwin' and not os.environ.get('ATLAS',None):\n args = []\n link_args = []\n if os.path.exists('/System/Library/Frameworks/Accelerate.framework/'):\n args.extend(['-faltivec','-framework','Accelerate'])\n link_args.extend(['-Wl,-framework','-Wl,Accelerate'])\n elif os.path.exists('/System/Library/Frameworks/vecLib.framework/'):\n args.extend(['-faltivec','-framework','vecLib'])\n link_args.extend(['-Wl,-framework','-Wl,vecLib'])\n if args:\n self.set_info(extra_compile_args=args,\n extra_link_args=link_args,\n define_macros=[('NO_ATLAS_INFO',3)])\n return\n\n atlas_info = get_info('atlas_blas_threads')\n if not atlas_info:\n atlas_info = get_info('atlas_blas')\n atlas_version = None\n need_blas = 0\n info = {}\n if atlas_info:\n version_info = atlas_info.copy()\n version_info['libraries'] = [version_info['libraries'][-1]]\n atlas_version = get_atlas_version(**version_info)\n if not atlas_info.has_key('define_macros'):\n atlas_info['define_macros'] = []\n if atlas_version is None:\n atlas_info['define_macros'].append(('NO_ATLAS_INFO',2))\n else:\n atlas_info['define_macros'].append(('ATLAS_INFO',\n '\"\\\\\"%s\\\\\"\"' % atlas_version))\n info = atlas_info\n else:\n warnings.warn(AtlasNotFoundError.__doc__)\n need_blas = 1\n dict_append(info,define_macros=[('NO_ATLAS_INFO',1)])\n\n if need_blas:\n blas_info = get_info('blas')\n if blas_info:\n dict_append(info,**blas_info)\n else:\n warnings.warn(BlasNotFoundError.__doc__)\n blas_src_info = get_info('blas_src')\n if not blas_src_info:\n warnings.warn(BlasSrcNotFoundError.__doc__)\n return\n dict_append(info,libraries=[('fblas_src',blas_src_info)])\n\n self.set_info(**info)\n return\n\n\nclass blas_info(system_info):\n section = 'blas'\n dir_env_var = 'BLAS'\n _lib_names = ['blas']\n notfounderror = BlasNotFoundError\n\n def calc_info(self):\n lib_dirs = self.get_lib_dirs()\n\n blas_libs = self.get_libs('blas_libs', self._lib_names)\n for d in lib_dirs:\n blas = self.check_libs(d,blas_libs,[])\n if blas is not None:\n info = blas \n break\n else:\n return\n info['language'] = 'f77' # XXX: is it generally true?\n self.set_info(**info)\n\n\nclass blas_src_info(system_info):\n section = 'blas_src'\n dir_env_var = 'BLAS_SRC'\n notfounderror = BlasSrcNotFoundError\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['blas']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'daxpy.f')):\n src_dir = d\n break\n if not src_dir:\n #XXX: Get sources from netlib. May be ask first.\n return\n blas1 = '''\n caxpy csscal dnrm2 dzasum saxpy srotg zdotc ccopy cswap drot\n dznrm2 scasum srotm zdotu cdotc dasum drotg icamax scnrm2\n srotmg zdrot cdotu daxpy drotm idamax scopy sscal zdscal crotg\n dcabs1 drotmg isamax sdot sswap zrotg cscal dcopy dscal izamax\n snrm2 zaxpy zscal csrot ddot dswap sasum srot zcopy zswap\n '''\n blas2 = '''\n cgbmv chpmv ctrsv dsymv dtrsv sspr2 strmv zhemv ztpmv cgemv\n chpr dgbmv dsyr lsame ssymv strsv zher ztpsv cgerc chpr2 dgemv\n dsyr2 sgbmv ssyr xerbla zher2 ztrmv cgeru ctbmv dger dtbmv\n sgemv ssyr2 zgbmv zhpmv ztrsv chbmv ctbsv dsbmv dtbsv sger\n stbmv zgemv zhpr chemv ctpmv dspmv dtpmv ssbmv stbsv zgerc\n zhpr2 cher ctpsv dspr dtpsv sspmv stpmv zgeru ztbmv cher2\n ctrmv dspr2 dtrmv sspr stpsv zhbmv ztbsv\n '''\n blas3 = '''\n cgemm csymm ctrsm dsyrk sgemm strmm zhemm zsyr2k chemm csyr2k\n dgemm dtrmm ssymm strsm zher2k zsyrk cher2k csyrk dsymm dtrsm\n ssyr2k zherk ztrmm cherk ctrmm dsyr2k ssyrk zgemm zsymm ztrsm\n '''\n sources = [os.path.join(src_dir,f+'.f') \\\n for f in (blas1+blas2+blas3).split()]\n #XXX: should we check here actual existence of source files?\n info = {'sources':sources,'language':'f77'}\n self.set_info(**info)\n\nclass x11_info(system_info):\n section = 'x11'\n notfounderror = X11NotFoundError\n\n def __init__(self):\n system_info.__init__(self,\n default_lib_dirs=default_x11_lib_dirs,\n default_include_dirs=default_x11_include_dirs)\n\n def calc_info(self):\n if sys.platform in ['win32']:\n return\n lib_dirs = self.get_lib_dirs()\n include_dirs = self.get_include_dirs()\n x11_libs = self.get_libs('x11_libs', ['X11'])\n for lib_dir in lib_dirs:\n info = self.check_libs(lib_dir, x11_libs, [])\n if info is not None:\n break\n else:\n return\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d, 'X11/X.h'):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n self.set_info(**info)\n\nclass numpy_info(system_info):\n section = 'numpy'\n modulename = 'Numeric'\n notfounderror = NumericNotFoundError\n\n def __init__(self):\n from distutils.sysconfig import get_python_inc\n include_dirs = []\n try:\n module = __import__(self.modulename)\n prefix = []\n for name in module.__file__.split(os.sep):\n if name=='lib':\n break\n prefix.append(name)\n include_dirs.append(get_python_inc(prefix=os.sep.join(prefix)))\n except ImportError:\n pass\n py_incl_dir = get_python_inc()\n include_dirs.append(py_incl_dir)\n for d in default_include_dirs:\n d = os.path.join(d, os.path.basename(py_incl_dir))\n if d not in include_dirs:\n include_dirs.append(d)\n system_info.__init__(self,\n default_lib_dirs=[],\n default_include_dirs=include_dirs)\n\n def calc_info(self):\n try:\n module = __import__(self.modulename)\n except ImportError:\n return\n info = {}\n macros = [(self.modulename.upper()+'_VERSION',\n '\"\\\\\"%s\\\\\"\"' % (module.__version__))]\n## try:\n## macros.append(\n## (self.modulename.upper()+'_VERSION_HEX',\n## hex(vstr2hex(module.__version__))),\n## )\n## except Exception,msg:\n## print msg\n dict_append(info, define_macros = macros)\n include_dirs = self.get_include_dirs()\n inc_dir = None\n for d in include_dirs:\n if self.combine_paths(d,\n os.path.join(self.modulename,\n 'arrayobject.h')):\n inc_dir = d\n break\n if inc_dir is not None:\n dict_append(info, include_dirs=[inc_dir])\n if info:\n self.set_info(**info)\n return\n\nclass numarray_info(numpy_info):\n section = 'numarray'\n modulename = 'numarray'\n\nclass boost_python_info(system_info):\n section = 'boost_python'\n dir_env_var = 'BOOST'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['boost*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n from distutils.sysconfig import get_python_inc\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'libs','python','src','module.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n py_incl_dir = get_python_inc()\n srcs_dir = os.path.join(src_dir,'libs','python','src')\n bpl_srcs = glob(os.path.join(srcs_dir,'*.cpp'))\n bpl_srcs += glob(os.path.join(srcs_dir,'*','*.cpp'))\n info = {'libraries':[('boost_python_src',{'include_dirs':[src_dir,py_incl_dir],\n 'sources':bpl_srcs})],\n 'include_dirs':[src_dir],\n }\n if info:\n self.set_info(**info)\n return\n\nclass agg2_info(system_info):\n section = 'agg2'\n dir_env_var = 'AGG2'\n\n def get_paths(self, section, key):\n pre_dirs = system_info.get_paths(self, section, key)\n dirs = []\n for d in pre_dirs:\n dirs.extend([d] + self.combine_paths(d,['agg2*']))\n return [ d for d in dirs if os.path.isdir(d) ]\n\n def calc_info(self):\n src_dirs = self.get_src_dirs()\n src_dir = ''\n for d in src_dirs:\n if os.path.isfile(os.path.join(d,'src','agg_affine_matrix.cpp')):\n src_dir = d\n break\n if not src_dir:\n return\n if sys.platform=='win32':\n agg2_srcs = glob(os.path.join(src_dir,'src','platform','win32','agg_win32_bmp.cpp'))\n else:\n agg2_srcs = glob(os.path.join(src_dir,'src','*.cpp'))\n agg2_srcs += [os.path.join(src_dir,'src','platform','X11','agg_platform_support.cpp')]\n \n info = {'libraries':[('agg2_src',{'sources':agg2_srcs,\n 'include_dirs':[os.path.join(src_dir,'include')],\n })],\n 'include_dirs':[os.path.join(src_dir,'include')],\n }\n if info:\n self.set_info(**info)\n return\n\n\n## def vstr2hex(version):\n## bits = []\n## n = [24,16,8,4,0]\n## r = 0\n## for s in version.split('.'):\n## r |= int(s) << n[0]\n## del n[0]\n## return r\n\n#--------------------------------------------------------------------\n\ndef combine_paths(*args,**kws):\n \"\"\" Return a list of existing paths composed by all combinations of\n items from arguments.\n \"\"\"\n r = []\n for a in args:\n if not a: continue\n if type(a) is types.StringType:\n a = [a]\n r.append(a)\n args = r\n if not args: return []\n if len(args)==1:\n result = reduce(lambda a,b:a+b,map(glob,args[0]),[])\n elif len (args)==2:\n result = []\n for a0 in args[0]:\n for a1 in args[1]:\n result.extend(glob(os.path.join(a0,a1)))\n else:\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n verbosity = kws.get('verbosity',1)\n if verbosity>1 and result:\n print '(','paths:',','.join(result),')'\n return result\n\nlanguage_map = {'c':0,'c++':1,'f77':2,'f90':3}\ninv_language_map = {0:'c',1:'c++',2:'f77',3:'f90'}\ndef dict_append(d,**kws):\n languages = []\n for k,v in kws.items():\n if k=='language':\n languages.append(v)\n continue\n if d.has_key(k):\n if k in ['library_dirs','include_dirs','define_macros']:\n [d[k].append(vv) for vv in v if vv not in d[k]]\n else:\n d[k].extend(v)\n else:\n d[k] = v\n if languages:\n l = inv_language_map[max([language_map.get(l,0) for l in languages])]\n d['language'] = l\n return\n\ndef show_all():\n import system_info\n import pprint\n match_info = re.compile(r'.*?_info').match\n for n in filter(match_info,dir(system_info)):\n if n in ['system_info','get_info']: continue\n c = getattr(system_info,n)()\n c.verbosity = 2\n r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n if 0:\n c = lapack_opt_info()\n c.verbosity = 2\n c.get_info()\n", "methods": [ { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 27, "complexity": 1, "token_count": 130, "parameters": [ "name", "notfound_action" ], "start_line": 129, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", "filename": "system_info.py", "nloc": 25, "complexity": 3, "token_count": 200, "parameters": [ "self", "default_lib_dirs", "default_include_dirs", "verbosity" ], "start_line": 241, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "set_info", "long_name": "set_info( self , ** info )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "info" ], "start_line": 267, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "has_info", "long_name": "has_info( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "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": "get_info", "long_name": "get_info( self , notfound_action = 0 )", "filename": "system_info.py", "nloc": 30, "complexity": 15, "token_count": 206, "parameters": [ "self", "notfound_action" ], "start_line": 273, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 23, "complexity": 10, "token_count": 252, "parameters": [ "self", "section", "key" ], "start_line": 310, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 334, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_include_dirs", "long_name": "get_include_dirs( self , key = 'include_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 337, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_src_dirs", "long_name": "get_src_dirs( self , key = 'src_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 340, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libs", "long_name": "get_libs( self , key , default )", "filename": "system_info.py", "nloc": 6, "complexity": 3, "token_count": 49, "parameters": [ "self", "key", "default" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_libs", "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", "filename": "system_info.py", "nloc": 10, "complexity": 5, "token_count": 76, "parameters": [ "self", "lib_dir", "libs", "opt_libs" ], "start_line": 350, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "_lib_list", "long_name": "_lib_list( self , lib_dir , libs , ext )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "lib_dir", "libs", "ext" ], "start_line": 363, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "_extract_lib_names", "long_name": "_extract_lib_names( self , libs )", "filename": "system_info.py", "nloc": 3, "complexity": 2, "token_count": 37, "parameters": [ "self", "libs" ], "start_line": 373, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_check_libs", "long_name": "_check_libs( self , lib_dir , libs , opt_libs , ext )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 99, "parameters": [ "self", "lib_dir", "libs", "opt_libs", "ext" ], "start_line": 377, "end_line": 386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( self , * args )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "args" ], "start_line": 388, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 399, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 26, "complexity": 8, "token_count": 150, "parameters": [ "self" ], "start_line": 402, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 469, "end_line": 474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 7, "token_count": 139, "parameters": [ "self" ], "start_line": 476, "end_line": 496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 7, "complexity": 4, "token_count": 74, "parameters": [ "self", "section", "key" ], "start_line": 505, "end_line": 511, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 78, "complexity": 17, "token_count": 441, "parameters": [ "self" ], "start_line": 513, "end_line": 592, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 80, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 27, "complexity": 8, "token_count": 176, "parameters": [ "self" ], "start_line": 597, "end_line": 625, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 645, "end_line": 657, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 68, "parameters": [ "self", "section", "key" ], "start_line": 664, "end_line": 669, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 81, "complexity": 10, "token_count": 232, "parameters": [ "self" ], "start_line": 671, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "magic" ], "start_line": 778, "end_line": 787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 44, "complexity": 9, "token_count": 280, "parameters": [ "config" ], "start_line": 774, "end_line": 827, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 67, "complexity": 18, "token_count": 431, "parameters": [ "self" ], "start_line": 832, "end_line": 906, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 50, "complexity": 13, "token_count": 331, "parameters": [ "self" ], "start_line": 911, "end_line": 964, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 973, "end_line": 985, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 993, "end_line": 998, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 34, "complexity": 5, "token_count": 106, "parameters": [ "self" ], "start_line": 1000, "end_line": 1035, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 1041, "end_line": 1044, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 20, "complexity": 7, "token_count": 114, "parameters": [ "self" ], "start_line": 1046, "end_line": 1065, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 139, "parameters": [ "self" ], "start_line": 1072, "end_line": 1093, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 121, "parameters": [ "self" ], "start_line": 1095, "end_line": 1123, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1133, "end_line": 1138, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 5, "token_count": 156, "parameters": [ "self" ], "start_line": 1140, "end_line": 1160, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1166, "end_line": 1171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 177, "parameters": [ "self" ], "start_line": 1173, "end_line": 1195, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( * args , ** kws )", "filename": "system_info.py", "nloc": 22, "complexity": 11, "token_count": 195, "parameters": [ "args", "kws" ], "start_line": 1209, "end_line": 1233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "system_info.py", "nloc": 17, "complexity": 9, "token_count": 128, "parameters": [ "d", "kws" ], "start_line": 1237, "end_line": 1253, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "show_all", "long_name": "show_all( )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 64, "parameters": [], "start_line": 1255, "end_line": 1263, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_info", "long_name": "get_info( name , notfound_action = 0 )", "filename": "system_info.py", "nloc": 27, "complexity": 1, "token_count": 130, "parameters": [ "name", "notfound_action" ], "start_line": 129, "end_line": 161, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 33, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , default_lib_dirs = default_lib_dirs , default_include_dirs = default_include_dirs , verbosity = 1 , )", "filename": "system_info.py", "nloc": 25, "complexity": 3, "token_count": 200, "parameters": [ "self", "default_lib_dirs", "default_include_dirs", "verbosity" ], "start_line": 241, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 1 }, { "name": "set_info", "long_name": "set_info( self , ** info )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "info" ], "start_line": 267, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "has_info", "long_name": "has_info( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 18, "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": "get_info", "long_name": "get_info( self , notfound_action = 0 )", "filename": "system_info.py", "nloc": 30, "complexity": 15, "token_count": 206, "parameters": [ "self", "notfound_action" ], "start_line": 273, "end_line": 308, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 23, "complexity": 10, "token_count": 252, "parameters": [ "self", "section", "key" ], "start_line": 310, "end_line": 332, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "get_lib_dirs", "long_name": "get_lib_dirs( self , key = 'library_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 334, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_include_dirs", "long_name": "get_include_dirs( self , key = 'include_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 337, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_src_dirs", "long_name": "get_src_dirs( self , key = 'src_dirs' )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 20, "parameters": [ "self", "key" ], "start_line": 340, "end_line": 341, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_libs", "long_name": "get_libs( self , key , default )", "filename": "system_info.py", "nloc": 6, "complexity": 3, "token_count": 49, "parameters": [ "self", "key", "default" ], "start_line": 343, "end_line": 348, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "check_libs", "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", "filename": "system_info.py", "nloc": 10, "complexity": 5, "token_count": 76, "parameters": [ "self", "lib_dir", "libs", "opt_libs" ], "start_line": 350, "end_line": 361, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "_lib_list", "long_name": "_lib_list( self , lib_dir , libs , ext )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 65, "parameters": [ "self", "lib_dir", "libs", "ext" ], "start_line": 363, "end_line": 371, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 1 }, { "name": "_extract_lib_names", "long_name": "_extract_lib_names( self , libs )", "filename": "system_info.py", "nloc": 3, "complexity": 2, "token_count": 37, "parameters": [ "self", "libs" ], "start_line": 373, "end_line": 375, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "_check_libs", "long_name": "_check_libs( self , lib_dir , libs , opt_libs , ext )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 99, "parameters": [ "self", "lib_dir", "libs", "opt_libs", "ext" ], "start_line": 377, "end_line": 386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( self , * args )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "self", "args" ], "start_line": 388, "end_line": 389, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 399, "end_line": 400, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 26, "complexity": 8, "token_count": 150, "parameters": [ "self" ], "start_line": 402, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 469, "end_line": 474, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 7, "token_count": 139, "parameters": [ "self" ], "start_line": 476, "end_line": 496, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 7, "complexity": 4, "token_count": 74, "parameters": [ "self", "section", "key" ], "start_line": 505, "end_line": 511, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 78, "complexity": 17, "token_count": 441, "parameters": [ "self" ], "start_line": 513, "end_line": 592, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 80, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 27, "complexity": 8, "token_count": 176, "parameters": [ "self" ], "start_line": 597, "end_line": 625, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 645, "end_line": 657, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 68, "parameters": [ "self", "section", "key" ], "start_line": 664, "end_line": 669, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 81, "complexity": 10, "token_count": 232, "parameters": [ "self" ], "start_line": 671, "end_line": 755, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 1 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , macig = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "macig" ], "start_line": 778, "end_line": 787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 41, "complexity": 8, "token_count": 269, "parameters": [ "config" ], "start_line": 774, "end_line": 824, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 51, "top_nesting_level": 0 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 67, "complexity": 18, "token_count": 431, "parameters": [ "self" ], "start_line": 829, "end_line": 903, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 50, "complexity": 13, "token_count": 331, "parameters": [ "self" ], "start_line": 908, "end_line": 961, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 12, "complexity": 3, "token_count": 68, "parameters": [ "self" ], "start_line": 970, "end_line": 982, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 990, "end_line": 995, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 34, "complexity": 5, "token_count": 106, "parameters": [ "self" ], "start_line": 997, "end_line": 1032, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 4, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 1038, "end_line": 1041, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 20, "complexity": 7, "token_count": 114, "parameters": [ "self" ], "start_line": 1043, "end_line": 1062, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 139, "parameters": [ "self" ], "start_line": 1069, "end_line": 1090, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 121, "parameters": [ "self" ], "start_line": 1092, "end_line": 1120, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 29, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1130, "end_line": 1135, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 21, "complexity": 5, "token_count": 156, "parameters": [ "self" ], "start_line": 1137, "end_line": 1157, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "get_paths", "long_name": "get_paths( self , section , key )", "filename": "system_info.py", "nloc": 6, "complexity": 4, "token_count": 66, "parameters": [ "self", "section", "key" ], "start_line": 1163, "end_line": 1168, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 1 }, { "name": "calc_info", "long_name": "calc_info( self )", "filename": "system_info.py", "nloc": 22, "complexity": 6, "token_count": 177, "parameters": [ "self" ], "start_line": 1170, "end_line": 1192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "combine_paths", "long_name": "combine_paths( * args , ** kws )", "filename": "system_info.py", "nloc": 22, "complexity": 11, "token_count": 195, "parameters": [ "args", "kws" ], "start_line": 1206, "end_line": 1230, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "system_info.py", "nloc": 17, "complexity": 9, "token_count": 128, "parameters": [ "d", "kws" ], "start_line": 1234, "end_line": 1250, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "show_all", "long_name": "show_all( )", "filename": "system_info.py", "nloc": 9, "complexity": 3, "token_count": 64, "parameters": [], "start_line": 1252, "end_line": 1260, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 9, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_atlas_version", "long_name": "get_atlas_version( ** config )", "filename": "system_info.py", "nloc": 44, "complexity": 9, "token_count": 280, "parameters": [ "config" ], "start_line": 774, "end_line": 827, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 54, "top_nesting_level": 0 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , macig = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "macig" ], "start_line": 778, "end_line": 787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "get_atlas_version.atlas_version_c", "long_name": "get_atlas_version.atlas_version_c( extension , build_dir , magic = magic )", "filename": "system_info.py", "nloc": 10, "complexity": 3, "token_count": 74, "parameters": [ "extension", "build_dir", "magic" ], "start_line": 778, "end_line": 787, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 } ], "nloc": 1112, "complexity": 234, "token_count": 6165, "diff_parsed": { "added": [ " def atlas_version_c(extension, build_dir,magic=magic):", " print \"##### msg: %s\" % msg", " if not msg:", " msg = \"Unknown Exception\"" ], "deleted": [ " def atlas_version_c(extension, build_dir,macig=magic):" ] } } ] }, { "hash": "208baf5040453401ffa6e26c8f48dd4e1917361a", "msg": "commented out call to recently commented out __get_cc_args", "author": { "name": "Travis Vaught", "email": "travis@enthought.com" }, "committer": { "name": "Travis Vaught", "email": "travis@enthought.com" }, "author_date": "2004-03-17T21:23:21+00:00", "author_timezone": 0, "committer_date": "2004-03-17T21:23:21+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "8957ad32bf04dc802ae86caa8bcf11233679e976" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/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/fcompiler.py", "new_path": "scipy_distutils/fcompiler.py", "filename": "fcompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -501,7 +501,7 @@ def compile(self, sources, output_dir=None, macros=None,\n ext = os.path.splitext(src)[1]\n self.mkpath(os.path.dirname(obj))\n build[obj] = src, ext\n- cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n+ cc_args = [] #self._get_cc_args(pp_opts, debug, extra_preargs)\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n return objects\n", "added_lines": 1, "deleted_lines": 1, "source_code": "\"\"\"scipy_distutils.fcompiler\n\nContains FCompiler, an abstract base class that defines the interface\nfor the Scipy_distutils Fortran compiler abstraction model.\n\n\"\"\"\n\nimport re\nimport os\nimport sys\nimport atexit\nfrom types import StringType, NoneType, ListType, TupleType\nfrom glob import glob\n\nfrom distutils.version import StrictVersion\nfrom scipy_distutils.ccompiler import CCompiler, gen_lib_options\n# distutils.ccompiler provides the following functions:\n# gen_preprocess_options(macros, include_dirs)\n# gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries)\nfrom distutils.errors import DistutilsModuleError,DistutilsArgError,\\\n DistutilsExecError,CompileError,LinkError,DistutilsPlatformError\nfrom distutils.core import Command\nfrom distutils.util import split_quoted\nfrom distutils.fancy_getopt import FancyGetopt\nfrom distutils.sysconfig import get_config_var\nfrom distutils.spawn import _nt_quote_args \n\n\nfrom scipy_distutils.command.config_compiler import config_fc\n\nimport log\nfrom misc_util import compiler_to_string\nfrom exec_command import find_executable, exec_command\n\nclass FCompiler(CCompiler):\n \"\"\" Abstract base class to define the interface that must be implemented\n by real Fortran compiler classes.\n\n Methods that subclasses may redefine:\n\n get_version_cmd(), get_linker_so(), get_version()\n get_flags(), get_flags_opt(), get_flags_arch(), get_flags_debug()\n get_flags_f77(), get_flags_opt_f77(), get_flags_arch_f77(),\n get_flags_debug_f77(), get_flags_f90(), get_flags_opt_f90(),\n get_flags_arch_f90(), get_flags_debug_f90(),\n get_flags_fix(), get_flags_linker_so(), get_flags_version()\n\n DON'T call these methods (except get_version) after\n constructing a compiler instance or inside any other method.\n All methods, except get_version_cmd() and get_flags_version(), may\n call get_version() method.\n\n After constructing a compiler instance, always call customize(dist=None)\n method that finalizes compiler construction and makes the following\n attributes available:\n compiler_f77\n compiler_f90\n compiler_fix\n linker_so\n archiver\n ranlib\n libraries\n library_dirs\n \"\"\"\n # CCompiler defines the following attributes:\n # compiler_type\n # src_extensions\n # obj_extension\n # static_lib_extension\n # shared_lib_extension\n # static_lib_format\n # shared_lib_format\n # exe_extension\n # language_map ### REDEFINED\n # language_order ### REDEFINED\n # and the following public methods:\n # set_executables(**args)\n # set_executable(key,value)\n # define_macro(name, value=None)\n # undefine_macro(name)\n # add_include_dir(dir)\n # set_include_dirs(dirs)\n # add_library(libname)\n # set_libraries(libnames)\n # add_library_dir(dir)\n # set_library_dirs(dirs)\n # add_runtime_library_dir(dir)\n # set_runtime_library_dirs(dirs)\n # add_link_object(object)\n # set_link_objects(objects)\n #\n # detect_language(sources) ### USABLE\n #\n # preprocess(source,output_file=None,macros=None,include_dirs=None,\n # extra_preargs=None,extra_postargs=None)\n # compile(sources, output_dir=None, macros=None,\n # include_dirs=None, debug=0, extra_preargs=None,\n # extra_postargs=None, depends=None)\n # create_static_lib(objects,output_libname,output_dir=None,debug=0,target_lang=None):\n # link(target_desc, objects, output_filename, output_dir=None,\n # libraries=None, library_dirs=None, runtime_library_dirs=None,\n # export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None,\n # build_temp=None, target_lang=None)\n # link_shared_lib(objects, output_libname, output_dir=None,\n # libraries=None, library_dirs=None, runtime_library_dirs=None,\n # export_symbols=None, debug=0, extra_preargs=None,\n # extra_postargs=None, build_temp=None, target_lang=None)\n # link_shared_object(objects,output_filename,output_dir=None,\n # libraries=None,library_dirs=None,runtime_library_dirs=None,\n # export_symbols=None,debug=0,extra_preargs=None,\n # extra_postargs=None,build_temp=None,target_lang=None)\n # link_executable(objects,output_progname,output_dir=None,\n # libraries=None,library_dirs=None,runtime_library_dirs=None,\n # debug=0,extra_preargs=None,extra_postargs=None,target_lang=None)\n #\n # library_dir_option(dir)\n # runtime_library_dir_option(dir)\n # library_option(lib)\n # has_function(funcname,includes=None,include_dirs=None,\n # libraries=None,library_dirs=None)\n # find_library_file(dirs, lib, debug=0)\n #\n # object_filenames(source_filenames, strip_dir=0, output_dir='')\n # shared_object_filename(basename, strip_dir=0, output_dir='')\n # executable_filenamee(basename, strip_dir=0, output_dir='')\n # library_filename(libname, lib_type='static',strip_dir=0, output_dir=''):\n #\n # announce(msg, level=1)\n # debug_print(msg)\n # warn(msg)\n # execute(func, args, msg=None, level=1)\n # spawn(cmd)\n # move_file(src,dst)\n # mkpath(name, mode=0777)\n #\n\n language_map = {'.f':'f77',\n '.for':'f77',\n '.ftn':'f77',\n '.f77':'f77',\n '.f90':'f90',\n '.f95':'f90'}\n language_order = ['f90','f77']\n\n version_pattern = None\n\n executables = {\n 'version_cmd' : [\"f77\",\"-v\"],\n 'compiler_f77' : [\"f77\"],\n 'compiler_f90' : [\"f90\"],\n 'compiler_fix' : [\"f90\",\"-fixed\"],\n 'linker_so' : [\"f90\",\"-shared\"],\n #'linker_exe' : [\"f90\"], # XXX do we need it??\n 'archiver' : [\"ar\",\"-cr\"],\n 'ranlib' : None,\n }\n\n compile_switch = \"-c\"\n object_switch = \"-o \" # Ending space matters! It will be stripped\n # but if it is missing then object_switch\n # will be prefixed to object file name by\n # string concatenation.\n library_switch = \"-o \" # Ditto!\n\n # Switch to specify where module files are created and searched\n # for USE statement. Normally it is a string and also here ending\n # space matters. See above.\n module_dir_switch = None\n\n # Switch to specify where module files are searched for USE statement.\n module_include_switch = '-I' \n\n pic_flags = [] # Flags to create position-independent code\n\n src_extensions = ['.for','.ftn','.f77','.f','.f90','.f95']\n obj_extension = \".o\"\n shared_lib_extension = get_config_var('SO') # or .dll\n static_lib_extension = \".a\" # or .lib\n static_lib_format = \"lib%s%s\" # or %s%s\n shared_lib_format = \"%s%s\"\n exe_extension = \"\"\n\n ######################################################################\n ## Methods that subclasses may redefine. But don't call these methods!\n ## They are private to FCompiler class and may return unexpected\n ## results if used elsewhere. So, you have been warned..\n\n def get_version_cmd(self):\n \"\"\" Compiler command to print out version information. \"\"\"\n f77 = self.executables['compiler_f77']\n if f77 is not None:\n f77 = f77[0]\n cmd = self.executables['version_cmd']\n if cmd is not None:\n cmd = cmd[0]\n if cmd==f77:\n cmd = self.compiler_f77[0]\n else:\n f90 = self.executables['compiler_f90']\n if f90 is not None:\n f90 = f90[0]\n if cmd==f90:\n cmd = self.compiler_f90[0]\n return cmd\n\n def get_linker_so(self):\n \"\"\" Linker command to build shared libraries. \"\"\"\n f77 = self.executables['compiler_f77']\n if f77 is not None:\n f77 = f77[0]\n ln = self.executables['linker_so']\n if ln is not None:\n ln = ln[0]\n if ln==f77:\n ln = self.compiler_f77[0]\n else:\n f90 = self.executables['compiler_f90']\n if f90 is not None:\n f90 = f90[0]\n if ln==f90:\n ln = self.compiler_f90[0]\n return ln\n\n def get_flags(self):\n \"\"\" List of flags common to all compiler types. \"\"\"\n return [] + self.pic_flags\n def get_flags_version(self):\n \"\"\" List of compiler flags to print out version information. \"\"\"\n if self.executables['version_cmd']:\n return self.executables['version_cmd'][1:]\n return []\n def get_flags_f77(self):\n \"\"\" List of Fortran 77 specific flags. \"\"\"\n if self.executables['compiler_f77']:\n return self.executables['compiler_f77'][1:]\n return []\n def get_flags_f90(self):\n \"\"\" List of Fortran 90 specific flags. \"\"\"\n if self.executables['compiler_f90']:\n return self.executables['compiler_f90'][1:]\n return []\n def get_flags_fix(self):\n \"\"\" List of Fortran 90 fixed format specific flags. \"\"\"\n if self.executables['compiler_fix']:\n return self.executables['compiler_fix'][1:]\n return []\n def get_flags_linker_so(self):\n \"\"\" List of linker flags to build a shared library. \"\"\"\n if self.executables['linker_so']:\n return self.executables['linker_so'][1:]\n return []\n def get_flags_ar(self):\n \"\"\" List of archiver flags. \"\"\"\n if self.executables['archiver']:\n return self.executables['archiver'][1:]\n return []\n def get_flags_opt(self):\n \"\"\" List of architecture independent compiler flags. \"\"\"\n return []\n def get_flags_arch(self):\n \"\"\" List of architecture dependent compiler flags. \"\"\"\n return []\n def get_flags_debug(self):\n \"\"\" List of compiler flags to compile with debugging information. \"\"\"\n return []\n get_flags_opt_f77 = get_flags_opt_f90 = get_flags_opt\n get_flags_arch_f77 = get_flags_arch_f90 = get_flags_arch\n get_flags_debug_f77 = get_flags_debug_f90 = get_flags_debug\n\n def get_libraries(self):\n \"\"\" List of compiler libraries. \"\"\"\n return self.libraries[:]\n def get_library_dirs(self):\n \"\"\" List of compiler library directories. \"\"\"\n return self.library_dirs[:]\n\n ############################################################\n\n ## Public methods:\n\n def customize(self, dist=None):\n \"\"\" Customize Fortran compiler.\n\n This method gets Fortran compiler specific information from\n (i) class definition, (ii) environment, (iii) distutils config\n files, and (iv) command line.\n\n This method should be always called after constructing a\n compiler instance. But not in __init__ because Distribution\n instance is needed for (iii) and (iv).\n \"\"\"\n log.info('customize %s' % (self.__class__.__name__))\n if dist is None:\n # These hooks are for testing only!\n from dist import Distribution\n dist = Distribution()\n dist.script_name = os.path.basename(sys.argv[0])\n dist.script_args = ['config_fc'] + sys.argv[1:]\n dist.cmdclass['config_fc'] = config_fc\n dist.parse_config_files()\n dist.parse_command_line()\n\n conf = dist.get_option_dict('config_fc')\n\n noopt = conf.get('noopt',[None,0])[1]\n noarch = conf.get('noarch',[None,noopt])[1]\n debug = conf.get('debug',[None,0])[1]\n\n f77 = self.__get_cmd('compiler_f77','F77',(conf,'f77exec'))\n f90 = self.__get_cmd('compiler_f90','F90',(conf,'f90exec'))\n # Temporarily setting f77,f90 compilers so that\n # version_cmd can use their executables.\n if f77:\n self.set_executables(compiler_f77=[f77])\n if f90:\n self.set_executables(compiler_f90=[f90])\n\n # Must set version_cmd before others as self.get_flags*\n # methods may call self.get_version.\n vers_cmd = self.__get_cmd(self.get_version_cmd)\n if vers_cmd:\n vflags = self.__get_flags(self.get_flags_version)\n self.set_executables(version_cmd=[vers_cmd]+vflags)\n\n if f77:\n f77flags = self.__get_flags(self.get_flags_f77,'F77FLAGS',\n (conf,'f77flags'))\n if f90:\n f90flags = self.__get_flags(self.get_flags_f90,'F90FLAGS',\n (conf,'f90flags'))\n\n # XXX Assuming that free format is default for f90 compiler.\n fix = self.__get_cmd('compiler_fix','F90',(conf,'f90exec'))\n if fix:\n fixflags = self.__get_flags(self.get_flags_fix) + f90flags\n\n oflags,aflags,dflags = [],[],[]\n if not noopt:\n oflags = self.__get_flags(self.get_flags_opt,'FOPT',(conf,'opt'))\n if f77 and self.get_flags_opt is not self.get_flags_opt_f77:\n f77flags += self.__get_flags(self.get_flags_opt_f77)\n if f90 and self.get_flags_opt is not self.get_flags_opt_f90:\n f90flags += self.__get_flags(self.get_flags_opt_f90)\n if fix and self.get_flags_opt is not self.get_flags_opt_f90:\n fixflags += self.__get_flags(self.get_flags_opt_f90)\n if not noarch:\n aflags = self.__get_flags(self.get_flags_arch,'FARCH',\n (conf,'arch'))\n if f77 and self.get_flags_arch is not self.get_flags_arch_f77:\n f77flags += self.__get_flags(self.get_flags_arch_f77)\n if f90 and self.get_flags_arch is not self.get_flags_arch_f90:\n f90flags += self.__get_flags(self.get_flags_arch_f90)\n if fix and self.get_flags_arch is not self.get_flags_arch_f90:\n fixflags += self.__get_flags(self.get_flags_arch_f90)\n if debug:\n dflags = self.__get_flags(self.get_flags_debug,'FDEBUG')\n if f77 and self.get_flags_debug is not self.get_flags_debug_f77:\n f77flags += self.__get_flags(self.get_flags_debug_f77)\n if f90 and self.get_flags_debug is not self.get_flags_debug_f90:\n f90flags += self.__get_flags(self.get_flags_debug_f90)\n if fix and self.get_flags_debug is not self.get_flags_debug_f90:\n fixflags += self.__get_flags(self.get_flags_debug_f90)\n\n fflags = self.__get_flags(self.get_flags,'FFLAGS') \\\n + dflags + oflags + aflags\n\n if f77:\n self.set_executables(compiler_f77=[f77]+f77flags+fflags)\n if f90:\n self.set_executables(compiler_f90=[f90]+f90flags+fflags)\n if fix:\n self.set_executables(compiler_fix=[fix]+fixflags+fflags)\n\n #XXX: Do we need LDSHARED->SOSHARED, LDFLAGS->SOFLAGS\n linker_so = self.__get_cmd(self.get_linker_so,'LDSHARED')\n if linker_so:\n linker_so_flags = self.__get_flags(self.get_flags_linker_so,'LDFLAGS')\n self.set_executables(linker_so=[linker_so]+linker_so_flags)\n\n ar = self.__get_cmd('archiver','AR')\n if ar:\n arflags = self.__get_flags(self.get_flags_ar,'ARFLAGS')\n self.set_executables(archiver=[ar]+arflags)\n\n ranlib = self.__get_cmd('ranlib','RANLIB')\n if ranlib:\n self.set_executables(ranlib=[ranlib])\n\n self.set_library_dirs(self.get_library_dirs())\n self.set_libraries(self.get_libraries())\n\n verbose = conf.get('verbose',[None,0])[1]\n if verbose:\n self.dump_properties()\n return\n\n def dump_properties(self):\n \"\"\" Print out the attributes of a compiler instance. \"\"\"\n props = []\n for key in self.executables.keys() + \\\n ['version','libraries','library_dirs',\n 'object_switch','compile_switch']:\n if hasattr(self,key):\n v = getattr(self,key)\n props.append((key, None, '= '+`v`))\n props.sort()\n\n pretty_printer = FancyGetopt(props)\n for l in pretty_printer.generate_help(\"%s instance properties:\" \\\n % (self.__class__.__name__)):\n if l[:4]==' --':\n l = ' ' + l[4:]\n print l\n return\n\n ###################\n\n def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):\n \"\"\"Compile 'src' to product 'obj'.\"\"\"\n if is_f_file(src):\n flavor = ':f77'\n compiler = self.compiler_f77\n elif is_free_format(src):\n flavor = ':f90'\n compiler = self.compiler_f90\n if compiler is None:\n raise DistutilsExecError, 'f90 not supported by '\\\n +self.__class__.__name__\n else:\n flavor = ':fix'\n compiler = self.compiler_fix\n if compiler is None:\n raise DistutilsExecError, 'f90 (fixed) not supported by '\\\n +self.__class__.__name__\n if self.object_switch[-1]==' ':\n o_args = [self.object_switch.strip(),obj]\n else:\n o_args = [self.object_switch.strip()+obj]\n\n assert self.compile_switch.strip()\n s_args = [self.compile_switch, src]\n\n if os.name == 'nt':\n compiler = _nt_quote_args(compiler)\n command = compiler + cc_args + s_args + o_args + extra_postargs\n\n display = '%s: %s' % (os.path.basename(compiler[0]) + flavor,\n src)\n try:\n self.spawn(command,display=display)\n except DistutilsExecError, msg:\n raise CompileError, msg\n\n return\n\n def module_options(self, module_dirs, module_build_dir):\n options = []\n if self.module_dir_switch is not None:\n if self.module_dir_switch[-1]==' ':\n options.extend([self.module_dir_switch.strip(),module_build_dir])\n else:\n options.append(self.module_dir_switch.strip()+module_build_dir)\n else:\n print 'XXX: module_build_dir=%r option ignored' % (module_build_dir)\n print 'XXX: Fix module_dir_switch for ',self.__class__.__name__\n if self.module_include_switch is not None:\n for d in [module_build_dir]+module_dirs:\n options.append('%s%s' % (self.module_include_switch, d))\n else:\n print 'XXX: module_dirs=%r option ignored' % (module_dirs)\n print 'XXX: Fix module_include_switch for ',self.__class__.__name__\n return options\n\n def library_option(self, lib):\n return \"-l\" + lib\n def library_dir_option(self, dir):\n return \"-L\" + dir\n\n# def _get_cc_args(self, pp_opts, debug, extra_preargs):\n# return []\n\n if sys.version[:3]<'2.3':\n def compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if output_dir is None: output_dir = self.output_dir\n if macros is None: macros = self.macros\n elif type(macros) is ListType: macros = macros + (self.macros or [])\n if include_dirs is None: include_dirs = self.include_dirs\n elif type(include_dirs) in (ListType, TupleType):\n include_dirs = list(include_dirs) + (self.include_dirs or [])\n if extra_preargs is None: extra_preargs=[]\n from distutils.sysconfig import python_build\n objects = self.object_filenames(sources,strip_dir=python_build,\n output_dir=output_dir)\n from distutils.ccompiler import gen_preprocess_options\n pp_opts = gen_preprocess_options(macros, include_dirs)\n build = {}\n for i in range(len(sources)):\n src,obj = sources[i],objects[i]\n ext = os.path.splitext(src)[1]\n self.mkpath(os.path.dirname(obj))\n build[obj] = src, ext\n cc_args = [] #self._get_cc_args(pp_opts, debug, extra_preargs)\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n return objects\n def detect_language(self, sources):\n return\n\n def link(self, target_desc, objects,\n output_filename, output_dir=None, libraries=None,\n library_dirs=None, runtime_library_dirs=None,\n export_symbols=None, debug=0, extra_preargs=None,\n extra_postargs=None, build_temp=None, target_lang=None):\n objects, output_dir = self._fix_object_args(objects, output_dir)\n libraries, library_dirs, runtime_library_dirs = \\\n self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)\n\n lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,\n libraries)\n if type(output_dir) not in (StringType, NoneType):\n raise TypeError, \"'output_dir' must be a string or None\"\n if output_dir is not None:\n output_filename = os.path.join(output_dir, output_filename)\n\n if self._need_link(objects, output_filename):\n if self.library_switch[-1]==' ':\n o_args = [self.library_switch.strip(),output_filename]\n else:\n o_args = [self.library_switch.strip()+output_filename]\n ld_args = (objects + self.objects +\n lib_opts + o_args)\n if debug:\n ld_args[:0] = ['-g']\n if extra_preargs:\n ld_args[:0] = extra_preargs\n if extra_postargs:\n ld_args.extend(extra_postargs)\n self.mkpath(os.path.dirname(output_filename))\n if target_desc == CCompiler.EXECUTABLE:\n raise NotImplementedError,self.__class__.__name__+'.linker_exe attribute'\n else:\n linker = self.linker_so[:]\n if os.name == 'nt':\n linker = _nt_quote_args(linker)\n command = linker + ld_args\n try:\n self.spawn(command)\n except DistutilsExecError, msg:\n raise LinkError, msg\n else:\n log.debug(\"skipping %s (up-to-date)\", output_filename)\n return\n\n ############################################################\n\n ## Private methods:\n\n def __get_cmd(self, command, envvar=None, confvar=None):\n if command is None:\n var = None\n elif type(command) is type(''):\n var = self.executables[command]\n if var is not None:\n var = var[0]\n else:\n var = command()\n if envvar is not None:\n var = os.environ.get(envvar, var)\n if confvar is not None:\n var = confvar[0].get(confvar[1], [None,var])[1]\n return var\n\n def __get_flags(self, command, envvar=None, confvar=None):\n if command is None:\n var = []\n elif type(command) is type(''):\n var = self.executables[command][1:]\n else:\n var = command()\n if envvar is not None:\n var = os.environ.get(envvar, var)\n if confvar is not None:\n var = confvar[0].get(confvar[1], [None,var])[1]\n if type(var) is type(''):\n var = split_quoted(var)\n return var\n\n ## class FCompiler\n\n##############################################################################\n\nfcompiler_class = {'gnu':('gnufcompiler','GnuFCompiler',\n \"GNU Fortran Compiler\"),\n 'pg':('pgfcompiler','PGroupFCompiler',\n \"Portland Group Fortran Compiler\"),\n 'absoft':('absoftfcompiler','AbsoftFCompiler',\n \"Absoft Corp Fortran Compiler\"),\n 'mips':('mipsfcompiler','MipsFCompiler',\n \"MIPSpro Fortran Compiler\"),\n 'sun':('sunfcompiler','SunFCompiler',\n \"Sun|Forte Fortran 95 Compiler\"),\n 'intel':('intelfcompiler','IntelFCompiler',\n \"Intel Fortran Compiler for 32-bit apps\"),\n 'intelv':('intelfcompiler','IntelVisualFCompiler',\n \"Intel Visual Fortran Compiler for 32-bit apps\"),\n 'intele':('intelfcompiler','IntelItaniumFCompiler',\n \"Intel Fortran Compiler for Itanium apps\"),\n 'intelev':('intelfcompiler','IntelItaniumVisualFCompiler',\n \"Intel Visual Fortran Compiler for Itanium apps\"),\n 'nag':('nagfcompiler','NAGFCompiler',\n \"NAGWare Fortran 95 Compiler\"),\n 'compaq':('compaqfcompiler','CompaqFCompiler',\n \"Compaq Fortran Compiler\"),\n 'compaqv':('compaqfcompiler','CompaqVisualFCompiler',\n \"DIGITAL|Compaq Visual Fortran Compiler\"),\n 'vast':('vastfcompiler','VastFCompiler',\n \"Pacific-Sierra Research Fortran 90 Compiler\"),\n 'hpux':('hpuxfcompiler','HPUXFCompiler',\n \"HP Fortran 90 Compiler\"),\n 'lahey':('laheyfcompiler','LaheyFCompiler',\n \"Lahey/Fujitsu Fortran 95 Compiler\"),\n 'ibm':('ibmfcompiler','IbmFCompiler',\n \"IBM XL Fortran Compiler\"),\n 'f':('fcompiler','FFCompiler',\n \"Fortran Company/NAG F Compiler\"),\n }\n\n_default_compilers = (\n # Platform mappings\n ('win32',('gnu','intelv','absoft','compaqv','intelev')),\n ('cygwin.*',('gnu','intelv','absoft','compaqv','intelev')),\n ('linux.*',('gnu','intel','lahey','pg','absoft','nag','vast','compaq',\n 'intele')),\n ('darwin.*',('nag','absoft','ibm','gnu')),\n ('sunos.*',('forte','gnu','sun')),\n ('irix.*',('mips','gnu')),\n ('aix.*',('ibm','gnu')),\n # OS mappings\n ('posix',('gnu',)),\n ('nt',('gnu',)),\n ('mac',('gnu',)),\n )\n\ndef _find_existing_fcompiler(compilers, osname=None, platform=None):\n for compiler in compilers:\n v = None\n try:\n c = new_fcompiler(plat=platform, compiler=compiler)\n c.customize()\n v = c.get_version()\n except DistutilsModuleError:\n pass\n except Exception, msg:\n log.warn(msg)\n if v is not None:\n return compiler\n return\n\ndef get_default_fcompiler(osname=None, platform=None):\n \"\"\" Determine the default Fortran compiler to use for the given platform. \"\"\"\n if osname is None:\n osname = os.name\n if platform is None:\n platform = sys.platform\n matching_compilers = []\n for pattern, compiler in _default_compilers:\n if re.match(pattern, platform) is not None or \\\n re.match(pattern, osname) is not None:\n if type(compiler) is type(()):\n matching_compilers.extend(list(compiler))\n else:\n matching_compilers.append(compiler)\n if not matching_compilers:\n matching_compilers.append('gnu')\n compiler = _find_existing_fcompiler(matching_compilers,\n osname=osname,\n platform=platform)\n if compiler is not None:\n return compiler\n return matching_compilers[0]\n\ndef new_fcompiler(plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n \"\"\" Generate an instance of some FCompiler subclass for the supplied\n platform/compiler combination.\n \"\"\"\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_fcompiler(plat)\n (module_name, class_name, long_description) = fcompiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile Fortran code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler.\" % compiler\n msg = msg + \" Supported compilers are: %s)\" \\\n % (','.join(fcompiler_class.keys()))\n raise DistutilsPlatformError, msg\n\n try:\n module_name = 'scipy_distutils.'+module_name\n __import__ (module_name)\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile Fortran code: unable to load module '%s'\" % \\\n module_name\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile Fortran code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\ndef show_fcompilers(dist = None):\n \"\"\" Print list of available compilers (used by the \"--help-fcompiler\"\n option to \"config_fc\").\n \"\"\"\n if dist is None:\n from dist import Distribution\n dist = Distribution()\n dist.script_name = os.path.basename(sys.argv[0])\n dist.script_args = ['config_fc'] + sys.argv[1:]\n dist.cmdclass['config_fc'] = config_fc\n dist.parse_config_files()\n dist.parse_command_line()\n\n compilers = []\n compilers_na = []\n compilers_ni = []\n for compiler in fcompiler_class.keys():\n v = 'N/A'\n try:\n c = new_fcompiler(compiler=compiler)\n c.customize(dist)\n v = c.get_version()\n except DistutilsModuleError:\n pass\n except Exception, msg:\n log.warn(msg)\n if v is None:\n compilers_na.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2]))\n elif v=='N/A':\n compilers_ni.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2]))\n else:\n compilers.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2] + ' (%s)' % v))\n compilers.sort()\n compilers_na.sort()\n pretty_printer = FancyGetopt(compilers)\n pretty_printer.print_help(\"List of available Fortran compilers:\")\n pretty_printer = FancyGetopt(compilers_na)\n pretty_printer.print_help(\"List of unavailable Fortran compilers:\")\n if compilers_ni:\n pretty_printer = FancyGetopt(compilers_ni)\n pretty_printer.print_help(\"List of unimplemented Fortran compilers:\")\n print \"For compiler details, run 'config_fc --verbose' setup command.\"\n\ndef dummy_fortran_file():\n import tempfile\n dummy_name = tempfile.mktemp()+'__dummy'\n dummy = open(dummy_name+'.f','w')\n dummy.write(\" subroutine dummy()\\n end\\n\")\n dummy.close()\n def rm_file(name=dummy_name,log_threshold=log._global_log.threshold):\n save_th = log._global_log.threshold\n log.set_threshold(log_threshold)\n try: os.remove(name+'.f'); log.debug('removed '+name+'.f')\n except OSError: pass\n try: os.remove(name+'.o'); log.debug('removed '+name+'.o')\n except OSError: pass\n log.set_threshold(save_th)\n atexit.register(rm_file)\n return dummy_name\n\nis_f_file = re.compile(r'.*[.](for|ftn|f77|f)\\Z',re.I).match\n_has_f_header = re.compile(r'-[*]-\\s*fortran\\s*-[*]-',re.I).search\n_has_f90_header = re.compile(r'-[*]-\\s*f90\\s*-[*]-',re.I).search\n_free_f90_start = re.compile(r'[^c*][^\\s\\d\\t]',re.I).match\ndef is_free_format(file):\n \"\"\"Check if file is in free format Fortran.\"\"\"\n # f90 allows both fixed and free format, assuming fixed unless\n # signs of free format are detected.\n result = 0\n f = open(file,'r')\n line = f.readline()\n n = 15 # the number of non-comment lines to scan for hints\n if _has_f_header(line):\n n = 0\n elif _has_f90_header(line):\n n = 0\n result = 1\n while n>0 and line:\n if line[0]!='!':\n n -= 1\n if (line[0]!='\\t' and _free_f90_start(line[:5])) or line[-2:-1]=='&':\n result = 1\n break\n line = f.readline()\n f.close()\n return result\n\nif __name__ == '__main__':\n show_fcompilers()\n", "source_code_before": "\"\"\"scipy_distutils.fcompiler\n\nContains FCompiler, an abstract base class that defines the interface\nfor the Scipy_distutils Fortran compiler abstraction model.\n\n\"\"\"\n\nimport re\nimport os\nimport sys\nimport atexit\nfrom types import StringType, NoneType, ListType, TupleType\nfrom glob import glob\n\nfrom distutils.version import StrictVersion\nfrom scipy_distutils.ccompiler import CCompiler, gen_lib_options\n# distutils.ccompiler provides the following functions:\n# gen_preprocess_options(macros, include_dirs)\n# gen_lib_options(compiler, library_dirs, runtime_library_dirs, libraries)\nfrom distutils.errors import DistutilsModuleError,DistutilsArgError,\\\n DistutilsExecError,CompileError,LinkError,DistutilsPlatformError\nfrom distutils.core import Command\nfrom distutils.util import split_quoted\nfrom distutils.fancy_getopt import FancyGetopt\nfrom distutils.sysconfig import get_config_var\nfrom distutils.spawn import _nt_quote_args \n\n\nfrom scipy_distutils.command.config_compiler import config_fc\n\nimport log\nfrom misc_util import compiler_to_string\nfrom exec_command import find_executable, exec_command\n\nclass FCompiler(CCompiler):\n \"\"\" Abstract base class to define the interface that must be implemented\n by real Fortran compiler classes.\n\n Methods that subclasses may redefine:\n\n get_version_cmd(), get_linker_so(), get_version()\n get_flags(), get_flags_opt(), get_flags_arch(), get_flags_debug()\n get_flags_f77(), get_flags_opt_f77(), get_flags_arch_f77(),\n get_flags_debug_f77(), get_flags_f90(), get_flags_opt_f90(),\n get_flags_arch_f90(), get_flags_debug_f90(),\n get_flags_fix(), get_flags_linker_so(), get_flags_version()\n\n DON'T call these methods (except get_version) after\n constructing a compiler instance or inside any other method.\n All methods, except get_version_cmd() and get_flags_version(), may\n call get_version() method.\n\n After constructing a compiler instance, always call customize(dist=None)\n method that finalizes compiler construction and makes the following\n attributes available:\n compiler_f77\n compiler_f90\n compiler_fix\n linker_so\n archiver\n ranlib\n libraries\n library_dirs\n \"\"\"\n # CCompiler defines the following attributes:\n # compiler_type\n # src_extensions\n # obj_extension\n # static_lib_extension\n # shared_lib_extension\n # static_lib_format\n # shared_lib_format\n # exe_extension\n # language_map ### REDEFINED\n # language_order ### REDEFINED\n # and the following public methods:\n # set_executables(**args)\n # set_executable(key,value)\n # define_macro(name, value=None)\n # undefine_macro(name)\n # add_include_dir(dir)\n # set_include_dirs(dirs)\n # add_library(libname)\n # set_libraries(libnames)\n # add_library_dir(dir)\n # set_library_dirs(dirs)\n # add_runtime_library_dir(dir)\n # set_runtime_library_dirs(dirs)\n # add_link_object(object)\n # set_link_objects(objects)\n #\n # detect_language(sources) ### USABLE\n #\n # preprocess(source,output_file=None,macros=None,include_dirs=None,\n # extra_preargs=None,extra_postargs=None)\n # compile(sources, output_dir=None, macros=None,\n # include_dirs=None, debug=0, extra_preargs=None,\n # extra_postargs=None, depends=None)\n # create_static_lib(objects,output_libname,output_dir=None,debug=0,target_lang=None):\n # link(target_desc, objects, output_filename, output_dir=None,\n # libraries=None, library_dirs=None, runtime_library_dirs=None,\n # export_symbols=None, debug=0, extra_preargs=None, extra_postargs=None,\n # build_temp=None, target_lang=None)\n # link_shared_lib(objects, output_libname, output_dir=None,\n # libraries=None, library_dirs=None, runtime_library_dirs=None,\n # export_symbols=None, debug=0, extra_preargs=None,\n # extra_postargs=None, build_temp=None, target_lang=None)\n # link_shared_object(objects,output_filename,output_dir=None,\n # libraries=None,library_dirs=None,runtime_library_dirs=None,\n # export_symbols=None,debug=0,extra_preargs=None,\n # extra_postargs=None,build_temp=None,target_lang=None)\n # link_executable(objects,output_progname,output_dir=None,\n # libraries=None,library_dirs=None,runtime_library_dirs=None,\n # debug=0,extra_preargs=None,extra_postargs=None,target_lang=None)\n #\n # library_dir_option(dir)\n # runtime_library_dir_option(dir)\n # library_option(lib)\n # has_function(funcname,includes=None,include_dirs=None,\n # libraries=None,library_dirs=None)\n # find_library_file(dirs, lib, debug=0)\n #\n # object_filenames(source_filenames, strip_dir=0, output_dir='')\n # shared_object_filename(basename, strip_dir=0, output_dir='')\n # executable_filenamee(basename, strip_dir=0, output_dir='')\n # library_filename(libname, lib_type='static',strip_dir=0, output_dir=''):\n #\n # announce(msg, level=1)\n # debug_print(msg)\n # warn(msg)\n # execute(func, args, msg=None, level=1)\n # spawn(cmd)\n # move_file(src,dst)\n # mkpath(name, mode=0777)\n #\n\n language_map = {'.f':'f77',\n '.for':'f77',\n '.ftn':'f77',\n '.f77':'f77',\n '.f90':'f90',\n '.f95':'f90'}\n language_order = ['f90','f77']\n\n version_pattern = None\n\n executables = {\n 'version_cmd' : [\"f77\",\"-v\"],\n 'compiler_f77' : [\"f77\"],\n 'compiler_f90' : [\"f90\"],\n 'compiler_fix' : [\"f90\",\"-fixed\"],\n 'linker_so' : [\"f90\",\"-shared\"],\n #'linker_exe' : [\"f90\"], # XXX do we need it??\n 'archiver' : [\"ar\",\"-cr\"],\n 'ranlib' : None,\n }\n\n compile_switch = \"-c\"\n object_switch = \"-o \" # Ending space matters! It will be stripped\n # but if it is missing then object_switch\n # will be prefixed to object file name by\n # string concatenation.\n library_switch = \"-o \" # Ditto!\n\n # Switch to specify where module files are created and searched\n # for USE statement. Normally it is a string and also here ending\n # space matters. See above.\n module_dir_switch = None\n\n # Switch to specify where module files are searched for USE statement.\n module_include_switch = '-I' \n\n pic_flags = [] # Flags to create position-independent code\n\n src_extensions = ['.for','.ftn','.f77','.f','.f90','.f95']\n obj_extension = \".o\"\n shared_lib_extension = get_config_var('SO') # or .dll\n static_lib_extension = \".a\" # or .lib\n static_lib_format = \"lib%s%s\" # or %s%s\n shared_lib_format = \"%s%s\"\n exe_extension = \"\"\n\n ######################################################################\n ## Methods that subclasses may redefine. But don't call these methods!\n ## They are private to FCompiler class and may return unexpected\n ## results if used elsewhere. So, you have been warned..\n\n def get_version_cmd(self):\n \"\"\" Compiler command to print out version information. \"\"\"\n f77 = self.executables['compiler_f77']\n if f77 is not None:\n f77 = f77[0]\n cmd = self.executables['version_cmd']\n if cmd is not None:\n cmd = cmd[0]\n if cmd==f77:\n cmd = self.compiler_f77[0]\n else:\n f90 = self.executables['compiler_f90']\n if f90 is not None:\n f90 = f90[0]\n if cmd==f90:\n cmd = self.compiler_f90[0]\n return cmd\n\n def get_linker_so(self):\n \"\"\" Linker command to build shared libraries. \"\"\"\n f77 = self.executables['compiler_f77']\n if f77 is not None:\n f77 = f77[0]\n ln = self.executables['linker_so']\n if ln is not None:\n ln = ln[0]\n if ln==f77:\n ln = self.compiler_f77[0]\n else:\n f90 = self.executables['compiler_f90']\n if f90 is not None:\n f90 = f90[0]\n if ln==f90:\n ln = self.compiler_f90[0]\n return ln\n\n def get_flags(self):\n \"\"\" List of flags common to all compiler types. \"\"\"\n return [] + self.pic_flags\n def get_flags_version(self):\n \"\"\" List of compiler flags to print out version information. \"\"\"\n if self.executables['version_cmd']:\n return self.executables['version_cmd'][1:]\n return []\n def get_flags_f77(self):\n \"\"\" List of Fortran 77 specific flags. \"\"\"\n if self.executables['compiler_f77']:\n return self.executables['compiler_f77'][1:]\n return []\n def get_flags_f90(self):\n \"\"\" List of Fortran 90 specific flags. \"\"\"\n if self.executables['compiler_f90']:\n return self.executables['compiler_f90'][1:]\n return []\n def get_flags_fix(self):\n \"\"\" List of Fortran 90 fixed format specific flags. \"\"\"\n if self.executables['compiler_fix']:\n return self.executables['compiler_fix'][1:]\n return []\n def get_flags_linker_so(self):\n \"\"\" List of linker flags to build a shared library. \"\"\"\n if self.executables['linker_so']:\n return self.executables['linker_so'][1:]\n return []\n def get_flags_ar(self):\n \"\"\" List of archiver flags. \"\"\"\n if self.executables['archiver']:\n return self.executables['archiver'][1:]\n return []\n def get_flags_opt(self):\n \"\"\" List of architecture independent compiler flags. \"\"\"\n return []\n def get_flags_arch(self):\n \"\"\" List of architecture dependent compiler flags. \"\"\"\n return []\n def get_flags_debug(self):\n \"\"\" List of compiler flags to compile with debugging information. \"\"\"\n return []\n get_flags_opt_f77 = get_flags_opt_f90 = get_flags_opt\n get_flags_arch_f77 = get_flags_arch_f90 = get_flags_arch\n get_flags_debug_f77 = get_flags_debug_f90 = get_flags_debug\n\n def get_libraries(self):\n \"\"\" List of compiler libraries. \"\"\"\n return self.libraries[:]\n def get_library_dirs(self):\n \"\"\" List of compiler library directories. \"\"\"\n return self.library_dirs[:]\n\n ############################################################\n\n ## Public methods:\n\n def customize(self, dist=None):\n \"\"\" Customize Fortran compiler.\n\n This method gets Fortran compiler specific information from\n (i) class definition, (ii) environment, (iii) distutils config\n files, and (iv) command line.\n\n This method should be always called after constructing a\n compiler instance. But not in __init__ because Distribution\n instance is needed for (iii) and (iv).\n \"\"\"\n log.info('customize %s' % (self.__class__.__name__))\n if dist is None:\n # These hooks are for testing only!\n from dist import Distribution\n dist = Distribution()\n dist.script_name = os.path.basename(sys.argv[0])\n dist.script_args = ['config_fc'] + sys.argv[1:]\n dist.cmdclass['config_fc'] = config_fc\n dist.parse_config_files()\n dist.parse_command_line()\n\n conf = dist.get_option_dict('config_fc')\n\n noopt = conf.get('noopt',[None,0])[1]\n noarch = conf.get('noarch',[None,noopt])[1]\n debug = conf.get('debug',[None,0])[1]\n\n f77 = self.__get_cmd('compiler_f77','F77',(conf,'f77exec'))\n f90 = self.__get_cmd('compiler_f90','F90',(conf,'f90exec'))\n # Temporarily setting f77,f90 compilers so that\n # version_cmd can use their executables.\n if f77:\n self.set_executables(compiler_f77=[f77])\n if f90:\n self.set_executables(compiler_f90=[f90])\n\n # Must set version_cmd before others as self.get_flags*\n # methods may call self.get_version.\n vers_cmd = self.__get_cmd(self.get_version_cmd)\n if vers_cmd:\n vflags = self.__get_flags(self.get_flags_version)\n self.set_executables(version_cmd=[vers_cmd]+vflags)\n\n if f77:\n f77flags = self.__get_flags(self.get_flags_f77,'F77FLAGS',\n (conf,'f77flags'))\n if f90:\n f90flags = self.__get_flags(self.get_flags_f90,'F90FLAGS',\n (conf,'f90flags'))\n\n # XXX Assuming that free format is default for f90 compiler.\n fix = self.__get_cmd('compiler_fix','F90',(conf,'f90exec'))\n if fix:\n fixflags = self.__get_flags(self.get_flags_fix) + f90flags\n\n oflags,aflags,dflags = [],[],[]\n if not noopt:\n oflags = self.__get_flags(self.get_flags_opt,'FOPT',(conf,'opt'))\n if f77 and self.get_flags_opt is not self.get_flags_opt_f77:\n f77flags += self.__get_flags(self.get_flags_opt_f77)\n if f90 and self.get_flags_opt is not self.get_flags_opt_f90:\n f90flags += self.__get_flags(self.get_flags_opt_f90)\n if fix and self.get_flags_opt is not self.get_flags_opt_f90:\n fixflags += self.__get_flags(self.get_flags_opt_f90)\n if not noarch:\n aflags = self.__get_flags(self.get_flags_arch,'FARCH',\n (conf,'arch'))\n if f77 and self.get_flags_arch is not self.get_flags_arch_f77:\n f77flags += self.__get_flags(self.get_flags_arch_f77)\n if f90 and self.get_flags_arch is not self.get_flags_arch_f90:\n f90flags += self.__get_flags(self.get_flags_arch_f90)\n if fix and self.get_flags_arch is not self.get_flags_arch_f90:\n fixflags += self.__get_flags(self.get_flags_arch_f90)\n if debug:\n dflags = self.__get_flags(self.get_flags_debug,'FDEBUG')\n if f77 and self.get_flags_debug is not self.get_flags_debug_f77:\n f77flags += self.__get_flags(self.get_flags_debug_f77)\n if f90 and self.get_flags_debug is not self.get_flags_debug_f90:\n f90flags += self.__get_flags(self.get_flags_debug_f90)\n if fix and self.get_flags_debug is not self.get_flags_debug_f90:\n fixflags += self.__get_flags(self.get_flags_debug_f90)\n\n fflags = self.__get_flags(self.get_flags,'FFLAGS') \\\n + dflags + oflags + aflags\n\n if f77:\n self.set_executables(compiler_f77=[f77]+f77flags+fflags)\n if f90:\n self.set_executables(compiler_f90=[f90]+f90flags+fflags)\n if fix:\n self.set_executables(compiler_fix=[fix]+fixflags+fflags)\n\n #XXX: Do we need LDSHARED->SOSHARED, LDFLAGS->SOFLAGS\n linker_so = self.__get_cmd(self.get_linker_so,'LDSHARED')\n if linker_so:\n linker_so_flags = self.__get_flags(self.get_flags_linker_so,'LDFLAGS')\n self.set_executables(linker_so=[linker_so]+linker_so_flags)\n\n ar = self.__get_cmd('archiver','AR')\n if ar:\n arflags = self.__get_flags(self.get_flags_ar,'ARFLAGS')\n self.set_executables(archiver=[ar]+arflags)\n\n ranlib = self.__get_cmd('ranlib','RANLIB')\n if ranlib:\n self.set_executables(ranlib=[ranlib])\n\n self.set_library_dirs(self.get_library_dirs())\n self.set_libraries(self.get_libraries())\n\n verbose = conf.get('verbose',[None,0])[1]\n if verbose:\n self.dump_properties()\n return\n\n def dump_properties(self):\n \"\"\" Print out the attributes of a compiler instance. \"\"\"\n props = []\n for key in self.executables.keys() + \\\n ['version','libraries','library_dirs',\n 'object_switch','compile_switch']:\n if hasattr(self,key):\n v = getattr(self,key)\n props.append((key, None, '= '+`v`))\n props.sort()\n\n pretty_printer = FancyGetopt(props)\n for l in pretty_printer.generate_help(\"%s instance properties:\" \\\n % (self.__class__.__name__)):\n if l[:4]==' --':\n l = ' ' + l[4:]\n print l\n return\n\n ###################\n\n def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):\n \"\"\"Compile 'src' to product 'obj'.\"\"\"\n if is_f_file(src):\n flavor = ':f77'\n compiler = self.compiler_f77\n elif is_free_format(src):\n flavor = ':f90'\n compiler = self.compiler_f90\n if compiler is None:\n raise DistutilsExecError, 'f90 not supported by '\\\n +self.__class__.__name__\n else:\n flavor = ':fix'\n compiler = self.compiler_fix\n if compiler is None:\n raise DistutilsExecError, 'f90 (fixed) not supported by '\\\n +self.__class__.__name__\n if self.object_switch[-1]==' ':\n o_args = [self.object_switch.strip(),obj]\n else:\n o_args = [self.object_switch.strip()+obj]\n\n assert self.compile_switch.strip()\n s_args = [self.compile_switch, src]\n\n if os.name == 'nt':\n compiler = _nt_quote_args(compiler)\n command = compiler + cc_args + s_args + o_args + extra_postargs\n\n display = '%s: %s' % (os.path.basename(compiler[0]) + flavor,\n src)\n try:\n self.spawn(command,display=display)\n except DistutilsExecError, msg:\n raise CompileError, msg\n\n return\n\n def module_options(self, module_dirs, module_build_dir):\n options = []\n if self.module_dir_switch is not None:\n if self.module_dir_switch[-1]==' ':\n options.extend([self.module_dir_switch.strip(),module_build_dir])\n else:\n options.append(self.module_dir_switch.strip()+module_build_dir)\n else:\n print 'XXX: module_build_dir=%r option ignored' % (module_build_dir)\n print 'XXX: Fix module_dir_switch for ',self.__class__.__name__\n if self.module_include_switch is not None:\n for d in [module_build_dir]+module_dirs:\n options.append('%s%s' % (self.module_include_switch, d))\n else:\n print 'XXX: module_dirs=%r option ignored' % (module_dirs)\n print 'XXX: Fix module_include_switch for ',self.__class__.__name__\n return options\n\n def library_option(self, lib):\n return \"-l\" + lib\n def library_dir_option(self, dir):\n return \"-L\" + dir\n\n# def _get_cc_args(self, pp_opts, debug, extra_preargs):\n# return []\n\n if sys.version[:3]<'2.3':\n def compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if output_dir is None: output_dir = self.output_dir\n if macros is None: macros = self.macros\n elif type(macros) is ListType: macros = macros + (self.macros or [])\n if include_dirs is None: include_dirs = self.include_dirs\n elif type(include_dirs) in (ListType, TupleType):\n include_dirs = list(include_dirs) + (self.include_dirs or [])\n if extra_preargs is None: extra_preargs=[]\n from distutils.sysconfig import python_build\n objects = self.object_filenames(sources,strip_dir=python_build,\n output_dir=output_dir)\n from distutils.ccompiler import gen_preprocess_options\n pp_opts = gen_preprocess_options(macros, include_dirs)\n build = {}\n for i in range(len(sources)):\n src,obj = sources[i],objects[i]\n ext = os.path.splitext(src)[1]\n self.mkpath(os.path.dirname(obj))\n build[obj] = src, ext\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n return objects\n def detect_language(self, sources):\n return\n\n def link(self, target_desc, objects,\n output_filename, output_dir=None, libraries=None,\n library_dirs=None, runtime_library_dirs=None,\n export_symbols=None, debug=0, extra_preargs=None,\n extra_postargs=None, build_temp=None, target_lang=None):\n objects, output_dir = self._fix_object_args(objects, output_dir)\n libraries, library_dirs, runtime_library_dirs = \\\n self._fix_lib_args(libraries, library_dirs, runtime_library_dirs)\n\n lib_opts = gen_lib_options(self, library_dirs, runtime_library_dirs,\n libraries)\n if type(output_dir) not in (StringType, NoneType):\n raise TypeError, \"'output_dir' must be a string or None\"\n if output_dir is not None:\n output_filename = os.path.join(output_dir, output_filename)\n\n if self._need_link(objects, output_filename):\n if self.library_switch[-1]==' ':\n o_args = [self.library_switch.strip(),output_filename]\n else:\n o_args = [self.library_switch.strip()+output_filename]\n ld_args = (objects + self.objects +\n lib_opts + o_args)\n if debug:\n ld_args[:0] = ['-g']\n if extra_preargs:\n ld_args[:0] = extra_preargs\n if extra_postargs:\n ld_args.extend(extra_postargs)\n self.mkpath(os.path.dirname(output_filename))\n if target_desc == CCompiler.EXECUTABLE:\n raise NotImplementedError,self.__class__.__name__+'.linker_exe attribute'\n else:\n linker = self.linker_so[:]\n if os.name == 'nt':\n linker = _nt_quote_args(linker)\n command = linker + ld_args\n try:\n self.spawn(command)\n except DistutilsExecError, msg:\n raise LinkError, msg\n else:\n log.debug(\"skipping %s (up-to-date)\", output_filename)\n return\n\n ############################################################\n\n ## Private methods:\n\n def __get_cmd(self, command, envvar=None, confvar=None):\n if command is None:\n var = None\n elif type(command) is type(''):\n var = self.executables[command]\n if var is not None:\n var = var[0]\n else:\n var = command()\n if envvar is not None:\n var = os.environ.get(envvar, var)\n if confvar is not None:\n var = confvar[0].get(confvar[1], [None,var])[1]\n return var\n\n def __get_flags(self, command, envvar=None, confvar=None):\n if command is None:\n var = []\n elif type(command) is type(''):\n var = self.executables[command][1:]\n else:\n var = command()\n if envvar is not None:\n var = os.environ.get(envvar, var)\n if confvar is not None:\n var = confvar[0].get(confvar[1], [None,var])[1]\n if type(var) is type(''):\n var = split_quoted(var)\n return var\n\n ## class FCompiler\n\n##############################################################################\n\nfcompiler_class = {'gnu':('gnufcompiler','GnuFCompiler',\n \"GNU Fortran Compiler\"),\n 'pg':('pgfcompiler','PGroupFCompiler',\n \"Portland Group Fortran Compiler\"),\n 'absoft':('absoftfcompiler','AbsoftFCompiler',\n \"Absoft Corp Fortran Compiler\"),\n 'mips':('mipsfcompiler','MipsFCompiler',\n \"MIPSpro Fortran Compiler\"),\n 'sun':('sunfcompiler','SunFCompiler',\n \"Sun|Forte Fortran 95 Compiler\"),\n 'intel':('intelfcompiler','IntelFCompiler',\n \"Intel Fortran Compiler for 32-bit apps\"),\n 'intelv':('intelfcompiler','IntelVisualFCompiler',\n \"Intel Visual Fortran Compiler for 32-bit apps\"),\n 'intele':('intelfcompiler','IntelItaniumFCompiler',\n \"Intel Fortran Compiler for Itanium apps\"),\n 'intelev':('intelfcompiler','IntelItaniumVisualFCompiler',\n \"Intel Visual Fortran Compiler for Itanium apps\"),\n 'nag':('nagfcompiler','NAGFCompiler',\n \"NAGWare Fortran 95 Compiler\"),\n 'compaq':('compaqfcompiler','CompaqFCompiler',\n \"Compaq Fortran Compiler\"),\n 'compaqv':('compaqfcompiler','CompaqVisualFCompiler',\n \"DIGITAL|Compaq Visual Fortran Compiler\"),\n 'vast':('vastfcompiler','VastFCompiler',\n \"Pacific-Sierra Research Fortran 90 Compiler\"),\n 'hpux':('hpuxfcompiler','HPUXFCompiler',\n \"HP Fortran 90 Compiler\"),\n 'lahey':('laheyfcompiler','LaheyFCompiler',\n \"Lahey/Fujitsu Fortran 95 Compiler\"),\n 'ibm':('ibmfcompiler','IbmFCompiler',\n \"IBM XL Fortran Compiler\"),\n 'f':('fcompiler','FFCompiler',\n \"Fortran Company/NAG F Compiler\"),\n }\n\n_default_compilers = (\n # Platform mappings\n ('win32',('gnu','intelv','absoft','compaqv','intelev')),\n ('cygwin.*',('gnu','intelv','absoft','compaqv','intelev')),\n ('linux.*',('gnu','intel','lahey','pg','absoft','nag','vast','compaq',\n 'intele')),\n ('darwin.*',('nag','absoft','ibm','gnu')),\n ('sunos.*',('forte','gnu','sun')),\n ('irix.*',('mips','gnu')),\n ('aix.*',('ibm','gnu')),\n # OS mappings\n ('posix',('gnu',)),\n ('nt',('gnu',)),\n ('mac',('gnu',)),\n )\n\ndef _find_existing_fcompiler(compilers, osname=None, platform=None):\n for compiler in compilers:\n v = None\n try:\n c = new_fcompiler(plat=platform, compiler=compiler)\n c.customize()\n v = c.get_version()\n except DistutilsModuleError:\n pass\n except Exception, msg:\n log.warn(msg)\n if v is not None:\n return compiler\n return\n\ndef get_default_fcompiler(osname=None, platform=None):\n \"\"\" Determine the default Fortran compiler to use for the given platform. \"\"\"\n if osname is None:\n osname = os.name\n if platform is None:\n platform = sys.platform\n matching_compilers = []\n for pattern, compiler in _default_compilers:\n if re.match(pattern, platform) is not None or \\\n re.match(pattern, osname) is not None:\n if type(compiler) is type(()):\n matching_compilers.extend(list(compiler))\n else:\n matching_compilers.append(compiler)\n if not matching_compilers:\n matching_compilers.append('gnu')\n compiler = _find_existing_fcompiler(matching_compilers,\n osname=osname,\n platform=platform)\n if compiler is not None:\n return compiler\n return matching_compilers[0]\n\ndef new_fcompiler(plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n \"\"\" Generate an instance of some FCompiler subclass for the supplied\n platform/compiler combination.\n \"\"\"\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_fcompiler(plat)\n (module_name, class_name, long_description) = fcompiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile Fortran code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler.\" % compiler\n msg = msg + \" Supported compilers are: %s)\" \\\n % (','.join(fcompiler_class.keys()))\n raise DistutilsPlatformError, msg\n\n try:\n module_name = 'scipy_distutils.'+module_name\n __import__ (module_name)\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile Fortran code: unable to load module '%s'\" % \\\n module_name\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile Fortran code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\ndef show_fcompilers(dist = None):\n \"\"\" Print list of available compilers (used by the \"--help-fcompiler\"\n option to \"config_fc\").\n \"\"\"\n if dist is None:\n from dist import Distribution\n dist = Distribution()\n dist.script_name = os.path.basename(sys.argv[0])\n dist.script_args = ['config_fc'] + sys.argv[1:]\n dist.cmdclass['config_fc'] = config_fc\n dist.parse_config_files()\n dist.parse_command_line()\n\n compilers = []\n compilers_na = []\n compilers_ni = []\n for compiler in fcompiler_class.keys():\n v = 'N/A'\n try:\n c = new_fcompiler(compiler=compiler)\n c.customize(dist)\n v = c.get_version()\n except DistutilsModuleError:\n pass\n except Exception, msg:\n log.warn(msg)\n if v is None:\n compilers_na.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2]))\n elif v=='N/A':\n compilers_ni.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2]))\n else:\n compilers.append((\"fcompiler=\"+compiler, None,\n fcompiler_class[compiler][2] + ' (%s)' % v))\n compilers.sort()\n compilers_na.sort()\n pretty_printer = FancyGetopt(compilers)\n pretty_printer.print_help(\"List of available Fortran compilers:\")\n pretty_printer = FancyGetopt(compilers_na)\n pretty_printer.print_help(\"List of unavailable Fortran compilers:\")\n if compilers_ni:\n pretty_printer = FancyGetopt(compilers_ni)\n pretty_printer.print_help(\"List of unimplemented Fortran compilers:\")\n print \"For compiler details, run 'config_fc --verbose' setup command.\"\n\ndef dummy_fortran_file():\n import tempfile\n dummy_name = tempfile.mktemp()+'__dummy'\n dummy = open(dummy_name+'.f','w')\n dummy.write(\" subroutine dummy()\\n end\\n\")\n dummy.close()\n def rm_file(name=dummy_name,log_threshold=log._global_log.threshold):\n save_th = log._global_log.threshold\n log.set_threshold(log_threshold)\n try: os.remove(name+'.f'); log.debug('removed '+name+'.f')\n except OSError: pass\n try: os.remove(name+'.o'); log.debug('removed '+name+'.o')\n except OSError: pass\n log.set_threshold(save_th)\n atexit.register(rm_file)\n return dummy_name\n\nis_f_file = re.compile(r'.*[.](for|ftn|f77|f)\\Z',re.I).match\n_has_f_header = re.compile(r'-[*]-\\s*fortran\\s*-[*]-',re.I).search\n_has_f90_header = re.compile(r'-[*]-\\s*f90\\s*-[*]-',re.I).search\n_free_f90_start = re.compile(r'[^c*][^\\s\\d\\t]',re.I).match\ndef is_free_format(file):\n \"\"\"Check if file is in free format Fortran.\"\"\"\n # f90 allows both fixed and free format, assuming fixed unless\n # signs of free format are detected.\n result = 0\n f = open(file,'r')\n line = f.readline()\n n = 15 # the number of non-comment lines to scan for hints\n if _has_f_header(line):\n n = 0\n elif _has_f90_header(line):\n n = 0\n result = 1\n while n>0 and line:\n if line[0]!='!':\n n -= 1\n if (line[0]!='\\t' and _free_f90_start(line[:5])) or line[-2:-1]=='&':\n result = 1\n break\n line = f.readline()\n f.close()\n return result\n\nif __name__ == '__main__':\n show_fcompilers()\n", "methods": [ { "name": "get_version_cmd", "long_name": "get_version_cmd( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 6, "token_count": 96, "parameters": [ "self" ], "start_line": 188, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 6, "token_count": 96, "parameters": [ "self" ], "start_line": 206, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 224, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_version", "long_name": "get_flags_version( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 227, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f77", "long_name": "get_flags_f77( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 232, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f90", "long_name": "get_flags_f90( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 237, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_fix", "long_name": "get_flags_fix( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 242, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 247, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_ar", "long_name": "get_flags_ar( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 252, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 257, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 260, "end_line": 262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 263, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 270, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 273, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "customize", "long_name": "customize( self , dist = None )", "filename": "fcompiler.py", "nloc": 84, "complexity": 36, "token_count": 799, "parameters": [ "self", "dist" ], "start_line": 281, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 115, "top_nesting_level": 1 }, { "name": "dump_properties", "long_name": "dump_properties( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 5, "token_count": 117, "parameters": [ "self" ], "start_line": 397, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "_compile", "long_name": "_compile( self , obj , src , ext , cc_args , extra_postargs , pp_opts )", "filename": "fcompiler.py", "nloc": 32, "complexity": 8, "token_count": 211, "parameters": [ "self", "obj", "src", "ext", "cc_args", "extra_postargs", "pp_opts" ], "start_line": 418, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 1 }, { "name": "module_options", "long_name": "module_options( self , module_dirs , module_build_dir )", "filename": "fcompiler.py", "nloc": 17, "complexity": 5, "token_count": 129, "parameters": [ "self", "module_dirs", "module_build_dir" ], "start_line": 456, "end_line": 472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "library_option", "long_name": "library_option( self , lib )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "lib" ], "start_line": 474, "end_line": 475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "library_dir_option", "long_name": "library_dir_option( self , dir )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "dir" ], "start_line": 476, "end_line": 477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "compile", "long_name": "compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "fcompiler.py", "nloc": 25, "complexity": 11, "token_count": 256, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 483, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 2 }, { "name": "detect_language", "long_name": "detect_language( self , sources )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self", "sources" ], "start_line": 508, "end_line": 509, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 2 }, { "name": "link", "long_name": "link( self , target_desc , objects , output_filename , output_dir = None , libraries = None , library_dirs = None , runtime_library_dirs = None , export_symbols = None , debug = 0 , extra_preargs = None , extra_postargs = None , build_temp = None , target_lang = None )", "filename": "fcompiler.py", "nloc": 42, "complexity": 11, "token_count": 306, "parameters": [ "self", "target_desc", "objects", "output_filename", "output_dir", "libraries", "library_dirs", "runtime_library_dirs", "export_symbols", "debug", "extra_preargs", "extra_postargs", "build_temp", "target_lang" ], "start_line": 511, "end_line": 554, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 1 }, { "name": "__get_cmd", "long_name": "__get_cmd( self , command , envvar = None , confvar = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 6, "token_count": 110, "parameters": [ "self", "command", "envvar", "confvar" ], "start_line": 560, "end_line": 573, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "__get_flags", "long_name": "__get_flags( self , command , envvar = None , confvar = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 6, "token_count": 120, "parameters": [ "self", "command", "envvar", "confvar" ], "start_line": 575, "end_line": 588, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "_find_existing_fcompiler", "long_name": "_find_existing_fcompiler( compilers , osname = None , platform = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 5, "token_count": 71, "parameters": [ "compilers", "osname", "platform" ], "start_line": 646, "end_line": 659, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_default_fcompiler", "long_name": "get_default_fcompiler( osname = None , platform = None )", "filename": "fcompiler.py", "nloc": 21, "complexity": 9, "token_count": 135, "parameters": [ "osname", "platform" ], "start_line": 661, "end_line": 682, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "new_fcompiler", "long_name": "new_fcompiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "fcompiler.py", "nloc": 34, "complexity": 7, "token_count": 182, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 684, "end_line": 721, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "show_fcompilers", "long_name": "show_fcompilers( dist = None )", "filename": "fcompiler.py", "nloc": 41, "complexity": 8, "token_count": 261, "parameters": [ "dist" ], "start_line": 723, "end_line": 767, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 0 }, { "name": "dummy_fortran_file.rm_file", "long_name": "dummy_fortran_file.rm_file( name = dummy_name , log_threshold = log . _global_log . threshold )", "filename": "fcompiler.py", "nloc": 8, "complexity": 3, "token_count": 84, "parameters": [ "name", "log_threshold" ], "start_line": 775, "end_line": 782, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "dummy_fortran_file", "long_name": "dummy_fortran_file( )", "filename": "fcompiler.py", "nloc": 9, "complexity": 1, "token_count": 46, "parameters": [], "start_line": 769, "end_line": 784, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "is_free_format", "long_name": "is_free_format( file )", "filename": "fcompiler.py", "nloc": 19, "complexity": 9, "token_count": 114, "parameters": [ "file" ], "start_line": 790, "end_line": 811, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_version_cmd", "long_name": "get_version_cmd( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 6, "token_count": 96, "parameters": [ "self" ], "start_line": 188, "end_line": 204, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "get_linker_so", "long_name": "get_linker_so( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 6, "token_count": 96, "parameters": [ "self" ], "start_line": 206, "end_line": 222, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 224, "end_line": 226, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_version", "long_name": "get_flags_version( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 227, "end_line": 231, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f77", "long_name": "get_flags_f77( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 232, "end_line": 236, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_f90", "long_name": "get_flags_f90( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 237, "end_line": 241, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_fix", "long_name": "get_flags_fix( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 242, "end_line": 246, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 247, "end_line": 251, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_ar", "long_name": "get_flags_ar( self )", "filename": "fcompiler.py", "nloc": 4, "complexity": 2, "token_count": 28, "parameters": [ "self" ], "start_line": 252, "end_line": 256, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 257, "end_line": 259, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 260, "end_line": 262, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 263, "end_line": 265, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_libraries", "long_name": "get_libraries( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 270, "end_line": 272, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_library_dirs", "long_name": "get_library_dirs( self )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 13, "parameters": [ "self" ], "start_line": 273, "end_line": 275, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "customize", "long_name": "customize( self , dist = None )", "filename": "fcompiler.py", "nloc": 84, "complexity": 36, "token_count": 799, "parameters": [ "self", "dist" ], "start_line": 281, "end_line": 395, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 115, "top_nesting_level": 1 }, { "name": "dump_properties", "long_name": "dump_properties( self )", "filename": "fcompiler.py", "nloc": 16, "complexity": 5, "token_count": 117, "parameters": [ "self" ], "start_line": 397, "end_line": 414, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 18, "top_nesting_level": 1 }, { "name": "_compile", "long_name": "_compile( self , obj , src , ext , cc_args , extra_postargs , pp_opts )", "filename": "fcompiler.py", "nloc": 32, "complexity": 8, "token_count": 211, "parameters": [ "self", "obj", "src", "ext", "cc_args", "extra_postargs", "pp_opts" ], "start_line": 418, "end_line": 454, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 1 }, { "name": "module_options", "long_name": "module_options( self , module_dirs , module_build_dir )", "filename": "fcompiler.py", "nloc": 17, "complexity": 5, "token_count": 129, "parameters": [ "self", "module_dirs", "module_build_dir" ], "start_line": 456, "end_line": 472, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 1 }, { "name": "library_option", "long_name": "library_option( self , lib )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "lib" ], "start_line": 474, "end_line": 475, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "library_dir_option", "long_name": "library_dir_option( self , dir )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self", "dir" ], "start_line": 476, "end_line": 477, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "compile", "long_name": "compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "fcompiler.py", "nloc": 25, "complexity": 11, "token_count": 264, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 483, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 2 }, { "name": "detect_language", "long_name": "detect_language( self , sources )", "filename": "fcompiler.py", "nloc": 2, "complexity": 1, "token_count": 8, "parameters": [ "self", "sources" ], "start_line": 508, "end_line": 509, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 2 }, { "name": "link", "long_name": "link( self , target_desc , objects , output_filename , output_dir = None , libraries = None , library_dirs = None , runtime_library_dirs = None , export_symbols = None , debug = 0 , extra_preargs = None , extra_postargs = None , build_temp = None , target_lang = None )", "filename": "fcompiler.py", "nloc": 42, "complexity": 11, "token_count": 306, "parameters": [ "self", "target_desc", "objects", "output_filename", "output_dir", "libraries", "library_dirs", "runtime_library_dirs", "export_symbols", "debug", "extra_preargs", "extra_postargs", "build_temp", "target_lang" ], "start_line": 511, "end_line": 554, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 1 }, { "name": "__get_cmd", "long_name": "__get_cmd( self , command , envvar = None , confvar = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 6, "token_count": 110, "parameters": [ "self", "command", "envvar", "confvar" ], "start_line": 560, "end_line": 573, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "__get_flags", "long_name": "__get_flags( self , command , envvar = None , confvar = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 6, "token_count": 120, "parameters": [ "self", "command", "envvar", "confvar" ], "start_line": 575, "end_line": 588, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 1 }, { "name": "_find_existing_fcompiler", "long_name": "_find_existing_fcompiler( compilers , osname = None , platform = None )", "filename": "fcompiler.py", "nloc": 14, "complexity": 5, "token_count": 71, "parameters": [ "compilers", "osname", "platform" ], "start_line": 646, "end_line": 659, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "get_default_fcompiler", "long_name": "get_default_fcompiler( osname = None , platform = None )", "filename": "fcompiler.py", "nloc": 21, "complexity": 9, "token_count": 135, "parameters": [ "osname", "platform" ], "start_line": 661, "end_line": 682, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "new_fcompiler", "long_name": "new_fcompiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "fcompiler.py", "nloc": 34, "complexity": 7, "token_count": 182, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 684, "end_line": 721, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "show_fcompilers", "long_name": "show_fcompilers( dist = None )", "filename": "fcompiler.py", "nloc": 41, "complexity": 8, "token_count": 261, "parameters": [ "dist" ], "start_line": 723, "end_line": 767, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 45, "top_nesting_level": 0 }, { "name": "dummy_fortran_file.rm_file", "long_name": "dummy_fortran_file.rm_file( name = dummy_name , log_threshold = log . _global_log . threshold )", "filename": "fcompiler.py", "nloc": 8, "complexity": 3, "token_count": 84, "parameters": [ "name", "log_threshold" ], "start_line": 775, "end_line": 782, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 1 }, { "name": "dummy_fortran_file", "long_name": "dummy_fortran_file( )", "filename": "fcompiler.py", "nloc": 9, "complexity": 1, "token_count": 46, "parameters": [], "start_line": 769, "end_line": 784, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "is_free_format", "long_name": "is_free_format( file )", "filename": "fcompiler.py", "nloc": 19, "complexity": 9, "token_count": 114, "parameters": [ "file" ], "start_line": 790, "end_line": 811, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "compile", "long_name": "compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "fcompiler.py", "nloc": 25, "complexity": 11, "token_count": 256, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 483, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 25, "top_nesting_level": 2 } ], "nloc": 606, "complexity": 163, "token_count": 4083, "diff_parsed": { "added": [ " cc_args = [] #self._get_cc_args(pp_opts, debug, extra_preargs)" ], "deleted": [ " cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)" ] } } ] }, { "hash": "0380887ac694b8585420db1a9fc881809c9e1d82", "msg": "Deal with pure python subpackages that have no setup_*.py file.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-20T22:58:34+00:00", "author_timezone": 0, "committer_date": "2004-03-20T22:58:34+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "208baf5040453401ffa6e26c8f48dd4e1917361a" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 1, "insertions": 9, "lines": 10, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.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": "@@ -444,7 +444,15 @@ def get_subpackages(path,\n del sys.path[0]\n \n for package_name in include_packages:\n- sys.path.insert(0,os.path.join(path, package_name))\n+ dirname = os.path.join(path, package_name)\n+ setup_file = os.path.join(dirname,'setup_' + package_name+'.py')\n+ if not os.path.isfile(setup_file):\n+ print 'Assuming default configuration (%r was not found)' \\\n+ % (setup_file)\n+ config = default_config_dict(package_name, parent or '')\n+ config_list.append(config)\n+ continue\n+ sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n", "added_lines": 9, "deleted_lines": 1, "source_code": "import os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\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 mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\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\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() function 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 \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\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 # Todo: implement check for this assumption.\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\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 if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and 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 get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\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 dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\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\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[]):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n for package_name in include_packages:\n dirname = os.path.join(path, package_name)\n setup_file = os.path.join(dirname,'setup_' + package_name+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n config = default_config_dict(package_name, parent or '')\n config_list.append(config)\n continue\n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "source_code_before": "import os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\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 mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\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\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() function 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 \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\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 # Todo: implement check for this assumption.\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\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 if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and 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 get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\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 dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\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\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[]):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n for package_name in include_packages:\n sys.path.insert(0,os.path.join(path, package_name))\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "methods": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 13, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 59, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "self", "name" ], "start_line": 62, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 5, "token_count": 124, "parameters": [ "mod_name", "parent_path" ], "start_line": 65, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "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": 86, "end_line": 88, "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": 90, "end_line": 93, "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": 95, "end_line": 96, "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": 98, "end_line": 112, "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": 114, "end_line": 124, "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": 126, "end_line": 138, "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": 29, "complexity": 13, "token_count": 266, "parameters": [ "name", "parent_name" ], "start_line": 145, "end_line": 183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 185, "end_line": 192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 13, "complexity": 6, "token_count": 89, "parameters": [ "config_list" ], "start_line": 194, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 44, "parameters": [ "d", "kws" ], "start_line": 208, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 215, "end_line": 216, "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": 218, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 235, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 241, "end_line": 244, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 255, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "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": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 270, "end_line": 281, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 282, "end_line": 283, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 291, "end_line": 294, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 295, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 297, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 307, "end_line": 323, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 325, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 332, "end_line": 337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 339, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 346, "end_line": 366, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 368, "end_line": 386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] )", "filename": "misc_util.py", "nloc": 53, "complexity": 15, "token_count": 387, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages" ], "start_line": 388, "end_line": 468, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 81, "top_nesting_level": 0 } ], "methods_before": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 13, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 59, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "self", "name" ], "start_line": 62, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 5, "token_count": 124, "parameters": [ "mod_name", "parent_path" ], "start_line": 65, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "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": 86, "end_line": 88, "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": 90, "end_line": 93, "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": 95, "end_line": 96, "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": 98, "end_line": 112, "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": 114, "end_line": 124, "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": 126, "end_line": 138, "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": 29, "complexity": 13, "token_count": 266, "parameters": [ "name", "parent_name" ], "start_line": 145, "end_line": 183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 185, "end_line": 192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 13, "complexity": 6, "token_count": 89, "parameters": [ "config_list" ], "start_line": 194, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 44, "parameters": [ "d", "kws" ], "start_line": 208, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 215, "end_line": 216, "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": 218, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 235, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 241, "end_line": 244, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 255, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "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": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 270, "end_line": 281, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 282, "end_line": 283, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 291, "end_line": 294, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 295, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 297, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 307, "end_line": 323, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 325, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 332, "end_line": 337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 339, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 346, "end_line": 366, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 368, "end_line": 386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] )", "filename": "misc_util.py", "nloc": 45, "complexity": 13, "token_count": 333, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages" ], "start_line": 388, "end_line": 460, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 73, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] )", "filename": "misc_util.py", "nloc": 53, "complexity": 15, "token_count": 387, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages" ], "start_line": 388, "end_line": 468, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 81, "top_nesting_level": 0 } ], "nloc": 347, "complexity": 113, "token_count": 2532, "diff_parsed": { "added": [ " dirname = os.path.join(path, package_name)", " setup_file = os.path.join(dirname,'setup_' + package_name+'.py')", " if not os.path.isfile(setup_file):", " print 'Assuming default configuration (%r was not found)' \\", " % (setup_file)", " config = default_config_dict(package_name, parent or '')", " config_list.append(config)", " continue", " sys.path.insert(0,dirname)" ], "deleted": [ " sys.path.insert(0,os.path.join(path, package_name))" ] } } ] }, { "hash": "6a376b2f578e5455fb440e1a89c0a937d3543dcf", "msg": "Fixed local_path for previously commited feature", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-20T23:20:29+00:00", "author_timezone": 0, "committer_date": "2004-03-20T23:20:29+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "0380887ac694b8585420db1a9fc881809c9e1d82" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 5, "insertions": 10, "lines": 15, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.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": "@@ -142,7 +142,7 @@ def package_config(primary,dependencies=[]):\n 'headers']\n dict_keys = ['package_dir']\n \n-def default_config_dict(name = None, parent_name = None):\n+def default_config_dict(name = None, parent_name = None, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\n@@ -156,9 +156,10 @@ def default_config_dict(name = None, parent_name = None):\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n # Todo: implement check for this assumption.\n- frame = get_frame(1)\n- caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n- local_path = get_path(caller_name)\n+ if local_path is None:\n+ frame = get_frame(1)\n+ caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n+ local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n@@ -445,13 +446,17 @@ def get_subpackages(path,\n \n for package_name in include_packages:\n dirname = os.path.join(path, package_name)\n+\n setup_file = os.path.join(dirname,'setup_' + package_name+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n- config = default_config_dict(package_name, parent or '')\n+\n+ config = default_config_dict(package_name, parent or '',\n+ local_path=dirname)\n config_list.append(config)\n continue\n+ \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n", "added_lines": 10, "deleted_lines": 5, "source_code": "import os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\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 mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\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\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() function 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, local_path=None):\n \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\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 # Todo: implement check for this assumption.\n if local_path is None:\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\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 if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and 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 get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\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 dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\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\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[]):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n for package_name in include_packages:\n dirname = os.path.join(path, package_name)\n\n setup_file = os.path.join(dirname,'setup_' + package_name+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n\n config = default_config_dict(package_name, parent or '',\n local_path=dirname)\n config_list.append(config)\n continue\n \n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "source_code_before": "import os,sys,string\nimport re\nimport types\nimport glob\n\nif sys.version[:3]<='2.1':\n from distutils import util\n util_get_platform = util.get_platform\n util.get_platform = lambda : util_get_platform().replace(' ','_')\n\n# Hooks for colored terminal output.\n# See also http://www.livinglogic.de/Python/ansistyle\ndef terminal_has_colors():\n if sys.platform=='cygwin' and not os.environ.has_key('USE_COLOR'):\n # Avoid importing curses that causes illegal operation\n # with a message:\n # PYTHON2 caused an invalid page fault in\n # module CYGNURSES7.DLL as 015f:18bbfc28\n # Details: Python 2.3.3 [GCC 3.3.1 (cygming special)]\n # ssh to Win32 machine from debian\n # curses.version is 2.2\n # CYGWIN_98-4.10, release 1.5.7(0.109/3/2))\n return 0\n if hasattr(sys.stdout,'isatty') and sys.stdout.isatty(): \n try:\n import curses\n curses.setupterm()\n if (curses.tigetnum(\"colors\") >= 0\n and curses.tigetnum(\"pairs\") >= 0\n and ((curses.tigetstr(\"setf\") is not None \n and curses.tigetstr(\"setb\") is not None) \n or (curses.tigetstr(\"setaf\") is not None\n and curses.tigetstr(\"setab\") is not None)\n or curses.tigetstr(\"scp\") is not None)):\n return 1\n except Exception,msg:\n pass\n return 0\n\nif terminal_has_colors():\n def red_text(s): return '\\x1b[31m%s\\x1b[0m'%s\n def green_text(s): return '\\x1b[32m%s\\x1b[0m'%s\n def yellow_text(s): return '\\x1b[33m%s\\x1b[0m'%s\n def blue_text(s): return '\\x1b[34m%s\\x1b[0m'%s\n def cyan_text(s): return '\\x1b[35m%s\\x1b[0m'%s\nelse:\n def red_text(s): return s\n def green_text(s): return s\n def yellow_text(s): return s\n def cyan_text(s): return s\n def blue_text(s): return s\n\nclass PostponedException:\n \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"\n #Example usage:\n # try: import foo\n # except ImportError: foo = PostponedException()\n __all__ = []\n def __init__(self):\n self._info = sys.exc_info()[:2]\n self.__doc__ = '%s: %s' % tuple(self._info)\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef get_path(mod_name,parent_path=None):\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 mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n if parent_path is not None:\n pd = os.path.abspath(parent_path)\n if pd==d[:len(pd)]:\n d = d[len(pd)+1:]\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\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() function 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 \"\"\" Return a configuration dictionary for usage in\n configuration() function defined in file setup_.py.\n \"\"\"\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 # Todo: implement check for this assumption.\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n test_path = os.path.join(local_path,'tests')\n if 0 and name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\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 if os.path.exists(test_path):\n d['packages'].append(dot_join(full_name,'tests'))\n d['package_dir'][dot_join(full_name,'tests')] = test_path\n d['name'] = full_name\n if 0 and 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 get_frame(level=0):\n try:\n return sys._getframe(level+1)\n except AttributeError:\n frame = sys.exc_info()[2].tb_frame\n for i in range(level+1):\n frame = frame.f_back\n return frame\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n name = d.get('name',None)\n if name is not None:\n result['name'] = name\n break\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 dict_append(d,**kws):\n for k,v in kws.items():\n if d.has_key(k):\n d[k].extend(v)\n else:\n d[k] = v\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ): #obsolete feature\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\ndef get_environ_include_dirs(): #obsolete feature\n includes = []\n if os.environ.has_key('PYTHONINCLUDE'):\n includes = os.environ['PYTHONINCLUDE'].split(os.pathsep)\n return includes\n\ndef get_build_temp():\n from distutils.util import get_platform\n plat_specifier = \".%s-%s\" % (get_platform(), sys.version[0:3])\n return os.path.join('build','temp'+plat_specifier)\n\nclass SourceGenerator: #obsolete feature\n \"\"\" SourceGenerator\n func - creates target, arguments are (target,sources)+args\n sources - target source files\n args - extra arguments to func\n\n If func is None then target must exist and it is touched whenever\n sources are newer.\n \"\"\"\n def __init__(self,func,target,sources=[],*args):\n if not os.path.isabs(target) and func is not None:\n g = sys._getframe(1).f_globals\n fn = g.get('__file__',g.get('__name__'))\n if fn=='__main__': fn = sys.argv[0]\n caller_dir = os.path.abspath(os.path.dirname(fn))\n prefix = os.path.commonprefix([caller_dir,os.getcwd()])\n target_dir = caller_dir[len(prefix)+1:]\n target = os.path.join(get_build_temp(),target_dir,target)\n self.func = func\n self.target = target\n self.sources = sources\n self.args = args\n def __str__(self):\n return str(self.target)\n def generate(self):\n from distutils import dep_util,dir_util\n if dep_util.newer_group(self.sources,self.target):\n print 'Running generate',self.target\n dir_util.mkpath(os.path.dirname(self.target),verbose=1)\n if self.func is None:\n # Touch target\n os.utime(self.target,None)\n else:\n self.func(self.target,self.sources,*self.args)\n assert os.path.exists(self.target),`self.target`\n return self.target\n def __call__(self, extension, src_dir):\n return self.generate()\n\nclass SourceFilter: #obsolete feature\n \"\"\" SourceFilter\n func - implements criteria to filter sources\n sources - source files\n args - extra arguments to func\n \"\"\"\n def __init__(self,func,sources,*args):\n self.func = func\n self.sources = sources\n self.args = args\n def filter(self):\n return self.func(self.sources,*self.args)\n def __call__(self, extension, src_dir):\n return self.filter()\n\n##\n\n#XXX need support for .C that is also C++\ncxx_ext_match = re.compile(r'.*[.](cpp|cxx|cc)\\Z',re.I).match\nfortran_ext_match = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\nf90_ext_match = re.compile(r'.*[.](f90|f95)\\Z',re.I).match\nf90_module_name_match = re.compile(r'\\s*module\\s*(?P[\\w_]+)',re.I).match\ndef get_f90_modules(source):\n \"\"\" Return a list of Fortran f90 module names that\n given source file defines.\n \"\"\"\n if not f90_ext_match(source):\n return []\n modules = []\n f = open(source,'r')\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = f90_module_name_match(line)\n if m:\n name = m.group('name')\n modules.append(name)\n # break # XXX can we assume that there is one module per file?\n f.close()\n return modules\n\ndef all_strings(lst):\n \"\"\" Return True if all items in lst are string objects. \"\"\"\n for item in lst:\n if type(item) is not types.StringType:\n return 0\n return 1\n\ndef has_f_sources(sources):\n \"\"\" Return True if sources contains Fortran files \"\"\"\n for source in sources:\n if fortran_ext_match(source):\n return 1\n return 0\n\ndef has_cxx_sources(sources):\n \"\"\" Return True if sources contains C++ files \"\"\"\n for source in sources:\n if cxx_ext_match(source):\n return 1\n return 0\n\ndef filter_sources(sources):\n \"\"\" Return four lists of filenames containing\n C, C++, Fortran, and Fortran 90 module sources,\n respectively.\n \"\"\"\n c_sources = []\n cxx_sources = []\n f_sources = []\n fmodule_sources = []\n for source in sources:\n if fortran_ext_match(source):\n modules = get_f90_modules(source)\n if modules:\n fmodule_sources.append(source)\n else:\n f_sources.append(source)\n elif cxx_ext_match(source):\n cxx_sources.append(source)\n else:\n c_sources.append(source) \n return c_sources, cxx_sources, f_sources, fmodule_sources\n\ndef compiler_to_string(compiler):\n props = []\n mx = 0\n keys = compiler.executables.keys()\n for key in ['version','libraries','library_dirs',\n 'object_switch','compile_switch',\n 'include_dirs','define','undef','rpath','link_objects']:\n if key not in keys:\n keys.append(key)\n for key in keys:\n if hasattr(compiler,key):\n v = getattr(compiler, key)\n mx = max(mx,len(key))\n props.append((key,`v`))\n lines = []\n format = '%-' +`mx+1`+ 's = %s'\n for prop in props:\n lines.append(format % prop)\n return '\\n'.join(lines)\n\ndef get_subpackages(path,\n parent=None,\n parent_path=None,\n include_packages=[],\n ignore_packages=[]):\n\n \"\"\"\n Return a list of configurations found in a tree of Python\n packages.\n\n It is assumed that each package xxx in path/xxx has file\n path/xxx/info_xxx.py that follows convention specified in\n scipy/DEVELOPERS.txt.\n\n Packages that do not define info_*.py files or should override\n options in info*_.py files can be specified in include_packages\n list.\n\n Unless a package xxx is specified standalone, it will be installed\n as parent.xxx.\n\n Specifying parent_path is recommended for reducing verbosity of\n compilations.\n\n Packages in ignore_packages list will be ignored unless they are\n also in include_packages.\n \"\"\"\n\n config_list = []\n\n for info_file in glob.glob(os.path.join(path,'*','info_*.py')):\n\n package_name = os.path.basename(os.path.dirname(info_file))\n if package_name != os.path.splitext(os.path.basename(info_file))[0][5:]:\n print ' !! Mismatch of package name %r and %s' \\\n % (package_name, info_file)\n continue\n\n if package_name in ignore_packages:\n continue\n\n sys.path.insert(0,os.path.dirname(info_file))\n try:\n exec 'import %s as info_module' \\\n % (os.path.splitext(os.path.basename(info_file))[0])\n if not getattr(info_module,'ignore',0):\n exec 'import setup_%s as setup_module' % (package_name)\n if getattr(info_module,'standalone',0) or not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n\n for package_name in include_packages:\n dirname = os.path.join(path, package_name)\n setup_file = os.path.join(dirname,'setup_' + package_name+'.py')\n if not os.path.isfile(setup_file):\n print 'Assuming default configuration (%r was not found)' \\\n % (setup_file)\n config = default_config_dict(package_name, parent or '')\n config_list.append(config)\n continue\n sys.path.insert(0,dirname)\n try:\n exec 'import setup_%s as setup_module' % (package_name)\n if not parent:\n args = ('',)\n else:\n args = (parent,)\n if setup_module.configuration.func_code.co_argcount>1:\n args = args + (parent_path,)\n config = setup_module.configuration(*args)\n config_list.append(config)\n finally:\n del sys.path[0]\n return config_list\n\nif __name__ == '__main__':\n print 'terminal_has_colors:',terminal_has_colors()\n print red_text(\"This is red text\")\n print yellow_text(\"This is yellow text\")\n", "methods": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 13, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 59, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "self", "name" ], "start_line": 62, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 5, "token_count": 124, "parameters": [ "mod_name", "parent_path" ], "start_line": 65, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "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": 86, "end_line": 88, "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": 90, "end_line": 93, "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": 95, "end_line": 96, "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": 98, "end_line": 112, "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": 114, "end_line": 124, "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": 126, "end_line": 138, "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 , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 145, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 186, "end_line": 193, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 13, "complexity": 6, "token_count": 89, "parameters": [ "config_list" ], "start_line": 195, "end_line": 207, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 44, "parameters": [ "d", "kws" ], "start_line": 209, "end_line": 214, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 216, "end_line": 217, "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": 219, "end_line": 234, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 236, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 242, "end_line": 245, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 256, "end_line": 268, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "parameters": [ "self" ], "start_line": 269, "end_line": 270, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 271, "end_line": 282, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 283, "end_line": 284, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 292, "end_line": 295, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "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": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 298, "end_line": 299, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 308, "end_line": 324, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 326, "end_line": 331, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 333, "end_line": 338, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 340, "end_line": 345, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 347, "end_line": 367, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 369, "end_line": 387, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] )", "filename": "misc_util.py", "nloc": 54, "complexity": 15, "token_count": 391, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages" ], "start_line": 389, "end_line": 473, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 0 } ], "methods_before": [ { "name": "terminal_has_colors", "long_name": "terminal_has_colors( )", "filename": "misc_util.py", "nloc": 18, "complexity": 13, "token_count": 137, "parameters": [], "start_line": 13, "end_line": 38, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "misc_util.py", "nloc": 3, "complexity": 1, "token_count": 30, "parameters": [ "self" ], "start_line": 59, "end_line": 61, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "__getattr__", "long_name": "__getattr__( self , name )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 21, "parameters": [ "self", "name" ], "start_line": 62, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_path", "long_name": "get_path( mod_name , parent_path = None )", "filename": "misc_util.py", "nloc": 14, "complexity": 5, "token_count": 124, "parameters": [ "mod_name", "parent_path" ], "start_line": 65, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "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": 86, "end_line": 88, "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": 90, "end_line": 93, "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": 95, "end_line": 96, "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": 98, "end_line": 112, "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": 114, "end_line": 124, "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": 126, "end_line": 138, "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": 29, "complexity": 13, "token_count": 266, "parameters": [ "name", "parent_name" ], "start_line": 145, "end_line": 183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 }, { "name": "get_frame", "long_name": "get_frame( level = 0 )", "filename": "misc_util.py", "nloc": 8, "complexity": 3, "token_count": 50, "parameters": [ "level" ], "start_line": 185, "end_line": 192, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "merge_config_dicts", "long_name": "merge_config_dicts( config_list )", "filename": "misc_util.py", "nloc": 13, "complexity": 6, "token_count": 89, "parameters": [ "config_list" ], "start_line": 194, "end_line": 206, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 0 }, { "name": "dict_append", "long_name": "dict_append( d , ** kws )", "filename": "misc_util.py", "nloc": 6, "complexity": 3, "token_count": 44, "parameters": [ "d", "kws" ], "start_line": 208, "end_line": 213, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "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": 215, "end_line": 216, "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": 218, "end_line": 233, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "get_environ_include_dirs", "long_name": "get_environ_include_dirs( )", "filename": "misc_util.py", "nloc": 5, "complexity": 2, "token_count": 35, "parameters": [], "start_line": 235, "end_line": 239, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 0 }, { "name": "get_build_temp", "long_name": "get_build_temp( )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 41, "parameters": [], "start_line": 241, "end_line": 244, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , func , target , sources = [ ] , * args )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 154, "parameters": [ "self", "func", "target", "sources", "args" ], "start_line": 255, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 13, "top_nesting_level": 1 }, { "name": "__str__", "long_name": "__str__( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 12, "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": "generate", "long_name": "generate( self )", "filename": "misc_util.py", "nloc": 11, "complexity": 3, "token_count": 107, "parameters": [ "self" ], "start_line": 270, "end_line": 281, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 282, "end_line": 283, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self , func , sources , * args )", "filename": "misc_util.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "self", "func", "sources", "args" ], "start_line": 291, "end_line": 294, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "filter", "long_name": "filter( self )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 295, "end_line": 296, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , extension , src_dir )", "filename": "misc_util.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "extension", "src_dir" ], "start_line": 297, "end_line": 298, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_f90_modules", "long_name": "get_f90_modules( source )", "filename": "misc_util.py", "nloc": 13, "complexity": 4, "token_count": 77, "parameters": [ "source" ], "start_line": 307, "end_line": 323, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "all_strings", "long_name": "all_strings( lst )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 26, "parameters": [ "lst" ], "start_line": 325, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_f_sources", "long_name": "has_f_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 332, "end_line": 337, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "has_cxx_sources", "long_name": "has_cxx_sources( sources )", "filename": "misc_util.py", "nloc": 5, "complexity": 3, "token_count": 21, "parameters": [ "sources" ], "start_line": 339, "end_line": 344, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "filter_sources", "long_name": "filter_sources( sources )", "filename": "misc_util.py", "nloc": 17, "complexity": 5, "token_count": 84, "parameters": [ "sources" ], "start_line": 346, "end_line": 366, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "compiler_to_string", "long_name": "compiler_to_string( compiler )", "filename": "misc_util.py", "nloc": 19, "complexity": 6, "token_count": 137, "parameters": [ "compiler" ], "start_line": 368, "end_line": 386, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 19, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] )", "filename": "misc_util.py", "nloc": 53, "complexity": 15, "token_count": 387, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages" ], "start_line": 388, "end_line": 468, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 81, "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": 29, "complexity": 13, "token_count": 266, "parameters": [ "name", "parent_name" ], "start_line": 145, "end_line": 183, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 39, "top_nesting_level": 0 }, { "name": "get_subpackages", "long_name": "get_subpackages( path , parent = None , parent_path = None , include_packages = [ ] , ignore_packages = [ ] )", "filename": "misc_util.py", "nloc": 54, "complexity": 15, "token_count": 391, "parameters": [ "path", "parent", "parent_path", "include_packages", "ignore_packages" ], "start_line": 389, "end_line": 473, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 85, "top_nesting_level": 0 }, { "name": "default_config_dict", "long_name": "default_config_dict( name = None , parent_name = None , local_path = None )", "filename": "misc_util.py", "nloc": 30, "complexity": 14, "token_count": 275, "parameters": [ "name", "parent_name", "local_path" ], "start_line": 145, "end_line": 184, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 } ], "nloc": 349, "complexity": 114, "token_count": 2545, "diff_parsed": { "added": [ "def default_config_dict(name = None, parent_name = None, local_path=None):", " if local_path is None:", " frame = get_frame(1)", " caller_name = eval('__name__',frame.f_globals,frame.f_locals)", " local_path = get_path(caller_name)", "", "", " config = default_config_dict(package_name, parent or '',", " local_path=dirname)", "" ], "deleted": [ "def default_config_dict(name = None, parent_name = None):", " frame = get_frame(1)", " caller_name = eval('__name__',frame.f_globals,frame.f_locals)", " local_path = get_path(caller_name)", " config = default_config_dict(package_name, parent or '')" ] } } ] }, { "hash": "db74b2b2b6f420627fb163ac87bfd06633148379", "msg": "Handle the case where one of the arguments is scalar in assert_array_equal", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-22T17:36:59+00:00", "author_timezone": 0, "committer_date": "2004-03-22T17:36:59+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "6a376b2f578e5455fb440e1a89c0a937d3543dcf" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 3, "insertions": 5, "lines": 8, "files": 1, "dmm_unit_size": 0.0, "dmm_unit_complexity": 0.0, "dmm_unit_interfacing": 0.0, "modified_files": [ { "old_path": "scipy_test/testing.py", "new_path": "scipy_test/testing.py", "filename": "testing.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -638,9 +638,11 @@ def assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n- assert len(shape(x))==len(shape(y)) and \\\n- alltrue(equal(shape(x),shape(y))),\\\n- msg + ' (shapes %s, %s mismatch):\\n\\t' % (shape(x),shape(y)) + err_msg\n+ assert 0 in [len(shape(x)),len(shape(y))] \\\n+ or (len(shape(x))==len(shape(y)) and \\\n+ alltrue(equal(shape(x),shape(y)))),\\\n+ msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n+ % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n", "added_lines": 5, "deleted_lines": 3, "source_code": "\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n import scipy_base.fastumath as math\nexcept ImportError:\n pass\n\nDEBUG=0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.dirname(os.path.abspath(testfile))\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog []'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\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\n__all__.append('harvest_modules')\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 d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\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\n__all__.append('harvest_packages')\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 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\n__all__.append('harvest_modules_and_packages')\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\n__all__.append('harvest_test_suites')\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 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 print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\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\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('assert_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\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 actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n try:\n sc_desired = desired/pow(10,math.floor(math.log10(abs(desired))))\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/pow(10,math.floor(math.log10(abs(actual))))\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert 0 in [len(shape(x)),len(shape(y))] \\\n or (len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y)))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' \\\n % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\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 = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\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'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import whrandom\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = whrandom.random()\n return results\n\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": "\n__all__ = []\n\nimport os,sys,time,glob,string,traceback,unittest\nimport types\nimport imp\n\ntry:\n # These are used by Numeric tests.\n # If Numeric and scipy_base are not available, then some of the\n # functions below will not be available.\n from Numeric import alltrue,equal,shape,ravel,around,zeros,Float64,asarray,\\\n less_equal,array2string,less\n import scipy_base.fastumath as math\nexcept ImportError:\n pass\n\nDEBUG=0\n\n__all__.append('set_package_path')\ndef set_package_path(level=1):\n \"\"\" Prepend package directory to sys.path.\n\n set_package_path should be called from a test_file.py that\n satisfies the following tree structure:\n\n //test_file.py\n\n Then the first existing path name from the following list\n\n /build/lib.-\n /..\n\n is prepended to sys.path.\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from distutils.util import get_platform\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n d = os.path.dirname(os.path.dirname(os.path.abspath(testfile)))\n d1 = os.path.join(d,'build','lib.%s-%s'%(get_platform(),sys.version[:3]))\n if not os.path.isdir(d1):\n d1 = os.path.dirname(d)\n if DEBUG:\n print 'Inserting %r to sys.path' % (d1)\n sys.path.insert(0,d1)\n\n__all__.append('set_local_path')\ndef set_local_path(level=1):\n \"\"\" Prepend local directory to sys.path.\n\n The caller is responsible for removing this path by using\n\n restore_path()\n \"\"\"\n from scipy_distutils.misc_util import get_frame\n f = get_frame(level)\n if f.f_locals['__name__']=='__main__':\n testfile = sys.argv[0]\n else:\n testfile = f.f_locals['__file__']\n local_path = os.path.dirname(os.path.abspath(testfile))\n if DEBUG:\n print 'Inserting %r to sys.path' % (local_path)\n sys.path.insert(0,local_path)\n\n__all__.append('restore_path')\ndef restore_path():\n if DEBUG:\n print 'Removing %r from sys.path' % (sys.path[0])\n del sys.path[0]\n\nif sys.platform[:5]=='linux':\n def jiffies(_proc_pid_stat = '/proc/%s/stat'%(os.getpid()),\n _load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. See man 5 proc. \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[13])\n except:\n return int(100*(time.time()-_load_time))\n\n def memusage(_proc_pid_stat = '/proc/%s/stat'%(os.getpid())):\n \"\"\" Return virtual memory size in bytes of the running python.\n \"\"\"\n try:\n f=open(_proc_pid_stat,'r')\n l = f.readline().split(' ')\n f.close()\n return int(l[22])\n except:\n return\nelse:\n # os.getpid is not in all platforms available.\n # Using time is safe but inaccurate, especially when process\n # was suspended or sleeping.\n def jiffies(_load_time=time.time()):\n \"\"\" Return number of jiffies (1/100ths of a second) that this\n process has been scheduled in user mode. [Emulation with time.time]. \"\"\"\n return int(100*(time.time()-_load_time))\n\n def memusage():\n \"\"\" Return memory usage of running python. [Not implemented]\"\"\"\n return\n\n__all__.append('ScipyTestCase')\nclass ScipyTestCase (unittest.TestCase):\n\n def measure(self,code_str,times=1):\n \"\"\" Return elapsed time for executing code_str in the\n namespace of the caller for given times.\n \"\"\"\n frame = sys._getframe(1)\n locs,globs = frame.f_locals,frame.f_globals\n code = compile(code_str,\n 'ScipyTestCase runner for '+self.__class__.__name__,\n 'exec')\n i = 0\n elapsed = jiffies()\n while i>> ScipyTest().test(level=1,verbosity=2)\n\n is package name or its module object.\n\n Package is supposed to contain a directory tests/\n with test_*.py files where * refers to the names of submodules.\n\n test_*.py files are supposed to define a classes, derived\n from ScipyTestCase or unittest.TestCase, with methods having\n names starting with test or bench or check.\n\n And that is it! No need to implement test or test_suite functions\n in each .py file.\n\n Also old styled test_suite(level=1) hooks are supported but\n soon to be removed.\n \"\"\"\n def __init__(self, package='__main__'):\n self.package = package\n\n def _module_str(self, module):\n filename = module.__file__[-30:]\n if filename!=module.__file__:\n filename = '...'+filename\n return '' % (`module.__name__`, `filename`)\n\n def _get_method_names(self,clsobj,level):\n names = []\n for mthname in _get_all_method_names(clsobj):\n if mthname[:5] not in ['bench','check'] \\\n and mthname[:4] not in ['test']:\n continue\n mth = getattr(clsobj, mthname)\n if type(mth) is not types.MethodType:\n continue\n d = mth.im_func.func_defaults\n if d is not None:\n mthlevel = d[0]\n else:\n mthlevel = 1\n if level>=mthlevel:\n if mthname not in names:\n names.append(mthname)\n for base in clsobj.__bases__:\n for n in self._get_method_names(base,level):\n if n not in names:\n names.append(n)\n return names\n\n def _get_module_tests(self,module,level):\n mstr = self._module_str\n d,f = os.path.split(module.__file__)\n\n short_module_name = os.path.splitext(os.path.basename(f))[0]\n test_dir = os.path.join(d,'tests')\n test_file = os.path.join(test_dir,'test_'+short_module_name+'.py')\n\n local_test_dir = os.path.join(os.getcwd(),'tests')\n local_test_file = os.path.join(local_test_dir,\n 'test_'+short_module_name+'.py')\n if os.path.basename(os.path.dirname(local_test_dir)) \\\n == os.path.basename(os.path.dirname(test_dir)) \\\n and os.path.isfile(local_test_file):\n test_file = local_test_file\n\n if not os.path.isfile(test_file):\n print ' !! No test file %r found for %s' \\\n % (os.path.basename(test_file), mstr(module))\n return []\n\n try:\n if sys.version[:3]=='2.1':\n # Workaround for Python 2.1 .pyc file generator bug\n import random\n pref = '-nopyc'+`random.randint(1,100)`\n else:\n pref = ''\n f = open(test_file,'r')\n test_module = imp.load_module(\\\n module.__name__+'.test_'+short_module_name+pref,\n f, test_file+pref,('.py', 'r', 1))\n f.close()\n if sys.version[:3]=='2.1' and os.path.isfile(test_file+pref+'c'):\n os.remove(test_file+pref+'c')\n except:\n print ' !! FAILURE importing tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n return self._get_suite_list(test_module, level, module.__name__)\n\n def _get_suite_list(self, test_module, level, module_name='__main__'):\n if hasattr(test_module,'test_suite'):\n # Using old styled test suite\n try:\n total_suite = test_module.test_suite(level)\n return total_suite._tests\n except:\n print ' !! FAILURE building tests for ', mstr(module)\n print ' ',\n output_exception()\n return []\n suite_list = []\n for name in dir(test_module):\n obj = getattr(test_module, name)\n if type(obj) is not type(unittest.TestCase) \\\n or not issubclass(obj, unittest.TestCase) \\\n or obj.__name__[:4] != 'test':\n continue\n suite_list.extend(map(obj,self._get_method_names(obj,level)))\n print ' Found',len(suite_list),'tests for',module_name\n return suite_list\n\n def _touch_ppimported(self, module):\n from scipy_base.ppimport import _ModuleLoader\n if os.path.isdir(os.path.join(os.path.dirname(module.__file__),'tests')):\n # only touching those modules that have tests/ directory\n try: module._pliuh_plauh\n except AttributeError: pass\n for name in dir(module):\n obj = getattr(module,name)\n if isinstance(obj,_ModuleLoader) \\\n and not hasattr(obj,'_ppimport_module') \\\n and not hasattr(obj,'_ppimport_exc_info'):\n self._touch_ppimported(obj)\n\n def test(self,level=1,verbosity=1):\n \"\"\" Run Scipy module test suite with level and verbosity.\n \"\"\"\n if type(self.package) is type(''):\n exec 'import %s as this_package' % (self.package)\n else:\n this_package = self.package\n\n self._touch_ppimported(this_package)\n\n package_name = this_package.__name__\n\n suites = []\n for name, module in sys.modules.items():\n if package_name != name[:len(package_name)] \\\n or module is None \\\n or os.path.basename(os.path.dirname(module.__file__))=='tests':\n continue\n suites.extend(self._get_module_tests(module, level))\n\n suites.extend(self._get_suite_list(sys.modules[package_name], level))\n\n all_tests = unittest.TestSuite(suites)\n runner = unittest.TextTestRunner(verbosity=verbosity)\n runner.run(all_tests)\n return runner\n\n def run(self):\n \"\"\" Run Scipy module test suite with level and verbosity\n taken from sys.argv. Requires optparse module.\n \"\"\"\n try:\n from optparse import OptionParser\n except ImportError:\n print 'Failed to import optparse module, ignoring.'\n return self.test()\n usage = r'usage: %prog []'\n parser = OptionParser(usage)\n parser.add_option(\"-v\", \"--verbosity\",\n action=\"store\",\n dest=\"verbosity\",\n default=1,\n type='int')\n parser.add_option(\"-l\", \"--level\",\n action=\"store\",\n dest=\"level\",\n default=1,\n type='int')\n (options, args) = parser.parse_args()\n self.test(options.level,options.verbosity)\n\n#------------\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\n__all__.append('harvest_modules')\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 d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\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\n__all__.append('harvest_packages')\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 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\n__all__.append('harvest_modules_and_packages')\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\n__all__.append('harvest_test_suites')\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 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 print \" !! FAILURE without error - shouldn't happen\",\n print module.__name__\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\n__all__.append('module_test')\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('module_test_suite')\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # insert the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.insert(0,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\n__all__.append('assert_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert desired == actual, msg\n\n__all__.append('assert_almost_equal')\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(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\n__all__.append('assert_approx_equal')\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 actual, desired = map(float, (actual, desired))\n # Normalized the numbers to be in range (-10.0,10.0)\n try:\n sc_desired = desired/pow(10,math.floor(math.log10(abs(desired))))\n except ZeroDivisionError:\n sc_desired = 0.0\n try:\n sc_actual = actual/pow(10,math.floor(math.log10(abs(actual))))\n except ZeroDivisionError:\n sc_actual = 0.0\n try:\n if ( verbose and len(repr(desired)) < 100 and len(repr(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + repr(desired) \\\n + '\\nACTUAL: ' + repr(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n\n\n__all__.append('assert_array_equal')\ndef assert_array_equal(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not equal'\n try:\n assert len(shape(x))==len(shape(y)) and \\\n alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes %s, %s mismatch):\\n\\t' % (shape(x),shape(y)) + err_msg\n reduced = ravel(equal(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n raise ValueError, msg\n\n__all__.append('assert_array_almost_equal')\ndef assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n x = asarray(x)\n y = asarray(y)\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 = ravel(equal(less_equal(around(abs(x-y),decimal),10.0**(-decimal)),1))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=decimal+1)\n s2 = array2string(y,precision=decimal+1)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\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'\n\n__all__.append('assert_array_less')\ndef assert_array_less(x,y,err_msg=''):\n x,y = asarray(x), asarray(y)\n msg = '\\nArrays are not less-ordered'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = ravel(less(x,y))\n cond = alltrue(reduced)\n if not cond:\n s1 = array2string(x,precision=16)\n s2 = array2string(y,precision=16)\n if len(s1)>120: s1 = s1[:120] + '...'\n if len(s2)>120: s2 = s2[:120] + '...'\n match = 100-100.0*reduced.tolist().count(1)/len(reduced)\n msg = msg + ' (mismatch %s%%):\\n\\tArray 1: %s\\n\\tArray 2: %s' % (match,s1,s2)\n assert cond,\\\n msg + '\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not less-ordered'\n\n__all__.append('rand')\ndef rand(*args):\n \"\"\" Returns an array of random numbers with the given shape.\n used for testing\n \"\"\"\n import whrandom\n results = zeros(args,Float64)\n f = results.flat\n for i in range(len(f)):\n f[i] = whrandom.random()\n return results\n\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": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 21, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 84, "parameters": [ "level" ], "start_line": 55, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 74, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 80, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 92, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 106, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 111, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 118, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 149, "parameters": [ "self", "result" ], "start_line": 135, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 153, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 155, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 164, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 195, "end_line": 196, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 198, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 204, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 36, "complexity": 8, "token_count": 331, "parameters": [ "self", "module", "level" ], "start_line": 227, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 141, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 269, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 291, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 304, "end_line": 329, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 331, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 357, "end_line": 363, "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": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 365, "end_line": 384, "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": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 387, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 426, "end_line": 460, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 463, "end_line": 469, "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": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 472, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 510, "end_line": 537, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 540, "end_line": 562, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 572, "end_line": 586, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 589, "end_line": 603, "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": "testing.py", "nloc": 22, "complexity": 7, "token_count": 195, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 606, "end_line": 633, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 637, "end_line": 658, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 23, "complexity": 5, "token_count": 226, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 661, "end_line": 683, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 686, "end_line": 705, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 708, "end_line": 717, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 719, "end_line": 729, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "methods_before": [ { "name": "set_package_path", "long_name": "set_package_path( level = 1 )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 146, "parameters": [ "level" ], "start_line": 21, "end_line": 52, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 32, "top_nesting_level": 0 }, { "name": "set_local_path", "long_name": "set_local_path( level = 1 )", "filename": "testing.py", "nloc": 11, "complexity": 3, "token_count": 84, "parameters": [ "level" ], "start_line": 55, "end_line": 71, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "restore_path", "long_name": "restore_path( )", "filename": "testing.py", "nloc": 4, "complexity": 2, "token_count": 25, "parameters": [], "start_line": 74, "end_line": 77, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "jiffies", "long_name": "jiffies( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 23, "parameters": [ "_proc_pid_stat" ], "start_line": 80, "end_line": 81, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( _proc_pid_stat = '/proc/%s/stat' % ( os . getpid ( )", "filename": "testing.py", "nloc": 10, "complexity": 2, "token_count": 54, "parameters": [ "_proc_pid_stat" ], "start_line": 92, "end_line": 101, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 1 }, { "name": "jiffies", "long_name": "jiffies( _load_time = time . time ( )", "filename": "testing.py", "nloc": 4, "complexity": 1, "token_count": 27, "parameters": [ "_load_time" ], "start_line": 106, "end_line": 109, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "memusage", "long_name": "memusage( )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 6, "parameters": [], "start_line": 111, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "measure", "long_name": "measure( self , code_str , times = 1 )", "filename": "testing.py", "nloc": 13, "complexity": 2, "token_count": 82, "parameters": [ "self", "code_str", "times" ], "start_line": 118, "end_line": 133, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__call__", "long_name": "__call__( self , result = None )", "filename": "testing.py", "nloc": 15, "complexity": 4, "token_count": 149, "parameters": [ "self", "result" ], "start_line": 135, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 1 }, { "name": "__init__", "long_name": "__init__( self )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 153, "end_line": 154, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "write", "long_name": "write( self , message )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 15, "parameters": [ "self", "message" ], "start_line": 155, "end_line": 156, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_get_all_method_names", "long_name": "_get_all_method_names( cls )", "filename": "testing.py", "nloc": 8, "complexity": 5, "token_count": 56, "parameters": [ "cls" ], "start_line": 164, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "__init__", "long_name": "__init__( self , package = '__main__' )", "filename": "testing.py", "nloc": 2, "complexity": 1, "token_count": 14, "parameters": [ "self", "package" ], "start_line": 195, "end_line": 196, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "_module_str", "long_name": "_module_str( self , module )", "filename": "testing.py", "nloc": 5, "complexity": 2, "token_count": 43, "parameters": [ "self", "module" ], "start_line": 198, "end_line": 202, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 5, "top_nesting_level": 1 }, { "name": "_get_method_names", "long_name": "_get_method_names( self , clsobj , level )", "filename": "testing.py", "nloc": 22, "complexity": 11, "token_count": 142, "parameters": [ "self", "clsobj", "level" ], "start_line": 204, "end_line": 225, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 1 }, { "name": "_get_module_tests", "long_name": "_get_module_tests( self , module , level )", "filename": "testing.py", "nloc": 36, "complexity": 8, "token_count": 331, "parameters": [ "self", "module", "level" ], "start_line": 227, "end_line": 267, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 41, "top_nesting_level": 1 }, { "name": "_get_suite_list", "long_name": "_get_suite_list( self , test_module , level , module_name = '__main__' )", "filename": "testing.py", "nloc": 20, "complexity": 7, "token_count": 141, "parameters": [ "self", "test_module", "level", "module_name" ], "start_line": 269, "end_line": 289, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 1 }, { "name": "_touch_ppimported", "long_name": "_touch_ppimported( self , module )", "filename": "testing.py", "nloc": 11, "complexity": 7, "token_count": 98, "parameters": [ "self", "module" ], "start_line": 291, "end_line": 302, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 12, "top_nesting_level": 1 }, { "name": "test", "long_name": "test( self , level = 1 , verbosity = 1 )", "filename": "testing.py", "nloc": 19, "complexity": 6, "token_count": 166, "parameters": [ "self", "level", "verbosity" ], "start_line": 304, "end_line": 329, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 26, "top_nesting_level": 1 }, { "name": "run", "long_name": "run( self )", "filename": "testing.py", "nloc": 20, "complexity": 2, "token_count": 104, "parameters": [ "self" ], "start_line": 331, "end_line": 353, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 1 }, { "name": "remove_ignored_patterns", "long_name": "remove_ignored_patterns( files , pattern )", "filename": "testing.py", "nloc": 7, "complexity": 3, "token_count": 37, "parameters": [ "files", "pattern" ], "start_line": 357, "end_line": 363, "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": "testing.py", "nloc": 12, "complexity": 3, "token_count": 93, "parameters": [ "original", "ignored_files", "cur_dir" ], "start_line": 365, "end_line": 384, "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": "testing.py", "nloc": 21, "complexity": 4, "token_count": 134, "parameters": [ "package", "ignore" ], "start_line": 387, "end_line": 423, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "harvest_packages", "long_name": "harvest_packages( package , ignore = None )", "filename": "testing.py", "nloc": 23, "complexity": 6, "token_count": 148, "parameters": [ "package", "ignore" ], "start_line": 426, "end_line": 460, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 35, "top_nesting_level": 0 }, { "name": "harvest_modules_and_packages", "long_name": "harvest_modules_and_packages( package , ignore = None )", "filename": "testing.py", "nloc": 3, "complexity": 1, "token_count": 27, "parameters": [ "package", "ignore" ], "start_line": 463, "end_line": 469, "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": "testing.py", "nloc": 23, "complexity": 6, "token_count": 113, "parameters": [ "package", "ignore", "level" ], "start_line": 472, "end_line": 507, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 36, "top_nesting_level": 0 }, { "name": "module_test", "long_name": "module_test( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 10, "complexity": 1, "token_count": 98, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 510, "end_line": 537, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "module_test_suite", "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", "filename": "testing.py", "nloc": 12, "complexity": 1, "token_count": 103, "parameters": [ "mod_name", "mod_file", "level" ], "start_line": 540, "end_line": 562, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 92, "parameters": [ "actual", "desired", "err_msg", "verbose" ], "start_line": 572, "end_line": 586, "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": "testing.py", "nloc": 12, "complexity": 5, "token_count": 106, "parameters": [ "actual", "desired", "decimal", "err_msg", "verbose" ], "start_line": 589, "end_line": 603, "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": "testing.py", "nloc": 22, "complexity": 7, "token_count": 195, "parameters": [ "actual", "desired", "significant", "err_msg", "verbose" ], "start_line": 606, "end_line": 633, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 28, "top_nesting_level": 0 }, { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 6, "token_count": 208, "parameters": [ "x", "y", "err_msg" ], "start_line": 637, "end_line": 656, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "assert_array_almost_equal", "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", "filename": "testing.py", "nloc": 23, "complexity": 5, "token_count": 226, "parameters": [ "x", "y", "decimal", "err_msg" ], "start_line": 659, "end_line": 681, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "assert_array_less", "long_name": "assert_array_less( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 20, "complexity": 5, "token_count": 189, "parameters": [ "x", "y", "err_msg" ], "start_line": 684, "end_line": 703, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 20, "top_nesting_level": 0 }, { "name": "rand", "long_name": "rand( * args )", "filename": "testing.py", "nloc": 7, "complexity": 2, "token_count": 45, "parameters": [ "args" ], "start_line": 706, "end_line": 715, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 10, "top_nesting_level": 0 }, { "name": "output_exception", "long_name": "output_exception( )", "filename": "testing.py", "nloc": 9, "complexity": 2, "token_count": 67, "parameters": [], "start_line": 717, "end_line": 727, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 11, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "assert_array_equal", "long_name": "assert_array_equal( x , y , err_msg = '' )", "filename": "testing.py", "nloc": 22, "complexity": 7, "token_count": 232, "parameters": [ "x", "y", "err_msg" ], "start_line": 637, "end_line": 658, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 } ], "nloc": 527, "complexity": 134, "token_count": 3922, "diff_parsed": { "added": [ " assert 0 in [len(shape(x)),len(shape(y))] \\", " or (len(shape(x))==len(shape(y)) and \\", " alltrue(equal(shape(x),shape(y)))),\\", " msg + ' (shapes %s, %s mismatch):\\n\\t' \\", " % (shape(x),shape(y)) + err_msg" ], "deleted": [ " assert len(shape(x))==len(shape(y)) and \\", " alltrue(equal(shape(x),shape(y))),\\", " msg + ' (shapes %s, %s mismatch):\\n\\t' % (shape(x),shape(y)) + err_msg" ] } } ] }, { "hash": "840e26184ef327ad193e6c8246fb1f118981971e", "msg": "Fixed bug when the fullpath to an executable contains spaces", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-24T19:33:38+00:00", "author_timezone": 0, "committer_date": "2004-03-24T19:33:38+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "db74b2b2b6f420627fb163ac87bfd06633148379" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 3, "insertions": 11, "lines": 14, "files": 1, "dmm_unit_size": 0.5, "dmm_unit_complexity": 0.5, "dmm_unit_interfacing": 0.5, "modified_files": [ { "old_path": "scipy_distutils/exec_command.py", "new_path": "scipy_distutils/exec_command.py", "filename": "exec_command.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -390,8 +390,12 @@ def _exec_command( command, use_shell=None, **env ):\n else:\n os.dup2(fout.fileno(),se_fileno)\n \n+ argv0 = argv[0]\n+ if ' ' in argv[0]:\n+ argv[0] = '\"%s\"' % (argv[0])\n+\n try:\n- status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)\n+ status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n@@ -431,7 +435,6 @@ def test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n-\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n \n@@ -457,7 +460,7 @@ def test_nt(**kws):\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n- else:\n+ elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n \n@@ -570,6 +573,10 @@ def test_execute_in(**kws):\n os.remove(tmpfile)\n print 'ok'\n \n+def test_svn():\n+ s,o = exec_command(['svn','status'])\n+ assert s,(s,o)\n+\n if os.name=='posix':\n test = test_posix\n elif os.name in ['nt','dos']:\n@@ -586,3 +593,4 @@ def test_execute_in(**kws):\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n+ test_svn()\n", "added_lines": 11, "deleted_lines": 3, "source_code": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = fn+s\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix' and sys.platform[:5]!='sunos':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c'] + command\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n argv0 = argv[0]\n if ' ' in argv[0]:\n argv[0] = '\"%s\"' % (argv[0])\n\n try:\n status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "source_code_before": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = fn+s\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix' and sys.platform[:5]!='sunos':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c'] + command\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n try:\n status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n else:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n", "methods": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 34, "complexity": 15, "token_count": 282, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 157, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 164, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 15, "token_count": 341, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 169, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 242, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 293, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 79, "complexity": 18, "token_count": 562, "parameters": [ "command", "use_shell", "env" ], "start_line": 333, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 434, "end_line": 508, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 510, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 558, "end_line": 574, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 576, "end_line": 578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 34, "complexity": 15, "token_count": 282, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 157, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 164, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 15, "token_count": 341, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 169, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 242, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 293, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 76, "complexity": 17, "token_count": 538, "parameters": [ "command", "use_shell", "env" ], "start_line": 333, "end_line": 427, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 95, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 21, "token_count": 506, "parameters": [ "kws" ], "start_line": 430, "end_line": 505, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 76, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 507, "end_line": 553, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 555, "end_line": 571, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 576, "end_line": 578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 79, "complexity": 18, "token_count": 562, "parameters": [ "command", "use_shell", "env" ], "start_line": 333, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 434, "end_line": 508, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 } ], "nloc": 418, "complexity": 131, "token_count": 3288, "diff_parsed": { "added": [ " argv0 = argv[0]", " if ' ' in argv[0]:", " argv[0] = '\"%s\"' % (argv[0])", "", " status = spawn_command(os.P_WAIT,argv0,argv,os.environ)", " elif 0:", "def test_svn():", " s,o = exec_command(['svn','status'])", " assert s,(s,o)", "", " test_svn()" ], "deleted": [ " status = spawn_command(os.P_WAIT,argv[0],argv,os.environ)", "", " else:" ] } } ] }, { "hash": "112824ccfdfab97d98f7939b2d31119d6acb4240", "msg": "Fixed compiler_switch", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-24T19:37:42+00:00", "author_timezone": 0, "committer_date": "2004-03-24T19:37:42+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "840e26184ef327ad193e6c8246fb1f118981971e" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/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/compaqfcompiler.py", "new_path": "scipy_distutils/compaqfcompiler.py", "filename": "compaqfcompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -50,7 +50,7 @@ class CompaqVisualFCompiler(FCompiler):\n version_pattern = r'(DIGITAL|Compaq) Visual Fortran Optimizing Compiler'\\\n ' Version (?P[^\\s]*).*'\n \n- compile_switch = '/compile_only '\n+ compile_switch = '/compile_only'\n object_switch = '/object:'\n library_switch = '/OUT:' #No space after /OUT:!\n \n", "added_lines": 1, "deleted_lines": 1, "source_code": "\n#http://www.compaq.com/fortran/docs/\n\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler\n\nclass CompaqFCompiler(FCompiler):\n\n compiler_type = 'compaq'\n version_pattern = r'Compaq Fortran (?P[^\\s]*).*'\n\n if sys.platform[:5]=='linux':\n fc_exe = 'fort'\n else:\n fc_exe = 'f90'\n\n executables = {\n 'version_cmd' : [fc_exe, \"-version\"],\n 'compiler_f77' : [fc_exe, \"-f77rtl\",\"-fixed\"],\n 'compiler_fix' : [fc_exe, \"-fixed\"],\n 'compiler_f90' : [fc_exe],\n 'linker_so' : [fc_exe],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\n module_dir_switch = None #XXX Fix me\n module_include_switch = None #XXX Fix me\n\n def get_flags(self):\n return ['-assume no2underscore','-nomixed_str_len_arg']\n def get_flags_debug(self):\n return ['-g','-check bounds']\n def get_flags_opt(self):\n return ['-O4','-align dcommons','-assume bigarrays',\n '-assume nozsize','-math_library fast']\n def get_flags_arch(self):\n return ['-arch host', '-tune host']\n def get_flags_linker_so(self):\n if sys.platform[:5]=='linux':\n return ['-shared']\n return ['-shared','-Wl,-expect_unresolved,*']\n\nclass CompaqVisualFCompiler(FCompiler):\n\n compiler_type = 'compaqv'\n version_pattern = r'(DIGITAL|Compaq) Visual Fortran Optimizing Compiler'\\\n ' Version (?P[^\\s]*).*'\n\n compile_switch = '/compile_only'\n object_switch = '/object:'\n library_switch = '/OUT:' #No space after /OUT:!\n\n static_lib_extension = \".lib\"\n static_lib_format = \"%s%s\"\n module_dir_switch = None #XXX Fix me\n module_include_switch = None #XXX Fix me\n\n ar_exe = 'lib.exe'\n fc_exe = 'DF'\n if sys.platform=='win32':\n from distutils.msvccompiler import MSVCCompiler\n ar_exe = MSVCCompiler().lib\n\n executables = {\n 'version_cmd' : ['DF', \"/what\"],\n 'compiler_f77' : ['DF', \"/f77rtl\",\"/fixed\"],\n 'compiler_fix' : ['DF', \"/fixed\"],\n 'compiler_f90' : ['DF'],\n 'linker_so' : ['DF'],\n 'archiver' : [ar_exe, \"/OUT:\"],\n 'ranlib' : None\n }\n\n def get_flags(self):\n return ['/nologo','/MD','/WX','/iface=(cref,nomixed_str_len_arg)',\n '/names:lowercase','/assume:underscore']\n def get_flags_opt(self):\n return ['/Ox','/fast','/optimize:5','/unroll:0','/math_library:fast']\n def get_flags_arch(self):\n return ['/threads']\n def get_flags_debug(self):\n return ['/debug']\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='compaq')\n compiler.customize()\n print compiler.get_version()\n", "source_code_before": "\n#http://www.compaq.com/fortran/docs/\n\nimport os\nimport sys\n\nfrom cpuinfo import cpu\nfrom fcompiler import FCompiler\n\nclass CompaqFCompiler(FCompiler):\n\n compiler_type = 'compaq'\n version_pattern = r'Compaq Fortran (?P[^\\s]*).*'\n\n if sys.platform[:5]=='linux':\n fc_exe = 'fort'\n else:\n fc_exe = 'f90'\n\n executables = {\n 'version_cmd' : [fc_exe, \"-version\"],\n 'compiler_f77' : [fc_exe, \"-f77rtl\",\"-fixed\"],\n 'compiler_fix' : [fc_exe, \"-fixed\"],\n 'compiler_f90' : [fc_exe],\n 'linker_so' : [fc_exe],\n 'archiver' : [\"ar\", \"-cr\"],\n 'ranlib' : [\"ranlib\"]\n }\n\n module_dir_switch = None #XXX Fix me\n module_include_switch = None #XXX Fix me\n\n def get_flags(self):\n return ['-assume no2underscore','-nomixed_str_len_arg']\n def get_flags_debug(self):\n return ['-g','-check bounds']\n def get_flags_opt(self):\n return ['-O4','-align dcommons','-assume bigarrays',\n '-assume nozsize','-math_library fast']\n def get_flags_arch(self):\n return ['-arch host', '-tune host']\n def get_flags_linker_so(self):\n if sys.platform[:5]=='linux':\n return ['-shared']\n return ['-shared','-Wl,-expect_unresolved,*']\n\nclass CompaqVisualFCompiler(FCompiler):\n\n compiler_type = 'compaqv'\n version_pattern = r'(DIGITAL|Compaq) Visual Fortran Optimizing Compiler'\\\n ' Version (?P[^\\s]*).*'\n\n compile_switch = '/compile_only '\n object_switch = '/object:'\n library_switch = '/OUT:' #No space after /OUT:!\n\n static_lib_extension = \".lib\"\n static_lib_format = \"%s%s\"\n module_dir_switch = None #XXX Fix me\n module_include_switch = None #XXX Fix me\n\n ar_exe = 'lib.exe'\n fc_exe = 'DF'\n if sys.platform=='win32':\n from distutils.msvccompiler import MSVCCompiler\n ar_exe = MSVCCompiler().lib\n\n executables = {\n 'version_cmd' : ['DF', \"/what\"],\n 'compiler_f77' : ['DF', \"/f77rtl\",\"/fixed\"],\n 'compiler_fix' : ['DF', \"/fixed\"],\n 'compiler_f90' : ['DF'],\n 'linker_so' : ['DF'],\n 'archiver' : [ar_exe, \"/OUT:\"],\n 'ranlib' : None\n }\n\n def get_flags(self):\n return ['/nologo','/MD','/WX','/iface=(cref,nomixed_str_len_arg)',\n '/names:lowercase','/assume:underscore']\n def get_flags_opt(self):\n return ['/Ox','/fast','/optimize:5','/unroll:0','/math_library:fast']\n def get_flags_arch(self):\n return ['/threads']\n def get_flags_debug(self):\n return ['/debug']\n\nif __name__ == '__main__':\n from distutils import log\n log.set_verbosity(2)\n from fcompiler import new_fcompiler\n compiler = new_fcompiler(compiler='compaq')\n compiler.customize()\n print compiler.get_version()\n", "methods": [ { "name": "get_flags", "long_name": "get_flags( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 33, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 35, "end_line": 36, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "compaqfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 37, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 40, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "compaqfcompiler.py", "nloc": 4, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 42, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "compaqfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 78, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 81, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 83, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 85, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "methods_before": [ { "name": "get_flags", "long_name": "get_flags( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 33, "end_line": 34, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 35, "end_line": 36, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "compaqfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 37, "end_line": 39, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 11, "parameters": [ "self" ], "start_line": 40, "end_line": 41, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_linker_so", "long_name": "get_flags_linker_so( self )", "filename": "compaqfcompiler.py", "nloc": 4, "complexity": 2, "token_count": 26, "parameters": [ "self" ], "start_line": 42, "end_line": 45, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 1 }, { "name": "get_flags", "long_name": "get_flags( self )", "filename": "compaqfcompiler.py", "nloc": 3, "complexity": 1, "token_count": 19, "parameters": [ "self" ], "start_line": 78, "end_line": 80, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 1 }, { "name": "get_flags_opt", "long_name": "get_flags_opt( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 17, "parameters": [ "self" ], "start_line": 81, "end_line": 82, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_arch", "long_name": "get_flags_arch( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 83, "end_line": 84, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 }, { "name": "get_flags_debug", "long_name": "get_flags_debug( self )", "filename": "compaqfcompiler.py", "nloc": 2, "complexity": 1, "token_count": 9, "parameters": [ "self" ], "start_line": 85, "end_line": 86, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 2, "top_nesting_level": 1 } ], "changed_methods": [], "nloc": 76, "complexity": 10, "token_count": 397, "diff_parsed": { "added": [ " compile_switch = '/compile_only'" ], "deleted": [ " compile_switch = '/compile_only '" ] } } ] }, { "hash": "7bf0e17070f0a95f1e8f5d86716a5a62cd6bc31c", "msg": "Fixed duplicate quotation of a command path.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-25T15:36:21+00:00", "author_timezone": 0, "committer_date": "2004-03-25T15:36:21+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "112824ccfdfab97d98f7939b2d31119d6acb4240" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 3, "insertions": 5, "lines": 8, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/exec_command.py", "new_path": "scipy_distutils/exec_command.py", "filename": "exec_command.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -329,6 +329,10 @@ def _exec_command_python(command,\n \n return status, text\n \n+def quote_arg(arg):\n+ if arg[0]!='\"' and ' ' in arg:\n+ return '\"%s\"' % arg\n+ return arg\n \n def _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n@@ -390,9 +394,7 @@ def _exec_command( command, use_shell=None, **env ):\n else:\n os.dup2(fout.fileno(),se_fileno)\n \n- argv0 = argv[0]\n- if ' ' in argv[0]:\n- argv[0] = '\"%s\"' % (argv[0])\n+ argv0 = quote_arg(argv[0])\n \n try:\n status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n", "added_lines": 5, "deleted_lines": 3, "source_code": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = fn+s\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix' and sys.platform[:5]!='sunos':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c'] + command\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n argv0 = quote_arg(argv[0])\n\n try:\n status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "source_code_before": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = fn+s\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix' and sys.platform[:5]!='sunos':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c'] + command\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n argv0 = argv[0]\n if ' ' in argv[0]:\n argv[0] = '\"%s\"' % (argv[0])\n\n try:\n status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "methods": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 34, "complexity": 15, "token_count": 282, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 157, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 164, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 15, "token_count": 341, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 169, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 242, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 293, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 332, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 77, "complexity": 17, "token_count": 544, "parameters": [ "command", "use_shell", "env" ], "start_line": 337, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 436, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 512, "end_line": 558, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 560, "end_line": 576, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 578, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 34, "complexity": 15, "token_count": 282, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 157, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 164, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 15, "token_count": 341, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 169, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 242, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 293, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 79, "complexity": 18, "token_count": 562, "parameters": [ "command", "use_shell", "env" ], "start_line": 333, "end_line": 431, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 99, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 434, "end_line": 508, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 510, "end_line": 556, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 558, "end_line": 574, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 576, "end_line": 578, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 77, "complexity": 17, "token_count": 544, "parameters": [ "command", "use_shell", "env" ], "start_line": 337, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 332, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 } ], "nloc": 420, "complexity": 133, "token_count": 3294, "diff_parsed": { "added": [ "def quote_arg(arg):", " if arg[0]!='\"' and ' ' in arg:", " return '\"%s\"' % arg", " return arg", " argv0 = quote_arg(argv[0])" ], "deleted": [ " argv0 = argv[0]", " if ' ' in argv[0]:", " argv[0] = '\"%s\"' % (argv[0])" ] } } ] }, { "hash": "7712b8989f4e765d0898ca81f36105058a1c5c20", "msg": "Fixed displaying log messages that contain % characters", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-26T16:18:51+00:00", "author_timezone": 0, "committer_date": "2004-03-26T16:18:51+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "7bf0e17070f0a95f1e8f5d86716a5a62cd6bc31c" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 2, "insertions": 9, "lines": 11, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/log.py", "new_path": "scipy_distutils/log.py", "filename": "log.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -2,6 +2,13 @@\n \n import sys\n \n+def _fix_args(args,flag=1):\n+ if type(args) is type(''):\n+ return args.replace('%','%%')\n+ if flag and type(args) is type(()):\n+ return tuple([_fix_args(a,flag=0) for a in args])\n+ return args\n+\n if sys.version[:3]>='2.3':\n from distutils.log import *\n from distutils.log import Log as old_Log\n@@ -10,7 +17,7 @@ class Log(old_Log):\n def _log(self, level, msg, args):\n if level>= self.threshold:\n if args:\n- print _global_color_map[level](msg % args)\n+ print _global_color_map[level](msg % _fix_args(args))\n else:\n print _global_color_map[level](msg)\n sys.stdout.flush()\n@@ -32,7 +39,7 @@ def __init__(self, threshold=WARN):\n \n def _log(self, level, msg, args):\n if level >= self.threshold:\n- print _global_color_map[level](msg % args)\n+ print _global_color_map[level](msg % _fix_args(args))\n sys.stdout.flush()\n \n def log(self, level, msg, *args):\n", "added_lines": 9, "deleted_lines": 2, "source_code": "# Python 2.3 distutils.log backported to Python 2.1.x, 2.2.x\n\nimport sys\n\ndef _fix_args(args,flag=1):\n if type(args) is type(''):\n return args.replace('%','%%')\n if flag and type(args) is type(()):\n return tuple([_fix_args(a,flag=0) for a in args])\n return args\n\nif sys.version[:3]>='2.3':\n from distutils.log import *\n from distutils.log import Log as old_Log\n from distutils.log import _global_log\n class Log(old_Log):\n def _log(self, level, msg, args):\n if level>= self.threshold:\n if args:\n print _global_color_map[level](msg % _fix_args(args))\n else:\n print _global_color_map[level](msg)\n sys.stdout.flush()\n _global_log.__class__ = Log\n\nelse:\n exec \"\"\"\n# Here follows (slightly) modified copy of Python 2.3 distutils/log.py\n\nDEBUG = 1\nINFO = 2\nWARN = 3\nERROR = 4\nFATAL = 5\nclass Log:\n\n def __init__(self, threshold=WARN):\n self.threshold = threshold\n\n def _log(self, level, msg, args):\n if level >= self.threshold:\n print _global_color_map[level](msg % _fix_args(args))\n sys.stdout.flush()\n\n def log(self, level, msg, *args):\n self._log(level, msg, args)\n\n def debug(self, msg, *args):\n self._log(DEBUG, msg, args)\n\n def info(self, msg, *args):\n self._log(INFO, msg, args)\n \n def warn(self, msg, *args):\n self._log(WARN, red_text(msg), args)\n \n def error(self, msg, *args):\n self._log(ERROR, msg, args)\n \n def fatal(self, msg, *args):\n self._log(FATAL, msg, args)\n\n_global_log = Log()\nlog = _global_log.log\ndebug = _global_log.debug\ninfo = _global_log.info\nwarn = _global_log.warn\nerror = _global_log.error\nfatal = _global_log.fatal\n\ndef set_threshold(level):\n _global_log.threshold = level\n\ndef set_verbosity(v):\n if v <= 0:\n set_threshold(WARN)\n elif v == 1:\n set_threshold(INFO)\n elif v >= 2:\n set_threshold(DEBUG)\n\"\"\"\n\nfrom misc_util import red_text, yellow_text, cyan_text\n_global_color_map = {\n DEBUG:cyan_text,\n INFO:yellow_text,\n WARN:red_text,\n ERROR:red_text,\n FATAL:red_text\n}\n\nset_verbosity(1)\n", "source_code_before": "# Python 2.3 distutils.log backported to Python 2.1.x, 2.2.x\n\nimport sys\n\nif sys.version[:3]>='2.3':\n from distutils.log import *\n from distutils.log import Log as old_Log\n from distutils.log import _global_log\n class Log(old_Log):\n def _log(self, level, msg, args):\n if level>= self.threshold:\n if args:\n print _global_color_map[level](msg % args)\n else:\n print _global_color_map[level](msg)\n sys.stdout.flush()\n _global_log.__class__ = Log\n\nelse:\n exec \"\"\"\n# Here follows (slightly) modified copy of Python 2.3 distutils/log.py\n\nDEBUG = 1\nINFO = 2\nWARN = 3\nERROR = 4\nFATAL = 5\nclass Log:\n\n def __init__(self, threshold=WARN):\n self.threshold = threshold\n\n def _log(self, level, msg, args):\n if level >= self.threshold:\n print _global_color_map[level](msg % args)\n sys.stdout.flush()\n\n def log(self, level, msg, *args):\n self._log(level, msg, args)\n\n def debug(self, msg, *args):\n self._log(DEBUG, msg, args)\n\n def info(self, msg, *args):\n self._log(INFO, msg, args)\n \n def warn(self, msg, *args):\n self._log(WARN, red_text(msg), args)\n \n def error(self, msg, *args):\n self._log(ERROR, msg, args)\n \n def fatal(self, msg, *args):\n self._log(FATAL, msg, args)\n\n_global_log = Log()\nlog = _global_log.log\ndebug = _global_log.debug\ninfo = _global_log.info\nwarn = _global_log.warn\nerror = _global_log.error\nfatal = _global_log.fatal\n\ndef set_threshold(level):\n _global_log.threshold = level\n\ndef set_verbosity(v):\n if v <= 0:\n set_threshold(WARN)\n elif v == 1:\n set_threshold(INFO)\n elif v >= 2:\n set_threshold(DEBUG)\n\"\"\"\n\nfrom misc_util import red_text, yellow_text, cyan_text\n_global_color_map = {\n DEBUG:cyan_text,\n INFO:yellow_text,\n WARN:red_text,\n ERROR:red_text,\n FATAL:red_text\n}\n\nset_verbosity(1)\n", "methods": [ { "name": "_fix_args", "long_name": "_fix_args( args , flag = 1 )", "filename": "log.py", "nloc": 6, "complexity": 5, "token_count": 63, "parameters": [ "args", "flag" ], "start_line": 5, "end_line": 10, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_log", "long_name": "_log( self , level , msg , args )", "filename": "log.py", "nloc": 7, "complexity": 3, "token_count": 51, "parameters": [ "self", "level", "msg", "args" ], "start_line": 17, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 2 } ], "methods_before": [ { "name": "_log", "long_name": "_log( self , level , msg , args )", "filename": "log.py", "nloc": 7, "complexity": 3, "token_count": 48, "parameters": [ "self", "level", "msg", "args" ], "start_line": 10, "end_line": 16, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 2 } ], "changed_methods": [ { "name": "_fix_args", "long_name": "_fix_args( args , flag = 1 )", "filename": "log.py", "nloc": 6, "complexity": 5, "token_count": 63, "parameters": [ "args", "flag" ], "start_line": 5, "end_line": 10, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_log", "long_name": "_log( self , level , msg , args )", "filename": "log.py", "nloc": 7, "complexity": 3, "token_count": 51, "parameters": [ "self", "level", "msg", "args" ], "start_line": 17, "end_line": 23, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 7, "top_nesting_level": 2 } ], "nloc": 85, "complexity": 8, "token_count": 199, "diff_parsed": { "added": [ "def _fix_args(args,flag=1):", " if type(args) is type(''):", " return args.replace('%','%%')", " if flag and type(args) is type(()):", " return tuple([_fix_args(a,flag=0) for a in args])", " return args", "", " print _global_color_map[level](msg % _fix_args(args))", " print _global_color_map[level](msg % _fix_args(args))" ], "deleted": [ " print _global_color_map[level](msg % args)", " print _global_color_map[level](msg % args)" ] } } ] }, { "hash": "88424c57b68646e5c2e3f202c130e9d6b7c9f4f4", "msg": "Fixed _exec_command when use_shell is true", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-26T16:58:00+00:00", "author_timezone": 0, "committer_date": "2004-03-26T16:58:00+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "7712b8989f4e765d0898ca81f36105058a1c5c20" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/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/exec_command.py", "new_path": "scipy_distutils/exec_command.py", "filename": "exec_command.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -346,7 +346,7 @@ def _exec_command( command, use_shell=None, **env ):\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n- argv = [sh,'-c'] + command\n+ argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n", "added_lines": 1, "deleted_lines": 1, "source_code": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = fn+s\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix' and sys.platform[:5]!='sunos':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n argv0 = quote_arg(argv[0])\n\n try:\n status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "source_code_before": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = fn+s\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix' and sys.platform[:5]!='sunos':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c'] + command\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n argv0 = quote_arg(argv[0])\n\n try:\n status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "methods": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 34, "complexity": 15, "token_count": 282, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 157, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 164, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 15, "token_count": 341, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 169, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 242, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 293, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 332, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 77, "complexity": 17, "token_count": 549, "parameters": [ "command", "use_shell", "env" ], "start_line": 337, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 436, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 512, "end_line": 558, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 560, "end_line": 576, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 578, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 34, "complexity": 15, "token_count": 282, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 157, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 164, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 15, "token_count": 341, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 169, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 242, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 293, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 332, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 77, "complexity": 17, "token_count": 544, "parameters": [ "command", "use_shell", "env" ], "start_line": 337, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 436, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 512, "end_line": 558, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 560, "end_line": 576, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 578, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 77, "complexity": 17, "token_count": 549, "parameters": [ "command", "use_shell", "env" ], "start_line": 337, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 } ], "nloc": 420, "complexity": 133, "token_count": 3299, "diff_parsed": { "added": [ " argv = [sh,'-c',' '.join(command)]" ], "deleted": [ " argv = [sh,'-c'] + command" ] } } ] }, { "hash": "0d3f9d2ec9b74efde4025961fa79a62c2515ef18", "msg": "Disabled use_shell for sun os", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-26T17:05:47+00:00", "author_timezone": 0, "committer_date": "2004-03-26T17:05:47+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "88424c57b68646e5c2e3f202c130e9d6b7c9f4f4" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/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/exec_command.py", "new_path": "scipy_distutils/exec_command.py", "filename": "exec_command.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -188,7 +188,7 @@ def exec_command( command,\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n- use_shell = os.name=='posix'\n+ use_shell = os.name=='posix' and sys.platform[:5]!='sunos'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n \n", "added_lines": 1, "deleted_lines": 1, "source_code": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = fn+s\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix' and sys.platform[:5]!='sunos'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix' and sys.platform[:5]!='sunos':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n argv0 = quote_arg(argv[0])\n\n try:\n status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "source_code_before": "#!/usr/bin/env python\n#\n# exec_command\n#\n# Implements exec_command function that is (almost) equivalent to\n# commands.getstatusoutput function but on NT, DOS systems the\n# returned status is actually correct (though, the returned status\n# values may be different by a factor). In addition, exec_command\n# takes keyword arguments for (re-)defining environment variables.\n#\n# Provides functions:\n# exec_command --- execute command in a specified directory and\n# in the modified environment.\n# splitcmdline --- inverse of ' '.join(argv)\n# find_executable --- locate a command using info from environment\n# variable PATH. Equivalent to posix `which`\n# command.\n#\n# Author: Pearu Peterson \n# Created: 11 January 2003\n#\n# Requires: Python 2.x\n#\n# Succesfully tested on:\n# os.name | sys.platform | comments\n# --------+--------------+----------\n# posix | linux2 | Debian (sid) Linux, Python 2.1.3+, 2.2.3+, 2.3.3\n# PyCrust 0.9.3, Idle 1.0.2\n# posix | linux2 | Red Hat 9 Linux, Python 2.1.3, 2.2.2, 2.3.2\n# posix | sunos5 | SunOS 5.9, Python 2.2, 2.3.2\n# posix | darwin | Darwin 7.2.0, Python 2.3\n# nt | win32 | Windows Me\n# Python 2.3(EE), Idle 1.0, PyCrust 0.7.2\n# Python 2.1.1 Idle 0.8\n# nt | win32 | Windows 98, Python 2.1.1. Idle 0.8\n# nt | win32 | Cygwin 98-4.10, Python 2.1.1(MSC) - echo tests\n# fail i.e. redefining environment variables may\n# not work. FIXED: don't use cygwin echo!\n# Comment: also `cmd /c echo` will not work\n# but redefining environment variables do work.\n# posix | cygwin | Cygwin 98-4.10, Python 2.3.3(cygming special)\n\n__all__ = ['exec_command','find_executable']\n\nimport os\nimport re\nimport sys\nimport tempfile\n\n############################################################\n\nfrom log import _global_log as log\n\n############################################################\n\ndef get_pythonexe():\n pythonexe = sys.executable\n if os.name in ['nt','dos']:\n fdir,fn = os.path.split(pythonexe)\n fn = fn.upper().replace('PYTHONW','PYTHON')\n pythonexe = os.path.join(fdir,fn)\n assert os.path.isfile(pythonexe),`pythonexe`+' is not a file'\n return pythonexe\n\n############################################################\n\ndef splitcmdline(line):\n \"\"\" Inverse of ' '.join(sys.argv).\n \"\"\"\n log.info('splitcmdline(%r)' % (line))\n lst = []\n flag = 0\n s,pc,cc = '','',''\n for nc in line+' ':\n if flag==0:\n flag = (pc != '\\\\' and \\\n ((cc=='\"' and 1) or (cc==\"'\" and 2) or \\\n (cc==' ' and pc!=' ' and -2))) or flag\n elif flag==1:\n flag = (cc=='\"' and pc!='\\\\' and nc==' ' and -1) or flag\n elif flag==2:\n flag = (cc==\"'\" and pc!='\\\\' and nc==' ' and -1) or flag\n if flag!=-2:\n s += cc\n if flag<0:\n flag = 0\n s = s.strip()\n if s:\n lst.append(s)\n s = ''\n pc,cc = cc,nc\n else:\n s = s.strip()\n if s:\n lst.append(s)\n log.debug('splitcmdline -> %r' % (lst))\n return lst\n\ndef test_splitcmdline():\n l = splitcmdline('a b cc')\n assert l==['a','b','cc'],`l`\n l = splitcmdline('a')\n assert l==['a'],`l`\n l = splitcmdline('a \" b cc\"')\n assert l==['a','\" b cc\"'],`l`\n l = splitcmdline('\"a bcc\" -h')\n assert l==['\"a bcc\"','-h'],`l`\n l = splitcmdline(r'\"\\\"a \\\" bcc\" -h')\n assert l==[r'\"\\\"a \\\" bcc\"','-h'],`l`\n l = splitcmdline(\" 'a bcc' -h\")\n assert l==[\"'a bcc'\",'-h'],`l`\n l = splitcmdline(r\"'\\'a \\' bcc' -h\")\n assert l==[r\"'\\'a \\' bcc'\",'-h'],`l`\n\n############################################################\n\ndef find_executable(exe, path=None):\n \"\"\" Return full path of a executable.\n \"\"\"\n log.debug('find_executable(%r)' % exe)\n if path is None:\n path = os.environ.get('PATH',os.defpath)\n\n suffices = ['']\n if os.name in ['nt','dos','os2']:\n fn,ext = os.path.splitext(exe)\n extra_suffices = ['.exe','.com','.bat']\n if ext.lower() not in extra_suffices:\n suffices = extra_suffices\n if os.path.isabs(exe):\n paths = ['']\n else:\n paths = map(os.path.abspath, path.split(os.pathsep))\n if 0 and os.name == 'nt':\n new_paths = []\n cygwin_paths = []\n for path in paths:\n d,p = os.path.splitdrive(path)\n if p.lower().find('cygwin') >= 0:\n cygwin_paths.append(path)\n else:\n new_paths.append(path)\n paths = new_paths + cygwin_paths\n for path in paths:\n fn = os.path.join(path,exe)\n for s in suffices:\n f_ext = fn+s\n if os.path.isfile(f_ext) and os.access(f_ext,os.X_OK):\n log.debug('Found executable %s' % f_ext)\n return f_ext\n if not os.path.isfile(exe) or os.access(exe,os.X_OK):\n log.warn('Could not locate executable %s' % exe)\n return exe\n\n############################################################\n\ndef _preserve_environment( names ):\n log.debug('_preserve_environment(%r)' % (names))\n env = {}\n for name in names:\n env[name] = os.environ.get(name)\n return env\n\ndef _update_environment( **env ):\n log.debug('_update_environment(...)')\n for name,value in env.items():\n os.environ[name] = value or ''\n\ndef exec_command( command,\n execute_in='', use_shell=None, use_tee = None,\n _with_python = 1,\n **env ):\n \"\"\" Return (status,output) of executed command.\n\n command is a concatenated string of executable and arguments.\n The output contains both stdout and stderr messages.\n The following special keyword arguments can be used:\n use_shell - execute `sh -c command`\n use_tee - pipe the output of command through tee\n execute_in - before command `cd execute_in` and after `cd -`.\n\n On NT, DOS systems the returned status is correct for external commands.\n Wild cards will not work for non-posix systems or when use_shell=0.\n \"\"\"\n log.debug('exec_command(%r,%s)' % (command,\\\n ','.join(['%s=%r'%kv for kv in env.items()])))\n\n if use_tee is None:\n use_tee = os.name=='posix'\n if use_shell is None:\n use_shell = os.name=='posix'\n execute_in = os.path.abspath(execute_in)\n oldcwd = os.path.abspath(os.getcwd())\n\n if __name__[-12:] == 'exec_command':\n exec_dir = os.path.dirname(os.path.abspath(__file__))\n elif os.path.isfile('exec_command.py'):\n exec_dir = os.path.abspath('.')\n else:\n exec_dir = os.path.abspath(sys.argv[0])\n if os.path.isfile(exec_dir):\n exec_dir = os.path.dirname(exec_dir)\n\n if oldcwd!=execute_in:\n os.chdir(execute_in)\n log.debug('New cwd: %s' % execute_in)\n else:\n log.debug('Retaining cwd: %s' % oldcwd)\n\n oldenv = _preserve_environment( env.keys() )\n _update_environment( **env )\n\n try:\n # _exec_command is robust but slow, it relies on\n # usable sys.std*.fileno() descriptors. If they\n # are bad (like in win32 Idle, PyCrust environments)\n # then _exec_command_python (even slower)\n # will be used as a last resort.\n #\n # _exec_command_posix uses os.system and is faster\n # but not on all platforms os.system will return\n # a correct status.\n if _with_python and (0 or sys.__stdout__.fileno()==-1):\n st = _exec_command_python(command,\n exec_command_dir = exec_dir,\n **env)\n elif os.name=='posix' and sys.platform[:5]!='sunos':\n st = _exec_command_posix(command,\n use_shell=use_shell,\n use_tee=use_tee,\n **env)\n else:\n st = _exec_command(command, use_shell=use_shell, **env)\n finally:\n if oldcwd!=execute_in:\n os.chdir(oldcwd)\n log.debug('Restored cwd to %s' % oldcwd)\n _update_environment(**oldenv)\n\n return st\n\ndef _exec_command_posix( command,\n use_shell = None,\n use_tee = None,\n **env ):\n log.debug('_exec_command_posix(...)')\n\n if type(command) is type([]):\n command_str = ' '.join(command)\n else:\n command_str = command\n\n tmpfile = tempfile.mktemp()\n stsfile = None\n if use_tee:\n stsfile = tempfile.mktemp()\n filter = ''\n if use_tee == 2:\n filter = r'| tr -cd \"\\n\" | tr \"\\n\" \".\"; echo'\n command_posix = '( %s ; echo $? > %s ) 2>&1 | tee %s %s'\\\n % (command_str,stsfile,tmpfile,filter)\n else:\n stsfile = tempfile.mktemp()\n command_posix = '( %s ; echo $? > %s ) > %s 2>&1'\\\n % (command_str,stsfile,tmpfile)\n #command_posix = '( %s ) > %s 2>&1' % (command_str,tmpfile)\n\n log.debug('Running os.system(%r)' % (command_posix))\n status = os.system(command_posix)\n\n if use_tee:\n if status:\n # if command_tee fails then fall back to robust exec_command\n log.warn('_exec_command_posix failed (status=%s)' % status)\n return _exec_command(command, use_shell=use_shell, **env)\n if stsfile is not None:\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n\n f = open(tmpfile,'r')\n text = f.read()\n f.close()\n os.remove(tmpfile)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n \n return status, text\n\n\ndef _exec_command_python(command,\n exec_command_dir='', **env):\n log.debug('_exec_command_python(...)')\n\n python_exe = get_pythonexe()\n cmdfile = tempfile.mktemp()\n stsfile = tempfile.mktemp()\n outfile = tempfile.mktemp()\n\n f = open(cmdfile,'w')\n f.write('import os\\n')\n f.write('import sys\\n')\n f.write('sys.path.insert(0,%r)\\n' % (exec_command_dir))\n f.write('from exec_command import exec_command\\n')\n f.write('del sys.path[0]\\n')\n f.write('cmd = %r\\n' % command)\n f.write('os.environ = %r\\n' % (os.environ))\n f.write('s,o = exec_command(cmd, _with_python=0, **%r)\\n' % (env))\n f.write('f=open(%r,\"w\")\\nf.write(str(s))\\nf.close()\\n' % (stsfile))\n f.write('f=open(%r,\"w\")\\nf.write(o)\\nf.close()\\n' % (outfile))\n f.close()\n\n cmd = '%s %s' % (python_exe, cmdfile)\n status = os.system(cmd)\n assert not status,`cmd`+' failed'\n os.remove(cmdfile)\n\n f = open(stsfile,'r')\n status = int(f.read())\n f.close()\n os.remove(stsfile)\n \n f = open(outfile,'r')\n text = f.read()\n f.close()\n os.remove(outfile)\n \n return status, text\n\ndef quote_arg(arg):\n if arg[0]!='\"' and ' ' in arg:\n return '\"%s\"' % arg\n return arg\n\ndef _exec_command( command, use_shell=None, **env ):\n log.debug('_exec_command(...)')\n \n if use_shell is None:\n use_shell = os.name=='posix'\n\n using_command = 0\n if use_shell:\n # We use shell (unless use_shell==0) so that wildcards can be\n # used.\n sh = os.environ.get('SHELL','/bin/sh')\n if type(command) is type([]):\n argv = [sh,'-c',' '.join(command)]\n else:\n argv = [sh,'-c',command]\n else:\n # On NT, DOS we avoid using command.com as it's exit status is\n # not related to the exit status of a command.\n if type(command) is type([]):\n argv = command[:]\n else:\n argv = splitcmdline(command)\n \n if hasattr(os,'spawnvpe'):\n spawn_command = os.spawnvpe\n else:\n spawn_command = os.spawnve\n argv[0] = find_executable(argv[0])\n if not os.path.isfile(argv[0]):\n log.warn('Executable %s does not exist' % (argv[0]))\n if os.name in ['nt','dos']:\n # argv[0] might be internal command\n argv = [os.environ['COMSPEC'],'/C']+argv\n using_command = 1\n # sys.__std*__ is used instead of sys.std* because environments\n # like IDLE, PyCrust, etc overwrite sys.std* commands.\n so_fileno = sys.__stdout__.fileno()\n se_fileno = sys.__stderr__.fileno()\n so_flush = sys.__stdout__.flush\n se_flush = sys.__stderr__.flush\n so_dup = os.dup(so_fileno)\n se_dup = os.dup(se_fileno)\n\n outfile = tempfile.mktemp()\n fout = open(outfile,'w')\n if using_command:\n errfile = tempfile.mktemp()\n ferr = open(errfile,'w')\n\n log.debug('Running %s(%s,%r,%r,os.environ)' \\\n % (spawn_command.__name__,os.P_WAIT,argv[0],argv))\n\n so_flush()\n se_flush()\n os.dup2(fout.fileno(),so_fileno)\n if using_command:\n os.dup2(ferr.fileno(),se_fileno)\n else:\n os.dup2(fout.fileno(),se_fileno)\n\n argv0 = quote_arg(argv[0])\n\n try:\n status = spawn_command(os.P_WAIT,argv0,argv,os.environ)\n except OSError,errmess:\n status = 999\n sys.stderr.write('%s: %s'%(errmess,argv[0]))\n\n so_flush()\n se_flush()\n os.dup2(so_dup,so_fileno)\n os.dup2(se_dup,se_fileno)\n\n fout.close()\n fout = open(outfile,'r')\n text = fout.read()\n fout.close()\n os.remove(outfile)\n\n if using_command:\n ferr.close()\n ferr = open(errfile,'r')\n errmess = ferr.read()\n ferr.close()\n os.remove(errfile)\n if errmess and not status:\n status = 998\n if text:\n text = text + '\\n'\n text = '%sCOMMAND %r FAILED: %s' %(text,command,errmess)\n\n if text[-1:]=='\\n':\n text = text[:-1]\n if status is None:\n status = 0\n\n return status, text\n\n\ndef test_nt(**kws):\n pythonexe = get_pythonexe()\n echo = find_executable('echo')\n using_cygwin_echo = echo != 'echo'\n if using_cygwin_echo:\n log.warn('Using cygwin echo in win32 environment is not supported')\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\',\\'\\')\"')\n assert s==0 and o=='',(s,o)\n \n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'AAA\\')\"',\n AAA='Tere')\n assert s==0 and o=='Tere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"',\n BBB='Hey')\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command(pythonexe\\\n +' -c \"import os;print os.environ.get(\\'BBB\\',\\'\\')\"')\n assert s==0 and o=='Hi',(s,o)\n elif 0:\n s,o=exec_command('echo Hello')\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo a%AAA%')\n assert s==0 and o=='a',(s,o)\n\n s,o=exec_command('echo a%AAA%',AAA='Tere')\n assert s==0 and o=='aTere',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('echo a%BBB%',BBB='Hey')\n assert s==0 and o=='aHey', (s,o)\n s,o=exec_command('echo a%BBB%')\n assert s==0 and o=='aHi',(s,o)\n\n s,o=exec_command('this_is_not_a_command')\n assert s and o!='',(s,o)\n\n s,o=exec_command('type not_existing_file')\n assert s and o!='',(s,o)\n\n s,o=exec_command('echo path=%path%')\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('%s -c \"import sys;sys.stderr.write(sys.platform)\"' \\\n % pythonexe)\n assert s==0 and o=='win32',(s,o)\n\n s,o=exec_command('%s -c \"raise \\'Ignore me.\\'\"' % pythonexe)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"'\\\n % pythonexe)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('%s -c \"import sys;sys.exit(15)\"' % pythonexe)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('%s -c \"print \\'Heipa\\'\"' % pythonexe)\n assert s==0 and o=='Heipa',(s,o)\n\n print 'ok'\n\ndef test_posix(**kws):\n s,o=exec_command(\"echo Hello\",**kws)\n assert s==0 and o=='Hello',(s,o)\n\n s,o=exec_command('echo $AAA',**kws)\n assert s==0 and o=='',(s,o)\n\n s,o=exec_command('echo \"$AAA\"',AAA='Tere',**kws)\n assert s==0 and o=='Tere',(s,o)\n\n\n s,o=exec_command('echo \"$AAA\"',**kws)\n assert s==0 and o=='',(s,o)\n\n os.environ['BBB'] = 'Hi'\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',BBB='Hey',**kws)\n assert s==0 and o=='Hey',(s,o)\n\n s,o=exec_command('echo \"$BBB\"',**kws)\n assert s==0 and o=='Hi',(s,o)\n\n\n s,o=exec_command('this_is_not_a_command',**kws)\n assert s!=0 and o!='',(s,o)\n\n s,o=exec_command('echo path=$PATH',**kws)\n assert s==0 and o!='',(s,o)\n \n s,o=exec_command('python -c \"import sys,os;sys.stderr.write(os.name)\"',**kws)\n assert s==0 and o=='posix',(s,o)\n\n s,o=exec_command('python -c \"raise \\'Ignore me.\\'\"',**kws)\n assert s==1 and o,(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.stderr.write(\\'0\\');sys.stderr.write(\\'1\\');sys.stderr.write(\\'2\\')\"',**kws)\n assert s==0 and o=='012',(s,o)\n\n s,o=exec_command('python -c \"import sys;sys.exit(15)\"',**kws)\n assert s==15 and o=='',(s,o)\n\n s,o=exec_command('python -c \"print \\'Heipa\\'\"',**kws)\n assert s==0 and o=='Heipa',(s,o)\n \n print 'ok'\n\ndef test_execute_in(**kws):\n pythonexe = get_pythonexe()\n tmpfile = tempfile.mktemp()\n fn = os.path.basename(tmpfile)\n tmpdir = os.path.dirname(tmpfile)\n f = open(tmpfile,'w')\n f.write('Hello')\n f.close()\n\n s,o = exec_command('%s -c \"print \\'Ignore the following IOError:\\','\\\n 'open(%r,\\'r\\')\"' % (pythonexe,fn),**kws)\n assert s and o!='',(s,o)\n s,o = exec_command('%s -c \"print open(%r,\\'r\\').read()\"' % (pythonexe,fn),\n execute_in = tmpdir,**kws)\n assert s==0 and o=='Hello',(s,o)\n os.remove(tmpfile)\n print 'ok'\n\ndef test_svn():\n s,o = exec_command(['svn','status'])\n assert s,(s,o)\n\nif os.name=='posix':\n test = test_posix\nelif os.name in ['nt','dos']:\n test = test_nt\nelse:\n raise NotImplementedError,'exec_command tests for '+os.name\n\n############################################################\n\nif __name__ == \"__main__\":\n\n test_splitcmdline()\n test(use_tee=0)\n test(use_tee=1)\n test_execute_in(use_tee=0)\n test_execute_in(use_tee=1)\n test_svn()\n", "methods": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 34, "complexity": 15, "token_count": 282, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 157, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 164, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 16, "token_count": 351, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 169, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 242, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 293, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 332, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 77, "complexity": 17, "token_count": 549, "parameters": [ "command", "use_shell", "env" ], "start_line": 337, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 436, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 512, "end_line": 558, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 560, "end_line": 576, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 578, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "methods_before": [ { "name": "get_pythonexe", "long_name": "get_pythonexe( )", "filename": "exec_command.py", "nloc": 8, "complexity": 2, "token_count": 75, "parameters": [], "start_line": 56, "end_line": 63, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 8, "top_nesting_level": 0 }, { "name": "splitcmdline", "long_name": "splitcmdline( line )", "filename": "exec_command.py", "nloc": 29, "complexity": 25, "token_count": 211, "parameters": [ "line" ], "start_line": 67, "end_line": 97, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 31, "top_nesting_level": 0 }, { "name": "test_splitcmdline", "long_name": "test_splitcmdline( )", "filename": "exec_command.py", "nloc": 15, "complexity": 1, "token_count": 134, "parameters": [], "start_line": 99, "end_line": 113, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "find_executable", "long_name": "find_executable( exe , path = None )", "filename": "exec_command.py", "nloc": 34, "complexity": 15, "token_count": 282, "parameters": [ "exe", "path" ], "start_line": 117, "end_line": 153, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 37, "top_nesting_level": 0 }, { "name": "_preserve_environment", "long_name": "_preserve_environment( names )", "filename": "exec_command.py", "nloc": 6, "complexity": 2, "token_count": 39, "parameters": [ "names" ], "start_line": 157, "end_line": 162, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 6, "top_nesting_level": 0 }, { "name": "_update_environment", "long_name": "_update_environment( ** env )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 33, "parameters": [ "env" ], "start_line": 164, "end_line": 167, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 15, "token_count": 341, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 169, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 }, { "name": "_exec_command_posix", "long_name": "_exec_command_posix( command , use_shell = None , use_tee = None , ** env )", "filename": "exec_command.py", "nloc": 40, "complexity": 8, "token_count": 241, "parameters": [ "command", "use_shell", "use_tee", "env" ], "start_line": 242, "end_line": 290, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 49, "top_nesting_level": 0 }, { "name": "_exec_command_python", "long_name": "_exec_command_python( command , exec_command_dir = '' , ** env )", "filename": "exec_command.py", "nloc": 32, "complexity": 1, "token_count": 232, "parameters": [ "command", "exec_command_dir", "env" ], "start_line": 293, "end_line": 330, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 38, "top_nesting_level": 0 }, { "name": "quote_arg", "long_name": "quote_arg( arg )", "filename": "exec_command.py", "nloc": 4, "complexity": 3, "token_count": 23, "parameters": [ "arg" ], "start_line": 332, "end_line": 335, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 4, "top_nesting_level": 0 }, { "name": "_exec_command", "long_name": "_exec_command( command , use_shell = None , ** env )", "filename": "exec_command.py", "nloc": 77, "complexity": 17, "token_count": 549, "parameters": [ "command", "use_shell", "env" ], "start_line": 337, "end_line": 433, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 97, "top_nesting_level": 0 }, { "name": "test_nt", "long_name": "test_nt( ** kws )", "filename": "exec_command.py", "nloc": 57, "complexity": 22, "token_count": 507, "parameters": [ "kws" ], "start_line": 436, "end_line": 510, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 75, "top_nesting_level": 0 }, { "name": "test_posix", "long_name": "test_posix( ** kws )", "filename": "exec_command.py", "nloc": 31, "complexity": 15, "token_count": 372, "parameters": [ "kws" ], "start_line": 512, "end_line": 558, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 47, "top_nesting_level": 0 }, { "name": "test_execute_in", "long_name": "test_execute_in( ** kws )", "filename": "exec_command.py", "nloc": 16, "complexity": 3, "token_count": 131, "parameters": [ "kws" ], "start_line": 560, "end_line": 576, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 17, "top_nesting_level": 0 }, { "name": "test_svn", "long_name": "test_svn( )", "filename": "exec_command.py", "nloc": 3, "complexity": 1, "token_count": 24, "parameters": [], "start_line": 578, "end_line": 580, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 3, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "exec_command", "long_name": "exec_command( command , execute_in = '' , use_shell = None , use_tee = None , _with_python = 1 , ** env )", "filename": "exec_command.py", "nloc": 45, "complexity": 16, "token_count": 351, "parameters": [ "command", "execute_in", "use_shell", "use_tee", "_with_python", "env" ], "start_line": 169, "end_line": 240, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 72, "top_nesting_level": 0 } ], "nloc": 420, "complexity": 134, "token_count": 3309, "diff_parsed": { "added": [ " use_shell = os.name=='posix' and sys.platform[:5]!='sunos'" ], "deleted": [ " use_shell = os.name=='posix'" ] } } ] }, { "hash": "540903640fe0f8bc6be30294f4a213f98676bfcf", "msg": "Be verbose when command returns failure status.", "author": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "committer": { "name": "Pearu Peterson", "email": "pearu.peterson@gmail.com" }, "author_date": "2004-03-26T18:11:27+00:00", "author_timezone": 0, "committer_date": "2004-03-26T18:11:27+00:00", "committer_timezone": 0, "branches": [ "main" ], "in_main_branch": true, "merge": false, "parents": [ "0d3f9d2ec9b74efde4025961fa79a62c2515ef18" ], "project_name": "repo_copy", "project_path": "/tmp/tmp_gcrvvwa/repo_copy", "deletions": 3, "insertions": 1, "lines": 4, "files": 1, "dmm_unit_size": 1.0, "dmm_unit_complexity": 1.0, "dmm_unit_interfacing": 1.0, "modified_files": [ { "old_path": "scipy_distutils/ccompiler.py", "new_path": "scipy_distutils/ccompiler.py", "filename": "ccompiler.py", "extension": "py", "change_type": "MODIFY", "diff": "@@ -23,12 +23,10 @@ def CCompiler_spawn(self, cmd, display=None):\n if type(cmd) is type([]) and os.name == 'nt':\n cmd = _nt_quote_args(cmd)\n s,o = exec_command(cmd)\n- if os.name != 'posix': \n- print \" \".join(cmd)\n- print o\n if s:\n if type(cmd) is type([]):\n cmd = ' '.join(cmd)\n+ print o\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\n CCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n", "added_lines": 1, "deleted_lines": 3, "source_code": "\nimport re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import compiler_to_string\nfrom distutils.spawn import _nt_quote_args \n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if type(display) is type([]): display = ' '.join(display)\n log.info(display)\n if type(cmd) is type([]) and os.name == 'nt':\n cmd = _nt_quote_args(cmd)\n s,o = exec_command(cmd)\n if s:\n if type(cmd) is type([]):\n cmd = ' '.join(cmd)\n print o\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n \n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n \n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n print '*'*80\n print self.__class__\n print compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n if not (hasattr(self,'version_cmd') and\n hasattr(self,'version_pattern')):\n log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n % (self.__class__))\n return\n\n cmd = ' '.join(self.version_cmd)\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n m = re.match(self.version_pattern,output)\n if m:\n version = m.group('version')\n assert version,`version`\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if os.environ.get('OSTYPE','')=='msys' or \\\n os.environ.get('MSYSTEM','')=='MINGW32':\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from scipy_distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n\n module_name = \"scipy_distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n", "source_code_before": "\nimport re\nimport os\nimport sys\nimport new\n\nfrom distutils.ccompiler import *\nfrom distutils import ccompiler\nfrom distutils.sysconfig import customize_compiler\nfrom distutils.version import LooseVersion\n\nimport log\nfrom exec_command import exec_command\nfrom misc_util import compiler_to_string\nfrom distutils.spawn import _nt_quote_args \n\n# Using customized CCompiler.spawn.\ndef CCompiler_spawn(self, cmd, display=None):\n if display is None:\n display = cmd\n if type(display) is type([]): display = ' '.join(display)\n log.info(display)\n if type(cmd) is type([]) and os.name == 'nt':\n cmd = _nt_quote_args(cmd)\n s,o = exec_command(cmd)\n if os.name != 'posix': \n print \" \".join(cmd)\n print o\n if s:\n if type(cmd) is type([]):\n cmd = ' '.join(cmd)\n raise DistutilsExecError,\\\n 'Command \"%s\" failed with exit status %d' % (cmd, s)\nCCompiler.spawn = new.instancemethod(CCompiler_spawn,None,CCompiler)\n\ndef CCompiler_object_filenames(self, source_filenames, strip_dir=0, output_dir=''):\n if output_dir is None:\n output_dir = ''\n obj_names = []\n for src_name in source_filenames:\n base, ext = os.path.splitext(os.path.normpath(src_name))\n base = os.path.splitdrive(base)[1] # Chop off the drive\n base = base[os.path.isabs(base):] # If abs, chop off leading /\n if base.startswith('..'):\n # Resolve starting relative path components, middle ones\n # (if any) have been handled by os.path.normpath above.\n i = base.rfind('..')+2\n d = base[:i]\n d = os.path.basename(os.path.abspath(d))\n base = d + base[i:]\n if ext not in self.src_extensions:\n raise UnknownFileError, \\\n \"unknown file type '%s' (from '%s')\" % (ext, src_name)\n if strip_dir:\n base = os.path.basename(base)\n obj_name = os.path.join(output_dir,base + self.obj_extension)\n obj_names.append(obj_name)\n return obj_names\n\nCCompiler.object_filenames = new.instancemethod(CCompiler_object_filenames,\n None,CCompiler)\n\ndef CCompiler_compile(self, sources, output_dir=None, macros=None,\n include_dirs=None, debug=0, extra_preargs=None,\n extra_postargs=None, depends=None):\n if not sources:\n return []\n from fcompiler import FCompiler\n if isinstance(self, FCompiler):\n display = []\n for fc in ['f77','f90','fix']:\n fcomp = getattr(self,'compiler_'+fc)\n if fcomp is None:\n continue\n display.append(\"%s(%s) options: '%s'\" % (os.path.basename(fcomp[0]),\n fc,\n ' '.join(fcomp[1:])))\n display = '\\n'.join(display)\n else:\n ccomp = self.compiler_so\n display = \"%s options: '%s'\" % (os.path.basename(ccomp[0]),\n ' '.join(ccomp[1:]))\n log.info(display)\n macros, objects, extra_postargs, pp_opts, build = \\\n self._setup_compile(output_dir, macros, include_dirs, sources,\n depends, extra_postargs)\n cc_args = self._get_cc_args(pp_opts, debug, extra_preargs)\n display = \"compile options: '%s'\" % (' '.join(cc_args))\n if extra_postargs:\n display += \"\\nextra options: '%s'\" % (' '.join(extra_postargs))\n log.info(display)\n \n # build any sources in same order as they were originally specified\n # especially important for fortran .f90 files using modules\n if isinstance(self, FCompiler):\n objects_to_build = build.keys()\n for obj in objects:\n if obj in objects_to_build:\n src, ext = build[obj]\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n else:\n for obj, (src, ext) in build.items():\n self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts)\n \n # Return *all* object filenames, not just the ones we just built.\n return objects\n\nCCompiler.compile = new.instancemethod(CCompiler_compile,None,CCompiler)\n\ndef CCompiler_customize_cmd(self, cmd):\n \"\"\" Customize compiler using distutils command.\n \"\"\"\n log.info('customize %s using %s' % (self.__class__.__name__,\n cmd.__class__.__name__))\n if getattr(cmd,'include_dirs',None) is not None:\n self.set_include_dirs(cmd.include_dirs)\n if getattr(cmd,'define',None) is not None:\n for (name,value) in cmd.define:\n self.define_macro(name, value)\n if getattr(cmd,'undef',None) is not None:\n for macro in cmd.undef:\n self.undefine_macro(macro)\n if getattr(cmd,'libraries',None) is not None:\n self.set_libraries(self.libraries + cmd.libraries)\n if getattr(cmd,'library_dirs',None) is not None:\n self.set_library_dirs(self.library_dirs + cmd.library_dirs)\n if getattr(cmd,'rpath',None) is not None:\n self.set_runtime_library_dirs(cmd.rpath)\n if getattr(cmd,'link_objects',None) is not None:\n self.set_link_objects(cmd.link_objects)\n return\n\nCCompiler.customize_cmd = new.instancemethod(\\\n CCompiler_customize_cmd,None,CCompiler)\n\ndef CCompiler_show_customization(self):\n if 0:\n for attrname in ['include_dirs','define','undef',\n 'libraries','library_dirs',\n 'rpath','link_objects']:\n attr = getattr(self,attrname,None)\n if not attr:\n continue\n log.info(\"compiler '%s' is set to %s\" % (attrname,attr))\n try: self.get_version()\n except: pass\n print '*'*80\n print self.__class__\n print compiler_to_string(self)\n print '*'*80\n\nCCompiler.show_customization = new.instancemethod(\\\n CCompiler_show_customization,None,CCompiler)\n\n\ndef CCompiler_customize(self, dist, need_cxx=0):\n # See FCompiler.customize for suggested usage.\n log.info('customize %s' % (self.__class__.__name__))\n customize_compiler(self)\n if need_cxx:\n if hasattr(self,'compiler') and self.compiler[0].find('gcc')>=0:\n if sys.version[:3]>='2.3':\n if not self.compiler_cxx:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n self.compiler_cxx = [self.compiler[0].replace('gcc','g++')]\\\n + self.compiler[1:]\n else:\n log.warn('Missing compiler_cxx fix for '+self.__class__.__name__)\n return\n\nCCompiler.customize = new.instancemethod(\\\n CCompiler_customize,None,CCompiler)\n\ndef CCompiler_get_version(self, force=0, ok_status=[0]):\n \"\"\" Compiler version. Returns None if compiler is not available. \"\"\"\n if not force and hasattr(self,'version'):\n return self.version\n if not (hasattr(self,'version_cmd') and\n hasattr(self,'version_pattern')):\n log.warn('%s does not provide version_cmd and version_pattern attributes' \\\n % (self.__class__))\n return\n\n cmd = ' '.join(self.version_cmd)\n status, output = exec_command(cmd,use_tee=0)\n version = None\n if status in ok_status:\n m = re.match(self.version_pattern,output)\n if m:\n version = m.group('version')\n assert version,`version`\n version = LooseVersion(version)\n self.version = version\n return version\n\nCCompiler.get_version = new.instancemethod(\\\n CCompiler_get_version,None,CCompiler)\n\nif sys.platform == 'win32':\n compiler_class['mingw32'] = ('mingw32ccompiler', 'Mingw32CCompiler',\n \"Mingw32 port of GNU C Compiler for Win32\"\\\n \"(for MSC built Python)\")\n if os.environ.get('OSTYPE','')=='msys' or \\\n os.environ.get('MSYSTEM','')=='MINGW32':\n # On windows platforms, we want to default to mingw32 (gcc)\n # because msvc can't build blitz stuff.\n log.info('Setting mingw32 as default compiler for nt.')\n ccompiler._default_compilers = (('nt', 'mingw32'),) \\\n + ccompiler._default_compilers\n\n\n_distutils_new_compiler = new_compiler\ndef new_compiler (plat=None,\n compiler=None,\n verbose=0,\n dry_run=0,\n force=0):\n # Try first C compilers from scipy_distutils.\n if plat is None:\n plat = os.name\n try:\n if compiler is None:\n compiler = get_default_compiler(plat)\n (module_name, class_name, long_description) = compiler_class[compiler]\n except KeyError:\n msg = \"don't know how to compile C/C++ code on platform '%s'\" % plat\n if compiler is not None:\n msg = msg + \" with '%s' compiler\" % compiler\n raise DistutilsPlatformError, msg\n\n module_name = \"scipy_distutils.\" + module_name\n try:\n __import__ (module_name)\n except ImportError, msg:\n print msg\n module_name = module_name[6:]\n try:\n __import__(module_name)\n except ImportError:\n raise DistutilsModuleError, \\\n \"can't compile C/C++ code: unable to load module '%s'\" % \\\n module_name\n try:\n module = sys.modules[module_name]\n klass = vars(module)[class_name]\n except KeyError:\n raise DistutilsModuleError, \\\n (\"can't compile C/C++ code: unable to find class '%s' \" +\n \"in module '%s'\") % (class_name, module_name)\n compiler = klass(None, dry_run, force)\n log.debug('new_fcompiler returns %s' % (klass))\n return compiler\n\nccompiler.new_compiler = new_compiler\n\n", "methods": [ { "name": "CCompiler_spawn", "long_name": "CCompiler_spawn( self , cmd , display = None )", "filename": "ccompiler.py", "nloc": 14, "complexity": 7, "token_count": 113, "parameters": [ "self", "cmd", "display" ], "start_line": 18, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 }, { "name": "CCompiler_object_filenames", "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", "filename": "ccompiler.py", "nloc": 21, "complexity": 6, "token_count": 185, "parameters": [ "self", "source_filenames", "strip_dir", "output_dir" ], "start_line": 34, "end_line": 56, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "CCompiler_compile", "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "ccompiler.py", "nloc": 39, "complexity": 10, "token_count": 323, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 61, "end_line": 104, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 0 }, { "name": "CCompiler_customize_cmd", "long_name": "CCompiler_customize_cmd( self , cmd )", "filename": "ccompiler.py", "nloc": 20, "complexity": 10, "token_count": 200, "parameters": [ "self", "cmd" ], "start_line": 108, "end_line": 129, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_show_customization", "long_name": "CCompiler_show_customization( self )", "filename": "ccompiler.py", "nloc": 15, "complexity": 5, "token_count": 81, "parameters": [ "self" ], "start_line": 134, "end_line": 148, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 15, "complexity": 6, "token_count": 144, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 154, "end_line": 169, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_get_version", "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", "filename": "ccompiler.py", "nloc": 19, "complexity": 7, "token_count": 135, "parameters": [ "self", "force", "ok_status" ], "start_line": 174, "end_line": 194, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "new_compiler", "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "ccompiler.py", "nloc": 38, "complexity": 8, "token_count": 184, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 213, "end_line": 252, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 } ], "methods_before": [ { "name": "CCompiler_spawn", "long_name": "CCompiler_spawn( self , cmd , display = None )", "filename": "ccompiler.py", "nloc": 16, "complexity": 8, "token_count": 127, "parameters": [ "self", "cmd", "display" ], "start_line": 18, "end_line": 33, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_object_filenames", "long_name": "CCompiler_object_filenames( self , source_filenames , strip_dir = 0 , output_dir = '' )", "filename": "ccompiler.py", "nloc": 21, "complexity": 6, "token_count": 185, "parameters": [ "self", "source_filenames", "strip_dir", "output_dir" ], "start_line": 36, "end_line": 58, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 23, "top_nesting_level": 0 }, { "name": "CCompiler_compile", "long_name": "CCompiler_compile( self , sources , output_dir = None , macros = None , include_dirs = None , debug = 0 , extra_preargs = None , extra_postargs = None , depends = None )", "filename": "ccompiler.py", "nloc": 39, "complexity": 10, "token_count": 323, "parameters": [ "self", "sources", "output_dir", "macros", "include_dirs", "debug", "extra_preargs", "extra_postargs", "depends" ], "start_line": 63, "end_line": 106, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 44, "top_nesting_level": 0 }, { "name": "CCompiler_customize_cmd", "long_name": "CCompiler_customize_cmd( self , cmd )", "filename": "ccompiler.py", "nloc": 20, "complexity": 10, "token_count": 200, "parameters": [ "self", "cmd" ], "start_line": 110, "end_line": 131, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 22, "top_nesting_level": 0 }, { "name": "CCompiler_show_customization", "long_name": "CCompiler_show_customization( self )", "filename": "ccompiler.py", "nloc": 15, "complexity": 5, "token_count": 81, "parameters": [ "self" ], "start_line": 136, "end_line": 150, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 15, "top_nesting_level": 0 }, { "name": "CCompiler_customize", "long_name": "CCompiler_customize( self , dist , need_cxx = 0 )", "filename": "ccompiler.py", "nloc": 15, "complexity": 6, "token_count": 144, "parameters": [ "self", "dist", "need_cxx" ], "start_line": 156, "end_line": 171, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 16, "top_nesting_level": 0 }, { "name": "CCompiler_get_version", "long_name": "CCompiler_get_version( self , force = 0 , ok_status = [ 0 ] )", "filename": "ccompiler.py", "nloc": 19, "complexity": 7, "token_count": 135, "parameters": [ "self", "force", "ok_status" ], "start_line": 176, "end_line": 196, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 21, "top_nesting_level": 0 }, { "name": "new_compiler", "long_name": "new_compiler( plat = None , compiler = None , verbose = 0 , dry_run = 0 , force = 0 )", "filename": "ccompiler.py", "nloc": 38, "complexity": 8, "token_count": 184, "parameters": [ "plat", "compiler", "verbose", "dry_run", "force" ], "start_line": 215, "end_line": 254, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 40, "top_nesting_level": 0 } ], "changed_methods": [ { "name": "CCompiler_spawn", "long_name": "CCompiler_spawn( self , cmd , display = None )", "filename": "ccompiler.py", "nloc": 14, "complexity": 7, "token_count": 113, "parameters": [ "self", "cmd", "display" ], "start_line": 18, "end_line": 31, "fan_in": 0, "fan_out": 0, "general_fan_out": 0, "length": 14, "top_nesting_level": 0 } ], "nloc": 216, "complexity": 59, "token_count": 1601, "diff_parsed": { "added": [ " print o" ], "deleted": [ " if os.name != 'posix':", " print \" \".join(cmd)", " print o" ] } } ] } ]