diff --git "a/partition_6.json" "b/partition_6.json" new file mode 100644--- /dev/null +++ "b/partition_6.json" @@ -0,0 +1,41065 @@ +[ + { + "hash": "64ffff9d53d2c26f0b7c014fb0152ccfc6568c34", + "msg": "Fixed bug in build_ext.py", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-02-19T17:33:57+00:00", + "author_timezone": 0, + "committer_date": "2002-02-19T17:33:57+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "5ba533b4b7b4562c36df4d0a698efff872a98086" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/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/command/build_ext.py", + "new_path": "scipy_distutils/command/build_ext.py", + "filename": "build_ext.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -71,7 +71,7 @@ def build_extension(self, ext):\n #self.compiler.libraries = self.compiler.libraries + l\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n- if lib_dir not in self.compiler.libraries_dirs:\n+ if lib_dir not in self.compiler.library_dirs:\n self.compiler.libraries.append(lib_dir)\n #self.compiler.library_dirs = self.compiler.library_dirs + l\n \n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os, string\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import *\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n #XXX: anything else we need to save?\n save_linker_so = self.compiler.linker_so\n save_compiler_libs = self.compiler.libraries\n save_compiler_libs_dirs = self.compiler.library_dirs\n \n # support for building static fortran libraries\n need_f_libs = 0\n ext_name = string.split(ext.name,'.')[-1]\n\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n if build_flib.has_f_library(ext_name):\n need_f_libs = 1\n else:\n for lib_name in ext.libraries:\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n print ext.name,ext_name,'needs fortran libraries',need_f_libs\n \n if need_f_libs:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n if moreargs != []:\n if ext.extra_link_args is None:\n ext.extra_link_args = moreargs\n else:\n ext.extra_link_args += moreargs\n if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.append(ext_name)\n for lib_name in ext.libraries[:]:\n ext.libraries.extend(build_flib.get_library_names(lib_name))\n ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))\n \n ext.library_dirs.append(build_flib.build_flib)\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n \n linker_so = build_flib.fcompiler.get_linker_so()\n\n if linker_so is not None:\n if linker_so is not save_linker_so:\n print 'replacing linker_so %s with %s' %(save_linker_so,linker_so)\n self.compiler.linker_so = linker_so\n l = build_flib.get_fcompiler_library_names()\n #l = self.compiler.libraries + l\n self.compiler.libraries = l\n l = build_flib.get_fcompiler_library_dirs()\n #l = self.compiler.library_dirs + l\n self.compiler.library_dirs = l\n else:\n libs = build_flib.get_fcompiler_library_names()\n for lib in libs:\n if lib not in self.compiler.libraries:\n self.compiler.libraries.append(lib)\n #self.compiler.libraries = self.compiler.libraries + l\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n if lib_dir not in self.compiler.library_dirs:\n self.compiler.libraries.append(lib_dir)\n #self.compiler.library_dirs = self.compiler.library_dirs + l\n \n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n\n if save_linker_so is not self.compiler.linker_so:\n print 'restoring linker_so',save_linker_so\n self.compiler.linker_so = save_linker_so\n self.compiler.libraries = save_compiler_libs\n self.compiler.library_dirs = save_compiler_libs_dirs\n\n return res\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n filenames.extend(ext.sources)\n filenames.extend(get_headers(get_directories(ext.sources)))\n\n return filenames\n", + "source_code_before": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os, string\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import *\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n #XXX: anything else we need to save?\n save_linker_so = self.compiler.linker_so\n save_compiler_libs = self.compiler.libraries\n save_compiler_libs_dirs = self.compiler.library_dirs\n \n # support for building static fortran libraries\n need_f_libs = 0\n ext_name = string.split(ext.name,'.')[-1]\n\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n if build_flib.has_f_library(ext_name):\n need_f_libs = 1\n else:\n for lib_name in ext.libraries:\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n print ext.name,ext_name,'needs fortran libraries',need_f_libs\n \n if need_f_libs:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n if moreargs != []:\n if ext.extra_link_args is None:\n ext.extra_link_args = moreargs\n else:\n ext.extra_link_args += moreargs\n if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.append(ext_name)\n for lib_name in ext.libraries[:]:\n ext.libraries.extend(build_flib.get_library_names(lib_name))\n ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))\n \n ext.library_dirs.append(build_flib.build_flib)\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n \n linker_so = build_flib.fcompiler.get_linker_so()\n\n if linker_so is not None:\n if linker_so is not save_linker_so:\n print 'replacing linker_so %s with %s' %(save_linker_so,linker_so)\n self.compiler.linker_so = linker_so\n l = build_flib.get_fcompiler_library_names()\n #l = self.compiler.libraries + l\n self.compiler.libraries = l\n l = build_flib.get_fcompiler_library_dirs()\n #l = self.compiler.library_dirs + l\n self.compiler.library_dirs = l\n else:\n libs = build_flib.get_fcompiler_library_names()\n for lib in libs:\n if lib not in self.compiler.libraries:\n self.compiler.libraries.append(lib)\n #self.compiler.libraries = self.compiler.libraries + l\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n if lib_dir not in self.compiler.libraries_dirs:\n self.compiler.libraries.append(lib_dir)\n #self.compiler.library_dirs = self.compiler.library_dirs + l\n \n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n\n if save_linker_so is not self.compiler.linker_so:\n print 'restoring linker_so',save_linker_so\n self.compiler.linker_so = save_linker_so\n self.compiler.libraries = save_compiler_libs\n self.compiler.library_dirs = save_compiler_libs_dirs\n\n return res\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n filenames.extend(ext.sources)\n filenames.extend(get_headers(get_directories(ext.sources)))\n\n return filenames\n", + "methods": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 57, + "complexity": 19, + "token_count": 408, + "parameters": [ + "self", + "ext" + ], + "start_line": 15, + "end_line": 87, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_ext.py", + "nloc": 7, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 89, + "end_line": 98, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 57, + "complexity": 19, + "token_count": 408, + "parameters": [ + "self", + "ext" + ], + "start_line": 15, + "end_line": 87, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_ext.py", + "nloc": 7, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 89, + "end_line": 98, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 57, + "complexity": 19, + "token_count": 408, + "parameters": [ + "self", + "ext" + ], + "start_line": 15, + "end_line": 87, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 1 + } + ], + "nloc": 73, + "complexity": 21, + "token_count": 509, + "diff_parsed": { + "added": [ + " if lib_dir not in self.compiler.library_dirs:" + ], + "deleted": [ + " if lib_dir not in self.compiler.libraries_dirs:" + ] + } + } + ] + }, + { + "hash": "1fb3905e0f4987b02c11de1954e9b8e31636c551", + "msg": "Finalized scipy version hooks", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-02-20T15:33:06+00:00", + "author_timezone": 0, + "committer_date": "2002-02-20T15:33:06+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "64ffff9d53d2c26f0b7c014fb0152ccfc6568c34" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 7, + "insertions": 3, + "lines": 10, + "files": 3, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "scipy_distutils/__version__.py", + "new_path": null, + "filename": "__version__.py", + "extension": "py", + "change_type": "DELETE", + "diff": "@@ -1,4 +0,0 @@\n-# This file is automatically updated with update_version\n-# function from scipy_distutils.misc_util.py\n-version = '0.6.23-alpha-116'\n-version_info = (0, 6, 23, 'alpha', 116)\n", + "added_lines": 0, + "deleted_lines": 4, + "source_code": null, + "source_code_before": "# This file is automatically updated with update_version\n# function from scipy_distutils.misc_util.py\nversion = '0.6.23-alpha-116'\nversion_info = (0, 6, 23, 'alpha', 116)\n", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [], + "deleted": [ + "# This file is automatically updated with update_version", + "# function from scipy_distutils.misc_util.py", + "version = '0.6.23-alpha-116'", + "version_info = (0, 6, 23, 'alpha', 116)" + ] + } + }, + { + "old_path": "scipy_distutils/atlas_info.py", + "new_path": "scipy_distutils/atlas_info.py", + "filename": "atlas_info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -1,7 +1,7 @@\n import sys, os\n from misc_util import get_path\n \n-library_path = ''\n+library_path = ['/home/peterson/opt/lib/atlas']\n \n def get_atlas_info():\n if sys.platform == 'win32':\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "import sys, os\nfrom misc_util import get_path\n\nlibrary_path = ['/home/peterson/opt/lib/atlas']\n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not library_path:\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries \n else:\n if not library_path:\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", + "source_code_before": "import sys, os\nfrom misc_util import get_path\n\nlibrary_path = ''\n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not library_path:\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries \n else:\n if not library_path:\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", + "methods": [ + { + "name": "get_atlas_info", + "long_name": "get_atlas_info( )", + "filename": "atlas_info.py", + "nloc": 16, + "complexity": 4, + "token_count": 86, + "parameters": [], + "start_line": 6, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "unix_atlas_directory", + "long_name": "unix_atlas_directory( platform )", + "filename": "atlas_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "platform" + ], + "start_line": 23, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "get_atlas_info", + "long_name": "get_atlas_info( )", + "filename": "atlas_info.py", + "nloc": 16, + "complexity": 4, + "token_count": 86, + "parameters": [], + "start_line": 6, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "unix_atlas_directory", + "long_name": "unix_atlas_directory( platform )", + "filename": "atlas_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "platform" + ], + "start_line": 23, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 26, + "complexity": 7, + "token_count": 140, + "diff_parsed": { + "added": [ + "library_path = ['/home/peterson/opt/lib/atlas']" + ], + "deleted": [ + "library_path = ''" + ] + } + }, + { + "old_path": "scipy_distutils/misc_util.py", + "new_path": "scipy_distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -244,9 +244,9 @@ def default_config_dict(name = None, parent_name = None):\n frame = sys._getframe(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n- if name and not parent_name:\n+ if name and parent_name is None:\n # Useful for local builds\n- d['version'] = update_version(path=local_path)\n+ d['version'] = get_version(path=local_path)\n \n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n", + "added_lines": 2, + "deleted_lines": 2, + "source_code": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = sys._getframe(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", + "source_code_before": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = sys._getframe(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and not parent_name:\n # Useful for local builds\n d['version'] = update_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", + "methods": [ + { + "name": "update_version", + "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", + "filename": "misc_util.py", + "nloc": 65, + "complexity": 12, + "token_count": 351, + "parameters": [ + "release_level", + "path", + "major", + "overwrite_version_py" + ], + "start_line": 3, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "get_version", + "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "release_level", + "path", + "major" + ], + "start_line": 111, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "get_cvs_revision", + "long_name": "get_cvs_revision( path )", + "filename": "misc_util.py", + "nloc": 21, + "complexity": 10, + "token_count": 190, + "parameters": [ + "path" + ], + "start_line": 127, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 156, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "add_local_to_path", + "long_name": "add_local_to_path( mod_name )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "mod_name" + ], + "start_line": 174, + "end_line": 176, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "add_grandparent_to_path", + "long_name": "add_grandparent_to_path( mod_name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 34, + "parameters": [ + "mod_name" + ], + "start_line": 179, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "restore_path", + "long_name": "restore_path( )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [], + "start_line": 184, + "end_line": 185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "append_package_dir_to_path", + "long_name": "append_package_dir_to_path( package_name )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 64, + "parameters": [ + "package_name" + ], + "start_line": 187, + "end_line": 201, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "get_package_config", + "long_name": "get_package_config( package_name )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 1, + "token_count": 27, + "parameters": [ + "package_name" + ], + "start_line": 203, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "package_config", + "long_name": "package_config( primary , dependencies = [ ] )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 53, + "parameters": [ + "primary", + "dependencies" + ], + "start_line": 215, + "end_line": 227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 213, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 234, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "merge_config_dicts", + "long_name": "merge_config_dicts( config_list )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 4, + "token_count": 61, + "parameters": [ + "config_list" + ], + "start_line": 267, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "args" + ], + "start_line": 276, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "fortran_library_item", + "long_name": "fortran_library_item( lib_name , sources , ** attrs )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 3, + "token_count": 67, + "parameters": [ + "lib_name", + "sources", + "attrs" + ], + "start_line": 279, + "end_line": 294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "update_version", + "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", + "filename": "misc_util.py", + "nloc": 65, + "complexity": 12, + "token_count": 351, + "parameters": [ + "release_level", + "path", + "major", + "overwrite_version_py" + ], + "start_line": 3, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "get_version", + "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "release_level", + "path", + "major" + ], + "start_line": 111, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "get_cvs_revision", + "long_name": "get_cvs_revision( path )", + "filename": "misc_util.py", + "nloc": 21, + "complexity": 10, + "token_count": 190, + "parameters": [ + "path" + ], + "start_line": 127, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 156, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "add_local_to_path", + "long_name": "add_local_to_path( mod_name )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "mod_name" + ], + "start_line": 174, + "end_line": 176, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "add_grandparent_to_path", + "long_name": "add_grandparent_to_path( mod_name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 34, + "parameters": [ + "mod_name" + ], + "start_line": 179, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "restore_path", + "long_name": "restore_path( )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [], + "start_line": 184, + "end_line": 185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "append_package_dir_to_path", + "long_name": "append_package_dir_to_path( package_name )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 64, + "parameters": [ + "package_name" + ], + "start_line": 187, + "end_line": 201, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "get_package_config", + "long_name": "get_package_config( package_name )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 1, + "token_count": 27, + "parameters": [ + "package_name" + ], + "start_line": 203, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "package_config", + "long_name": "package_config( primary , dependencies = [ ] )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 53, + "parameters": [ + "primary", + "dependencies" + ], + "start_line": 215, + "end_line": 227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 212, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 234, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "merge_config_dicts", + "long_name": "merge_config_dicts( config_list )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 4, + "token_count": 61, + "parameters": [ + "config_list" + ], + "start_line": 267, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "args" + ], + "start_line": 276, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "fortran_library_item", + "long_name": "fortran_library_item( lib_name , sources , ** attrs )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 3, + "token_count": 67, + "parameters": [ + "lib_name", + "sources", + "attrs" + ], + "start_line": 279, + "end_line": 294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 213, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 234, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + } + ], + "nloc": 185, + "complexity": 54, + "token_count": 1279, + "diff_parsed": { + "added": [ + " if name and parent_name is None:", + " d['version'] = get_version(path=local_path)" + ], + "deleted": [ + " if name and not parent_name:", + " d['version'] = update_version(path=local_path)" + ] + } + } + ] + }, + { + "hash": "a9e45905eb56f143eda3f33df88a07444e64488d", + "msg": "Impl. system_info and x11_info", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-02-20T18:14:13+00:00", + "author_timezone": 0, + "committer_date": "2002-02-20T18:14:13+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "1fb3905e0f4987b02c11de1954e9b8e31636c551" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 0, + "insertions": 102, + "lines": 102, + "files": 2, + "dmm_unit_size": 0.38461538461538464, + "dmm_unit_complexity": 0.38461538461538464, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "scipy_distutils/misc_util.py", + "new_path": "scipy_distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -273,6 +273,13 @@ def merge_config_dicts(config_list):\n result[key].update(d.get(key,{}))\n return result\n \n+def 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+\n def dot_join(*args):\n return string.join(filter(None,args),'.')\n \n", + "added_lines": 7, + "deleted_lines": 0, + "source_code": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = sys._getframe(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef 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 ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", + "source_code_before": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = sys._getframe(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef dot_join(*args):\n return string.join(filter(None,args),'.')\n\ndef fortran_library_item(lib_name,\n sources,\n **attrs\n ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", + "methods": [ + { + "name": "update_version", + "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", + "filename": "misc_util.py", + "nloc": 65, + "complexity": 12, + "token_count": 351, + "parameters": [ + "release_level", + "path", + "major", + "overwrite_version_py" + ], + "start_line": 3, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "get_version", + "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "release_level", + "path", + "major" + ], + "start_line": 111, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "get_cvs_revision", + "long_name": "get_cvs_revision( path )", + "filename": "misc_util.py", + "nloc": 21, + "complexity": 10, + "token_count": 190, + "parameters": [ + "path" + ], + "start_line": 127, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 156, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "add_local_to_path", + "long_name": "add_local_to_path( mod_name )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "mod_name" + ], + "start_line": 174, + "end_line": 176, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "add_grandparent_to_path", + "long_name": "add_grandparent_to_path( mod_name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 34, + "parameters": [ + "mod_name" + ], + "start_line": 179, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "restore_path", + "long_name": "restore_path( )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [], + "start_line": 184, + "end_line": 185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "append_package_dir_to_path", + "long_name": "append_package_dir_to_path( package_name )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 64, + "parameters": [ + "package_name" + ], + "start_line": 187, + "end_line": 201, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "get_package_config", + "long_name": "get_package_config( package_name )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 1, + "token_count": 27, + "parameters": [ + "package_name" + ], + "start_line": 203, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "package_config", + "long_name": "package_config( primary , dependencies = [ ] )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 53, + "parameters": [ + "primary", + "dependencies" + ], + "start_line": 215, + "end_line": 227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 213, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 234, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "merge_config_dicts", + "long_name": "merge_config_dicts( config_list )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 4, + "token_count": 61, + "parameters": [ + "config_list" + ], + "start_line": 267, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 276, + "end_line": 281, + "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": 283, + "end_line": 284, + "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": 286, + "end_line": 301, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "update_version", + "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", + "filename": "misc_util.py", + "nloc": 65, + "complexity": 12, + "token_count": 351, + "parameters": [ + "release_level", + "path", + "major", + "overwrite_version_py" + ], + "start_line": 3, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "get_version", + "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "release_level", + "path", + "major" + ], + "start_line": 111, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "get_cvs_revision", + "long_name": "get_cvs_revision( path )", + "filename": "misc_util.py", + "nloc": 21, + "complexity": 10, + "token_count": 190, + "parameters": [ + "path" + ], + "start_line": 127, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 156, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "add_local_to_path", + "long_name": "add_local_to_path( mod_name )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "mod_name" + ], + "start_line": 174, + "end_line": 176, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "add_grandparent_to_path", + "long_name": "add_grandparent_to_path( mod_name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 34, + "parameters": [ + "mod_name" + ], + "start_line": 179, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "restore_path", + "long_name": "restore_path( )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [], + "start_line": 184, + "end_line": 185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "append_package_dir_to_path", + "long_name": "append_package_dir_to_path( package_name )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 64, + "parameters": [ + "package_name" + ], + "start_line": 187, + "end_line": 201, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "get_package_config", + "long_name": "get_package_config( package_name )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 1, + "token_count": 27, + "parameters": [ + "package_name" + ], + "start_line": 203, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "package_config", + "long_name": "package_config( primary , dependencies = [ ] )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 53, + "parameters": [ + "primary", + "dependencies" + ], + "start_line": 215, + "end_line": 227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 213, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 234, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "merge_config_dicts", + "long_name": "merge_config_dicts( config_list )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 4, + "token_count": 61, + "parameters": [ + "config_list" + ], + "start_line": 267, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "dot_join", + "long_name": "dot_join( * args )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "args" + ], + "start_line": 276, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "fortran_library_item", + "long_name": "fortran_library_item( lib_name , sources , ** attrs )", + "filename": "misc_util.py", + "nloc": 14, + "complexity": 3, + "token_count": 67, + "parameters": [ + "lib_name", + "sources", + "attrs" + ], + "start_line": 279, + "end_line": 294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "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": 276, + "end_line": 281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + } + ], + "nloc": 191, + "complexity": 57, + "token_count": 1324, + "diff_parsed": { + "added": [ + "def dict_append(d,**kws):", + " for k,v in kws.items():", + " if d.has_key(k):", + " d[k].extend(v)", + " else:", + " d[k] = v", + "" + ], + "deleted": [] + } + }, + { + "old_path": null, + "new_path": "scipy_distutils/system_info.py", + "filename": "system_info.py", + "extension": "py", + "change_type": "ADD", + "diff": "@@ -0,0 +1,95 @@\n+#!/usr/bin/env python\n+\n+import sys,os,re,types\n+from glob import glob\n+\n+class system_info:\n+\n+ if sys.platform == 'win32':\n+ prefixes = [] # XXX: what is prefix in win32? C: maybe?\n+ else:\n+ prefixes = ['/usr','/usr/local','/opt']\n+ if sys.prefix not in prefixes:\n+ prefixes.append(sys.prefix)\n+ prefixes = filter(os.path.isdir,prefixes)\n+\n+ def __init__ (self):\n+ self.info = {}\n+ self.need_refresh = 1\n+ def get_info(self):\n+ \"\"\" Return a dictonary with items that are compatible\n+ with scipy_distutils.setup keyword arguments.\n+ \"\"\"\n+ if self.need_refresh:\n+ for p in self.prefixes:\n+ r = self.calc_info(p)\n+ if r: break\n+ self.need_refresh = 0\n+ return self.info\n+ def calc_info(self,prefix):\n+ \"\"\" Calculate info distionary. \"\"\"\n+\n+class fftw_info(system_info):\n+ pass\n+\n+class atlas_info(system_info):\n+ pass\n+\n+class x11_info(system_info):\n+\n+ def calc_info(self, prefix):\n+ if sys.platform == 'win32':\n+ return\n+ for x11_dir in combine_paths(prefix,['X11R6','X11']):\n+ inc_dir = None\n+ for d in combine_paths(x11_dir,['include','include/X11']):\n+ if combine_paths(d,'X.h'):\n+ inc_dir = d\n+ break\n+ if not d: return\n+ lib_dir = combine_paths(x11_dir,'lib')\n+ if not lib_dir: return\n+ info = {}\n+ if combine_paths(lib_dir,'libX11.a'):\n+ info['library_dirs'] = lib_dir\n+ info['libraries'] = ['X11']\n+ else:\n+ shared_libs = combine_paths(lib_dir,'libX11.so*')\n+ if not shared_libs: return\n+ info['extra_linker_arguments'] = [shared_libs[0]]\n+ info['include_dirs'] = [inc_dir]\n+ self.info = info\n+ return 1\n+\n+def combine_paths(*args):\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: return map(glob,args[0])\n+ if 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+ return result\n+ return combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n+\n+def show_all():\n+ import system_info\n+ match_info = re.compile(r'.*?_info').match\n+ for n in filter(match_info,dir(system_info)):\n+ if n=='system_info': continue\n+ c = getattr(system_info,n)()\n+ print '------------>',n\n+ print c.get_info()\n+\n+if __name__ == \"__main__\":\n+ show_all()\n", + "added_lines": 95, + "deleted_lines": 0, + "source_code": "#!/usr/bin/env python\n\nimport sys,os,re,types\nfrom glob import glob\n\nclass system_info:\n\n if sys.platform == 'win32':\n prefixes = [] # XXX: what is prefix in win32? C: maybe?\n else:\n prefixes = ['/usr','/usr/local','/opt']\n if sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\n prefixes = filter(os.path.isdir,prefixes)\n\n def __init__ (self):\n self.info = {}\n self.need_refresh = 1\n def get_info(self):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n if self.need_refresh:\n for p in self.prefixes:\n r = self.calc_info(p)\n if r: break\n self.need_refresh = 0\n return self.info\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\n\nclass fftw_info(system_info):\n pass\n\nclass atlas_info(system_info):\n pass\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = {}\n if combine_paths(lib_dir,'libX11.a'):\n info['library_dirs'] = lib_dir\n info['libraries'] = ['X11']\n else:\n shared_libs = combine_paths(lib_dir,'libX11.so*')\n if not shared_libs: return\n info['extra_linker_arguments'] = [shared_libs[0]]\n info['include_dirs'] = [inc_dir]\n self.info = info\n return 1\n\ndef combine_paths(*args):\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: return map(glob,args[0])\n if 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 return result\n return combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n\ndef show_all():\n import system_info\n match_info = re.compile(r'.*?_info').match\n for n in filter(match_info,dir(system_info)):\n if n=='system_info': continue\n c = getattr(system_info,n)()\n print '------------>',n\n print c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n", + "source_code_before": null, + "methods": [ + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 16, + "end_line": 18, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 39, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 28, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 29, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 9, + "token_count": 143, + "parameters": [ + "self", + "prefix" + ], + "start_line": 40, + "end_line": 62, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 9, + "token_count": 143, + "parameters": [ + "args" + ], + "start_line": 64, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 56, + "parameters": [], + "start_line": 85, + "end_line": 92, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "methods_before": [], + "changed_methods": [ + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 56, + "parameters": [], + "start_line": 85, + "end_line": 92, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 39, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 28, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 29, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 9, + "token_count": 143, + "parameters": [ + "args" + ], + "start_line": 64, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 16, + "end_line": 18, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + } + ], + "nloc": 76, + "complexity": 27, + "token_count": 504, + "diff_parsed": { + "added": [ + "#!/usr/bin/env python", + "", + "import sys,os,re,types", + "from glob import glob", + "", + "class system_info:", + "", + " if sys.platform == 'win32':", + " prefixes = [] # XXX: what is prefix in win32? C: maybe?", + " else:", + " prefixes = ['/usr','/usr/local','/opt']", + " if sys.prefix not in prefixes:", + " prefixes.append(sys.prefix)", + " prefixes = filter(os.path.isdir,prefixes)", + "", + " def __init__ (self):", + " self.info = {}", + " self.need_refresh = 1", + " def get_info(self):", + " \"\"\" Return a dictonary with items that are compatible", + " with scipy_distutils.setup keyword arguments.", + " \"\"\"", + " if self.need_refresh:", + " for p in self.prefixes:", + " r = self.calc_info(p)", + " if r: break", + " self.need_refresh = 0", + " return self.info", + " def calc_info(self,prefix):", + " \"\"\" Calculate info distionary. \"\"\"", + "", + "class fftw_info(system_info):", + " pass", + "", + "class atlas_info(system_info):", + " pass", + "", + "class x11_info(system_info):", + "", + " def calc_info(self, prefix):", + " if sys.platform == 'win32':", + " return", + " for x11_dir in combine_paths(prefix,['X11R6','X11']):", + " inc_dir = None", + " for d in combine_paths(x11_dir,['include','include/X11']):", + " if combine_paths(d,'X.h'):", + " inc_dir = d", + " break", + " if not d: return", + " lib_dir = combine_paths(x11_dir,'lib')", + " if not lib_dir: return", + " info = {}", + " if combine_paths(lib_dir,'libX11.a'):", + " info['library_dirs'] = lib_dir", + " info['libraries'] = ['X11']", + " else:", + " shared_libs = combine_paths(lib_dir,'libX11.so*')", + " if not shared_libs: return", + " info['extra_linker_arguments'] = [shared_libs[0]]", + " info['include_dirs'] = [inc_dir]", + " self.info = info", + " return 1", + "", + "def combine_paths(*args):", + " \"\"\" Return a list of existing paths composed by all combinations of", + " items from arguments.", + " \"\"\"", + " r = []", + " for a in args:", + " if not a: continue", + " if type(a) is types.StringType:", + " a = [a]", + " r.append(a)", + " args = r", + " if not args: return []", + " if len (args)==1: return map(glob,args[0])", + " if len (args)==2:", + " result = []", + " for a0 in args[0]:", + " for a1 in args[1]:", + " result.extend(glob(os.path.join(a0,a1)))", + " return result", + " return combine_paths(*(combine_paths(args[0],args[1])+args[2:]))", + "", + "def show_all():", + " import system_info", + " match_info = re.compile(r'.*?_info').match", + " for n in filter(match_info,dir(system_info)):", + " if n=='system_info': continue", + " c = getattr(system_info,n)()", + " print '------------>',n", + " print c.get_info()", + "", + "if __name__ == \"__main__\":", + " show_all()" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "19ad2a8e5a712a12f5eb1bfcd347e978eb303058", + "msg": "Fixed bug in scipy_distutils -- extra_linker_arguments was the incorrect variable in system_info. Also, changed library_path at the top of atlas_info to None so that the list would be searched.", + "author": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "committer": { + "name": "Travis Oliphant", + "email": "oliphant@enthought.com" + }, + "author_date": "2002-02-20T18:46:07+00:00", + "author_timezone": 0, + "committer_date": "2002-02-20T18:46:07+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "a9e45905eb56f143eda3f33df88a07444e64488d" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 2, + "insertions": 2, + "lines": 4, + "files": 2, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "scipy_distutils/atlas_info.py", + "new_path": "scipy_distutils/atlas_info.py", + "filename": "atlas_info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -1,7 +1,7 @@\n import sys, os\n from misc_util import get_path\n \n-library_path = ['/home/peterson/opt/lib/atlas']\n+library_path = None \n \n def get_atlas_info():\n if sys.platform == 'win32':\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "import sys, os\nfrom misc_util import get_path\n\nlibrary_path = None \n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not library_path:\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries \n else:\n if not library_path:\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", + "source_code_before": "import sys, os\nfrom misc_util import get_path\n\nlibrary_path = ['/home/peterson/opt/lib/atlas']\n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not library_path:\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries \n else:\n if not library_path:\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", + "methods": [ + { + "name": "get_atlas_info", + "long_name": "get_atlas_info( )", + "filename": "atlas_info.py", + "nloc": 16, + "complexity": 4, + "token_count": 86, + "parameters": [], + "start_line": 6, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "unix_atlas_directory", + "long_name": "unix_atlas_directory( platform )", + "filename": "atlas_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "platform" + ], + "start_line": 23, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "get_atlas_info", + "long_name": "get_atlas_info( )", + "filename": "atlas_info.py", + "nloc": 16, + "complexity": 4, + "token_count": 86, + "parameters": [], + "start_line": 6, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "unix_atlas_directory", + "long_name": "unix_atlas_directory( platform )", + "filename": "atlas_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "platform" + ], + "start_line": 23, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 26, + "complexity": 7, + "token_count": 138, + "diff_parsed": { + "added": [ + "library_path = None" + ], + "deleted": [ + "library_path = ['/home/peterson/opt/lib/atlas']" + ] + } + }, + { + "old_path": "scipy_distutils/system_info.py", + "new_path": "scipy_distutils/system_info.py", + "filename": "system_info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -56,7 +56,7 @@ def calc_info(self, prefix):\n else:\n shared_libs = combine_paths(lib_dir,'libX11.so*')\n if not shared_libs: return\n- info['extra_linker_arguments'] = [shared_libs[0]]\n+ info['extra_link_args'] = [shared_libs[0]]\n info['include_dirs'] = [inc_dir]\n self.info = info\n return 1\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "#!/usr/bin/env python\n\nimport sys,os,re,types\nfrom glob import glob\n\nclass system_info:\n\n if sys.platform == 'win32':\n prefixes = [] # XXX: what is prefix in win32? C: maybe?\n else:\n prefixes = ['/usr','/usr/local','/opt']\n if sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\n prefixes = filter(os.path.isdir,prefixes)\n\n def __init__ (self):\n self.info = {}\n self.need_refresh = 1\n def get_info(self):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n if self.need_refresh:\n for p in self.prefixes:\n r = self.calc_info(p)\n if r: break\n self.need_refresh = 0\n return self.info\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\n\nclass fftw_info(system_info):\n pass\n\nclass atlas_info(system_info):\n pass\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = {}\n if combine_paths(lib_dir,'libX11.a'):\n info['library_dirs'] = lib_dir\n info['libraries'] = ['X11']\n else:\n shared_libs = combine_paths(lib_dir,'libX11.so*')\n if not shared_libs: return\n info['extra_link_args'] = [shared_libs[0]]\n info['include_dirs'] = [inc_dir]\n self.info = info\n return 1\n\ndef combine_paths(*args):\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: return map(glob,args[0])\n if 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 return result\n return combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n\ndef show_all():\n import system_info\n match_info = re.compile(r'.*?_info').match\n for n in filter(match_info,dir(system_info)):\n if n=='system_info': continue\n c = getattr(system_info,n)()\n print '------------>',n\n print c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n", + "source_code_before": "#!/usr/bin/env python\n\nimport sys,os,re,types\nfrom glob import glob\n\nclass system_info:\n\n if sys.platform == 'win32':\n prefixes = [] # XXX: what is prefix in win32? C: maybe?\n else:\n prefixes = ['/usr','/usr/local','/opt']\n if sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\n prefixes = filter(os.path.isdir,prefixes)\n\n def __init__ (self):\n self.info = {}\n self.need_refresh = 1\n def get_info(self):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n if self.need_refresh:\n for p in self.prefixes:\n r = self.calc_info(p)\n if r: break\n self.need_refresh = 0\n return self.info\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\n\nclass fftw_info(system_info):\n pass\n\nclass atlas_info(system_info):\n pass\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = {}\n if combine_paths(lib_dir,'libX11.a'):\n info['library_dirs'] = lib_dir\n info['libraries'] = ['X11']\n else:\n shared_libs = combine_paths(lib_dir,'libX11.so*')\n if not shared_libs: return\n info['extra_linker_arguments'] = [shared_libs[0]]\n info['include_dirs'] = [inc_dir]\n self.info = info\n return 1\n\ndef combine_paths(*args):\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: return map(glob,args[0])\n if 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 return result\n return combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n\ndef show_all():\n import system_info\n match_info = re.compile(r'.*?_info').match\n for n in filter(match_info,dir(system_info)):\n if n=='system_info': continue\n c = getattr(system_info,n)()\n print '------------>',n\n print c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n", + "methods": [ + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 16, + "end_line": 18, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 39, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 28, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 29, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 9, + "token_count": 143, + "parameters": [ + "self", + "prefix" + ], + "start_line": 40, + "end_line": 62, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 9, + "token_count": 143, + "parameters": [ + "args" + ], + "start_line": 64, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 56, + "parameters": [], + "start_line": 85, + "end_line": 92, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 16, + "end_line": 18, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 39, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 28, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 29, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 9, + "token_count": 143, + "parameters": [ + "self", + "prefix" + ], + "start_line": 40, + "end_line": 62, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 9, + "token_count": 143, + "parameters": [ + "args" + ], + "start_line": 64, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 56, + "parameters": [], + "start_line": 85, + "end_line": 92, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 9, + "token_count": 143, + "parameters": [ + "self", + "prefix" + ], + "start_line": 40, + "end_line": 62, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + } + ], + "nloc": 76, + "complexity": 27, + "token_count": 504, + "diff_parsed": { + "added": [ + " info['extra_link_args'] = [shared_libs[0]]" + ], + "deleted": [ + " info['extra_linker_arguments'] = [shared_libs[0]]" + ] + } + } + ] + }, + { + "hash": "b928b922ba440f9fa361be6b98e4e958b6c52f9e", + "msg": "Allowing for wrong directories to be mentioned in library_path.", + "author": { + "name": "prabhu", + "email": "prabhu@localhost" + }, + "committer": { + "name": "prabhu", + "email": "prabhu@localhost" + }, + "author_date": "2002-02-20T19:01:10+00:00", + "author_timezone": 0, + "committer_date": "2002-02-20T19:01:10+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "19ad2a8e5a712a12f5eb1bfcd347e978eb303058" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 2, + "insertions": 8, + "lines": 10, + "files": 1, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "scipy_distutils/atlas_info.py", + "new_path": "scipy_distutils/atlas_info.py", + "filename": "atlas_info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -3,16 +3,22 @@\n \n library_path = None \n \n+def dir_exists(dir_list):\n+ if dir_list:\n+ if os.path.exists(dir_list[0]):\n+ return 1\n+ return 0\n+\n def get_atlas_info():\n if sys.platform == 'win32':\n- if not library_path:\n+ if not dir_exists(library_path):\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries \n else:\n- if not library_path:\n+ if not dir_exists(library_path):\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n", + "added_lines": 8, + "deleted_lines": 2, + "source_code": "import sys, os\nfrom misc_util import get_path\n\nlibrary_path = None \n\ndef dir_exists(dir_list):\n if dir_list:\n if os.path.exists(dir_list[0]):\n return 1\n return 0\n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not dir_exists(library_path):\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries \n else:\n if not dir_exists(library_path):\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", + "source_code_before": "import sys, os\nfrom misc_util import get_path\n\nlibrary_path = None \n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not library_path:\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries \n else:\n if not library_path:\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", + "methods": [ + { + "name": "dir_exists", + "long_name": "dir_exists( dir_list )", + "filename": "atlas_info.py", + "nloc": 5, + "complexity": 3, + "token_count": 25, + "parameters": [ + "dir_list" + ], + "start_line": 6, + "end_line": 10, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "get_atlas_info", + "long_name": "get_atlas_info( )", + "filename": "atlas_info.py", + "nloc": 16, + "complexity": 4, + "token_count": 92, + "parameters": [], + "start_line": 12, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "unix_atlas_directory", + "long_name": "unix_atlas_directory( platform )", + "filename": "atlas_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "platform" + ], + "start_line": 29, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "get_atlas_info", + "long_name": "get_atlas_info( )", + "filename": "atlas_info.py", + "nloc": 16, + "complexity": 4, + "token_count": 86, + "parameters": [], + "start_line": 6, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "unix_atlas_directory", + "long_name": "unix_atlas_directory( platform )", + "filename": "atlas_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "platform" + ], + "start_line": 23, + "end_line": 46, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "dir_exists", + "long_name": "dir_exists( dir_list )", + "filename": "atlas_info.py", + "nloc": 5, + "complexity": 3, + "token_count": 25, + "parameters": [ + "dir_list" + ], + "start_line": 6, + "end_line": 10, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "get_atlas_info", + "long_name": "get_atlas_info( )", + "filename": "atlas_info.py", + "nloc": 16, + "complexity": 4, + "token_count": 92, + "parameters": [], + "start_line": 12, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "nloc": 31, + "complexity": 10, + "token_count": 170, + "diff_parsed": { + "added": [ + "def dir_exists(dir_list):", + " if dir_list:", + " if os.path.exists(dir_list[0]):", + " return 1", + " return 0", + "", + " if not dir_exists(library_path):", + " if not dir_exists(library_path):" + ], + "deleted": [ + " if not library_path:", + " if not library_path:" + ] + } + } + ] + }, + { + "hash": "0ae7d411b836a5cbd3de7d0e703911660ac16b9a", + "msg": "Impl. atlas_info, fftw_info classes", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-02-21T22:10:56+00:00", + "author_timezone": 0, + "committer_date": "2002-02-21T22:10:56+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "b928b922ba440f9fa361be6b98e4e958b6c52f9e" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 30, + "insertions": 272, + "lines": 302, + "files": 2, + "dmm_unit_size": 0.27218934911242604, + "dmm_unit_complexity": 0.1952662721893491, + "dmm_unit_interfacing": 0.8402366863905325, + "modified_files": [ + { + "old_path": "scipy_distutils/atlas_info.py", + "new_path": "scipy_distutils/atlas_info.py", + "filename": "atlas_info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -1,7 +1,7 @@\n import sys, os\n from misc_util import get_path\n \n-library_path = None \n+library_path = None\n \n def dir_exists(dir_list):\n if dir_list:\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "import sys, os\nfrom misc_util import get_path\n\nlibrary_path = None\n\ndef dir_exists(dir_list):\n if dir_list:\n if os.path.exists(dir_list[0]):\n return 1\n return 0\n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not dir_exists(library_path):\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries \n else:\n if not dir_exists(library_path):\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", + "source_code_before": "import sys, os\nfrom misc_util import get_path\n\nlibrary_path = None \n\ndef dir_exists(dir_list):\n if dir_list:\n if os.path.exists(dir_list[0]):\n return 1\n return 0\n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not dir_exists(library_path):\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries \n else:\n if not dir_exists(library_path):\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", + "methods": [ + { + "name": "dir_exists", + "long_name": "dir_exists( dir_list )", + "filename": "atlas_info.py", + "nloc": 5, + "complexity": 3, + "token_count": 25, + "parameters": [ + "dir_list" + ], + "start_line": 6, + "end_line": 10, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "get_atlas_info", + "long_name": "get_atlas_info( )", + "filename": "atlas_info.py", + "nloc": 16, + "complexity": 4, + "token_count": 92, + "parameters": [], + "start_line": 12, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "unix_atlas_directory", + "long_name": "unix_atlas_directory( platform )", + "filename": "atlas_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "platform" + ], + "start_line": 29, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "dir_exists", + "long_name": "dir_exists( dir_list )", + "filename": "atlas_info.py", + "nloc": 5, + "complexity": 3, + "token_count": 25, + "parameters": [ + "dir_list" + ], + "start_line": 6, + "end_line": 10, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "get_atlas_info", + "long_name": "get_atlas_info( )", + "filename": "atlas_info.py", + "nloc": 16, + "complexity": 4, + "token_count": 92, + "parameters": [], + "start_line": 12, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "unix_atlas_directory", + "long_name": "unix_atlas_directory( platform )", + "filename": "atlas_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "platform" + ], + "start_line": 29, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 31, + "complexity": 10, + "token_count": 170, + "diff_parsed": { + "added": [ + "library_path = None" + ], + "deleted": [ + "library_path = None" + ] + } + }, + { + "old_path": "scipy_distutils/system_info.py", + "new_path": "scipy_distutils/system_info.py", + "filename": "system_info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -1,40 +1,275 @@\n #!/usr/bin/env python\n+\"\"\"\n+This file defines a set of system_info classes for getting\n+information about various resources (libraries, library directories,\n+include directories, etc.) in the system. Currently, the following\n+classes are available:\n+ atlas_info\n+ fftw_info\n+ x11_info\n+The following environment variables are used if defined:\n+ ATLAS - path to ATLAS library\n+ FFTW - path to FFTW library\n \n-import sys,os,re,types\n+Usage:\n+ For example,\n+ info = atlas_info().get_info()\n+ info will be a dictionary that is compatible with distutils.setup keyword\n+ arguments. If info == {}, then the asked resource is not available.\n+\n+Global parameters:\n+ prefixes - a list of prefixes for scanning the location of\n+ resources.\n+ system_info.static_first - a flag for indicating that static\n+ libraries are searched first than shared ones.\n+ system_info.verbose - show the results if set.\n+\n+Author:\n+ Pearu Peterson , February 2002\n+Permission to use, modify, and distribute this software is given under the\n+terms of the LGPL. See http://www.fsf.org\n+NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n+\"\"\"\n+\n+import sys,os,re,types,pprint\n from glob import glob\n \n+from distutils.sysconfig import get_config_vars\n+\n+if sys.platform == 'win32':\n+ prefixes = ['C:'] # XXX: what is prefix in win32?\n+else:\n+ prefixes = ['/usr','/usr/local','/opt']\n+if sys.prefix not in prefixes:\n+ prefixes.append(sys.prefix)\n+prefixes = filter(os.path.isdir,prefixes) # XXX: Is this ok on win32? Is 'C:' dir?\n+\n+so_ext = get_config_vars('SO')[0] or ''\n+\n class system_info:\n \n- if sys.platform == 'win32':\n- prefixes = [] # XXX: what is prefix in win32? C: maybe?\n- else:\n- prefixes = ['/usr','/usr/local','/opt']\n- if sys.prefix not in prefixes:\n- prefixes.append(sys.prefix)\n- prefixes = filter(os.path.isdir,prefixes)\n+ \"\"\" get_info() is the only public method. Don't use others.\n+ \"\"\"\n+\n+ static_first = 1\n+ verbose = 1\n \n def __init__ (self):\n- self.info = {}\n- self.need_refresh = 1\n+ self.__class__.info = {}\n+ self.need_refresh = not self.info\n+ self.local_prefixes = []\n+\n+ def set_info(self,**info):\n+ self.__class__.info = info\n+\n def get_info(self):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n if self.need_refresh:\n- for p in self.prefixes:\n- r = self.calc_info(p)\n- if r: break\n+ if self.verbose:\n+ print self.__class__.__name__ + ':'\n+ for p in self.local_prefixes + prefixes:\n+ if self.verbose:\n+ print ' Looking in',p,'...'\n+ self.calc_info(p)\n+ if self.info: break\n self.need_refresh = 0\n+ if self.verbose:\n+ if not self.info:\n+ print ' NOT AVAILABLE'\n+ else:\n+ print ' FOUND:'\n+ for k,v in self.info.items():\n+ print ' %s = %s'%(k,v)\n+ print\n return self.info\n+\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\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+ mths = [self.check_static_libs,self.check_shared_libs]\n+ if not self.static_first:\n+ mths.reverse() # if one prefers shared libraries\n+ for m in mths:\n+ info = m(lib_dir,libs,opt_libs)\n+ if info is not None: return info\n+\n+ def check_static_libs(self,lib_dir,libs,opt_libs =[]):\n+ #XXX: what are .lib and .dll files under win32?\n+ if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs])) == len(libs):\n+ info = {'libraries':libs,'library_dirs':[lib_dir]}\n+ if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs]))\\\n+ ==len(opt_libs):\n+ info['libraries'].extend(opt_libs)\n+ return info\n+\n+ def check_shared_libs(self,lib_dir,libs,opt_libs =[]):\n+ shared_libs = []\n+ for l in libs:\n+ p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n+ if p is not None: shared_libs.append(p)\n+ if len(shared_libs) == len(libs):\n+ info = {'extra_objects':shared_libs}\n+ opt_shared_libs = []\n+ for l in opt_libs:\n+ p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n+ if p is not None: opt_shared_libs.append(p)\n+ info['extra_objects'].extend(opt_shared_libs)\n+ return info\n+\n+\n class fftw_info(system_info):\n- pass\n+\n+ def __init__(self):\n+ system_info.__init__(self)\n+ p = os.environ.get('FFTW')\n+ if p is not None:\n+ p = os.path.abspath(p)\n+ if os.path.isdir(p):\n+ self.local_prefixes.insert(0,p)\n+\n+ def calc_info(self,prefix):\n+ lib_dirs = filter(os.path.isdir,\n+ combine_paths(prefix,'lib',['fftw*','FFTW*']))\n+ if not lib_dirs:\n+ lib_dirs = filter(os.path.isdir,\n+ combine_paths(prefix,['fftw*','FFTW*'],'lib'))\n+ if not lib_dirs:\n+ lib_dirs = filter(os.path.isdir,\n+ combine_paths(prefix,['lib','fftw*','FFTW*']))\n+ \n+ if not lib_dirs: return\n+ incl_dirs = filter(os.path.isdir,\n+ combine_paths(prefix,'include',['fftw*','FFTW*']))\n+ if not incl_dirs:\n+ incl_dirs = filter(os.path.isdir,\n+ combine_paths(prefix,['fftw*','FFTW*'],'include'))\n+ if not incl_dirs:\n+ incl_dirs = filter(os.path.isdir,\n+ combine_paths(prefix,['include','fftw*','FFTW*']))\n+ if not incl_dirs: return\n+ incl_dir = None\n+\n+ libs = ['fftw','rfftw']\n+ opt_libs = ['fftw_threads','rfftw_threads']\n+ info = None\n+ for d in lib_dirs:\n+ r = self.check_libs(d,libs,opt_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(combine_paths(d,['fftw.h','rfftw.h']))==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=('SCIPY_FFTW_H',1))\n+ else:\n+ info = None\n+\n+ if info is None:\n+ libs = ['dfftw','drfftw']\n+ opt_libs = ['dfftw_threads','drfftw_threads']\n+ for d in lib_dirs:\n+ r = self.check_libs(d,libs,opt_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(combine_paths(d,['dfftw.h','drfftw.h']))==2:\n+ if incl_dir is None:\n+ dict_append(info,include_dirs=[d])\n+ incl_dirs = [d]\n+ incl_dir = d\n+ flag = 1\n+ break\n+ if flag:\n+ dict_append(info,define_macros=('SCIPY_DFFTW_H',1))\n+ else:\n+ info = None\n+ \n+ libs = ['sfftw','srfftw']\n+ opt_libs = ['sfftw_threads','srfftw_threads']\n+ flag = 0\n+ for d in lib_dirs:\n+ r = self.check_libs(d,libs,opt_libs)\n+ if r is not None:\n+ if info is None: info = r\n+ else: dict_append(info,**r)\n+ flag = 1\n+ break\n+ if info is not None and flag:\n+ for d in incl_dirs:\n+ if len(combine_paths(d,['sfftw.h','srfftw.h']))==2:\n+ if incl_dir is None:\n+ dict_append(info,include_dirs=[d])\n+ dict_append(info,define_macros=('SCIPY_SFFTW_H',1))\n+ break\n+ if info is not None:\n+ self.set_info(**info)\n+\n \n class atlas_info(system_info):\n+\n+ def __init__(self):\n+ system_info.__init__(self)\n+ p = os.environ.get('ATLAS')\n+ if p is not None:\n+ p = os.path.abspath(p)\n+ if os.path.isdir(p):\n+ self.local_prefixes.insert(0,p)\n+\n+ def calc_info(self, prefix):\n+ lib_dirs = filter(os.path.isdir,combine_paths(prefix,'lib',\n+ ['atlas*','ATLAS*']))\n+ if lib_dirs:\n+ other_dirs = filter(os.path.isdir,combine_paths(lib_dirs,'*'))\n+ other_dirs.extend(filter(os.path.isdir,combine_paths(prefix,'lib')))\n+ lib_dirs.extend(other_dirs)\n+ else:\n+ lib_dirs = filter(os.path.isdir,\n+ combine_paths(prefix,['lib','atlas*','ATLAS*']))\n+ if not lib_dirs:\n+ lib_dirs = [prefix]\n+\n+ h = (combine_paths(lib_dirs,'cblas.h') or [None])[0]\n+ if not h:\n+ h = (combine_paths(lib_dirs,'include','cblas.h') or [None])[0]\n+ if h: h = os.path.dirname(h)\n+\n+ libs = ['lapack','f77blas','cblas','atlas']\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 None: return\n+ if h: dict_append(info,include_dirs=h)\n+ self.set_info(**info)\n+\n+\n+class blas_info(system_info):\n+ # For Fortran or optimized blas, not atlas.\n+ pass\n+\n+\n+class lapack_info(system_info):\n+ # For Fortran or optimized lapack, not atlas\n pass\n \n+\n class x11_info(system_info):\n \n def calc_info(self, prefix):\n@@ -49,17 +284,15 @@ def calc_info(self, prefix):\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n- info = {}\n- if combine_paths(lib_dir,'libX11.a'):\n- info['library_dirs'] = lib_dir\n- info['libraries'] = ['X11']\n- else:\n- shared_libs = combine_paths(lib_dir,'libX11.so*')\n- if not shared_libs: return\n- info['extra_link_args'] = [shared_libs[0]]\n- info['include_dirs'] = [inc_dir]\n- self.info = info\n- return 1\n+ info = self.check_libs(lib_dir[0],['X11'],[])\n+ if info is None:\n+ continue\n+ dict_append(info,include_dirs=[inc_dir])\n+ self.set_info(**info)\n+\n+def shortest_path(pths):\n+ pths.sort()\n+ if pths: return pths[0]\n \n def combine_paths(*args):\n \"\"\" Return a list of existing paths composed by all combinations of\n@@ -73,23 +306,32 @@ def combine_paths(*args):\n r.append(a)\n args = r\n if not args: return []\n- if len (args)==1: return map(glob,args[0])\n+ if len (args)==1:\n+ return [r for r in map(glob,args[0]) if r]\n if 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 return result\n- return combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n+ result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n+ return result\n+\n+def 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 \n def 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=='system_info': continue\n c = getattr(system_info,n)()\n- print '------------>',n\n- print c.get_info()\n+ r = c.get_info()\n \n if __name__ == \"__main__\":\n show_all()\n", + "added_lines": 271, + "deleted_lines": 29, + "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 fftw_info\n x11_info\nThe following environment variables are used if defined:\n ATLAS - path to ATLAS library\n FFTW - path to FFTW library\n\nUsage:\n For example,\n info = atlas_info().get_info()\n info will be a dictionary that is compatible with distutils.setup keyword\n arguments. If info == {}, then the asked resource is not available.\n\nGlobal parameters:\n prefixes - a list of prefixes for scanning the location of\n resources.\n system_info.static_first - a flag for indicating that static\n libraries are searched first than shared ones.\n system_info.verbose - show the results if set.\n\nAuthor:\n Pearu Peterson , February 2002\nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re,types,pprint\nfrom glob import glob\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n prefixes = ['C:'] # XXX: what is prefix in win32?\nelse:\n prefixes = ['/usr','/usr/local','/opt']\nif sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\nprefixes = filter(os.path.isdir,prefixes) # XXX: Is this ok on win32? Is 'C:' dir?\n\nso_ext = get_config_vars('SO')[0] or ''\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n\n static_first = 1\n verbose = 1\n\n def __init__ (self):\n self.__class__.info = {}\n self.need_refresh = not self.info\n self.local_prefixes = []\n\n def set_info(self,**info):\n self.__class__.info = info\n\n def get_info(self):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n if self.need_refresh:\n if self.verbose:\n print self.__class__.__name__ + ':'\n for p in self.local_prefixes + prefixes:\n if self.verbose:\n print ' Looking in',p,'...'\n self.calc_info(p)\n if self.info: break\n self.need_refresh = 0\n if self.verbose:\n if not self.info:\n print ' NOT AVAILABLE'\n else:\n print ' FOUND:'\n for k,v in self.info.items():\n print ' %s = %s'%(k,v)\n print\n return self.info\n\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\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 mths = [self.check_static_libs,self.check_shared_libs]\n if not self.static_first:\n mths.reverse() # if one prefers shared libraries\n for m in mths:\n info = m(lib_dir,libs,opt_libs)\n if info is not None: return info\n\n def check_static_libs(self,lib_dir,libs,opt_libs =[]):\n #XXX: what are .lib and .dll files under win32?\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs])) == len(libs):\n info = {'libraries':libs,'library_dirs':[lib_dir]}\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs]))\\\n ==len(opt_libs):\n info['libraries'].extend(opt_libs)\n return info\n\n def check_shared_libs(self,lib_dir,libs,opt_libs =[]):\n shared_libs = []\n for l in libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: shared_libs.append(p)\n if len(shared_libs) == len(libs):\n info = {'extra_objects':shared_libs}\n opt_shared_libs = []\n for l in opt_libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: opt_shared_libs.append(p)\n info['extra_objects'].extend(opt_shared_libs)\n return info\n\n\nclass fftw_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('FFTW')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self,prefix):\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,'lib',['fftw*','FFTW*']))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'lib'))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','fftw*','FFTW*']))\n \n if not lib_dirs: return\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,'include',['fftw*','FFTW*']))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'include'))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['include','fftw*','FFTW*']))\n if not incl_dirs: return\n incl_dir = None\n\n libs = ['fftw','rfftw']\n opt_libs = ['fftw_threads','rfftw_threads']\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['fftw.h','rfftw.h']))==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=('SCIPY_FFTW_H',1))\n else:\n info = None\n\n if info is None:\n libs = ['dfftw','drfftw']\n opt_libs = ['dfftw_threads','drfftw_threads']\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['dfftw.h','drfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n incl_dirs = [d]\n incl_dir = d\n flag = 1\n break\n if flag:\n dict_append(info,define_macros=('SCIPY_DFFTW_H',1))\n else:\n info = None\n \n libs = ['sfftw','srfftw']\n opt_libs = ['sfftw_threads','srfftw_threads']\n flag = 0\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_libs)\n if r is not None:\n if info is None: info = r\n else: dict_append(info,**r)\n flag = 1\n break\n if info is not None and flag:\n for d in incl_dirs:\n if len(combine_paths(d,['sfftw.h','srfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n dict_append(info,define_macros=('SCIPY_SFFTW_H',1))\n break\n if info is not None:\n self.set_info(**info)\n\n\nclass atlas_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('ATLAS')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self, prefix):\n lib_dirs = filter(os.path.isdir,combine_paths(prefix,'lib',\n ['atlas*','ATLAS*']))\n if lib_dirs:\n other_dirs = filter(os.path.isdir,combine_paths(lib_dirs,'*'))\n other_dirs.extend(filter(os.path.isdir,combine_paths(prefix,'lib')))\n lib_dirs.extend(other_dirs)\n else:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','atlas*','ATLAS*']))\n if not lib_dirs:\n lib_dirs = [prefix]\n\n h = (combine_paths(lib_dirs,'cblas.h') or [None])[0]\n if not h:\n h = (combine_paths(lib_dirs,'include','cblas.h') or [None])[0]\n if h: h = os.path.dirname(h)\n\n libs = ['lapack','f77blas','cblas','atlas']\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 None: return\n if h: dict_append(info,include_dirs=h)\n self.set_info(**info)\n\n\nclass blas_info(system_info):\n # For Fortran or optimized blas, not atlas.\n pass\n\n\nclass lapack_info(system_info):\n # For Fortran or optimized lapack, not atlas\n pass\n\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = self.check_libs(lib_dir[0],['X11'],[])\n if info is None:\n continue\n dict_append(info,include_dirs=[inc_dir])\n self.set_info(**info)\n\ndef shortest_path(pths):\n pths.sort()\n if pths: return pths[0]\n\ndef combine_paths(*args):\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 return [r for r in map(glob,args[0]) if r]\n if 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 return result\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\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 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=='system_info': continue\n c = getattr(system_info,n)()\n r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n", + "source_code_before": "#!/usr/bin/env python\n\nimport sys,os,re,types\nfrom glob import glob\n\nclass system_info:\n\n if sys.platform == 'win32':\n prefixes = [] # XXX: what is prefix in win32? C: maybe?\n else:\n prefixes = ['/usr','/usr/local','/opt']\n if sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\n prefixes = filter(os.path.isdir,prefixes)\n\n def __init__ (self):\n self.info = {}\n self.need_refresh = 1\n def get_info(self):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n if self.need_refresh:\n for p in self.prefixes:\n r = self.calc_info(p)\n if r: break\n self.need_refresh = 0\n return self.info\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\n\nclass fftw_info(system_info):\n pass\n\nclass atlas_info(system_info):\n pass\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = {}\n if combine_paths(lib_dir,'libX11.a'):\n info['library_dirs'] = lib_dir\n info['libraries'] = ['X11']\n else:\n shared_libs = combine_paths(lib_dir,'libX11.so*')\n if not shared_libs: return\n info['extra_link_args'] = [shared_libs[0]]\n info['include_dirs'] = [inc_dir]\n self.info = info\n return 1\n\ndef combine_paths(*args):\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: return map(glob,args[0])\n if 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 return result\n return combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n\ndef show_all():\n import system_info\n match_info = re.compile(r'.*?_info').match\n for n in filter(match_info,dir(system_info)):\n if n=='system_info': continue\n c = getattr(system_info,n)()\n print '------------>',n\n print c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n", + "methods": [ + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self" + ], + "start_line": 57, + "end_line": 60, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "set_info", + "long_name": "set_info( self , ** info )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "info" + ], + "start_line": 62, + "end_line": 63, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 9, + "token_count": 104, + "parameters": [ + "self" + ], + "start_line": 65, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 88, + "end_line": 89, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 60, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 91, + "end_line": 99, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_static_libs", + "long_name": "check_static_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 5, + "token_count": 91, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 101, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_shared_libs", + "long_name": "check_shared_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 13, + "complexity": 6, + "token_count": 119, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 110, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 127, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 82, + "complexity": 30, + "token_count": 547, + "parameters": [ + "self", + "prefix" + ], + "start_line": 135, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 225, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 11, + "token_count": 229, + "parameters": [ + "self", + "prefix" + ], + "start_line": 233, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "prefix" + ], + "start_line": 275, + "end_line": 291, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "shortest_path", + "long_name": "shortest_path( pths )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "pths" + ], + "start_line": 293, + "end_line": 295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 11, + "token_count": 154, + "parameters": [ + "args" + ], + "start_line": 297, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 320, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 55, + "parameters": [], + "start_line": 327, + "end_line": 334, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 16, + "end_line": 18, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 39, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 28, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 29, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 9, + "token_count": 143, + "parameters": [ + "self", + "prefix" + ], + "start_line": 40, + "end_line": 62, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 9, + "token_count": 143, + "parameters": [ + "args" + ], + "start_line": 64, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 56, + "parameters": [], + "start_line": 85, + "end_line": 92, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "shortest_path", + "long_name": "shortest_path( pths )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "pths" + ], + "start_line": 293, + "end_line": 295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 55, + "parameters": [], + "start_line": 327, + "end_line": 334, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "check_static_libs", + "long_name": "check_static_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 5, + "token_count": 91, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 101, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "set_info", + "long_name": "set_info( self , ** info )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "info" + ], + "start_line": 62, + "end_line": 63, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 320, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self" + ], + "start_line": 57, + "end_line": 60, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 11, + "token_count": 154, + "parameters": [ + "args" + ], + "start_line": 297, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 9, + "token_count": 104, + "parameters": [ + "self" + ], + "start_line": 65, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 82, + "complexity": 30, + "token_count": 547, + "parameters": [ + "self", + "prefix" + ], + "start_line": 135, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "top_nesting_level": 1 + }, + { + "name": "check_shared_libs", + "long_name": "check_shared_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 13, + "complexity": 6, + "token_count": 119, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 110, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 60, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 91, + "end_line": 99, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + } + ], + "nloc": 284, + "complexity": 101, + "token_count": 1851, + "diff_parsed": { + "added": [ + "\"\"\"", + "This file defines a set of system_info classes for getting", + "information about various resources (libraries, library directories,", + "include directories, etc.) in the system. Currently, the following", + "classes are available:", + " atlas_info", + " fftw_info", + " x11_info", + "The following environment variables are used if defined:", + " ATLAS - path to ATLAS library", + " FFTW - path to FFTW library", + "Usage:", + " For example,", + " info = atlas_info().get_info()", + " info will be a dictionary that is compatible with distutils.setup keyword", + " arguments. If info == {}, then the asked resource is not available.", + "", + "Global parameters:", + " prefixes - a list of prefixes for scanning the location of", + " resources.", + " system_info.static_first - a flag for indicating that static", + " libraries are searched first than shared ones.", + " system_info.verbose - show the results if set.", + "", + "Author:", + " Pearu Peterson , February 2002", + "Permission to use, modify, and distribute this software is given under the", + "terms of the LGPL. See http://www.fsf.org", + "NO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.", + "\"\"\"", + "", + "import sys,os,re,types,pprint", + "from distutils.sysconfig import get_config_vars", + "", + "if sys.platform == 'win32':", + " prefixes = ['C:'] # XXX: what is prefix in win32?", + "else:", + " prefixes = ['/usr','/usr/local','/opt']", + "if sys.prefix not in prefixes:", + " prefixes.append(sys.prefix)", + "prefixes = filter(os.path.isdir,prefixes) # XXX: Is this ok on win32? Is 'C:' dir?", + "", + "so_ext = get_config_vars('SO')[0] or ''", + "", + " \"\"\" get_info() is the only public method. Don't use others.", + " \"\"\"", + "", + " static_first = 1", + " verbose = 1", + " self.__class__.info = {}", + " self.need_refresh = not self.info", + " self.local_prefixes = []", + "", + " def set_info(self,**info):", + " self.__class__.info = info", + "", + " if self.verbose:", + " print self.__class__.__name__ + ':'", + " for p in self.local_prefixes + prefixes:", + " if self.verbose:", + " print ' Looking in',p,'...'", + " self.calc_info(p)", + " if self.info: break", + " if self.verbose:", + " if not self.info:", + " print ' NOT AVAILABLE'", + " else:", + " print ' FOUND:'", + " for k,v in self.info.items():", + " print ' %s = %s'%(k,v)", + " print", + "", + " def check_libs(self,lib_dir,libs,opt_libs =[]):", + " \"\"\" If static or shared libraries are available then return", + " their info dictionary. \"\"\"", + " mths = [self.check_static_libs,self.check_shared_libs]", + " if not self.static_first:", + " mths.reverse() # if one prefers shared libraries", + " for m in mths:", + " info = m(lib_dir,libs,opt_libs)", + " if info is not None: return info", + "", + " def check_static_libs(self,lib_dir,libs,opt_libs =[]):", + " #XXX: what are .lib and .dll files under win32?", + " if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs])) == len(libs):", + " info = {'libraries':libs,'library_dirs':[lib_dir]}", + " if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs]))\\", + " ==len(opt_libs):", + " info['libraries'].extend(opt_libs)", + " return info", + "", + " def check_shared_libs(self,lib_dir,libs,opt_libs =[]):", + " shared_libs = []", + " for l in libs:", + " p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))", + " if p is not None: shared_libs.append(p)", + " if len(shared_libs) == len(libs):", + " info = {'extra_objects':shared_libs}", + " opt_shared_libs = []", + " for l in opt_libs:", + " p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))", + " if p is not None: opt_shared_libs.append(p)", + " info['extra_objects'].extend(opt_shared_libs)", + " return info", + "", + "", + "", + " def __init__(self):", + " system_info.__init__(self)", + " p = os.environ.get('FFTW')", + " if p is not None:", + " p = os.path.abspath(p)", + " if os.path.isdir(p):", + " self.local_prefixes.insert(0,p)", + "", + " def calc_info(self,prefix):", + " lib_dirs = filter(os.path.isdir,", + " combine_paths(prefix,'lib',['fftw*','FFTW*']))", + " if not lib_dirs:", + " lib_dirs = filter(os.path.isdir,", + " combine_paths(prefix,['fftw*','FFTW*'],'lib'))", + " if not lib_dirs:", + " lib_dirs = filter(os.path.isdir,", + " combine_paths(prefix,['lib','fftw*','FFTW*']))", + "", + " if not lib_dirs: return", + " incl_dirs = filter(os.path.isdir,", + " combine_paths(prefix,'include',['fftw*','FFTW*']))", + " if not incl_dirs:", + " incl_dirs = filter(os.path.isdir,", + " combine_paths(prefix,['fftw*','FFTW*'],'include'))", + " if not incl_dirs:", + " incl_dirs = filter(os.path.isdir,", + " combine_paths(prefix,['include','fftw*','FFTW*']))", + " if not incl_dirs: return", + " incl_dir = None", + "", + " libs = ['fftw','rfftw']", + " opt_libs = ['fftw_threads','rfftw_threads']", + " info = None", + " for d in lib_dirs:", + " r = self.check_libs(d,libs,opt_libs)", + " if r is not None:", + " info = r", + " break", + " if info is not None:", + " flag = 0", + " for d in incl_dirs:", + " if len(combine_paths(d,['fftw.h','rfftw.h']))==2:", + " dict_append(info,include_dirs=[d])", + " flag = 1", + " incl_dirs = [d]", + " incl_dir = d", + " break", + " if flag:", + " dict_append(info,define_macros=('SCIPY_FFTW_H',1))", + " else:", + " info = None", + "", + " if info is None:", + " libs = ['dfftw','drfftw']", + " opt_libs = ['dfftw_threads','drfftw_threads']", + " for d in lib_dirs:", + " r = self.check_libs(d,libs,opt_libs)", + " if r is not None:", + " info = r", + " break", + " if info is not None:", + " flag = 0", + " for d in incl_dirs:", + " if len(combine_paths(d,['dfftw.h','drfftw.h']))==2:", + " if incl_dir is None:", + " dict_append(info,include_dirs=[d])", + " incl_dirs = [d]", + " incl_dir = d", + " flag = 1", + " break", + " if flag:", + " dict_append(info,define_macros=('SCIPY_DFFTW_H',1))", + " else:", + " info = None", + "", + " libs = ['sfftw','srfftw']", + " opt_libs = ['sfftw_threads','srfftw_threads']", + " flag = 0", + " for d in lib_dirs:", + " r = self.check_libs(d,libs,opt_libs)", + " if r is not None:", + " if info is None: info = r", + " else: dict_append(info,**r)", + " flag = 1", + " break", + " if info is not None and flag:", + " for d in incl_dirs:", + " if len(combine_paths(d,['sfftw.h','srfftw.h']))==2:", + " if incl_dir is None:", + " dict_append(info,include_dirs=[d])", + " dict_append(info,define_macros=('SCIPY_SFFTW_H',1))", + " break", + " if info is not None:", + " self.set_info(**info)", + "", + "", + " def __init__(self):", + " system_info.__init__(self)", + " p = os.environ.get('ATLAS')", + " if p is not None:", + " p = os.path.abspath(p)", + " if os.path.isdir(p):", + " self.local_prefixes.insert(0,p)", + "", + " def calc_info(self, prefix):", + " lib_dirs = filter(os.path.isdir,combine_paths(prefix,'lib',", + " ['atlas*','ATLAS*']))", + " if lib_dirs:", + " other_dirs = filter(os.path.isdir,combine_paths(lib_dirs,'*'))", + " other_dirs.extend(filter(os.path.isdir,combine_paths(prefix,'lib')))", + " lib_dirs.extend(other_dirs)", + " else:", + " lib_dirs = filter(os.path.isdir,", + " combine_paths(prefix,['lib','atlas*','ATLAS*']))", + " if not lib_dirs:", + " lib_dirs = [prefix]", + "", + " h = (combine_paths(lib_dirs,'cblas.h') or [None])[0]", + " if not h:", + " h = (combine_paths(lib_dirs,'include','cblas.h') or [None])[0]", + " if h: h = os.path.dirname(h)", + "", + " libs = ['lapack','f77blas','cblas','atlas']", + " info = None", + " for d in lib_dirs:", + " r = self.check_libs(d,libs,[])", + " if r is not None:", + " info = r", + " break", + " if info is None: return", + " if h: dict_append(info,include_dirs=h)", + " self.set_info(**info)", + "", + "", + "class blas_info(system_info):", + " # For Fortran or optimized blas, not atlas.", + " pass", + "", + "", + "class lapack_info(system_info):", + " # For Fortran or optimized lapack, not atlas", + "", + " info = self.check_libs(lib_dir[0],['X11'],[])", + " if info is None:", + " continue", + " dict_append(info,include_dirs=[inc_dir])", + " self.set_info(**info)", + "", + "def shortest_path(pths):", + " pths.sort()", + " if pths: return pths[0]", + " if len (args)==1:", + " return [r for r in map(glob,args[0]) if r]", + " result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))", + " return result", + "", + "def dict_append(d,**kws):", + " for k,v in kws.items():", + " if d.has_key(k):", + " d[k].extend(v)", + " else:", + " d[k] = v", + " import pprint", + " r = c.get_info()" + ], + "deleted": [ + "import sys,os,re,types", + " if sys.platform == 'win32':", + " prefixes = [] # XXX: what is prefix in win32? C: maybe?", + " else:", + " prefixes = ['/usr','/usr/local','/opt']", + " if sys.prefix not in prefixes:", + " prefixes.append(sys.prefix)", + " prefixes = filter(os.path.isdir,prefixes)", + " self.info = {}", + " self.need_refresh = 1", + " for p in self.prefixes:", + " r = self.calc_info(p)", + " if r: break", + " pass", + " info = {}", + " if combine_paths(lib_dir,'libX11.a'):", + " info['library_dirs'] = lib_dir", + " info['libraries'] = ['X11']", + " else:", + " shared_libs = combine_paths(lib_dir,'libX11.so*')", + " if not shared_libs: return", + " info['extra_link_args'] = [shared_libs[0]]", + " info['include_dirs'] = [inc_dir]", + " self.info = info", + " return 1", + " if len (args)==1: return map(glob,args[0])", + " return combine_paths(*(combine_paths(args[0],args[1])+args[2:]))", + " print '------------>',n", + " print c.get_info()" + ] + } + } + ] + }, + { + "hash": "06a9f21379b2631f3e5fd182ea2af524fedbdf28", + "msg": "Fixed bugs, introduced get_info function", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-02-22T15:47:33+00:00", + "author_timezone": 0, + "committer_date": "2002-02-22T15:47:33+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "0ae7d411b836a5cbd3de7d0e703911660ac16b9a" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 25, + "insertions": 41, + "lines": 66, + "files": 1, + "dmm_unit_size": 0.6, + "dmm_unit_complexity": 0.6, + "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": "@@ -12,10 +12,12 @@\n FFTW - path to FFTW library\n \n Usage:\n- For example,\n- info = atlas_info().get_info()\n- info will be a dictionary that is compatible with distutils.setup keyword\n- arguments. If info == {}, then the asked resource is not available.\n+ info_dict = get_info()\n+ where is a string 'atlas','x11','fftw'.\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 (or system_info could not find it).\n \n Global parameters:\n prefixes - a list of prefixes for scanning the location of\n@@ -46,6 +48,12 @@\n \n so_ext = get_config_vars('SO')[0] or ''\n \n+def get_info(name):\n+ cl = {'atlas':atlas_info,\n+ 'x11':x11_info,\n+ 'fftw':fftw_info}.get(name.lower(),system_info)\n+ return cl().get_info()\n+\n class system_info:\n \n \"\"\" get_info() is the only public method. Don't use others.\n@@ -53,37 +61,45 @@ class system_info:\n \n static_first = 1\n verbose = 1\n-\n+ need_refresh = 1\n+ saved_results = {}\n+ \n def __init__ (self):\n self.__class__.info = {}\n- self.need_refresh = not self.info\n+ #self.__class__.need_refresh = not self.info\n self.local_prefixes = []\n \n def set_info(self,**info):\n- self.__class__.info = info\n-\n+ #self.__class__.info = info\n+ self.saved_results[self.__class__.__name__] = info\n+ def has_info(self):\n+ return self.saved_results.has_key(self.__class__.__name__)\n def get_info(self):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n- if self.need_refresh:\n+ flag = 0\n+ if not self.has_info():\n+ flag = 1\n if self.verbose:\n print self.__class__.__name__ + ':'\n for p in self.local_prefixes + prefixes:\n if self.verbose:\n print ' Looking in',p,'...'\n self.calc_info(p)\n- if self.info: break\n- self.need_refresh = 0\n+ if self.has_info(): break\n if self.verbose:\n- if not self.info:\n+ if not self.has_info():\n print ' NOT AVAILABLE'\n+ self.set_info()\n else:\n print ' FOUND:'\n- for k,v in self.info.items():\n- print ' %s = %s'%(k,v)\n- print\n- return self.info\n+ res = self.saved_results.get(self.__class__.__name__)\n+ if self.verbose and flag:\n+ for k,v in res.items():\n+ print ' %s = %s'%(k,v)\n+ print\n+ return res\n \n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\n@@ -172,7 +188,7 @@ def calc_info(self,prefix):\n incl_dir = d\n break\n if flag:\n- dict_append(info,define_macros=('SCIPY_FFTW_H',1))\n+ dict_append(info,define_macros=[('SCIPY_FFTW_H',1)])\n else:\n info = None\n \n@@ -195,7 +211,7 @@ def calc_info(self,prefix):\n flag = 1\n break\n if flag:\n- dict_append(info,define_macros=('SCIPY_DFFTW_H',1))\n+ dict_append(info,define_macros=[('SCIPY_DFFTW_H',1)])\n else:\n info = None\n \n@@ -214,7 +230,7 @@ def calc_info(self,prefix):\n if len(combine_paths(d,['sfftw.h','srfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n- dict_append(info,define_macros=('SCIPY_SFFTW_H',1))\n+ dict_append(info,define_macros=[('SCIPY_SFFTW_H',1)])\n break\n if info is not None:\n self.set_info(**info)\n@@ -306,15 +322,15 @@ def combine_paths(*args):\n r.append(a)\n args = r\n if not args: return []\n- if len (args)==1:\n- return [r for r in map(glob,args[0]) if r]\n- if len (args)==2:\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- return result\n- result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n+ else:\n+ result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\n return result\n \n def dict_append(d,**kws):\n@@ -329,7 +345,7 @@ def show_all():\n import pprint\n match_info = re.compile(r'.*?_info').match\n for n in filter(match_info,dir(system_info)):\n- if n=='system_info': continue\n+ if n in ['system_info','get_info']: continue\n c = getattr(system_info,n)()\n r = c.get_info()\n \n", + "added_lines": 41, + "deleted_lines": 25, + "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 fftw_info\n x11_info\nThe following environment variables are used if defined:\n ATLAS - path to ATLAS library\n FFTW - path to FFTW library\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw'.\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 (or system_info could not find it).\n\nGlobal parameters:\n prefixes - a list of prefixes for scanning the location of\n resources.\n system_info.static_first - a flag for indicating that static\n libraries are searched first than shared ones.\n system_info.verbose - show the results if set.\n\nAuthor:\n Pearu Peterson , February 2002\nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re,types,pprint\nfrom glob import glob\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n prefixes = ['C:'] # XXX: what is prefix in win32?\nelse:\n prefixes = ['/usr','/usr/local','/opt']\nif sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\nprefixes = filter(os.path.isdir,prefixes) # XXX: Is this ok on win32? Is 'C:' dir?\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name):\n cl = {'atlas':atlas_info,\n 'x11':x11_info,\n 'fftw':fftw_info}.get(name.lower(),system_info)\n return cl().get_info()\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n\n static_first = 1\n verbose = 1\n need_refresh = 1\n saved_results = {}\n \n def __init__ (self):\n self.__class__.info = {}\n #self.__class__.need_refresh = not self.info\n self.local_prefixes = []\n\n def set_info(self,**info):\n #self.__class__.info = info\n self.saved_results[self.__class__.__name__] = info\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n def get_info(self):\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.verbose:\n print self.__class__.__name__ + ':'\n for p in self.local_prefixes + prefixes:\n if self.verbose:\n print ' Looking in',p,'...'\n self.calc_info(p)\n if self.has_info(): break\n if self.verbose:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbose and flag:\n for k,v in res.items():\n print ' %s = %s'%(k,v)\n print\n return res\n\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\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 mths = [self.check_static_libs,self.check_shared_libs]\n if not self.static_first:\n mths.reverse() # if one prefers shared libraries\n for m in mths:\n info = m(lib_dir,libs,opt_libs)\n if info is not None: return info\n\n def check_static_libs(self,lib_dir,libs,opt_libs =[]):\n #XXX: what are .lib and .dll files under win32?\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs])) == len(libs):\n info = {'libraries':libs,'library_dirs':[lib_dir]}\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs]))\\\n ==len(opt_libs):\n info['libraries'].extend(opt_libs)\n return info\n\n def check_shared_libs(self,lib_dir,libs,opt_libs =[]):\n shared_libs = []\n for l in libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: shared_libs.append(p)\n if len(shared_libs) == len(libs):\n info = {'extra_objects':shared_libs}\n opt_shared_libs = []\n for l in opt_libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: opt_shared_libs.append(p)\n info['extra_objects'].extend(opt_shared_libs)\n return info\n\n\nclass fftw_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('FFTW')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self,prefix):\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,'lib',['fftw*','FFTW*']))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'lib'))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','fftw*','FFTW*']))\n \n if not lib_dirs: return\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,'include',['fftw*','FFTW*']))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'include'))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['include','fftw*','FFTW*']))\n if not incl_dirs: return\n incl_dir = None\n\n libs = ['fftw','rfftw']\n opt_libs = ['fftw_threads','rfftw_threads']\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['fftw.h','rfftw.h']))==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=[('SCIPY_FFTW_H',1)])\n else:\n info = None\n\n if info is None:\n libs = ['dfftw','drfftw']\n opt_libs = ['dfftw_threads','drfftw_threads']\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['dfftw.h','drfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n incl_dirs = [d]\n incl_dir = d\n flag = 1\n break\n if flag:\n dict_append(info,define_macros=[('SCIPY_DFFTW_H',1)])\n else:\n info = None\n \n libs = ['sfftw','srfftw']\n opt_libs = ['sfftw_threads','srfftw_threads']\n flag = 0\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_libs)\n if r is not None:\n if info is None: info = r\n else: dict_append(info,**r)\n flag = 1\n break\n if info is not None and flag:\n for d in incl_dirs:\n if len(combine_paths(d,['sfftw.h','srfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n dict_append(info,define_macros=[('SCIPY_SFFTW_H',1)])\n break\n if info is not None:\n self.set_info(**info)\n\n\nclass atlas_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('ATLAS')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self, prefix):\n lib_dirs = filter(os.path.isdir,combine_paths(prefix,'lib',\n ['atlas*','ATLAS*']))\n if lib_dirs:\n other_dirs = filter(os.path.isdir,combine_paths(lib_dirs,'*'))\n other_dirs.extend(filter(os.path.isdir,combine_paths(prefix,'lib')))\n lib_dirs.extend(other_dirs)\n else:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','atlas*','ATLAS*']))\n if not lib_dirs:\n lib_dirs = [prefix]\n\n h = (combine_paths(lib_dirs,'cblas.h') or [None])[0]\n if not h:\n h = (combine_paths(lib_dirs,'include','cblas.h') or [None])[0]\n if h: h = os.path.dirname(h)\n\n libs = ['lapack','f77blas','cblas','atlas']\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 None: return\n if h: dict_append(info,include_dirs=h)\n self.set_info(**info)\n\n\nclass blas_info(system_info):\n # For Fortran or optimized blas, not atlas.\n pass\n\n\nclass lapack_info(system_info):\n # For Fortran or optimized lapack, not atlas\n pass\n\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = self.check_libs(lib_dir[0],['X11'],[])\n if info is None:\n continue\n dict_append(info,include_dirs=[inc_dir])\n self.set_info(**info)\n\ndef shortest_path(pths):\n pths.sort()\n if pths: return pths[0]\n\ndef combine_paths(*args):\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 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 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 r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\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 fftw_info\n x11_info\nThe following environment variables are used if defined:\n ATLAS - path to ATLAS library\n FFTW - path to FFTW library\n\nUsage:\n For example,\n info = atlas_info().get_info()\n info will be a dictionary that is compatible with distutils.setup keyword\n arguments. If info == {}, then the asked resource is not available.\n\nGlobal parameters:\n prefixes - a list of prefixes for scanning the location of\n resources.\n system_info.static_first - a flag for indicating that static\n libraries are searched first than shared ones.\n system_info.verbose - show the results if set.\n\nAuthor:\n Pearu Peterson , February 2002\nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re,types,pprint\nfrom glob import glob\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n prefixes = ['C:'] # XXX: what is prefix in win32?\nelse:\n prefixes = ['/usr','/usr/local','/opt']\nif sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\nprefixes = filter(os.path.isdir,prefixes) # XXX: Is this ok on win32? Is 'C:' dir?\n\nso_ext = get_config_vars('SO')[0] or ''\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n\n static_first = 1\n verbose = 1\n\n def __init__ (self):\n self.__class__.info = {}\n self.need_refresh = not self.info\n self.local_prefixes = []\n\n def set_info(self,**info):\n self.__class__.info = info\n\n def get_info(self):\n \"\"\" Return a dictonary with items that are compatible\n with scipy_distutils.setup keyword arguments.\n \"\"\"\n if self.need_refresh:\n if self.verbose:\n print self.__class__.__name__ + ':'\n for p in self.local_prefixes + prefixes:\n if self.verbose:\n print ' Looking in',p,'...'\n self.calc_info(p)\n if self.info: break\n self.need_refresh = 0\n if self.verbose:\n if not self.info:\n print ' NOT AVAILABLE'\n else:\n print ' FOUND:'\n for k,v in self.info.items():\n print ' %s = %s'%(k,v)\n print\n return self.info\n\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\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 mths = [self.check_static_libs,self.check_shared_libs]\n if not self.static_first:\n mths.reverse() # if one prefers shared libraries\n for m in mths:\n info = m(lib_dir,libs,opt_libs)\n if info is not None: return info\n\n def check_static_libs(self,lib_dir,libs,opt_libs =[]):\n #XXX: what are .lib and .dll files under win32?\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs])) == len(libs):\n info = {'libraries':libs,'library_dirs':[lib_dir]}\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs]))\\\n ==len(opt_libs):\n info['libraries'].extend(opt_libs)\n return info\n\n def check_shared_libs(self,lib_dir,libs,opt_libs =[]):\n shared_libs = []\n for l in libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: shared_libs.append(p)\n if len(shared_libs) == len(libs):\n info = {'extra_objects':shared_libs}\n opt_shared_libs = []\n for l in opt_libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: opt_shared_libs.append(p)\n info['extra_objects'].extend(opt_shared_libs)\n return info\n\n\nclass fftw_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('FFTW')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self,prefix):\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,'lib',['fftw*','FFTW*']))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'lib'))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','fftw*','FFTW*']))\n \n if not lib_dirs: return\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,'include',['fftw*','FFTW*']))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'include'))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['include','fftw*','FFTW*']))\n if not incl_dirs: return\n incl_dir = None\n\n libs = ['fftw','rfftw']\n opt_libs = ['fftw_threads','rfftw_threads']\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['fftw.h','rfftw.h']))==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=('SCIPY_FFTW_H',1))\n else:\n info = None\n\n if info is None:\n libs = ['dfftw','drfftw']\n opt_libs = ['dfftw_threads','drfftw_threads']\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['dfftw.h','drfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n incl_dirs = [d]\n incl_dir = d\n flag = 1\n break\n if flag:\n dict_append(info,define_macros=('SCIPY_DFFTW_H',1))\n else:\n info = None\n \n libs = ['sfftw','srfftw']\n opt_libs = ['sfftw_threads','srfftw_threads']\n flag = 0\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_libs)\n if r is not None:\n if info is None: info = r\n else: dict_append(info,**r)\n flag = 1\n break\n if info is not None and flag:\n for d in incl_dirs:\n if len(combine_paths(d,['sfftw.h','srfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n dict_append(info,define_macros=('SCIPY_SFFTW_H',1))\n break\n if info is not None:\n self.set_info(**info)\n\n\nclass atlas_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('ATLAS')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self, prefix):\n lib_dirs = filter(os.path.isdir,combine_paths(prefix,'lib',\n ['atlas*','ATLAS*']))\n if lib_dirs:\n other_dirs = filter(os.path.isdir,combine_paths(lib_dirs,'*'))\n other_dirs.extend(filter(os.path.isdir,combine_paths(prefix,'lib')))\n lib_dirs.extend(other_dirs)\n else:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','atlas*','ATLAS*']))\n if not lib_dirs:\n lib_dirs = [prefix]\n\n h = (combine_paths(lib_dirs,'cblas.h') or [None])[0]\n if not h:\n h = (combine_paths(lib_dirs,'include','cblas.h') or [None])[0]\n if h: h = os.path.dirname(h)\n\n libs = ['lapack','f77blas','cblas','atlas']\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 None: return\n if h: dict_append(info,include_dirs=h)\n self.set_info(**info)\n\n\nclass blas_info(system_info):\n # For Fortran or optimized blas, not atlas.\n pass\n\n\nclass lapack_info(system_info):\n # For Fortran or optimized lapack, not atlas\n pass\n\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = self.check_libs(lib_dir[0],['X11'],[])\n if info is None:\n continue\n dict_append(info,include_dirs=[inc_dir])\n self.set_info(**info)\n\ndef shortest_path(pths):\n pths.sort()\n if pths: return pths[0]\n\ndef combine_paths(*args):\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 return [r for r in map(glob,args[0]) if r]\n if 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 return result\n result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))\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 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=='system_info': continue\n c = getattr(system_info,n)()\n r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n", + "methods": [ + { + "name": "get_info", + "long_name": "get_info( name )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 1, + "token_count": 39, + "parameters": [ + "name" + ], + "start_line": 51, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 67, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "set_info", + "long_name": "set_info( self , ** info )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "info" + ], + "start_line": 72, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "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": 75, + "end_line": 76, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 11, + "token_count": 134, + "parameters": [ + "self" + ], + "start_line": 77, + "end_line": 102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 104, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 60, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 107, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_static_libs", + "long_name": "check_static_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 5, + "token_count": 91, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 117, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_shared_libs", + "long_name": "check_shared_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 13, + "complexity": 6, + "token_count": 119, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 126, + "end_line": 138, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 143, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 82, + "complexity": 30, + "token_count": 553, + "parameters": [ + "self", + "prefix" + ], + "start_line": 151, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 241, + "end_line": 247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 11, + "token_count": 229, + "parameters": [ + "self", + "prefix" + ], + "start_line": 249, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "prefix" + ], + "start_line": 291, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "shortest_path", + "long_name": "shortest_path( pths )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "pths" + ], + "start_line": 309, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 9, + "token_count": 162, + "parameters": [ + "args" + ], + "start_line": 313, + "end_line": 334, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 336, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [], + "start_line": 343, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 4, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self" + ], + "start_line": 57, + "end_line": 60, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "set_info", + "long_name": "set_info( self , ** info )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 15, + "parameters": [ + "self", + "info" + ], + "start_line": 62, + "end_line": 63, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 9, + "token_count": 104, + "parameters": [ + "self" + ], + "start_line": 65, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 88, + "end_line": 89, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 60, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 91, + "end_line": 99, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_static_libs", + "long_name": "check_static_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 5, + "token_count": 91, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 101, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_shared_libs", + "long_name": "check_shared_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 13, + "complexity": 6, + "token_count": 119, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 110, + "end_line": 122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 127, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 82, + "complexity": 30, + "token_count": 547, + "parameters": [ + "self", + "prefix" + ], + "start_line": 135, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 225, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 11, + "token_count": 229, + "parameters": [ + "self", + "prefix" + ], + "start_line": 233, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "prefix" + ], + "start_line": 275, + "end_line": 291, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "shortest_path", + "long_name": "shortest_path( pths )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "pths" + ], + "start_line": 293, + "end_line": 295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 11, + "token_count": 154, + "parameters": [ + "args" + ], + "start_line": 297, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 320, + "end_line": 325, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 55, + "parameters": [], + "start_line": 327, + "end_line": 334, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [], + "start_line": 343, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "get_info", + "long_name": "get_info( name )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 1, + "token_count": 39, + "parameters": [ + "name" + ], + "start_line": 51, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "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": 72, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 67, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "has_info", + "long_name": "has_info( self )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 75, + "end_line": 76, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 9, + "token_count": 162, + "parameters": [ + "args" + ], + "start_line": 313, + "end_line": 334, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 11, + "token_count": 134, + "parameters": [ + "self" + ], + "start_line": 77, + "end_line": 102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 82, + "complexity": 30, + "token_count": 553, + "parameters": [ + "self", + "prefix" + ], + "start_line": 151, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "top_nesting_level": 1 + } + ], + "nloc": 298, + "complexity": 103, + "token_count": 1962, + "diff_parsed": { + "added": [ + " info_dict = get_info()", + " where is a string 'atlas','x11','fftw'.", + "", + " Returned info_dict is a dictionary which is compatible with", + " distutils.setup keyword arguments. If info_dict == {}, then the", + " asked resource is not available (or system_info could not find it).", + "def get_info(name):", + " cl = {'atlas':atlas_info,", + " 'x11':x11_info,", + " 'fftw':fftw_info}.get(name.lower(),system_info)", + " return cl().get_info()", + "", + " need_refresh = 1", + " saved_results = {}", + "", + " #self.__class__.need_refresh = not self.info", + " #self.__class__.info = info", + " self.saved_results[self.__class__.__name__] = info", + " def has_info(self):", + " return self.saved_results.has_key(self.__class__.__name__)", + " flag = 0", + " if not self.has_info():", + " flag = 1", + " if self.has_info(): break", + " if not self.has_info():", + " self.set_info()", + " res = self.saved_results.get(self.__class__.__name__)", + " if self.verbose and flag:", + " for k,v in res.items():", + " print ' %s = %s'%(k,v)", + " print", + " return res", + " dict_append(info,define_macros=[('SCIPY_FFTW_H',1)])", + " dict_append(info,define_macros=[('SCIPY_DFFTW_H',1)])", + " dict_append(info,define_macros=[('SCIPY_SFFTW_H',1)])", + " if len(args)==1:", + " result = reduce(lambda a,b:a+b,map(glob,args[0]),[])", + " elif len (args)==2:", + " else:", + " result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))", + " if n in ['system_info','get_info']: continue" + ], + "deleted": [ + " For example,", + " info = atlas_info().get_info()", + " info will be a dictionary that is compatible with distutils.setup keyword", + " arguments. If info == {}, then the asked resource is not available.", + "", + " self.need_refresh = not self.info", + " self.__class__.info = info", + "", + " if self.need_refresh:", + " if self.info: break", + " self.need_refresh = 0", + " if not self.info:", + " for k,v in self.info.items():", + " print ' %s = %s'%(k,v)", + " print", + " return self.info", + " dict_append(info,define_macros=('SCIPY_FFTW_H',1))", + " dict_append(info,define_macros=('SCIPY_DFFTW_H',1))", + " dict_append(info,define_macros=('SCIPY_SFFTW_H',1))", + " if len (args)==1:", + " return [r for r in map(glob,args[0]) if r]", + " if len (args)==2:", + " return result", + " result = combine_paths(*(combine_paths(args[0],args[1])+args[2:]))", + " if n=='system_info': continue" + ] + } + } + ] + }, + { + "hash": "c22540a20f509e9f94a522567cbb5d2c1b8a96e9", + "msg": "Applied system_info hooks to scipy. Win32 support is still open.", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-02-22T16:43:52+00:00", + "author_timezone": 0, + "committer_date": "2002-02-22T16:43:52+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "06a9f21379b2631f3e5fd182ea2af524fedbdf28" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 16, + "insertions": 31, + "lines": 47, + "files": 4, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "scipy_distutils/atlas_info.py", + "new_path": "scipy_distutils/atlas_info.py", + "filename": "atlas_info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -1,5 +1,6 @@\n import sys, os\n from misc_util import get_path\n+from system_info import get_info\n \n library_path = None\n \n@@ -16,8 +17,15 @@ def get_atlas_info():\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n- lapack_libraries = ['lapack'] + blas_libraries \n+ lapack_libraries = ['lapack'] + blas_libraries\n+ #XXX: need to use `atlas_info = get_info('atlas')'\n+ atlas_info = {'libraries':lapack_libraries,\n+ 'library_dirs':atlas_library_dirs}\n+ return atlas_info\n else:\n+ atlas_info = get_info('atlas')\n+ return atlas_info\n+\n if not dir_exists(library_path):\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n", + "added_lines": 9, + "deleted_lines": 1, + "source_code": "import sys, os\nfrom misc_util import get_path\nfrom system_info import get_info\n\nlibrary_path = None\n\ndef dir_exists(dir_list):\n if dir_list:\n if os.path.exists(dir_list[0]):\n return 1\n return 0\n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not dir_exists(library_path):\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n #XXX: need to use `atlas_info = get_info('atlas')'\n atlas_info = {'libraries':lapack_libraries,\n 'library_dirs':atlas_library_dirs}\n return atlas_info\n else:\n atlas_info = get_info('atlas')\n return atlas_info\n\n if not dir_exists(library_path):\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", + "source_code_before": "import sys, os\nfrom misc_util import get_path\n\nlibrary_path = None\n\ndef dir_exists(dir_list):\n if dir_list:\n if os.path.exists(dir_list[0]):\n return 1\n return 0\n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not dir_exists(library_path):\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries \n else:\n if not dir_exists(library_path):\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", + "methods": [ + { + "name": "dir_exists", + "long_name": "dir_exists( dir_list )", + "filename": "atlas_info.py", + "nloc": 5, + "complexity": 3, + "token_count": 25, + "parameters": [ + "dir_list" + ], + "start_line": 7, + "end_line": 11, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "get_atlas_info", + "long_name": "get_atlas_info( )", + "filename": "atlas_info.py", + "nloc": 21, + "complexity": 4, + "token_count": 113, + "parameters": [], + "start_line": 13, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "unix_atlas_directory", + "long_name": "unix_atlas_directory( platform )", + "filename": "atlas_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "platform" + ], + "start_line": 37, + "end_line": 60, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "dir_exists", + "long_name": "dir_exists( dir_list )", + "filename": "atlas_info.py", + "nloc": 5, + "complexity": 3, + "token_count": 25, + "parameters": [ + "dir_list" + ], + "start_line": 6, + "end_line": 10, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "get_atlas_info", + "long_name": "get_atlas_info( )", + "filename": "atlas_info.py", + "nloc": 16, + "complexity": 4, + "token_count": 92, + "parameters": [], + "start_line": 12, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "unix_atlas_directory", + "long_name": "unix_atlas_directory( platform )", + "filename": "atlas_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "platform" + ], + "start_line": 29, + "end_line": 52, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "get_atlas_info", + "long_name": "get_atlas_info( )", + "filename": "atlas_info.py", + "nloc": 21, + "complexity": 4, + "token_count": 113, + "parameters": [], + "start_line": 13, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + } + ], + "nloc": 37, + "complexity": 10, + "token_count": 195, + "diff_parsed": { + "added": [ + "from system_info import get_info", + " lapack_libraries = ['lapack'] + blas_libraries", + " #XXX: need to use `atlas_info = get_info('atlas')'", + " atlas_info = {'libraries':lapack_libraries,", + " 'library_dirs':atlas_library_dirs}", + " return atlas_info", + " atlas_info = get_info('atlas')", + " return atlas_info", + "" + ], + "deleted": [ + " lapack_libraries = ['lapack'] + blas_libraries" + ] + } + }, + { + "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": "@@ -20,6 +20,7 @@ def build_extension(self, ext):\n \n # support for building static fortran libraries\n need_f_libs = 0\n+ need_f_opts = getattr(ext,'need_fcompiler_opts',0)\n ext_name = string.split(ext.name,'.')[-1]\n \n if self.distribution.has_f_libraries():\n@@ -31,15 +32,12 @@ def build_extension(self, ext):\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n- print ext.name,ext_name,'needs fortran libraries',need_f_libs\n+ elif need_f_opts:\n+ build_flib = self.get_finalized_command('build_flib')\n+ print ext.name,ext_name,'needs fortran libraries',\\\n+ need_f_libs,need_f_opts\n \n if need_f_libs:\n- moreargs = build_flib.fcompiler.get_extra_link_args()\n- if moreargs != []:\n- if ext.extra_link_args is None:\n- ext.extra_link_args = moreargs\n- else:\n- ext.extra_link_args += moreargs\n if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.append(ext_name)\n@@ -48,9 +46,18 @@ def build_extension(self, ext):\n ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))\n \n ext.library_dirs.append(build_flib.build_flib)\n+\n+ if need_f_libs or need_f_opts:\n+ moreargs = build_flib.fcompiler.get_extra_link_args()\n+ if moreargs != []:\n+ if ext.extra_link_args is None:\n+ ext.extra_link_args = moreargs\n+ else:\n+ ext.extra_link_args += moreargs\n+\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n- \n+\n linker_so = build_flib.fcompiler.get_linker_so()\n \n if linker_so is not None:\n", + "added_lines": 15, + "deleted_lines": 8, + "source_code": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os, string\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import *\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n #XXX: anything else we need to save?\n save_linker_so = self.compiler.linker_so\n save_compiler_libs = self.compiler.libraries\n save_compiler_libs_dirs = self.compiler.library_dirs\n \n # support for building static fortran libraries\n need_f_libs = 0\n need_f_opts = getattr(ext,'need_fcompiler_opts',0)\n ext_name = string.split(ext.name,'.')[-1]\n\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n if build_flib.has_f_library(ext_name):\n need_f_libs = 1\n else:\n for lib_name in ext.libraries:\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n elif need_f_opts:\n build_flib = self.get_finalized_command('build_flib')\n print ext.name,ext_name,'needs fortran libraries',\\\n need_f_libs,need_f_opts\n \n if need_f_libs:\n if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.append(ext_name)\n for lib_name in ext.libraries[:]:\n ext.libraries.extend(build_flib.get_library_names(lib_name))\n ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))\n \n ext.library_dirs.append(build_flib.build_flib)\n\n if need_f_libs or need_f_opts:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n if moreargs != []:\n if ext.extra_link_args is None:\n ext.extra_link_args = moreargs\n else:\n ext.extra_link_args += moreargs\n\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n\n linker_so = build_flib.fcompiler.get_linker_so()\n\n if linker_so is not None:\n if linker_so is not save_linker_so:\n print 'replacing linker_so %s with %s' %(save_linker_so,linker_so)\n self.compiler.linker_so = linker_so\n l = build_flib.get_fcompiler_library_names()\n #l = self.compiler.libraries + l\n self.compiler.libraries = l\n l = build_flib.get_fcompiler_library_dirs()\n #l = self.compiler.library_dirs + l\n self.compiler.library_dirs = l\n else:\n libs = build_flib.get_fcompiler_library_names()\n for lib in libs:\n if lib not in self.compiler.libraries:\n self.compiler.libraries.append(lib)\n #self.compiler.libraries = self.compiler.libraries + l\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n if lib_dir not in self.compiler.library_dirs:\n self.compiler.libraries.append(lib_dir)\n #self.compiler.library_dirs = self.compiler.library_dirs + l\n \n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n\n if save_linker_so is not self.compiler.linker_so:\n print 'restoring linker_so',save_linker_so\n self.compiler.linker_so = save_linker_so\n self.compiler.libraries = save_compiler_libs\n self.compiler.library_dirs = save_compiler_libs_dirs\n\n return res\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n filenames.extend(ext.sources)\n filenames.extend(get_headers(get_directories(ext.sources)))\n\n return filenames\n", + "source_code_before": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os, string\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import *\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n #XXX: anything else we need to save?\n save_linker_so = self.compiler.linker_so\n save_compiler_libs = self.compiler.libraries\n save_compiler_libs_dirs = self.compiler.library_dirs\n \n # support for building static fortran libraries\n need_f_libs = 0\n ext_name = string.split(ext.name,'.')[-1]\n\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n if build_flib.has_f_library(ext_name):\n need_f_libs = 1\n else:\n for lib_name in ext.libraries:\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n print ext.name,ext_name,'needs fortran libraries',need_f_libs\n \n if need_f_libs:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n if moreargs != []:\n if ext.extra_link_args is None:\n ext.extra_link_args = moreargs\n else:\n ext.extra_link_args += moreargs\n if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.append(ext_name)\n for lib_name in ext.libraries[:]:\n ext.libraries.extend(build_flib.get_library_names(lib_name))\n ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))\n \n ext.library_dirs.append(build_flib.build_flib)\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n \n linker_so = build_flib.fcompiler.get_linker_so()\n\n if linker_so is not None:\n if linker_so is not save_linker_so:\n print 'replacing linker_so %s with %s' %(save_linker_so,linker_so)\n self.compiler.linker_so = linker_so\n l = build_flib.get_fcompiler_library_names()\n #l = self.compiler.libraries + l\n self.compiler.libraries = l\n l = build_flib.get_fcompiler_library_dirs()\n #l = self.compiler.library_dirs + l\n self.compiler.library_dirs = l\n else:\n libs = build_flib.get_fcompiler_library_names()\n for lib in libs:\n if lib not in self.compiler.libraries:\n self.compiler.libraries.append(lib)\n #self.compiler.libraries = self.compiler.libraries + l\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n if lib_dir not in self.compiler.library_dirs:\n self.compiler.libraries.append(lib_dir)\n #self.compiler.library_dirs = self.compiler.library_dirs + l\n \n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n\n if save_linker_so is not self.compiler.linker_so:\n print 'restoring linker_so',save_linker_so\n self.compiler.linker_so = save_linker_so\n self.compiler.libraries = save_compiler_libs\n self.compiler.library_dirs = save_compiler_libs_dirs\n\n return res\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n filenames.extend(ext.sources)\n filenames.extend(get_headers(get_directories(ext.sources)))\n\n return filenames\n", + "methods": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 62, + "complexity": 22, + "token_count": 437, + "parameters": [ + "self", + "ext" + ], + "start_line": 15, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_ext.py", + "nloc": 7, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 96, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 57, + "complexity": 19, + "token_count": 408, + "parameters": [ + "self", + "ext" + ], + "start_line": 15, + "end_line": 87, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 73, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_ext.py", + "nloc": 7, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 89, + "end_line": 98, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 62, + "complexity": 22, + "token_count": 437, + "parameters": [ + "self", + "ext" + ], + "start_line": 15, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 1 + } + ], + "nloc": 78, + "complexity": 24, + "token_count": 538, + "diff_parsed": { + "added": [ + " need_f_opts = getattr(ext,'need_fcompiler_opts',0)", + " elif need_f_opts:", + " build_flib = self.get_finalized_command('build_flib')", + " print ext.name,ext_name,'needs fortran libraries',\\", + " need_f_libs,need_f_opts", + "", + " if need_f_libs or need_f_opts:", + " moreargs = build_flib.fcompiler.get_extra_link_args()", + " if moreargs != []:", + " if ext.extra_link_args is None:", + " ext.extra_link_args = moreargs", + " else:", + " ext.extra_link_args += moreargs", + "", + "" + ], + "deleted": [ + " print ext.name,ext_name,'needs fortran libraries',need_f_libs", + " moreargs = build_flib.fcompiler.get_extra_link_args()", + " if moreargs != []:", + " if ext.extra_link_args is None:", + " ext.extra_link_args = moreargs", + " else:", + " ext.extra_link_args += moreargs", + "" + ] + } + }, + { + "old_path": "scipy_distutils/command/build_flib.py", + "new_path": "scipy_distutils/command/build_flib.py", + "filename": "build_flib.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -174,15 +174,15 @@ def get_library_names(self, name=None):\n return lib_names\n \n def get_fcompiler_library_names(self):\n- if not self.has_f_libraries():\n- return None\n+ #if not self.has_f_libraries():\n+ # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_libraries()\n return []\n \n def get_fcompiler_library_dirs(self):\n- if not self.has_f_libraries():\n- return None\n+ #if not self.has_f_libraries():\n+ # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_library_dirs()\n return []\n@@ -211,8 +211,8 @@ def get_library_dirs(self, name=None):\n # get_library_dirs ()\n \n def get_runtime_library_dirs(self):\n- if not self.has_f_libraries():\n- return []\n+ #if not self.has_f_libraries():\n+ # return []\n \n lib_dirs = []\n \n", + "added_lines": 6, + "deleted_lines": 6, + "source_code": "\"\"\" Implements the build_flib command which should go into Distutils\n at some point.\n \n Note:\n Right now, we're dynamically linking to the Fortran libraries on \n some platforms (Sun for sure). This is fine for local installations\n but a bad thing for redistribution because these libraries won't\n live on any machine that doesn't have a fortran compiler installed.\n It is pretty hard (impossible?) to get gcc to pass the right compiler\n flags on Sun to get the linker to use static libs for the fortran\n stuff. Investigate further...\n\nBugs:\n *** Options -e and -x have no effect when used with --help-compiler\n options. E.g. \n ./setup.py build_flib --help-compiler -e g77-3.0\n finds g77-2.95.\n How to extract these options inside the show_compilers function?\n *** compiler.is_available() method may not work correctly on nt\n because of lack of knowledge how to get exit status in\n run_command function. However, it may give reasonable results\n based on a version string.\n *** Some vendors provide different compilers for F77 and F90\n compilations. Currently, checking the availability of these\n compilers is based on only checking the availability of the\n corresponding F77 compiler. If it exists, then F90 is assumed\n to exist also.\n\nOpen issues:\n *** User-defined compiler flags. Do we need --fflags?\n\nFortran compilers (as to be used with --fcompiler= option):\n Absoft\n Sun\n SGI\n Intel\n Itanium\n NAG\n Compaq\n Gnu\n VAST\n\"\"\"\n\nimport distutils\nimport distutils.dep_util, distutils.dir_util\nimport os,sys,string\nimport commands,re\nfrom types import *\nfrom distutils.command.build_clib import build_clib\nfrom distutils.errors import *\n\nclass FortranCompilerError (CCompilerError):\n \"\"\"Some compile/link operation failed.\"\"\"\nclass FortranCompileError (FortranCompilerError):\n \"\"\"Failure to compile one or more Fortran source files.\"\"\"\n\nif os.name == 'nt':\n def run_command(command):\n \"\"\" not sure how to get exit status on nt. \"\"\"\n in_pipe,out_pipe = os.popen4(command)\n in_pipe.close()\n text = out_pipe.read()\n return 0, text\nelse:\n run_command = commands.getstatusoutput\n \ndef show_compilers():\n for compiler_class in all_compilers:\n compiler = compiler_class()\n if compiler.is_available():\n print compiler\n\nclass build_flib (build_clib):\n\n description = \"build f77/f90 libraries used by Python extensions\"\n\n user_options = [\n ('build-flib', 'b',\n \"directory to build f77/f90 libraries to\"),\n ('build-temp', 't',\n \"directory to put temporary build by-products\"),\n ('debug', 'g',\n \"compile with debugging information\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ('fcompiler=', 'c',\n \"specify the compiler type\"),\n ('fcompiler-exec=', 'e',\n \"specify the path to F77 compiler\"),\n ('f90compiler-exec=', 'x',\n \"specify the path to F90 compiler\"),\n ]\n\n boolean_options = ['debug', 'force']\n\n help_options = [\n ('help-compiler', None,\n \"list available compilers\", show_compilers),\n ]\n\n def initialize_options (self):\n\n self.build_flib = None\n self.build_temp = None\n\n self.fortran_libraries = None\n self.define = None\n self.undef = None\n self.debug = None\n self.force = 0\n self.fcompiler = None\n self.fcompiler_exec = None\n self.f90compiler_exec = None\n\n # initialize_options()\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_flib'),\n ('build_temp', 'build_temp'),\n ('debug', 'debug'),\n ('force', 'force'))\n fc = find_fortran_compiler(self.fcompiler,\n self.fcompiler_exec,\n self.f90compiler_exec)\n if not fc:\n raise DistutilsOptionError, 'Fortran compiler not available: %s'%(self.fcompiler)\n else:\n self.announce(' using %s Fortran compiler' % fc)\n self.fcompiler = fc\n if self.has_f_libraries():\n self.fortran_libraries = self.distribution.fortran_libraries\n self.check_library_list(self.fortran_libraries)\n\n # finalize_options()\n\n def has_f_libraries(self):\n return self.distribution.fortran_libraries \\\n and len(self.distribution.fortran_libraries) > 0\n\n def run (self):\n if not self.has_f_libraries():\n return\n self.build_libraries(self.fortran_libraries)\n\n # run ()\n\n def has_f_library(self,name):\n if self.has_f_libraries():\n for (lib_name, build_info) in self.fortran_libraries:\n if lib_name == name:\n return 1\n \n def get_library_names(self, name=None):\n if not self.has_f_libraries():\n return None\n\n lib_names = []\n\n if name is None:\n for (lib_name, build_info) in self.fortran_libraries:\n lib_names.append(lib_name)\n\n if self.fcompiler is not None:\n lib_names.extend(self.fcompiler.get_libraries())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n for n in build_info.get('libraries',[]):\n lib_names.append(n)\n #XXX: how to catch recursive calls here?\n lib_names.extend(self.get_library_names(n))\n break\n return lib_names\n\n def get_fcompiler_library_names(self):\n #if not self.has_f_libraries():\n # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_libraries()\n return []\n\n def get_fcompiler_library_dirs(self):\n #if not self.has_f_libraries():\n # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_library_dirs()\n return []\n\n # get_library_names ()\n\n def get_library_dirs(self, name=None):\n if not self.has_f_libraries():\n return []\n\n lib_dirs = [] \n\n if name is None:\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_library_dirs())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n lib_dirs.extend(build_info.get('library_dirs',[]))\n for n in build_info.get('libraries',[]):\n lib_dirs.extend(self.get_library_dirs(n))\n break\n\n return lib_dirs\n\n # get_library_dirs ()\n\n def get_runtime_library_dirs(self):\n #if not self.has_f_libraries():\n # return []\n\n lib_dirs = []\n\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_runtime_library_dirs())\n \n return lib_dirs\n\n # get_library_dirs ()\n\n def get_source_files (self):\n if not self.has_f_libraries():\n return []\n\n self.check_library_list(self.fortran_libraries)\n filenames = []\n\n # Gets source files specified \n for ext in self.fortran_libraries:\n filenames.extend(ext[1]['sources'])\n\n return filenames \n \n def build_libraries (self, fortran_libraries):\n \n fcompiler = self.fcompiler\n \n for (lib_name, build_info) in fortran_libraries:\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'fortran_libraries' option (library '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % lib_name\n sources = list(sources)\n module_dirs = build_info.get('module_dirs')\n module_files = build_info.get('module_files')\n self.announce(\" building '%s' library\" % lib_name)\n \n if module_files:\n fcompiler.build_library(lib_name, module_files,\n temp_dir=self.build_temp)\n \n fcompiler.build_library(lib_name, sources,\n module_dirs, temp_dir=self.build_temp)\n\n # for loop\n\n # build_libraries ()\n\n\nclass fortran_compiler_base:\n\n vendor = None\n ver_match = None\n \n def __init__(self):\n # Default initialization. Constructors of derived classes MUST\n # call this functions.\n self.version = None\n \n self.f77_switches = ''\n self.f77_opt = ''\n self.f77_debug = ''\n \n self.f90_switches = ''\n self.f90_opt = ''\n self.f90_debug = ''\n \n self.libraries = []\n self.library_dirs = []\n\n if self.vendor is None:\n raise DistutilsInternalError,\\\n '%s must define vendor attribute'%(self.__class__)\n if self.ver_match is None:\n raise DistutilsInternalError,\\\n '%s must define ver_match attribute'%(self.__class__)\n\n def to_object(self,dirty_files,module_dirs=None, temp_dir=''):\n files = string.join(dirty_files)\n f90_files = get_f90_files(dirty_files)\n f77_files = get_f77_files(dirty_files)\n if f90_files != []:\n obj1 = self.f90_compile(f90_files,module_dirs,temp_dir = temp_dir)\n else:\n obj1 = []\n if f77_files != []:\n obj2 = self.f77_compile(f77_files, temp_dir = temp_dir)\n else:\n obj2 = []\n return obj1 + obj2\n\n def source_to_object_names(self,source_files, temp_dir=''):\n file_list = map(lambda x: os.path.basename(x),source_files)\n file_base_ext = map(lambda x: os.path.splitext(x),file_list)\n object_list = map(lambda x: x[0] +'.o',file_base_ext)\n object_files = map(lambda x,td=temp_dir: os.path.join(td,x),object_list)\n return object_files\n \n def source_and_object_pairs(self,source_files, temp_dir=''):\n object_files = self.source_to_object_names(source_files,temp_dir)\n file_pairs = zip(source_files,object_files)\n return file_pairs\n \n def f_compile(self,compiler,switches, source_files,\n module_dirs=None, temp_dir=''):\n module_switch = self.build_module_switch(module_dirs)\n file_pairs = self.source_and_object_pairs(source_files,temp_dir)\n object_files = []\n for source,object in file_pairs:\n if distutils.dep_util.newer(source,object):\n cmd = compiler + ' ' + switches + \\\n module_switch + ' -c ' + source + ' -o ' + object \n print cmd\n failure = os.system(cmd)\n if failure:\n raise FortranCompileError, 'failure during compile' \n object_files.append(object)\n return object_files\n #return all object files to make sure everything is archived \n #return map(lambda x: x[1], file_pairs)\n\n def f90_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f90_switches, self.f90_opt))\n return self.f_compile(self.f90_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n def f77_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f77_switches, self.f77_opt))\n return self.f_compile(self.f77_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n\n def build_module_switch(self, module_dirs):\n return ''\n\n def create_static_lib(self, object_files, library_name,\n output_dir='', debug=None):\n lib_file = os.path.join(output_dir,'lib'+library_name+'.a')\n newer = distutils.dep_util.newer\n # This doesn't work -- no way to know if the file is in the archive\n #object_files = filter(lambda o,lib=lib_file:\\\n # distutils.dep_util.newer(o,lib),object_files)\n objects = string.join(object_files)\n if objects:\n cmd = 'ar -cur %s %s' % (lib_file,objects)\n print cmd\n os.system(cmd)\n\n def build_library(self,library_name,source_list,module_dirs=None,\n temp_dir = ''):\n #make sure the temp directory exists before trying to build files\n import distutils.dir_util\n distutils.dir_util.mkpath(temp_dir)\n\n #this compiles the files\n object_list = self.to_object(source_list,module_dirs,temp_dir)\n\n # actually we need to use all the object file names here to\n # make sure the library is always built. It could occur that an\n # object file exists but hasn't been put in the archive. (happens\n # a lot when builds fail once and are restarted).\n object_list = self.source_to_object_names(source_list, temp_dir)\n\n if os.name == 'nt':\n # This is pure bunk...\n # Windows fails for long argument strings on the command line.\n # if objects is real long (> 2048 chars or so on my machine),\n # the command fails (cmd.exe /e:2048 on w2k)\n # for now we'll split linking into to steps which should work for\n objects = object_list[:]\n while objects:\n obj,objects = objects[:20],objects[20:]\n self.create_static_lib(obj,library_name,temp_dir)\n else:\n self.create_static_lib(object_list,library_name,temp_dir)\n\n def dummy_fortran_files(self):\n import tempfile \n d = tempfile.gettempdir()\n dummy_name = os.path.join(d,'__dummy.f')\n dummy = open(dummy_name,'w')\n dummy.write(\" subroutine dummy()\\n end\\n\")\n dummy.close()\n return (os.path.join(d,'__dummy.f'),os.path.join(d,'__dummy.o'))\n \n def is_available(self):\n return self.get_version()\n \n def get_version(self):\n \"\"\"Return the compiler version. If compiler is not available,\n return empty string.\"\"\"\n # XXX: Is there compilers that have no version? If yes,\n # this test will fail even if the compiler is available.\n if self.version is not None:\n # Finding version is expensive, so return previously found\n # version string.\n return self.version\n self.version = ''\n # works I think only for unix... \n #print 'command:', self.ver_cmd\n exit_status, out_text = run_command(self.ver_cmd)\n #print exit_status, out_text\n if not exit_status:\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\n return self.version\n\n def get_libraries(self):\n return self.libraries\n def get_library_dirs(self):\n return self.library_dirs\n def get_extra_link_args(self):\n return []\n def get_runtime_library_dirs(self):\n return []\n def get_linker_so(self):\n \"\"\"\n If a compiler requires specific linker then return a list\n containing a linker executable name and linker options.\n Otherwise, return None.\n \"\"\"\n\n def __str__(self):\n return \"%s %s\" % (self.vendor, self.get_version())\n\n\nclass absoft_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Absoft'\n ver_match = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n \n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n # got rid of -B108 cause it was generating 2 underscores instead\n # of one on the newest version. Now we use -YEXT_SFX=_ to \n # specify the output format\n if os.name == 'nt':\n self.f90_switches = '-f fixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -Q100'\n self.f77_switches = '-N22 -N90 -N110'\n self.f77_opt = '-O -Q100'\n self.libraries = ['fio', 'fmath', 'f90math', 'COMDLG32']\n else:\n self.f90_switches = '-ffixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -B101' \n self.f77_switches = '-N22 -N90 -N110 -B108'\n self.f77_opt = '-O -B101'\n\n self.libraries = ['fio', 'f77math', 'f90math']\n \n try:\n dir = os.environ['ABSOFT'] \n self.library_dirs = [os.path.join(dir,'lib')]\n except KeyError:\n self.library_dirs = []\n\n self.ver_cmd = self.f77_compiler + ' -V -c %s -o %s' % \\\n self.dummy_fortran_files()\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -p' + mod\n return res\n\n def get_extra_link_args(self):\n return []\n # Couldn't get this to link for anything using gcc.\n #dr = \"c:\\\\Absoft62\\\\lib\"\n #libs = ['fio.lib', 'COMDLG32.lib','fmath.lib', 'f90math.lib','libcomdlg32.a' ] \n #libs = map(lambda x,dr=dr:os.path.join(dr,x),libs)\n #return libs\n\n\nclass sun_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Sun'\n ver_match = r'f77: (?P[^\\s*,]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc # not tested\n self.f77_switches = ' -pic '\n self.f77_opt = ' -fast -dalign '\n\n self.f90_compiler = f90c\n self.f90_switches = ' -fixed ' # ??? why fixed?\n self.f90_opt = ' -fast -dalign '\n\n self.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\n #threaded\n #self.libraries = ['f90', 'F77_mt', 'sunmath_mt', 'm', 'thread']\n #self.libraries = []\n self.library_dirs = self.find_lib_dir()\n #print 'sun:',self.library_dirs\n\n self.ver_cmd = self.f77_compiler + ' -V'\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -M' + mod\n return res\n\n def find_lib_dir(self):\n library_dirs = []\n lib_match = r'### f90: Note: LD_RUN_PATH\\s*= '\\\n '(?P[^\\s.]*).*'\n cmd = self.f90_compiler + ' -dryrun dummy.f'\n exit_status, output = run_command(cmd)\n if not exit_status:\n libs = re.findall(lib_match,output)\n if libs:\n library_dirs = string.split(libs[0],':')\n self.get_version() # force version calculation\n compiler_home = os.path.dirname(library_dirs[0])\n library_dirs.append(os.path.join(compiler_home,\n self.version,'lib'))\n return library_dirs\n def get_runtime_library_dirs(self):\n return self.find_lib_dir()\n def get_extra_link_args(self):\n return ['-mimpure-text']\n\n\nclass mips_fortran_compiler(fortran_compiler_base):\n\n vendor = 'SGI'\n ver_match = r'MIPSpro Compilers: Version (?P[^\\s*,]*)'\n \n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc # not tested\n self.f77_switches = ' -n32 -KPIC '\n self.f77_opt = ' -O3 '\n\n self.f90_compiler = f90c\n self.f90_switches = ' -n32 -KPIC -fixedform ' # why fixed ???\n self.f90_opt = ' ' \n \n self.libraries = ['fortran', 'ftn', 'm']\n self.library_dirs = self.find_lib_dir()\n\n self.ver_cmd = self.f77_compiler + ' -version'\n\n def build_module_switch(self,module_dirs):\n res = ''\n return res \n def find_lib_dir(self):\n library_dirs = []\n return library_dirs\n def get_runtime_library_dirs(self):\n\treturn self.find_lib_dir() \n def get_extra_link_args(self):\n\treturn []\n\n\nclass gnu_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Gnu'\n ver_match = r'g77 version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if sys.platform == 'win32':\n self.libraries = ['gcc','g2c']\n self.library_dirs = self.find_lib_directories()\n else:\n # On linux g77 does not need lib_directories to be specified.\n self.libraries = ['g2c']\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n\n switches = ' -Wall -fno-second-underscore '\n\n if os.name != 'nt':\n switches = switches + ' -fpic '\n\n self.f77_switches = switches\n\n self.ver_cmd = self.f77_compiler + ' -v '\n self.f77_opt = self.get_opt()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 -funroll-loops '\n \n # only check for more optimization if g77 can handle\n # it.\n if self.get_version():\n if self.version[0]=='3': # is g77 3.x.x\n if cpu.is_AthlonK6():\n opt = opt + ' -march=k6 '\n elif cpu.is_AthlonK7():\n opt = opt + ' -march=athlon '\n if cpu.is_i686():\n opt = opt + ' -march=i686 '\n elif cpu.is_i586():\n opt = opt + ' -march=i586 '\n elif cpu.is_i486():\n opt = opt + ' -march=i486 '\n elif cpu.is_i386():\n opt = opt + ' -march=i386 '\n if cpu.is_Intel():\n opt = opt + ' -malign-double ' \n return opt\n \n def find_lib_directories(self):\n lib_dir = []\n match = r'Reading specs from (.*)/specs'\n\n # works I think only for unix... \n exit_status, out_text = run_command('g77 -v')\n if not exit_status:\n m = re.findall(match,out_text)\n if m:\n lib_dir= m #m[0] \n return lib_dir\n\n def get_linker_so(self):\n # win32 linking should be handled by standard linker\n if sys.platform != 'win32':\n return [self.f77_compiler,'-shared']\n \n def f90_compile(self,source_files,module_files,temp_dir=''):\n raise DistutilsExecError, 'f90 not supported by Gnu'\n\n\n#http://developer.intel.com/software/products/compilers/f50/linux/\nclass intel_ia32_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Intel' # Intel(R) Corporation \n ver_match = r'Intel\\(R\\) Fortran Compiler for 32-bit applications, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'ifc'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -KPIC '\n\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n if cpu.has_fdiv_bug():\n switches = switches + ' -fdiv_check '\n if cpu.has_f00f_bug():\n switches = switches + ' -0f_check '\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -FI -w90 -w95 '\n\n self.f77_opt = self.f90_opt = self.get_opt()\n \n debug = ' -g -C '\n self.f77_debug = self.f90_debug = debug\n\n self.ver_cmd = self.f77_compiler+' -FI -V -c %s -o %s' %\\\n self.dummy_fortran_files()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 '\n if cpu.is_PentiumPro() or cpu.is_PentiumII():\n opt = opt + ' -tpp6 -xi '\n elif cpu.is_PentiumIII():\n opt = opt + ' -tpp6 '\n elif cpu.is_Pentium():\n opt = opt + ' -tpp5 '\n elif cpu.is_PentiumIV():\n opt = opt + ' -tpp7 -xW '\n elif cpu.has_mmx():\n opt = opt + ' -xM '\n return opt\n \n\n def get_linker_so(self):\n return [self.f77_compiler,'-shared']\n\n\nclass intel_itanium_fortran_compiler(intel_ia32_fortran_compiler):\n\n vendor = 'Itanium'\n ver_match = r'Intel\\(R\\) Fortran 90 Compiler Itanium\\(TM\\) Compiler for the Itanium\\(TM\\)-based applications, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n if fc is None:\n fc = 'efc'\n intel_ia32_fortran_compiler.__init__(self, fc, f90c)\n\n\nclass nag_fortran_compiler(fortran_compiler_base):\n\n vendor = 'NAG'\n ver_match = r'NAGWare Fortran 95 compiler Release (?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'f95'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ''\n debug = ' -g -gline -g90 -nan -C '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -fixed '\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -target=native '\n return opt\n\n def get_linker_so(self):\n return [self.f77_compiler,'-Wl,-shared']\n\n\nclass vast_fortran_compiler(fortran_compiler_base):\n\n vendor = 'VAST'\n ver_match = r'\\s*Pacific-Sierra Research vf90 (Personal|Professional)\\s+(?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n d,b = os.path.split(f90c)\n vf90 = os.path.join(d,'v'+b)\n self.ver_cmd = vf90+' -v '\n\n gnu = gnu_fortran_compiler(fc)\n if not gnu.is_available(): # VAST compiler requires g77.\n self.version = ''\n return\n if not self.is_available():\n return\n\n self.f77_switches = gnu.f77_switches\n self.f77_debug = gnu.f77_debug\n self.f77_opt = gnu.f77_opt \n\n # XXX: need f90 switches, debug, opt\n\n def get_linker_so(self):\n return [self.f90_compiler,'-shared']\n\nclass compaq_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Compaq'\n ver_match = r'Compaq Fortran (?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'fort'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -assume no2underscore -nomixed_str_len_arg '\n debug = ' -g -check_bounds '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n # XXX: uncomment if required\n #self.libraries = ' -lUfor -lfor -lFutil -lcpml -lots -lc '\n\n # XXX: fix the version showing flag\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -align dcommons -arch host -assume bigarrays -assume nozsize -math_library fast -tune host '\n return opt\n\n def get_linker_so(self):\n # XXX: is -shared needed?\n return [self.f77_compiler,'-shared']\n\n\ndef match_extension(files,ext):\n match = re.compile(r'.*[.]('+ext+r')\\Z',re.I).match\n return filter(lambda x,match = match: match(x),files)\n\ndef get_f77_files(files):\n return match_extension(files,'for|f77|ftn|f')\n\ndef get_f90_files(files):\n return match_extension(files,'f90|f95')\n\ndef get_fortran_files(files):\n return match_extension(files,'f90|f95|for|f77|ftn|f')\n\ndef find_fortran_compiler(vendor = None, fc = None, f90c = None):\n fcompiler = None\n for compiler_class in all_compilers:\n if vendor is not None and vendor != compiler_class.vendor:\n continue\n print compiler_class\n compiler = compiler_class(fc,f90c)\n if compiler.is_available():\n fcompiler = compiler\n break\n return fcompiler\n\nall_compilers = [absoft_fortran_compiler,\n mips_fortran_compiler,\n sun_fortran_compiler,\n intel_ia32_fortran_compiler,\n intel_itanium_fortran_compiler,\n nag_fortran_compiler,\n compaq_fortran_compiler,\n vast_fortran_compiler,\n gnu_fortran_compiler,\n ]\n\nif __name__ == \"__main__\":\n show_compilers()\n", + "source_code_before": "\"\"\" Implements the build_flib command which should go into Distutils\n at some point.\n \n Note:\n Right now, we're dynamically linking to the Fortran libraries on \n some platforms (Sun for sure). This is fine for local installations\n but a bad thing for redistribution because these libraries won't\n live on any machine that doesn't have a fortran compiler installed.\n It is pretty hard (impossible?) to get gcc to pass the right compiler\n flags on Sun to get the linker to use static libs for the fortran\n stuff. Investigate further...\n\nBugs:\n *** Options -e and -x have no effect when used with --help-compiler\n options. E.g. \n ./setup.py build_flib --help-compiler -e g77-3.0\n finds g77-2.95.\n How to extract these options inside the show_compilers function?\n *** compiler.is_available() method may not work correctly on nt\n because of lack of knowledge how to get exit status in\n run_command function. However, it may give reasonable results\n based on a version string.\n *** Some vendors provide different compilers for F77 and F90\n compilations. Currently, checking the availability of these\n compilers is based on only checking the availability of the\n corresponding F77 compiler. If it exists, then F90 is assumed\n to exist also.\n\nOpen issues:\n *** User-defined compiler flags. Do we need --fflags?\n\nFortran compilers (as to be used with --fcompiler= option):\n Absoft\n Sun\n SGI\n Intel\n Itanium\n NAG\n Compaq\n Gnu\n VAST\n\"\"\"\n\nimport distutils\nimport distutils.dep_util, distutils.dir_util\nimport os,sys,string\nimport commands,re\nfrom types import *\nfrom distutils.command.build_clib import build_clib\nfrom distutils.errors import *\n\nclass FortranCompilerError (CCompilerError):\n \"\"\"Some compile/link operation failed.\"\"\"\nclass FortranCompileError (FortranCompilerError):\n \"\"\"Failure to compile one or more Fortran source files.\"\"\"\n\nif os.name == 'nt':\n def run_command(command):\n \"\"\" not sure how to get exit status on nt. \"\"\"\n in_pipe,out_pipe = os.popen4(command)\n in_pipe.close()\n text = out_pipe.read()\n return 0, text\nelse:\n run_command = commands.getstatusoutput\n \ndef show_compilers():\n for compiler_class in all_compilers:\n compiler = compiler_class()\n if compiler.is_available():\n print compiler\n\nclass build_flib (build_clib):\n\n description = \"build f77/f90 libraries used by Python extensions\"\n\n user_options = [\n ('build-flib', 'b',\n \"directory to build f77/f90 libraries to\"),\n ('build-temp', 't',\n \"directory to put temporary build by-products\"),\n ('debug', 'g',\n \"compile with debugging information\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ('fcompiler=', 'c',\n \"specify the compiler type\"),\n ('fcompiler-exec=', 'e',\n \"specify the path to F77 compiler\"),\n ('f90compiler-exec=', 'x',\n \"specify the path to F90 compiler\"),\n ]\n\n boolean_options = ['debug', 'force']\n\n help_options = [\n ('help-compiler', None,\n \"list available compilers\", show_compilers),\n ]\n\n def initialize_options (self):\n\n self.build_flib = None\n self.build_temp = None\n\n self.fortran_libraries = None\n self.define = None\n self.undef = None\n self.debug = None\n self.force = 0\n self.fcompiler = None\n self.fcompiler_exec = None\n self.f90compiler_exec = None\n\n # initialize_options()\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_flib'),\n ('build_temp', 'build_temp'),\n ('debug', 'debug'),\n ('force', 'force'))\n fc = find_fortran_compiler(self.fcompiler,\n self.fcompiler_exec,\n self.f90compiler_exec)\n if not fc:\n raise DistutilsOptionError, 'Fortran compiler not available: %s'%(self.fcompiler)\n else:\n self.announce(' using %s Fortran compiler' % fc)\n self.fcompiler = fc\n if self.has_f_libraries():\n self.fortran_libraries = self.distribution.fortran_libraries\n self.check_library_list(self.fortran_libraries)\n\n # finalize_options()\n\n def has_f_libraries(self):\n return self.distribution.fortran_libraries \\\n and len(self.distribution.fortran_libraries) > 0\n\n def run (self):\n if not self.has_f_libraries():\n return\n self.build_libraries(self.fortran_libraries)\n\n # run ()\n\n def has_f_library(self,name):\n if self.has_f_libraries():\n for (lib_name, build_info) in self.fortran_libraries:\n if lib_name == name:\n return 1\n \n def get_library_names(self, name=None):\n if not self.has_f_libraries():\n return None\n\n lib_names = []\n\n if name is None:\n for (lib_name, build_info) in self.fortran_libraries:\n lib_names.append(lib_name)\n\n if self.fcompiler is not None:\n lib_names.extend(self.fcompiler.get_libraries())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n for n in build_info.get('libraries',[]):\n lib_names.append(n)\n #XXX: how to catch recursive calls here?\n lib_names.extend(self.get_library_names(n))\n break\n return lib_names\n\n def get_fcompiler_library_names(self):\n if not self.has_f_libraries():\n return None\n if self.fcompiler is not None:\n return self.fcompiler.get_libraries()\n return []\n\n def get_fcompiler_library_dirs(self):\n if not self.has_f_libraries():\n return None\n if self.fcompiler is not None:\n return self.fcompiler.get_library_dirs()\n return []\n\n # get_library_names ()\n\n def get_library_dirs(self, name=None):\n if not self.has_f_libraries():\n return []\n\n lib_dirs = [] \n\n if name is None:\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_library_dirs())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n lib_dirs.extend(build_info.get('library_dirs',[]))\n for n in build_info.get('libraries',[]):\n lib_dirs.extend(self.get_library_dirs(n))\n break\n\n return lib_dirs\n\n # get_library_dirs ()\n\n def get_runtime_library_dirs(self):\n if not self.has_f_libraries():\n return []\n\n lib_dirs = []\n\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_runtime_library_dirs())\n \n return lib_dirs\n\n # get_library_dirs ()\n\n def get_source_files (self):\n if not self.has_f_libraries():\n return []\n\n self.check_library_list(self.fortran_libraries)\n filenames = []\n\n # Gets source files specified \n for ext in self.fortran_libraries:\n filenames.extend(ext[1]['sources'])\n\n return filenames \n \n def build_libraries (self, fortran_libraries):\n \n fcompiler = self.fcompiler\n \n for (lib_name, build_info) in fortran_libraries:\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'fortran_libraries' option (library '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % lib_name\n sources = list(sources)\n module_dirs = build_info.get('module_dirs')\n module_files = build_info.get('module_files')\n self.announce(\" building '%s' library\" % lib_name)\n \n if module_files:\n fcompiler.build_library(lib_name, module_files,\n temp_dir=self.build_temp)\n \n fcompiler.build_library(lib_name, sources,\n module_dirs, temp_dir=self.build_temp)\n\n # for loop\n\n # build_libraries ()\n\n\nclass fortran_compiler_base:\n\n vendor = None\n ver_match = None\n \n def __init__(self):\n # Default initialization. Constructors of derived classes MUST\n # call this functions.\n self.version = None\n \n self.f77_switches = ''\n self.f77_opt = ''\n self.f77_debug = ''\n \n self.f90_switches = ''\n self.f90_opt = ''\n self.f90_debug = ''\n \n self.libraries = []\n self.library_dirs = []\n\n if self.vendor is None:\n raise DistutilsInternalError,\\\n '%s must define vendor attribute'%(self.__class__)\n if self.ver_match is None:\n raise DistutilsInternalError,\\\n '%s must define ver_match attribute'%(self.__class__)\n\n def to_object(self,dirty_files,module_dirs=None, temp_dir=''):\n files = string.join(dirty_files)\n f90_files = get_f90_files(dirty_files)\n f77_files = get_f77_files(dirty_files)\n if f90_files != []:\n obj1 = self.f90_compile(f90_files,module_dirs,temp_dir = temp_dir)\n else:\n obj1 = []\n if f77_files != []:\n obj2 = self.f77_compile(f77_files, temp_dir = temp_dir)\n else:\n obj2 = []\n return obj1 + obj2\n\n def source_to_object_names(self,source_files, temp_dir=''):\n file_list = map(lambda x: os.path.basename(x),source_files)\n file_base_ext = map(lambda x: os.path.splitext(x),file_list)\n object_list = map(lambda x: x[0] +'.o',file_base_ext)\n object_files = map(lambda x,td=temp_dir: os.path.join(td,x),object_list)\n return object_files\n \n def source_and_object_pairs(self,source_files, temp_dir=''):\n object_files = self.source_to_object_names(source_files,temp_dir)\n file_pairs = zip(source_files,object_files)\n return file_pairs\n \n def f_compile(self,compiler,switches, source_files,\n module_dirs=None, temp_dir=''):\n module_switch = self.build_module_switch(module_dirs)\n file_pairs = self.source_and_object_pairs(source_files,temp_dir)\n object_files = []\n for source,object in file_pairs:\n if distutils.dep_util.newer(source,object):\n cmd = compiler + ' ' + switches + \\\n module_switch + ' -c ' + source + ' -o ' + object \n print cmd\n failure = os.system(cmd)\n if failure:\n raise FortranCompileError, 'failure during compile' \n object_files.append(object)\n return object_files\n #return all object files to make sure everything is archived \n #return map(lambda x: x[1], file_pairs)\n\n def f90_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f90_switches, self.f90_opt))\n return self.f_compile(self.f90_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n def f77_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f77_switches, self.f77_opt))\n return self.f_compile(self.f77_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n\n def build_module_switch(self, module_dirs):\n return ''\n\n def create_static_lib(self, object_files, library_name,\n output_dir='', debug=None):\n lib_file = os.path.join(output_dir,'lib'+library_name+'.a')\n newer = distutils.dep_util.newer\n # This doesn't work -- no way to know if the file is in the archive\n #object_files = filter(lambda o,lib=lib_file:\\\n # distutils.dep_util.newer(o,lib),object_files)\n objects = string.join(object_files)\n if objects:\n cmd = 'ar -cur %s %s' % (lib_file,objects)\n print cmd\n os.system(cmd)\n\n def build_library(self,library_name,source_list,module_dirs=None,\n temp_dir = ''):\n #make sure the temp directory exists before trying to build files\n import distutils.dir_util\n distutils.dir_util.mkpath(temp_dir)\n\n #this compiles the files\n object_list = self.to_object(source_list,module_dirs,temp_dir)\n\n # actually we need to use all the object file names here to\n # make sure the library is always built. It could occur that an\n # object file exists but hasn't been put in the archive. (happens\n # a lot when builds fail once and are restarted).\n object_list = self.source_to_object_names(source_list, temp_dir)\n\n if os.name == 'nt':\n # This is pure bunk...\n # Windows fails for long argument strings on the command line.\n # if objects is real long (> 2048 chars or so on my machine),\n # the command fails (cmd.exe /e:2048 on w2k)\n # for now we'll split linking into to steps which should work for\n objects = object_list[:]\n while objects:\n obj,objects = objects[:20],objects[20:]\n self.create_static_lib(obj,library_name,temp_dir)\n else:\n self.create_static_lib(object_list,library_name,temp_dir)\n\n def dummy_fortran_files(self):\n import tempfile \n d = tempfile.gettempdir()\n dummy_name = os.path.join(d,'__dummy.f')\n dummy = open(dummy_name,'w')\n dummy.write(\" subroutine dummy()\\n end\\n\")\n dummy.close()\n return (os.path.join(d,'__dummy.f'),os.path.join(d,'__dummy.o'))\n \n def is_available(self):\n return self.get_version()\n \n def get_version(self):\n \"\"\"Return the compiler version. If compiler is not available,\n return empty string.\"\"\"\n # XXX: Is there compilers that have no version? If yes,\n # this test will fail even if the compiler is available.\n if self.version is not None:\n # Finding version is expensive, so return previously found\n # version string.\n return self.version\n self.version = ''\n # works I think only for unix... \n #print 'command:', self.ver_cmd\n exit_status, out_text = run_command(self.ver_cmd)\n #print exit_status, out_text\n if not exit_status:\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\n return self.version\n\n def get_libraries(self):\n return self.libraries\n def get_library_dirs(self):\n return self.library_dirs\n def get_extra_link_args(self):\n return []\n def get_runtime_library_dirs(self):\n return []\n def get_linker_so(self):\n \"\"\"\n If a compiler requires specific linker then return a list\n containing a linker executable name and linker options.\n Otherwise, return None.\n \"\"\"\n\n def __str__(self):\n return \"%s %s\" % (self.vendor, self.get_version())\n\n\nclass absoft_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Absoft'\n ver_match = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n \n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n # got rid of -B108 cause it was generating 2 underscores instead\n # of one on the newest version. Now we use -YEXT_SFX=_ to \n # specify the output format\n if os.name == 'nt':\n self.f90_switches = '-f fixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -Q100'\n self.f77_switches = '-N22 -N90 -N110'\n self.f77_opt = '-O -Q100'\n self.libraries = ['fio', 'fmath', 'f90math', 'COMDLG32']\n else:\n self.f90_switches = '-ffixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -B101' \n self.f77_switches = '-N22 -N90 -N110 -B108'\n self.f77_opt = '-O -B101'\n\n self.libraries = ['fio', 'f77math', 'f90math']\n \n try:\n dir = os.environ['ABSOFT'] \n self.library_dirs = [os.path.join(dir,'lib')]\n except KeyError:\n self.library_dirs = []\n\n self.ver_cmd = self.f77_compiler + ' -V -c %s -o %s' % \\\n self.dummy_fortran_files()\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -p' + mod\n return res\n\n def get_extra_link_args(self):\n return []\n # Couldn't get this to link for anything using gcc.\n #dr = \"c:\\\\Absoft62\\\\lib\"\n #libs = ['fio.lib', 'COMDLG32.lib','fmath.lib', 'f90math.lib','libcomdlg32.a' ] \n #libs = map(lambda x,dr=dr:os.path.join(dr,x),libs)\n #return libs\n\n\nclass sun_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Sun'\n ver_match = r'f77: (?P[^\\s*,]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc # not tested\n self.f77_switches = ' -pic '\n self.f77_opt = ' -fast -dalign '\n\n self.f90_compiler = f90c\n self.f90_switches = ' -fixed ' # ??? why fixed?\n self.f90_opt = ' -fast -dalign '\n\n self.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\n #threaded\n #self.libraries = ['f90', 'F77_mt', 'sunmath_mt', 'm', 'thread']\n #self.libraries = []\n self.library_dirs = self.find_lib_dir()\n #print 'sun:',self.library_dirs\n\n self.ver_cmd = self.f77_compiler + ' -V'\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -M' + mod\n return res\n\n def find_lib_dir(self):\n library_dirs = []\n lib_match = r'### f90: Note: LD_RUN_PATH\\s*= '\\\n '(?P[^\\s.]*).*'\n cmd = self.f90_compiler + ' -dryrun dummy.f'\n exit_status, output = run_command(cmd)\n if not exit_status:\n libs = re.findall(lib_match,output)\n if libs:\n library_dirs = string.split(libs[0],':')\n self.get_version() # force version calculation\n compiler_home = os.path.dirname(library_dirs[0])\n library_dirs.append(os.path.join(compiler_home,\n self.version,'lib'))\n return library_dirs\n def get_runtime_library_dirs(self):\n return self.find_lib_dir()\n def get_extra_link_args(self):\n return ['-mimpure-text']\n\n\nclass mips_fortran_compiler(fortran_compiler_base):\n\n vendor = 'SGI'\n ver_match = r'MIPSpro Compilers: Version (?P[^\\s*,]*)'\n \n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc # not tested\n self.f77_switches = ' -n32 -KPIC '\n self.f77_opt = ' -O3 '\n\n self.f90_compiler = f90c\n self.f90_switches = ' -n32 -KPIC -fixedform ' # why fixed ???\n self.f90_opt = ' ' \n \n self.libraries = ['fortran', 'ftn', 'm']\n self.library_dirs = self.find_lib_dir()\n\n self.ver_cmd = self.f77_compiler + ' -version'\n\n def build_module_switch(self,module_dirs):\n res = ''\n return res \n def find_lib_dir(self):\n library_dirs = []\n return library_dirs\n def get_runtime_library_dirs(self):\n\treturn self.find_lib_dir() \n def get_extra_link_args(self):\n\treturn []\n\n\nclass gnu_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Gnu'\n ver_match = r'g77 version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if sys.platform == 'win32':\n self.libraries = ['gcc','g2c']\n self.library_dirs = self.find_lib_directories()\n else:\n # On linux g77 does not need lib_directories to be specified.\n self.libraries = ['g2c']\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n\n switches = ' -Wall -fno-second-underscore '\n\n if os.name != 'nt':\n switches = switches + ' -fpic '\n\n self.f77_switches = switches\n\n self.ver_cmd = self.f77_compiler + ' -v '\n self.f77_opt = self.get_opt()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 -funroll-loops '\n \n # only check for more optimization if g77 can handle\n # it.\n if self.get_version():\n if self.version[0]=='3': # is g77 3.x.x\n if cpu.is_AthlonK6():\n opt = opt + ' -march=k6 '\n elif cpu.is_AthlonK7():\n opt = opt + ' -march=athlon '\n if cpu.is_i686():\n opt = opt + ' -march=i686 '\n elif cpu.is_i586():\n opt = opt + ' -march=i586 '\n elif cpu.is_i486():\n opt = opt + ' -march=i486 '\n elif cpu.is_i386():\n opt = opt + ' -march=i386 '\n if cpu.is_Intel():\n opt = opt + ' -malign-double ' \n return opt\n \n def find_lib_directories(self):\n lib_dir = []\n match = r'Reading specs from (.*)/specs'\n\n # works I think only for unix... \n exit_status, out_text = run_command('g77 -v')\n if not exit_status:\n m = re.findall(match,out_text)\n if m:\n lib_dir= m #m[0] \n return lib_dir\n\n def get_linker_so(self):\n # win32 linking should be handled by standard linker\n if sys.platform != 'win32':\n return [self.f77_compiler,'-shared']\n \n def f90_compile(self,source_files,module_files,temp_dir=''):\n raise DistutilsExecError, 'f90 not supported by Gnu'\n\n\n#http://developer.intel.com/software/products/compilers/f50/linux/\nclass intel_ia32_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Intel' # Intel(R) Corporation \n ver_match = r'Intel\\(R\\) Fortran Compiler for 32-bit applications, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'ifc'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -KPIC '\n\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n if cpu.has_fdiv_bug():\n switches = switches + ' -fdiv_check '\n if cpu.has_f00f_bug():\n switches = switches + ' -0f_check '\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -FI -w90 -w95 '\n\n self.f77_opt = self.f90_opt = self.get_opt()\n \n debug = ' -g -C '\n self.f77_debug = self.f90_debug = debug\n\n self.ver_cmd = self.f77_compiler+' -FI -V -c %s -o %s' %\\\n self.dummy_fortran_files()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 '\n if cpu.is_PentiumPro() or cpu.is_PentiumII():\n opt = opt + ' -tpp6 -xi '\n elif cpu.is_PentiumIII():\n opt = opt + ' -tpp6 '\n elif cpu.is_Pentium():\n opt = opt + ' -tpp5 '\n elif cpu.is_PentiumIV():\n opt = opt + ' -tpp7 -xW '\n elif cpu.has_mmx():\n opt = opt + ' -xM '\n return opt\n \n\n def get_linker_so(self):\n return [self.f77_compiler,'-shared']\n\n\nclass intel_itanium_fortran_compiler(intel_ia32_fortran_compiler):\n\n vendor = 'Itanium'\n ver_match = r'Intel\\(R\\) Fortran 90 Compiler Itanium\\(TM\\) Compiler for the Itanium\\(TM\\)-based applications, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n if fc is None:\n fc = 'efc'\n intel_ia32_fortran_compiler.__init__(self, fc, f90c)\n\n\nclass nag_fortran_compiler(fortran_compiler_base):\n\n vendor = 'NAG'\n ver_match = r'NAGWare Fortran 95 compiler Release (?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'f95'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ''\n debug = ' -g -gline -g90 -nan -C '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -fixed '\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -target=native '\n return opt\n\n def get_linker_so(self):\n return [self.f77_compiler,'-Wl,-shared']\n\n\nclass vast_fortran_compiler(fortran_compiler_base):\n\n vendor = 'VAST'\n ver_match = r'\\s*Pacific-Sierra Research vf90 (Personal|Professional)\\s+(?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n d,b = os.path.split(f90c)\n vf90 = os.path.join(d,'v'+b)\n self.ver_cmd = vf90+' -v '\n\n gnu = gnu_fortran_compiler(fc)\n if not gnu.is_available(): # VAST compiler requires g77.\n self.version = ''\n return\n if not self.is_available():\n return\n\n self.f77_switches = gnu.f77_switches\n self.f77_debug = gnu.f77_debug\n self.f77_opt = gnu.f77_opt \n\n # XXX: need f90 switches, debug, opt\n\n def get_linker_so(self):\n return [self.f90_compiler,'-shared']\n\nclass compaq_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Compaq'\n ver_match = r'Compaq Fortran (?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'fort'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -assume no2underscore -nomixed_str_len_arg '\n debug = ' -g -check_bounds '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n # XXX: uncomment if required\n #self.libraries = ' -lUfor -lfor -lFutil -lcpml -lots -lc '\n\n # XXX: fix the version showing flag\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -align dcommons -arch host -assume bigarrays -assume nozsize -math_library fast -tune host '\n return opt\n\n def get_linker_so(self):\n # XXX: is -shared needed?\n return [self.f77_compiler,'-shared']\n\n\ndef match_extension(files,ext):\n match = re.compile(r'.*[.]('+ext+r')\\Z',re.I).match\n return filter(lambda x,match = match: match(x),files)\n\ndef get_f77_files(files):\n return match_extension(files,'for|f77|ftn|f')\n\ndef get_f90_files(files):\n return match_extension(files,'f90|f95')\n\ndef get_fortran_files(files):\n return match_extension(files,'f90|f95|for|f77|ftn|f')\n\ndef find_fortran_compiler(vendor = None, fc = None, f90c = None):\n fcompiler = None\n for compiler_class in all_compilers:\n if vendor is not None and vendor != compiler_class.vendor:\n continue\n print compiler_class\n compiler = compiler_class(fc,f90c)\n if compiler.is_available():\n fcompiler = compiler\n break\n return fcompiler\n\nall_compilers = [absoft_fortran_compiler,\n mips_fortran_compiler,\n sun_fortran_compiler,\n intel_ia32_fortran_compiler,\n intel_itanium_fortran_compiler,\n nag_fortran_compiler,\n compaq_fortran_compiler,\n vast_fortran_compiler,\n gnu_fortran_compiler,\n ]\n\nif __name__ == \"__main__\":\n show_compilers()\n", + "methods": [ + { + "name": "run_command", + "long_name": "run_command( command )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 1, + "token_count": 32, + "parameters": [ + "command" + ], + "start_line": 58, + "end_line": 63, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "show_compilers", + "long_name": "show_compilers( )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 3, + "token_count": 23, + "parameters": [], + "start_line": 67, + "end_line": 71, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "build_flib.py", + "nloc": 11, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 101, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "build_flib.py", + "nloc": 17, + "complexity": 3, + "token_count": 104, + "parameters": [ + "self" + ], + "start_line": 117, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "has_f_libraries", + "long_name": "has_f_libraries( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 2, + "token_count": 23, + "parameters": [ + "self" + ], + "start_line": 137, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 141, + "end_line": 144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "has_f_library", + "long_name": "has_f_library( self , name )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 4, + "token_count": 32, + "parameters": [ + "self", + "name" + ], + "start_line": 148, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "get_library_names", + "long_name": "get_library_names( self , name = None )", + "filename": "build_flib.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "name" + ], + "start_line": 154, + "end_line": 174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "get_fcompiler_library_names", + "long_name": "get_fcompiler_library_names( self )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 176, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_fcompiler_library_dirs", + "long_name": "get_fcompiler_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 183, + "end_line": 188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self , name = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 7, + "token_count": 109, + "parameters": [ + "self", + "name" + ], + "start_line": 192, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 213, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_flib.py", + "nloc": 8, + "complexity": 3, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 226, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "build_libraries", + "long_name": "build_libraries( self , fortran_libraries )", + "filename": "build_flib.py", + "nloc": 18, + "complexity": 5, + "token_count": 122, + "parameters": [ + "self", + "fortran_libraries" + ], + "start_line": 239, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "build_flib.py", + "nloc": 16, + "complexity": 3, + "token_count": 88, + "parameters": [ + "self" + ], + "start_line": 272, + "end_line": 293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "to_object", + "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 13, + "complexity": 3, + "token_count": 89, + "parameters": [ + "self", + "dirty_files", + "module_dirs", + "temp_dir" + ], + "start_line": 295, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "source_to_object_names", + "long_name": "source_to_object_names( self , source_files , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 6, + "complexity": 1, + "token_count": 89, + "parameters": [ + "self", + "source_files", + "temp_dir" + ], + "start_line": 309, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "source_and_object_pairs", + "long_name": "source_and_object_pairs( self , source_files , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self", + "source_files", + "temp_dir" + ], + "start_line": 316, + "end_line": 319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "f_compile", + "long_name": "f_compile( self , compiler , switches , source_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 4, + "token_count": 103, + "parameters": [ + "self", + "compiler", + "switches", + "source_files", + "module_dirs", + "temp_dir" + ], + "start_line": 321, + "end_line": 335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "f90_compile", + "long_name": "f90_compile( self , source_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 1, + "token_count": 48, + "parameters": [ + "self", + "source_files", + "module_dirs", + "temp_dir" + ], + "start_line": 339, + "end_line": 342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "f77_compile", + "long_name": "f77_compile( self , source_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 1, + "token_count": 48, + "parameters": [ + "self", + "source_files", + "module_dirs", + "temp_dir" + ], + "start_line": 344, + "end_line": 347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 350, + "end_line": 351, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "create_static_lib", + "long_name": "create_static_lib( self , object_files , library_name , output_dir = '' , debug = None )", + "filename": "build_flib.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "object_files", + "library_name", + "output_dir", + "debug" + ], + "start_line": 353, + "end_line": 364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "build_library", + "long_name": "build_library( self , library_name , source_list , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 13, + "complexity": 3, + "token_count": 104, + "parameters": [ + "self", + "library_name", + "source_list", + "module_dirs", + "temp_dir" + ], + "start_line": 366, + "end_line": 392, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "dummy_fortran_files", + "long_name": "dummy_fortran_files( self )", + "filename": "build_flib.py", + "nloc": 8, + "complexity": 1, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 394, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "is_available", + "long_name": "is_available( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 403, + "end_line": 404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "build_flib.py", + "nloc": 10, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 406, + "end_line": 424, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 426, + "end_line": 427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 428, + "end_line": 429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 430, + "end_line": 431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 432, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 1, + "complexity": 1, + "token_count": 6, + "parameters": [ + "self" + ], + "start_line": 434, + "end_line": 439, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 441, + "end_line": 442, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 31, + "complexity": 5, + "token_count": 177, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 450, + "end_line": 488, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 6, + "complexity": 3, + "token_count": 27, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 490, + "end_line": 495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 497, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 98, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 511, + "end_line": 533, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 6, + "complexity": 3, + "token_count": 27, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 535, + "end_line": 540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "find_lib_dir", + "long_name": "find_lib_dir( self )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 99, + "parameters": [ + "self" + ], + "start_line": 542, + "end_line": 556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 557, + "end_line": 558, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 559, + "end_line": 560, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 94, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 568, + "end_line": 586, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 588, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "find_lib_dir", + "long_name": "find_lib_dir( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 591, + "end_line": 593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 594, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 596, + "end_line": 597, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 18, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 605, + "end_line": 629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 21, + "complexity": 10, + "token_count": 120, + "parameters": [ + "self" + ], + "start_line": 631, + "end_line": 654, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "find_lib_directories", + "long_name": "find_lib_directories( self )", + "filename": "build_flib.py", + "nloc": 9, + "complexity": 3, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 656, + "end_line": 666, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 2, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 668, + "end_line": 671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "f90_compile", + "long_name": "f90_compile( self , source_files , module_files , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "source_files", + "module_files", + "temp_dir" + ], + "start_line": 673, + "end_line": 674, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 22, + "complexity": 5, + "token_count": 140, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 683, + "end_line": 711, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 7, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 713, + "end_line": 727, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 730, + "end_line": 731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 739, + "end_line": 742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 100, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 750, + "end_line": 769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 771, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 775, + "end_line": 776, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 20, + "complexity": 5, + "token_count": 128, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 784, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 812, + "end_line": 813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 14, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 820, + "end_line": 842, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 844, + "end_line": 846, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 848, + "end_line": 850, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "match_extension", + "long_name": "match_extension( files , ext )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 44, + "parameters": [ + "files", + "ext" + ], + "start_line": 853, + "end_line": 855, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_f77_files", + "long_name": "get_f77_files( files )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "files" + ], + "start_line": 857, + "end_line": 858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_f90_files", + "long_name": "get_f90_files( files )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "files" + ], + "start_line": 860, + "end_line": 861, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_fortran_files", + "long_name": "get_fortran_files( files )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "files" + ], + "start_line": 863, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "find_fortran_compiler", + "long_name": "find_fortran_compiler( vendor = None , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 11, + "complexity": 5, + "token_count": 59, + "parameters": [ + "vendor", + "fc", + "f90c" + ], + "start_line": 866, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "run_command", + "long_name": "run_command( command )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 1, + "token_count": 32, + "parameters": [ + "command" + ], + "start_line": 58, + "end_line": 63, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "show_compilers", + "long_name": "show_compilers( )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 3, + "token_count": 23, + "parameters": [], + "start_line": 67, + "end_line": 71, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "build_flib.py", + "nloc": 11, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 101, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "build_flib.py", + "nloc": 17, + "complexity": 3, + "token_count": 104, + "parameters": [ + "self" + ], + "start_line": 117, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "has_f_libraries", + "long_name": "has_f_libraries( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 2, + "token_count": 23, + "parameters": [ + "self" + ], + "start_line": 137, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 141, + "end_line": 144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "has_f_library", + "long_name": "has_f_library( self , name )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 4, + "token_count": 32, + "parameters": [ + "self", + "name" + ], + "start_line": 148, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "get_library_names", + "long_name": "get_library_names( self , name = None )", + "filename": "build_flib.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "name" + ], + "start_line": 154, + "end_line": 174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "get_fcompiler_library_names", + "long_name": "get_fcompiler_library_names( self )", + "filename": "build_flib.py", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 176, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_fcompiler_library_dirs", + "long_name": "get_fcompiler_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 6, + "complexity": 3, + "token_count": 34, + "parameters": [ + "self" + ], + "start_line": 183, + "end_line": 188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self , name = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 7, + "token_count": 109, + "parameters": [ + "self", + "name" + ], + "start_line": 192, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 7, + "complexity": 3, + "token_count": 42, + "parameters": [ + "self" + ], + "start_line": 213, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_flib.py", + "nloc": 8, + "complexity": 3, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 226, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "build_libraries", + "long_name": "build_libraries( self , fortran_libraries )", + "filename": "build_flib.py", + "nloc": 18, + "complexity": 5, + "token_count": 122, + "parameters": [ + "self", + "fortran_libraries" + ], + "start_line": 239, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "build_flib.py", + "nloc": 16, + "complexity": 3, + "token_count": 88, + "parameters": [ + "self" + ], + "start_line": 272, + "end_line": 293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "to_object", + "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 13, + "complexity": 3, + "token_count": 89, + "parameters": [ + "self", + "dirty_files", + "module_dirs", + "temp_dir" + ], + "start_line": 295, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "source_to_object_names", + "long_name": "source_to_object_names( self , source_files , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 6, + "complexity": 1, + "token_count": 89, + "parameters": [ + "self", + "source_files", + "temp_dir" + ], + "start_line": 309, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "source_and_object_pairs", + "long_name": "source_and_object_pairs( self , source_files , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self", + "source_files", + "temp_dir" + ], + "start_line": 316, + "end_line": 319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "f_compile", + "long_name": "f_compile( self , compiler , switches , source_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 4, + "token_count": 103, + "parameters": [ + "self", + "compiler", + "switches", + "source_files", + "module_dirs", + "temp_dir" + ], + "start_line": 321, + "end_line": 335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "f90_compile", + "long_name": "f90_compile( self , source_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 1, + "token_count": 48, + "parameters": [ + "self", + "source_files", + "module_dirs", + "temp_dir" + ], + "start_line": 339, + "end_line": 342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "f77_compile", + "long_name": "f77_compile( self , source_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 1, + "token_count": 48, + "parameters": [ + "self", + "source_files", + "module_dirs", + "temp_dir" + ], + "start_line": 344, + "end_line": 347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 350, + "end_line": 351, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "create_static_lib", + "long_name": "create_static_lib( self , object_files , library_name , output_dir = '' , debug = None )", + "filename": "build_flib.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "object_files", + "library_name", + "output_dir", + "debug" + ], + "start_line": 353, + "end_line": 364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "build_library", + "long_name": "build_library( self , library_name , source_list , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 13, + "complexity": 3, + "token_count": 104, + "parameters": [ + "self", + "library_name", + "source_list", + "module_dirs", + "temp_dir" + ], + "start_line": 366, + "end_line": 392, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "dummy_fortran_files", + "long_name": "dummy_fortran_files( self )", + "filename": "build_flib.py", + "nloc": 8, + "complexity": 1, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 394, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "is_available", + "long_name": "is_available( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 403, + "end_line": 404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "build_flib.py", + "nloc": 10, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 406, + "end_line": 424, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 426, + "end_line": 427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 428, + "end_line": 429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 430, + "end_line": 431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 432, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 1, + "complexity": 1, + "token_count": 6, + "parameters": [ + "self" + ], + "start_line": 434, + "end_line": 439, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 441, + "end_line": 442, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 31, + "complexity": 5, + "token_count": 177, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 450, + "end_line": 488, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 6, + "complexity": 3, + "token_count": 27, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 490, + "end_line": 495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 497, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 98, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 511, + "end_line": 533, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 6, + "complexity": 3, + "token_count": 27, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 535, + "end_line": 540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "find_lib_dir", + "long_name": "find_lib_dir( self )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 99, + "parameters": [ + "self" + ], + "start_line": 542, + "end_line": 556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 557, + "end_line": 558, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 559, + "end_line": 560, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 94, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 568, + "end_line": 586, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 588, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "find_lib_dir", + "long_name": "find_lib_dir( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 591, + "end_line": 593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 594, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 596, + "end_line": 597, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 18, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 605, + "end_line": 629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 21, + "complexity": 10, + "token_count": 120, + "parameters": [ + "self" + ], + "start_line": 631, + "end_line": 654, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "find_lib_directories", + "long_name": "find_lib_directories( self )", + "filename": "build_flib.py", + "nloc": 9, + "complexity": 3, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 656, + "end_line": 666, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 2, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 668, + "end_line": 671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "f90_compile", + "long_name": "f90_compile( self , source_files , module_files , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "source_files", + "module_files", + "temp_dir" + ], + "start_line": 673, + "end_line": 674, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 22, + "complexity": 5, + "token_count": 140, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 683, + "end_line": 711, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 7, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 713, + "end_line": 727, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 730, + "end_line": 731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 739, + "end_line": 742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 100, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 750, + "end_line": 769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 771, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 775, + "end_line": 776, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 20, + "complexity": 5, + "token_count": 128, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 784, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 812, + "end_line": 813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 14, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 820, + "end_line": 842, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 844, + "end_line": 846, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 848, + "end_line": 850, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "match_extension", + "long_name": "match_extension( files , ext )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 44, + "parameters": [ + "files", + "ext" + ], + "start_line": 853, + "end_line": 855, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_f77_files", + "long_name": "get_f77_files( files )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "files" + ], + "start_line": 857, + "end_line": 858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_f90_files", + "long_name": "get_f90_files( files )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "files" + ], + "start_line": 860, + "end_line": 861, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_fortran_files", + "long_name": "get_fortran_files( files )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "files" + ], + "start_line": 863, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "find_fortran_compiler", + "long_name": "find_fortran_compiler( vendor = None , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 11, + "complexity": 5, + "token_count": 59, + "parameters": [ + "vendor", + "fc", + "f90c" + ], + "start_line": 866, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "get_fcompiler_library_dirs", + "long_name": "get_fcompiler_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 183, + "end_line": 188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_fcompiler_library_names", + "long_name": "get_fcompiler_library_names( self )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 176, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 213, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "nloc": 640, + "complexity": 165, + "token_count": 3720, + "diff_parsed": { + "added": [ + " #if not self.has_f_libraries():", + " # return None", + " #if not self.has_f_libraries():", + " # return None", + " #if not self.has_f_libraries():", + " # return []" + ], + "deleted": [ + " if not self.has_f_libraries():", + " return None", + " if not self.has_f_libraries():", + " return None", + " if not self.has_f_libraries():", + " return []" + ] + } + }, + { + "old_path": "scipy_distutils/system_info.py", + "new_path": "scipy_distutils/system_info.py", + "filename": "system_info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -39,7 +39,7 @@\n from distutils.sysconfig import get_config_vars\n \n if sys.platform == 'win32':\n- prefixes = ['C:'] # XXX: what is prefix in win32?\n+ prefixes = ['C:\\\\'] # XXX: what is prefix in win32?\n else:\n prefixes = ['/usr','/usr/local','/opt']\n if sys.prefix not in prefixes:\n", + "added_lines": 1, + "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 fftw_info\n x11_info\nThe following environment variables are used if defined:\n ATLAS - path to ATLAS library\n FFTW - path to FFTW library\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw'.\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 (or system_info could not find it).\n\nGlobal parameters:\n prefixes - a list of prefixes for scanning the location of\n resources.\n system_info.static_first - a flag for indicating that static\n libraries are searched first than shared ones.\n system_info.verbose - show the results if set.\n\nAuthor:\n Pearu Peterson , February 2002\nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re,types,pprint\nfrom glob import glob\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n prefixes = ['C:\\\\'] # XXX: what is prefix in win32?\nelse:\n prefixes = ['/usr','/usr/local','/opt']\nif sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\nprefixes = filter(os.path.isdir,prefixes) # XXX: Is this ok on win32? Is 'C:' dir?\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name):\n cl = {'atlas':atlas_info,\n 'x11':x11_info,\n 'fftw':fftw_info}.get(name.lower(),system_info)\n return cl().get_info()\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n\n static_first = 1\n verbose = 1\n need_refresh = 1\n saved_results = {}\n \n def __init__ (self):\n self.__class__.info = {}\n #self.__class__.need_refresh = not self.info\n self.local_prefixes = []\n\n def set_info(self,**info):\n #self.__class__.info = info\n self.saved_results[self.__class__.__name__] = info\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n def get_info(self):\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.verbose:\n print self.__class__.__name__ + ':'\n for p in self.local_prefixes + prefixes:\n if self.verbose:\n print ' Looking in',p,'...'\n self.calc_info(p)\n if self.has_info(): break\n if self.verbose:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbose and flag:\n for k,v in res.items():\n print ' %s = %s'%(k,v)\n print\n return res\n\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\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 mths = [self.check_static_libs,self.check_shared_libs]\n if not self.static_first:\n mths.reverse() # if one prefers shared libraries\n for m in mths:\n info = m(lib_dir,libs,opt_libs)\n if info is not None: return info\n\n def check_static_libs(self,lib_dir,libs,opt_libs =[]):\n #XXX: what are .lib and .dll files under win32?\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs])) == len(libs):\n info = {'libraries':libs,'library_dirs':[lib_dir]}\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs]))\\\n ==len(opt_libs):\n info['libraries'].extend(opt_libs)\n return info\n\n def check_shared_libs(self,lib_dir,libs,opt_libs =[]):\n shared_libs = []\n for l in libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: shared_libs.append(p)\n if len(shared_libs) == len(libs):\n info = {'extra_objects':shared_libs}\n opt_shared_libs = []\n for l in opt_libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: opt_shared_libs.append(p)\n info['extra_objects'].extend(opt_shared_libs)\n return info\n\n\nclass fftw_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('FFTW')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self,prefix):\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,'lib',['fftw*','FFTW*']))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'lib'))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','fftw*','FFTW*']))\n \n if not lib_dirs: return\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,'include',['fftw*','FFTW*']))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'include'))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['include','fftw*','FFTW*']))\n if not incl_dirs: return\n incl_dir = None\n\n libs = ['fftw','rfftw']\n opt_libs = ['fftw_threads','rfftw_threads']\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['fftw.h','rfftw.h']))==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=[('SCIPY_FFTW_H',1)])\n else:\n info = None\n\n if info is None:\n libs = ['dfftw','drfftw']\n opt_libs = ['dfftw_threads','drfftw_threads']\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['dfftw.h','drfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n incl_dirs = [d]\n incl_dir = d\n flag = 1\n break\n if flag:\n dict_append(info,define_macros=[('SCIPY_DFFTW_H',1)])\n else:\n info = None\n \n libs = ['sfftw','srfftw']\n opt_libs = ['sfftw_threads','srfftw_threads']\n flag = 0\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_libs)\n if r is not None:\n if info is None: info = r\n else: dict_append(info,**r)\n flag = 1\n break\n if info is not None and flag:\n for d in incl_dirs:\n if len(combine_paths(d,['sfftw.h','srfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n dict_append(info,define_macros=[('SCIPY_SFFTW_H',1)])\n break\n if info is not None:\n self.set_info(**info)\n\n\nclass atlas_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('ATLAS')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self, prefix):\n lib_dirs = filter(os.path.isdir,combine_paths(prefix,'lib',\n ['atlas*','ATLAS*']))\n if lib_dirs:\n other_dirs = filter(os.path.isdir,combine_paths(lib_dirs,'*'))\n other_dirs.extend(filter(os.path.isdir,combine_paths(prefix,'lib')))\n lib_dirs.extend(other_dirs)\n else:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','atlas*','ATLAS*']))\n if not lib_dirs:\n lib_dirs = [prefix]\n\n h = (combine_paths(lib_dirs,'cblas.h') or [None])[0]\n if not h:\n h = (combine_paths(lib_dirs,'include','cblas.h') or [None])[0]\n if h: h = os.path.dirname(h)\n\n libs = ['lapack','f77blas','cblas','atlas']\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 None: return\n if h: dict_append(info,include_dirs=h)\n self.set_info(**info)\n\n\nclass blas_info(system_info):\n # For Fortran or optimized blas, not atlas.\n pass\n\n\nclass lapack_info(system_info):\n # For Fortran or optimized lapack, not atlas\n pass\n\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = self.check_libs(lib_dir[0],['X11'],[])\n if info is None:\n continue\n dict_append(info,include_dirs=[inc_dir])\n self.set_info(**info)\n\ndef shortest_path(pths):\n pths.sort()\n if pths: return pths[0]\n\ndef combine_paths(*args):\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 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 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 r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\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 fftw_info\n x11_info\nThe following environment variables are used if defined:\n ATLAS - path to ATLAS library\n FFTW - path to FFTW library\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw'.\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 (or system_info could not find it).\n\nGlobal parameters:\n prefixes - a list of prefixes for scanning the location of\n resources.\n system_info.static_first - a flag for indicating that static\n libraries are searched first than shared ones.\n system_info.verbose - show the results if set.\n\nAuthor:\n Pearu Peterson , February 2002\nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re,types,pprint\nfrom glob import glob\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n prefixes = ['C:'] # XXX: what is prefix in win32?\nelse:\n prefixes = ['/usr','/usr/local','/opt']\nif sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\nprefixes = filter(os.path.isdir,prefixes) # XXX: Is this ok on win32? Is 'C:' dir?\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name):\n cl = {'atlas':atlas_info,\n 'x11':x11_info,\n 'fftw':fftw_info}.get(name.lower(),system_info)\n return cl().get_info()\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n\n static_first = 1\n verbose = 1\n need_refresh = 1\n saved_results = {}\n \n def __init__ (self):\n self.__class__.info = {}\n #self.__class__.need_refresh = not self.info\n self.local_prefixes = []\n\n def set_info(self,**info):\n #self.__class__.info = info\n self.saved_results[self.__class__.__name__] = info\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n def get_info(self):\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.verbose:\n print self.__class__.__name__ + ':'\n for p in self.local_prefixes + prefixes:\n if self.verbose:\n print ' Looking in',p,'...'\n self.calc_info(p)\n if self.has_info(): break\n if self.verbose:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbose and flag:\n for k,v in res.items():\n print ' %s = %s'%(k,v)\n print\n return res\n\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\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 mths = [self.check_static_libs,self.check_shared_libs]\n if not self.static_first:\n mths.reverse() # if one prefers shared libraries\n for m in mths:\n info = m(lib_dir,libs,opt_libs)\n if info is not None: return info\n\n def check_static_libs(self,lib_dir,libs,opt_libs =[]):\n #XXX: what are .lib and .dll files under win32?\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs])) == len(libs):\n info = {'libraries':libs,'library_dirs':[lib_dir]}\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs]))\\\n ==len(opt_libs):\n info['libraries'].extend(opt_libs)\n return info\n\n def check_shared_libs(self,lib_dir,libs,opt_libs =[]):\n shared_libs = []\n for l in libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: shared_libs.append(p)\n if len(shared_libs) == len(libs):\n info = {'extra_objects':shared_libs}\n opt_shared_libs = []\n for l in opt_libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: opt_shared_libs.append(p)\n info['extra_objects'].extend(opt_shared_libs)\n return info\n\n\nclass fftw_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('FFTW')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self,prefix):\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,'lib',['fftw*','FFTW*']))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'lib'))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','fftw*','FFTW*']))\n \n if not lib_dirs: return\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,'include',['fftw*','FFTW*']))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'include'))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['include','fftw*','FFTW*']))\n if not incl_dirs: return\n incl_dir = None\n\n libs = ['fftw','rfftw']\n opt_libs = ['fftw_threads','rfftw_threads']\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['fftw.h','rfftw.h']))==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=[('SCIPY_FFTW_H',1)])\n else:\n info = None\n\n if info is None:\n libs = ['dfftw','drfftw']\n opt_libs = ['dfftw_threads','drfftw_threads']\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['dfftw.h','drfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n incl_dirs = [d]\n incl_dir = d\n flag = 1\n break\n if flag:\n dict_append(info,define_macros=[('SCIPY_DFFTW_H',1)])\n else:\n info = None\n \n libs = ['sfftw','srfftw']\n opt_libs = ['sfftw_threads','srfftw_threads']\n flag = 0\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_libs)\n if r is not None:\n if info is None: info = r\n else: dict_append(info,**r)\n flag = 1\n break\n if info is not None and flag:\n for d in incl_dirs:\n if len(combine_paths(d,['sfftw.h','srfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n dict_append(info,define_macros=[('SCIPY_SFFTW_H',1)])\n break\n if info is not None:\n self.set_info(**info)\n\n\nclass atlas_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('ATLAS')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self, prefix):\n lib_dirs = filter(os.path.isdir,combine_paths(prefix,'lib',\n ['atlas*','ATLAS*']))\n if lib_dirs:\n other_dirs = filter(os.path.isdir,combine_paths(lib_dirs,'*'))\n other_dirs.extend(filter(os.path.isdir,combine_paths(prefix,'lib')))\n lib_dirs.extend(other_dirs)\n else:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','atlas*','ATLAS*']))\n if not lib_dirs:\n lib_dirs = [prefix]\n\n h = (combine_paths(lib_dirs,'cblas.h') or [None])[0]\n if not h:\n h = (combine_paths(lib_dirs,'include','cblas.h') or [None])[0]\n if h: h = os.path.dirname(h)\n\n libs = ['lapack','f77blas','cblas','atlas']\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 None: return\n if h: dict_append(info,include_dirs=h)\n self.set_info(**info)\n\n\nclass blas_info(system_info):\n # For Fortran or optimized blas, not atlas.\n pass\n\n\nclass lapack_info(system_info):\n # For Fortran or optimized lapack, not atlas\n pass\n\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = self.check_libs(lib_dir[0],['X11'],[])\n if info is None:\n continue\n dict_append(info,include_dirs=[inc_dir])\n self.set_info(**info)\n\ndef shortest_path(pths):\n pths.sort()\n if pths: return pths[0]\n\ndef combine_paths(*args):\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 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 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 r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n", + "methods": [ + { + "name": "get_info", + "long_name": "get_info( name )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 1, + "token_count": 39, + "parameters": [ + "name" + ], + "start_line": 51, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 67, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "set_info", + "long_name": "set_info( self , ** info )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "info" + ], + "start_line": 72, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "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": 75, + "end_line": 76, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 11, + "token_count": 134, + "parameters": [ + "self" + ], + "start_line": 77, + "end_line": 102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 104, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 60, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 107, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_static_libs", + "long_name": "check_static_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 5, + "token_count": 91, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 117, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_shared_libs", + "long_name": "check_shared_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 13, + "complexity": 6, + "token_count": 119, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 126, + "end_line": 138, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 143, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 82, + "complexity": 30, + "token_count": 553, + "parameters": [ + "self", + "prefix" + ], + "start_line": 151, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 241, + "end_line": 247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 11, + "token_count": 229, + "parameters": [ + "self", + "prefix" + ], + "start_line": 249, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "prefix" + ], + "start_line": 291, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "shortest_path", + "long_name": "shortest_path( pths )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "pths" + ], + "start_line": 309, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 9, + "token_count": 162, + "parameters": [ + "args" + ], + "start_line": 313, + "end_line": 334, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 336, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [], + "start_line": 343, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "get_info", + "long_name": "get_info( name )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 1, + "token_count": 39, + "parameters": [ + "name" + ], + "start_line": 51, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 67, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "set_info", + "long_name": "set_info( self , ** info )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "info" + ], + "start_line": 72, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "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": 75, + "end_line": 76, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 11, + "token_count": 134, + "parameters": [ + "self" + ], + "start_line": 77, + "end_line": 102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 104, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 60, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 107, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_static_libs", + "long_name": "check_static_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 5, + "token_count": 91, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 117, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_shared_libs", + "long_name": "check_shared_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 13, + "complexity": 6, + "token_count": 119, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 126, + "end_line": 138, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 143, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 82, + "complexity": 30, + "token_count": 553, + "parameters": [ + "self", + "prefix" + ], + "start_line": 151, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 241, + "end_line": 247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 11, + "token_count": 229, + "parameters": [ + "self", + "prefix" + ], + "start_line": 249, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "prefix" + ], + "start_line": 291, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "shortest_path", + "long_name": "shortest_path( pths )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "pths" + ], + "start_line": 309, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 9, + "token_count": 162, + "parameters": [ + "args" + ], + "start_line": 313, + "end_line": 334, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 336, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [], + "start_line": 343, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 298, + "complexity": 103, + "token_count": 1962, + "diff_parsed": { + "added": [ + " prefixes = ['C:\\\\'] # XXX: what is prefix in win32?" + ], + "deleted": [ + " prefixes = ['C:'] # XXX: what is prefix in win32?" + ] + } + } + ] + }, + { + "hash": "75d348683333d757c769b1d0d1a117e05bcc1260", + "msg": "Python 2.0 support", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-02-23T09:46:27+00:00", + "author_timezone": 0, + "committer_date": "2002-02-23T09:46:27+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "c22540a20f509e9f94a522567cbb5d2c1b8a96e9" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 7, + "insertions": 5, + "lines": 12, + "files": 5, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "scipy_distutils/command/build.py", + "new_path": "scipy_distutils/command/build.py", + "filename": "build.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -2,7 +2,6 @@\n # This class must be used as the entry for the build key in the cmdclass\n # dictionary which is given to the setup command.\n \n-from distutils.command.build import *\n from distutils.command.build import build as old_build\n \n class build(old_build):\n", + "added_lines": 0, + "deleted_lines": 1, + "source_code": "# Need to override the build command to include building of fortran libraries\n# This class must be used as the entry for the build key in the cmdclass\n# dictionary which is given to the setup command.\n\nfrom distutils.command.build import build as old_build\n\nclass build(old_build):\n def has_f_libraries(self):\n return self.distribution.has_f_libraries()\n def has_f2py_sources(self):\n return self.distribution.has_f2py_sources()\n\n sub_commands = [('build_py', old_build.has_pure_modules),\n ('build_clib', old_build.has_c_libraries),\n ('run_f2py', has_f2py_sources), # new feature\n ('build_flib', has_f_libraries), # new feature\n ('build_ext', old_build.has_ext_modules),\n ('build_scripts', old_build.has_scripts),\n ]\n", + "source_code_before": "# Need to override the build command to include building of fortran libraries\n# This class must be used as the entry for the build key in the cmdclass\n# dictionary which is given to the setup command.\n\nfrom distutils.command.build import *\nfrom distutils.command.build import build as old_build\n\nclass build(old_build):\n def has_f_libraries(self):\n return self.distribution.has_f_libraries()\n def has_f2py_sources(self):\n return self.distribution.has_f2py_sources()\n\n sub_commands = [('build_py', old_build.has_pure_modules),\n ('build_clib', old_build.has_c_libraries),\n ('run_f2py', has_f2py_sources), # new feature\n ('build_flib', has_f_libraries), # new feature\n ('build_ext', old_build.has_ext_modules),\n ('build_scripts', old_build.has_scripts),\n ]\n", + "methods": [ + { + "name": "has_f_libraries", + "long_name": "has_f_libraries( self )", + "filename": "build.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 8, + "end_line": 9, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "has_f2py_sources", + "long_name": "has_f2py_sources( self )", + "filename": "build.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 10, + "end_line": 11, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "has_f_libraries", + "long_name": "has_f_libraries( self )", + "filename": "build.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 9, + "end_line": 10, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "has_f2py_sources", + "long_name": "has_f2py_sources( self )", + "filename": "build.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 11, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + } + ], + "changed_methods": [], + "nloc": 13, + "complexity": 2, + "token_count": 92, + "diff_parsed": { + "added": [], + "deleted": [ + "from distutils.command.build import *" + ] + } + }, + { + "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": "@@ -5,7 +5,6 @@\n from types import *\n \n from distutils.dep_util import newer_group, newer\n-from distutils.command.build_ext import *\n from distutils.command.build_ext import build_ext as old_build_ext\n \n from scipy_distutils.command.build_clib import get_headers,get_directories\n@@ -40,7 +39,7 @@ def build_extension(self, ext):\n if need_f_libs:\n if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n- ext.libraries.append(ext_name)\n+ ext.libraries.insert(0,ext_name)\n for lib_name in ext.libraries[:]:\n ext.libraries.extend(build_flib.get_library_names(lib_name))\n ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))\n@@ -103,3 +102,5 @@ def get_source_files (self):\n filenames.extend(get_headers(get_directories(ext.sources)))\n \n return filenames\n+\n+ \n", + "added_lines": 3, + "deleted_lines": 2, + "source_code": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os, string\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n #XXX: anything else we need to save?\n save_linker_so = self.compiler.linker_so\n save_compiler_libs = self.compiler.libraries\n save_compiler_libs_dirs = self.compiler.library_dirs\n \n # support for building static fortran libraries\n need_f_libs = 0\n need_f_opts = getattr(ext,'need_fcompiler_opts',0)\n ext_name = string.split(ext.name,'.')[-1]\n\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n if build_flib.has_f_library(ext_name):\n need_f_libs = 1\n else:\n for lib_name in ext.libraries:\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n elif need_f_opts:\n build_flib = self.get_finalized_command('build_flib')\n print ext.name,ext_name,'needs fortran libraries',\\\n need_f_libs,need_f_opts\n \n if need_f_libs:\n if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.insert(0,ext_name)\n for lib_name in ext.libraries[:]:\n ext.libraries.extend(build_flib.get_library_names(lib_name))\n ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))\n \n ext.library_dirs.append(build_flib.build_flib)\n\n if need_f_libs or need_f_opts:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n if moreargs != []:\n if ext.extra_link_args is None:\n ext.extra_link_args = moreargs\n else:\n ext.extra_link_args += moreargs\n\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n\n linker_so = build_flib.fcompiler.get_linker_so()\n\n if linker_so is not None:\n if linker_so is not save_linker_so:\n print 'replacing linker_so %s with %s' %(save_linker_so,linker_so)\n self.compiler.linker_so = linker_so\n l = build_flib.get_fcompiler_library_names()\n #l = self.compiler.libraries + l\n self.compiler.libraries = l\n l = build_flib.get_fcompiler_library_dirs()\n #l = self.compiler.library_dirs + l\n self.compiler.library_dirs = l\n else:\n libs = build_flib.get_fcompiler_library_names()\n for lib in libs:\n if lib not in self.compiler.libraries:\n self.compiler.libraries.append(lib)\n #self.compiler.libraries = self.compiler.libraries + l\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n if lib_dir not in self.compiler.library_dirs:\n self.compiler.libraries.append(lib_dir)\n #self.compiler.library_dirs = self.compiler.library_dirs + l\n \n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n\n if save_linker_so is not self.compiler.linker_so:\n print 'restoring linker_so',save_linker_so\n self.compiler.linker_so = save_linker_so\n self.compiler.libraries = save_compiler_libs\n self.compiler.library_dirs = save_compiler_libs_dirs\n\n return res\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n filenames.extend(ext.sources)\n filenames.extend(get_headers(get_directories(ext.sources)))\n\n return filenames\n\n \n", + "source_code_before": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os, string\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import *\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n #XXX: anything else we need to save?\n save_linker_so = self.compiler.linker_so\n save_compiler_libs = self.compiler.libraries\n save_compiler_libs_dirs = self.compiler.library_dirs\n \n # support for building static fortran libraries\n need_f_libs = 0\n need_f_opts = getattr(ext,'need_fcompiler_opts',0)\n ext_name = string.split(ext.name,'.')[-1]\n\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n if build_flib.has_f_library(ext_name):\n need_f_libs = 1\n else:\n for lib_name in ext.libraries:\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n elif need_f_opts:\n build_flib = self.get_finalized_command('build_flib')\n print ext.name,ext_name,'needs fortran libraries',\\\n need_f_libs,need_f_opts\n \n if need_f_libs:\n if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.append(ext_name)\n for lib_name in ext.libraries[:]:\n ext.libraries.extend(build_flib.get_library_names(lib_name))\n ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))\n \n ext.library_dirs.append(build_flib.build_flib)\n\n if need_f_libs or need_f_opts:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n if moreargs != []:\n if ext.extra_link_args is None:\n ext.extra_link_args = moreargs\n else:\n ext.extra_link_args += moreargs\n\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n\n linker_so = build_flib.fcompiler.get_linker_so()\n\n if linker_so is not None:\n if linker_so is not save_linker_so:\n print 'replacing linker_so %s with %s' %(save_linker_so,linker_so)\n self.compiler.linker_so = linker_so\n l = build_flib.get_fcompiler_library_names()\n #l = self.compiler.libraries + l\n self.compiler.libraries = l\n l = build_flib.get_fcompiler_library_dirs()\n #l = self.compiler.library_dirs + l\n self.compiler.library_dirs = l\n else:\n libs = build_flib.get_fcompiler_library_names()\n for lib in libs:\n if lib not in self.compiler.libraries:\n self.compiler.libraries.append(lib)\n #self.compiler.libraries = self.compiler.libraries + l\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n if lib_dir not in self.compiler.library_dirs:\n self.compiler.libraries.append(lib_dir)\n #self.compiler.library_dirs = self.compiler.library_dirs + l\n \n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n\n if save_linker_so is not self.compiler.linker_so:\n print 'restoring linker_so',save_linker_so\n self.compiler.linker_so = save_linker_so\n self.compiler.libraries = save_compiler_libs\n self.compiler.library_dirs = save_compiler_libs_dirs\n\n return res\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n filenames.extend(ext.sources)\n filenames.extend(get_headers(get_directories(ext.sources)))\n\n return filenames\n", + "methods": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 62, + "complexity": 22, + "token_count": 439, + "parameters": [ + "self", + "ext" + ], + "start_line": 14, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_ext.py", + "nloc": 7, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 95, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 62, + "complexity": 22, + "token_count": 437, + "parameters": [ + "self", + "ext" + ], + "start_line": 15, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_ext.py", + "nloc": 7, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 96, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 62, + "complexity": 22, + "token_count": 439, + "parameters": [ + "self", + "ext" + ], + "start_line": 14, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 1 + } + ], + "nloc": 77, + "complexity": 24, + "token_count": 532, + "diff_parsed": { + "added": [ + " ext.libraries.insert(0,ext_name)", + "", + "" + ], + "deleted": [ + "from distutils.command.build_ext import *", + " ext.libraries.append(ext_name)" + ] + } + }, + { + "old_path": "scipy_distutils/command/run_f2py.py", + "new_path": "scipy_distutils/command/run_f2py.py", + "filename": "run_f2py.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -102,7 +102,8 @@ def f2py_sources (self, sources, ext):\n if source_ext == \".pyf\": # f2py interface file\n # get extension module name\n f = open(source)\n- for line in f.xreadlines():\n+ f_readlines = getattr(f,'xreadlines',f.readlines)\n+ for line in f_readlines():\n m = module_name_re(line)\n if m:\n if user_module_name_re(line): # skip *__user__* names\n@@ -173,7 +174,6 @@ def f2py_sources (self, sources, ext):\n new_sources.append(target)\n if os.path.exists(fortran_target):\n new_sources.append(fortran_target)\n-\n return new_sources\n \n # f2py_sources ()\n", + "added_lines": 2, + "deleted_lines": 2, + "source_code": "\"\"\"distutils.command.run_f2py\n\nImplements the Distutils 'run_f2py' command.\n\"\"\"\n\n# created 2002/01/09, Pearu Peterson \n\n__revision__ = \"$Id$\"\n\nfrom distutils.dep_util import newer\nfrom scipy_distutils.core import Command\n\nimport re,os\n\nmodule_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',re.I).match\nuser_module_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?__user__[\\w_]*)',re.I).match\nfortran_ext_re = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\n\nclass run_f2py(Command):\n\n description = \"\\\"run_f2py\\\" runs f2py that builds Fortran wrapper sources\"\\\n \"(C and occasionally Fortran).\"\n\n user_options = [('build-dir=', 'b',\n \"directory to build fortran wrappers to\"),\n ('debug-capi', None,\n \"generate C/API extensions with debugging code\"),\n ('no-wrap-functions', None,\n \"do not generate wrappers for Fortran functions,etc.\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ]\n\n def initialize_options (self):\n self.build_dir = None\n self.debug_capi = None\n self.force = None\n self.no_wrap_functions = None\n self.f2py_options = []\n # initialize_options()\n\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_dir'),\n ('force', 'force'))\n\n self.f2py_options.extend(['--build-dir',self.build_dir])\n\n if self.debug_capi is not None:\n self.f2py_options.append('--debug-capi')\n if self.no_wrap_functions is not None:\n self.f2py_options.append('--no-wrap-functions')\n\n # finalize_options()\n\n def run (self):\n if self.distribution.has_ext_modules():\n # XXX: might need also\n # build_flib = self.get_finalized_command('build_flib')\n # ...\n # for getting extra f2py_options that are specific to\n # a given fortran compiler.\n for ext in self.distribution.ext_modules:\n ext.sources = self.f2py_sources(ext.sources,ext)\n self.fortran_sources_to_flib(ext)\n # run()\n\n def f2py_sources (self, sources, ext):\n\n \"\"\"Walk the list of source files in 'sources', looking for f2py\n interface (.pyf) files. Run f2py on all that are found, and\n return a modified 'sources' list with f2py source files replaced\n by the generated C (or C++) and Fortran files.\n If 'sources' contains not .pyf files, then create a temporary\n one from the Fortran files in 'sources'.\n \"\"\"\n import string\n import f2py2e\n # f2py generates the following files for an extension module\n # with a name :\n # module.c\n # -f2pywrappers.f [occasionally]\n # In addition, /src/fortranobject.{c,h} are needed\n # for building f2py generated extension modules.\n # It is assumed that one pyf file contains defintions for exactly\n # one extension module.\n\n target_dir = self.build_dir\n \n new_sources = []\n f2py_sources = []\n fortran_sources = []\n f2py_targets = {}\n f2py_fortran_targets = {}\n target_ext = 'module.c'\n fortran_target_ext = '-f2pywrappers.f'\n\n for source in sources:\n (base, source_ext) = os.path.splitext(source)\n (source_dir, base) = os.path.split(base)\n if source_ext == \".pyf\": # f2py interface file\n # get extension module name\n f = open(source)\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = module_name_re(line)\n if m:\n if user_module_name_re(line): # skip *__user__* names\n continue\n base = m.group('name')\n break\n f.close()\n if ext.name == 'untitled':\n ext.name = base\n if base != string.split(ext.name,'.')[-1]:\n # XXX: Should we do here more than just warn?\n self.warn('%s provides %s but this extension is %s' \\\n % (source,`base`,`ext.name`))\n target_file = os.path.join(target_dir,base+target_ext)\n fortran_target_file = os.path.join(target_dir,base+fortran_target_ext)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n f2py_fortran_targets[source] = fortran_target_file\n elif fortran_ext_re(source_ext):\n fortran_sources.append(source) \n else:\n new_sources.append(source)\n\n if not (f2py_sources or fortran_sources):\n return new_sources\n\n # make sure the target dir exists\n from distutils.dir_util import mkpath\n mkpath(target_dir)\n\n if not f2py_sources:\n # creating a temporary pyf file from fortran sources\n pyf_target = os.path.join(target_dir,ext.name+'.pyf')\n pyf_target_file = os.path.join(target_dir,ext.name+target_ext)\n pyf_fortran_target_file = os.path.join(target_dir,ext.name+fortran_target_ext)\n f2py_opts2 = ['-m',ext.name,'-h',pyf_target,'--overwrite-signature']\n for source in fortran_sources:\n if newer(source,pyf_target) or self.force:\n self.announce(\"f2py-ing a new %s\" % (pyf_target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_opts2,' '))\n f2py2e.run_main(fortran_sources + f2py_opts2)\n break\n f2py_sources.append(pyf_target)\n f2py_targets[pyf_target] = pyf_target_file\n f2py_fortran_targets[pyf_target] = pyf_fortran_target_file\n\n new_sources.extend(fortran_sources)\n\n if len(f2py_sources) > 1:\n self.warn('Only one .pyf file can be used per Extension but got %s.'\\\n % (len(f2py_sources)))\n\n # a bit of a hack, but I think it'll work. Just include one of\n # the fortranobject.c files that was copied into most \n d = os.path.dirname(f2py2e.__file__)\n new_sources.append(os.path.join(d,'src','fortranobject.c'))\n ext.include_dirs.append(os.path.join(d,'src'))\n\n f2py_options = ext.f2py_options + self.f2py_options\n\n for source in f2py_sources:\n target = f2py_targets[source]\n fortran_target = f2py_fortran_targets[source]\n if newer(source,target) or self.force:\n self.announce(\"f2py-ing %s to %s\" % (source, target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_options,' '))\n f2py2e.run_main(f2py_options + [source])\n new_sources.append(target)\n if os.path.exists(fortran_target):\n new_sources.append(fortran_target)\n return new_sources\n\n # f2py_sources ()\n\n def fortran_sources_to_flib(self, ext):\n \"\"\"\n Extract fortran files from ext.sources and append them to\n fortran_libraries item having the same name as ext.\n \"\"\"\n sources = []\n f_files = []\n\n for file in ext.sources:\n if fortran_ext_re(file):\n f_files.append(file)\n else:\n sources.append(file)\n if not f_files:\n return\n\n ext.sources = sources\n\n if self.distribution.fortran_libraries is None:\n self.distribution.fortran_libraries = []\n fortran_libraries = self.distribution.fortran_libraries\n\n name = ext.name\n flib = None\n for n,d in fortran_libraries:\n if n == name:\n flib = d\n break\n if flib is None:\n flib = {'sources':[]}\n fortran_libraries.append((name,flib))\n\n flib['sources'].extend(f_files)\n \n# class run_f2py\n", + "source_code_before": "\"\"\"distutils.command.run_f2py\n\nImplements the Distutils 'run_f2py' command.\n\"\"\"\n\n# created 2002/01/09, Pearu Peterson \n\n__revision__ = \"$Id$\"\n\nfrom distutils.dep_util import newer\nfrom scipy_distutils.core import Command\n\nimport re,os\n\nmodule_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',re.I).match\nuser_module_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?__user__[\\w_]*)',re.I).match\nfortran_ext_re = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\n\nclass run_f2py(Command):\n\n description = \"\\\"run_f2py\\\" runs f2py that builds Fortran wrapper sources\"\\\n \"(C and occasionally Fortran).\"\n\n user_options = [('build-dir=', 'b',\n \"directory to build fortran wrappers to\"),\n ('debug-capi', None,\n \"generate C/API extensions with debugging code\"),\n ('no-wrap-functions', None,\n \"do not generate wrappers for Fortran functions,etc.\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ]\n\n def initialize_options (self):\n self.build_dir = None\n self.debug_capi = None\n self.force = None\n self.no_wrap_functions = None\n self.f2py_options = []\n # initialize_options()\n\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_dir'),\n ('force', 'force'))\n\n self.f2py_options.extend(['--build-dir',self.build_dir])\n\n if self.debug_capi is not None:\n self.f2py_options.append('--debug-capi')\n if self.no_wrap_functions is not None:\n self.f2py_options.append('--no-wrap-functions')\n\n # finalize_options()\n\n def run (self):\n if self.distribution.has_ext_modules():\n # XXX: might need also\n # build_flib = self.get_finalized_command('build_flib')\n # ...\n # for getting extra f2py_options that are specific to\n # a given fortran compiler.\n for ext in self.distribution.ext_modules:\n ext.sources = self.f2py_sources(ext.sources,ext)\n self.fortran_sources_to_flib(ext)\n # run()\n\n def f2py_sources (self, sources, ext):\n\n \"\"\"Walk the list of source files in 'sources', looking for f2py\n interface (.pyf) files. Run f2py on all that are found, and\n return a modified 'sources' list with f2py source files replaced\n by the generated C (or C++) and Fortran files.\n If 'sources' contains not .pyf files, then create a temporary\n one from the Fortran files in 'sources'.\n \"\"\"\n import string\n import f2py2e\n # f2py generates the following files for an extension module\n # with a name :\n # module.c\n # -f2pywrappers.f [occasionally]\n # In addition, /src/fortranobject.{c,h} are needed\n # for building f2py generated extension modules.\n # It is assumed that one pyf file contains defintions for exactly\n # one extension module.\n\n target_dir = self.build_dir\n \n new_sources = []\n f2py_sources = []\n fortran_sources = []\n f2py_targets = {}\n f2py_fortran_targets = {}\n target_ext = 'module.c'\n fortran_target_ext = '-f2pywrappers.f'\n\n for source in sources:\n (base, source_ext) = os.path.splitext(source)\n (source_dir, base) = os.path.split(base)\n if source_ext == \".pyf\": # f2py interface file\n # get extension module name\n f = open(source)\n for line in f.xreadlines():\n m = module_name_re(line)\n if m:\n if user_module_name_re(line): # skip *__user__* names\n continue\n base = m.group('name')\n break\n f.close()\n if ext.name == 'untitled':\n ext.name = base\n if base != string.split(ext.name,'.')[-1]:\n # XXX: Should we do here more than just warn?\n self.warn('%s provides %s but this extension is %s' \\\n % (source,`base`,`ext.name`))\n target_file = os.path.join(target_dir,base+target_ext)\n fortran_target_file = os.path.join(target_dir,base+fortran_target_ext)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n f2py_fortran_targets[source] = fortran_target_file\n elif fortran_ext_re(source_ext):\n fortran_sources.append(source) \n else:\n new_sources.append(source)\n\n if not (f2py_sources or fortran_sources):\n return new_sources\n\n # make sure the target dir exists\n from distutils.dir_util import mkpath\n mkpath(target_dir)\n\n if not f2py_sources:\n # creating a temporary pyf file from fortran sources\n pyf_target = os.path.join(target_dir,ext.name+'.pyf')\n pyf_target_file = os.path.join(target_dir,ext.name+target_ext)\n pyf_fortran_target_file = os.path.join(target_dir,ext.name+fortran_target_ext)\n f2py_opts2 = ['-m',ext.name,'-h',pyf_target,'--overwrite-signature']\n for source in fortran_sources:\n if newer(source,pyf_target) or self.force:\n self.announce(\"f2py-ing a new %s\" % (pyf_target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_opts2,' '))\n f2py2e.run_main(fortran_sources + f2py_opts2)\n break\n f2py_sources.append(pyf_target)\n f2py_targets[pyf_target] = pyf_target_file\n f2py_fortran_targets[pyf_target] = pyf_fortran_target_file\n\n new_sources.extend(fortran_sources)\n\n if len(f2py_sources) > 1:\n self.warn('Only one .pyf file can be used per Extension but got %s.'\\\n % (len(f2py_sources)))\n\n # a bit of a hack, but I think it'll work. Just include one of\n # the fortranobject.c files that was copied into most \n d = os.path.dirname(f2py2e.__file__)\n new_sources.append(os.path.join(d,'src','fortranobject.c'))\n ext.include_dirs.append(os.path.join(d,'src'))\n\n f2py_options = ext.f2py_options + self.f2py_options\n\n for source in f2py_sources:\n target = f2py_targets[source]\n fortran_target = f2py_fortran_targets[source]\n if newer(source,target) or self.force:\n self.announce(\"f2py-ing %s to %s\" % (source, target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_options,' '))\n f2py2e.run_main(f2py_options + [source])\n new_sources.append(target)\n if os.path.exists(fortran_target):\n new_sources.append(fortran_target)\n\n return new_sources\n\n # f2py_sources ()\n\n def fortran_sources_to_flib(self, ext):\n \"\"\"\n Extract fortran files from ext.sources and append them to\n fortran_libraries item having the same name as ext.\n \"\"\"\n sources = []\n f_files = []\n\n for file in ext.sources:\n if fortran_ext_re(file):\n f_files.append(file)\n else:\n sources.append(file)\n if not f_files:\n return\n\n ext.sources = sources\n\n if self.distribution.fortran_libraries is None:\n self.distribution.fortran_libraries = []\n fortran_libraries = self.distribution.fortran_libraries\n\n name = ext.name\n flib = None\n for n,d in fortran_libraries:\n if n == name:\n flib = d\n break\n if flib is None:\n flib = {'sources':[]}\n fortran_libraries.append((name,flib))\n\n flib['sources'].extend(f_files)\n \n# class run_f2py\n", + "methods": [ + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "run_f2py.py", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 39, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "run_f2py.py", + "nloc": 9, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 43, + "end_line": 53, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "run_f2py.py", + "nloc": 5, + "complexity": 3, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 57, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "f2py_sources", + "long_name": "f2py_sources( self , sources , ext )", + "filename": "run_f2py.py", + "nloc": 76, + "complexity": 20, + "token_count": 584, + "parameters": [ + "self", + "sources", + "ext" + ], + "start_line": 69, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 1 + }, + { + "name": "fortran_sources_to_flib", + "long_name": "fortran_sources_to_flib( self , ext )", + "filename": "run_f2py.py", + "nloc": 24, + "complexity": 8, + "token_count": 133, + "parameters": [ + "self", + "ext" + ], + "start_line": 181, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "run_f2py.py", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 39, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "run_f2py.py", + "nloc": 9, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 43, + "end_line": 53, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "run_f2py.py", + "nloc": 5, + "complexity": 3, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 57, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "f2py_sources", + "long_name": "f2py_sources( self , sources , ext )", + "filename": "run_f2py.py", + "nloc": 75, + "complexity": 20, + "token_count": 574, + "parameters": [ + "self", + "sources", + "ext" + ], + "start_line": 69, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 1 + }, + { + "name": "fortran_sources_to_flib", + "long_name": "fortran_sources_to_flib( self , ext )", + "filename": "run_f2py.py", + "nloc": 24, + "complexity": 8, + "token_count": 133, + "parameters": [ + "self", + "ext" + ], + "start_line": 181, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "f2py_sources", + "long_name": "f2py_sources( self , sources , ext )", + "filename": "run_f2py.py", + "nloc": 76, + "complexity": 20, + "token_count": 584, + "parameters": [ + "self", + "sources", + "ext" + ], + "start_line": 69, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 1 + } + ], + "nloc": 143, + "complexity": 35, + "token_count": 977, + "diff_parsed": { + "added": [ + " f_readlines = getattr(f,'xreadlines',f.readlines)", + " for line in f_readlines():" + ], + "deleted": [ + " for line in f.xreadlines():", + "" + ] + } + }, + { + "old_path": "scipy_distutils/core.py", + "new_path": "scipy_distutils/core.py", + "filename": "core.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -31,7 +31,6 @@ def setup(**attr):\n 'install': install.install,\n 'install_headers': install_headers.install_headers\n }\n- \n new_attr = attr.copy()\n if new_attr.has_key('cmdclass'):\n cmdclass.update(new_attr['cmdclass']) \n", + "added_lines": 0, + "deleted_lines": 1, + "source_code": "from distutils.core import *\nfrom distutils.core import setup as old_setup\n\nfrom distutils.cmd import Command\nfrom scipy_distutils.extension import Extension\n\n# Our dist is different than the standard one.\nfrom scipy_distutils.dist import Distribution\n\nfrom scipy_distutils.command import build\nfrom scipy_distutils.command import build_py\nfrom scipy_distutils.command import build_ext\nfrom scipy_distutils.command import build_clib\nfrom scipy_distutils.command import build_flib\nfrom scipy_distutils.command import run_f2py\nfrom scipy_distutils.command import sdist\nfrom scipy_distutils.command import install_data\nfrom scipy_distutils.command import install\nfrom scipy_distutils.command import install_headers\n\ndef setup(**attr):\n distclass = Distribution\n cmdclass = {'build': build.build,\n 'build_flib': build_flib.build_flib,\n 'build_ext': build_ext.build_ext,\n 'build_py': build_py.build_py, \n 'build_clib': build_clib.build_clib,\n 'run_f2py': run_f2py.run_f2py,\n 'sdist': sdist.sdist,\n 'install_data': install_data.install_data,\n 'install': install.install,\n 'install_headers': install_headers.install_headers\n }\n new_attr = attr.copy()\n if new_attr.has_key('cmdclass'):\n cmdclass.update(new_attr['cmdclass']) \n new_attr['cmdclass'] = cmdclass\n \n if not new_attr.has_key('distclass'):\n new_attr['distclass'] = distclass \n \n return old_setup(**new_attr)\n", + "source_code_before": "from distutils.core import *\nfrom distutils.core import setup as old_setup\n\nfrom distutils.cmd import Command\nfrom scipy_distutils.extension import Extension\n\n# Our dist is different than the standard one.\nfrom scipy_distutils.dist import Distribution\n\nfrom scipy_distutils.command import build\nfrom scipy_distutils.command import build_py\nfrom scipy_distutils.command import build_ext\nfrom scipy_distutils.command import build_clib\nfrom scipy_distutils.command import build_flib\nfrom scipy_distutils.command import run_f2py\nfrom scipy_distutils.command import sdist\nfrom scipy_distutils.command import install_data\nfrom scipy_distutils.command import install\nfrom scipy_distutils.command import install_headers\n\ndef setup(**attr):\n distclass = Distribution\n cmdclass = {'build': build.build,\n 'build_flib': build_flib.build_flib,\n 'build_ext': build_ext.build_ext,\n 'build_py': build_py.build_py, \n 'build_clib': build_clib.build_clib,\n 'run_f2py': run_f2py.run_f2py,\n 'sdist': sdist.sdist,\n 'install_data': install_data.install_data,\n 'install': install.install,\n 'install_headers': install_headers.install_headers\n }\n \n new_attr = attr.copy()\n if new_attr.has_key('cmdclass'):\n cmdclass.update(new_attr['cmdclass']) \n new_attr['cmdclass'] = cmdclass\n \n if not new_attr.has_key('distclass'):\n new_attr['distclass'] = distclass \n \n return old_setup(**new_attr)\n", + "methods": [ + { + "name": "setup", + "long_name": "setup( ** attr )", + "filename": "core.py", + "nloc": 20, + "complexity": 3, + "token_count": 123, + "parameters": [ + "attr" + ], + "start_line": 21, + "end_line": 42, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "setup", + "long_name": "setup( ** attr )", + "filename": "core.py", + "nloc": 20, + "complexity": 3, + "token_count": 123, + "parameters": [ + "attr" + ], + "start_line": 21, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "setup", + "long_name": "setup( ** attr )", + "filename": "core.py", + "nloc": 20, + "complexity": 3, + "token_count": 123, + "parameters": [ + "attr" + ], + "start_line": 21, + "end_line": 43, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + } + ], + "nloc": 35, + "complexity": 3, + "token_count": 216, + "diff_parsed": { + "added": [], + "deleted": [ + "" + ] + } + }, + { + "old_path": "scipy_distutils/misc_util.py", + "new_path": "scipy_distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -165,7 +165,6 @@ def get_path(mod_name):\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n- #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n", + "added_lines": 0, + "deleted_lines": 1, + "source_code": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = sys._getframe(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef 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 ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", + "source_code_before": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n #import scipy_distutils.setup\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = sys._getframe(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef 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 ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", + "methods": [ + { + "name": "update_version", + "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", + "filename": "misc_util.py", + "nloc": 65, + "complexity": 12, + "token_count": 351, + "parameters": [ + "release_level", + "path", + "major", + "overwrite_version_py" + ], + "start_line": 3, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "get_version", + "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "release_level", + "path", + "major" + ], + "start_line": 111, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "get_cvs_revision", + "long_name": "get_cvs_revision( path )", + "filename": "misc_util.py", + "nloc": 21, + "complexity": 10, + "token_count": 190, + "parameters": [ + "path" + ], + "start_line": 127, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 156, + "end_line": 171, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 173, + "end_line": 175, + "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": 178, + "end_line": 181, + "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": 183, + "end_line": 184, + "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": 186, + "end_line": 200, + "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": 202, + "end_line": 212, + "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": 214, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 213, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 233, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "merge_config_dicts", + "long_name": "merge_config_dicts( config_list )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 4, + "token_count": 61, + "parameters": [ + "config_list" + ], + "start_line": 266, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 275, + "end_line": 280, + "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": 282, + "end_line": 283, + "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": 285, + "end_line": 300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "update_version", + "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", + "filename": "misc_util.py", + "nloc": 65, + "complexity": 12, + "token_count": 351, + "parameters": [ + "release_level", + "path", + "major", + "overwrite_version_py" + ], + "start_line": 3, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "get_version", + "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "release_level", + "path", + "major" + ], + "start_line": 111, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "get_cvs_revision", + "long_name": "get_cvs_revision( path )", + "filename": "misc_util.py", + "nloc": 21, + "complexity": 10, + "token_count": 190, + "parameters": [ + "path" + ], + "start_line": 127, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 156, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + }, + { + "name": "add_local_to_path", + "long_name": "add_local_to_path( mod_name )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 21, + "parameters": [ + "mod_name" + ], + "start_line": 174, + "end_line": 176, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "add_grandparent_to_path", + "long_name": "add_grandparent_to_path( mod_name )", + "filename": "misc_util.py", + "nloc": 4, + "complexity": 1, + "token_count": 34, + "parameters": [ + "mod_name" + ], + "start_line": 179, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 0 + }, + { + "name": "restore_path", + "long_name": "restore_path( )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [], + "start_line": 184, + "end_line": 185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "append_package_dir_to_path", + "long_name": "append_package_dir_to_path( package_name )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 64, + "parameters": [ + "package_name" + ], + "start_line": 187, + "end_line": 201, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "get_package_config", + "long_name": "get_package_config( package_name )", + "filename": "misc_util.py", + "nloc": 5, + "complexity": 1, + "token_count": 27, + "parameters": [ + "package_name" + ], + "start_line": 203, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + }, + { + "name": "package_config", + "long_name": "package_config( primary , dependencies = [ ] )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 53, + "parameters": [ + "primary", + "dependencies" + ], + "start_line": 215, + "end_line": 227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 213, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 234, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "merge_config_dicts", + "long_name": "merge_config_dicts( config_list )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 4, + "token_count": 61, + "parameters": [ + "config_list" + ], + "start_line": 267, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "misc_util.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 276, + "end_line": 281, + "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": 283, + "end_line": 284, + "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": 286, + "end_line": 301, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 156, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 0 + } + ], + "nloc": 191, + "complexity": 57, + "token_count": 1324, + "diff_parsed": { + "added": [], + "deleted": [ + " #import scipy_distutils.setup" + ] + } + } + ] + }, + { + "hash": "421cba8a32c44d28624d6bdc73188ffdc50de750", + "msg": "Py 2.0 support", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-02-23T10:51:19+00:00", + "author_timezone": 0, + "committer_date": "2002-02-23T10:51:19+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "75d348683333d757c769b1d0d1a117e05bcc1260" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 1, + "insertions": 9, + "lines": 10, + "files": 1, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "scipy_distutils/misc_util.py", + "new_path": "scipy_distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -240,7 +240,7 @@ def default_config_dict(name = None, parent_name = None):\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n- frame = sys._getframe(1)\n+ frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and parent_name is None:\n@@ -263,6 +263,14 @@ def default_config_dict(name = None, parent_name = None):\n break\n return d\n \n+def 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 def merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n", + "added_lines": 9, + "deleted_lines": 1, + "source_code": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef 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\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef 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 ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", + "source_code_before": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = sys._getframe(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef 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 ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", + "methods": [ + { + "name": "update_version", + "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", + "filename": "misc_util.py", + "nloc": 65, + "complexity": 12, + "token_count": 351, + "parameters": [ + "release_level", + "path", + "major", + "overwrite_version_py" + ], + "start_line": 3, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "get_version", + "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "release_level", + "path", + "major" + ], + "start_line": 111, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "get_cvs_revision", + "long_name": "get_cvs_revision( path )", + "filename": "misc_util.py", + "nloc": 21, + "complexity": 10, + "token_count": 190, + "parameters": [ + "path" + ], + "start_line": 127, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 156, + "end_line": 171, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 173, + "end_line": 175, + "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": 178, + "end_line": 181, + "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": 183, + "end_line": 184, + "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": 186, + "end_line": 200, + "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": 202, + "end_line": 212, + "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": 214, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 211, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 233, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "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": 266, + "end_line": 273, + "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": 8, + "complexity": 4, + "token_count": 61, + "parameters": [ + "config_list" + ], + "start_line": 274, + "end_line": 281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 283, + "end_line": 288, + "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": 290, + "end_line": 291, + "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": 293, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "update_version", + "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", + "filename": "misc_util.py", + "nloc": 65, + "complexity": 12, + "token_count": 351, + "parameters": [ + "release_level", + "path", + "major", + "overwrite_version_py" + ], + "start_line": 3, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "get_version", + "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "release_level", + "path", + "major" + ], + "start_line": 111, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "get_cvs_revision", + "long_name": "get_cvs_revision( path )", + "filename": "misc_util.py", + "nloc": 21, + "complexity": 10, + "token_count": 190, + "parameters": [ + "path" + ], + "start_line": 127, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 156, + "end_line": 171, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 173, + "end_line": 175, + "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": 178, + "end_line": 181, + "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": 183, + "end_line": 184, + "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": 186, + "end_line": 200, + "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": 202, + "end_line": 212, + "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": 214, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 213, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 233, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + }, + { + "name": "merge_config_dicts", + "long_name": "merge_config_dicts( config_list )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 4, + "token_count": 61, + "parameters": [ + "config_list" + ], + "start_line": 266, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 275, + "end_line": 280, + "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": 282, + "end_line": 283, + "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": 285, + "end_line": 300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "get_frame", + "long_name": "get_frame( level = 0 )", + "filename": "misc_util.py", + "nloc": 8, + "complexity": 3, + "token_count": 50, + "parameters": [ + "level" + ], + "start_line": 266, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 211, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 233, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 0 + } + ], + "nloc": 199, + "complexity": 60, + "token_count": 1373, + "diff_parsed": { + "added": [ + " frame = get_frame(1)", + "def get_frame(level=0):", + " try:", + " return sys._getframe(level+1)", + " except AttributeError:", + " frame = sys.exc_info()[2].tb_frame", + " for i in range(level+1):", + " frame = frame.f_back", + " return frame" + ], + "deleted": [ + " frame = sys._getframe(1)" + ] + } + } + ] + }, + { + "hash": "98b313f079374f9219d62ee48102afeccc7456d9", + "msg": "Some hacks to get NumPy working (arrgh!! import_array() call\nrequired!). Still not quite ready for prime time (though\ngetitem works on Numeric arrays). Still have to think through\nhow to deal with explict reference counting. It is likely\nbetter to test for contiguous arrays and convert to a int*\n(though we lose binops!).", + "author": { + "name": "patmiller", + "email": "patmiller@localhost" + }, + "committer": { + "name": "patmiller", + "email": "patmiller@localhost" + }, + "author_date": "2002-02-25T05:44:26+00:00", + "author_timezone": 0, + "committer_date": "2002-02-25T05:44:26+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "421cba8a32c44d28624d6bdc73188ffdc50de750" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 24, + "insertions": 52, + "lines": 76, + "files": 2, + "dmm_unit_size": 0.8928571428571429, + "dmm_unit_complexity": 0.8928571428571429, + "dmm_unit_interfacing": 0.6071428571428571, + "modified_files": [ + { + "old_path": "weave/accelerate_tools.py", + "new_path": "weave/accelerate_tools.py", + "filename": "accelerate_tools.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -31,6 +31,8 @@ def outbound(self,s):\n return \"%s(%s)\"%(self.outbounder,s)\n \n class Basic_Number(Basic):\n+ def literalizer(self,s):\n+ return str(s)\n def binop(self,symbol,a,b):\n assert symbol in ['+','-','*','/'],symbol\n return '%s %s %s'%(a,symbol,b),self\n@@ -60,22 +62,23 @@ def literalizer(self,s):\n \n class Vector(bytecodecompiler.Type_Descriptor):\n cxxtype = 'PyArrayObject*'\n+ refcount = 1\n prerequisites = bytecodecompiler.Type_Descriptor.prerequisites+\\\n- ['#include \"Numeric/arrayobject.h\"',\n- 'static PyObject* PyArray_AsPyObject(PyArrayObject* A) { PyObject* X = '\n- 'reinterpret_cast(A);'\n- 'std::cerr << \"Here in cast\" << std::endl;'\n- 'Py_XINCREF(X); return X;}']\n+ ['#include \"Numeric/arrayobject.h\"']\n dims = 1\n def check(self,s):\n- return \"PyArray_Check(%s) /* && dims==%d && typecode==%s */\"%(s,self.dims,self.typecode)\n+ return \"PyArray_Check(%s) && ((PyArrayObject*)%s)->nd == %d && ((PyArrayObject*)%s)->descr->type_num == %s\"%(\n+ s,s,self.dims,s,self.typecode)\n def inbound(self,s):\n return \"(PyArrayObject*)(%s)\"%s\n def outbound(self,s):\n return \"(PyObject*)(%s)\"%s\n+ def binopMixed(self,symbol,a,b):\n+ return '*((%s*)(%s->data+%s*%s->strides[0]))'%(self.cxxbase,a,b,a),Integer()\n \n class IntegerVector(Vector):\n- typecode = 'l'\n+ typecode = 'PyArray_INT'\n+ cxxbase = 'int'\n \n typedefs = {\n IntType: Integer(),\n@@ -108,18 +111,24 @@ def __init__(self, function, *args, **kw):\n import __main__\n self.module = __main__\n self.__call_map = {}\n- return\n \n- def __call__(self,*args):\n- # Figure out type info -- Do as tuple so its hashable\n- signature = tuple( map(lookup_type,args) )\n+ def __cache(self,*args):\n+ raise TypeError\n \n- # If we know the function, call it\n+ def __call__(self,*args):\n try:\n- return self.__call_map[signature](*args)\n- except:\n- fast = self.singleton(signature)\n- self.__call_map[signature] = fast\n+ return self.__cache(*args)\n+ except TypeError:\n+ # Figure out type info -- Do as tuple so its hashable\n+ signature = tuple( map(lookup_type,args) )\n+ \n+ # If we know the function, call it\n+ try:\n+ fast = self.__call_map[signature]\n+ except:\n+ fast = self.singleton(signature)\n+ self.__cache = fast\n+ self.__call_map[signature] = fast\n return fast(*args)\n \n def signature(self,*args):\n@@ -197,6 +206,7 @@ def __init__(self,f,signature,name=None):\n 1),'%s not all type objects'%signature\n self.arg_specs = []\n self.customize = weave.base_info.custom_info()\n+ self.customize.add_module_init_code('import_array()\\n')\n \n bytecodecompiler.CXXCoder.__init__(self,f,signature,name)\n return\n", + "added_lines": 26, + "deleted_lines": 16, + "source_code": "#**************************************************************************#\n#* FILE ************** accelerate_tools.py ************************#\n#**************************************************************************#\n#* Author: Patrick Miller February 9 2002 *#\n#**************************************************************************#\n\"\"\"\naccelerate_tools contains the interface for on-the-fly building of\nC++ equivalents to Python functions.\n\"\"\"\n#**************************************************************************#\n\nfrom types import FunctionType,IntType,FloatType,StringType,TypeType\nimport inspect\nimport md5\nimport weave\nimport bytecodecompiler\n\ndef CStr(s):\n \"Hacky way to get legal C string from Python string\"\n if s == None: return '\"\"'\n assert type(s) == StringType,\"Only None and string allowed\"\n r = repr('\"'+s) # Better for embedded quotes\n return '\"'+r[2:-1]+'\"'\n\nclass Basic(bytecodecompiler.Type_Descriptor):\n def check(self,s):\n return \"%s(%s)\"%(self.checker,s)\n def inbound(self,s):\n return \"%s(%s)\"%(self.inbounder,s)\n def outbound(self,s):\n return \"%s(%s)\"%(self.outbounder,s)\n\nclass Basic_Number(Basic):\n def literalizer(self,s):\n return str(s)\n def binop(self,symbol,a,b):\n assert symbol in ['+','-','*','/'],symbol\n return '%s %s %s'%(a,symbol,b),self\n\nclass Integer(Basic_Number):\n cxxtype = \"long\"\n checker = \"PyInt_Check\"\n inbounder = \"PyInt_AsLong\"\n outbounder = \"PyInt_FromLong\"\n\nclass Double(Basic_Number):\n cxxtype = \"double\"\n checker = \"PyFloat_Check\"\n inbounder = \"PyFloat_AsDouble\"\n outbounder = \"PyFloat_FromDouble\"\n\nclass String(Basic):\n cxxtype = \"char*\"\n checker = \"PyString_Check\"\n inbounder = \"PyString_AsString\"\n outbounder = \"PyString_FromString\"\n\n def literalizer(self,s):\n return CStr(s)\n\nimport Numeric\n\nclass Vector(bytecodecompiler.Type_Descriptor):\n cxxtype = 'PyArrayObject*'\n refcount = 1\n prerequisites = bytecodecompiler.Type_Descriptor.prerequisites+\\\n ['#include \"Numeric/arrayobject.h\"']\n dims = 1\n def check(self,s):\n return \"PyArray_Check(%s) && ((PyArrayObject*)%s)->nd == %d && ((PyArrayObject*)%s)->descr->type_num == %s\"%(\n s,s,self.dims,s,self.typecode)\n def inbound(self,s):\n return \"(PyArrayObject*)(%s)\"%s\n def outbound(self,s):\n return \"(PyObject*)(%s)\"%s\n def binopMixed(self,symbol,a,b):\n return '*((%s*)(%s->data+%s*%s->strides[0]))'%(self.cxxbase,a,b,a),Integer()\n\nclass IntegerVector(Vector):\n typecode = 'PyArray_INT'\n cxxbase = 'int'\n\ntypedefs = {\n IntType: Integer(),\n FloatType: Double(),\n StringType: String(),\n (Numeric.ArrayType,1,'l'): IntegerVector(),\n }\n\n\n##################################################################\n# FUNCTION LOOKUP_TYPE #\n##################################################################\ndef lookup_type(x):\n T = type(x)\n try:\n return typedefs[T]\n except:\n return typedefs[(T,len(x.shape),x.typecode())]\n\n##################################################################\n# class ACCELERATE #\n##################################################################\nclass accelerate:\n \n def __init__(self, function, *args, **kw):\n assert type(function) == FunctionType\n self.function = function\n self.module = inspect.getmodule(function)\n if self.module == None:\n import __main__\n self.module = __main__\n self.__call_map = {}\n\n def __cache(self,*args):\n raise TypeError\n\n def __call__(self,*args):\n try:\n return self.__cache(*args)\n except TypeError:\n # Figure out type info -- Do as tuple so its hashable\n signature = tuple( map(lookup_type,args) )\n \n # If we know the function, call it\n try:\n fast = self.__call_map[signature]\n except:\n fast = self.singleton(signature)\n self.__cache = fast\n self.__call_map[signature] = fast\n return fast(*args)\n\n def signature(self,*args):\n # Figure out type info -- Do as tuple so its hashable\n signature = tuple( map(lookup_type,args) )\n return self.singleton(signature)\n\n\n def singleton(self,signature):\n identifier = self.identifier(signature)\n \n # Generate a new function, then call it\n f = self.function\n\n # See if we have an accelerated version of module\n try:\n accelerated_module = __import__(self.module.__name__+'_weave')\n fast = getattr(accelerated_module,identifier)\n return fast\n except:\n accelerated_module = None\n\n P = self.accelerate(signature,identifier)\n\n E = weave.ext_tools.ext_module(self.module.__name__+'_weave')\n E.add_function(P)\n E.generate_file()\n weave.build_tools.build_extension(self.module.__name__+'_weave.cpp',verbose=2)\n\n if accelerated_module:\n accelerated_module = reload(accelerated_module)\n else:\n accelerated_module = __import__(self.module.__name__+'_weave')\n\n fast = getattr(accelerated_module,identifier)\n return fast\n\n def identifier(self,signature):\n # Build an MD5 checksum\n f = self.function\n co = f.func_code\n identifier = str(signature)+\\\n str(co.co_consts)+\\\n str(co.co_varnames)+\\\n co.co_code\n return 'F'+md5.md5(identifier).hexdigest()\n \n def accelerate(self,signature,identifier):\n P = Python2CXX(self.function,signature,name=identifier)\n return P\n\n def code(self,*args):\n signature = tuple( map(lookup_type,args) )\n ident = self.function.__name__\n return self.accelerate(signature,ident).function_code()\n \n\n##################################################################\n# CLASS PYTHON2CXX #\n##################################################################\nclass Python2CXX(bytecodecompiler.CXXCoder):\n def typedef_by_value(self,v):\n T = lookup_type(v)\n if T not in self.used: self.used.append(T)\n return T\n\n def __init__(self,f,signature,name=None):\n # Make sure function is a function\n import types\n assert type(f) == FunctionType\n # and check the input type signature\n assert reduce(lambda x,y: x and y,\n map(lambda x: isinstance(x,bytecodecompiler.Type_Descriptor),\n signature),\n 1),'%s not all type objects'%signature\n self.arg_specs = []\n self.customize = weave.base_info.custom_info()\n self.customize.add_module_init_code('import_array()\\n')\n\n bytecodecompiler.CXXCoder.__init__(self,f,signature,name)\n return\n\n def function_code(self):\n return self.wrapped_code()\n\n def python_function_definition_code(self):\n return '{ \"%s\", wrapper_%s, METH_VARARGS, %s },\\n'%(\n self.name,\n self.name,\n CStr(self.function.__doc__))\n", + "source_code_before": "#**************************************************************************#\n#* FILE ************** accelerate_tools.py ************************#\n#**************************************************************************#\n#* Author: Patrick Miller February 9 2002 *#\n#**************************************************************************#\n\"\"\"\naccelerate_tools contains the interface for on-the-fly building of\nC++ equivalents to Python functions.\n\"\"\"\n#**************************************************************************#\n\nfrom types import FunctionType,IntType,FloatType,StringType,TypeType\nimport inspect\nimport md5\nimport weave\nimport bytecodecompiler\n\ndef CStr(s):\n \"Hacky way to get legal C string from Python string\"\n if s == None: return '\"\"'\n assert type(s) == StringType,\"Only None and string allowed\"\n r = repr('\"'+s) # Better for embedded quotes\n return '\"'+r[2:-1]+'\"'\n\nclass Basic(bytecodecompiler.Type_Descriptor):\n def check(self,s):\n return \"%s(%s)\"%(self.checker,s)\n def inbound(self,s):\n return \"%s(%s)\"%(self.inbounder,s)\n def outbound(self,s):\n return \"%s(%s)\"%(self.outbounder,s)\n\nclass Basic_Number(Basic):\n def binop(self,symbol,a,b):\n assert symbol in ['+','-','*','/'],symbol\n return '%s %s %s'%(a,symbol,b),self\n\nclass Integer(Basic_Number):\n cxxtype = \"long\"\n checker = \"PyInt_Check\"\n inbounder = \"PyInt_AsLong\"\n outbounder = \"PyInt_FromLong\"\n\nclass Double(Basic_Number):\n cxxtype = \"double\"\n checker = \"PyFloat_Check\"\n inbounder = \"PyFloat_AsDouble\"\n outbounder = \"PyFloat_FromDouble\"\n\nclass String(Basic):\n cxxtype = \"char*\"\n checker = \"PyString_Check\"\n inbounder = \"PyString_AsString\"\n outbounder = \"PyString_FromString\"\n\n def literalizer(self,s):\n return CStr(s)\n\nimport Numeric\n\nclass Vector(bytecodecompiler.Type_Descriptor):\n cxxtype = 'PyArrayObject*'\n prerequisites = bytecodecompiler.Type_Descriptor.prerequisites+\\\n ['#include \"Numeric/arrayobject.h\"',\n 'static PyObject* PyArray_AsPyObject(PyArrayObject* A) { PyObject* X = '\n 'reinterpret_cast(A);'\n 'std::cerr << \"Here in cast\" << std::endl;'\n 'Py_XINCREF(X); return X;}']\n dims = 1\n def check(self,s):\n return \"PyArray_Check(%s) /* && dims==%d && typecode==%s */\"%(s,self.dims,self.typecode)\n def inbound(self,s):\n return \"(PyArrayObject*)(%s)\"%s\n def outbound(self,s):\n return \"(PyObject*)(%s)\"%s\n\nclass IntegerVector(Vector):\n typecode = 'l'\n\ntypedefs = {\n IntType: Integer(),\n FloatType: Double(),\n StringType: String(),\n (Numeric.ArrayType,1,'l'): IntegerVector(),\n }\n\n\n##################################################################\n# FUNCTION LOOKUP_TYPE #\n##################################################################\ndef lookup_type(x):\n T = type(x)\n try:\n return typedefs[T]\n except:\n return typedefs[(T,len(x.shape),x.typecode())]\n\n##################################################################\n# class ACCELERATE #\n##################################################################\nclass accelerate:\n \n def __init__(self, function, *args, **kw):\n assert type(function) == FunctionType\n self.function = function\n self.module = inspect.getmodule(function)\n if self.module == None:\n import __main__\n self.module = __main__\n self.__call_map = {}\n return\n\n def __call__(self,*args):\n # Figure out type info -- Do as tuple so its hashable\n signature = tuple( map(lookup_type,args) )\n\n # If we know the function, call it\n try:\n return self.__call_map[signature](*args)\n except:\n fast = self.singleton(signature)\n self.__call_map[signature] = fast\n return fast(*args)\n\n def signature(self,*args):\n # Figure out type info -- Do as tuple so its hashable\n signature = tuple( map(lookup_type,args) )\n return self.singleton(signature)\n\n\n def singleton(self,signature):\n identifier = self.identifier(signature)\n \n # Generate a new function, then call it\n f = self.function\n\n # See if we have an accelerated version of module\n try:\n accelerated_module = __import__(self.module.__name__+'_weave')\n fast = getattr(accelerated_module,identifier)\n return fast\n except:\n accelerated_module = None\n\n P = self.accelerate(signature,identifier)\n\n E = weave.ext_tools.ext_module(self.module.__name__+'_weave')\n E.add_function(P)\n E.generate_file()\n weave.build_tools.build_extension(self.module.__name__+'_weave.cpp',verbose=2)\n\n if accelerated_module:\n accelerated_module = reload(accelerated_module)\n else:\n accelerated_module = __import__(self.module.__name__+'_weave')\n\n fast = getattr(accelerated_module,identifier)\n return fast\n\n def identifier(self,signature):\n # Build an MD5 checksum\n f = self.function\n co = f.func_code\n identifier = str(signature)+\\\n str(co.co_consts)+\\\n str(co.co_varnames)+\\\n co.co_code\n return 'F'+md5.md5(identifier).hexdigest()\n \n def accelerate(self,signature,identifier):\n P = Python2CXX(self.function,signature,name=identifier)\n return P\n\n def code(self,*args):\n signature = tuple( map(lookup_type,args) )\n ident = self.function.__name__\n return self.accelerate(signature,ident).function_code()\n \n\n##################################################################\n# CLASS PYTHON2CXX #\n##################################################################\nclass Python2CXX(bytecodecompiler.CXXCoder):\n def typedef_by_value(self,v):\n T = lookup_type(v)\n if T not in self.used: self.used.append(T)\n return T\n\n def __init__(self,f,signature,name=None):\n # Make sure function is a function\n import types\n assert type(f) == FunctionType\n # and check the input type signature\n assert reduce(lambda x,y: x and y,\n map(lambda x: isinstance(x,bytecodecompiler.Type_Descriptor),\n signature),\n 1),'%s not all type objects'%signature\n self.arg_specs = []\n self.customize = weave.base_info.custom_info()\n\n bytecodecompiler.CXXCoder.__init__(self,f,signature,name)\n return\n\n def function_code(self):\n return self.wrapped_code()\n\n def python_function_definition_code(self):\n return '{ \"%s\", wrapper_%s, METH_VARARGS, %s },\\n'%(\n self.name,\n self.name,\n CStr(self.function.__doc__))\n", + "methods": [ + { + "name": "CStr", + "long_name": "CStr( s )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "s" + ], + "start_line": 18, + "end_line": 23, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "check", + "long_name": "check( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 26, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "inbound", + "long_name": "inbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 28, + "end_line": 29, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "outbound", + "long_name": "outbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 30, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "literalizer", + "long_name": "literalizer( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "s" + ], + "start_line": 34, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "binop", + "long_name": "binop( self , symbol , a , b )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 37, + "parameters": [ + "self", + "symbol", + "a", + "b" + ], + "start_line": 36, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "literalizer", + "long_name": "literalizer( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "s" + ], + "start_line": 58, + "end_line": 59, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check", + "long_name": "check( self , s )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self", + "s" + ], + "start_line": 69, + "end_line": 71, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "inbound", + "long_name": "inbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "s" + ], + "start_line": 72, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "outbound", + "long_name": "outbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "s" + ], + "start_line": 74, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "binopMixed", + "long_name": "binopMixed( self , symbol , a , b )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "symbol", + "a", + "b" + ], + "start_line": 76, + "end_line": 77, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "lookup_type", + "long_name": "lookup_type( x )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 2, + "token_count": 40, + "parameters": [ + "x" + ], + "start_line": 94, + "end_line": 99, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , function , * args , ** kw )", + "filename": "accelerate_tools.py", + "nloc": 8, + "complexity": 2, + "token_count": 55, + "parameters": [ + "self", + "function", + "args", + "kw" + ], + "start_line": 106, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__cache", + "long_name": "__cache( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "args" + ], + "start_line": 115, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 12, + "complexity": 3, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 118, + "end_line": 132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "signature", + "long_name": "signature( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "args" + ], + "start_line": 134, + "end_line": 137, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "singleton", + "long_name": "singleton( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 20, + "complexity": 3, + "token_count": 137, + "parameters": [ + "self", + "signature" + ], + "start_line": 140, + "end_line": 167, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "identifier", + "long_name": "identifier( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 8, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self", + "signature" + ], + "start_line": 169, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "accelerate", + "long_name": "accelerate( self , signature , identifier )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self", + "signature", + "identifier" + ], + "start_line": 179, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "code", + "long_name": "code( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 4, + "complexity": 1, + "token_count": 39, + "parameters": [ + "self", + "args" + ], + "start_line": 183, + "end_line": 186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "typedef_by_value", + "long_name": "typedef_by_value( self , v )", + "filename": "accelerate_tools.py", + "nloc": 4, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "v" + ], + "start_line": 193, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , f , signature , name = None )", + "filename": "accelerate_tools.py", + "nloc": 12, + "complexity": 2, + "token_count": 97, + "parameters": [ + "self", + "f", + "signature", + "name" + ], + "start_line": 198, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "function_code", + "long_name": "function_code( self )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 214, + "end_line": 215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "python_function_definition_code", + "long_name": "python_function_definition_code( self )", + "filename": "accelerate_tools.py", + "nloc": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 217, + "end_line": 221, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "CStr", + "long_name": "CStr( s )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "s" + ], + "start_line": 18, + "end_line": 23, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "check", + "long_name": "check( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 26, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "inbound", + "long_name": "inbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 28, + "end_line": 29, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "outbound", + "long_name": "outbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 30, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "binop", + "long_name": "binop( self , symbol , a , b )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 37, + "parameters": [ + "self", + "symbol", + "a", + "b" + ], + "start_line": 34, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "literalizer", + "long_name": "literalizer( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "s" + ], + "start_line": 56, + "end_line": 57, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check", + "long_name": "check( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "s" + ], + "start_line": 70, + "end_line": 71, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "inbound", + "long_name": "inbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "s" + ], + "start_line": 72, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "outbound", + "long_name": "outbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "s" + ], + "start_line": 74, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "lookup_type", + "long_name": "lookup_type( x )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 2, + "token_count": 40, + "parameters": [ + "x" + ], + "start_line": 91, + "end_line": 96, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , function , * args , ** kw )", + "filename": "accelerate_tools.py", + "nloc": 9, + "complexity": 2, + "token_count": 56, + "parameters": [ + "self", + "function", + "args", + "kw" + ], + "start_line": 103, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 8, + "complexity": 2, + "token_count": 56, + "parameters": [ + "self", + "args" + ], + "start_line": 113, + "end_line": 123, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "signature", + "long_name": "signature( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "args" + ], + "start_line": 125, + "end_line": 128, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "singleton", + "long_name": "singleton( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 20, + "complexity": 3, + "token_count": 137, + "parameters": [ + "self", + "signature" + ], + "start_line": 131, + "end_line": 158, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "identifier", + "long_name": "identifier( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 8, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self", + "signature" + ], + "start_line": 160, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "accelerate", + "long_name": "accelerate( self , signature , identifier )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self", + "signature", + "identifier" + ], + "start_line": 170, + "end_line": 172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "code", + "long_name": "code( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 4, + "complexity": 1, + "token_count": 39, + "parameters": [ + "self", + "args" + ], + "start_line": 174, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "typedef_by_value", + "long_name": "typedef_by_value( self , v )", + "filename": "accelerate_tools.py", + "nloc": 4, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "v" + ], + "start_line": 184, + "end_line": 187, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , f , signature , name = None )", + "filename": "accelerate_tools.py", + "nloc": 11, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "f", + "signature", + "name" + ], + "start_line": 189, + "end_line": 202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "function_code", + "long_name": "function_code( self )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 204, + "end_line": 205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "python_function_definition_code", + "long_name": "python_function_definition_code( self )", + "filename": "accelerate_tools.py", + "nloc": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 207, + "end_line": 211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "__init__", + "long_name": "__init__( self , f , signature , name = None )", + "filename": "accelerate_tools.py", + "nloc": 12, + "complexity": 2, + "token_count": 97, + "parameters": [ + "self", + "f", + "signature", + "name" + ], + "start_line": 198, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , function , * args , ** kw )", + "filename": "accelerate_tools.py", + "nloc": 9, + "complexity": 2, + "token_count": 56, + "parameters": [ + "self", + "function", + "args", + "kw" + ], + "start_line": 103, + "end_line": 111, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check", + "long_name": "check( self , s )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self", + "s" + ], + "start_line": 69, + "end_line": 71, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "literalizer", + "long_name": "literalizer( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "s" + ], + "start_line": 34, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__cache", + "long_name": "__cache( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "args" + ], + "start_line": 115, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "binopMixed", + "long_name": "binopMixed( self , symbol , a , b )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "symbol", + "a", + "b" + ], + "start_line": 76, + "end_line": 77, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 12, + "complexity": 3, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 118, + "end_line": 132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + } + ], + "nloc": 161, + "complexity": 33, + "token_count": 1058, + "diff_parsed": { + "added": [ + " def literalizer(self,s):", + " return str(s)", + " refcount = 1", + " ['#include \"Numeric/arrayobject.h\"']", + " return \"PyArray_Check(%s) && ((PyArrayObject*)%s)->nd == %d && ((PyArrayObject*)%s)->descr->type_num == %s\"%(", + " s,s,self.dims,s,self.typecode)", + " def binopMixed(self,symbol,a,b):", + " return '*((%s*)(%s->data+%s*%s->strides[0]))'%(self.cxxbase,a,b,a),Integer()", + " typecode = 'PyArray_INT'", + " cxxbase = 'int'", + " def __cache(self,*args):", + " raise TypeError", + " def __call__(self,*args):", + " return self.__cache(*args)", + " except TypeError:", + " # Figure out type info -- Do as tuple so its hashable", + " signature = tuple( map(lookup_type,args) )", + "", + " # If we know the function, call it", + " try:", + " fast = self.__call_map[signature]", + " except:", + " fast = self.singleton(signature)", + " self.__cache = fast", + " self.__call_map[signature] = fast", + " self.customize.add_module_init_code('import_array()\\n')" + ], + "deleted": [ + " ['#include \"Numeric/arrayobject.h\"',", + " 'static PyObject* PyArray_AsPyObject(PyArrayObject* A) { PyObject* X = '", + " 'reinterpret_cast(A);'", + " 'std::cerr << \"Here in cast\" << std::endl;'", + " 'Py_XINCREF(X); return X;}']", + " return \"PyArray_Check(%s) /* && dims==%d && typecode==%s */\"%(s,self.dims,self.typecode)", + " typecode = 'l'", + " return", + " def __call__(self,*args):", + " # Figure out type info -- Do as tuple so its hashable", + " signature = tuple( map(lookup_type,args) )", + " # If we know the function, call it", + " return self.__call_map[signature](*args)", + " except:", + " fast = self.singleton(signature)", + " self.__call_map[signature] = fast" + ] + } + }, + { + "old_path": "weave/bytecodecompiler.py", + "new_path": "weave/bytecodecompiler.py", + "filename": "bytecodecompiler.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -16,6 +16,7 @@\n ##################################################################\n class Type_Descriptor:\n prerequisites = []\n+ refcount = 0\n def __repr__(self):\n return self.__module__+'.'+self.__class__.__name__\n \n@@ -184,7 +185,10 @@ def listing(f):\n source = ''\n if arg == None: arg = ''\n s += '%3d] %20s %5s : %s\\n'%(pc,name,arg,source)\n- pc += 1\n+ if op >= haveArgument:\n+ pc += 3\n+ else:\n+ pc += 1\n return s\n \n ##################################################################\n@@ -715,8 +719,9 @@ def generate(self):\n # the body\n # -----------------------------------------------\n code = self.codeobject.co_code\n+ bytes = len(code)\n pc = 0\n- while pc != None:\n+ while pc != None and pc < bytes:\n pc = self.evaluate(pc,code)\n \n # -----------------------------------------------\n@@ -742,7 +747,7 @@ def generate(self):\n # -----------------------------------------------\n code += '#include \"Python.h\"\\n'\n for T in self.used:\n- print T.prerequisites\n+ if T == None: continue\n for pre in T.prerequisites:\n code += pre\n code += '\\n'\n@@ -764,9 +769,8 @@ def generate(self):\n for i in range(self.codeobject.co_argcount,\n self.codeobject.co_nlocals):\n t = self.types[i]\n- descriptor = typedefs[t]\n code += '%s %s;\\n'%(\n- descriptor.cxxtype,\n+ t.cxxtype,\n self.codeobject.co_varnames[i],\n )\n \n@@ -932,13 +936,14 @@ def binop(self,pc,symbol):\n if t1 == t2:\n rhs,rhs_type = t1.binop(symbol,v1,v2)\n else:\n- raise NotImplementedError,'mixed types'\n+ rhs,rhs_type = t1.binopMixed(symbol,v1,v2)\n \n lhs = self.unique()\n self.emit('%s %s = %s;\\n'%(\n rhs_type.cxxtype,\n lhs,\n rhs))\n+ print self.__body\n self.push(lhs,rhs_type)\n return \n \n@@ -955,6 +960,8 @@ def BINARY_DIVIDE(self,pc):\n return self.binop(pc,'/')\n def BINARY_MODULO(self,pc):\n return self.binop(pc,'%')\n+ def BINARY_SUBSCR(self,pc):\n+ return self.binop(pc,'[]')\n def COMPARE_OP(self,pc,opname):\n symbol = self.cmp_op(opname) # convert numeric to name\n return self.binop(pc,symbol)\n@@ -1012,10 +1019,11 @@ def LOAD_CONST(self,pc,consti):\n # Fetch the constant\n k = self.consts[consti]\n t = type(k)\n+ print 'LOAD_CONST',repr(k),t\n \n # Fetch a None is just skipped\n if t == NoneType:\n- self.push('',t) \n+ self.push('',t) \n return\n \n self.emit_value(k)\n@@ -1028,6 +1036,9 @@ def LOAD_CONST(self,pc,consti):\n def LOAD_FAST(self,pc,var_num):\n v = self.stack[var_num]\n t = self.types[var_num]\n+ print 'LOADFAST',var_num,v,t\n+ if t.refcount:\n+ self.emit('Py_XINCREF(%s);'%v)\n self.push(v,t)\n return\n \n@@ -1078,6 +1089,7 @@ def LOAD_GLOBAL(self,pc,var_num):\n def STORE_FAST(self,pc,var_num):\n \n v,t = self.pop()\n+ print 'STORE FAST',var_num,v,t\n \n save = self.stack[var_num]\n saveT = self.types[var_num]\n@@ -1085,6 +1097,9 @@ def STORE_FAST(self,pc,var_num):\n # See if type is same....\n # Note that None means no assignment made yet\n if saveT == None or t == saveT:\n+ if t.refcount:\n+ self.emit('Py_XINCREF(%s);'%v)\n+ self.emit('Py_XDECREF(%s);'%save)\n self.emit('%s = %s;\\n'%(save,v))\n self.types[var_num] = t\n return\n@@ -1194,11 +1209,14 @@ def JUMP_FORWARD(self,pc,delta):\n def RETURN_VALUE(self,pc):\n v,t = self.pop()\n if hasattr(self,'rtype'):\n+ print v,t\n+ if t == NoneType: return # just the extra return\n raise ValueError,'multiple returns'\n self.rtype = t\n if t == NoneType:\n self.emit('return;')\n else:\n self.emit('return %s;'%v)\n- return -1\n+ print 'return with',v\n+ return\n \n", + "added_lines": 26, + "deleted_lines": 8, + "source_code": "#**************************************************************************#\n#* FILE ************** bytecodecompiler.py ************************#\n#************************************************************************ **#\n#* Author: Patrick Miller February 9 2002 *#\n#* Copyright (C) 2002 Patrick J. Miller *#\n#**************************************************************************#\n#* *#\n#**************************************************************************#\nfrom types import *\nimport string\nimport inspect\n\n\n##################################################################\n# CLASS CXXTYPEDESCRIPTION #\n##################################################################\nclass Type_Descriptor:\n prerequisites = []\n refcount = 0\n def __repr__(self):\n return self.__module__+'.'+self.__class__.__name__\n\n\nhaveArgument = 90 # Opcodes greater-equal to this have argument\nbyName = {\n 'STOP_CODE': 0,\n 'POP_TOP': 1,\n 'ROT_TWO': 2,\n 'ROT_THREE': 3,\n 'DUP_TOP': 4,\n 'ROT_FOUR': 5,\n 'UNARY_POSITIVE': 10,\n 'UNARY_NEGATIVE': 11,\n 'UNARY_NOT': 12,\n 'UNARY_CONVERT': 13,\n 'UNARY_INVERT': 15,\n 'BINARY_POWER': 19,\n 'BINARY_MULTIPLY': 20,\n 'BINARY_DIVIDE': 21,\n 'BINARY_MODULO': 22,\n 'BINARY_ADD': 23,\n 'BINARY_SUBTRACT': 24,\n 'BINARY_SUBSCR': 25,\n 'BINARY_FLOOR_DIVIDE': 26,\n 'BINARY_TRUE_DIVIDE': 27,\n 'INPLACE_FLOOR_DIVIDE': 28,\n 'INPLACE_TRUE_DIVIDE': 29,\n 'SLICE': 30,\n 'STORE_SLICE': 40,\n 'DELETE_SLICE': 50,\n 'INPLACE_ADD': 55,\n 'INPLACE_SUBTRACT': 56,\n 'INPLACE_MULTIPLY': 57,\n 'INPLACE_DIVIDE': 58,\n 'INPLACE_MODULO': 59,\n 'STORE_SUBSCR': 60,\n 'DELETE_SUBSCR': 61,\n 'BINARY_LSHIFT': 62,\n 'BINARY_RSHIFT': 63,\n 'BINARY_AND': 64,\n 'BINARY_XOR': 65,\n 'BINARY_OR': 66,\n 'INPLACE_POWER': 67,\n 'GET_ITER': 68,\n 'PRINT_EXPR': 70,\n 'PRINT_ITEM': 71,\n 'PRINT_NEWLINE': 72,\n 'PRINT_ITEM_TO': 73,\n 'PRINT_NEWLINE_TO': 74,\n 'INPLACE_LSHIFT': 75,\n 'INPLACE_RSHIFT': 76,\n 'INPLACE_AND': 77,\n 'INPLACE_XOR': 78,\n 'INPLACE_OR': 79,\n 'BREAK_LOOP': 80,\n 'LOAD_LOCALS': 82,\n 'RETURN_VALUE': 83,\n 'IMPORT_STAR': 84,\n 'EXEC_STMT': 85,\n 'YIELD_VALUE': 86,\n 'POP_BLOCK': 87,\n 'END_FINALLY': 88,\n 'BUILD_CLASS': 89,\n 'STORE_NAME': 90,\n 'DELETE_NAME': 91,\n 'UNPACK_SEQUENCE': 92,\n 'FOR_ITER': 93,\n 'STORE_ATTR': 95,\n 'DELETE_ATTR': 96,\n 'STORE_GLOBAL': 97,\n 'DELETE_GLOBAL': 98,\n 'DUP_TOPX': 99,\n 'LOAD_CONST': 100,\n 'LOAD_NAME': 101,\n 'BUILD_TUPLE': 102,\n 'BUILD_LIST': 103,\n 'BUILD_MAP': 104,\n 'LOAD_ATTR': 105,\n 'COMPARE_OP': 106,\n 'IMPORT_NAME': 107,\n 'IMPORT_FROM': 108,\n 'JUMP_FORWARD': 110,\n 'JUMP_IF_FALSE': 111,\n 'JUMP_IF_TRUE': 112,\n 'JUMP_ABSOLUTE': 113,\n 'FOR_LOOP': 114,\n 'LOAD_GLOBAL': 116,\n 'CONTINUE_LOOP': 119,\n 'SETUP_LOOP': 120,\n 'SETUP_EXCEPT': 121,\n 'SETUP_FINALLY': 122,\n 'LOAD_FAST': 124,\n 'STORE_FAST': 125,\n 'DELETE_FAST': 126,\n 'SET_LINENO': 127,\n 'RAISE_VARARGS': 130,\n 'CALL_FUNCTION': 131,\n 'MAKE_FUNCTION': 132,\n 'BUILD_SLICE': 133,\n 'MAKE_CLOSURE': 134,\n 'LOAD_CLOSURE': 135,\n 'LOAD_DEREF': 136,\n 'STORE_DEREF': 137,\n 'CALL_FUNCTION_VAR': 140,\n 'CALL_FUNCTION_KW': 141,\n 'CALL_FUNCTION_VAR_KW': 142,\n }\n\n# -----------------------------------------------\n# Build one in the reverse sense\n# -----------------------------------------------\nbyOpcode = {}\nfor name,op in map(None, byName.keys(), byName.values()):\n byOpcode[op] = name\n del name\n del op\n \n\n##################################################################\n# FUNCTION OPCODIZE #\n##################################################################\ndef opcodize(s):\n \"Slightly more readable form\"\n length = len(s)\n i = 0\n answer = []\n while i < length:\n bytecode = ord(s[i])\n name = byOpcode[bytecode]\n if bytecode >= haveArgument:\n argument = 256*ord(s[i+2])+ord(s[i+1])\n i += 3\n else:\n argument = None\n i += 1\n answer.append((bytecode,argument,name))\n return answer\n\n\n\n##################################################################\n# FUNCTION LIST #\n##################################################################\ndef listing(f):\n \"Pretty print the internals of your function\"\n assert type(f) == FunctionType,\"Arg %r must be a function\"%f\n filename = f.func_code.co_filename\n try:\n lines = open(filename).readlines()\n except:\n lines = None\n pc = 0\n s = ''\n lastLine = None\n for op,arg,name in opcodize(f.func_code.co_code):\n if lines and name == 'SET_LINENO':\n source = lines[arg-1][:-1]\n while lastLine and lastLine < arg-1:\n nonEmittingSource = lines[lastLine][:-1]\n lastLine += 1\n s += '%3s %20s %5s : %s\\n'%(\n '','','',nonEmittingSource)\n lastLine = arg\n else:\n source = ''\n if arg == None: arg = ''\n s += '%3d] %20s %5s : %s\\n'%(pc,name,arg,source)\n if op >= haveArgument:\n pc += 3\n else:\n pc += 1\n return s\n\n##################################################################\n# CLASS BYTECODEMEANING #\n##################################################################\nclass ByteCodeMeaning:\n def fetch(self, pc,code):\n opcode = ord(code[pc])\n if opcode >= haveArgument:\n argument = 256*ord(code[pc+2])+ord(code[pc+1])\n next = pc+3\n else:\n argument = None\n next = pc+1\n return next,opcode,argument\n \n def execute(self,pc,opcode,argument):\n name = byOpcode[opcode]\n method = getattr(self,name)\n if argument == None:\n return apply(method,(pc,))\n else:\n return apply(method,(pc,argument,))\n\n def evaluate(self, pc,code):\n next, opcode,argument = self.fetch(pc,code)\n goto = self.execute(next,opcode,argument)\n if goto == -1:\n return None # Must be done\n elif goto == None:\n return next # Normal\n else:\n raise 'xx'\n\n symbols = { 0: 'less', 1: 'lesseq', 2: 'equal', 3: 'notequal',\n 4: 'greater', 5: 'greatereq', 6: 'in', 7: 'not in',\n 8: 'is', 9: 'is not', 10: 'exe match',\n 11 : 'bad',\n }\n def cmp_op(self,opname):\n return self.symbols[opname]\n \n def STOP_CODE(self,pc):\n \"Indicates end-of-code to the compiler, not used by the interpreter.\"\n raise NotImplementedError\n def POP_TOP(self,pc):\n \"Removes the top-of-stack (TOS) item.\"\n raise NotImplementedError\n\n def ROT_TWO(self,pc):\n \"Swaps the two top-most stack items.\"\n raise NotImplementedError\n\n def ROT_THREE(self,pc):\n \"Lifts second and third stack item one position up, moves top down to position three.\"\n raise NotImplementedError\n\n def ROT_FOUR(self,pc):\n \"Lifts second, third and forth stack item one position up, moves top down to position four.\"\n raise NotImplementedError\n\n def DUP_TOP(self,pc):\n \"Duplicates the reference on top of the stack.\"\n raise NotImplementedError\n\n # Unary Operations take the top of the stack, apply the operation, and push the result back on the stack.\n\n def UNARY_POSITIVE(self,pc):\n \"Implements TOS = +TOS.\"\n raise NotImplementedError\n\n def UNARY_NEGATIVE(self,pc):\n \"Implements TOS = -TOS.\"\n raise NotImplementedError\n\n def UNARY_NOT(self,pc):\n \"Implements TOS = not TOS.\"\n raise NotImplementedError\n\n def UNARY_CONVERT(self,pc):\n \"Implements TOS = `TOS`.\"\n raise NotImplementedError\n\n def UNARY_INVERT(self,pc):\n \"Implements TOS = ~TOS.\"\n raise NotImplementedError\n\n #Binary operations remove the top of the stack (TOS) and the second top-most stack item (TOS1) from the stack. They perform the operation, and put the result back on the stack.\n\n def BINARY_POWER(self,pc):\n \"Implements TOS = TOS1 ** TOS.\"\n raise NotImplementedError\n\n def BINARY_MULTIPLY(self,pc):\n \"Implements TOS = TOS1 * TOS.\"\n raise NotImplementedError\n\n def BINARY_DIVIDE(self,pc):\n \"Implements TOS = TOS1 / TOS.\"\n raise NotImplementedError\n\n def BINARY_MODULO(self,pc):\n \"Implements TOS = TOS1 % TOS.\"\n raise NotImplementedError\n\n def BINARY_ADD(self,pc):\n \"Implements TOS = TOS1 + TOS.\"\n raise NotImplementedError\n\n def BINARY_SUBTRACT(self,pc):\n \"Implements TOS = TOS1 - TOS.\"\n raise NotImplementedError\n\n def BINARY_SUBSCR(self,pc):\n \"Implements TOS = TOS1[TOS].\"\n raise NotImplementedError\n\n def BINARY_LSHIFT(self,pc):\n \"Implements TOS = TOS1 << TOS.\"\n raise NotImplementedError\n\n def BINARY_RSHIFT(self,pc):\n \"Implements TOS = TOS1 >> TOS.\"\n raise NotImplementedError\n\n def BINARY_AND(self,pc):\n \"Implements TOS = TOS1 & TOS.\"\n raise NotImplementedError\n\n def BINARY_XOR(self,pc):\n \"Implements TOS = TOS1 ^ TOS.\"\n raise NotImplementedError\n\n def BINARY_OR(self,pc):\n \"Implements TOS = TOS1 | TOS.\"\n raise NotImplementedError\n\n #In-place operations are like binary operations, in that they remove TOS and TOS1, and push the result back on the stack, but the operation is done in-place when TOS1 supports it, and the resulting TOS may be (but does not have to be) the original TOS1.\n\n def INPLACE_POWER(self,pc):\n \"Implements in-place TOS = TOS1 ** TOS.\"\n raise NotImplementedError\n\n def INPLACE_MULTIPLY(self,pc):\n \"Implements in-place TOS = TOS1 * TOS.\"\n raise NotImplementedError\n\n def INPLACE_DIVIDE(self,pc):\n \"Implements in-place TOS = TOS1 / TOS.\"\n raise NotImplementedError\n\n def INPLACE_MODULO(self,pc):\n \"Implements in-place TOS = TOS1 % TOS.\"\n raise NotImplementedError\n\n def INPLACE_ADD(self,pc):\n \"Implements in-place TOS = TOS1 + TOS.\"\n raise NotImplementedError\n\n def INPLACE_SUBTRACT(self,pc):\n \"Implements in-place TOS = TOS1 - TOS.\"\n raise NotImplementedError\n\n def INPLACE_LSHIFT(self,pc):\n \"Implements in-place TOS = TOS1 << TOS.\"\n raise NotImplementedError\n\n def INPLACE_RSHIFT(self,pc):\n \"Implements in-place TOS = TOS1 >> TOS.\"\n raise NotImplementedError\n\n def INPLACE_AND(self,pc):\n \"Implements in-place TOS = TOS1 & TOS.\"\n raise NotImplementedError\n\n def INPLACE_XOR(self,pc):\n \"Implements in-place TOS = TOS1 ^ TOS.\"\n raise NotImplementedError\n\n def INPLACE_OR(self,pc):\n \"Implements in-place TOS = TOS1 | TOS.\"\n raise NotImplementedError\n\n #The slice opcodes take up to three parameters.\n\n def SLICE_0(self,pc):\n \"Implements TOS = TOS[:].\"\n raise NotImplementedError\n\n def SLICE_1(self,pc):\n \"Implements TOS = TOS1[TOS:].\"\n raise NotImplementedError\n\n def SLICE_2(self,pc):\n \"Implements TOS = TOS1[:TOS1].\"\n raise NotImplementedError\n\n def SLICE_3(self,pc):\n \"Implements TOS = TOS2[TOS1:TOS].\"\n raise NotImplementedError\n\n #Slice assignment needs even an additional parameter. As any statement, they put nothing on the stack.\n\n def STORE_SLICE_0(self,pc):\n \"Implements TOS[:] = TOS1.\"\n raise NotImplementedError\n\n def STORE_SLICE_1(self,pc):\n \"Implements TOS1[TOS:] = TOS2.\"\n raise NotImplementedError\n\n def STORE_SLICE_2(self,pc):\n \"Implements TOS1[:TOS] = TOS2.\"\n raise NotImplementedError\n\n def STORE_SLICE_3(self,pc):\n \"Implements TOS2[TOS1:TOS] = TOS3.\"\n raise NotImplementedError\n\n def DELETE_SLICE_0(self,pc):\n \"Implements del TOS[:].\"\n raise NotImplementedError\n\n def DELETE_SLICE_1(self,pc):\n \"Implements del TOS1[TOS:].\"\n raise NotImplementedError\n\n def DELETE_SLICE_2(self,pc):\n \"Implements del TOS1[:TOS].\"\n raise NotImplementedError\n\n def DELETE_SLICE_3(self,pc):\n \"Implements del TOS2[TOS1:TOS].\"\n raise NotImplementedError\n\n def STORE_SUBSCR(self,pc):\n \"Implements TOS1[TOS] = TOS2.\"\n raise NotImplementedError\n\n def DELETE_SUBSCR(self,pc):\n \"Implements del TOS1[TOS].\"\n raise NotImplementedError\n\n def PRINT_EXPR(self,pc):\n \"Implements the expression statement for the interactive mode. TOS is removed from the stack and printed. In non-interactive mode, an expression statement is terminated with POP_STACK.\"\n raise NotImplementedError\n\n def PRINT_ITEM(self,pc):\n \"Prints TOS to the file-like object bound to sys.stdout. There is one such instruction for each item in the print statement.\"\n raise NotImplementedError\n\n def PRINT_ITEM_TO(self,pc):\n \"Like PRINT_ITEM, but prints the item second from TOS to the file-like object at TOS. This is used by the extended print statement.\"\n raise NotImplementedError\n\n def PRINT_NEWLINE(self,pc):\n \"Prints a new line on sys.stdout. This is generated as the last operation of a print statement, unless the statement ends with a comma.\"\n raise NotImplementedError\n\n def PRINT_NEWLINE_TO(self,pc):\n \"Like PRINT_NEWLINE, but prints the new line on the file-like object on the TOS. This is used by the extended print statement.\"\n raise NotImplementedError\n\n def BREAK_LOOP(self,pc):\n \"Terminates a loop due to a break statement.\"\n raise NotImplementedError\n\n def LOAD_LOCALS(self,pc):\n \"Pushes a reference to the locals of the current scope on the stack. This is used in the code for a class definition: After the class body is evaluated, the locals are passed to the class definition.\"\n raise NotImplementedError\n\n def RETURN_VALUE(self,pc):\n \"Returns with TOS to the caller of the function.\"\n raise NotImplementedError\n\n def IMPORT_STAR(self,pc):\n \"Loads all symbols not starting with _ directly from the module TOS to the local namespace. The module is popped after loading all names. This opcode implements from module import *.\"\n raise NotImplementedError\n\n def EXEC_STMT(self,pc):\n \"Implements exec TOS2,TOS1,TOS. The compiler fills missing optional parameters with None.\"\n raise NotImplementedError\n\n def POP_BLOCK(self,pc):\n \"Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.\"\n raise NotImplementedError\n\n def END_FINALLY(self,pc):\n \"Terminates a finally clause. The interpreter recalls whether the exception has to be re-raised, or whether the function returns, and continues with the outer-next block.\"\n raise NotImplementedError\n\n def BUILD_CLASS(self,pc):\n \"Creates a new class object. TOS is the methods dictionary, TOS1 the tuple of the names of the base classes, and TOS2 the class name.\"\n raise NotImplementedError\n\n #All of the following opcodes expect arguments. An argument is two bytes, with the more significant byte last.\n\n def STORE_NAME(self,pc,namei):\n \"Implements name = TOS. namei is the index of name in the attribute co_names of the code object. The compiler tries to use STORE_LOCAL or STORE_GLOBAL if possible.\"\n raise NotImplementedError\n\n def DELETE_NAME(self,pc,namei):\n \"Implements del name, where namei is the index into co_names attribute of the code object.\"\n raise NotImplementedError\n\n def UNPACK_SEQUENCE(self,pc,count):\n \"Unpacks TOS into count individual values, which are put onto the stack right-to-left.\"\n raise NotImplementedError\n\n def DUP_TOPX(self,pc,count):\n \"Duplicate count items, keeping them in the same order. Due to implementation limits, count should be between 1 and 5 inclusive.\"\n raise NotImplementedError\n\n def STORE_ATTR(self,pc,namei):\n \"Implements TOS.name = TOS1, where namei is the index of name in co_names.\"\n raise NotImplementedError\n\n def DELETE_ATTR(self,pc,namei):\n \"Implements del TOS.name, using namei as index into co_names.\"\n raise NotImplementedError\n\n def STORE_GLOBAL(self,pc,namei):\n \"Works as STORE_NAME, but stores the name as a global.\"\n raise NotImplementedError\n\n def DELETE_GLOBAL(self,pc,namei):\n \"Works as DELETE_NAME, but deletes a global name.\"\n raise NotImplementedError\n\n def LOAD_CONST(self,pc,consti):\n \"Pushes co_consts[consti] onto the stack.\"\n raise NotImplementedError\n\n def LOAD_NAME(self,pc,namei):\n \"Pushes the value associated with co_names[namei] onto the stack.\"\n raise NotImplementedError\n\n def BUILD_TUPLE(self,pc,count):\n \"Creates a tuple consuming count items from the stack, and pushes the resulting tuple onto the stack.\"\n raise NotImplementedError\n\n def BUILD_LIST(self,pc,count):\n \"Works as BUILD_TUPLE, but creates a list.\"\n raise NotImplementedError\n\n def BUILD_MAP(self,pc,zero):\n \"Pushes a new empty dictionary object onto the stack. The argument is ignored and set to zero by the compiler.\"\n raise NotImplementedError\n\n def LOAD_ATTR(self,pc,namei):\n \"Replaces TOS with getattr(TOS, co_names[namei].\"\n raise NotImplementedError\n\n def COMPARE_OP(self,pc,opname):\n \"Performs a Boolean operation. The operation name can be found in cmp_op[opname].\"\n raise NotImplementedError\n\n def IMPORT_NAME(self,pc,namei):\n \"Imports the module co_names[namei]. The module object is pushed onto the stack. The current namespace is not affected: for a proper import statement, a subsequent STORE_FAST instruction modifies the namespace.\"\n raise NotImplementedError\n\n def IMPORT_FROM(self,pc,namei):\n \"Loads the attribute co_names[namei] from the module found in TOS. The resulting object is pushed onto the stack, to be subsequently stored by a STORE_FAST instruction.\"\n raise NotImplementedError\n\n def JUMP_FORWARD(self,pc,delta):\n \"Increments byte code counter by delta.\"\n raise NotImplementedError\n\n def JUMP_IF_TRUE(self,pc,delta):\n \"If TOS is true, increment the byte code counter by delta. TOS is left on the stack.\"\n raise NotImplementedError\n\n def JUMP_IF_FALSE(self,pc,delta):\n \"If TOS is false, increment the byte code counter by delta. TOS is not changed.\"\n raise NotImplementedError\n\n def JUMP_ABSOLUTE(self,pc,target):\n \"Set byte code counter to target.\"\n raise NotImplementedError\n\n def FOR_LOOP(self,pc,delta):\n \"Iterate over a sequence. TOS is the current index, TOS1 the sequence. First, the next element is computed. If the sequence is exhausted, increment byte code counter by delta. Otherwise, push the sequence, the incremented counter, and the current item onto the stack.\"\n raise NotImplementedError\n\n def LOAD_GLOBAL(self,pc,namei):\n \"Loads the global named co_names[namei] onto the stack.\"\n raise NotImplementedError\n\n def SETUP_LOOP(self,pc,delta):\n \"Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.\"\n raise NotImplementedError\n\n def SETUP_EXCEPT(self,pc,delta):\n \"Pushes a try block from a try-except clause onto the block stack. delta points to the first except block.\"\n raise NotImplementedError\n\n def SETUP_FINALLY(self,pc,delta):\n \"Pushes a try block from a try-except clause onto the block stack. delta points to the finally block.\"\n raise NotImplementedError\n\n def LOAD_FAST(self,pc,var_num):\n \"Pushes a reference to the local co_varnames[var_num] onto the stack.\"\n raise NotImplementedError\n\n def STORE_FAST(self,pc,var_num):\n \"Stores TOS into the local co_varnames[var_num].\"\n raise NotImplementedError\n\n def DELETE_FAST(self,pc,var_num):\n \"Deletes local co_varnames[var_num].\"\n raise NotImplementedError\n\n def LOAD_CLOSURE(self,pc,i):\n \"Pushes a reference to the cell contained in slot i of the cell and free variable storage. The name of the variable is co_cellvars[i] if i is less than the length of co_cellvars. Otherwise it is co_freevars[i - len(co_cellvars)].\"\n raise NotImplementedError\n\n def LOAD_DEREF(self,pc,i):\n \"Loads the cell contained in slot i of the cell and free variable storage. Pushes a reference to the object the cell contains on the stack.\"\n raise NotImplementedError\n\n def STORE_DEREF(self,pc,i):\n \"Stores TOS into the cell contained in slot i of the cell and free variable storage.\"\n raise NotImplementedError\n\n def SET_LINENO(self,pc,lineno):\n \"Sets the current line number to lineno.\"\n raise NotImplementedError\n\n def RAISE_VARARGS(self,pc,argc):\n \"Raises an exception. argc indicates the number of parameters to the raise statement, ranging from 0 to 3. The handler will find the traceback as TOS2, the parameter as TOS1, and the exception as TOS.\"\n raise NotImplementedError\n\n def CALL_FUNCTION(self,pc,argc):\n \"Calls a function. The low byte of argc indicates the number of positional parameters, the high byte the number of keyword parameters. On the stack, the opcode finds the keyword parameters first. For each keyword argument, the value is on top of the key. Below the keyword parameters, the positional parameters are on the stack, with the right-most parameter on top. Below the parameters, the function object to call is on the stack.\"\n raise NotImplementedError\n\n def MAKE_FUNCTION(self,pc,argc):\n \"Pushes a new function object on the stack. TOS is the code associated with the function. The function object is defined to have argc default parameters, which are found below TOS.\"\n raise NotImplementedError\n\n def MAKE_CLOSURE(self,pc,argc):\n \"Creates a new function object, sets its func_closure slot, and pushes it on the stack. TOS is the code associated with the function. If the code object has N free variables, the next N items on the stack are the cells for these variables. The function also has argc default parameters, where are found before the cells.\"\n raise NotImplementedError\n\n def BUILD_SLICE(self,pc,argc):\n \"Pushes a slice object on the stack. argc must be 2 or 3. If it is 2, slice(TOS1, TOS) is pushed; if it is 3, slice(TOS2, TOS1, TOS) is pushed. See the slice() built-in function for more information.\"\n raise NotImplementedError\n\n def EXTENDED_ARG(self,pc,ext):\n \"Prefixes any opcode which has an argument too big to fit into the default two bytes. ext holds two additional bytes which, taken together with the subsequent opcode's argument, comprise a four-byte argument, ext being the two most-significant bytes.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_VAR(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the variable argument list, followed by keyword and positional arguments.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_KW(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by explicit keyword and positional arguments.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_VAR_KW(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by the variable-arguments tuple, followed by explicit keyword and positional arguments.\"\n raise NotImplementedError\n\n \n\n##################################################################\n# CLASS CXXCODER #\n##################################################################\nclass CXXCoder(ByteCodeMeaning):\n\n ##################################################################\n # MEMBER TYPEDEF_BY_VALUE #\n ##################################################################\n def typedef_by_value(self,v):\n raise NotImplementedError # VIRTUAL\n \n ##################################################################\n # MEMBER __INIT__ #\n ##################################################################\n def __init__(self,function,signature,name=None):\n assert type(function) == FunctionType,\"Arg must be a user function\"\n assert not function.func_defaults ,\"Function cannot have default args (yet)\"\n if name == None: name = function.func_name\n self.name = name\n self.function = function\n self.signature = signature\n self.codeobject = function.func_code\n self.__uid = 0 # Builds temps\n return\n\n ##################################################################\n # MEMBER EVALUATE #\n ##################################################################\n def evaluate(self, pc,code):\n # See if we posted any forwards for this offset\n if self.forwards.has_key(pc):\n for f in self.forwards[pc]:\n f()\n self.forwards[pc] = []\n return ByteCodeMeaning.evaluate(self,pc,code)\n \n ##################################################################\n # MEMBER GENERATE #\n ##################################################################\n def generate(self):\n self.forwards = {} # Actions on forward interprets\n self.__body = '' # Body will be built\n self.helpers = [] # headers and stuff\n\n # -----------------------------------------------\n # OK, crack open the function object and build\n # initial stack (not a real frame!)\n # -----------------------------------------------\n arglen = len(self.signature)\n nlocals = self.codeobject.co_nlocals\n\n self.consts = self.codeobject.co_consts\n self.stack = list(self.codeobject.co_varnames)\n self.types = list(self.signature)+[None]*(nlocals-arglen)\n self.used = []\n for T in self.types:\n if T not in self.used: self.used.append(T)\n\n # -----------------------------------------------\n # One pass through the byte codes to generate\n # the body\n # -----------------------------------------------\n code = self.codeobject.co_code\n bytes = len(code)\n pc = 0\n while pc != None and pc < bytes:\n pc = self.evaluate(pc,code)\n\n # -----------------------------------------------\n # Return?\n # -----------------------------------------------\n if self.rtype == NoneType:\n rtype = 'void'\n else:\n rtype = self.rtype.cxxtype\n \n # -----------------------------------------------\n # Insert code body if available\n # -----------------------------------------------\n source = inspect.getsource(self.function)\n if not source: source = ''\n comments = inspect.getcomments(self.function)\n if comments: source = comments+source\n code = string.join(map(lambda x: '/////// '+x,string.split(source,'\\n')),\n '\\n')+'\\n'\n\n # -----------------------------------------------\n # Add in the headers\n # -----------------------------------------------\n code += '#include \"Python.h\"\\n'\n for T in self.used:\n if T == None: continue\n for pre in T.prerequisites:\n code += pre\n code += '\\n'\n\n # -----------------------------------------------\n # Real body\n # -----------------------------------------------\n code += '\\n'\n code += '\\nstatic %s %s('%(rtype,self.name)\n for i in range(len(self.signature)):\n if i != 0: code += ', '\n n = self.stack[i]\n t = self.types[i]\n code += '%s %s'%(t.cxxtype,n)\n code += ') {\\n'\n\n # Add in non-argument temporaries\n # Assuming first argcount locals are positional args\n for i in range(self.codeobject.co_argcount,\n self.codeobject.co_nlocals):\n t = self.types[i]\n code += '%s %s;\\n'%(\n t.cxxtype,\n self.codeobject.co_varnames[i],\n )\n\n # Add in the body\n code += self.__body\n code += '}\\n\\n'\n return code\n\n\n ##################################################################\n # MEMBER WRAPPED_CODE #\n ##################################################################\n def wrapped_code(self):\n code = self.generate()\n \n # -----------------------------------------------\n # Wrapper\n # -----------------------------------------------\n code += 'static PyObject* wrapper_%s(PyObject*,PyObject* args) {\\n'%self.name\n\n code += ' // Length check\\n'\n code += ' if ( PyTuple_Size(args) != %d ) {\\n'%len(self.signature)\n code += ' PyErr_SetString(PyExc_TypeError,\"Expected %d arguments\");\\n'%len(self.signature)\n code += ' return 0;\\n'\n code += ' }\\n'\n\n code += '\\n // Load Py versions of args\\n'\n for i in range(len(self.signature)):\n T = self.signature[i]\n code += ' PyObject* py_%s = PyTuple_GET_ITEM(args,%d);\\n'%(\n self.codeobject.co_varnames[i],i\n )\n\n code += ' if ( !%s ) {\\n'% \\\n T.check('py_'+self.codeobject.co_varnames[i])\n code += ' PyErr_SetString(PyExc_TypeError,\"Bad type for arg %d (expected %s)\");\\n'%(\n i+1,\n T.__class__.__name__)\n code += ' return 0;\\n'\n code += ' }\\n'\n \n code += '\\n // Do conversions\\n'\n argnames = []\n for i in range(len(self.signature)):\n T = self.signature[i]\n\n code += ' %s %s=%s;\\n'%(\n T.cxxtype,\n self.codeobject.co_varnames[i],\n T.inbound('py_'+self.codeobject.co_varnames[i]),\n )\n code += ' if ( PyErr_Occurred() ) return 0;\\n'\n argnames.append(self.codeobject.co_varnames[i])\n\n code += '\\n // Compute result\\n'\n if self.rtype != NoneType:\n code += ' %s _result = '%(\n self.rtype.cxxtype,\n )\n else:\n code += ' '\n code += '%s(%s);\\n'%(\n self.name,\n string.join(argnames,','),\n )\n\n\n code += '\\n // Pack return\\n'\n if ( self.rtype == NoneType ):\n code += ' Py_INCREF(Py_None);\\n'\n code += ' return Py_None;\\n'\n else:\n result = self.rtype.outbound('_result')\n code += ' return %s;\\n'%result\n code += '}\\n'\n return code\n\n\n ##################################################################\n # MEMBER EMIT #\n ##################################################################\n def emit(self,s):\n self.__body += s\n self.__body += '\\n'\n return\n\n ##################################################################\n # MEMBER PUSH #\n ##################################################################\n def push(self,v,t):\n self.stack.append(v)\n self.types.append(t)\n return\n\n\n ##################################################################\n # MEMBER POP #\n ##################################################################\n def pop(self):\n v = self.stack[-1]\n del self.stack[-1]\n t = self.types[-1]\n del self.types[-1]\n return v,t\n\n ##################################################################\n # MEMBER UNIQUE #\n ##################################################################\n def unique(self):\n self.__uid += 1\n return 't%d'%self.__uid\n\n ##################################################################\n # MEMBER POST #\n ##################################################################\n def post(self,pc,action):\n if not self.forwards.has_key(pc):\n self.forwards[pc] = []\n self.forwards[pc].append(action)\n return\n\n ##################################################################\n # MEMBER EMIT_VALUE #\n ##################################################################\n def emit_value(self, v):\n descriptor = self.typedef_by_value(v)\n \n # Convert representation to CXX rhs\n rhs = descriptor.literalizer(v)\n lhs = self.unique()\n self.emit('%s %s = %s;'%(\n descriptor.cxxtype,\n lhs,\n rhs))\n self.push(lhs,descriptor)\n return \n\n ##################################################################\n # MEMBER GLOBAL_INFO #\n ##################################################################\n def global_info(self,var_num):\n # This is the name value is known by\n var_name = self.codeobject.co_names[var_num]\n\n # First, figure out who owns this global\n import sys\n myHash = id(self.function.func_globals)\n for module_name in sys.modules.keys():\n module = sys.modules[module_name]\n if module and id(module.__dict__) == myHash:\n break\n else:\n raise ValueError,'Cannot locate module owning %s'%varname\n return module_name,var_name\n\n ##################################################################\n # MEMBER BINOP #\n ##################################################################\n def binop(self,pc,symbol):\n v2,t2 = self.pop()\n v1,t1 = self.pop()\n\n if t1 == t2:\n rhs,rhs_type = t1.binop(symbol,v1,v2)\n else:\n rhs,rhs_type = t1.binopMixed(symbol,v1,v2)\n \n lhs = self.unique()\n self.emit('%s %s = %s;\\n'%(\n rhs_type.cxxtype,\n lhs,\n rhs))\n print self.__body\n self.push(lhs,rhs_type)\n return \n\n ##################################################################\n # MEMBER BINARY_XXX #\n ##################################################################\n def BINARY_ADD(self,pc):\n return self.binop(pc,'+')\n def BINARY_SUBTRACT(self,pc):\n return self.binop(pc,'-')\n def BINARY_MULTIPLY(self,pc):\n return self.binop(pc,'*')\n def BINARY_DIVIDE(self,pc):\n return self.binop(pc,'/')\n def BINARY_MODULO(self,pc):\n return self.binop(pc,'%')\n def BINARY_SUBSCR(self,pc):\n return self.binop(pc,'[]')\n def COMPARE_OP(self,pc,opname):\n symbol = self.cmp_op(opname) # convert numeric to name\n return self.binop(pc,symbol)\n\n\n ##################################################################\n # MEMBER PRINT_ITEM #\n ##################################################################\n def PRINT_ITEM(self,pc):\n # Printing correctly is tricky... best to let Python\n # do the real work here\n w = self.unique()\n self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n self.emit('if (PyFile_SoftSpace(%s,1)) PyFile_WriteString(\" \",%s);'%(w,w))\n v,t = self.pop()\n\n py = self.unique()\n self.emit('PyObject* %s = %s;'%(py, t.outbound(v)))\n self.emit('PyFile_WriteObject(%s,%s,Py_PRINT_RAW);'%(\n py,w))\n self.emit('Py_XDECREF(%s);'%py)\n return\n\n\n ##################################################################\n # MEMBER PRINT_NEWLINE #\n ##################################################################\n def PRINT_NEWLINE(self,pc):\n # Printing correctly is tricky... best to let Python\n # do the real work here\n w = self.unique()\n self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n self.emit('PyFile_WriteString(\"\\\\n\",%s);'%w);\n self.emit('PyFile_SoftSpace(%s,0);'%w);\n return\n \n ##################################################################\n # MEMBER SET_LINENO #\n ##################################################################\n def SET_LINENO(self,pc,lineno):\n self.emit('// %s:%d'%(self.codeobject.co_filename,lineno))\n return\n\n ##################################################################\n # MEMBER POP_TOP #\n ##################################################################\n def POP_TOP(self,pc):\n v,t = self.pop()\n return\n\n ##################################################################\n # MEMBER LOAD_CONST #\n ##################################################################\n def LOAD_CONST(self,pc,consti):\n # Fetch the constant\n k = self.consts[consti]\n t = type(k)\n print 'LOAD_CONST',repr(k),t\n\n # Fetch a None is just skipped\n if t == NoneType:\n self.push('',t) \n return\n\n self.emit_value(k)\n return\n\n\n ##################################################################\n # MEMBER LOAD_FAST #\n ##################################################################\n def LOAD_FAST(self,pc,var_num):\n v = self.stack[var_num]\n t = self.types[var_num]\n print 'LOADFAST',var_num,v,t\n if t.refcount:\n self.emit('Py_XINCREF(%s);'%v)\n self.push(v,t)\n return\n\n ##################################################################\n # MEMBER LOAD_GLOBAL #\n ##################################################################\n def LOAD_GLOBAL(self,pc,var_num):\n # Figure out the name and load it\n try:\n F = self.function.func_globals[self.codeobject.co_names[var_num]]\n except:\n F = getattr(__builtins__,self.codeobject.co_names[var_num])\n\n # For functions, we see if we know about this function\n if callable(F):\n assert functiondefs.has_key(F),\"Function %s is known\"%F\n self.push(F,type(F))\n return\n\n # We need the name of the module that matches\n # the global state for the function and\n # the name of the variable\n module_name,var_name = self.global_info(var_num)\n\n # We hope it's type is correct\n t = type(F)\n descriptor = typedefs[t]\n native = self.unique()\n py = self.unique()\n mod = self.unique()\n\n self.emit('')\n self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n mod,module_name))\n self.emit('PyObject* %s = PyObject_GetAttrString(%s,\"%s\");'%(\n py,mod,var_name))\n self.emit('%s %s = %s;'%(\n descriptor.cxxtype,\n native,\n descriptor.inbound%py))\n\n self.push(native,t)\n return\n\n ##################################################################\n # MEMBER STORE_FAST #\n ##################################################################\n def STORE_FAST(self,pc,var_num):\n\n v,t = self.pop()\n print 'STORE FAST',var_num,v,t\n\n save = self.stack[var_num]\n saveT = self.types[var_num]\n\n # See if type is same....\n # Note that None means no assignment made yet\n if saveT == None or t == saveT:\n if t.refcount:\n self.emit('Py_XINCREF(%s);'%v)\n self.emit('Py_XDECREF(%s);'%save)\n self.emit('%s = %s;\\n'%(save,v))\n self.types[var_num] = t\n return\n\n raise TypeError,(t,saveT)\n\n ##################################################################\n # MEMBER STORE_GLOBAL #\n ##################################################################\n def STORE_GLOBAL(self,pc,var_num):\n\n # We need the name of the module that matches\n # the global state for the function and\n # the name of the variable\n module_name,var_name = self.global_info(var_num)\n\n # Convert the value to Python object\n v,t = self.pop()\n descriptor = typedefs[t]\n py = self.unique()\n self.emit('PyObject* %s = %s;'%(\n py,\n descriptor.outbound%v))\n mod = self.unique()\n self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n mod,module_name))\n self.emit('PyObject_SetAttrString(%s,\"%s\",%s);'%(\n mod,var_name,py))\n self.emit('Py_DECREF(%s);'%py)\n return\n\n ##################################################################\n # MEMBER CALL_FUNCTION #\n ##################################################################\n def CALL_FUNCTION(self,pc,argc):\n # Pull args off stack\n args = []\n types = []\n for i in range(argc):\n v,t = self.pop()\n args = [v]+args\n types = [t]+types\n \n # Pull function object off stack and get descriptor\n f,t = self.pop()\n descriptor = functiondefs[f]\n #self.prerequisites += descriptor['prerequisite']+'\\n'\n \n # Look through descriptors for a match\n for inputs,outputs,format in descriptor:\n if inputs == types:\n break\n else:\n raise TypeError,f\n\n # Build a rhs\n rhs = format%string.join(args,',')\n\n # Build a statement\n assert len(outputs) == 1,\"Single valued return\"\n assert typedefs.has_key(outputs[0]),\"Know about type %s\"%outputs[0]\n description = typedefs[outputs[0]]\n temp = self.unique()\n self.emit('%s %s = %s;\\n'%(\n description.cxxtype,\n temp,\n rhs))\n\n self.push(temp,outputs[0])\n return\n\n\n ##################################################################\n # MEMBER JUMP_IF_FALSE #\n ##################################################################\n def JUMP_IF_FALSE(self,pc,delta):\n v,t = self.pop()\n self.push(v,t)\n # We need to do some work when we get to the\n # else part (put the value that's gonna get\n # popped back on the stack, emit } else {,\n # ...)\n action = lambda v=v,t=t,self=self: (\n self.emit('} else {'),\n self.push(v,t),\n )\n self.post(pc+delta,action)\n if t != IntType: raise TypeError, 'Invalid comparison type %s'%t\n self.emit('if (%s) {\\n'%v)\n return\n \n\n ##################################################################\n # MEMBER JUMP_FORWARD #\n ##################################################################\n def JUMP_FORWARD(self,pc,delta):\n # We need to close the if after the delta\n action = lambda self=self: (\n self.emit('}'),\n )\n self.post(pc+delta,action)\n return\n \n ##################################################################\n # MEMBER RETURN_VALUE #\n ##################################################################\n def RETURN_VALUE(self,pc):\n v,t = self.pop()\n if hasattr(self,'rtype'):\n print v,t\n if t == NoneType: return # just the extra return\n raise ValueError,'multiple returns'\n self.rtype = t\n if t == NoneType:\n self.emit('return;')\n else:\n self.emit('return %s;'%v)\n print 'return with',v\n return\n\n", + "source_code_before": "#**************************************************************************#\n#* FILE ************** bytecodecompiler.py ************************#\n#************************************************************************ **#\n#* Author: Patrick Miller February 9 2002 *#\n#* Copyright (C) 2002 Patrick J. Miller *#\n#**************************************************************************#\n#* *#\n#**************************************************************************#\nfrom types import *\nimport string\nimport inspect\n\n\n##################################################################\n# CLASS CXXTYPEDESCRIPTION #\n##################################################################\nclass Type_Descriptor:\n prerequisites = []\n def __repr__(self):\n return self.__module__+'.'+self.__class__.__name__\n\n\nhaveArgument = 90 # Opcodes greater-equal to this have argument\nbyName = {\n 'STOP_CODE': 0,\n 'POP_TOP': 1,\n 'ROT_TWO': 2,\n 'ROT_THREE': 3,\n 'DUP_TOP': 4,\n 'ROT_FOUR': 5,\n 'UNARY_POSITIVE': 10,\n 'UNARY_NEGATIVE': 11,\n 'UNARY_NOT': 12,\n 'UNARY_CONVERT': 13,\n 'UNARY_INVERT': 15,\n 'BINARY_POWER': 19,\n 'BINARY_MULTIPLY': 20,\n 'BINARY_DIVIDE': 21,\n 'BINARY_MODULO': 22,\n 'BINARY_ADD': 23,\n 'BINARY_SUBTRACT': 24,\n 'BINARY_SUBSCR': 25,\n 'BINARY_FLOOR_DIVIDE': 26,\n 'BINARY_TRUE_DIVIDE': 27,\n 'INPLACE_FLOOR_DIVIDE': 28,\n 'INPLACE_TRUE_DIVIDE': 29,\n 'SLICE': 30,\n 'STORE_SLICE': 40,\n 'DELETE_SLICE': 50,\n 'INPLACE_ADD': 55,\n 'INPLACE_SUBTRACT': 56,\n 'INPLACE_MULTIPLY': 57,\n 'INPLACE_DIVIDE': 58,\n 'INPLACE_MODULO': 59,\n 'STORE_SUBSCR': 60,\n 'DELETE_SUBSCR': 61,\n 'BINARY_LSHIFT': 62,\n 'BINARY_RSHIFT': 63,\n 'BINARY_AND': 64,\n 'BINARY_XOR': 65,\n 'BINARY_OR': 66,\n 'INPLACE_POWER': 67,\n 'GET_ITER': 68,\n 'PRINT_EXPR': 70,\n 'PRINT_ITEM': 71,\n 'PRINT_NEWLINE': 72,\n 'PRINT_ITEM_TO': 73,\n 'PRINT_NEWLINE_TO': 74,\n 'INPLACE_LSHIFT': 75,\n 'INPLACE_RSHIFT': 76,\n 'INPLACE_AND': 77,\n 'INPLACE_XOR': 78,\n 'INPLACE_OR': 79,\n 'BREAK_LOOP': 80,\n 'LOAD_LOCALS': 82,\n 'RETURN_VALUE': 83,\n 'IMPORT_STAR': 84,\n 'EXEC_STMT': 85,\n 'YIELD_VALUE': 86,\n 'POP_BLOCK': 87,\n 'END_FINALLY': 88,\n 'BUILD_CLASS': 89,\n 'STORE_NAME': 90,\n 'DELETE_NAME': 91,\n 'UNPACK_SEQUENCE': 92,\n 'FOR_ITER': 93,\n 'STORE_ATTR': 95,\n 'DELETE_ATTR': 96,\n 'STORE_GLOBAL': 97,\n 'DELETE_GLOBAL': 98,\n 'DUP_TOPX': 99,\n 'LOAD_CONST': 100,\n 'LOAD_NAME': 101,\n 'BUILD_TUPLE': 102,\n 'BUILD_LIST': 103,\n 'BUILD_MAP': 104,\n 'LOAD_ATTR': 105,\n 'COMPARE_OP': 106,\n 'IMPORT_NAME': 107,\n 'IMPORT_FROM': 108,\n 'JUMP_FORWARD': 110,\n 'JUMP_IF_FALSE': 111,\n 'JUMP_IF_TRUE': 112,\n 'JUMP_ABSOLUTE': 113,\n 'FOR_LOOP': 114,\n 'LOAD_GLOBAL': 116,\n 'CONTINUE_LOOP': 119,\n 'SETUP_LOOP': 120,\n 'SETUP_EXCEPT': 121,\n 'SETUP_FINALLY': 122,\n 'LOAD_FAST': 124,\n 'STORE_FAST': 125,\n 'DELETE_FAST': 126,\n 'SET_LINENO': 127,\n 'RAISE_VARARGS': 130,\n 'CALL_FUNCTION': 131,\n 'MAKE_FUNCTION': 132,\n 'BUILD_SLICE': 133,\n 'MAKE_CLOSURE': 134,\n 'LOAD_CLOSURE': 135,\n 'LOAD_DEREF': 136,\n 'STORE_DEREF': 137,\n 'CALL_FUNCTION_VAR': 140,\n 'CALL_FUNCTION_KW': 141,\n 'CALL_FUNCTION_VAR_KW': 142,\n }\n\n# -----------------------------------------------\n# Build one in the reverse sense\n# -----------------------------------------------\nbyOpcode = {}\nfor name,op in map(None, byName.keys(), byName.values()):\n byOpcode[op] = name\n del name\n del op\n \n\n##################################################################\n# FUNCTION OPCODIZE #\n##################################################################\ndef opcodize(s):\n \"Slightly more readable form\"\n length = len(s)\n i = 0\n answer = []\n while i < length:\n bytecode = ord(s[i])\n name = byOpcode[bytecode]\n if bytecode >= haveArgument:\n argument = 256*ord(s[i+2])+ord(s[i+1])\n i += 3\n else:\n argument = None\n i += 1\n answer.append((bytecode,argument,name))\n return answer\n\n\n\n##################################################################\n# FUNCTION LIST #\n##################################################################\ndef listing(f):\n \"Pretty print the internals of your function\"\n assert type(f) == FunctionType,\"Arg %r must be a function\"%f\n filename = f.func_code.co_filename\n try:\n lines = open(filename).readlines()\n except:\n lines = None\n pc = 0\n s = ''\n lastLine = None\n for op,arg,name in opcodize(f.func_code.co_code):\n if lines and name == 'SET_LINENO':\n source = lines[arg-1][:-1]\n while lastLine and lastLine < arg-1:\n nonEmittingSource = lines[lastLine][:-1]\n lastLine += 1\n s += '%3s %20s %5s : %s\\n'%(\n '','','',nonEmittingSource)\n lastLine = arg\n else:\n source = ''\n if arg == None: arg = ''\n s += '%3d] %20s %5s : %s\\n'%(pc,name,arg,source)\n pc += 1\n return s\n\n##################################################################\n# CLASS BYTECODEMEANING #\n##################################################################\nclass ByteCodeMeaning:\n def fetch(self, pc,code):\n opcode = ord(code[pc])\n if opcode >= haveArgument:\n argument = 256*ord(code[pc+2])+ord(code[pc+1])\n next = pc+3\n else:\n argument = None\n next = pc+1\n return next,opcode,argument\n \n def execute(self,pc,opcode,argument):\n name = byOpcode[opcode]\n method = getattr(self,name)\n if argument == None:\n return apply(method,(pc,))\n else:\n return apply(method,(pc,argument,))\n\n def evaluate(self, pc,code):\n next, opcode,argument = self.fetch(pc,code)\n goto = self.execute(next,opcode,argument)\n if goto == -1:\n return None # Must be done\n elif goto == None:\n return next # Normal\n else:\n raise 'xx'\n\n symbols = { 0: 'less', 1: 'lesseq', 2: 'equal', 3: 'notequal',\n 4: 'greater', 5: 'greatereq', 6: 'in', 7: 'not in',\n 8: 'is', 9: 'is not', 10: 'exe match',\n 11 : 'bad',\n }\n def cmp_op(self,opname):\n return self.symbols[opname]\n \n def STOP_CODE(self,pc):\n \"Indicates end-of-code to the compiler, not used by the interpreter.\"\n raise NotImplementedError\n def POP_TOP(self,pc):\n \"Removes the top-of-stack (TOS) item.\"\n raise NotImplementedError\n\n def ROT_TWO(self,pc):\n \"Swaps the two top-most stack items.\"\n raise NotImplementedError\n\n def ROT_THREE(self,pc):\n \"Lifts second and third stack item one position up, moves top down to position three.\"\n raise NotImplementedError\n\n def ROT_FOUR(self,pc):\n \"Lifts second, third and forth stack item one position up, moves top down to position four.\"\n raise NotImplementedError\n\n def DUP_TOP(self,pc):\n \"Duplicates the reference on top of the stack.\"\n raise NotImplementedError\n\n # Unary Operations take the top of the stack, apply the operation, and push the result back on the stack.\n\n def UNARY_POSITIVE(self,pc):\n \"Implements TOS = +TOS.\"\n raise NotImplementedError\n\n def UNARY_NEGATIVE(self,pc):\n \"Implements TOS = -TOS.\"\n raise NotImplementedError\n\n def UNARY_NOT(self,pc):\n \"Implements TOS = not TOS.\"\n raise NotImplementedError\n\n def UNARY_CONVERT(self,pc):\n \"Implements TOS = `TOS`.\"\n raise NotImplementedError\n\n def UNARY_INVERT(self,pc):\n \"Implements TOS = ~TOS.\"\n raise NotImplementedError\n\n #Binary operations remove the top of the stack (TOS) and the second top-most stack item (TOS1) from the stack. They perform the operation, and put the result back on the stack.\n\n def BINARY_POWER(self,pc):\n \"Implements TOS = TOS1 ** TOS.\"\n raise NotImplementedError\n\n def BINARY_MULTIPLY(self,pc):\n \"Implements TOS = TOS1 * TOS.\"\n raise NotImplementedError\n\n def BINARY_DIVIDE(self,pc):\n \"Implements TOS = TOS1 / TOS.\"\n raise NotImplementedError\n\n def BINARY_MODULO(self,pc):\n \"Implements TOS = TOS1 % TOS.\"\n raise NotImplementedError\n\n def BINARY_ADD(self,pc):\n \"Implements TOS = TOS1 + TOS.\"\n raise NotImplementedError\n\n def BINARY_SUBTRACT(self,pc):\n \"Implements TOS = TOS1 - TOS.\"\n raise NotImplementedError\n\n def BINARY_SUBSCR(self,pc):\n \"Implements TOS = TOS1[TOS].\"\n raise NotImplementedError\n\n def BINARY_LSHIFT(self,pc):\n \"Implements TOS = TOS1 << TOS.\"\n raise NotImplementedError\n\n def BINARY_RSHIFT(self,pc):\n \"Implements TOS = TOS1 >> TOS.\"\n raise NotImplementedError\n\n def BINARY_AND(self,pc):\n \"Implements TOS = TOS1 & TOS.\"\n raise NotImplementedError\n\n def BINARY_XOR(self,pc):\n \"Implements TOS = TOS1 ^ TOS.\"\n raise NotImplementedError\n\n def BINARY_OR(self,pc):\n \"Implements TOS = TOS1 | TOS.\"\n raise NotImplementedError\n\n #In-place operations are like binary operations, in that they remove TOS and TOS1, and push the result back on the stack, but the operation is done in-place when TOS1 supports it, and the resulting TOS may be (but does not have to be) the original TOS1.\n\n def INPLACE_POWER(self,pc):\n \"Implements in-place TOS = TOS1 ** TOS.\"\n raise NotImplementedError\n\n def INPLACE_MULTIPLY(self,pc):\n \"Implements in-place TOS = TOS1 * TOS.\"\n raise NotImplementedError\n\n def INPLACE_DIVIDE(self,pc):\n \"Implements in-place TOS = TOS1 / TOS.\"\n raise NotImplementedError\n\n def INPLACE_MODULO(self,pc):\n \"Implements in-place TOS = TOS1 % TOS.\"\n raise NotImplementedError\n\n def INPLACE_ADD(self,pc):\n \"Implements in-place TOS = TOS1 + TOS.\"\n raise NotImplementedError\n\n def INPLACE_SUBTRACT(self,pc):\n \"Implements in-place TOS = TOS1 - TOS.\"\n raise NotImplementedError\n\n def INPLACE_LSHIFT(self,pc):\n \"Implements in-place TOS = TOS1 << TOS.\"\n raise NotImplementedError\n\n def INPLACE_RSHIFT(self,pc):\n \"Implements in-place TOS = TOS1 >> TOS.\"\n raise NotImplementedError\n\n def INPLACE_AND(self,pc):\n \"Implements in-place TOS = TOS1 & TOS.\"\n raise NotImplementedError\n\n def INPLACE_XOR(self,pc):\n \"Implements in-place TOS = TOS1 ^ TOS.\"\n raise NotImplementedError\n\n def INPLACE_OR(self,pc):\n \"Implements in-place TOS = TOS1 | TOS.\"\n raise NotImplementedError\n\n #The slice opcodes take up to three parameters.\n\n def SLICE_0(self,pc):\n \"Implements TOS = TOS[:].\"\n raise NotImplementedError\n\n def SLICE_1(self,pc):\n \"Implements TOS = TOS1[TOS:].\"\n raise NotImplementedError\n\n def SLICE_2(self,pc):\n \"Implements TOS = TOS1[:TOS1].\"\n raise NotImplementedError\n\n def SLICE_3(self,pc):\n \"Implements TOS = TOS2[TOS1:TOS].\"\n raise NotImplementedError\n\n #Slice assignment needs even an additional parameter. As any statement, they put nothing on the stack.\n\n def STORE_SLICE_0(self,pc):\n \"Implements TOS[:] = TOS1.\"\n raise NotImplementedError\n\n def STORE_SLICE_1(self,pc):\n \"Implements TOS1[TOS:] = TOS2.\"\n raise NotImplementedError\n\n def STORE_SLICE_2(self,pc):\n \"Implements TOS1[:TOS] = TOS2.\"\n raise NotImplementedError\n\n def STORE_SLICE_3(self,pc):\n \"Implements TOS2[TOS1:TOS] = TOS3.\"\n raise NotImplementedError\n\n def DELETE_SLICE_0(self,pc):\n \"Implements del TOS[:].\"\n raise NotImplementedError\n\n def DELETE_SLICE_1(self,pc):\n \"Implements del TOS1[TOS:].\"\n raise NotImplementedError\n\n def DELETE_SLICE_2(self,pc):\n \"Implements del TOS1[:TOS].\"\n raise NotImplementedError\n\n def DELETE_SLICE_3(self,pc):\n \"Implements del TOS2[TOS1:TOS].\"\n raise NotImplementedError\n\n def STORE_SUBSCR(self,pc):\n \"Implements TOS1[TOS] = TOS2.\"\n raise NotImplementedError\n\n def DELETE_SUBSCR(self,pc):\n \"Implements del TOS1[TOS].\"\n raise NotImplementedError\n\n def PRINT_EXPR(self,pc):\n \"Implements the expression statement for the interactive mode. TOS is removed from the stack and printed. In non-interactive mode, an expression statement is terminated with POP_STACK.\"\n raise NotImplementedError\n\n def PRINT_ITEM(self,pc):\n \"Prints TOS to the file-like object bound to sys.stdout. There is one such instruction for each item in the print statement.\"\n raise NotImplementedError\n\n def PRINT_ITEM_TO(self,pc):\n \"Like PRINT_ITEM, but prints the item second from TOS to the file-like object at TOS. This is used by the extended print statement.\"\n raise NotImplementedError\n\n def PRINT_NEWLINE(self,pc):\n \"Prints a new line on sys.stdout. This is generated as the last operation of a print statement, unless the statement ends with a comma.\"\n raise NotImplementedError\n\n def PRINT_NEWLINE_TO(self,pc):\n \"Like PRINT_NEWLINE, but prints the new line on the file-like object on the TOS. This is used by the extended print statement.\"\n raise NotImplementedError\n\n def BREAK_LOOP(self,pc):\n \"Terminates a loop due to a break statement.\"\n raise NotImplementedError\n\n def LOAD_LOCALS(self,pc):\n \"Pushes a reference to the locals of the current scope on the stack. This is used in the code for a class definition: After the class body is evaluated, the locals are passed to the class definition.\"\n raise NotImplementedError\n\n def RETURN_VALUE(self,pc):\n \"Returns with TOS to the caller of the function.\"\n raise NotImplementedError\n\n def IMPORT_STAR(self,pc):\n \"Loads all symbols not starting with _ directly from the module TOS to the local namespace. The module is popped after loading all names. This opcode implements from module import *.\"\n raise NotImplementedError\n\n def EXEC_STMT(self,pc):\n \"Implements exec TOS2,TOS1,TOS. The compiler fills missing optional parameters with None.\"\n raise NotImplementedError\n\n def POP_BLOCK(self,pc):\n \"Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.\"\n raise NotImplementedError\n\n def END_FINALLY(self,pc):\n \"Terminates a finally clause. The interpreter recalls whether the exception has to be re-raised, or whether the function returns, and continues with the outer-next block.\"\n raise NotImplementedError\n\n def BUILD_CLASS(self,pc):\n \"Creates a new class object. TOS is the methods dictionary, TOS1 the tuple of the names of the base classes, and TOS2 the class name.\"\n raise NotImplementedError\n\n #All of the following opcodes expect arguments. An argument is two bytes, with the more significant byte last.\n\n def STORE_NAME(self,pc,namei):\n \"Implements name = TOS. namei is the index of name in the attribute co_names of the code object. The compiler tries to use STORE_LOCAL or STORE_GLOBAL if possible.\"\n raise NotImplementedError\n\n def DELETE_NAME(self,pc,namei):\n \"Implements del name, where namei is the index into co_names attribute of the code object.\"\n raise NotImplementedError\n\n def UNPACK_SEQUENCE(self,pc,count):\n \"Unpacks TOS into count individual values, which are put onto the stack right-to-left.\"\n raise NotImplementedError\n\n def DUP_TOPX(self,pc,count):\n \"Duplicate count items, keeping them in the same order. Due to implementation limits, count should be between 1 and 5 inclusive.\"\n raise NotImplementedError\n\n def STORE_ATTR(self,pc,namei):\n \"Implements TOS.name = TOS1, where namei is the index of name in co_names.\"\n raise NotImplementedError\n\n def DELETE_ATTR(self,pc,namei):\n \"Implements del TOS.name, using namei as index into co_names.\"\n raise NotImplementedError\n\n def STORE_GLOBAL(self,pc,namei):\n \"Works as STORE_NAME, but stores the name as a global.\"\n raise NotImplementedError\n\n def DELETE_GLOBAL(self,pc,namei):\n \"Works as DELETE_NAME, but deletes a global name.\"\n raise NotImplementedError\n\n def LOAD_CONST(self,pc,consti):\n \"Pushes co_consts[consti] onto the stack.\"\n raise NotImplementedError\n\n def LOAD_NAME(self,pc,namei):\n \"Pushes the value associated with co_names[namei] onto the stack.\"\n raise NotImplementedError\n\n def BUILD_TUPLE(self,pc,count):\n \"Creates a tuple consuming count items from the stack, and pushes the resulting tuple onto the stack.\"\n raise NotImplementedError\n\n def BUILD_LIST(self,pc,count):\n \"Works as BUILD_TUPLE, but creates a list.\"\n raise NotImplementedError\n\n def BUILD_MAP(self,pc,zero):\n \"Pushes a new empty dictionary object onto the stack. The argument is ignored and set to zero by the compiler.\"\n raise NotImplementedError\n\n def LOAD_ATTR(self,pc,namei):\n \"Replaces TOS with getattr(TOS, co_names[namei].\"\n raise NotImplementedError\n\n def COMPARE_OP(self,pc,opname):\n \"Performs a Boolean operation. The operation name can be found in cmp_op[opname].\"\n raise NotImplementedError\n\n def IMPORT_NAME(self,pc,namei):\n \"Imports the module co_names[namei]. The module object is pushed onto the stack. The current namespace is not affected: for a proper import statement, a subsequent STORE_FAST instruction modifies the namespace.\"\n raise NotImplementedError\n\n def IMPORT_FROM(self,pc,namei):\n \"Loads the attribute co_names[namei] from the module found in TOS. The resulting object is pushed onto the stack, to be subsequently stored by a STORE_FAST instruction.\"\n raise NotImplementedError\n\n def JUMP_FORWARD(self,pc,delta):\n \"Increments byte code counter by delta.\"\n raise NotImplementedError\n\n def JUMP_IF_TRUE(self,pc,delta):\n \"If TOS is true, increment the byte code counter by delta. TOS is left on the stack.\"\n raise NotImplementedError\n\n def JUMP_IF_FALSE(self,pc,delta):\n \"If TOS is false, increment the byte code counter by delta. TOS is not changed.\"\n raise NotImplementedError\n\n def JUMP_ABSOLUTE(self,pc,target):\n \"Set byte code counter to target.\"\n raise NotImplementedError\n\n def FOR_LOOP(self,pc,delta):\n \"Iterate over a sequence. TOS is the current index, TOS1 the sequence. First, the next element is computed. If the sequence is exhausted, increment byte code counter by delta. Otherwise, push the sequence, the incremented counter, and the current item onto the stack.\"\n raise NotImplementedError\n\n def LOAD_GLOBAL(self,pc,namei):\n \"Loads the global named co_names[namei] onto the stack.\"\n raise NotImplementedError\n\n def SETUP_LOOP(self,pc,delta):\n \"Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.\"\n raise NotImplementedError\n\n def SETUP_EXCEPT(self,pc,delta):\n \"Pushes a try block from a try-except clause onto the block stack. delta points to the first except block.\"\n raise NotImplementedError\n\n def SETUP_FINALLY(self,pc,delta):\n \"Pushes a try block from a try-except clause onto the block stack. delta points to the finally block.\"\n raise NotImplementedError\n\n def LOAD_FAST(self,pc,var_num):\n \"Pushes a reference to the local co_varnames[var_num] onto the stack.\"\n raise NotImplementedError\n\n def STORE_FAST(self,pc,var_num):\n \"Stores TOS into the local co_varnames[var_num].\"\n raise NotImplementedError\n\n def DELETE_FAST(self,pc,var_num):\n \"Deletes local co_varnames[var_num].\"\n raise NotImplementedError\n\n def LOAD_CLOSURE(self,pc,i):\n \"Pushes a reference to the cell contained in slot i of the cell and free variable storage. The name of the variable is co_cellvars[i] if i is less than the length of co_cellvars. Otherwise it is co_freevars[i - len(co_cellvars)].\"\n raise NotImplementedError\n\n def LOAD_DEREF(self,pc,i):\n \"Loads the cell contained in slot i of the cell and free variable storage. Pushes a reference to the object the cell contains on the stack.\"\n raise NotImplementedError\n\n def STORE_DEREF(self,pc,i):\n \"Stores TOS into the cell contained in slot i of the cell and free variable storage.\"\n raise NotImplementedError\n\n def SET_LINENO(self,pc,lineno):\n \"Sets the current line number to lineno.\"\n raise NotImplementedError\n\n def RAISE_VARARGS(self,pc,argc):\n \"Raises an exception. argc indicates the number of parameters to the raise statement, ranging from 0 to 3. The handler will find the traceback as TOS2, the parameter as TOS1, and the exception as TOS.\"\n raise NotImplementedError\n\n def CALL_FUNCTION(self,pc,argc):\n \"Calls a function. The low byte of argc indicates the number of positional parameters, the high byte the number of keyword parameters. On the stack, the opcode finds the keyword parameters first. For each keyword argument, the value is on top of the key. Below the keyword parameters, the positional parameters are on the stack, with the right-most parameter on top. Below the parameters, the function object to call is on the stack.\"\n raise NotImplementedError\n\n def MAKE_FUNCTION(self,pc,argc):\n \"Pushes a new function object on the stack. TOS is the code associated with the function. The function object is defined to have argc default parameters, which are found below TOS.\"\n raise NotImplementedError\n\n def MAKE_CLOSURE(self,pc,argc):\n \"Creates a new function object, sets its func_closure slot, and pushes it on the stack. TOS is the code associated with the function. If the code object has N free variables, the next N items on the stack are the cells for these variables. The function also has argc default parameters, where are found before the cells.\"\n raise NotImplementedError\n\n def BUILD_SLICE(self,pc,argc):\n \"Pushes a slice object on the stack. argc must be 2 or 3. If it is 2, slice(TOS1, TOS) is pushed; if it is 3, slice(TOS2, TOS1, TOS) is pushed. See the slice() built-in function for more information.\"\n raise NotImplementedError\n\n def EXTENDED_ARG(self,pc,ext):\n \"Prefixes any opcode which has an argument too big to fit into the default two bytes. ext holds two additional bytes which, taken together with the subsequent opcode's argument, comprise a four-byte argument, ext being the two most-significant bytes.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_VAR(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the variable argument list, followed by keyword and positional arguments.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_KW(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by explicit keyword and positional arguments.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_VAR_KW(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by the variable-arguments tuple, followed by explicit keyword and positional arguments.\"\n raise NotImplementedError\n\n \n\n##################################################################\n# CLASS CXXCODER #\n##################################################################\nclass CXXCoder(ByteCodeMeaning):\n\n ##################################################################\n # MEMBER TYPEDEF_BY_VALUE #\n ##################################################################\n def typedef_by_value(self,v):\n raise NotImplementedError # VIRTUAL\n \n ##################################################################\n # MEMBER __INIT__ #\n ##################################################################\n def __init__(self,function,signature,name=None):\n assert type(function) == FunctionType,\"Arg must be a user function\"\n assert not function.func_defaults ,\"Function cannot have default args (yet)\"\n if name == None: name = function.func_name\n self.name = name\n self.function = function\n self.signature = signature\n self.codeobject = function.func_code\n self.__uid = 0 # Builds temps\n return\n\n ##################################################################\n # MEMBER EVALUATE #\n ##################################################################\n def evaluate(self, pc,code):\n # See if we posted any forwards for this offset\n if self.forwards.has_key(pc):\n for f in self.forwards[pc]:\n f()\n self.forwards[pc] = []\n return ByteCodeMeaning.evaluate(self,pc,code)\n \n ##################################################################\n # MEMBER GENERATE #\n ##################################################################\n def generate(self):\n self.forwards = {} # Actions on forward interprets\n self.__body = '' # Body will be built\n self.helpers = [] # headers and stuff\n\n # -----------------------------------------------\n # OK, crack open the function object and build\n # initial stack (not a real frame!)\n # -----------------------------------------------\n arglen = len(self.signature)\n nlocals = self.codeobject.co_nlocals\n\n self.consts = self.codeobject.co_consts\n self.stack = list(self.codeobject.co_varnames)\n self.types = list(self.signature)+[None]*(nlocals-arglen)\n self.used = []\n for T in self.types:\n if T not in self.used: self.used.append(T)\n\n # -----------------------------------------------\n # One pass through the byte codes to generate\n # the body\n # -----------------------------------------------\n code = self.codeobject.co_code\n pc = 0\n while pc != None:\n pc = self.evaluate(pc,code)\n\n # -----------------------------------------------\n # Return?\n # -----------------------------------------------\n if self.rtype == NoneType:\n rtype = 'void'\n else:\n rtype = self.rtype.cxxtype\n \n # -----------------------------------------------\n # Insert code body if available\n # -----------------------------------------------\n source = inspect.getsource(self.function)\n if not source: source = ''\n comments = inspect.getcomments(self.function)\n if comments: source = comments+source\n code = string.join(map(lambda x: '/////// '+x,string.split(source,'\\n')),\n '\\n')+'\\n'\n\n # -----------------------------------------------\n # Add in the headers\n # -----------------------------------------------\n code += '#include \"Python.h\"\\n'\n for T in self.used:\n print T.prerequisites\n for pre in T.prerequisites:\n code += pre\n code += '\\n'\n\n # -----------------------------------------------\n # Real body\n # -----------------------------------------------\n code += '\\n'\n code += '\\nstatic %s %s('%(rtype,self.name)\n for i in range(len(self.signature)):\n if i != 0: code += ', '\n n = self.stack[i]\n t = self.types[i]\n code += '%s %s'%(t.cxxtype,n)\n code += ') {\\n'\n\n # Add in non-argument temporaries\n # Assuming first argcount locals are positional args\n for i in range(self.codeobject.co_argcount,\n self.codeobject.co_nlocals):\n t = self.types[i]\n descriptor = typedefs[t]\n code += '%s %s;\\n'%(\n descriptor.cxxtype,\n self.codeobject.co_varnames[i],\n )\n\n # Add in the body\n code += self.__body\n code += '}\\n\\n'\n return code\n\n\n ##################################################################\n # MEMBER WRAPPED_CODE #\n ##################################################################\n def wrapped_code(self):\n code = self.generate()\n \n # -----------------------------------------------\n # Wrapper\n # -----------------------------------------------\n code += 'static PyObject* wrapper_%s(PyObject*,PyObject* args) {\\n'%self.name\n\n code += ' // Length check\\n'\n code += ' if ( PyTuple_Size(args) != %d ) {\\n'%len(self.signature)\n code += ' PyErr_SetString(PyExc_TypeError,\"Expected %d arguments\");\\n'%len(self.signature)\n code += ' return 0;\\n'\n code += ' }\\n'\n\n code += '\\n // Load Py versions of args\\n'\n for i in range(len(self.signature)):\n T = self.signature[i]\n code += ' PyObject* py_%s = PyTuple_GET_ITEM(args,%d);\\n'%(\n self.codeobject.co_varnames[i],i\n )\n\n code += ' if ( !%s ) {\\n'% \\\n T.check('py_'+self.codeobject.co_varnames[i])\n code += ' PyErr_SetString(PyExc_TypeError,\"Bad type for arg %d (expected %s)\");\\n'%(\n i+1,\n T.__class__.__name__)\n code += ' return 0;\\n'\n code += ' }\\n'\n \n code += '\\n // Do conversions\\n'\n argnames = []\n for i in range(len(self.signature)):\n T = self.signature[i]\n\n code += ' %s %s=%s;\\n'%(\n T.cxxtype,\n self.codeobject.co_varnames[i],\n T.inbound('py_'+self.codeobject.co_varnames[i]),\n )\n code += ' if ( PyErr_Occurred() ) return 0;\\n'\n argnames.append(self.codeobject.co_varnames[i])\n\n code += '\\n // Compute result\\n'\n if self.rtype != NoneType:\n code += ' %s _result = '%(\n self.rtype.cxxtype,\n )\n else:\n code += ' '\n code += '%s(%s);\\n'%(\n self.name,\n string.join(argnames,','),\n )\n\n\n code += '\\n // Pack return\\n'\n if ( self.rtype == NoneType ):\n code += ' Py_INCREF(Py_None);\\n'\n code += ' return Py_None;\\n'\n else:\n result = self.rtype.outbound('_result')\n code += ' return %s;\\n'%result\n code += '}\\n'\n return code\n\n\n ##################################################################\n # MEMBER EMIT #\n ##################################################################\n def emit(self,s):\n self.__body += s\n self.__body += '\\n'\n return\n\n ##################################################################\n # MEMBER PUSH #\n ##################################################################\n def push(self,v,t):\n self.stack.append(v)\n self.types.append(t)\n return\n\n\n ##################################################################\n # MEMBER POP #\n ##################################################################\n def pop(self):\n v = self.stack[-1]\n del self.stack[-1]\n t = self.types[-1]\n del self.types[-1]\n return v,t\n\n ##################################################################\n # MEMBER UNIQUE #\n ##################################################################\n def unique(self):\n self.__uid += 1\n return 't%d'%self.__uid\n\n ##################################################################\n # MEMBER POST #\n ##################################################################\n def post(self,pc,action):\n if not self.forwards.has_key(pc):\n self.forwards[pc] = []\n self.forwards[pc].append(action)\n return\n\n ##################################################################\n # MEMBER EMIT_VALUE #\n ##################################################################\n def emit_value(self, v):\n descriptor = self.typedef_by_value(v)\n \n # Convert representation to CXX rhs\n rhs = descriptor.literalizer(v)\n lhs = self.unique()\n self.emit('%s %s = %s;'%(\n descriptor.cxxtype,\n lhs,\n rhs))\n self.push(lhs,descriptor)\n return \n\n ##################################################################\n # MEMBER GLOBAL_INFO #\n ##################################################################\n def global_info(self,var_num):\n # This is the name value is known by\n var_name = self.codeobject.co_names[var_num]\n\n # First, figure out who owns this global\n import sys\n myHash = id(self.function.func_globals)\n for module_name in sys.modules.keys():\n module = sys.modules[module_name]\n if module and id(module.__dict__) == myHash:\n break\n else:\n raise ValueError,'Cannot locate module owning %s'%varname\n return module_name,var_name\n\n ##################################################################\n # MEMBER BINOP #\n ##################################################################\n def binop(self,pc,symbol):\n v2,t2 = self.pop()\n v1,t1 = self.pop()\n\n if t1 == t2:\n rhs,rhs_type = t1.binop(symbol,v1,v2)\n else:\n raise NotImplementedError,'mixed types'\n \n lhs = self.unique()\n self.emit('%s %s = %s;\\n'%(\n rhs_type.cxxtype,\n lhs,\n rhs))\n self.push(lhs,rhs_type)\n return \n\n ##################################################################\n # MEMBER BINARY_XXX #\n ##################################################################\n def BINARY_ADD(self,pc):\n return self.binop(pc,'+')\n def BINARY_SUBTRACT(self,pc):\n return self.binop(pc,'-')\n def BINARY_MULTIPLY(self,pc):\n return self.binop(pc,'*')\n def BINARY_DIVIDE(self,pc):\n return self.binop(pc,'/')\n def BINARY_MODULO(self,pc):\n return self.binop(pc,'%')\n def COMPARE_OP(self,pc,opname):\n symbol = self.cmp_op(opname) # convert numeric to name\n return self.binop(pc,symbol)\n\n\n ##################################################################\n # MEMBER PRINT_ITEM #\n ##################################################################\n def PRINT_ITEM(self,pc):\n # Printing correctly is tricky... best to let Python\n # do the real work here\n w = self.unique()\n self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n self.emit('if (PyFile_SoftSpace(%s,1)) PyFile_WriteString(\" \",%s);'%(w,w))\n v,t = self.pop()\n\n py = self.unique()\n self.emit('PyObject* %s = %s;'%(py, t.outbound(v)))\n self.emit('PyFile_WriteObject(%s,%s,Py_PRINT_RAW);'%(\n py,w))\n self.emit('Py_XDECREF(%s);'%py)\n return\n\n\n ##################################################################\n # MEMBER PRINT_NEWLINE #\n ##################################################################\n def PRINT_NEWLINE(self,pc):\n # Printing correctly is tricky... best to let Python\n # do the real work here\n w = self.unique()\n self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n self.emit('PyFile_WriteString(\"\\\\n\",%s);'%w);\n self.emit('PyFile_SoftSpace(%s,0);'%w);\n return\n \n ##################################################################\n # MEMBER SET_LINENO #\n ##################################################################\n def SET_LINENO(self,pc,lineno):\n self.emit('// %s:%d'%(self.codeobject.co_filename,lineno))\n return\n\n ##################################################################\n # MEMBER POP_TOP #\n ##################################################################\n def POP_TOP(self,pc):\n v,t = self.pop()\n return\n\n ##################################################################\n # MEMBER LOAD_CONST #\n ##################################################################\n def LOAD_CONST(self,pc,consti):\n # Fetch the constant\n k = self.consts[consti]\n t = type(k)\n\n # Fetch a None is just skipped\n if t == NoneType:\n self.push('',t) \n return\n\n self.emit_value(k)\n return\n\n\n ##################################################################\n # MEMBER LOAD_FAST #\n ##################################################################\n def LOAD_FAST(self,pc,var_num):\n v = self.stack[var_num]\n t = self.types[var_num]\n self.push(v,t)\n return\n\n ##################################################################\n # MEMBER LOAD_GLOBAL #\n ##################################################################\n def LOAD_GLOBAL(self,pc,var_num):\n # Figure out the name and load it\n try:\n F = self.function.func_globals[self.codeobject.co_names[var_num]]\n except:\n F = getattr(__builtins__,self.codeobject.co_names[var_num])\n\n # For functions, we see if we know about this function\n if callable(F):\n assert functiondefs.has_key(F),\"Function %s is known\"%F\n self.push(F,type(F))\n return\n\n # We need the name of the module that matches\n # the global state for the function and\n # the name of the variable\n module_name,var_name = self.global_info(var_num)\n\n # We hope it's type is correct\n t = type(F)\n descriptor = typedefs[t]\n native = self.unique()\n py = self.unique()\n mod = self.unique()\n\n self.emit('')\n self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n mod,module_name))\n self.emit('PyObject* %s = PyObject_GetAttrString(%s,\"%s\");'%(\n py,mod,var_name))\n self.emit('%s %s = %s;'%(\n descriptor.cxxtype,\n native,\n descriptor.inbound%py))\n\n self.push(native,t)\n return\n\n ##################################################################\n # MEMBER STORE_FAST #\n ##################################################################\n def STORE_FAST(self,pc,var_num):\n\n v,t = self.pop()\n\n save = self.stack[var_num]\n saveT = self.types[var_num]\n\n # See if type is same....\n # Note that None means no assignment made yet\n if saveT == None or t == saveT:\n self.emit('%s = %s;\\n'%(save,v))\n self.types[var_num] = t\n return\n\n raise TypeError,(t,saveT)\n\n ##################################################################\n # MEMBER STORE_GLOBAL #\n ##################################################################\n def STORE_GLOBAL(self,pc,var_num):\n\n # We need the name of the module that matches\n # the global state for the function and\n # the name of the variable\n module_name,var_name = self.global_info(var_num)\n\n # Convert the value to Python object\n v,t = self.pop()\n descriptor = typedefs[t]\n py = self.unique()\n self.emit('PyObject* %s = %s;'%(\n py,\n descriptor.outbound%v))\n mod = self.unique()\n self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n mod,module_name))\n self.emit('PyObject_SetAttrString(%s,\"%s\",%s);'%(\n mod,var_name,py))\n self.emit('Py_DECREF(%s);'%py)\n return\n\n ##################################################################\n # MEMBER CALL_FUNCTION #\n ##################################################################\n def CALL_FUNCTION(self,pc,argc):\n # Pull args off stack\n args = []\n types = []\n for i in range(argc):\n v,t = self.pop()\n args = [v]+args\n types = [t]+types\n \n # Pull function object off stack and get descriptor\n f,t = self.pop()\n descriptor = functiondefs[f]\n #self.prerequisites += descriptor['prerequisite']+'\\n'\n \n # Look through descriptors for a match\n for inputs,outputs,format in descriptor:\n if inputs == types:\n break\n else:\n raise TypeError,f\n\n # Build a rhs\n rhs = format%string.join(args,',')\n\n # Build a statement\n assert len(outputs) == 1,\"Single valued return\"\n assert typedefs.has_key(outputs[0]),\"Know about type %s\"%outputs[0]\n description = typedefs[outputs[0]]\n temp = self.unique()\n self.emit('%s %s = %s;\\n'%(\n description.cxxtype,\n temp,\n rhs))\n\n self.push(temp,outputs[0])\n return\n\n\n ##################################################################\n # MEMBER JUMP_IF_FALSE #\n ##################################################################\n def JUMP_IF_FALSE(self,pc,delta):\n v,t = self.pop()\n self.push(v,t)\n # We need to do some work when we get to the\n # else part (put the value that's gonna get\n # popped back on the stack, emit } else {,\n # ...)\n action = lambda v=v,t=t,self=self: (\n self.emit('} else {'),\n self.push(v,t),\n )\n self.post(pc+delta,action)\n if t != IntType: raise TypeError, 'Invalid comparison type %s'%t\n self.emit('if (%s) {\\n'%v)\n return\n \n\n ##################################################################\n # MEMBER JUMP_FORWARD #\n ##################################################################\n def JUMP_FORWARD(self,pc,delta):\n # We need to close the if after the delta\n action = lambda self=self: (\n self.emit('}'),\n )\n self.post(pc+delta,action)\n return\n \n ##################################################################\n # MEMBER RETURN_VALUE #\n ##################################################################\n def RETURN_VALUE(self,pc):\n v,t = self.pop()\n if hasattr(self,'rtype'):\n raise ValueError,'multiple returns'\n self.rtype = t\n if t == NoneType:\n self.emit('return;')\n else:\n self.emit('return %s;'%v)\n return -1\n\n", + "methods": [ + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self" + ], + "start_line": 20, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "opcodize", + "long_name": "opcodize( s )", + "filename": "bytecodecompiler.py", + "nloc": 16, + "complexity": 3, + "token_count": 92, + "parameters": [ + "s" + ], + "start_line": 142, + "end_line": 157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "listing", + "long_name": "listing( f )", + "filename": "bytecodecompiler.py", + "nloc": 29, + "complexity": 9, + "token_count": 166, + "parameters": [ + "f" + ], + "start_line": 164, + "end_line": 192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "fetch", + "long_name": "fetch( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 198, + "end_line": 206, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "execute", + "long_name": "execute( self , pc , opcode , argument )", + "filename": "bytecodecompiler.py", + "nloc": 7, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "pc", + "opcode", + "argument" + ], + "start_line": 208, + "end_line": 214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "evaluate", + "long_name": "evaluate( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 216, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "cmp_op", + "long_name": "cmp_op( self , opname )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "opname" + ], + "start_line": 231, + "end_line": 232, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "STOP_CODE", + "long_name": "STOP_CODE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 234, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_TOP", + "long_name": "POP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 237, + "end_line": 239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_TWO", + "long_name": "ROT_TWO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 241, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_THREE", + "long_name": "ROT_THREE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 245, + "end_line": 247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_FOUR", + "long_name": "ROT_FOUR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 249, + "end_line": 251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DUP_TOP", + "long_name": "DUP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 253, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_POSITIVE", + "long_name": "UNARY_POSITIVE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 259, + "end_line": 261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_NEGATIVE", + "long_name": "UNARY_NEGATIVE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 263, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_NOT", + "long_name": "UNARY_NOT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 267, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_CONVERT", + "long_name": "UNARY_CONVERT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 271, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_INVERT", + "long_name": "UNARY_INVERT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 275, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_POWER", + "long_name": "BINARY_POWER( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 281, + "end_line": 283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MULTIPLY", + "long_name": "BINARY_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 285, + "end_line": 287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_DIVIDE", + "long_name": "BINARY_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 289, + "end_line": 291, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MODULO", + "long_name": "BINARY_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 293, + "end_line": 295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_ADD", + "long_name": "BINARY_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 297, + "end_line": 299, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBTRACT", + "long_name": "BINARY_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 301, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBSCR", + "long_name": "BINARY_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 305, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_LSHIFT", + "long_name": "BINARY_LSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 309, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_RSHIFT", + "long_name": "BINARY_RSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 313, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_AND", + "long_name": "BINARY_AND( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 317, + "end_line": 319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_XOR", + "long_name": "BINARY_XOR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 321, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_OR", + "long_name": "BINARY_OR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 325, + "end_line": 327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_POWER", + "long_name": "INPLACE_POWER( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 331, + "end_line": 333, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_MULTIPLY", + "long_name": "INPLACE_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 335, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_DIVIDE", + "long_name": "INPLACE_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 339, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_MODULO", + "long_name": "INPLACE_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 343, + "end_line": 345, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_ADD", + "long_name": "INPLACE_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 347, + "end_line": 349, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_SUBTRACT", + "long_name": "INPLACE_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 351, + "end_line": 353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_LSHIFT", + "long_name": "INPLACE_LSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 355, + "end_line": 357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_RSHIFT", + "long_name": "INPLACE_RSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 359, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_AND", + "long_name": "INPLACE_AND( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 363, + "end_line": 365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_XOR", + "long_name": "INPLACE_XOR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 367, + "end_line": 369, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_OR", + "long_name": "INPLACE_OR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 371, + "end_line": 373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_0", + "long_name": "SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 377, + "end_line": 379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_1", + "long_name": "SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 381, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_2", + "long_name": "SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 385, + "end_line": 387, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_3", + "long_name": "SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 389, + "end_line": 391, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_0", + "long_name": "STORE_SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 395, + "end_line": 397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_1", + "long_name": "STORE_SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 399, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_2", + "long_name": "STORE_SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 403, + "end_line": 405, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_3", + "long_name": "STORE_SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 407, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_0", + "long_name": "DELETE_SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 411, + "end_line": 413, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_1", + "long_name": "DELETE_SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 415, + "end_line": 417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_2", + "long_name": "DELETE_SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 419, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_3", + "long_name": "DELETE_SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 423, + "end_line": 425, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SUBSCR", + "long_name": "STORE_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 427, + "end_line": 429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SUBSCR", + "long_name": "DELETE_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 431, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_EXPR", + "long_name": "PRINT_EXPR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 435, + "end_line": 437, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM", + "long_name": "PRINT_ITEM( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 439, + "end_line": 441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM_TO", + "long_name": "PRINT_ITEM_TO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 443, + "end_line": 445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE", + "long_name": "PRINT_NEWLINE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 447, + "end_line": 449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE_TO", + "long_name": "PRINT_NEWLINE_TO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 451, + "end_line": 453, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BREAK_LOOP", + "long_name": "BREAK_LOOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 455, + "end_line": 457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_LOCALS", + "long_name": "LOAD_LOCALS( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 459, + "end_line": 461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "RETURN_VALUE", + "long_name": "RETURN_VALUE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 463, + "end_line": 465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_STAR", + "long_name": "IMPORT_STAR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 467, + "end_line": 469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "EXEC_STMT", + "long_name": "EXEC_STMT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 471, + "end_line": 473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_BLOCK", + "long_name": "POP_BLOCK( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 475, + "end_line": 477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "END_FINALLY", + "long_name": "END_FINALLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 479, + "end_line": 481, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_CLASS", + "long_name": "BUILD_CLASS( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 483, + "end_line": 485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_NAME", + "long_name": "STORE_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 489, + "end_line": 491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_NAME", + "long_name": "DELETE_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 493, + "end_line": 495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNPACK_SEQUENCE", + "long_name": "UNPACK_SEQUENCE( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 497, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DUP_TOPX", + "long_name": "DUP_TOPX( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 501, + "end_line": 503, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_ATTR", + "long_name": "STORE_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 505, + "end_line": 507, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_ATTR", + "long_name": "DELETE_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 509, + "end_line": 511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_GLOBAL", + "long_name": "STORE_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 513, + "end_line": 515, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_GLOBAL", + "long_name": "DELETE_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 517, + "end_line": 519, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CONST", + "long_name": "LOAD_CONST( self , pc , consti )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "consti" + ], + "start_line": 521, + "end_line": 523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_NAME", + "long_name": "LOAD_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 525, + "end_line": 527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_TUPLE", + "long_name": "BUILD_TUPLE( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 529, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_LIST", + "long_name": "BUILD_LIST( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 533, + "end_line": 535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_MAP", + "long_name": "BUILD_MAP( self , pc , zero )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "zero" + ], + "start_line": 537, + "end_line": 539, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_ATTR", + "long_name": "LOAD_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 541, + "end_line": 543, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "COMPARE_OP", + "long_name": "COMPARE_OP( self , pc , opname )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "opname" + ], + "start_line": 545, + "end_line": 547, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_NAME", + "long_name": "IMPORT_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 549, + "end_line": 551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_FROM", + "long_name": "IMPORT_FROM( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 553, + "end_line": 555, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_FORWARD", + "long_name": "JUMP_FORWARD( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 557, + "end_line": 559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_TRUE", + "long_name": "JUMP_IF_TRUE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 561, + "end_line": 563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_FALSE", + "long_name": "JUMP_IF_FALSE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 565, + "end_line": 567, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_ABSOLUTE", + "long_name": "JUMP_ABSOLUTE( self , pc , target )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "target" + ], + "start_line": 569, + "end_line": 571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "FOR_LOOP", + "long_name": "FOR_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 573, + "end_line": 575, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_GLOBAL", + "long_name": "LOAD_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 577, + "end_line": 579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_LOOP", + "long_name": "SETUP_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 581, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_EXCEPT", + "long_name": "SETUP_EXCEPT( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 585, + "end_line": 587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_FINALLY", + "long_name": "SETUP_FINALLY( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 589, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_FAST", + "long_name": "LOAD_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 593, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_FAST", + "long_name": "STORE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 597, + "end_line": 599, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_FAST", + "long_name": "DELETE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 601, + "end_line": 603, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CLOSURE", + "long_name": "LOAD_CLOSURE( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 605, + "end_line": 607, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_DEREF", + "long_name": "LOAD_DEREF( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 609, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_DEREF", + "long_name": "STORE_DEREF( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 613, + "end_line": 615, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SET_LINENO", + "long_name": "SET_LINENO( self , pc , lineno )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "lineno" + ], + "start_line": 617, + "end_line": 619, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "RAISE_VARARGS", + "long_name": "RAISE_VARARGS( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 621, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION", + "long_name": "CALL_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 625, + "end_line": 627, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "MAKE_FUNCTION", + "long_name": "MAKE_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 629, + "end_line": 631, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "MAKE_CLOSURE", + "long_name": "MAKE_CLOSURE( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 633, + "end_line": 635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_SLICE", + "long_name": "BUILD_SLICE( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 637, + "end_line": 639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "EXTENDED_ARG", + "long_name": "EXTENDED_ARG( self , pc , ext )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "ext" + ], + "start_line": 641, + "end_line": 643, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_VAR", + "long_name": "CALL_FUNCTION_VAR( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 645, + "end_line": 647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_KW", + "long_name": "CALL_FUNCTION_KW( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 649, + "end_line": 651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_VAR_KW", + "long_name": "CALL_FUNCTION_VAR_KW( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 653, + "end_line": 655, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "typedef_by_value", + "long_name": "typedef_by_value( self , v )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "v" + ], + "start_line": 667, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , function , signature , name = None )", + "filename": "bytecodecompiler.py", + "nloc": 10, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "function", + "signature", + "name" + ], + "start_line": 673, + "end_line": 682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "evaluate", + "long_name": "evaluate( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 3, + "token_count": 52, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 687, + "end_line": 693, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "generate", + "long_name": "generate( self )", + "filename": "bytecodecompiler.py", + "nloc": 51, + "complexity": 14, + "token_count": 374, + "parameters": [ + "self" + ], + "start_line": 698, + "end_line": 780, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "wrapped_code", + "long_name": "wrapped_code( self )", + "filename": "bytecodecompiler.py", + "nloc": 52, + "complexity": 5, + "token_count": 294, + "parameters": [ + "self" + ], + "start_line": 786, + "end_line": 849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "emit", + "long_name": "emit( self , s )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "s" + ], + "start_line": 855, + "end_line": 858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "push", + "long_name": "push( self , v , t )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "v", + "t" + ], + "start_line": 863, + "end_line": 866, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "pop", + "long_name": "pop( self )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 872, + "end_line": 877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "unique", + "long_name": "unique( self )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 882, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "post", + "long_name": "post( self , pc , action )", + "filename": "bytecodecompiler.py", + "nloc": 5, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "pc", + "action" + ], + "start_line": 889, + "end_line": 893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "emit_value", + "long_name": "emit_value( self , v )", + "filename": "bytecodecompiler.py", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self", + "v" + ], + "start_line": 898, + "end_line": 909, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "global_info", + "long_name": "global_info( self , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 4, + "token_count": 73, + "parameters": [ + "self", + "var_num" + ], + "start_line": 914, + "end_line": 927, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "binop", + "long_name": "binop( self , pc , symbol )", + "filename": "bytecodecompiler.py", + "nloc": 15, + "complexity": 2, + "token_count": 98, + "parameters": [ + "self", + "pc", + "symbol" + ], + "start_line": 932, + "end_line": 948, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "BINARY_ADD", + "long_name": "BINARY_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 953, + "end_line": 954, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBTRACT", + "long_name": "BINARY_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 955, + "end_line": 956, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MULTIPLY", + "long_name": "BINARY_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 957, + "end_line": 958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_DIVIDE", + "long_name": "BINARY_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 959, + "end_line": 960, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MODULO", + "long_name": "BINARY_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 961, + "end_line": 962, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBSCR", + "long_name": "BINARY_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 963, + "end_line": 964, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "COMPARE_OP", + "long_name": "COMPARE_OP( self , pc , opname )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "pc", + "opname" + ], + "start_line": 965, + "end_line": 967, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM", + "long_name": "PRINT_ITEM( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 1, + "token_count": 88, + "parameters": [ + "self", + "pc" + ], + "start_line": 973, + "end_line": 986, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE", + "long_name": "PRINT_NEWLINE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 41, + "parameters": [ + "self", + "pc" + ], + "start_line": 992, + "end_line": 999, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "SET_LINENO", + "long_name": "SET_LINENO( self , pc , lineno )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "pc", + "lineno" + ], + "start_line": 1004, + "end_line": 1006, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_TOP", + "long_name": "POP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "pc" + ], + "start_line": 1011, + "end_line": 1013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CONST", + "long_name": "LOAD_CONST( self , pc , consti )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "pc", + "consti" + ], + "start_line": 1018, + "end_line": 1030, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "LOAD_FAST", + "long_name": "LOAD_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 8, + "complexity": 2, + "token_count": 55, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1036, + "end_line": 1043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "LOAD_GLOBAL", + "long_name": "LOAD_GLOBAL( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 26, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1048, + "end_line": 1084, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 1 + }, + { + "name": "STORE_FAST", + "long_name": "STORE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1089, + "end_line": 1107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "STORE_GLOBAL", + "long_name": "STORE_GLOBAL( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 15, + "complexity": 1, + "token_count": 99, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1112, + "end_line": 1132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION", + "long_name": "CALL_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 25, + "complexity": 4, + "token_count": 166, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 1137, + "end_line": 1172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_FALSE", + "long_name": "JUMP_IF_FALSE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1178, + "end_line": 1192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "JUMP_FORWARD", + "long_name": "JUMP_FORWARD( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1198, + "end_line": 1204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "RETURN_VALUE", + "long_name": "RETURN_VALUE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 13, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "pc" + ], + "start_line": 1209, + "end_line": 1221, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 20, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "opcodize", + "long_name": "opcodize( s )", + "filename": "bytecodecompiler.py", + "nloc": 16, + "complexity": 3, + "token_count": 92, + "parameters": [ + "s" + ], + "start_line": 141, + "end_line": 156, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "listing", + "long_name": "listing( f )", + "filename": "bytecodecompiler.py", + "nloc": 26, + "complexity": 8, + "token_count": 156, + "parameters": [ + "f" + ], + "start_line": 163, + "end_line": 188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 0 + }, + { + "name": "fetch", + "long_name": "fetch( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 194, + "end_line": 202, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "execute", + "long_name": "execute( self , pc , opcode , argument )", + "filename": "bytecodecompiler.py", + "nloc": 7, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "pc", + "opcode", + "argument" + ], + "start_line": 204, + "end_line": 210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "evaluate", + "long_name": "evaluate( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 212, + "end_line": 220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "cmp_op", + "long_name": "cmp_op( self , opname )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "opname" + ], + "start_line": 227, + "end_line": 228, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "STOP_CODE", + "long_name": "STOP_CODE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 230, + "end_line": 232, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_TOP", + "long_name": "POP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 233, + "end_line": 235, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_TWO", + "long_name": "ROT_TWO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 237, + "end_line": 239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_THREE", + "long_name": "ROT_THREE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 241, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_FOUR", + "long_name": "ROT_FOUR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 245, + "end_line": 247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DUP_TOP", + "long_name": "DUP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 249, + "end_line": 251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_POSITIVE", + "long_name": "UNARY_POSITIVE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 255, + "end_line": 257, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_NEGATIVE", + "long_name": "UNARY_NEGATIVE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 259, + "end_line": 261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_NOT", + "long_name": "UNARY_NOT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 263, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_CONVERT", + "long_name": "UNARY_CONVERT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 267, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_INVERT", + "long_name": "UNARY_INVERT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 271, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_POWER", + "long_name": "BINARY_POWER( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 277, + "end_line": 279, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MULTIPLY", + "long_name": "BINARY_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 281, + "end_line": 283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_DIVIDE", + "long_name": "BINARY_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 285, + "end_line": 287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MODULO", + "long_name": "BINARY_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 289, + "end_line": 291, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_ADD", + "long_name": "BINARY_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 293, + "end_line": 295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBTRACT", + "long_name": "BINARY_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 297, + "end_line": 299, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBSCR", + "long_name": "BINARY_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 301, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_LSHIFT", + "long_name": "BINARY_LSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 305, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_RSHIFT", + "long_name": "BINARY_RSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 309, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_AND", + "long_name": "BINARY_AND( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 313, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_XOR", + "long_name": "BINARY_XOR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 317, + "end_line": 319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_OR", + "long_name": "BINARY_OR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 321, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_POWER", + "long_name": "INPLACE_POWER( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 327, + "end_line": 329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_MULTIPLY", + "long_name": "INPLACE_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 331, + "end_line": 333, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_DIVIDE", + "long_name": "INPLACE_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 335, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_MODULO", + "long_name": "INPLACE_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 339, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_ADD", + "long_name": "INPLACE_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 343, + "end_line": 345, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_SUBTRACT", + "long_name": "INPLACE_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 347, + "end_line": 349, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_LSHIFT", + "long_name": "INPLACE_LSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 351, + "end_line": 353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_RSHIFT", + "long_name": "INPLACE_RSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 355, + "end_line": 357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_AND", + "long_name": "INPLACE_AND( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 359, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_XOR", + "long_name": "INPLACE_XOR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 363, + "end_line": 365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_OR", + "long_name": "INPLACE_OR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 367, + "end_line": 369, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_0", + "long_name": "SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 373, + "end_line": 375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_1", + "long_name": "SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 377, + "end_line": 379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_2", + "long_name": "SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 381, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_3", + "long_name": "SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 385, + "end_line": 387, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_0", + "long_name": "STORE_SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 391, + "end_line": 393, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_1", + "long_name": "STORE_SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 395, + "end_line": 397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_2", + "long_name": "STORE_SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 399, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_3", + "long_name": "STORE_SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 403, + "end_line": 405, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_0", + "long_name": "DELETE_SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 407, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_1", + "long_name": "DELETE_SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 411, + "end_line": 413, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_2", + "long_name": "DELETE_SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 415, + "end_line": 417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_3", + "long_name": "DELETE_SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 419, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SUBSCR", + "long_name": "STORE_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 423, + "end_line": 425, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SUBSCR", + "long_name": "DELETE_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 427, + "end_line": 429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_EXPR", + "long_name": "PRINT_EXPR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 431, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM", + "long_name": "PRINT_ITEM( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 435, + "end_line": 437, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM_TO", + "long_name": "PRINT_ITEM_TO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 439, + "end_line": 441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE", + "long_name": "PRINT_NEWLINE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 443, + "end_line": 445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE_TO", + "long_name": "PRINT_NEWLINE_TO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 447, + "end_line": 449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BREAK_LOOP", + "long_name": "BREAK_LOOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 451, + "end_line": 453, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_LOCALS", + "long_name": "LOAD_LOCALS( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 455, + "end_line": 457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "RETURN_VALUE", + "long_name": "RETURN_VALUE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 459, + "end_line": 461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_STAR", + "long_name": "IMPORT_STAR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 463, + "end_line": 465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "EXEC_STMT", + "long_name": "EXEC_STMT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 467, + "end_line": 469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_BLOCK", + "long_name": "POP_BLOCK( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 471, + "end_line": 473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "END_FINALLY", + "long_name": "END_FINALLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 475, + "end_line": 477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_CLASS", + "long_name": "BUILD_CLASS( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 479, + "end_line": 481, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_NAME", + "long_name": "STORE_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 485, + "end_line": 487, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_NAME", + "long_name": "DELETE_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 489, + "end_line": 491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNPACK_SEQUENCE", + "long_name": "UNPACK_SEQUENCE( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 493, + "end_line": 495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DUP_TOPX", + "long_name": "DUP_TOPX( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 497, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_ATTR", + "long_name": "STORE_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 501, + "end_line": 503, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_ATTR", + "long_name": "DELETE_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 505, + "end_line": 507, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_GLOBAL", + "long_name": "STORE_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 509, + "end_line": 511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_GLOBAL", + "long_name": "DELETE_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 513, + "end_line": 515, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CONST", + "long_name": "LOAD_CONST( self , pc , consti )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "consti" + ], + "start_line": 517, + "end_line": 519, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_NAME", + "long_name": "LOAD_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 521, + "end_line": 523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_TUPLE", + "long_name": "BUILD_TUPLE( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 525, + "end_line": 527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_LIST", + "long_name": "BUILD_LIST( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 529, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_MAP", + "long_name": "BUILD_MAP( self , pc , zero )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "zero" + ], + "start_line": 533, + "end_line": 535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_ATTR", + "long_name": "LOAD_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 537, + "end_line": 539, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "COMPARE_OP", + "long_name": "COMPARE_OP( self , pc , opname )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "opname" + ], + "start_line": 541, + "end_line": 543, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_NAME", + "long_name": "IMPORT_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 545, + "end_line": 547, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_FROM", + "long_name": "IMPORT_FROM( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 549, + "end_line": 551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_FORWARD", + "long_name": "JUMP_FORWARD( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 553, + "end_line": 555, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_TRUE", + "long_name": "JUMP_IF_TRUE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 557, + "end_line": 559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_FALSE", + "long_name": "JUMP_IF_FALSE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 561, + "end_line": 563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_ABSOLUTE", + "long_name": "JUMP_ABSOLUTE( self , pc , target )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "target" + ], + "start_line": 565, + "end_line": 567, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "FOR_LOOP", + "long_name": "FOR_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 569, + "end_line": 571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_GLOBAL", + "long_name": "LOAD_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 573, + "end_line": 575, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_LOOP", + "long_name": "SETUP_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 577, + "end_line": 579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_EXCEPT", + "long_name": "SETUP_EXCEPT( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 581, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_FINALLY", + "long_name": "SETUP_FINALLY( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 585, + "end_line": 587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_FAST", + "long_name": "LOAD_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 589, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_FAST", + "long_name": "STORE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 593, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_FAST", + "long_name": "DELETE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 597, + "end_line": 599, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CLOSURE", + "long_name": "LOAD_CLOSURE( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 601, + "end_line": 603, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_DEREF", + "long_name": "LOAD_DEREF( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 605, + "end_line": 607, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_DEREF", + "long_name": "STORE_DEREF( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 609, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SET_LINENO", + "long_name": "SET_LINENO( self , pc , lineno )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "lineno" + ], + "start_line": 613, + "end_line": 615, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "RAISE_VARARGS", + "long_name": "RAISE_VARARGS( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 617, + "end_line": 619, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION", + "long_name": "CALL_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 621, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "MAKE_FUNCTION", + "long_name": "MAKE_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 625, + "end_line": 627, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "MAKE_CLOSURE", + "long_name": "MAKE_CLOSURE( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 629, + "end_line": 631, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_SLICE", + "long_name": "BUILD_SLICE( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 633, + "end_line": 635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "EXTENDED_ARG", + "long_name": "EXTENDED_ARG( self , pc , ext )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "ext" + ], + "start_line": 637, + "end_line": 639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_VAR", + "long_name": "CALL_FUNCTION_VAR( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 641, + "end_line": 643, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_KW", + "long_name": "CALL_FUNCTION_KW( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 645, + "end_line": 647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_VAR_KW", + "long_name": "CALL_FUNCTION_VAR_KW( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 649, + "end_line": 651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "typedef_by_value", + "long_name": "typedef_by_value( self , v )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "v" + ], + "start_line": 663, + "end_line": 664, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , function , signature , name = None )", + "filename": "bytecodecompiler.py", + "nloc": 10, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "function", + "signature", + "name" + ], + "start_line": 669, + "end_line": 678, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "evaluate", + "long_name": "evaluate( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 3, + "token_count": 52, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 683, + "end_line": 689, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "generate", + "long_name": "generate( self )", + "filename": "bytecodecompiler.py", + "nloc": 51, + "complexity": 12, + "token_count": 368, + "parameters": [ + "self" + ], + "start_line": 694, + "end_line": 776, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "wrapped_code", + "long_name": "wrapped_code( self )", + "filename": "bytecodecompiler.py", + "nloc": 52, + "complexity": 5, + "token_count": 294, + "parameters": [ + "self" + ], + "start_line": 782, + "end_line": 845, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "emit", + "long_name": "emit( self , s )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "s" + ], + "start_line": 851, + "end_line": 854, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "push", + "long_name": "push( self , v , t )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "v", + "t" + ], + "start_line": 859, + "end_line": 862, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "pop", + "long_name": "pop( self )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 868, + "end_line": 873, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "unique", + "long_name": "unique( self )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 878, + "end_line": 880, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "post", + "long_name": "post( self , pc , action )", + "filename": "bytecodecompiler.py", + "nloc": 5, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "pc", + "action" + ], + "start_line": 885, + "end_line": 889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "emit_value", + "long_name": "emit_value( self , v )", + "filename": "bytecodecompiler.py", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self", + "v" + ], + "start_line": 894, + "end_line": 905, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "global_info", + "long_name": "global_info( self , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 4, + "token_count": 73, + "parameters": [ + "self", + "var_num" + ], + "start_line": 910, + "end_line": 923, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "binop", + "long_name": "binop( self , pc , symbol )", + "filename": "bytecodecompiler.py", + "nloc": 14, + "complexity": 2, + "token_count": 84, + "parameters": [ + "self", + "pc", + "symbol" + ], + "start_line": 928, + "end_line": 943, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "BINARY_ADD", + "long_name": "BINARY_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 948, + "end_line": 949, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBTRACT", + "long_name": "BINARY_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 950, + "end_line": 951, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MULTIPLY", + "long_name": "BINARY_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 952, + "end_line": 953, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_DIVIDE", + "long_name": "BINARY_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 954, + "end_line": 955, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MODULO", + "long_name": "BINARY_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 956, + "end_line": 957, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "COMPARE_OP", + "long_name": "COMPARE_OP( self , pc , opname )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "pc", + "opname" + ], + "start_line": 958, + "end_line": 960, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM", + "long_name": "PRINT_ITEM( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 1, + "token_count": 88, + "parameters": [ + "self", + "pc" + ], + "start_line": 966, + "end_line": 979, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE", + "long_name": "PRINT_NEWLINE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 41, + "parameters": [ + "self", + "pc" + ], + "start_line": 985, + "end_line": 992, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "SET_LINENO", + "long_name": "SET_LINENO( self , pc , lineno )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "pc", + "lineno" + ], + "start_line": 997, + "end_line": 999, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_TOP", + "long_name": "POP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "pc" + ], + "start_line": 1004, + "end_line": 1006, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CONST", + "long_name": "LOAD_CONST( self , pc , consti )", + "filename": "bytecodecompiler.py", + "nloc": 8, + "complexity": 2, + "token_count": 44, + "parameters": [ + "self", + "pc", + "consti" + ], + "start_line": 1011, + "end_line": 1022, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "LOAD_FAST", + "long_name": "LOAD_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 5, + "complexity": 1, + "token_count": 34, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1028, + "end_line": 1032, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "LOAD_GLOBAL", + "long_name": "LOAD_GLOBAL( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 26, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1037, + "end_line": 1073, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 1 + }, + { + "name": "STORE_FAST", + "long_name": "STORE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 3, + "token_count": 72, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1078, + "end_line": 1092, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "STORE_GLOBAL", + "long_name": "STORE_GLOBAL( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 15, + "complexity": 1, + "token_count": 99, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1097, + "end_line": 1117, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION", + "long_name": "CALL_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 25, + "complexity": 4, + "token_count": 166, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 1122, + "end_line": 1157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_FALSE", + "long_name": "JUMP_IF_FALSE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1163, + "end_line": 1177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "JUMP_FORWARD", + "long_name": "JUMP_FORWARD( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1183, + "end_line": 1189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "RETURN_VALUE", + "long_name": "RETURN_VALUE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 10, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self", + "pc" + ], + "start_line": 1194, + "end_line": 1203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "listing", + "long_name": "listing( f )", + "filename": "bytecodecompiler.py", + "nloc": 29, + "complexity": 9, + "token_count": 166, + "parameters": [ + "f" + ], + "start_line": 164, + "end_line": 192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "LOAD_FAST", + "long_name": "LOAD_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 8, + "complexity": 2, + "token_count": 55, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1036, + "end_line": 1043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "STORE_FAST", + "long_name": "STORE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1089, + "end_line": 1107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "generate", + "long_name": "generate( self )", + "filename": "bytecodecompiler.py", + "nloc": 51, + "complexity": 14, + "token_count": 374, + "parameters": [ + "self" + ], + "start_line": 698, + "end_line": 780, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CONST", + "long_name": "LOAD_CONST( self , pc , consti )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "pc", + "consti" + ], + "start_line": 1018, + "end_line": 1030, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "binop", + "long_name": "binop( self , pc , symbol )", + "filename": "bytecodecompiler.py", + "nloc": 15, + "complexity": 2, + "token_count": 98, + "parameters": [ + "self", + "pc", + "symbol" + ], + "start_line": 932, + "end_line": 948, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBSCR", + "long_name": "BINARY_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 963, + "end_line": 964, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "RETURN_VALUE", + "long_name": "RETURN_VALUE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 13, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "pc" + ], + "start_line": 1209, + "end_line": 1221, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + } + ], + "nloc": 848, + "complexity": 196, + "token_count": 4553, + "diff_parsed": { + "added": [ + " refcount = 0", + " if op >= haveArgument:", + " pc += 3", + " else:", + " pc += 1", + " bytes = len(code)", + " while pc != None and pc < bytes:", + " if T == None: continue", + " t.cxxtype,", + " rhs,rhs_type = t1.binopMixed(symbol,v1,v2)", + " print self.__body", + " def BINARY_SUBSCR(self,pc):", + " return self.binop(pc,'[]')", + " print 'LOAD_CONST',repr(k),t", + " self.push('',t)", + " print 'LOADFAST',var_num,v,t", + " if t.refcount:", + " self.emit('Py_XINCREF(%s);'%v)", + " print 'STORE FAST',var_num,v,t", + " if t.refcount:", + " self.emit('Py_XINCREF(%s);'%v)", + " self.emit('Py_XDECREF(%s);'%save)", + " print v,t", + " if t == NoneType: return # just the extra return", + " print 'return with',v", + " return" + ], + "deleted": [ + " pc += 1", + " while pc != None:", + " print T.prerequisites", + " descriptor = typedefs[t]", + " descriptor.cxxtype,", + " raise NotImplementedError,'mixed types'", + " self.push('',t)", + " return -1" + ] + } + } + ] + }, + { + "hash": "a66dce587128e0df7b614a22fcaca701a449dc90", + "msg": "fixed missing , typo that broke module import/reload/test in some situations (it looked like it should break all situations)...", + "author": { + "name": "Eric Jones", + "email": "eric@enthought.com" + }, + "committer": { + "name": "Eric Jones", + "email": "eric@enthought.com" + }, + "author_date": "2002-02-26T19:01:12+00:00", + "author_timezone": 0, + "committer_date": "2002-02-26T19:01:12+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "98b313f079374f9219d62ee48102afeccc7456d9" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/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_test/scipy_test.py", + "new_path": "scipy_test/scipy_test.py", + "filename": "scipy_test.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -173,7 +173,7 @@ def module_test(mod_name,mod_file,level=10):\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+ ((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", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "import os\n\ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files \n \ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n \n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files \n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n \n return good_files\n \ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n import os,sys\n\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n import glob\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n \n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n \n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f) \n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception() \n \n return all_modules\n\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n import os,sys\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n \n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files: \n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception() \n return all_packages\n\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object \n (not a string) \n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n import unittest\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite) \n else:\n msg = \" !! FAILURE without error - shouldn't happen\" + \\\n module.__name__ \n print msg\n except:\n print ' !! FAILURE building test for ', module.__name__ \n print ' ',\n output_exception() \n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has \n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n import os,sys,string\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # add the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.append(test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module,)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[:-1]\n\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n import os,sys,string\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # add the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.append(test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[:-1]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception() \n\n\n# Utility function to facilitate testing.\n\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(str(desired)) < 100 and len(str(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n assert desired == actual, msg\n\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(str(desired)) < 100 and len(str(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits \n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n sc_desired = desired/pow(10,math.floor(math.log10(desired)))\n sc_actual = actual/pow(10,math.floor(math.log10(actual)))\n try:\n if ( verbose and len(str(desired)) < 100 and len(str(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n \ntry:\n # Numeric specific testss\n from Numeric import *\n from fastumath import *\n \n def assert_array_equal(x,y,err_msg=''):\n msg = '\\nArrays are not equal'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = equal(x,y)\n assert alltrue(ravel(reduced)),\\\n msg + ':\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not equal'\n \n def assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n msg = '\\nArrays are not almost equal'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = equal(around(abs(x-y),decimal),0)\n assert alltrue(ravel(reduced)),\\\n msg + ':\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\nexcept:\n pass # Numeric not installed\n \nimport traceback,sys\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n", + "source_code_before": "import os\n\ndef remove_ignored_patterns(files,pattern):\n from fnmatch import fnmatch\n good_files = []\n for file in files:\n if not fnmatch(file,pattern):\n good_files.append(file)\n return good_files \n \ndef remove_ignored_files(original,ignored_files,cur_dir):\n \"\"\" This is actually expanded to do pattern matching.\n \n \"\"\"\n if not ignored_files: ignored_files = []\n ignored_modules = map(lambda x: x+'.py',ignored_files)\n ignored_packages = ignored_files[:]\n # always ignore setup.py and __init__.py files\n ignored_files = ['setup.py','setup_*.py','__init__.py']\n ignored_files += ignored_modules + ignored_packages\n ignored_files = map(lambda x,cur_dir=cur_dir: os.path.join(cur_dir,x),\n ignored_files)\n #print 'ignored:', ignored_files \n #good_files = filter(lambda x,ignored = ignored_files: x not in ignored,\n # original)\n good_files = original\n for pattern in ignored_files:\n good_files = remove_ignored_patterns(good_files,pattern)\n \n return good_files\n \ndef harvest_modules(package,ignore=None):\n \"\"\"* Retreive a list of all modules that live within a package.\n\n Only retreive files that are immediate children of the\n package -- do not recurse through child packages or\n directories. The returned list contains actual modules, not\n just their names.\n *\"\"\"\n import os,sys\n\n d,f = os.path.split(package.__file__)\n\n # go through the directory and import every py file there.\n import glob\n common_dir = os.path.join(d,'*.py')\n py_files = glob.glob(common_dir)\n #py_files.remove(os.path.join(d,'__init__.py'))\n #py_files.remove(os.path.join(d,'setup.py'))\n \n py_files = remove_ignored_files(py_files,ignore,d)\n #print 'py_files:', py_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n \n all_modules = []\n for file in py_files:\n d,f = os.path.split(file)\n base,ext = os.path.splitext(f) \n mod = prefix + '.' + base\n #print 'module: import ' + mod\n try:\n exec ('import ' + mod)\n all_modules.append(eval(mod))\n except:\n print 'FAILURE to import ' + mod\n output_exception() \n \n return all_modules\n\ndef harvest_packages(package,ignore = None):\n \"\"\" Retreive a list of all sub-packages that live within a package.\n\n Only retreive packages that are immediate children of this\n package -- do not recurse through child packages or\n directories. The returned list contains actual package objects, not\n just their names.\n \"\"\"\n import os,sys\n join = os.path.join\n\n d,f = os.path.split(package.__file__)\n\n common_dir = os.path.abspath(d)\n all_files = os.listdir(d)\n \n all_files = remove_ignored_files(all_files,ignore,'')\n #print 'all_files:', all_files\n try:\n prefix = package.__name__\n except:\n prefix = ''\n all_packages = []\n for directory in all_files: \n path = join(common_dir,directory)\n if os.path.isdir(path) and \\\n os.path.exists(join(path,'__init__.py')):\n sub_package = prefix + '.' + directory\n #print 'sub-package import ' + sub_package\n try:\n exec ('import ' + sub_package)\n all_packages.append(eval(sub_package))\n except:\n print 'FAILURE to import ' + sub_package\n output_exception() \n return all_packages\n\ndef harvest_modules_and_packages(package,ignore=None):\n \"\"\" Retreive list of all packages and modules that live within a package.\n\n See harvest_packages() and harvest_modules()\n \"\"\"\n all = harvest_modules(package,ignore) + harvest_packages(package,ignore)\n return all\n\ndef harvest_test_suites(package,ignore = None,level=10):\n \"\"\"\n package -- the module to test. This is an actual module object \n (not a string) \n ignore -- a list of module names to omit from the tests\n level -- a value between 1 and 10. 1 will run the minimum number\n of tests. This is a fast \"smoke test\". Tests that take\n longer to run should have higher numbers ranging up to 10.\n \"\"\"\n import unittest\n suites=[]\n test_modules = harvest_modules_and_packages(package,ignore)\n #for i in test_modules:\n # print i.__name__\n for module in test_modules:\n if hasattr(module,'test_suite'):\n try:\n suite = module.test_suite(level=level)\n if suite:\n suites.append(suite) \n else:\n msg = \" !! FAILURE without error - shouldn't happen\" + \\\n module.__name__ \n print msg\n except:\n print ' !! FAILURE building test for ', module.__name__ \n print ' ',\n output_exception() \n else:\n try:\n print 'No test suite found for ', module.__name__\n except AttributeError:\n # __version__.py getting replaced by a string throws a kink\n # in checking for modules, so we think is a module has \n # actually been overwritten\n print 'No test suite found for ', str(module)\n total_suite = unittest.TestSuite(suites)\n return total_suite\n\ndef module_test(mod_name,mod_file,level=10):\n \"\"\"*\n\n *\"\"\"\n import os,sys,string\n #print 'testing', mod_name\n d,f = os.path.split(mod_file)\n\n # add the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.append(test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);%s.test(%d)' % \\\n ((test_module)*3 + (level,))\n\n # This would be better cause it forces a reload of the orginal\n # module. It doesn't behave with packages however.\n #test_string = 'reload(%s);import %s;reload(%s);%s.test(%d)' % \\\n # ((mod_name,) + (test_module,)*3)\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[:-1]\n\ndef module_test_suite(mod_name,mod_file,level=10):\n #try:\n import os,sys,string\n print ' creating test suite for:', mod_name\n d,f = os.path.split(mod_file)\n\n # add the tests directory to the python path\n test_dir = os.path.join(d,'tests')\n sys.path.append(test_dir)\n\n # call the \"test_xxx.test()\" function for the appropriate\n # module.\n\n # This should deal with package naming issues correctly\n short_mod_name = string.split(mod_name,'.')[-1]\n test_module = 'test_' + short_mod_name\n test_string = 'import %s;reload(%s);suite = %s.test_suite(%d)' % \\\n ((test_module,)*3+(level,))\n #print test_string\n exec(test_string)\n\n # remove test directory from python path.\n sys.path = sys.path[:-1]\n return suite\n #except:\n # print ' !! FAILURE loading test suite from', test_module, ':'\n # print ' ',\n # output_exception() \n\n\n# Utility function to facilitate testing.\n\ndef assert_equal(actual,desired,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(str(desired)) < 100 and len(str(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n assert desired == actual, msg\n\ndef assert_almost_equal(actual,desired,decimal=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n \"\"\"\n msg = '\\nItems are not equal:\\n' + err_msg\n try:\n if ( verbose and len(str(desired)) < 100 and len(str(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n assert round(abs(desired - actual),decimal) == 0, msg\n\ndef assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=1):\n \"\"\" Raise an assertion if two items are not\n equal. I think this should be part of unittest.py\n Approximately equal is defined as the number of significant digits \n correct\n \"\"\"\n msg = '\\nItems are not equal to %d significant digits:\\n' % significant\n msg += err_msg\n sc_desired = desired/pow(10,math.floor(math.log10(desired)))\n sc_actual = actual/pow(10,math.floor(math.log10(actual)))\n try:\n if ( verbose and len(str(desired)) < 100 and len(str(actual)) ):\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n except:\n msg = msg \\\n + 'DESIRED: ' + str(desired) \\\n + '\\nACTUAL: ' + str(actual)\n assert math.fabs(sc_desired - sc_actual) < pow(10.,-1*significant), msg\n \ntry:\n # Numeric specific testss\n from Numeric import *\n from fastumath import *\n \n def assert_array_equal(x,y,err_msg=''):\n msg = '\\nArrays are not equal'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = equal(x,y)\n assert alltrue(ravel(reduced)),\\\n msg + ':\\n\\t' + err_msg\n except ValueError:\n print shape(x),shape(y)\n raise ValueError, 'arrays are not equal'\n \n def assert_array_almost_equal(x,y,decimal=6,err_msg=''):\n msg = '\\nArrays are not almost equal'\n try:\n assert alltrue(equal(shape(x),shape(y))),\\\n msg + ' (shapes mismatch):\\n\\t' + err_msg\n reduced = equal(around(abs(x-y),decimal),0)\n assert alltrue(ravel(reduced)),\\\n msg + ':\\n\\t' + err_msg\n except ValueError:\n print sys.exc_value\n print shape(x),shape(y)\n print x, y\n raise ValueError, 'arrays are not almost equal'\nexcept:\n pass # Numeric not installed\n \nimport traceback,sys\ndef output_exception():\n try:\n type, value, tb = sys.exc_info()\n info = traceback.extract_tb(tb)\n #this is more verbose\n #traceback.print_exc()\n filename, lineno, function, text = info[-1] # last line only\n print \"%s:%d: %s: %s (in %s)\" %\\\n (filename, lineno, type.__name__, str(value), function)\n finally:\n type = value = tb = None # clean up\n", + "methods": [ + { + "name": "remove_ignored_patterns", + "long_name": "remove_ignored_patterns( files , pattern )", + "filename": "scipy_test.py", + "nloc": 7, + "complexity": 3, + "token_count": 37, + "parameters": [ + "files", + "pattern" + ], + "start_line": 3, + "end_line": 9, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "remove_ignored_files", + "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", + "filename": "scipy_test.py", + "nloc": 12, + "complexity": 3, + "token_count": 93, + "parameters": [ + "original", + "ignored_files", + "cur_dir" + ], + "start_line": 11, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "harvest_modules", + "long_name": "harvest_modules( package , ignore = None )", + "filename": "scipy_test.py", + "nloc": 23, + "complexity": 4, + "token_count": 140, + "parameters": [ + "package", + "ignore" + ], + "start_line": 32, + "end_line": 71, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "harvest_packages", + "long_name": "harvest_packages( package , ignore = None )", + "filename": "scipy_test.py", + "nloc": 24, + "complexity": 6, + "token_count": 152, + "parameters": [ + "package", + "ignore" + ], + "start_line": 73, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "harvest_modules_and_packages", + "long_name": "harvest_modules_and_packages( package , ignore = None )", + "filename": "scipy_test.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "package", + "ignore" + ], + "start_line": 110, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "harvest_test_suites", + "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", + "filename": "scipy_test.py", + "nloc": 25, + "complexity": 6, + "token_count": 118, + "parameters": [ + "package", + "ignore", + "level" + ], + "start_line": 118, + "end_line": 155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "module_test", + "long_name": "module_test( mod_name , mod_file , level = 10 )", + "filename": "scipy_test.py", + "nloc": 11, + "complexity": 1, + "token_count": 103, + "parameters": [ + "mod_name", + "mod_file", + "level" + ], + "start_line": 157, + "end_line": 185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "module_test_suite", + "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", + "filename": "scipy_test.py", + "nloc": 13, + "complexity": 1, + "token_count": 108, + "parameters": [ + "mod_name", + "mod_file", + "level" + ], + "start_line": 187, + "end_line": 210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "assert_equal", + "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", + "filename": "scipy_test.py", + "nloc": 12, + "complexity": 5, + "token_count": 92, + "parameters": [ + "actual", + "desired", + "err_msg", + "verbose" + ], + "start_line": 219, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "assert_almost_equal", + "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", + "filename": "scipy_test.py", + "nloc": 12, + "complexity": 5, + "token_count": 106, + "parameters": [ + "actual", + "desired", + "decimal", + "err_msg", + "verbose" + ], + "start_line": 235, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "assert_approx_equal", + "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", + "filename": "scipy_test.py", + "nloc": 15, + "complexity": 5, + "token_count": 155, + "parameters": [ + "actual", + "desired", + "significant", + "err_msg", + "verbose" + ], + "start_line": 251, + "end_line": 270, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "assert_array_equal", + "long_name": "assert_array_equal( x , y , err_msg = '' )", + "filename": "scipy_test.py", + "nloc": 11, + "complexity": 2, + "token_count": 79, + "parameters": [ + "x", + "y", + "err_msg" + ], + "start_line": 277, + "end_line": 287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "assert_array_almost_equal", + "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", + "filename": "scipy_test.py", + "nloc": 13, + "complexity": 2, + "token_count": 101, + "parameters": [ + "x", + "y", + "decimal", + "err_msg" + ], + "start_line": 289, + "end_line": 301, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "output_exception", + "long_name": "output_exception( )", + "filename": "scipy_test.py", + "nloc": 9, + "complexity": 2, + "token_count": 67, + "parameters": [], + "start_line": 306, + "end_line": 316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "remove_ignored_patterns", + "long_name": "remove_ignored_patterns( files , pattern )", + "filename": "scipy_test.py", + "nloc": 7, + "complexity": 3, + "token_count": 37, + "parameters": [ + "files", + "pattern" + ], + "start_line": 3, + "end_line": 9, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "remove_ignored_files", + "long_name": "remove_ignored_files( original , ignored_files , cur_dir )", + "filename": "scipy_test.py", + "nloc": 12, + "complexity": 3, + "token_count": 93, + "parameters": [ + "original", + "ignored_files", + "cur_dir" + ], + "start_line": 11, + "end_line": 30, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "harvest_modules", + "long_name": "harvest_modules( package , ignore = None )", + "filename": "scipy_test.py", + "nloc": 23, + "complexity": 4, + "token_count": 140, + "parameters": [ + "package", + "ignore" + ], + "start_line": 32, + "end_line": 71, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 0 + }, + { + "name": "harvest_packages", + "long_name": "harvest_packages( package , ignore = None )", + "filename": "scipy_test.py", + "nloc": 24, + "complexity": 6, + "token_count": 152, + "parameters": [ + "package", + "ignore" + ], + "start_line": 73, + "end_line": 108, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 0 + }, + { + "name": "harvest_modules_and_packages", + "long_name": "harvest_modules_and_packages( package , ignore = None )", + "filename": "scipy_test.py", + "nloc": 3, + "complexity": 1, + "token_count": 27, + "parameters": [ + "package", + "ignore" + ], + "start_line": 110, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 0 + }, + { + "name": "harvest_test_suites", + "long_name": "harvest_test_suites( package , ignore = None , level = 10 )", + "filename": "scipy_test.py", + "nloc": 25, + "complexity": 6, + "token_count": 118, + "parameters": [ + "package", + "ignore", + "level" + ], + "start_line": 118, + "end_line": 155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 38, + "top_nesting_level": 0 + }, + { + "name": "module_test", + "long_name": "module_test( mod_name , mod_file , level = 10 )", + "filename": "scipy_test.py", + "nloc": 11, + "complexity": 1, + "token_count": 102, + "parameters": [ + "mod_name", + "mod_file", + "level" + ], + "start_line": 157, + "end_line": 185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "module_test_suite", + "long_name": "module_test_suite( mod_name , mod_file , level = 10 )", + "filename": "scipy_test.py", + "nloc": 13, + "complexity": 1, + "token_count": 108, + "parameters": [ + "mod_name", + "mod_file", + "level" + ], + "start_line": 187, + "end_line": 210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + }, + { + "name": "assert_equal", + "long_name": "assert_equal( actual , desired , err_msg = '' , verbose = 1 )", + "filename": "scipy_test.py", + "nloc": 12, + "complexity": 5, + "token_count": 92, + "parameters": [ + "actual", + "desired", + "err_msg", + "verbose" + ], + "start_line": 219, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "assert_almost_equal", + "long_name": "assert_almost_equal( actual , desired , decimal = 7 , err_msg = '' , verbose = 1 )", + "filename": "scipy_test.py", + "nloc": 12, + "complexity": 5, + "token_count": 106, + "parameters": [ + "actual", + "desired", + "decimal", + "err_msg", + "verbose" + ], + "start_line": 235, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 0 + }, + { + "name": "assert_approx_equal", + "long_name": "assert_approx_equal( actual , desired , significant = 7 , err_msg = '' , verbose = 1 )", + "filename": "scipy_test.py", + "nloc": 15, + "complexity": 5, + "token_count": 155, + "parameters": [ + "actual", + "desired", + "significant", + "err_msg", + "verbose" + ], + "start_line": 251, + "end_line": 270, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 0 + }, + { + "name": "assert_array_equal", + "long_name": "assert_array_equal( x , y , err_msg = '' )", + "filename": "scipy_test.py", + "nloc": 11, + "complexity": 2, + "token_count": 79, + "parameters": [ + "x", + "y", + "err_msg" + ], + "start_line": 277, + "end_line": 287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "assert_array_almost_equal", + "long_name": "assert_array_almost_equal( x , y , decimal = 6 , err_msg = '' )", + "filename": "scipy_test.py", + "nloc": 13, + "complexity": 2, + "token_count": 101, + "parameters": [ + "x", + "y", + "decimal", + "err_msg" + ], + "start_line": 289, + "end_line": 301, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "output_exception", + "long_name": "output_exception( )", + "filename": "scipy_test.py", + "nloc": 9, + "complexity": 2, + "token_count": 67, + "parameters": [], + "start_line": 306, + "end_line": 316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "module_test", + "long_name": "module_test( mod_name , mod_file , level = 10 )", + "filename": "scipy_test.py", + "nloc": 11, + "complexity": 1, + "token_count": 103, + "parameters": [ + "mod_name", + "mod_file", + "level" + ], + "start_line": 157, + "end_line": 185, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + } + ], + "nloc": 197, + "complexity": 46, + "token_count": 1411, + "diff_parsed": { + "added": [ + " ((test_module,)*3 + (level,))" + ], + "deleted": [ + " ((test_module)*3 + (level,))" + ] + } + } + ] + }, + { + "hash": "af4d15bf79a35239984fdb5d65b3970dc497474f", + "msg": "fixed a problem with non-breaking spaces not terminated with ';' that screwed up Mozilla", + "author": { + "name": "Eric Jones", + "email": "eric@enthought.com" + }, + "committer": { + "name": "Eric Jones", + "email": "eric@enthought.com" + }, + "author_date": "2002-02-27T06:20:19+00:00", + "author_timezone": 0, + "committer_date": "2002-02-27T06:20:19+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "a66dce587128e0df7b614a22fcaca701a449dc90" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 11, + "insertions": 11, + "lines": 22, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "weave/doc/tutorial.html", + "new_path": "weave/doc/tutorial.html", + "filename": "tutorial.html", + "extension": "html", + "change_type": "MODIFY", + "diff": "@@ -354,20 +354,20 @@

Benchmarks

\n \n

inline and ext_tools

\n

Algorithm

Speed up \n- binary search   1.50 \n- fibonacci (recursive)  82.10 \n- fibonacci (loop)   9.17 \n- return None   0.14 \n- map   1.20 \n- dictionary sort   2.54 \n- vector quantization  37.40 \n+ binary search   1.50 \n+ fibonacci (recursive)  82.10 \n+ fibonacci (loop)   9.17 \n+ return None   0.14 \n+ map   1.20 \n+ dictionary sort   2.54 \n+ vector quantization  37.40 \n \n

blitz -- double precision

\n

Algorithm

Speed up \n- a = b + c 512x512   3.05 \n- a = b + c + d 512x512   4.59 \n- 5 pt avg. filter, 2D Image 512x512   9.01 \n- Electromagnetics (FDTD) 100x100x100   8.61 \n+ a = b + c 512x512   3.05 \n+ a = b + c + d 512x512   4.59 \n+ 5 pt avg. filter, 2D Image 512x512   9.01 \n+ Electromagnetics (FDTD) 100x100x100   8.61 \n \n \n \n", + "added_lines": 11, + "deleted_lines": 11, + "source_code": "\n

Weave Documentation

\n

\nBy Eric Jones eric@enthought.com\n

\n

Outline

\n
\n
Introduction\n
Requirements\n
Installation\n
Testing\n
Benchmarks\n
Inline\n
\n
More with printf\n
\n More examples\n
\n
Binary search\n
Dictionary sort\n
Numeric -- cast/copy/transpose\n
wxPython
\n
\n
Keyword options\n
Returning values\n
\n
\n The issue with locals()
\n
\n
A quick look at the code\n
\n Technical Details\n
\n
Converting Types\n
\n
\n Numeric Argument Conversion\n
\n String, List, Tuple, and Dictionary Conversion\n
File Conversion \n
\n Callable, Instance, and Module Conversion \n
Customizing Conversions\n
\n
Compiling Code\n
\"Cataloging\" functions\n
\n
Function Storage\n
The PYTHONCOMPILED evnironment variable
\n
\n
\n
\n
\n
\n
Blitz\n
\n
Requirements\n
Limitations\n
Numeric Efficiency Issues\n
The Tools \n
\n
Parser\n
Blitz and Numeric\n
\n
Type defintions and coersion\n
Cataloging Compiled Functions\n
Checking Array Sizes\n
Creating the Extension Module\n
\n
Extension Modules\n
\n
A Simple Example\n
Fibonacci Example\n
\n
Customizing Type Conversions -- Type Factories (not written)\n
\n
Type Specifications\n
Type Information\n
The Conversion Process \n
\n
\n\n

Introduction

\n\n

\nThe weave package provides tools for including C/C++ code within\nin Python code. This offers both another level of optimization to those who need \nit, and an easy way to modify and extend any supported extension libraries such \nas wxPython and hopefully VTK soon. Inlining C/C++ code within Python generally\nresults in speed ups of 1.5x to 30x speed-up over algorithms written in pure\nPython (However, it is also possible to slow things down...). Generally \nalgorithms that require a large number of calls to the Python API don't benefit\nas much from the conversion to C/C++ as algorithms that have inner loops \ncompletely convertable to C.\n

\nThere are three basic ways to use weave. The \nweave.inline() function executes C code directly within Python, \nand weave.blitz() translates Python Numeric expressions to C++ \nfor fast execution. blitz() was the original reason \nweave was built. For those interested in building extension\nlibraries, the ext_tools module provides classes for building \nextension modules within Python. \n

\nMost of weave's functionality should work on Windows and Unix, \nalthough some of its functionality requires gcc or a similarly \nmodern C++ compiler that handles templates well. Up to now, most testing has \nbeen done on Windows 2000 with Microsoft's C++ compiler (MSVC) and with gcc \n(mingw32 2.95.2 and 2.95.3-6). All tests also pass on Linux (RH 7.1 \nwith gcc 2.96), and I've had reports that it works on Debian also (thanks \nPearu).\n

\nThe inline and blitz provide new functionality to \nPython (although I've recently learned about the PyInline project which may offer \nsimilar functionality to inline). On the other hand, tools for \nbuilding Python extension modules already exists (SWIG, SIP, pycpp, CXX, and \nothers). As of yet, I'm not sure where weave fits in this \nspectrum. It is closest in flavor to CXX in that it makes creating new C/C++ \nextension modules pretty easy. However, if you're wrapping a gaggle of legacy \nfunctions or classes, SWIG and friends are definitely the better choice. \nweave is set up so that you can customize how Python types are \nconverted to C types in weave. This is great for \ninline(), but, for wrapping legacy code, it is more flexible to \nspecify things the other way around -- that is how C types map to Python types. \nThis weave does not do. I guess it would be possible to build \nsuch a tool on top of weave, but with good tools like SWIG around, \nI'm not sure the effort produces any new capabilities. Things like function \noverloading are probably easily implemented in weave and it might \nbe easier to mix Python/C code in function calls, but nothing beyond this comes \nto mind. So, if you're developing new extension modules or optimizing Python \nfunctions in C, weave.ext_tools() might be the tool \nfor you. If you're wrapping legacy code, stick with SWIG.\n

\nThe next several sections give the basics of how to use weave.\nWe'll discuss what's happening under the covers in more detail later \non. Serious users will need to at least look at the type conversion section to \nunderstand how Python variables map to C/C++ types and how to customize this \nbehavior. One other note. If you don't know C or C++ then these docs are \nprobably of very little help to you. Further, it'd be helpful if you know \nsomething about writing Python extensions. weave does quite a \nbit for you, but for anything complex, you'll need to do some conversions, \nreference counting, etc.\n

\n\nNote: weave is actually part of the SciPy package. However, it works fine as a \nstandalone package. The examples here are given as if it is used as a stand \nalone package. If you are using from within scipy, you can use from \nscipy import weave and the examples will work identically.\n\n\n

Requirements

\n
    \n
  • Python\n

    \n I use 2.1.1. Probably 2.0 or higher should work.\n

    \n

  • \n \n
  • C++ compiler\n

    \n weave uses distutils to actually build \n extension modules, so it uses whatever compiler was originally used to \n build Python. weave itself requires a C++ compiler. If \n you used a C++ compiler to build Python, your probably fine.\n

    \n On Unix gcc is the preferred choice because I've done a little \n testing with it. All testing has been done with gcc, but I expect the \n majority of compilers should work for inline and \n ext_tools. The one issue I'm not sure about is that I've \n hard coded things so that compilations are linked with the \n stdc++ library. Is this standard across \n Unix compilers, or is this a gcc-ism?\n

    \n For blitz(), you'll need a reasonably recent version of \n gcc. 2.95.2 works on windows and 2.96 looks fine on Linux. Other \n versions are likely to work. Its likely that KAI's C++ compiler and \n maybe some others will work, but I haven't tried. My advice is to use \n gcc for now unless your willing to tinker with the code some.\n

    \n On Windows, either MSVC or gcc (www.mingw.org\" > mingw32) should work. Again, \n you'll need gcc for blitz() as the\n MSVC compiler doesn't handle templates well.\n

    \n I have not tried Cygwin, so please report success if it works for you.\n

    \n

  • \n\n
  • Numeric (optional)\n

    \n The python Numeric module from here. is required for \n blitz() to work. Be sure and get NumPy, not NumArray\n which is the \"next generation\" implementation. This is not\n required for using inline() or ext_tools.\n

    \n

  • \n
  • scipy_distutils and scipy_test (packaged with weave)\n

    \n These two modules are packaged with weave in both\n the windows installer and the source distributions. If you are using\n CVS, however, you'll need to download these separately (also available\n through CVS at SciPy).\n

    \n

  • \n
\n

\n\n\n

Installation

\n

\nThere are currently two ways to get weave. Fist, \nweave is part of SciPy and installed automatically (as a sub-\npackage) whenever SciPy is installed (although the latest version isn't in \nSciPy yet, so use this one for now). Second, since weave is \nuseful outside of the scientific community, it has been setup so that it can be\nused as a stand-alone module. \n\n

\nThe stand-alone version can be downloaded from here. Unix users should grab the \ntar ball (.tgz file) and install it using the following commands.\n\n

\n    tar -xzvf weave-0.2.tar.gz\n    cd weave-0.2\n    python setup.py install\n    
\n\nThis will also install two other packages, scipy_distutils and \nscipy_test. The first is needed by the setup process itself and \nboth are used in the unit-testing process. Numeric is required if you want to \nuse blitz(), but isn't necessary for inline() or \next_tools\n

\nFor Windows users, it's even easier. You can download the click-install .exe \nfile and run it for automatic installation. There is also a .zip file of the\nsource for those interested. It also includes a setup.py file to simplify\ninstallation. \n

\nIf you're using the CVS version, you'll need to install \nscipy_distutils and scipy_test packages (also \navailable from CVS) on your own.\n

\n \nNote: The dependency issue here is a little sticky. I hate to make people \ndownload more than one file (and so I haven't), but distutils doesn't have a \nway to do conditional installation -- at least that I know about. This can \nlead to undesired clobbering of the scipy_test and scipy_distutils modules. \nWhat to do, what to do... Right now it is a very minor issue.\n\n

\n\n

Testing

\nOnce weave is installed, fire up python and run its unit tests.\n\n
\n    >>> import weave\n    >>> weave.test()\n    runs long time... spews tons of output and a few warnings\n    .\n    .\n    .\n    ..............................................................\n    ................................................................\n    ..................................................\n    ----------------------------------------------------------------------\n    Ran 184 tests in 158.418s\n\n    OK\n    \n    >>> \n    
\n\nThis takes a loooong time. On windows, it is usually several minutes. On Unix \nwith remote file systems, I've had it take 15 or so minutes. In the end, it \nshould run about 180 tests and spew some speed results along the way. If you \nget errors, they'll be reported at the end of the output. Please let me know\nwhat if this occurs.\n\nIf you don't have Numeric installed, you'll get some module import errors \nduring the test setup phase for modules that are Numeric specific (blitz_spec, \nblitz_tools, size_check, standard_array_spec, ast_tools), but all test should\npass (about 100 and they should complete in several minutes).\n

\nIf you only want to test a single module of the package, you can do this by\nrunning test() for that specific module.\n\n

\n    >>> import weave.scalar_spec\n    >>> weave.scalar_spec.test()\n    .......\n    ----------------------------------------------------------------------\n    Ran 7 tests in 23.284s\n    
\n\nTesting Notes:\n
    \n
  • \n Windows 1\n

    \n I've had some test fail on windows machines where I have msvc, gcc-2.95.2 \n (in c:\\gcc-2.95.2), and gcc-2.95.3-6 (in c:\\gcc) all installed. My \n environment has c:\\gcc in the path and does not have c:\\gcc-2.95.2 in the \n path. The test process runs very smoothly until the end where several test \n using gcc fail with cpp0 not found by g++. If I check os.system('gcc -v') \n before running tests, I get gcc-2.95.3-6. If I check after running tests \n (and after failure), I get gcc-2.95.2. ??huh??. The os.environ['PATH'] \n still has c:\\gcc first in it and is not corrupted (msvc/distutils messes \n with the environment variables, so we have to undo its work in some \n places). If anyone else sees this, let me know - - it may just be an quirk \n on my machine (unlikely). Testing with the gcc- 2.95.2 installation always \n works.\n

    \n

  • \n
  • \n Windows 2\n

    \n If you run the tests from PythonWin or some other GUI tool, you'll get a\n ton of DOS windows popping up periodically as weave spawns\n the compiler multiple times. Very annoying. Anyone know how to fix this?\n

    \n

  • \n
  • \n wxPython\n

    \n wxPython tests are not enabled by default because importing wxPython on a \n Unix machine without access to a X-term will cause the program to exit. \n Anyone know of a safe way to detect whether wxPython can be imported and \n whether a display exists on a machine? \n

    \n

  • \n
    \n\n

    \n

\n\n\n

Benchmarks

\nThis section has a few benchmarks -- thats all people want to see anyway right? \nThese are mostly taken from running files in the weave/example \ndirectory and also from the test scripts. Without more information about what \nthe test actually do, their value is limited. Still, their here for the \ncurious. Look at the example scripts for more specifics about what problem was \nactually solved by each run. These examples are run under windows 2000 using \nMicrosoft Visual C++ and python2.1 on a 850 MHz PIII laptop with 320 MB of RAM.\nSpeed up is the improvement (degredation) factor of weave compared to \nconventional Python functions. The blitz() comparisons are shown\ncompared to Numeric.\n

\n

\n\n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n
\n

inline and ext_tools

Algorithm

Speed up

binary search   1.50
fibonacci (recursive)  82.10
fibonacci (loop)   9.17
return None   0.14
map   1.20
dictionary sort   2.54
vector quantization  37.40
\n

blitz -- double precision

Algorithm

Speed up

a = b + c 512x512   3.05
a = b + c + d 512x512   4.59
5 pt avg. filter, 2D Image 512x512   9.01
Electromagnetics (FDTD) 100x100x100   8.61
\n
\n

\n\nThe benchmarks shown blitz in the best possible light. Numeric \n(at least on my machine) is significantly worse for double precision than it is \nfor single precision calculations. If your interested in single precision \nresults, you can pretty much divide the double precision speed up by 3 and you'll\nbe close.\n\n\n

Inline

\n

\ninline() compiles and executes C/C++ code on the fly. Variables \nin the local and global Python scope are also available in the C/C++ code. \nValues are passed to the C/C++ code by assignment much like variables \nare passed into a standard Python function. Values are returned from the C/C++ \ncode through a special argument called return_val. Also, the contents of \nmutable objects can be changed within the C/C++ code and the changes remain \nafter the C code exits and returns to Python. (more on this later)\n

\nHere's a trivial printf example using inline():\n\n

\n    >>> import weave    \n    >>> a  = 1\n    >>> weave.inline('printf(\"%d\\\\n\",a);',['a'])\n    1\n    
\n

\nIn this, its most basic form, inline(c_code, var_list) requires two \narguments. c_code is a string of valid C/C++ code. \nvar_list is a list of variable names that are passed from \nPython into C/C++. Here we have a simple printf statement that \nwrites the Python variable a to the screen. The first time you run \nthis, there will be a pause while the code is written to a .cpp file, compiled \ninto an extension module, loaded into Python, cataloged for future use, and \nexecuted. On windows (850 MHz PIII), this takes about 1.5 seconds when using \nMicrosoft's C++ compiler (MSVC) and 6-12 seconds using gcc (mingw32 2.95.2). \nAll subsequent executions of the code will happen very quickly because the code \nonly needs to be compiled once. If you kill and restart the interpreter and then \nexecute the same code fragment again, there will be a much shorter delay in the \nfractions of seconds range. This is because weave stores a \ncatalog of all previously compiled functions in an on disk cache. When it sees \na string that has been compiled, it loads the already compiled module and \nexecutes the appropriate function. \n

\n\nNote: If you try the printf example in a GUI shell such as IDLE, \nPythonWin, PyShell, etc., you're unlikely to see the output. This is because the \nC code is writing to stdout, instead of to the GUI window. This doesn't mean \nthat inline doesn't work in these environments -- it only means that standard \nout in C is not the same as the standard out for Python in these cases. Non \ninput/output functions will work as expected.\n\n

\nAlthough effort has been made to reduce the overhead associated with calling \ninline, it is still less efficient for simple code snippets than using \nequivalent Python code. The simple printf example is actually \nslower by 30% or so than using Python print statement. And, it is \nnot difficult to create code fragments that are 8-10 times slower using inline \nthan equivalent Python. However, for more complicated algorithms, \nthe speed up can be worth while -- anywhwere from 1.5- 30 times faster. \nAlgorithms that have to manipulate Python objects (sorting a list) usually only \nsee a factor of 2 or so improvement. Algorithms that are highly computational \nor manipulate Numeric arrays can see much larger improvements. The \nexamples/vq.py file shows a factor of 30 or more improvement on the vector \nquantization algorithm that is used heavily in information theory and \nclassification problems.\n

\n\n\n

More with printf

\n

\nMSVC users will actually see a bit of compiler output that distutils does not\nsupress the first time the code executes:\n\n

    \n    >>> weave.inline(r'printf(\"%d\\n\",a);',['a'])\n    sc_e013937dbc8c647ac62438874e5795131.cpp\n       Creating library C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\n       \\Release\\sc_e013937dbc8c647ac62438874e5795131.lib and object C:\\DOCUME\n       ~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\sc_e013937dbc8c64\n       7ac62438874e5795131.exp\n    1\n    
\n

\nNothing bad is happening, its just a bit annoying. Anyone know how to \nturn this off? \n

\nThis example also demonstrates using 'raw strings'. The r \npreceeding the code string in the last example denotes that this is a 'raw \nstring'. In raw strings, the backslash character is not interpreted as an \nescape character, and so it isn't necessary to use a double backslash to \nindicate that the '\\n' is meant to be interpreted in the C printf \nstatement instead of by Python. If your C code contains a lot\nof strings and control characters, raw strings might make things easier.\nMost of the time, however, standard strings work just as well.\n\n

\nThe printf statement in these examples is formatted to print \nout integers. What happens if a is a string? inline\nwill happily, compile a new version of the code to accept strings as input,\nand execute the code. The result?\n\n

    \n    >>> a = 'string'\n    >>> weave.inline(r'printf(\"%d\\n\",a);',['a'])\n    32956972\n    
\n

\nIn this case, the result is non-sensical, but also non-fatal. In other \nsituations, it might produce a compile time error because a is \nrequired to be an integer at some point in the code, or it could produce a \nsegmentation fault. Its possible to protect against passing \ninline arguments of the wrong data type by using asserts in \nPython.\n\n

    \n    >>> a = 'string'\n    >>> def protected_printf(a):    \n    ...     assert(type(a) == type(1))\n    ...     weave.inline(r'printf(\"%d\\n\",a);',['a'])\n    >>> protected_printf(1)\n     1\n    >>> protected_printf('string')\n    AssertError...\n    
\n\n

\nFor printing strings, the format statement needs to be changed. Also, weave\ndoesn't convert strings to char*. Instead it uses CXX Py::String type, so \nyou have to do a little more work. Here we convert it to a C++ std::string\nand then ask cor the char* version.\n\n

    \n    >>> a = 'string'    \n    >>> weave.inline(r'printf(\"%s\\n\",std::string(a).c_str());',['a'])\n    string\n    
\n

\n \nThis is a little convoluted. Perhaps strings should convert to std::string\nobjects instead of CXX objects. Or maybe to char*.\n\n\n

\nAs in this case, C/C++ code fragments often have to change to accept different \ntypes. For the given printing task, however, C++ streams provide a way of a \nsingle statement that works for integers and strings. By default, the stream \nobjects live in the std (standard) namespace and thus require the use of \nstd::.\n\n

    \n    >>> weave.inline('std::cout << a << std::endl;',['a'])\n    1    \n    >>> a = 'string'\n    >>> weave.inline('std::cout << a << std::endl;',['a'])\n    string\n    
\n \n

\nExamples using printf and cout are included in \nexamples/print_example.py.\n\n\n

More examples

\n\nThis section shows several more advanced uses of inline. It \nincludes a few algorithms from the Python Cookbook \nthat have been re-written in inline C to improve speed as well as a couple \nexamples using Numeric and wxPython.\n\n\n

Binary search

\nLets look at the example of searching a sorted list of integers for a value. \nFor inspiration, we'll use Kalle Svensson's \nbinary_search() algorithm from the Python Cookbook. His recipe follows:\n\n
\n    def binary_search(seq, t):\n        min = 0; max = len(seq) - 1\n        while 1:\n            if max < min:\n                return -1\n            m = (min  + max)  / 2\n            if seq[m] < t: \n                min = m  + 1 \n            elif seq[m] > t: \n                max = m  - 1 \n            else:\n                return m    \n    
\n\nThis Python version works for arbitrary Python data types. The C version below is \nspecialized to handle integer values. There is a little type checking done in \nPython to assure that we're working with the correct data types before heading \ninto C. The variables seq and t don't need to be \ndeclared beacuse weave handles converting and declaring them in \nthe C code. All other temporary variables such as min, max, etc. \nmust be declared -- it is C after all. Here's the new mixed Python/C function:\n\n
    \n    def c_int_binary_search(seq,t):\n        # do a little type checking in Python\n        assert(type(t) == type(1))\n        assert(type(seq) == type([]))\n        \n        # now the C code\n        code = \"\"\"\n               #line 29 \"binary_search.py\"\n               int val, m, min = 0;  \n               int max = seq.length() - 1;\n               PyObject *py_val; \n               for(;;)\n               {\n                   if (max < min  ) \n                   { \n                       return_val =  Py::new_reference_to(Py::Int(-1)); \n                       break;\n                   } \n                   m =  (min + max) /2;\n                   val =    py_to_int(PyList_GetItem(seq.ptr(),m),\"val\"); \n                   if (val  < t) \n                       min = m  + 1;\n                   else if (val >  t)\n                       max = m - 1;\n                   else\n                   {\n                       return_val = Py::new_reference_to(Py::Int(m));\n                       break;\n                   }\n               }\n               \"\"\"\n        return inline(code,['seq','t'])\n    
\n

\nWe have two variables seq and t passed in. \nt is guaranteed (by the assert) to be an integer. \nPython integers are converted to C int types in the transition from Python to \nC. seq is a Python list. By default, it is translated to a CXX \nlist object. Full documentation for the CXX library can be found at its website. The basics are that the CXX \nprovides C++ class equivalents for Python objects that simplify, or at \nleast object orientify, working with Python objects in C/C++. For example, \nseq.length() returns the length of the list. A little more about\nCXX and its class methods, etc. is in the ** type conversions ** section.\n

\n\nNote: CXX uses templates and therefore may be a little less portable than \nanother alternative by Gordan McMillan called SCXX which was inspired by\nCXX. It doesn't use templates so it should compile faster and be more portable.\nSCXX has a few less features, but it appears to me that it would mesh with\nthe needs of weave quite well. Hopefully xxx_spec files will be written\nfor SCXX in the future, and we'll be able to compare on a more empirical\nbasis. Both sets of spec files will probably stick around, it just a question\nof which becomes the default.\n\n

\nMost of the algorithm above looks similar in C to the original Python code. \nThere are two main differences. The first is the setting of \nreturn_val instead of directly returning from the C code with a \nreturn statement. return_val is an automatically \ndefined variable of type PyObject* that is returned from the C \ncode back to Python. You'll have to handle reference counting issues when \nsetting this variable. In this example, CXX classes and functions handle the \ndirty work. All CXX functions and classes live in the namespace \nPy::. The following code converts the integer m to a \nCXX Int() object and then to a PyObject* with an \nincremented reference count using Py::new_reference_to().\n\n

   \n    return_val = Py::new_reference_to(Py::Int(m));\n    
\n

\nThe second big differences shows up in the retrieval of integer values from the \nPython list. The simple Python seq[i] call balloons into a C \nPython API call to grab the value out of the list and then a separate call to \npy_to_int() that converts the PyObject* to an integer. \npy_to_int() includes both a NULL cheack and a \nPyInt_Check() call as well as the conversion call. If either of \nthe checks fail, an exception is raised. The entire C++ code block is executed \nwith in a try/catch block that handles exceptions much like Python \ndoes. This removes the need for most error checking code.\n

\nIt is worth note that CXX lists do have indexing operators that result \nin code that looks much like Python. However, the overhead in using them \nappears to be relatively high, so the standard Python API was used on the \nseq.ptr() which is the underlying PyObject* of the \nList object.\n

\nThe #line directive that is the first line of the C code \nblock isn't necessary, but it's nice for debugging. If the compilation fails \nbecause of the syntax error in the code, the error will be reported as an error \nin the Python file \"binary_search.py\" with an offset from the given line number \n(29 here).\n

\nSo what was all our effort worth in terms of efficiency? Well not a lot in \nthis case. The examples/binary_search.py file runs both Python and C versions \nof the functions As well as using the standard bisect module. If \nwe run it on a 1 million element list and run the search 3000 times (for 0-\n2999), here are the results we get:\n\n

   \n    C:\\home\\ej\\wrk\\scipy\\weave\\examples> python binary_search.py\n    Binary search for 3000 items in 1000000 length list of integers:\n     speed in python: 0.159999966621\n     speed of bisect: 0.121000051498\n     speed up: 1.32\n     speed in c: 0.110000014305\n     speed up: 1.45\n     speed in c(no asserts): 0.0900000333786\n     speed up: 1.78\n    
\n

\nSo, we get roughly a 50-75% improvement depending on whether we use the Python \nasserts in our C version. If we move down to searching a 10000 element list, \nthe advantage evaporates. Even smaller lists might result in the Python \nversion being faster. I'd like to say that moving to Numeric lists (and \ngetting rid of the GetItem() call) offers a substantial speed up, but my \npreliminary efforts didn't produce one. I think the log(N) algorithm is to \nblame. Because the algorithm is nice, there just isn't much time spent \ncomputing things, so moving to C isn't that big of a win. If there are ways to \nreduce conversion overhead of values, this may improve the C/Python speed \nup. Anyone have other explanations or faster code, please let me know.\n\n\n

Dictionary Sort

\n

\nThe demo in examples/dict_sort.py is another example from the Python CookBook. \nThis \nsubmission, by Alex Martelli, demonstrates how to return the values from a \ndictionary sorted by their keys:\n\n

       \n    def sortedDictValues3(adict):\n        keys = adict.keys()\n        keys.sort()\n        return map(adict.get, keys)\n    
\n

\nAlex provides 3 algorithms and this is the 3rd and fastest of the set. The C \nversion of this same algorithm follows:\n\n

       \n    def c_sort(adict):\n        assert(type(adict) == type({}))\n        code = \"\"\"     \n        #line 21 \"dict_sort.py\"  \n        Py::List keys = adict.keys();\n        Py::List items(keys.length()); keys.sort();     \n        PyObject* item = NULL; \n        for(int i = 0;  i < keys.length();i++)\n        {\n            item = PyList_GET_ITEM(keys.ptr(),i);\n            item = PyDict_GetItem(adict.ptr(),item);\n            Py_XINCREF(item);\n            PyList_SetItem(items.ptr(),i,item);              \n        }           \n        return_val = Py::new_reference_to(items);\n        \"\"\"   \n        return inline_tools.inline(code,['adict'],verbose=1)\n    
\n

\nLike the original Python function, the C++ version can handle any Python \ndictionary regardless of the key/value pair types. It uses CXX objects for the \nmost part to declare python types in C++, but uses Python API calls to manipulate \ntheir contents. Again, this choice is made for speed. The C++ version, while\nmore complicated, is about a factor of 2 faster than Python.\n\n

       \n    C:\\home\\ej\\wrk\\scipy\\weave\\examples> python dict_sort.py\n    Dict sort of 1000 items for 300 iterations:\n     speed in python: 0.319999933243\n    [0, 1, 2, 3, 4]\n     speed in c: 0.151000022888\n     speed up: 2.12\n    [0, 1, 2, 3, 4]\n    
\n

\n\n

Numeric -- cast/copy/transpose

\n\nCastCopyTranspose is a function called quite heavily by Linear Algebra routines\nin the Numeric library. Its needed in part because of the row-major memory layout\nof multi-demensional Python (and C) arrays vs. the col-major order of the underlying\nFortran algorithms. For small matrices (say 100x100 or less), a significant\nportion of the common routines such as LU decompisition or singular value decompostion\nare spent in this setup routine. This shouldn't happen. Here is the Python\nversion of the function using standard Numeric operations.\n\n
       \n    def _castCopyAndTranspose(type, array):\n        if a.typecode() == type:\n            cast_array = copy.copy(Numeric.transpose(a))\n        else:\n            cast_array = copy.copy(Numeric.transpose(a).astype(type))\n        return cast_array\n    
\n\nAnd the following is a inline C version of the same function:\n\n
\n    from weave.blitz_tools import blitz_type_factories\n    from weave import scalar_spec\n    from weave import inline\n    def _cast_copy_transpose(type,a_2d):\n        assert(len(shape(a_2d)) == 2)\n        new_array = zeros(shape(a_2d),type)\n        numeric_type = scalar_spec.numeric_to_blitz_type_mapping[type]\n        code = \\\n        \"\"\"  \n        for(int i = 0;i < _Na_2d[0]; i++)  \n            for(int j = 0;  j < _Na_2d[1]; j++)\n                new_array(i,j) = (%s) a_2d(j,i);\n        \"\"\" % numeric_type\n        inline(code,['new_array','a_2d'],\n               type_factories = blitz_type_factories,compiler='gcc')\n        return new_array\n    
\n\nThis example uses blitz++ arrays instead of the standard representation of \nNumeric arrays so that indexing is simplier to write. This is accomplished by \npassing in the blitz++ \"type factories\" to override the standard Python to C++ \ntype conversions. Blitz++ arrays allow you to write clean, fast code, but they \nalso are sloooow to compile (20 seconds or more for this snippet). This is why \nthey aren't the default type used for Numeric arrays (and also because most \ncompilers can't compile blitz arrays...). inline() is also forced \nto use 'gcc' as the compiler because the default compiler on Windows (MSVC) \nwill not compile blitz code. 'gcc' I think will use the standard compiler \non Unix machine instead of explicitly forcing gcc (check this) \n\nComparisons of the Python vs inline C++ code show a factor of 3 speed up. Also \nshown are the results of an \"inplace\" transpose routine that can be used if the \noutput of the linear algebra routine can overwrite the original matrix (this is \noften appropriate). This provides another factor of 2 improvement.\n\n
\n     #C:\\home\\ej\\wrk\\scipy\\weave\\examples> python cast_copy_transpose.py\n    # Cast/Copy/Transposing (150,150)array 1 times\n    #  speed in python: 0.870999932289\n    #  speed in c: 0.25\n    #  speed up: 3.48\n    #  inplace transpose c: 0.129999995232\n    #  speed up: 6.70\n    
\n\n\n

wxPython

\n\ninline knows how to handle wxPython objects. Thats nice in and of\nitself, but it also demonstrates that the type conversion mechanism is reasonably \nflexible. Chances are, it won't take a ton of effort to support special types\nyou might have. The examples/wx_example.py borrows the scrolled window\nexample from the wxPython demo, accept that it mixes inline C code in the middle\nof the drawing function.\n\n
\n    def DoDrawing(self, dc):\n        \n        red = wxNamedColour(\"RED\");\n        blue = wxNamedColour(\"BLUE\");\n        grey_brush = wxLIGHT_GREY_BRUSH;\n        code = \\\n        \"\"\"\n        #line 108 \"wx_example.py\" \n        dc->BeginDrawing();\n        dc->SetPen(wxPen(*red,4,wxSOLID));\n        dc->DrawRectangle(5,5,50,50);\n        dc->SetBrush(*grey_brush);\n        dc->SetPen(wxPen(*blue,4,wxSOLID));\n        dc->DrawRectangle(15, 15, 50, 50);\n        \"\"\"\n        inline(code,['dc','red','blue','grey_brush'])\n        \n        dc.SetFont(wxFont(14, wxSWISS, wxNORMAL, wxNORMAL))\n        dc.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))\n        te = dc.GetTextExtent(\"Hello World\")\n        dc.DrawText(\"Hello World\", 60, 65)\n\n        dc.SetPen(wxPen(wxNamedColour('VIOLET'), 4))\n        dc.DrawLine(5, 65+te[1], 60+te[0], 65+te[1])\n        ...\n    
\n\nHere, some of the Python calls to wx objects were just converted to C++ calls. There\nisn't any benefit, it just demonstrates the capabilities. You might want to use this\nif you have a computationally intensive loop in your drawing code that you want to \nspeed up.\n\nOn windows, you'll have to use the MSVC compiler if you use the standard wxPython\nDLLs distributed by Robin Dunn. Thats because MSVC and gcc, while binary\ncompatible in C, are not binary compatible for C++. In fact, its probably best, no \nmatter what platform you're on, to specify that inline use the same\ncompiler that was used to build wxPython to be on the safe side. There isn't currently\na way to learn this info from the library -- you just have to know. Also, at least\non the windows platform, you'll need to install the wxWindows libraries and link to \nthem. I think there is a way around this, but I haven't found it yet -- I get some\nlinking errors dealing with wxString. One final note. You'll probably have to\ntweak weave/wx_spec.py or weave/wx_info.py for your machine's configuration to\npoint at the correct directories etc. There. That should sufficiently scare people\ninto not even looking at this... :)\n\n
\n

Keyword Options

\n

\nThe basic definition of the inline() function has a slew of \noptional variables. It also takes keyword arguments that are passed to \ndistutils as compiler options. The following is a formatted \ncut/paste of the argument section of inline's doc-string. It \nexplains all of the variables. Some examples using various options will \nfollow.\n\n

       \n    def inline(code,arg_names,local_dict = None, global_dict = None, \n               force = 0, \n               compiler='',\n               verbose = 0, \n               support_code = None,\n               customize=None, \n               type_factories = None, \n               auto_downcast=1,\n               **kw):\n    
\n\n \ninline has quite \na few options as listed below. Also, the keyword arguments for distutils \nextension modules are accepted to specify extra information needed for \ncompiling. \n
\n

inline Arguments:

\n
\n
\n
code
\n \n
\nstring. A string of valid C++ code. It should not \n specify a return statement. Instead it should assign results that need to be \n returned to Python in the return_val. \n
\n\n
arg_names
\n \n
\nlist of strings. A list of Python variable names \n that should be transferred from Python into the C/C++ code. \n
\n\n
local_dict
\n \n
\noptional. dictionary. If specified, it is a \n dictionary of values that should be used as the local scope for the C/C++ \n code. If local_dict is not specified the local dictionary of the calling \n function is used. \n
\n\n
global_dict
\n \n
\noptional. dictionary. If specified, it is a \n dictionary of values that should be used as the global scope for the C/C++ \n code. If global_dict is not specified the global dictionary of the calling \n function is used. \n
\n\n
force
\n \n
\noptional. 0 or 1. default 0. If 1, the C++ code is \n compiled every time inline is called. This is really only useful for \n debugging, and probably only useful if you're editing support_code a lot. \n
\n\n
compiler
\n \n
\noptional. string. The name of compiler to use when compiling. On windows, it \nunderstands 'msvc' and 'gcc' as well as all the compiler names understood by \ndistutils. On Unix, it'll only understand the values understoof by distutils. \n(I should add 'gcc' though to this).\n

\nOn windows, the compiler defaults to the Microsoft C++ compiler. If this isn't \navailable, it looks for mingw32 (the gcc compiler).\n

\nOn Unix, it'll probably use the same compiler that was used when compiling \nPython. Cygwin's behavior should be similar.

\n
\n\n
verbose
\n \n
\noptional. 0,1, or 2. defualt 0. Speficies how much \n much information is printed during the compile phase of inlining code. 0 is \n silent (except on windows with msvc where it still prints some garbage). 1 \n informs you when compiling starts, finishes, and how long it took. 2 prints \n out the command lines for the compilation process and can be useful if you're \n having problems getting code to work. Its handy for finding the name of the \n .cpp file if you need to examine it. verbose has no affect if the \n compilation isn't necessary. \n
\n\n
support_code
\n \n
\noptional. string. A string of valid C++ code \n declaring extra code that might be needed by your compiled function. This \n could be declarations of functions, classes, or structures. \n
\n\n
customize
\n \n
\noptional. base_info.custom_info object. An \n alternative way to specifiy support_code, headers, etc. needed by the \n function see the weave.base_info module for more details. (not sure \n this'll be used much). \n \n
\n
type_factories
\n \n
\noptional. list of type specification factories. These guys are what convert \nPython data types to C/C++ data types. If you'd like to use a different set of \ntype conversions than the default, specify them here. Look in the type \nconversions section of the main documentation for examples.\n
\n
auto_downcast
\n \n
\noptional. 0 or 1. default 1. This only affects functions that have Numeric \narrays as input variables. Setting this to 1 will cause all floating point \nvalues to be cast as float instead of double if all the Numeric arrays are of \ntype float. If even one of the arrays has type double or double complex, all \nvariables maintain there standard types.\n
\n
\n
\n\n

Distutils keywords:

\n
\ninline() also accepts a number of distutils keywords \nfor controlling how the code is compiled. The following descriptions have been \ncopied from Greg Ward's distutils.extension.Extension class doc-\nstrings for convenience:\n\n
\n
sources
\n \n
\n[string] list of source filenames, relative to the \n distribution root (where the setup script lives), in Unix form \n (slash-separated) for portability. Source files may be C, C++, SWIG (.i), \n platform-specific resource files, or whatever else is recognized by the \n \"build_ext\" command as source for a Python extension. Note: The module_path \n file is always appended to the front of this list \n
\n\n
include_dirs
\n \n
\n[string] list of directories to search for C/C++ \n header files (in Unix form for portability) \n
\n\n
define_macros
\n \n
\n[(name : string, value : string|None)] list of \n macros to define; each macro is defined using a 2-tuple, where 'value' is \n either the string to define it to or None to define it without a particular \n value (equivalent of \"#define FOO\" in source or -DFOO on Unix C compiler \n command line) \n
\n
undef_macros
\n \n
\n[string] list of macros to undefine explicitly \n
\n
library_dirs
\n
\n[string] list of directories to search for C/C++ libraries at link time \n
\n
libraries
\n
\n[string] list of library names (not filenames or paths) to link against \n
\n
runtime_library_dirs
\n
\n[string] list of directories to search for C/C++ libraries at run time (for \nshared extensions, this is when the extension is loaded) \n
\n\n
extra_objects
\n \n
\n[string] list of extra files to link with (eg. \n object files not implied by 'sources', static library that must be \n explicitly specified, binary resource files, etc.) \n
\n\n
extra_compile_args
\n \n
\n[string] any extra platform- and compiler-specific \n information to use when compiling the source files in 'sources'. For \n platforms and compilers where \"command line\" makes sense, this is typically \n a list of command-line arguments, but for other platforms it could be \n anything. \n
\n
extra_link_args
\n \n
\n[string] any extra platform- and compiler-specific \n information to use when linking object files together to create the \n extension (or to create a new static Python interpreter). Similar \n interpretation as for 'extra_compile_args'. \n
\n
export_symbols
\n \n
\n[string] list of symbols to be exported from a shared extension. Not used on \nall platforms, and not generally necessary for Python extensions, which \ntypically export exactly one symbol: \"init\" + extension_name. \n
\n
\n
\n\n\n

Keyword Option Examples

\nWe'll walk through several examples here to demonstrate the behavior of \ninline and also how the various arguments are used.\n\nIn the simplest (most) cases, code and arg_names\nare the only arguments that need to be specified. Here's a simple example\nrun on Windows machine that has Microsoft VC++ installed.\n\n
\n    >>> from weave import inline\n    >>> a = 'string'\n    >>> code = \"\"\"\n    ...        int l = a.length();\n    ...        return_val = Py::new_reference_to(Py::Int(l));\n    ...        \"\"\"\n    >>> inline(code,['a'])\n     sc_86e98826b65b047ffd2cd5f479c627f12.cpp\n    Creating\n       library C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\sc_86e98826b65b047ffd2cd5f479c627f12.lib\n    and object C:\\DOCUME~ 1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\sc_86e98826b65b047ff\n    d2cd5f479c627f12.exp\n    6\n    >>> inline(code,['a'])\n    6\n    
\n \nWhen inline is first run, you'll notice that pause and some \ntrash printed to the screen. The \"trash\" is acutually part of the compilers\noutput that distutils does not supress. The name of the extension file, \nsc_bighonkingnumber.cpp, is generated from the md5 check sum\nof the C/C++ code fragment. On Unix or windows machines with only\ngcc installed, the trash will not appear. On the second call, the code \nfragment is not compiled since it already exists, and only the answer is \nreturned. Now kill the interpreter and restart, and run the same code with\na different string.\n\n
\n    >>> from weave import inline\n    >>> a = 'a longer string' \n    >>> code = \"\"\" \n    ...        int l = a.length();\n    ...        return_val = Py::new_reference_to(Py::Int(l));  \n    ...        \"\"\"\n    >>> inline(code,['a'])\n    15\n    
\n

\nNotice this time, inline() did not recompile the code because it\nfound the compiled function in the persistent catalog of functions. There is\na short pause as it looks up and loads the function, but it is much shorter \nthan compiling would require.\n

\nYou can specify the local and global dictionaries if you'd like (much like \nexec or eval() in Python), but if they aren't \nspecified, the \"expected\" ones are used -- i.e. the ones from the function that \ncalled inline() . This is accomplished through a little call \nframe trickery. Here is an example where the local_dict is specified using\nthe same code example from above:\n\n

\n    >>> a = 'a longer string'\n    >>> b = 'an even  longer string' \n    >>> my_dict = {'a':b}\n    >>> inline(code,['a'])\n    15\n    >>> inline(code,['a'],my_dict)\n    21\n    
\n \n

\nEverytime, the code is changed, inline does a \nrecompile. However, changing any of the other options in inline does not\nforce a recompile. The force option was added so that one\ncould force a recompile when tinkering with other variables. In practice,\nit is just as easy to change the code by a single character\n(like adding a space some place) to force the recompile. Note: It also \nmight be nice to add some methods for purging the cache and on disk \ncatalogs.\n

\nI use verbose sometimes for debugging. When set to 2, it'll \noutput all the information (including the name of the .cpp file) that you'd\nexpect from running a make file. This is nice if you need to examine the\ngenerated code to see where things are going haywire. Note that error\nmessages from failed compiles are printed to the screen even if verbose\n is set to 0.\n

\nThe following example demonstrates using gcc instead of the standard msvc \ncompiler on windows using same code fragment as above. Because the example has \nalready been compiled, the force=1 flag is needed to make \ninline() ignore the previously compiled version and recompile \nusing gcc. The verbose flag is added to show what is printed out:\n\n

\n    >>>inline(code,['a'],compiler='gcc',verbose=2,force=1)\n    running build_ext    \n    building 'sc_86e98826b65b047ffd2cd5f479c627f13' extension \n    c:\\gcc-2.95.2\\bin\\g++.exe -mno-cygwin -mdll -O2 -w -Wstrict-prototypes -IC:\n    \\home\\ej\\wrk\\scipy\\weave -IC:\\Python21\\Include -c C:\\DOCUME~1\\eric\\LOCAL\n    S~1\\Temp\\python21_compiled\\sc_86e98826b65b047ffd2cd5f479c627f13.cpp -o C:\\D\n    OCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\sc_86e98826b65b04\n    7ffd2cd5f479c627f13.o    \n    skipping C:\\home\\ej\\wrk\\scipy\\weave\\CXX\\cxxextensions.c (C:\\DOCUME~1\\eri\n    c\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\cxxextensions.o up-to-date)\n    skipping C:\\home\\ej\\wrk\\scipy\\weave\\CXX\\cxxsupport.cxx (C:\\DOCUME~1\\eric\n    \\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\cxxsupport.o up-to-date)\n    skipping C:\\home\\ej\\wrk\\scipy\\weave\\CXX\\IndirectPythonInterface.cxx (C:\\\n    DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\indirectpythonin\n    terface.o up-to-date)\n    skipping C:\\home\\ej\\wrk\\scipy\\weave\\CXX\\cxx_extensions.cxx (C:\\DOCUME~1\\\n    eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\cxx_extensions.o up-to-da\n    te)\n    writing C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\sc_86\n    e98826b65b047ffd2cd5f479c627f13.def\n    c:\\gcc-2.95.2\\bin\\dllwrap.exe --driver-name g++ -mno-cygwin -mdll -static -\n    -output-lib C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\l\n    ibsc_86e98826b65b047ffd2cd5f479c627f13.a --def C:\\DOCUME~1\\eric\\LOCALS~1\\Te\n    mp\\python21_compiled\\temp\\Release\\sc_86e98826b65b047ffd2cd5f479c627f13.def \n    -s C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\sc_86e9882\n    6b65b047ffd2cd5f479c627f13.o C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compil\n    ed\\temp\\Release\\cxxextensions.o C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_com\n    piled\\temp\\Release\\cxxsupport.o C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_com\n    piled\\temp\\Release\\indirectpythoninterface.o C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\n    \\python21_compiled\\temp\\Release\\cxx_extensions.o -LC:\\Python21\\libs -lpytho\n    n21 -o C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\sc_86e98826b65b047f\n    fd2cd5f479c627f13.pyd\n    15\n    
\n\nThat's quite a bit of output. verbose=1 just prints the compile\ntime.\n\n
\n    >>>inline(code,['a'],compiler='gcc',verbose=1,force=1)\n    Compiling code...\n    finished compiling (sec):  6.00800001621\n    15\n    
\n\n

\n Note: I've only used the compiler option for switching between 'msvc'\nand 'gcc' on windows. It may have use on Unix also, but I don't know yet.\n\n\n

\nThe support_code argument is likely to be used a lot. It allows \nyou to specify extra code fragments such as function, structure or class \ndefinitions that you want to use in the code string. Note that \nchanges to support_code do not force a recompile. The \ncatalog only relies on code (for performance reasons) to determine \nwhether recompiling is necessary. So, if you make a change to support_code, \nyou'll need to alter code in some way or use the \nforce argument to get the code to recompile. I usually just add \nsome inocuous whitespace to the end of one of the lines in code \nsomewhere. Here's an example of defining a separate method for calculating\nthe string length:\n\n

\n    >>> from weave import inline\n    >>> a = 'a longer string'\n    >>> support_code = \"\"\"\n    ...                PyObject* length(Py::String a)\n    ...                {\n    ...                    int l = a.length();  \n    ...                    return Py::new_reference_to(Py::Int(l)); \n    ...                }\n    ...                \"\"\"        \n    >>> inline(\"return_val = length(a);\",['a'],\n    ...        support_code = support_code)\n    15\n    
\n

\ncustomize is a left over from a previous way of specifying \ncompiler options. It is a custom_info object that can specify \nquite a bit of information about how a file is compiled. These \ninfo objects are the standard way of defining compile information \nfor type conversion classes. However, I don't think they are as handy here, \nespecially since we've exposed all the keyword arguments that distutils can \nhandle. Between these keywords, and the support_code option, I \nthink customize may be obsolete. We'll see if anyone cares to use \nit. If not, it'll get axed in the next version.\n

\nThe type_factories variable is important to people who want to\ncustomize the way arguments are converted from Python to C. We'll talk about\nthis in the next chapter **xx** of this document when we discuss type\nconversions.\n

\nauto_downcast handles one of the big type conversion issues that\nis common when using Numeric arrays in conjunction with Python scalar values.\nIf you have an array of single precision values and multiply that array by a \nPython scalar, the result is upcast to a double precision array because the\nscalar value is double precision. This is not usually the desired behavior\nbecause it can double your memory usage. auto_downcast goes\nsome distance towards changing the casting precedence of arrays and scalars.\nIf your only using single precision arrays, it will automatically downcast all\nscalar values from double to single precision when they are passed into the\nC++ code. This is the default behavior. If you want all values to keep there\ndefault type, set auto_downcast to 0.\n

\n\n\n\n

Returning Values

\n\nPython variables in the local and global scope transfer seemlessly from Python \ninto the C++ snippets. And, if inline were to completely live up\nto its name, any modifications to variables in the C++ code would be reflected\nin the Python variables when control was passed back to Python. For example,\nthe desired behavior would be something like:\n\n
\n    # THIS DOES NOT WORK\n    >>> a = 1\n    >>> weave.inline(\"a++;\",['a'])\n    >>> a\n    2\n    
\n\nInstead you get:\n\n
\n    >>> a = 1\n    >>> weave.inline(\"a++;\",['a'])\n    >>> a\n    1\n    
\n \nVariables are passed into C++ as if you are calling a Python function. Python's \ncalling convention is sometimes called \"pass by assignment\". This means its as \nif a c_a = a assignment is made right before inline \ncall is made and the c_a variable is used within the C++ code. \nThus, any changes made to c_a are not reflected in Python's \na variable. Things do get a little more confusing, however, when \nlooking at variables with mutable types. Changes made in C++ to the contents \nof mutable types are reflected in the Python variables.\n\n
\n    >>> a= [1,2]\n    >>> weave.inline(\"PyList_SetItem(a.ptr(),0,PyInt_FromLong(3));\",['a'])\n    >>> print a\n    [3, 2]\n    
\n\nSo modifications to the contents of mutable types in C++ are seen when control\nis returned to Python. Modifications to immutable types such as tuples,\nstrings, and numbers do not alter the Python variables.\n\nIf you need to make changes to an immutable variable, you'll need to assign\nthe new value to the \"magic\" variable return_val in C++. This\nvalue is returned by the inline() function:\n\n
\n    >>> a = 1\n    >>> a = weave.inline(\"return_val = Py::new_reference_to(Py::Int(a+1));\",['a'])  \n    >>> a\n    2\n    
\n\nThe return_val variable can also be used to return newly created \nvalues. This is possible by returning a tuple. The following trivial example \nillustrates how this can be done:\n\n
       \n    # python version\n    def multi_return():\n        return 1, '2nd'\n    \n    # C version.\n    def c_multi_return():    \n        code =  \"\"\"\n     \t        Py::Tuple results(2);\n     \t        results[0] = Py::Int(1);\n     \t        results[1] = Py::String(\"2nd\");\n     \t        return_val = Py::new_reference_to(results); \t        \n                \"\"\"\n        return inline_tools.inline(code)\n    
\n

\nThe example is available in examples/tuple_return.py. It also\nhas the dubious honor of demonstrating how much inline() can \nslow things down. The C version here is about 10 times slower than the Python\nversion. Of course, something so trivial has no reason to be written in\nC anyway.\n\n\n

The issue with locals()

\n

\ninline passes the locals() and globals() \ndictionaries from Python into the C++ function from the calling function. It \nextracts the variables that are used in the C++ code from these dictionaries, \nconverts then to C++ variables, and then calculates using them. It seems like \nit would be trivial, then, after the calculations were finished to then insert \nthe new values back into the locals() and globals() \ndictionaries so that the modified values were reflected in Python. \nUnfortunately, as pointed out by the Python manual, the locals() dictionary is \nnot writable. \n

\n\nI suspect locals() is not writable because there are some \noptimizations done to speed lookups of the local namespace. I'm guessing local \nlookups don't always look at a dictionary to find values. Can someone \"in the \nknow\" confirm or correct this? Another thing I'd like to know is whether there \nis a way to write to the local namespace of another stack frame from C/C++. If \nso, it would be possible to have some clean up code in compiled functions that \nwrote final values of variables in C++ back to the correct Python stack frame. \nI think this goes a long way toward making inline truely live up \nto its name. I don't think we'll get to the point of creating variables in \nPython for variables created in C -- although I suppose with a C/C++ parser you \ncould do that also.\n\n

\n\n\n

A quick look at the code

\n\nweave generates a C++ file holding an extension function for \neach inline code snippet. These file names are generated using \nfrom the md5 signature of the code snippet and saved to a location specified by \nthe PYTHONCOMPILED environment variable (discussed later). The cpp files are \ngenerally about 200-400 lines long and include quite a few functions to support \ntype conversions, etc. However, the actual compiled function is pretty simple. \nBelow is the familiar printf example:\n\n
\n    >>> import weave    \n    >>> a = 1\n    >>> weave.inline('printf(\"%d\\\\n\",a);',['a'])\n    1\n    
\n\nAnd here is the extension function generated by inline:\n\n
\n    static PyObject* compiled_func(PyObject*self, PyObject* args)\n    {\n        // The Py_None needs an incref before returning\n        PyObject *return_val = NULL;\n        int exception_occured = 0;\n        PyObject *py__locals = NULL;\n        PyObject *py__globals = NULL;\n        PyObject *py_a;\n        py_a = NULL;\n        \n        if(!PyArg_ParseTuple(args,\"OO:compiled_func\",&py__locals,&py__globals))\n            return NULL;\n        try                              \n        {                                \n            PyObject* raw_locals = py_to_raw_dict(py__locals,\"_locals\");\n            PyObject* raw_globals = py_to_raw_dict(py__globals,\"_globals\");\n            int a = py_to_int (get_variable(\"a\",raw_locals,raw_globals),\"a\");\n            /* Here is the inline code */            \n            printf(\"%d\\n\",a);\n            /* I would like to fill in changed locals and globals here... */\n        }                                       \n        catch( Py::Exception& e)           \n        {                                \n            return_val =  Py::Null();    \n            exception_occured = 1;       \n        }                                 \n        if(!return_val && !exception_occured)\n        {\n                                      \n            Py_INCREF(Py_None);              \n            return_val = Py_None;            \n        }\n        /* clean up code */\n        \n        /* return */                              \n        return return_val;           \n    }                                \n    
\n\nEvery inline function takes exactly two arguments -- the local and global\ndictionaries for the current scope. All variable values are looked up out\nof these dictionaries. The lookups, along with all inline code \nexecution, are done within a C++ try block. If the variables\naren't found, or there is an error converting a Python variable to the \nappropriate type in C++, an exception is raised. The C++ exception\nis automatically converted to a Python exception by CXX and returned to Python.\n\nThe py_to_int() function illustrates how the conversions and\nexception handling works. py_to_int first checks that the given PyObject*\npointer is not NULL and is a Python integer. If all is well, it calls the\nPython API to convert the value to an int. Otherwise, it calls\nhandle_bad_type() which gathers information about what went wrong\nand then raises a CXX TypeError which returns to Python as a TypeError.\n\n
\n    int py_to_int(PyObject* py_obj,char* name)\n    {\n        if (!py_obj || !PyInt_Check(py_obj))\n            handle_bad_type(py_obj,\"int\", name);\n        return (int) PyInt_AsLong(py_obj);\n    }\n    
\n\n
\n    void handle_bad_type(PyObject* py_obj, char* good_type, char*  var_name)\n    {\n        char msg[500];\n        sprintf(msg,\"received '%s' type instead of '%s' for variable '%s'\",\n                find_type(py_obj),good_type,var_name);\n        throw Py::TypeError(msg);\n    }\n    \n    char* find_type(PyObject* py_obj)\n    {\n        if(py_obj == NULL) return \"C NULL value\";\n        if(PyCallable_Check(py_obj)) return \"callable\";\n        if(PyString_Check(py_obj)) return \"string\";\n        if(PyInt_Check(py_obj)) return \"int\";\n        if(PyFloat_Check(py_obj)) return \"float\";\n        if(PyDict_Check(py_obj)) return \"dict\";\n        if(PyList_Check(py_obj)) return \"list\";\n        if(PyTuple_Check(py_obj)) return \"tuple\";\n        if(PyFile_Check(py_obj)) return \"file\";\n        if(PyModule_Check(py_obj)) return \"module\";\n        \n        //should probably do more interagation (and thinking) on these.\n        if(PyCallable_Check(py_obj) && PyInstance_Check(py_obj)) return \"callable\";\n        if(PyInstance_Check(py_obj)) return \"instance\"; \n        if(PyCallable_Check(py_obj)) return \"callable\";\n        return \"unkown type\";\n    }\n    
\n\nSince the inline is also executed within the try/catch\nblock, you can use CXX exceptions within your code. It is usually a bad idea\nto directly return from your code, even if an error occurs. This\nskips the clean up section of the extension function. In this simple example,\nthere isn't any clean up code, but in more complicated examples, there may\nbe some reference counting that needs to be taken care of here on converted\nvariables. To avoid this, either uses exceptions or set \nreturn_val to NULL and use if/then's to skip code\nafter errors.\n\n\n

Technical Details

\n

\nThere are several main steps to using C/C++ code withing Python:\n

    \n
  1. Type conversion \n
  2. Generating C/C++ code \n
  3. Compile the code to an extension module \n
  4. Catalog (and cache) the function for future use
  5. \n
\n

\nItems 1 and 2 above are related, but most easily discussed separately. Type \nconversions are customizable by the user if needed. Understanding them is \npretty important for anything beyond trivial uses of inline. \nGenerating the C/C++ code is handled by ext_function and \next_module classes and . For the most part, compiling the code is \nhandled by distutils. Some customizations were needed, but they were \nrelatively minor and do not require changes to distutils itself. Cataloging is \npretty simple in concept, but surprisingly required the most code to implement \n(and still likely needs some work). So, this section covers items 1 and 4 from \nthe list. Item 2 is covered later in the chapter covering the \next_tools module, and distutils is covered by a completely \nseparate document xxx.\n\n

Passing Variables in/out of the C/C++ code

\n\nNote: Passing variables into the C code is pretty straight forward, but there \nare subtlties to how variable modifications in C are returned to Python. see Returning Values for a more thorough discussion of \nthis issue.\n \n \n\n

Type Conversions

\n\n\nNote: Maybe xxx_converter instead of \nxxx_specification is a more descriptive name. Might change in \nfuture version?\n\n\n

\nBy default, inline() makes the following type conversions between\nPython and C++ types.\n

\n\n

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\n

Default Data Type Conversions

\n

Python

\n

C++

   int   int
   float   double
   complex   std::complex
   string   Py::String
   list   Py::List
   dict   Py::Dict
   tuple   Py::Tuple
   file   FILE*
   callable   PyObject*
   instance   PyObject*
   Numeric.array   PyArrayObject*
   wxXXX   wxXXX*
\n
\n

\nThe Py:: namespace is defined by the \nCXX library which has C++ class\nequivalents for many Python types. std:: is the namespace of the\nstandard library in C++.\n

\n\nNote: \n

    \n
  • I haven't figured out how to handle long int yet (I think they are currenlty converted \n to int - - check this). \n \n
  • \nHopefully VTK will be added to the list soon
  • \n
\n\n

\n\nPython to C++ conversions fill in code in several locations in the generated\ninline extension function. Below is the basic template for the\nfunction. This is actually the exact code that is generated by calling\nweave.inline(\"\").\n\n

\n    static PyObject* compiled_func(PyObject*self, PyObject* args)\n    {\n        PyObject *return_val = NULL;\n        int exception_occured = 0;\n        PyObject *py__locals = NULL;\n        PyObject *py__globals = NULL;\n        PyObject *py_a;\n        py_a = NULL;\n    \n        if(!PyArg_ParseTuple(args,\"OO:compiled_func\",&py__locals,&py__globals))\n            return NULL;\n        try\n        {\n            PyObject* raw_locals = py_to_raw_dict(py__locals,\"_locals\");\n            PyObject* raw_globals = py_to_raw_dict(py__globals,\"_globals\");\n            /* argument conversion code */\n            /* inline code */\n            /*I would like to fill in changed locals and globals here...*/\n    \n        }\n        catch( Py::Exception& e)\n        {\n            return_val =  Py::Null();\n            exception_occured = 1;\n        }\n        /* cleanup code */\n        if(!return_val && !exception_occured)\n        {\n    \n            Py_INCREF(Py_None);\n            return_val = Py_None;\n        }\n    \n        return return_val;\n    }\n    
\n\nThe /* inline code */ section is filled with the code passed to\nthe inline() function call. The \n/*argument convserion code*/ and /* cleanup code */\nsections are filled with code that handles conversion from Python to C++\ntypes and code that deallocates memory or manipulates reference counts before\nthe function returns. The following sections demostrate how these two areas\nare filled in by the default conversion methods.\n\n \nNote: I'm not sure I have reference counting correct on a few of these. The \nonly thing I increase/decrease the ref count on is Numeric arrays. If you\nsee an issue, please let me know.\n\n\n\n

Numeric Argument Conversion

\n\nInteger, floating point, and complex arguments are handled in a very similar\nfashion. Consider the following inline function that has a single integer \nvariable passed in:\n\n
\n    >>> a = 1\n    >>> inline(\"\",['a'])\n    
\n\nThe argument conversion code inserted for a is:\n\n
\n    /* argument conversion code */\n    int a = py_to_int (get_variable(\"a\",raw_locals,raw_globals),\"a\");\n    
\n\nget_variable() reads the variable a\nfrom the local and global namespaces. py_to_int() has the following\nform:\n\n
\n    static int py_to_int(PyObject* py_obj,char* name)\n    {\n        if (!py_obj || !PyInt_Check(py_obj))\n            handle_bad_type(py_obj,\"int\", name);\n        return (int) PyInt_AsLong(py_obj);\n    }\n    
\n\nSimilarly, the float and complex conversion routines look like:\n\n
    \n    static double py_to_float(PyObject* py_obj,char* name)\n    {\n        if (!py_obj || !PyFloat_Check(py_obj))\n            handle_bad_type(py_obj,\"float\", name);\n        return PyFloat_AsDouble(py_obj);\n    }\n    \n    static std::complex py_to_complex(PyObject* py_obj,char* name)\n    {\n        if (!py_obj || !PyComplex_Check(py_obj))\n            handle_bad_type(py_obj,\"complex\", name);\n        return std::complex(PyComplex_RealAsDouble(py_obj),\n                                    PyComplex_ImagAsDouble(py_obj));    \n    }\n    
\n\nNumeric conversions do not require any clean up code.\n\n\n

String, List, Tuple, and Dictionary Conversion

\n\nStrings, Lists, Tuples and Dictionary conversions are all converted to \nCXX types by default.\n\nFor the following code, \n\n
\n    >>> a = [1]\n    >>> inline(\"\",['a'])\n    
\n\nThe argument conversion code inserted for a is:\n\n
\n    /* argument conversion code */\n    Py::List a = py_to_list (get_variable(\"a\",raw_locals,raw_globals),\"a\");\n    
\n\nget_variable() reads the variable a\nfrom the local and global namespaces. py_to_list() and its\nfriends has the following form:\n\n
    \n    static Py::List py_to_list(PyObject* py_obj,char* name)\n    {\n        if (!py_obj || !PyList_Check(py_obj))\n            handle_bad_type(py_obj,\"list\", name);\n        return Py::List(py_obj);\n    }\n    \n    static Py::String py_to_string(PyObject* py_obj,char* name)\n    {\n        if (!PyString_Check(py_obj))\n            handle_bad_type(py_obj,\"string\", name);\n        return Py::String(py_obj);\n    }\n\n    static Py::Dict py_to_dict(PyObject* py_obj,char* name)\n    {\n        if (!py_obj || !PyDict_Check(py_obj))\n            handle_bad_type(py_obj,\"dict\", name);\n        return Py::Dict(py_obj);\n    }\n    \n    static Py::Tuple py_to_tuple(PyObject* py_obj,char* name)\n    {\n        if (!py_obj || !PyTuple_Check(py_obj))\n            handle_bad_type(py_obj,\"tuple\", name);\n        return Py::Tuple(py_obj);\n    }\n    
\n\nCXX handles reference counts on for strings, lists, tuples, and dictionaries,\nso clean up code isn't necessary.\n\n\n

File Conversion

\n\nFor the following code, \n\n
\n    >>> a = open(\"bob\",'w')  \n    >>> inline(\"\",['a'])\n    
\n\nThe argument conversion code is:\n\n
\n    /* argument conversion code */\n    PyObject* py_a = get_variable(\"a\",raw_locals,raw_globals);\n    FILE* a = py_to_file(py_a,\"a\");\n    
\n\nget_variable() reads the variable a\nfrom the local and global namespaces. py_to_file() converts\nPyObject* to a FILE* and increments the reference count of the PyObject*:\n\n
\n    FILE* py_to_file(PyObject* py_obj, char* name)\n    {\n        if (!py_obj || !PyFile_Check(py_obj))\n            handle_bad_type(py_obj,\"file\", name);\n    \n        Py_INCREF(py_obj);\n        return PyFile_AsFile(py_obj);\n    }\n    
\n\nBecause the PyObject* was incremented, the clean up code needs to decrement\nthe counter\n\n
\n    /* cleanup code */\n    Py_XDECREF(py_a);\n    
\n\nIts important to understand that file conversion only works on actual files --\ni.e. ones created using the open() command in Python. It does\nnot support converting arbitrary objects that support the file interface into\nC FILE* pointers. This can affect many things. For example, in\ninitial printf() examples, one might be tempted to solve the \nproblem of C and Python IDE's (PythonWin, PyCrust, etc.) writing to different\nstdout and stderr by using fprintf() and passing in \nsys.stdout and sys.stderr. For example, instead of\n\n
\n    >>> weave.inline('printf(\"hello\\\\n\");')\n    
\n \nYou might try:\n\n
\n    >>> buf = sys.stdout\n    >>> weave.inline('fprintf(buf,\"hello\\\\n\");',['buf'])\n    
\n\nThis will work as expected from a standard python interpreter, but in PythonWin,\nthe following occurs:\n\n
\n    >>> buf = sys.stdout\n    >>> weave.inline('fprintf(buf,\"hello\\\\n\");',['buf'])\n    Traceback (most recent call last):\n        File \"\", line 1, in ?\n        File \"C:\\Python21\\weave\\inline_tools.py\", line 315, in inline\n            auto_downcast = auto_downcast,\n        File \"C:\\Python21\\weave\\inline_tools.py\", line 386, in compile_function\n            type_factories = type_factories)\n        File \"C:\\Python21\\weave\\ext_tools.py\", line 197, in __init__\n            auto_downcast, type_factories)\n        File \"C:\\Python21\\weave\\ext_tools.py\", line 390, in assign_variable_types\n            raise TypeError, format_error_msg(errors)\n        TypeError: {'buf': \"Unable to convert variable 'buf' to a C++ type.\"}\n    
\n\nThe traceback tells us that inline() was unable to convert 'buf' to a\nC++ type (If instance conversion was implemented, the error would have occurred at \nruntime instead). Why is this? Let's look at what the buf object \nreally is:\n\n
\n    >>> buf\n    pywin.framework.interact.InteractiveView instance at 00EAD014\n    
\n\nPythonWin has reassigned sys.stdout to a special object that \nimplements the Python file interface. This works great in Python, but since \nthe special object doesn't have a FILE* pointer underlying it, fprintf doesn't \nknow what to do with it (well this will be the problem when instance conversion \nis implemented...).\n\n\n

Callable, Instance, and Module Conversion

\n\nNote: Need to look into how ref counts should be handled. Also,\nInstance and Module conversion are not currently implemented.\n\n\n
\n    >>> def a(): \n        pass\n    >>> inline(\"\",['a'])\n    
\n\nCallable and instance variables are converted to PyObject*. Nothing is done\nto there reference counts.\n\n
\n    /* argument conversion code */\n    PyObject* a = py_to_callable(get_variable(\"a\",raw_locals,raw_globals),\"a\");\n    
\n\nget_variable() reads the variable a\nfrom the local and global namespaces. The py_to_callable() and\npy_to_instance() don't currently increment the ref count.\n\n
    \n    PyObject* py_to_callable(PyObject* py_obj, char* name)\n    {\n        if (!py_obj || !PyCallable_Check(py_obj))\n            handle_bad_type(py_obj,\"callable\", name);    \n        return py_obj;\n    }\n\n    PyObject* py_to_instance(PyObject* py_obj, char* name)\n    {\n        if (!py_obj || !PyFile_Check(py_obj))\n            handle_bad_type(py_obj,\"instance\", name);    \n        return py_obj;\n    }\n    
\n \nThere is no cleanup code for callables, modules, or instances.\n\n\n

Customizing Conversions

\n

\nConverting from Python to C++ types is handled by xxx_specification classes. A \ntype specification class actually serve in two related but different \nroles. The first is in determining whether a Python variable that needs to be \nconverted should be represented by the given class. The second is as a code \ngenerator that generate C++ code needed to convert from Python to C++ types for \na specific variable.\n

\nWhen \n\n

\n    >>> a = 1\n    >>> weave.inline('printf(\"%d\",a);',['a'])\n    
\n \nis called for the first time, the code snippet has to be compiled. In this \nprocess, the variable 'a' is tested against a list of type specifications (the \ndefault list is stored in weave/ext_tools.py). The first \nspecification in the list is used to represent the variable. \n\n

\nExamples of xxx_specification are scattered throughout numerous \n\"xxx_spec.py\" files in the weave package. Closely related to \nthe xxx_specification classes are yyy_info classes. \nThese classes contain compiler, header, and support code information necessary \nfor including a certain set of capabilities (such as blitz++ or CXX support)\nin a compiled module. xxx_specification classes have one or more\nyyy_info classes associated with them.\n\nIf you'd like to define your own set of type specifications, the current best route\nis to examine some of the existing spec and info files. Maybe looking over\nsequence_spec.py and cxx_info.py are a good place to start. After defining \nspecification classes, you'll need to pass them into inline using the \ntype_factories argument. \n\nA lot of times you may just want to change how a specific variable type is \nrepresented. Say you'd rather have Python strings converted to \nstd::string or maybe char* instead of using the CXX \nstring object, but would like all other type conversions to have default \nbehavior. This requires that a new specification class that handles strings\nis written and then prepended to a list of the default type specifications. Since\nit is closer to the front of the list, it effectively overrides the default\nstring specification.\n\nThe following code demonstrates how this is done:\n\n...\n\n\n

The Catalog

\n

\ncatalog.py has a class called catalog that helps keep \ntrack of previously compiled functions. This prevents inline() \nand related functions from having to compile functions everytime they are \ncalled. Instead, catalog will check an in memory cache to see if the function \nhas already been loaded into python. If it hasn't, then it starts searching \nthrough persisent catalogs on disk to see if it finds an entry for the given \nfunction. By saving information about compiled functions to disk, it isn't\nnecessary to re-compile functions everytime you stop and restart the interpreter.\nFunctions are compiled once and stored for future use.\n\n

\nWhen inline(cpp_code) is called the following things happen:\n

    \n
  1. \n A fast local cache of functions is checked for the last function called for \n cpp_code. If an entry for cpp_code doesn't exist in the \n cache or the cached function call fails (perhaps because the function doesn't \n have compatible types) then the next step is to check the catalog. \n
  2. \n The catalog class also keeps an in-memory cache with a list of all the \n functions compiled for cpp_code. If cpp_code has\n ever been called, then this cache will be present (loaded from disk). If\n the cache isn't present, then it is loaded from disk.\n

    \n If the cache is present, each function in the cache is \n called until one is found that was compiled for the correct argument types. If \n none of the functions work, a new function is compiled with the given argument \n types. This function is written to the on-disk catalog as well as into the \n in-memory cache.

    \n
  3. \n When a lookup for cpp_code fails, the catalog looks through \n the on-disk function catalogs for the entries. The PYTHONCOMPILED variable \n determines where to search for these catalogs and in what order. If \n PYTHONCOMPILED is not present several platform dependent locations are \n searched. All functions found for cpp_code in the path are \n loaded into the in-memory cache with functions found earlier in the search \n path closer to the front of the call list.\n

    \n If the function isn't found in the on-disk catalog, \n then the function is compiled, written to the first writable directory in the \n PYTHONCOMPILED path, and also loaded into the in-memory cache.

    \n
  4. \n
\n\n\n

Function Storage: How functions are stored in caches and on disk

\n

\nFunction caches are stored as dictionaries where the key is the entire C++\ncode string and the value is either a single function (as in the \"level 1\"\ncache) or a list of functions (as in the main catalog cache). On disk\ncatalogs are stored in the same manor using standard Python shelves.\n

\nEarly on, there was a question as to whether md5 check sums of the C++\ncode strings should be used instead of the actual code strings. I think this\nis the route inline Perl took. Some (admittedly quick) tests of the md5 vs.\nthe entire string showed that using the entire string was at least a\nfactor of 3 or 4 faster for Python. I think this is because it is more\ntime consuming to compute the md5 value than it is to do look-ups of long\nstrings in the dictionary. Look at the examples/md5_speed.py file for the\ntest run. \n\n\n

Catalog search paths and the PYTHONCOMPILED variable

\n

\nThe default location for catalog files on Unix is is ~/.pythonXX_compiled where \nXX is version of Python being used. If this directory doesn't exist, it is \ncreated the first time a catalog is used. The directory must be writable. If, \nfor any reason it isn't, then the catalog attempts to create a directory based \non your user id in the /tmp directory. The directory permissions are set so \nthat only you have access to the directory. If this fails, I think you're out of \nluck. I don't think either of these should ever fail though. On Windows, a \ndirectory called pythonXX_compiled is created in the user's temporary \ndirectory. \n

\nThe actual catalog file that lives in this directory is a Python shelve with\na platform specific name such as \"nt21compiled_catalog\" so that multiple OSes\ncan share the same file systems without trampling on each other. Along with\nthe catalog file, the .cpp and .so or .pyd files created by inline will live\nin this directory. The catalog file simply contains keys which are the C++\ncode strings with values that are lists of functions. The function lists point\nat functions within these compiled modules. Each function in the lists \nexecutes the same C++ code string, but compiled for different input variables.\n

\nYou can use the PYTHONCOMPILED environment variable to specify alternative\nlocations for compiled functions. On Unix this is a colon (':') separated\nlist of directories. On windows, it is a (';') separated list of directories.\nThese directories will be searched prior to the default directory for a\ncompiled function catalog. Also, the first writable directory in the list\nis where all new compiled function catalogs, .cpp and .so or .pyd files are\nwritten. Relative directory paths ('.' and '..') should work fine in the\nPYTHONCOMPILED variable as should environement variables.\n

\nThere is a \"special\" path variable called MODULE that can be placed in the \nPYTHONCOMPILED variable. It specifies that the compiled catalog should\nreside in the same directory as the module that called it. This is useful\nif an admin wants to build a lot of compiled functions during the build\nof a package and then install them in site-packages along with the package.\nUser's who specify MODULE in their PYTHONCOMPILED variable will have access\nto these compiled functions. Note, however, that if they call the function\nwith a set of argument types that it hasn't previously been built for, the\nnew function will be stored in their default directory (or some other writable\ndirectory in the PYTHONCOMPILED path) because the user will not have write\naccess to the site-packages directory.\n

\nAn example of using the PYTHONCOMPILED path on bash follows:\n\n

\n    PYTHONCOMPILED=MODULE:/some/path;export PYTHONCOMPILED;\n    
\n\nIf you are using python21 on linux, and the module bob.py in site-packages\nhas a compiled function in it, then the catalog search order when calling that\nfunction for the first time in a python session would be:\n\n
\n    /usr/lib/python21/site-packages/linuxpython_compiled\n    /some/path/linuxpython_compiled\n    ~/.python21_compiled/linuxpython_compiled\n    
\n\nThe default location is always included in the search path.\n

\n \nNote: hmmm. see a possible problem here. I should probably make a sub-\ndirectory such as /usr/lib/python21/site-\npackages/python21_compiled/linuxpython_compiled so that library files compiled \nwith python21 are tried to link with python22 files in some strange scenarios. \nNeed to check this.\n\n\n

\nThe in-module cache (in weave.inline_tools reduces the overhead \nof calling inline functions by about a factor of 2. It can be reduced a little \nmore for type loop calls where the same function is called over and over again \nif the cache was a single value instead of a dictionary, but the benefit is \nvery small (less than 5%) and the utility is quite a bit less. So, we'll stick \nwith a dictionary as the cache.\n

\n\n\n

Blitz

\n Note: most of this section is lifted from old documentation. It should be\npretty accurate, but there may be a few discrepancies.\n

\nweave.blitz() compiles Numeric Python expressions for fast \nexecution. For most applications, compiled expressions should provide a \nfactor of 2-10 speed-up over Numeric arrays. Using compiled \nexpressions is meant to be as unobtrusive as possible and works much like \npythons exec statement. As an example, the following code fragment takes a 5 \npoint average of the 512x512 2d image, b, and stores it in array, a:\n\n

\n    from scipy import *  # or from Numeric import *\n    a = ones((512,512), Float64) \n    b = ones((512,512), Float64) \n    # ...do some stuff to fill in b...\n    # now average\n    a[1:-1,1:-1] =  (b[1:-1,1:-1] + b[2:,1:-1] + b[:-2,1:-1] \\\n                   + b[1:-1,2:] + b[1:-1,:-2]) / 5.\n    
\n \nTo compile the expression, convert the expression to a string by putting\nquotes around it and then use weave.blitz:\n\n
\n    import weave\n    expr = \"a[1:-1,1:-1] =  (b[1:-1,1:-1] + b[2:,1:-1] + b[:-2,1:-1]\" \\\n                          \"+ b[1:-1,2:] + b[1:-1,:-2]) / 5.\"\n    weave.blitz(expr)\n    
\n\nThe first time weave.blitz is run for a given expression and \nset of arguements, C++ code that accomplishes the exact same task as the Python \nexpression is generated and compiled to an extension module. This can take up \nto a couple of minutes depending on the complexity of the function. Subsequent \ncalls to the function are very fast. Futher, the generated module is saved \nbetween program executions so that the compilation is only done once for a \ngiven expression and associated set of array types. If the given expression\nis executed with a new set of array types, the code most be compiled again. This\ndoes not overwrite the previously compiled function -- both of them are saved and\navailable for exectution. \n

\nThe following table compares the run times for standard Numeric code and \ncompiled code for the 5 point averaging.\n

\n

\n\n\n\n\n\n
Method Run Time (seconds)
Standard Numeric 0.46349
blitz (1st time compiling) 78.95526
blitz (subsequent calls) 0.05843 (factor of 8 speedup)
\n
\n

\nThese numbers are for a 512x512 double precision image run on a 400 MHz Celeron \nprocessor under RedHat Linux 6.2.\n

\nBecause of the slow compile times, its probably most effective to develop \nalgorithms as you usually do using the capabilities of scipy or the Numeric \nmodule. Once the algorithm is perfected, put quotes around it and execute it \nusing weave.blitz. This provides the standard rapid \nprototyping strengths of Python and results in algorithms that run close to \nthat of hand coded C or Fortran.\n\n\n

Requirements

\n\nCurrently, the weave.blitz has only been tested under Linux \nwith gcc-2.95-3 and on Windows with Mingw32 (2.95.2). Its compiler \nrequirements are pretty heavy duty (see the \nblitz++ home page), so it won't \nwork with just any compiler. Particularly MSVC++ isn't up to snuff. A number \nof other compilers such as KAI++ will also work, but my suspicions are that gcc \nwill get the most use.\n\n\n

Limitations

\n
    \n
  1. \nCurrently, weave.blitz handles all standard mathematic \noperators except for the ** power operator. The built-in trigonmetric, log, \nfloor/ceil, and fabs functions might work (but haven't been tested). It also \nhandles all types of array indexing supported by the Numeric module. \n

    \nweave.blitz does not currently support operations that use \narray broadcasting, nor have any of the special purpose functions in Numeric \nsuch as take, compress, etc. been implemented. Note that there are no obvious \nreasons why most of this functionality cannot be added to scipy.weave, so it \nwill likely trickle into future versions. Using slice() objects \ndirectly instead of start:stop:step is also not supported.\n

  2. \n
  3. \nCurrently Python only works on expressions that include assignment such as\n \n
    \n    >>> result = b + c + d\n    
    \n\nThis means that the result array must exist before calling \nweave.blitz. Future versions will allow the following:\n\n
    \n    >>> result = weave.blitz_eval(\"b + c + d\")\n    
    \n
  4. \n
  5. \nweave.blitz works best when algorithms can be expressed in a \n\"vectorized\" form. Algorithms that have a large number of if/thens and other \nconditions are better hand written in C or Fortran. Further, the restrictions \nimposed by requiring vectorized expressions sometimes preclude the use of more \nefficient data structures or algorithms. For maximum speed in these cases, \nhand-coded C or Fortran code is the only way to go.\n
  6. \n
  7. \nweave.blitz can produce different results than Numeric in certain \nsituations. It can happen when the array receiving the results of a \ncalculation is also used during the calculation. The Numeric behavior is to \ncarry out the entire calculation on the right hand side of an equation and \nstore it in a temporary array. This temprorary array is assigned to the array \non the left hand side of the equation. blitz, on the other hand, does a \n\"running\" calculation of the array elements assigning values from the right hand\nside to the elements on the left hand side immediately after they are calculated.\nHere is an example, provided by Prabhu Ramachandran, where this happens:\n\n
    \n        # 4 point average.\n        >>> expr = \"u[1:-1, 1:-1] = (u[0:-2, 1:-1] + u[2:, 1:-1] + \"\\\n        ...                \"u[1:-1,0:-2] + u[1:-1, 2:])*0.25\"\n        >>> u = zeros((5, 5), 'd'); u[0,:] = 100\n        >>> exec (expr)\n        >>> u\n        array([[ 100.,  100.,  100.,  100.,  100.],\n               [   0.,   25.,   25.,   25.,    0.],\n               [   0.,    0.,    0.,    0.,    0.],\n               [   0.,    0.,    0.,    0.,    0.],\n               [   0.,    0.,    0.,    0.,    0.]])\n        \n        >>> u = zeros((5, 5), 'd'); u[0,:] = 100\n        >>> weave.blitz (expr)\n        >>> u\n        array([[ 100.  ,  100.       ,  100.       ,  100.       ,  100. ],\n               [   0.  ,   25.       ,   31.25     ,   32.8125   ,    0. ],\n               [   0.  ,    6.25     ,    9.375    ,   10.546875 ,    0. ],\n               [   0.  ,    1.5625   ,    2.734375 ,    3.3203125,    0. ],\n               [   0.  ,    0.       ,    0.       ,    0.       ,    0. ]])    \n        
    \n \n You can prevent this behavior by using a temporary array.\n \n
    \n        >>> u = zeros((5, 5), 'd'); u[0,:] = 100\n        >>> temp = zeros((4, 4), 'd');\n        >>> expr = \"temp = (u[0:-2, 1:-1] + u[2:, 1:-1] + \"\\\n        ...        \"u[1:-1,0:-2] + u[1:-1, 2:])*0.25;\"\\\n        ...        \"u[1:-1,1:-1] = temp\"\n        >>> weave.blitz (expr)\n        >>> u\n        array([[ 100.,  100.,  100.,  100.,  100.],\n               [   0.,   25.,   25.,   25.,    0.],\n               [   0.,    0.,    0.,    0.,    0.],\n               [   0.,    0.,    0.,    0.,    0.],\n               [   0.,    0.,    0.,    0.,    0.]])\n        
    \n \n
  8. \n
  9. \nOne other point deserves mention lest people be confused. \nweave.blitz is not a general purpose Python->C compiler. It \nonly works for expressions that contain Numeric arrays and/or \nPython scalar values. This focused scope concentrates effort on the \ncompuationally intensive regions of the program and sidesteps the difficult \nissues associated with a general purpose Python->C compiler.\n
  10. \n
\n\n\n

Numeric efficiency issues: What compilation buys you

\n\nSome might wonder why compiling Numeric expressions to C++ is beneficial since \noperations on Numeric array operations are already executed within C loops. \nThe problem is that anything other than the simplest expression are executed in \nless than optimal fashion. Consider the following Numeric expression:\n\n
\n    a = 1.2 * b + c * d\n    
\n \nWhen Numeric calculates the value for the 2d array, a, it does \nthe following steps:\n\n
\n    temp1 = 1.2 * b\n    temp2 = c * d\n    a = temp1 + temp2\n    
\n \nTwo things to note. Since c is an (perhaps large) array, a large \ntemporary array must be created to store the results of 1.2 * b. \nThe same is true for temp2. Allocation is slow. The second thing \nis that we have 3 loops executing, one to calculate temp1, one for \ntemp2 and one for adding them up. A C loop for the same problem \nmight look like:\n\n
\n    for(int i = 0; i < M; i++)\n        for(int j = 0; j < N; j++)\n            a[i,j] = 1.2 * b[i,j] + c[i,j] * d[i,j]\n    
\n \nHere, the 3 loops have been fused into a single loop and there is no longer\na need for a temporary array. This provides a significant speed improvement\nover the above example (write me and tell me what you get). \n

\nSo, converting Numeric expressions into C/C++ loops that fuse the loops and \neliminate temporary arrays can provide big gains. The goal then,is to convert \nNumeric expression to C/C++ loops, compile them in an extension module, and \nthen call the compiled extension function. The good news is that there is an \nobvious correspondence between the Numeric expression above and the C loop. The \nbad news is that Numeric is generally much more powerful than this simple \nexample illustrates and handling all possible indexing possibilities results in \nloops that are less than straight forward to write. (take a peak in Numeric for \nconfirmation). Luckily, there are several available tools that simplify the \nprocess.\n\n\n

The Tools

\n\nweave.blitz relies heavily on several remarkable tools. On the \nPython side, the main facilitators are Jermey Hylton's parser module and Jim \nHuginin's Numeric module. On the compiled language side, Todd Veldhuizen's \nblitz++ array library, written in C++ (shhhh. don't tell David Beazley), does \nthe heavy lifting. Don't assume that, because it's C++, it's much slower than C \nor Fortran. Blitz++ uses a jaw dropping array of template techniques \n(metaprogramming, template expression, etc) to convert innocent looking and \nreadable C++ expressions into to code that usually executes within a few \npercentage points of Fortran code for the same problem. This is good. \nUnfortunately all the template raz-ma-taz is very expensive to compile, so the \n200 line extension modules often take 2 or more minutes to compile. This isn't so \ngood. weave.blitz works to minimize this issue by remembering \nwhere compiled modules live and reusing them instead of re-compiling every time \na program is re-run.\n\n\n

Parser

\nTearing Numeric expressions apart, examining the pieces, and then rebuilding \nthem as C++ (blitz) expressions requires a parser of some sort. I can imagine \nsomeone attacking this problem with regular expressions, but it'd likely be \nugly and fragile. Amazingly, Python solves this problem for us. It actually \nexposes its parsing engine to the world through the parser module. \nThe following fragment creates an Abstract Syntax Tree (AST) object for the \nexpression and then converts to a (rather unpleasant looking) deeply nested list \nrepresentation of the tree. \n \n
\n    >>> import parser\n    >>> import scipy.weave.misc\n    >>> ast = parser.suite(\"a = b * c + d\")\n    >>> ast_list = ast.tolist()\n    >>> sym_list = scipy.weave.misc.translate_symbols(ast_list)\n    >>> pprint.pprint(sym_list)\n    ['file_input',\n     ['stmt',\n      ['simple_stmt',\n       ['small_stmt',\n        ['expr_stmt',\n         ['testlist',\n          ['test',\n           ['and_test',\n            ['not_test',\n             ['comparison',\n              ['expr',\n               ['xor_expr',\n                ['and_expr',\n                 ['shift_expr',\n                  ['arith_expr',\n                   ['term',\n                    ['factor', ['power', ['atom', ['NAME', 'a']]]]]]]]]]]]]]],\n         ['EQUAL', '='],\n         ['testlist',\n          ['test',\n           ['and_test',\n            ['not_test',\n             ['comparison',\n              ['expr',\n               ['xor_expr',\n                ['and_expr',\n                 ['shift_expr',\n                  ['arith_expr',\n                   ['term',\n                    ['factor', ['power', ['atom', ['NAME', 'b']]]],\n                    ['STAR', '*'],\n                    ['factor', ['power', ['atom', ['NAME', 'c']]]]],\n                   ['PLUS', '+'],\n                   ['term',\n                    ['factor', ['power', ['atom', ['NAME', 'd']]]]]]]]]]]]]]]]],\n       ['NEWLINE', '']]],\n     ['ENDMARKER', '']]\n    
\n\nDespite its looks, with some tools developed by Jermey H., its possible\nto search these trees for specific patterns (sub-trees), extract the \nsub-tree, manipulate them converting python specific code fragments\nto blitz code fragments, and then re-insert it in the parse tree. The parser\nmodule documentation has some details on how to do this. Traversing the \nnew blitzified tree, writing out the terminal symbols as you go, creates\nour new blitz++ expression string.\n\n \n

Blitz and Numeric

\nThe other nice discovery in the project is that the data structure used\nfor Numeric arrays and blitz arrays is nearly identical. Numeric stores\n\"strides\" as byte offsets and blitz stores them as element offsets, but\nother than that, they are the same. Further, most of the concept and\ncapabilities of the two libraries are remarkably similar. It is satisfying \nthat two completely different implementations solved the problem with \nsimilar basic architectures. It is also fortitous. The work involved in \nconverting Numeric expressions to blitz expressions was greatly diminished.\nAs an example, consider the code for slicing an array in Python with a\nstride:\n\n
\n    >>> a = b[0:4:2] + c\n    >>> a\n    [0,2,4]\n    
\n\n\nIn Blitz it is as follows:\n\n
\n    Array<2,int> b(10);\n    Array<2,int> c(3);\n    // ...\n    Array<2,int> a = b(Range(0,3,2)) + c;\n    
\n\n\nHere the range object works exactly like Python slice objects with the exception\nthat the top index (3) is inclusive where as Python's (4) is exclusive. Other \ndifferences include the type declaraions in C++ and parentheses instead of \nbrackets for indexing arrays. Currently, weave.blitz handles the \ninclusive/exclusive issue by subtracting one from upper indices during the\ntranslation. An alternative that is likely more robust/maintainable in the \nlong run, is to write a PyRange class that behaves like Python's range. \nThis is likely very easy.\n

\nThe stock blitz also doesn't handle negative indices in ranges. The current \nimplementation of the blitz() has a partial solution to this \nproblem. It calculates and index that starts with a '-' sign by subtracting it \nfrom the maximum index in the array so that:\n\n

\n                    upper index limit\n                        /-----\\\n    b[:-1] -> b(Range(0,Nb[0]-1-1))\n    
\n\nThis approach fails, however, when the top index is calculated from other \nvalues. In the following scenario, if i+j evaluates to a negative \nvalue, the compiled code will produce incorrect results and could even core-\ndump. Right now, all calculated indices are assumed to be positive.\n \n
\n    b[:i-j] -> b(Range(0,i+j))\n    
\n\nA solution is to calculate all indices up front using if/then to handle the\n+/- cases. This is a little work and results in more code, so it hasn't been\ndone. I'm holding out to see if blitz++ can be modified to handle negative\nindexing, but haven't looked into how much effort is involved yet. While it \nneeds fixin', I don't think there is a ton of code where this is an issue.\n

\nThe actual translation of the Python expressions to blitz expressions is \ncurrently a two part process. First, all x:y:z slicing expression are removed\nfrom the AST, converted to slice(x,y,z) and re-inserted into the tree. Any\nmath needed on these expressions (subtracting from the \nmaximum index, etc.) are also preformed here. _beg and _end are used as special\nvariables that are defined as blitz::fromBegin and blitz::toEnd.\n\n

\n    a[i+j:i+j+1,:] = b[2:3,:] \n    
\n\nbecomes a more verbose:\n \n
\n    a[slice(i+j,i+j+1),slice(_beg,_end)] = b[slice(2,3),slice(_beg,_end)]\n    
\n \nThe second part does a simple string search/replace to convert to a blitz \nexpression with the following translations:\n\n
\n    slice(_beg,_end) -> _all  # not strictly needed, but cuts down on code.\n    slice            -> blitz::Range\n    [                -> (\n    ]                -> )\n    _stp             -> 1\n    
\n\n_all is defined in the compiled function as \nblitz::Range.all(). These translations could of course happen \ndirectly in the syntax tree. But the string replacement is slightly easier. \nNote that name spaces are maintained in the C++ code to lessen the likelyhood \nof name clashes. Currently no effort is made to detect name clashes. A good \nrule of thumb is don't use values that start with '_' or 'py_' in compiled \nexpressions and you'll be fine.\n\n \n

Type definitions and coersion

\n\nSo far we've glossed over the dynamic vs. static typing issue between Python \nand C++. In Python, the type of value that a variable holds can change\nthrough the course of program execution. C/C++, on the other hand, forces you\nto declare the type of value a variables will hold prior at compile time.\nweave.blitz handles this issue by examining the types of the\nvariables in the expression being executed, and compiling a function for those\nexplicit types. For example:\n\n
\n    a = ones((5,5),Float32)\n    b = ones((5,5),Float32)\n    weave.blitz(\"a = a + b\")\n    
\n\nWhen compiling this expression to C++, weave.blitz sees that the\nvalues for a and b in the local scope have type Float32, or 'float'\non a 32 bit architecture. As a result, it compiles the function using \nthe float type (no attempt has been made to deal with 64 bit issues).\nIt also goes one step further. If all arrays have the same type, a templated\nversion of the function is made and instantiated for float, double, \ncomplex, and complex arrays. Note: This feature has been \nremoved from the current version of the code. Each version will be compiled\nseparately \n

\nWhat happens if you call a compiled function with array types that are \ndifferent than the ones for which it was originally compiled? No biggie, you'll \njust have to wait on it to compile a new version for your new types. This \ndoesn't overwrite the old functions, as they are still accessible. See the \ncatalog section in the inline() documentation to see how this is handled. \nSuffice to say, the mechanism is transparent to the user and behaves \nlike dynamic typing with the occasional wait for compiling newly typed \nfunctions.\n

\nWhen working with combined scalar/array operations, the type of the array is \nalways used. This is similar to the savespace flag that was recently \nadded to Numeric. This prevents issues with the following expression perhaps \nunexpectedly being calculated at a higher (more expensive) precision that can \noccur in Python:\n\n

\n    >>> a = array((1,2,3),typecode = Float32)\n    >>> b = a * 2.1 # results in b being a Float64 array.\n    
\n \nIn this example, \n\n
\n    >>> a = ones((5,5),Float32)\n    >>> b = ones((5,5),Float32)\n    >>> weave.blitz(\"b = a * 2.1\")\n    
\n \nthe 2.1 is cast down to a float before carrying out \nthe operation. If you really want to force the calculation to be a \ndouble, define a and b as \ndouble arrays.\n

\nOne other point of note. Currently, you must include both the right hand side \nand left hand side (assignment side) of your equation in the compiled \nexpression. Also, the array being assigned to must be created prior to calling \nweave.blitz. I'm pretty sure this is easily changed so that a \ncompiled_eval expression can be defined, but no effort has been made to \nallocate new arrays (and decern their type) on the fly.\n\n \n

Cataloging Compiled Functions

\n\nSee the Cataloging functions section in the \nweave.inline() documentation.\n\n \n

Checking Array Sizes

\n\nSurprisingly, one of the big initial problems with compiled code was making\nsure all the arrays in an operation were of compatible type. The following\ncase is trivially easy:\n\n
\n    a = b + c\n    
\n \nIt only requires that arrays a, b, and c \nhave the same shape. However, expressions like:\n\n
\n    a[i+j:i+j+1,:] = b[2:3,:] + c\n    
\n\nare not so trivial. Since slicing is involved, the size of the slices, not the \ninput arrays must be checked. Broadcasting complicates things further because \narrays and slices with different dimensions and shapes may be compatible for \nmath operations (broadcasting isn't yet supported by \nweave.blitz). Reductions have a similar effect as their \nresults are different shapes than their input operand. The binary operators in \nNumeric compare the shapes of their two operands just before they operate on \nthem. This is possible because Numeric treats each operation independently. \nThe intermediate (temporary) arrays created during sub-operations in an \nexpression are tested for the correct shape before they are combined by another \noperation. Because weave.blitz fuses all operations into a \nsingle loop, this isn't possible. The shape comparisons must be done and \nguaranteed compatible before evaluating the expression.\n

\nThe solution chosen converts input arrays to \"dummy arrays\" that only represent \nthe dimensions of the arrays, not the data. Binary operations on dummy arrays \ncheck that input array sizes are comptible and return a dummy array with the \nsize correct size. Evaluating an expression of dummy arrays traces the \nchanging array sizes through all operations and fails if incompatible array \nsizes are ever found. \n

\nThe machinery for this is housed in weave.size_check. It \nbasically involves writing a new class (dummy array) and overloading it math \noperators to calculate the new sizes correctly. All the code is in Python and \nthere is a fair amount of logic (mainly to handle indexing and slicing) so the \noperation does impose some overhead. For large arrays (ie. 50x50x50), the \noverhead is negligible compared to evaluating the actual expression. For small \narrays (ie. 16x16), the overhead imposed for checking the shapes with this \nmethod can cause the weave.blitz to be slower than evaluating \nthe expression in Python. \n

\nWhat can be done to reduce the overhead? (1) The size checking code could be \nmoved into C. This would likely remove most of the overhead penalty compared \nto Numeric (although there is also some calling overhead), but no effort has \nbeen made to do this. (2) You can also call weave.blitz with\ncheck_size=0 and the size checking isn't done. However, if the \nsizes aren't compatible, it can cause a core-dump. So, foregoing size_checking\nisn't advisable until your code is well debugged.\n\n \n

Creating the Extension Module

\n\nweave.blitz uses the same machinery as \nweave.inline to build the extension module. The only difference\nis the code included in the function is automatically generated from the\nNumeric array expression instead of supplied by the user.\n\n\n

Extension Modules

\nweave.inline and weave.blitz are high level tools\nthat generate extension modules automatically. Under the covers, they use several\nclasses from weave.ext_tools to help generate the extension module.\nThe main two classes are ext_module and ext_function (I'd\nlike to add ext_class and ext_method also). These classes\nsimplify the process of generating extension modules by handling most of the \"boiler\nplate\" code automatically.\n\n\nNote: inline actually sub-classes weave.ext_tools.ext_function \nto generate slightly different code than the standard ext_function.\nThe main difference is that the standard class converts function arguments to\nC types, while inline always has two arguments, the local and global dicts, and\nthe grabs the variables that need to be convereted to C from these.\n\n\n\n

A Simple Example

\nThe following simple example demonstrates how to build an extension module within\na Python function:\n\n
\n    # examples/increment_example.py\n    from weave import ext_tools\n    \n    def build_increment_ext():\n        \"\"\" Build a simple extension with functions that increment numbers.\n            The extension will be built in the local directory.\n        \"\"\"        \n        mod = ext_tools.ext_module('increment_ext')\n    \n        a = 1 # effectively a type declaration for 'a' in the \n              # following functions.\n    \n        ext_code = \"return_val = Py::new_reference_to(Py::Int(a+1));\"    \n        func = ext_tools.ext_function('increment',ext_code,['a'])\n        mod.add_function(func)\n        \n        ext_code = \"return_val = Py::new_reference_to(Py::Int(a+2));\"    \n        func = ext_tools.ext_function('increment_by_2',ext_code,['a'])\n        mod.add_function(func)\n                \n        mod.compile()\n    
\n\n\nThe function build_increment_ext() creates an extension module \nnamed increment_ext and compiles it to a shared library (.so or \n.pyd) that can be loaded into Python.. increment_ext contains two \nfunctions, increment and increment_by_2. \n\nThe first line of build_increment_ext(),\n\n
\n        mod = ext_tools.ext_module('increment_ext') \n    
\n\ncreates an ext_module instance that is ready to have \next_function instances added to it. ext_function \ninstances are created much with a calling convention similar to \nweave.inline(). The most common call includes a C/C++ code \nsnippet and a list of the arguments for the function. The following\n\n
\n        ext_code = \"return_val = Py::new_reference_to(Py::Int(a+1));\"    \n        func = ext_tools.ext_function('increment',ext_code,['a'])\n    
\n \ncreates a C/C++ extension function that is equivalent to the following Python\nfunction:\n\n
\n        def increment(a):\n            return a + 1\n    
\n\nA second method is also added to the module and then,\n\n
\n        mod.compile()\n    
\n\nis called to build the extension module. By default, the module is created\nin the current working directory.\n\nThis example is available in the examples/increment_example.py file\nfound in the weave directory. At the bottom of the file in the\nmodule's \"main\" program, an attempt to import increment_ext without\nbuilding it is made. If this fails (the module doesn't exist in the PYTHONPATH), \nthe module is built by calling build_increment_ext(). This approach\nonly takes the time consuming ( a few seconds for this example) process of building\nthe module if it hasn't been built before.\n\n
\n    if __name__ == \"__main__\":\n        try:\n            import increment_ext\n        except ImportError:\n            build_increment_ext()\n            import increment_ext\n        a = 1\n        print 'a, a+1:', a, increment_ext.increment(a)\n        print 'a, a+2:', a, increment_ext.increment_by_2(a)           \n    
\n\n\nNote: If we were willing to always pay the penalty of building the C++ code for \na module, we could store the md5 checksum of the C++ code along with some \ninformation about the compiler, platform, etc. Then, \next_module.compile() could try importing the module before it actually\ncompiles it, check the md5 checksum and other meta-data in the imported module\nwith the meta-data of the code it just produced and only compile the code if\nthe module didn't exist or the meta-data didn't match. This would reduce the\nabove code to:\n\n
\n    if __name__ == \"__main__\":\n        build_increment_ext()\n\n        a = 1\n        print 'a, a+1:', a, increment_ext.increment(a)\n        print 'a, a+2:', a, increment_ext.increment_by_2(a)           \n    
\n\nNote: There would always be the overhead of building the C++ code, but it would only actually compile the code once. You pay a little in overhead and get cleaner\n\"import\" code. Needs some thought.\n\n

\n\nIf you run increment_example.py from the command line, you get\nthe following:\n\n

\n    [eric@n0]$ python increment_example.py\n    a, a+1: 1 2\n    a, a+2: 1 3\n    
\n\nIf the module didn't exist before it was run, the module is created. If it did\nexist, it is just imported and used.\n\n\n

Fibonacci Example

\nexamples/fibonacci.py provides a little more complex example of \nhow to use ext_tools. Fibonacci numbers are a series of numbers \nwhere each number in the series is the sum of the previous two: 1, 1, 2, 3, 5, \n8, etc. Here, the first two numbers in the series are taken to be 1. One \napproach to calculating Fibonacci numbers uses recursive function calls. In \nPython, it might be written as:\n\n
\n    def fib(a):\n        if a <= 2:\n            return 1\n        else:\n            return fib(a-2) + fib(a-1)\n    
\n\nIn C, the same function would look something like this:\n\n
\n     int fib(int a)\n     {                   \n         if(a <= 2)\n             return 1;\n         else\n             return fib(a-2) + fib(a-1);  \n     }                      \n    
\n\nRecursion is much faster in C than in Python, so it would be beneficial\nto use the C version for fibonacci number calculations instead of the\nPython version. We need an extension function that calls this C function\nto do this. This is possible by including the above code snippet as \n\"support code\" and then calling it from the extension function. Support \ncode snippets (usually structure definitions, helper functions and the like)\nare inserted into the extension module C/C++ file before the extension\nfunction code. Here is how to build the C version of the fibonacci number\ngenerator:\n\n
\ndef build_fibonacci():\n    \"\"\" Builds an extension module with fibonacci calculators.\n    \"\"\"\n    mod = ext_tools.ext_module('fibonacci_ext')\n    a = 1 # this is effectively a type declaration\n    \n    # recursive fibonacci in C \n    fib_code = \"\"\"\n                   int fib1(int a)\n                   {                   \n                       if(a <= 2)\n                           return 1;\n                       else\n                           return fib1(a-2) + fib1(a-1);  \n                   }                         \n               \"\"\"\n    ext_code = \"\"\"\n                   int val = fib1(a);\n                   return_val = Py::new_reference_to(Py::Int(val));\n               \"\"\"    \n    fib = ext_tools.ext_function('fib',ext_code,['a'])\n    fib.customize.add_support_code(fib_code)\n    mod.add_function(fib)\n\n    mod.compile()\n\n    
\n\nXXX More about custom_info, and what xxx_info instances are good for.\n\n

\n\nNote: recursion is not the fastest way to calculate fibonacci numbers, but this \napproach serves nicely for this example.\n\n

\n\n

Customizing Type Conversions -- Type Factories

\nnot written\n\n

Things I wish weave did

\n\nIt is possible to get name clashes if you uses a variable name that is already defined\nin a header automatically included (such as stdio.h) For instance, if you\ntry to pass in a variable named stdout, you'll get a cryptic error report\ndue to the fact that stdio.h also defines the name. weave\nshould probably try and handle this in some way.\n\nOther things...", + "source_code_before": "\n

Weave Documentation

\n

\nBy Eric Jones eric@enthought.com\n

\n

Outline

\n
\n
Introduction\n
Requirements\n
Installation\n
Testing\n
Benchmarks\n
Inline\n
\n
More with printf\n
\n More examples\n
\n
Binary search\n
Dictionary sort\n
Numeric -- cast/copy/transpose\n
wxPython
\n
\n
Keyword options\n
Returning values\n
\n
\n The issue with locals()
\n
\n
A quick look at the code\n
\n Technical Details\n
\n
Converting Types\n
\n
\n Numeric Argument Conversion\n
\n String, List, Tuple, and Dictionary Conversion\n
File Conversion \n
\n Callable, Instance, and Module Conversion \n
Customizing Conversions\n
\n
Compiling Code\n
\"Cataloging\" functions\n
\n
Function Storage\n
The PYTHONCOMPILED evnironment variable
\n
\n
\n
\n
\n
\n
Blitz\n
\n
Requirements\n
Limitations\n
Numeric Efficiency Issues\n
The Tools \n
\n
Parser\n
Blitz and Numeric\n
\n
Type defintions and coersion\n
Cataloging Compiled Functions\n
Checking Array Sizes\n
Creating the Extension Module\n
\n
Extension Modules\n
\n
A Simple Example\n
Fibonacci Example\n
\n
Customizing Type Conversions -- Type Factories (not written)\n
\n
Type Specifications\n
Type Information\n
The Conversion Process \n
\n
\n\n

Introduction

\n\n

\nThe weave package provides tools for including C/C++ code within\nin Python code. This offers both another level of optimization to those who need \nit, and an easy way to modify and extend any supported extension libraries such \nas wxPython and hopefully VTK soon. Inlining C/C++ code within Python generally\nresults in speed ups of 1.5x to 30x speed-up over algorithms written in pure\nPython (However, it is also possible to slow things down...). Generally \nalgorithms that require a large number of calls to the Python API don't benefit\nas much from the conversion to C/C++ as algorithms that have inner loops \ncompletely convertable to C.\n

\nThere are three basic ways to use weave. The \nweave.inline() function executes C code directly within Python, \nand weave.blitz() translates Python Numeric expressions to C++ \nfor fast execution. blitz() was the original reason \nweave was built. For those interested in building extension\nlibraries, the ext_tools module provides classes for building \nextension modules within Python. \n

\nMost of weave's functionality should work on Windows and Unix, \nalthough some of its functionality requires gcc or a similarly \nmodern C++ compiler that handles templates well. Up to now, most testing has \nbeen done on Windows 2000 with Microsoft's C++ compiler (MSVC) and with gcc \n(mingw32 2.95.2 and 2.95.3-6). All tests also pass on Linux (RH 7.1 \nwith gcc 2.96), and I've had reports that it works on Debian also (thanks \nPearu).\n

\nThe inline and blitz provide new functionality to \nPython (although I've recently learned about the PyInline project which may offer \nsimilar functionality to inline). On the other hand, tools for \nbuilding Python extension modules already exists (SWIG, SIP, pycpp, CXX, and \nothers). As of yet, I'm not sure where weave fits in this \nspectrum. It is closest in flavor to CXX in that it makes creating new C/C++ \nextension modules pretty easy. However, if you're wrapping a gaggle of legacy \nfunctions or classes, SWIG and friends are definitely the better choice. \nweave is set up so that you can customize how Python types are \nconverted to C types in weave. This is great for \ninline(), but, for wrapping legacy code, it is more flexible to \nspecify things the other way around -- that is how C types map to Python types. \nThis weave does not do. I guess it would be possible to build \nsuch a tool on top of weave, but with good tools like SWIG around, \nI'm not sure the effort produces any new capabilities. Things like function \noverloading are probably easily implemented in weave and it might \nbe easier to mix Python/C code in function calls, but nothing beyond this comes \nto mind. So, if you're developing new extension modules or optimizing Python \nfunctions in C, weave.ext_tools() might be the tool \nfor you. If you're wrapping legacy code, stick with SWIG.\n

\nThe next several sections give the basics of how to use weave.\nWe'll discuss what's happening under the covers in more detail later \non. Serious users will need to at least look at the type conversion section to \nunderstand how Python variables map to C/C++ types and how to customize this \nbehavior. One other note. If you don't know C or C++ then these docs are \nprobably of very little help to you. Further, it'd be helpful if you know \nsomething about writing Python extensions. weave does quite a \nbit for you, but for anything complex, you'll need to do some conversions, \nreference counting, etc.\n

\n\nNote: weave is actually part of the SciPy package. However, it works fine as a \nstandalone package. The examples here are given as if it is used as a stand \nalone package. If you are using from within scipy, you can use from \nscipy import weave and the examples will work identically.\n\n\n

Requirements

\n
    \n
  • Python\n

    \n I use 2.1.1. Probably 2.0 or higher should work.\n

    \n

  • \n \n
  • C++ compiler\n

    \n weave uses distutils to actually build \n extension modules, so it uses whatever compiler was originally used to \n build Python. weave itself requires a C++ compiler. If \n you used a C++ compiler to build Python, your probably fine.\n

    \n On Unix gcc is the preferred choice because I've done a little \n testing with it. All testing has been done with gcc, but I expect the \n majority of compilers should work for inline and \n ext_tools. The one issue I'm not sure about is that I've \n hard coded things so that compilations are linked with the \n stdc++ library. Is this standard across \n Unix compilers, or is this a gcc-ism?\n

    \n For blitz(), you'll need a reasonably recent version of \n gcc. 2.95.2 works on windows and 2.96 looks fine on Linux. Other \n versions are likely to work. Its likely that KAI's C++ compiler and \n maybe some others will work, but I haven't tried. My advice is to use \n gcc for now unless your willing to tinker with the code some.\n

    \n On Windows, either MSVC or gcc (www.mingw.org\" > mingw32) should work. Again, \n you'll need gcc for blitz() as the\n MSVC compiler doesn't handle templates well.\n

    \n I have not tried Cygwin, so please report success if it works for you.\n

    \n

  • \n\n
  • Numeric (optional)\n

    \n The python Numeric module from here. is required for \n blitz() to work. Be sure and get NumPy, not NumArray\n which is the \"next generation\" implementation. This is not\n required for using inline() or ext_tools.\n

    \n

  • \n
  • scipy_distutils and scipy_test (packaged with weave)\n

    \n These two modules are packaged with weave in both\n the windows installer and the source distributions. If you are using\n CVS, however, you'll need to download these separately (also available\n through CVS at SciPy).\n

    \n

  • \n
\n

\n\n\n

Installation

\n

\nThere are currently two ways to get weave. Fist, \nweave is part of SciPy and installed automatically (as a sub-\npackage) whenever SciPy is installed (although the latest version isn't in \nSciPy yet, so use this one for now). Second, since weave is \nuseful outside of the scientific community, it has been setup so that it can be\nused as a stand-alone module. \n\n

\nThe stand-alone version can be downloaded from here. Unix users should grab the \ntar ball (.tgz file) and install it using the following commands.\n\n

\n    tar -xzvf weave-0.2.tar.gz\n    cd weave-0.2\n    python setup.py install\n    
\n\nThis will also install two other packages, scipy_distutils and \nscipy_test. The first is needed by the setup process itself and \nboth are used in the unit-testing process. Numeric is required if you want to \nuse blitz(), but isn't necessary for inline() or \next_tools\n

\nFor Windows users, it's even easier. You can download the click-install .exe \nfile and run it for automatic installation. There is also a .zip file of the\nsource for those interested. It also includes a setup.py file to simplify\ninstallation. \n

\nIf you're using the CVS version, you'll need to install \nscipy_distutils and scipy_test packages (also \navailable from CVS) on your own.\n

\n \nNote: The dependency issue here is a little sticky. I hate to make people \ndownload more than one file (and so I haven't), but distutils doesn't have a \nway to do conditional installation -- at least that I know about. This can \nlead to undesired clobbering of the scipy_test and scipy_distutils modules. \nWhat to do, what to do... Right now it is a very minor issue.\n\n

\n\n

Testing

\nOnce weave is installed, fire up python and run its unit tests.\n\n
\n    >>> import weave\n    >>> weave.test()\n    runs long time... spews tons of output and a few warnings\n    .\n    .\n    .\n    ..............................................................\n    ................................................................\n    ..................................................\n    ----------------------------------------------------------------------\n    Ran 184 tests in 158.418s\n\n    OK\n    \n    >>> \n    
\n\nThis takes a loooong time. On windows, it is usually several minutes. On Unix \nwith remote file systems, I've had it take 15 or so minutes. In the end, it \nshould run about 180 tests and spew some speed results along the way. If you \nget errors, they'll be reported at the end of the output. Please let me know\nwhat if this occurs.\n\nIf you don't have Numeric installed, you'll get some module import errors \nduring the test setup phase for modules that are Numeric specific (blitz_spec, \nblitz_tools, size_check, standard_array_spec, ast_tools), but all test should\npass (about 100 and they should complete in several minutes).\n

\nIf you only want to test a single module of the package, you can do this by\nrunning test() for that specific module.\n\n

\n    >>> import weave.scalar_spec\n    >>> weave.scalar_spec.test()\n    .......\n    ----------------------------------------------------------------------\n    Ran 7 tests in 23.284s\n    
\n\nTesting Notes:\n
    \n
  • \n Windows 1\n

    \n I've had some test fail on windows machines where I have msvc, gcc-2.95.2 \n (in c:\\gcc-2.95.2), and gcc-2.95.3-6 (in c:\\gcc) all installed. My \n environment has c:\\gcc in the path and does not have c:\\gcc-2.95.2 in the \n path. The test process runs very smoothly until the end where several test \n using gcc fail with cpp0 not found by g++. If I check os.system('gcc -v') \n before running tests, I get gcc-2.95.3-6. If I check after running tests \n (and after failure), I get gcc-2.95.2. ??huh??. The os.environ['PATH'] \n still has c:\\gcc first in it and is not corrupted (msvc/distutils messes \n with the environment variables, so we have to undo its work in some \n places). If anyone else sees this, let me know - - it may just be an quirk \n on my machine (unlikely). Testing with the gcc- 2.95.2 installation always \n works.\n

    \n

  • \n
  • \n Windows 2\n

    \n If you run the tests from PythonWin or some other GUI tool, you'll get a\n ton of DOS windows popping up periodically as weave spawns\n the compiler multiple times. Very annoying. Anyone know how to fix this?\n

    \n

  • \n
  • \n wxPython\n

    \n wxPython tests are not enabled by default because importing wxPython on a \n Unix machine without access to a X-term will cause the program to exit. \n Anyone know of a safe way to detect whether wxPython can be imported and \n whether a display exists on a machine? \n

    \n

  • \n
    \n\n

    \n

\n\n\n

Benchmarks

\nThis section has a few benchmarks -- thats all people want to see anyway right? \nThese are mostly taken from running files in the weave/example \ndirectory and also from the test scripts. Without more information about what \nthe test actually do, their value is limited. Still, their here for the \ncurious. Look at the example scripts for more specifics about what problem was \nactually solved by each run. These examples are run under windows 2000 using \nMicrosoft Visual C++ and python2.1 on a 850 MHz PIII laptop with 320 MB of RAM.\nSpeed up is the improvement (degredation) factor of weave compared to \nconventional Python functions. The blitz() comparisons are shown\ncompared to Numeric.\n

\n

\n\n\n \n \n \n \n \n \n \n \n\n \n \n \n \n \n \n
\n

inline and ext_tools

Algorithm

Speed up

binary search   1.50
fibonacci (recursive)  82.10
fibonacci (loop)   9.17
return None   0.14
map   1.20
dictionary sort   2.54
vector quantization  37.40
\n

blitz -- double precision

Algorithm

Speed up

a = b + c 512x512   3.05
a = b + c + d 512x512   4.59
5 pt avg. filter, 2D Image 512x512   9.01
Electromagnetics (FDTD) 100x100x100   8.61
\n
\n

\n\nThe benchmarks shown blitz in the best possible light. Numeric \n(at least on my machine) is significantly worse for double precision than it is \nfor single precision calculations. If your interested in single precision \nresults, you can pretty much divide the double precision speed up by 3 and you'll\nbe close.\n\n\n

Inline

\n

\ninline() compiles and executes C/C++ code on the fly. Variables \nin the local and global Python scope are also available in the C/C++ code. \nValues are passed to the C/C++ code by assignment much like variables \nare passed into a standard Python function. Values are returned from the C/C++ \ncode through a special argument called return_val. Also, the contents of \nmutable objects can be changed within the C/C++ code and the changes remain \nafter the C code exits and returns to Python. (more on this later)\n

\nHere's a trivial printf example using inline():\n\n

\n    >>> import weave    \n    >>> a  = 1\n    >>> weave.inline('printf(\"%d\\\\n\",a);',['a'])\n    1\n    
\n

\nIn this, its most basic form, inline(c_code, var_list) requires two \narguments. c_code is a string of valid C/C++ code. \nvar_list is a list of variable names that are passed from \nPython into C/C++. Here we have a simple printf statement that \nwrites the Python variable a to the screen. The first time you run \nthis, there will be a pause while the code is written to a .cpp file, compiled \ninto an extension module, loaded into Python, cataloged for future use, and \nexecuted. On windows (850 MHz PIII), this takes about 1.5 seconds when using \nMicrosoft's C++ compiler (MSVC) and 6-12 seconds using gcc (mingw32 2.95.2). \nAll subsequent executions of the code will happen very quickly because the code \nonly needs to be compiled once. If you kill and restart the interpreter and then \nexecute the same code fragment again, there will be a much shorter delay in the \nfractions of seconds range. This is because weave stores a \ncatalog of all previously compiled functions in an on disk cache. When it sees \na string that has been compiled, it loads the already compiled module and \nexecutes the appropriate function. \n

\n\nNote: If you try the printf example in a GUI shell such as IDLE, \nPythonWin, PyShell, etc., you're unlikely to see the output. This is because the \nC code is writing to stdout, instead of to the GUI window. This doesn't mean \nthat inline doesn't work in these environments -- it only means that standard \nout in C is not the same as the standard out for Python in these cases. Non \ninput/output functions will work as expected.\n\n

\nAlthough effort has been made to reduce the overhead associated with calling \ninline, it is still less efficient for simple code snippets than using \nequivalent Python code. The simple printf example is actually \nslower by 30% or so than using Python print statement. And, it is \nnot difficult to create code fragments that are 8-10 times slower using inline \nthan equivalent Python. However, for more complicated algorithms, \nthe speed up can be worth while -- anywhwere from 1.5- 30 times faster. \nAlgorithms that have to manipulate Python objects (sorting a list) usually only \nsee a factor of 2 or so improvement. Algorithms that are highly computational \nor manipulate Numeric arrays can see much larger improvements. The \nexamples/vq.py file shows a factor of 30 or more improvement on the vector \nquantization algorithm that is used heavily in information theory and \nclassification problems.\n

\n\n\n

More with printf

\n

\nMSVC users will actually see a bit of compiler output that distutils does not\nsupress the first time the code executes:\n\n

    \n    >>> weave.inline(r'printf(\"%d\\n\",a);',['a'])\n    sc_e013937dbc8c647ac62438874e5795131.cpp\n       Creating library C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\n       \\Release\\sc_e013937dbc8c647ac62438874e5795131.lib and object C:\\DOCUME\n       ~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\sc_e013937dbc8c64\n       7ac62438874e5795131.exp\n    1\n    
\n

\nNothing bad is happening, its just a bit annoying. Anyone know how to \nturn this off? \n

\nThis example also demonstrates using 'raw strings'. The r \npreceeding the code string in the last example denotes that this is a 'raw \nstring'. In raw strings, the backslash character is not interpreted as an \nescape character, and so it isn't necessary to use a double backslash to \nindicate that the '\\n' is meant to be interpreted in the C printf \nstatement instead of by Python. If your C code contains a lot\nof strings and control characters, raw strings might make things easier.\nMost of the time, however, standard strings work just as well.\n\n

\nThe printf statement in these examples is formatted to print \nout integers. What happens if a is a string? inline\nwill happily, compile a new version of the code to accept strings as input,\nand execute the code. The result?\n\n

    \n    >>> a = 'string'\n    >>> weave.inline(r'printf(\"%d\\n\",a);',['a'])\n    32956972\n    
\n

\nIn this case, the result is non-sensical, but also non-fatal. In other \nsituations, it might produce a compile time error because a is \nrequired to be an integer at some point in the code, or it could produce a \nsegmentation fault. Its possible to protect against passing \ninline arguments of the wrong data type by using asserts in \nPython.\n\n

    \n    >>> a = 'string'\n    >>> def protected_printf(a):    \n    ...     assert(type(a) == type(1))\n    ...     weave.inline(r'printf(\"%d\\n\",a);',['a'])\n    >>> protected_printf(1)\n     1\n    >>> protected_printf('string')\n    AssertError...\n    
\n\n

\nFor printing strings, the format statement needs to be changed. Also, weave\ndoesn't convert strings to char*. Instead it uses CXX Py::String type, so \nyou have to do a little more work. Here we convert it to a C++ std::string\nand then ask cor the char* version.\n\n

    \n    >>> a = 'string'    \n    >>> weave.inline(r'printf(\"%s\\n\",std::string(a).c_str());',['a'])\n    string\n    
\n

\n \nThis is a little convoluted. Perhaps strings should convert to std::string\nobjects instead of CXX objects. Or maybe to char*.\n\n\n

\nAs in this case, C/C++ code fragments often have to change to accept different \ntypes. For the given printing task, however, C++ streams provide a way of a \nsingle statement that works for integers and strings. By default, the stream \nobjects live in the std (standard) namespace and thus require the use of \nstd::.\n\n

    \n    >>> weave.inline('std::cout << a << std::endl;',['a'])\n    1    \n    >>> a = 'string'\n    >>> weave.inline('std::cout << a << std::endl;',['a'])\n    string\n    
\n \n

\nExamples using printf and cout are included in \nexamples/print_example.py.\n\n\n

More examples

\n\nThis section shows several more advanced uses of inline. It \nincludes a few algorithms from the Python Cookbook \nthat have been re-written in inline C to improve speed as well as a couple \nexamples using Numeric and wxPython.\n\n\n

Binary search

\nLets look at the example of searching a sorted list of integers for a value. \nFor inspiration, we'll use Kalle Svensson's \nbinary_search() algorithm from the Python Cookbook. His recipe follows:\n\n
\n    def binary_search(seq, t):\n        min = 0; max = len(seq) - 1\n        while 1:\n            if max < min:\n                return -1\n            m = (min  + max)  / 2\n            if seq[m] < t: \n                min = m  + 1 \n            elif seq[m] > t: \n                max = m  - 1 \n            else:\n                return m    \n    
\n\nThis Python version works for arbitrary Python data types. The C version below is \nspecialized to handle integer values. There is a little type checking done in \nPython to assure that we're working with the correct data types before heading \ninto C. The variables seq and t don't need to be \ndeclared beacuse weave handles converting and declaring them in \nthe C code. All other temporary variables such as min, max, etc. \nmust be declared -- it is C after all. Here's the new mixed Python/C function:\n\n
    \n    def c_int_binary_search(seq,t):\n        # do a little type checking in Python\n        assert(type(t) == type(1))\n        assert(type(seq) == type([]))\n        \n        # now the C code\n        code = \"\"\"\n               #line 29 \"binary_search.py\"\n               int val, m, min = 0;  \n               int max = seq.length() - 1;\n               PyObject *py_val; \n               for(;;)\n               {\n                   if (max < min  ) \n                   { \n                       return_val =  Py::new_reference_to(Py::Int(-1)); \n                       break;\n                   } \n                   m =  (min + max) /2;\n                   val =    py_to_int(PyList_GetItem(seq.ptr(),m),\"val\"); \n                   if (val  < t) \n                       min = m  + 1;\n                   else if (val >  t)\n                       max = m - 1;\n                   else\n                   {\n                       return_val = Py::new_reference_to(Py::Int(m));\n                       break;\n                   }\n               }\n               \"\"\"\n        return inline(code,['seq','t'])\n    
\n

\nWe have two variables seq and t passed in. \nt is guaranteed (by the assert) to be an integer. \nPython integers are converted to C int types in the transition from Python to \nC. seq is a Python list. By default, it is translated to a CXX \nlist object. Full documentation for the CXX library can be found at its website. The basics are that the CXX \nprovides C++ class equivalents for Python objects that simplify, or at \nleast object orientify, working with Python objects in C/C++. For example, \nseq.length() returns the length of the list. A little more about\nCXX and its class methods, etc. is in the ** type conversions ** section.\n

\n\nNote: CXX uses templates and therefore may be a little less portable than \nanother alternative by Gordan McMillan called SCXX which was inspired by\nCXX. It doesn't use templates so it should compile faster and be more portable.\nSCXX has a few less features, but it appears to me that it would mesh with\nthe needs of weave quite well. Hopefully xxx_spec files will be written\nfor SCXX in the future, and we'll be able to compare on a more empirical\nbasis. Both sets of spec files will probably stick around, it just a question\nof which becomes the default.\n\n

\nMost of the algorithm above looks similar in C to the original Python code. \nThere are two main differences. The first is the setting of \nreturn_val instead of directly returning from the C code with a \nreturn statement. return_val is an automatically \ndefined variable of type PyObject* that is returned from the C \ncode back to Python. You'll have to handle reference counting issues when \nsetting this variable. In this example, CXX classes and functions handle the \ndirty work. All CXX functions and classes live in the namespace \nPy::. The following code converts the integer m to a \nCXX Int() object and then to a PyObject* with an \nincremented reference count using Py::new_reference_to().\n\n

   \n    return_val = Py::new_reference_to(Py::Int(m));\n    
\n

\nThe second big differences shows up in the retrieval of integer values from the \nPython list. The simple Python seq[i] call balloons into a C \nPython API call to grab the value out of the list and then a separate call to \npy_to_int() that converts the PyObject* to an integer. \npy_to_int() includes both a NULL cheack and a \nPyInt_Check() call as well as the conversion call. If either of \nthe checks fail, an exception is raised. The entire C++ code block is executed \nwith in a try/catch block that handles exceptions much like Python \ndoes. This removes the need for most error checking code.\n

\nIt is worth note that CXX lists do have indexing operators that result \nin code that looks much like Python. However, the overhead in using them \nappears to be relatively high, so the standard Python API was used on the \nseq.ptr() which is the underlying PyObject* of the \nList object.\n

\nThe #line directive that is the first line of the C code \nblock isn't necessary, but it's nice for debugging. If the compilation fails \nbecause of the syntax error in the code, the error will be reported as an error \nin the Python file \"binary_search.py\" with an offset from the given line number \n(29 here).\n

\nSo what was all our effort worth in terms of efficiency? Well not a lot in \nthis case. The examples/binary_search.py file runs both Python and C versions \nof the functions As well as using the standard bisect module. If \nwe run it on a 1 million element list and run the search 3000 times (for 0-\n2999), here are the results we get:\n\n

   \n    C:\\home\\ej\\wrk\\scipy\\weave\\examples> python binary_search.py\n    Binary search for 3000 items in 1000000 length list of integers:\n     speed in python: 0.159999966621\n     speed of bisect: 0.121000051498\n     speed up: 1.32\n     speed in c: 0.110000014305\n     speed up: 1.45\n     speed in c(no asserts): 0.0900000333786\n     speed up: 1.78\n    
\n

\nSo, we get roughly a 50-75% improvement depending on whether we use the Python \nasserts in our C version. If we move down to searching a 10000 element list, \nthe advantage evaporates. Even smaller lists might result in the Python \nversion being faster. I'd like to say that moving to Numeric lists (and \ngetting rid of the GetItem() call) offers a substantial speed up, but my \npreliminary efforts didn't produce one. I think the log(N) algorithm is to \nblame. Because the algorithm is nice, there just isn't much time spent \ncomputing things, so moving to C isn't that big of a win. If there are ways to \nreduce conversion overhead of values, this may improve the C/Python speed \nup. Anyone have other explanations or faster code, please let me know.\n\n\n

Dictionary Sort

\n

\nThe demo in examples/dict_sort.py is another example from the Python CookBook. \nThis \nsubmission, by Alex Martelli, demonstrates how to return the values from a \ndictionary sorted by their keys:\n\n

       \n    def sortedDictValues3(adict):\n        keys = adict.keys()\n        keys.sort()\n        return map(adict.get, keys)\n    
\n

\nAlex provides 3 algorithms and this is the 3rd and fastest of the set. The C \nversion of this same algorithm follows:\n\n

       \n    def c_sort(adict):\n        assert(type(adict) == type({}))\n        code = \"\"\"     \n        #line 21 \"dict_sort.py\"  \n        Py::List keys = adict.keys();\n        Py::List items(keys.length()); keys.sort();     \n        PyObject* item = NULL; \n        for(int i = 0;  i < keys.length();i++)\n        {\n            item = PyList_GET_ITEM(keys.ptr(),i);\n            item = PyDict_GetItem(adict.ptr(),item);\n            Py_XINCREF(item);\n            PyList_SetItem(items.ptr(),i,item);              \n        }           \n        return_val = Py::new_reference_to(items);\n        \"\"\"   \n        return inline_tools.inline(code,['adict'],verbose=1)\n    
\n

\nLike the original Python function, the C++ version can handle any Python \ndictionary regardless of the key/value pair types. It uses CXX objects for the \nmost part to declare python types in C++, but uses Python API calls to manipulate \ntheir contents. Again, this choice is made for speed. The C++ version, while\nmore complicated, is about a factor of 2 faster than Python.\n\n

       \n    C:\\home\\ej\\wrk\\scipy\\weave\\examples> python dict_sort.py\n    Dict sort of 1000 items for 300 iterations:\n     speed in python: 0.319999933243\n    [0, 1, 2, 3, 4]\n     speed in c: 0.151000022888\n     speed up: 2.12\n    [0, 1, 2, 3, 4]\n    
\n

\n\n

Numeric -- cast/copy/transpose

\n\nCastCopyTranspose is a function called quite heavily by Linear Algebra routines\nin the Numeric library. Its needed in part because of the row-major memory layout\nof multi-demensional Python (and C) arrays vs. the col-major order of the underlying\nFortran algorithms. For small matrices (say 100x100 or less), a significant\nportion of the common routines such as LU decompisition or singular value decompostion\nare spent in this setup routine. This shouldn't happen. Here is the Python\nversion of the function using standard Numeric operations.\n\n
       \n    def _castCopyAndTranspose(type, array):\n        if a.typecode() == type:\n            cast_array = copy.copy(Numeric.transpose(a))\n        else:\n            cast_array = copy.copy(Numeric.transpose(a).astype(type))\n        return cast_array\n    
\n\nAnd the following is a inline C version of the same function:\n\n
\n    from weave.blitz_tools import blitz_type_factories\n    from weave import scalar_spec\n    from weave import inline\n    def _cast_copy_transpose(type,a_2d):\n        assert(len(shape(a_2d)) == 2)\n        new_array = zeros(shape(a_2d),type)\n        numeric_type = scalar_spec.numeric_to_blitz_type_mapping[type]\n        code = \\\n        \"\"\"  \n        for(int i = 0;i < _Na_2d[0]; i++)  \n            for(int j = 0;  j < _Na_2d[1]; j++)\n                new_array(i,j) = (%s) a_2d(j,i);\n        \"\"\" % numeric_type\n        inline(code,['new_array','a_2d'],\n               type_factories = blitz_type_factories,compiler='gcc')\n        return new_array\n    
\n\nThis example uses blitz++ arrays instead of the standard representation of \nNumeric arrays so that indexing is simplier to write. This is accomplished by \npassing in the blitz++ \"type factories\" to override the standard Python to C++ \ntype conversions. Blitz++ arrays allow you to write clean, fast code, but they \nalso are sloooow to compile (20 seconds or more for this snippet). This is why \nthey aren't the default type used for Numeric arrays (and also because most \ncompilers can't compile blitz arrays...). inline() is also forced \nto use 'gcc' as the compiler because the default compiler on Windows (MSVC) \nwill not compile blitz code. 'gcc' I think will use the standard compiler \non Unix machine instead of explicitly forcing gcc (check this) \n\nComparisons of the Python vs inline C++ code show a factor of 3 speed up. Also \nshown are the results of an \"inplace\" transpose routine that can be used if the \noutput of the linear algebra routine can overwrite the original matrix (this is \noften appropriate). This provides another factor of 2 improvement.\n\n
\n     #C:\\home\\ej\\wrk\\scipy\\weave\\examples> python cast_copy_transpose.py\n    # Cast/Copy/Transposing (150,150)array 1 times\n    #  speed in python: 0.870999932289\n    #  speed in c: 0.25\n    #  speed up: 3.48\n    #  inplace transpose c: 0.129999995232\n    #  speed up: 6.70\n    
\n\n\n

wxPython

\n\ninline knows how to handle wxPython objects. Thats nice in and of\nitself, but it also demonstrates that the type conversion mechanism is reasonably \nflexible. Chances are, it won't take a ton of effort to support special types\nyou might have. The examples/wx_example.py borrows the scrolled window\nexample from the wxPython demo, accept that it mixes inline C code in the middle\nof the drawing function.\n\n
\n    def DoDrawing(self, dc):\n        \n        red = wxNamedColour(\"RED\");\n        blue = wxNamedColour(\"BLUE\");\n        grey_brush = wxLIGHT_GREY_BRUSH;\n        code = \\\n        \"\"\"\n        #line 108 \"wx_example.py\" \n        dc->BeginDrawing();\n        dc->SetPen(wxPen(*red,4,wxSOLID));\n        dc->DrawRectangle(5,5,50,50);\n        dc->SetBrush(*grey_brush);\n        dc->SetPen(wxPen(*blue,4,wxSOLID));\n        dc->DrawRectangle(15, 15, 50, 50);\n        \"\"\"\n        inline(code,['dc','red','blue','grey_brush'])\n        \n        dc.SetFont(wxFont(14, wxSWISS, wxNORMAL, wxNORMAL))\n        dc.SetTextForeground(wxColour(0xFF, 0x20, 0xFF))\n        te = dc.GetTextExtent(\"Hello World\")\n        dc.DrawText(\"Hello World\", 60, 65)\n\n        dc.SetPen(wxPen(wxNamedColour('VIOLET'), 4))\n        dc.DrawLine(5, 65+te[1], 60+te[0], 65+te[1])\n        ...\n    
\n\nHere, some of the Python calls to wx objects were just converted to C++ calls. There\nisn't any benefit, it just demonstrates the capabilities. You might want to use this\nif you have a computationally intensive loop in your drawing code that you want to \nspeed up.\n\nOn windows, you'll have to use the MSVC compiler if you use the standard wxPython\nDLLs distributed by Robin Dunn. Thats because MSVC and gcc, while binary\ncompatible in C, are not binary compatible for C++. In fact, its probably best, no \nmatter what platform you're on, to specify that inline use the same\ncompiler that was used to build wxPython to be on the safe side. There isn't currently\na way to learn this info from the library -- you just have to know. Also, at least\non the windows platform, you'll need to install the wxWindows libraries and link to \nthem. I think there is a way around this, but I haven't found it yet -- I get some\nlinking errors dealing with wxString. One final note. You'll probably have to\ntweak weave/wx_spec.py or weave/wx_info.py for your machine's configuration to\npoint at the correct directories etc. There. That should sufficiently scare people\ninto not even looking at this... :)\n\n
\n

Keyword Options

\n

\nThe basic definition of the inline() function has a slew of \noptional variables. It also takes keyword arguments that are passed to \ndistutils as compiler options. The following is a formatted \ncut/paste of the argument section of inline's doc-string. It \nexplains all of the variables. Some examples using various options will \nfollow.\n\n

       \n    def inline(code,arg_names,local_dict = None, global_dict = None, \n               force = 0, \n               compiler='',\n               verbose = 0, \n               support_code = None,\n               customize=None, \n               type_factories = None, \n               auto_downcast=1,\n               **kw):\n    
\n\n \ninline has quite \na few options as listed below. Also, the keyword arguments for distutils \nextension modules are accepted to specify extra information needed for \ncompiling. \n
\n

inline Arguments:

\n
\n
\n
code
\n \n
\nstring. A string of valid C++ code. It should not \n specify a return statement. Instead it should assign results that need to be \n returned to Python in the return_val. \n
\n\n
arg_names
\n \n
\nlist of strings. A list of Python variable names \n that should be transferred from Python into the C/C++ code. \n
\n\n
local_dict
\n \n
\noptional. dictionary. If specified, it is a \n dictionary of values that should be used as the local scope for the C/C++ \n code. If local_dict is not specified the local dictionary of the calling \n function is used. \n
\n\n
global_dict
\n \n
\noptional. dictionary. If specified, it is a \n dictionary of values that should be used as the global scope for the C/C++ \n code. If global_dict is not specified the global dictionary of the calling \n function is used. \n
\n\n
force
\n \n
\noptional. 0 or 1. default 0. If 1, the C++ code is \n compiled every time inline is called. This is really only useful for \n debugging, and probably only useful if you're editing support_code a lot. \n
\n\n
compiler
\n \n
\noptional. string. The name of compiler to use when compiling. On windows, it \nunderstands 'msvc' and 'gcc' as well as all the compiler names understood by \ndistutils. On Unix, it'll only understand the values understoof by distutils. \n(I should add 'gcc' though to this).\n

\nOn windows, the compiler defaults to the Microsoft C++ compiler. If this isn't \navailable, it looks for mingw32 (the gcc compiler).\n

\nOn Unix, it'll probably use the same compiler that was used when compiling \nPython. Cygwin's behavior should be similar.

\n
\n\n
verbose
\n \n
\noptional. 0,1, or 2. defualt 0. Speficies how much \n much information is printed during the compile phase of inlining code. 0 is \n silent (except on windows with msvc where it still prints some garbage). 1 \n informs you when compiling starts, finishes, and how long it took. 2 prints \n out the command lines for the compilation process and can be useful if you're \n having problems getting code to work. Its handy for finding the name of the \n .cpp file if you need to examine it. verbose has no affect if the \n compilation isn't necessary. \n
\n\n
support_code
\n \n
\noptional. string. A string of valid C++ code \n declaring extra code that might be needed by your compiled function. This \n could be declarations of functions, classes, or structures. \n
\n\n
customize
\n \n
\noptional. base_info.custom_info object. An \n alternative way to specifiy support_code, headers, etc. needed by the \n function see the weave.base_info module for more details. (not sure \n this'll be used much). \n \n
\n
type_factories
\n \n
\noptional. list of type specification factories. These guys are what convert \nPython data types to C/C++ data types. If you'd like to use a different set of \ntype conversions than the default, specify them here. Look in the type \nconversions section of the main documentation for examples.\n
\n
auto_downcast
\n \n
\noptional. 0 or 1. default 1. This only affects functions that have Numeric \narrays as input variables. Setting this to 1 will cause all floating point \nvalues to be cast as float instead of double if all the Numeric arrays are of \ntype float. If even one of the arrays has type double or double complex, all \nvariables maintain there standard types.\n
\n
\n
\n\n

Distutils keywords:

\n
\ninline() also accepts a number of distutils keywords \nfor controlling how the code is compiled. The following descriptions have been \ncopied from Greg Ward's distutils.extension.Extension class doc-\nstrings for convenience:\n\n
\n
sources
\n \n
\n[string] list of source filenames, relative to the \n distribution root (where the setup script lives), in Unix form \n (slash-separated) for portability. Source files may be C, C++, SWIG (.i), \n platform-specific resource files, or whatever else is recognized by the \n \"build_ext\" command as source for a Python extension. Note: The module_path \n file is always appended to the front of this list \n
\n\n
include_dirs
\n \n
\n[string] list of directories to search for C/C++ \n header files (in Unix form for portability) \n
\n\n
define_macros
\n \n
\n[(name : string, value : string|None)] list of \n macros to define; each macro is defined using a 2-tuple, where 'value' is \n either the string to define it to or None to define it without a particular \n value (equivalent of \"#define FOO\" in source or -DFOO on Unix C compiler \n command line) \n
\n
undef_macros
\n \n
\n[string] list of macros to undefine explicitly \n
\n
library_dirs
\n
\n[string] list of directories to search for C/C++ libraries at link time \n
\n
libraries
\n
\n[string] list of library names (not filenames or paths) to link against \n
\n
runtime_library_dirs
\n
\n[string] list of directories to search for C/C++ libraries at run time (for \nshared extensions, this is when the extension is loaded) \n
\n\n
extra_objects
\n \n
\n[string] list of extra files to link with (eg. \n object files not implied by 'sources', static library that must be \n explicitly specified, binary resource files, etc.) \n
\n\n
extra_compile_args
\n \n
\n[string] any extra platform- and compiler-specific \n information to use when compiling the source files in 'sources'. For \n platforms and compilers where \"command line\" makes sense, this is typically \n a list of command-line arguments, but for other platforms it could be \n anything. \n
\n
extra_link_args
\n \n
\n[string] any extra platform- and compiler-specific \n information to use when linking object files together to create the \n extension (or to create a new static Python interpreter). Similar \n interpretation as for 'extra_compile_args'. \n
\n
export_symbols
\n \n
\n[string] list of symbols to be exported from a shared extension. Not used on \nall platforms, and not generally necessary for Python extensions, which \ntypically export exactly one symbol: \"init\" + extension_name. \n
\n
\n
\n\n\n

Keyword Option Examples

\nWe'll walk through several examples here to demonstrate the behavior of \ninline and also how the various arguments are used.\n\nIn the simplest (most) cases, code and arg_names\nare the only arguments that need to be specified. Here's a simple example\nrun on Windows machine that has Microsoft VC++ installed.\n\n
\n    >>> from weave import inline\n    >>> a = 'string'\n    >>> code = \"\"\"\n    ...        int l = a.length();\n    ...        return_val = Py::new_reference_to(Py::Int(l));\n    ...        \"\"\"\n    >>> inline(code,['a'])\n     sc_86e98826b65b047ffd2cd5f479c627f12.cpp\n    Creating\n       library C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\sc_86e98826b65b047ffd2cd5f479c627f12.lib\n    and object C:\\DOCUME~ 1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\sc_86e98826b65b047ff\n    d2cd5f479c627f12.exp\n    6\n    >>> inline(code,['a'])\n    6\n    
\n \nWhen inline is first run, you'll notice that pause and some \ntrash printed to the screen. The \"trash\" is acutually part of the compilers\noutput that distutils does not supress. The name of the extension file, \nsc_bighonkingnumber.cpp, is generated from the md5 check sum\nof the C/C++ code fragment. On Unix or windows machines with only\ngcc installed, the trash will not appear. On the second call, the code \nfragment is not compiled since it already exists, and only the answer is \nreturned. Now kill the interpreter and restart, and run the same code with\na different string.\n\n
\n    >>> from weave import inline\n    >>> a = 'a longer string' \n    >>> code = \"\"\" \n    ...        int l = a.length();\n    ...        return_val = Py::new_reference_to(Py::Int(l));  \n    ...        \"\"\"\n    >>> inline(code,['a'])\n    15\n    
\n

\nNotice this time, inline() did not recompile the code because it\nfound the compiled function in the persistent catalog of functions. There is\na short pause as it looks up and loads the function, but it is much shorter \nthan compiling would require.\n

\nYou can specify the local and global dictionaries if you'd like (much like \nexec or eval() in Python), but if they aren't \nspecified, the \"expected\" ones are used -- i.e. the ones from the function that \ncalled inline() . This is accomplished through a little call \nframe trickery. Here is an example where the local_dict is specified using\nthe same code example from above:\n\n

\n    >>> a = 'a longer string'\n    >>> b = 'an even  longer string' \n    >>> my_dict = {'a':b}\n    >>> inline(code,['a'])\n    15\n    >>> inline(code,['a'],my_dict)\n    21\n    
\n \n

\nEverytime, the code is changed, inline does a \nrecompile. However, changing any of the other options in inline does not\nforce a recompile. The force option was added so that one\ncould force a recompile when tinkering with other variables. In practice,\nit is just as easy to change the code by a single character\n(like adding a space some place) to force the recompile. Note: It also \nmight be nice to add some methods for purging the cache and on disk \ncatalogs.\n

\nI use verbose sometimes for debugging. When set to 2, it'll \noutput all the information (including the name of the .cpp file) that you'd\nexpect from running a make file. This is nice if you need to examine the\ngenerated code to see where things are going haywire. Note that error\nmessages from failed compiles are printed to the screen even if verbose\n is set to 0.\n

\nThe following example demonstrates using gcc instead of the standard msvc \ncompiler on windows using same code fragment as above. Because the example has \nalready been compiled, the force=1 flag is needed to make \ninline() ignore the previously compiled version and recompile \nusing gcc. The verbose flag is added to show what is printed out:\n\n

\n    >>>inline(code,['a'],compiler='gcc',verbose=2,force=1)\n    running build_ext    \n    building 'sc_86e98826b65b047ffd2cd5f479c627f13' extension \n    c:\\gcc-2.95.2\\bin\\g++.exe -mno-cygwin -mdll -O2 -w -Wstrict-prototypes -IC:\n    \\home\\ej\\wrk\\scipy\\weave -IC:\\Python21\\Include -c C:\\DOCUME~1\\eric\\LOCAL\n    S~1\\Temp\\python21_compiled\\sc_86e98826b65b047ffd2cd5f479c627f13.cpp -o C:\\D\n    OCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\sc_86e98826b65b04\n    7ffd2cd5f479c627f13.o    \n    skipping C:\\home\\ej\\wrk\\scipy\\weave\\CXX\\cxxextensions.c (C:\\DOCUME~1\\eri\n    c\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\cxxextensions.o up-to-date)\n    skipping C:\\home\\ej\\wrk\\scipy\\weave\\CXX\\cxxsupport.cxx (C:\\DOCUME~1\\eric\n    \\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\cxxsupport.o up-to-date)\n    skipping C:\\home\\ej\\wrk\\scipy\\weave\\CXX\\IndirectPythonInterface.cxx (C:\\\n    DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\indirectpythonin\n    terface.o up-to-date)\n    skipping C:\\home\\ej\\wrk\\scipy\\weave\\CXX\\cxx_extensions.cxx (C:\\DOCUME~1\\\n    eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\cxx_extensions.o up-to-da\n    te)\n    writing C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\sc_86\n    e98826b65b047ffd2cd5f479c627f13.def\n    c:\\gcc-2.95.2\\bin\\dllwrap.exe --driver-name g++ -mno-cygwin -mdll -static -\n    -output-lib C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\l\n    ibsc_86e98826b65b047ffd2cd5f479c627f13.a --def C:\\DOCUME~1\\eric\\LOCALS~1\\Te\n    mp\\python21_compiled\\temp\\Release\\sc_86e98826b65b047ffd2cd5f479c627f13.def \n    -s C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\temp\\Release\\sc_86e9882\n    6b65b047ffd2cd5f479c627f13.o C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compil\n    ed\\temp\\Release\\cxxextensions.o C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_com\n    piled\\temp\\Release\\cxxsupport.o C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_com\n    piled\\temp\\Release\\indirectpythoninterface.o C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\n    \\python21_compiled\\temp\\Release\\cxx_extensions.o -LC:\\Python21\\libs -lpytho\n    n21 -o C:\\DOCUME~1\\eric\\LOCALS~1\\Temp\\python21_compiled\\sc_86e98826b65b047f\n    fd2cd5f479c627f13.pyd\n    15\n    
\n\nThat's quite a bit of output. verbose=1 just prints the compile\ntime.\n\n
\n    >>>inline(code,['a'],compiler='gcc',verbose=1,force=1)\n    Compiling code...\n    finished compiling (sec):  6.00800001621\n    15\n    
\n\n

\n Note: I've only used the compiler option for switching between 'msvc'\nand 'gcc' on windows. It may have use on Unix also, but I don't know yet.\n\n\n

\nThe support_code argument is likely to be used a lot. It allows \nyou to specify extra code fragments such as function, structure or class \ndefinitions that you want to use in the code string. Note that \nchanges to support_code do not force a recompile. The \ncatalog only relies on code (for performance reasons) to determine \nwhether recompiling is necessary. So, if you make a change to support_code, \nyou'll need to alter code in some way or use the \nforce argument to get the code to recompile. I usually just add \nsome inocuous whitespace to the end of one of the lines in code \nsomewhere. Here's an example of defining a separate method for calculating\nthe string length:\n\n

\n    >>> from weave import inline\n    >>> a = 'a longer string'\n    >>> support_code = \"\"\"\n    ...                PyObject* length(Py::String a)\n    ...                {\n    ...                    int l = a.length();  \n    ...                    return Py::new_reference_to(Py::Int(l)); \n    ...                }\n    ...                \"\"\"        \n    >>> inline(\"return_val = length(a);\",['a'],\n    ...        support_code = support_code)\n    15\n    
\n

\ncustomize is a left over from a previous way of specifying \ncompiler options. It is a custom_info object that can specify \nquite a bit of information about how a file is compiled. These \ninfo objects are the standard way of defining compile information \nfor type conversion classes. However, I don't think they are as handy here, \nespecially since we've exposed all the keyword arguments that distutils can \nhandle. Between these keywords, and the support_code option, I \nthink customize may be obsolete. We'll see if anyone cares to use \nit. If not, it'll get axed in the next version.\n

\nThe type_factories variable is important to people who want to\ncustomize the way arguments are converted from Python to C. We'll talk about\nthis in the next chapter **xx** of this document when we discuss type\nconversions.\n

\nauto_downcast handles one of the big type conversion issues that\nis common when using Numeric arrays in conjunction with Python scalar values.\nIf you have an array of single precision values and multiply that array by a \nPython scalar, the result is upcast to a double precision array because the\nscalar value is double precision. This is not usually the desired behavior\nbecause it can double your memory usage. auto_downcast goes\nsome distance towards changing the casting precedence of arrays and scalars.\nIf your only using single precision arrays, it will automatically downcast all\nscalar values from double to single precision when they are passed into the\nC++ code. This is the default behavior. If you want all values to keep there\ndefault type, set auto_downcast to 0.\n

\n\n\n\n

Returning Values

\n\nPython variables in the local and global scope transfer seemlessly from Python \ninto the C++ snippets. And, if inline were to completely live up\nto its name, any modifications to variables in the C++ code would be reflected\nin the Python variables when control was passed back to Python. For example,\nthe desired behavior would be something like:\n\n
\n    # THIS DOES NOT WORK\n    >>> a = 1\n    >>> weave.inline(\"a++;\",['a'])\n    >>> a\n    2\n    
\n\nInstead you get:\n\n
\n    >>> a = 1\n    >>> weave.inline(\"a++;\",['a'])\n    >>> a\n    1\n    
\n \nVariables are passed into C++ as if you are calling a Python function. Python's \ncalling convention is sometimes called \"pass by assignment\". This means its as \nif a c_a = a assignment is made right before inline \ncall is made and the c_a variable is used within the C++ code. \nThus, any changes made to c_a are not reflected in Python's \na variable. Things do get a little more confusing, however, when \nlooking at variables with mutable types. Changes made in C++ to the contents \nof mutable types are reflected in the Python variables.\n\n
\n    >>> a= [1,2]\n    >>> weave.inline(\"PyList_SetItem(a.ptr(),0,PyInt_FromLong(3));\",['a'])\n    >>> print a\n    [3, 2]\n    
\n\nSo modifications to the contents of mutable types in C++ are seen when control\nis returned to Python. Modifications to immutable types such as tuples,\nstrings, and numbers do not alter the Python variables.\n\nIf you need to make changes to an immutable variable, you'll need to assign\nthe new value to the \"magic\" variable return_val in C++. This\nvalue is returned by the inline() function:\n\n
\n    >>> a = 1\n    >>> a = weave.inline(\"return_val = Py::new_reference_to(Py::Int(a+1));\",['a'])  \n    >>> a\n    2\n    
\n\nThe return_val variable can also be used to return newly created \nvalues. This is possible by returning a tuple. The following trivial example \nillustrates how this can be done:\n\n
       \n    # python version\n    def multi_return():\n        return 1, '2nd'\n    \n    # C version.\n    def c_multi_return():    \n        code =  \"\"\"\n     \t        Py::Tuple results(2);\n     \t        results[0] = Py::Int(1);\n     \t        results[1] = Py::String(\"2nd\");\n     \t        return_val = Py::new_reference_to(results); \t        \n                \"\"\"\n        return inline_tools.inline(code)\n    
\n

\nThe example is available in examples/tuple_return.py. It also\nhas the dubious honor of demonstrating how much inline() can \nslow things down. The C version here is about 10 times slower than the Python\nversion. Of course, something so trivial has no reason to be written in\nC anyway.\n\n\n

The issue with locals()

\n

\ninline passes the locals() and globals() \ndictionaries from Python into the C++ function from the calling function. It \nextracts the variables that are used in the C++ code from these dictionaries, \nconverts then to C++ variables, and then calculates using them. It seems like \nit would be trivial, then, after the calculations were finished to then insert \nthe new values back into the locals() and globals() \ndictionaries so that the modified values were reflected in Python. \nUnfortunately, as pointed out by the Python manual, the locals() dictionary is \nnot writable. \n

\n\nI suspect locals() is not writable because there are some \noptimizations done to speed lookups of the local namespace. I'm guessing local \nlookups don't always look at a dictionary to find values. Can someone \"in the \nknow\" confirm or correct this? Another thing I'd like to know is whether there \nis a way to write to the local namespace of another stack frame from C/C++. If \nso, it would be possible to have some clean up code in compiled functions that \nwrote final values of variables in C++ back to the correct Python stack frame. \nI think this goes a long way toward making inline truely live up \nto its name. I don't think we'll get to the point of creating variables in \nPython for variables created in C -- although I suppose with a C/C++ parser you \ncould do that also.\n\n

\n\n\n

A quick look at the code

\n\nweave generates a C++ file holding an extension function for \neach inline code snippet. These file names are generated using \nfrom the md5 signature of the code snippet and saved to a location specified by \nthe PYTHONCOMPILED environment variable (discussed later). The cpp files are \ngenerally about 200-400 lines long and include quite a few functions to support \ntype conversions, etc. However, the actual compiled function is pretty simple. \nBelow is the familiar printf example:\n\n
\n    >>> import weave    \n    >>> a = 1\n    >>> weave.inline('printf(\"%d\\\\n\",a);',['a'])\n    1\n    
\n\nAnd here is the extension function generated by inline:\n\n
\n    static PyObject* compiled_func(PyObject*self, PyObject* args)\n    {\n        // The Py_None needs an incref before returning\n        PyObject *return_val = NULL;\n        int exception_occured = 0;\n        PyObject *py__locals = NULL;\n        PyObject *py__globals = NULL;\n        PyObject *py_a;\n        py_a = NULL;\n        \n        if(!PyArg_ParseTuple(args,\"OO:compiled_func\",&py__locals,&py__globals))\n            return NULL;\n        try                              \n        {                                \n            PyObject* raw_locals = py_to_raw_dict(py__locals,\"_locals\");\n            PyObject* raw_globals = py_to_raw_dict(py__globals,\"_globals\");\n            int a = py_to_int (get_variable(\"a\",raw_locals,raw_globals),\"a\");\n            /* Here is the inline code */            \n            printf(\"%d\\n\",a);\n            /* I would like to fill in changed locals and globals here... */\n        }                                       \n        catch( Py::Exception& e)           \n        {                                \n            return_val =  Py::Null();    \n            exception_occured = 1;       \n        }                                 \n        if(!return_val && !exception_occured)\n        {\n                                      \n            Py_INCREF(Py_None);              \n            return_val = Py_None;            \n        }\n        /* clean up code */\n        \n        /* return */                              \n        return return_val;           \n    }                                \n    
\n\nEvery inline function takes exactly two arguments -- the local and global\ndictionaries for the current scope. All variable values are looked up out\nof these dictionaries. The lookups, along with all inline code \nexecution, are done within a C++ try block. If the variables\naren't found, or there is an error converting a Python variable to the \nappropriate type in C++, an exception is raised. The C++ exception\nis automatically converted to a Python exception by CXX and returned to Python.\n\nThe py_to_int() function illustrates how the conversions and\nexception handling works. py_to_int first checks that the given PyObject*\npointer is not NULL and is a Python integer. If all is well, it calls the\nPython API to convert the value to an int. Otherwise, it calls\nhandle_bad_type() which gathers information about what went wrong\nand then raises a CXX TypeError which returns to Python as a TypeError.\n\n
\n    int py_to_int(PyObject* py_obj,char* name)\n    {\n        if (!py_obj || !PyInt_Check(py_obj))\n            handle_bad_type(py_obj,\"int\", name);\n        return (int) PyInt_AsLong(py_obj);\n    }\n    
\n\n
\n    void handle_bad_type(PyObject* py_obj, char* good_type, char*  var_name)\n    {\n        char msg[500];\n        sprintf(msg,\"received '%s' type instead of '%s' for variable '%s'\",\n                find_type(py_obj),good_type,var_name);\n        throw Py::TypeError(msg);\n    }\n    \n    char* find_type(PyObject* py_obj)\n    {\n        if(py_obj == NULL) return \"C NULL value\";\n        if(PyCallable_Check(py_obj)) return \"callable\";\n        if(PyString_Check(py_obj)) return \"string\";\n        if(PyInt_Check(py_obj)) return \"int\";\n        if(PyFloat_Check(py_obj)) return \"float\";\n        if(PyDict_Check(py_obj)) return \"dict\";\n        if(PyList_Check(py_obj)) return \"list\";\n        if(PyTuple_Check(py_obj)) return \"tuple\";\n        if(PyFile_Check(py_obj)) return \"file\";\n        if(PyModule_Check(py_obj)) return \"module\";\n        \n        //should probably do more interagation (and thinking) on these.\n        if(PyCallable_Check(py_obj) && PyInstance_Check(py_obj)) return \"callable\";\n        if(PyInstance_Check(py_obj)) return \"instance\"; \n        if(PyCallable_Check(py_obj)) return \"callable\";\n        return \"unkown type\";\n    }\n    
\n\nSince the inline is also executed within the try/catch\nblock, you can use CXX exceptions within your code. It is usually a bad idea\nto directly return from your code, even if an error occurs. This\nskips the clean up section of the extension function. In this simple example,\nthere isn't any clean up code, but in more complicated examples, there may\nbe some reference counting that needs to be taken care of here on converted\nvariables. To avoid this, either uses exceptions or set \nreturn_val to NULL and use if/then's to skip code\nafter errors.\n\n\n

Technical Details

\n

\nThere are several main steps to using C/C++ code withing Python:\n

    \n
  1. Type conversion \n
  2. Generating C/C++ code \n
  3. Compile the code to an extension module \n
  4. Catalog (and cache) the function for future use
  5. \n
\n

\nItems 1 and 2 above are related, but most easily discussed separately. Type \nconversions are customizable by the user if needed. Understanding them is \npretty important for anything beyond trivial uses of inline. \nGenerating the C/C++ code is handled by ext_function and \next_module classes and . For the most part, compiling the code is \nhandled by distutils. Some customizations were needed, but they were \nrelatively minor and do not require changes to distutils itself. Cataloging is \npretty simple in concept, but surprisingly required the most code to implement \n(and still likely needs some work). So, this section covers items 1 and 4 from \nthe list. Item 2 is covered later in the chapter covering the \next_tools module, and distutils is covered by a completely \nseparate document xxx.\n\n

Passing Variables in/out of the C/C++ code

\n\nNote: Passing variables into the C code is pretty straight forward, but there \nare subtlties to how variable modifications in C are returned to Python. see Returning Values for a more thorough discussion of \nthis issue.\n \n \n\n

Type Conversions

\n\n\nNote: Maybe xxx_converter instead of \nxxx_specification is a more descriptive name. Might change in \nfuture version?\n\n\n

\nBy default, inline() makes the following type conversions between\nPython and C++ types.\n

\n\n

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
\n

Default Data Type Conversions

\n

Python

\n

C++

   int   int
   float   double
   complex   std::complex
   string   Py::String
   list   Py::List
   dict   Py::Dict
   tuple   Py::Tuple
   file   FILE*
   callable   PyObject*
   instance   PyObject*
   Numeric.array   PyArrayObject*
   wxXXX   wxXXX*
\n
\n

\nThe Py:: namespace is defined by the \nCXX library which has C++ class\nequivalents for many Python types. std:: is the namespace of the\nstandard library in C++.\n

\n\nNote: \n

    \n
  • I haven't figured out how to handle long int yet (I think they are currenlty converted \n to int - - check this). \n \n
  • \nHopefully VTK will be added to the list soon
  • \n
\n\n

\n\nPython to C++ conversions fill in code in several locations in the generated\ninline extension function. Below is the basic template for the\nfunction. This is actually the exact code that is generated by calling\nweave.inline(\"\").\n\n

\n    static PyObject* compiled_func(PyObject*self, PyObject* args)\n    {\n        PyObject *return_val = NULL;\n        int exception_occured = 0;\n        PyObject *py__locals = NULL;\n        PyObject *py__globals = NULL;\n        PyObject *py_a;\n        py_a = NULL;\n    \n        if(!PyArg_ParseTuple(args,\"OO:compiled_func\",&py__locals,&py__globals))\n            return NULL;\n        try\n        {\n            PyObject* raw_locals = py_to_raw_dict(py__locals,\"_locals\");\n            PyObject* raw_globals = py_to_raw_dict(py__globals,\"_globals\");\n            /* argument conversion code */\n            /* inline code */\n            /*I would like to fill in changed locals and globals here...*/\n    \n        }\n        catch( Py::Exception& e)\n        {\n            return_val =  Py::Null();\n            exception_occured = 1;\n        }\n        /* cleanup code */\n        if(!return_val && !exception_occured)\n        {\n    \n            Py_INCREF(Py_None);\n            return_val = Py_None;\n        }\n    \n        return return_val;\n    }\n    
\n\nThe /* inline code */ section is filled with the code passed to\nthe inline() function call. The \n/*argument convserion code*/ and /* cleanup code */\nsections are filled with code that handles conversion from Python to C++\ntypes and code that deallocates memory or manipulates reference counts before\nthe function returns. The following sections demostrate how these two areas\nare filled in by the default conversion methods.\n\n \nNote: I'm not sure I have reference counting correct on a few of these. The \nonly thing I increase/decrease the ref count on is Numeric arrays. If you\nsee an issue, please let me know.\n\n\n\n

Numeric Argument Conversion

\n\nInteger, floating point, and complex arguments are handled in a very similar\nfashion. Consider the following inline function that has a single integer \nvariable passed in:\n\n
\n    >>> a = 1\n    >>> inline(\"\",['a'])\n    
\n\nThe argument conversion code inserted for a is:\n\n
\n    /* argument conversion code */\n    int a = py_to_int (get_variable(\"a\",raw_locals,raw_globals),\"a\");\n    
\n\nget_variable() reads the variable a\nfrom the local and global namespaces. py_to_int() has the following\nform:\n\n
\n    static int py_to_int(PyObject* py_obj,char* name)\n    {\n        if (!py_obj || !PyInt_Check(py_obj))\n            handle_bad_type(py_obj,\"int\", name);\n        return (int) PyInt_AsLong(py_obj);\n    }\n    
\n\nSimilarly, the float and complex conversion routines look like:\n\n
    \n    static double py_to_float(PyObject* py_obj,char* name)\n    {\n        if (!py_obj || !PyFloat_Check(py_obj))\n            handle_bad_type(py_obj,\"float\", name);\n        return PyFloat_AsDouble(py_obj);\n    }\n    \n    static std::complex py_to_complex(PyObject* py_obj,char* name)\n    {\n        if (!py_obj || !PyComplex_Check(py_obj))\n            handle_bad_type(py_obj,\"complex\", name);\n        return std::complex(PyComplex_RealAsDouble(py_obj),\n                                    PyComplex_ImagAsDouble(py_obj));    \n    }\n    
\n\nNumeric conversions do not require any clean up code.\n\n\n

String, List, Tuple, and Dictionary Conversion

\n\nStrings, Lists, Tuples and Dictionary conversions are all converted to \nCXX types by default.\n\nFor the following code, \n\n
\n    >>> a = [1]\n    >>> inline(\"\",['a'])\n    
\n\nThe argument conversion code inserted for a is:\n\n
\n    /* argument conversion code */\n    Py::List a = py_to_list (get_variable(\"a\",raw_locals,raw_globals),\"a\");\n    
\n\nget_variable() reads the variable a\nfrom the local and global namespaces. py_to_list() and its\nfriends has the following form:\n\n
    \n    static Py::List py_to_list(PyObject* py_obj,char* name)\n    {\n        if (!py_obj || !PyList_Check(py_obj))\n            handle_bad_type(py_obj,\"list\", name);\n        return Py::List(py_obj);\n    }\n    \n    static Py::String py_to_string(PyObject* py_obj,char* name)\n    {\n        if (!PyString_Check(py_obj))\n            handle_bad_type(py_obj,\"string\", name);\n        return Py::String(py_obj);\n    }\n\n    static Py::Dict py_to_dict(PyObject* py_obj,char* name)\n    {\n        if (!py_obj || !PyDict_Check(py_obj))\n            handle_bad_type(py_obj,\"dict\", name);\n        return Py::Dict(py_obj);\n    }\n    \n    static Py::Tuple py_to_tuple(PyObject* py_obj,char* name)\n    {\n        if (!py_obj || !PyTuple_Check(py_obj))\n            handle_bad_type(py_obj,\"tuple\", name);\n        return Py::Tuple(py_obj);\n    }\n    
\n\nCXX handles reference counts on for strings, lists, tuples, and dictionaries,\nso clean up code isn't necessary.\n\n\n

File Conversion

\n\nFor the following code, \n\n
\n    >>> a = open(\"bob\",'w')  \n    >>> inline(\"\",['a'])\n    
\n\nThe argument conversion code is:\n\n
\n    /* argument conversion code */\n    PyObject* py_a = get_variable(\"a\",raw_locals,raw_globals);\n    FILE* a = py_to_file(py_a,\"a\");\n    
\n\nget_variable() reads the variable a\nfrom the local and global namespaces. py_to_file() converts\nPyObject* to a FILE* and increments the reference count of the PyObject*:\n\n
\n    FILE* py_to_file(PyObject* py_obj, char* name)\n    {\n        if (!py_obj || !PyFile_Check(py_obj))\n            handle_bad_type(py_obj,\"file\", name);\n    \n        Py_INCREF(py_obj);\n        return PyFile_AsFile(py_obj);\n    }\n    
\n\nBecause the PyObject* was incremented, the clean up code needs to decrement\nthe counter\n\n
\n    /* cleanup code */\n    Py_XDECREF(py_a);\n    
\n\nIts important to understand that file conversion only works on actual files --\ni.e. ones created using the open() command in Python. It does\nnot support converting arbitrary objects that support the file interface into\nC FILE* pointers. This can affect many things. For example, in\ninitial printf() examples, one might be tempted to solve the \nproblem of C and Python IDE's (PythonWin, PyCrust, etc.) writing to different\nstdout and stderr by using fprintf() and passing in \nsys.stdout and sys.stderr. For example, instead of\n\n
\n    >>> weave.inline('printf(\"hello\\\\n\");')\n    
\n \nYou might try:\n\n
\n    >>> buf = sys.stdout\n    >>> weave.inline('fprintf(buf,\"hello\\\\n\");',['buf'])\n    
\n\nThis will work as expected from a standard python interpreter, but in PythonWin,\nthe following occurs:\n\n
\n    >>> buf = sys.stdout\n    >>> weave.inline('fprintf(buf,\"hello\\\\n\");',['buf'])\n    Traceback (most recent call last):\n        File \"\", line 1, in ?\n        File \"C:\\Python21\\weave\\inline_tools.py\", line 315, in inline\n            auto_downcast = auto_downcast,\n        File \"C:\\Python21\\weave\\inline_tools.py\", line 386, in compile_function\n            type_factories = type_factories)\n        File \"C:\\Python21\\weave\\ext_tools.py\", line 197, in __init__\n            auto_downcast, type_factories)\n        File \"C:\\Python21\\weave\\ext_tools.py\", line 390, in assign_variable_types\n            raise TypeError, format_error_msg(errors)\n        TypeError: {'buf': \"Unable to convert variable 'buf' to a C++ type.\"}\n    
\n\nThe traceback tells us that inline() was unable to convert 'buf' to a\nC++ type (If instance conversion was implemented, the error would have occurred at \nruntime instead). Why is this? Let's look at what the buf object \nreally is:\n\n
\n    >>> buf\n    pywin.framework.interact.InteractiveView instance at 00EAD014\n    
\n\nPythonWin has reassigned sys.stdout to a special object that \nimplements the Python file interface. This works great in Python, but since \nthe special object doesn't have a FILE* pointer underlying it, fprintf doesn't \nknow what to do with it (well this will be the problem when instance conversion \nis implemented...).\n\n\n

Callable, Instance, and Module Conversion

\n\nNote: Need to look into how ref counts should be handled. Also,\nInstance and Module conversion are not currently implemented.\n\n\n
\n    >>> def a(): \n        pass\n    >>> inline(\"\",['a'])\n    
\n\nCallable and instance variables are converted to PyObject*. Nothing is done\nto there reference counts.\n\n
\n    /* argument conversion code */\n    PyObject* a = py_to_callable(get_variable(\"a\",raw_locals,raw_globals),\"a\");\n    
\n\nget_variable() reads the variable a\nfrom the local and global namespaces. The py_to_callable() and\npy_to_instance() don't currently increment the ref count.\n\n
    \n    PyObject* py_to_callable(PyObject* py_obj, char* name)\n    {\n        if (!py_obj || !PyCallable_Check(py_obj))\n            handle_bad_type(py_obj,\"callable\", name);    \n        return py_obj;\n    }\n\n    PyObject* py_to_instance(PyObject* py_obj, char* name)\n    {\n        if (!py_obj || !PyFile_Check(py_obj))\n            handle_bad_type(py_obj,\"instance\", name);    \n        return py_obj;\n    }\n    
\n \nThere is no cleanup code for callables, modules, or instances.\n\n\n

Customizing Conversions

\n

\nConverting from Python to C++ types is handled by xxx_specification classes. A \ntype specification class actually serve in two related but different \nroles. The first is in determining whether a Python variable that needs to be \nconverted should be represented by the given class. The second is as a code \ngenerator that generate C++ code needed to convert from Python to C++ types for \na specific variable.\n

\nWhen \n\n

\n    >>> a = 1\n    >>> weave.inline('printf(\"%d\",a);',['a'])\n    
\n \nis called for the first time, the code snippet has to be compiled. In this \nprocess, the variable 'a' is tested against a list of type specifications (the \ndefault list is stored in weave/ext_tools.py). The first \nspecification in the list is used to represent the variable. \n\n

\nExamples of xxx_specification are scattered throughout numerous \n\"xxx_spec.py\" files in the weave package. Closely related to \nthe xxx_specification classes are yyy_info classes. \nThese classes contain compiler, header, and support code information necessary \nfor including a certain set of capabilities (such as blitz++ or CXX support)\nin a compiled module. xxx_specification classes have one or more\nyyy_info classes associated with them.\n\nIf you'd like to define your own set of type specifications, the current best route\nis to examine some of the existing spec and info files. Maybe looking over\nsequence_spec.py and cxx_info.py are a good place to start. After defining \nspecification classes, you'll need to pass them into inline using the \ntype_factories argument. \n\nA lot of times you may just want to change how a specific variable type is \nrepresented. Say you'd rather have Python strings converted to \nstd::string or maybe char* instead of using the CXX \nstring object, but would like all other type conversions to have default \nbehavior. This requires that a new specification class that handles strings\nis written and then prepended to a list of the default type specifications. Since\nit is closer to the front of the list, it effectively overrides the default\nstring specification.\n\nThe following code demonstrates how this is done:\n\n...\n\n\n

The Catalog

\n

\ncatalog.py has a class called catalog that helps keep \ntrack of previously compiled functions. This prevents inline() \nand related functions from having to compile functions everytime they are \ncalled. Instead, catalog will check an in memory cache to see if the function \nhas already been loaded into python. If it hasn't, then it starts searching \nthrough persisent catalogs on disk to see if it finds an entry for the given \nfunction. By saving information about compiled functions to disk, it isn't\nnecessary to re-compile functions everytime you stop and restart the interpreter.\nFunctions are compiled once and stored for future use.\n\n

\nWhen inline(cpp_code) is called the following things happen:\n

    \n
  1. \n A fast local cache of functions is checked for the last function called for \n cpp_code. If an entry for cpp_code doesn't exist in the \n cache or the cached function call fails (perhaps because the function doesn't \n have compatible types) then the next step is to check the catalog. \n
  2. \n The catalog class also keeps an in-memory cache with a list of all the \n functions compiled for cpp_code. If cpp_code has\n ever been called, then this cache will be present (loaded from disk). If\n the cache isn't present, then it is loaded from disk.\n

    \n If the cache is present, each function in the cache is \n called until one is found that was compiled for the correct argument types. If \n none of the functions work, a new function is compiled with the given argument \n types. This function is written to the on-disk catalog as well as into the \n in-memory cache.

    \n
  3. \n When a lookup for cpp_code fails, the catalog looks through \n the on-disk function catalogs for the entries. The PYTHONCOMPILED variable \n determines where to search for these catalogs and in what order. If \n PYTHONCOMPILED is not present several platform dependent locations are \n searched. All functions found for cpp_code in the path are \n loaded into the in-memory cache with functions found earlier in the search \n path closer to the front of the call list.\n

    \n If the function isn't found in the on-disk catalog, \n then the function is compiled, written to the first writable directory in the \n PYTHONCOMPILED path, and also loaded into the in-memory cache.

    \n
  4. \n
\n\n\n

Function Storage: How functions are stored in caches and on disk

\n

\nFunction caches are stored as dictionaries where the key is the entire C++\ncode string and the value is either a single function (as in the \"level 1\"\ncache) or a list of functions (as in the main catalog cache). On disk\ncatalogs are stored in the same manor using standard Python shelves.\n

\nEarly on, there was a question as to whether md5 check sums of the C++\ncode strings should be used instead of the actual code strings. I think this\nis the route inline Perl took. Some (admittedly quick) tests of the md5 vs.\nthe entire string showed that using the entire string was at least a\nfactor of 3 or 4 faster for Python. I think this is because it is more\ntime consuming to compute the md5 value than it is to do look-ups of long\nstrings in the dictionary. Look at the examples/md5_speed.py file for the\ntest run. \n\n\n

Catalog search paths and the PYTHONCOMPILED variable

\n

\nThe default location for catalog files on Unix is is ~/.pythonXX_compiled where \nXX is version of Python being used. If this directory doesn't exist, it is \ncreated the first time a catalog is used. The directory must be writable. If, \nfor any reason it isn't, then the catalog attempts to create a directory based \non your user id in the /tmp directory. The directory permissions are set so \nthat only you have access to the directory. If this fails, I think you're out of \nluck. I don't think either of these should ever fail though. On Windows, a \ndirectory called pythonXX_compiled is created in the user's temporary \ndirectory. \n

\nThe actual catalog file that lives in this directory is a Python shelve with\na platform specific name such as \"nt21compiled_catalog\" so that multiple OSes\ncan share the same file systems without trampling on each other. Along with\nthe catalog file, the .cpp and .so or .pyd files created by inline will live\nin this directory. The catalog file simply contains keys which are the C++\ncode strings with values that are lists of functions. The function lists point\nat functions within these compiled modules. Each function in the lists \nexecutes the same C++ code string, but compiled for different input variables.\n

\nYou can use the PYTHONCOMPILED environment variable to specify alternative\nlocations for compiled functions. On Unix this is a colon (':') separated\nlist of directories. On windows, it is a (';') separated list of directories.\nThese directories will be searched prior to the default directory for a\ncompiled function catalog. Also, the first writable directory in the list\nis where all new compiled function catalogs, .cpp and .so or .pyd files are\nwritten. Relative directory paths ('.' and '..') should work fine in the\nPYTHONCOMPILED variable as should environement variables.\n

\nThere is a \"special\" path variable called MODULE that can be placed in the \nPYTHONCOMPILED variable. It specifies that the compiled catalog should\nreside in the same directory as the module that called it. This is useful\nif an admin wants to build a lot of compiled functions during the build\nof a package and then install them in site-packages along with the package.\nUser's who specify MODULE in their PYTHONCOMPILED variable will have access\nto these compiled functions. Note, however, that if they call the function\nwith a set of argument types that it hasn't previously been built for, the\nnew function will be stored in their default directory (or some other writable\ndirectory in the PYTHONCOMPILED path) because the user will not have write\naccess to the site-packages directory.\n

\nAn example of using the PYTHONCOMPILED path on bash follows:\n\n

\n    PYTHONCOMPILED=MODULE:/some/path;export PYTHONCOMPILED;\n    
\n\nIf you are using python21 on linux, and the module bob.py in site-packages\nhas a compiled function in it, then the catalog search order when calling that\nfunction for the first time in a python session would be:\n\n
\n    /usr/lib/python21/site-packages/linuxpython_compiled\n    /some/path/linuxpython_compiled\n    ~/.python21_compiled/linuxpython_compiled\n    
\n\nThe default location is always included in the search path.\n

\n \nNote: hmmm. see a possible problem here. I should probably make a sub-\ndirectory such as /usr/lib/python21/site-\npackages/python21_compiled/linuxpython_compiled so that library files compiled \nwith python21 are tried to link with python22 files in some strange scenarios. \nNeed to check this.\n\n\n

\nThe in-module cache (in weave.inline_tools reduces the overhead \nof calling inline functions by about a factor of 2. It can be reduced a little \nmore for type loop calls where the same function is called over and over again \nif the cache was a single value instead of a dictionary, but the benefit is \nvery small (less than 5%) and the utility is quite a bit less. So, we'll stick \nwith a dictionary as the cache.\n

\n\n\n

Blitz

\n Note: most of this section is lifted from old documentation. It should be\npretty accurate, but there may be a few discrepancies.\n

\nweave.blitz() compiles Numeric Python expressions for fast \nexecution. For most applications, compiled expressions should provide a \nfactor of 2-10 speed-up over Numeric arrays. Using compiled \nexpressions is meant to be as unobtrusive as possible and works much like \npythons exec statement. As an example, the following code fragment takes a 5 \npoint average of the 512x512 2d image, b, and stores it in array, a:\n\n

\n    from scipy import *  # or from Numeric import *\n    a = ones((512,512), Float64) \n    b = ones((512,512), Float64) \n    # ...do some stuff to fill in b...\n    # now average\n    a[1:-1,1:-1] =  (b[1:-1,1:-1] + b[2:,1:-1] + b[:-2,1:-1] \\\n                   + b[1:-1,2:] + b[1:-1,:-2]) / 5.\n    
\n \nTo compile the expression, convert the expression to a string by putting\nquotes around it and then use weave.blitz:\n\n
\n    import weave\n    expr = \"a[1:-1,1:-1] =  (b[1:-1,1:-1] + b[2:,1:-1] + b[:-2,1:-1]\" \\\n                          \"+ b[1:-1,2:] + b[1:-1,:-2]) / 5.\"\n    weave.blitz(expr)\n    
\n\nThe first time weave.blitz is run for a given expression and \nset of arguements, C++ code that accomplishes the exact same task as the Python \nexpression is generated and compiled to an extension module. This can take up \nto a couple of minutes depending on the complexity of the function. Subsequent \ncalls to the function are very fast. Futher, the generated module is saved \nbetween program executions so that the compilation is only done once for a \ngiven expression and associated set of array types. If the given expression\nis executed with a new set of array types, the code most be compiled again. This\ndoes not overwrite the previously compiled function -- both of them are saved and\navailable for exectution. \n

\nThe following table compares the run times for standard Numeric code and \ncompiled code for the 5 point averaging.\n

\n

\n\n\n\n\n\n
Method Run Time (seconds)
Standard Numeric 0.46349
blitz (1st time compiling) 78.95526
blitz (subsequent calls) 0.05843 (factor of 8 speedup)
\n
\n

\nThese numbers are for a 512x512 double precision image run on a 400 MHz Celeron \nprocessor under RedHat Linux 6.2.\n

\nBecause of the slow compile times, its probably most effective to develop \nalgorithms as you usually do using the capabilities of scipy or the Numeric \nmodule. Once the algorithm is perfected, put quotes around it and execute it \nusing weave.blitz. This provides the standard rapid \nprototyping strengths of Python and results in algorithms that run close to \nthat of hand coded C or Fortran.\n\n\n

Requirements

\n\nCurrently, the weave.blitz has only been tested under Linux \nwith gcc-2.95-3 and on Windows with Mingw32 (2.95.2). Its compiler \nrequirements are pretty heavy duty (see the \nblitz++ home page), so it won't \nwork with just any compiler. Particularly MSVC++ isn't up to snuff. A number \nof other compilers such as KAI++ will also work, but my suspicions are that gcc \nwill get the most use.\n\n\n

Limitations

\n
    \n
  1. \nCurrently, weave.blitz handles all standard mathematic \noperators except for the ** power operator. The built-in trigonmetric, log, \nfloor/ceil, and fabs functions might work (but haven't been tested). It also \nhandles all types of array indexing supported by the Numeric module. \n

    \nweave.blitz does not currently support operations that use \narray broadcasting, nor have any of the special purpose functions in Numeric \nsuch as take, compress, etc. been implemented. Note that there are no obvious \nreasons why most of this functionality cannot be added to scipy.weave, so it \nwill likely trickle into future versions. Using slice() objects \ndirectly instead of start:stop:step is also not supported.\n

  2. \n
  3. \nCurrently Python only works on expressions that include assignment such as\n \n
    \n    >>> result = b + c + d\n    
    \n\nThis means that the result array must exist before calling \nweave.blitz. Future versions will allow the following:\n\n
    \n    >>> result = weave.blitz_eval(\"b + c + d\")\n    
    \n
  4. \n
  5. \nweave.blitz works best when algorithms can be expressed in a \n\"vectorized\" form. Algorithms that have a large number of if/thens and other \nconditions are better hand written in C or Fortran. Further, the restrictions \nimposed by requiring vectorized expressions sometimes preclude the use of more \nefficient data structures or algorithms. For maximum speed in these cases, \nhand-coded C or Fortran code is the only way to go.\n
  6. \n
  7. \nweave.blitz can produce different results than Numeric in certain \nsituations. It can happen when the array receiving the results of a \ncalculation is also used during the calculation. The Numeric behavior is to \ncarry out the entire calculation on the right hand side of an equation and \nstore it in a temporary array. This temprorary array is assigned to the array \non the left hand side of the equation. blitz, on the other hand, does a \n\"running\" calculation of the array elements assigning values from the right hand\nside to the elements on the left hand side immediately after they are calculated.\nHere is an example, provided by Prabhu Ramachandran, where this happens:\n\n
    \n        # 4 point average.\n        >>> expr = \"u[1:-1, 1:-1] = (u[0:-2, 1:-1] + u[2:, 1:-1] + \"\\\n        ...                \"u[1:-1,0:-2] + u[1:-1, 2:])*0.25\"\n        >>> u = zeros((5, 5), 'd'); u[0,:] = 100\n        >>> exec (expr)\n        >>> u\n        array([[ 100.,  100.,  100.,  100.,  100.],\n               [   0.,   25.,   25.,   25.,    0.],\n               [   0.,    0.,    0.,    0.,    0.],\n               [   0.,    0.,    0.,    0.,    0.],\n               [   0.,    0.,    0.,    0.,    0.]])\n        \n        >>> u = zeros((5, 5), 'd'); u[0,:] = 100\n        >>> weave.blitz (expr)\n        >>> u\n        array([[ 100.  ,  100.       ,  100.       ,  100.       ,  100. ],\n               [   0.  ,   25.       ,   31.25     ,   32.8125   ,    0. ],\n               [   0.  ,    6.25     ,    9.375    ,   10.546875 ,    0. ],\n               [   0.  ,    1.5625   ,    2.734375 ,    3.3203125,    0. ],\n               [   0.  ,    0.       ,    0.       ,    0.       ,    0. ]])    \n        
    \n \n You can prevent this behavior by using a temporary array.\n \n
    \n        >>> u = zeros((5, 5), 'd'); u[0,:] = 100\n        >>> temp = zeros((4, 4), 'd');\n        >>> expr = \"temp = (u[0:-2, 1:-1] + u[2:, 1:-1] + \"\\\n        ...        \"u[1:-1,0:-2] + u[1:-1, 2:])*0.25;\"\\\n        ...        \"u[1:-1,1:-1] = temp\"\n        >>> weave.blitz (expr)\n        >>> u\n        array([[ 100.,  100.,  100.,  100.,  100.],\n               [   0.,   25.,   25.,   25.,    0.],\n               [   0.,    0.,    0.,    0.,    0.],\n               [   0.,    0.,    0.,    0.,    0.],\n               [   0.,    0.,    0.,    0.,    0.]])\n        
    \n \n
  8. \n
  9. \nOne other point deserves mention lest people be confused. \nweave.blitz is not a general purpose Python->C compiler. It \nonly works for expressions that contain Numeric arrays and/or \nPython scalar values. This focused scope concentrates effort on the \ncompuationally intensive regions of the program and sidesteps the difficult \nissues associated with a general purpose Python->C compiler.\n
  10. \n
\n\n\n

Numeric efficiency issues: What compilation buys you

\n\nSome might wonder why compiling Numeric expressions to C++ is beneficial since \noperations on Numeric array operations are already executed within C loops. \nThe problem is that anything other than the simplest expression are executed in \nless than optimal fashion. Consider the following Numeric expression:\n\n
\n    a = 1.2 * b + c * d\n    
\n \nWhen Numeric calculates the value for the 2d array, a, it does \nthe following steps:\n\n
\n    temp1 = 1.2 * b\n    temp2 = c * d\n    a = temp1 + temp2\n    
\n \nTwo things to note. Since c is an (perhaps large) array, a large \ntemporary array must be created to store the results of 1.2 * b. \nThe same is true for temp2. Allocation is slow. The second thing \nis that we have 3 loops executing, one to calculate temp1, one for \ntemp2 and one for adding them up. A C loop for the same problem \nmight look like:\n\n
\n    for(int i = 0; i < M; i++)\n        for(int j = 0; j < N; j++)\n            a[i,j] = 1.2 * b[i,j] + c[i,j] * d[i,j]\n    
\n \nHere, the 3 loops have been fused into a single loop and there is no longer\na need for a temporary array. This provides a significant speed improvement\nover the above example (write me and tell me what you get). \n

\nSo, converting Numeric expressions into C/C++ loops that fuse the loops and \neliminate temporary arrays can provide big gains. The goal then,is to convert \nNumeric expression to C/C++ loops, compile them in an extension module, and \nthen call the compiled extension function. The good news is that there is an \nobvious correspondence between the Numeric expression above and the C loop. The \nbad news is that Numeric is generally much more powerful than this simple \nexample illustrates and handling all possible indexing possibilities results in \nloops that are less than straight forward to write. (take a peak in Numeric for \nconfirmation). Luckily, there are several available tools that simplify the \nprocess.\n\n\n

The Tools

\n\nweave.blitz relies heavily on several remarkable tools. On the \nPython side, the main facilitators are Jermey Hylton's parser module and Jim \nHuginin's Numeric module. On the compiled language side, Todd Veldhuizen's \nblitz++ array library, written in C++ (shhhh. don't tell David Beazley), does \nthe heavy lifting. Don't assume that, because it's C++, it's much slower than C \nor Fortran. Blitz++ uses a jaw dropping array of template techniques \n(metaprogramming, template expression, etc) to convert innocent looking and \nreadable C++ expressions into to code that usually executes within a few \npercentage points of Fortran code for the same problem. This is good. \nUnfortunately all the template raz-ma-taz is very expensive to compile, so the \n200 line extension modules often take 2 or more minutes to compile. This isn't so \ngood. weave.blitz works to minimize this issue by remembering \nwhere compiled modules live and reusing them instead of re-compiling every time \na program is re-run.\n\n\n

Parser

\nTearing Numeric expressions apart, examining the pieces, and then rebuilding \nthem as C++ (blitz) expressions requires a parser of some sort. I can imagine \nsomeone attacking this problem with regular expressions, but it'd likely be \nugly and fragile. Amazingly, Python solves this problem for us. It actually \nexposes its parsing engine to the world through the parser module. \nThe following fragment creates an Abstract Syntax Tree (AST) object for the \nexpression and then converts to a (rather unpleasant looking) deeply nested list \nrepresentation of the tree. \n \n
\n    >>> import parser\n    >>> import scipy.weave.misc\n    >>> ast = parser.suite(\"a = b * c + d\")\n    >>> ast_list = ast.tolist()\n    >>> sym_list = scipy.weave.misc.translate_symbols(ast_list)\n    >>> pprint.pprint(sym_list)\n    ['file_input',\n     ['stmt',\n      ['simple_stmt',\n       ['small_stmt',\n        ['expr_stmt',\n         ['testlist',\n          ['test',\n           ['and_test',\n            ['not_test',\n             ['comparison',\n              ['expr',\n               ['xor_expr',\n                ['and_expr',\n                 ['shift_expr',\n                  ['arith_expr',\n                   ['term',\n                    ['factor', ['power', ['atom', ['NAME', 'a']]]]]]]]]]]]]]],\n         ['EQUAL', '='],\n         ['testlist',\n          ['test',\n           ['and_test',\n            ['not_test',\n             ['comparison',\n              ['expr',\n               ['xor_expr',\n                ['and_expr',\n                 ['shift_expr',\n                  ['arith_expr',\n                   ['term',\n                    ['factor', ['power', ['atom', ['NAME', 'b']]]],\n                    ['STAR', '*'],\n                    ['factor', ['power', ['atom', ['NAME', 'c']]]]],\n                   ['PLUS', '+'],\n                   ['term',\n                    ['factor', ['power', ['atom', ['NAME', 'd']]]]]]]]]]]]]]]]],\n       ['NEWLINE', '']]],\n     ['ENDMARKER', '']]\n    
\n\nDespite its looks, with some tools developed by Jermey H., its possible\nto search these trees for specific patterns (sub-trees), extract the \nsub-tree, manipulate them converting python specific code fragments\nto blitz code fragments, and then re-insert it in the parse tree. The parser\nmodule documentation has some details on how to do this. Traversing the \nnew blitzified tree, writing out the terminal symbols as you go, creates\nour new blitz++ expression string.\n\n \n

Blitz and Numeric

\nThe other nice discovery in the project is that the data structure used\nfor Numeric arrays and blitz arrays is nearly identical. Numeric stores\n\"strides\" as byte offsets and blitz stores them as element offsets, but\nother than that, they are the same. Further, most of the concept and\ncapabilities of the two libraries are remarkably similar. It is satisfying \nthat two completely different implementations solved the problem with \nsimilar basic architectures. It is also fortitous. The work involved in \nconverting Numeric expressions to blitz expressions was greatly diminished.\nAs an example, consider the code for slicing an array in Python with a\nstride:\n\n
\n    >>> a = b[0:4:2] + c\n    >>> a\n    [0,2,4]\n    
\n\n\nIn Blitz it is as follows:\n\n
\n    Array<2,int> b(10);\n    Array<2,int> c(3);\n    // ...\n    Array<2,int> a = b(Range(0,3,2)) + c;\n    
\n\n\nHere the range object works exactly like Python slice objects with the exception\nthat the top index (3) is inclusive where as Python's (4) is exclusive. Other \ndifferences include the type declaraions in C++ and parentheses instead of \nbrackets for indexing arrays. Currently, weave.blitz handles the \ninclusive/exclusive issue by subtracting one from upper indices during the\ntranslation. An alternative that is likely more robust/maintainable in the \nlong run, is to write a PyRange class that behaves like Python's range. \nThis is likely very easy.\n

\nThe stock blitz also doesn't handle negative indices in ranges. The current \nimplementation of the blitz() has a partial solution to this \nproblem. It calculates and index that starts with a '-' sign by subtracting it \nfrom the maximum index in the array so that:\n\n

\n                    upper index limit\n                        /-----\\\n    b[:-1] -> b(Range(0,Nb[0]-1-1))\n    
\n\nThis approach fails, however, when the top index is calculated from other \nvalues. In the following scenario, if i+j evaluates to a negative \nvalue, the compiled code will produce incorrect results and could even core-\ndump. Right now, all calculated indices are assumed to be positive.\n \n
\n    b[:i-j] -> b(Range(0,i+j))\n    
\n\nA solution is to calculate all indices up front using if/then to handle the\n+/- cases. This is a little work and results in more code, so it hasn't been\ndone. I'm holding out to see if blitz++ can be modified to handle negative\nindexing, but haven't looked into how much effort is involved yet. While it \nneeds fixin', I don't think there is a ton of code where this is an issue.\n

\nThe actual translation of the Python expressions to blitz expressions is \ncurrently a two part process. First, all x:y:z slicing expression are removed\nfrom the AST, converted to slice(x,y,z) and re-inserted into the tree. Any\nmath needed on these expressions (subtracting from the \nmaximum index, etc.) are also preformed here. _beg and _end are used as special\nvariables that are defined as blitz::fromBegin and blitz::toEnd.\n\n

\n    a[i+j:i+j+1,:] = b[2:3,:] \n    
\n\nbecomes a more verbose:\n \n
\n    a[slice(i+j,i+j+1),slice(_beg,_end)] = b[slice(2,3),slice(_beg,_end)]\n    
\n \nThe second part does a simple string search/replace to convert to a blitz \nexpression with the following translations:\n\n
\n    slice(_beg,_end) -> _all  # not strictly needed, but cuts down on code.\n    slice            -> blitz::Range\n    [                -> (\n    ]                -> )\n    _stp             -> 1\n    
\n\n_all is defined in the compiled function as \nblitz::Range.all(). These translations could of course happen \ndirectly in the syntax tree. But the string replacement is slightly easier. \nNote that name spaces are maintained in the C++ code to lessen the likelyhood \nof name clashes. Currently no effort is made to detect name clashes. A good \nrule of thumb is don't use values that start with '_' or 'py_' in compiled \nexpressions and you'll be fine.\n\n \n

Type definitions and coersion

\n\nSo far we've glossed over the dynamic vs. static typing issue between Python \nand C++. In Python, the type of value that a variable holds can change\nthrough the course of program execution. C/C++, on the other hand, forces you\nto declare the type of value a variables will hold prior at compile time.\nweave.blitz handles this issue by examining the types of the\nvariables in the expression being executed, and compiling a function for those\nexplicit types. For example:\n\n
\n    a = ones((5,5),Float32)\n    b = ones((5,5),Float32)\n    weave.blitz(\"a = a + b\")\n    
\n\nWhen compiling this expression to C++, weave.blitz sees that the\nvalues for a and b in the local scope have type Float32, or 'float'\non a 32 bit architecture. As a result, it compiles the function using \nthe float type (no attempt has been made to deal with 64 bit issues).\nIt also goes one step further. If all arrays have the same type, a templated\nversion of the function is made and instantiated for float, double, \ncomplex, and complex arrays. Note: This feature has been \nremoved from the current version of the code. Each version will be compiled\nseparately \n

\nWhat happens if you call a compiled function with array types that are \ndifferent than the ones for which it was originally compiled? No biggie, you'll \njust have to wait on it to compile a new version for your new types. This \ndoesn't overwrite the old functions, as they are still accessible. See the \ncatalog section in the inline() documentation to see how this is handled. \nSuffice to say, the mechanism is transparent to the user and behaves \nlike dynamic typing with the occasional wait for compiling newly typed \nfunctions.\n

\nWhen working with combined scalar/array operations, the type of the array is \nalways used. This is similar to the savespace flag that was recently \nadded to Numeric. This prevents issues with the following expression perhaps \nunexpectedly being calculated at a higher (more expensive) precision that can \noccur in Python:\n\n

\n    >>> a = array((1,2,3),typecode = Float32)\n    >>> b = a * 2.1 # results in b being a Float64 array.\n    
\n \nIn this example, \n\n
\n    >>> a = ones((5,5),Float32)\n    >>> b = ones((5,5),Float32)\n    >>> weave.blitz(\"b = a * 2.1\")\n    
\n \nthe 2.1 is cast down to a float before carrying out \nthe operation. If you really want to force the calculation to be a \ndouble, define a and b as \ndouble arrays.\n

\nOne other point of note. Currently, you must include both the right hand side \nand left hand side (assignment side) of your equation in the compiled \nexpression. Also, the array being assigned to must be created prior to calling \nweave.blitz. I'm pretty sure this is easily changed so that a \ncompiled_eval expression can be defined, but no effort has been made to \nallocate new arrays (and decern their type) on the fly.\n\n \n

Cataloging Compiled Functions

\n\nSee the Cataloging functions section in the \nweave.inline() documentation.\n\n \n

Checking Array Sizes

\n\nSurprisingly, one of the big initial problems with compiled code was making\nsure all the arrays in an operation were of compatible type. The following\ncase is trivially easy:\n\n
\n    a = b + c\n    
\n \nIt only requires that arrays a, b, and c \nhave the same shape. However, expressions like:\n\n
\n    a[i+j:i+j+1,:] = b[2:3,:] + c\n    
\n\nare not so trivial. Since slicing is involved, the size of the slices, not the \ninput arrays must be checked. Broadcasting complicates things further because \narrays and slices with different dimensions and shapes may be compatible for \nmath operations (broadcasting isn't yet supported by \nweave.blitz). Reductions have a similar effect as their \nresults are different shapes than their input operand. The binary operators in \nNumeric compare the shapes of their two operands just before they operate on \nthem. This is possible because Numeric treats each operation independently. \nThe intermediate (temporary) arrays created during sub-operations in an \nexpression are tested for the correct shape before they are combined by another \noperation. Because weave.blitz fuses all operations into a \nsingle loop, this isn't possible. The shape comparisons must be done and \nguaranteed compatible before evaluating the expression.\n

\nThe solution chosen converts input arrays to \"dummy arrays\" that only represent \nthe dimensions of the arrays, not the data. Binary operations on dummy arrays \ncheck that input array sizes are comptible and return a dummy array with the \nsize correct size. Evaluating an expression of dummy arrays traces the \nchanging array sizes through all operations and fails if incompatible array \nsizes are ever found. \n

\nThe machinery for this is housed in weave.size_check. It \nbasically involves writing a new class (dummy array) and overloading it math \noperators to calculate the new sizes correctly. All the code is in Python and \nthere is a fair amount of logic (mainly to handle indexing and slicing) so the \noperation does impose some overhead. For large arrays (ie. 50x50x50), the \noverhead is negligible compared to evaluating the actual expression. For small \narrays (ie. 16x16), the overhead imposed for checking the shapes with this \nmethod can cause the weave.blitz to be slower than evaluating \nthe expression in Python. \n

\nWhat can be done to reduce the overhead? (1) The size checking code could be \nmoved into C. This would likely remove most of the overhead penalty compared \nto Numeric (although there is also some calling overhead), but no effort has \nbeen made to do this. (2) You can also call weave.blitz with\ncheck_size=0 and the size checking isn't done. However, if the \nsizes aren't compatible, it can cause a core-dump. So, foregoing size_checking\nisn't advisable until your code is well debugged.\n\n \n

Creating the Extension Module

\n\nweave.blitz uses the same machinery as \nweave.inline to build the extension module. The only difference\nis the code included in the function is automatically generated from the\nNumeric array expression instead of supplied by the user.\n\n\n

Extension Modules

\nweave.inline and weave.blitz are high level tools\nthat generate extension modules automatically. Under the covers, they use several\nclasses from weave.ext_tools to help generate the extension module.\nThe main two classes are ext_module and ext_function (I'd\nlike to add ext_class and ext_method also). These classes\nsimplify the process of generating extension modules by handling most of the \"boiler\nplate\" code automatically.\n\n\nNote: inline actually sub-classes weave.ext_tools.ext_function \nto generate slightly different code than the standard ext_function.\nThe main difference is that the standard class converts function arguments to\nC types, while inline always has two arguments, the local and global dicts, and\nthe grabs the variables that need to be convereted to C from these.\n\n\n\n

A Simple Example

\nThe following simple example demonstrates how to build an extension module within\na Python function:\n\n
\n    # examples/increment_example.py\n    from weave import ext_tools\n    \n    def build_increment_ext():\n        \"\"\" Build a simple extension with functions that increment numbers.\n            The extension will be built in the local directory.\n        \"\"\"        \n        mod = ext_tools.ext_module('increment_ext')\n    \n        a = 1 # effectively a type declaration for 'a' in the \n              # following functions.\n    \n        ext_code = \"return_val = Py::new_reference_to(Py::Int(a+1));\"    \n        func = ext_tools.ext_function('increment',ext_code,['a'])\n        mod.add_function(func)\n        \n        ext_code = \"return_val = Py::new_reference_to(Py::Int(a+2));\"    \n        func = ext_tools.ext_function('increment_by_2',ext_code,['a'])\n        mod.add_function(func)\n                \n        mod.compile()\n    
\n\n\nThe function build_increment_ext() creates an extension module \nnamed increment_ext and compiles it to a shared library (.so or \n.pyd) that can be loaded into Python.. increment_ext contains two \nfunctions, increment and increment_by_2. \n\nThe first line of build_increment_ext(),\n\n
\n        mod = ext_tools.ext_module('increment_ext') \n    
\n\ncreates an ext_module instance that is ready to have \next_function instances added to it. ext_function \ninstances are created much with a calling convention similar to \nweave.inline(). The most common call includes a C/C++ code \nsnippet and a list of the arguments for the function. The following\n\n
\n        ext_code = \"return_val = Py::new_reference_to(Py::Int(a+1));\"    \n        func = ext_tools.ext_function('increment',ext_code,['a'])\n    
\n \ncreates a C/C++ extension function that is equivalent to the following Python\nfunction:\n\n
\n        def increment(a):\n            return a + 1\n    
\n\nA second method is also added to the module and then,\n\n
\n        mod.compile()\n    
\n\nis called to build the extension module. By default, the module is created\nin the current working directory.\n\nThis example is available in the examples/increment_example.py file\nfound in the weave directory. At the bottom of the file in the\nmodule's \"main\" program, an attempt to import increment_ext without\nbuilding it is made. If this fails (the module doesn't exist in the PYTHONPATH), \nthe module is built by calling build_increment_ext(). This approach\nonly takes the time consuming ( a few seconds for this example) process of building\nthe module if it hasn't been built before.\n\n
\n    if __name__ == \"__main__\":\n        try:\n            import increment_ext\n        except ImportError:\n            build_increment_ext()\n            import increment_ext\n        a = 1\n        print 'a, a+1:', a, increment_ext.increment(a)\n        print 'a, a+2:', a, increment_ext.increment_by_2(a)           \n    
\n\n\nNote: If we were willing to always pay the penalty of building the C++ code for \na module, we could store the md5 checksum of the C++ code along with some \ninformation about the compiler, platform, etc. Then, \next_module.compile() could try importing the module before it actually\ncompiles it, check the md5 checksum and other meta-data in the imported module\nwith the meta-data of the code it just produced and only compile the code if\nthe module didn't exist or the meta-data didn't match. This would reduce the\nabove code to:\n\n
\n    if __name__ == \"__main__\":\n        build_increment_ext()\n\n        a = 1\n        print 'a, a+1:', a, increment_ext.increment(a)\n        print 'a, a+2:', a, increment_ext.increment_by_2(a)           \n    
\n\nNote: There would always be the overhead of building the C++ code, but it would only actually compile the code once. You pay a little in overhead and get cleaner\n\"import\" code. Needs some thought.\n\n

\n\nIf you run increment_example.py from the command line, you get\nthe following:\n\n

\n    [eric@n0]$ python increment_example.py\n    a, a+1: 1 2\n    a, a+2: 1 3\n    
\n\nIf the module didn't exist before it was run, the module is created. If it did\nexist, it is just imported and used.\n\n\n

Fibonacci Example

\nexamples/fibonacci.py provides a little more complex example of \nhow to use ext_tools. Fibonacci numbers are a series of numbers \nwhere each number in the series is the sum of the previous two: 1, 1, 2, 3, 5, \n8, etc. Here, the first two numbers in the series are taken to be 1. One \napproach to calculating Fibonacci numbers uses recursive function calls. In \nPython, it might be written as:\n\n
\n    def fib(a):\n        if a <= 2:\n            return 1\n        else:\n            return fib(a-2) + fib(a-1)\n    
\n\nIn C, the same function would look something like this:\n\n
\n     int fib(int a)\n     {                   \n         if(a <= 2)\n             return 1;\n         else\n             return fib(a-2) + fib(a-1);  \n     }                      \n    
\n\nRecursion is much faster in C than in Python, so it would be beneficial\nto use the C version for fibonacci number calculations instead of the\nPython version. We need an extension function that calls this C function\nto do this. This is possible by including the above code snippet as \n\"support code\" and then calling it from the extension function. Support \ncode snippets (usually structure definitions, helper functions and the like)\nare inserted into the extension module C/C++ file before the extension\nfunction code. Here is how to build the C version of the fibonacci number\ngenerator:\n\n
\ndef build_fibonacci():\n    \"\"\" Builds an extension module with fibonacci calculators.\n    \"\"\"\n    mod = ext_tools.ext_module('fibonacci_ext')\n    a = 1 # this is effectively a type declaration\n    \n    # recursive fibonacci in C \n    fib_code = \"\"\"\n                   int fib1(int a)\n                   {                   \n                       if(a <= 2)\n                           return 1;\n                       else\n                           return fib1(a-2) + fib1(a-1);  \n                   }                         \n               \"\"\"\n    ext_code = \"\"\"\n                   int val = fib1(a);\n                   return_val = Py::new_reference_to(Py::Int(val));\n               \"\"\"    \n    fib = ext_tools.ext_function('fib',ext_code,['a'])\n    fib.customize.add_support_code(fib_code)\n    mod.add_function(fib)\n\n    mod.compile()\n\n    
\n\nXXX More about custom_info, and what xxx_info instances are good for.\n\n

\n\nNote: recursion is not the fastest way to calculate fibonacci numbers, but this \napproach serves nicely for this example.\n\n

\n\n

Customizing Type Conversions -- Type Factories

\nnot written\n\n

Things I wish weave did

\n\nIt is possible to get name clashes if you uses a variable name that is already defined\nin a header automatically included (such as stdio.h) For instance, if you\ntry to pass in a variable named stdout, you'll get a cryptic error report\ndue to the fact that stdio.h also defines the name. weave\nshould probably try and handle this in some way.\n\nOther things...", + "methods": [], + "methods_before": [], + "changed_methods": [], + "nloc": null, + "complexity": null, + "token_count": null, + "diff_parsed": { + "added": [ + " binary search   1.50 ", + " fibonacci (recursive)  82.10 ", + " fibonacci (loop)   9.17 ", + " return None   0.14 ", + " map   1.20 ", + " dictionary sort   2.54 ", + " vector quantization  37.40 ", + " a = b + c 512x512   3.05 ", + " a = b + c + d 512x512   4.59 ", + " 5 pt avg. filter, 2D Image 512x512   9.01 ", + " Electromagnetics (FDTD) 100x100x100   8.61 " + ], + "deleted": [ + " binary search   1.50 ", + " fibonacci (recursive)  82.10 ", + " fibonacci (loop)   9.17 ", + " return None   0.14 ", + " map   1.20 ", + " dictionary sort   2.54 ", + " vector quantization  37.40 ", + " a = b + c 512x512   3.05 ", + " a = b + c + d 512x512   4.59 ", + " 5 pt avg. filter, 2D Image 512x512   9.01 ", + " Electromagnetics (FDTD) 100x100x100   8.61 " + ] + } + } + ] + }, + { + "hash": "956709dd991cfe4c15a80657c83c4318834525cb", + "msg": "Introduced NotFoundError exceptions with informative doc strings", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-02-28T22:23:14+00:00", + "author_timezone": 0, + "committer_date": "2002-02-28T22:23:14+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "af4d15bf79a35239984fdb5d65b3970dc497474f" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 2, + "insertions": 37, + "lines": 39, + "files": 3, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "scipy_distutils/atlas_info.py", + "new_path": "scipy_distutils/atlas_info.py", + "filename": "atlas_info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -34,7 +34,7 @@ def get_atlas_info():\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n \n-def unix_atlas_directory(platform):\n+def unix_atlas_directory(platform): #OBSOLETE (see system_info)\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n", + "added_lines": 1, + "deleted_lines": 1, + "source_code": "import sys, os\nfrom misc_util import get_path\nfrom system_info import get_info\n\nlibrary_path = None\n\ndef dir_exists(dir_list):\n if dir_list:\n if os.path.exists(dir_list[0]):\n return 1\n return 0\n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not dir_exists(library_path):\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n #XXX: need to use `atlas_info = get_info('atlas')'\n atlas_info = {'libraries':lapack_libraries,\n 'library_dirs':atlas_library_dirs}\n return atlas_info\n else:\n atlas_info = get_info('atlas')\n return atlas_info\n\n if not dir_exists(library_path):\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform): #OBSOLETE (see system_info)\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", + "source_code_before": "import sys, os\nfrom misc_util import get_path\nfrom system_info import get_info\n\nlibrary_path = None\n\ndef dir_exists(dir_list):\n if dir_list:\n if os.path.exists(dir_list[0]):\n return 1\n return 0\n\ndef get_atlas_info():\n if sys.platform == 'win32':\n if not dir_exists(library_path):\n atlas_library_dirs=['C:\\\\atlas\\\\WinNT_PIIISSE1']\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['f77blas', 'cblas', 'atlas', 'g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n #XXX: need to use `atlas_info = get_info('atlas')'\n atlas_info = {'libraries':lapack_libraries,\n 'library_dirs':atlas_library_dirs}\n return atlas_info\n else:\n atlas_info = get_info('atlas')\n return atlas_info\n\n if not dir_exists(library_path):\n atlas_library_dirs = unix_atlas_directory(sys.platform)\n else:\n atlas_library_dirs = library_path\n blas_libraries = ['cblas','f77blas','atlas','g2c']\n lapack_libraries = ['lapack'] + blas_libraries\n return blas_libraries, lapack_libraries, atlas_library_dirs\n\ndef unix_atlas_directory(platform):\n \"\"\" Search a list of common locations looking for the atlas directory.\n \n Return None if the directory isn't found, otherwise return the\n directory name. This isn't very sophisticated right now. I can\n imagine doing an ftp to our server on platforms that we know about.\n \n Atlas is a highly optimized version of lapack and blas that is fast\n on almost all platforms.\n \"\"\"\n result = [] #None\n # do a little looking for the linalg directory for atlas libraries\n #path = get_path(__name__)\n #local_atlas0 = os.path.join(path,platform,'atlas')\n #local_atlas1 = os.path.join(path,platform[:-1],'atlas')\n \n # first look for a system defined atlas directory\n dir_search = ['/usr/local/lib/atlas','/usr/lib/atlas']#,\n # local_atlas0, local_atlas1]\n for directory in dir_search:\n if os.path.exists(directory):\n result = [directory]\n # we should really do an ftp search or something like that at this point.\n return result \n", + "methods": [ + { + "name": "dir_exists", + "long_name": "dir_exists( dir_list )", + "filename": "atlas_info.py", + "nloc": 5, + "complexity": 3, + "token_count": 25, + "parameters": [ + "dir_list" + ], + "start_line": 7, + "end_line": 11, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "get_atlas_info", + "long_name": "get_atlas_info( )", + "filename": "atlas_info.py", + "nloc": 21, + "complexity": 4, + "token_count": 113, + "parameters": [], + "start_line": 13, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "unix_atlas_directory", + "long_name": "unix_atlas_directory( platform )", + "filename": "atlas_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "platform" + ], + "start_line": 37, + "end_line": 60, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "dir_exists", + "long_name": "dir_exists( dir_list )", + "filename": "atlas_info.py", + "nloc": 5, + "complexity": 3, + "token_count": 25, + "parameters": [ + "dir_list" + ], + "start_line": 7, + "end_line": 11, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "get_atlas_info", + "long_name": "get_atlas_info( )", + "filename": "atlas_info.py", + "nloc": 21, + "complexity": 4, + "token_count": 113, + "parameters": [], + "start_line": 13, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 0 + }, + { + "name": "unix_atlas_directory", + "long_name": "unix_atlas_directory( platform )", + "filename": "atlas_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "platform" + ], + "start_line": 37, + "end_line": 60, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "unix_atlas_directory", + "long_name": "unix_atlas_directory( platform )", + "filename": "atlas_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 39, + "parameters": [ + "platform" + ], + "start_line": 37, + "end_line": 60, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 0 + } + ], + "nloc": 37, + "complexity": 10, + "token_count": 195, + "diff_parsed": { + "added": [ + "def unix_atlas_directory(platform): #OBSOLETE (see system_info)" + ], + "deleted": [ + "def unix_atlas_directory(platform):" + ] + } + }, + { + "old_path": "scipy_distutils/command/run_f2py.py", + "new_path": "scipy_distutils/command/run_f2py.py", + "filename": "run_f2py.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -9,6 +9,7 @@\n \n from distutils.dep_util import newer\n from scipy_distutils.core import Command\n+from scipy_distutils.system_info import F2pyNotFoundError\n \n import re,os\n \n@@ -76,7 +77,10 @@ def f2py_sources (self, sources, ext):\n one from the Fortran files in 'sources'.\n \"\"\"\n import string\n- import f2py2e\n+ try:\n+ import f2py2e\n+ except ImportError:\n+ raise F2pyNotFoundError,F2pyNotFoundError.__doc__\n # f2py generates the following files for an extension module\n # with a name :\n # module.c\n", + "added_lines": 5, + "deleted_lines": 1, + "source_code": "\"\"\"distutils.command.run_f2py\n\nImplements the Distutils 'run_f2py' command.\n\"\"\"\n\n# created 2002/01/09, Pearu Peterson \n\n__revision__ = \"$Id$\"\n\nfrom distutils.dep_util import newer\nfrom scipy_distutils.core import Command\nfrom scipy_distutils.system_info import F2pyNotFoundError\n\nimport re,os\n\nmodule_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',re.I).match\nuser_module_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?__user__[\\w_]*)',re.I).match\nfortran_ext_re = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\n\nclass run_f2py(Command):\n\n description = \"\\\"run_f2py\\\" runs f2py that builds Fortran wrapper sources\"\\\n \"(C and occasionally Fortran).\"\n\n user_options = [('build-dir=', 'b',\n \"directory to build fortran wrappers to\"),\n ('debug-capi', None,\n \"generate C/API extensions with debugging code\"),\n ('no-wrap-functions', None,\n \"do not generate wrappers for Fortran functions,etc.\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ]\n\n def initialize_options (self):\n self.build_dir = None\n self.debug_capi = None\n self.force = None\n self.no_wrap_functions = None\n self.f2py_options = []\n # initialize_options()\n\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_dir'),\n ('force', 'force'))\n\n self.f2py_options.extend(['--build-dir',self.build_dir])\n\n if self.debug_capi is not None:\n self.f2py_options.append('--debug-capi')\n if self.no_wrap_functions is not None:\n self.f2py_options.append('--no-wrap-functions')\n\n # finalize_options()\n\n def run (self):\n if self.distribution.has_ext_modules():\n # XXX: might need also\n # build_flib = self.get_finalized_command('build_flib')\n # ...\n # for getting extra f2py_options that are specific to\n # a given fortran compiler.\n for ext in self.distribution.ext_modules:\n ext.sources = self.f2py_sources(ext.sources,ext)\n self.fortran_sources_to_flib(ext)\n # run()\n\n def f2py_sources (self, sources, ext):\n\n \"\"\"Walk the list of source files in 'sources', looking for f2py\n interface (.pyf) files. Run f2py on all that are found, and\n return a modified 'sources' list with f2py source files replaced\n by the generated C (or C++) and Fortran files.\n If 'sources' contains not .pyf files, then create a temporary\n one from the Fortran files in 'sources'.\n \"\"\"\n import string\n try:\n import f2py2e\n except ImportError:\n raise F2pyNotFoundError,F2pyNotFoundError.__doc__\n # f2py generates the following files for an extension module\n # with a name :\n # module.c\n # -f2pywrappers.f [occasionally]\n # In addition, /src/fortranobject.{c,h} are needed\n # for building f2py generated extension modules.\n # It is assumed that one pyf file contains defintions for exactly\n # one extension module.\n\n target_dir = self.build_dir\n \n new_sources = []\n f2py_sources = []\n fortran_sources = []\n f2py_targets = {}\n f2py_fortran_targets = {}\n target_ext = 'module.c'\n fortran_target_ext = '-f2pywrappers.f'\n\n for source in sources:\n (base, source_ext) = os.path.splitext(source)\n (source_dir, base) = os.path.split(base)\n if source_ext == \".pyf\": # f2py interface file\n # get extension module name\n f = open(source)\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = module_name_re(line)\n if m:\n if user_module_name_re(line): # skip *__user__* names\n continue\n base = m.group('name')\n break\n f.close()\n if ext.name == 'untitled':\n ext.name = base\n if base != string.split(ext.name,'.')[-1]:\n # XXX: Should we do here more than just warn?\n self.warn('%s provides %s but this extension is %s' \\\n % (source,`base`,`ext.name`))\n target_file = os.path.join(target_dir,base+target_ext)\n fortran_target_file = os.path.join(target_dir,base+fortran_target_ext)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n f2py_fortran_targets[source] = fortran_target_file\n elif fortran_ext_re(source_ext):\n fortran_sources.append(source) \n else:\n new_sources.append(source)\n\n if not (f2py_sources or fortran_sources):\n return new_sources\n\n # make sure the target dir exists\n from distutils.dir_util import mkpath\n mkpath(target_dir)\n\n if not f2py_sources:\n # creating a temporary pyf file from fortran sources\n pyf_target = os.path.join(target_dir,ext.name+'.pyf')\n pyf_target_file = os.path.join(target_dir,ext.name+target_ext)\n pyf_fortran_target_file = os.path.join(target_dir,ext.name+fortran_target_ext)\n f2py_opts2 = ['-m',ext.name,'-h',pyf_target,'--overwrite-signature']\n for source in fortran_sources:\n if newer(source,pyf_target) or self.force:\n self.announce(\"f2py-ing a new %s\" % (pyf_target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_opts2,' '))\n f2py2e.run_main(fortran_sources + f2py_opts2)\n break\n f2py_sources.append(pyf_target)\n f2py_targets[pyf_target] = pyf_target_file\n f2py_fortran_targets[pyf_target] = pyf_fortran_target_file\n\n new_sources.extend(fortran_sources)\n\n if len(f2py_sources) > 1:\n self.warn('Only one .pyf file can be used per Extension but got %s.'\\\n % (len(f2py_sources)))\n\n # a bit of a hack, but I think it'll work. Just include one of\n # the fortranobject.c files that was copied into most \n d = os.path.dirname(f2py2e.__file__)\n new_sources.append(os.path.join(d,'src','fortranobject.c'))\n ext.include_dirs.append(os.path.join(d,'src'))\n\n f2py_options = ext.f2py_options + self.f2py_options\n\n for source in f2py_sources:\n target = f2py_targets[source]\n fortran_target = f2py_fortran_targets[source]\n if newer(source,target) or self.force:\n self.announce(\"f2py-ing %s to %s\" % (source, target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_options,' '))\n f2py2e.run_main(f2py_options + [source])\n new_sources.append(target)\n if os.path.exists(fortran_target):\n new_sources.append(fortran_target)\n return new_sources\n\n # f2py_sources ()\n\n def fortran_sources_to_flib(self, ext):\n \"\"\"\n Extract fortran files from ext.sources and append them to\n fortran_libraries item having the same name as ext.\n \"\"\"\n sources = []\n f_files = []\n\n for file in ext.sources:\n if fortran_ext_re(file):\n f_files.append(file)\n else:\n sources.append(file)\n if not f_files:\n return\n\n ext.sources = sources\n\n if self.distribution.fortran_libraries is None:\n self.distribution.fortran_libraries = []\n fortran_libraries = self.distribution.fortran_libraries\n\n name = ext.name\n flib = None\n for n,d in fortran_libraries:\n if n == name:\n flib = d\n break\n if flib is None:\n flib = {'sources':[]}\n fortran_libraries.append((name,flib))\n\n flib['sources'].extend(f_files)\n \n# class run_f2py\n", + "source_code_before": "\"\"\"distutils.command.run_f2py\n\nImplements the Distutils 'run_f2py' command.\n\"\"\"\n\n# created 2002/01/09, Pearu Peterson \n\n__revision__ = \"$Id$\"\n\nfrom distutils.dep_util import newer\nfrom scipy_distutils.core import Command\n\nimport re,os\n\nmodule_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',re.I).match\nuser_module_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?__user__[\\w_]*)',re.I).match\nfortran_ext_re = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\n\nclass run_f2py(Command):\n\n description = \"\\\"run_f2py\\\" runs f2py that builds Fortran wrapper sources\"\\\n \"(C and occasionally Fortran).\"\n\n user_options = [('build-dir=', 'b',\n \"directory to build fortran wrappers to\"),\n ('debug-capi', None,\n \"generate C/API extensions with debugging code\"),\n ('no-wrap-functions', None,\n \"do not generate wrappers for Fortran functions,etc.\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ]\n\n def initialize_options (self):\n self.build_dir = None\n self.debug_capi = None\n self.force = None\n self.no_wrap_functions = None\n self.f2py_options = []\n # initialize_options()\n\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_dir'),\n ('force', 'force'))\n\n self.f2py_options.extend(['--build-dir',self.build_dir])\n\n if self.debug_capi is not None:\n self.f2py_options.append('--debug-capi')\n if self.no_wrap_functions is not None:\n self.f2py_options.append('--no-wrap-functions')\n\n # finalize_options()\n\n def run (self):\n if self.distribution.has_ext_modules():\n # XXX: might need also\n # build_flib = self.get_finalized_command('build_flib')\n # ...\n # for getting extra f2py_options that are specific to\n # a given fortran compiler.\n for ext in self.distribution.ext_modules:\n ext.sources = self.f2py_sources(ext.sources,ext)\n self.fortran_sources_to_flib(ext)\n # run()\n\n def f2py_sources (self, sources, ext):\n\n \"\"\"Walk the list of source files in 'sources', looking for f2py\n interface (.pyf) files. Run f2py on all that are found, and\n return a modified 'sources' list with f2py source files replaced\n by the generated C (or C++) and Fortran files.\n If 'sources' contains not .pyf files, then create a temporary\n one from the Fortran files in 'sources'.\n \"\"\"\n import string\n import f2py2e\n # f2py generates the following files for an extension module\n # with a name :\n # module.c\n # -f2pywrappers.f [occasionally]\n # In addition, /src/fortranobject.{c,h} are needed\n # for building f2py generated extension modules.\n # It is assumed that one pyf file contains defintions for exactly\n # one extension module.\n\n target_dir = self.build_dir\n \n new_sources = []\n f2py_sources = []\n fortran_sources = []\n f2py_targets = {}\n f2py_fortran_targets = {}\n target_ext = 'module.c'\n fortran_target_ext = '-f2pywrappers.f'\n\n for source in sources:\n (base, source_ext) = os.path.splitext(source)\n (source_dir, base) = os.path.split(base)\n if source_ext == \".pyf\": # f2py interface file\n # get extension module name\n f = open(source)\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = module_name_re(line)\n if m:\n if user_module_name_re(line): # skip *__user__* names\n continue\n base = m.group('name')\n break\n f.close()\n if ext.name == 'untitled':\n ext.name = base\n if base != string.split(ext.name,'.')[-1]:\n # XXX: Should we do here more than just warn?\n self.warn('%s provides %s but this extension is %s' \\\n % (source,`base`,`ext.name`))\n target_file = os.path.join(target_dir,base+target_ext)\n fortran_target_file = os.path.join(target_dir,base+fortran_target_ext)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n f2py_fortran_targets[source] = fortran_target_file\n elif fortran_ext_re(source_ext):\n fortran_sources.append(source) \n else:\n new_sources.append(source)\n\n if not (f2py_sources or fortran_sources):\n return new_sources\n\n # make sure the target dir exists\n from distutils.dir_util import mkpath\n mkpath(target_dir)\n\n if not f2py_sources:\n # creating a temporary pyf file from fortran sources\n pyf_target = os.path.join(target_dir,ext.name+'.pyf')\n pyf_target_file = os.path.join(target_dir,ext.name+target_ext)\n pyf_fortran_target_file = os.path.join(target_dir,ext.name+fortran_target_ext)\n f2py_opts2 = ['-m',ext.name,'-h',pyf_target,'--overwrite-signature']\n for source in fortran_sources:\n if newer(source,pyf_target) or self.force:\n self.announce(\"f2py-ing a new %s\" % (pyf_target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_opts2,' '))\n f2py2e.run_main(fortran_sources + f2py_opts2)\n break\n f2py_sources.append(pyf_target)\n f2py_targets[pyf_target] = pyf_target_file\n f2py_fortran_targets[pyf_target] = pyf_fortran_target_file\n\n new_sources.extend(fortran_sources)\n\n if len(f2py_sources) > 1:\n self.warn('Only one .pyf file can be used per Extension but got %s.'\\\n % (len(f2py_sources)))\n\n # a bit of a hack, but I think it'll work. Just include one of\n # the fortranobject.c files that was copied into most \n d = os.path.dirname(f2py2e.__file__)\n new_sources.append(os.path.join(d,'src','fortranobject.c'))\n ext.include_dirs.append(os.path.join(d,'src'))\n\n f2py_options = ext.f2py_options + self.f2py_options\n\n for source in f2py_sources:\n target = f2py_targets[source]\n fortran_target = f2py_fortran_targets[source]\n if newer(source,target) or self.force:\n self.announce(\"f2py-ing %s to %s\" % (source, target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_options,' '))\n f2py2e.run_main(f2py_options + [source])\n new_sources.append(target)\n if os.path.exists(fortran_target):\n new_sources.append(fortran_target)\n return new_sources\n\n # f2py_sources ()\n\n def fortran_sources_to_flib(self, ext):\n \"\"\"\n Extract fortran files from ext.sources and append them to\n fortran_libraries item having the same name as ext.\n \"\"\"\n sources = []\n f_files = []\n\n for file in ext.sources:\n if fortran_ext_re(file):\n f_files.append(file)\n else:\n sources.append(file)\n if not f_files:\n return\n\n ext.sources = sources\n\n if self.distribution.fortran_libraries is None:\n self.distribution.fortran_libraries = []\n fortran_libraries = self.distribution.fortran_libraries\n\n name = ext.name\n flib = None\n for n,d in fortran_libraries:\n if n == name:\n flib = d\n break\n if flib is None:\n flib = {'sources':[]}\n fortran_libraries.append((name,flib))\n\n flib['sources'].extend(f_files)\n \n# class run_f2py\n", + "methods": [ + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "run_f2py.py", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 35, + "end_line": 40, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "run_f2py.py", + "nloc": 9, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 44, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "run_f2py.py", + "nloc": 5, + "complexity": 3, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 58, + "end_line": 67, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "f2py_sources", + "long_name": "f2py_sources( self , sources , ext )", + "filename": "run_f2py.py", + "nloc": 79, + "complexity": 21, + "token_count": 595, + "parameters": [ + "self", + "sources", + "ext" + ], + "start_line": 70, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 1 + }, + { + "name": "fortran_sources_to_flib", + "long_name": "fortran_sources_to_flib( self , ext )", + "filename": "run_f2py.py", + "nloc": 24, + "complexity": 8, + "token_count": 133, + "parameters": [ + "self", + "ext" + ], + "start_line": 185, + "end_line": 217, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "run_f2py.py", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 34, + "end_line": 39, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "run_f2py.py", + "nloc": 9, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 43, + "end_line": 53, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "run_f2py.py", + "nloc": 5, + "complexity": 3, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 57, + "end_line": 66, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "f2py_sources", + "long_name": "f2py_sources( self , sources , ext )", + "filename": "run_f2py.py", + "nloc": 76, + "complexity": 20, + "token_count": 584, + "parameters": [ + "self", + "sources", + "ext" + ], + "start_line": 69, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 109, + "top_nesting_level": 1 + }, + { + "name": "fortran_sources_to_flib", + "long_name": "fortran_sources_to_flib( self , ext )", + "filename": "run_f2py.py", + "nloc": 24, + "complexity": 8, + "token_count": 133, + "parameters": [ + "self", + "ext" + ], + "start_line": 181, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "f2py_sources", + "long_name": "f2py_sources( self , sources , ext )", + "filename": "run_f2py.py", + "nloc": 79, + "complexity": 21, + "token_count": 595, + "parameters": [ + "self", + "sources", + "ext" + ], + "start_line": 70, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 1 + } + ], + "nloc": 147, + "complexity": 36, + "token_count": 994, + "diff_parsed": { + "added": [ + "from scipy_distutils.system_info import F2pyNotFoundError", + " try:", + " import f2py2e", + " except ImportError:", + " raise F2pyNotFoundError,F2pyNotFoundError.__doc__" + ], + "deleted": [ + " import f2py2e" + ] + } + }, + { + "old_path": "scipy_distutils/system_info.py", + "new_path": "scipy_distutils/system_info.py", + "filename": "system_info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -34,6 +34,7 @@\n \"\"\"\n \n import sys,os,re,types,pprint\n+from distutils.errors import DistutilsError\n from glob import glob\n \n from distutils.sysconfig import get_config_vars\n@@ -54,6 +55,36 @@ def get_info(name):\n 'fftw':fftw_info}.get(name.lower(),system_info)\n return cl().get_info()\n \n+class NotFoundError(DistutilsError):\n+ \"\"\"Some third-party program or library is not found.\"\"\"\n+\n+class AtlasNotFoundError(NotFoundError):\n+ \"\"\"\n+ Atlas (http://math-atlas.sourceforge.net/) libraries not found.\n+ Either install them in /usr/local/lib/atlas or /usr/lib/atlas\n+ and retry setup.py. One can use also ATLAS environment variable\n+ to indicate the location of Atlas libraries.\"\"\"\n+\n+class FFTWNotFoundError(NotFoundError):\n+ \"\"\"\n+ FFTW (http://www.fftw.org/) libraries not found.\n+ Either install them in /usr/local/lib or /usr/lib and retry setup.py.\n+ One can use also FFTW environment variable to indicate\n+ the location of FFTW libraries.\"\"\"\n+\n+class 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+\n+class NumericNotFoundError(NotFoundError):\n+ \"\"\"\n+ Numeric (http://pfdubois.com/numpy/) module not found.\n+ Get it from above location, install it, and retry setup.py.\"\"\"\n+\n+class X11NotFoundError(NotFoundError):\n+ \"\"\"X11 libraries not found.\"\"\"\n+\n class system_info:\n \n \"\"\" get_info() is the only public method. Don't use others.\n", + "added_lines": 31, + "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 fftw_info\n x11_info\nThe following environment variables are used if defined:\n ATLAS - path to ATLAS library\n FFTW - path to FFTW library\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw'.\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 (or system_info could not find it).\n\nGlobal parameters:\n prefixes - a list of prefixes for scanning the location of\n resources.\n system_info.static_first - a flag for indicating that static\n libraries are searched first than shared ones.\n system_info.verbose - show the results if set.\n\nAuthor:\n Pearu Peterson , February 2002\nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re,types,pprint\nfrom distutils.errors import DistutilsError\nfrom glob import glob\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n prefixes = ['C:\\\\'] # XXX: what is prefix in win32?\nelse:\n prefixes = ['/usr','/usr/local','/opt']\nif sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\nprefixes = filter(os.path.isdir,prefixes) # XXX: Is this ok on win32? Is 'C:' dir?\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name):\n cl = {'atlas':atlas_info,\n 'x11':x11_info,\n 'fftw':fftw_info}.get(name.lower(),system_info)\n return cl().get_info()\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 Either install them in /usr/local/lib/atlas or /usr/lib/atlas\n and retry setup.py. One can use also ATLAS environment variable\n to indicate the location of Atlas libraries.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Either install them in /usr/local/lib or /usr/lib and retry setup.py.\n One can use also FFTW environment variable to indicate\n the location of FFTW libraries.\"\"\"\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://pfdubois.com/numpy/) 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\n static_first = 1\n verbose = 1\n need_refresh = 1\n saved_results = {}\n \n def __init__ (self):\n self.__class__.info = {}\n #self.__class__.need_refresh = not self.info\n self.local_prefixes = []\n\n def set_info(self,**info):\n #self.__class__.info = info\n self.saved_results[self.__class__.__name__] = info\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n def get_info(self):\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.verbose:\n print self.__class__.__name__ + ':'\n for p in self.local_prefixes + prefixes:\n if self.verbose:\n print ' Looking in',p,'...'\n self.calc_info(p)\n if self.has_info(): break\n if self.verbose:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbose and flag:\n for k,v in res.items():\n print ' %s = %s'%(k,v)\n print\n return res\n\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\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 mths = [self.check_static_libs,self.check_shared_libs]\n if not self.static_first:\n mths.reverse() # if one prefers shared libraries\n for m in mths:\n info = m(lib_dir,libs,opt_libs)\n if info is not None: return info\n\n def check_static_libs(self,lib_dir,libs,opt_libs =[]):\n #XXX: what are .lib and .dll files under win32?\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs])) == len(libs):\n info = {'libraries':libs,'library_dirs':[lib_dir]}\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs]))\\\n ==len(opt_libs):\n info['libraries'].extend(opt_libs)\n return info\n\n def check_shared_libs(self,lib_dir,libs,opt_libs =[]):\n shared_libs = []\n for l in libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: shared_libs.append(p)\n if len(shared_libs) == len(libs):\n info = {'extra_objects':shared_libs}\n opt_shared_libs = []\n for l in opt_libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: opt_shared_libs.append(p)\n info['extra_objects'].extend(opt_shared_libs)\n return info\n\n\nclass fftw_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('FFTW')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self,prefix):\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,'lib',['fftw*','FFTW*']))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'lib'))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','fftw*','FFTW*']))\n \n if not lib_dirs: return\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,'include',['fftw*','FFTW*']))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'include'))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['include','fftw*','FFTW*']))\n if not incl_dirs: return\n incl_dir = None\n\n libs = ['fftw','rfftw']\n opt_libs = ['fftw_threads','rfftw_threads']\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['fftw.h','rfftw.h']))==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=[('SCIPY_FFTW_H',1)])\n else:\n info = None\n\n if info is None:\n libs = ['dfftw','drfftw']\n opt_libs = ['dfftw_threads','drfftw_threads']\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['dfftw.h','drfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n incl_dirs = [d]\n incl_dir = d\n flag = 1\n break\n if flag:\n dict_append(info,define_macros=[('SCIPY_DFFTW_H',1)])\n else:\n info = None\n \n libs = ['sfftw','srfftw']\n opt_libs = ['sfftw_threads','srfftw_threads']\n flag = 0\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_libs)\n if r is not None:\n if info is None: info = r\n else: dict_append(info,**r)\n flag = 1\n break\n if info is not None and flag:\n for d in incl_dirs:\n if len(combine_paths(d,['sfftw.h','srfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n dict_append(info,define_macros=[('SCIPY_SFFTW_H',1)])\n break\n if info is not None:\n self.set_info(**info)\n\n\nclass atlas_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('ATLAS')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self, prefix):\n lib_dirs = filter(os.path.isdir,combine_paths(prefix,'lib',\n ['atlas*','ATLAS*']))\n if lib_dirs:\n other_dirs = filter(os.path.isdir,combine_paths(lib_dirs,'*'))\n other_dirs.extend(filter(os.path.isdir,combine_paths(prefix,'lib')))\n lib_dirs.extend(other_dirs)\n else:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','atlas*','ATLAS*']))\n if not lib_dirs:\n lib_dirs = [prefix]\n\n h = (combine_paths(lib_dirs,'cblas.h') or [None])[0]\n if not h:\n h = (combine_paths(lib_dirs,'include','cblas.h') or [None])[0]\n if h: h = os.path.dirname(h)\n\n libs = ['lapack','f77blas','cblas','atlas']\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 None: return\n if h: dict_append(info,include_dirs=h)\n self.set_info(**info)\n\n\nclass blas_info(system_info):\n # For Fortran or optimized blas, not atlas.\n pass\n\n\nclass lapack_info(system_info):\n # For Fortran or optimized lapack, not atlas\n pass\n\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = self.check_libs(lib_dir[0],['X11'],[])\n if info is None:\n continue\n dict_append(info,include_dirs=[inc_dir])\n self.set_info(**info)\n\ndef shortest_path(pths):\n pths.sort()\n if pths: return pths[0]\n\ndef combine_paths(*args):\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 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 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 r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\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 fftw_info\n x11_info\nThe following environment variables are used if defined:\n ATLAS - path to ATLAS library\n FFTW - path to FFTW library\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw'.\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 (or system_info could not find it).\n\nGlobal parameters:\n prefixes - a list of prefixes for scanning the location of\n resources.\n system_info.static_first - a flag for indicating that static\n libraries are searched first than shared ones.\n system_info.verbose - show the results if set.\n\nAuthor:\n Pearu Peterson , February 2002\nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re,types,pprint\nfrom glob import glob\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n prefixes = ['C:\\\\'] # XXX: what is prefix in win32?\nelse:\n prefixes = ['/usr','/usr/local','/opt']\nif sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\nprefixes = filter(os.path.isdir,prefixes) # XXX: Is this ok on win32? Is 'C:' dir?\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name):\n cl = {'atlas':atlas_info,\n 'x11':x11_info,\n 'fftw':fftw_info}.get(name.lower(),system_info)\n return cl().get_info()\n\nclass system_info:\n\n \"\"\" get_info() is the only public method. Don't use others.\n \"\"\"\n\n static_first = 1\n verbose = 1\n need_refresh = 1\n saved_results = {}\n \n def __init__ (self):\n self.__class__.info = {}\n #self.__class__.need_refresh = not self.info\n self.local_prefixes = []\n\n def set_info(self,**info):\n #self.__class__.info = info\n self.saved_results[self.__class__.__name__] = info\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n def get_info(self):\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.verbose:\n print self.__class__.__name__ + ':'\n for p in self.local_prefixes + prefixes:\n if self.verbose:\n print ' Looking in',p,'...'\n self.calc_info(p)\n if self.has_info(): break\n if self.verbose:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbose and flag:\n for k,v in res.items():\n print ' %s = %s'%(k,v)\n print\n return res\n\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\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 mths = [self.check_static_libs,self.check_shared_libs]\n if not self.static_first:\n mths.reverse() # if one prefers shared libraries\n for m in mths:\n info = m(lib_dir,libs,opt_libs)\n if info is not None: return info\n\n def check_static_libs(self,lib_dir,libs,opt_libs =[]):\n #XXX: what are .lib and .dll files under win32?\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs])) == len(libs):\n info = {'libraries':libs,'library_dirs':[lib_dir]}\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs]))\\\n ==len(opt_libs):\n info['libraries'].extend(opt_libs)\n return info\n\n def check_shared_libs(self,lib_dir,libs,opt_libs =[]):\n shared_libs = []\n for l in libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: shared_libs.append(p)\n if len(shared_libs) == len(libs):\n info = {'extra_objects':shared_libs}\n opt_shared_libs = []\n for l in opt_libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: opt_shared_libs.append(p)\n info['extra_objects'].extend(opt_shared_libs)\n return info\n\n\nclass fftw_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('FFTW')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self,prefix):\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,'lib',['fftw*','FFTW*']))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'lib'))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','fftw*','FFTW*']))\n \n if not lib_dirs: return\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,'include',['fftw*','FFTW*']))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'include'))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['include','fftw*','FFTW*']))\n if not incl_dirs: return\n incl_dir = None\n\n libs = ['fftw','rfftw']\n opt_libs = ['fftw_threads','rfftw_threads']\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['fftw.h','rfftw.h']))==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=[('SCIPY_FFTW_H',1)])\n else:\n info = None\n\n if info is None:\n libs = ['dfftw','drfftw']\n opt_libs = ['dfftw_threads','drfftw_threads']\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['dfftw.h','drfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n incl_dirs = [d]\n incl_dir = d\n flag = 1\n break\n if flag:\n dict_append(info,define_macros=[('SCIPY_DFFTW_H',1)])\n else:\n info = None\n \n libs = ['sfftw','srfftw']\n opt_libs = ['sfftw_threads','srfftw_threads']\n flag = 0\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_libs)\n if r is not None:\n if info is None: info = r\n else: dict_append(info,**r)\n flag = 1\n break\n if info is not None and flag:\n for d in incl_dirs:\n if len(combine_paths(d,['sfftw.h','srfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n dict_append(info,define_macros=[('SCIPY_SFFTW_H',1)])\n break\n if info is not None:\n self.set_info(**info)\n\n\nclass atlas_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('ATLAS')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self, prefix):\n lib_dirs = filter(os.path.isdir,combine_paths(prefix,'lib',\n ['atlas*','ATLAS*']))\n if lib_dirs:\n other_dirs = filter(os.path.isdir,combine_paths(lib_dirs,'*'))\n other_dirs.extend(filter(os.path.isdir,combine_paths(prefix,'lib')))\n lib_dirs.extend(other_dirs)\n else:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','atlas*','ATLAS*']))\n if not lib_dirs:\n lib_dirs = [prefix]\n\n h = (combine_paths(lib_dirs,'cblas.h') or [None])[0]\n if not h:\n h = (combine_paths(lib_dirs,'include','cblas.h') or [None])[0]\n if h: h = os.path.dirname(h)\n\n libs = ['lapack','f77blas','cblas','atlas']\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 None: return\n if h: dict_append(info,include_dirs=h)\n self.set_info(**info)\n\n\nclass blas_info(system_info):\n # For Fortran or optimized blas, not atlas.\n pass\n\n\nclass lapack_info(system_info):\n # For Fortran or optimized lapack, not atlas\n pass\n\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = self.check_libs(lib_dir[0],['X11'],[])\n if info is None:\n continue\n dict_append(info,include_dirs=[inc_dir])\n self.set_info(**info)\n\ndef shortest_path(pths):\n pths.sort()\n if pths: return pths[0]\n\ndef combine_paths(*args):\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 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 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 r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n", + "methods": [ + { + "name": "get_info", + "long_name": "get_info( name )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 1, + "token_count": 39, + "parameters": [ + "name" + ], + "start_line": 52, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 98, + "end_line": 101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 103, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "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": 106, + "end_line": 107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 11, + "token_count": 134, + "parameters": [ + "self" + ], + "start_line": 108, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 135, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 60, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 138, + "end_line": 146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_static_libs", + "long_name": "check_static_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 5, + "token_count": 91, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 148, + "end_line": 155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_shared_libs", + "long_name": "check_shared_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 13, + "complexity": 6, + "token_count": 119, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 157, + "end_line": 169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 174, + "end_line": 180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 82, + "complexity": 30, + "token_count": 553, + "parameters": [ + "self", + "prefix" + ], + "start_line": 182, + "end_line": 267, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 272, + "end_line": 278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 11, + "token_count": 229, + "parameters": [ + "self", + "prefix" + ], + "start_line": 280, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "prefix" + ], + "start_line": 322, + "end_line": 338, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "shortest_path", + "long_name": "shortest_path( pths )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "pths" + ], + "start_line": 340, + "end_line": 342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 9, + "token_count": 162, + "parameters": [ + "args" + ], + "start_line": 344, + "end_line": 365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 367, + "end_line": 372, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [], + "start_line": 374, + "end_line": 381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "get_info", + "long_name": "get_info( name )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 1, + "token_count": 39, + "parameters": [ + "name" + ], + "start_line": 51, + "end_line": 55, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 67, + "end_line": 70, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "set_info", + "long_name": "set_info( self , ** info )", + "filename": "system_info.py", + "nloc": 2, + "complexity": 1, + "token_count": 20, + "parameters": [ + "self", + "info" + ], + "start_line": 72, + "end_line": 74, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "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": 75, + "end_line": 76, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 11, + "token_count": 134, + "parameters": [ + "self" + ], + "start_line": 77, + "end_line": 102, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 104, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 60, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 107, + "end_line": 115, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_static_libs", + "long_name": "check_static_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 5, + "token_count": 91, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 117, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_shared_libs", + "long_name": "check_shared_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 13, + "complexity": 6, + "token_count": 119, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 126, + "end_line": 138, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 143, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 82, + "complexity": 30, + "token_count": 553, + "parameters": [ + "self", + "prefix" + ], + "start_line": 151, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 241, + "end_line": 247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 11, + "token_count": 229, + "parameters": [ + "self", + "prefix" + ], + "start_line": 249, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "prefix" + ], + "start_line": 291, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "shortest_path", + "long_name": "shortest_path( pths )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "pths" + ], + "start_line": 309, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 9, + "token_count": 162, + "parameters": [ + "args" + ], + "start_line": 313, + "end_line": 334, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 336, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [], + "start_line": 343, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "changed_methods": [], + "nloc": 323, + "complexity": 103, + "token_count": 2010, + "diff_parsed": { + "added": [ + "from distutils.errors import DistutilsError", + "class NotFoundError(DistutilsError):", + " \"\"\"Some third-party program or library is not found.\"\"\"", + "", + "class AtlasNotFoundError(NotFoundError):", + " \"\"\"", + " Atlas (http://math-atlas.sourceforge.net/) libraries not found.", + " Either install them in /usr/local/lib/atlas or /usr/lib/atlas", + " and retry setup.py. One can use also ATLAS environment variable", + " to indicate the location of Atlas libraries.\"\"\"", + "", + "class FFTWNotFoundError(NotFoundError):", + " \"\"\"", + " FFTW (http://www.fftw.org/) libraries not found.", + " Either install them in /usr/local/lib or /usr/lib and retry setup.py.", + " One can use also FFTW environment variable to indicate", + " the location of FFTW libraries.\"\"\"", + "", + "class F2pyNotFoundError(NotFoundError):", + " \"\"\"", + " f2py2e (http://cens.ioc.ee/projects/f2py2e/) module not found.", + " Get it from above location, install it, and retry setup.py.\"\"\"", + "", + "class NumericNotFoundError(NotFoundError):", + " \"\"\"", + " Numeric (http://pfdubois.com/numpy/) module not found.", + " Get it from above location, install it, and retry setup.py.\"\"\"", + "", + "class X11NotFoundError(NotFoundError):", + " \"\"\"X11 libraries not found.\"\"\"", + "" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "b25fc06001bccd8692ef5b4f49ecbe49007309d9", + "msg": "Rudimentary loops (range and xrange). Really good speedups\nso far", + "author": { + "name": "patmiller", + "email": "patmiller@localhost" + }, + "committer": { + "name": "patmiller", + "email": "patmiller@localhost" + }, + "author_date": "2002-03-01T07:01:21+00:00", + "author_timezone": 0, + "committer_date": "2002-03-01T07:01:21+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "956709dd991cfe4c15a80657c83c4318834525cb" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 35, + "insertions": 115, + "lines": 150, + "files": 2, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 0.5416666666666666, + "modified_files": [ + { + "old_path": "weave/accelerate_tools.py", + "new_path": "weave/accelerate_tools.py", + "filename": "accelerate_tools.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -9,11 +9,11 @@\n \"\"\"\n #**************************************************************************#\n \n-from types import FunctionType,IntType,FloatType,StringType,TypeType\n+from types import FunctionType,IntType,FloatType,StringType,TypeType,XRangeType\n import inspect\n import md5\n import weave\n-import bytecodecompiler\n+from bytecodecompiler import CXXCoder,Type_Descriptor,Function_Descriptor\n \n def CStr(s):\n \"Hacky way to get legal C string from Python string\"\n@@ -22,7 +22,7 @@ def CStr(s):\n r = repr('\"'+s) # Better for embedded quotes\n return '\"'+r[2:-1]+'\"'\n \n-class Basic(bytecodecompiler.Type_Descriptor):\n+class Basic(Type_Descriptor):\n def check(self,s):\n return \"%s(%s)\"%(self.checker,s)\n def inbound(self,s):\n@@ -60,10 +60,12 @@ def literalizer(self,s):\n \n import Numeric\n \n-class Vector(bytecodecompiler.Type_Descriptor):\n+class Vector(Type_Descriptor):\n cxxtype = 'PyArrayObject*'\n refcount = 1\n- prerequisites = bytecodecompiler.Type_Descriptor.prerequisites+\\\n+ module_init_code = 'import_array'\n+\n+ prerequisites = Type_Descriptor.prerequisites+\\\n ['#include \"Numeric/arrayobject.h\"']\n dims = 1\n def check(self,s):\n@@ -74,19 +76,53 @@ def inbound(self,s):\n def outbound(self,s):\n return \"(PyObject*)(%s)\"%s\n def binopMixed(self,symbol,a,b):\n- return '*((%s*)(%s->data+%s*%s->strides[0]))'%(self.cxxbase,a,b,a),Integer()\n+ return '*((%s*)(%s->data+%s*%s->strides[0]))'%(self.cxxbase,a,b,a),Integer\n \n class IntegerVector(Vector):\n typecode = 'PyArray_INT'\n cxxbase = 'int'\n \n+class XRange(Type_Descriptor):\n+ cxxtype = 'XRange'\n+ prerequisites = ['''\n+ class XRange {\n+ public:\n+ XRange(long aLow, long aHigh, long aStep=1)\n+ : low(aLow),high(aHigh),step(aStep)\n+ {\n+ }\n+ long low;\n+ long high;\n+ long step;\n+ };''']\n+\n+# -----------------------------------------------\n+# Singletonize the type names\n+# -----------------------------------------------\n+Integer = Integer()\n+Double = Double()\n+String = String()\n+IntegerVector = IntegerVector()\n+XRange = XRange()\n+\n typedefs = {\n- IntType: Integer(),\n- FloatType: Double(),\n- StringType: String(),\n- (Numeric.ArrayType,1,'l'): IntegerVector(),\n+ IntType: Integer,\n+ FloatType: Double,\n+ StringType: String,\n+ (Numeric.ArrayType,1,'l'): IntegerVector,\n+ XRangeType : XRange,\n }\n \n+import math\n+functiondefs = {\n+ (range,(Integer,Integer)):\n+ Function_Descriptor(code='XRange(%s)',return_type=XRange),\n+\n+ (math.sin,(Double,)):\n+ Function_Descriptor(code='sin(%s)',return_type=Double),\n+ }\n+ \n+\n \n ##################################################################\n # FUNCTION LOOKUP_TYPE #\n@@ -189,30 +225,41 @@ def code(self,*args):\n ##################################################################\n # CLASS PYTHON2CXX #\n ##################################################################\n-class Python2CXX(bytecodecompiler.CXXCoder):\n+class Python2CXX(CXXCoder):\n def typedef_by_value(self,v):\n T = lookup_type(v)\n- if T not in self.used: self.used.append(T)\n+ if T not in self.used:\n+ self.used.append(T)\n return T\n \n+ def function_by_signature(self,signature):\n+ descriptor = functiondefs[signature]\n+ if descriptor.return_type not in self.used:\n+ self.used.append(descriptor.return_type)\n+ return descriptor\n+\n def __init__(self,f,signature,name=None):\n # Make sure function is a function\n import types\n assert type(f) == FunctionType\n # and check the input type signature\n assert reduce(lambda x,y: x and y,\n- map(lambda x: isinstance(x,bytecodecompiler.Type_Descriptor),\n+ map(lambda x: isinstance(x,Type_Descriptor),\n signature),\n 1),'%s not all type objects'%signature\n self.arg_specs = []\n self.customize = weave.base_info.custom_info()\n- self.customize.add_module_init_code('import_array()\\n')\n \n- bytecodecompiler.CXXCoder.__init__(self,f,signature,name)\n+ CXXCoder.__init__(self,f,signature,name)\n+\n return\n \n def function_code(self):\n- return self.wrapped_code()\n+ code = self.wrapped_code()\n+ for T in self.used:\n+ if T != None and T.module_init_code:\n+ self.customize.add_module_init_code(T.module_init_code)\n+ return code\n \n def python_function_definition_code(self):\n return '{ \"%s\", wrapper_%s, METH_VARARGS, %s },\\n'%(\n", + "added_lines": 63, + "deleted_lines": 16, + "source_code": "#**************************************************************************#\n#* FILE ************** accelerate_tools.py ************************#\n#**************************************************************************#\n#* Author: Patrick Miller February 9 2002 *#\n#**************************************************************************#\n\"\"\"\naccelerate_tools contains the interface for on-the-fly building of\nC++ equivalents to Python functions.\n\"\"\"\n#**************************************************************************#\n\nfrom types import FunctionType,IntType,FloatType,StringType,TypeType,XRangeType\nimport inspect\nimport md5\nimport weave\nfrom bytecodecompiler import CXXCoder,Type_Descriptor,Function_Descriptor\n\ndef CStr(s):\n \"Hacky way to get legal C string from Python string\"\n if s == None: return '\"\"'\n assert type(s) == StringType,\"Only None and string allowed\"\n r = repr('\"'+s) # Better for embedded quotes\n return '\"'+r[2:-1]+'\"'\n\nclass Basic(Type_Descriptor):\n def check(self,s):\n return \"%s(%s)\"%(self.checker,s)\n def inbound(self,s):\n return \"%s(%s)\"%(self.inbounder,s)\n def outbound(self,s):\n return \"%s(%s)\"%(self.outbounder,s)\n\nclass Basic_Number(Basic):\n def literalizer(self,s):\n return str(s)\n def binop(self,symbol,a,b):\n assert symbol in ['+','-','*','/'],symbol\n return '%s %s %s'%(a,symbol,b),self\n\nclass Integer(Basic_Number):\n cxxtype = \"long\"\n checker = \"PyInt_Check\"\n inbounder = \"PyInt_AsLong\"\n outbounder = \"PyInt_FromLong\"\n\nclass Double(Basic_Number):\n cxxtype = \"double\"\n checker = \"PyFloat_Check\"\n inbounder = \"PyFloat_AsDouble\"\n outbounder = \"PyFloat_FromDouble\"\n\nclass String(Basic):\n cxxtype = \"char*\"\n checker = \"PyString_Check\"\n inbounder = \"PyString_AsString\"\n outbounder = \"PyString_FromString\"\n\n def literalizer(self,s):\n return CStr(s)\n\nimport Numeric\n\nclass Vector(Type_Descriptor):\n cxxtype = 'PyArrayObject*'\n refcount = 1\n module_init_code = 'import_array'\n\n prerequisites = Type_Descriptor.prerequisites+\\\n ['#include \"Numeric/arrayobject.h\"']\n dims = 1\n def check(self,s):\n return \"PyArray_Check(%s) && ((PyArrayObject*)%s)->nd == %d && ((PyArrayObject*)%s)->descr->type_num == %s\"%(\n s,s,self.dims,s,self.typecode)\n def inbound(self,s):\n return \"(PyArrayObject*)(%s)\"%s\n def outbound(self,s):\n return \"(PyObject*)(%s)\"%s\n def binopMixed(self,symbol,a,b):\n return '*((%s*)(%s->data+%s*%s->strides[0]))'%(self.cxxbase,a,b,a),Integer\n\nclass IntegerVector(Vector):\n typecode = 'PyArray_INT'\n cxxbase = 'int'\n\nclass XRange(Type_Descriptor):\n cxxtype = 'XRange'\n prerequisites = ['''\n class XRange {\n public:\n XRange(long aLow, long aHigh, long aStep=1)\n : low(aLow),high(aHigh),step(aStep)\n {\n }\n long low;\n long high;\n long step;\n };''']\n\n# -----------------------------------------------\n# Singletonize the type names\n# -----------------------------------------------\nInteger = Integer()\nDouble = Double()\nString = String()\nIntegerVector = IntegerVector()\nXRange = XRange()\n\ntypedefs = {\n IntType: Integer,\n FloatType: Double,\n StringType: String,\n (Numeric.ArrayType,1,'l'): IntegerVector,\n XRangeType : XRange,\n }\n\nimport math\nfunctiondefs = {\n (range,(Integer,Integer)):\n Function_Descriptor(code='XRange(%s)',return_type=XRange),\n\n (math.sin,(Double,)):\n Function_Descriptor(code='sin(%s)',return_type=Double),\n }\n \n\n\n##################################################################\n# FUNCTION LOOKUP_TYPE #\n##################################################################\ndef lookup_type(x):\n T = type(x)\n try:\n return typedefs[T]\n except:\n return typedefs[(T,len(x.shape),x.typecode())]\n\n##################################################################\n# class ACCELERATE #\n##################################################################\nclass accelerate:\n \n def __init__(self, function, *args, **kw):\n assert type(function) == FunctionType\n self.function = function\n self.module = inspect.getmodule(function)\n if self.module == None:\n import __main__\n self.module = __main__\n self.__call_map = {}\n\n def __cache(self,*args):\n raise TypeError\n\n def __call__(self,*args):\n try:\n return self.__cache(*args)\n except TypeError:\n # Figure out type info -- Do as tuple so its hashable\n signature = tuple( map(lookup_type,args) )\n \n # If we know the function, call it\n try:\n fast = self.__call_map[signature]\n except:\n fast = self.singleton(signature)\n self.__cache = fast\n self.__call_map[signature] = fast\n return fast(*args)\n\n def signature(self,*args):\n # Figure out type info -- Do as tuple so its hashable\n signature = tuple( map(lookup_type,args) )\n return self.singleton(signature)\n\n\n def singleton(self,signature):\n identifier = self.identifier(signature)\n \n # Generate a new function, then call it\n f = self.function\n\n # See if we have an accelerated version of module\n try:\n accelerated_module = __import__(self.module.__name__+'_weave')\n fast = getattr(accelerated_module,identifier)\n return fast\n except:\n accelerated_module = None\n\n P = self.accelerate(signature,identifier)\n\n E = weave.ext_tools.ext_module(self.module.__name__+'_weave')\n E.add_function(P)\n E.generate_file()\n weave.build_tools.build_extension(self.module.__name__+'_weave.cpp',verbose=2)\n\n if accelerated_module:\n accelerated_module = reload(accelerated_module)\n else:\n accelerated_module = __import__(self.module.__name__+'_weave')\n\n fast = getattr(accelerated_module,identifier)\n return fast\n\n def identifier(self,signature):\n # Build an MD5 checksum\n f = self.function\n co = f.func_code\n identifier = str(signature)+\\\n str(co.co_consts)+\\\n str(co.co_varnames)+\\\n co.co_code\n return 'F'+md5.md5(identifier).hexdigest()\n \n def accelerate(self,signature,identifier):\n P = Python2CXX(self.function,signature,name=identifier)\n return P\n\n def code(self,*args):\n signature = tuple( map(lookup_type,args) )\n ident = self.function.__name__\n return self.accelerate(signature,ident).function_code()\n \n\n##################################################################\n# CLASS PYTHON2CXX #\n##################################################################\nclass Python2CXX(CXXCoder):\n def typedef_by_value(self,v):\n T = lookup_type(v)\n if T not in self.used:\n self.used.append(T)\n return T\n\n def function_by_signature(self,signature):\n descriptor = functiondefs[signature]\n if descriptor.return_type not in self.used:\n self.used.append(descriptor.return_type)\n return descriptor\n\n def __init__(self,f,signature,name=None):\n # Make sure function is a function\n import types\n assert type(f) == FunctionType\n # and check the input type signature\n assert reduce(lambda x,y: x and y,\n map(lambda x: isinstance(x,Type_Descriptor),\n signature),\n 1),'%s not all type objects'%signature\n self.arg_specs = []\n self.customize = weave.base_info.custom_info()\n\n CXXCoder.__init__(self,f,signature,name)\n\n return\n\n def function_code(self):\n code = self.wrapped_code()\n for T in self.used:\n if T != None and T.module_init_code:\n self.customize.add_module_init_code(T.module_init_code)\n return code\n\n def python_function_definition_code(self):\n return '{ \"%s\", wrapper_%s, METH_VARARGS, %s },\\n'%(\n self.name,\n self.name,\n CStr(self.function.__doc__))\n", + "source_code_before": "#**************************************************************************#\n#* FILE ************** accelerate_tools.py ************************#\n#**************************************************************************#\n#* Author: Patrick Miller February 9 2002 *#\n#**************************************************************************#\n\"\"\"\naccelerate_tools contains the interface for on-the-fly building of\nC++ equivalents to Python functions.\n\"\"\"\n#**************************************************************************#\n\nfrom types import FunctionType,IntType,FloatType,StringType,TypeType\nimport inspect\nimport md5\nimport weave\nimport bytecodecompiler\n\ndef CStr(s):\n \"Hacky way to get legal C string from Python string\"\n if s == None: return '\"\"'\n assert type(s) == StringType,\"Only None and string allowed\"\n r = repr('\"'+s) # Better for embedded quotes\n return '\"'+r[2:-1]+'\"'\n\nclass Basic(bytecodecompiler.Type_Descriptor):\n def check(self,s):\n return \"%s(%s)\"%(self.checker,s)\n def inbound(self,s):\n return \"%s(%s)\"%(self.inbounder,s)\n def outbound(self,s):\n return \"%s(%s)\"%(self.outbounder,s)\n\nclass Basic_Number(Basic):\n def literalizer(self,s):\n return str(s)\n def binop(self,symbol,a,b):\n assert symbol in ['+','-','*','/'],symbol\n return '%s %s %s'%(a,symbol,b),self\n\nclass Integer(Basic_Number):\n cxxtype = \"long\"\n checker = \"PyInt_Check\"\n inbounder = \"PyInt_AsLong\"\n outbounder = \"PyInt_FromLong\"\n\nclass Double(Basic_Number):\n cxxtype = \"double\"\n checker = \"PyFloat_Check\"\n inbounder = \"PyFloat_AsDouble\"\n outbounder = \"PyFloat_FromDouble\"\n\nclass String(Basic):\n cxxtype = \"char*\"\n checker = \"PyString_Check\"\n inbounder = \"PyString_AsString\"\n outbounder = \"PyString_FromString\"\n\n def literalizer(self,s):\n return CStr(s)\n\nimport Numeric\n\nclass Vector(bytecodecompiler.Type_Descriptor):\n cxxtype = 'PyArrayObject*'\n refcount = 1\n prerequisites = bytecodecompiler.Type_Descriptor.prerequisites+\\\n ['#include \"Numeric/arrayobject.h\"']\n dims = 1\n def check(self,s):\n return \"PyArray_Check(%s) && ((PyArrayObject*)%s)->nd == %d && ((PyArrayObject*)%s)->descr->type_num == %s\"%(\n s,s,self.dims,s,self.typecode)\n def inbound(self,s):\n return \"(PyArrayObject*)(%s)\"%s\n def outbound(self,s):\n return \"(PyObject*)(%s)\"%s\n def binopMixed(self,symbol,a,b):\n return '*((%s*)(%s->data+%s*%s->strides[0]))'%(self.cxxbase,a,b,a),Integer()\n\nclass IntegerVector(Vector):\n typecode = 'PyArray_INT'\n cxxbase = 'int'\n\ntypedefs = {\n IntType: Integer(),\n FloatType: Double(),\n StringType: String(),\n (Numeric.ArrayType,1,'l'): IntegerVector(),\n }\n\n\n##################################################################\n# FUNCTION LOOKUP_TYPE #\n##################################################################\ndef lookup_type(x):\n T = type(x)\n try:\n return typedefs[T]\n except:\n return typedefs[(T,len(x.shape),x.typecode())]\n\n##################################################################\n# class ACCELERATE #\n##################################################################\nclass accelerate:\n \n def __init__(self, function, *args, **kw):\n assert type(function) == FunctionType\n self.function = function\n self.module = inspect.getmodule(function)\n if self.module == None:\n import __main__\n self.module = __main__\n self.__call_map = {}\n\n def __cache(self,*args):\n raise TypeError\n\n def __call__(self,*args):\n try:\n return self.__cache(*args)\n except TypeError:\n # Figure out type info -- Do as tuple so its hashable\n signature = tuple( map(lookup_type,args) )\n \n # If we know the function, call it\n try:\n fast = self.__call_map[signature]\n except:\n fast = self.singleton(signature)\n self.__cache = fast\n self.__call_map[signature] = fast\n return fast(*args)\n\n def signature(self,*args):\n # Figure out type info -- Do as tuple so its hashable\n signature = tuple( map(lookup_type,args) )\n return self.singleton(signature)\n\n\n def singleton(self,signature):\n identifier = self.identifier(signature)\n \n # Generate a new function, then call it\n f = self.function\n\n # See if we have an accelerated version of module\n try:\n accelerated_module = __import__(self.module.__name__+'_weave')\n fast = getattr(accelerated_module,identifier)\n return fast\n except:\n accelerated_module = None\n\n P = self.accelerate(signature,identifier)\n\n E = weave.ext_tools.ext_module(self.module.__name__+'_weave')\n E.add_function(P)\n E.generate_file()\n weave.build_tools.build_extension(self.module.__name__+'_weave.cpp',verbose=2)\n\n if accelerated_module:\n accelerated_module = reload(accelerated_module)\n else:\n accelerated_module = __import__(self.module.__name__+'_weave')\n\n fast = getattr(accelerated_module,identifier)\n return fast\n\n def identifier(self,signature):\n # Build an MD5 checksum\n f = self.function\n co = f.func_code\n identifier = str(signature)+\\\n str(co.co_consts)+\\\n str(co.co_varnames)+\\\n co.co_code\n return 'F'+md5.md5(identifier).hexdigest()\n \n def accelerate(self,signature,identifier):\n P = Python2CXX(self.function,signature,name=identifier)\n return P\n\n def code(self,*args):\n signature = tuple( map(lookup_type,args) )\n ident = self.function.__name__\n return self.accelerate(signature,ident).function_code()\n \n\n##################################################################\n# CLASS PYTHON2CXX #\n##################################################################\nclass Python2CXX(bytecodecompiler.CXXCoder):\n def typedef_by_value(self,v):\n T = lookup_type(v)\n if T not in self.used: self.used.append(T)\n return T\n\n def __init__(self,f,signature,name=None):\n # Make sure function is a function\n import types\n assert type(f) == FunctionType\n # and check the input type signature\n assert reduce(lambda x,y: x and y,\n map(lambda x: isinstance(x,bytecodecompiler.Type_Descriptor),\n signature),\n 1),'%s not all type objects'%signature\n self.arg_specs = []\n self.customize = weave.base_info.custom_info()\n self.customize.add_module_init_code('import_array()\\n')\n\n bytecodecompiler.CXXCoder.__init__(self,f,signature,name)\n return\n\n def function_code(self):\n return self.wrapped_code()\n\n def python_function_definition_code(self):\n return '{ \"%s\", wrapper_%s, METH_VARARGS, %s },\\n'%(\n self.name,\n self.name,\n CStr(self.function.__doc__))\n", + "methods": [ + { + "name": "CStr", + "long_name": "CStr( s )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "s" + ], + "start_line": 18, + "end_line": 23, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "check", + "long_name": "check( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 26, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "inbound", + "long_name": "inbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 28, + "end_line": 29, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "outbound", + "long_name": "outbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 30, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "literalizer", + "long_name": "literalizer( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "s" + ], + "start_line": 34, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "binop", + "long_name": "binop( self , symbol , a , b )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 37, + "parameters": [ + "self", + "symbol", + "a", + "b" + ], + "start_line": 36, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "literalizer", + "long_name": "literalizer( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "s" + ], + "start_line": 58, + "end_line": 59, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check", + "long_name": "check( self , s )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self", + "s" + ], + "start_line": 71, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "inbound", + "long_name": "inbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "s" + ], + "start_line": 74, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "outbound", + "long_name": "outbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "s" + ], + "start_line": 76, + "end_line": 77, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "binopMixed", + "long_name": "binopMixed( self , symbol , a , b )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "symbol", + "a", + "b" + ], + "start_line": 78, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "lookup_type", + "long_name": "lookup_type( x )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 2, + "token_count": 40, + "parameters": [ + "x" + ], + "start_line": 130, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , function , * args , ** kw )", + "filename": "accelerate_tools.py", + "nloc": 8, + "complexity": 2, + "token_count": 55, + "parameters": [ + "self", + "function", + "args", + "kw" + ], + "start_line": 142, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__cache", + "long_name": "__cache( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "args" + ], + "start_line": 151, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 12, + "complexity": 3, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 154, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "signature", + "long_name": "signature( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "args" + ], + "start_line": 170, + "end_line": 173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "singleton", + "long_name": "singleton( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 20, + "complexity": 3, + "token_count": 137, + "parameters": [ + "self", + "signature" + ], + "start_line": 176, + "end_line": 203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "identifier", + "long_name": "identifier( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 8, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self", + "signature" + ], + "start_line": 205, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "accelerate", + "long_name": "accelerate( self , signature , identifier )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self", + "signature", + "identifier" + ], + "start_line": 215, + "end_line": 217, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "code", + "long_name": "code( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 4, + "complexity": 1, + "token_count": 39, + "parameters": [ + "self", + "args" + ], + "start_line": 219, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "typedef_by_value", + "long_name": "typedef_by_value( self , v )", + "filename": "accelerate_tools.py", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "v" + ], + "start_line": 229, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "function_by_signature", + "long_name": "function_by_signature( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self", + "signature" + ], + "start_line": 235, + "end_line": 239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , f , signature , name = None )", + "filename": "accelerate_tools.py", + "nloc": 11, + "complexity": 2, + "token_count": 85, + "parameters": [ + "self", + "f", + "signature", + "name" + ], + "start_line": 241, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "function_code", + "long_name": "function_code( self )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 4, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 257, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "python_function_definition_code", + "long_name": "python_function_definition_code( self )", + "filename": "accelerate_tools.py", + "nloc": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 264, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "CStr", + "long_name": "CStr( s )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "s" + ], + "start_line": 18, + "end_line": 23, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "check", + "long_name": "check( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 26, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "inbound", + "long_name": "inbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 28, + "end_line": 29, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "outbound", + "long_name": "outbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 30, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "literalizer", + "long_name": "literalizer( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "s" + ], + "start_line": 34, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "binop", + "long_name": "binop( self , symbol , a , b )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 37, + "parameters": [ + "self", + "symbol", + "a", + "b" + ], + "start_line": 36, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "literalizer", + "long_name": "literalizer( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "s" + ], + "start_line": 58, + "end_line": 59, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check", + "long_name": "check( self , s )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self", + "s" + ], + "start_line": 69, + "end_line": 71, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "inbound", + "long_name": "inbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "s" + ], + "start_line": 72, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "outbound", + "long_name": "outbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "s" + ], + "start_line": 74, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "binopMixed", + "long_name": "binopMixed( self , symbol , a , b )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "symbol", + "a", + "b" + ], + "start_line": 76, + "end_line": 77, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "lookup_type", + "long_name": "lookup_type( x )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 2, + "token_count": 40, + "parameters": [ + "x" + ], + "start_line": 94, + "end_line": 99, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , function , * args , ** kw )", + "filename": "accelerate_tools.py", + "nloc": 8, + "complexity": 2, + "token_count": 55, + "parameters": [ + "self", + "function", + "args", + "kw" + ], + "start_line": 106, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__cache", + "long_name": "__cache( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "args" + ], + "start_line": 115, + "end_line": 116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 12, + "complexity": 3, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 118, + "end_line": 132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "signature", + "long_name": "signature( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "args" + ], + "start_line": 134, + "end_line": 137, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "singleton", + "long_name": "singleton( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 20, + "complexity": 3, + "token_count": 137, + "parameters": [ + "self", + "signature" + ], + "start_line": 140, + "end_line": 167, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "identifier", + "long_name": "identifier( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 8, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self", + "signature" + ], + "start_line": 169, + "end_line": 177, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "accelerate", + "long_name": "accelerate( self , signature , identifier )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self", + "signature", + "identifier" + ], + "start_line": 179, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "code", + "long_name": "code( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 4, + "complexity": 1, + "token_count": 39, + "parameters": [ + "self", + "args" + ], + "start_line": 183, + "end_line": 186, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "typedef_by_value", + "long_name": "typedef_by_value( self , v )", + "filename": "accelerate_tools.py", + "nloc": 4, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "v" + ], + "start_line": 193, + "end_line": 196, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , f , signature , name = None )", + "filename": "accelerate_tools.py", + "nloc": 12, + "complexity": 2, + "token_count": 97, + "parameters": [ + "self", + "f", + "signature", + "name" + ], + "start_line": 198, + "end_line": 212, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "function_code", + "long_name": "function_code( self )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 214, + "end_line": 215, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "python_function_definition_code", + "long_name": "python_function_definition_code( self )", + "filename": "accelerate_tools.py", + "nloc": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 217, + "end_line": 221, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "__init__", + "long_name": "__init__( self , f , signature , name = None )", + "filename": "accelerate_tools.py", + "nloc": 11, + "complexity": 2, + "token_count": 85, + "parameters": [ + "self", + "f", + "signature", + "name" + ], + "start_line": 241, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "function_by_signature", + "long_name": "function_by_signature( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self", + "signature" + ], + "start_line": 235, + "end_line": 239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "function_code", + "long_name": "function_code( self )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 4, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 257, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "typedef_by_value", + "long_name": "typedef_by_value( self , v )", + "filename": "accelerate_tools.py", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "v" + ], + "start_line": 229, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "binopMixed", + "long_name": "binopMixed( self , symbol , a , b )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "symbol", + "a", + "b" + ], + "start_line": 78, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + } + ], + "nloc": 197, + "complexity": 38, + "token_count": 1196, + "diff_parsed": { + "added": [ + "from types import FunctionType,IntType,FloatType,StringType,TypeType,XRangeType", + "from bytecodecompiler import CXXCoder,Type_Descriptor,Function_Descriptor", + "class Basic(Type_Descriptor):", + "class Vector(Type_Descriptor):", + " module_init_code = 'import_array'", + "", + " prerequisites = Type_Descriptor.prerequisites+\\", + " return '*((%s*)(%s->data+%s*%s->strides[0]))'%(self.cxxbase,a,b,a),Integer", + "class XRange(Type_Descriptor):", + " cxxtype = 'XRange'", + " prerequisites = ['''", + " class XRange {", + " public:", + " XRange(long aLow, long aHigh, long aStep=1)", + " : low(aLow),high(aHigh),step(aStep)", + " {", + " }", + " long low;", + " long high;", + " long step;", + " };''']", + "", + "# -----------------------------------------------", + "# Singletonize the type names", + "# -----------------------------------------------", + "Integer = Integer()", + "Double = Double()", + "String = String()", + "IntegerVector = IntegerVector()", + "XRange = XRange()", + "", + " IntType: Integer,", + " FloatType: Double,", + " StringType: String,", + " (Numeric.ArrayType,1,'l'): IntegerVector,", + " XRangeType : XRange,", + "import math", + "functiondefs = {", + " (range,(Integer,Integer)):", + " Function_Descriptor(code='XRange(%s)',return_type=XRange),", + "", + " (math.sin,(Double,)):", + " Function_Descriptor(code='sin(%s)',return_type=Double),", + " }", + "", + "", + "class Python2CXX(CXXCoder):", + " if T not in self.used:", + " self.used.append(T)", + " def function_by_signature(self,signature):", + " descriptor = functiondefs[signature]", + " if descriptor.return_type not in self.used:", + " self.used.append(descriptor.return_type)", + " return descriptor", + "", + " map(lambda x: isinstance(x,Type_Descriptor),", + " CXXCoder.__init__(self,f,signature,name)", + "", + " code = self.wrapped_code()", + " for T in self.used:", + " if T != None and T.module_init_code:", + " self.customize.add_module_init_code(T.module_init_code)", + " return code" + ], + "deleted": [ + "from types import FunctionType,IntType,FloatType,StringType,TypeType", + "import bytecodecompiler", + "class Basic(bytecodecompiler.Type_Descriptor):", + "class Vector(bytecodecompiler.Type_Descriptor):", + " prerequisites = bytecodecompiler.Type_Descriptor.prerequisites+\\", + " return '*((%s*)(%s->data+%s*%s->strides[0]))'%(self.cxxbase,a,b,a),Integer()", + " IntType: Integer(),", + " FloatType: Double(),", + " StringType: String(),", + " (Numeric.ArrayType,1,'l'): IntegerVector(),", + "class Python2CXX(bytecodecompiler.CXXCoder):", + " if T not in self.used: self.used.append(T)", + " map(lambda x: isinstance(x,bytecodecompiler.Type_Descriptor),", + " self.customize.add_module_init_code('import_array()\\n')", + " bytecodecompiler.CXXCoder.__init__(self,f,signature,name)", + " return self.wrapped_code()" + ] + } + }, + { + "old_path": "weave/bytecodecompiler.py", + "new_path": "weave/bytecodecompiler.py", + "filename": "bytecodecompiler.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -10,16 +10,33 @@\n import string\n import inspect\n \n-\n ##################################################################\n-# CLASS CXXTYPEDESCRIPTION #\n+# CLASS __DESCRIPTOR #\n ##################################################################\n-class Type_Descriptor:\n+class __Descriptor:\n prerequisites = []\n refcount = 0\n def __repr__(self):\n return self.__module__+'.'+self.__class__.__name__\n \n+##################################################################\n+# CLASS TYPE_DESCRIPTOR #\n+##################################################################\n+class Type_Descriptor(__Descriptor):\n+ module_init_code = ''\n+\n+##################################################################\n+# CLASS FUNCTION_DESCRIPTOR #\n+##################################################################\n+class Function_Descriptor(__Descriptor):\n+ def __init__(self,code,return_type,support=''):\n+\tself.code\t= code\n+\tself.return_type\t= return_type\n+ self.support = support\n+\treturn\n+\n+ \n+ \n \n haveArgument = 90 # Opcodes greater-equal to this have argument\n byName = {\n@@ -1050,11 +1067,10 @@ def LOAD_GLOBAL(self,pc,var_num):\n try:\n F = self.function.func_globals[self.codeobject.co_names[var_num]]\n except:\n- F = getattr(__builtins__,self.codeobject.co_names[var_num])\n+ F = __builtins__[self.codeobject.co_names[var_num]]\n \n # For functions, we see if we know about this function\n if callable(F):\n- assert functiondefs.has_key(F),\"Function %s is known\"%F\n self.push(F,type(F))\n return\n \n@@ -1083,6 +1099,32 @@ def LOAD_GLOBAL(self,pc,var_num):\n self.push(native,t)\n return\n \n+ def SETUP_LOOP(self,pc,delta):\n+ \"Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.\"\n+ return\n+\n+ def FOR_LOOP(self,pc,delta):\n+ \"Iterate over a sequence. TOS is the current index, TOS1 the sequence. First, the next element is computed. If the sequence is exhausted, increment byte code counter by delta. Otherwise, push the sequence, the incremented counter, and the current item onto the stack.\"\n+ # Pull off control variable and range info\n+ v2,t2 = self.pop()\n+ v1,t1 = self.pop()\n+ self.emit('for(%s=%s.low; %s<%s.high; %s += %s.step) {'%(\n+ v2,v1,v2,v1,v2,v1))\n+\n+ # Put range back on for assignment\n+ self.push(v2,t2)\n+ return\n+\n+ def JUMP_ABSOLUTE(self,pc,target):\n+ \"Set byte code counter to target.\"\n+ self.emit('}')\n+ return\n+\n+ def POP_BLOCK(self,pc):\n+ \"Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.\"\n+ return\n+\n+\n ##################################################################\n # MEMBER STORE_FAST #\n ##################################################################\n@@ -1145,30 +1187,21 @@ def CALL_FUNCTION(self,pc,argc):\n \n # Pull function object off stack and get descriptor\n f,t = self.pop()\n- descriptor = functiondefs[f]\n+ signature = (f,tuple(types))\n+ descriptor = self.function_by_signature(signature)\n #self.prerequisites += descriptor['prerequisite']+'\\n'\n \n- # Look through descriptors for a match\n- for inputs,outputs,format in descriptor:\n- if inputs == types:\n- break\n- else:\n- raise TypeError,f\n-\n # Build a rhs\n- rhs = format%string.join(args,',')\n+ rhs = descriptor.code%string.join(args,',')\n \n # Build a statement\n- assert len(outputs) == 1,\"Single valued return\"\n- assert typedefs.has_key(outputs[0]),\"Know about type %s\"%outputs[0]\n- description = typedefs[outputs[0]]\n temp = self.unique()\n self.emit('%s %s = %s;\\n'%(\n- description.cxxtype,\n+ descriptor.return_type.cxxtype,\n temp,\n rhs))\n \n- self.push(temp,outputs[0])\n+ self.push(temp,descriptor.return_type)\n return\n \n \n", + "added_lines": 52, + "deleted_lines": 19, + "source_code": "#**************************************************************************#\n#* FILE ************** bytecodecompiler.py ************************#\n#************************************************************************ **#\n#* Author: Patrick Miller February 9 2002 *#\n#* Copyright (C) 2002 Patrick J. Miller *#\n#**************************************************************************#\n#* *#\n#**************************************************************************#\nfrom types import *\nimport string\nimport inspect\n\n##################################################################\n# CLASS __DESCRIPTOR #\n##################################################################\nclass __Descriptor:\n prerequisites = []\n refcount = 0\n def __repr__(self):\n return self.__module__+'.'+self.__class__.__name__\n\n##################################################################\n# CLASS TYPE_DESCRIPTOR #\n##################################################################\nclass Type_Descriptor(__Descriptor):\n module_init_code = ''\n\n##################################################################\n# CLASS FUNCTION_DESCRIPTOR #\n##################################################################\nclass Function_Descriptor(__Descriptor):\n def __init__(self,code,return_type,support=''):\n\tself.code\t= code\n\tself.return_type\t= return_type\n self.support = support\n\treturn\n\n \n \n\nhaveArgument = 90 # Opcodes greater-equal to this have argument\nbyName = {\n 'STOP_CODE': 0,\n 'POP_TOP': 1,\n 'ROT_TWO': 2,\n 'ROT_THREE': 3,\n 'DUP_TOP': 4,\n 'ROT_FOUR': 5,\n 'UNARY_POSITIVE': 10,\n 'UNARY_NEGATIVE': 11,\n 'UNARY_NOT': 12,\n 'UNARY_CONVERT': 13,\n 'UNARY_INVERT': 15,\n 'BINARY_POWER': 19,\n 'BINARY_MULTIPLY': 20,\n 'BINARY_DIVIDE': 21,\n 'BINARY_MODULO': 22,\n 'BINARY_ADD': 23,\n 'BINARY_SUBTRACT': 24,\n 'BINARY_SUBSCR': 25,\n 'BINARY_FLOOR_DIVIDE': 26,\n 'BINARY_TRUE_DIVIDE': 27,\n 'INPLACE_FLOOR_DIVIDE': 28,\n 'INPLACE_TRUE_DIVIDE': 29,\n 'SLICE': 30,\n 'STORE_SLICE': 40,\n 'DELETE_SLICE': 50,\n 'INPLACE_ADD': 55,\n 'INPLACE_SUBTRACT': 56,\n 'INPLACE_MULTIPLY': 57,\n 'INPLACE_DIVIDE': 58,\n 'INPLACE_MODULO': 59,\n 'STORE_SUBSCR': 60,\n 'DELETE_SUBSCR': 61,\n 'BINARY_LSHIFT': 62,\n 'BINARY_RSHIFT': 63,\n 'BINARY_AND': 64,\n 'BINARY_XOR': 65,\n 'BINARY_OR': 66,\n 'INPLACE_POWER': 67,\n 'GET_ITER': 68,\n 'PRINT_EXPR': 70,\n 'PRINT_ITEM': 71,\n 'PRINT_NEWLINE': 72,\n 'PRINT_ITEM_TO': 73,\n 'PRINT_NEWLINE_TO': 74,\n 'INPLACE_LSHIFT': 75,\n 'INPLACE_RSHIFT': 76,\n 'INPLACE_AND': 77,\n 'INPLACE_XOR': 78,\n 'INPLACE_OR': 79,\n 'BREAK_LOOP': 80,\n 'LOAD_LOCALS': 82,\n 'RETURN_VALUE': 83,\n 'IMPORT_STAR': 84,\n 'EXEC_STMT': 85,\n 'YIELD_VALUE': 86,\n 'POP_BLOCK': 87,\n 'END_FINALLY': 88,\n 'BUILD_CLASS': 89,\n 'STORE_NAME': 90,\n 'DELETE_NAME': 91,\n 'UNPACK_SEQUENCE': 92,\n 'FOR_ITER': 93,\n 'STORE_ATTR': 95,\n 'DELETE_ATTR': 96,\n 'STORE_GLOBAL': 97,\n 'DELETE_GLOBAL': 98,\n 'DUP_TOPX': 99,\n 'LOAD_CONST': 100,\n 'LOAD_NAME': 101,\n 'BUILD_TUPLE': 102,\n 'BUILD_LIST': 103,\n 'BUILD_MAP': 104,\n 'LOAD_ATTR': 105,\n 'COMPARE_OP': 106,\n 'IMPORT_NAME': 107,\n 'IMPORT_FROM': 108,\n 'JUMP_FORWARD': 110,\n 'JUMP_IF_FALSE': 111,\n 'JUMP_IF_TRUE': 112,\n 'JUMP_ABSOLUTE': 113,\n 'FOR_LOOP': 114,\n 'LOAD_GLOBAL': 116,\n 'CONTINUE_LOOP': 119,\n 'SETUP_LOOP': 120,\n 'SETUP_EXCEPT': 121,\n 'SETUP_FINALLY': 122,\n 'LOAD_FAST': 124,\n 'STORE_FAST': 125,\n 'DELETE_FAST': 126,\n 'SET_LINENO': 127,\n 'RAISE_VARARGS': 130,\n 'CALL_FUNCTION': 131,\n 'MAKE_FUNCTION': 132,\n 'BUILD_SLICE': 133,\n 'MAKE_CLOSURE': 134,\n 'LOAD_CLOSURE': 135,\n 'LOAD_DEREF': 136,\n 'STORE_DEREF': 137,\n 'CALL_FUNCTION_VAR': 140,\n 'CALL_FUNCTION_KW': 141,\n 'CALL_FUNCTION_VAR_KW': 142,\n }\n\n# -----------------------------------------------\n# Build one in the reverse sense\n# -----------------------------------------------\nbyOpcode = {}\nfor name,op in map(None, byName.keys(), byName.values()):\n byOpcode[op] = name\n del name\n del op\n \n\n##################################################################\n# FUNCTION OPCODIZE #\n##################################################################\ndef opcodize(s):\n \"Slightly more readable form\"\n length = len(s)\n i = 0\n answer = []\n while i < length:\n bytecode = ord(s[i])\n name = byOpcode[bytecode]\n if bytecode >= haveArgument:\n argument = 256*ord(s[i+2])+ord(s[i+1])\n i += 3\n else:\n argument = None\n i += 1\n answer.append((bytecode,argument,name))\n return answer\n\n\n\n##################################################################\n# FUNCTION LIST #\n##################################################################\ndef listing(f):\n \"Pretty print the internals of your function\"\n assert type(f) == FunctionType,\"Arg %r must be a function\"%f\n filename = f.func_code.co_filename\n try:\n lines = open(filename).readlines()\n except:\n lines = None\n pc = 0\n s = ''\n lastLine = None\n for op,arg,name in opcodize(f.func_code.co_code):\n if lines and name == 'SET_LINENO':\n source = lines[arg-1][:-1]\n while lastLine and lastLine < arg-1:\n nonEmittingSource = lines[lastLine][:-1]\n lastLine += 1\n s += '%3s %20s %5s : %s\\n'%(\n '','','',nonEmittingSource)\n lastLine = arg\n else:\n source = ''\n if arg == None: arg = ''\n s += '%3d] %20s %5s : %s\\n'%(pc,name,arg,source)\n if op >= haveArgument:\n pc += 3\n else:\n pc += 1\n return s\n\n##################################################################\n# CLASS BYTECODEMEANING #\n##################################################################\nclass ByteCodeMeaning:\n def fetch(self, pc,code):\n opcode = ord(code[pc])\n if opcode >= haveArgument:\n argument = 256*ord(code[pc+2])+ord(code[pc+1])\n next = pc+3\n else:\n argument = None\n next = pc+1\n return next,opcode,argument\n \n def execute(self,pc,opcode,argument):\n name = byOpcode[opcode]\n method = getattr(self,name)\n if argument == None:\n return apply(method,(pc,))\n else:\n return apply(method,(pc,argument,))\n\n def evaluate(self, pc,code):\n next, opcode,argument = self.fetch(pc,code)\n goto = self.execute(next,opcode,argument)\n if goto == -1:\n return None # Must be done\n elif goto == None:\n return next # Normal\n else:\n raise 'xx'\n\n symbols = { 0: 'less', 1: 'lesseq', 2: 'equal', 3: 'notequal',\n 4: 'greater', 5: 'greatereq', 6: 'in', 7: 'not in',\n 8: 'is', 9: 'is not', 10: 'exe match',\n 11 : 'bad',\n }\n def cmp_op(self,opname):\n return self.symbols[opname]\n \n def STOP_CODE(self,pc):\n \"Indicates end-of-code to the compiler, not used by the interpreter.\"\n raise NotImplementedError\n def POP_TOP(self,pc):\n \"Removes the top-of-stack (TOS) item.\"\n raise NotImplementedError\n\n def ROT_TWO(self,pc):\n \"Swaps the two top-most stack items.\"\n raise NotImplementedError\n\n def ROT_THREE(self,pc):\n \"Lifts second and third stack item one position up, moves top down to position three.\"\n raise NotImplementedError\n\n def ROT_FOUR(self,pc):\n \"Lifts second, third and forth stack item one position up, moves top down to position four.\"\n raise NotImplementedError\n\n def DUP_TOP(self,pc):\n \"Duplicates the reference on top of the stack.\"\n raise NotImplementedError\n\n # Unary Operations take the top of the stack, apply the operation, and push the result back on the stack.\n\n def UNARY_POSITIVE(self,pc):\n \"Implements TOS = +TOS.\"\n raise NotImplementedError\n\n def UNARY_NEGATIVE(self,pc):\n \"Implements TOS = -TOS.\"\n raise NotImplementedError\n\n def UNARY_NOT(self,pc):\n \"Implements TOS = not TOS.\"\n raise NotImplementedError\n\n def UNARY_CONVERT(self,pc):\n \"Implements TOS = `TOS`.\"\n raise NotImplementedError\n\n def UNARY_INVERT(self,pc):\n \"Implements TOS = ~TOS.\"\n raise NotImplementedError\n\n #Binary operations remove the top of the stack (TOS) and the second top-most stack item (TOS1) from the stack. They perform the operation, and put the result back on the stack.\n\n def BINARY_POWER(self,pc):\n \"Implements TOS = TOS1 ** TOS.\"\n raise NotImplementedError\n\n def BINARY_MULTIPLY(self,pc):\n \"Implements TOS = TOS1 * TOS.\"\n raise NotImplementedError\n\n def BINARY_DIVIDE(self,pc):\n \"Implements TOS = TOS1 / TOS.\"\n raise NotImplementedError\n\n def BINARY_MODULO(self,pc):\n \"Implements TOS = TOS1 % TOS.\"\n raise NotImplementedError\n\n def BINARY_ADD(self,pc):\n \"Implements TOS = TOS1 + TOS.\"\n raise NotImplementedError\n\n def BINARY_SUBTRACT(self,pc):\n \"Implements TOS = TOS1 - TOS.\"\n raise NotImplementedError\n\n def BINARY_SUBSCR(self,pc):\n \"Implements TOS = TOS1[TOS].\"\n raise NotImplementedError\n\n def BINARY_LSHIFT(self,pc):\n \"Implements TOS = TOS1 << TOS.\"\n raise NotImplementedError\n\n def BINARY_RSHIFT(self,pc):\n \"Implements TOS = TOS1 >> TOS.\"\n raise NotImplementedError\n\n def BINARY_AND(self,pc):\n \"Implements TOS = TOS1 & TOS.\"\n raise NotImplementedError\n\n def BINARY_XOR(self,pc):\n \"Implements TOS = TOS1 ^ TOS.\"\n raise NotImplementedError\n\n def BINARY_OR(self,pc):\n \"Implements TOS = TOS1 | TOS.\"\n raise NotImplementedError\n\n #In-place operations are like binary operations, in that they remove TOS and TOS1, and push the result back on the stack, but the operation is done in-place when TOS1 supports it, and the resulting TOS may be (but does not have to be) the original TOS1.\n\n def INPLACE_POWER(self,pc):\n \"Implements in-place TOS = TOS1 ** TOS.\"\n raise NotImplementedError\n\n def INPLACE_MULTIPLY(self,pc):\n \"Implements in-place TOS = TOS1 * TOS.\"\n raise NotImplementedError\n\n def INPLACE_DIVIDE(self,pc):\n \"Implements in-place TOS = TOS1 / TOS.\"\n raise NotImplementedError\n\n def INPLACE_MODULO(self,pc):\n \"Implements in-place TOS = TOS1 % TOS.\"\n raise NotImplementedError\n\n def INPLACE_ADD(self,pc):\n \"Implements in-place TOS = TOS1 + TOS.\"\n raise NotImplementedError\n\n def INPLACE_SUBTRACT(self,pc):\n \"Implements in-place TOS = TOS1 - TOS.\"\n raise NotImplementedError\n\n def INPLACE_LSHIFT(self,pc):\n \"Implements in-place TOS = TOS1 << TOS.\"\n raise NotImplementedError\n\n def INPLACE_RSHIFT(self,pc):\n \"Implements in-place TOS = TOS1 >> TOS.\"\n raise NotImplementedError\n\n def INPLACE_AND(self,pc):\n \"Implements in-place TOS = TOS1 & TOS.\"\n raise NotImplementedError\n\n def INPLACE_XOR(self,pc):\n \"Implements in-place TOS = TOS1 ^ TOS.\"\n raise NotImplementedError\n\n def INPLACE_OR(self,pc):\n \"Implements in-place TOS = TOS1 | TOS.\"\n raise NotImplementedError\n\n #The slice opcodes take up to three parameters.\n\n def SLICE_0(self,pc):\n \"Implements TOS = TOS[:].\"\n raise NotImplementedError\n\n def SLICE_1(self,pc):\n \"Implements TOS = TOS1[TOS:].\"\n raise NotImplementedError\n\n def SLICE_2(self,pc):\n \"Implements TOS = TOS1[:TOS1].\"\n raise NotImplementedError\n\n def SLICE_3(self,pc):\n \"Implements TOS = TOS2[TOS1:TOS].\"\n raise NotImplementedError\n\n #Slice assignment needs even an additional parameter. As any statement, they put nothing on the stack.\n\n def STORE_SLICE_0(self,pc):\n \"Implements TOS[:] = TOS1.\"\n raise NotImplementedError\n\n def STORE_SLICE_1(self,pc):\n \"Implements TOS1[TOS:] = TOS2.\"\n raise NotImplementedError\n\n def STORE_SLICE_2(self,pc):\n \"Implements TOS1[:TOS] = TOS2.\"\n raise NotImplementedError\n\n def STORE_SLICE_3(self,pc):\n \"Implements TOS2[TOS1:TOS] = TOS3.\"\n raise NotImplementedError\n\n def DELETE_SLICE_0(self,pc):\n \"Implements del TOS[:].\"\n raise NotImplementedError\n\n def DELETE_SLICE_1(self,pc):\n \"Implements del TOS1[TOS:].\"\n raise NotImplementedError\n\n def DELETE_SLICE_2(self,pc):\n \"Implements del TOS1[:TOS].\"\n raise NotImplementedError\n\n def DELETE_SLICE_3(self,pc):\n \"Implements del TOS2[TOS1:TOS].\"\n raise NotImplementedError\n\n def STORE_SUBSCR(self,pc):\n \"Implements TOS1[TOS] = TOS2.\"\n raise NotImplementedError\n\n def DELETE_SUBSCR(self,pc):\n \"Implements del TOS1[TOS].\"\n raise NotImplementedError\n\n def PRINT_EXPR(self,pc):\n \"Implements the expression statement for the interactive mode. TOS is removed from the stack and printed. In non-interactive mode, an expression statement is terminated with POP_STACK.\"\n raise NotImplementedError\n\n def PRINT_ITEM(self,pc):\n \"Prints TOS to the file-like object bound to sys.stdout. There is one such instruction for each item in the print statement.\"\n raise NotImplementedError\n\n def PRINT_ITEM_TO(self,pc):\n \"Like PRINT_ITEM, but prints the item second from TOS to the file-like object at TOS. This is used by the extended print statement.\"\n raise NotImplementedError\n\n def PRINT_NEWLINE(self,pc):\n \"Prints a new line on sys.stdout. This is generated as the last operation of a print statement, unless the statement ends with a comma.\"\n raise NotImplementedError\n\n def PRINT_NEWLINE_TO(self,pc):\n \"Like PRINT_NEWLINE, but prints the new line on the file-like object on the TOS. This is used by the extended print statement.\"\n raise NotImplementedError\n\n def BREAK_LOOP(self,pc):\n \"Terminates a loop due to a break statement.\"\n raise NotImplementedError\n\n def LOAD_LOCALS(self,pc):\n \"Pushes a reference to the locals of the current scope on the stack. This is used in the code for a class definition: After the class body is evaluated, the locals are passed to the class definition.\"\n raise NotImplementedError\n\n def RETURN_VALUE(self,pc):\n \"Returns with TOS to the caller of the function.\"\n raise NotImplementedError\n\n def IMPORT_STAR(self,pc):\n \"Loads all symbols not starting with _ directly from the module TOS to the local namespace. The module is popped after loading all names. This opcode implements from module import *.\"\n raise NotImplementedError\n\n def EXEC_STMT(self,pc):\n \"Implements exec TOS2,TOS1,TOS. The compiler fills missing optional parameters with None.\"\n raise NotImplementedError\n\n def POP_BLOCK(self,pc):\n \"Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.\"\n raise NotImplementedError\n\n def END_FINALLY(self,pc):\n \"Terminates a finally clause. The interpreter recalls whether the exception has to be re-raised, or whether the function returns, and continues with the outer-next block.\"\n raise NotImplementedError\n\n def BUILD_CLASS(self,pc):\n \"Creates a new class object. TOS is the methods dictionary, TOS1 the tuple of the names of the base classes, and TOS2 the class name.\"\n raise NotImplementedError\n\n #All of the following opcodes expect arguments. An argument is two bytes, with the more significant byte last.\n\n def STORE_NAME(self,pc,namei):\n \"Implements name = TOS. namei is the index of name in the attribute co_names of the code object. The compiler tries to use STORE_LOCAL or STORE_GLOBAL if possible.\"\n raise NotImplementedError\n\n def DELETE_NAME(self,pc,namei):\n \"Implements del name, where namei is the index into co_names attribute of the code object.\"\n raise NotImplementedError\n\n def UNPACK_SEQUENCE(self,pc,count):\n \"Unpacks TOS into count individual values, which are put onto the stack right-to-left.\"\n raise NotImplementedError\n\n def DUP_TOPX(self,pc,count):\n \"Duplicate count items, keeping them in the same order. Due to implementation limits, count should be between 1 and 5 inclusive.\"\n raise NotImplementedError\n\n def STORE_ATTR(self,pc,namei):\n \"Implements TOS.name = TOS1, where namei is the index of name in co_names.\"\n raise NotImplementedError\n\n def DELETE_ATTR(self,pc,namei):\n \"Implements del TOS.name, using namei as index into co_names.\"\n raise NotImplementedError\n\n def STORE_GLOBAL(self,pc,namei):\n \"Works as STORE_NAME, but stores the name as a global.\"\n raise NotImplementedError\n\n def DELETE_GLOBAL(self,pc,namei):\n \"Works as DELETE_NAME, but deletes a global name.\"\n raise NotImplementedError\n\n def LOAD_CONST(self,pc,consti):\n \"Pushes co_consts[consti] onto the stack.\"\n raise NotImplementedError\n\n def LOAD_NAME(self,pc,namei):\n \"Pushes the value associated with co_names[namei] onto the stack.\"\n raise NotImplementedError\n\n def BUILD_TUPLE(self,pc,count):\n \"Creates a tuple consuming count items from the stack, and pushes the resulting tuple onto the stack.\"\n raise NotImplementedError\n\n def BUILD_LIST(self,pc,count):\n \"Works as BUILD_TUPLE, but creates a list.\"\n raise NotImplementedError\n\n def BUILD_MAP(self,pc,zero):\n \"Pushes a new empty dictionary object onto the stack. The argument is ignored and set to zero by the compiler.\"\n raise NotImplementedError\n\n def LOAD_ATTR(self,pc,namei):\n \"Replaces TOS with getattr(TOS, co_names[namei].\"\n raise NotImplementedError\n\n def COMPARE_OP(self,pc,opname):\n \"Performs a Boolean operation. The operation name can be found in cmp_op[opname].\"\n raise NotImplementedError\n\n def IMPORT_NAME(self,pc,namei):\n \"Imports the module co_names[namei]. The module object is pushed onto the stack. The current namespace is not affected: for a proper import statement, a subsequent STORE_FAST instruction modifies the namespace.\"\n raise NotImplementedError\n\n def IMPORT_FROM(self,pc,namei):\n \"Loads the attribute co_names[namei] from the module found in TOS. The resulting object is pushed onto the stack, to be subsequently stored by a STORE_FAST instruction.\"\n raise NotImplementedError\n\n def JUMP_FORWARD(self,pc,delta):\n \"Increments byte code counter by delta.\"\n raise NotImplementedError\n\n def JUMP_IF_TRUE(self,pc,delta):\n \"If TOS is true, increment the byte code counter by delta. TOS is left on the stack.\"\n raise NotImplementedError\n\n def JUMP_IF_FALSE(self,pc,delta):\n \"If TOS is false, increment the byte code counter by delta. TOS is not changed.\"\n raise NotImplementedError\n\n def JUMP_ABSOLUTE(self,pc,target):\n \"Set byte code counter to target.\"\n raise NotImplementedError\n\n def FOR_LOOP(self,pc,delta):\n \"Iterate over a sequence. TOS is the current index, TOS1 the sequence. First, the next element is computed. If the sequence is exhausted, increment byte code counter by delta. Otherwise, push the sequence, the incremented counter, and the current item onto the stack.\"\n raise NotImplementedError\n\n def LOAD_GLOBAL(self,pc,namei):\n \"Loads the global named co_names[namei] onto the stack.\"\n raise NotImplementedError\n\n def SETUP_LOOP(self,pc,delta):\n \"Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.\"\n raise NotImplementedError\n\n def SETUP_EXCEPT(self,pc,delta):\n \"Pushes a try block from a try-except clause onto the block stack. delta points to the first except block.\"\n raise NotImplementedError\n\n def SETUP_FINALLY(self,pc,delta):\n \"Pushes a try block from a try-except clause onto the block stack. delta points to the finally block.\"\n raise NotImplementedError\n\n def LOAD_FAST(self,pc,var_num):\n \"Pushes a reference to the local co_varnames[var_num] onto the stack.\"\n raise NotImplementedError\n\n def STORE_FAST(self,pc,var_num):\n \"Stores TOS into the local co_varnames[var_num].\"\n raise NotImplementedError\n\n def DELETE_FAST(self,pc,var_num):\n \"Deletes local co_varnames[var_num].\"\n raise NotImplementedError\n\n def LOAD_CLOSURE(self,pc,i):\n \"Pushes a reference to the cell contained in slot i of the cell and free variable storage. The name of the variable is co_cellvars[i] if i is less than the length of co_cellvars. Otherwise it is co_freevars[i - len(co_cellvars)].\"\n raise NotImplementedError\n\n def LOAD_DEREF(self,pc,i):\n \"Loads the cell contained in slot i of the cell and free variable storage. Pushes a reference to the object the cell contains on the stack.\"\n raise NotImplementedError\n\n def STORE_DEREF(self,pc,i):\n \"Stores TOS into the cell contained in slot i of the cell and free variable storage.\"\n raise NotImplementedError\n\n def SET_LINENO(self,pc,lineno):\n \"Sets the current line number to lineno.\"\n raise NotImplementedError\n\n def RAISE_VARARGS(self,pc,argc):\n \"Raises an exception. argc indicates the number of parameters to the raise statement, ranging from 0 to 3. The handler will find the traceback as TOS2, the parameter as TOS1, and the exception as TOS.\"\n raise NotImplementedError\n\n def CALL_FUNCTION(self,pc,argc):\n \"Calls a function. The low byte of argc indicates the number of positional parameters, the high byte the number of keyword parameters. On the stack, the opcode finds the keyword parameters first. For each keyword argument, the value is on top of the key. Below the keyword parameters, the positional parameters are on the stack, with the right-most parameter on top. Below the parameters, the function object to call is on the stack.\"\n raise NotImplementedError\n\n def MAKE_FUNCTION(self,pc,argc):\n \"Pushes a new function object on the stack. TOS is the code associated with the function. The function object is defined to have argc default parameters, which are found below TOS.\"\n raise NotImplementedError\n\n def MAKE_CLOSURE(self,pc,argc):\n \"Creates a new function object, sets its func_closure slot, and pushes it on the stack. TOS is the code associated with the function. If the code object has N free variables, the next N items on the stack are the cells for these variables. The function also has argc default parameters, where are found before the cells.\"\n raise NotImplementedError\n\n def BUILD_SLICE(self,pc,argc):\n \"Pushes a slice object on the stack. argc must be 2 or 3. If it is 2, slice(TOS1, TOS) is pushed; if it is 3, slice(TOS2, TOS1, TOS) is pushed. See the slice() built-in function for more information.\"\n raise NotImplementedError\n\n def EXTENDED_ARG(self,pc,ext):\n \"Prefixes any opcode which has an argument too big to fit into the default two bytes. ext holds two additional bytes which, taken together with the subsequent opcode's argument, comprise a four-byte argument, ext being the two most-significant bytes.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_VAR(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the variable argument list, followed by keyword and positional arguments.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_KW(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by explicit keyword and positional arguments.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_VAR_KW(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by the variable-arguments tuple, followed by explicit keyword and positional arguments.\"\n raise NotImplementedError\n\n \n\n##################################################################\n# CLASS CXXCODER #\n##################################################################\nclass CXXCoder(ByteCodeMeaning):\n\n ##################################################################\n # MEMBER TYPEDEF_BY_VALUE #\n ##################################################################\n def typedef_by_value(self,v):\n raise NotImplementedError # VIRTUAL\n \n ##################################################################\n # MEMBER __INIT__ #\n ##################################################################\n def __init__(self,function,signature,name=None):\n assert type(function) == FunctionType,\"Arg must be a user function\"\n assert not function.func_defaults ,\"Function cannot have default args (yet)\"\n if name == None: name = function.func_name\n self.name = name\n self.function = function\n self.signature = signature\n self.codeobject = function.func_code\n self.__uid = 0 # Builds temps\n return\n\n ##################################################################\n # MEMBER EVALUATE #\n ##################################################################\n def evaluate(self, pc,code):\n # See if we posted any forwards for this offset\n if self.forwards.has_key(pc):\n for f in self.forwards[pc]:\n f()\n self.forwards[pc] = []\n return ByteCodeMeaning.evaluate(self,pc,code)\n \n ##################################################################\n # MEMBER GENERATE #\n ##################################################################\n def generate(self):\n self.forwards = {} # Actions on forward interprets\n self.__body = '' # Body will be built\n self.helpers = [] # headers and stuff\n\n # -----------------------------------------------\n # OK, crack open the function object and build\n # initial stack (not a real frame!)\n # -----------------------------------------------\n arglen = len(self.signature)\n nlocals = self.codeobject.co_nlocals\n\n self.consts = self.codeobject.co_consts\n self.stack = list(self.codeobject.co_varnames)\n self.types = list(self.signature)+[None]*(nlocals-arglen)\n self.used = []\n for T in self.types:\n if T not in self.used: self.used.append(T)\n\n # -----------------------------------------------\n # One pass through the byte codes to generate\n # the body\n # -----------------------------------------------\n code = self.codeobject.co_code\n bytes = len(code)\n pc = 0\n while pc != None and pc < bytes:\n pc = self.evaluate(pc,code)\n\n # -----------------------------------------------\n # Return?\n # -----------------------------------------------\n if self.rtype == NoneType:\n rtype = 'void'\n else:\n rtype = self.rtype.cxxtype\n \n # -----------------------------------------------\n # Insert code body if available\n # -----------------------------------------------\n source = inspect.getsource(self.function)\n if not source: source = ''\n comments = inspect.getcomments(self.function)\n if comments: source = comments+source\n code = string.join(map(lambda x: '/////// '+x,string.split(source,'\\n')),\n '\\n')+'\\n'\n\n # -----------------------------------------------\n # Add in the headers\n # -----------------------------------------------\n code += '#include \"Python.h\"\\n'\n for T in self.used:\n if T == None: continue\n for pre in T.prerequisites:\n code += pre\n code += '\\n'\n\n # -----------------------------------------------\n # Real body\n # -----------------------------------------------\n code += '\\n'\n code += '\\nstatic %s %s('%(rtype,self.name)\n for i in range(len(self.signature)):\n if i != 0: code += ', '\n n = self.stack[i]\n t = self.types[i]\n code += '%s %s'%(t.cxxtype,n)\n code += ') {\\n'\n\n # Add in non-argument temporaries\n # Assuming first argcount locals are positional args\n for i in range(self.codeobject.co_argcount,\n self.codeobject.co_nlocals):\n t = self.types[i]\n code += '%s %s;\\n'%(\n t.cxxtype,\n self.codeobject.co_varnames[i],\n )\n\n # Add in the body\n code += self.__body\n code += '}\\n\\n'\n return code\n\n\n ##################################################################\n # MEMBER WRAPPED_CODE #\n ##################################################################\n def wrapped_code(self):\n code = self.generate()\n \n # -----------------------------------------------\n # Wrapper\n # -----------------------------------------------\n code += 'static PyObject* wrapper_%s(PyObject*,PyObject* args) {\\n'%self.name\n\n code += ' // Length check\\n'\n code += ' if ( PyTuple_Size(args) != %d ) {\\n'%len(self.signature)\n code += ' PyErr_SetString(PyExc_TypeError,\"Expected %d arguments\");\\n'%len(self.signature)\n code += ' return 0;\\n'\n code += ' }\\n'\n\n code += '\\n // Load Py versions of args\\n'\n for i in range(len(self.signature)):\n T = self.signature[i]\n code += ' PyObject* py_%s = PyTuple_GET_ITEM(args,%d);\\n'%(\n self.codeobject.co_varnames[i],i\n )\n\n code += ' if ( !%s ) {\\n'% \\\n T.check('py_'+self.codeobject.co_varnames[i])\n code += ' PyErr_SetString(PyExc_TypeError,\"Bad type for arg %d (expected %s)\");\\n'%(\n i+1,\n T.__class__.__name__)\n code += ' return 0;\\n'\n code += ' }\\n'\n \n code += '\\n // Do conversions\\n'\n argnames = []\n for i in range(len(self.signature)):\n T = self.signature[i]\n\n code += ' %s %s=%s;\\n'%(\n T.cxxtype,\n self.codeobject.co_varnames[i],\n T.inbound('py_'+self.codeobject.co_varnames[i]),\n )\n code += ' if ( PyErr_Occurred() ) return 0;\\n'\n argnames.append(self.codeobject.co_varnames[i])\n\n code += '\\n // Compute result\\n'\n if self.rtype != NoneType:\n code += ' %s _result = '%(\n self.rtype.cxxtype,\n )\n else:\n code += ' '\n code += '%s(%s);\\n'%(\n self.name,\n string.join(argnames,','),\n )\n\n\n code += '\\n // Pack return\\n'\n if ( self.rtype == NoneType ):\n code += ' Py_INCREF(Py_None);\\n'\n code += ' return Py_None;\\n'\n else:\n result = self.rtype.outbound('_result')\n code += ' return %s;\\n'%result\n code += '}\\n'\n return code\n\n\n ##################################################################\n # MEMBER EMIT #\n ##################################################################\n def emit(self,s):\n self.__body += s\n self.__body += '\\n'\n return\n\n ##################################################################\n # MEMBER PUSH #\n ##################################################################\n def push(self,v,t):\n self.stack.append(v)\n self.types.append(t)\n return\n\n\n ##################################################################\n # MEMBER POP #\n ##################################################################\n def pop(self):\n v = self.stack[-1]\n del self.stack[-1]\n t = self.types[-1]\n del self.types[-1]\n return v,t\n\n ##################################################################\n # MEMBER UNIQUE #\n ##################################################################\n def unique(self):\n self.__uid += 1\n return 't%d'%self.__uid\n\n ##################################################################\n # MEMBER POST #\n ##################################################################\n def post(self,pc,action):\n if not self.forwards.has_key(pc):\n self.forwards[pc] = []\n self.forwards[pc].append(action)\n return\n\n ##################################################################\n # MEMBER EMIT_VALUE #\n ##################################################################\n def emit_value(self, v):\n descriptor = self.typedef_by_value(v)\n \n # Convert representation to CXX rhs\n rhs = descriptor.literalizer(v)\n lhs = self.unique()\n self.emit('%s %s = %s;'%(\n descriptor.cxxtype,\n lhs,\n rhs))\n self.push(lhs,descriptor)\n return \n\n ##################################################################\n # MEMBER GLOBAL_INFO #\n ##################################################################\n def global_info(self,var_num):\n # This is the name value is known by\n var_name = self.codeobject.co_names[var_num]\n\n # First, figure out who owns this global\n import sys\n myHash = id(self.function.func_globals)\n for module_name in sys.modules.keys():\n module = sys.modules[module_name]\n if module and id(module.__dict__) == myHash:\n break\n else:\n raise ValueError,'Cannot locate module owning %s'%varname\n return module_name,var_name\n\n ##################################################################\n # MEMBER BINOP #\n ##################################################################\n def binop(self,pc,symbol):\n v2,t2 = self.pop()\n v1,t1 = self.pop()\n\n if t1 == t2:\n rhs,rhs_type = t1.binop(symbol,v1,v2)\n else:\n rhs,rhs_type = t1.binopMixed(symbol,v1,v2)\n \n lhs = self.unique()\n self.emit('%s %s = %s;\\n'%(\n rhs_type.cxxtype,\n lhs,\n rhs))\n print self.__body\n self.push(lhs,rhs_type)\n return \n\n ##################################################################\n # MEMBER BINARY_XXX #\n ##################################################################\n def BINARY_ADD(self,pc):\n return self.binop(pc,'+')\n def BINARY_SUBTRACT(self,pc):\n return self.binop(pc,'-')\n def BINARY_MULTIPLY(self,pc):\n return self.binop(pc,'*')\n def BINARY_DIVIDE(self,pc):\n return self.binop(pc,'/')\n def BINARY_MODULO(self,pc):\n return self.binop(pc,'%')\n def BINARY_SUBSCR(self,pc):\n return self.binop(pc,'[]')\n def COMPARE_OP(self,pc,opname):\n symbol = self.cmp_op(opname) # convert numeric to name\n return self.binop(pc,symbol)\n\n\n ##################################################################\n # MEMBER PRINT_ITEM #\n ##################################################################\n def PRINT_ITEM(self,pc):\n # Printing correctly is tricky... best to let Python\n # do the real work here\n w = self.unique()\n self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n self.emit('if (PyFile_SoftSpace(%s,1)) PyFile_WriteString(\" \",%s);'%(w,w))\n v,t = self.pop()\n\n py = self.unique()\n self.emit('PyObject* %s = %s;'%(py, t.outbound(v)))\n self.emit('PyFile_WriteObject(%s,%s,Py_PRINT_RAW);'%(\n py,w))\n self.emit('Py_XDECREF(%s);'%py)\n return\n\n\n ##################################################################\n # MEMBER PRINT_NEWLINE #\n ##################################################################\n def PRINT_NEWLINE(self,pc):\n # Printing correctly is tricky... best to let Python\n # do the real work here\n w = self.unique()\n self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n self.emit('PyFile_WriteString(\"\\\\n\",%s);'%w);\n self.emit('PyFile_SoftSpace(%s,0);'%w);\n return\n \n ##################################################################\n # MEMBER SET_LINENO #\n ##################################################################\n def SET_LINENO(self,pc,lineno):\n self.emit('// %s:%d'%(self.codeobject.co_filename,lineno))\n return\n\n ##################################################################\n # MEMBER POP_TOP #\n ##################################################################\n def POP_TOP(self,pc):\n v,t = self.pop()\n return\n\n ##################################################################\n # MEMBER LOAD_CONST #\n ##################################################################\n def LOAD_CONST(self,pc,consti):\n # Fetch the constant\n k = self.consts[consti]\n t = type(k)\n print 'LOAD_CONST',repr(k),t\n\n # Fetch a None is just skipped\n if t == NoneType:\n self.push('',t) \n return\n\n self.emit_value(k)\n return\n\n\n ##################################################################\n # MEMBER LOAD_FAST #\n ##################################################################\n def LOAD_FAST(self,pc,var_num):\n v = self.stack[var_num]\n t = self.types[var_num]\n print 'LOADFAST',var_num,v,t\n if t.refcount:\n self.emit('Py_XINCREF(%s);'%v)\n self.push(v,t)\n return\n\n ##################################################################\n # MEMBER LOAD_GLOBAL #\n ##################################################################\n def LOAD_GLOBAL(self,pc,var_num):\n # Figure out the name and load it\n try:\n F = self.function.func_globals[self.codeobject.co_names[var_num]]\n except:\n F = __builtins__[self.codeobject.co_names[var_num]]\n\n # For functions, we see if we know about this function\n if callable(F):\n self.push(F,type(F))\n return\n\n # We need the name of the module that matches\n # the global state for the function and\n # the name of the variable\n module_name,var_name = self.global_info(var_num)\n\n # We hope it's type is correct\n t = type(F)\n descriptor = typedefs[t]\n native = self.unique()\n py = self.unique()\n mod = self.unique()\n\n self.emit('')\n self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n mod,module_name))\n self.emit('PyObject* %s = PyObject_GetAttrString(%s,\"%s\");'%(\n py,mod,var_name))\n self.emit('%s %s = %s;'%(\n descriptor.cxxtype,\n native,\n descriptor.inbound%py))\n\n self.push(native,t)\n return\n\n def SETUP_LOOP(self,pc,delta):\n \"Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.\"\n return\n\n def FOR_LOOP(self,pc,delta):\n \"Iterate over a sequence. TOS is the current index, TOS1 the sequence. First, the next element is computed. If the sequence is exhausted, increment byte code counter by delta. Otherwise, push the sequence, the incremented counter, and the current item onto the stack.\"\n # Pull off control variable and range info\n v2,t2 = self.pop()\n v1,t1 = self.pop()\n self.emit('for(%s=%s.low; %s<%s.high; %s += %s.step) {'%(\n v2,v1,v2,v1,v2,v1))\n\n # Put range back on for assignment\n self.push(v2,t2)\n return\n\n def JUMP_ABSOLUTE(self,pc,target):\n \"Set byte code counter to target.\"\n self.emit('}')\n return\n\n def POP_BLOCK(self,pc):\n \"Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.\"\n return\n\n\n ##################################################################\n # MEMBER STORE_FAST #\n ##################################################################\n def STORE_FAST(self,pc,var_num):\n\n v,t = self.pop()\n print 'STORE FAST',var_num,v,t\n\n save = self.stack[var_num]\n saveT = self.types[var_num]\n\n # See if type is same....\n # Note that None means no assignment made yet\n if saveT == None or t == saveT:\n if t.refcount:\n self.emit('Py_XINCREF(%s);'%v)\n self.emit('Py_XDECREF(%s);'%save)\n self.emit('%s = %s;\\n'%(save,v))\n self.types[var_num] = t\n return\n\n raise TypeError,(t,saveT)\n\n ##################################################################\n # MEMBER STORE_GLOBAL #\n ##################################################################\n def STORE_GLOBAL(self,pc,var_num):\n\n # We need the name of the module that matches\n # the global state for the function and\n # the name of the variable\n module_name,var_name = self.global_info(var_num)\n\n # Convert the value to Python object\n v,t = self.pop()\n descriptor = typedefs[t]\n py = self.unique()\n self.emit('PyObject* %s = %s;'%(\n py,\n descriptor.outbound%v))\n mod = self.unique()\n self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n mod,module_name))\n self.emit('PyObject_SetAttrString(%s,\"%s\",%s);'%(\n mod,var_name,py))\n self.emit('Py_DECREF(%s);'%py)\n return\n\n ##################################################################\n # MEMBER CALL_FUNCTION #\n ##################################################################\n def CALL_FUNCTION(self,pc,argc):\n # Pull args off stack\n args = []\n types = []\n for i in range(argc):\n v,t = self.pop()\n args = [v]+args\n types = [t]+types\n \n # Pull function object off stack and get descriptor\n f,t = self.pop()\n signature = (f,tuple(types))\n descriptor = self.function_by_signature(signature)\n #self.prerequisites += descriptor['prerequisite']+'\\n'\n \n # Build a rhs\n rhs = descriptor.code%string.join(args,',')\n\n # Build a statement\n temp = self.unique()\n self.emit('%s %s = %s;\\n'%(\n descriptor.return_type.cxxtype,\n temp,\n rhs))\n\n self.push(temp,descriptor.return_type)\n return\n\n\n ##################################################################\n # MEMBER JUMP_IF_FALSE #\n ##################################################################\n def JUMP_IF_FALSE(self,pc,delta):\n v,t = self.pop()\n self.push(v,t)\n # We need to do some work when we get to the\n # else part (put the value that's gonna get\n # popped back on the stack, emit } else {,\n # ...)\n action = lambda v=v,t=t,self=self: (\n self.emit('} else {'),\n self.push(v,t),\n )\n self.post(pc+delta,action)\n if t != IntType: raise TypeError, 'Invalid comparison type %s'%t\n self.emit('if (%s) {\\n'%v)\n return\n \n\n ##################################################################\n # MEMBER JUMP_FORWARD #\n ##################################################################\n def JUMP_FORWARD(self,pc,delta):\n # We need to close the if after the delta\n action = lambda self=self: (\n self.emit('}'),\n )\n self.post(pc+delta,action)\n return\n \n ##################################################################\n # MEMBER RETURN_VALUE #\n ##################################################################\n def RETURN_VALUE(self,pc):\n v,t = self.pop()\n if hasattr(self,'rtype'):\n print v,t\n if t == NoneType: return # just the extra return\n raise ValueError,'multiple returns'\n self.rtype = t\n if t == NoneType:\n self.emit('return;')\n else:\n self.emit('return %s;'%v)\n print 'return with',v\n return\n\n", + "source_code_before": "#**************************************************************************#\n#* FILE ************** bytecodecompiler.py ************************#\n#************************************************************************ **#\n#* Author: Patrick Miller February 9 2002 *#\n#* Copyright (C) 2002 Patrick J. Miller *#\n#**************************************************************************#\n#* *#\n#**************************************************************************#\nfrom types import *\nimport string\nimport inspect\n\n\n##################################################################\n# CLASS CXXTYPEDESCRIPTION #\n##################################################################\nclass Type_Descriptor:\n prerequisites = []\n refcount = 0\n def __repr__(self):\n return self.__module__+'.'+self.__class__.__name__\n\n\nhaveArgument = 90 # Opcodes greater-equal to this have argument\nbyName = {\n 'STOP_CODE': 0,\n 'POP_TOP': 1,\n 'ROT_TWO': 2,\n 'ROT_THREE': 3,\n 'DUP_TOP': 4,\n 'ROT_FOUR': 5,\n 'UNARY_POSITIVE': 10,\n 'UNARY_NEGATIVE': 11,\n 'UNARY_NOT': 12,\n 'UNARY_CONVERT': 13,\n 'UNARY_INVERT': 15,\n 'BINARY_POWER': 19,\n 'BINARY_MULTIPLY': 20,\n 'BINARY_DIVIDE': 21,\n 'BINARY_MODULO': 22,\n 'BINARY_ADD': 23,\n 'BINARY_SUBTRACT': 24,\n 'BINARY_SUBSCR': 25,\n 'BINARY_FLOOR_DIVIDE': 26,\n 'BINARY_TRUE_DIVIDE': 27,\n 'INPLACE_FLOOR_DIVIDE': 28,\n 'INPLACE_TRUE_DIVIDE': 29,\n 'SLICE': 30,\n 'STORE_SLICE': 40,\n 'DELETE_SLICE': 50,\n 'INPLACE_ADD': 55,\n 'INPLACE_SUBTRACT': 56,\n 'INPLACE_MULTIPLY': 57,\n 'INPLACE_DIVIDE': 58,\n 'INPLACE_MODULO': 59,\n 'STORE_SUBSCR': 60,\n 'DELETE_SUBSCR': 61,\n 'BINARY_LSHIFT': 62,\n 'BINARY_RSHIFT': 63,\n 'BINARY_AND': 64,\n 'BINARY_XOR': 65,\n 'BINARY_OR': 66,\n 'INPLACE_POWER': 67,\n 'GET_ITER': 68,\n 'PRINT_EXPR': 70,\n 'PRINT_ITEM': 71,\n 'PRINT_NEWLINE': 72,\n 'PRINT_ITEM_TO': 73,\n 'PRINT_NEWLINE_TO': 74,\n 'INPLACE_LSHIFT': 75,\n 'INPLACE_RSHIFT': 76,\n 'INPLACE_AND': 77,\n 'INPLACE_XOR': 78,\n 'INPLACE_OR': 79,\n 'BREAK_LOOP': 80,\n 'LOAD_LOCALS': 82,\n 'RETURN_VALUE': 83,\n 'IMPORT_STAR': 84,\n 'EXEC_STMT': 85,\n 'YIELD_VALUE': 86,\n 'POP_BLOCK': 87,\n 'END_FINALLY': 88,\n 'BUILD_CLASS': 89,\n 'STORE_NAME': 90,\n 'DELETE_NAME': 91,\n 'UNPACK_SEQUENCE': 92,\n 'FOR_ITER': 93,\n 'STORE_ATTR': 95,\n 'DELETE_ATTR': 96,\n 'STORE_GLOBAL': 97,\n 'DELETE_GLOBAL': 98,\n 'DUP_TOPX': 99,\n 'LOAD_CONST': 100,\n 'LOAD_NAME': 101,\n 'BUILD_TUPLE': 102,\n 'BUILD_LIST': 103,\n 'BUILD_MAP': 104,\n 'LOAD_ATTR': 105,\n 'COMPARE_OP': 106,\n 'IMPORT_NAME': 107,\n 'IMPORT_FROM': 108,\n 'JUMP_FORWARD': 110,\n 'JUMP_IF_FALSE': 111,\n 'JUMP_IF_TRUE': 112,\n 'JUMP_ABSOLUTE': 113,\n 'FOR_LOOP': 114,\n 'LOAD_GLOBAL': 116,\n 'CONTINUE_LOOP': 119,\n 'SETUP_LOOP': 120,\n 'SETUP_EXCEPT': 121,\n 'SETUP_FINALLY': 122,\n 'LOAD_FAST': 124,\n 'STORE_FAST': 125,\n 'DELETE_FAST': 126,\n 'SET_LINENO': 127,\n 'RAISE_VARARGS': 130,\n 'CALL_FUNCTION': 131,\n 'MAKE_FUNCTION': 132,\n 'BUILD_SLICE': 133,\n 'MAKE_CLOSURE': 134,\n 'LOAD_CLOSURE': 135,\n 'LOAD_DEREF': 136,\n 'STORE_DEREF': 137,\n 'CALL_FUNCTION_VAR': 140,\n 'CALL_FUNCTION_KW': 141,\n 'CALL_FUNCTION_VAR_KW': 142,\n }\n\n# -----------------------------------------------\n# Build one in the reverse sense\n# -----------------------------------------------\nbyOpcode = {}\nfor name,op in map(None, byName.keys(), byName.values()):\n byOpcode[op] = name\n del name\n del op\n \n\n##################################################################\n# FUNCTION OPCODIZE #\n##################################################################\ndef opcodize(s):\n \"Slightly more readable form\"\n length = len(s)\n i = 0\n answer = []\n while i < length:\n bytecode = ord(s[i])\n name = byOpcode[bytecode]\n if bytecode >= haveArgument:\n argument = 256*ord(s[i+2])+ord(s[i+1])\n i += 3\n else:\n argument = None\n i += 1\n answer.append((bytecode,argument,name))\n return answer\n\n\n\n##################################################################\n# FUNCTION LIST #\n##################################################################\ndef listing(f):\n \"Pretty print the internals of your function\"\n assert type(f) == FunctionType,\"Arg %r must be a function\"%f\n filename = f.func_code.co_filename\n try:\n lines = open(filename).readlines()\n except:\n lines = None\n pc = 0\n s = ''\n lastLine = None\n for op,arg,name in opcodize(f.func_code.co_code):\n if lines and name == 'SET_LINENO':\n source = lines[arg-1][:-1]\n while lastLine and lastLine < arg-1:\n nonEmittingSource = lines[lastLine][:-1]\n lastLine += 1\n s += '%3s %20s %5s : %s\\n'%(\n '','','',nonEmittingSource)\n lastLine = arg\n else:\n source = ''\n if arg == None: arg = ''\n s += '%3d] %20s %5s : %s\\n'%(pc,name,arg,source)\n if op >= haveArgument:\n pc += 3\n else:\n pc += 1\n return s\n\n##################################################################\n# CLASS BYTECODEMEANING #\n##################################################################\nclass ByteCodeMeaning:\n def fetch(self, pc,code):\n opcode = ord(code[pc])\n if opcode >= haveArgument:\n argument = 256*ord(code[pc+2])+ord(code[pc+1])\n next = pc+3\n else:\n argument = None\n next = pc+1\n return next,opcode,argument\n \n def execute(self,pc,opcode,argument):\n name = byOpcode[opcode]\n method = getattr(self,name)\n if argument == None:\n return apply(method,(pc,))\n else:\n return apply(method,(pc,argument,))\n\n def evaluate(self, pc,code):\n next, opcode,argument = self.fetch(pc,code)\n goto = self.execute(next,opcode,argument)\n if goto == -1:\n return None # Must be done\n elif goto == None:\n return next # Normal\n else:\n raise 'xx'\n\n symbols = { 0: 'less', 1: 'lesseq', 2: 'equal', 3: 'notequal',\n 4: 'greater', 5: 'greatereq', 6: 'in', 7: 'not in',\n 8: 'is', 9: 'is not', 10: 'exe match',\n 11 : 'bad',\n }\n def cmp_op(self,opname):\n return self.symbols[opname]\n \n def STOP_CODE(self,pc):\n \"Indicates end-of-code to the compiler, not used by the interpreter.\"\n raise NotImplementedError\n def POP_TOP(self,pc):\n \"Removes the top-of-stack (TOS) item.\"\n raise NotImplementedError\n\n def ROT_TWO(self,pc):\n \"Swaps the two top-most stack items.\"\n raise NotImplementedError\n\n def ROT_THREE(self,pc):\n \"Lifts second and third stack item one position up, moves top down to position three.\"\n raise NotImplementedError\n\n def ROT_FOUR(self,pc):\n \"Lifts second, third and forth stack item one position up, moves top down to position four.\"\n raise NotImplementedError\n\n def DUP_TOP(self,pc):\n \"Duplicates the reference on top of the stack.\"\n raise NotImplementedError\n\n # Unary Operations take the top of the stack, apply the operation, and push the result back on the stack.\n\n def UNARY_POSITIVE(self,pc):\n \"Implements TOS = +TOS.\"\n raise NotImplementedError\n\n def UNARY_NEGATIVE(self,pc):\n \"Implements TOS = -TOS.\"\n raise NotImplementedError\n\n def UNARY_NOT(self,pc):\n \"Implements TOS = not TOS.\"\n raise NotImplementedError\n\n def UNARY_CONVERT(self,pc):\n \"Implements TOS = `TOS`.\"\n raise NotImplementedError\n\n def UNARY_INVERT(self,pc):\n \"Implements TOS = ~TOS.\"\n raise NotImplementedError\n\n #Binary operations remove the top of the stack (TOS) and the second top-most stack item (TOS1) from the stack. They perform the operation, and put the result back on the stack.\n\n def BINARY_POWER(self,pc):\n \"Implements TOS = TOS1 ** TOS.\"\n raise NotImplementedError\n\n def BINARY_MULTIPLY(self,pc):\n \"Implements TOS = TOS1 * TOS.\"\n raise NotImplementedError\n\n def BINARY_DIVIDE(self,pc):\n \"Implements TOS = TOS1 / TOS.\"\n raise NotImplementedError\n\n def BINARY_MODULO(self,pc):\n \"Implements TOS = TOS1 % TOS.\"\n raise NotImplementedError\n\n def BINARY_ADD(self,pc):\n \"Implements TOS = TOS1 + TOS.\"\n raise NotImplementedError\n\n def BINARY_SUBTRACT(self,pc):\n \"Implements TOS = TOS1 - TOS.\"\n raise NotImplementedError\n\n def BINARY_SUBSCR(self,pc):\n \"Implements TOS = TOS1[TOS].\"\n raise NotImplementedError\n\n def BINARY_LSHIFT(self,pc):\n \"Implements TOS = TOS1 << TOS.\"\n raise NotImplementedError\n\n def BINARY_RSHIFT(self,pc):\n \"Implements TOS = TOS1 >> TOS.\"\n raise NotImplementedError\n\n def BINARY_AND(self,pc):\n \"Implements TOS = TOS1 & TOS.\"\n raise NotImplementedError\n\n def BINARY_XOR(self,pc):\n \"Implements TOS = TOS1 ^ TOS.\"\n raise NotImplementedError\n\n def BINARY_OR(self,pc):\n \"Implements TOS = TOS1 | TOS.\"\n raise NotImplementedError\n\n #In-place operations are like binary operations, in that they remove TOS and TOS1, and push the result back on the stack, but the operation is done in-place when TOS1 supports it, and the resulting TOS may be (but does not have to be) the original TOS1.\n\n def INPLACE_POWER(self,pc):\n \"Implements in-place TOS = TOS1 ** TOS.\"\n raise NotImplementedError\n\n def INPLACE_MULTIPLY(self,pc):\n \"Implements in-place TOS = TOS1 * TOS.\"\n raise NotImplementedError\n\n def INPLACE_DIVIDE(self,pc):\n \"Implements in-place TOS = TOS1 / TOS.\"\n raise NotImplementedError\n\n def INPLACE_MODULO(self,pc):\n \"Implements in-place TOS = TOS1 % TOS.\"\n raise NotImplementedError\n\n def INPLACE_ADD(self,pc):\n \"Implements in-place TOS = TOS1 + TOS.\"\n raise NotImplementedError\n\n def INPLACE_SUBTRACT(self,pc):\n \"Implements in-place TOS = TOS1 - TOS.\"\n raise NotImplementedError\n\n def INPLACE_LSHIFT(self,pc):\n \"Implements in-place TOS = TOS1 << TOS.\"\n raise NotImplementedError\n\n def INPLACE_RSHIFT(self,pc):\n \"Implements in-place TOS = TOS1 >> TOS.\"\n raise NotImplementedError\n\n def INPLACE_AND(self,pc):\n \"Implements in-place TOS = TOS1 & TOS.\"\n raise NotImplementedError\n\n def INPLACE_XOR(self,pc):\n \"Implements in-place TOS = TOS1 ^ TOS.\"\n raise NotImplementedError\n\n def INPLACE_OR(self,pc):\n \"Implements in-place TOS = TOS1 | TOS.\"\n raise NotImplementedError\n\n #The slice opcodes take up to three parameters.\n\n def SLICE_0(self,pc):\n \"Implements TOS = TOS[:].\"\n raise NotImplementedError\n\n def SLICE_1(self,pc):\n \"Implements TOS = TOS1[TOS:].\"\n raise NotImplementedError\n\n def SLICE_2(self,pc):\n \"Implements TOS = TOS1[:TOS1].\"\n raise NotImplementedError\n\n def SLICE_3(self,pc):\n \"Implements TOS = TOS2[TOS1:TOS].\"\n raise NotImplementedError\n\n #Slice assignment needs even an additional parameter. As any statement, they put nothing on the stack.\n\n def STORE_SLICE_0(self,pc):\n \"Implements TOS[:] = TOS1.\"\n raise NotImplementedError\n\n def STORE_SLICE_1(self,pc):\n \"Implements TOS1[TOS:] = TOS2.\"\n raise NotImplementedError\n\n def STORE_SLICE_2(self,pc):\n \"Implements TOS1[:TOS] = TOS2.\"\n raise NotImplementedError\n\n def STORE_SLICE_3(self,pc):\n \"Implements TOS2[TOS1:TOS] = TOS3.\"\n raise NotImplementedError\n\n def DELETE_SLICE_0(self,pc):\n \"Implements del TOS[:].\"\n raise NotImplementedError\n\n def DELETE_SLICE_1(self,pc):\n \"Implements del TOS1[TOS:].\"\n raise NotImplementedError\n\n def DELETE_SLICE_2(self,pc):\n \"Implements del TOS1[:TOS].\"\n raise NotImplementedError\n\n def DELETE_SLICE_3(self,pc):\n \"Implements del TOS2[TOS1:TOS].\"\n raise NotImplementedError\n\n def STORE_SUBSCR(self,pc):\n \"Implements TOS1[TOS] = TOS2.\"\n raise NotImplementedError\n\n def DELETE_SUBSCR(self,pc):\n \"Implements del TOS1[TOS].\"\n raise NotImplementedError\n\n def PRINT_EXPR(self,pc):\n \"Implements the expression statement for the interactive mode. TOS is removed from the stack and printed. In non-interactive mode, an expression statement is terminated with POP_STACK.\"\n raise NotImplementedError\n\n def PRINT_ITEM(self,pc):\n \"Prints TOS to the file-like object bound to sys.stdout. There is one such instruction for each item in the print statement.\"\n raise NotImplementedError\n\n def PRINT_ITEM_TO(self,pc):\n \"Like PRINT_ITEM, but prints the item second from TOS to the file-like object at TOS. This is used by the extended print statement.\"\n raise NotImplementedError\n\n def PRINT_NEWLINE(self,pc):\n \"Prints a new line on sys.stdout. This is generated as the last operation of a print statement, unless the statement ends with a comma.\"\n raise NotImplementedError\n\n def PRINT_NEWLINE_TO(self,pc):\n \"Like PRINT_NEWLINE, but prints the new line on the file-like object on the TOS. This is used by the extended print statement.\"\n raise NotImplementedError\n\n def BREAK_LOOP(self,pc):\n \"Terminates a loop due to a break statement.\"\n raise NotImplementedError\n\n def LOAD_LOCALS(self,pc):\n \"Pushes a reference to the locals of the current scope on the stack. This is used in the code for a class definition: After the class body is evaluated, the locals are passed to the class definition.\"\n raise NotImplementedError\n\n def RETURN_VALUE(self,pc):\n \"Returns with TOS to the caller of the function.\"\n raise NotImplementedError\n\n def IMPORT_STAR(self,pc):\n \"Loads all symbols not starting with _ directly from the module TOS to the local namespace. The module is popped after loading all names. This opcode implements from module import *.\"\n raise NotImplementedError\n\n def EXEC_STMT(self,pc):\n \"Implements exec TOS2,TOS1,TOS. The compiler fills missing optional parameters with None.\"\n raise NotImplementedError\n\n def POP_BLOCK(self,pc):\n \"Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.\"\n raise NotImplementedError\n\n def END_FINALLY(self,pc):\n \"Terminates a finally clause. The interpreter recalls whether the exception has to be re-raised, or whether the function returns, and continues with the outer-next block.\"\n raise NotImplementedError\n\n def BUILD_CLASS(self,pc):\n \"Creates a new class object. TOS is the methods dictionary, TOS1 the tuple of the names of the base classes, and TOS2 the class name.\"\n raise NotImplementedError\n\n #All of the following opcodes expect arguments. An argument is two bytes, with the more significant byte last.\n\n def STORE_NAME(self,pc,namei):\n \"Implements name = TOS. namei is the index of name in the attribute co_names of the code object. The compiler tries to use STORE_LOCAL or STORE_GLOBAL if possible.\"\n raise NotImplementedError\n\n def DELETE_NAME(self,pc,namei):\n \"Implements del name, where namei is the index into co_names attribute of the code object.\"\n raise NotImplementedError\n\n def UNPACK_SEQUENCE(self,pc,count):\n \"Unpacks TOS into count individual values, which are put onto the stack right-to-left.\"\n raise NotImplementedError\n\n def DUP_TOPX(self,pc,count):\n \"Duplicate count items, keeping them in the same order. Due to implementation limits, count should be between 1 and 5 inclusive.\"\n raise NotImplementedError\n\n def STORE_ATTR(self,pc,namei):\n \"Implements TOS.name = TOS1, where namei is the index of name in co_names.\"\n raise NotImplementedError\n\n def DELETE_ATTR(self,pc,namei):\n \"Implements del TOS.name, using namei as index into co_names.\"\n raise NotImplementedError\n\n def STORE_GLOBAL(self,pc,namei):\n \"Works as STORE_NAME, but stores the name as a global.\"\n raise NotImplementedError\n\n def DELETE_GLOBAL(self,pc,namei):\n \"Works as DELETE_NAME, but deletes a global name.\"\n raise NotImplementedError\n\n def LOAD_CONST(self,pc,consti):\n \"Pushes co_consts[consti] onto the stack.\"\n raise NotImplementedError\n\n def LOAD_NAME(self,pc,namei):\n \"Pushes the value associated with co_names[namei] onto the stack.\"\n raise NotImplementedError\n\n def BUILD_TUPLE(self,pc,count):\n \"Creates a tuple consuming count items from the stack, and pushes the resulting tuple onto the stack.\"\n raise NotImplementedError\n\n def BUILD_LIST(self,pc,count):\n \"Works as BUILD_TUPLE, but creates a list.\"\n raise NotImplementedError\n\n def BUILD_MAP(self,pc,zero):\n \"Pushes a new empty dictionary object onto the stack. The argument is ignored and set to zero by the compiler.\"\n raise NotImplementedError\n\n def LOAD_ATTR(self,pc,namei):\n \"Replaces TOS with getattr(TOS, co_names[namei].\"\n raise NotImplementedError\n\n def COMPARE_OP(self,pc,opname):\n \"Performs a Boolean operation. The operation name can be found in cmp_op[opname].\"\n raise NotImplementedError\n\n def IMPORT_NAME(self,pc,namei):\n \"Imports the module co_names[namei]. The module object is pushed onto the stack. The current namespace is not affected: for a proper import statement, a subsequent STORE_FAST instruction modifies the namespace.\"\n raise NotImplementedError\n\n def IMPORT_FROM(self,pc,namei):\n \"Loads the attribute co_names[namei] from the module found in TOS. The resulting object is pushed onto the stack, to be subsequently stored by a STORE_FAST instruction.\"\n raise NotImplementedError\n\n def JUMP_FORWARD(self,pc,delta):\n \"Increments byte code counter by delta.\"\n raise NotImplementedError\n\n def JUMP_IF_TRUE(self,pc,delta):\n \"If TOS is true, increment the byte code counter by delta. TOS is left on the stack.\"\n raise NotImplementedError\n\n def JUMP_IF_FALSE(self,pc,delta):\n \"If TOS is false, increment the byte code counter by delta. TOS is not changed.\"\n raise NotImplementedError\n\n def JUMP_ABSOLUTE(self,pc,target):\n \"Set byte code counter to target.\"\n raise NotImplementedError\n\n def FOR_LOOP(self,pc,delta):\n \"Iterate over a sequence. TOS is the current index, TOS1 the sequence. First, the next element is computed. If the sequence is exhausted, increment byte code counter by delta. Otherwise, push the sequence, the incremented counter, and the current item onto the stack.\"\n raise NotImplementedError\n\n def LOAD_GLOBAL(self,pc,namei):\n \"Loads the global named co_names[namei] onto the stack.\"\n raise NotImplementedError\n\n def SETUP_LOOP(self,pc,delta):\n \"Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.\"\n raise NotImplementedError\n\n def SETUP_EXCEPT(self,pc,delta):\n \"Pushes a try block from a try-except clause onto the block stack. delta points to the first except block.\"\n raise NotImplementedError\n\n def SETUP_FINALLY(self,pc,delta):\n \"Pushes a try block from a try-except clause onto the block stack. delta points to the finally block.\"\n raise NotImplementedError\n\n def LOAD_FAST(self,pc,var_num):\n \"Pushes a reference to the local co_varnames[var_num] onto the stack.\"\n raise NotImplementedError\n\n def STORE_FAST(self,pc,var_num):\n \"Stores TOS into the local co_varnames[var_num].\"\n raise NotImplementedError\n\n def DELETE_FAST(self,pc,var_num):\n \"Deletes local co_varnames[var_num].\"\n raise NotImplementedError\n\n def LOAD_CLOSURE(self,pc,i):\n \"Pushes a reference to the cell contained in slot i of the cell and free variable storage. The name of the variable is co_cellvars[i] if i is less than the length of co_cellvars. Otherwise it is co_freevars[i - len(co_cellvars)].\"\n raise NotImplementedError\n\n def LOAD_DEREF(self,pc,i):\n \"Loads the cell contained in slot i of the cell and free variable storage. Pushes a reference to the object the cell contains on the stack.\"\n raise NotImplementedError\n\n def STORE_DEREF(self,pc,i):\n \"Stores TOS into the cell contained in slot i of the cell and free variable storage.\"\n raise NotImplementedError\n\n def SET_LINENO(self,pc,lineno):\n \"Sets the current line number to lineno.\"\n raise NotImplementedError\n\n def RAISE_VARARGS(self,pc,argc):\n \"Raises an exception. argc indicates the number of parameters to the raise statement, ranging from 0 to 3. The handler will find the traceback as TOS2, the parameter as TOS1, and the exception as TOS.\"\n raise NotImplementedError\n\n def CALL_FUNCTION(self,pc,argc):\n \"Calls a function. The low byte of argc indicates the number of positional parameters, the high byte the number of keyword parameters. On the stack, the opcode finds the keyword parameters first. For each keyword argument, the value is on top of the key. Below the keyword parameters, the positional parameters are on the stack, with the right-most parameter on top. Below the parameters, the function object to call is on the stack.\"\n raise NotImplementedError\n\n def MAKE_FUNCTION(self,pc,argc):\n \"Pushes a new function object on the stack. TOS is the code associated with the function. The function object is defined to have argc default parameters, which are found below TOS.\"\n raise NotImplementedError\n\n def MAKE_CLOSURE(self,pc,argc):\n \"Creates a new function object, sets its func_closure slot, and pushes it on the stack. TOS is the code associated with the function. If the code object has N free variables, the next N items on the stack are the cells for these variables. The function also has argc default parameters, where are found before the cells.\"\n raise NotImplementedError\n\n def BUILD_SLICE(self,pc,argc):\n \"Pushes a slice object on the stack. argc must be 2 or 3. If it is 2, slice(TOS1, TOS) is pushed; if it is 3, slice(TOS2, TOS1, TOS) is pushed. See the slice() built-in function for more information.\"\n raise NotImplementedError\n\n def EXTENDED_ARG(self,pc,ext):\n \"Prefixes any opcode which has an argument too big to fit into the default two bytes. ext holds two additional bytes which, taken together with the subsequent opcode's argument, comprise a four-byte argument, ext being the two most-significant bytes.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_VAR(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the variable argument list, followed by keyword and positional arguments.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_KW(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by explicit keyword and positional arguments.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_VAR_KW(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by the variable-arguments tuple, followed by explicit keyword and positional arguments.\"\n raise NotImplementedError\n\n \n\n##################################################################\n# CLASS CXXCODER #\n##################################################################\nclass CXXCoder(ByteCodeMeaning):\n\n ##################################################################\n # MEMBER TYPEDEF_BY_VALUE #\n ##################################################################\n def typedef_by_value(self,v):\n raise NotImplementedError # VIRTUAL\n \n ##################################################################\n # MEMBER __INIT__ #\n ##################################################################\n def __init__(self,function,signature,name=None):\n assert type(function) == FunctionType,\"Arg must be a user function\"\n assert not function.func_defaults ,\"Function cannot have default args (yet)\"\n if name == None: name = function.func_name\n self.name = name\n self.function = function\n self.signature = signature\n self.codeobject = function.func_code\n self.__uid = 0 # Builds temps\n return\n\n ##################################################################\n # MEMBER EVALUATE #\n ##################################################################\n def evaluate(self, pc,code):\n # See if we posted any forwards for this offset\n if self.forwards.has_key(pc):\n for f in self.forwards[pc]:\n f()\n self.forwards[pc] = []\n return ByteCodeMeaning.evaluate(self,pc,code)\n \n ##################################################################\n # MEMBER GENERATE #\n ##################################################################\n def generate(self):\n self.forwards = {} # Actions on forward interprets\n self.__body = '' # Body will be built\n self.helpers = [] # headers and stuff\n\n # -----------------------------------------------\n # OK, crack open the function object and build\n # initial stack (not a real frame!)\n # -----------------------------------------------\n arglen = len(self.signature)\n nlocals = self.codeobject.co_nlocals\n\n self.consts = self.codeobject.co_consts\n self.stack = list(self.codeobject.co_varnames)\n self.types = list(self.signature)+[None]*(nlocals-arglen)\n self.used = []\n for T in self.types:\n if T not in self.used: self.used.append(T)\n\n # -----------------------------------------------\n # One pass through the byte codes to generate\n # the body\n # -----------------------------------------------\n code = self.codeobject.co_code\n bytes = len(code)\n pc = 0\n while pc != None and pc < bytes:\n pc = self.evaluate(pc,code)\n\n # -----------------------------------------------\n # Return?\n # -----------------------------------------------\n if self.rtype == NoneType:\n rtype = 'void'\n else:\n rtype = self.rtype.cxxtype\n \n # -----------------------------------------------\n # Insert code body if available\n # -----------------------------------------------\n source = inspect.getsource(self.function)\n if not source: source = ''\n comments = inspect.getcomments(self.function)\n if comments: source = comments+source\n code = string.join(map(lambda x: '/////// '+x,string.split(source,'\\n')),\n '\\n')+'\\n'\n\n # -----------------------------------------------\n # Add in the headers\n # -----------------------------------------------\n code += '#include \"Python.h\"\\n'\n for T in self.used:\n if T == None: continue\n for pre in T.prerequisites:\n code += pre\n code += '\\n'\n\n # -----------------------------------------------\n # Real body\n # -----------------------------------------------\n code += '\\n'\n code += '\\nstatic %s %s('%(rtype,self.name)\n for i in range(len(self.signature)):\n if i != 0: code += ', '\n n = self.stack[i]\n t = self.types[i]\n code += '%s %s'%(t.cxxtype,n)\n code += ') {\\n'\n\n # Add in non-argument temporaries\n # Assuming first argcount locals are positional args\n for i in range(self.codeobject.co_argcount,\n self.codeobject.co_nlocals):\n t = self.types[i]\n code += '%s %s;\\n'%(\n t.cxxtype,\n self.codeobject.co_varnames[i],\n )\n\n # Add in the body\n code += self.__body\n code += '}\\n\\n'\n return code\n\n\n ##################################################################\n # MEMBER WRAPPED_CODE #\n ##################################################################\n def wrapped_code(self):\n code = self.generate()\n \n # -----------------------------------------------\n # Wrapper\n # -----------------------------------------------\n code += 'static PyObject* wrapper_%s(PyObject*,PyObject* args) {\\n'%self.name\n\n code += ' // Length check\\n'\n code += ' if ( PyTuple_Size(args) != %d ) {\\n'%len(self.signature)\n code += ' PyErr_SetString(PyExc_TypeError,\"Expected %d arguments\");\\n'%len(self.signature)\n code += ' return 0;\\n'\n code += ' }\\n'\n\n code += '\\n // Load Py versions of args\\n'\n for i in range(len(self.signature)):\n T = self.signature[i]\n code += ' PyObject* py_%s = PyTuple_GET_ITEM(args,%d);\\n'%(\n self.codeobject.co_varnames[i],i\n )\n\n code += ' if ( !%s ) {\\n'% \\\n T.check('py_'+self.codeobject.co_varnames[i])\n code += ' PyErr_SetString(PyExc_TypeError,\"Bad type for arg %d (expected %s)\");\\n'%(\n i+1,\n T.__class__.__name__)\n code += ' return 0;\\n'\n code += ' }\\n'\n \n code += '\\n // Do conversions\\n'\n argnames = []\n for i in range(len(self.signature)):\n T = self.signature[i]\n\n code += ' %s %s=%s;\\n'%(\n T.cxxtype,\n self.codeobject.co_varnames[i],\n T.inbound('py_'+self.codeobject.co_varnames[i]),\n )\n code += ' if ( PyErr_Occurred() ) return 0;\\n'\n argnames.append(self.codeobject.co_varnames[i])\n\n code += '\\n // Compute result\\n'\n if self.rtype != NoneType:\n code += ' %s _result = '%(\n self.rtype.cxxtype,\n )\n else:\n code += ' '\n code += '%s(%s);\\n'%(\n self.name,\n string.join(argnames,','),\n )\n\n\n code += '\\n // Pack return\\n'\n if ( self.rtype == NoneType ):\n code += ' Py_INCREF(Py_None);\\n'\n code += ' return Py_None;\\n'\n else:\n result = self.rtype.outbound('_result')\n code += ' return %s;\\n'%result\n code += '}\\n'\n return code\n\n\n ##################################################################\n # MEMBER EMIT #\n ##################################################################\n def emit(self,s):\n self.__body += s\n self.__body += '\\n'\n return\n\n ##################################################################\n # MEMBER PUSH #\n ##################################################################\n def push(self,v,t):\n self.stack.append(v)\n self.types.append(t)\n return\n\n\n ##################################################################\n # MEMBER POP #\n ##################################################################\n def pop(self):\n v = self.stack[-1]\n del self.stack[-1]\n t = self.types[-1]\n del self.types[-1]\n return v,t\n\n ##################################################################\n # MEMBER UNIQUE #\n ##################################################################\n def unique(self):\n self.__uid += 1\n return 't%d'%self.__uid\n\n ##################################################################\n # MEMBER POST #\n ##################################################################\n def post(self,pc,action):\n if not self.forwards.has_key(pc):\n self.forwards[pc] = []\n self.forwards[pc].append(action)\n return\n\n ##################################################################\n # MEMBER EMIT_VALUE #\n ##################################################################\n def emit_value(self, v):\n descriptor = self.typedef_by_value(v)\n \n # Convert representation to CXX rhs\n rhs = descriptor.literalizer(v)\n lhs = self.unique()\n self.emit('%s %s = %s;'%(\n descriptor.cxxtype,\n lhs,\n rhs))\n self.push(lhs,descriptor)\n return \n\n ##################################################################\n # MEMBER GLOBAL_INFO #\n ##################################################################\n def global_info(self,var_num):\n # This is the name value is known by\n var_name = self.codeobject.co_names[var_num]\n\n # First, figure out who owns this global\n import sys\n myHash = id(self.function.func_globals)\n for module_name in sys.modules.keys():\n module = sys.modules[module_name]\n if module and id(module.__dict__) == myHash:\n break\n else:\n raise ValueError,'Cannot locate module owning %s'%varname\n return module_name,var_name\n\n ##################################################################\n # MEMBER BINOP #\n ##################################################################\n def binop(self,pc,symbol):\n v2,t2 = self.pop()\n v1,t1 = self.pop()\n\n if t1 == t2:\n rhs,rhs_type = t1.binop(symbol,v1,v2)\n else:\n rhs,rhs_type = t1.binopMixed(symbol,v1,v2)\n \n lhs = self.unique()\n self.emit('%s %s = %s;\\n'%(\n rhs_type.cxxtype,\n lhs,\n rhs))\n print self.__body\n self.push(lhs,rhs_type)\n return \n\n ##################################################################\n # MEMBER BINARY_XXX #\n ##################################################################\n def BINARY_ADD(self,pc):\n return self.binop(pc,'+')\n def BINARY_SUBTRACT(self,pc):\n return self.binop(pc,'-')\n def BINARY_MULTIPLY(self,pc):\n return self.binop(pc,'*')\n def BINARY_DIVIDE(self,pc):\n return self.binop(pc,'/')\n def BINARY_MODULO(self,pc):\n return self.binop(pc,'%')\n def BINARY_SUBSCR(self,pc):\n return self.binop(pc,'[]')\n def COMPARE_OP(self,pc,opname):\n symbol = self.cmp_op(opname) # convert numeric to name\n return self.binop(pc,symbol)\n\n\n ##################################################################\n # MEMBER PRINT_ITEM #\n ##################################################################\n def PRINT_ITEM(self,pc):\n # Printing correctly is tricky... best to let Python\n # do the real work here\n w = self.unique()\n self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n self.emit('if (PyFile_SoftSpace(%s,1)) PyFile_WriteString(\" \",%s);'%(w,w))\n v,t = self.pop()\n\n py = self.unique()\n self.emit('PyObject* %s = %s;'%(py, t.outbound(v)))\n self.emit('PyFile_WriteObject(%s,%s,Py_PRINT_RAW);'%(\n py,w))\n self.emit('Py_XDECREF(%s);'%py)\n return\n\n\n ##################################################################\n # MEMBER PRINT_NEWLINE #\n ##################################################################\n def PRINT_NEWLINE(self,pc):\n # Printing correctly is tricky... best to let Python\n # do the real work here\n w = self.unique()\n self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n self.emit('PyFile_WriteString(\"\\\\n\",%s);'%w);\n self.emit('PyFile_SoftSpace(%s,0);'%w);\n return\n \n ##################################################################\n # MEMBER SET_LINENO #\n ##################################################################\n def SET_LINENO(self,pc,lineno):\n self.emit('// %s:%d'%(self.codeobject.co_filename,lineno))\n return\n\n ##################################################################\n # MEMBER POP_TOP #\n ##################################################################\n def POP_TOP(self,pc):\n v,t = self.pop()\n return\n\n ##################################################################\n # MEMBER LOAD_CONST #\n ##################################################################\n def LOAD_CONST(self,pc,consti):\n # Fetch the constant\n k = self.consts[consti]\n t = type(k)\n print 'LOAD_CONST',repr(k),t\n\n # Fetch a None is just skipped\n if t == NoneType:\n self.push('',t) \n return\n\n self.emit_value(k)\n return\n\n\n ##################################################################\n # MEMBER LOAD_FAST #\n ##################################################################\n def LOAD_FAST(self,pc,var_num):\n v = self.stack[var_num]\n t = self.types[var_num]\n print 'LOADFAST',var_num,v,t\n if t.refcount:\n self.emit('Py_XINCREF(%s);'%v)\n self.push(v,t)\n return\n\n ##################################################################\n # MEMBER LOAD_GLOBAL #\n ##################################################################\n def LOAD_GLOBAL(self,pc,var_num):\n # Figure out the name and load it\n try:\n F = self.function.func_globals[self.codeobject.co_names[var_num]]\n except:\n F = getattr(__builtins__,self.codeobject.co_names[var_num])\n\n # For functions, we see if we know about this function\n if callable(F):\n assert functiondefs.has_key(F),\"Function %s is known\"%F\n self.push(F,type(F))\n return\n\n # We need the name of the module that matches\n # the global state for the function and\n # the name of the variable\n module_name,var_name = self.global_info(var_num)\n\n # We hope it's type is correct\n t = type(F)\n descriptor = typedefs[t]\n native = self.unique()\n py = self.unique()\n mod = self.unique()\n\n self.emit('')\n self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n mod,module_name))\n self.emit('PyObject* %s = PyObject_GetAttrString(%s,\"%s\");'%(\n py,mod,var_name))\n self.emit('%s %s = %s;'%(\n descriptor.cxxtype,\n native,\n descriptor.inbound%py))\n\n self.push(native,t)\n return\n\n ##################################################################\n # MEMBER STORE_FAST #\n ##################################################################\n def STORE_FAST(self,pc,var_num):\n\n v,t = self.pop()\n print 'STORE FAST',var_num,v,t\n\n save = self.stack[var_num]\n saveT = self.types[var_num]\n\n # See if type is same....\n # Note that None means no assignment made yet\n if saveT == None or t == saveT:\n if t.refcount:\n self.emit('Py_XINCREF(%s);'%v)\n self.emit('Py_XDECREF(%s);'%save)\n self.emit('%s = %s;\\n'%(save,v))\n self.types[var_num] = t\n return\n\n raise TypeError,(t,saveT)\n\n ##################################################################\n # MEMBER STORE_GLOBAL #\n ##################################################################\n def STORE_GLOBAL(self,pc,var_num):\n\n # We need the name of the module that matches\n # the global state for the function and\n # the name of the variable\n module_name,var_name = self.global_info(var_num)\n\n # Convert the value to Python object\n v,t = self.pop()\n descriptor = typedefs[t]\n py = self.unique()\n self.emit('PyObject* %s = %s;'%(\n py,\n descriptor.outbound%v))\n mod = self.unique()\n self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n mod,module_name))\n self.emit('PyObject_SetAttrString(%s,\"%s\",%s);'%(\n mod,var_name,py))\n self.emit('Py_DECREF(%s);'%py)\n return\n\n ##################################################################\n # MEMBER CALL_FUNCTION #\n ##################################################################\n def CALL_FUNCTION(self,pc,argc):\n # Pull args off stack\n args = []\n types = []\n for i in range(argc):\n v,t = self.pop()\n args = [v]+args\n types = [t]+types\n \n # Pull function object off stack and get descriptor\n f,t = self.pop()\n descriptor = functiondefs[f]\n #self.prerequisites += descriptor['prerequisite']+'\\n'\n \n # Look through descriptors for a match\n for inputs,outputs,format in descriptor:\n if inputs == types:\n break\n else:\n raise TypeError,f\n\n # Build a rhs\n rhs = format%string.join(args,',')\n\n # Build a statement\n assert len(outputs) == 1,\"Single valued return\"\n assert typedefs.has_key(outputs[0]),\"Know about type %s\"%outputs[0]\n description = typedefs[outputs[0]]\n temp = self.unique()\n self.emit('%s %s = %s;\\n'%(\n description.cxxtype,\n temp,\n rhs))\n\n self.push(temp,outputs[0])\n return\n\n\n ##################################################################\n # MEMBER JUMP_IF_FALSE #\n ##################################################################\n def JUMP_IF_FALSE(self,pc,delta):\n v,t = self.pop()\n self.push(v,t)\n # We need to do some work when we get to the\n # else part (put the value that's gonna get\n # popped back on the stack, emit } else {,\n # ...)\n action = lambda v=v,t=t,self=self: (\n self.emit('} else {'),\n self.push(v,t),\n )\n self.post(pc+delta,action)\n if t != IntType: raise TypeError, 'Invalid comparison type %s'%t\n self.emit('if (%s) {\\n'%v)\n return\n \n\n ##################################################################\n # MEMBER JUMP_FORWARD #\n ##################################################################\n def JUMP_FORWARD(self,pc,delta):\n # We need to close the if after the delta\n action = lambda self=self: (\n self.emit('}'),\n )\n self.post(pc+delta,action)\n return\n \n ##################################################################\n # MEMBER RETURN_VALUE #\n ##################################################################\n def RETURN_VALUE(self,pc):\n v,t = self.pop()\n if hasattr(self,'rtype'):\n print v,t\n if t == NoneType: return # just the extra return\n raise ValueError,'multiple returns'\n self.rtype = t\n if t == NoneType:\n self.emit('return;')\n else:\n self.emit('return %s;'%v)\n print 'return with',v\n return\n\n", + "methods": [ + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 20, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , code , return_type , support = '' )", + "filename": "bytecodecompiler.py", + "nloc": 5, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "code", + "return_type", + "support" + ], + "start_line": 32, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "opcodize", + "long_name": "opcodize( s )", + "filename": "bytecodecompiler.py", + "nloc": 16, + "complexity": 3, + "token_count": 92, + "parameters": [ + "s" + ], + "start_line": 159, + "end_line": 174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "listing", + "long_name": "listing( f )", + "filename": "bytecodecompiler.py", + "nloc": 29, + "complexity": 9, + "token_count": 166, + "parameters": [ + "f" + ], + "start_line": 181, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "fetch", + "long_name": "fetch( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 215, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "execute", + "long_name": "execute( self , pc , opcode , argument )", + "filename": "bytecodecompiler.py", + "nloc": 7, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "pc", + "opcode", + "argument" + ], + "start_line": 225, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "evaluate", + "long_name": "evaluate( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 233, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "cmp_op", + "long_name": "cmp_op( self , opname )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "opname" + ], + "start_line": 248, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "STOP_CODE", + "long_name": "STOP_CODE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 251, + "end_line": 253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_TOP", + "long_name": "POP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 254, + "end_line": 256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_TWO", + "long_name": "ROT_TWO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 258, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_THREE", + "long_name": "ROT_THREE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 262, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_FOUR", + "long_name": "ROT_FOUR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 266, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DUP_TOP", + "long_name": "DUP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 270, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_POSITIVE", + "long_name": "UNARY_POSITIVE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 276, + "end_line": 278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_NEGATIVE", + "long_name": "UNARY_NEGATIVE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 280, + "end_line": 282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_NOT", + "long_name": "UNARY_NOT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 284, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_CONVERT", + "long_name": "UNARY_CONVERT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 288, + "end_line": 290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_INVERT", + "long_name": "UNARY_INVERT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 292, + "end_line": 294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_POWER", + "long_name": "BINARY_POWER( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 298, + "end_line": 300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MULTIPLY", + "long_name": "BINARY_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 302, + "end_line": 304, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_DIVIDE", + "long_name": "BINARY_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 306, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MODULO", + "long_name": "BINARY_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 310, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_ADD", + "long_name": "BINARY_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 314, + "end_line": 316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBTRACT", + "long_name": "BINARY_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 318, + "end_line": 320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBSCR", + "long_name": "BINARY_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 322, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_LSHIFT", + "long_name": "BINARY_LSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 326, + "end_line": 328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_RSHIFT", + "long_name": "BINARY_RSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 330, + "end_line": 332, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_AND", + "long_name": "BINARY_AND( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 334, + "end_line": 336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_XOR", + "long_name": "BINARY_XOR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 338, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_OR", + "long_name": "BINARY_OR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 342, + "end_line": 344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_POWER", + "long_name": "INPLACE_POWER( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 348, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_MULTIPLY", + "long_name": "INPLACE_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 352, + "end_line": 354, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_DIVIDE", + "long_name": "INPLACE_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 356, + "end_line": 358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_MODULO", + "long_name": "INPLACE_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 360, + "end_line": 362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_ADD", + "long_name": "INPLACE_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 364, + "end_line": 366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_SUBTRACT", + "long_name": "INPLACE_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 368, + "end_line": 370, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_LSHIFT", + "long_name": "INPLACE_LSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 372, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_RSHIFT", + "long_name": "INPLACE_RSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 376, + "end_line": 378, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_AND", + "long_name": "INPLACE_AND( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 380, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_XOR", + "long_name": "INPLACE_XOR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 384, + "end_line": 386, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_OR", + "long_name": "INPLACE_OR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 388, + "end_line": 390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_0", + "long_name": "SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 394, + "end_line": 396, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_1", + "long_name": "SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 398, + "end_line": 400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_2", + "long_name": "SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 402, + "end_line": 404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_3", + "long_name": "SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 406, + "end_line": 408, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_0", + "long_name": "STORE_SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 412, + "end_line": 414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_1", + "long_name": "STORE_SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 416, + "end_line": 418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_2", + "long_name": "STORE_SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 420, + "end_line": 422, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_3", + "long_name": "STORE_SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 424, + "end_line": 426, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_0", + "long_name": "DELETE_SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 428, + "end_line": 430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_1", + "long_name": "DELETE_SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 432, + "end_line": 434, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_2", + "long_name": "DELETE_SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 436, + "end_line": 438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_3", + "long_name": "DELETE_SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 440, + "end_line": 442, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SUBSCR", + "long_name": "STORE_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 444, + "end_line": 446, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SUBSCR", + "long_name": "DELETE_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 448, + "end_line": 450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_EXPR", + "long_name": "PRINT_EXPR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 452, + "end_line": 454, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM", + "long_name": "PRINT_ITEM( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 456, + "end_line": 458, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM_TO", + "long_name": "PRINT_ITEM_TO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 460, + "end_line": 462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE", + "long_name": "PRINT_NEWLINE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 464, + "end_line": 466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE_TO", + "long_name": "PRINT_NEWLINE_TO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 468, + "end_line": 470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BREAK_LOOP", + "long_name": "BREAK_LOOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 472, + "end_line": 474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_LOCALS", + "long_name": "LOAD_LOCALS( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 476, + "end_line": 478, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "RETURN_VALUE", + "long_name": "RETURN_VALUE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 480, + "end_line": 482, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_STAR", + "long_name": "IMPORT_STAR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 484, + "end_line": 486, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "EXEC_STMT", + "long_name": "EXEC_STMT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 488, + "end_line": 490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_BLOCK", + "long_name": "POP_BLOCK( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 492, + "end_line": 494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "END_FINALLY", + "long_name": "END_FINALLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 496, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_CLASS", + "long_name": "BUILD_CLASS( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 500, + "end_line": 502, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_NAME", + "long_name": "STORE_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 506, + "end_line": 508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_NAME", + "long_name": "DELETE_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 510, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNPACK_SEQUENCE", + "long_name": "UNPACK_SEQUENCE( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 514, + "end_line": 516, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DUP_TOPX", + "long_name": "DUP_TOPX( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 518, + "end_line": 520, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_ATTR", + "long_name": "STORE_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 522, + "end_line": 524, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_ATTR", + "long_name": "DELETE_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 526, + "end_line": 528, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_GLOBAL", + "long_name": "STORE_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 530, + "end_line": 532, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_GLOBAL", + "long_name": "DELETE_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 534, + "end_line": 536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CONST", + "long_name": "LOAD_CONST( self , pc , consti )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "consti" + ], + "start_line": 538, + "end_line": 540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_NAME", + "long_name": "LOAD_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 542, + "end_line": 544, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_TUPLE", + "long_name": "BUILD_TUPLE( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 546, + "end_line": 548, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_LIST", + "long_name": "BUILD_LIST( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 550, + "end_line": 552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_MAP", + "long_name": "BUILD_MAP( self , pc , zero )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "zero" + ], + "start_line": 554, + "end_line": 556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_ATTR", + "long_name": "LOAD_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 558, + "end_line": 560, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "COMPARE_OP", + "long_name": "COMPARE_OP( self , pc , opname )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "opname" + ], + "start_line": 562, + "end_line": 564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_NAME", + "long_name": "IMPORT_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 566, + "end_line": 568, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_FROM", + "long_name": "IMPORT_FROM( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 570, + "end_line": 572, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_FORWARD", + "long_name": "JUMP_FORWARD( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 574, + "end_line": 576, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_TRUE", + "long_name": "JUMP_IF_TRUE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 578, + "end_line": 580, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_FALSE", + "long_name": "JUMP_IF_FALSE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 582, + "end_line": 584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_ABSOLUTE", + "long_name": "JUMP_ABSOLUTE( self , pc , target )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "target" + ], + "start_line": 586, + "end_line": 588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "FOR_LOOP", + "long_name": "FOR_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 590, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_GLOBAL", + "long_name": "LOAD_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 594, + "end_line": 596, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_LOOP", + "long_name": "SETUP_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 598, + "end_line": 600, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_EXCEPT", + "long_name": "SETUP_EXCEPT( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 602, + "end_line": 604, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_FINALLY", + "long_name": "SETUP_FINALLY( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 606, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_FAST", + "long_name": "LOAD_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 610, + "end_line": 612, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_FAST", + "long_name": "STORE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 614, + "end_line": 616, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_FAST", + "long_name": "DELETE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 618, + "end_line": 620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CLOSURE", + "long_name": "LOAD_CLOSURE( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 622, + "end_line": 624, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_DEREF", + "long_name": "LOAD_DEREF( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 626, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_DEREF", + "long_name": "STORE_DEREF( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 630, + "end_line": 632, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SET_LINENO", + "long_name": "SET_LINENO( self , pc , lineno )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "lineno" + ], + "start_line": 634, + "end_line": 636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "RAISE_VARARGS", + "long_name": "RAISE_VARARGS( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 638, + "end_line": 640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION", + "long_name": "CALL_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 642, + "end_line": 644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "MAKE_FUNCTION", + "long_name": "MAKE_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 646, + "end_line": 648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "MAKE_CLOSURE", + "long_name": "MAKE_CLOSURE( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 650, + "end_line": 652, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_SLICE", + "long_name": "BUILD_SLICE( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 654, + "end_line": 656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "EXTENDED_ARG", + "long_name": "EXTENDED_ARG( self , pc , ext )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "ext" + ], + "start_line": 658, + "end_line": 660, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_VAR", + "long_name": "CALL_FUNCTION_VAR( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 662, + "end_line": 664, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_KW", + "long_name": "CALL_FUNCTION_KW( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 666, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_VAR_KW", + "long_name": "CALL_FUNCTION_VAR_KW( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 670, + "end_line": 672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "typedef_by_value", + "long_name": "typedef_by_value( self , v )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "v" + ], + "start_line": 684, + "end_line": 685, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , function , signature , name = None )", + "filename": "bytecodecompiler.py", + "nloc": 10, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "function", + "signature", + "name" + ], + "start_line": 690, + "end_line": 699, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "evaluate", + "long_name": "evaluate( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 3, + "token_count": 52, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 704, + "end_line": 710, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "generate", + "long_name": "generate( self )", + "filename": "bytecodecompiler.py", + "nloc": 51, + "complexity": 14, + "token_count": 374, + "parameters": [ + "self" + ], + "start_line": 715, + "end_line": 797, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "wrapped_code", + "long_name": "wrapped_code( self )", + "filename": "bytecodecompiler.py", + "nloc": 52, + "complexity": 5, + "token_count": 294, + "parameters": [ + "self" + ], + "start_line": 803, + "end_line": 866, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "emit", + "long_name": "emit( self , s )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "s" + ], + "start_line": 872, + "end_line": 875, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "push", + "long_name": "push( self , v , t )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "v", + "t" + ], + "start_line": 880, + "end_line": 883, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "pop", + "long_name": "pop( self )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 889, + "end_line": 894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "unique", + "long_name": "unique( self )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 899, + "end_line": 901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "post", + "long_name": "post( self , pc , action )", + "filename": "bytecodecompiler.py", + "nloc": 5, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "pc", + "action" + ], + "start_line": 906, + "end_line": 910, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "emit_value", + "long_name": "emit_value( self , v )", + "filename": "bytecodecompiler.py", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self", + "v" + ], + "start_line": 915, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "global_info", + "long_name": "global_info( self , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 4, + "token_count": 73, + "parameters": [ + "self", + "var_num" + ], + "start_line": 931, + "end_line": 944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "binop", + "long_name": "binop( self , pc , symbol )", + "filename": "bytecodecompiler.py", + "nloc": 15, + "complexity": 2, + "token_count": 98, + "parameters": [ + "self", + "pc", + "symbol" + ], + "start_line": 949, + "end_line": 965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "BINARY_ADD", + "long_name": "BINARY_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 970, + "end_line": 971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBTRACT", + "long_name": "BINARY_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 972, + "end_line": 973, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MULTIPLY", + "long_name": "BINARY_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 974, + "end_line": 975, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_DIVIDE", + "long_name": "BINARY_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 976, + "end_line": 977, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MODULO", + "long_name": "BINARY_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 978, + "end_line": 979, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBSCR", + "long_name": "BINARY_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 980, + "end_line": 981, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "COMPARE_OP", + "long_name": "COMPARE_OP( self , pc , opname )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "pc", + "opname" + ], + "start_line": 982, + "end_line": 984, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM", + "long_name": "PRINT_ITEM( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 1, + "token_count": 88, + "parameters": [ + "self", + "pc" + ], + "start_line": 990, + "end_line": 1003, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE", + "long_name": "PRINT_NEWLINE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 41, + "parameters": [ + "self", + "pc" + ], + "start_line": 1009, + "end_line": 1016, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "SET_LINENO", + "long_name": "SET_LINENO( self , pc , lineno )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "pc", + "lineno" + ], + "start_line": 1021, + "end_line": 1023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_TOP", + "long_name": "POP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "pc" + ], + "start_line": 1028, + "end_line": 1030, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CONST", + "long_name": "LOAD_CONST( self , pc , consti )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "pc", + "consti" + ], + "start_line": 1035, + "end_line": 1047, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "LOAD_FAST", + "long_name": "LOAD_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 8, + "complexity": 2, + "token_count": 55, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1053, + "end_line": 1060, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "LOAD_GLOBAL", + "long_name": "LOAD_GLOBAL( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 25, + "complexity": 3, + "token_count": 165, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1065, + "end_line": 1100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "SETUP_LOOP", + "long_name": "SETUP_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1102, + "end_line": 1104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "FOR_LOOP", + "long_name": "FOR_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 8, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1106, + "end_line": 1116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "JUMP_ABSOLUTE", + "long_name": "JUMP_ABSOLUTE( self , pc , target )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "pc", + "target" + ], + "start_line": 1118, + "end_line": 1121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "POP_BLOCK", + "long_name": "POP_BLOCK( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "pc" + ], + "start_line": 1123, + "end_line": 1125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_FAST", + "long_name": "STORE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1131, + "end_line": 1149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "STORE_GLOBAL", + "long_name": "STORE_GLOBAL( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 15, + "complexity": 1, + "token_count": 99, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1154, + "end_line": 1174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION", + "long_name": "CALL_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 18, + "complexity": 2, + "token_count": 125, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 1179, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_FALSE", + "long_name": "JUMP_IF_FALSE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1211, + "end_line": 1225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "JUMP_FORWARD", + "long_name": "JUMP_FORWARD( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1231, + "end_line": 1237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "RETURN_VALUE", + "long_name": "RETURN_VALUE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 13, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "pc" + ], + "start_line": 1242, + "end_line": 1254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self" + ], + "start_line": 20, + "end_line": 21, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "opcodize", + "long_name": "opcodize( s )", + "filename": "bytecodecompiler.py", + "nloc": 16, + "complexity": 3, + "token_count": 92, + "parameters": [ + "s" + ], + "start_line": 142, + "end_line": 157, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "listing", + "long_name": "listing( f )", + "filename": "bytecodecompiler.py", + "nloc": 29, + "complexity": 9, + "token_count": 166, + "parameters": [ + "f" + ], + "start_line": 164, + "end_line": 192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "fetch", + "long_name": "fetch( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 198, + "end_line": 206, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "execute", + "long_name": "execute( self , pc , opcode , argument )", + "filename": "bytecodecompiler.py", + "nloc": 7, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "pc", + "opcode", + "argument" + ], + "start_line": 208, + "end_line": 214, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "evaluate", + "long_name": "evaluate( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 216, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "cmp_op", + "long_name": "cmp_op( self , opname )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "opname" + ], + "start_line": 231, + "end_line": 232, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "STOP_CODE", + "long_name": "STOP_CODE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 234, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_TOP", + "long_name": "POP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 237, + "end_line": 239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_TWO", + "long_name": "ROT_TWO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 241, + "end_line": 243, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_THREE", + "long_name": "ROT_THREE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 245, + "end_line": 247, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_FOUR", + "long_name": "ROT_FOUR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 249, + "end_line": 251, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DUP_TOP", + "long_name": "DUP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 253, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_POSITIVE", + "long_name": "UNARY_POSITIVE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 259, + "end_line": 261, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_NEGATIVE", + "long_name": "UNARY_NEGATIVE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 263, + "end_line": 265, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_NOT", + "long_name": "UNARY_NOT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 267, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_CONVERT", + "long_name": "UNARY_CONVERT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 271, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_INVERT", + "long_name": "UNARY_INVERT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 275, + "end_line": 277, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_POWER", + "long_name": "BINARY_POWER( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 281, + "end_line": 283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MULTIPLY", + "long_name": "BINARY_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 285, + "end_line": 287, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_DIVIDE", + "long_name": "BINARY_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 289, + "end_line": 291, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MODULO", + "long_name": "BINARY_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 293, + "end_line": 295, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_ADD", + "long_name": "BINARY_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 297, + "end_line": 299, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBTRACT", + "long_name": "BINARY_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 301, + "end_line": 303, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBSCR", + "long_name": "BINARY_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 305, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_LSHIFT", + "long_name": "BINARY_LSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 309, + "end_line": 311, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_RSHIFT", + "long_name": "BINARY_RSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 313, + "end_line": 315, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_AND", + "long_name": "BINARY_AND( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 317, + "end_line": 319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_XOR", + "long_name": "BINARY_XOR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 321, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_OR", + "long_name": "BINARY_OR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 325, + "end_line": 327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_POWER", + "long_name": "INPLACE_POWER( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 331, + "end_line": 333, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_MULTIPLY", + "long_name": "INPLACE_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 335, + "end_line": 337, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_DIVIDE", + "long_name": "INPLACE_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 339, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_MODULO", + "long_name": "INPLACE_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 343, + "end_line": 345, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_ADD", + "long_name": "INPLACE_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 347, + "end_line": 349, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_SUBTRACT", + "long_name": "INPLACE_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 351, + "end_line": 353, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_LSHIFT", + "long_name": "INPLACE_LSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 355, + "end_line": 357, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_RSHIFT", + "long_name": "INPLACE_RSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 359, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_AND", + "long_name": "INPLACE_AND( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 363, + "end_line": 365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_XOR", + "long_name": "INPLACE_XOR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 367, + "end_line": 369, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_OR", + "long_name": "INPLACE_OR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 371, + "end_line": 373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_0", + "long_name": "SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 377, + "end_line": 379, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_1", + "long_name": "SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 381, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_2", + "long_name": "SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 385, + "end_line": 387, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_3", + "long_name": "SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 389, + "end_line": 391, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_0", + "long_name": "STORE_SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 395, + "end_line": 397, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_1", + "long_name": "STORE_SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 399, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_2", + "long_name": "STORE_SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 403, + "end_line": 405, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_3", + "long_name": "STORE_SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 407, + "end_line": 409, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_0", + "long_name": "DELETE_SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 411, + "end_line": 413, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_1", + "long_name": "DELETE_SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 415, + "end_line": 417, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_2", + "long_name": "DELETE_SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 419, + "end_line": 421, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_3", + "long_name": "DELETE_SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 423, + "end_line": 425, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SUBSCR", + "long_name": "STORE_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 427, + "end_line": 429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SUBSCR", + "long_name": "DELETE_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 431, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_EXPR", + "long_name": "PRINT_EXPR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 435, + "end_line": 437, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM", + "long_name": "PRINT_ITEM( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 439, + "end_line": 441, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM_TO", + "long_name": "PRINT_ITEM_TO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 443, + "end_line": 445, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE", + "long_name": "PRINT_NEWLINE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 447, + "end_line": 449, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE_TO", + "long_name": "PRINT_NEWLINE_TO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 451, + "end_line": 453, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BREAK_LOOP", + "long_name": "BREAK_LOOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 455, + "end_line": 457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_LOCALS", + "long_name": "LOAD_LOCALS( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 459, + "end_line": 461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "RETURN_VALUE", + "long_name": "RETURN_VALUE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 463, + "end_line": 465, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_STAR", + "long_name": "IMPORT_STAR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 467, + "end_line": 469, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "EXEC_STMT", + "long_name": "EXEC_STMT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 471, + "end_line": 473, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_BLOCK", + "long_name": "POP_BLOCK( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 475, + "end_line": 477, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "END_FINALLY", + "long_name": "END_FINALLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 479, + "end_line": 481, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_CLASS", + "long_name": "BUILD_CLASS( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 483, + "end_line": 485, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_NAME", + "long_name": "STORE_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 489, + "end_line": 491, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_NAME", + "long_name": "DELETE_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 493, + "end_line": 495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNPACK_SEQUENCE", + "long_name": "UNPACK_SEQUENCE( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 497, + "end_line": 499, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DUP_TOPX", + "long_name": "DUP_TOPX( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 501, + "end_line": 503, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_ATTR", + "long_name": "STORE_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 505, + "end_line": 507, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_ATTR", + "long_name": "DELETE_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 509, + "end_line": 511, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_GLOBAL", + "long_name": "STORE_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 513, + "end_line": 515, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_GLOBAL", + "long_name": "DELETE_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 517, + "end_line": 519, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CONST", + "long_name": "LOAD_CONST( self , pc , consti )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "consti" + ], + "start_line": 521, + "end_line": 523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_NAME", + "long_name": "LOAD_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 525, + "end_line": 527, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_TUPLE", + "long_name": "BUILD_TUPLE( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 529, + "end_line": 531, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_LIST", + "long_name": "BUILD_LIST( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 533, + "end_line": 535, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_MAP", + "long_name": "BUILD_MAP( self , pc , zero )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "zero" + ], + "start_line": 537, + "end_line": 539, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_ATTR", + "long_name": "LOAD_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 541, + "end_line": 543, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "COMPARE_OP", + "long_name": "COMPARE_OP( self , pc , opname )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "opname" + ], + "start_line": 545, + "end_line": 547, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_NAME", + "long_name": "IMPORT_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 549, + "end_line": 551, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_FROM", + "long_name": "IMPORT_FROM( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 553, + "end_line": 555, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_FORWARD", + "long_name": "JUMP_FORWARD( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 557, + "end_line": 559, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_TRUE", + "long_name": "JUMP_IF_TRUE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 561, + "end_line": 563, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_FALSE", + "long_name": "JUMP_IF_FALSE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 565, + "end_line": 567, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_ABSOLUTE", + "long_name": "JUMP_ABSOLUTE( self , pc , target )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "target" + ], + "start_line": 569, + "end_line": 571, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "FOR_LOOP", + "long_name": "FOR_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 573, + "end_line": 575, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_GLOBAL", + "long_name": "LOAD_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 577, + "end_line": 579, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_LOOP", + "long_name": "SETUP_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 581, + "end_line": 583, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_EXCEPT", + "long_name": "SETUP_EXCEPT( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 585, + "end_line": 587, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_FINALLY", + "long_name": "SETUP_FINALLY( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 589, + "end_line": 591, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_FAST", + "long_name": "LOAD_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 593, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_FAST", + "long_name": "STORE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 597, + "end_line": 599, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_FAST", + "long_name": "DELETE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 601, + "end_line": 603, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CLOSURE", + "long_name": "LOAD_CLOSURE( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 605, + "end_line": 607, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_DEREF", + "long_name": "LOAD_DEREF( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 609, + "end_line": 611, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_DEREF", + "long_name": "STORE_DEREF( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 613, + "end_line": 615, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SET_LINENO", + "long_name": "SET_LINENO( self , pc , lineno )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "lineno" + ], + "start_line": 617, + "end_line": 619, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "RAISE_VARARGS", + "long_name": "RAISE_VARARGS( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 621, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION", + "long_name": "CALL_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 625, + "end_line": 627, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "MAKE_FUNCTION", + "long_name": "MAKE_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 629, + "end_line": 631, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "MAKE_CLOSURE", + "long_name": "MAKE_CLOSURE( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 633, + "end_line": 635, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_SLICE", + "long_name": "BUILD_SLICE( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 637, + "end_line": 639, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "EXTENDED_ARG", + "long_name": "EXTENDED_ARG( self , pc , ext )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "ext" + ], + "start_line": 641, + "end_line": 643, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_VAR", + "long_name": "CALL_FUNCTION_VAR( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 645, + "end_line": 647, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_KW", + "long_name": "CALL_FUNCTION_KW( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 649, + "end_line": 651, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_VAR_KW", + "long_name": "CALL_FUNCTION_VAR_KW( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 653, + "end_line": 655, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "typedef_by_value", + "long_name": "typedef_by_value( self , v )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "v" + ], + "start_line": 667, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , function , signature , name = None )", + "filename": "bytecodecompiler.py", + "nloc": 10, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "function", + "signature", + "name" + ], + "start_line": 673, + "end_line": 682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "evaluate", + "long_name": "evaluate( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 3, + "token_count": 52, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 687, + "end_line": 693, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "generate", + "long_name": "generate( self )", + "filename": "bytecodecompiler.py", + "nloc": 51, + "complexity": 14, + "token_count": 374, + "parameters": [ + "self" + ], + "start_line": 698, + "end_line": 780, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "wrapped_code", + "long_name": "wrapped_code( self )", + "filename": "bytecodecompiler.py", + "nloc": 52, + "complexity": 5, + "token_count": 294, + "parameters": [ + "self" + ], + "start_line": 786, + "end_line": 849, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "emit", + "long_name": "emit( self , s )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "s" + ], + "start_line": 855, + "end_line": 858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "push", + "long_name": "push( self , v , t )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "v", + "t" + ], + "start_line": 863, + "end_line": 866, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "pop", + "long_name": "pop( self )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 872, + "end_line": 877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "unique", + "long_name": "unique( self )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 882, + "end_line": 884, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "post", + "long_name": "post( self , pc , action )", + "filename": "bytecodecompiler.py", + "nloc": 5, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "pc", + "action" + ], + "start_line": 889, + "end_line": 893, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "emit_value", + "long_name": "emit_value( self , v )", + "filename": "bytecodecompiler.py", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self", + "v" + ], + "start_line": 898, + "end_line": 909, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "global_info", + "long_name": "global_info( self , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 4, + "token_count": 73, + "parameters": [ + "self", + "var_num" + ], + "start_line": 914, + "end_line": 927, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "binop", + "long_name": "binop( self , pc , symbol )", + "filename": "bytecodecompiler.py", + "nloc": 15, + "complexity": 2, + "token_count": 98, + "parameters": [ + "self", + "pc", + "symbol" + ], + "start_line": 932, + "end_line": 948, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "BINARY_ADD", + "long_name": "BINARY_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 953, + "end_line": 954, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBTRACT", + "long_name": "BINARY_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 955, + "end_line": 956, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MULTIPLY", + "long_name": "BINARY_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 957, + "end_line": 958, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_DIVIDE", + "long_name": "BINARY_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 959, + "end_line": 960, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MODULO", + "long_name": "BINARY_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 961, + "end_line": 962, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBSCR", + "long_name": "BINARY_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 963, + "end_line": 964, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "COMPARE_OP", + "long_name": "COMPARE_OP( self , pc , opname )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "pc", + "opname" + ], + "start_line": 965, + "end_line": 967, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM", + "long_name": "PRINT_ITEM( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 1, + "token_count": 88, + "parameters": [ + "self", + "pc" + ], + "start_line": 973, + "end_line": 986, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE", + "long_name": "PRINT_NEWLINE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 41, + "parameters": [ + "self", + "pc" + ], + "start_line": 992, + "end_line": 999, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "SET_LINENO", + "long_name": "SET_LINENO( self , pc , lineno )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "pc", + "lineno" + ], + "start_line": 1004, + "end_line": 1006, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_TOP", + "long_name": "POP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "pc" + ], + "start_line": 1011, + "end_line": 1013, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CONST", + "long_name": "LOAD_CONST( self , pc , consti )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "pc", + "consti" + ], + "start_line": 1018, + "end_line": 1030, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "LOAD_FAST", + "long_name": "LOAD_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 8, + "complexity": 2, + "token_count": 55, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1036, + "end_line": 1043, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "LOAD_GLOBAL", + "long_name": "LOAD_GLOBAL( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 26, + "complexity": 3, + "token_count": 178, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1048, + "end_line": 1084, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 37, + "top_nesting_level": 1 + }, + { + "name": "STORE_FAST", + "long_name": "STORE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1089, + "end_line": 1107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "STORE_GLOBAL", + "long_name": "STORE_GLOBAL( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 15, + "complexity": 1, + "token_count": 99, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1112, + "end_line": 1132, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION", + "long_name": "CALL_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 25, + "complexity": 4, + "token_count": 166, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 1137, + "end_line": 1172, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_FALSE", + "long_name": "JUMP_IF_FALSE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1178, + "end_line": 1192, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "JUMP_FORWARD", + "long_name": "JUMP_FORWARD( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1198, + "end_line": 1204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "RETURN_VALUE", + "long_name": "RETURN_VALUE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 13, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "pc" + ], + "start_line": 1209, + "end_line": 1221, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "__init__", + "long_name": "__init__( self , code , return_type , support = '' )", + "filename": "bytecodecompiler.py", + "nloc": 5, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "code", + "return_type", + "support" + ], + "start_line": 32, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "LOAD_GLOBAL", + "long_name": "LOAD_GLOBAL( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 25, + "complexity": 3, + "token_count": 165, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1065, + "end_line": 1100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "POP_BLOCK", + "long_name": "POP_BLOCK( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "pc" + ], + "start_line": 1123, + "end_line": 1125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_LOOP", + "long_name": "SETUP_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1102, + "end_line": 1104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_ABSOLUTE", + "long_name": "JUMP_ABSOLUTE( self , pc , target )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "pc", + "target" + ], + "start_line": 1118, + "end_line": 1121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION", + "long_name": "CALL_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 18, + "complexity": 2, + "token_count": 125, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 1179, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "FOR_LOOP", + "long_name": "FOR_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 8, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1106, + "end_line": 1116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + } + ], + "nloc": 866, + "complexity": 199, + "token_count": 4642, + "diff_parsed": { + "added": [ + "# CLASS __DESCRIPTOR #", + "class __Descriptor:", + "##################################################################", + "# CLASS TYPE_DESCRIPTOR #", + "##################################################################", + "class Type_Descriptor(__Descriptor):", + " module_init_code = ''", + "", + "##################################################################", + "# CLASS FUNCTION_DESCRIPTOR #", + "##################################################################", + "class Function_Descriptor(__Descriptor):", + " def __init__(self,code,return_type,support=''):", + "\tself.code\t= code", + "\tself.return_type\t= return_type", + " self.support = support", + "\treturn", + "", + "", + "", + " F = __builtins__[self.codeobject.co_names[var_num]]", + " def SETUP_LOOP(self,pc,delta):", + " \"Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.\"", + " return", + "", + " def FOR_LOOP(self,pc,delta):", + " \"Iterate over a sequence. TOS is the current index, TOS1 the sequence. First, the next element is computed. If the sequence is exhausted, increment byte code counter by delta. Otherwise, push the sequence, the incremented counter, and the current item onto the stack.\"", + " # Pull off control variable and range info", + " v2,t2 = self.pop()", + " v1,t1 = self.pop()", + " self.emit('for(%s=%s.low; %s<%s.high; %s += %s.step) {'%(", + " v2,v1,v2,v1,v2,v1))", + "", + " # Put range back on for assignment", + " self.push(v2,t2)", + " return", + "", + " def JUMP_ABSOLUTE(self,pc,target):", + " \"Set byte code counter to target.\"", + " self.emit('}')", + " return", + "", + " def POP_BLOCK(self,pc):", + " \"Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.\"", + " return", + "", + "", + " signature = (f,tuple(types))", + " descriptor = self.function_by_signature(signature)", + " rhs = descriptor.code%string.join(args,',')", + " descriptor.return_type.cxxtype,", + " self.push(temp,descriptor.return_type)" + ], + "deleted": [ + "", + "# CLASS CXXTYPEDESCRIPTION #", + "class Type_Descriptor:", + " F = getattr(__builtins__,self.codeobject.co_names[var_num])", + " assert functiondefs.has_key(F),\"Function %s is known\"%F", + " descriptor = functiondefs[f]", + " # Look through descriptors for a match", + " for inputs,outputs,format in descriptor:", + " if inputs == types:", + " break", + " else:", + " raise TypeError,f", + "", + " rhs = format%string.join(args,',')", + " assert len(outputs) == 1,\"Single valued return\"", + " assert typedefs.has_key(outputs[0]),\"Know about type %s\"%outputs[0]", + " description = typedefs[outputs[0]]", + " description.cxxtype,", + " self.push(temp,outputs[0])" + ] + } + } + ] + }, + { + "hash": "5c232de49fabe194369cc53e9e0f57245c780973", + "msg": "Introduced PostponedException", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-03-01T16:56:38+00:00", + "author_timezone": 0, + "committer_date": "2002-03-01T16:56:38+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "b25fc06001bccd8692ef5b4f49ecbe49007309d9" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 0, + "insertions": 11, + "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/misc_util.py", + "new_path": "scipy_distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -1,5 +1,16 @@\n import os,sys,string\n \n+class 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+ \"\"\"\n+ def __init__(self):\n+ self.info = sys.exc_info()[:2]\n+ def __getattr__(self,name):\n+ raise self.info[0],self.info[1]\n+\n def update_version(release_level='alpha',\n path='.',\n version_template = \\\n", + "added_lines": 11, + "deleted_lines": 0, + "source_code": "import os,sys,string\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 \"\"\"\n def __init__(self):\n self.info = sys.exc_info()[:2]\n def __getattr__(self,name):\n raise self.info[0],self.info[1]\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef 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\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef 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 ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", + "source_code_before": "import os,sys,string\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef 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\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef 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 ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", + "methods": [ + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 9, + "end_line": 10, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "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": 11, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "update_version", + "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", + "filename": "misc_util.py", + "nloc": 65, + "complexity": 12, + "token_count": 351, + "parameters": [ + "release_level", + "path", + "major", + "overwrite_version_py" + ], + "start_line": 14, + "end_line": 120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "get_version", + "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "release_level", + "path", + "major" + ], + "start_line": 122, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "get_cvs_revision", + "long_name": "get_cvs_revision( path )", + "filename": "misc_util.py", + "nloc": 21, + "complexity": 10, + "token_count": 190, + "parameters": [ + "path" + ], + "start_line": 138, + "end_line": 165, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 167, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 184, + "end_line": 186, + "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": 189, + "end_line": 192, + "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": 194, + "end_line": 195, + "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": 197, + "end_line": 211, + "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": 213, + "end_line": 223, + "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": 225, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 211, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 244, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "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": 277, + "end_line": 284, + "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": 8, + "complexity": 4, + "token_count": 61, + "parameters": [ + "config_list" + ], + "start_line": 285, + "end_line": 292, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 294, + "end_line": 299, + "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": 301, + "end_line": 302, + "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": 304, + "end_line": 319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "update_version", + "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", + "filename": "misc_util.py", + "nloc": 65, + "complexity": 12, + "token_count": 351, + "parameters": [ + "release_level", + "path", + "major", + "overwrite_version_py" + ], + "start_line": 3, + "end_line": 109, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "get_version", + "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "release_level", + "path", + "major" + ], + "start_line": 111, + "end_line": 124, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "get_cvs_revision", + "long_name": "get_cvs_revision( path )", + "filename": "misc_util.py", + "nloc": 21, + "complexity": 10, + "token_count": 190, + "parameters": [ + "path" + ], + "start_line": 127, + "end_line": 154, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 156, + "end_line": 171, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 173, + "end_line": 175, + "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": 178, + "end_line": 181, + "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": 183, + "end_line": 184, + "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": 186, + "end_line": 200, + "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": 202, + "end_line": 212, + "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": 214, + "end_line": 226, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 211, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 233, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "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": 266, + "end_line": 273, + "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": 8, + "complexity": 4, + "token_count": 61, + "parameters": [ + "config_list" + ], + "start_line": 274, + "end_line": 281, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 283, + "end_line": 288, + "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": 290, + "end_line": 291, + "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": 293, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "__getattr__", + "long_name": "__getattr__( self , name )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "name" + ], + "start_line": 11, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 9, + "end_line": 10, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + } + ], + "nloc": 209, + "complexity": 62, + "token_count": 1418, + "diff_parsed": { + "added": [ + "class PostponedException:", + " \"\"\"Postpone exception until an attempt is made to use a resource.", + " Example usage:", + " try: import foo", + " except ImportError: foo = PostponedException()", + " \"\"\"", + " def __init__(self):", + " self.info = sys.exc_info()[:2]", + " def __getattr__(self,name):", + " raise self.info[0],self.info[1]", + "" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "6c6d36aae7965d1c6756d3efc66f4a17957bff6e", + "msg": "Introduced PostponedException", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-03-01T17:02:10+00:00", + "author_timezone": 0, + "committer_date": "2002-03-01T17:02:10+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "5c232de49fabe194369cc53e9e0f57245c780973" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 7, + "insertions": 6, + "lines": 13, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "scipy_distutils/misc_util.py", + "new_path": "scipy_distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -1,15 +1,14 @@\n import os,sys,string\n \n class 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- \"\"\"\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 def __init__(self):\n- self.info = sys.exc_info()[:2]\n+ self._info = sys.exc_info()[:2]\n def __getattr__(self,name):\n- raise self.info[0],self.info[1]\n+ raise self._info[0],self._info[1]\n \n def update_version(release_level='alpha',\n path='.',\n", + "added_lines": 6, + "deleted_lines": 7, + "source_code": "import os,sys,string\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 def __init__(self):\n self._info = sys.exc_info()[:2]\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef 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\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef 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 ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", + "source_code_before": "import os,sys,string\n\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 \"\"\"\n def __init__(self):\n self.info = sys.exc_info()[:2]\n def __getattr__(self,name):\n raise self.info[0],self.info[1]\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef 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\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef 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 ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", + "methods": [ + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 8, + "end_line": 9, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "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": 10, + "end_line": 11, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "update_version", + "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", + "filename": "misc_util.py", + "nloc": 65, + "complexity": 12, + "token_count": 351, + "parameters": [ + "release_level", + "path", + "major", + "overwrite_version_py" + ], + "start_line": 13, + "end_line": 119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "get_version", + "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "release_level", + "path", + "major" + ], + "start_line": 121, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "get_cvs_revision", + "long_name": "get_cvs_revision( path )", + "filename": "misc_util.py", + "nloc": 21, + "complexity": 10, + "token_count": 190, + "parameters": [ + "path" + ], + "start_line": 137, + "end_line": 164, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 166, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 183, + "end_line": 185, + "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": 188, + "end_line": 191, + "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": 193, + "end_line": 194, + "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": 196, + "end_line": 210, + "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": 212, + "end_line": 222, + "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": 224, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 211, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 243, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "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": 276, + "end_line": 283, + "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": 8, + "complexity": 4, + "token_count": 61, + "parameters": [ + "config_list" + ], + "start_line": 284, + "end_line": 291, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 293, + "end_line": 298, + "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": 300, + "end_line": 301, + "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": 303, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 9, + "end_line": 10, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "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": 11, + "end_line": 12, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "update_version", + "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", + "filename": "misc_util.py", + "nloc": 65, + "complexity": 12, + "token_count": 351, + "parameters": [ + "release_level", + "path", + "major", + "overwrite_version_py" + ], + "start_line": 14, + "end_line": 120, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "get_version", + "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "release_level", + "path", + "major" + ], + "start_line": 122, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "get_cvs_revision", + "long_name": "get_cvs_revision( path )", + "filename": "misc_util.py", + "nloc": 21, + "complexity": 10, + "token_count": 190, + "parameters": [ + "path" + ], + "start_line": 138, + "end_line": 165, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 167, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 184, + "end_line": 186, + "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": 189, + "end_line": 192, + "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": 194, + "end_line": 195, + "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": 197, + "end_line": 211, + "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": 213, + "end_line": 223, + "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": 225, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 211, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 244, + "end_line": 275, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "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": 277, + "end_line": 284, + "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": 8, + "complexity": 4, + "token_count": 61, + "parameters": [ + "config_list" + ], + "start_line": 285, + "end_line": 292, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 294, + "end_line": 299, + "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": 301, + "end_line": 302, + "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": 304, + "end_line": 319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "__getattr__", + "long_name": "__getattr__( self , name )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 21, + "parameters": [ + "self", + "name" + ], + "start_line": 10, + "end_line": 11, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 8, + "end_line": 9, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + } + ], + "nloc": 205, + "complexity": 62, + "token_count": 1418, + "diff_parsed": { + "added": [ + " \"\"\"Postpone exception until an attempt is made to use a resource.\"\"\"", + " #Example usage:", + " # try: import foo", + " # except ImportError: foo = PostponedException()", + " self._info = sys.exc_info()[:2]", + " raise self._info[0],self._info[1]" + ], + "deleted": [ + " \"\"\"Postpone exception until an attempt is made to use a resource.", + " Example usage:", + " try: import foo", + " except ImportError: foo = PostponedException()", + " \"\"\"", + " self.info = sys.exc_info()[:2]", + " raise self.info[0],self.info[1]" + ] + } + } + ] + }, + { + "hash": "51f44ff4f1e50db5c51c3d3114500a01810505ec", + "msg": "Added prefix for fftw search path", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-03-01T21:59:29+00:00", + "author_timezone": 0, + "committer_date": "2002-03-01T21:59:29+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "6c6d36aae7965d1c6756d3efc66f4a17957bff6e" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 2, + "insertions": 4, + "lines": 6, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "scipy_distutils/system_info.py", + "new_path": "scipy_distutils/system_info.py", + "filename": "system_info.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -189,7 +189,8 @@ def calc_info(self,prefix):\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','fftw*','FFTW*']))\n \n- if not lib_dirs: return\n+ if not lib_dirs:\n+ lib_dirs = [prefix]\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,'include',['fftw*','FFTW*']))\n if not incl_dirs:\n@@ -198,7 +199,8 @@ def calc_info(self,prefix):\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['include','fftw*','FFTW*']))\n- if not incl_dirs: return\n+ if not incl_dirs:\n+ incl_dirs = [prefix]\n incl_dir = None\n \n libs = ['fftw','rfftw']\n", + "added_lines": 4, + "deleted_lines": 2, + "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 fftw_info\n x11_info\nThe following environment variables are used if defined:\n ATLAS - path to ATLAS library\n FFTW - path to FFTW library\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw'.\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 (or system_info could not find it).\n\nGlobal parameters:\n prefixes - a list of prefixes for scanning the location of\n resources.\n system_info.static_first - a flag for indicating that static\n libraries are searched first than shared ones.\n system_info.verbose - show the results if set.\n\nAuthor:\n Pearu Peterson , February 2002\nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re,types,pprint\nfrom distutils.errors import DistutilsError\nfrom glob import glob\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n prefixes = ['C:\\\\'] # XXX: what is prefix in win32?\nelse:\n prefixes = ['/usr','/usr/local','/opt']\nif sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\nprefixes = filter(os.path.isdir,prefixes) # XXX: Is this ok on win32? Is 'C:' dir?\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name):\n cl = {'atlas':atlas_info,\n 'x11':x11_info,\n 'fftw':fftw_info}.get(name.lower(),system_info)\n return cl().get_info()\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 Either install them in /usr/local/lib/atlas or /usr/lib/atlas\n and retry setup.py. One can use also ATLAS environment variable\n to indicate the location of Atlas libraries.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Either install them in /usr/local/lib or /usr/lib and retry setup.py.\n One can use also FFTW environment variable to indicate\n the location of FFTW libraries.\"\"\"\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://pfdubois.com/numpy/) 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\n static_first = 1\n verbose = 1\n need_refresh = 1\n saved_results = {}\n \n def __init__ (self):\n self.__class__.info = {}\n #self.__class__.need_refresh = not self.info\n self.local_prefixes = []\n\n def set_info(self,**info):\n #self.__class__.info = info\n self.saved_results[self.__class__.__name__] = info\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n def get_info(self):\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.verbose:\n print self.__class__.__name__ + ':'\n for p in self.local_prefixes + prefixes:\n if self.verbose:\n print ' Looking in',p,'...'\n self.calc_info(p)\n if self.has_info(): break\n if self.verbose:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbose and flag:\n for k,v in res.items():\n print ' %s = %s'%(k,v)\n print\n return res\n\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\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 mths = [self.check_static_libs,self.check_shared_libs]\n if not self.static_first:\n mths.reverse() # if one prefers shared libraries\n for m in mths:\n info = m(lib_dir,libs,opt_libs)\n if info is not None: return info\n\n def check_static_libs(self,lib_dir,libs,opt_libs =[]):\n #XXX: what are .lib and .dll files under win32?\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs])) == len(libs):\n info = {'libraries':libs,'library_dirs':[lib_dir]}\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs]))\\\n ==len(opt_libs):\n info['libraries'].extend(opt_libs)\n return info\n\n def check_shared_libs(self,lib_dir,libs,opt_libs =[]):\n shared_libs = []\n for l in libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: shared_libs.append(p)\n if len(shared_libs) == len(libs):\n info = {'extra_objects':shared_libs}\n opt_shared_libs = []\n for l in opt_libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: opt_shared_libs.append(p)\n info['extra_objects'].extend(opt_shared_libs)\n return info\n\n\nclass fftw_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('FFTW')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self,prefix):\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,'lib',['fftw*','FFTW*']))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'lib'))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','fftw*','FFTW*']))\n \n if not lib_dirs:\n lib_dirs = [prefix]\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,'include',['fftw*','FFTW*']))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'include'))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['include','fftw*','FFTW*']))\n if not incl_dirs:\n incl_dirs = [prefix]\n incl_dir = None\n\n libs = ['fftw','rfftw']\n opt_libs = ['fftw_threads','rfftw_threads']\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['fftw.h','rfftw.h']))==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=[('SCIPY_FFTW_H',1)])\n else:\n info = None\n\n if info is None:\n libs = ['dfftw','drfftw']\n opt_libs = ['dfftw_threads','drfftw_threads']\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['dfftw.h','drfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n incl_dirs = [d]\n incl_dir = d\n flag = 1\n break\n if flag:\n dict_append(info,define_macros=[('SCIPY_DFFTW_H',1)])\n else:\n info = None\n \n libs = ['sfftw','srfftw']\n opt_libs = ['sfftw_threads','srfftw_threads']\n flag = 0\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_libs)\n if r is not None:\n if info is None: info = r\n else: dict_append(info,**r)\n flag = 1\n break\n if info is not None and flag:\n for d in incl_dirs:\n if len(combine_paths(d,['sfftw.h','srfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n dict_append(info,define_macros=[('SCIPY_SFFTW_H',1)])\n break\n if info is not None:\n self.set_info(**info)\n\n\nclass atlas_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('ATLAS')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self, prefix):\n lib_dirs = filter(os.path.isdir,combine_paths(prefix,'lib',\n ['atlas*','ATLAS*']))\n if lib_dirs:\n other_dirs = filter(os.path.isdir,combine_paths(lib_dirs,'*'))\n other_dirs.extend(filter(os.path.isdir,combine_paths(prefix,'lib')))\n lib_dirs.extend(other_dirs)\n else:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','atlas*','ATLAS*']))\n if not lib_dirs:\n lib_dirs = [prefix]\n\n h = (combine_paths(lib_dirs,'cblas.h') or [None])[0]\n if not h:\n h = (combine_paths(lib_dirs,'include','cblas.h') or [None])[0]\n if h: h = os.path.dirname(h)\n\n libs = ['lapack','f77blas','cblas','atlas']\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 None: return\n if h: dict_append(info,include_dirs=h)\n self.set_info(**info)\n\n\nclass blas_info(system_info):\n # For Fortran or optimized blas, not atlas.\n pass\n\n\nclass lapack_info(system_info):\n # For Fortran or optimized lapack, not atlas\n pass\n\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = self.check_libs(lib_dir[0],['X11'],[])\n if info is None:\n continue\n dict_append(info,include_dirs=[inc_dir])\n self.set_info(**info)\n\ndef shortest_path(pths):\n pths.sort()\n if pths: return pths[0]\n\ndef combine_paths(*args):\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 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 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 r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\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 fftw_info\n x11_info\nThe following environment variables are used if defined:\n ATLAS - path to ATLAS library\n FFTW - path to FFTW library\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw'.\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 (or system_info could not find it).\n\nGlobal parameters:\n prefixes - a list of prefixes for scanning the location of\n resources.\n system_info.static_first - a flag for indicating that static\n libraries are searched first than shared ones.\n system_info.verbose - show the results if set.\n\nAuthor:\n Pearu Peterson , February 2002\nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re,types,pprint\nfrom distutils.errors import DistutilsError\nfrom glob import glob\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n prefixes = ['C:\\\\'] # XXX: what is prefix in win32?\nelse:\n prefixes = ['/usr','/usr/local','/opt']\nif sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\nprefixes = filter(os.path.isdir,prefixes) # XXX: Is this ok on win32? Is 'C:' dir?\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name):\n cl = {'atlas':atlas_info,\n 'x11':x11_info,\n 'fftw':fftw_info}.get(name.lower(),system_info)\n return cl().get_info()\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 Either install them in /usr/local/lib/atlas or /usr/lib/atlas\n and retry setup.py. One can use also ATLAS environment variable\n to indicate the location of Atlas libraries.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Either install them in /usr/local/lib or /usr/lib and retry setup.py.\n One can use also FFTW environment variable to indicate\n the location of FFTW libraries.\"\"\"\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://pfdubois.com/numpy/) 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\n static_first = 1\n verbose = 1\n need_refresh = 1\n saved_results = {}\n \n def __init__ (self):\n self.__class__.info = {}\n #self.__class__.need_refresh = not self.info\n self.local_prefixes = []\n\n def set_info(self,**info):\n #self.__class__.info = info\n self.saved_results[self.__class__.__name__] = info\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n def get_info(self):\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.verbose:\n print self.__class__.__name__ + ':'\n for p in self.local_prefixes + prefixes:\n if self.verbose:\n print ' Looking in',p,'...'\n self.calc_info(p)\n if self.has_info(): break\n if self.verbose:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbose and flag:\n for k,v in res.items():\n print ' %s = %s'%(k,v)\n print\n return res\n\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\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 mths = [self.check_static_libs,self.check_shared_libs]\n if not self.static_first:\n mths.reverse() # if one prefers shared libraries\n for m in mths:\n info = m(lib_dir,libs,opt_libs)\n if info is not None: return info\n\n def check_static_libs(self,lib_dir,libs,opt_libs =[]):\n #XXX: what are .lib and .dll files under win32?\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs])) == len(libs):\n info = {'libraries':libs,'library_dirs':[lib_dir]}\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs]))\\\n ==len(opt_libs):\n info['libraries'].extend(opt_libs)\n return info\n\n def check_shared_libs(self,lib_dir,libs,opt_libs =[]):\n shared_libs = []\n for l in libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: shared_libs.append(p)\n if len(shared_libs) == len(libs):\n info = {'extra_objects':shared_libs}\n opt_shared_libs = []\n for l in opt_libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: opt_shared_libs.append(p)\n info['extra_objects'].extend(opt_shared_libs)\n return info\n\n\nclass fftw_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('FFTW')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self,prefix):\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,'lib',['fftw*','FFTW*']))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'lib'))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','fftw*','FFTW*']))\n \n if not lib_dirs: return\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,'include',['fftw*','FFTW*']))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'include'))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['include','fftw*','FFTW*']))\n if not incl_dirs: return\n incl_dir = None\n\n libs = ['fftw','rfftw']\n opt_libs = ['fftw_threads','rfftw_threads']\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['fftw.h','rfftw.h']))==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=[('SCIPY_FFTW_H',1)])\n else:\n info = None\n\n if info is None:\n libs = ['dfftw','drfftw']\n opt_libs = ['dfftw_threads','drfftw_threads']\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['dfftw.h','drfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n incl_dirs = [d]\n incl_dir = d\n flag = 1\n break\n if flag:\n dict_append(info,define_macros=[('SCIPY_DFFTW_H',1)])\n else:\n info = None\n \n libs = ['sfftw','srfftw']\n opt_libs = ['sfftw_threads','srfftw_threads']\n flag = 0\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_libs)\n if r is not None:\n if info is None: info = r\n else: dict_append(info,**r)\n flag = 1\n break\n if info is not None and flag:\n for d in incl_dirs:\n if len(combine_paths(d,['sfftw.h','srfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n dict_append(info,define_macros=[('SCIPY_SFFTW_H',1)])\n break\n if info is not None:\n self.set_info(**info)\n\n\nclass atlas_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('ATLAS')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self, prefix):\n lib_dirs = filter(os.path.isdir,combine_paths(prefix,'lib',\n ['atlas*','ATLAS*']))\n if lib_dirs:\n other_dirs = filter(os.path.isdir,combine_paths(lib_dirs,'*'))\n other_dirs.extend(filter(os.path.isdir,combine_paths(prefix,'lib')))\n lib_dirs.extend(other_dirs)\n else:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','atlas*','ATLAS*']))\n if not lib_dirs:\n lib_dirs = [prefix]\n\n h = (combine_paths(lib_dirs,'cblas.h') or [None])[0]\n if not h:\n h = (combine_paths(lib_dirs,'include','cblas.h') or [None])[0]\n if h: h = os.path.dirname(h)\n\n libs = ['lapack','f77blas','cblas','atlas']\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 None: return\n if h: dict_append(info,include_dirs=h)\n self.set_info(**info)\n\n\nclass blas_info(system_info):\n # For Fortran or optimized blas, not atlas.\n pass\n\n\nclass lapack_info(system_info):\n # For Fortran or optimized lapack, not atlas\n pass\n\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = self.check_libs(lib_dir[0],['X11'],[])\n if info is None:\n continue\n dict_append(info,include_dirs=[inc_dir])\n self.set_info(**info)\n\ndef shortest_path(pths):\n pths.sort()\n if pths: return pths[0]\n\ndef combine_paths(*args):\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 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 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 r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n", + "methods": [ + { + "name": "get_info", + "long_name": "get_info( name )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 1, + "token_count": 39, + "parameters": [ + "name" + ], + "start_line": 52, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 98, + "end_line": 101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 103, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "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": 106, + "end_line": 107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 11, + "token_count": 134, + "parameters": [ + "self" + ], + "start_line": 108, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 135, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 60, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 138, + "end_line": 146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_static_libs", + "long_name": "check_static_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 5, + "token_count": 91, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 148, + "end_line": 155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_shared_libs", + "long_name": "check_shared_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 13, + "complexity": 6, + "token_count": 119, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 157, + "end_line": 169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 174, + "end_line": 180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 84, + "complexity": 30, + "token_count": 561, + "parameters": [ + "self", + "prefix" + ], + "start_line": 182, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 11, + "token_count": 229, + "parameters": [ + "self", + "prefix" + ], + "start_line": 282, + "end_line": 309, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "prefix" + ], + "start_line": 324, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "shortest_path", + "long_name": "shortest_path( pths )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "pths" + ], + "start_line": 342, + "end_line": 344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 9, + "token_count": 162, + "parameters": [ + "args" + ], + "start_line": 346, + "end_line": 367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 369, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [], + "start_line": 376, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "get_info", + "long_name": "get_info( name )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 1, + "token_count": 39, + "parameters": [ + "name" + ], + "start_line": 52, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 98, + "end_line": 101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 103, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "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": 106, + "end_line": 107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 11, + "token_count": 134, + "parameters": [ + "self" + ], + "start_line": 108, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 135, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 60, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 138, + "end_line": 146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_static_libs", + "long_name": "check_static_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 5, + "token_count": 91, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 148, + "end_line": 155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_shared_libs", + "long_name": "check_shared_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 13, + "complexity": 6, + "token_count": 119, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 157, + "end_line": 169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 174, + "end_line": 180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 82, + "complexity": 30, + "token_count": 553, + "parameters": [ + "self", + "prefix" + ], + "start_line": 182, + "end_line": 267, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 86, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 272, + "end_line": 278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 11, + "token_count": 229, + "parameters": [ + "self", + "prefix" + ], + "start_line": 280, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "prefix" + ], + "start_line": 322, + "end_line": 338, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "shortest_path", + "long_name": "shortest_path( pths )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "pths" + ], + "start_line": 340, + "end_line": 342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 9, + "token_count": 162, + "parameters": [ + "args" + ], + "start_line": 344, + "end_line": 365, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 367, + "end_line": 372, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [], + "start_line": 374, + "end_line": 381, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 84, + "complexity": 30, + "token_count": 561, + "parameters": [ + "self", + "prefix" + ], + "start_line": 182, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 1 + } + ], + "nloc": 325, + "complexity": 103, + "token_count": 2018, + "diff_parsed": { + "added": [ + " if not lib_dirs:", + " lib_dirs = [prefix]", + " if not incl_dirs:", + " incl_dirs = [prefix]" + ], + "deleted": [ + " if not lib_dirs: return", + " if not incl_dirs: return" + ] + } + } + ] + }, + { + "hash": "ebe901ba76179aca6074b728164da7c0ccab023f", + "msg": "Minor enhancments", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-03-02T09:18:01+00:00", + "author_timezone": 0, + "committer_date": "2002-03-02T09:18:01+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "51f44ff4f1e50db5c51c3d3114500a01810505ec" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 0, + "insertions": 2, + "lines": 2, + "files": 1, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 1.0, + "modified_files": [ + { + "old_path": "scipy_distutils/misc_util.py", + "new_path": "scipy_distutils/misc_util.py", + "filename": "misc_util.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -5,8 +5,10 @@ class PostponedException:\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 \n", + "added_lines": 2, + "deleted_lines": 0, + "source_code": "import os,sys,string\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 update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef 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\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef 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 ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", + "source_code_before": "import os,sys,string\n\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 def __init__(self):\n self._info = sys.exc_info()[:2]\n def __getattr__(self,name):\n raise self._info[0],self._info[1]\n\ndef update_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n overwrite_version_py = 1):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . If the version information is different from the one\n found in the /__version__.py file, update_version updates\n the file automatically. The version information will be always\n increasing in time.\n If CVS tree does not exist (e.g. as in distribution packages),\n return the version string found from /__version__.py.\n If no version information is available, return None.\n\n Default version string is in the form\n\n ..--\n\n The items have the following meanings:\n\n serial - shows cumulative changes in all files in the CVS\n repository\n micro - a number that is equivalent to the number of files\n minor - indicates the changes in micro value (files are added\n or removed)\n release_level - is alpha, beta, canditate, or final\n major - indicates changes in release_level.\n\n \"\"\"\n # Issues:\n # *** Recommend or not to add __version__.py file to CVS\n # repository? If it is in CVS, then when commiting, the\n # version information will change, but __version__.py\n # is commited with the old version information. To get\n # __version__.py also up to date, a second commit of the\n # __version__.py file is required after you re-run\n # update_version(..). To summarize:\n # 1) cvs commit ...\n # 2) python setup.py # that should call update_version\n # 3) cvs commit -m \"updating version\" __version__.py\n\n release_level_map = {'alpha':0,\n 'beta':1,\n 'canditate':2,\n 'final':3}\n release_level_value = release_level_map.get(release_level)\n if release_level_value is None:\n print 'Warning: release_level=%s is not %s'\\\n % (release_level,\n string.join(release_level_map.keys(),','))\n\n cwd = os.getcwd()\n os.chdir(path)\n try:\n version_module = __import__('__version__')\n reload(version_module)\n old_version_info = version_module.version_info\n old_version = version_module.version\n except:\n print sys.exc_value\n old_version_info = None\n old_version = None\n os.chdir(cwd)\n\n cvs_revs = get_cvs_revision(path)\n if cvs_revs is None:\n return old_version\n\n minor = 1\n micro,serial = cvs_revs\n if old_version_info is not None:\n minor = old_version_info[1]\n old_release_level_value = release_level_map.get(old_version_info[3])\n if micro != old_version_info[2]: # files have beed added or removed\n minor = minor + 1\n if major is None:\n major = old_version_info[0]\n if old_release_level_value is not None:\n if old_release_level_value > release_level_value:\n major = major + 1\n if major is None:\n major = 0\n\n version_info = (major,minor,micro,release_level,serial)\n version_dict = {'major':major,'minor':minor,'micro':micro,\n 'release_level':release_level,'serial':serial\n }\n version = version_template % version_dict\n\n if version_info != old_version_info:\n print 'version increase detected: %s -> %s'%(old_version,version)\n version_file = os.path.join(path,'__version__.py')\n if not overwrite_version_py:\n print 'keeping %s with old version, returing new version' \\\n % (version_file)\n return version\n print 'updating version in %s' % version_file\n version_file = os.path.abspath(version_file)\n f = open(version_file,'w')\n f.write('# This file is automatically updated with update_version\\n'\\\n '# function from scipy_distutils.misc_util.py\\n'\\\n 'version = %s\\n'\\\n 'version_info = %s\\n'%(repr(version),version_info))\n f.close()\n return version\n\ndef get_version(release_level='alpha',\n path='.',\n version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d',\n major=None,\n ):\n \"\"\"\n Return version string calculated from CVS/Entries file(s) starting\n at . Does not change /__version__.py.\n See also update_version(..) function.\n \"\"\"\n return update_version(release_level = release_level,path = path,\n version_template = version_template,\n major = major,overwrite_version_py = 0)\n\n\ndef get_cvs_revision(path):\n \"\"\"\n Return two last cumulative revision numbers of a CVS tree starting\n at . The first number shows the number of files in the CVS\n tree (this is often true, but not always) and the second number\n characterizes the changes in these files.\n If /CVS/Entries is not existing then return None.\n \"\"\"\n entries_file = os.path.join(path,'CVS','Entries')\n if os.path.exists(entries_file):\n rev1,rev2 = 0,0\n for line in open(entries_file).readlines():\n items = string.split(line,'/')\n if items[0]=='D' and len(items)>1:\n try:\n d1,d2 = get_cvs_revision(os.path.join(path,items[1]))\n except:\n d1,d2 = 0,0\n elif items[0]=='' and len(items)>3 and items[1]!='__version__.py':\n\t\tlast_numbers = map(eval,string.split(items[2],'.')[-2:])\n\t\tif len(last_numbers)==2:\n\t\t d1,d2 = last_numbers\n\t\telse: # this is when 'cvs add' but not yet 'cvs commit'\n\t\t d1,d2 = 0,0\n else:\n continue\n rev1,rev2 = rev1+d1,rev2+d2\n return rev1,rev2\n\ndef get_path(mod_name):\n \"\"\" This function makes sure installation is done from the\n correct directory no matter if it is installed from the\n command line or from another package or run_setup function.\n \n \"\"\"\n if mod_name == '__main__':\n d = os.path.abspath('.')\n elif mod_name == '__builtin__':\n #builtin if/then added by Pearu for use in core.run_setup. \n d = os.path.dirname(os.path.abspath(sys.argv[0]))\n else:\n mod = __import__(mod_name)\n file = mod.__file__\n d = os.path.dirname(os.path.abspath(file))\n return d\n \ndef add_local_to_path(mod_name):\n local_path = get_path(mod_name)\n sys.path.insert(0,local_path)\n\n\ndef add_grandparent_to_path(mod_name):\n local_path = get_path(mod_name)\n gp_dir = os.path.split(local_path)[0]\n sys.path.insert(0,gp_dir)\n\ndef restore_path():\n del sys.path[0]\n\ndef append_package_dir_to_path(package_name): \n \"\"\" Search for a directory with package_name and append it to PYTHONPATH\n \n The local directory is searched first and then the parent directory.\n \"\"\"\n # first see if it is in the current path\n # then try parent. If it isn't found, fail silently\n # and let the import error occur.\n \n # not an easy way to clean up after this...\n import os,sys\n if os.path.exists(package_name):\n sys.path.append(package_name)\n elif os.path.exists(os.path.join('..',package_name)):\n sys.path.append(os.path.join('..',package_name))\n\ndef get_package_config(package_name):\n \"\"\" grab the configuration info from the setup_xxx.py file\n in a package directory. The package directory is searched\n from the current directory, so setting the path to the\n setup.py file directory of the file calling this is usually\n needed to get search the path correct.\n \"\"\"\n append_package_dir_to_path(package_name)\n mod = __import__('setup_'+package_name)\n config = mod.configuration()\n return config\n\ndef package_config(primary,dependencies=[]):\n \"\"\" Create a configuration dictionary ready for setup.py from\n a list of primary and dependent package names. Each\n package listed must have a directory with the same name\n in the current or parent working directory. Further, it\n should have a setup_xxx.py module within that directory that\n has a configuration() file in it. \n \"\"\"\n config = []\n config.extend([get_package_config(x) for x in primary])\n config.extend([get_package_config(x) for x in dependencies]) \n config_dict = merge_config_dicts(config)\n return config_dict\n \nlist_keys = ['packages', 'ext_modules', 'data_files',\n 'include_dirs', 'libraries', 'fortran_libraries',\n 'headers']\ndict_keys = ['package_dir'] \n\ndef default_config_dict(name = None, parent_name = None):\n d={}\n for key in list_keys: d[key] = []\n for key in dict_keys: d[key] = {}\n\n full_name = dot_join(parent_name,name)\n\n if full_name:\n # XXX: The following assumes that default_config_dict is called\n # only from setup_.configuration().\n frame = get_frame(1)\n caller_name = eval('__name__',frame.f_globals,frame.f_locals)\n local_path = get_path(caller_name)\n if name and parent_name is None:\n # Useful for local builds\n d['version'] = get_version(path=local_path)\n\n if os.path.exists(os.path.join(local_path,'__init__.py')):\n d['packages'].append(full_name)\n d['package_dir'][full_name] = local_path\n d['name'] = full_name\n if not parent_name:\n # Include scipy_distutils to local distributions\n for p in ['.','..']:\n dir_name = os.path.abspath(os.path.join(local_path,\n p,'scipy_distutils'))\n if os.path.exists(dir_name):\n d['packages'].append('scipy_distutils')\n d['packages'].append('scipy_distutils.command')\n d['package_dir']['scipy_distutils'] = dir_name\n break\n return d\n\ndef 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\ndef merge_config_dicts(config_list):\n result = default_config_dict()\n for d in config_list:\n for key in list_keys:\n result[key].extend(d.get(key,[]))\n for key in dict_keys:\n result[key].update(d.get(key,{}))\n return result\n\ndef 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 ):\n \"\"\" Helper function for creating fortran_libraries items. \"\"\"\n build_info = {'sources':sources}\n known_attrs = ['module_files','module_dirs',\n 'libraries','library_dirs']\n for key,value in attrs.items():\n if key not in known_attrs:\n raise TypeError,\\\n \"fortran_library_item() got an unexpected keyword \"\\\n \"argument '%s'\" % key\n build_info[key] = value\n \n return (lib_name,build_info)\n", + "methods": [ + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 9, + "end_line": 11, + "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": 12, + "end_line": 13, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "update_version", + "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", + "filename": "misc_util.py", + "nloc": 65, + "complexity": 12, + "token_count": 351, + "parameters": [ + "release_level", + "path", + "major", + "overwrite_version_py" + ], + "start_line": 15, + "end_line": 121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "get_version", + "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "release_level", + "path", + "major" + ], + "start_line": 123, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "get_cvs_revision", + "long_name": "get_cvs_revision( path )", + "filename": "misc_util.py", + "nloc": 21, + "complexity": 10, + "token_count": 190, + "parameters": [ + "path" + ], + "start_line": 139, + "end_line": 166, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 168, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 185, + "end_line": 187, + "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": 190, + "end_line": 193, + "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": 195, + "end_line": 196, + "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": 198, + "end_line": 212, + "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": 214, + "end_line": 224, + "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": 226, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 211, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 245, + "end_line": 276, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "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": 278, + "end_line": 285, + "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": 8, + "complexity": 4, + "token_count": 61, + "parameters": [ + "config_list" + ], + "start_line": 286, + "end_line": 293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 295, + "end_line": 300, + "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": 302, + "end_line": 303, + "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": 305, + "end_line": 320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "misc_util.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 8, + "end_line": 9, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "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": 10, + "end_line": 11, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "update_version", + "long_name": "update_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , overwrite_version_py = 1 )", + "filename": "misc_util.py", + "nloc": 65, + "complexity": 12, + "token_count": 351, + "parameters": [ + "release_level", + "path", + "major", + "overwrite_version_py" + ], + "start_line": 13, + "end_line": 119, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 107, + "top_nesting_level": 0 + }, + { + "name": "get_version", + "long_name": "get_version( release_level = 'alpha' , path = '.' , version_template = \\\n '%(major)d.%(minor)d.%(micro)d-%(release_level)s-%(serial)d' , major = None , )", + "filename": "misc_util.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "release_level", + "path", + "major" + ], + "start_line": 121, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 0 + }, + { + "name": "get_cvs_revision", + "long_name": "get_cvs_revision( path )", + "filename": "misc_util.py", + "nloc": 21, + "complexity": 10, + "token_count": 190, + "parameters": [ + "path" + ], + "start_line": 137, + "end_line": 164, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 0 + }, + { + "name": "get_path", + "long_name": "get_path( mod_name )", + "filename": "misc_util.py", + "nloc": 10, + "complexity": 3, + "token_count": 80, + "parameters": [ + "mod_name" + ], + "start_line": 166, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "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": 183, + "end_line": 185, + "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": 188, + "end_line": 191, + "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": 193, + "end_line": 194, + "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": 196, + "end_line": 210, + "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": 212, + "end_line": 222, + "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": 224, + "end_line": 236, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 0 + }, + { + "name": "default_config_dict", + "long_name": "default_config_dict( name = None , parent_name = None )", + "filename": "misc_util.py", + "nloc": 25, + "complexity": 10, + "token_count": 211, + "parameters": [ + "name", + "parent_name" + ], + "start_line": 243, + "end_line": 274, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "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": 276, + "end_line": 283, + "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": 8, + "complexity": 4, + "token_count": 61, + "parameters": [ + "config_list" + ], + "start_line": 284, + "end_line": 291, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "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": 293, + "end_line": 298, + "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": 300, + "end_line": 301, + "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": 303, + "end_line": 318, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "misc_util.py", + "nloc": 3, + "complexity": 1, + "token_count": 30, + "parameters": [ + "self" + ], + "start_line": 9, + "end_line": 11, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + } + ], + "nloc": 207, + "complexity": 62, + "token_count": 1434, + "diff_parsed": { + "added": [ + " __all__ = []", + " self.__doc__ = '%s: %s' % tuple(self._info)" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "85943af1f38224aab592e5bf7a50b20d9aebde05", + "msg": "Loops and 2D Numpy arrays (getitem and setitem). Still issues\nwith refcounting and really no safety net, but enough to demonstrate\nsome speed.", + "author": { + "name": "patmiller", + "email": "patmiller@localhost" + }, + "committer": { + "name": "patmiller", + "email": "patmiller@localhost" + }, + "author_date": "2002-03-03T07:02:48+00:00", + "author_timezone": 0, + "committer_date": "2002-03-03T07:02:48+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "ebe901ba76179aca6074b728164da7c0ccab023f" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 23, + "insertions": 179, + "lines": 202, + "files": 2, + "dmm_unit_size": 1.0, + "dmm_unit_complexity": 1.0, + "dmm_unit_interfacing": 0.5925925925925926, + "modified_files": [ + { + "old_path": "weave/accelerate_tools.py", + "new_path": "weave/accelerate_tools.py", + "filename": "accelerate_tools.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -58,12 +58,20 @@ class String(Basic):\n def literalizer(self,s):\n return CStr(s)\n \n+# -----------------------------------------------\n+# Singletonize the type names\n+# -----------------------------------------------\n+Integer = Integer()\n+Double = Double()\n+String = String()\n+\n import Numeric\n \n class Vector(Type_Descriptor):\n cxxtype = 'PyArrayObject*'\n refcount = 1\n- module_init_code = 'import_array'\n+ dims = 1\n+ module_init_code = 'import_array();'\n \n prerequisites = Type_Descriptor.prerequisites+\\\n ['#include \"Numeric/arrayobject.h\"']\n@@ -75,12 +83,49 @@ def inbound(self,s):\n return \"(PyArrayObject*)(%s)\"%s\n def outbound(self,s):\n return \"(PyObject*)(%s)\"%s\n- def binopMixed(self,symbol,a,b):\n- return '*((%s*)(%s->data+%s*%s->strides[0]))'%(self.cxxbase,a,b,a),Integer\n+ def getitem(self,A,v,t):\n+ assert self.dims == len(v),'Expect dimension %d'%self.dims\n+ code = '*((%s*)(%s->data'%(self.cxxbase,A)\n+ for i in range(self.dims):\n+ # assert that ''t[i]'' is an integer\n+ code += '+%s*%s->strides[%d]'%(v[i],A,i)\n+ code += '))'\n+ return code,self.pybase\n+ def setitem(self,A,v,t):\n+ return self.getitem(A,v,t)\n+\n+class Matrix(Vector):\n+ dims = 2\n \n class IntegerVector(Vector):\n typecode = 'PyArray_INT'\n cxxbase = 'int'\n+ pybase = Integer\n+\n+class IntegerMatrix(Matrix):\n+ typecode = 'PyArray_INT'\n+ cxxbase = 'int'\n+ pybase = Integer\n+\n+class LongVector(Vector):\n+ typecode = 'PyArray_LONG'\n+ cxxbase = 'long'\n+ pybase = Integer\n+\n+class LongMatrix(Matrix):\n+ typecode = 'PyArray_LONG'\n+ cxxbase = 'long'\n+ pybase = Integer\n+\n+class DoubleVector(Vector):\n+ typecode = 'PyArray_DOUBLE'\n+ cxxbase = 'double'\n+ pybase = Double\n+\n+class DoubleMatrix(Matrix):\n+ typecode = 'PyArray_DOUBLE'\n+ cxxbase = 'double'\n+ pybase = Double\n \n class XRange(Type_Descriptor):\n cxxtype = 'XRange'\n@@ -99,17 +144,24 @@ class XRange {\n # -----------------------------------------------\n # Singletonize the type names\n # -----------------------------------------------\n-Integer = Integer()\n-Double = Double()\n-String = String()\n IntegerVector = IntegerVector()\n+IntegerMatrix = IntegerMatrix()\n+LongVector = LongVector()\n+LongMatrix = LongMatrix()\n+DoubleVector = DoubleVector()\n+DoubleMatrix = DoubleMatrix()\n XRange = XRange()\n \n typedefs = {\n IntType: Integer,\n FloatType: Double,\n StringType: String,\n- (Numeric.ArrayType,1,'l'): IntegerVector,\n+ (Numeric.ArrayType,1,'i'): IntegerVector,\n+ (Numeric.ArrayType,2,'i'): IntegerMatrix,\n+ (Numeric.ArrayType,1,'l'): LongVector,\n+ (Numeric.ArrayType,2,'l'): LongMatrix,\n+ (Numeric.ArrayType,1,'d'): DoubleVector,\n+ (Numeric.ArrayType,2,'d'): DoubleMatrix,\n XRangeType : XRange,\n }\n \n@@ -120,6 +172,9 @@ class XRange {\n \n (math.sin,(Double,)):\n Function_Descriptor(code='sin(%s)',return_type=Double),\n+\n+ (math.sqrt,(Double,)):\n+ Function_Descriptor(code='sqrt(%s)',return_type=Double),\n }\n \n \n@@ -207,6 +262,7 @@ def identifier(self,signature):\n f = self.function\n co = f.func_code\n identifier = str(signature)+\\\n+ str(co.co_argcount)+\\\n str(co.co_consts)+\\\n str(co.co_varnames)+\\\n co.co_code\n@@ -217,6 +273,11 @@ def accelerate(self,signature,identifier):\n return P\n \n def code(self,*args):\n+ if len(args) != self.function.func_code.co_argcount:\n+ raise TypeError,'%s() takes exactly %d arguments (%d given)'%(\n+ self.function.__name__,\n+ self.function.func_code.co_argcount,\n+ len(args))\n signature = tuple( map(lookup_type,args) )\n ident = self.function.__name__\n return self.accelerate(signature,ident).function_code()\n", + "added_lines": 68, + "deleted_lines": 7, + "source_code": "#**************************************************************************#\n#* FILE ************** accelerate_tools.py ************************#\n#**************************************************************************#\n#* Author: Patrick Miller February 9 2002 *#\n#**************************************************************************#\n\"\"\"\naccelerate_tools contains the interface for on-the-fly building of\nC++ equivalents to Python functions.\n\"\"\"\n#**************************************************************************#\n\nfrom types import FunctionType,IntType,FloatType,StringType,TypeType,XRangeType\nimport inspect\nimport md5\nimport weave\nfrom bytecodecompiler import CXXCoder,Type_Descriptor,Function_Descriptor\n\ndef CStr(s):\n \"Hacky way to get legal C string from Python string\"\n if s == None: return '\"\"'\n assert type(s) == StringType,\"Only None and string allowed\"\n r = repr('\"'+s) # Better for embedded quotes\n return '\"'+r[2:-1]+'\"'\n\nclass Basic(Type_Descriptor):\n def check(self,s):\n return \"%s(%s)\"%(self.checker,s)\n def inbound(self,s):\n return \"%s(%s)\"%(self.inbounder,s)\n def outbound(self,s):\n return \"%s(%s)\"%(self.outbounder,s)\n\nclass Basic_Number(Basic):\n def literalizer(self,s):\n return str(s)\n def binop(self,symbol,a,b):\n assert symbol in ['+','-','*','/'],symbol\n return '%s %s %s'%(a,symbol,b),self\n\nclass Integer(Basic_Number):\n cxxtype = \"long\"\n checker = \"PyInt_Check\"\n inbounder = \"PyInt_AsLong\"\n outbounder = \"PyInt_FromLong\"\n\nclass Double(Basic_Number):\n cxxtype = \"double\"\n checker = \"PyFloat_Check\"\n inbounder = \"PyFloat_AsDouble\"\n outbounder = \"PyFloat_FromDouble\"\n\nclass String(Basic):\n cxxtype = \"char*\"\n checker = \"PyString_Check\"\n inbounder = \"PyString_AsString\"\n outbounder = \"PyString_FromString\"\n\n def literalizer(self,s):\n return CStr(s)\n\n# -----------------------------------------------\n# Singletonize the type names\n# -----------------------------------------------\nInteger = Integer()\nDouble = Double()\nString = String()\n\nimport Numeric\n\nclass Vector(Type_Descriptor):\n cxxtype = 'PyArrayObject*'\n refcount = 1\n dims = 1\n module_init_code = 'import_array();'\n\n prerequisites = Type_Descriptor.prerequisites+\\\n ['#include \"Numeric/arrayobject.h\"']\n dims = 1\n def check(self,s):\n return \"PyArray_Check(%s) && ((PyArrayObject*)%s)->nd == %d && ((PyArrayObject*)%s)->descr->type_num == %s\"%(\n s,s,self.dims,s,self.typecode)\n def inbound(self,s):\n return \"(PyArrayObject*)(%s)\"%s\n def outbound(self,s):\n return \"(PyObject*)(%s)\"%s\n def getitem(self,A,v,t):\n assert self.dims == len(v),'Expect dimension %d'%self.dims\n code = '*((%s*)(%s->data'%(self.cxxbase,A)\n for i in range(self.dims):\n # assert that ''t[i]'' is an integer\n code += '+%s*%s->strides[%d]'%(v[i],A,i)\n code += '))'\n return code,self.pybase\n def setitem(self,A,v,t):\n return self.getitem(A,v,t)\n\nclass Matrix(Vector):\n dims = 2\n\nclass IntegerVector(Vector):\n typecode = 'PyArray_INT'\n cxxbase = 'int'\n pybase = Integer\n\nclass IntegerMatrix(Matrix):\n typecode = 'PyArray_INT'\n cxxbase = 'int'\n pybase = Integer\n\nclass LongVector(Vector):\n typecode = 'PyArray_LONG'\n cxxbase = 'long'\n pybase = Integer\n\nclass LongMatrix(Matrix):\n typecode = 'PyArray_LONG'\n cxxbase = 'long'\n pybase = Integer\n\nclass DoubleVector(Vector):\n typecode = 'PyArray_DOUBLE'\n cxxbase = 'double'\n pybase = Double\n\nclass DoubleMatrix(Matrix):\n typecode = 'PyArray_DOUBLE'\n cxxbase = 'double'\n pybase = Double\n\nclass XRange(Type_Descriptor):\n cxxtype = 'XRange'\n prerequisites = ['''\n class XRange {\n public:\n XRange(long aLow, long aHigh, long aStep=1)\n : low(aLow),high(aHigh),step(aStep)\n {\n }\n long low;\n long high;\n long step;\n };''']\n\n# -----------------------------------------------\n# Singletonize the type names\n# -----------------------------------------------\nIntegerVector = IntegerVector()\nIntegerMatrix = IntegerMatrix()\nLongVector = LongVector()\nLongMatrix = LongMatrix()\nDoubleVector = DoubleVector()\nDoubleMatrix = DoubleMatrix()\nXRange = XRange()\n\ntypedefs = {\n IntType: Integer,\n FloatType: Double,\n StringType: String,\n (Numeric.ArrayType,1,'i'): IntegerVector,\n (Numeric.ArrayType,2,'i'): IntegerMatrix,\n (Numeric.ArrayType,1,'l'): LongVector,\n (Numeric.ArrayType,2,'l'): LongMatrix,\n (Numeric.ArrayType,1,'d'): DoubleVector,\n (Numeric.ArrayType,2,'d'): DoubleMatrix,\n XRangeType : XRange,\n }\n\nimport math\nfunctiondefs = {\n (range,(Integer,Integer)):\n Function_Descriptor(code='XRange(%s)',return_type=XRange),\n\n (math.sin,(Double,)):\n Function_Descriptor(code='sin(%s)',return_type=Double),\n\n (math.sqrt,(Double,)):\n Function_Descriptor(code='sqrt(%s)',return_type=Double),\n }\n \n\n\n##################################################################\n# FUNCTION LOOKUP_TYPE #\n##################################################################\ndef lookup_type(x):\n T = type(x)\n try:\n return typedefs[T]\n except:\n return typedefs[(T,len(x.shape),x.typecode())]\n\n##################################################################\n# class ACCELERATE #\n##################################################################\nclass accelerate:\n \n def __init__(self, function, *args, **kw):\n assert type(function) == FunctionType\n self.function = function\n self.module = inspect.getmodule(function)\n if self.module == None:\n import __main__\n self.module = __main__\n self.__call_map = {}\n\n def __cache(self,*args):\n raise TypeError\n\n def __call__(self,*args):\n try:\n return self.__cache(*args)\n except TypeError:\n # Figure out type info -- Do as tuple so its hashable\n signature = tuple( map(lookup_type,args) )\n \n # If we know the function, call it\n try:\n fast = self.__call_map[signature]\n except:\n fast = self.singleton(signature)\n self.__cache = fast\n self.__call_map[signature] = fast\n return fast(*args)\n\n def signature(self,*args):\n # Figure out type info -- Do as tuple so its hashable\n signature = tuple( map(lookup_type,args) )\n return self.singleton(signature)\n\n\n def singleton(self,signature):\n identifier = self.identifier(signature)\n \n # Generate a new function, then call it\n f = self.function\n\n # See if we have an accelerated version of module\n try:\n accelerated_module = __import__(self.module.__name__+'_weave')\n fast = getattr(accelerated_module,identifier)\n return fast\n except:\n accelerated_module = None\n\n P = self.accelerate(signature,identifier)\n\n E = weave.ext_tools.ext_module(self.module.__name__+'_weave')\n E.add_function(P)\n E.generate_file()\n weave.build_tools.build_extension(self.module.__name__+'_weave.cpp',verbose=2)\n\n if accelerated_module:\n accelerated_module = reload(accelerated_module)\n else:\n accelerated_module = __import__(self.module.__name__+'_weave')\n\n fast = getattr(accelerated_module,identifier)\n return fast\n\n def identifier(self,signature):\n # Build an MD5 checksum\n f = self.function\n co = f.func_code\n identifier = str(signature)+\\\n str(co.co_argcount)+\\\n str(co.co_consts)+\\\n str(co.co_varnames)+\\\n co.co_code\n return 'F'+md5.md5(identifier).hexdigest()\n \n def accelerate(self,signature,identifier):\n P = Python2CXX(self.function,signature,name=identifier)\n return P\n\n def code(self,*args):\n if len(args) != self.function.func_code.co_argcount:\n raise TypeError,'%s() takes exactly %d arguments (%d given)'%(\n self.function.__name__,\n self.function.func_code.co_argcount,\n len(args))\n signature = tuple( map(lookup_type,args) )\n ident = self.function.__name__\n return self.accelerate(signature,ident).function_code()\n \n\n##################################################################\n# CLASS PYTHON2CXX #\n##################################################################\nclass Python2CXX(CXXCoder):\n def typedef_by_value(self,v):\n T = lookup_type(v)\n if T not in self.used:\n self.used.append(T)\n return T\n\n def function_by_signature(self,signature):\n descriptor = functiondefs[signature]\n if descriptor.return_type not in self.used:\n self.used.append(descriptor.return_type)\n return descriptor\n\n def __init__(self,f,signature,name=None):\n # Make sure function is a function\n import types\n assert type(f) == FunctionType\n # and check the input type signature\n assert reduce(lambda x,y: x and y,\n map(lambda x: isinstance(x,Type_Descriptor),\n signature),\n 1),'%s not all type objects'%signature\n self.arg_specs = []\n self.customize = weave.base_info.custom_info()\n\n CXXCoder.__init__(self,f,signature,name)\n\n return\n\n def function_code(self):\n code = self.wrapped_code()\n for T in self.used:\n if T != None and T.module_init_code:\n self.customize.add_module_init_code(T.module_init_code)\n return code\n\n def python_function_definition_code(self):\n return '{ \"%s\", wrapper_%s, METH_VARARGS, %s },\\n'%(\n self.name,\n self.name,\n CStr(self.function.__doc__))\n", + "source_code_before": "#**************************************************************************#\n#* FILE ************** accelerate_tools.py ************************#\n#**************************************************************************#\n#* Author: Patrick Miller February 9 2002 *#\n#**************************************************************************#\n\"\"\"\naccelerate_tools contains the interface for on-the-fly building of\nC++ equivalents to Python functions.\n\"\"\"\n#**************************************************************************#\n\nfrom types import FunctionType,IntType,FloatType,StringType,TypeType,XRangeType\nimport inspect\nimport md5\nimport weave\nfrom bytecodecompiler import CXXCoder,Type_Descriptor,Function_Descriptor\n\ndef CStr(s):\n \"Hacky way to get legal C string from Python string\"\n if s == None: return '\"\"'\n assert type(s) == StringType,\"Only None and string allowed\"\n r = repr('\"'+s) # Better for embedded quotes\n return '\"'+r[2:-1]+'\"'\n\nclass Basic(Type_Descriptor):\n def check(self,s):\n return \"%s(%s)\"%(self.checker,s)\n def inbound(self,s):\n return \"%s(%s)\"%(self.inbounder,s)\n def outbound(self,s):\n return \"%s(%s)\"%(self.outbounder,s)\n\nclass Basic_Number(Basic):\n def literalizer(self,s):\n return str(s)\n def binop(self,symbol,a,b):\n assert symbol in ['+','-','*','/'],symbol\n return '%s %s %s'%(a,symbol,b),self\n\nclass Integer(Basic_Number):\n cxxtype = \"long\"\n checker = \"PyInt_Check\"\n inbounder = \"PyInt_AsLong\"\n outbounder = \"PyInt_FromLong\"\n\nclass Double(Basic_Number):\n cxxtype = \"double\"\n checker = \"PyFloat_Check\"\n inbounder = \"PyFloat_AsDouble\"\n outbounder = \"PyFloat_FromDouble\"\n\nclass String(Basic):\n cxxtype = \"char*\"\n checker = \"PyString_Check\"\n inbounder = \"PyString_AsString\"\n outbounder = \"PyString_FromString\"\n\n def literalizer(self,s):\n return CStr(s)\n\nimport Numeric\n\nclass Vector(Type_Descriptor):\n cxxtype = 'PyArrayObject*'\n refcount = 1\n module_init_code = 'import_array'\n\n prerequisites = Type_Descriptor.prerequisites+\\\n ['#include \"Numeric/arrayobject.h\"']\n dims = 1\n def check(self,s):\n return \"PyArray_Check(%s) && ((PyArrayObject*)%s)->nd == %d && ((PyArrayObject*)%s)->descr->type_num == %s\"%(\n s,s,self.dims,s,self.typecode)\n def inbound(self,s):\n return \"(PyArrayObject*)(%s)\"%s\n def outbound(self,s):\n return \"(PyObject*)(%s)\"%s\n def binopMixed(self,symbol,a,b):\n return '*((%s*)(%s->data+%s*%s->strides[0]))'%(self.cxxbase,a,b,a),Integer\n\nclass IntegerVector(Vector):\n typecode = 'PyArray_INT'\n cxxbase = 'int'\n\nclass XRange(Type_Descriptor):\n cxxtype = 'XRange'\n prerequisites = ['''\n class XRange {\n public:\n XRange(long aLow, long aHigh, long aStep=1)\n : low(aLow),high(aHigh),step(aStep)\n {\n }\n long low;\n long high;\n long step;\n };''']\n\n# -----------------------------------------------\n# Singletonize the type names\n# -----------------------------------------------\nInteger = Integer()\nDouble = Double()\nString = String()\nIntegerVector = IntegerVector()\nXRange = XRange()\n\ntypedefs = {\n IntType: Integer,\n FloatType: Double,\n StringType: String,\n (Numeric.ArrayType,1,'l'): IntegerVector,\n XRangeType : XRange,\n }\n\nimport math\nfunctiondefs = {\n (range,(Integer,Integer)):\n Function_Descriptor(code='XRange(%s)',return_type=XRange),\n\n (math.sin,(Double,)):\n Function_Descriptor(code='sin(%s)',return_type=Double),\n }\n \n\n\n##################################################################\n# FUNCTION LOOKUP_TYPE #\n##################################################################\ndef lookup_type(x):\n T = type(x)\n try:\n return typedefs[T]\n except:\n return typedefs[(T,len(x.shape),x.typecode())]\n\n##################################################################\n# class ACCELERATE #\n##################################################################\nclass accelerate:\n \n def __init__(self, function, *args, **kw):\n assert type(function) == FunctionType\n self.function = function\n self.module = inspect.getmodule(function)\n if self.module == None:\n import __main__\n self.module = __main__\n self.__call_map = {}\n\n def __cache(self,*args):\n raise TypeError\n\n def __call__(self,*args):\n try:\n return self.__cache(*args)\n except TypeError:\n # Figure out type info -- Do as tuple so its hashable\n signature = tuple( map(lookup_type,args) )\n \n # If we know the function, call it\n try:\n fast = self.__call_map[signature]\n except:\n fast = self.singleton(signature)\n self.__cache = fast\n self.__call_map[signature] = fast\n return fast(*args)\n\n def signature(self,*args):\n # Figure out type info -- Do as tuple so its hashable\n signature = tuple( map(lookup_type,args) )\n return self.singleton(signature)\n\n\n def singleton(self,signature):\n identifier = self.identifier(signature)\n \n # Generate a new function, then call it\n f = self.function\n\n # See if we have an accelerated version of module\n try:\n accelerated_module = __import__(self.module.__name__+'_weave')\n fast = getattr(accelerated_module,identifier)\n return fast\n except:\n accelerated_module = None\n\n P = self.accelerate(signature,identifier)\n\n E = weave.ext_tools.ext_module(self.module.__name__+'_weave')\n E.add_function(P)\n E.generate_file()\n weave.build_tools.build_extension(self.module.__name__+'_weave.cpp',verbose=2)\n\n if accelerated_module:\n accelerated_module = reload(accelerated_module)\n else:\n accelerated_module = __import__(self.module.__name__+'_weave')\n\n fast = getattr(accelerated_module,identifier)\n return fast\n\n def identifier(self,signature):\n # Build an MD5 checksum\n f = self.function\n co = f.func_code\n identifier = str(signature)+\\\n str(co.co_consts)+\\\n str(co.co_varnames)+\\\n co.co_code\n return 'F'+md5.md5(identifier).hexdigest()\n \n def accelerate(self,signature,identifier):\n P = Python2CXX(self.function,signature,name=identifier)\n return P\n\n def code(self,*args):\n signature = tuple( map(lookup_type,args) )\n ident = self.function.__name__\n return self.accelerate(signature,ident).function_code()\n \n\n##################################################################\n# CLASS PYTHON2CXX #\n##################################################################\nclass Python2CXX(CXXCoder):\n def typedef_by_value(self,v):\n T = lookup_type(v)\n if T not in self.used:\n self.used.append(T)\n return T\n\n def function_by_signature(self,signature):\n descriptor = functiondefs[signature]\n if descriptor.return_type not in self.used:\n self.used.append(descriptor.return_type)\n return descriptor\n\n def __init__(self,f,signature,name=None):\n # Make sure function is a function\n import types\n assert type(f) == FunctionType\n # and check the input type signature\n assert reduce(lambda x,y: x and y,\n map(lambda x: isinstance(x,Type_Descriptor),\n signature),\n 1),'%s not all type objects'%signature\n self.arg_specs = []\n self.customize = weave.base_info.custom_info()\n\n CXXCoder.__init__(self,f,signature,name)\n\n return\n\n def function_code(self):\n code = self.wrapped_code()\n for T in self.used:\n if T != None and T.module_init_code:\n self.customize.add_module_init_code(T.module_init_code)\n return code\n\n def python_function_definition_code(self):\n return '{ \"%s\", wrapper_%s, METH_VARARGS, %s },\\n'%(\n self.name,\n self.name,\n CStr(self.function.__doc__))\n", + "methods": [ + { + "name": "CStr", + "long_name": "CStr( s )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "s" + ], + "start_line": 18, + "end_line": 23, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "check", + "long_name": "check( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 26, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "inbound", + "long_name": "inbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 28, + "end_line": 29, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "outbound", + "long_name": "outbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 30, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "literalizer", + "long_name": "literalizer( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "s" + ], + "start_line": 34, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "binop", + "long_name": "binop( self , symbol , a , b )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 37, + "parameters": [ + "self", + "symbol", + "a", + "b" + ], + "start_line": 36, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "literalizer", + "long_name": "literalizer( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "s" + ], + "start_line": 58, + "end_line": 59, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check", + "long_name": "check( self , s )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self", + "s" + ], + "start_line": 79, + "end_line": 81, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "inbound", + "long_name": "inbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "s" + ], + "start_line": 82, + "end_line": 83, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "outbound", + "long_name": "outbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "s" + ], + "start_line": 84, + "end_line": 85, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "getitem", + "long_name": "getitem( self , A , v , t )", + "filename": "accelerate_tools.py", + "nloc": 7, + "complexity": 2, + "token_count": 70, + "parameters": [ + "self", + "A", + "v", + "t" + ], + "start_line": 86, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "setitem", + "long_name": "setitem( self , A , v , t )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "A", + "v", + "t" + ], + "start_line": 94, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "lookup_type", + "long_name": "lookup_type( x )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 2, + "token_count": 40, + "parameters": [ + "x" + ], + "start_line": 185, + "end_line": 190, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , function , * args , ** kw )", + "filename": "accelerate_tools.py", + "nloc": 8, + "complexity": 2, + "token_count": 55, + "parameters": [ + "self", + "function", + "args", + "kw" + ], + "start_line": 197, + "end_line": 204, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__cache", + "long_name": "__cache( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "args" + ], + "start_line": 206, + "end_line": 207, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 12, + "complexity": 3, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 209, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "signature", + "long_name": "signature( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "args" + ], + "start_line": 225, + "end_line": 228, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "singleton", + "long_name": "singleton( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 20, + "complexity": 3, + "token_count": 137, + "parameters": [ + "self", + "signature" + ], + "start_line": 231, + "end_line": 258, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "identifier", + "long_name": "identifier( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 9, + "complexity": 1, + "token_count": 65, + "parameters": [ + "self", + "signature" + ], + "start_line": 260, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "accelerate", + "long_name": "accelerate( self , signature , identifier )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self", + "signature", + "identifier" + ], + "start_line": 271, + "end_line": 273, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "code", + "long_name": "code( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args" + ], + "start_line": 275, + "end_line": 283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "typedef_by_value", + "long_name": "typedef_by_value( self , v )", + "filename": "accelerate_tools.py", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "v" + ], + "start_line": 290, + "end_line": 294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "function_by_signature", + "long_name": "function_by_signature( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self", + "signature" + ], + "start_line": 296, + "end_line": 300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , f , signature , name = None )", + "filename": "accelerate_tools.py", + "nloc": 11, + "complexity": 2, + "token_count": 85, + "parameters": [ + "self", + "f", + "signature", + "name" + ], + "start_line": 302, + "end_line": 316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "function_code", + "long_name": "function_code( self )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 4, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 318, + "end_line": 323, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "python_function_definition_code", + "long_name": "python_function_definition_code( self )", + "filename": "accelerate_tools.py", + "nloc": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 325, + "end_line": 329, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "CStr", + "long_name": "CStr( s )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 2, + "token_count": 42, + "parameters": [ + "s" + ], + "start_line": 18, + "end_line": 23, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "check", + "long_name": "check( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 26, + "end_line": 27, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "inbound", + "long_name": "inbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 28, + "end_line": 29, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "outbound", + "long_name": "outbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "s" + ], + "start_line": 30, + "end_line": 31, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "literalizer", + "long_name": "literalizer( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "s" + ], + "start_line": 34, + "end_line": 35, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "binop", + "long_name": "binop( self , symbol , a , b )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 37, + "parameters": [ + "self", + "symbol", + "a", + "b" + ], + "start_line": 36, + "end_line": 38, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "literalizer", + "long_name": "literalizer( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "s" + ], + "start_line": 58, + "end_line": 59, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check", + "long_name": "check( self , s )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self", + "s" + ], + "start_line": 71, + "end_line": 73, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "inbound", + "long_name": "inbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "s" + ], + "start_line": 74, + "end_line": 75, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "outbound", + "long_name": "outbound( self , s )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "s" + ], + "start_line": 76, + "end_line": 77, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "binopMixed", + "long_name": "binopMixed( self , symbol , a , b )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "symbol", + "a", + "b" + ], + "start_line": 78, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "lookup_type", + "long_name": "lookup_type( x )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 2, + "token_count": 40, + "parameters": [ + "x" + ], + "start_line": 130, + "end_line": 135, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self , function , * args , ** kw )", + "filename": "accelerate_tools.py", + "nloc": 8, + "complexity": 2, + "token_count": 55, + "parameters": [ + "self", + "function", + "args", + "kw" + ], + "start_line": 142, + "end_line": 149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "__cache", + "long_name": "__cache( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "args" + ], + "start_line": 151, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__call__", + "long_name": "__call__( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 12, + "complexity": 3, + "token_count": 71, + "parameters": [ + "self", + "args" + ], + "start_line": 154, + "end_line": 168, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "signature", + "long_name": "signature( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "args" + ], + "start_line": 170, + "end_line": 173, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "singleton", + "long_name": "singleton( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 20, + "complexity": 3, + "token_count": 137, + "parameters": [ + "self", + "signature" + ], + "start_line": 176, + "end_line": 203, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "identifier", + "long_name": "identifier( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 8, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self", + "signature" + ], + "start_line": 205, + "end_line": 213, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "accelerate", + "long_name": "accelerate( self , signature , identifier )", + "filename": "accelerate_tools.py", + "nloc": 3, + "complexity": 1, + "token_count": 25, + "parameters": [ + "self", + "signature", + "identifier" + ], + "start_line": 215, + "end_line": 217, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "code", + "long_name": "code( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 4, + "complexity": 1, + "token_count": 39, + "parameters": [ + "self", + "args" + ], + "start_line": 219, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "typedef_by_value", + "long_name": "typedef_by_value( self , v )", + "filename": "accelerate_tools.py", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "v" + ], + "start_line": 229, + "end_line": 233, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "function_by_signature", + "long_name": "function_by_signature( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 5, + "complexity": 2, + "token_count": 35, + "parameters": [ + "self", + "signature" + ], + "start_line": 235, + "end_line": 239, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , f , signature , name = None )", + "filename": "accelerate_tools.py", + "nloc": 11, + "complexity": 2, + "token_count": 85, + "parameters": [ + "self", + "f", + "signature", + "name" + ], + "start_line": 241, + "end_line": 255, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "function_code", + "long_name": "function_code( self )", + "filename": "accelerate_tools.py", + "nloc": 6, + "complexity": 4, + "token_count": 40, + "parameters": [ + "self" + ], + "start_line": 257, + "end_line": 262, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "python_function_definition_code", + "long_name": "python_function_definition_code( self )", + "filename": "accelerate_tools.py", + "nloc": 5, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self" + ], + "start_line": 264, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "identifier", + "long_name": "identifier( self , signature )", + "filename": "accelerate_tools.py", + "nloc": 9, + "complexity": 1, + "token_count": 65, + "parameters": [ + "self", + "signature" + ], + "start_line": 260, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "getitem", + "long_name": "getitem( self , A , v , t )", + "filename": "accelerate_tools.py", + "nloc": 7, + "complexity": 2, + "token_count": 70, + "parameters": [ + "self", + "A", + "v", + "t" + ], + "start_line": 86, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "binopMixed", + "long_name": "binopMixed( self , symbol , a , b )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 27, + "parameters": [ + "self", + "symbol", + "a", + "b" + ], + "start_line": 78, + "end_line": 79, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "setitem", + "long_name": "setitem( self , A , v , t )", + "filename": "accelerate_tools.py", + "nloc": 2, + "complexity": 1, + "token_count": 22, + "parameters": [ + "self", + "A", + "v", + "t" + ], + "start_line": 94, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "code", + "long_name": "code( self , * args )", + "filename": "accelerate_tools.py", + "nloc": 9, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "args" + ], + "start_line": 275, + "end_line": 283, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + } + ], + "nloc": 246, + "complexity": 41, + "token_count": 1506, + "diff_parsed": { + "added": [ + "# -----------------------------------------------", + "# Singletonize the type names", + "# -----------------------------------------------", + "Integer = Integer()", + "Double = Double()", + "String = String()", + "", + " dims = 1", + " module_init_code = 'import_array();'", + " def getitem(self,A,v,t):", + " assert self.dims == len(v),'Expect dimension %d'%self.dims", + " code = '*((%s*)(%s->data'%(self.cxxbase,A)", + " for i in range(self.dims):", + " # assert that ''t[i]'' is an integer", + " code += '+%s*%s->strides[%d]'%(v[i],A,i)", + " code += '))'", + " return code,self.pybase", + " def setitem(self,A,v,t):", + " return self.getitem(A,v,t)", + "", + "class Matrix(Vector):", + " dims = 2", + " pybase = Integer", + "", + "class IntegerMatrix(Matrix):", + " typecode = 'PyArray_INT'", + " cxxbase = 'int'", + " pybase = Integer", + "", + "class LongVector(Vector):", + " typecode = 'PyArray_LONG'", + " cxxbase = 'long'", + " pybase = Integer", + "", + "class LongMatrix(Matrix):", + " typecode = 'PyArray_LONG'", + " cxxbase = 'long'", + " pybase = Integer", + "", + "class DoubleVector(Vector):", + " typecode = 'PyArray_DOUBLE'", + " cxxbase = 'double'", + " pybase = Double", + "", + "class DoubleMatrix(Matrix):", + " typecode = 'PyArray_DOUBLE'", + " cxxbase = 'double'", + " pybase = Double", + "IntegerMatrix = IntegerMatrix()", + "LongVector = LongVector()", + "LongMatrix = LongMatrix()", + "DoubleVector = DoubleVector()", + "DoubleMatrix = DoubleMatrix()", + " (Numeric.ArrayType,1,'i'): IntegerVector,", + " (Numeric.ArrayType,2,'i'): IntegerMatrix,", + " (Numeric.ArrayType,1,'l'): LongVector,", + " (Numeric.ArrayType,2,'l'): LongMatrix,", + " (Numeric.ArrayType,1,'d'): DoubleVector,", + " (Numeric.ArrayType,2,'d'): DoubleMatrix,", + "", + " (math.sqrt,(Double,)):", + " Function_Descriptor(code='sqrt(%s)',return_type=Double),", + " str(co.co_argcount)+\\", + " if len(args) != self.function.func_code.co_argcount:", + " raise TypeError,'%s() takes exactly %d arguments (%d given)'%(", + " self.function.__name__,", + " self.function.func_code.co_argcount,", + " len(args))" + ], + "deleted": [ + " module_init_code = 'import_array'", + " def binopMixed(self,symbol,a,b):", + " return '*((%s*)(%s->data+%s*%s->strides[0]))'%(self.cxxbase,a,b,a),Integer", + "Integer = Integer()", + "Double = Double()", + "String = String()", + " (Numeric.ArrayType,1,'l'): IntegerVector," + ] + } + }, + { + "old_path": "weave/bytecodecompiler.py", + "new_path": "weave/bytecodecompiler.py", + "filename": "bytecodecompiler.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -696,6 +696,7 @@ def __init__(self,function,signature,name=None):\n self.signature = signature\n self.codeobject = function.func_code\n self.__uid = 0 # Builds temps\n+ self.__indent = 1\n return\n \n ##################################################################\n@@ -721,7 +722,7 @@ def generate(self):\n # OK, crack open the function object and build\n # initial stack (not a real frame!)\n # -----------------------------------------------\n- arglen = len(self.signature)\n+ arglen = self.codeobject.co_argcount\n nlocals = self.codeobject.co_nlocals\n \n self.consts = self.codeobject.co_consts\n@@ -821,8 +822,10 @@ def wrapped_code(self):\n self.codeobject.co_varnames[i],i\n )\n \n- code += ' if ( !%s ) {\\n'% \\\n+ code += ' if ( !(%s) ) {\\n'% \\\n T.check('py_'+self.codeobject.co_varnames[i])\n+ #code += ' PyObject_Print(py_A,stdout,0); puts(\"\");\\n'\n+ #code += ' printf(\"nd=%d typecode=%d\\\\n\",((PyArrayObject*)py_A)->nd,((PyArrayObject*)py_A)->descr->type_num);\\n'\n code += ' PyErr_SetString(PyExc_TypeError,\"Bad type for arg %d (expected %s)\");\\n'%(\n i+1,\n T.__class__.__name__)\n@@ -865,11 +868,19 @@ def wrapped_code(self):\n code += '}\\n'\n return code\n \n+ def indent(self):\n+ self.__indent += 1\n+ return\n+\n+ def dedent(self):\n+ self.__indent -= 1\n+ return\n \n ##################################################################\n # MEMBER EMIT #\n ##################################################################\n def emit(self,s):\n+ self.__body += ' '*(3*self.__indent)\n self.__body += s\n self.__body += '\\n'\n return\n@@ -882,17 +893,46 @@ def push(self,v,t):\n self.types.append(t)\n return\n \n-\n ##################################################################\n # MEMBER POP #\n ##################################################################\n def pop(self):\n v = self.stack[-1]\n+ assert type(v) != TupleType\n del self.stack[-1]\n t = self.types[-1]\n+ assert type(t) != TupleType\n del self.types[-1]\n return v,t\n \n+ ##################################################################\n+ # MEMBER PUSHTUPLE #\n+ ##################################################################\n+ def pushTuple(self,V,T):\n+ assert type(V) == TupleType\n+ self.stack.append(V)\n+ assert type(V) == TupleType\n+ self.types.append(T)\n+ return\n+\n+\n+ ##################################################################\n+ # MEMBER POPTUPLE #\n+ ##################################################################\n+ def popTuple(self):\n+ v = self.stack[-1]\n+ assert type(v) == TupleType\n+ del self.stack[-1]\n+ t = self.types[-1]\n+ assert type(t) == TupleType\n+ del self.types[-1]\n+ return v,t\n+ ##################################################################\n+ # MEMBER MULTIARG #\n+ ##################################################################\n+ def multiarg(self):\n+ return type(self.stack[-1]) == TupleType\n+ \n ##################################################################\n # MEMBER UNIQUE #\n ##################################################################\n@@ -943,18 +983,11 @@ def global_info(self,var_num):\n raise ValueError,'Cannot locate module owning %s'%varname\n return module_name,var_name\n \n+\n ##################################################################\n- # MEMBER BINOP #\n+ # MEMBER CODEUP #\n ##################################################################\n- def binop(self,pc,symbol):\n- v2,t2 = self.pop()\n- v1,t1 = self.pop()\n-\n- if t1 == t2:\n- rhs,rhs_type = t1.binop(symbol,v1,v2)\n- else:\n- rhs,rhs_type = t1.binopMixed(symbol,v1,v2)\n- \n+ def codeup(self, rhs, rhs_type):\n lhs = self.unique()\n self.emit('%s %s = %s;\\n'%(\n rhs_type.cxxtype,\n@@ -963,6 +996,22 @@ def binop(self,pc,symbol):\n print self.__body\n self.push(lhs,rhs_type)\n return \n+ \n+\n+ ##################################################################\n+ # MEMBER BINOP #\n+ ##################################################################\n+ def binop(self,pc,symbol):\n+ v2,t2 = self.pop()\n+ v1,t1 = self.pop()\n+\n+ if t1 == t2:\n+ rhs,rhs_type = t1.binop(symbol,v1,v2)\n+ else:\n+ rhs,rhs_type = t1.binopMixed(symbol,v1,v2,t2)\n+\n+ self.codeup(rhs,rhs_type)\n+ return\n \n ##################################################################\n # MEMBER BINARY_XXX #\n@@ -972,13 +1021,39 @@ def BINARY_ADD(self,pc):\n def BINARY_SUBTRACT(self,pc):\n return self.binop(pc,'-')\n def BINARY_MULTIPLY(self,pc):\n+ print 'MULTIPLY',self.stack[-2],self.types[-2],'*',self.stack[-1],self.types[-1]\n return self.binop(pc,'*')\n def BINARY_DIVIDE(self,pc):\n return self.binop(pc,'/')\n def BINARY_MODULO(self,pc):\n return self.binop(pc,'%')\n def BINARY_SUBSCR(self,pc):\n- return self.binop(pc,'[]')\n+ if self.multiarg():\n+ v2,t2 = self.popTuple()\n+ else:\n+ v2,t2 = self.pop()\n+ v2 = (v2,)\n+ t2 = (t2,)\n+ v1,t1 = self.pop()\n+ rhs,rhs_type = t1.getitem(v1,v2,t2)\n+ self.codeup(rhs,rhs_type)\n+ return\n+\n+ def STORE_SUBSCR(self,pc):\n+ if self.multiarg():\n+ v2,t2 = self.popTuple()\n+ else:\n+ v2,t2 = self.pop()\n+ v2 = (v2,)\n+ t2 = (t2,)\n+ v1,t1 = self.pop()\n+ v0,t0 = self.pop()\n+ \n+ rhs,rhs_type = t1.setitem(v1,v2,t2)\n+ assert rhs_type == t0,\"Store the right thing\"\n+ self.emit('%s = %s;'%(rhs,v0))\n+ return\n+\n def COMPARE_OP(self,pc,opname):\n symbol = self.cmp_op(opname) # convert numeric to name\n return self.binop(pc,symbol)\n@@ -1047,6 +1122,22 @@ def LOAD_CONST(self,pc,consti):\n return\n \n \n+ ##################################################################\n+ # MEMBER BUILD_TUPLE #\n+ ##################################################################\n+ def BUILD_TUPLE(self,pc,count):\n+ \"Creates a tuple consuming count items from the stack, and pushes the resulting tuple onto the stack.\"\n+ V = []\n+ T = []\n+ for i in range(count):\n+ v,t = self.pop()\n+ V.append(v)\n+ T.append(t)\n+ V.reverse()\n+ T.reverse()\n+ self.pushTuple(tuple(V),tuple(T))\n+ return\n+\n ##################################################################\n # MEMBER LOAD_FAST #\n ##################################################################\n@@ -1054,8 +1145,12 @@ def LOAD_FAST(self,pc,var_num):\n v = self.stack[var_num]\n t = self.types[var_num]\n print 'LOADFAST',var_num,v,t\n- if t.refcount:\n- self.emit('Py_XINCREF(%s);'%v)\n+ for VV,TT in map(None, self.stack, self.types):\n+ print VV,':',TT\n+ if t == None:\n+ raise TypeError,'%s used before set?'%v\n+ print self.__body\n+ print 'PC',pc\n self.push(v,t)\n return\n \n", + "added_lines": 111, + "deleted_lines": 16, + "source_code": "#**************************************************************************#\n#* FILE ************** bytecodecompiler.py ************************#\n#************************************************************************ **#\n#* Author: Patrick Miller February 9 2002 *#\n#* Copyright (C) 2002 Patrick J. Miller *#\n#**************************************************************************#\n#* *#\n#**************************************************************************#\nfrom types import *\nimport string\nimport inspect\n\n##################################################################\n# CLASS __DESCRIPTOR #\n##################################################################\nclass __Descriptor:\n prerequisites = []\n refcount = 0\n def __repr__(self):\n return self.__module__+'.'+self.__class__.__name__\n\n##################################################################\n# CLASS TYPE_DESCRIPTOR #\n##################################################################\nclass Type_Descriptor(__Descriptor):\n module_init_code = ''\n\n##################################################################\n# CLASS FUNCTION_DESCRIPTOR #\n##################################################################\nclass Function_Descriptor(__Descriptor):\n def __init__(self,code,return_type,support=''):\n\tself.code\t= code\n\tself.return_type\t= return_type\n self.support = support\n\treturn\n\n \n \n\nhaveArgument = 90 # Opcodes greater-equal to this have argument\nbyName = {\n 'STOP_CODE': 0,\n 'POP_TOP': 1,\n 'ROT_TWO': 2,\n 'ROT_THREE': 3,\n 'DUP_TOP': 4,\n 'ROT_FOUR': 5,\n 'UNARY_POSITIVE': 10,\n 'UNARY_NEGATIVE': 11,\n 'UNARY_NOT': 12,\n 'UNARY_CONVERT': 13,\n 'UNARY_INVERT': 15,\n 'BINARY_POWER': 19,\n 'BINARY_MULTIPLY': 20,\n 'BINARY_DIVIDE': 21,\n 'BINARY_MODULO': 22,\n 'BINARY_ADD': 23,\n 'BINARY_SUBTRACT': 24,\n 'BINARY_SUBSCR': 25,\n 'BINARY_FLOOR_DIVIDE': 26,\n 'BINARY_TRUE_DIVIDE': 27,\n 'INPLACE_FLOOR_DIVIDE': 28,\n 'INPLACE_TRUE_DIVIDE': 29,\n 'SLICE': 30,\n 'STORE_SLICE': 40,\n 'DELETE_SLICE': 50,\n 'INPLACE_ADD': 55,\n 'INPLACE_SUBTRACT': 56,\n 'INPLACE_MULTIPLY': 57,\n 'INPLACE_DIVIDE': 58,\n 'INPLACE_MODULO': 59,\n 'STORE_SUBSCR': 60,\n 'DELETE_SUBSCR': 61,\n 'BINARY_LSHIFT': 62,\n 'BINARY_RSHIFT': 63,\n 'BINARY_AND': 64,\n 'BINARY_XOR': 65,\n 'BINARY_OR': 66,\n 'INPLACE_POWER': 67,\n 'GET_ITER': 68,\n 'PRINT_EXPR': 70,\n 'PRINT_ITEM': 71,\n 'PRINT_NEWLINE': 72,\n 'PRINT_ITEM_TO': 73,\n 'PRINT_NEWLINE_TO': 74,\n 'INPLACE_LSHIFT': 75,\n 'INPLACE_RSHIFT': 76,\n 'INPLACE_AND': 77,\n 'INPLACE_XOR': 78,\n 'INPLACE_OR': 79,\n 'BREAK_LOOP': 80,\n 'LOAD_LOCALS': 82,\n 'RETURN_VALUE': 83,\n 'IMPORT_STAR': 84,\n 'EXEC_STMT': 85,\n 'YIELD_VALUE': 86,\n 'POP_BLOCK': 87,\n 'END_FINALLY': 88,\n 'BUILD_CLASS': 89,\n 'STORE_NAME': 90,\n 'DELETE_NAME': 91,\n 'UNPACK_SEQUENCE': 92,\n 'FOR_ITER': 93,\n 'STORE_ATTR': 95,\n 'DELETE_ATTR': 96,\n 'STORE_GLOBAL': 97,\n 'DELETE_GLOBAL': 98,\n 'DUP_TOPX': 99,\n 'LOAD_CONST': 100,\n 'LOAD_NAME': 101,\n 'BUILD_TUPLE': 102,\n 'BUILD_LIST': 103,\n 'BUILD_MAP': 104,\n 'LOAD_ATTR': 105,\n 'COMPARE_OP': 106,\n 'IMPORT_NAME': 107,\n 'IMPORT_FROM': 108,\n 'JUMP_FORWARD': 110,\n 'JUMP_IF_FALSE': 111,\n 'JUMP_IF_TRUE': 112,\n 'JUMP_ABSOLUTE': 113,\n 'FOR_LOOP': 114,\n 'LOAD_GLOBAL': 116,\n 'CONTINUE_LOOP': 119,\n 'SETUP_LOOP': 120,\n 'SETUP_EXCEPT': 121,\n 'SETUP_FINALLY': 122,\n 'LOAD_FAST': 124,\n 'STORE_FAST': 125,\n 'DELETE_FAST': 126,\n 'SET_LINENO': 127,\n 'RAISE_VARARGS': 130,\n 'CALL_FUNCTION': 131,\n 'MAKE_FUNCTION': 132,\n 'BUILD_SLICE': 133,\n 'MAKE_CLOSURE': 134,\n 'LOAD_CLOSURE': 135,\n 'LOAD_DEREF': 136,\n 'STORE_DEREF': 137,\n 'CALL_FUNCTION_VAR': 140,\n 'CALL_FUNCTION_KW': 141,\n 'CALL_FUNCTION_VAR_KW': 142,\n }\n\n# -----------------------------------------------\n# Build one in the reverse sense\n# -----------------------------------------------\nbyOpcode = {}\nfor name,op in map(None, byName.keys(), byName.values()):\n byOpcode[op] = name\n del name\n del op\n \n\n##################################################################\n# FUNCTION OPCODIZE #\n##################################################################\ndef opcodize(s):\n \"Slightly more readable form\"\n length = len(s)\n i = 0\n answer = []\n while i < length:\n bytecode = ord(s[i])\n name = byOpcode[bytecode]\n if bytecode >= haveArgument:\n argument = 256*ord(s[i+2])+ord(s[i+1])\n i += 3\n else:\n argument = None\n i += 1\n answer.append((bytecode,argument,name))\n return answer\n\n\n\n##################################################################\n# FUNCTION LIST #\n##################################################################\ndef listing(f):\n \"Pretty print the internals of your function\"\n assert type(f) == FunctionType,\"Arg %r must be a function\"%f\n filename = f.func_code.co_filename\n try:\n lines = open(filename).readlines()\n except:\n lines = None\n pc = 0\n s = ''\n lastLine = None\n for op,arg,name in opcodize(f.func_code.co_code):\n if lines and name == 'SET_LINENO':\n source = lines[arg-1][:-1]\n while lastLine and lastLine < arg-1:\n nonEmittingSource = lines[lastLine][:-1]\n lastLine += 1\n s += '%3s %20s %5s : %s\\n'%(\n '','','',nonEmittingSource)\n lastLine = arg\n else:\n source = ''\n if arg == None: arg = ''\n s += '%3d] %20s %5s : %s\\n'%(pc,name,arg,source)\n if op >= haveArgument:\n pc += 3\n else:\n pc += 1\n return s\n\n##################################################################\n# CLASS BYTECODEMEANING #\n##################################################################\nclass ByteCodeMeaning:\n def fetch(self, pc,code):\n opcode = ord(code[pc])\n if opcode >= haveArgument:\n argument = 256*ord(code[pc+2])+ord(code[pc+1])\n next = pc+3\n else:\n argument = None\n next = pc+1\n return next,opcode,argument\n \n def execute(self,pc,opcode,argument):\n name = byOpcode[opcode]\n method = getattr(self,name)\n if argument == None:\n return apply(method,(pc,))\n else:\n return apply(method,(pc,argument,))\n\n def evaluate(self, pc,code):\n next, opcode,argument = self.fetch(pc,code)\n goto = self.execute(next,opcode,argument)\n if goto == -1:\n return None # Must be done\n elif goto == None:\n return next # Normal\n else:\n raise 'xx'\n\n symbols = { 0: 'less', 1: 'lesseq', 2: 'equal', 3: 'notequal',\n 4: 'greater', 5: 'greatereq', 6: 'in', 7: 'not in',\n 8: 'is', 9: 'is not', 10: 'exe match',\n 11 : 'bad',\n }\n def cmp_op(self,opname):\n return self.symbols[opname]\n \n def STOP_CODE(self,pc):\n \"Indicates end-of-code to the compiler, not used by the interpreter.\"\n raise NotImplementedError\n def POP_TOP(self,pc):\n \"Removes the top-of-stack (TOS) item.\"\n raise NotImplementedError\n\n def ROT_TWO(self,pc):\n \"Swaps the two top-most stack items.\"\n raise NotImplementedError\n\n def ROT_THREE(self,pc):\n \"Lifts second and third stack item one position up, moves top down to position three.\"\n raise NotImplementedError\n\n def ROT_FOUR(self,pc):\n \"Lifts second, third and forth stack item one position up, moves top down to position four.\"\n raise NotImplementedError\n\n def DUP_TOP(self,pc):\n \"Duplicates the reference on top of the stack.\"\n raise NotImplementedError\n\n # Unary Operations take the top of the stack, apply the operation, and push the result back on the stack.\n\n def UNARY_POSITIVE(self,pc):\n \"Implements TOS = +TOS.\"\n raise NotImplementedError\n\n def UNARY_NEGATIVE(self,pc):\n \"Implements TOS = -TOS.\"\n raise NotImplementedError\n\n def UNARY_NOT(self,pc):\n \"Implements TOS = not TOS.\"\n raise NotImplementedError\n\n def UNARY_CONVERT(self,pc):\n \"Implements TOS = `TOS`.\"\n raise NotImplementedError\n\n def UNARY_INVERT(self,pc):\n \"Implements TOS = ~TOS.\"\n raise NotImplementedError\n\n #Binary operations remove the top of the stack (TOS) and the second top-most stack item (TOS1) from the stack. They perform the operation, and put the result back on the stack.\n\n def BINARY_POWER(self,pc):\n \"Implements TOS = TOS1 ** TOS.\"\n raise NotImplementedError\n\n def BINARY_MULTIPLY(self,pc):\n \"Implements TOS = TOS1 * TOS.\"\n raise NotImplementedError\n\n def BINARY_DIVIDE(self,pc):\n \"Implements TOS = TOS1 / TOS.\"\n raise NotImplementedError\n\n def BINARY_MODULO(self,pc):\n \"Implements TOS = TOS1 % TOS.\"\n raise NotImplementedError\n\n def BINARY_ADD(self,pc):\n \"Implements TOS = TOS1 + TOS.\"\n raise NotImplementedError\n\n def BINARY_SUBTRACT(self,pc):\n \"Implements TOS = TOS1 - TOS.\"\n raise NotImplementedError\n\n def BINARY_SUBSCR(self,pc):\n \"Implements TOS = TOS1[TOS].\"\n raise NotImplementedError\n\n def BINARY_LSHIFT(self,pc):\n \"Implements TOS = TOS1 << TOS.\"\n raise NotImplementedError\n\n def BINARY_RSHIFT(self,pc):\n \"Implements TOS = TOS1 >> TOS.\"\n raise NotImplementedError\n\n def BINARY_AND(self,pc):\n \"Implements TOS = TOS1 & TOS.\"\n raise NotImplementedError\n\n def BINARY_XOR(self,pc):\n \"Implements TOS = TOS1 ^ TOS.\"\n raise NotImplementedError\n\n def BINARY_OR(self,pc):\n \"Implements TOS = TOS1 | TOS.\"\n raise NotImplementedError\n\n #In-place operations are like binary operations, in that they remove TOS and TOS1, and push the result back on the stack, but the operation is done in-place when TOS1 supports it, and the resulting TOS may be (but does not have to be) the original TOS1.\n\n def INPLACE_POWER(self,pc):\n \"Implements in-place TOS = TOS1 ** TOS.\"\n raise NotImplementedError\n\n def INPLACE_MULTIPLY(self,pc):\n \"Implements in-place TOS = TOS1 * TOS.\"\n raise NotImplementedError\n\n def INPLACE_DIVIDE(self,pc):\n \"Implements in-place TOS = TOS1 / TOS.\"\n raise NotImplementedError\n\n def INPLACE_MODULO(self,pc):\n \"Implements in-place TOS = TOS1 % TOS.\"\n raise NotImplementedError\n\n def INPLACE_ADD(self,pc):\n \"Implements in-place TOS = TOS1 + TOS.\"\n raise NotImplementedError\n\n def INPLACE_SUBTRACT(self,pc):\n \"Implements in-place TOS = TOS1 - TOS.\"\n raise NotImplementedError\n\n def INPLACE_LSHIFT(self,pc):\n \"Implements in-place TOS = TOS1 << TOS.\"\n raise NotImplementedError\n\n def INPLACE_RSHIFT(self,pc):\n \"Implements in-place TOS = TOS1 >> TOS.\"\n raise NotImplementedError\n\n def INPLACE_AND(self,pc):\n \"Implements in-place TOS = TOS1 & TOS.\"\n raise NotImplementedError\n\n def INPLACE_XOR(self,pc):\n \"Implements in-place TOS = TOS1 ^ TOS.\"\n raise NotImplementedError\n\n def INPLACE_OR(self,pc):\n \"Implements in-place TOS = TOS1 | TOS.\"\n raise NotImplementedError\n\n #The slice opcodes take up to three parameters.\n\n def SLICE_0(self,pc):\n \"Implements TOS = TOS[:].\"\n raise NotImplementedError\n\n def SLICE_1(self,pc):\n \"Implements TOS = TOS1[TOS:].\"\n raise NotImplementedError\n\n def SLICE_2(self,pc):\n \"Implements TOS = TOS1[:TOS1].\"\n raise NotImplementedError\n\n def SLICE_3(self,pc):\n \"Implements TOS = TOS2[TOS1:TOS].\"\n raise NotImplementedError\n\n #Slice assignment needs even an additional parameter. As any statement, they put nothing on the stack.\n\n def STORE_SLICE_0(self,pc):\n \"Implements TOS[:] = TOS1.\"\n raise NotImplementedError\n\n def STORE_SLICE_1(self,pc):\n \"Implements TOS1[TOS:] = TOS2.\"\n raise NotImplementedError\n\n def STORE_SLICE_2(self,pc):\n \"Implements TOS1[:TOS] = TOS2.\"\n raise NotImplementedError\n\n def STORE_SLICE_3(self,pc):\n \"Implements TOS2[TOS1:TOS] = TOS3.\"\n raise NotImplementedError\n\n def DELETE_SLICE_0(self,pc):\n \"Implements del TOS[:].\"\n raise NotImplementedError\n\n def DELETE_SLICE_1(self,pc):\n \"Implements del TOS1[TOS:].\"\n raise NotImplementedError\n\n def DELETE_SLICE_2(self,pc):\n \"Implements del TOS1[:TOS].\"\n raise NotImplementedError\n\n def DELETE_SLICE_3(self,pc):\n \"Implements del TOS2[TOS1:TOS].\"\n raise NotImplementedError\n\n def STORE_SUBSCR(self,pc):\n \"Implements TOS1[TOS] = TOS2.\"\n raise NotImplementedError\n\n def DELETE_SUBSCR(self,pc):\n \"Implements del TOS1[TOS].\"\n raise NotImplementedError\n\n def PRINT_EXPR(self,pc):\n \"Implements the expression statement for the interactive mode. TOS is removed from the stack and printed. In non-interactive mode, an expression statement is terminated with POP_STACK.\"\n raise NotImplementedError\n\n def PRINT_ITEM(self,pc):\n \"Prints TOS to the file-like object bound to sys.stdout. There is one such instruction for each item in the print statement.\"\n raise NotImplementedError\n\n def PRINT_ITEM_TO(self,pc):\n \"Like PRINT_ITEM, but prints the item second from TOS to the file-like object at TOS. This is used by the extended print statement.\"\n raise NotImplementedError\n\n def PRINT_NEWLINE(self,pc):\n \"Prints a new line on sys.stdout. This is generated as the last operation of a print statement, unless the statement ends with a comma.\"\n raise NotImplementedError\n\n def PRINT_NEWLINE_TO(self,pc):\n \"Like PRINT_NEWLINE, but prints the new line on the file-like object on the TOS. This is used by the extended print statement.\"\n raise NotImplementedError\n\n def BREAK_LOOP(self,pc):\n \"Terminates a loop due to a break statement.\"\n raise NotImplementedError\n\n def LOAD_LOCALS(self,pc):\n \"Pushes a reference to the locals of the current scope on the stack. This is used in the code for a class definition: After the class body is evaluated, the locals are passed to the class definition.\"\n raise NotImplementedError\n\n def RETURN_VALUE(self,pc):\n \"Returns with TOS to the caller of the function.\"\n raise NotImplementedError\n\n def IMPORT_STAR(self,pc):\n \"Loads all symbols not starting with _ directly from the module TOS to the local namespace. The module is popped after loading all names. This opcode implements from module import *.\"\n raise NotImplementedError\n\n def EXEC_STMT(self,pc):\n \"Implements exec TOS2,TOS1,TOS. The compiler fills missing optional parameters with None.\"\n raise NotImplementedError\n\n def POP_BLOCK(self,pc):\n \"Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.\"\n raise NotImplementedError\n\n def END_FINALLY(self,pc):\n \"Terminates a finally clause. The interpreter recalls whether the exception has to be re-raised, or whether the function returns, and continues with the outer-next block.\"\n raise NotImplementedError\n\n def BUILD_CLASS(self,pc):\n \"Creates a new class object. TOS is the methods dictionary, TOS1 the tuple of the names of the base classes, and TOS2 the class name.\"\n raise NotImplementedError\n\n #All of the following opcodes expect arguments. An argument is two bytes, with the more significant byte last.\n\n def STORE_NAME(self,pc,namei):\n \"Implements name = TOS. namei is the index of name in the attribute co_names of the code object. The compiler tries to use STORE_LOCAL or STORE_GLOBAL if possible.\"\n raise NotImplementedError\n\n def DELETE_NAME(self,pc,namei):\n \"Implements del name, where namei is the index into co_names attribute of the code object.\"\n raise NotImplementedError\n\n def UNPACK_SEQUENCE(self,pc,count):\n \"Unpacks TOS into count individual values, which are put onto the stack right-to-left.\"\n raise NotImplementedError\n\n def DUP_TOPX(self,pc,count):\n \"Duplicate count items, keeping them in the same order. Due to implementation limits, count should be between 1 and 5 inclusive.\"\n raise NotImplementedError\n\n def STORE_ATTR(self,pc,namei):\n \"Implements TOS.name = TOS1, where namei is the index of name in co_names.\"\n raise NotImplementedError\n\n def DELETE_ATTR(self,pc,namei):\n \"Implements del TOS.name, using namei as index into co_names.\"\n raise NotImplementedError\n\n def STORE_GLOBAL(self,pc,namei):\n \"Works as STORE_NAME, but stores the name as a global.\"\n raise NotImplementedError\n\n def DELETE_GLOBAL(self,pc,namei):\n \"Works as DELETE_NAME, but deletes a global name.\"\n raise NotImplementedError\n\n def LOAD_CONST(self,pc,consti):\n \"Pushes co_consts[consti] onto the stack.\"\n raise NotImplementedError\n\n def LOAD_NAME(self,pc,namei):\n \"Pushes the value associated with co_names[namei] onto the stack.\"\n raise NotImplementedError\n\n def BUILD_TUPLE(self,pc,count):\n \"Creates a tuple consuming count items from the stack, and pushes the resulting tuple onto the stack.\"\n raise NotImplementedError\n\n def BUILD_LIST(self,pc,count):\n \"Works as BUILD_TUPLE, but creates a list.\"\n raise NotImplementedError\n\n def BUILD_MAP(self,pc,zero):\n \"Pushes a new empty dictionary object onto the stack. The argument is ignored and set to zero by the compiler.\"\n raise NotImplementedError\n\n def LOAD_ATTR(self,pc,namei):\n \"Replaces TOS with getattr(TOS, co_names[namei].\"\n raise NotImplementedError\n\n def COMPARE_OP(self,pc,opname):\n \"Performs a Boolean operation. The operation name can be found in cmp_op[opname].\"\n raise NotImplementedError\n\n def IMPORT_NAME(self,pc,namei):\n \"Imports the module co_names[namei]. The module object is pushed onto the stack. The current namespace is not affected: for a proper import statement, a subsequent STORE_FAST instruction modifies the namespace.\"\n raise NotImplementedError\n\n def IMPORT_FROM(self,pc,namei):\n \"Loads the attribute co_names[namei] from the module found in TOS. The resulting object is pushed onto the stack, to be subsequently stored by a STORE_FAST instruction.\"\n raise NotImplementedError\n\n def JUMP_FORWARD(self,pc,delta):\n \"Increments byte code counter by delta.\"\n raise NotImplementedError\n\n def JUMP_IF_TRUE(self,pc,delta):\n \"If TOS is true, increment the byte code counter by delta. TOS is left on the stack.\"\n raise NotImplementedError\n\n def JUMP_IF_FALSE(self,pc,delta):\n \"If TOS is false, increment the byte code counter by delta. TOS is not changed.\"\n raise NotImplementedError\n\n def JUMP_ABSOLUTE(self,pc,target):\n \"Set byte code counter to target.\"\n raise NotImplementedError\n\n def FOR_LOOP(self,pc,delta):\n \"Iterate over a sequence. TOS is the current index, TOS1 the sequence. First, the next element is computed. If the sequence is exhausted, increment byte code counter by delta. Otherwise, push the sequence, the incremented counter, and the current item onto the stack.\"\n raise NotImplementedError\n\n def LOAD_GLOBAL(self,pc,namei):\n \"Loads the global named co_names[namei] onto the stack.\"\n raise NotImplementedError\n\n def SETUP_LOOP(self,pc,delta):\n \"Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.\"\n raise NotImplementedError\n\n def SETUP_EXCEPT(self,pc,delta):\n \"Pushes a try block from a try-except clause onto the block stack. delta points to the first except block.\"\n raise NotImplementedError\n\n def SETUP_FINALLY(self,pc,delta):\n \"Pushes a try block from a try-except clause onto the block stack. delta points to the finally block.\"\n raise NotImplementedError\n\n def LOAD_FAST(self,pc,var_num):\n \"Pushes a reference to the local co_varnames[var_num] onto the stack.\"\n raise NotImplementedError\n\n def STORE_FAST(self,pc,var_num):\n \"Stores TOS into the local co_varnames[var_num].\"\n raise NotImplementedError\n\n def DELETE_FAST(self,pc,var_num):\n \"Deletes local co_varnames[var_num].\"\n raise NotImplementedError\n\n def LOAD_CLOSURE(self,pc,i):\n \"Pushes a reference to the cell contained in slot i of the cell and free variable storage. The name of the variable is co_cellvars[i] if i is less than the length of co_cellvars. Otherwise it is co_freevars[i - len(co_cellvars)].\"\n raise NotImplementedError\n\n def LOAD_DEREF(self,pc,i):\n \"Loads the cell contained in slot i of the cell and free variable storage. Pushes a reference to the object the cell contains on the stack.\"\n raise NotImplementedError\n\n def STORE_DEREF(self,pc,i):\n \"Stores TOS into the cell contained in slot i of the cell and free variable storage.\"\n raise NotImplementedError\n\n def SET_LINENO(self,pc,lineno):\n \"Sets the current line number to lineno.\"\n raise NotImplementedError\n\n def RAISE_VARARGS(self,pc,argc):\n \"Raises an exception. argc indicates the number of parameters to the raise statement, ranging from 0 to 3. The handler will find the traceback as TOS2, the parameter as TOS1, and the exception as TOS.\"\n raise NotImplementedError\n\n def CALL_FUNCTION(self,pc,argc):\n \"Calls a function. The low byte of argc indicates the number of positional parameters, the high byte the number of keyword parameters. On the stack, the opcode finds the keyword parameters first. For each keyword argument, the value is on top of the key. Below the keyword parameters, the positional parameters are on the stack, with the right-most parameter on top. Below the parameters, the function object to call is on the stack.\"\n raise NotImplementedError\n\n def MAKE_FUNCTION(self,pc,argc):\n \"Pushes a new function object on the stack. TOS is the code associated with the function. The function object is defined to have argc default parameters, which are found below TOS.\"\n raise NotImplementedError\n\n def MAKE_CLOSURE(self,pc,argc):\n \"Creates a new function object, sets its func_closure slot, and pushes it on the stack. TOS is the code associated with the function. If the code object has N free variables, the next N items on the stack are the cells for these variables. The function also has argc default parameters, where are found before the cells.\"\n raise NotImplementedError\n\n def BUILD_SLICE(self,pc,argc):\n \"Pushes a slice object on the stack. argc must be 2 or 3. If it is 2, slice(TOS1, TOS) is pushed; if it is 3, slice(TOS2, TOS1, TOS) is pushed. See the slice() built-in function for more information.\"\n raise NotImplementedError\n\n def EXTENDED_ARG(self,pc,ext):\n \"Prefixes any opcode which has an argument too big to fit into the default two bytes. ext holds two additional bytes which, taken together with the subsequent opcode's argument, comprise a four-byte argument, ext being the two most-significant bytes.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_VAR(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the variable argument list, followed by keyword and positional arguments.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_KW(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by explicit keyword and positional arguments.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_VAR_KW(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by the variable-arguments tuple, followed by explicit keyword and positional arguments.\"\n raise NotImplementedError\n\n \n\n##################################################################\n# CLASS CXXCODER #\n##################################################################\nclass CXXCoder(ByteCodeMeaning):\n\n ##################################################################\n # MEMBER TYPEDEF_BY_VALUE #\n ##################################################################\n def typedef_by_value(self,v):\n raise NotImplementedError # VIRTUAL\n \n ##################################################################\n # MEMBER __INIT__ #\n ##################################################################\n def __init__(self,function,signature,name=None):\n assert type(function) == FunctionType,\"Arg must be a user function\"\n assert not function.func_defaults ,\"Function cannot have default args (yet)\"\n if name == None: name = function.func_name\n self.name = name\n self.function = function\n self.signature = signature\n self.codeobject = function.func_code\n self.__uid = 0 # Builds temps\n self.__indent = 1\n return\n\n ##################################################################\n # MEMBER EVALUATE #\n ##################################################################\n def evaluate(self, pc,code):\n # See if we posted any forwards for this offset\n if self.forwards.has_key(pc):\n for f in self.forwards[pc]:\n f()\n self.forwards[pc] = []\n return ByteCodeMeaning.evaluate(self,pc,code)\n \n ##################################################################\n # MEMBER GENERATE #\n ##################################################################\n def generate(self):\n self.forwards = {} # Actions on forward interprets\n self.__body = '' # Body will be built\n self.helpers = [] # headers and stuff\n\n # -----------------------------------------------\n # OK, crack open the function object and build\n # initial stack (not a real frame!)\n # -----------------------------------------------\n arglen = self.codeobject.co_argcount\n nlocals = self.codeobject.co_nlocals\n\n self.consts = self.codeobject.co_consts\n self.stack = list(self.codeobject.co_varnames)\n self.types = list(self.signature)+[None]*(nlocals-arglen)\n self.used = []\n for T in self.types:\n if T not in self.used: self.used.append(T)\n\n # -----------------------------------------------\n # One pass through the byte codes to generate\n # the body\n # -----------------------------------------------\n code = self.codeobject.co_code\n bytes = len(code)\n pc = 0\n while pc != None and pc < bytes:\n pc = self.evaluate(pc,code)\n\n # -----------------------------------------------\n # Return?\n # -----------------------------------------------\n if self.rtype == NoneType:\n rtype = 'void'\n else:\n rtype = self.rtype.cxxtype\n \n # -----------------------------------------------\n # Insert code body if available\n # -----------------------------------------------\n source = inspect.getsource(self.function)\n if not source: source = ''\n comments = inspect.getcomments(self.function)\n if comments: source = comments+source\n code = string.join(map(lambda x: '/////// '+x,string.split(source,'\\n')),\n '\\n')+'\\n'\n\n # -----------------------------------------------\n # Add in the headers\n # -----------------------------------------------\n code += '#include \"Python.h\"\\n'\n for T in self.used:\n if T == None: continue\n for pre in T.prerequisites:\n code += pre\n code += '\\n'\n\n # -----------------------------------------------\n # Real body\n # -----------------------------------------------\n code += '\\n'\n code += '\\nstatic %s %s('%(rtype,self.name)\n for i in range(len(self.signature)):\n if i != 0: code += ', '\n n = self.stack[i]\n t = self.types[i]\n code += '%s %s'%(t.cxxtype,n)\n code += ') {\\n'\n\n # Add in non-argument temporaries\n # Assuming first argcount locals are positional args\n for i in range(self.codeobject.co_argcount,\n self.codeobject.co_nlocals):\n t = self.types[i]\n code += '%s %s;\\n'%(\n t.cxxtype,\n self.codeobject.co_varnames[i],\n )\n\n # Add in the body\n code += self.__body\n code += '}\\n\\n'\n return code\n\n\n ##################################################################\n # MEMBER WRAPPED_CODE #\n ##################################################################\n def wrapped_code(self):\n code = self.generate()\n \n # -----------------------------------------------\n # Wrapper\n # -----------------------------------------------\n code += 'static PyObject* wrapper_%s(PyObject*,PyObject* args) {\\n'%self.name\n\n code += ' // Length check\\n'\n code += ' if ( PyTuple_Size(args) != %d ) {\\n'%len(self.signature)\n code += ' PyErr_SetString(PyExc_TypeError,\"Expected %d arguments\");\\n'%len(self.signature)\n code += ' return 0;\\n'\n code += ' }\\n'\n\n code += '\\n // Load Py versions of args\\n'\n for i in range(len(self.signature)):\n T = self.signature[i]\n code += ' PyObject* py_%s = PyTuple_GET_ITEM(args,%d);\\n'%(\n self.codeobject.co_varnames[i],i\n )\n\n code += ' if ( !(%s) ) {\\n'% \\\n T.check('py_'+self.codeobject.co_varnames[i])\n #code += ' PyObject_Print(py_A,stdout,0); puts(\"\");\\n'\n #code += ' printf(\"nd=%d typecode=%d\\\\n\",((PyArrayObject*)py_A)->nd,((PyArrayObject*)py_A)->descr->type_num);\\n'\n code += ' PyErr_SetString(PyExc_TypeError,\"Bad type for arg %d (expected %s)\");\\n'%(\n i+1,\n T.__class__.__name__)\n code += ' return 0;\\n'\n code += ' }\\n'\n \n code += '\\n // Do conversions\\n'\n argnames = []\n for i in range(len(self.signature)):\n T = self.signature[i]\n\n code += ' %s %s=%s;\\n'%(\n T.cxxtype,\n self.codeobject.co_varnames[i],\n T.inbound('py_'+self.codeobject.co_varnames[i]),\n )\n code += ' if ( PyErr_Occurred() ) return 0;\\n'\n argnames.append(self.codeobject.co_varnames[i])\n\n code += '\\n // Compute result\\n'\n if self.rtype != NoneType:\n code += ' %s _result = '%(\n self.rtype.cxxtype,\n )\n else:\n code += ' '\n code += '%s(%s);\\n'%(\n self.name,\n string.join(argnames,','),\n )\n\n\n code += '\\n // Pack return\\n'\n if ( self.rtype == NoneType ):\n code += ' Py_INCREF(Py_None);\\n'\n code += ' return Py_None;\\n'\n else:\n result = self.rtype.outbound('_result')\n code += ' return %s;\\n'%result\n code += '}\\n'\n return code\n\n def indent(self):\n self.__indent += 1\n return\n\n def dedent(self):\n self.__indent -= 1\n return\n\n ##################################################################\n # MEMBER EMIT #\n ##################################################################\n def emit(self,s):\n self.__body += ' '*(3*self.__indent)\n self.__body += s\n self.__body += '\\n'\n return\n\n ##################################################################\n # MEMBER PUSH #\n ##################################################################\n def push(self,v,t):\n self.stack.append(v)\n self.types.append(t)\n return\n\n ##################################################################\n # MEMBER POP #\n ##################################################################\n def pop(self):\n v = self.stack[-1]\n assert type(v) != TupleType\n del self.stack[-1]\n t = self.types[-1]\n assert type(t) != TupleType\n del self.types[-1]\n return v,t\n\n ##################################################################\n # MEMBER PUSHTUPLE #\n ##################################################################\n def pushTuple(self,V,T):\n assert type(V) == TupleType\n self.stack.append(V)\n assert type(V) == TupleType\n self.types.append(T)\n return\n\n\n ##################################################################\n # MEMBER POPTUPLE #\n ##################################################################\n def popTuple(self):\n v = self.stack[-1]\n assert type(v) == TupleType\n del self.stack[-1]\n t = self.types[-1]\n assert type(t) == TupleType\n del self.types[-1]\n return v,t\n ##################################################################\n # MEMBER MULTIARG #\n ##################################################################\n def multiarg(self):\n return type(self.stack[-1]) == TupleType\n \n ##################################################################\n # MEMBER UNIQUE #\n ##################################################################\n def unique(self):\n self.__uid += 1\n return 't%d'%self.__uid\n\n ##################################################################\n # MEMBER POST #\n ##################################################################\n def post(self,pc,action):\n if not self.forwards.has_key(pc):\n self.forwards[pc] = []\n self.forwards[pc].append(action)\n return\n\n ##################################################################\n # MEMBER EMIT_VALUE #\n ##################################################################\n def emit_value(self, v):\n descriptor = self.typedef_by_value(v)\n \n # Convert representation to CXX rhs\n rhs = descriptor.literalizer(v)\n lhs = self.unique()\n self.emit('%s %s = %s;'%(\n descriptor.cxxtype,\n lhs,\n rhs))\n self.push(lhs,descriptor)\n return \n\n ##################################################################\n # MEMBER GLOBAL_INFO #\n ##################################################################\n def global_info(self,var_num):\n # This is the name value is known by\n var_name = self.codeobject.co_names[var_num]\n\n # First, figure out who owns this global\n import sys\n myHash = id(self.function.func_globals)\n for module_name in sys.modules.keys():\n module = sys.modules[module_name]\n if module and id(module.__dict__) == myHash:\n break\n else:\n raise ValueError,'Cannot locate module owning %s'%varname\n return module_name,var_name\n\n\n ##################################################################\n # MEMBER CODEUP #\n ##################################################################\n def codeup(self, rhs, rhs_type):\n lhs = self.unique()\n self.emit('%s %s = %s;\\n'%(\n rhs_type.cxxtype,\n lhs,\n rhs))\n print self.__body\n self.push(lhs,rhs_type)\n return \n \n\n ##################################################################\n # MEMBER BINOP #\n ##################################################################\n def binop(self,pc,symbol):\n v2,t2 = self.pop()\n v1,t1 = self.pop()\n\n if t1 == t2:\n rhs,rhs_type = t1.binop(symbol,v1,v2)\n else:\n rhs,rhs_type = t1.binopMixed(symbol,v1,v2,t2)\n\n self.codeup(rhs,rhs_type)\n return\n\n ##################################################################\n # MEMBER BINARY_XXX #\n ##################################################################\n def BINARY_ADD(self,pc):\n return self.binop(pc,'+')\n def BINARY_SUBTRACT(self,pc):\n return self.binop(pc,'-')\n def BINARY_MULTIPLY(self,pc):\n print 'MULTIPLY',self.stack[-2],self.types[-2],'*',self.stack[-1],self.types[-1]\n return self.binop(pc,'*')\n def BINARY_DIVIDE(self,pc):\n return self.binop(pc,'/')\n def BINARY_MODULO(self,pc):\n return self.binop(pc,'%')\n def BINARY_SUBSCR(self,pc):\n if self.multiarg():\n v2,t2 = self.popTuple()\n else:\n v2,t2 = self.pop()\n v2 = (v2,)\n t2 = (t2,)\n v1,t1 = self.pop()\n rhs,rhs_type = t1.getitem(v1,v2,t2)\n self.codeup(rhs,rhs_type)\n return\n\n def STORE_SUBSCR(self,pc):\n if self.multiarg():\n v2,t2 = self.popTuple()\n else:\n v2,t2 = self.pop()\n v2 = (v2,)\n t2 = (t2,)\n v1,t1 = self.pop()\n v0,t0 = self.pop()\n \n rhs,rhs_type = t1.setitem(v1,v2,t2)\n assert rhs_type == t0,\"Store the right thing\"\n self.emit('%s = %s;'%(rhs,v0))\n return\n\n def COMPARE_OP(self,pc,opname):\n symbol = self.cmp_op(opname) # convert numeric to name\n return self.binop(pc,symbol)\n\n\n ##################################################################\n # MEMBER PRINT_ITEM #\n ##################################################################\n def PRINT_ITEM(self,pc):\n # Printing correctly is tricky... best to let Python\n # do the real work here\n w = self.unique()\n self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n self.emit('if (PyFile_SoftSpace(%s,1)) PyFile_WriteString(\" \",%s);'%(w,w))\n v,t = self.pop()\n\n py = self.unique()\n self.emit('PyObject* %s = %s;'%(py, t.outbound(v)))\n self.emit('PyFile_WriteObject(%s,%s,Py_PRINT_RAW);'%(\n py,w))\n self.emit('Py_XDECREF(%s);'%py)\n return\n\n\n ##################################################################\n # MEMBER PRINT_NEWLINE #\n ##################################################################\n def PRINT_NEWLINE(self,pc):\n # Printing correctly is tricky... best to let Python\n # do the real work here\n w = self.unique()\n self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n self.emit('PyFile_WriteString(\"\\\\n\",%s);'%w);\n self.emit('PyFile_SoftSpace(%s,0);'%w);\n return\n \n ##################################################################\n # MEMBER SET_LINENO #\n ##################################################################\n def SET_LINENO(self,pc,lineno):\n self.emit('// %s:%d'%(self.codeobject.co_filename,lineno))\n return\n\n ##################################################################\n # MEMBER POP_TOP #\n ##################################################################\n def POP_TOP(self,pc):\n v,t = self.pop()\n return\n\n ##################################################################\n # MEMBER LOAD_CONST #\n ##################################################################\n def LOAD_CONST(self,pc,consti):\n # Fetch the constant\n k = self.consts[consti]\n t = type(k)\n print 'LOAD_CONST',repr(k),t\n\n # Fetch a None is just skipped\n if t == NoneType:\n self.push('',t) \n return\n\n self.emit_value(k)\n return\n\n\n ##################################################################\n # MEMBER BUILD_TUPLE #\n ##################################################################\n def BUILD_TUPLE(self,pc,count):\n \"Creates a tuple consuming count items from the stack, and pushes the resulting tuple onto the stack.\"\n V = []\n T = []\n for i in range(count):\n v,t = self.pop()\n V.append(v)\n T.append(t)\n V.reverse()\n T.reverse()\n self.pushTuple(tuple(V),tuple(T))\n return\n\n ##################################################################\n # MEMBER LOAD_FAST #\n ##################################################################\n def LOAD_FAST(self,pc,var_num):\n v = self.stack[var_num]\n t = self.types[var_num]\n print 'LOADFAST',var_num,v,t\n for VV,TT in map(None, self.stack, self.types):\n print VV,':',TT\n if t == None:\n raise TypeError,'%s used before set?'%v\n print self.__body\n print 'PC',pc\n self.push(v,t)\n return\n\n ##################################################################\n # MEMBER LOAD_GLOBAL #\n ##################################################################\n def LOAD_GLOBAL(self,pc,var_num):\n # Figure out the name and load it\n try:\n F = self.function.func_globals[self.codeobject.co_names[var_num]]\n except:\n F = __builtins__[self.codeobject.co_names[var_num]]\n\n # For functions, we see if we know about this function\n if callable(F):\n self.push(F,type(F))\n return\n\n # We need the name of the module that matches\n # the global state for the function and\n # the name of the variable\n module_name,var_name = self.global_info(var_num)\n\n # We hope it's type is correct\n t = type(F)\n descriptor = typedefs[t]\n native = self.unique()\n py = self.unique()\n mod = self.unique()\n\n self.emit('')\n self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n mod,module_name))\n self.emit('PyObject* %s = PyObject_GetAttrString(%s,\"%s\");'%(\n py,mod,var_name))\n self.emit('%s %s = %s;'%(\n descriptor.cxxtype,\n native,\n descriptor.inbound%py))\n\n self.push(native,t)\n return\n\n def SETUP_LOOP(self,pc,delta):\n \"Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.\"\n return\n\n def FOR_LOOP(self,pc,delta):\n \"Iterate over a sequence. TOS is the current index, TOS1 the sequence. First, the next element is computed. If the sequence is exhausted, increment byte code counter by delta. Otherwise, push the sequence, the incremented counter, and the current item onto the stack.\"\n # Pull off control variable and range info\n v2,t2 = self.pop()\n v1,t1 = self.pop()\n self.emit('for(%s=%s.low; %s<%s.high; %s += %s.step) {'%(\n v2,v1,v2,v1,v2,v1))\n\n # Put range back on for assignment\n self.push(v2,t2)\n return\n\n def JUMP_ABSOLUTE(self,pc,target):\n \"Set byte code counter to target.\"\n self.emit('}')\n return\n\n def POP_BLOCK(self,pc):\n \"Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.\"\n return\n\n\n ##################################################################\n # MEMBER STORE_FAST #\n ##################################################################\n def STORE_FAST(self,pc,var_num):\n\n v,t = self.pop()\n print 'STORE FAST',var_num,v,t\n\n save = self.stack[var_num]\n saveT = self.types[var_num]\n\n # See if type is same....\n # Note that None means no assignment made yet\n if saveT == None or t == saveT:\n if t.refcount:\n self.emit('Py_XINCREF(%s);'%v)\n self.emit('Py_XDECREF(%s);'%save)\n self.emit('%s = %s;\\n'%(save,v))\n self.types[var_num] = t\n return\n\n raise TypeError,(t,saveT)\n\n ##################################################################\n # MEMBER STORE_GLOBAL #\n ##################################################################\n def STORE_GLOBAL(self,pc,var_num):\n\n # We need the name of the module that matches\n # the global state for the function and\n # the name of the variable\n module_name,var_name = self.global_info(var_num)\n\n # Convert the value to Python object\n v,t = self.pop()\n descriptor = typedefs[t]\n py = self.unique()\n self.emit('PyObject* %s = %s;'%(\n py,\n descriptor.outbound%v))\n mod = self.unique()\n self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n mod,module_name))\n self.emit('PyObject_SetAttrString(%s,\"%s\",%s);'%(\n mod,var_name,py))\n self.emit('Py_DECREF(%s);'%py)\n return\n\n ##################################################################\n # MEMBER CALL_FUNCTION #\n ##################################################################\n def CALL_FUNCTION(self,pc,argc):\n # Pull args off stack\n args = []\n types = []\n for i in range(argc):\n v,t = self.pop()\n args = [v]+args\n types = [t]+types\n \n # Pull function object off stack and get descriptor\n f,t = self.pop()\n signature = (f,tuple(types))\n descriptor = self.function_by_signature(signature)\n #self.prerequisites += descriptor['prerequisite']+'\\n'\n \n # Build a rhs\n rhs = descriptor.code%string.join(args,',')\n\n # Build a statement\n temp = self.unique()\n self.emit('%s %s = %s;\\n'%(\n descriptor.return_type.cxxtype,\n temp,\n rhs))\n\n self.push(temp,descriptor.return_type)\n return\n\n\n ##################################################################\n # MEMBER JUMP_IF_FALSE #\n ##################################################################\n def JUMP_IF_FALSE(self,pc,delta):\n v,t = self.pop()\n self.push(v,t)\n # We need to do some work when we get to the\n # else part (put the value that's gonna get\n # popped back on the stack, emit } else {,\n # ...)\n action = lambda v=v,t=t,self=self: (\n self.emit('} else {'),\n self.push(v,t),\n )\n self.post(pc+delta,action)\n if t != IntType: raise TypeError, 'Invalid comparison type %s'%t\n self.emit('if (%s) {\\n'%v)\n return\n \n\n ##################################################################\n # MEMBER JUMP_FORWARD #\n ##################################################################\n def JUMP_FORWARD(self,pc,delta):\n # We need to close the if after the delta\n action = lambda self=self: (\n self.emit('}'),\n )\n self.post(pc+delta,action)\n return\n \n ##################################################################\n # MEMBER RETURN_VALUE #\n ##################################################################\n def RETURN_VALUE(self,pc):\n v,t = self.pop()\n if hasattr(self,'rtype'):\n print v,t\n if t == NoneType: return # just the extra return\n raise ValueError,'multiple returns'\n self.rtype = t\n if t == NoneType:\n self.emit('return;')\n else:\n self.emit('return %s;'%v)\n print 'return with',v\n return\n\n", + "source_code_before": "#**************************************************************************#\n#* FILE ************** bytecodecompiler.py ************************#\n#************************************************************************ **#\n#* Author: Patrick Miller February 9 2002 *#\n#* Copyright (C) 2002 Patrick J. Miller *#\n#**************************************************************************#\n#* *#\n#**************************************************************************#\nfrom types import *\nimport string\nimport inspect\n\n##################################################################\n# CLASS __DESCRIPTOR #\n##################################################################\nclass __Descriptor:\n prerequisites = []\n refcount = 0\n def __repr__(self):\n return self.__module__+'.'+self.__class__.__name__\n\n##################################################################\n# CLASS TYPE_DESCRIPTOR #\n##################################################################\nclass Type_Descriptor(__Descriptor):\n module_init_code = ''\n\n##################################################################\n# CLASS FUNCTION_DESCRIPTOR #\n##################################################################\nclass Function_Descriptor(__Descriptor):\n def __init__(self,code,return_type,support=''):\n\tself.code\t= code\n\tself.return_type\t= return_type\n self.support = support\n\treturn\n\n \n \n\nhaveArgument = 90 # Opcodes greater-equal to this have argument\nbyName = {\n 'STOP_CODE': 0,\n 'POP_TOP': 1,\n 'ROT_TWO': 2,\n 'ROT_THREE': 3,\n 'DUP_TOP': 4,\n 'ROT_FOUR': 5,\n 'UNARY_POSITIVE': 10,\n 'UNARY_NEGATIVE': 11,\n 'UNARY_NOT': 12,\n 'UNARY_CONVERT': 13,\n 'UNARY_INVERT': 15,\n 'BINARY_POWER': 19,\n 'BINARY_MULTIPLY': 20,\n 'BINARY_DIVIDE': 21,\n 'BINARY_MODULO': 22,\n 'BINARY_ADD': 23,\n 'BINARY_SUBTRACT': 24,\n 'BINARY_SUBSCR': 25,\n 'BINARY_FLOOR_DIVIDE': 26,\n 'BINARY_TRUE_DIVIDE': 27,\n 'INPLACE_FLOOR_DIVIDE': 28,\n 'INPLACE_TRUE_DIVIDE': 29,\n 'SLICE': 30,\n 'STORE_SLICE': 40,\n 'DELETE_SLICE': 50,\n 'INPLACE_ADD': 55,\n 'INPLACE_SUBTRACT': 56,\n 'INPLACE_MULTIPLY': 57,\n 'INPLACE_DIVIDE': 58,\n 'INPLACE_MODULO': 59,\n 'STORE_SUBSCR': 60,\n 'DELETE_SUBSCR': 61,\n 'BINARY_LSHIFT': 62,\n 'BINARY_RSHIFT': 63,\n 'BINARY_AND': 64,\n 'BINARY_XOR': 65,\n 'BINARY_OR': 66,\n 'INPLACE_POWER': 67,\n 'GET_ITER': 68,\n 'PRINT_EXPR': 70,\n 'PRINT_ITEM': 71,\n 'PRINT_NEWLINE': 72,\n 'PRINT_ITEM_TO': 73,\n 'PRINT_NEWLINE_TO': 74,\n 'INPLACE_LSHIFT': 75,\n 'INPLACE_RSHIFT': 76,\n 'INPLACE_AND': 77,\n 'INPLACE_XOR': 78,\n 'INPLACE_OR': 79,\n 'BREAK_LOOP': 80,\n 'LOAD_LOCALS': 82,\n 'RETURN_VALUE': 83,\n 'IMPORT_STAR': 84,\n 'EXEC_STMT': 85,\n 'YIELD_VALUE': 86,\n 'POP_BLOCK': 87,\n 'END_FINALLY': 88,\n 'BUILD_CLASS': 89,\n 'STORE_NAME': 90,\n 'DELETE_NAME': 91,\n 'UNPACK_SEQUENCE': 92,\n 'FOR_ITER': 93,\n 'STORE_ATTR': 95,\n 'DELETE_ATTR': 96,\n 'STORE_GLOBAL': 97,\n 'DELETE_GLOBAL': 98,\n 'DUP_TOPX': 99,\n 'LOAD_CONST': 100,\n 'LOAD_NAME': 101,\n 'BUILD_TUPLE': 102,\n 'BUILD_LIST': 103,\n 'BUILD_MAP': 104,\n 'LOAD_ATTR': 105,\n 'COMPARE_OP': 106,\n 'IMPORT_NAME': 107,\n 'IMPORT_FROM': 108,\n 'JUMP_FORWARD': 110,\n 'JUMP_IF_FALSE': 111,\n 'JUMP_IF_TRUE': 112,\n 'JUMP_ABSOLUTE': 113,\n 'FOR_LOOP': 114,\n 'LOAD_GLOBAL': 116,\n 'CONTINUE_LOOP': 119,\n 'SETUP_LOOP': 120,\n 'SETUP_EXCEPT': 121,\n 'SETUP_FINALLY': 122,\n 'LOAD_FAST': 124,\n 'STORE_FAST': 125,\n 'DELETE_FAST': 126,\n 'SET_LINENO': 127,\n 'RAISE_VARARGS': 130,\n 'CALL_FUNCTION': 131,\n 'MAKE_FUNCTION': 132,\n 'BUILD_SLICE': 133,\n 'MAKE_CLOSURE': 134,\n 'LOAD_CLOSURE': 135,\n 'LOAD_DEREF': 136,\n 'STORE_DEREF': 137,\n 'CALL_FUNCTION_VAR': 140,\n 'CALL_FUNCTION_KW': 141,\n 'CALL_FUNCTION_VAR_KW': 142,\n }\n\n# -----------------------------------------------\n# Build one in the reverse sense\n# -----------------------------------------------\nbyOpcode = {}\nfor name,op in map(None, byName.keys(), byName.values()):\n byOpcode[op] = name\n del name\n del op\n \n\n##################################################################\n# FUNCTION OPCODIZE #\n##################################################################\ndef opcodize(s):\n \"Slightly more readable form\"\n length = len(s)\n i = 0\n answer = []\n while i < length:\n bytecode = ord(s[i])\n name = byOpcode[bytecode]\n if bytecode >= haveArgument:\n argument = 256*ord(s[i+2])+ord(s[i+1])\n i += 3\n else:\n argument = None\n i += 1\n answer.append((bytecode,argument,name))\n return answer\n\n\n\n##################################################################\n# FUNCTION LIST #\n##################################################################\ndef listing(f):\n \"Pretty print the internals of your function\"\n assert type(f) == FunctionType,\"Arg %r must be a function\"%f\n filename = f.func_code.co_filename\n try:\n lines = open(filename).readlines()\n except:\n lines = None\n pc = 0\n s = ''\n lastLine = None\n for op,arg,name in opcodize(f.func_code.co_code):\n if lines and name == 'SET_LINENO':\n source = lines[arg-1][:-1]\n while lastLine and lastLine < arg-1:\n nonEmittingSource = lines[lastLine][:-1]\n lastLine += 1\n s += '%3s %20s %5s : %s\\n'%(\n '','','',nonEmittingSource)\n lastLine = arg\n else:\n source = ''\n if arg == None: arg = ''\n s += '%3d] %20s %5s : %s\\n'%(pc,name,arg,source)\n if op >= haveArgument:\n pc += 3\n else:\n pc += 1\n return s\n\n##################################################################\n# CLASS BYTECODEMEANING #\n##################################################################\nclass ByteCodeMeaning:\n def fetch(self, pc,code):\n opcode = ord(code[pc])\n if opcode >= haveArgument:\n argument = 256*ord(code[pc+2])+ord(code[pc+1])\n next = pc+3\n else:\n argument = None\n next = pc+1\n return next,opcode,argument\n \n def execute(self,pc,opcode,argument):\n name = byOpcode[opcode]\n method = getattr(self,name)\n if argument == None:\n return apply(method,(pc,))\n else:\n return apply(method,(pc,argument,))\n\n def evaluate(self, pc,code):\n next, opcode,argument = self.fetch(pc,code)\n goto = self.execute(next,opcode,argument)\n if goto == -1:\n return None # Must be done\n elif goto == None:\n return next # Normal\n else:\n raise 'xx'\n\n symbols = { 0: 'less', 1: 'lesseq', 2: 'equal', 3: 'notequal',\n 4: 'greater', 5: 'greatereq', 6: 'in', 7: 'not in',\n 8: 'is', 9: 'is not', 10: 'exe match',\n 11 : 'bad',\n }\n def cmp_op(self,opname):\n return self.symbols[opname]\n \n def STOP_CODE(self,pc):\n \"Indicates end-of-code to the compiler, not used by the interpreter.\"\n raise NotImplementedError\n def POP_TOP(self,pc):\n \"Removes the top-of-stack (TOS) item.\"\n raise NotImplementedError\n\n def ROT_TWO(self,pc):\n \"Swaps the two top-most stack items.\"\n raise NotImplementedError\n\n def ROT_THREE(self,pc):\n \"Lifts second and third stack item one position up, moves top down to position three.\"\n raise NotImplementedError\n\n def ROT_FOUR(self,pc):\n \"Lifts second, third and forth stack item one position up, moves top down to position four.\"\n raise NotImplementedError\n\n def DUP_TOP(self,pc):\n \"Duplicates the reference on top of the stack.\"\n raise NotImplementedError\n\n # Unary Operations take the top of the stack, apply the operation, and push the result back on the stack.\n\n def UNARY_POSITIVE(self,pc):\n \"Implements TOS = +TOS.\"\n raise NotImplementedError\n\n def UNARY_NEGATIVE(self,pc):\n \"Implements TOS = -TOS.\"\n raise NotImplementedError\n\n def UNARY_NOT(self,pc):\n \"Implements TOS = not TOS.\"\n raise NotImplementedError\n\n def UNARY_CONVERT(self,pc):\n \"Implements TOS = `TOS`.\"\n raise NotImplementedError\n\n def UNARY_INVERT(self,pc):\n \"Implements TOS = ~TOS.\"\n raise NotImplementedError\n\n #Binary operations remove the top of the stack (TOS) and the second top-most stack item (TOS1) from the stack. They perform the operation, and put the result back on the stack.\n\n def BINARY_POWER(self,pc):\n \"Implements TOS = TOS1 ** TOS.\"\n raise NotImplementedError\n\n def BINARY_MULTIPLY(self,pc):\n \"Implements TOS = TOS1 * TOS.\"\n raise NotImplementedError\n\n def BINARY_DIVIDE(self,pc):\n \"Implements TOS = TOS1 / TOS.\"\n raise NotImplementedError\n\n def BINARY_MODULO(self,pc):\n \"Implements TOS = TOS1 % TOS.\"\n raise NotImplementedError\n\n def BINARY_ADD(self,pc):\n \"Implements TOS = TOS1 + TOS.\"\n raise NotImplementedError\n\n def BINARY_SUBTRACT(self,pc):\n \"Implements TOS = TOS1 - TOS.\"\n raise NotImplementedError\n\n def BINARY_SUBSCR(self,pc):\n \"Implements TOS = TOS1[TOS].\"\n raise NotImplementedError\n\n def BINARY_LSHIFT(self,pc):\n \"Implements TOS = TOS1 << TOS.\"\n raise NotImplementedError\n\n def BINARY_RSHIFT(self,pc):\n \"Implements TOS = TOS1 >> TOS.\"\n raise NotImplementedError\n\n def BINARY_AND(self,pc):\n \"Implements TOS = TOS1 & TOS.\"\n raise NotImplementedError\n\n def BINARY_XOR(self,pc):\n \"Implements TOS = TOS1 ^ TOS.\"\n raise NotImplementedError\n\n def BINARY_OR(self,pc):\n \"Implements TOS = TOS1 | TOS.\"\n raise NotImplementedError\n\n #In-place operations are like binary operations, in that they remove TOS and TOS1, and push the result back on the stack, but the operation is done in-place when TOS1 supports it, and the resulting TOS may be (but does not have to be) the original TOS1.\n\n def INPLACE_POWER(self,pc):\n \"Implements in-place TOS = TOS1 ** TOS.\"\n raise NotImplementedError\n\n def INPLACE_MULTIPLY(self,pc):\n \"Implements in-place TOS = TOS1 * TOS.\"\n raise NotImplementedError\n\n def INPLACE_DIVIDE(self,pc):\n \"Implements in-place TOS = TOS1 / TOS.\"\n raise NotImplementedError\n\n def INPLACE_MODULO(self,pc):\n \"Implements in-place TOS = TOS1 % TOS.\"\n raise NotImplementedError\n\n def INPLACE_ADD(self,pc):\n \"Implements in-place TOS = TOS1 + TOS.\"\n raise NotImplementedError\n\n def INPLACE_SUBTRACT(self,pc):\n \"Implements in-place TOS = TOS1 - TOS.\"\n raise NotImplementedError\n\n def INPLACE_LSHIFT(self,pc):\n \"Implements in-place TOS = TOS1 << TOS.\"\n raise NotImplementedError\n\n def INPLACE_RSHIFT(self,pc):\n \"Implements in-place TOS = TOS1 >> TOS.\"\n raise NotImplementedError\n\n def INPLACE_AND(self,pc):\n \"Implements in-place TOS = TOS1 & TOS.\"\n raise NotImplementedError\n\n def INPLACE_XOR(self,pc):\n \"Implements in-place TOS = TOS1 ^ TOS.\"\n raise NotImplementedError\n\n def INPLACE_OR(self,pc):\n \"Implements in-place TOS = TOS1 | TOS.\"\n raise NotImplementedError\n\n #The slice opcodes take up to three parameters.\n\n def SLICE_0(self,pc):\n \"Implements TOS = TOS[:].\"\n raise NotImplementedError\n\n def SLICE_1(self,pc):\n \"Implements TOS = TOS1[TOS:].\"\n raise NotImplementedError\n\n def SLICE_2(self,pc):\n \"Implements TOS = TOS1[:TOS1].\"\n raise NotImplementedError\n\n def SLICE_3(self,pc):\n \"Implements TOS = TOS2[TOS1:TOS].\"\n raise NotImplementedError\n\n #Slice assignment needs even an additional parameter. As any statement, they put nothing on the stack.\n\n def STORE_SLICE_0(self,pc):\n \"Implements TOS[:] = TOS1.\"\n raise NotImplementedError\n\n def STORE_SLICE_1(self,pc):\n \"Implements TOS1[TOS:] = TOS2.\"\n raise NotImplementedError\n\n def STORE_SLICE_2(self,pc):\n \"Implements TOS1[:TOS] = TOS2.\"\n raise NotImplementedError\n\n def STORE_SLICE_3(self,pc):\n \"Implements TOS2[TOS1:TOS] = TOS3.\"\n raise NotImplementedError\n\n def DELETE_SLICE_0(self,pc):\n \"Implements del TOS[:].\"\n raise NotImplementedError\n\n def DELETE_SLICE_1(self,pc):\n \"Implements del TOS1[TOS:].\"\n raise NotImplementedError\n\n def DELETE_SLICE_2(self,pc):\n \"Implements del TOS1[:TOS].\"\n raise NotImplementedError\n\n def DELETE_SLICE_3(self,pc):\n \"Implements del TOS2[TOS1:TOS].\"\n raise NotImplementedError\n\n def STORE_SUBSCR(self,pc):\n \"Implements TOS1[TOS] = TOS2.\"\n raise NotImplementedError\n\n def DELETE_SUBSCR(self,pc):\n \"Implements del TOS1[TOS].\"\n raise NotImplementedError\n\n def PRINT_EXPR(self,pc):\n \"Implements the expression statement for the interactive mode. TOS is removed from the stack and printed. In non-interactive mode, an expression statement is terminated with POP_STACK.\"\n raise NotImplementedError\n\n def PRINT_ITEM(self,pc):\n \"Prints TOS to the file-like object bound to sys.stdout. There is one such instruction for each item in the print statement.\"\n raise NotImplementedError\n\n def PRINT_ITEM_TO(self,pc):\n \"Like PRINT_ITEM, but prints the item second from TOS to the file-like object at TOS. This is used by the extended print statement.\"\n raise NotImplementedError\n\n def PRINT_NEWLINE(self,pc):\n \"Prints a new line on sys.stdout. This is generated as the last operation of a print statement, unless the statement ends with a comma.\"\n raise NotImplementedError\n\n def PRINT_NEWLINE_TO(self,pc):\n \"Like PRINT_NEWLINE, but prints the new line on the file-like object on the TOS. This is used by the extended print statement.\"\n raise NotImplementedError\n\n def BREAK_LOOP(self,pc):\n \"Terminates a loop due to a break statement.\"\n raise NotImplementedError\n\n def LOAD_LOCALS(self,pc):\n \"Pushes a reference to the locals of the current scope on the stack. This is used in the code for a class definition: After the class body is evaluated, the locals are passed to the class definition.\"\n raise NotImplementedError\n\n def RETURN_VALUE(self,pc):\n \"Returns with TOS to the caller of the function.\"\n raise NotImplementedError\n\n def IMPORT_STAR(self,pc):\n \"Loads all symbols not starting with _ directly from the module TOS to the local namespace. The module is popped after loading all names. This opcode implements from module import *.\"\n raise NotImplementedError\n\n def EXEC_STMT(self,pc):\n \"Implements exec TOS2,TOS1,TOS. The compiler fills missing optional parameters with None.\"\n raise NotImplementedError\n\n def POP_BLOCK(self,pc):\n \"Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.\"\n raise NotImplementedError\n\n def END_FINALLY(self,pc):\n \"Terminates a finally clause. The interpreter recalls whether the exception has to be re-raised, or whether the function returns, and continues with the outer-next block.\"\n raise NotImplementedError\n\n def BUILD_CLASS(self,pc):\n \"Creates a new class object. TOS is the methods dictionary, TOS1 the tuple of the names of the base classes, and TOS2 the class name.\"\n raise NotImplementedError\n\n #All of the following opcodes expect arguments. An argument is two bytes, with the more significant byte last.\n\n def STORE_NAME(self,pc,namei):\n \"Implements name = TOS. namei is the index of name in the attribute co_names of the code object. The compiler tries to use STORE_LOCAL or STORE_GLOBAL if possible.\"\n raise NotImplementedError\n\n def DELETE_NAME(self,pc,namei):\n \"Implements del name, where namei is the index into co_names attribute of the code object.\"\n raise NotImplementedError\n\n def UNPACK_SEQUENCE(self,pc,count):\n \"Unpacks TOS into count individual values, which are put onto the stack right-to-left.\"\n raise NotImplementedError\n\n def DUP_TOPX(self,pc,count):\n \"Duplicate count items, keeping them in the same order. Due to implementation limits, count should be between 1 and 5 inclusive.\"\n raise NotImplementedError\n\n def STORE_ATTR(self,pc,namei):\n \"Implements TOS.name = TOS1, where namei is the index of name in co_names.\"\n raise NotImplementedError\n\n def DELETE_ATTR(self,pc,namei):\n \"Implements del TOS.name, using namei as index into co_names.\"\n raise NotImplementedError\n\n def STORE_GLOBAL(self,pc,namei):\n \"Works as STORE_NAME, but stores the name as a global.\"\n raise NotImplementedError\n\n def DELETE_GLOBAL(self,pc,namei):\n \"Works as DELETE_NAME, but deletes a global name.\"\n raise NotImplementedError\n\n def LOAD_CONST(self,pc,consti):\n \"Pushes co_consts[consti] onto the stack.\"\n raise NotImplementedError\n\n def LOAD_NAME(self,pc,namei):\n \"Pushes the value associated with co_names[namei] onto the stack.\"\n raise NotImplementedError\n\n def BUILD_TUPLE(self,pc,count):\n \"Creates a tuple consuming count items from the stack, and pushes the resulting tuple onto the stack.\"\n raise NotImplementedError\n\n def BUILD_LIST(self,pc,count):\n \"Works as BUILD_TUPLE, but creates a list.\"\n raise NotImplementedError\n\n def BUILD_MAP(self,pc,zero):\n \"Pushes a new empty dictionary object onto the stack. The argument is ignored and set to zero by the compiler.\"\n raise NotImplementedError\n\n def LOAD_ATTR(self,pc,namei):\n \"Replaces TOS with getattr(TOS, co_names[namei].\"\n raise NotImplementedError\n\n def COMPARE_OP(self,pc,opname):\n \"Performs a Boolean operation. The operation name can be found in cmp_op[opname].\"\n raise NotImplementedError\n\n def IMPORT_NAME(self,pc,namei):\n \"Imports the module co_names[namei]. The module object is pushed onto the stack. The current namespace is not affected: for a proper import statement, a subsequent STORE_FAST instruction modifies the namespace.\"\n raise NotImplementedError\n\n def IMPORT_FROM(self,pc,namei):\n \"Loads the attribute co_names[namei] from the module found in TOS. The resulting object is pushed onto the stack, to be subsequently stored by a STORE_FAST instruction.\"\n raise NotImplementedError\n\n def JUMP_FORWARD(self,pc,delta):\n \"Increments byte code counter by delta.\"\n raise NotImplementedError\n\n def JUMP_IF_TRUE(self,pc,delta):\n \"If TOS is true, increment the byte code counter by delta. TOS is left on the stack.\"\n raise NotImplementedError\n\n def JUMP_IF_FALSE(self,pc,delta):\n \"If TOS is false, increment the byte code counter by delta. TOS is not changed.\"\n raise NotImplementedError\n\n def JUMP_ABSOLUTE(self,pc,target):\n \"Set byte code counter to target.\"\n raise NotImplementedError\n\n def FOR_LOOP(self,pc,delta):\n \"Iterate over a sequence. TOS is the current index, TOS1 the sequence. First, the next element is computed. If the sequence is exhausted, increment byte code counter by delta. Otherwise, push the sequence, the incremented counter, and the current item onto the stack.\"\n raise NotImplementedError\n\n def LOAD_GLOBAL(self,pc,namei):\n \"Loads the global named co_names[namei] onto the stack.\"\n raise NotImplementedError\n\n def SETUP_LOOP(self,pc,delta):\n \"Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.\"\n raise NotImplementedError\n\n def SETUP_EXCEPT(self,pc,delta):\n \"Pushes a try block from a try-except clause onto the block stack. delta points to the first except block.\"\n raise NotImplementedError\n\n def SETUP_FINALLY(self,pc,delta):\n \"Pushes a try block from a try-except clause onto the block stack. delta points to the finally block.\"\n raise NotImplementedError\n\n def LOAD_FAST(self,pc,var_num):\n \"Pushes a reference to the local co_varnames[var_num] onto the stack.\"\n raise NotImplementedError\n\n def STORE_FAST(self,pc,var_num):\n \"Stores TOS into the local co_varnames[var_num].\"\n raise NotImplementedError\n\n def DELETE_FAST(self,pc,var_num):\n \"Deletes local co_varnames[var_num].\"\n raise NotImplementedError\n\n def LOAD_CLOSURE(self,pc,i):\n \"Pushes a reference to the cell contained in slot i of the cell and free variable storage. The name of the variable is co_cellvars[i] if i is less than the length of co_cellvars. Otherwise it is co_freevars[i - len(co_cellvars)].\"\n raise NotImplementedError\n\n def LOAD_DEREF(self,pc,i):\n \"Loads the cell contained in slot i of the cell and free variable storage. Pushes a reference to the object the cell contains on the stack.\"\n raise NotImplementedError\n\n def STORE_DEREF(self,pc,i):\n \"Stores TOS into the cell contained in slot i of the cell and free variable storage.\"\n raise NotImplementedError\n\n def SET_LINENO(self,pc,lineno):\n \"Sets the current line number to lineno.\"\n raise NotImplementedError\n\n def RAISE_VARARGS(self,pc,argc):\n \"Raises an exception. argc indicates the number of parameters to the raise statement, ranging from 0 to 3. The handler will find the traceback as TOS2, the parameter as TOS1, and the exception as TOS.\"\n raise NotImplementedError\n\n def CALL_FUNCTION(self,pc,argc):\n \"Calls a function. The low byte of argc indicates the number of positional parameters, the high byte the number of keyword parameters. On the stack, the opcode finds the keyword parameters first. For each keyword argument, the value is on top of the key. Below the keyword parameters, the positional parameters are on the stack, with the right-most parameter on top. Below the parameters, the function object to call is on the stack.\"\n raise NotImplementedError\n\n def MAKE_FUNCTION(self,pc,argc):\n \"Pushes a new function object on the stack. TOS is the code associated with the function. The function object is defined to have argc default parameters, which are found below TOS.\"\n raise NotImplementedError\n\n def MAKE_CLOSURE(self,pc,argc):\n \"Creates a new function object, sets its func_closure slot, and pushes it on the stack. TOS is the code associated with the function. If the code object has N free variables, the next N items on the stack are the cells for these variables. The function also has argc default parameters, where are found before the cells.\"\n raise NotImplementedError\n\n def BUILD_SLICE(self,pc,argc):\n \"Pushes a slice object on the stack. argc must be 2 or 3. If it is 2, slice(TOS1, TOS) is pushed; if it is 3, slice(TOS2, TOS1, TOS) is pushed. See the slice() built-in function for more information.\"\n raise NotImplementedError\n\n def EXTENDED_ARG(self,pc,ext):\n \"Prefixes any opcode which has an argument too big to fit into the default two bytes. ext holds two additional bytes which, taken together with the subsequent opcode's argument, comprise a four-byte argument, ext being the two most-significant bytes.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_VAR(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the variable argument list, followed by keyword and positional arguments.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_KW(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by explicit keyword and positional arguments.\"\n raise NotImplementedError\n\n def CALL_FUNCTION_VAR_KW(self,pc,argc):\n \"Calls a function. argc is interpreted as in CALL_FUNCTION. The top element on the stack contains the keyword arguments dictionary, followed by the variable-arguments tuple, followed by explicit keyword and positional arguments.\"\n raise NotImplementedError\n\n \n\n##################################################################\n# CLASS CXXCODER #\n##################################################################\nclass CXXCoder(ByteCodeMeaning):\n\n ##################################################################\n # MEMBER TYPEDEF_BY_VALUE #\n ##################################################################\n def typedef_by_value(self,v):\n raise NotImplementedError # VIRTUAL\n \n ##################################################################\n # MEMBER __INIT__ #\n ##################################################################\n def __init__(self,function,signature,name=None):\n assert type(function) == FunctionType,\"Arg must be a user function\"\n assert not function.func_defaults ,\"Function cannot have default args (yet)\"\n if name == None: name = function.func_name\n self.name = name\n self.function = function\n self.signature = signature\n self.codeobject = function.func_code\n self.__uid = 0 # Builds temps\n return\n\n ##################################################################\n # MEMBER EVALUATE #\n ##################################################################\n def evaluate(self, pc,code):\n # See if we posted any forwards for this offset\n if self.forwards.has_key(pc):\n for f in self.forwards[pc]:\n f()\n self.forwards[pc] = []\n return ByteCodeMeaning.evaluate(self,pc,code)\n \n ##################################################################\n # MEMBER GENERATE #\n ##################################################################\n def generate(self):\n self.forwards = {} # Actions on forward interprets\n self.__body = '' # Body will be built\n self.helpers = [] # headers and stuff\n\n # -----------------------------------------------\n # OK, crack open the function object and build\n # initial stack (not a real frame!)\n # -----------------------------------------------\n arglen = len(self.signature)\n nlocals = self.codeobject.co_nlocals\n\n self.consts = self.codeobject.co_consts\n self.stack = list(self.codeobject.co_varnames)\n self.types = list(self.signature)+[None]*(nlocals-arglen)\n self.used = []\n for T in self.types:\n if T not in self.used: self.used.append(T)\n\n # -----------------------------------------------\n # One pass through the byte codes to generate\n # the body\n # -----------------------------------------------\n code = self.codeobject.co_code\n bytes = len(code)\n pc = 0\n while pc != None and pc < bytes:\n pc = self.evaluate(pc,code)\n\n # -----------------------------------------------\n # Return?\n # -----------------------------------------------\n if self.rtype == NoneType:\n rtype = 'void'\n else:\n rtype = self.rtype.cxxtype\n \n # -----------------------------------------------\n # Insert code body if available\n # -----------------------------------------------\n source = inspect.getsource(self.function)\n if not source: source = ''\n comments = inspect.getcomments(self.function)\n if comments: source = comments+source\n code = string.join(map(lambda x: '/////// '+x,string.split(source,'\\n')),\n '\\n')+'\\n'\n\n # -----------------------------------------------\n # Add in the headers\n # -----------------------------------------------\n code += '#include \"Python.h\"\\n'\n for T in self.used:\n if T == None: continue\n for pre in T.prerequisites:\n code += pre\n code += '\\n'\n\n # -----------------------------------------------\n # Real body\n # -----------------------------------------------\n code += '\\n'\n code += '\\nstatic %s %s('%(rtype,self.name)\n for i in range(len(self.signature)):\n if i != 0: code += ', '\n n = self.stack[i]\n t = self.types[i]\n code += '%s %s'%(t.cxxtype,n)\n code += ') {\\n'\n\n # Add in non-argument temporaries\n # Assuming first argcount locals are positional args\n for i in range(self.codeobject.co_argcount,\n self.codeobject.co_nlocals):\n t = self.types[i]\n code += '%s %s;\\n'%(\n t.cxxtype,\n self.codeobject.co_varnames[i],\n )\n\n # Add in the body\n code += self.__body\n code += '}\\n\\n'\n return code\n\n\n ##################################################################\n # MEMBER WRAPPED_CODE #\n ##################################################################\n def wrapped_code(self):\n code = self.generate()\n \n # -----------------------------------------------\n # Wrapper\n # -----------------------------------------------\n code += 'static PyObject* wrapper_%s(PyObject*,PyObject* args) {\\n'%self.name\n\n code += ' // Length check\\n'\n code += ' if ( PyTuple_Size(args) != %d ) {\\n'%len(self.signature)\n code += ' PyErr_SetString(PyExc_TypeError,\"Expected %d arguments\");\\n'%len(self.signature)\n code += ' return 0;\\n'\n code += ' }\\n'\n\n code += '\\n // Load Py versions of args\\n'\n for i in range(len(self.signature)):\n T = self.signature[i]\n code += ' PyObject* py_%s = PyTuple_GET_ITEM(args,%d);\\n'%(\n self.codeobject.co_varnames[i],i\n )\n\n code += ' if ( !%s ) {\\n'% \\\n T.check('py_'+self.codeobject.co_varnames[i])\n code += ' PyErr_SetString(PyExc_TypeError,\"Bad type for arg %d (expected %s)\");\\n'%(\n i+1,\n T.__class__.__name__)\n code += ' return 0;\\n'\n code += ' }\\n'\n \n code += '\\n // Do conversions\\n'\n argnames = []\n for i in range(len(self.signature)):\n T = self.signature[i]\n\n code += ' %s %s=%s;\\n'%(\n T.cxxtype,\n self.codeobject.co_varnames[i],\n T.inbound('py_'+self.codeobject.co_varnames[i]),\n )\n code += ' if ( PyErr_Occurred() ) return 0;\\n'\n argnames.append(self.codeobject.co_varnames[i])\n\n code += '\\n // Compute result\\n'\n if self.rtype != NoneType:\n code += ' %s _result = '%(\n self.rtype.cxxtype,\n )\n else:\n code += ' '\n code += '%s(%s);\\n'%(\n self.name,\n string.join(argnames,','),\n )\n\n\n code += '\\n // Pack return\\n'\n if ( self.rtype == NoneType ):\n code += ' Py_INCREF(Py_None);\\n'\n code += ' return Py_None;\\n'\n else:\n result = self.rtype.outbound('_result')\n code += ' return %s;\\n'%result\n code += '}\\n'\n return code\n\n\n ##################################################################\n # MEMBER EMIT #\n ##################################################################\n def emit(self,s):\n self.__body += s\n self.__body += '\\n'\n return\n\n ##################################################################\n # MEMBER PUSH #\n ##################################################################\n def push(self,v,t):\n self.stack.append(v)\n self.types.append(t)\n return\n\n\n ##################################################################\n # MEMBER POP #\n ##################################################################\n def pop(self):\n v = self.stack[-1]\n del self.stack[-1]\n t = self.types[-1]\n del self.types[-1]\n return v,t\n\n ##################################################################\n # MEMBER UNIQUE #\n ##################################################################\n def unique(self):\n self.__uid += 1\n return 't%d'%self.__uid\n\n ##################################################################\n # MEMBER POST #\n ##################################################################\n def post(self,pc,action):\n if not self.forwards.has_key(pc):\n self.forwards[pc] = []\n self.forwards[pc].append(action)\n return\n\n ##################################################################\n # MEMBER EMIT_VALUE #\n ##################################################################\n def emit_value(self, v):\n descriptor = self.typedef_by_value(v)\n \n # Convert representation to CXX rhs\n rhs = descriptor.literalizer(v)\n lhs = self.unique()\n self.emit('%s %s = %s;'%(\n descriptor.cxxtype,\n lhs,\n rhs))\n self.push(lhs,descriptor)\n return \n\n ##################################################################\n # MEMBER GLOBAL_INFO #\n ##################################################################\n def global_info(self,var_num):\n # This is the name value is known by\n var_name = self.codeobject.co_names[var_num]\n\n # First, figure out who owns this global\n import sys\n myHash = id(self.function.func_globals)\n for module_name in sys.modules.keys():\n module = sys.modules[module_name]\n if module and id(module.__dict__) == myHash:\n break\n else:\n raise ValueError,'Cannot locate module owning %s'%varname\n return module_name,var_name\n\n ##################################################################\n # MEMBER BINOP #\n ##################################################################\n def binop(self,pc,symbol):\n v2,t2 = self.pop()\n v1,t1 = self.pop()\n\n if t1 == t2:\n rhs,rhs_type = t1.binop(symbol,v1,v2)\n else:\n rhs,rhs_type = t1.binopMixed(symbol,v1,v2)\n \n lhs = self.unique()\n self.emit('%s %s = %s;\\n'%(\n rhs_type.cxxtype,\n lhs,\n rhs))\n print self.__body\n self.push(lhs,rhs_type)\n return \n\n ##################################################################\n # MEMBER BINARY_XXX #\n ##################################################################\n def BINARY_ADD(self,pc):\n return self.binop(pc,'+')\n def BINARY_SUBTRACT(self,pc):\n return self.binop(pc,'-')\n def BINARY_MULTIPLY(self,pc):\n return self.binop(pc,'*')\n def BINARY_DIVIDE(self,pc):\n return self.binop(pc,'/')\n def BINARY_MODULO(self,pc):\n return self.binop(pc,'%')\n def BINARY_SUBSCR(self,pc):\n return self.binop(pc,'[]')\n def COMPARE_OP(self,pc,opname):\n symbol = self.cmp_op(opname) # convert numeric to name\n return self.binop(pc,symbol)\n\n\n ##################################################################\n # MEMBER PRINT_ITEM #\n ##################################################################\n def PRINT_ITEM(self,pc):\n # Printing correctly is tricky... best to let Python\n # do the real work here\n w = self.unique()\n self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n self.emit('if (PyFile_SoftSpace(%s,1)) PyFile_WriteString(\" \",%s);'%(w,w))\n v,t = self.pop()\n\n py = self.unique()\n self.emit('PyObject* %s = %s;'%(py, t.outbound(v)))\n self.emit('PyFile_WriteObject(%s,%s,Py_PRINT_RAW);'%(\n py,w))\n self.emit('Py_XDECREF(%s);'%py)\n return\n\n\n ##################################################################\n # MEMBER PRINT_NEWLINE #\n ##################################################################\n def PRINT_NEWLINE(self,pc):\n # Printing correctly is tricky... best to let Python\n # do the real work here\n w = self.unique()\n self.emit('PyObject* %s = PySys_GetObject(\"stdout\");'%w)\n self.emit('PyFile_WriteString(\"\\\\n\",%s);'%w);\n self.emit('PyFile_SoftSpace(%s,0);'%w);\n return\n \n ##################################################################\n # MEMBER SET_LINENO #\n ##################################################################\n def SET_LINENO(self,pc,lineno):\n self.emit('// %s:%d'%(self.codeobject.co_filename,lineno))\n return\n\n ##################################################################\n # MEMBER POP_TOP #\n ##################################################################\n def POP_TOP(self,pc):\n v,t = self.pop()\n return\n\n ##################################################################\n # MEMBER LOAD_CONST #\n ##################################################################\n def LOAD_CONST(self,pc,consti):\n # Fetch the constant\n k = self.consts[consti]\n t = type(k)\n print 'LOAD_CONST',repr(k),t\n\n # Fetch a None is just skipped\n if t == NoneType:\n self.push('',t) \n return\n\n self.emit_value(k)\n return\n\n\n ##################################################################\n # MEMBER LOAD_FAST #\n ##################################################################\n def LOAD_FAST(self,pc,var_num):\n v = self.stack[var_num]\n t = self.types[var_num]\n print 'LOADFAST',var_num,v,t\n if t.refcount:\n self.emit('Py_XINCREF(%s);'%v)\n self.push(v,t)\n return\n\n ##################################################################\n # MEMBER LOAD_GLOBAL #\n ##################################################################\n def LOAD_GLOBAL(self,pc,var_num):\n # Figure out the name and load it\n try:\n F = self.function.func_globals[self.codeobject.co_names[var_num]]\n except:\n F = __builtins__[self.codeobject.co_names[var_num]]\n\n # For functions, we see if we know about this function\n if callable(F):\n self.push(F,type(F))\n return\n\n # We need the name of the module that matches\n # the global state for the function and\n # the name of the variable\n module_name,var_name = self.global_info(var_num)\n\n # We hope it's type is correct\n t = type(F)\n descriptor = typedefs[t]\n native = self.unique()\n py = self.unique()\n mod = self.unique()\n\n self.emit('')\n self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n mod,module_name))\n self.emit('PyObject* %s = PyObject_GetAttrString(%s,\"%s\");'%(\n py,mod,var_name))\n self.emit('%s %s = %s;'%(\n descriptor.cxxtype,\n native,\n descriptor.inbound%py))\n\n self.push(native,t)\n return\n\n def SETUP_LOOP(self,pc,delta):\n \"Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of delta bytes.\"\n return\n\n def FOR_LOOP(self,pc,delta):\n \"Iterate over a sequence. TOS is the current index, TOS1 the sequence. First, the next element is computed. If the sequence is exhausted, increment byte code counter by delta. Otherwise, push the sequence, the incremented counter, and the current item onto the stack.\"\n # Pull off control variable and range info\n v2,t2 = self.pop()\n v1,t1 = self.pop()\n self.emit('for(%s=%s.low; %s<%s.high; %s += %s.step) {'%(\n v2,v1,v2,v1,v2,v1))\n\n # Put range back on for assignment\n self.push(v2,t2)\n return\n\n def JUMP_ABSOLUTE(self,pc,target):\n \"Set byte code counter to target.\"\n self.emit('}')\n return\n\n def POP_BLOCK(self,pc):\n \"Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.\"\n return\n\n\n ##################################################################\n # MEMBER STORE_FAST #\n ##################################################################\n def STORE_FAST(self,pc,var_num):\n\n v,t = self.pop()\n print 'STORE FAST',var_num,v,t\n\n save = self.stack[var_num]\n saveT = self.types[var_num]\n\n # See if type is same....\n # Note that None means no assignment made yet\n if saveT == None or t == saveT:\n if t.refcount:\n self.emit('Py_XINCREF(%s);'%v)\n self.emit('Py_XDECREF(%s);'%save)\n self.emit('%s = %s;\\n'%(save,v))\n self.types[var_num] = t\n return\n\n raise TypeError,(t,saveT)\n\n ##################################################################\n # MEMBER STORE_GLOBAL #\n ##################################################################\n def STORE_GLOBAL(self,pc,var_num):\n\n # We need the name of the module that matches\n # the global state for the function and\n # the name of the variable\n module_name,var_name = self.global_info(var_num)\n\n # Convert the value to Python object\n v,t = self.pop()\n descriptor = typedefs[t]\n py = self.unique()\n self.emit('PyObject* %s = %s;'%(\n py,\n descriptor.outbound%v))\n mod = self.unique()\n self.emit('PyObject* %s = PyImport_ImportModule(\"%s\");'%(\n mod,module_name))\n self.emit('PyObject_SetAttrString(%s,\"%s\",%s);'%(\n mod,var_name,py))\n self.emit('Py_DECREF(%s);'%py)\n return\n\n ##################################################################\n # MEMBER CALL_FUNCTION #\n ##################################################################\n def CALL_FUNCTION(self,pc,argc):\n # Pull args off stack\n args = []\n types = []\n for i in range(argc):\n v,t = self.pop()\n args = [v]+args\n types = [t]+types\n \n # Pull function object off stack and get descriptor\n f,t = self.pop()\n signature = (f,tuple(types))\n descriptor = self.function_by_signature(signature)\n #self.prerequisites += descriptor['prerequisite']+'\\n'\n \n # Build a rhs\n rhs = descriptor.code%string.join(args,',')\n\n # Build a statement\n temp = self.unique()\n self.emit('%s %s = %s;\\n'%(\n descriptor.return_type.cxxtype,\n temp,\n rhs))\n\n self.push(temp,descriptor.return_type)\n return\n\n\n ##################################################################\n # MEMBER JUMP_IF_FALSE #\n ##################################################################\n def JUMP_IF_FALSE(self,pc,delta):\n v,t = self.pop()\n self.push(v,t)\n # We need to do some work when we get to the\n # else part (put the value that's gonna get\n # popped back on the stack, emit } else {,\n # ...)\n action = lambda v=v,t=t,self=self: (\n self.emit('} else {'),\n self.push(v,t),\n )\n self.post(pc+delta,action)\n if t != IntType: raise TypeError, 'Invalid comparison type %s'%t\n self.emit('if (%s) {\\n'%v)\n return\n \n\n ##################################################################\n # MEMBER JUMP_FORWARD #\n ##################################################################\n def JUMP_FORWARD(self,pc,delta):\n # We need to close the if after the delta\n action = lambda self=self: (\n self.emit('}'),\n )\n self.post(pc+delta,action)\n return\n \n ##################################################################\n # MEMBER RETURN_VALUE #\n ##################################################################\n def RETURN_VALUE(self,pc):\n v,t = self.pop()\n if hasattr(self,'rtype'):\n print v,t\n if t == NoneType: return # just the extra return\n raise ValueError,'multiple returns'\n self.rtype = t\n if t == NoneType:\n self.emit('return;')\n else:\n self.emit('return %s;'%v)\n print 'return with',v\n return\n\n", + "methods": [ + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 20, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , code , return_type , support = '' )", + "filename": "bytecodecompiler.py", + "nloc": 5, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "code", + "return_type", + "support" + ], + "start_line": 32, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "opcodize", + "long_name": "opcodize( s )", + "filename": "bytecodecompiler.py", + "nloc": 16, + "complexity": 3, + "token_count": 92, + "parameters": [ + "s" + ], + "start_line": 159, + "end_line": 174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "listing", + "long_name": "listing( f )", + "filename": "bytecodecompiler.py", + "nloc": 29, + "complexity": 9, + "token_count": 166, + "parameters": [ + "f" + ], + "start_line": 181, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "fetch", + "long_name": "fetch( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 215, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "execute", + "long_name": "execute( self , pc , opcode , argument )", + "filename": "bytecodecompiler.py", + "nloc": 7, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "pc", + "opcode", + "argument" + ], + "start_line": 225, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "evaluate", + "long_name": "evaluate( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 233, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "cmp_op", + "long_name": "cmp_op( self , opname )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "opname" + ], + "start_line": 248, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "STOP_CODE", + "long_name": "STOP_CODE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 251, + "end_line": 253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_TOP", + "long_name": "POP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 254, + "end_line": 256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_TWO", + "long_name": "ROT_TWO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 258, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_THREE", + "long_name": "ROT_THREE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 262, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_FOUR", + "long_name": "ROT_FOUR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 266, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DUP_TOP", + "long_name": "DUP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 270, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_POSITIVE", + "long_name": "UNARY_POSITIVE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 276, + "end_line": 278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_NEGATIVE", + "long_name": "UNARY_NEGATIVE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 280, + "end_line": 282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_NOT", + "long_name": "UNARY_NOT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 284, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_CONVERT", + "long_name": "UNARY_CONVERT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 288, + "end_line": 290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_INVERT", + "long_name": "UNARY_INVERT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 292, + "end_line": 294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_POWER", + "long_name": "BINARY_POWER( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 298, + "end_line": 300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MULTIPLY", + "long_name": "BINARY_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 302, + "end_line": 304, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_DIVIDE", + "long_name": "BINARY_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 306, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MODULO", + "long_name": "BINARY_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 310, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_ADD", + "long_name": "BINARY_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 314, + "end_line": 316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBTRACT", + "long_name": "BINARY_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 318, + "end_line": 320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBSCR", + "long_name": "BINARY_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 322, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_LSHIFT", + "long_name": "BINARY_LSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 326, + "end_line": 328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_RSHIFT", + "long_name": "BINARY_RSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 330, + "end_line": 332, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_AND", + "long_name": "BINARY_AND( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 334, + "end_line": 336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_XOR", + "long_name": "BINARY_XOR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 338, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_OR", + "long_name": "BINARY_OR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 342, + "end_line": 344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_POWER", + "long_name": "INPLACE_POWER( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 348, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_MULTIPLY", + "long_name": "INPLACE_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 352, + "end_line": 354, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_DIVIDE", + "long_name": "INPLACE_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 356, + "end_line": 358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_MODULO", + "long_name": "INPLACE_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 360, + "end_line": 362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_ADD", + "long_name": "INPLACE_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 364, + "end_line": 366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_SUBTRACT", + "long_name": "INPLACE_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 368, + "end_line": 370, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_LSHIFT", + "long_name": "INPLACE_LSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 372, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_RSHIFT", + "long_name": "INPLACE_RSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 376, + "end_line": 378, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_AND", + "long_name": "INPLACE_AND( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 380, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_XOR", + "long_name": "INPLACE_XOR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 384, + "end_line": 386, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_OR", + "long_name": "INPLACE_OR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 388, + "end_line": 390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_0", + "long_name": "SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 394, + "end_line": 396, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_1", + "long_name": "SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 398, + "end_line": 400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_2", + "long_name": "SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 402, + "end_line": 404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_3", + "long_name": "SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 406, + "end_line": 408, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_0", + "long_name": "STORE_SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 412, + "end_line": 414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_1", + "long_name": "STORE_SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 416, + "end_line": 418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_2", + "long_name": "STORE_SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 420, + "end_line": 422, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_3", + "long_name": "STORE_SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 424, + "end_line": 426, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_0", + "long_name": "DELETE_SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 428, + "end_line": 430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_1", + "long_name": "DELETE_SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 432, + "end_line": 434, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_2", + "long_name": "DELETE_SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 436, + "end_line": 438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_3", + "long_name": "DELETE_SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 440, + "end_line": 442, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SUBSCR", + "long_name": "STORE_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 444, + "end_line": 446, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SUBSCR", + "long_name": "DELETE_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 448, + "end_line": 450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_EXPR", + "long_name": "PRINT_EXPR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 452, + "end_line": 454, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM", + "long_name": "PRINT_ITEM( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 456, + "end_line": 458, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM_TO", + "long_name": "PRINT_ITEM_TO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 460, + "end_line": 462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE", + "long_name": "PRINT_NEWLINE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 464, + "end_line": 466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE_TO", + "long_name": "PRINT_NEWLINE_TO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 468, + "end_line": 470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BREAK_LOOP", + "long_name": "BREAK_LOOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 472, + "end_line": 474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_LOCALS", + "long_name": "LOAD_LOCALS( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 476, + "end_line": 478, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "RETURN_VALUE", + "long_name": "RETURN_VALUE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 480, + "end_line": 482, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_STAR", + "long_name": "IMPORT_STAR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 484, + "end_line": 486, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "EXEC_STMT", + "long_name": "EXEC_STMT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 488, + "end_line": 490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_BLOCK", + "long_name": "POP_BLOCK( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 492, + "end_line": 494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "END_FINALLY", + "long_name": "END_FINALLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 496, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_CLASS", + "long_name": "BUILD_CLASS( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 500, + "end_line": 502, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_NAME", + "long_name": "STORE_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 506, + "end_line": 508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_NAME", + "long_name": "DELETE_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 510, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNPACK_SEQUENCE", + "long_name": "UNPACK_SEQUENCE( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 514, + "end_line": 516, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DUP_TOPX", + "long_name": "DUP_TOPX( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 518, + "end_line": 520, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_ATTR", + "long_name": "STORE_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 522, + "end_line": 524, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_ATTR", + "long_name": "DELETE_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 526, + "end_line": 528, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_GLOBAL", + "long_name": "STORE_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 530, + "end_line": 532, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_GLOBAL", + "long_name": "DELETE_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 534, + "end_line": 536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CONST", + "long_name": "LOAD_CONST( self , pc , consti )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "consti" + ], + "start_line": 538, + "end_line": 540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_NAME", + "long_name": "LOAD_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 542, + "end_line": 544, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_TUPLE", + "long_name": "BUILD_TUPLE( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 546, + "end_line": 548, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_LIST", + "long_name": "BUILD_LIST( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 550, + "end_line": 552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_MAP", + "long_name": "BUILD_MAP( self , pc , zero )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "zero" + ], + "start_line": 554, + "end_line": 556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_ATTR", + "long_name": "LOAD_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 558, + "end_line": 560, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "COMPARE_OP", + "long_name": "COMPARE_OP( self , pc , opname )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "opname" + ], + "start_line": 562, + "end_line": 564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_NAME", + "long_name": "IMPORT_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 566, + "end_line": 568, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_FROM", + "long_name": "IMPORT_FROM( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 570, + "end_line": 572, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_FORWARD", + "long_name": "JUMP_FORWARD( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 574, + "end_line": 576, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_TRUE", + "long_name": "JUMP_IF_TRUE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 578, + "end_line": 580, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_FALSE", + "long_name": "JUMP_IF_FALSE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 582, + "end_line": 584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_ABSOLUTE", + "long_name": "JUMP_ABSOLUTE( self , pc , target )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "target" + ], + "start_line": 586, + "end_line": 588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "FOR_LOOP", + "long_name": "FOR_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 590, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_GLOBAL", + "long_name": "LOAD_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 594, + "end_line": 596, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_LOOP", + "long_name": "SETUP_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 598, + "end_line": 600, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_EXCEPT", + "long_name": "SETUP_EXCEPT( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 602, + "end_line": 604, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_FINALLY", + "long_name": "SETUP_FINALLY( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 606, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_FAST", + "long_name": "LOAD_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 610, + "end_line": 612, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_FAST", + "long_name": "STORE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 614, + "end_line": 616, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_FAST", + "long_name": "DELETE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 618, + "end_line": 620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CLOSURE", + "long_name": "LOAD_CLOSURE( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 622, + "end_line": 624, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_DEREF", + "long_name": "LOAD_DEREF( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 626, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_DEREF", + "long_name": "STORE_DEREF( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 630, + "end_line": 632, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SET_LINENO", + "long_name": "SET_LINENO( self , pc , lineno )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "lineno" + ], + "start_line": 634, + "end_line": 636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "RAISE_VARARGS", + "long_name": "RAISE_VARARGS( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 638, + "end_line": 640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION", + "long_name": "CALL_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 642, + "end_line": 644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "MAKE_FUNCTION", + "long_name": "MAKE_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 646, + "end_line": 648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "MAKE_CLOSURE", + "long_name": "MAKE_CLOSURE( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 650, + "end_line": 652, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_SLICE", + "long_name": "BUILD_SLICE( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 654, + "end_line": 656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "EXTENDED_ARG", + "long_name": "EXTENDED_ARG( self , pc , ext )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "ext" + ], + "start_line": 658, + "end_line": 660, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_VAR", + "long_name": "CALL_FUNCTION_VAR( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 662, + "end_line": 664, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_KW", + "long_name": "CALL_FUNCTION_KW( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 666, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_VAR_KW", + "long_name": "CALL_FUNCTION_VAR_KW( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 670, + "end_line": 672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "typedef_by_value", + "long_name": "typedef_by_value( self , v )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "v" + ], + "start_line": 684, + "end_line": 685, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , function , signature , name = None )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 2, + "token_count": 72, + "parameters": [ + "self", + "function", + "signature", + "name" + ], + "start_line": 690, + "end_line": 700, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "evaluate", + "long_name": "evaluate( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 3, + "token_count": 52, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 705, + "end_line": 711, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "generate", + "long_name": "generate( self )", + "filename": "bytecodecompiler.py", + "nloc": 51, + "complexity": 14, + "token_count": 373, + "parameters": [ + "self" + ], + "start_line": 716, + "end_line": 798, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "wrapped_code", + "long_name": "wrapped_code( self )", + "filename": "bytecodecompiler.py", + "nloc": 52, + "complexity": 5, + "token_count": 294, + "parameters": [ + "self" + ], + "start_line": 804, + "end_line": 869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 1 + }, + { + "name": "indent", + "long_name": "indent( self )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 871, + "end_line": 873, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "dedent", + "long_name": "dedent( self )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 875, + "end_line": 877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "emit", + "long_name": "emit( self , s )", + "filename": "bytecodecompiler.py", + "nloc": 5, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self", + "s" + ], + "start_line": 882, + "end_line": 886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "push", + "long_name": "push( self , v , t )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "v", + "t" + ], + "start_line": 891, + "end_line": 894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "pop", + "long_name": "pop( self )", + "filename": "bytecodecompiler.py", + "nloc": 8, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 899, + "end_line": 906, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "pushTuple", + "long_name": "pushTuple( self , V , T )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 40, + "parameters": [ + "self", + "V", + "T" + ], + "start_line": 911, + "end_line": 916, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "popTuple", + "long_name": "popTuple( self )", + "filename": "bytecodecompiler.py", + "nloc": 8, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 922, + "end_line": 929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "multiarg", + "long_name": "multiarg( self )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 933, + "end_line": 934, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "unique", + "long_name": "unique( self )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 939, + "end_line": 941, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "post", + "long_name": "post( self , pc , action )", + "filename": "bytecodecompiler.py", + "nloc": 5, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "pc", + "action" + ], + "start_line": 946, + "end_line": 950, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "emit_value", + "long_name": "emit_value( self , v )", + "filename": "bytecodecompiler.py", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self", + "v" + ], + "start_line": 955, + "end_line": 966, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "global_info", + "long_name": "global_info( self , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 4, + "token_count": 73, + "parameters": [ + "self", + "var_num" + ], + "start_line": 971, + "end_line": 984, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "codeup", + "long_name": "codeup( self , rhs , rhs_type )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "self", + "rhs", + "rhs_type" + ], + "start_line": 990, + "end_line": 998, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "binop", + "long_name": "binop( self , pc , symbol )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 2, + "token_count": 73, + "parameters": [ + "self", + "pc", + "symbol" + ], + "start_line": 1004, + "end_line": 1014, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "BINARY_ADD", + "long_name": "BINARY_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 1019, + "end_line": 1020, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBTRACT", + "long_name": "BINARY_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 1021, + "end_line": 1022, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MULTIPLY", + "long_name": "BINARY_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 52, + "parameters": [ + "self", + "pc" + ], + "start_line": 1023, + "end_line": 1025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_DIVIDE", + "long_name": "BINARY_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 1026, + "end_line": 1027, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MODULO", + "long_name": "BINARY_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 1028, + "end_line": 1029, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBSCR", + "long_name": "BINARY_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "pc" + ], + "start_line": 1030, + "end_line": 1040, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "STORE_SUBSCR", + "long_name": "STORE_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 13, + "complexity": 2, + "token_count": 97, + "parameters": [ + "self", + "pc" + ], + "start_line": 1042, + "end_line": 1055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "COMPARE_OP", + "long_name": "COMPARE_OP( self , pc , opname )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "pc", + "opname" + ], + "start_line": 1057, + "end_line": 1059, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM", + "long_name": "PRINT_ITEM( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 1, + "token_count": 88, + "parameters": [ + "self", + "pc" + ], + "start_line": 1065, + "end_line": 1078, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE", + "long_name": "PRINT_NEWLINE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 41, + "parameters": [ + "self", + "pc" + ], + "start_line": 1084, + "end_line": 1091, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "SET_LINENO", + "long_name": "SET_LINENO( self , pc , lineno )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "pc", + "lineno" + ], + "start_line": 1096, + "end_line": 1098, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_TOP", + "long_name": "POP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "pc" + ], + "start_line": 1103, + "end_line": 1105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CONST", + "long_name": "LOAD_CONST( self , pc , consti )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "pc", + "consti" + ], + "start_line": 1110, + "end_line": 1122, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "BUILD_TUPLE", + "long_name": "BUILD_TUPLE( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 12, + "complexity": 2, + "token_count": 72, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 1128, + "end_line": 1139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "LOAD_FAST", + "long_name": "LOAD_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 12, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1144, + "end_line": 1155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "LOAD_GLOBAL", + "long_name": "LOAD_GLOBAL( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 25, + "complexity": 3, + "token_count": 165, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1160, + "end_line": 1195, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "SETUP_LOOP", + "long_name": "SETUP_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1197, + "end_line": 1199, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "FOR_LOOP", + "long_name": "FOR_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 8, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1201, + "end_line": 1211, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "JUMP_ABSOLUTE", + "long_name": "JUMP_ABSOLUTE( self , pc , target )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "pc", + "target" + ], + "start_line": 1213, + "end_line": 1216, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "POP_BLOCK", + "long_name": "POP_BLOCK( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "pc" + ], + "start_line": 1218, + "end_line": 1220, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_FAST", + "long_name": "STORE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1226, + "end_line": 1244, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "STORE_GLOBAL", + "long_name": "STORE_GLOBAL( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 15, + "complexity": 1, + "token_count": 99, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1249, + "end_line": 1269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION", + "long_name": "CALL_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 18, + "complexity": 2, + "token_count": 125, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 1274, + "end_line": 1300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_FALSE", + "long_name": "JUMP_IF_FALSE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1306, + "end_line": 1320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "JUMP_FORWARD", + "long_name": "JUMP_FORWARD( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1326, + "end_line": 1332, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "RETURN_VALUE", + "long_name": "RETURN_VALUE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 13, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "pc" + ], + "start_line": 1337, + "end_line": 1349, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "__repr__", + "long_name": "__repr__( self )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self" + ], + "start_line": 19, + "end_line": 20, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , code , return_type , support = '' )", + "filename": "bytecodecompiler.py", + "nloc": 5, + "complexity": 1, + "token_count": 29, + "parameters": [ + "self", + "code", + "return_type", + "support" + ], + "start_line": 32, + "end_line": 36, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "opcodize", + "long_name": "opcodize( s )", + "filename": "bytecodecompiler.py", + "nloc": 16, + "complexity": 3, + "token_count": 92, + "parameters": [ + "s" + ], + "start_line": 159, + "end_line": 174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 0 + }, + { + "name": "listing", + "long_name": "listing( f )", + "filename": "bytecodecompiler.py", + "nloc": 29, + "complexity": 9, + "token_count": 166, + "parameters": [ + "f" + ], + "start_line": 181, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 0 + }, + { + "name": "fetch", + "long_name": "fetch( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 215, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "execute", + "long_name": "execute( self , pc , opcode , argument )", + "filename": "bytecodecompiler.py", + "nloc": 7, + "complexity": 2, + "token_count": 54, + "parameters": [ + "self", + "pc", + "opcode", + "argument" + ], + "start_line": 225, + "end_line": 231, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "evaluate", + "long_name": "evaluate( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 3, + "token_count": 54, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 233, + "end_line": 241, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "cmp_op", + "long_name": "cmp_op( self , opname )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 14, + "parameters": [ + "self", + "opname" + ], + "start_line": 248, + "end_line": 249, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "STOP_CODE", + "long_name": "STOP_CODE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 251, + "end_line": 253, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_TOP", + "long_name": "POP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 254, + "end_line": 256, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_TWO", + "long_name": "ROT_TWO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 258, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_THREE", + "long_name": "ROT_THREE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 262, + "end_line": 264, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "ROT_FOUR", + "long_name": "ROT_FOUR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 266, + "end_line": 268, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DUP_TOP", + "long_name": "DUP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 270, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_POSITIVE", + "long_name": "UNARY_POSITIVE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 276, + "end_line": 278, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_NEGATIVE", + "long_name": "UNARY_NEGATIVE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 280, + "end_line": 282, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_NOT", + "long_name": "UNARY_NOT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 284, + "end_line": 286, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_CONVERT", + "long_name": "UNARY_CONVERT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 288, + "end_line": 290, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNARY_INVERT", + "long_name": "UNARY_INVERT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 292, + "end_line": 294, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_POWER", + "long_name": "BINARY_POWER( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 298, + "end_line": 300, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MULTIPLY", + "long_name": "BINARY_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 302, + "end_line": 304, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_DIVIDE", + "long_name": "BINARY_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 306, + "end_line": 308, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MODULO", + "long_name": "BINARY_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 310, + "end_line": 312, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_ADD", + "long_name": "BINARY_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 314, + "end_line": 316, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBTRACT", + "long_name": "BINARY_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 318, + "end_line": 320, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBSCR", + "long_name": "BINARY_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 322, + "end_line": 324, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_LSHIFT", + "long_name": "BINARY_LSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 326, + "end_line": 328, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_RSHIFT", + "long_name": "BINARY_RSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 330, + "end_line": 332, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_AND", + "long_name": "BINARY_AND( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 334, + "end_line": 336, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_XOR", + "long_name": "BINARY_XOR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 338, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BINARY_OR", + "long_name": "BINARY_OR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 342, + "end_line": 344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_POWER", + "long_name": "INPLACE_POWER( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 348, + "end_line": 350, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_MULTIPLY", + "long_name": "INPLACE_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 352, + "end_line": 354, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_DIVIDE", + "long_name": "INPLACE_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 356, + "end_line": 358, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_MODULO", + "long_name": "INPLACE_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 360, + "end_line": 362, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_ADD", + "long_name": "INPLACE_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 364, + "end_line": 366, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_SUBTRACT", + "long_name": "INPLACE_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 368, + "end_line": 370, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_LSHIFT", + "long_name": "INPLACE_LSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 372, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_RSHIFT", + "long_name": "INPLACE_RSHIFT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 376, + "end_line": 378, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_AND", + "long_name": "INPLACE_AND( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 380, + "end_line": 382, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_XOR", + "long_name": "INPLACE_XOR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 384, + "end_line": 386, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "INPLACE_OR", + "long_name": "INPLACE_OR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 388, + "end_line": 390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_0", + "long_name": "SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 394, + "end_line": 396, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_1", + "long_name": "SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 398, + "end_line": 400, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_2", + "long_name": "SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 402, + "end_line": 404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SLICE_3", + "long_name": "SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 406, + "end_line": 408, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_0", + "long_name": "STORE_SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 412, + "end_line": 414, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_1", + "long_name": "STORE_SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 416, + "end_line": 418, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_2", + "long_name": "STORE_SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 420, + "end_line": 422, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SLICE_3", + "long_name": "STORE_SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 424, + "end_line": 426, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_0", + "long_name": "DELETE_SLICE_0( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 428, + "end_line": 430, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_1", + "long_name": "DELETE_SLICE_1( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 432, + "end_line": 434, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_2", + "long_name": "DELETE_SLICE_2( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 436, + "end_line": 438, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SLICE_3", + "long_name": "DELETE_SLICE_3( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 440, + "end_line": 442, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SUBSCR", + "long_name": "STORE_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 444, + "end_line": 446, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_SUBSCR", + "long_name": "DELETE_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 448, + "end_line": 450, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_EXPR", + "long_name": "PRINT_EXPR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 452, + "end_line": 454, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM", + "long_name": "PRINT_ITEM( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 456, + "end_line": 458, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM_TO", + "long_name": "PRINT_ITEM_TO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 460, + "end_line": 462, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE", + "long_name": "PRINT_NEWLINE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 464, + "end_line": 466, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE_TO", + "long_name": "PRINT_NEWLINE_TO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 468, + "end_line": 470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BREAK_LOOP", + "long_name": "BREAK_LOOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 472, + "end_line": 474, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_LOCALS", + "long_name": "LOAD_LOCALS( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 476, + "end_line": 478, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "RETURN_VALUE", + "long_name": "RETURN_VALUE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 480, + "end_line": 482, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_STAR", + "long_name": "IMPORT_STAR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 484, + "end_line": 486, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "EXEC_STMT", + "long_name": "EXEC_STMT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 488, + "end_line": 490, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_BLOCK", + "long_name": "POP_BLOCK( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 492, + "end_line": 494, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "END_FINALLY", + "long_name": "END_FINALLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 496, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_CLASS", + "long_name": "BUILD_CLASS( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self", + "pc" + ], + "start_line": 500, + "end_line": 502, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_NAME", + "long_name": "STORE_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 506, + "end_line": 508, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_NAME", + "long_name": "DELETE_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 510, + "end_line": 512, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "UNPACK_SEQUENCE", + "long_name": "UNPACK_SEQUENCE( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 514, + "end_line": 516, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DUP_TOPX", + "long_name": "DUP_TOPX( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 518, + "end_line": 520, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_ATTR", + "long_name": "STORE_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 522, + "end_line": 524, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_ATTR", + "long_name": "DELETE_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 526, + "end_line": 528, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_GLOBAL", + "long_name": "STORE_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 530, + "end_line": 532, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_GLOBAL", + "long_name": "DELETE_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 534, + "end_line": 536, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CONST", + "long_name": "LOAD_CONST( self , pc , consti )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "consti" + ], + "start_line": 538, + "end_line": 540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_NAME", + "long_name": "LOAD_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 542, + "end_line": 544, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_TUPLE", + "long_name": "BUILD_TUPLE( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 546, + "end_line": 548, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_LIST", + "long_name": "BUILD_LIST( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 550, + "end_line": 552, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_MAP", + "long_name": "BUILD_MAP( self , pc , zero )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "zero" + ], + "start_line": 554, + "end_line": 556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_ATTR", + "long_name": "LOAD_ATTR( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 558, + "end_line": 560, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "COMPARE_OP", + "long_name": "COMPARE_OP( self , pc , opname )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "opname" + ], + "start_line": 562, + "end_line": 564, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_NAME", + "long_name": "IMPORT_NAME( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 566, + "end_line": 568, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "IMPORT_FROM", + "long_name": "IMPORT_FROM( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 570, + "end_line": 572, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_FORWARD", + "long_name": "JUMP_FORWARD( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 574, + "end_line": 576, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_TRUE", + "long_name": "JUMP_IF_TRUE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 578, + "end_line": 580, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_FALSE", + "long_name": "JUMP_IF_FALSE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 582, + "end_line": 584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "JUMP_ABSOLUTE", + "long_name": "JUMP_ABSOLUTE( self , pc , target )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "target" + ], + "start_line": 586, + "end_line": 588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "FOR_LOOP", + "long_name": "FOR_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 590, + "end_line": 592, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_GLOBAL", + "long_name": "LOAD_GLOBAL( self , pc , namei )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "namei" + ], + "start_line": 594, + "end_line": 596, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_LOOP", + "long_name": "SETUP_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 598, + "end_line": 600, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_EXCEPT", + "long_name": "SETUP_EXCEPT( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 602, + "end_line": 604, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SETUP_FINALLY", + "long_name": "SETUP_FINALLY( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 606, + "end_line": 608, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_FAST", + "long_name": "LOAD_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 610, + "end_line": 612, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_FAST", + "long_name": "STORE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 614, + "end_line": 616, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "DELETE_FAST", + "long_name": "DELETE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 618, + "end_line": 620, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CLOSURE", + "long_name": "LOAD_CLOSURE( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 622, + "end_line": 624, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_DEREF", + "long_name": "LOAD_DEREF( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 626, + "end_line": 628, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_DEREF", + "long_name": "STORE_DEREF( self , pc , i )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "i" + ], + "start_line": 630, + "end_line": 632, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "SET_LINENO", + "long_name": "SET_LINENO( self , pc , lineno )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "lineno" + ], + "start_line": 634, + "end_line": 636, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "RAISE_VARARGS", + "long_name": "RAISE_VARARGS( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 638, + "end_line": 640, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION", + "long_name": "CALL_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 642, + "end_line": 644, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "MAKE_FUNCTION", + "long_name": "MAKE_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 646, + "end_line": 648, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "MAKE_CLOSURE", + "long_name": "MAKE_CLOSURE( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 650, + "end_line": 652, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "BUILD_SLICE", + "long_name": "BUILD_SLICE( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 654, + "end_line": 656, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "EXTENDED_ARG", + "long_name": "EXTENDED_ARG( self , pc , ext )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "ext" + ], + "start_line": 658, + "end_line": 660, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_VAR", + "long_name": "CALL_FUNCTION_VAR( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 662, + "end_line": 664, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_KW", + "long_name": "CALL_FUNCTION_KW( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 666, + "end_line": 668, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION_VAR_KW", + "long_name": "CALL_FUNCTION_VAR_KW( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 670, + "end_line": 672, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "typedef_by_value", + "long_name": "typedef_by_value( self , v )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "v" + ], + "start_line": 684, + "end_line": 685, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , function , signature , name = None )", + "filename": "bytecodecompiler.py", + "nloc": 10, + "complexity": 2, + "token_count": 67, + "parameters": [ + "self", + "function", + "signature", + "name" + ], + "start_line": 690, + "end_line": 699, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "evaluate", + "long_name": "evaluate( self , pc , code )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 3, + "token_count": 52, + "parameters": [ + "self", + "pc", + "code" + ], + "start_line": 704, + "end_line": 710, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "generate", + "long_name": "generate( self )", + "filename": "bytecodecompiler.py", + "nloc": 51, + "complexity": 14, + "token_count": 374, + "parameters": [ + "self" + ], + "start_line": 715, + "end_line": 797, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "wrapped_code", + "long_name": "wrapped_code( self )", + "filename": "bytecodecompiler.py", + "nloc": 52, + "complexity": 5, + "token_count": 294, + "parameters": [ + "self" + ], + "start_line": 803, + "end_line": 866, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 64, + "top_nesting_level": 1 + }, + { + "name": "emit", + "long_name": "emit( self , s )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self", + "s" + ], + "start_line": 872, + "end_line": 875, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "push", + "long_name": "push( self , v , t )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "v", + "t" + ], + "start_line": 880, + "end_line": 883, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "pop", + "long_name": "pop( self )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 889, + "end_line": 894, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "unique", + "long_name": "unique( self )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self" + ], + "start_line": 899, + "end_line": 901, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "post", + "long_name": "post( self , pc , action )", + "filename": "bytecodecompiler.py", + "nloc": 5, + "complexity": 2, + "token_count": 41, + "parameters": [ + "self", + "pc", + "action" + ], + "start_line": 906, + "end_line": 910, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "emit_value", + "long_name": "emit_value( self , v )", + "filename": "bytecodecompiler.py", + "nloc": 10, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self", + "v" + ], + "start_line": 915, + "end_line": 926, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "global_info", + "long_name": "global_info( self , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 4, + "token_count": 73, + "parameters": [ + "self", + "var_num" + ], + "start_line": 931, + "end_line": 944, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "binop", + "long_name": "binop( self , pc , symbol )", + "filename": "bytecodecompiler.py", + "nloc": 15, + "complexity": 2, + "token_count": 98, + "parameters": [ + "self", + "pc", + "symbol" + ], + "start_line": 949, + "end_line": 965, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "BINARY_ADD", + "long_name": "BINARY_ADD( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 970, + "end_line": 971, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBTRACT", + "long_name": "BINARY_SUBTRACT( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 972, + "end_line": 973, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MULTIPLY", + "long_name": "BINARY_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 974, + "end_line": 975, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_DIVIDE", + "long_name": "BINARY_DIVIDE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 976, + "end_line": 977, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MODULO", + "long_name": "BINARY_MODULO( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 978, + "end_line": 979, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBSCR", + "long_name": "BINARY_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 16, + "parameters": [ + "self", + "pc" + ], + "start_line": 980, + "end_line": 981, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "COMPARE_OP", + "long_name": "COMPARE_OP( self , pc , opname )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "pc", + "opname" + ], + "start_line": 982, + "end_line": 984, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "PRINT_ITEM", + "long_name": "PRINT_ITEM( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 1, + "token_count": 88, + "parameters": [ + "self", + "pc" + ], + "start_line": 990, + "end_line": 1003, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + }, + { + "name": "PRINT_NEWLINE", + "long_name": "PRINT_NEWLINE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 41, + "parameters": [ + "self", + "pc" + ], + "start_line": 1009, + "end_line": 1016, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "SET_LINENO", + "long_name": "SET_LINENO( self , pc , lineno )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 26, + "parameters": [ + "self", + "pc", + "lineno" + ], + "start_line": 1021, + "end_line": 1023, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "POP_TOP", + "long_name": "POP_TOP( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "pc" + ], + "start_line": 1028, + "end_line": 1030, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "LOAD_CONST", + "long_name": "LOAD_CONST( self , pc , consti )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 2, + "token_count": 53, + "parameters": [ + "self", + "pc", + "consti" + ], + "start_line": 1035, + "end_line": 1047, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "LOAD_FAST", + "long_name": "LOAD_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 8, + "complexity": 2, + "token_count": 55, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1053, + "end_line": 1060, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "LOAD_GLOBAL", + "long_name": "LOAD_GLOBAL( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 25, + "complexity": 3, + "token_count": 165, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1065, + "end_line": 1100, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 36, + "top_nesting_level": 1 + }, + { + "name": "SETUP_LOOP", + "long_name": "SETUP_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1102, + "end_line": 1104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "FOR_LOOP", + "long_name": "FOR_LOOP( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 8, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1106, + "end_line": 1116, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "JUMP_ABSOLUTE", + "long_name": "JUMP_ABSOLUTE( self , pc , target )", + "filename": "bytecodecompiler.py", + "nloc": 4, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "pc", + "target" + ], + "start_line": 1118, + "end_line": 1121, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "POP_BLOCK", + "long_name": "POP_BLOCK( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "pc" + ], + "start_line": 1123, + "end_line": 1125, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_FAST", + "long_name": "STORE_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 13, + "complexity": 4, + "token_count": 101, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1131, + "end_line": 1149, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "STORE_GLOBAL", + "long_name": "STORE_GLOBAL( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 15, + "complexity": 1, + "token_count": 99, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1154, + "end_line": 1174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "CALL_FUNCTION", + "long_name": "CALL_FUNCTION( self , pc , argc )", + "filename": "bytecodecompiler.py", + "nloc": 18, + "complexity": 2, + "token_count": 125, + "parameters": [ + "self", + "pc", + "argc" + ], + "start_line": 1179, + "end_line": 1205, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "JUMP_IF_FALSE", + "long_name": "JUMP_IF_FALSE( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 2, + "token_count": 89, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1211, + "end_line": 1225, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "JUMP_FORWARD", + "long_name": "JUMP_FORWARD( self , pc , delta )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 36, + "parameters": [ + "self", + "pc", + "delta" + ], + "start_line": 1231, + "end_line": 1237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "RETURN_VALUE", + "long_name": "RETURN_VALUE( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 13, + "complexity": 4, + "token_count": 69, + "parameters": [ + "self", + "pc" + ], + "start_line": 1242, + "end_line": 1254, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "multiarg", + "long_name": "multiarg( self )", + "filename": "bytecodecompiler.py", + "nloc": 2, + "complexity": 1, + "token_count": 18, + "parameters": [ + "self" + ], + "start_line": 933, + "end_line": 934, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "LOAD_FAST", + "long_name": "LOAD_FAST( self , pc , var_num )", + "filename": "bytecodecompiler.py", + "nloc": 12, + "complexity": 3, + "token_count": 85, + "parameters": [ + "self", + "pc", + "var_num" + ], + "start_line": 1144, + "end_line": 1155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "BUILD_TUPLE", + "long_name": "BUILD_TUPLE( self , pc , count )", + "filename": "bytecodecompiler.py", + "nloc": 12, + "complexity": 2, + "token_count": 72, + "parameters": [ + "self", + "pc", + "count" + ], + "start_line": 1128, + "end_line": 1139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , function , signature , name = None )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 2, + "token_count": 72, + "parameters": [ + "self", + "function", + "signature", + "name" + ], + "start_line": 690, + "end_line": 700, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "generate", + "long_name": "generate( self )", + "filename": "bytecodecompiler.py", + "nloc": 51, + "complexity": 14, + "token_count": 373, + "parameters": [ + "self" + ], + "start_line": 716, + "end_line": 798, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 83, + "top_nesting_level": 1 + }, + { + "name": "emit", + "long_name": "emit( self , s )", + "filename": "bytecodecompiler.py", + "nloc": 5, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self", + "s" + ], + "start_line": 882, + "end_line": 886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "pop", + "long_name": "pop( self )", + "filename": "bytecodecompiler.py", + "nloc": 8, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 899, + "end_line": 906, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "binop", + "long_name": "binop( self , pc , symbol )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 2, + "token_count": 73, + "parameters": [ + "self", + "pc", + "symbol" + ], + "start_line": 1004, + "end_line": 1014, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "codeup", + "long_name": "codeup( self , rhs , rhs_type )", + "filename": "bytecodecompiler.py", + "nloc": 9, + "complexity": 1, + "token_count": 45, + "parameters": [ + "self", + "rhs", + "rhs_type" + ], + "start_line": 990, + "end_line": 998, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "BINARY_SUBSCR", + "long_name": "BINARY_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 11, + "complexity": 2, + "token_count": 78, + "parameters": [ + "self", + "pc" + ], + "start_line": 1030, + "end_line": 1040, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "wrapped_code", + "long_name": "wrapped_code( self )", + "filename": "bytecodecompiler.py", + "nloc": 52, + "complexity": 5, + "token_count": 294, + "parameters": [ + "self" + ], + "start_line": 804, + "end_line": 869, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 66, + "top_nesting_level": 1 + }, + { + "name": "BINARY_MULTIPLY", + "long_name": "BINARY_MULTIPLY( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 52, + "parameters": [ + "self", + "pc" + ], + "start_line": 1023, + "end_line": 1025, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "pushTuple", + "long_name": "pushTuple( self , V , T )", + "filename": "bytecodecompiler.py", + "nloc": 6, + "complexity": 1, + "token_count": 40, + "parameters": [ + "self", + "V", + "T" + ], + "start_line": 911, + "end_line": 916, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "dedent", + "long_name": "dedent( self )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 875, + "end_line": 877, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "popTuple", + "long_name": "popTuple( self )", + "filename": "bytecodecompiler.py", + "nloc": 8, + "complexity": 1, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 922, + "end_line": 929, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "indent", + "long_name": "indent( self )", + "filename": "bytecodecompiler.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 871, + "end_line": 873, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "STORE_SUBSCR", + "long_name": "STORE_SUBSCR( self , pc )", + "filename": "bytecodecompiler.py", + "nloc": 13, + "complexity": 2, + "token_count": 97, + "parameters": [ + "self", + "pc" + ], + "start_line": 1042, + "end_line": 1055, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 14, + "top_nesting_level": 1 + } + ], + "nloc": 934, + "complexity": 211, + "token_count": 5135, + "diff_parsed": { + "added": [ + " self.__indent = 1", + " arglen = self.codeobject.co_argcount", + " code += ' if ( !(%s) ) {\\n'% \\", + " #code += ' PyObject_Print(py_A,stdout,0); puts(\"\");\\n'", + " #code += ' printf(\"nd=%d typecode=%d\\\\n\",((PyArrayObject*)py_A)->nd,((PyArrayObject*)py_A)->descr->type_num);\\n'", + " def indent(self):", + " self.__indent += 1", + " return", + "", + " def dedent(self):", + " self.__indent -= 1", + " return", + " self.__body += ' '*(3*self.__indent)", + " assert type(v) != TupleType", + " assert type(t) != TupleType", + " ##################################################################", + " # MEMBER PUSHTUPLE #", + " ##################################################################", + " def pushTuple(self,V,T):", + " assert type(V) == TupleType", + " self.stack.append(V)", + " assert type(V) == TupleType", + " self.types.append(T)", + " return", + "", + "", + " ##################################################################", + " # MEMBER POPTUPLE #", + " ##################################################################", + " def popTuple(self):", + " v = self.stack[-1]", + " assert type(v) == TupleType", + " del self.stack[-1]", + " t = self.types[-1]", + " assert type(t) == TupleType", + " del self.types[-1]", + " return v,t", + " ##################################################################", + " # MEMBER MULTIARG #", + " ##################################################################", + " def multiarg(self):", + " return type(self.stack[-1]) == TupleType", + "", + "", + " # MEMBER CODEUP #", + " def codeup(self, rhs, rhs_type):", + "", + "", + " ##################################################################", + " # MEMBER BINOP #", + " ##################################################################", + " def binop(self,pc,symbol):", + " v2,t2 = self.pop()", + " v1,t1 = self.pop()", + "", + " if t1 == t2:", + " rhs,rhs_type = t1.binop(symbol,v1,v2)", + " else:", + " rhs,rhs_type = t1.binopMixed(symbol,v1,v2,t2)", + "", + " self.codeup(rhs,rhs_type)", + " return", + " print 'MULTIPLY',self.stack[-2],self.types[-2],'*',self.stack[-1],self.types[-1]", + " if self.multiarg():", + " v2,t2 = self.popTuple()", + " else:", + " v2,t2 = self.pop()", + " v2 = (v2,)", + " t2 = (t2,)", + " v1,t1 = self.pop()", + " rhs,rhs_type = t1.getitem(v1,v2,t2)", + " self.codeup(rhs,rhs_type)", + " return", + "", + " def STORE_SUBSCR(self,pc):", + " if self.multiarg():", + " v2,t2 = self.popTuple()", + " else:", + " v2,t2 = self.pop()", + " v2 = (v2,)", + " t2 = (t2,)", + " v1,t1 = self.pop()", + " v0,t0 = self.pop()", + "", + " rhs,rhs_type = t1.setitem(v1,v2,t2)", + " assert rhs_type == t0,\"Store the right thing\"", + " self.emit('%s = %s;'%(rhs,v0))", + " return", + "", + " ##################################################################", + " # MEMBER BUILD_TUPLE #", + " ##################################################################", + " def BUILD_TUPLE(self,pc,count):", + " \"Creates a tuple consuming count items from the stack, and pushes the resulting tuple onto the stack.\"", + " V = []", + " T = []", + " for i in range(count):", + " v,t = self.pop()", + " V.append(v)", + " T.append(t)", + " V.reverse()", + " T.reverse()", + " self.pushTuple(tuple(V),tuple(T))", + " return", + "", + " for VV,TT in map(None, self.stack, self.types):", + " print VV,':',TT", + " if t == None:", + " raise TypeError,'%s used before set?'%v", + " print self.__body", + " print 'PC',pc" + ], + "deleted": [ + " arglen = len(self.signature)", + " code += ' if ( !%s ) {\\n'% \\", + "", + " # MEMBER BINOP #", + " def binop(self,pc,symbol):", + " v2,t2 = self.pop()", + " v1,t1 = self.pop()", + "", + " if t1 == t2:", + " rhs,rhs_type = t1.binop(symbol,v1,v2)", + " else:", + " rhs,rhs_type = t1.binopMixed(symbol,v1,v2)", + "", + " return self.binop(pc,'[]')", + " if t.refcount:", + " self.emit('Py_XINCREF(%s);'%v)" + ] + } + } + ] + }, + { + "hash": "b8eb1007a34934bde5c2ba868852689d1f5311c8", + "msg": "added a routine to allow using the standard set of Fortran compilers with mingw32 instead of only allowing g77", + "author": { + "name": "Eric Jones", + "email": "eric@enthought.com" + }, + "committer": { + "name": "Eric Jones", + "email": "eric@enthought.com" + }, + "author_date": "2002-03-03T11:12:14+00:00", + "author_timezone": 0, + "committer_date": "2002-03-03T11:12:14+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "85943af1f38224aab592e5bf7a50b20d9aebde05" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 0, + "insertions": 4, + "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/mingw32_support.py", + "new_path": "scipy_distutils/mingw32_support.py", + "filename": "mingw32_support.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -90,9 +90,13 @@ def use_msvc():\n def use_gcc(): \n set_windows_compiler('mingw32') \n \n+ standard_compiler_list = build_flib.all_compilers[:]\n def use_g77():\n build_flib.all_compilers = [build_flib.gnu_fortran_compiler] \n \n+ def use_standard_fortran_compiler():\n+ build_flib.all_compilers = standard_compiler_list\n+ \n # 2. force the use of gcc on windows platform\n use_gcc()\n # 3. force the use of g77 on windows platform\n", + "added_lines": 4, + "deleted_lines": 0, + "source_code": "\"\"\"\nSupport code for building Python extensions on Windows.\n\n # NT stuff\n # 1. Make sure libpython.a exists for gcc. If not, build it.\n # 2. Force windows to use gcc (we're struggling with MSVC and g77 support) \n # 3. Force windows to use g77\n\n\"\"\"\n\nimport os, sys\nimport distutils.ccompiler\n\n# I'd really like to pull this out of scipy and make it part of distutils...\nimport scipy_distutils.command.build_flib as build_flib\n\n\nif sys.platform == 'win32':\n # NT stuff\n # 1. Make sure libpython.a exists for gcc. If not, build it.\n # 2. Force windows to use gcc (we're struggling with MSVC and g77 support) \n # 3. Force windows to use g77\n \n # 1. Build libpython from .lib and .dll if they don't exist. \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if sys.platform == 'win32':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n #print full_path\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n # lib2def lives in weave\n sys.path.append(os.path.join('.','weave'))\n\n import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile == None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n print cmd\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print \"WARNING: failed to build import library for gcc. \"\\\n \"Linking will fail.\"\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \n def set_windows_compiler(compiler):\n distutils.ccompiler._default_compilers = (\n \n # Platform string mappings\n \n # on a cygwin built python we can use gcc like an ordinary UNIXish\n # compiler\n ('cygwin.*', 'unix'),\n \n # OS name mappings\n ('posix', 'unix'),\n ('nt', compiler),\n ('mac', 'mwerks'),\n \n ) \n def use_msvc():\n set_windows_compiler('msvc')\n \n def use_gcc(): \n set_windows_compiler('mingw32') \n \n standard_compiler_list = build_flib.all_compilers[:]\n def use_g77():\n build_flib.all_compilers = [build_flib.gnu_fortran_compiler] \n \n def use_standard_fortran_compiler():\n build_flib.all_compilers = standard_compiler_list\n \n # 2. force the use of gcc on windows platform\n use_gcc()\n # 3. force the use of g77 on windows platform\n use_g77()\n if not import_library_exists():\n build_import_library()\n\n \n", + "source_code_before": "\"\"\"\nSupport code for building Python extensions on Windows.\n\n # NT stuff\n # 1. Make sure libpython.a exists for gcc. If not, build it.\n # 2. Force windows to use gcc (we're struggling with MSVC and g77 support) \n # 3. Force windows to use g77\n\n\"\"\"\n\nimport os, sys\nimport distutils.ccompiler\n\n# I'd really like to pull this out of scipy and make it part of distutils...\nimport scipy_distutils.command.build_flib as build_flib\n\n\nif sys.platform == 'win32':\n # NT stuff\n # 1. Make sure libpython.a exists for gcc. If not, build it.\n # 2. Force windows to use gcc (we're struggling with MSVC and g77 support) \n # 3. Force windows to use g77\n \n # 1. Build libpython from .lib and .dll if they don't exist. \n def import_library_exists():\n \"\"\" on windows platforms, make sure a gcc import library exists\n \"\"\"\n if sys.platform == 'win32':\n lib_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n full_path = os.path.join(sys.prefix,'libs',lib_name)\n #print full_path\n if not os.path.exists(full_path):\n return 0\n return 1\n \n def build_import_library():\n \"\"\" Build the import libraries for Mingw32-gcc on Windows\n \"\"\"\n # lib2def lives in weave\n sys.path.append(os.path.join('.','weave'))\n\n import lib2def\n #libfile, deffile = parse_cmd()\n #if deffile == None:\n # deffile = sys.stdout\n #else:\n # deffile = open(deffile, 'w')\n lib_name = \"python%d%d.lib\" % tuple(sys.version_info[:2]) \n lib_file = os.path.join(sys.prefix,'libs',lib_name)\n def_name = \"python%d%d.def\" % tuple(sys.version_info[:2]) \n def_file = os.path.join(sys.prefix,'libs',def_name)\n nm_cmd = '%s %s' % (lib2def.DEFAULT_NM, lib_file)\n nm_output = lib2def.getnm(nm_cmd)\n dlist, flist = lib2def.parse_nm(nm_output)\n lib2def.output_def(dlist, flist, lib2def.DEF_HEADER, open(def_file, 'w'))\n \n out_name = \"libpython%d%d.a\" % tuple(sys.version_info[:2])\n out_file = os.path.join(sys.prefix,'libs',out_name)\n dll_name = \"python%d%d.dll\" % tuple(sys.version_info[:2])\n args = (dll_name,def_file,out_file)\n cmd = 'dlltool --dllname %s --def %s --output-lib %s' % args\n print cmd\n success = not os.system(cmd)\n # for now, fail silently\n if not success:\n print \"WARNING: failed to build import library for gcc. \"\\\n \"Linking will fail.\"\n #if not success:\n # msg = \"Couldn't find import library, and failed to build it.\"\n # raise DistutilsPlatformError, msg\n \n def set_windows_compiler(compiler):\n distutils.ccompiler._default_compilers = (\n \n # Platform string mappings\n \n # on a cygwin built python we can use gcc like an ordinary UNIXish\n # compiler\n ('cygwin.*', 'unix'),\n \n # OS name mappings\n ('posix', 'unix'),\n ('nt', compiler),\n ('mac', 'mwerks'),\n \n ) \n def use_msvc():\n set_windows_compiler('msvc')\n \n def use_gcc(): \n set_windows_compiler('mingw32') \n \n def use_g77():\n build_flib.all_compilers = [build_flib.gnu_fortran_compiler] \n \n # 2. force the use of gcc on windows platform\n use_gcc()\n # 3. force the use of g77 on windows platform\n use_g77()\n if not import_library_exists():\n build_import_library()\n\n \n", + "methods": [ + { + "name": "import_library_exists", + "long_name": "import_library_exists( )", + "filename": "mingw32_support.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [], + "start_line": 25, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "build_import_library", + "long_name": "build_import_library( )", + "filename": "mingw32_support.py", + "nloc": 21, + "complexity": 2, + "token_count": 209, + "parameters": [], + "start_line": 36, + "end_line": 67, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "set_windows_compiler", + "long_name": "set_windows_compiler( compiler )", + "filename": "mingw32_support.py", + "nloc": 7, + "complexity": 1, + "token_count": 37, + "parameters": [ + "compiler" + ], + "start_line": 72, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "use_msvc", + "long_name": "use_msvc( )", + "filename": "mingw32_support.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [], + "start_line": 87, + "end_line": 88, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "use_gcc", + "long_name": "use_gcc( )", + "filename": "mingw32_support.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [], + "start_line": 90, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "use_g77", + "long_name": "use_g77( )", + "filename": "mingw32_support.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 94, + "end_line": 95, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "use_standard_fortran_compiler", + "long_name": "use_standard_fortran_compiler( )", + "filename": "mingw32_support.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [], + "start_line": 97, + "end_line": 98, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "import_library_exists", + "long_name": "import_library_exists( )", + "filename": "mingw32_support.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [], + "start_line": 25, + "end_line": 34, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "build_import_library", + "long_name": "build_import_library( )", + "filename": "mingw32_support.py", + "nloc": 21, + "complexity": 2, + "token_count": 209, + "parameters": [], + "start_line": 36, + "end_line": 67, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 32, + "top_nesting_level": 1 + }, + { + "name": "set_windows_compiler", + "long_name": "set_windows_compiler( compiler )", + "filename": "mingw32_support.py", + "nloc": 7, + "complexity": 1, + "token_count": 37, + "parameters": [ + "compiler" + ], + "start_line": 72, + "end_line": 86, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "use_msvc", + "long_name": "use_msvc( )", + "filename": "mingw32_support.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [], + "start_line": 87, + "end_line": 88, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "use_gcc", + "long_name": "use_gcc( )", + "filename": "mingw32_support.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [], + "start_line": 90, + "end_line": 91, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "use_g77", + "long_name": "use_g77( )", + "filename": "mingw32_support.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [], + "start_line": 93, + "end_line": 94, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "use_standard_fortran_compiler", + "long_name": "use_standard_fortran_compiler( )", + "filename": "mingw32_support.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [], + "start_line": 97, + "end_line": 98, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + } + ], + "nloc": 61, + "complexity": 10, + "token_count": 395, + "diff_parsed": { + "added": [ + " standard_compiler_list = build_flib.all_compilers[:]", + " def use_standard_fortran_compiler():", + " build_flib.all_compilers = standard_compiler_list", + "" + ], + "deleted": [] + } + } + ] + }, + { + "hash": "241b168ac07cbcafdfca709fa26bf32685afce91", + "msg": "fixed typo in variable name for setting library_dirs", + "author": { + "name": "Eric Jones", + "email": "eric@enthought.com" + }, + "committer": { + "name": "Eric Jones", + "email": "eric@enthought.com" + }, + "author_date": "2002-03-03T11:18:15+00:00", + "author_timezone": 0, + "committer_date": "2002-03-03T11:18:15+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "b8eb1007a34934bde5c2ba868852689d1f5311c8" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 3, + "insertions": 3, + "lines": 6, + "files": 1, + "dmm_unit_size": null, + "dmm_unit_complexity": null, + "dmm_unit_interfacing": null, + "modified_files": [ + { + "old_path": "scipy_distutils/command/build_ext.py", + "new_path": "scipy_distutils/command/build_ext.py", + "filename": "build_ext.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -74,12 +74,12 @@ def build_extension(self, ext):\n for lib in libs:\n if lib not in self.compiler.libraries:\n self.compiler.libraries.append(lib)\n- #self.compiler.libraries = self.compiler.libraries + l\n+\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n if lib_dir not in self.compiler.library_dirs:\n- self.compiler.libraries.append(lib_dir)\n- #self.compiler.library_dirs = self.compiler.library_dirs + l\n+ self.compiler.library_dirs.append(lib_dir)\n+\n \n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n", + "added_lines": 3, + "deleted_lines": 3, + "source_code": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os, string\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n #XXX: anything else we need to save?\n save_linker_so = self.compiler.linker_so\n save_compiler_libs = self.compiler.libraries\n save_compiler_libs_dirs = self.compiler.library_dirs\n \n # support for building static fortran libraries\n need_f_libs = 0\n need_f_opts = getattr(ext,'need_fcompiler_opts',0)\n ext_name = string.split(ext.name,'.')[-1]\n\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n if build_flib.has_f_library(ext_name):\n need_f_libs = 1\n else:\n for lib_name in ext.libraries:\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n elif need_f_opts:\n build_flib = self.get_finalized_command('build_flib')\n print ext.name,ext_name,'needs fortran libraries',\\\n need_f_libs,need_f_opts\n \n if need_f_libs:\n if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.insert(0,ext_name)\n for lib_name in ext.libraries[:]:\n ext.libraries.extend(build_flib.get_library_names(lib_name))\n ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))\n \n ext.library_dirs.append(build_flib.build_flib)\n\n if need_f_libs or need_f_opts:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n if moreargs != []:\n if ext.extra_link_args is None:\n ext.extra_link_args = moreargs\n else:\n ext.extra_link_args += moreargs\n\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n\n linker_so = build_flib.fcompiler.get_linker_so()\n\n if linker_so is not None:\n if linker_so is not save_linker_so:\n print 'replacing linker_so %s with %s' %(save_linker_so,linker_so)\n self.compiler.linker_so = linker_so\n l = build_flib.get_fcompiler_library_names()\n #l = self.compiler.libraries + l\n self.compiler.libraries = l\n l = build_flib.get_fcompiler_library_dirs()\n #l = self.compiler.library_dirs + l\n self.compiler.library_dirs = l\n else:\n libs = build_flib.get_fcompiler_library_names()\n for lib in libs:\n if lib not in self.compiler.libraries:\n self.compiler.libraries.append(lib)\n\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n if lib_dir not in self.compiler.library_dirs:\n self.compiler.library_dirs.append(lib_dir)\n\n \n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n\n if save_linker_so is not self.compiler.linker_so:\n print 'restoring linker_so',save_linker_so\n self.compiler.linker_so = save_linker_so\n self.compiler.libraries = save_compiler_libs\n self.compiler.library_dirs = save_compiler_libs_dirs\n\n return res\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n filenames.extend(ext.sources)\n filenames.extend(get_headers(get_directories(ext.sources)))\n\n return filenames\n\n \n", + "source_code_before": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os, string\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n #XXX: anything else we need to save?\n save_linker_so = self.compiler.linker_so\n save_compiler_libs = self.compiler.libraries\n save_compiler_libs_dirs = self.compiler.library_dirs\n \n # support for building static fortran libraries\n need_f_libs = 0\n need_f_opts = getattr(ext,'need_fcompiler_opts',0)\n ext_name = string.split(ext.name,'.')[-1]\n\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n if build_flib.has_f_library(ext_name):\n need_f_libs = 1\n else:\n for lib_name in ext.libraries:\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n elif need_f_opts:\n build_flib = self.get_finalized_command('build_flib')\n print ext.name,ext_name,'needs fortran libraries',\\\n need_f_libs,need_f_opts\n \n if need_f_libs:\n if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.insert(0,ext_name)\n for lib_name in ext.libraries[:]:\n ext.libraries.extend(build_flib.get_library_names(lib_name))\n ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))\n \n ext.library_dirs.append(build_flib.build_flib)\n\n if need_f_libs or need_f_opts:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n if moreargs != []:\n if ext.extra_link_args is None:\n ext.extra_link_args = moreargs\n else:\n ext.extra_link_args += moreargs\n\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n\n linker_so = build_flib.fcompiler.get_linker_so()\n\n if linker_so is not None:\n if linker_so is not save_linker_so:\n print 'replacing linker_so %s with %s' %(save_linker_so,linker_so)\n self.compiler.linker_so = linker_so\n l = build_flib.get_fcompiler_library_names()\n #l = self.compiler.libraries + l\n self.compiler.libraries = l\n l = build_flib.get_fcompiler_library_dirs()\n #l = self.compiler.library_dirs + l\n self.compiler.library_dirs = l\n else:\n libs = build_flib.get_fcompiler_library_names()\n for lib in libs:\n if lib not in self.compiler.libraries:\n self.compiler.libraries.append(lib)\n #self.compiler.libraries = self.compiler.libraries + l\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n if lib_dir not in self.compiler.library_dirs:\n self.compiler.libraries.append(lib_dir)\n #self.compiler.library_dirs = self.compiler.library_dirs + l\n \n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n\n if save_linker_so is not self.compiler.linker_so:\n print 'restoring linker_so',save_linker_so\n self.compiler.linker_so = save_linker_so\n self.compiler.libraries = save_compiler_libs\n self.compiler.library_dirs = save_compiler_libs_dirs\n\n return res\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n filenames.extend(ext.sources)\n filenames.extend(get_headers(get_directories(ext.sources)))\n\n return filenames\n\n \n", + "methods": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 62, + "complexity": 22, + "token_count": 439, + "parameters": [ + "self", + "ext" + ], + "start_line": 14, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_ext.py", + "nloc": 7, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 95, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 62, + "complexity": 22, + "token_count": 439, + "parameters": [ + "self", + "ext" + ], + "start_line": 14, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_ext.py", + "nloc": 7, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 95, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 62, + "complexity": 22, + "token_count": 439, + "parameters": [ + "self", + "ext" + ], + "start_line": 14, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 1 + } + ], + "nloc": 77, + "complexity": 24, + "token_count": 532, + "diff_parsed": { + "added": [ + "", + " self.compiler.library_dirs.append(lib_dir)", + "" + ], + "deleted": [ + " #self.compiler.libraries = self.compiler.libraries + l", + " self.compiler.libraries.append(lib_dir)", + " #self.compiler.library_dirs = self.compiler.library_dirs + l" + ] + } + } + ] + }, + { + "hash": "6e83d282ae09d4364f5dc383f53d96a19b86aa87", + "msg": "system_info was setting include_dirs to a string instead of to a list. This broke win32 builds of linalg2. Converted to a list.", + "author": { + "name": "Eric Jones", + "email": "eric@enthought.com" + }, + "committer": { + "name": "Eric Jones", + "email": "eric@enthought.com" + }, + "author_date": "2002-03-03T11:43:27+00:00", + "author_timezone": 0, + "committer_date": "2002-03-03T11:43:27+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "241b168ac07cbcafdfca709fa26bf32685afce91" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 2, + "insertions": 3, + "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": "@@ -179,7 +179,7 @@ def __init__(self):\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n \n- def calc_info(self,prefix):\n+ def calc_info(self,prefix): \n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,'lib',['fftw*','FFTW*']))\n if not lib_dirs:\n@@ -280,6 +280,7 @@ def __init__(self):\n self.local_prefixes.insert(0,p)\n \n def calc_info(self, prefix):\n+ print combine_paths(prefix,'lib',['atlas*','ATLAS*'])\n lib_dirs = filter(os.path.isdir,combine_paths(prefix,'lib',\n ['atlas*','ATLAS*']))\n if lib_dirs:\n@@ -305,7 +306,7 @@ def calc_info(self, prefix):\n info = r\n break\n if info is None: return\n- if h: dict_append(info,include_dirs=h)\n+ if h: dict_append(info,include_dirs=[h])\n self.set_info(**info)\n \n \n", + "added_lines": 3, + "deleted_lines": 2, + "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 fftw_info\n x11_info\nThe following environment variables are used if defined:\n ATLAS - path to ATLAS library\n FFTW - path to FFTW library\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw'.\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 (or system_info could not find it).\n\nGlobal parameters:\n prefixes - a list of prefixes for scanning the location of\n resources.\n system_info.static_first - a flag for indicating that static\n libraries are searched first than shared ones.\n system_info.verbose - show the results if set.\n\nAuthor:\n Pearu Peterson , February 2002\nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re,types,pprint\nfrom distutils.errors import DistutilsError\nfrom glob import glob\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n prefixes = ['C:\\\\'] # XXX: what is prefix in win32?\nelse:\n prefixes = ['/usr','/usr/local','/opt']\nif sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\nprefixes = filter(os.path.isdir,prefixes) # XXX: Is this ok on win32? Is 'C:' dir?\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name):\n cl = {'atlas':atlas_info,\n 'x11':x11_info,\n 'fftw':fftw_info}.get(name.lower(),system_info)\n return cl().get_info()\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 Either install them in /usr/local/lib/atlas or /usr/lib/atlas\n and retry setup.py. One can use also ATLAS environment variable\n to indicate the location of Atlas libraries.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Either install them in /usr/local/lib or /usr/lib and retry setup.py.\n One can use also FFTW environment variable to indicate\n the location of FFTW libraries.\"\"\"\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://pfdubois.com/numpy/) 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\n static_first = 1\n verbose = 1\n need_refresh = 1\n saved_results = {}\n \n def __init__ (self):\n self.__class__.info = {}\n #self.__class__.need_refresh = not self.info\n self.local_prefixes = []\n\n def set_info(self,**info):\n #self.__class__.info = info\n self.saved_results[self.__class__.__name__] = info\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n def get_info(self):\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.verbose:\n print self.__class__.__name__ + ':'\n for p in self.local_prefixes + prefixes:\n if self.verbose:\n print ' Looking in',p,'...'\n self.calc_info(p)\n if self.has_info(): break\n if self.verbose:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbose and flag:\n for k,v in res.items():\n print ' %s = %s'%(k,v)\n print\n return res\n\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\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 mths = [self.check_static_libs,self.check_shared_libs]\n if not self.static_first:\n mths.reverse() # if one prefers shared libraries\n for m in mths:\n info = m(lib_dir,libs,opt_libs)\n if info is not None: return info\n\n def check_static_libs(self,lib_dir,libs,opt_libs =[]):\n #XXX: what are .lib and .dll files under win32?\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs])) == len(libs):\n info = {'libraries':libs,'library_dirs':[lib_dir]}\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs]))\\\n ==len(opt_libs):\n info['libraries'].extend(opt_libs)\n return info\n\n def check_shared_libs(self,lib_dir,libs,opt_libs =[]):\n shared_libs = []\n for l in libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: shared_libs.append(p)\n if len(shared_libs) == len(libs):\n info = {'extra_objects':shared_libs}\n opt_shared_libs = []\n for l in opt_libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: opt_shared_libs.append(p)\n info['extra_objects'].extend(opt_shared_libs)\n return info\n\n\nclass fftw_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('FFTW')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self,prefix): \n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,'lib',['fftw*','FFTW*']))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'lib'))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','fftw*','FFTW*']))\n \n if not lib_dirs:\n lib_dirs = [prefix]\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,'include',['fftw*','FFTW*']))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'include'))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['include','fftw*','FFTW*']))\n if not incl_dirs:\n incl_dirs = [prefix]\n incl_dir = None\n\n libs = ['fftw','rfftw']\n opt_libs = ['fftw_threads','rfftw_threads']\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['fftw.h','rfftw.h']))==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=[('SCIPY_FFTW_H',1)])\n else:\n info = None\n\n if info is None:\n libs = ['dfftw','drfftw']\n opt_libs = ['dfftw_threads','drfftw_threads']\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['dfftw.h','drfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n incl_dirs = [d]\n incl_dir = d\n flag = 1\n break\n if flag:\n dict_append(info,define_macros=[('SCIPY_DFFTW_H',1)])\n else:\n info = None\n \n libs = ['sfftw','srfftw']\n opt_libs = ['sfftw_threads','srfftw_threads']\n flag = 0\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_libs)\n if r is not None:\n if info is None: info = r\n else: dict_append(info,**r)\n flag = 1\n break\n if info is not None and flag:\n for d in incl_dirs:\n if len(combine_paths(d,['sfftw.h','srfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n dict_append(info,define_macros=[('SCIPY_SFFTW_H',1)])\n break\n if info is not None:\n self.set_info(**info)\n\n\nclass atlas_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('ATLAS')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self, prefix):\n print combine_paths(prefix,'lib',['atlas*','ATLAS*'])\n lib_dirs = filter(os.path.isdir,combine_paths(prefix,'lib',\n ['atlas*','ATLAS*']))\n if lib_dirs:\n other_dirs = filter(os.path.isdir,combine_paths(lib_dirs,'*'))\n other_dirs.extend(filter(os.path.isdir,combine_paths(prefix,'lib')))\n lib_dirs.extend(other_dirs)\n else:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','atlas*','ATLAS*']))\n if not lib_dirs:\n lib_dirs = [prefix]\n\n h = (combine_paths(lib_dirs,'cblas.h') or [None])[0]\n if not h:\n h = (combine_paths(lib_dirs,'include','cblas.h') or [None])[0]\n if h: h = os.path.dirname(h)\n\n libs = ['lapack','f77blas','cblas','atlas']\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 None: return\n if h: dict_append(info,include_dirs=[h])\n self.set_info(**info)\n\n\nclass blas_info(system_info):\n # For Fortran or optimized blas, not atlas.\n pass\n\n\nclass lapack_info(system_info):\n # For Fortran or optimized lapack, not atlas\n pass\n\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = self.check_libs(lib_dir[0],['X11'],[])\n if info is None:\n continue\n dict_append(info,include_dirs=[inc_dir])\n self.set_info(**info)\n\ndef shortest_path(pths):\n pths.sort()\n if pths: return pths[0]\n\ndef combine_paths(*args):\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 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 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 r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\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 fftw_info\n x11_info\nThe following environment variables are used if defined:\n ATLAS - path to ATLAS library\n FFTW - path to FFTW library\n\nUsage:\n info_dict = get_info()\n where is a string 'atlas','x11','fftw'.\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 (or system_info could not find it).\n\nGlobal parameters:\n prefixes - a list of prefixes for scanning the location of\n resources.\n system_info.static_first - a flag for indicating that static\n libraries are searched first than shared ones.\n system_info.verbose - show the results if set.\n\nAuthor:\n Pearu Peterson , February 2002\nPermission to use, modify, and distribute this software is given under the\nterms of the LGPL. See http://www.fsf.org\nNO WARRANTY IS EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.\n\"\"\"\n\nimport sys,os,re,types,pprint\nfrom distutils.errors import DistutilsError\nfrom glob import glob\n\nfrom distutils.sysconfig import get_config_vars\n\nif sys.platform == 'win32':\n prefixes = ['C:\\\\'] # XXX: what is prefix in win32?\nelse:\n prefixes = ['/usr','/usr/local','/opt']\nif sys.prefix not in prefixes:\n prefixes.append(sys.prefix)\nprefixes = filter(os.path.isdir,prefixes) # XXX: Is this ok on win32? Is 'C:' dir?\n\nso_ext = get_config_vars('SO')[0] or ''\n\ndef get_info(name):\n cl = {'atlas':atlas_info,\n 'x11':x11_info,\n 'fftw':fftw_info}.get(name.lower(),system_info)\n return cl().get_info()\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 Either install them in /usr/local/lib/atlas or /usr/lib/atlas\n and retry setup.py. One can use also ATLAS environment variable\n to indicate the location of Atlas libraries.\"\"\"\n\nclass FFTWNotFoundError(NotFoundError):\n \"\"\"\n FFTW (http://www.fftw.org/) libraries not found.\n Either install them in /usr/local/lib or /usr/lib and retry setup.py.\n One can use also FFTW environment variable to indicate\n the location of FFTW libraries.\"\"\"\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://pfdubois.com/numpy/) 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\n static_first = 1\n verbose = 1\n need_refresh = 1\n saved_results = {}\n \n def __init__ (self):\n self.__class__.info = {}\n #self.__class__.need_refresh = not self.info\n self.local_prefixes = []\n\n def set_info(self,**info):\n #self.__class__.info = info\n self.saved_results[self.__class__.__name__] = info\n def has_info(self):\n return self.saved_results.has_key(self.__class__.__name__)\n def get_info(self):\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.verbose:\n print self.__class__.__name__ + ':'\n for p in self.local_prefixes + prefixes:\n if self.verbose:\n print ' Looking in',p,'...'\n self.calc_info(p)\n if self.has_info(): break\n if self.verbose:\n if not self.has_info():\n print ' NOT AVAILABLE'\n self.set_info()\n else:\n print ' FOUND:'\n res = self.saved_results.get(self.__class__.__name__)\n if self.verbose and flag:\n for k,v in res.items():\n print ' %s = %s'%(k,v)\n print\n return res\n\n def calc_info(self,prefix):\n \"\"\" Calculate info distionary. \"\"\"\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 mths = [self.check_static_libs,self.check_shared_libs]\n if not self.static_first:\n mths.reverse() # if one prefers shared libraries\n for m in mths:\n info = m(lib_dir,libs,opt_libs)\n if info is not None: return info\n\n def check_static_libs(self,lib_dir,libs,opt_libs =[]):\n #XXX: what are .lib and .dll files under win32?\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs])) == len(libs):\n info = {'libraries':libs,'library_dirs':[lib_dir]}\n if len(combine_paths(lib_dir,['lib'+l+'.a' for l in libs]))\\\n ==len(opt_libs):\n info['libraries'].extend(opt_libs)\n return info\n\n def check_shared_libs(self,lib_dir,libs,opt_libs =[]):\n shared_libs = []\n for l in libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: shared_libs.append(p)\n if len(shared_libs) == len(libs):\n info = {'extra_objects':shared_libs}\n opt_shared_libs = []\n for l in opt_libs:\n p = shortest_path(combine_paths(lib_dir,'lib'+l+so_ext+'*'))\n if p is not None: opt_shared_libs.append(p)\n info['extra_objects'].extend(opt_shared_libs)\n return info\n\n\nclass fftw_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('FFTW')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self,prefix):\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,'lib',['fftw*','FFTW*']))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'lib'))\n if not lib_dirs:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','fftw*','FFTW*']))\n \n if not lib_dirs:\n lib_dirs = [prefix]\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,'include',['fftw*','FFTW*']))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['fftw*','FFTW*'],'include'))\n if not incl_dirs:\n incl_dirs = filter(os.path.isdir,\n combine_paths(prefix,['include','fftw*','FFTW*']))\n if not incl_dirs:\n incl_dirs = [prefix]\n incl_dir = None\n\n libs = ['fftw','rfftw']\n opt_libs = ['fftw_threads','rfftw_threads']\n info = None\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['fftw.h','rfftw.h']))==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=[('SCIPY_FFTW_H',1)])\n else:\n info = None\n\n if info is None:\n libs = ['dfftw','drfftw']\n opt_libs = ['dfftw_threads','drfftw_threads']\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_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(combine_paths(d,['dfftw.h','drfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n incl_dirs = [d]\n incl_dir = d\n flag = 1\n break\n if flag:\n dict_append(info,define_macros=[('SCIPY_DFFTW_H',1)])\n else:\n info = None\n \n libs = ['sfftw','srfftw']\n opt_libs = ['sfftw_threads','srfftw_threads']\n flag = 0\n for d in lib_dirs:\n r = self.check_libs(d,libs,opt_libs)\n if r is not None:\n if info is None: info = r\n else: dict_append(info,**r)\n flag = 1\n break\n if info is not None and flag:\n for d in incl_dirs:\n if len(combine_paths(d,['sfftw.h','srfftw.h']))==2:\n if incl_dir is None:\n dict_append(info,include_dirs=[d])\n dict_append(info,define_macros=[('SCIPY_SFFTW_H',1)])\n break\n if info is not None:\n self.set_info(**info)\n\n\nclass atlas_info(system_info):\n\n def __init__(self):\n system_info.__init__(self)\n p = os.environ.get('ATLAS')\n if p is not None:\n p = os.path.abspath(p)\n if os.path.isdir(p):\n self.local_prefixes.insert(0,p)\n\n def calc_info(self, prefix):\n lib_dirs = filter(os.path.isdir,combine_paths(prefix,'lib',\n ['atlas*','ATLAS*']))\n if lib_dirs:\n other_dirs = filter(os.path.isdir,combine_paths(lib_dirs,'*'))\n other_dirs.extend(filter(os.path.isdir,combine_paths(prefix,'lib')))\n lib_dirs.extend(other_dirs)\n else:\n lib_dirs = filter(os.path.isdir,\n combine_paths(prefix,['lib','atlas*','ATLAS*']))\n if not lib_dirs:\n lib_dirs = [prefix]\n\n h = (combine_paths(lib_dirs,'cblas.h') or [None])[0]\n if not h:\n h = (combine_paths(lib_dirs,'include','cblas.h') or [None])[0]\n if h: h = os.path.dirname(h)\n\n libs = ['lapack','f77blas','cblas','atlas']\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 None: return\n if h: dict_append(info,include_dirs=h)\n self.set_info(**info)\n\n\nclass blas_info(system_info):\n # For Fortran or optimized blas, not atlas.\n pass\n\n\nclass lapack_info(system_info):\n # For Fortran or optimized lapack, not atlas\n pass\n\n\nclass x11_info(system_info):\n\n def calc_info(self, prefix):\n if sys.platform == 'win32':\n return\n for x11_dir in combine_paths(prefix,['X11R6','X11']):\n inc_dir = None\n for d in combine_paths(x11_dir,['include','include/X11']):\n if combine_paths(d,'X.h'):\n inc_dir = d\n break\n if not d: return\n lib_dir = combine_paths(x11_dir,'lib')\n if not lib_dir: return\n info = self.check_libs(lib_dir[0],['X11'],[])\n if info is None:\n continue\n dict_append(info,include_dirs=[inc_dir])\n self.set_info(**info)\n\ndef shortest_path(pths):\n pths.sort()\n if pths: return pths[0]\n\ndef combine_paths(*args):\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 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 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 r = c.get_info()\n\nif __name__ == \"__main__\":\n show_all()\n", + "methods": [ + { + "name": "get_info", + "long_name": "get_info( name )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 1, + "token_count": 39, + "parameters": [ + "name" + ], + "start_line": 52, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 98, + "end_line": 101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 103, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "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": 106, + "end_line": 107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 11, + "token_count": 134, + "parameters": [ + "self" + ], + "start_line": 108, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 135, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 60, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 138, + "end_line": 146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_static_libs", + "long_name": "check_static_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 5, + "token_count": 91, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 148, + "end_line": 155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_shared_libs", + "long_name": "check_shared_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 13, + "complexity": 6, + "token_count": 119, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 157, + "end_line": 169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 174, + "end_line": 180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 84, + "complexity": 30, + "token_count": 561, + "parameters": [ + "self", + "prefix" + ], + "start_line": 182, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 27, + "complexity": 11, + "token_count": 244, + "parameters": [ + "self", + "prefix" + ], + "start_line": 282, + "end_line": 310, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "prefix" + ], + "start_line": 325, + "end_line": 341, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "shortest_path", + "long_name": "shortest_path( pths )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "pths" + ], + "start_line": 343, + "end_line": 345, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 9, + "token_count": 162, + "parameters": [ + "args" + ], + "start_line": 347, + "end_line": 368, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 370, + "end_line": 375, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [], + "start_line": 377, + "end_line": 384, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "get_info", + "long_name": "get_info( name )", + "filename": "system_info.py", + "nloc": 5, + "complexity": 1, + "token_count": 39, + "parameters": [ + "name" + ], + "start_line": 52, + "end_line": 56, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 98, + "end_line": 101, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "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": 103, + "end_line": 105, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "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": 106, + "end_line": 107, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_info", + "long_name": "get_info( self )", + "filename": "system_info.py", + "nloc": 23, + "complexity": 11, + "token_count": 134, + "parameters": [ + "self" + ], + "start_line": 108, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 26, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 1, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self", + "prefix" + ], + "start_line": 135, + "end_line": 136, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "check_libs", + "long_name": "check_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 4, + "token_count": 60, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 138, + "end_line": 146, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 9, + "top_nesting_level": 1 + }, + { + "name": "check_static_libs", + "long_name": "check_static_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 5, + "token_count": 91, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 148, + "end_line": 155, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "check_shared_libs", + "long_name": "check_shared_libs( self , lib_dir , libs , opt_libs = [ ] )", + "filename": "system_info.py", + "nloc": 13, + "complexity": 6, + "token_count": 119, + "parameters": [ + "self", + "lib_dir", + "libs", + "opt_libs" + ], + "start_line": 157, + "end_line": 169, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 174, + "end_line": 180, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 84, + "complexity": 30, + "token_count": 561, + "parameters": [ + "self", + "prefix" + ], + "start_line": 182, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "system_info.py", + "nloc": 7, + "complexity": 3, + "token_count": 57, + "parameters": [ + "self" + ], + "start_line": 274, + "end_line": 280, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 7, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 26, + "complexity": 11, + "token_count": 229, + "parameters": [ + "self", + "prefix" + ], + "start_line": 282, + "end_line": 309, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 28, + "top_nesting_level": 1 + }, + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "prefix" + ], + "start_line": 324, + "end_line": 340, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "shortest_path", + "long_name": "shortest_path( pths )", + "filename": "system_info.py", + "nloc": 3, + "complexity": 2, + "token_count": 18, + "parameters": [ + "pths" + ], + "start_line": 342, + "end_line": 344, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "combine_paths", + "long_name": "combine_paths( * args )", + "filename": "system_info.py", + "nloc": 19, + "complexity": 9, + "token_count": 162, + "parameters": [ + "args" + ], + "start_line": 346, + "end_line": 367, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 0 + }, + { + "name": "dict_append", + "long_name": "dict_append( d , ** kws )", + "filename": "system_info.py", + "nloc": 6, + "complexity": 3, + "token_count": 44, + "parameters": [ + "d", + "kws" + ], + "start_line": 369, + "end_line": 374, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 0 + }, + { + "name": "show_all", + "long_name": "show_all( )", + "filename": "system_info.py", + "nloc": 8, + "complexity": 3, + "token_count": 59, + "parameters": [], + "start_line": 376, + "end_line": 383, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "calc_info", + "long_name": "calc_info( self , prefix )", + "filename": "system_info.py", + "nloc": 84, + "complexity": 30, + "token_count": 561, + "parameters": [ + "self", + "prefix" + ], + "start_line": 182, + "end_line": 269, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 88, + "top_nesting_level": 1 + } + ], + "nloc": 326, + "complexity": 103, + "token_count": 2033, + "diff_parsed": { + "added": [ + " def calc_info(self,prefix):", + " print combine_paths(prefix,'lib',['atlas*','ATLAS*'])", + " if h: dict_append(info,include_dirs=[h])" + ], + "deleted": [ + " def calc_info(self,prefix):", + " if h: dict_append(info,include_dirs=h)" + ] + } + } + ] + }, + { + "hash": "a0d6e39d2ca303935901c2f92444fb367f64f3f3", + "msg": "Subclassed fortran_compiler_base to CCompiler, fortran compiler gets now also -I -D -U options", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-03-03T19:30:38+00:00", + "author_timezone": 0, + "committer_date": "2002-03-03T19:30:38+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "6e83d282ae09d4364f5dc383f53d96a19b86aa87" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 14, + "insertions": 48, + "lines": 62, + "files": 3, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.0, + "modified_files": [ + { + "old_path": "scipy_distutils/command/build_ext.py", + "new_path": "scipy_distutils/command/build_ext.py", + "filename": "build_ext.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -80,7 +80,6 @@ def build_extension(self, ext):\n if lib_dir not in self.compiler.library_dirs:\n self.compiler.library_dirs.append(lib_dir)\n \n- \n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n \n", + "added_lines": 0, + "deleted_lines": 1, + "source_code": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os, string\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n #XXX: anything else we need to save?\n save_linker_so = self.compiler.linker_so\n save_compiler_libs = self.compiler.libraries\n save_compiler_libs_dirs = self.compiler.library_dirs\n \n # support for building static fortran libraries\n need_f_libs = 0\n need_f_opts = getattr(ext,'need_fcompiler_opts',0)\n ext_name = string.split(ext.name,'.')[-1]\n\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n if build_flib.has_f_library(ext_name):\n need_f_libs = 1\n else:\n for lib_name in ext.libraries:\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n elif need_f_opts:\n build_flib = self.get_finalized_command('build_flib')\n print ext.name,ext_name,'needs fortran libraries',\\\n need_f_libs,need_f_opts\n \n if need_f_libs:\n if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.insert(0,ext_name)\n for lib_name in ext.libraries[:]:\n ext.libraries.extend(build_flib.get_library_names(lib_name))\n ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))\n \n ext.library_dirs.append(build_flib.build_flib)\n\n if need_f_libs or need_f_opts:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n if moreargs != []:\n if ext.extra_link_args is None:\n ext.extra_link_args = moreargs\n else:\n ext.extra_link_args += moreargs\n\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n\n linker_so = build_flib.fcompiler.get_linker_so()\n\n if linker_so is not None:\n if linker_so is not save_linker_so:\n print 'replacing linker_so %s with %s' %(save_linker_so,linker_so)\n self.compiler.linker_so = linker_so\n l = build_flib.get_fcompiler_library_names()\n #l = self.compiler.libraries + l\n self.compiler.libraries = l\n l = build_flib.get_fcompiler_library_dirs()\n #l = self.compiler.library_dirs + l\n self.compiler.library_dirs = l\n else:\n libs = build_flib.get_fcompiler_library_names()\n for lib in libs:\n if lib not in self.compiler.libraries:\n self.compiler.libraries.append(lib)\n\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n if lib_dir not in self.compiler.library_dirs:\n self.compiler.library_dirs.append(lib_dir)\n\n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n\n if save_linker_so is not self.compiler.linker_so:\n print 'restoring linker_so',save_linker_so\n self.compiler.linker_so = save_linker_so\n self.compiler.libraries = save_compiler_libs\n self.compiler.library_dirs = save_compiler_libs_dirs\n\n return res\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n filenames.extend(ext.sources)\n filenames.extend(get_headers(get_directories(ext.sources)))\n\n return filenames\n\n \n", + "source_code_before": "\"\"\" Modified version of build_ext that handles fortran source files.\n\"\"\"\n\nimport os, string\nfrom types import *\n\nfrom distutils.dep_util import newer_group, newer\nfrom distutils.command.build_ext import build_ext as old_build_ext\n\nfrom scipy_distutils.command.build_clib import get_headers,get_directories\n\nclass build_ext (old_build_ext):\n\n def build_extension(self, ext):\n #XXX: anything else we need to save?\n save_linker_so = self.compiler.linker_so\n save_compiler_libs = self.compiler.libraries\n save_compiler_libs_dirs = self.compiler.library_dirs\n \n # support for building static fortran libraries\n need_f_libs = 0\n need_f_opts = getattr(ext,'need_fcompiler_opts',0)\n ext_name = string.split(ext.name,'.')[-1]\n\n if self.distribution.has_f_libraries():\n build_flib = self.get_finalized_command('build_flib')\n if build_flib.has_f_library(ext_name):\n need_f_libs = 1\n else:\n for lib_name in ext.libraries:\n if build_flib.has_f_library(lib_name):\n need_f_libs = 1\n break\n elif need_f_opts:\n build_flib = self.get_finalized_command('build_flib')\n print ext.name,ext_name,'needs fortran libraries',\\\n need_f_libs,need_f_opts\n \n if need_f_libs:\n if build_flib.has_f_library(ext_name) and \\\n ext_name not in ext.libraries:\n ext.libraries.insert(0,ext_name)\n for lib_name in ext.libraries[:]:\n ext.libraries.extend(build_flib.get_library_names(lib_name))\n ext.library_dirs.extend(build_flib.get_library_dirs(lib_name))\n \n ext.library_dirs.append(build_flib.build_flib)\n\n if need_f_libs or need_f_opts:\n moreargs = build_flib.fcompiler.get_extra_link_args()\n if moreargs != []:\n if ext.extra_link_args is None:\n ext.extra_link_args = moreargs\n else:\n ext.extra_link_args += moreargs\n\n runtime_dirs = build_flib.get_runtime_library_dirs()\n ext.runtime_library_dirs.extend(runtime_dirs or [])\n\n linker_so = build_flib.fcompiler.get_linker_so()\n\n if linker_so is not None:\n if linker_so is not save_linker_so:\n print 'replacing linker_so %s with %s' %(save_linker_so,linker_so)\n self.compiler.linker_so = linker_so\n l = build_flib.get_fcompiler_library_names()\n #l = self.compiler.libraries + l\n self.compiler.libraries = l\n l = build_flib.get_fcompiler_library_dirs()\n #l = self.compiler.library_dirs + l\n self.compiler.library_dirs = l\n else:\n libs = build_flib.get_fcompiler_library_names()\n for lib in libs:\n if lib not in self.compiler.libraries:\n self.compiler.libraries.append(lib)\n\n lib_dirs = build_flib.get_fcompiler_library_dirs()\n for lib_dir in lib_dirs:\n if lib_dir not in self.compiler.library_dirs:\n self.compiler.library_dirs.append(lib_dir)\n\n \n # end of fortran source support\n res = old_build_ext.build_extension(self,ext)\n\n if save_linker_so is not self.compiler.linker_so:\n print 'restoring linker_so',save_linker_so\n self.compiler.linker_so = save_linker_so\n self.compiler.libraries = save_compiler_libs\n self.compiler.library_dirs = save_compiler_libs_dirs\n\n return res\n\n def get_source_files (self):\n self.check_extensions_list(self.extensions)\n filenames = []\n\n # Get sources and any include files in the same directory.\n for ext in self.extensions:\n filenames.extend(ext.sources)\n filenames.extend(get_headers(get_directories(ext.sources)))\n\n return filenames\n\n \n", + "methods": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 62, + "complexity": 22, + "token_count": 439, + "parameters": [ + "self", + "ext" + ], + "start_line": 14, + "end_line": 92, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 79, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_ext.py", + "nloc": 7, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 94, + "end_line": 103, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 62, + "complexity": 22, + "token_count": 439, + "parameters": [ + "self", + "ext" + ], + "start_line": 14, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_ext.py", + "nloc": 7, + "complexity": 2, + "token_count": 48, + "parameters": [ + "self" + ], + "start_line": 95, + "end_line": 104, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "build_extension", + "long_name": "build_extension( self , ext )", + "filename": "build_ext.py", + "nloc": 62, + "complexity": 22, + "token_count": 439, + "parameters": [ + "self", + "ext" + ], + "start_line": 14, + "end_line": 93, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 80, + "top_nesting_level": 1 + } + ], + "nloc": 77, + "complexity": 24, + "token_count": 532, + "diff_parsed": { + "added": [], + "deleted": [ + "" + ] + } + }, + { + "old_path": "scipy_distutils/command/build_flib.py", + "new_path": "scipy_distutils/command/build_flib.py", + "filename": "build_flib.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -46,6 +46,7 @@\n import os,sys,string\n import commands,re\n from types import *\n+from distutils.ccompiler import CCompiler,gen_preprocess_options\n from distutils.command.build_clib import build_clib\n from distutils.errors import *\n \n@@ -131,7 +132,7 @@ def finalize_options (self):\n if self.has_f_libraries():\n self.fortran_libraries = self.distribution.fortran_libraries\n self.check_library_list(self.fortran_libraries)\n-\n+ \n # finalize_options()\n \n def has_f_libraries(self):\n@@ -241,6 +242,8 @@ def build_libraries (self, fortran_libraries):\n fcompiler = self.fcompiler\n \n for (lib_name, build_info) in fortran_libraries:\n+ self.announce(\" building '%s' library\" % lib_name)\n+\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n@@ -250,8 +253,17 @@ def build_libraries (self, fortran_libraries):\n sources = list(sources)\n module_dirs = build_info.get('module_dirs')\n module_files = build_info.get('module_files')\n- self.announce(\" building '%s' library\" % lib_name)\n- \n+\n+\n+ include_dirs = build_info.get('include_dirs')\n+\n+ if include_dirs:\n+ fcompiler.set_include_dirs(include_dirs)\n+ for n,v in build_info.get('define_macros') or []:\n+ fcompiler.define_macro(n,v)\n+ for n in build_info.get('undef_macros') or []:\n+ fcompiler.undefine_macro(n)\n+\n if module_files:\n fcompiler.build_library(lib_name, module_files,\n temp_dir=self.build_temp)\n@@ -264,14 +276,19 @@ def build_libraries (self, fortran_libraries):\n # build_libraries ()\n \n \n-class fortran_compiler_base:\n+class fortran_compiler_base(CCompiler):\n \n vendor = None\n ver_match = None\n+\n+ compiler_type = 'fortran'\n+ executables = {}\n \n- def __init__(self):\n+ def __init__(self,verbose=0,dry_run=0,force=0):\n # Default initialization. Constructors of derived classes MUST\n- # call this functions.\n+ # call this function.\n+ CCompiler.__init__(self,verbose,dry_run,force)\n+\n self.version = None\n \n self.f77_switches = ''\n@@ -282,8 +299,8 @@ def __init__(self):\n self.f90_opt = ''\n self.f90_debug = ''\n \n- self.libraries = []\n- self.library_dirs = []\n+ #self.libraries = []\n+ #self.library_dirs = []\n \n if self.vendor is None:\n raise DistutilsInternalError,\\\n@@ -292,7 +309,10 @@ def __init__(self):\n raise DistutilsInternalError,\\\n '%s must define ver_match attribute'%(self.__class__)\n \n- def to_object(self,dirty_files,module_dirs=None, temp_dir=''):\n+ def to_object(self,\n+ dirty_files,\n+ module_dirs=None,\n+ temp_dir=''):\n files = string.join(dirty_files)\n f90_files = get_f90_files(dirty_files)\n f77_files = get_f77_files(dirty_files)\n@@ -320,13 +340,19 @@ def source_and_object_pairs(self,source_files, temp_dir=''):\n \n def f_compile(self,compiler,switches, source_files,\n module_dirs=None, temp_dir=''):\n+\n+ pp_opts = gen_preprocess_options(self.macros,self.include_dirs)\n+\n+ switches = switches + string.join(pp_opts,' ')\n+\n module_switch = self.build_module_switch(module_dirs)\n file_pairs = self.source_and_object_pairs(source_files,temp_dir)\n object_files = []\n for source,object in file_pairs:\n if distutils.dep_util.newer(source,object):\n cmd = compiler + ' ' + switches + \\\n- module_switch + ' -c ' + source + ' -o ' + object \n+ module_switch + \\\n+ ' -c ' + source + ' -o ' + object \n print cmd\n failure = os.system(cmd)\n if failure:\n@@ -370,7 +396,9 @@ def build_library(self,library_name,source_list,module_dirs=None,\n distutils.dir_util.mkpath(temp_dir)\n \n #this compiles the files\n- object_list = self.to_object(source_list,module_dirs,temp_dir)\n+ object_list = self.to_object(source_list,\n+ module_dirs,\n+ temp_dir)\n \n # actually we need to use all the object file names here to\n # make sure the library is always built. It could occur that an\n", + "added_lines": 39, + "deleted_lines": 11, + "source_code": "\"\"\" Implements the build_flib command which should go into Distutils\n at some point.\n \n Note:\n Right now, we're dynamically linking to the Fortran libraries on \n some platforms (Sun for sure). This is fine for local installations\n but a bad thing for redistribution because these libraries won't\n live on any machine that doesn't have a fortran compiler installed.\n It is pretty hard (impossible?) to get gcc to pass the right compiler\n flags on Sun to get the linker to use static libs for the fortran\n stuff. Investigate further...\n\nBugs:\n *** Options -e and -x have no effect when used with --help-compiler\n options. E.g. \n ./setup.py build_flib --help-compiler -e g77-3.0\n finds g77-2.95.\n How to extract these options inside the show_compilers function?\n *** compiler.is_available() method may not work correctly on nt\n because of lack of knowledge how to get exit status in\n run_command function. However, it may give reasonable results\n based on a version string.\n *** Some vendors provide different compilers for F77 and F90\n compilations. Currently, checking the availability of these\n compilers is based on only checking the availability of the\n corresponding F77 compiler. If it exists, then F90 is assumed\n to exist also.\n\nOpen issues:\n *** User-defined compiler flags. Do we need --fflags?\n\nFortran compilers (as to be used with --fcompiler= option):\n Absoft\n Sun\n SGI\n Intel\n Itanium\n NAG\n Compaq\n Gnu\n VAST\n\"\"\"\n\nimport distutils\nimport distutils.dep_util, distutils.dir_util\nimport os,sys,string\nimport commands,re\nfrom types import *\nfrom distutils.ccompiler import CCompiler,gen_preprocess_options\nfrom distutils.command.build_clib import build_clib\nfrom distutils.errors import *\n\nclass FortranCompilerError (CCompilerError):\n \"\"\"Some compile/link operation failed.\"\"\"\nclass FortranCompileError (FortranCompilerError):\n \"\"\"Failure to compile one or more Fortran source files.\"\"\"\n\nif os.name == 'nt':\n def run_command(command):\n \"\"\" not sure how to get exit status on nt. \"\"\"\n in_pipe,out_pipe = os.popen4(command)\n in_pipe.close()\n text = out_pipe.read()\n return 0, text\nelse:\n run_command = commands.getstatusoutput\n \ndef show_compilers():\n for compiler_class in all_compilers:\n compiler = compiler_class()\n if compiler.is_available():\n print compiler\n\nclass build_flib (build_clib):\n\n description = \"build f77/f90 libraries used by Python extensions\"\n\n user_options = [\n ('build-flib', 'b',\n \"directory to build f77/f90 libraries to\"),\n ('build-temp', 't',\n \"directory to put temporary build by-products\"),\n ('debug', 'g',\n \"compile with debugging information\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ('fcompiler=', 'c',\n \"specify the compiler type\"),\n ('fcompiler-exec=', 'e',\n \"specify the path to F77 compiler\"),\n ('f90compiler-exec=', 'x',\n \"specify the path to F90 compiler\"),\n ]\n\n boolean_options = ['debug', 'force']\n\n help_options = [\n ('help-compiler', None,\n \"list available compilers\", show_compilers),\n ]\n\n def initialize_options (self):\n\n self.build_flib = None\n self.build_temp = None\n\n self.fortran_libraries = None\n self.define = None\n self.undef = None\n self.debug = None\n self.force = 0\n self.fcompiler = None\n self.fcompiler_exec = None\n self.f90compiler_exec = None\n\n # initialize_options()\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_flib'),\n ('build_temp', 'build_temp'),\n ('debug', 'debug'),\n ('force', 'force'))\n fc = find_fortran_compiler(self.fcompiler,\n self.fcompiler_exec,\n self.f90compiler_exec)\n if not fc:\n raise DistutilsOptionError, 'Fortran compiler not available: %s'%(self.fcompiler)\n else:\n self.announce(' using %s Fortran compiler' % fc)\n self.fcompiler = fc\n if self.has_f_libraries():\n self.fortran_libraries = self.distribution.fortran_libraries\n self.check_library_list(self.fortran_libraries)\n \n # finalize_options()\n\n def has_f_libraries(self):\n return self.distribution.fortran_libraries \\\n and len(self.distribution.fortran_libraries) > 0\n\n def run (self):\n if not self.has_f_libraries():\n return\n self.build_libraries(self.fortran_libraries)\n\n # run ()\n\n def has_f_library(self,name):\n if self.has_f_libraries():\n for (lib_name, build_info) in self.fortran_libraries:\n if lib_name == name:\n return 1\n \n def get_library_names(self, name=None):\n if not self.has_f_libraries():\n return None\n\n lib_names = []\n\n if name is None:\n for (lib_name, build_info) in self.fortran_libraries:\n lib_names.append(lib_name)\n\n if self.fcompiler is not None:\n lib_names.extend(self.fcompiler.get_libraries())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n for n in build_info.get('libraries',[]):\n lib_names.append(n)\n #XXX: how to catch recursive calls here?\n lib_names.extend(self.get_library_names(n))\n break\n return lib_names\n\n def get_fcompiler_library_names(self):\n #if not self.has_f_libraries():\n # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_libraries()\n return []\n\n def get_fcompiler_library_dirs(self):\n #if not self.has_f_libraries():\n # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_library_dirs()\n return []\n\n # get_library_names ()\n\n def get_library_dirs(self, name=None):\n if not self.has_f_libraries():\n return []\n\n lib_dirs = [] \n\n if name is None:\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_library_dirs())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n lib_dirs.extend(build_info.get('library_dirs',[]))\n for n in build_info.get('libraries',[]):\n lib_dirs.extend(self.get_library_dirs(n))\n break\n\n return lib_dirs\n\n # get_library_dirs ()\n\n def get_runtime_library_dirs(self):\n #if not self.has_f_libraries():\n # return []\n\n lib_dirs = []\n\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_runtime_library_dirs())\n \n return lib_dirs\n\n # get_library_dirs ()\n\n def get_source_files (self):\n if not self.has_f_libraries():\n return []\n\n self.check_library_list(self.fortran_libraries)\n filenames = []\n\n # Gets source files specified \n for ext in self.fortran_libraries:\n filenames.extend(ext[1]['sources'])\n\n return filenames \n \n def build_libraries (self, fortran_libraries):\n \n fcompiler = self.fcompiler\n \n for (lib_name, build_info) in fortran_libraries:\n self.announce(\" building '%s' library\" % lib_name)\n\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'fortran_libraries' option (library '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % lib_name\n sources = list(sources)\n module_dirs = build_info.get('module_dirs')\n module_files = build_info.get('module_files')\n\n\n include_dirs = build_info.get('include_dirs')\n\n if include_dirs:\n fcompiler.set_include_dirs(include_dirs)\n for n,v in build_info.get('define_macros') or []:\n fcompiler.define_macro(n,v)\n for n in build_info.get('undef_macros') or []:\n fcompiler.undefine_macro(n)\n\n if module_files:\n fcompiler.build_library(lib_name, module_files,\n temp_dir=self.build_temp)\n \n fcompiler.build_library(lib_name, sources,\n module_dirs, temp_dir=self.build_temp)\n\n # for loop\n\n # build_libraries ()\n\n\nclass fortran_compiler_base(CCompiler):\n\n vendor = None\n ver_match = None\n\n compiler_type = 'fortran'\n executables = {}\n \n def __init__(self,verbose=0,dry_run=0,force=0):\n # Default initialization. Constructors of derived classes MUST\n # call this function.\n CCompiler.__init__(self,verbose,dry_run,force)\n\n self.version = None\n \n self.f77_switches = ''\n self.f77_opt = ''\n self.f77_debug = ''\n \n self.f90_switches = ''\n self.f90_opt = ''\n self.f90_debug = ''\n \n #self.libraries = []\n #self.library_dirs = []\n\n if self.vendor is None:\n raise DistutilsInternalError,\\\n '%s must define vendor attribute'%(self.__class__)\n if self.ver_match is None:\n raise DistutilsInternalError,\\\n '%s must define ver_match attribute'%(self.__class__)\n\n def to_object(self,\n dirty_files,\n module_dirs=None,\n temp_dir=''):\n files = string.join(dirty_files)\n f90_files = get_f90_files(dirty_files)\n f77_files = get_f77_files(dirty_files)\n if f90_files != []:\n obj1 = self.f90_compile(f90_files,module_dirs,temp_dir = temp_dir)\n else:\n obj1 = []\n if f77_files != []:\n obj2 = self.f77_compile(f77_files, temp_dir = temp_dir)\n else:\n obj2 = []\n return obj1 + obj2\n\n def source_to_object_names(self,source_files, temp_dir=''):\n file_list = map(lambda x: os.path.basename(x),source_files)\n file_base_ext = map(lambda x: os.path.splitext(x),file_list)\n object_list = map(lambda x: x[0] +'.o',file_base_ext)\n object_files = map(lambda x,td=temp_dir: os.path.join(td,x),object_list)\n return object_files\n \n def source_and_object_pairs(self,source_files, temp_dir=''):\n object_files = self.source_to_object_names(source_files,temp_dir)\n file_pairs = zip(source_files,object_files)\n return file_pairs\n \n def f_compile(self,compiler,switches, source_files,\n module_dirs=None, temp_dir=''):\n\n pp_opts = gen_preprocess_options(self.macros,self.include_dirs)\n\n switches = switches + string.join(pp_opts,' ')\n\n module_switch = self.build_module_switch(module_dirs)\n file_pairs = self.source_and_object_pairs(source_files,temp_dir)\n object_files = []\n for source,object in file_pairs:\n if distutils.dep_util.newer(source,object):\n cmd = compiler + ' ' + switches + \\\n module_switch + \\\n ' -c ' + source + ' -o ' + object \n print cmd\n failure = os.system(cmd)\n if failure:\n raise FortranCompileError, 'failure during compile' \n object_files.append(object)\n return object_files\n #return all object files to make sure everything is archived \n #return map(lambda x: x[1], file_pairs)\n\n def f90_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f90_switches, self.f90_opt))\n return self.f_compile(self.f90_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n def f77_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f77_switches, self.f77_opt))\n return self.f_compile(self.f77_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n\n def build_module_switch(self, module_dirs):\n return ''\n\n def create_static_lib(self, object_files, library_name,\n output_dir='', debug=None):\n lib_file = os.path.join(output_dir,'lib'+library_name+'.a')\n newer = distutils.dep_util.newer\n # This doesn't work -- no way to know if the file is in the archive\n #object_files = filter(lambda o,lib=lib_file:\\\n # distutils.dep_util.newer(o,lib),object_files)\n objects = string.join(object_files)\n if objects:\n cmd = 'ar -cur %s %s' % (lib_file,objects)\n print cmd\n os.system(cmd)\n\n def build_library(self,library_name,source_list,module_dirs=None,\n temp_dir = ''):\n #make sure the temp directory exists before trying to build files\n import distutils.dir_util\n distutils.dir_util.mkpath(temp_dir)\n\n #this compiles the files\n object_list = self.to_object(source_list,\n module_dirs,\n temp_dir)\n\n # actually we need to use all the object file names here to\n # make sure the library is always built. It could occur that an\n # object file exists but hasn't been put in the archive. (happens\n # a lot when builds fail once and are restarted).\n object_list = self.source_to_object_names(source_list, temp_dir)\n\n if os.name == 'nt':\n # This is pure bunk...\n # Windows fails for long argument strings on the command line.\n # if objects is real long (> 2048 chars or so on my machine),\n # the command fails (cmd.exe /e:2048 on w2k)\n # for now we'll split linking into to steps which should work for\n objects = object_list[:]\n while objects:\n obj,objects = objects[:20],objects[20:]\n self.create_static_lib(obj,library_name,temp_dir)\n else:\n self.create_static_lib(object_list,library_name,temp_dir)\n\n def dummy_fortran_files(self):\n import tempfile \n d = tempfile.gettempdir()\n dummy_name = os.path.join(d,'__dummy.f')\n dummy = open(dummy_name,'w')\n dummy.write(\" subroutine dummy()\\n end\\n\")\n dummy.close()\n return (os.path.join(d,'__dummy.f'),os.path.join(d,'__dummy.o'))\n \n def is_available(self):\n return self.get_version()\n \n def get_version(self):\n \"\"\"Return the compiler version. If compiler is not available,\n return empty string.\"\"\"\n # XXX: Is there compilers that have no version? If yes,\n # this test will fail even if the compiler is available.\n if self.version is not None:\n # Finding version is expensive, so return previously found\n # version string.\n return self.version\n self.version = ''\n # works I think only for unix... \n #print 'command:', self.ver_cmd\n exit_status, out_text = run_command(self.ver_cmd)\n #print exit_status, out_text\n if not exit_status:\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\n return self.version\n\n def get_libraries(self):\n return self.libraries\n def get_library_dirs(self):\n return self.library_dirs\n def get_extra_link_args(self):\n return []\n def get_runtime_library_dirs(self):\n return []\n def get_linker_so(self):\n \"\"\"\n If a compiler requires specific linker then return a list\n containing a linker executable name and linker options.\n Otherwise, return None.\n \"\"\"\n\n def __str__(self):\n return \"%s %s\" % (self.vendor, self.get_version())\n\n\nclass absoft_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Absoft'\n ver_match = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n \n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n # got rid of -B108 cause it was generating 2 underscores instead\n # of one on the newest version. Now we use -YEXT_SFX=_ to \n # specify the output format\n if os.name == 'nt':\n self.f90_switches = '-f fixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -Q100'\n self.f77_switches = '-N22 -N90 -N110'\n self.f77_opt = '-O -Q100'\n self.libraries = ['fio', 'fmath', 'f90math', 'COMDLG32']\n else:\n self.f90_switches = '-ffixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -B101' \n self.f77_switches = '-N22 -N90 -N110 -B108'\n self.f77_opt = '-O -B101'\n\n self.libraries = ['fio', 'f77math', 'f90math']\n \n try:\n dir = os.environ['ABSOFT'] \n self.library_dirs = [os.path.join(dir,'lib')]\n except KeyError:\n self.library_dirs = []\n\n self.ver_cmd = self.f77_compiler + ' -V -c %s -o %s' % \\\n self.dummy_fortran_files()\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -p' + mod\n return res\n\n def get_extra_link_args(self):\n return []\n # Couldn't get this to link for anything using gcc.\n #dr = \"c:\\\\Absoft62\\\\lib\"\n #libs = ['fio.lib', 'COMDLG32.lib','fmath.lib', 'f90math.lib','libcomdlg32.a' ] \n #libs = map(lambda x,dr=dr:os.path.join(dr,x),libs)\n #return libs\n\n\nclass sun_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Sun'\n ver_match = r'f77: (?P[^\\s*,]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc # not tested\n self.f77_switches = ' -pic '\n self.f77_opt = ' -fast -dalign '\n\n self.f90_compiler = f90c\n self.f90_switches = ' -fixed ' # ??? why fixed?\n self.f90_opt = ' -fast -dalign '\n\n self.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\n #threaded\n #self.libraries = ['f90', 'F77_mt', 'sunmath_mt', 'm', 'thread']\n #self.libraries = []\n self.library_dirs = self.find_lib_dir()\n #print 'sun:',self.library_dirs\n\n self.ver_cmd = self.f77_compiler + ' -V'\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -M' + mod\n return res\n\n def find_lib_dir(self):\n library_dirs = []\n lib_match = r'### f90: Note: LD_RUN_PATH\\s*= '\\\n '(?P[^\\s.]*).*'\n cmd = self.f90_compiler + ' -dryrun dummy.f'\n exit_status, output = run_command(cmd)\n if not exit_status:\n libs = re.findall(lib_match,output)\n if libs:\n library_dirs = string.split(libs[0],':')\n self.get_version() # force version calculation\n compiler_home = os.path.dirname(library_dirs[0])\n library_dirs.append(os.path.join(compiler_home,\n self.version,'lib'))\n return library_dirs\n def get_runtime_library_dirs(self):\n return self.find_lib_dir()\n def get_extra_link_args(self):\n return ['-mimpure-text']\n\n\nclass mips_fortran_compiler(fortran_compiler_base):\n\n vendor = 'SGI'\n ver_match = r'MIPSpro Compilers: Version (?P[^\\s*,]*)'\n \n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc # not tested\n self.f77_switches = ' -n32 -KPIC '\n self.f77_opt = ' -O3 '\n\n self.f90_compiler = f90c\n self.f90_switches = ' -n32 -KPIC -fixedform ' # why fixed ???\n self.f90_opt = ' ' \n \n self.libraries = ['fortran', 'ftn', 'm']\n self.library_dirs = self.find_lib_dir()\n\n self.ver_cmd = self.f77_compiler + ' -version'\n\n def build_module_switch(self,module_dirs):\n res = ''\n return res \n def find_lib_dir(self):\n library_dirs = []\n return library_dirs\n def get_runtime_library_dirs(self):\n\treturn self.find_lib_dir() \n def get_extra_link_args(self):\n\treturn []\n\n\nclass gnu_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Gnu'\n ver_match = r'g77 version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if sys.platform == 'win32':\n self.libraries = ['gcc','g2c']\n self.library_dirs = self.find_lib_directories()\n else:\n # On linux g77 does not need lib_directories to be specified.\n self.libraries = ['g2c']\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n\n switches = ' -Wall -fno-second-underscore '\n\n if os.name != 'nt':\n switches = switches + ' -fpic '\n\n self.f77_switches = switches\n\n self.ver_cmd = self.f77_compiler + ' -v '\n self.f77_opt = self.get_opt()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 -funroll-loops '\n \n # only check for more optimization if g77 can handle\n # it.\n if self.get_version():\n if self.version[0]=='3': # is g77 3.x.x\n if cpu.is_AthlonK6():\n opt = opt + ' -march=k6 '\n elif cpu.is_AthlonK7():\n opt = opt + ' -march=athlon '\n if cpu.is_i686():\n opt = opt + ' -march=i686 '\n elif cpu.is_i586():\n opt = opt + ' -march=i586 '\n elif cpu.is_i486():\n opt = opt + ' -march=i486 '\n elif cpu.is_i386():\n opt = opt + ' -march=i386 '\n if cpu.is_Intel():\n opt = opt + ' -malign-double ' \n return opt\n \n def find_lib_directories(self):\n lib_dir = []\n match = r'Reading specs from (.*)/specs'\n\n # works I think only for unix... \n exit_status, out_text = run_command('g77 -v')\n if not exit_status:\n m = re.findall(match,out_text)\n if m:\n lib_dir= m #m[0] \n return lib_dir\n\n def get_linker_so(self):\n # win32 linking should be handled by standard linker\n if sys.platform != 'win32':\n return [self.f77_compiler,'-shared']\n \n def f90_compile(self,source_files,module_files,temp_dir=''):\n raise DistutilsExecError, 'f90 not supported by Gnu'\n\n\n#http://developer.intel.com/software/products/compilers/f50/linux/\nclass intel_ia32_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Intel' # Intel(R) Corporation \n ver_match = r'Intel\\(R\\) Fortran Compiler for 32-bit applications, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'ifc'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -KPIC '\n\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n if cpu.has_fdiv_bug():\n switches = switches + ' -fdiv_check '\n if cpu.has_f00f_bug():\n switches = switches + ' -0f_check '\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -FI -w90 -w95 '\n\n self.f77_opt = self.f90_opt = self.get_opt()\n \n debug = ' -g -C '\n self.f77_debug = self.f90_debug = debug\n\n self.ver_cmd = self.f77_compiler+' -FI -V -c %s -o %s' %\\\n self.dummy_fortran_files()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 '\n if cpu.is_PentiumPro() or cpu.is_PentiumII():\n opt = opt + ' -tpp6 -xi '\n elif cpu.is_PentiumIII():\n opt = opt + ' -tpp6 '\n elif cpu.is_Pentium():\n opt = opt + ' -tpp5 '\n elif cpu.is_PentiumIV():\n opt = opt + ' -tpp7 -xW '\n elif cpu.has_mmx():\n opt = opt + ' -xM '\n return opt\n \n\n def get_linker_so(self):\n return [self.f77_compiler,'-shared']\n\n\nclass intel_itanium_fortran_compiler(intel_ia32_fortran_compiler):\n\n vendor = 'Itanium'\n ver_match = r'Intel\\(R\\) Fortran 90 Compiler Itanium\\(TM\\) Compiler for the Itanium\\(TM\\)-based applications, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n if fc is None:\n fc = 'efc'\n intel_ia32_fortran_compiler.__init__(self, fc, f90c)\n\n\nclass nag_fortran_compiler(fortran_compiler_base):\n\n vendor = 'NAG'\n ver_match = r'NAGWare Fortran 95 compiler Release (?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'f95'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ''\n debug = ' -g -gline -g90 -nan -C '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -fixed '\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -target=native '\n return opt\n\n def get_linker_so(self):\n return [self.f77_compiler,'-Wl,-shared']\n\n\nclass vast_fortran_compiler(fortran_compiler_base):\n\n vendor = 'VAST'\n ver_match = r'\\s*Pacific-Sierra Research vf90 (Personal|Professional)\\s+(?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n d,b = os.path.split(f90c)\n vf90 = os.path.join(d,'v'+b)\n self.ver_cmd = vf90+' -v '\n\n gnu = gnu_fortran_compiler(fc)\n if not gnu.is_available(): # VAST compiler requires g77.\n self.version = ''\n return\n if not self.is_available():\n return\n\n self.f77_switches = gnu.f77_switches\n self.f77_debug = gnu.f77_debug\n self.f77_opt = gnu.f77_opt \n\n # XXX: need f90 switches, debug, opt\n\n def get_linker_so(self):\n return [self.f90_compiler,'-shared']\n\nclass compaq_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Compaq'\n ver_match = r'Compaq Fortran (?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'fort'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -assume no2underscore -nomixed_str_len_arg '\n debug = ' -g -check_bounds '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n # XXX: uncomment if required\n #self.libraries = ' -lUfor -lfor -lFutil -lcpml -lots -lc '\n\n # XXX: fix the version showing flag\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -align dcommons -arch host -assume bigarrays -assume nozsize -math_library fast -tune host '\n return opt\n\n def get_linker_so(self):\n # XXX: is -shared needed?\n return [self.f77_compiler,'-shared']\n\n\ndef match_extension(files,ext):\n match = re.compile(r'.*[.]('+ext+r')\\Z',re.I).match\n return filter(lambda x,match = match: match(x),files)\n\ndef get_f77_files(files):\n return match_extension(files,'for|f77|ftn|f')\n\ndef get_f90_files(files):\n return match_extension(files,'f90|f95')\n\ndef get_fortran_files(files):\n return match_extension(files,'f90|f95|for|f77|ftn|f')\n\ndef find_fortran_compiler(vendor = None, fc = None, f90c = None):\n fcompiler = None\n for compiler_class in all_compilers:\n if vendor is not None and vendor != compiler_class.vendor:\n continue\n print compiler_class\n compiler = compiler_class(fc,f90c)\n if compiler.is_available():\n fcompiler = compiler\n break\n return fcompiler\n\nall_compilers = [absoft_fortran_compiler,\n mips_fortran_compiler,\n sun_fortran_compiler,\n intel_ia32_fortran_compiler,\n intel_itanium_fortran_compiler,\n nag_fortran_compiler,\n compaq_fortran_compiler,\n vast_fortran_compiler,\n gnu_fortran_compiler,\n ]\n\nif __name__ == \"__main__\":\n show_compilers()\n", + "source_code_before": "\"\"\" Implements the build_flib command which should go into Distutils\n at some point.\n \n Note:\n Right now, we're dynamically linking to the Fortran libraries on \n some platforms (Sun for sure). This is fine for local installations\n but a bad thing for redistribution because these libraries won't\n live on any machine that doesn't have a fortran compiler installed.\n It is pretty hard (impossible?) to get gcc to pass the right compiler\n flags on Sun to get the linker to use static libs for the fortran\n stuff. Investigate further...\n\nBugs:\n *** Options -e and -x have no effect when used with --help-compiler\n options. E.g. \n ./setup.py build_flib --help-compiler -e g77-3.0\n finds g77-2.95.\n How to extract these options inside the show_compilers function?\n *** compiler.is_available() method may not work correctly on nt\n because of lack of knowledge how to get exit status in\n run_command function. However, it may give reasonable results\n based on a version string.\n *** Some vendors provide different compilers for F77 and F90\n compilations. Currently, checking the availability of these\n compilers is based on only checking the availability of the\n corresponding F77 compiler. If it exists, then F90 is assumed\n to exist also.\n\nOpen issues:\n *** User-defined compiler flags. Do we need --fflags?\n\nFortran compilers (as to be used with --fcompiler= option):\n Absoft\n Sun\n SGI\n Intel\n Itanium\n NAG\n Compaq\n Gnu\n VAST\n\"\"\"\n\nimport distutils\nimport distutils.dep_util, distutils.dir_util\nimport os,sys,string\nimport commands,re\nfrom types import *\nfrom distutils.command.build_clib import build_clib\nfrom distutils.errors import *\n\nclass FortranCompilerError (CCompilerError):\n \"\"\"Some compile/link operation failed.\"\"\"\nclass FortranCompileError (FortranCompilerError):\n \"\"\"Failure to compile one or more Fortran source files.\"\"\"\n\nif os.name == 'nt':\n def run_command(command):\n \"\"\" not sure how to get exit status on nt. \"\"\"\n in_pipe,out_pipe = os.popen4(command)\n in_pipe.close()\n text = out_pipe.read()\n return 0, text\nelse:\n run_command = commands.getstatusoutput\n \ndef show_compilers():\n for compiler_class in all_compilers:\n compiler = compiler_class()\n if compiler.is_available():\n print compiler\n\nclass build_flib (build_clib):\n\n description = \"build f77/f90 libraries used by Python extensions\"\n\n user_options = [\n ('build-flib', 'b',\n \"directory to build f77/f90 libraries to\"),\n ('build-temp', 't',\n \"directory to put temporary build by-products\"),\n ('debug', 'g',\n \"compile with debugging information\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ('fcompiler=', 'c',\n \"specify the compiler type\"),\n ('fcompiler-exec=', 'e',\n \"specify the path to F77 compiler\"),\n ('f90compiler-exec=', 'x',\n \"specify the path to F90 compiler\"),\n ]\n\n boolean_options = ['debug', 'force']\n\n help_options = [\n ('help-compiler', None,\n \"list available compilers\", show_compilers),\n ]\n\n def initialize_options (self):\n\n self.build_flib = None\n self.build_temp = None\n\n self.fortran_libraries = None\n self.define = None\n self.undef = None\n self.debug = None\n self.force = 0\n self.fcompiler = None\n self.fcompiler_exec = None\n self.f90compiler_exec = None\n\n # initialize_options()\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_flib'),\n ('build_temp', 'build_temp'),\n ('debug', 'debug'),\n ('force', 'force'))\n fc = find_fortran_compiler(self.fcompiler,\n self.fcompiler_exec,\n self.f90compiler_exec)\n if not fc:\n raise DistutilsOptionError, 'Fortran compiler not available: %s'%(self.fcompiler)\n else:\n self.announce(' using %s Fortran compiler' % fc)\n self.fcompiler = fc\n if self.has_f_libraries():\n self.fortran_libraries = self.distribution.fortran_libraries\n self.check_library_list(self.fortran_libraries)\n\n # finalize_options()\n\n def has_f_libraries(self):\n return self.distribution.fortran_libraries \\\n and len(self.distribution.fortran_libraries) > 0\n\n def run (self):\n if not self.has_f_libraries():\n return\n self.build_libraries(self.fortran_libraries)\n\n # run ()\n\n def has_f_library(self,name):\n if self.has_f_libraries():\n for (lib_name, build_info) in self.fortran_libraries:\n if lib_name == name:\n return 1\n \n def get_library_names(self, name=None):\n if not self.has_f_libraries():\n return None\n\n lib_names = []\n\n if name is None:\n for (lib_name, build_info) in self.fortran_libraries:\n lib_names.append(lib_name)\n\n if self.fcompiler is not None:\n lib_names.extend(self.fcompiler.get_libraries())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n for n in build_info.get('libraries',[]):\n lib_names.append(n)\n #XXX: how to catch recursive calls here?\n lib_names.extend(self.get_library_names(n))\n break\n return lib_names\n\n def get_fcompiler_library_names(self):\n #if not self.has_f_libraries():\n # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_libraries()\n return []\n\n def get_fcompiler_library_dirs(self):\n #if not self.has_f_libraries():\n # return None\n if self.fcompiler is not None:\n return self.fcompiler.get_library_dirs()\n return []\n\n # get_library_names ()\n\n def get_library_dirs(self, name=None):\n if not self.has_f_libraries():\n return []\n\n lib_dirs = [] \n\n if name is None:\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_library_dirs())\n else:\n for (lib_name, build_info) in self.fortran_libraries:\n if name != lib_name: continue\n lib_dirs.extend(build_info.get('library_dirs',[]))\n for n in build_info.get('libraries',[]):\n lib_dirs.extend(self.get_library_dirs(n))\n break\n\n return lib_dirs\n\n # get_library_dirs ()\n\n def get_runtime_library_dirs(self):\n #if not self.has_f_libraries():\n # return []\n\n lib_dirs = []\n\n if self.fcompiler is not None:\n lib_dirs.extend(self.fcompiler.get_runtime_library_dirs())\n \n return lib_dirs\n\n # get_library_dirs ()\n\n def get_source_files (self):\n if not self.has_f_libraries():\n return []\n\n self.check_library_list(self.fortran_libraries)\n filenames = []\n\n # Gets source files specified \n for ext in self.fortran_libraries:\n filenames.extend(ext[1]['sources'])\n\n return filenames \n \n def build_libraries (self, fortran_libraries):\n \n fcompiler = self.fcompiler\n \n for (lib_name, build_info) in fortran_libraries:\n sources = build_info.get('sources')\n if sources is None or type(sources) not in (ListType, TupleType):\n raise DistutilsSetupError, \\\n (\"in 'fortran_libraries' option (library '%s'), \" +\n \"'sources' must be present and must be \" +\n \"a list of source filenames\") % lib_name\n sources = list(sources)\n module_dirs = build_info.get('module_dirs')\n module_files = build_info.get('module_files')\n self.announce(\" building '%s' library\" % lib_name)\n \n if module_files:\n fcompiler.build_library(lib_name, module_files,\n temp_dir=self.build_temp)\n \n fcompiler.build_library(lib_name, sources,\n module_dirs, temp_dir=self.build_temp)\n\n # for loop\n\n # build_libraries ()\n\n\nclass fortran_compiler_base:\n\n vendor = None\n ver_match = None\n \n def __init__(self):\n # Default initialization. Constructors of derived classes MUST\n # call this functions.\n self.version = None\n \n self.f77_switches = ''\n self.f77_opt = ''\n self.f77_debug = ''\n \n self.f90_switches = ''\n self.f90_opt = ''\n self.f90_debug = ''\n \n self.libraries = []\n self.library_dirs = []\n\n if self.vendor is None:\n raise DistutilsInternalError,\\\n '%s must define vendor attribute'%(self.__class__)\n if self.ver_match is None:\n raise DistutilsInternalError,\\\n '%s must define ver_match attribute'%(self.__class__)\n\n def to_object(self,dirty_files,module_dirs=None, temp_dir=''):\n files = string.join(dirty_files)\n f90_files = get_f90_files(dirty_files)\n f77_files = get_f77_files(dirty_files)\n if f90_files != []:\n obj1 = self.f90_compile(f90_files,module_dirs,temp_dir = temp_dir)\n else:\n obj1 = []\n if f77_files != []:\n obj2 = self.f77_compile(f77_files, temp_dir = temp_dir)\n else:\n obj2 = []\n return obj1 + obj2\n\n def source_to_object_names(self,source_files, temp_dir=''):\n file_list = map(lambda x: os.path.basename(x),source_files)\n file_base_ext = map(lambda x: os.path.splitext(x),file_list)\n object_list = map(lambda x: x[0] +'.o',file_base_ext)\n object_files = map(lambda x,td=temp_dir: os.path.join(td,x),object_list)\n return object_files\n \n def source_and_object_pairs(self,source_files, temp_dir=''):\n object_files = self.source_to_object_names(source_files,temp_dir)\n file_pairs = zip(source_files,object_files)\n return file_pairs\n \n def f_compile(self,compiler,switches, source_files,\n module_dirs=None, temp_dir=''):\n module_switch = self.build_module_switch(module_dirs)\n file_pairs = self.source_and_object_pairs(source_files,temp_dir)\n object_files = []\n for source,object in file_pairs:\n if distutils.dep_util.newer(source,object):\n cmd = compiler + ' ' + switches + \\\n module_switch + ' -c ' + source + ' -o ' + object \n print cmd\n failure = os.system(cmd)\n if failure:\n raise FortranCompileError, 'failure during compile' \n object_files.append(object)\n return object_files\n #return all object files to make sure everything is archived \n #return map(lambda x: x[1], file_pairs)\n\n def f90_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f90_switches, self.f90_opt))\n return self.f_compile(self.f90_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n def f77_compile(self,source_files,module_dirs=None, temp_dir=''):\n switches = string.join((self.f77_switches, self.f77_opt))\n return self.f_compile(self.f77_compiler,switches,\n source_files, module_dirs,temp_dir)\n\n\n def build_module_switch(self, module_dirs):\n return ''\n\n def create_static_lib(self, object_files, library_name,\n output_dir='', debug=None):\n lib_file = os.path.join(output_dir,'lib'+library_name+'.a')\n newer = distutils.dep_util.newer\n # This doesn't work -- no way to know if the file is in the archive\n #object_files = filter(lambda o,lib=lib_file:\\\n # distutils.dep_util.newer(o,lib),object_files)\n objects = string.join(object_files)\n if objects:\n cmd = 'ar -cur %s %s' % (lib_file,objects)\n print cmd\n os.system(cmd)\n\n def build_library(self,library_name,source_list,module_dirs=None,\n temp_dir = ''):\n #make sure the temp directory exists before trying to build files\n import distutils.dir_util\n distutils.dir_util.mkpath(temp_dir)\n\n #this compiles the files\n object_list = self.to_object(source_list,module_dirs,temp_dir)\n\n # actually we need to use all the object file names here to\n # make sure the library is always built. It could occur that an\n # object file exists but hasn't been put in the archive. (happens\n # a lot when builds fail once and are restarted).\n object_list = self.source_to_object_names(source_list, temp_dir)\n\n if os.name == 'nt':\n # This is pure bunk...\n # Windows fails for long argument strings on the command line.\n # if objects is real long (> 2048 chars or so on my machine),\n # the command fails (cmd.exe /e:2048 on w2k)\n # for now we'll split linking into to steps which should work for\n objects = object_list[:]\n while objects:\n obj,objects = objects[:20],objects[20:]\n self.create_static_lib(obj,library_name,temp_dir)\n else:\n self.create_static_lib(object_list,library_name,temp_dir)\n\n def dummy_fortran_files(self):\n import tempfile \n d = tempfile.gettempdir()\n dummy_name = os.path.join(d,'__dummy.f')\n dummy = open(dummy_name,'w')\n dummy.write(\" subroutine dummy()\\n end\\n\")\n dummy.close()\n return (os.path.join(d,'__dummy.f'),os.path.join(d,'__dummy.o'))\n \n def is_available(self):\n return self.get_version()\n \n def get_version(self):\n \"\"\"Return the compiler version. If compiler is not available,\n return empty string.\"\"\"\n # XXX: Is there compilers that have no version? If yes,\n # this test will fail even if the compiler is available.\n if self.version is not None:\n # Finding version is expensive, so return previously found\n # version string.\n return self.version\n self.version = ''\n # works I think only for unix... \n #print 'command:', self.ver_cmd\n exit_status, out_text = run_command(self.ver_cmd)\n #print exit_status, out_text\n if not exit_status:\n m = re.match(self.ver_match,out_text)\n if m:\n self.version = m.group('version')\n return self.version\n\n def get_libraries(self):\n return self.libraries\n def get_library_dirs(self):\n return self.library_dirs\n def get_extra_link_args(self):\n return []\n def get_runtime_library_dirs(self):\n return []\n def get_linker_so(self):\n \"\"\"\n If a compiler requires specific linker then return a list\n containing a linker executable name and linker options.\n Otherwise, return None.\n \"\"\"\n\n def __str__(self):\n return \"%s %s\" % (self.vendor, self.get_version())\n\n\nclass absoft_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Absoft'\n ver_match = r'FORTRAN 77 Compiler (?P[^\\s*,]*).*?Absoft Corp'\n \n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n # got rid of -B108 cause it was generating 2 underscores instead\n # of one on the newest version. Now we use -YEXT_SFX=_ to \n # specify the output format\n if os.name == 'nt':\n self.f90_switches = '-f fixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -Q100'\n self.f77_switches = '-N22 -N90 -N110'\n self.f77_opt = '-O -Q100'\n self.libraries = ['fio', 'fmath', 'f90math', 'COMDLG32']\n else:\n self.f90_switches = '-ffixed -YCFRL=1 -YCOM_NAMES=LCS' \\\n ' -YCOM_PFX -YEXT_PFX -YEXT_NAMES=LCS' \\\n ' -YCOM_SFX=_ -YEXT_SFX=_ -YEXT_NAMES=LCS' \n self.f90_opt = '-O -B101' \n self.f77_switches = '-N22 -N90 -N110 -B108'\n self.f77_opt = '-O -B101'\n\n self.libraries = ['fio', 'f77math', 'f90math']\n \n try:\n dir = os.environ['ABSOFT'] \n self.library_dirs = [os.path.join(dir,'lib')]\n except KeyError:\n self.library_dirs = []\n\n self.ver_cmd = self.f77_compiler + ' -V -c %s -o %s' % \\\n self.dummy_fortran_files()\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -p' + mod\n return res\n\n def get_extra_link_args(self):\n return []\n # Couldn't get this to link for anything using gcc.\n #dr = \"c:\\\\Absoft62\\\\lib\"\n #libs = ['fio.lib', 'COMDLG32.lib','fmath.lib', 'f90math.lib','libcomdlg32.a' ] \n #libs = map(lambda x,dr=dr:os.path.join(dr,x),libs)\n #return libs\n\n\nclass sun_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Sun'\n ver_match = r'f77: (?P[^\\s*,]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc # not tested\n self.f77_switches = ' -pic '\n self.f77_opt = ' -fast -dalign '\n\n self.f90_compiler = f90c\n self.f90_switches = ' -fixed ' # ??? why fixed?\n self.f90_opt = ' -fast -dalign '\n\n self.libraries = ['f90', 'F77', 'M77', 'sunmath', 'm']\n #threaded\n #self.libraries = ['f90', 'F77_mt', 'sunmath_mt', 'm', 'thread']\n #self.libraries = []\n self.library_dirs = self.find_lib_dir()\n #print 'sun:',self.library_dirs\n\n self.ver_cmd = self.f77_compiler + ' -V'\n\n def build_module_switch(self,module_dirs):\n res = ''\n if module_dirs:\n for mod in module_dirs:\n res = res + ' -M' + mod\n return res\n\n def find_lib_dir(self):\n library_dirs = []\n lib_match = r'### f90: Note: LD_RUN_PATH\\s*= '\\\n '(?P[^\\s.]*).*'\n cmd = self.f90_compiler + ' -dryrun dummy.f'\n exit_status, output = run_command(cmd)\n if not exit_status:\n libs = re.findall(lib_match,output)\n if libs:\n library_dirs = string.split(libs[0],':')\n self.get_version() # force version calculation\n compiler_home = os.path.dirname(library_dirs[0])\n library_dirs.append(os.path.join(compiler_home,\n self.version,'lib'))\n return library_dirs\n def get_runtime_library_dirs(self):\n return self.find_lib_dir()\n def get_extra_link_args(self):\n return ['-mimpure-text']\n\n\nclass mips_fortran_compiler(fortran_compiler_base):\n\n vendor = 'SGI'\n ver_match = r'MIPSpro Compilers: Version (?P[^\\s*,]*)'\n \n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if fc is None:\n fc = 'f77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc # not tested\n self.f77_switches = ' -n32 -KPIC '\n self.f77_opt = ' -O3 '\n\n self.f90_compiler = f90c\n self.f90_switches = ' -n32 -KPIC -fixedform ' # why fixed ???\n self.f90_opt = ' ' \n \n self.libraries = ['fortran', 'ftn', 'm']\n self.library_dirs = self.find_lib_dir()\n\n self.ver_cmd = self.f77_compiler + ' -version'\n\n def build_module_switch(self,module_dirs):\n res = ''\n return res \n def find_lib_dir(self):\n library_dirs = []\n return library_dirs\n def get_runtime_library_dirs(self):\n\treturn self.find_lib_dir() \n def get_extra_link_args(self):\n\treturn []\n\n\nclass gnu_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Gnu'\n ver_match = r'g77 version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n if sys.platform == 'win32':\n self.libraries = ['gcc','g2c']\n self.library_dirs = self.find_lib_directories()\n else:\n # On linux g77 does not need lib_directories to be specified.\n self.libraries = ['g2c']\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n\n switches = ' -Wall -fno-second-underscore '\n\n if os.name != 'nt':\n switches = switches + ' -fpic '\n\n self.f77_switches = switches\n\n self.ver_cmd = self.f77_compiler + ' -v '\n self.f77_opt = self.get_opt()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 -funroll-loops '\n \n # only check for more optimization if g77 can handle\n # it.\n if self.get_version():\n if self.version[0]=='3': # is g77 3.x.x\n if cpu.is_AthlonK6():\n opt = opt + ' -march=k6 '\n elif cpu.is_AthlonK7():\n opt = opt + ' -march=athlon '\n if cpu.is_i686():\n opt = opt + ' -march=i686 '\n elif cpu.is_i586():\n opt = opt + ' -march=i586 '\n elif cpu.is_i486():\n opt = opt + ' -march=i486 '\n elif cpu.is_i386():\n opt = opt + ' -march=i386 '\n if cpu.is_Intel():\n opt = opt + ' -malign-double ' \n return opt\n \n def find_lib_directories(self):\n lib_dir = []\n match = r'Reading specs from (.*)/specs'\n\n # works I think only for unix... \n exit_status, out_text = run_command('g77 -v')\n if not exit_status:\n m = re.findall(match,out_text)\n if m:\n lib_dir= m #m[0] \n return lib_dir\n\n def get_linker_so(self):\n # win32 linking should be handled by standard linker\n if sys.platform != 'win32':\n return [self.f77_compiler,'-shared']\n \n def f90_compile(self,source_files,module_files,temp_dir=''):\n raise DistutilsExecError, 'f90 not supported by Gnu'\n\n\n#http://developer.intel.com/software/products/compilers/f50/linux/\nclass intel_ia32_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Intel' # Intel(R) Corporation \n ver_match = r'Intel\\(R\\) Fortran Compiler for 32-bit applications, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'ifc'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -KPIC '\n\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n if cpu.has_fdiv_bug():\n switches = switches + ' -fdiv_check '\n if cpu.has_f00f_bug():\n switches = switches + ' -0f_check '\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -FI -w90 -w95 '\n\n self.f77_opt = self.f90_opt = self.get_opt()\n \n debug = ' -g -C '\n self.f77_debug = self.f90_debug = debug\n\n self.ver_cmd = self.f77_compiler+' -FI -V -c %s -o %s' %\\\n self.dummy_fortran_files()\n\n def get_opt(self):\n import cpuinfo\n cpu = cpuinfo.cpuinfo()\n opt = ' -O3 '\n if cpu.is_PentiumPro() or cpu.is_PentiumII():\n opt = opt + ' -tpp6 -xi '\n elif cpu.is_PentiumIII():\n opt = opt + ' -tpp6 '\n elif cpu.is_Pentium():\n opt = opt + ' -tpp5 '\n elif cpu.is_PentiumIV():\n opt = opt + ' -tpp7 -xW '\n elif cpu.has_mmx():\n opt = opt + ' -xM '\n return opt\n \n\n def get_linker_so(self):\n return [self.f77_compiler,'-shared']\n\n\nclass intel_itanium_fortran_compiler(intel_ia32_fortran_compiler):\n\n vendor = 'Itanium'\n ver_match = r'Intel\\(R\\) Fortran 90 Compiler Itanium\\(TM\\) Compiler for the Itanium\\(TM\\)-based applications, Version (?P[^\\s*]*)'\n\n def __init__(self, fc = None, f90c = None):\n if fc is None:\n fc = 'efc'\n intel_ia32_fortran_compiler.__init__(self, fc, f90c)\n\n\nclass nag_fortran_compiler(fortran_compiler_base):\n\n vendor = 'NAG'\n ver_match = r'NAGWare Fortran 95 compiler Release (?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'f95'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ''\n debug = ' -g -gline -g90 -nan -C '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_switches = self.f77_switches + ' -fixed '\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -target=native '\n return opt\n\n def get_linker_so(self):\n return [self.f77_compiler,'-Wl,-shared']\n\n\nclass vast_fortran_compiler(fortran_compiler_base):\n\n vendor = 'VAST'\n ver_match = r'\\s*Pacific-Sierra Research vf90 (Personal|Professional)\\s+(?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'g77'\n if f90c is None:\n f90c = 'f90'\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n d,b = os.path.split(f90c)\n vf90 = os.path.join(d,'v'+b)\n self.ver_cmd = vf90+' -v '\n\n gnu = gnu_fortran_compiler(fc)\n if not gnu.is_available(): # VAST compiler requires g77.\n self.version = ''\n return\n if not self.is_available():\n return\n\n self.f77_switches = gnu.f77_switches\n self.f77_debug = gnu.f77_debug\n self.f77_opt = gnu.f77_opt \n\n # XXX: need f90 switches, debug, opt\n\n def get_linker_so(self):\n return [self.f90_compiler,'-shared']\n\nclass compaq_fortran_compiler(fortran_compiler_base):\n\n vendor = 'Compaq'\n ver_match = r'Compaq Fortran (?P[^\\s]*)'\n\n def __init__(self, fc = None, f90c = None):\n fortran_compiler_base.__init__(self)\n\n if fc is None:\n fc = 'fort'\n if f90c is None:\n f90c = fc\n\n self.f77_compiler = fc\n self.f90_compiler = f90c\n\n switches = ' -assume no2underscore -nomixed_str_len_arg '\n debug = ' -g -check_bounds '\n\n self.f77_switches = self.f90_switches = switches\n self.f77_debug = self.f90_debug = debug\n self.f77_opt = self.f90_opt = self.get_opt()\n\n # XXX: uncomment if required\n #self.libraries = ' -lUfor -lfor -lFutil -lcpml -lots -lc '\n\n # XXX: fix the version showing flag\n self.ver_cmd = self.f77_compiler+' -V '\n\n def get_opt(self):\n opt = ' -O4 -align dcommons -arch host -assume bigarrays -assume nozsize -math_library fast -tune host '\n return opt\n\n def get_linker_so(self):\n # XXX: is -shared needed?\n return [self.f77_compiler,'-shared']\n\n\ndef match_extension(files,ext):\n match = re.compile(r'.*[.]('+ext+r')\\Z',re.I).match\n return filter(lambda x,match = match: match(x),files)\n\ndef get_f77_files(files):\n return match_extension(files,'for|f77|ftn|f')\n\ndef get_f90_files(files):\n return match_extension(files,'f90|f95')\n\ndef get_fortran_files(files):\n return match_extension(files,'f90|f95|for|f77|ftn|f')\n\ndef find_fortran_compiler(vendor = None, fc = None, f90c = None):\n fcompiler = None\n for compiler_class in all_compilers:\n if vendor is not None and vendor != compiler_class.vendor:\n continue\n print compiler_class\n compiler = compiler_class(fc,f90c)\n if compiler.is_available():\n fcompiler = compiler\n break\n return fcompiler\n\nall_compilers = [absoft_fortran_compiler,\n mips_fortran_compiler,\n sun_fortran_compiler,\n intel_ia32_fortran_compiler,\n intel_itanium_fortran_compiler,\n nag_fortran_compiler,\n compaq_fortran_compiler,\n vast_fortran_compiler,\n gnu_fortran_compiler,\n ]\n\nif __name__ == \"__main__\":\n show_compilers()\n", + "methods": [ + { + "name": "run_command", + "long_name": "run_command( command )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 1, + "token_count": 32, + "parameters": [ + "command" + ], + "start_line": 59, + "end_line": 64, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "show_compilers", + "long_name": "show_compilers( )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 3, + "token_count": 23, + "parameters": [], + "start_line": 68, + "end_line": 72, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "build_flib.py", + "nloc": 11, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 102, + "end_line": 114, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "build_flib.py", + "nloc": 17, + "complexity": 3, + "token_count": 104, + "parameters": [ + "self" + ], + "start_line": 118, + "end_line": 134, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "has_f_libraries", + "long_name": "has_f_libraries( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 2, + "token_count": 23, + "parameters": [ + "self" + ], + "start_line": 138, + "end_line": 140, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 142, + "end_line": 145, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "has_f_library", + "long_name": "has_f_library( self , name )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 4, + "token_count": 32, + "parameters": [ + "self", + "name" + ], + "start_line": 149, + "end_line": 153, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "get_library_names", + "long_name": "get_library_names( self , name = None )", + "filename": "build_flib.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "name" + ], + "start_line": 155, + "end_line": 175, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "get_fcompiler_library_names", + "long_name": "get_fcompiler_library_names( self )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 177, + "end_line": 182, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_fcompiler_library_dirs", + "long_name": "get_fcompiler_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 184, + "end_line": 189, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self , name = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 7, + "token_count": 109, + "parameters": [ + "self", + "name" + ], + "start_line": 193, + "end_line": 210, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 214, + "end_line": 223, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_flib.py", + "nloc": 8, + "complexity": 3, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 227, + "end_line": 238, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "build_libraries", + "long_name": "build_libraries( self , fortran_libraries )", + "filename": "build_flib.py", + "nloc": 25, + "complexity": 10, + "token_count": 181, + "parameters": [ + "self", + "fortran_libraries" + ], + "start_line": 240, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 100, + "parameters": [ + "self", + "verbose", + "dry_run", + "force" + ], + "start_line": 287, + "end_line": 310, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "to_object", + "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 16, + "complexity": 3, + "token_count": 89, + "parameters": [ + "self", + "dirty_files", + "module_dirs", + "temp_dir" + ], + "start_line": 312, + "end_line": 327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "source_to_object_names", + "long_name": "source_to_object_names( self , source_files , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 6, + "complexity": 1, + "token_count": 89, + "parameters": [ + "self", + "source_files", + "temp_dir" + ], + "start_line": 329, + "end_line": 334, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "source_and_object_pairs", + "long_name": "source_and_object_pairs( self , source_files , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self", + "source_files", + "temp_dir" + ], + "start_line": 336, + "end_line": 339, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "f_compile", + "long_name": "f_compile( self , compiler , switches , source_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 18, + "complexity": 4, + "token_count": 128, + "parameters": [ + "self", + "compiler", + "switches", + "source_files", + "module_dirs", + "temp_dir" + ], + "start_line": 341, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "f90_compile", + "long_name": "f90_compile( self , source_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 1, + "token_count": 48, + "parameters": [ + "self", + "source_files", + "module_dirs", + "temp_dir" + ], + "start_line": 365, + "end_line": 368, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "f77_compile", + "long_name": "f77_compile( self , source_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 1, + "token_count": 48, + "parameters": [ + "self", + "source_files", + "module_dirs", + "temp_dir" + ], + "start_line": 370, + "end_line": 373, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 376, + "end_line": 377, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "create_static_lib", + "long_name": "create_static_lib( self , object_files , library_name , output_dir = '' , debug = None )", + "filename": "build_flib.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "object_files", + "library_name", + "output_dir", + "debug" + ], + "start_line": 379, + "end_line": 390, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "build_library", + "long_name": "build_library( self , library_name , source_list , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 104, + "parameters": [ + "self", + "library_name", + "source_list", + "module_dirs", + "temp_dir" + ], + "start_line": 392, + "end_line": 420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "dummy_fortran_files", + "long_name": "dummy_fortran_files( self )", + "filename": "build_flib.py", + "nloc": 8, + "complexity": 1, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 422, + "end_line": 429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "is_available", + "long_name": "is_available( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 431, + "end_line": 432, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "build_flib.py", + "nloc": 10, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 434, + "end_line": 452, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 454, + "end_line": 455, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 456, + "end_line": 457, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 458, + "end_line": 459, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 460, + "end_line": 461, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 1, + "complexity": 1, + "token_count": 6, + "parameters": [ + "self" + ], + "start_line": 462, + "end_line": 467, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 469, + "end_line": 470, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 31, + "complexity": 5, + "token_count": 177, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 478, + "end_line": 516, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 6, + "complexity": 3, + "token_count": 27, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 518, + "end_line": 523, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 525, + "end_line": 526, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 98, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 539, + "end_line": 561, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 6, + "complexity": 3, + "token_count": 27, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 563, + "end_line": 568, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "find_lib_dir", + "long_name": "find_lib_dir( self )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 99, + "parameters": [ + "self" + ], + "start_line": 570, + "end_line": 584, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 585, + "end_line": 586, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 587, + "end_line": 588, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 94, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 596, + "end_line": 614, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 616, + "end_line": 618, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "find_lib_dir", + "long_name": "find_lib_dir( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 619, + "end_line": 621, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 622, + "end_line": 623, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 624, + "end_line": 625, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 18, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 633, + "end_line": 657, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 21, + "complexity": 10, + "token_count": 120, + "parameters": [ + "self" + ], + "start_line": 659, + "end_line": 682, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "find_lib_directories", + "long_name": "find_lib_directories( self )", + "filename": "build_flib.py", + "nloc": 9, + "complexity": 3, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 684, + "end_line": 694, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 2, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 696, + "end_line": 699, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "f90_compile", + "long_name": "f90_compile( self , source_files , module_files , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "source_files", + "module_files", + "temp_dir" + ], + "start_line": 701, + "end_line": 702, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 22, + "complexity": 5, + "token_count": 140, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 711, + "end_line": 739, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 7, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 741, + "end_line": 755, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 758, + "end_line": 759, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 767, + "end_line": 770, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 100, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 778, + "end_line": 797, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 799, + "end_line": 801, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 803, + "end_line": 804, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 20, + "complexity": 5, + "token_count": 128, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 812, + "end_line": 836, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 840, + "end_line": 841, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 14, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 848, + "end_line": 870, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 872, + "end_line": 874, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 876, + "end_line": 878, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "match_extension", + "long_name": "match_extension( files , ext )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 44, + "parameters": [ + "files", + "ext" + ], + "start_line": 881, + "end_line": 883, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_f77_files", + "long_name": "get_f77_files( files )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "files" + ], + "start_line": 885, + "end_line": 886, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_f90_files", + "long_name": "get_f90_files( files )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "files" + ], + "start_line": 888, + "end_line": 889, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_fortran_files", + "long_name": "get_fortran_files( files )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "files" + ], + "start_line": 891, + "end_line": 892, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "find_fortran_compiler", + "long_name": "find_fortran_compiler( vendor = None , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 11, + "complexity": 5, + "token_count": 59, + "parameters": [ + "vendor", + "fc", + "f90c" + ], + "start_line": 894, + "end_line": 904, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "methods_before": [ + { + "name": "run_command", + "long_name": "run_command( command )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 1, + "token_count": 32, + "parameters": [ + "command" + ], + "start_line": 58, + "end_line": 63, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "show_compilers", + "long_name": "show_compilers( )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 3, + "token_count": 23, + "parameters": [], + "start_line": 67, + "end_line": 71, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 0 + }, + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "build_flib.py", + "nloc": 11, + "complexity": 1, + "token_count": 55, + "parameters": [ + "self" + ], + "start_line": 101, + "end_line": 113, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "build_flib.py", + "nloc": 17, + "complexity": 3, + "token_count": 104, + "parameters": [ + "self" + ], + "start_line": 117, + "end_line": 133, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 17, + "top_nesting_level": 1 + }, + { + "name": "has_f_libraries", + "long_name": "has_f_libraries( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 2, + "token_count": 23, + "parameters": [ + "self" + ], + "start_line": 137, + "end_line": 139, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 22, + "parameters": [ + "self" + ], + "start_line": 141, + "end_line": 144, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "has_f_library", + "long_name": "has_f_library( self , name )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 4, + "token_count": 32, + "parameters": [ + "self", + "name" + ], + "start_line": 148, + "end_line": 152, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 5, + "top_nesting_level": 1 + }, + { + "name": "get_library_names", + "long_name": "get_library_names( self , name = None )", + "filename": "build_flib.py", + "nloc": 17, + "complexity": 8, + "token_count": 117, + "parameters": [ + "self", + "name" + ], + "start_line": 154, + "end_line": 174, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "get_fcompiler_library_names", + "long_name": "get_fcompiler_library_names( self )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 176, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_fcompiler_library_dirs", + "long_name": "get_fcompiler_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 24, + "parameters": [ + "self" + ], + "start_line": 183, + "end_line": 188, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self , name = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 7, + "token_count": 109, + "parameters": [ + "self", + "name" + ], + "start_line": 192, + "end_line": 209, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 18, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 5, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 213, + "end_line": 222, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "get_source_files", + "long_name": "get_source_files( self )", + "filename": "build_flib.py", + "nloc": 8, + "complexity": 3, + "token_count": 49, + "parameters": [ + "self" + ], + "start_line": 226, + "end_line": 237, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "build_libraries", + "long_name": "build_libraries( self , fortran_libraries )", + "filename": "build_flib.py", + "nloc": 18, + "complexity": 5, + "token_count": 122, + "parameters": [ + "self", + "fortran_libraries" + ], + "start_line": 239, + "end_line": 260, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "build_flib.py", + "nloc": 16, + "complexity": 3, + "token_count": 88, + "parameters": [ + "self" + ], + "start_line": 272, + "end_line": 293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "to_object", + "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 13, + "complexity": 3, + "token_count": 89, + "parameters": [ + "self", + "dirty_files", + "module_dirs", + "temp_dir" + ], + "start_line": 295, + "end_line": 307, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 13, + "top_nesting_level": 1 + }, + { + "name": "source_to_object_names", + "long_name": "source_to_object_names( self , source_files , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 6, + "complexity": 1, + "token_count": 89, + "parameters": [ + "self", + "source_files", + "temp_dir" + ], + "start_line": 309, + "end_line": 314, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "source_and_object_pairs", + "long_name": "source_and_object_pairs( self , source_files , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self", + "source_files", + "temp_dir" + ], + "start_line": 316, + "end_line": 319, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "f_compile", + "long_name": "f_compile( self , compiler , switches , source_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 4, + "token_count": 103, + "parameters": [ + "self", + "compiler", + "switches", + "source_files", + "module_dirs", + "temp_dir" + ], + "start_line": 321, + "end_line": 335, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "f90_compile", + "long_name": "f90_compile( self , source_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 1, + "token_count": 48, + "parameters": [ + "self", + "source_files", + "module_dirs", + "temp_dir" + ], + "start_line": 339, + "end_line": 342, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "f77_compile", + "long_name": "f77_compile( self , source_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 1, + "token_count": 48, + "parameters": [ + "self", + "source_files", + "module_dirs", + "temp_dir" + ], + "start_line": 344, + "end_line": 347, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 350, + "end_line": 351, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "create_static_lib", + "long_name": "create_static_lib( self , object_files , library_name , output_dir = '' , debug = None )", + "filename": "build_flib.py", + "nloc": 9, + "complexity": 2, + "token_count": 68, + "parameters": [ + "self", + "object_files", + "library_name", + "output_dir", + "debug" + ], + "start_line": 353, + "end_line": 364, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 12, + "top_nesting_level": 1 + }, + { + "name": "build_library", + "long_name": "build_library( self , library_name , source_list , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 13, + "complexity": 3, + "token_count": 104, + "parameters": [ + "self", + "library_name", + "source_list", + "module_dirs", + "temp_dir" + ], + "start_line": 366, + "end_line": 392, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 27, + "top_nesting_level": 1 + }, + { + "name": "dummy_fortran_files", + "long_name": "dummy_fortran_files( self )", + "filename": "build_flib.py", + "nloc": 8, + "complexity": 1, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 394, + "end_line": 401, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 8, + "top_nesting_level": 1 + }, + { + "name": "is_available", + "long_name": "is_available( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 403, + "end_line": 404, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_version", + "long_name": "get_version( self )", + "filename": "build_flib.py", + "nloc": 10, + "complexity": 4, + "token_count": 66, + "parameters": [ + "self" + ], + "start_line": 406, + "end_line": 424, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "get_libraries", + "long_name": "get_libraries( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 426, + "end_line": 427, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_library_dirs", + "long_name": "get_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 428, + "end_line": 429, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 430, + "end_line": 431, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 432, + "end_line": 433, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 1, + "complexity": 1, + "token_count": 6, + "parameters": [ + "self" + ], + "start_line": 434, + "end_line": 439, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "__str__", + "long_name": "__str__( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 19, + "parameters": [ + "self" + ], + "start_line": 441, + "end_line": 442, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 31, + "complexity": 5, + "token_count": 177, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 450, + "end_line": 488, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 39, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 6, + "complexity": 3, + "token_count": 27, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 490, + "end_line": 495, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 497, + "end_line": 498, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 98, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 511, + "end_line": 533, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 6, + "complexity": 3, + "token_count": 27, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 535, + "end_line": 540, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "find_lib_dir", + "long_name": "find_lib_dir( self )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 99, + "parameters": [ + "self" + ], + "start_line": 542, + "end_line": 556, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 557, + "end_line": 558, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 9, + "parameters": [ + "self" + ], + "start_line": 559, + "end_line": 560, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 94, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 568, + "end_line": 586, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 19, + "top_nesting_level": 1 + }, + { + "name": "build_module_switch", + "long_name": "build_module_switch( self , module_dirs )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 12, + "parameters": [ + "self", + "module_dirs" + ], + "start_line": 588, + "end_line": 590, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "find_lib_dir", + "long_name": "find_lib_dir( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 591, + "end_line": 593, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_runtime_library_dirs", + "long_name": "get_runtime_library_dirs( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 11, + "parameters": [ + "self" + ], + "start_line": 594, + "end_line": 595, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "get_extra_link_args", + "long_name": "get_extra_link_args( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 8, + "parameters": [ + "self" + ], + "start_line": 596, + "end_line": 597, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 18, + "complexity": 5, + "token_count": 112, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 605, + "end_line": 629, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 21, + "complexity": 10, + "token_count": 120, + "parameters": [ + "self" + ], + "start_line": 631, + "end_line": 654, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + }, + { + "name": "find_lib_directories", + "long_name": "find_lib_directories( self )", + "filename": "build_flib.py", + "nloc": 9, + "complexity": 3, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 656, + "end_line": 666, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 2, + "token_count": 20, + "parameters": [ + "self" + ], + "start_line": 668, + "end_line": 671, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "f90_compile", + "long_name": "f90_compile( self , source_files , module_files , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 17, + "parameters": [ + "self", + "source_files", + "module_files", + "temp_dir" + ], + "start_line": 673, + "end_line": 674, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 22, + "complexity": 5, + "token_count": 140, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 683, + "end_line": 711, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 7, + "token_count": 85, + "parameters": [ + "self" + ], + "start_line": 713, + "end_line": 727, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 15, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 730, + "end_line": 731, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 4, + "complexity": 2, + "token_count": 31, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 739, + "end_line": 742, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 4, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 100, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 750, + "end_line": 769, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 20, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 771, + "end_line": 773, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 775, + "end_line": 776, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 20, + "complexity": 5, + "token_count": 128, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 784, + "end_line": 808, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 25, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 812, + "end_line": 813, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 14, + "complexity": 3, + "token_count": 91, + "parameters": [ + "self", + "fc", + "f90c" + ], + "start_line": 820, + "end_line": 842, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 23, + "top_nesting_level": 1 + }, + { + "name": "get_opt", + "long_name": "get_opt( self )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 10, + "parameters": [ + "self" + ], + "start_line": 844, + "end_line": 846, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "get_linker_so", + "long_name": "get_linker_so( self )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 13, + "parameters": [ + "self" + ], + "start_line": 848, + "end_line": 850, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 1 + }, + { + "name": "match_extension", + "long_name": "match_extension( files , ext )", + "filename": "build_flib.py", + "nloc": 3, + "complexity": 1, + "token_count": 44, + "parameters": [ + "files", + "ext" + ], + "start_line": 853, + "end_line": 855, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 3, + "top_nesting_level": 0 + }, + { + "name": "get_f77_files", + "long_name": "get_f77_files( files )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "files" + ], + "start_line": 857, + "end_line": 858, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_f90_files", + "long_name": "get_f90_files( files )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "files" + ], + "start_line": 860, + "end_line": 861, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "get_fortran_files", + "long_name": "get_fortran_files( files )", + "filename": "build_flib.py", + "nloc": 2, + "complexity": 1, + "token_count": 12, + "parameters": [ + "files" + ], + "start_line": 863, + "end_line": 864, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 2, + "top_nesting_level": 0 + }, + { + "name": "find_fortran_compiler", + "long_name": "find_fortran_compiler( vendor = None , fc = None , f90c = None )", + "filename": "build_flib.py", + "nloc": 11, + "complexity": 5, + "token_count": 59, + "parameters": [ + "vendor", + "fc", + "f90c" + ], + "start_line": 866, + "end_line": 876, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 0 + } + ], + "changed_methods": [ + { + "name": "build_library", + "long_name": "build_library( self , library_name , source_list , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 104, + "parameters": [ + "self", + "library_name", + "source_list", + "module_dirs", + "temp_dir" + ], + "start_line": 392, + "end_line": 420, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 29, + "top_nesting_level": 1 + }, + { + "name": "build_libraries", + "long_name": "build_libraries( self , fortran_libraries )", + "filename": "build_flib.py", + "nloc": 25, + "complexity": 10, + "token_count": 181, + "parameters": [ + "self", + "fortran_libraries" + ], + "start_line": 240, + "end_line": 272, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + }, + { + "name": "to_object", + "long_name": "to_object( self , dirty_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 16, + "complexity": 3, + "token_count": 89, + "parameters": [ + "self", + "dirty_files", + "module_dirs", + "temp_dir" + ], + "start_line": 312, + "end_line": 327, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 16, + "top_nesting_level": 1 + }, + { + "name": "f_compile", + "long_name": "f_compile( self , compiler , switches , source_files , module_dirs = None , temp_dir = '' )", + "filename": "build_flib.py", + "nloc": 18, + "complexity": 4, + "token_count": 128, + "parameters": [ + "self", + "compiler", + "switches", + "source_files", + "module_dirs", + "temp_dir" + ], + "start_line": 341, + "end_line": 361, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 21, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self )", + "filename": "build_flib.py", + "nloc": 16, + "complexity": 3, + "token_count": 88, + "parameters": [ + "self" + ], + "start_line": 272, + "end_line": 293, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 22, + "top_nesting_level": 1 + }, + { + "name": "__init__", + "long_name": "__init__( self , verbose = 0 , dry_run = 0 , force = 0 )", + "filename": "build_flib.py", + "nloc": 15, + "complexity": 3, + "token_count": 100, + "parameters": [ + "self", + "verbose", + "dry_run", + "force" + ], + "start_line": 287, + "end_line": 310, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 24, + "top_nesting_level": 1 + } + ], + "nloc": 657, + "complexity": 170, + "token_count": 3834, + "diff_parsed": { + "added": [ + "from distutils.ccompiler import CCompiler,gen_preprocess_options", + "", + " self.announce(\" building '%s' library\" % lib_name)", + "", + "", + "", + " include_dirs = build_info.get('include_dirs')", + "", + " if include_dirs:", + " fcompiler.set_include_dirs(include_dirs)", + " for n,v in build_info.get('define_macros') or []:", + " fcompiler.define_macro(n,v)", + " for n in build_info.get('undef_macros') or []:", + " fcompiler.undefine_macro(n)", + "", + "class fortran_compiler_base(CCompiler):", + "", + " compiler_type = 'fortran'", + " executables = {}", + " def __init__(self,verbose=0,dry_run=0,force=0):", + " # call this function.", + " CCompiler.__init__(self,verbose,dry_run,force)", + "", + " #self.libraries = []", + " #self.library_dirs = []", + " def to_object(self,", + " dirty_files,", + " module_dirs=None,", + " temp_dir=''):", + "", + " pp_opts = gen_preprocess_options(self.macros,self.include_dirs)", + "", + " switches = switches + string.join(pp_opts,' ')", + "", + " module_switch + \\", + " ' -c ' + source + ' -o ' + object", + " object_list = self.to_object(source_list,", + " module_dirs,", + " temp_dir)" + ], + "deleted": [ + "", + " self.announce(\" building '%s' library\" % lib_name)", + "", + "class fortran_compiler_base:", + " def __init__(self):", + " # call this functions.", + " self.libraries = []", + " self.library_dirs = []", + " def to_object(self,dirty_files,module_dirs=None, temp_dir=''):", + " module_switch + ' -c ' + source + ' -o ' + object", + " object_list = self.to_object(source_list,module_dirs,temp_dir)" + ] + } + }, + { + "old_path": "scipy_distutils/command/run_f2py.py", + "new_path": "scipy_distutils/command/run_f2py.py", + "filename": "run_f2py.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -211,9 +211,16 @@ def fortran_sources_to_flib(self, ext):\n flib = d\n break\n if flib is None:\n- flib = {'sources':[]}\n+ flib = {'sources':[],\n+ 'define_macros':[],\n+ 'undef_macros':[],\n+ 'include_dirs':[],\n+ }\n fortran_libraries.append((name,flib))\n-\n+ \n flib['sources'].extend(f_files)\n+ flib['define_macros'].extend(ext.define_macros)\n+ flib['undef_macros'].extend(ext.undef_macros)\n+ flib['include_dirs'].extend(ext.include_dirs)\n \n # class run_f2py\n", + "added_lines": 9, + "deleted_lines": 2, + "source_code": "\"\"\"distutils.command.run_f2py\n\nImplements the Distutils 'run_f2py' command.\n\"\"\"\n\n# created 2002/01/09, Pearu Peterson \n\n__revision__ = \"$Id$\"\n\nfrom distutils.dep_util import newer\nfrom scipy_distutils.core import Command\nfrom scipy_distutils.system_info import F2pyNotFoundError\n\nimport re,os\n\nmodule_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',re.I).match\nuser_module_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?__user__[\\w_]*)',re.I).match\nfortran_ext_re = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\n\nclass run_f2py(Command):\n\n description = \"\\\"run_f2py\\\" runs f2py that builds Fortran wrapper sources\"\\\n \"(C and occasionally Fortran).\"\n\n user_options = [('build-dir=', 'b',\n \"directory to build fortran wrappers to\"),\n ('debug-capi', None,\n \"generate C/API extensions with debugging code\"),\n ('no-wrap-functions', None,\n \"do not generate wrappers for Fortran functions,etc.\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ]\n\n def initialize_options (self):\n self.build_dir = None\n self.debug_capi = None\n self.force = None\n self.no_wrap_functions = None\n self.f2py_options = []\n # initialize_options()\n\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_dir'),\n ('force', 'force'))\n\n self.f2py_options.extend(['--build-dir',self.build_dir])\n\n if self.debug_capi is not None:\n self.f2py_options.append('--debug-capi')\n if self.no_wrap_functions is not None:\n self.f2py_options.append('--no-wrap-functions')\n\n # finalize_options()\n\n def run (self):\n if self.distribution.has_ext_modules():\n # XXX: might need also\n # build_flib = self.get_finalized_command('build_flib')\n # ...\n # for getting extra f2py_options that are specific to\n # a given fortran compiler.\n for ext in self.distribution.ext_modules:\n ext.sources = self.f2py_sources(ext.sources,ext)\n self.fortran_sources_to_flib(ext)\n # run()\n\n def f2py_sources (self, sources, ext):\n\n \"\"\"Walk the list of source files in 'sources', looking for f2py\n interface (.pyf) files. Run f2py on all that are found, and\n return a modified 'sources' list with f2py source files replaced\n by the generated C (or C++) and Fortran files.\n If 'sources' contains not .pyf files, then create a temporary\n one from the Fortran files in 'sources'.\n \"\"\"\n import string\n try:\n import f2py2e\n except ImportError:\n raise F2pyNotFoundError,F2pyNotFoundError.__doc__\n # f2py generates the following files for an extension module\n # with a name :\n # module.c\n # -f2pywrappers.f [occasionally]\n # In addition, /src/fortranobject.{c,h} are needed\n # for building f2py generated extension modules.\n # It is assumed that one pyf file contains defintions for exactly\n # one extension module.\n\n target_dir = self.build_dir\n \n new_sources = []\n f2py_sources = []\n fortran_sources = []\n f2py_targets = {}\n f2py_fortran_targets = {}\n target_ext = 'module.c'\n fortran_target_ext = '-f2pywrappers.f'\n\n for source in sources:\n (base, source_ext) = os.path.splitext(source)\n (source_dir, base) = os.path.split(base)\n if source_ext == \".pyf\": # f2py interface file\n # get extension module name\n f = open(source)\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = module_name_re(line)\n if m:\n if user_module_name_re(line): # skip *__user__* names\n continue\n base = m.group('name')\n break\n f.close()\n if ext.name == 'untitled':\n ext.name = base\n if base != string.split(ext.name,'.')[-1]:\n # XXX: Should we do here more than just warn?\n self.warn('%s provides %s but this extension is %s' \\\n % (source,`base`,`ext.name`))\n target_file = os.path.join(target_dir,base+target_ext)\n fortran_target_file = os.path.join(target_dir,base+fortran_target_ext)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n f2py_fortran_targets[source] = fortran_target_file\n elif fortran_ext_re(source_ext):\n fortran_sources.append(source) \n else:\n new_sources.append(source)\n\n if not (f2py_sources or fortran_sources):\n return new_sources\n\n # make sure the target dir exists\n from distutils.dir_util import mkpath\n mkpath(target_dir)\n\n if not f2py_sources:\n # creating a temporary pyf file from fortran sources\n pyf_target = os.path.join(target_dir,ext.name+'.pyf')\n pyf_target_file = os.path.join(target_dir,ext.name+target_ext)\n pyf_fortran_target_file = os.path.join(target_dir,ext.name+fortran_target_ext)\n f2py_opts2 = ['-m',ext.name,'-h',pyf_target,'--overwrite-signature']\n for source in fortran_sources:\n if newer(source,pyf_target) or self.force:\n self.announce(\"f2py-ing a new %s\" % (pyf_target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_opts2,' '))\n f2py2e.run_main(fortran_sources + f2py_opts2)\n break\n f2py_sources.append(pyf_target)\n f2py_targets[pyf_target] = pyf_target_file\n f2py_fortran_targets[pyf_target] = pyf_fortran_target_file\n\n new_sources.extend(fortran_sources)\n\n if len(f2py_sources) > 1:\n self.warn('Only one .pyf file can be used per Extension but got %s.'\\\n % (len(f2py_sources)))\n\n # a bit of a hack, but I think it'll work. Just include one of\n # the fortranobject.c files that was copied into most \n d = os.path.dirname(f2py2e.__file__)\n new_sources.append(os.path.join(d,'src','fortranobject.c'))\n ext.include_dirs.append(os.path.join(d,'src'))\n\n f2py_options = ext.f2py_options + self.f2py_options\n\n for source in f2py_sources:\n target = f2py_targets[source]\n fortran_target = f2py_fortran_targets[source]\n if newer(source,target) or self.force:\n self.announce(\"f2py-ing %s to %s\" % (source, target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_options,' '))\n f2py2e.run_main(f2py_options + [source])\n new_sources.append(target)\n if os.path.exists(fortran_target):\n new_sources.append(fortran_target)\n return new_sources\n\n # f2py_sources ()\n\n def fortran_sources_to_flib(self, ext):\n \"\"\"\n Extract fortran files from ext.sources and append them to\n fortran_libraries item having the same name as ext.\n \"\"\"\n sources = []\n f_files = []\n\n for file in ext.sources:\n if fortran_ext_re(file):\n f_files.append(file)\n else:\n sources.append(file)\n if not f_files:\n return\n\n ext.sources = sources\n\n if self.distribution.fortran_libraries is None:\n self.distribution.fortran_libraries = []\n fortran_libraries = self.distribution.fortran_libraries\n\n name = ext.name\n flib = None\n for n,d in fortran_libraries:\n if n == name:\n flib = d\n break\n if flib is None:\n flib = {'sources':[],\n 'define_macros':[],\n 'undef_macros':[],\n 'include_dirs':[],\n }\n fortran_libraries.append((name,flib))\n \n flib['sources'].extend(f_files)\n flib['define_macros'].extend(ext.define_macros)\n flib['undef_macros'].extend(ext.undef_macros)\n flib['include_dirs'].extend(ext.include_dirs)\n \n# class run_f2py\n", + "source_code_before": "\"\"\"distutils.command.run_f2py\n\nImplements the Distutils 'run_f2py' command.\n\"\"\"\n\n# created 2002/01/09, Pearu Peterson \n\n__revision__ = \"$Id$\"\n\nfrom distutils.dep_util import newer\nfrom scipy_distutils.core import Command\nfrom scipy_distutils.system_info import F2pyNotFoundError\n\nimport re,os\n\nmodule_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',re.I).match\nuser_module_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?__user__[\\w_]*)',re.I).match\nfortran_ext_re = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\n\nclass run_f2py(Command):\n\n description = \"\\\"run_f2py\\\" runs f2py that builds Fortran wrapper sources\"\\\n \"(C and occasionally Fortran).\"\n\n user_options = [('build-dir=', 'b',\n \"directory to build fortran wrappers to\"),\n ('debug-capi', None,\n \"generate C/API extensions with debugging code\"),\n ('no-wrap-functions', None,\n \"do not generate wrappers for Fortran functions,etc.\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ]\n\n def initialize_options (self):\n self.build_dir = None\n self.debug_capi = None\n self.force = None\n self.no_wrap_functions = None\n self.f2py_options = []\n # initialize_options()\n\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_dir'),\n ('force', 'force'))\n\n self.f2py_options.extend(['--build-dir',self.build_dir])\n\n if self.debug_capi is not None:\n self.f2py_options.append('--debug-capi')\n if self.no_wrap_functions is not None:\n self.f2py_options.append('--no-wrap-functions')\n\n # finalize_options()\n\n def run (self):\n if self.distribution.has_ext_modules():\n # XXX: might need also\n # build_flib = self.get_finalized_command('build_flib')\n # ...\n # for getting extra f2py_options that are specific to\n # a given fortran compiler.\n for ext in self.distribution.ext_modules:\n ext.sources = self.f2py_sources(ext.sources,ext)\n self.fortran_sources_to_flib(ext)\n # run()\n\n def f2py_sources (self, sources, ext):\n\n \"\"\"Walk the list of source files in 'sources', looking for f2py\n interface (.pyf) files. Run f2py on all that are found, and\n return a modified 'sources' list with f2py source files replaced\n by the generated C (or C++) and Fortran files.\n If 'sources' contains not .pyf files, then create a temporary\n one from the Fortran files in 'sources'.\n \"\"\"\n import string\n try:\n import f2py2e\n except ImportError:\n raise F2pyNotFoundError,F2pyNotFoundError.__doc__\n # f2py generates the following files for an extension module\n # with a name :\n # module.c\n # -f2pywrappers.f [occasionally]\n # In addition, /src/fortranobject.{c,h} are needed\n # for building f2py generated extension modules.\n # It is assumed that one pyf file contains defintions for exactly\n # one extension module.\n\n target_dir = self.build_dir\n \n new_sources = []\n f2py_sources = []\n fortran_sources = []\n f2py_targets = {}\n f2py_fortran_targets = {}\n target_ext = 'module.c'\n fortran_target_ext = '-f2pywrappers.f'\n\n for source in sources:\n (base, source_ext) = os.path.splitext(source)\n (source_dir, base) = os.path.split(base)\n if source_ext == \".pyf\": # f2py interface file\n # get extension module name\n f = open(source)\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = module_name_re(line)\n if m:\n if user_module_name_re(line): # skip *__user__* names\n continue\n base = m.group('name')\n break\n f.close()\n if ext.name == 'untitled':\n ext.name = base\n if base != string.split(ext.name,'.')[-1]:\n # XXX: Should we do here more than just warn?\n self.warn('%s provides %s but this extension is %s' \\\n % (source,`base`,`ext.name`))\n target_file = os.path.join(target_dir,base+target_ext)\n fortran_target_file = os.path.join(target_dir,base+fortran_target_ext)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n f2py_fortran_targets[source] = fortran_target_file\n elif fortran_ext_re(source_ext):\n fortran_sources.append(source) \n else:\n new_sources.append(source)\n\n if not (f2py_sources or fortran_sources):\n return new_sources\n\n # make sure the target dir exists\n from distutils.dir_util import mkpath\n mkpath(target_dir)\n\n if not f2py_sources:\n # creating a temporary pyf file from fortran sources\n pyf_target = os.path.join(target_dir,ext.name+'.pyf')\n pyf_target_file = os.path.join(target_dir,ext.name+target_ext)\n pyf_fortran_target_file = os.path.join(target_dir,ext.name+fortran_target_ext)\n f2py_opts2 = ['-m',ext.name,'-h',pyf_target,'--overwrite-signature']\n for source in fortran_sources:\n if newer(source,pyf_target) or self.force:\n self.announce(\"f2py-ing a new %s\" % (pyf_target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_opts2,' '))\n f2py2e.run_main(fortran_sources + f2py_opts2)\n break\n f2py_sources.append(pyf_target)\n f2py_targets[pyf_target] = pyf_target_file\n f2py_fortran_targets[pyf_target] = pyf_fortran_target_file\n\n new_sources.extend(fortran_sources)\n\n if len(f2py_sources) > 1:\n self.warn('Only one .pyf file can be used per Extension but got %s.'\\\n % (len(f2py_sources)))\n\n # a bit of a hack, but I think it'll work. Just include one of\n # the fortranobject.c files that was copied into most \n d = os.path.dirname(f2py2e.__file__)\n new_sources.append(os.path.join(d,'src','fortranobject.c'))\n ext.include_dirs.append(os.path.join(d,'src'))\n\n f2py_options = ext.f2py_options + self.f2py_options\n\n for source in f2py_sources:\n target = f2py_targets[source]\n fortran_target = f2py_fortran_targets[source]\n if newer(source,target) or self.force:\n self.announce(\"f2py-ing %s to %s\" % (source, target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_options,' '))\n f2py2e.run_main(f2py_options + [source])\n new_sources.append(target)\n if os.path.exists(fortran_target):\n new_sources.append(fortran_target)\n return new_sources\n\n # f2py_sources ()\n\n def fortran_sources_to_flib(self, ext):\n \"\"\"\n Extract fortran files from ext.sources and append them to\n fortran_libraries item having the same name as ext.\n \"\"\"\n sources = []\n f_files = []\n\n for file in ext.sources:\n if fortran_ext_re(file):\n f_files.append(file)\n else:\n sources.append(file)\n if not f_files:\n return\n\n ext.sources = sources\n\n if self.distribution.fortran_libraries is None:\n self.distribution.fortran_libraries = []\n fortran_libraries = self.distribution.fortran_libraries\n\n name = ext.name\n flib = None\n for n,d in fortran_libraries:\n if n == name:\n flib = d\n break\n if flib is None:\n flib = {'sources':[]}\n fortran_libraries.append((name,flib))\n\n flib['sources'].extend(f_files)\n \n# class run_f2py\n", + "methods": [ + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "run_f2py.py", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 35, + "end_line": 40, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "run_f2py.py", + "nloc": 9, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 44, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "run_f2py.py", + "nloc": 5, + "complexity": 3, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 58, + "end_line": 67, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "f2py_sources", + "long_name": "f2py_sources( self , sources , ext )", + "filename": "run_f2py.py", + "nloc": 79, + "complexity": 21, + "token_count": 595, + "parameters": [ + "self", + "sources", + "ext" + ], + "start_line": 70, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 1 + }, + { + "name": "fortran_sources_to_flib", + "long_name": "fortran_sources_to_flib( self , ext )", + "filename": "run_f2py.py", + "nloc": 31, + "complexity": 8, + "token_count": 182, + "parameters": [ + "self", + "ext" + ], + "start_line": 185, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "run_f2py.py", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 35, + "end_line": 40, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "run_f2py.py", + "nloc": 9, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 44, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "run_f2py.py", + "nloc": 5, + "complexity": 3, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 58, + "end_line": 67, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "f2py_sources", + "long_name": "f2py_sources( self , sources , ext )", + "filename": "run_f2py.py", + "nloc": 79, + "complexity": 21, + "token_count": 595, + "parameters": [ + "self", + "sources", + "ext" + ], + "start_line": 70, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 1 + }, + { + "name": "fortran_sources_to_flib", + "long_name": "fortran_sources_to_flib( self , ext )", + "filename": "run_f2py.py", + "nloc": 24, + "complexity": 8, + "token_count": 133, + "parameters": [ + "self", + "ext" + ], + "start_line": 185, + "end_line": 217, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 33, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "fortran_sources_to_flib", + "long_name": "fortran_sources_to_flib( self , ext )", + "filename": "run_f2py.py", + "nloc": 31, + "complexity": 8, + "token_count": 182, + "parameters": [ + "self", + "ext" + ], + "start_line": 185, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + } + ], + "nloc": 154, + "complexity": 36, + "token_count": 1043, + "diff_parsed": { + "added": [ + " flib = {'sources':[],", + " 'define_macros':[],", + " 'undef_macros':[],", + " 'include_dirs':[],", + " }", + "", + " flib['define_macros'].extend(ext.define_macros)", + " flib['undef_macros'].extend(ext.undef_macros)", + " flib['include_dirs'].extend(ext.include_dirs)" + ], + "deleted": [ + " flib = {'sources':[]}", + "" + ] + } + } + ] + }, + { + "hash": "cf5035a497ee83adb91090bf4f4d3c6faf969b9f", + "msg": "Fixed building extension modules from fortran sources", + "author": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "committer": { + "name": "Pearu Peterson", + "email": "pearu.peterson@gmail.com" + }, + "author_date": "2002-03-04T13:52:12+00:00", + "author_timezone": 0, + "committer_date": "2002-03-04T13:52:12+00:00", + "committer_timezone": 0, + "branches": [ + "main" + ], + "in_main_branch": true, + "merge": false, + "parents": [ + "a0d6e39d2ca303935901c2f92444fb367f64f3f3" + ], + "project_name": "repo_copy", + "project_path": "/tmp/tmp4nj7rs6j/repo_copy", + "deletions": 8, + "insertions": 11, + "lines": 19, + "files": 1, + "dmm_unit_size": 0.0, + "dmm_unit_complexity": 0.0, + "dmm_unit_interfacing": 0.3333333333333333, + "modified_files": [ + { + "old_path": "scipy_distutils/command/run_f2py.py", + "new_path": "scipy_distutils/command/run_f2py.py", + "filename": "run_f2py.py", + "extension": "py", + "change_type": "MODIFY", + "diff": "@@ -11,7 +11,7 @@\n from scipy_distutils.core import Command\n from scipy_distutils.system_info import F2pyNotFoundError\n \n-import re,os\n+import re,os,string\n \n module_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',re.I).match\n user_module_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?__user__[\\w_]*)',re.I).match\n@@ -99,6 +99,7 @@ def f2py_sources (self, sources, ext):\n f2py_fortran_targets = {}\n target_ext = 'module.c'\n fortran_target_ext = '-f2pywrappers.f'\n+ ext_name = string.split(ext.name,'.')[-1]\n \n for source in sources:\n (base, source_ext) = os.path.splitext(source)\n@@ -117,7 +118,7 @@ def f2py_sources (self, sources, ext):\n f.close()\n if ext.name == 'untitled':\n ext.name = base\n- if base != string.split(ext.name,'.')[-1]:\n+ if base != ext_name:\n # XXX: Should we do here more than just warn?\n self.warn('%s provides %s but this extension is %s' \\\n % (source,`base`,`ext.name`))\n@@ -140,14 +141,15 @@ def f2py_sources (self, sources, ext):\n \n if not f2py_sources:\n # creating a temporary pyf file from fortran sources\n- pyf_target = os.path.join(target_dir,ext.name+'.pyf')\n- pyf_target_file = os.path.join(target_dir,ext.name+target_ext)\n- pyf_fortran_target_file = os.path.join(target_dir,ext.name+fortran_target_ext)\n- f2py_opts2 = ['-m',ext.name,'-h',pyf_target,'--overwrite-signature']\n+ pyf_target = os.path.join(target_dir,ext_name+'.pyf')\n+ pyf_target_file = os.path.join(target_dir,ext_name+target_ext)\n+ pyf_fortran_target_file = os.path.join(target_dir,ext_name+fortran_target_ext)\n+ f2py_opts2 = ['-m',ext_name,'-h',pyf_target,'--overwrite-signature']\n for source in fortran_sources:\n if newer(source,pyf_target) or self.force:\n self.announce(\"f2py-ing a new %s\" % (pyf_target))\n- self.announce(\"f2py-opts: %s\" % string.join(f2py_opts2,' '))\n+ self.announce(\"f2py-opts: %s\" % \\\n+ string.join(f2py_opts2,' '))\n f2py2e.run_main(fortran_sources + f2py_opts2)\n break\n f2py_sources.append(pyf_target)\n@@ -204,7 +206,8 @@ def fortran_sources_to_flib(self, ext):\n self.distribution.fortran_libraries = []\n fortran_libraries = self.distribution.fortran_libraries\n \n- name = ext.name\n+ ext_name = string.split(ext.name,'.')[-1]\n+ name = ext_name\n flib = None\n for n,d in fortran_libraries:\n if n == name:\n", + "added_lines": 11, + "deleted_lines": 8, + "source_code": "\"\"\"distutils.command.run_f2py\n\nImplements the Distutils 'run_f2py' command.\n\"\"\"\n\n# created 2002/01/09, Pearu Peterson \n\n__revision__ = \"$Id$\"\n\nfrom distutils.dep_util import newer\nfrom scipy_distutils.core import Command\nfrom scipy_distutils.system_info import F2pyNotFoundError\n\nimport re,os,string\n\nmodule_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',re.I).match\nuser_module_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?__user__[\\w_]*)',re.I).match\nfortran_ext_re = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\n\nclass run_f2py(Command):\n\n description = \"\\\"run_f2py\\\" runs f2py that builds Fortran wrapper sources\"\\\n \"(C and occasionally Fortran).\"\n\n user_options = [('build-dir=', 'b',\n \"directory to build fortran wrappers to\"),\n ('debug-capi', None,\n \"generate C/API extensions with debugging code\"),\n ('no-wrap-functions', None,\n \"do not generate wrappers for Fortran functions,etc.\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ]\n\n def initialize_options (self):\n self.build_dir = None\n self.debug_capi = None\n self.force = None\n self.no_wrap_functions = None\n self.f2py_options = []\n # initialize_options()\n\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_dir'),\n ('force', 'force'))\n\n self.f2py_options.extend(['--build-dir',self.build_dir])\n\n if self.debug_capi is not None:\n self.f2py_options.append('--debug-capi')\n if self.no_wrap_functions is not None:\n self.f2py_options.append('--no-wrap-functions')\n\n # finalize_options()\n\n def run (self):\n if self.distribution.has_ext_modules():\n # XXX: might need also\n # build_flib = self.get_finalized_command('build_flib')\n # ...\n # for getting extra f2py_options that are specific to\n # a given fortran compiler.\n for ext in self.distribution.ext_modules:\n ext.sources = self.f2py_sources(ext.sources,ext)\n self.fortran_sources_to_flib(ext)\n # run()\n\n def f2py_sources (self, sources, ext):\n\n \"\"\"Walk the list of source files in 'sources', looking for f2py\n interface (.pyf) files. Run f2py on all that are found, and\n return a modified 'sources' list with f2py source files replaced\n by the generated C (or C++) and Fortran files.\n If 'sources' contains not .pyf files, then create a temporary\n one from the Fortran files in 'sources'.\n \"\"\"\n import string\n try:\n import f2py2e\n except ImportError:\n raise F2pyNotFoundError,F2pyNotFoundError.__doc__\n # f2py generates the following files for an extension module\n # with a name :\n # module.c\n # -f2pywrappers.f [occasionally]\n # In addition, /src/fortranobject.{c,h} are needed\n # for building f2py generated extension modules.\n # It is assumed that one pyf file contains defintions for exactly\n # one extension module.\n\n target_dir = self.build_dir\n \n new_sources = []\n f2py_sources = []\n fortran_sources = []\n f2py_targets = {}\n f2py_fortran_targets = {}\n target_ext = 'module.c'\n fortran_target_ext = '-f2pywrappers.f'\n ext_name = string.split(ext.name,'.')[-1]\n\n for source in sources:\n (base, source_ext) = os.path.splitext(source)\n (source_dir, base) = os.path.split(base)\n if source_ext == \".pyf\": # f2py interface file\n # get extension module name\n f = open(source)\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = module_name_re(line)\n if m:\n if user_module_name_re(line): # skip *__user__* names\n continue\n base = m.group('name')\n break\n f.close()\n if ext.name == 'untitled':\n ext.name = base\n if base != ext_name:\n # XXX: Should we do here more than just warn?\n self.warn('%s provides %s but this extension is %s' \\\n % (source,`base`,`ext.name`))\n target_file = os.path.join(target_dir,base+target_ext)\n fortran_target_file = os.path.join(target_dir,base+fortran_target_ext)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n f2py_fortran_targets[source] = fortran_target_file\n elif fortran_ext_re(source_ext):\n fortran_sources.append(source) \n else:\n new_sources.append(source)\n\n if not (f2py_sources or fortran_sources):\n return new_sources\n\n # make sure the target dir exists\n from distutils.dir_util import mkpath\n mkpath(target_dir)\n\n if not f2py_sources:\n # creating a temporary pyf file from fortran sources\n pyf_target = os.path.join(target_dir,ext_name+'.pyf')\n pyf_target_file = os.path.join(target_dir,ext_name+target_ext)\n pyf_fortran_target_file = os.path.join(target_dir,ext_name+fortran_target_ext)\n f2py_opts2 = ['-m',ext_name,'-h',pyf_target,'--overwrite-signature']\n for source in fortran_sources:\n if newer(source,pyf_target) or self.force:\n self.announce(\"f2py-ing a new %s\" % (pyf_target))\n self.announce(\"f2py-opts: %s\" % \\\n string.join(f2py_opts2,' '))\n f2py2e.run_main(fortran_sources + f2py_opts2)\n break\n f2py_sources.append(pyf_target)\n f2py_targets[pyf_target] = pyf_target_file\n f2py_fortran_targets[pyf_target] = pyf_fortran_target_file\n\n new_sources.extend(fortran_sources)\n\n if len(f2py_sources) > 1:\n self.warn('Only one .pyf file can be used per Extension but got %s.'\\\n % (len(f2py_sources)))\n\n # a bit of a hack, but I think it'll work. Just include one of\n # the fortranobject.c files that was copied into most \n d = os.path.dirname(f2py2e.__file__)\n new_sources.append(os.path.join(d,'src','fortranobject.c'))\n ext.include_dirs.append(os.path.join(d,'src'))\n\n f2py_options = ext.f2py_options + self.f2py_options\n\n for source in f2py_sources:\n target = f2py_targets[source]\n fortran_target = f2py_fortran_targets[source]\n if newer(source,target) or self.force:\n self.announce(\"f2py-ing %s to %s\" % (source, target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_options,' '))\n f2py2e.run_main(f2py_options + [source])\n new_sources.append(target)\n if os.path.exists(fortran_target):\n new_sources.append(fortran_target)\n return new_sources\n\n # f2py_sources ()\n\n def fortran_sources_to_flib(self, ext):\n \"\"\"\n Extract fortran files from ext.sources and append them to\n fortran_libraries item having the same name as ext.\n \"\"\"\n sources = []\n f_files = []\n\n for file in ext.sources:\n if fortran_ext_re(file):\n f_files.append(file)\n else:\n sources.append(file)\n if not f_files:\n return\n\n ext.sources = sources\n\n if self.distribution.fortran_libraries is None:\n self.distribution.fortran_libraries = []\n fortran_libraries = self.distribution.fortran_libraries\n\n ext_name = string.split(ext.name,'.')[-1]\n name = ext_name\n flib = None\n for n,d in fortran_libraries:\n if n == name:\n flib = d\n break\n if flib is None:\n flib = {'sources':[],\n 'define_macros':[],\n 'undef_macros':[],\n 'include_dirs':[],\n }\n fortran_libraries.append((name,flib))\n \n flib['sources'].extend(f_files)\n flib['define_macros'].extend(ext.define_macros)\n flib['undef_macros'].extend(ext.undef_macros)\n flib['include_dirs'].extend(ext.include_dirs)\n \n# class run_f2py\n", + "source_code_before": "\"\"\"distutils.command.run_f2py\n\nImplements the Distutils 'run_f2py' command.\n\"\"\"\n\n# created 2002/01/09, Pearu Peterson \n\n__revision__ = \"$Id$\"\n\nfrom distutils.dep_util import newer\nfrom scipy_distutils.core import Command\nfrom scipy_distutils.system_info import F2pyNotFoundError\n\nimport re,os\n\nmodule_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]+)',re.I).match\nuser_module_name_re = re.compile(r'\\s*python\\s*module\\s*(?P[\\w_]*?__user__[\\w_]*)',re.I).match\nfortran_ext_re = re.compile(r'.*[.](f90|f95|f77|for|ftn|f)\\Z',re.I).match\n\nclass run_f2py(Command):\n\n description = \"\\\"run_f2py\\\" runs f2py that builds Fortran wrapper sources\"\\\n \"(C and occasionally Fortran).\"\n\n user_options = [('build-dir=', 'b',\n \"directory to build fortran wrappers to\"),\n ('debug-capi', None,\n \"generate C/API extensions with debugging code\"),\n ('no-wrap-functions', None,\n \"do not generate wrappers for Fortran functions,etc.\"),\n ('force', 'f',\n \"forcibly build everything (ignore file timestamps)\"),\n ]\n\n def initialize_options (self):\n self.build_dir = None\n self.debug_capi = None\n self.force = None\n self.no_wrap_functions = None\n self.f2py_options = []\n # initialize_options()\n\n\n def finalize_options (self):\n self.set_undefined_options('build',\n ('build_temp', 'build_dir'),\n ('force', 'force'))\n\n self.f2py_options.extend(['--build-dir',self.build_dir])\n\n if self.debug_capi is not None:\n self.f2py_options.append('--debug-capi')\n if self.no_wrap_functions is not None:\n self.f2py_options.append('--no-wrap-functions')\n\n # finalize_options()\n\n def run (self):\n if self.distribution.has_ext_modules():\n # XXX: might need also\n # build_flib = self.get_finalized_command('build_flib')\n # ...\n # for getting extra f2py_options that are specific to\n # a given fortran compiler.\n for ext in self.distribution.ext_modules:\n ext.sources = self.f2py_sources(ext.sources,ext)\n self.fortran_sources_to_flib(ext)\n # run()\n\n def f2py_sources (self, sources, ext):\n\n \"\"\"Walk the list of source files in 'sources', looking for f2py\n interface (.pyf) files. Run f2py on all that are found, and\n return a modified 'sources' list with f2py source files replaced\n by the generated C (or C++) and Fortran files.\n If 'sources' contains not .pyf files, then create a temporary\n one from the Fortran files in 'sources'.\n \"\"\"\n import string\n try:\n import f2py2e\n except ImportError:\n raise F2pyNotFoundError,F2pyNotFoundError.__doc__\n # f2py generates the following files for an extension module\n # with a name :\n # module.c\n # -f2pywrappers.f [occasionally]\n # In addition, /src/fortranobject.{c,h} are needed\n # for building f2py generated extension modules.\n # It is assumed that one pyf file contains defintions for exactly\n # one extension module.\n\n target_dir = self.build_dir\n \n new_sources = []\n f2py_sources = []\n fortran_sources = []\n f2py_targets = {}\n f2py_fortran_targets = {}\n target_ext = 'module.c'\n fortran_target_ext = '-f2pywrappers.f'\n\n for source in sources:\n (base, source_ext) = os.path.splitext(source)\n (source_dir, base) = os.path.split(base)\n if source_ext == \".pyf\": # f2py interface file\n # get extension module name\n f = open(source)\n f_readlines = getattr(f,'xreadlines',f.readlines)\n for line in f_readlines():\n m = module_name_re(line)\n if m:\n if user_module_name_re(line): # skip *__user__* names\n continue\n base = m.group('name')\n break\n f.close()\n if ext.name == 'untitled':\n ext.name = base\n if base != string.split(ext.name,'.')[-1]:\n # XXX: Should we do here more than just warn?\n self.warn('%s provides %s but this extension is %s' \\\n % (source,`base`,`ext.name`))\n target_file = os.path.join(target_dir,base+target_ext)\n fortran_target_file = os.path.join(target_dir,base+fortran_target_ext)\n f2py_sources.append(source)\n f2py_targets[source] = target_file\n f2py_fortran_targets[source] = fortran_target_file\n elif fortran_ext_re(source_ext):\n fortran_sources.append(source) \n else:\n new_sources.append(source)\n\n if not (f2py_sources or fortran_sources):\n return new_sources\n\n # make sure the target dir exists\n from distutils.dir_util import mkpath\n mkpath(target_dir)\n\n if not f2py_sources:\n # creating a temporary pyf file from fortran sources\n pyf_target = os.path.join(target_dir,ext.name+'.pyf')\n pyf_target_file = os.path.join(target_dir,ext.name+target_ext)\n pyf_fortran_target_file = os.path.join(target_dir,ext.name+fortran_target_ext)\n f2py_opts2 = ['-m',ext.name,'-h',pyf_target,'--overwrite-signature']\n for source in fortran_sources:\n if newer(source,pyf_target) or self.force:\n self.announce(\"f2py-ing a new %s\" % (pyf_target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_opts2,' '))\n f2py2e.run_main(fortran_sources + f2py_opts2)\n break\n f2py_sources.append(pyf_target)\n f2py_targets[pyf_target] = pyf_target_file\n f2py_fortran_targets[pyf_target] = pyf_fortran_target_file\n\n new_sources.extend(fortran_sources)\n\n if len(f2py_sources) > 1:\n self.warn('Only one .pyf file can be used per Extension but got %s.'\\\n % (len(f2py_sources)))\n\n # a bit of a hack, but I think it'll work. Just include one of\n # the fortranobject.c files that was copied into most \n d = os.path.dirname(f2py2e.__file__)\n new_sources.append(os.path.join(d,'src','fortranobject.c'))\n ext.include_dirs.append(os.path.join(d,'src'))\n\n f2py_options = ext.f2py_options + self.f2py_options\n\n for source in f2py_sources:\n target = f2py_targets[source]\n fortran_target = f2py_fortran_targets[source]\n if newer(source,target) or self.force:\n self.announce(\"f2py-ing %s to %s\" % (source, target))\n self.announce(\"f2py-opts: %s\" % string.join(f2py_options,' '))\n f2py2e.run_main(f2py_options + [source])\n new_sources.append(target)\n if os.path.exists(fortran_target):\n new_sources.append(fortran_target)\n return new_sources\n\n # f2py_sources ()\n\n def fortran_sources_to_flib(self, ext):\n \"\"\"\n Extract fortran files from ext.sources and append them to\n fortran_libraries item having the same name as ext.\n \"\"\"\n sources = []\n f_files = []\n\n for file in ext.sources:\n if fortran_ext_re(file):\n f_files.append(file)\n else:\n sources.append(file)\n if not f_files:\n return\n\n ext.sources = sources\n\n if self.distribution.fortran_libraries is None:\n self.distribution.fortran_libraries = []\n fortran_libraries = self.distribution.fortran_libraries\n\n name = ext.name\n flib = None\n for n,d in fortran_libraries:\n if n == name:\n flib = d\n break\n if flib is None:\n flib = {'sources':[],\n 'define_macros':[],\n 'undef_macros':[],\n 'include_dirs':[],\n }\n fortran_libraries.append((name,flib))\n \n flib['sources'].extend(f_files)\n flib['define_macros'].extend(ext.define_macros)\n flib['undef_macros'].extend(ext.undef_macros)\n flib['include_dirs'].extend(ext.include_dirs)\n \n# class run_f2py\n", + "methods": [ + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "run_f2py.py", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 35, + "end_line": 40, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "run_f2py.py", + "nloc": 9, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 44, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "run_f2py.py", + "nloc": 5, + "complexity": 3, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 58, + "end_line": 67, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "f2py_sources", + "long_name": "f2py_sources( self , sources , ext )", + "filename": "run_f2py.py", + "nloc": 81, + "complexity": 21, + "token_count": 591, + "parameters": [ + "self", + "sources", + "ext" + ], + "start_line": 70, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 114, + "top_nesting_level": 1 + }, + { + "name": "fortran_sources_to_flib", + "long_name": "fortran_sources_to_flib( self , ext )", + "filename": "run_f2py.py", + "nloc": 32, + "complexity": 8, + "token_count": 196, + "parameters": [ + "self", + "ext" + ], + "start_line": 187, + "end_line": 227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + } + ], + "methods_before": [ + { + "name": "initialize_options", + "long_name": "initialize_options( self )", + "filename": "run_f2py.py", + "nloc": 6, + "complexity": 1, + "token_count": 31, + "parameters": [ + "self" + ], + "start_line": 35, + "end_line": 40, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 6, + "top_nesting_level": 1 + }, + { + "name": "finalize_options", + "long_name": "finalize_options( self )", + "filename": "run_f2py.py", + "nloc": 9, + "complexity": 3, + "token_count": 69, + "parameters": [ + "self" + ], + "start_line": 44, + "end_line": 54, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 11, + "top_nesting_level": 1 + }, + { + "name": "run", + "long_name": "run( self )", + "filename": "run_f2py.py", + "nloc": 5, + "complexity": 3, + "token_count": 43, + "parameters": [ + "self" + ], + "start_line": 58, + "end_line": 67, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 10, + "top_nesting_level": 1 + }, + { + "name": "f2py_sources", + "long_name": "f2py_sources( self , sources , ext )", + "filename": "run_f2py.py", + "nloc": 79, + "complexity": 21, + "token_count": 595, + "parameters": [ + "self", + "sources", + "ext" + ], + "start_line": 70, + "end_line": 181, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 112, + "top_nesting_level": 1 + }, + { + "name": "fortran_sources_to_flib", + "long_name": "fortran_sources_to_flib( self , ext )", + "filename": "run_f2py.py", + "nloc": 31, + "complexity": 8, + "token_count": 182, + "parameters": [ + "self", + "ext" + ], + "start_line": 185, + "end_line": 224, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 40, + "top_nesting_level": 1 + } + ], + "changed_methods": [ + { + "name": "fortran_sources_to_flib", + "long_name": "fortran_sources_to_flib( self , ext )", + "filename": "run_f2py.py", + "nloc": 32, + "complexity": 8, + "token_count": 196, + "parameters": [ + "self", + "ext" + ], + "start_line": 187, + "end_line": 227, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 41, + "top_nesting_level": 1 + }, + { + "name": "f2py_sources", + "long_name": "f2py_sources( self , sources , ext )", + "filename": "run_f2py.py", + "nloc": 81, + "complexity": 21, + "token_count": 591, + "parameters": [ + "self", + "sources", + "ext" + ], + "start_line": 70, + "end_line": 183, + "fan_in": 0, + "fan_out": 0, + "general_fan_out": 0, + "length": 114, + "top_nesting_level": 1 + } + ], + "nloc": 157, + "complexity": 36, + "token_count": 1055, + "diff_parsed": { + "added": [ + "import re,os,string", + " ext_name = string.split(ext.name,'.')[-1]", + " if base != ext_name:", + " pyf_target = os.path.join(target_dir,ext_name+'.pyf')", + " pyf_target_file = os.path.join(target_dir,ext_name+target_ext)", + " pyf_fortran_target_file = os.path.join(target_dir,ext_name+fortran_target_ext)", + " f2py_opts2 = ['-m',ext_name,'-h',pyf_target,'--overwrite-signature']", + " self.announce(\"f2py-opts: %s\" % \\", + " string.join(f2py_opts2,' '))", + " ext_name = string.split(ext.name,'.')[-1]", + " name = ext_name" + ], + "deleted": [ + "import re,os", + " if base != string.split(ext.name,'.')[-1]:", + " pyf_target = os.path.join(target_dir,ext.name+'.pyf')", + " pyf_target_file = os.path.join(target_dir,ext.name+target_ext)", + " pyf_fortran_target_file = os.path.join(target_dir,ext.name+fortran_target_ext)", + " f2py_opts2 = ['-m',ext.name,'-h',pyf_target,'--overwrite-signature']", + " self.announce(\"f2py-opts: %s\" % string.join(f2py_opts2,' '))", + " name = ext.name" + ] + } + } + ] + } +] \ No newline at end of file